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.

252125 lines
6.3MB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifdef __JUCE_JUCEHEADER__
  19. #error
  20. #endif
  21. /*** Start of inlined file: juce_TargetPlatform.h ***/
  22. #ifndef __JUCE_TARGETPLATFORM_JUCEHEADER__
  23. #define __JUCE_TARGETPLATFORM_JUCEHEADER__
  24. #if (defined (_WIN32) || defined (_WIN64))
  25. #define JUCE_WIN32 1
  26. #define JUCE_WINDOWS 1
  27. #elif defined (LINUX) || defined (__linux__)
  28. #define JUCE_LINUX 1
  29. #elif defined(__APPLE_CPP__) || defined(__APPLE_CC__)
  30. #include <CoreFoundation/CoreFoundation.h> // (needed to find out what platform we're using)
  31. #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
  32. #define JUCE_IPHONE 1
  33. #else
  34. #define JUCE_MAC 1
  35. #endif
  36. #else
  37. #error "Unknown platform!"
  38. #endif
  39. #if JUCE_WINDOWS
  40. #ifdef _MSC_VER
  41. #ifdef _WIN64
  42. #define JUCE_64BIT 1
  43. #else
  44. #define JUCE_32BIT 1
  45. #endif
  46. #endif
  47. #ifdef _DEBUG
  48. #define JUCE_DEBUG 1
  49. #endif
  50. #ifdef __MINGW32__
  51. #define JUCE_MINGW 1
  52. #endif
  53. #define JUCE_LITTLE_ENDIAN 1
  54. #define JUCE_INTEL 1
  55. #endif
  56. #if JUCE_MAC
  57. #ifndef NDEBUG
  58. #define JUCE_DEBUG 1
  59. #endif
  60. #ifdef __LITTLE_ENDIAN__
  61. #define JUCE_LITTLE_ENDIAN 1
  62. #else
  63. #define JUCE_BIG_ENDIAN 1
  64. #endif
  65. #if defined (__ppc__) || defined (__ppc64__)
  66. #define JUCE_PPC 1
  67. #undef MAC_OS_X_VERSION_MAX_ALLOWED
  68. #define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_4
  69. #else
  70. #define JUCE_INTEL 1
  71. #endif
  72. #ifdef __LP64__
  73. #define JUCE_64BIT 1
  74. #else
  75. #define JUCE_32BIT 1
  76. #endif
  77. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4
  78. #error "Building for OSX 10.3 is no longer supported!"
  79. #endif
  80. #ifndef MAC_OS_X_VERSION_10_5
  81. #error "To build with 10.4 compatibility, use a 10.5 or 10.6 SDK and set the deployment target to 10.4"
  82. #endif
  83. #endif
  84. #if JUCE_IPHONE
  85. #ifndef NDEBUG
  86. #define JUCE_DEBUG 1
  87. #endif
  88. #ifdef __LITTLE_ENDIAN__
  89. #define JUCE_LITTLE_ENDIAN 1
  90. #else
  91. #define JUCE_BIG_ENDIAN 1
  92. #endif
  93. #endif
  94. #if JUCE_LINUX
  95. #ifdef _DEBUG
  96. #define JUCE_DEBUG 1
  97. #endif
  98. // Allow override for big-endian Linux platforms
  99. #ifndef JUCE_BIG_ENDIAN
  100. #define JUCE_LITTLE_ENDIAN 1
  101. #endif
  102. #if defined (__LP64__) || defined (_LP64)
  103. #define JUCE_64BIT 1
  104. #else
  105. #define JUCE_32BIT 1
  106. #endif
  107. #define JUCE_INTEL 1
  108. #endif
  109. // Compiler type macros.
  110. #ifdef __GNUC__
  111. #define JUCE_GCC 1
  112. #elif defined (_MSC_VER)
  113. #define JUCE_MSVC 1
  114. #if _MSC_VER >= 1400
  115. #define JUCE_USE_INTRINSICS 1
  116. #endif
  117. #else
  118. #error unknown compiler
  119. #endif
  120. #endif // __JUCE_TARGETPLATFORM_JUCEHEADER__
  121. /*** End of inlined file: juce_TargetPlatform.h ***/
  122. // FORCE_AMALGAMATOR_INCLUDE
  123. /*** Start of inlined file: juce_Config.h ***/
  124. #ifndef __JUCE_CONFIG_JUCEHEADER__
  125. #define __JUCE_CONFIG_JUCEHEADER__
  126. #ifndef JUCE_NAMESPACE
  127. #define JUCE_NAMESPACE juce
  128. #endif
  129. #ifndef JUCE_FORCE_DEBUG
  130. //#define JUCE_FORCE_DEBUG 1
  131. #endif
  132. #ifndef JUCE_LOG_ASSERTIONS
  133. // #define JUCE_LOG_ASSERTIONS 1
  134. #endif
  135. #ifndef JUCE_ASIO
  136. #define JUCE_ASIO 1
  137. #endif
  138. #ifndef JUCE_WASAPI
  139. // #define JUCE_WASAPI 1
  140. #endif
  141. #ifndef JUCE_DIRECTSOUND
  142. #define JUCE_DIRECTSOUND 1
  143. #endif
  144. #ifndef JUCE_ALSA
  145. #define JUCE_ALSA 1
  146. #endif
  147. #ifndef JUCE_JACK
  148. #define JUCE_JACK 1
  149. #endif
  150. #if ! (defined (JUCE_QUICKTIME) || JUCE_LINUX || JUCE_IPHONE || (JUCE_WINDOWS && ! JUCE_MSVC))
  151. #define JUCE_QUICKTIME 1
  152. #endif
  153. #ifndef JUCE_OPENGL
  154. #define JUCE_OPENGL 1
  155. #endif
  156. #ifndef JUCE_USE_FLAC
  157. #define JUCE_USE_FLAC 1
  158. #endif
  159. #ifndef JUCE_USE_OGGVORBIS
  160. #define JUCE_USE_OGGVORBIS 1
  161. #endif
  162. #if (! defined (JUCE_USE_CDBURNER)) && ! (JUCE_WINDOWS && ! JUCE_MSVC)
  163. #define JUCE_USE_CDBURNER 1
  164. #endif
  165. #ifndef JUCE_USE_CDREADER
  166. #define JUCE_USE_CDREADER 1
  167. #endif
  168. #if JUCE_QUICKTIME && ! defined (JUCE_USE_CAMERA)
  169. // #define JUCE_USE_CAMERA 1
  170. #endif
  171. #ifndef JUCE_ENABLE_REPAINT_DEBUGGING
  172. // #define JUCE_ENABLE_REPAINT_DEBUGGING 1
  173. #endif
  174. #ifndef JUCE_USE_XINERAMA
  175. #define JUCE_USE_XINERAMA 1
  176. #endif
  177. #ifndef JUCE_USE_XSHM
  178. #define JUCE_USE_XSHM 1
  179. #endif
  180. #ifndef JUCE_PLUGINHOST_VST
  181. // #define JUCE_PLUGINHOST_VST 1
  182. #endif
  183. #ifndef JUCE_PLUGINHOST_AU
  184. // #define JUCE_PLUGINHOST_AU 1
  185. #endif
  186. #ifndef JUCE_ONLY_BUILD_CORE_LIBRARY
  187. //#define JUCE_ONLY_BUILD_CORE_LIBRARY 1
  188. #endif
  189. #ifndef JUCE_WEB_BROWSER
  190. #define JUCE_WEB_BROWSER 1
  191. #endif
  192. #ifndef JUCE_SUPPORT_CARBON
  193. #define JUCE_SUPPORT_CARBON 1
  194. #endif
  195. #ifndef JUCE_INCLUDE_ZLIB_CODE
  196. #define JUCE_INCLUDE_ZLIB_CODE 1
  197. #endif
  198. #ifndef JUCE_INCLUDE_FLAC_CODE
  199. #define JUCE_INCLUDE_FLAC_CODE 1
  200. #endif
  201. #ifndef JUCE_INCLUDE_OGGVORBIS_CODE
  202. #define JUCE_INCLUDE_OGGVORBIS_CODE 1
  203. #endif
  204. #ifndef JUCE_INCLUDE_PNGLIB_CODE
  205. #define JUCE_INCLUDE_PNGLIB_CODE 1
  206. #endif
  207. #ifndef JUCE_INCLUDE_JPEGLIB_CODE
  208. #define JUCE_INCLUDE_JPEGLIB_CODE 1
  209. #endif
  210. #ifndef JUCE_CHECK_MEMORY_LEAKS
  211. #define JUCE_CHECK_MEMORY_LEAKS 1
  212. #endif
  213. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  214. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  215. #endif
  216. #ifndef JUCE_STRINGS_ARE_UNICODE
  217. #define JUCE_STRINGS_ARE_UNICODE 1
  218. #endif
  219. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  220. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  221. #undef JUCE_QUICKTIME
  222. #define JUCE_QUICKTIME 0
  223. #undef JUCE_OPENGL
  224. #define JUCE_OPENGL 0
  225. #undef JUCE_USE_CDBURNER
  226. #define JUCE_USE_CDBURNER 0
  227. #undef JUCE_USE_CDREADER
  228. #define JUCE_USE_CDREADER 0
  229. #undef JUCE_WEB_BROWSER
  230. #define JUCE_WEB_BROWSER 0
  231. #undef JUCE_PLUGINHOST_AU
  232. #define JUCE_PLUGINHOST_AU 0
  233. #undef JUCE_PLUGINHOST_VST
  234. #define JUCE_PLUGINHOST_VST 0
  235. #endif
  236. #endif
  237. /*** End of inlined file: juce_Config.h ***/
  238. // FORCE_AMALGAMATOR_INCLUDE
  239. #ifndef JUCE_BUILD_CORE
  240. #define JUCE_BUILD_CORE 1
  241. #endif
  242. #ifndef JUCE_BUILD_MISC
  243. #define JUCE_BUILD_MISC 1
  244. #endif
  245. #ifndef JUCE_BUILD_GUI
  246. #define JUCE_BUILD_GUI 1
  247. #endif
  248. #ifndef JUCE_BUILD_NATIVE
  249. #define JUCE_BUILD_NATIVE 1
  250. #endif
  251. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  252. #undef JUCE_BUILD_MISC
  253. #undef JUCE_BUILD_GUI
  254. #endif
  255. //==============================================================================
  256. #if JUCE_BUILD_NATIVE || JUCE_BUILD_CORE || (JUCE_BUILD_MISC && (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_AU))
  257. #if JUCE_WINDOWS
  258. /*** Start of inlined file: juce_win32_NativeIncludes.h ***/
  259. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  260. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  261. #ifndef STRICT
  262. #define STRICT 1
  263. #endif
  264. #undef WIN32_LEAN_AND_MEAN
  265. #define WIN32_LEAN_AND_MEAN 1
  266. #ifdef _MSC_VER
  267. #pragma warning (push)
  268. #pragma warning (disable : 4100 4201 4514 4312 4995)
  269. #endif
  270. #define _WIN32_WINNT 0x0500
  271. #define _UNICODE 1
  272. #define UNICODE 1
  273. #ifndef _WIN32_IE
  274. #define _WIN32_IE 0x0400
  275. #endif
  276. #include <windows.h>
  277. #include <windowsx.h>
  278. #include <commdlg.h>
  279. #include <shellapi.h>
  280. #include <mmsystem.h>
  281. #include <vfw.h>
  282. #include <tchar.h>
  283. #include <stddef.h>
  284. #include <ctime>
  285. #include <wininet.h>
  286. #include <nb30.h>
  287. #include <iphlpapi.h>
  288. #include <mapi.h>
  289. #include <float.h>
  290. #include <process.h>
  291. #include <Exdisp.h>
  292. #include <exdispid.h>
  293. #include <shlobj.h>
  294. #if ! JUCE_MINGW
  295. #include <crtdbg.h>
  296. #include <comutil.h>
  297. #endif
  298. #if JUCE_OPENGL
  299. #include <gl/gl.h>
  300. #endif
  301. #undef PACKED
  302. #if JUCE_ASIO
  303. #include "iasiodrv.h"
  304. #endif
  305. #if JUCE_USE_CDBURNER
  306. #include <imapi.h>
  307. #include <imapierror.h>
  308. #endif
  309. #if JUCE_USE_CAMERA
  310. #include <dshow.h>
  311. #include <qedit.h>
  312. #endif
  313. #if JUCE_WASAPI
  314. #include <MMReg.h>
  315. #include <mmdeviceapi.h>
  316. #include <Audioclient.h>
  317. #include <Avrt.h>
  318. #include <functiondiscoverykeys.h>
  319. #endif
  320. #if JUCE_QUICKTIME
  321. #include <Movies.h>
  322. #include <QTML.h>
  323. #include <QuickTimeComponents.h>
  324. #include <MediaHandlers.h>
  325. #include <ImageCodec.h>
  326. #import <QTOLibrary.dll>
  327. #import <QTOControl.dll>
  328. #endif
  329. #ifdef _MSC_VER
  330. #pragma warning (pop)
  331. #endif
  332. template <class T>
  333. class ComSmartPtr
  334. {
  335. public:
  336. ComSmartPtr() throw() : p (0) {}
  337. ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  338. ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  339. ~ComSmartPtr() { if (p != 0) p->Release(); }
  340. operator T*() const throw() { return p; }
  341. T& operator*() const throw() { return *p; }
  342. T** operator&() throw() { return &p; }
  343. T* operator->() const throw() { return p; }
  344. T* operator= (T* const newP)
  345. {
  346. if (newP != 0)
  347. newP->AddRef();
  348. if (p != 0)
  349. p->Release();
  350. p = newP;
  351. return newP;
  352. }
  353. T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); }
  354. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext)
  355. {
  356. #ifndef __MINGW32__
  357. operator= (0);
  358. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p);
  359. #else
  360. return S_FALSE;
  361. #endif
  362. }
  363. T* p;
  364. };
  365. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  366. /*** End of inlined file: juce_win32_NativeIncludes.h ***/
  367. #elif JUCE_LINUX
  368. /*** Start of inlined file: juce_linux_NativeIncludes.h ***/
  369. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  370. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  371. #include <sched.h>
  372. #include <pthread.h>
  373. #include <sys/time.h>
  374. #include <errno.h>
  375. #include <sys/stat.h>
  376. #include <sys/dir.h>
  377. #include <sys/ptrace.h>
  378. #include <sys/vfs.h>
  379. #include <sys/wait.h>
  380. #include <fnmatch.h>
  381. #include <utime.h>
  382. #include <pwd.h>
  383. #include <fcntl.h>
  384. #include <dlfcn.h>
  385. #include <netdb.h>
  386. #include <arpa/inet.h>
  387. #include <netinet/in.h>
  388. #include <sys/types.h>
  389. #include <sys/ioctl.h>
  390. #include <sys/socket.h>
  391. #include <linux/if.h>
  392. #include <sys/sysinfo.h>
  393. #include <sys/file.h>
  394. #include <signal.h>
  395. #include <ft2build.h>
  396. #include FT_FREETYPE_H
  397. #include <X11/Xlib.h>
  398. #include <X11/Xatom.h>
  399. #include <X11/Xresource.h>
  400. #include <X11/Xutil.h>
  401. #include <X11/Xmd.h>
  402. #include <X11/keysym.h>
  403. #include <X11/cursorfont.h>
  404. #if JUCE_USE_XINERAMA
  405. #include <X11/extensions/Xinerama.h>
  406. #endif
  407. #if JUCE_USE_XSHM
  408. #include <X11/extensions/XShm.h>
  409. #include <sys/shm.h>
  410. #include <sys/ipc.h>
  411. #endif
  412. #if JUCE_OPENGL
  413. #include <GL/glx.h>
  414. #endif
  415. #undef KeyPress
  416. #if JUCE_ALSA
  417. #include <alsa/asoundlib.h>
  418. #endif
  419. #if JUCE_JACK
  420. #include <jack/jack.h>
  421. //#include <jack/transport.h>
  422. #endif
  423. #undef SIZEOF
  424. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  425. /*** End of inlined file: juce_linux_NativeIncludes.h ***/
  426. #elif JUCE_MAC || JUCE_IPHONE
  427. /*** Start of inlined file: juce_mac_NativeIncludes.h ***/
  428. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  429. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  430. #define USE_COREGRAPHICS_RENDERING 1
  431. #if JUCE_IPHONE
  432. #import <Foundation/Foundation.h>
  433. #import <UIKit/UIKit.h>
  434. #import <AudioToolbox/AudioToolbox.h>
  435. #import <AVFoundation/AVFoundation.h>
  436. #import <CoreData/CoreData.h>
  437. #import <MobileCoreServices/MobileCoreServices.h>
  438. #include <sys/fcntl.h>
  439. #else
  440. #import <Cocoa/Cocoa.h>
  441. #import <CoreAudio/HostTime.h>
  442. #import <CoreAudio/AudioHardware.h>
  443. #import <CoreMIDI/MIDIServices.h>
  444. #import <QTKit/QTKit.h>
  445. #import <WebKit/WebKit.h>
  446. #import <DiscRecording/DiscRecording.h>
  447. #import <IOKit/IOKitLib.h>
  448. #import <IOKit/IOCFPlugIn.h>
  449. #import <IOKit/hid/IOHIDLib.h>
  450. #import <IOKit/hid/IOHIDKeys.h>
  451. #import <IOKit/pwr_mgt/IOPMLib.h>
  452. #include <Carbon/Carbon.h>
  453. #include <sys/dir.h>
  454. #include <sys/socket.h>
  455. #endif
  456. #include <sys/sysctl.h>
  457. #include <sys/stat.h>
  458. #include <sys/param.h>
  459. #include <sys/mount.h>
  460. #include <fnmatch.h>
  461. #include <utime.h>
  462. #include <dlfcn.h>
  463. #include <ifaddrs.h>
  464. #include <net/if_dl.h>
  465. #include <mach/mach_time.h>
  466. #if MACOS_10_4_OR_EARLIER
  467. #include <GLUT/glut.h>
  468. #endif
  469. #if ! CGFLOAT_DEFINED
  470. #define CGFloat float
  471. #endif
  472. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  473. /*** End of inlined file: juce_mac_NativeIncludes.h ***/
  474. #else
  475. #error "Unknown platform!"
  476. #endif
  477. #endif
  478. //==============================================================================
  479. #define DONT_SET_USING_JUCE_NAMESPACE 1
  480. #undef max
  481. #undef min
  482. #define NO_DUMMY_DECL
  483. #if JUCE_BUILD_NATIVE
  484. #include "juce_amalgamated.h" // FORCE_AMALGAMATOR_INCLUDE
  485. #endif
  486. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  487. #pragma warning (disable: 4309 4305)
  488. #endif
  489. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  490. BEGIN_JUCE_NAMESPACE
  491. /*** Start of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  492. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  493. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  494. class CarbonViewWrapperComponent : public Component,
  495. public ComponentMovementWatcher,
  496. public Timer
  497. {
  498. public:
  499. CarbonViewWrapperComponent()
  500. : ComponentMovementWatcher (this),
  501. wrapperWindow (0),
  502. embeddedView (0),
  503. recursiveResize (false)
  504. {
  505. }
  506. virtual ~CarbonViewWrapperComponent()
  507. {
  508. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  509. }
  510. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  511. virtual void removeView (HIViewRef embeddedView) = 0;
  512. virtual void mouseDown (int x, int y) {}
  513. virtual void paint() {}
  514. virtual bool getEmbeddedViewSize (int& w, int& h)
  515. {
  516. if (embeddedView == 0)
  517. return false;
  518. HIRect bounds;
  519. HIViewGetBounds (embeddedView, &bounds);
  520. w = jmax (1, roundToInt (bounds.size.width));
  521. h = jmax (1, roundToInt (bounds.size.height));
  522. return true;
  523. }
  524. void createWindow()
  525. {
  526. if (wrapperWindow == 0)
  527. {
  528. Rect r;
  529. r.left = getScreenX();
  530. r.top = getScreenY();
  531. r.right = r.left + getWidth();
  532. r.bottom = r.top + getHeight();
  533. CreateNewWindow (kDocumentWindowClass,
  534. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  535. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  536. &r, &wrapperWindow);
  537. jassert (wrapperWindow != 0);
  538. if (wrapperWindow == 0)
  539. return;
  540. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  541. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  542. [ownerWindow addChildWindow: carbonWindow
  543. ordered: NSWindowAbove];
  544. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  545. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  546. { kEventClassWindow, kEventWindowHandleDeactivate } };
  547. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  548. InstallWindowEventHandler (wrapperWindow, upp,
  549. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  550. windowEventTypes, this, &eventHandlerRef);
  551. setOurSizeToEmbeddedViewSize();
  552. setEmbeddedWindowToOurSize();
  553. creationTime = Time::getCurrentTime();
  554. }
  555. }
  556. void deleteWindow()
  557. {
  558. removeView (embeddedView);
  559. embeddedView = 0;
  560. if (wrapperWindow != 0)
  561. {
  562. RemoveEventHandler (eventHandlerRef);
  563. DisposeWindow (wrapperWindow);
  564. wrapperWindow = 0;
  565. }
  566. }
  567. void setOurSizeToEmbeddedViewSize()
  568. {
  569. int w, h;
  570. if (getEmbeddedViewSize (w, h))
  571. {
  572. if (w != getWidth() || h != getHeight())
  573. {
  574. startTimer (50);
  575. setSize (w, h);
  576. if (getParentComponent() != 0)
  577. getParentComponent()->setSize (w, h);
  578. }
  579. else
  580. {
  581. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  582. }
  583. }
  584. else
  585. {
  586. stopTimer();
  587. }
  588. }
  589. void setEmbeddedWindowToOurSize()
  590. {
  591. if (! recursiveResize)
  592. {
  593. recursiveResize = true;
  594. if (embeddedView != 0)
  595. {
  596. HIRect r;
  597. r.origin.x = 0;
  598. r.origin.y = 0;
  599. r.size.width = (float) getWidth();
  600. r.size.height = (float) getHeight();
  601. HIViewSetFrame (embeddedView, &r);
  602. }
  603. if (wrapperWindow != 0)
  604. {
  605. Rect wr;
  606. wr.left = getScreenX();
  607. wr.top = getScreenY();
  608. wr.right = wr.left + getWidth();
  609. wr.bottom = wr.top + getHeight();
  610. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  611. ShowWindow (wrapperWindow);
  612. }
  613. recursiveResize = false;
  614. }
  615. }
  616. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  617. {
  618. setEmbeddedWindowToOurSize();
  619. }
  620. void componentPeerChanged()
  621. {
  622. deleteWindow();
  623. createWindow();
  624. }
  625. void componentVisibilityChanged (Component&)
  626. {
  627. if (isShowing())
  628. createWindow();
  629. else
  630. deleteWindow();
  631. setEmbeddedWindowToOurSize();
  632. }
  633. static void recursiveHIViewRepaint (HIViewRef view)
  634. {
  635. HIViewSetNeedsDisplay (view, true);
  636. HIViewRef child = HIViewGetFirstSubview (view);
  637. while (child != 0)
  638. {
  639. recursiveHIViewRepaint (child);
  640. child = HIViewGetNextView (child);
  641. }
  642. }
  643. void timerCallback()
  644. {
  645. setOurSizeToEmbeddedViewSize();
  646. // To avoid strange overpainting problems when the UI is first opened, we'll
  647. // repaint it a few times during the first second that it's on-screen..
  648. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  649. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  650. }
  651. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  652. EventRef event)
  653. {
  654. switch (GetEventKind (event))
  655. {
  656. case kEventWindowHandleDeactivate:
  657. ActivateWindow (wrapperWindow, TRUE);
  658. break;
  659. case kEventWindowGetClickActivation:
  660. {
  661. getTopLevelComponent()->toFront (false);
  662. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  663. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  664. sizeof (ClickActivationResult), &howToHandleClick);
  665. HIViewSetNeedsDisplay (embeddedView, true);
  666. }
  667. break;
  668. }
  669. return noErr;
  670. }
  671. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  672. EventRef event, void* userData)
  673. {
  674. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  675. }
  676. protected:
  677. WindowRef wrapperWindow;
  678. HIViewRef embeddedView;
  679. bool recursiveResize;
  680. Time creationTime;
  681. EventHandlerRef eventHandlerRef;
  682. };
  683. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  684. /*** End of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  685. END_JUCE_NAMESPACE
  686. #endif
  687. #define JUCE_AMALGAMATED_TEMPLATE 1
  688. //==============================================================================
  689. #if JUCE_BUILD_CORE
  690. /*** Start of inlined file: juce_FileLogger.cpp ***/
  691. BEGIN_JUCE_NAMESPACE
  692. FileLogger::FileLogger (const File& logFile_,
  693. const String& welcomeMessage,
  694. const int maxInitialFileSizeBytes)
  695. : logFile (logFile_)
  696. {
  697. if (maxInitialFileSizeBytes >= 0)
  698. trimFileSize (maxInitialFileSizeBytes);
  699. if (! logFile_.exists())
  700. {
  701. // do this so that the parent directories get created..
  702. logFile_.create();
  703. }
  704. logStream = logFile_.createOutputStream (256);
  705. jassert (logStream != 0);
  706. String welcome;
  707. welcome << "\r\n**********************************************************\r\n"
  708. << welcomeMessage
  709. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  710. << "\r\n";
  711. logMessage (welcome);
  712. }
  713. FileLogger::~FileLogger()
  714. {
  715. }
  716. void FileLogger::logMessage (const String& message)
  717. {
  718. if (logStream != 0)
  719. {
  720. DBG (message);
  721. const ScopedLock sl (logLock);
  722. (*logStream) << message << T("\r\n");
  723. logStream->flush();
  724. }
  725. }
  726. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  727. {
  728. if (maxFileSizeBytes <= 0)
  729. {
  730. logFile.deleteFile();
  731. }
  732. else
  733. {
  734. const int64 fileSize = logFile.getSize();
  735. if (fileSize > maxFileSizeBytes)
  736. {
  737. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  738. jassert (in != 0);
  739. if (in != 0)
  740. {
  741. in->setPosition (fileSize - maxFileSizeBytes);
  742. String content;
  743. {
  744. MemoryBlock contentToSave;
  745. contentToSave.setSize (maxFileSizeBytes + 4);
  746. contentToSave.fillWith (0);
  747. in->read (contentToSave.getData(), maxFileSizeBytes);
  748. in = 0;
  749. content = contentToSave.toString();
  750. }
  751. int newStart = 0;
  752. while (newStart < fileSize
  753. && content[newStart] != '\n'
  754. && content[newStart] != '\r')
  755. ++newStart;
  756. logFile.deleteFile();
  757. logFile.appendText (content.substring (newStart), false, false);
  758. }
  759. }
  760. }
  761. }
  762. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  763. const String& logFileName,
  764. const String& welcomeMessage,
  765. const int maxInitialFileSizeBytes)
  766. {
  767. #if JUCE_MAC
  768. File logFile ("~/Library/Logs");
  769. logFile = logFile.getChildFile (logFileSubDirectoryName)
  770. .getChildFile (logFileName);
  771. #else
  772. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  773. if (logFile.isDirectory())
  774. {
  775. logFile = logFile.getChildFile (logFileSubDirectoryName)
  776. .getChildFile (logFileName);
  777. }
  778. #endif
  779. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  780. }
  781. END_JUCE_NAMESPACE
  782. /*** End of inlined file: juce_FileLogger.cpp ***/
  783. /*** Start of inlined file: juce_Logger.cpp ***/
  784. BEGIN_JUCE_NAMESPACE
  785. Logger::Logger()
  786. {
  787. }
  788. Logger::~Logger()
  789. {
  790. }
  791. static Logger* currentLogger = 0;
  792. void Logger::setCurrentLogger (Logger* const newLogger,
  793. const bool deleteOldLogger)
  794. {
  795. Logger* const oldLogger = currentLogger;
  796. currentLogger = newLogger;
  797. if (deleteOldLogger)
  798. delete oldLogger;
  799. }
  800. void Logger::writeToLog (const String& message)
  801. {
  802. if (currentLogger != 0)
  803. currentLogger->logMessage (message);
  804. else
  805. outputDebugString (message);
  806. }
  807. #if JUCE_LOG_ASSERTIONS
  808. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  809. {
  810. String m ("JUCE Assertion failure in ");
  811. m << filename << ", line " << lineNum;
  812. Logger::writeToLog (m);
  813. }
  814. #endif
  815. END_JUCE_NAMESPACE
  816. /*** End of inlined file: juce_Logger.cpp ***/
  817. /*** Start of inlined file: juce_Random.cpp ***/
  818. BEGIN_JUCE_NAMESPACE
  819. Random::Random (const int64 seedValue) throw()
  820. : seed (seedValue)
  821. {
  822. }
  823. Random::~Random() throw()
  824. {
  825. }
  826. void Random::setSeed (const int64 newSeed) throw()
  827. {
  828. seed = newSeed;
  829. }
  830. void Random::combineSeed (const int64 seedValue) throw()
  831. {
  832. seed ^= nextInt64() ^ seedValue;
  833. }
  834. void Random::setSeedRandomly()
  835. {
  836. combineSeed ((int64) (pointer_sized_int) this);
  837. combineSeed (Time::getMillisecondCounter());
  838. combineSeed (Time::getHighResolutionTicks());
  839. combineSeed (Time::getHighResolutionTicksPerSecond());
  840. combineSeed (Time::currentTimeMillis());
  841. }
  842. int Random::nextInt() throw()
  843. {
  844. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  845. return (int) (seed >> 16);
  846. }
  847. int Random::nextInt (const int maxValue) throw()
  848. {
  849. jassert (maxValue > 0);
  850. return (nextInt() & 0x7fffffff) % maxValue;
  851. }
  852. int64 Random::nextInt64() throw()
  853. {
  854. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  855. }
  856. bool Random::nextBool() throw()
  857. {
  858. return (nextInt() & 0x80000000) != 0;
  859. }
  860. float Random::nextFloat() throw()
  861. {
  862. return ((uint32) nextInt()) / (float) 0xffffffff;
  863. }
  864. double Random::nextDouble() throw()
  865. {
  866. return ((uint32) nextInt()) / (double) 0xffffffff;
  867. }
  868. const BitArray Random::nextLargeNumber (const BitArray& maximumValue) throw()
  869. {
  870. BitArray n;
  871. do
  872. {
  873. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  874. }
  875. while (n.compare (maximumValue) >= 0);
  876. return n;
  877. }
  878. void Random::fillBitsRandomly (BitArray& arrayToChange, int startBit, int numBits) throw()
  879. {
  880. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  881. while ((startBit & 31) != 0 && numBits > 0)
  882. {
  883. arrayToChange.setBit (startBit++, nextBool());
  884. --numBits;
  885. }
  886. while (numBits >= 32)
  887. {
  888. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  889. startBit += 32;
  890. numBits -= 32;
  891. }
  892. while (--numBits >= 0)
  893. arrayToChange.setBit (startBit + numBits, nextBool());
  894. }
  895. Random& Random::getSystemRandom() throw()
  896. {
  897. static Random sysRand (1);
  898. return sysRand;
  899. }
  900. END_JUCE_NAMESPACE
  901. /*** End of inlined file: juce_Random.cpp ***/
  902. /*** Start of inlined file: juce_RelativeTime.cpp ***/
  903. BEGIN_JUCE_NAMESPACE
  904. RelativeTime::RelativeTime (const double seconds_) throw()
  905. : seconds (seconds_)
  906. {
  907. }
  908. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  909. : seconds (other.seconds)
  910. {
  911. }
  912. RelativeTime::~RelativeTime() throw()
  913. {
  914. }
  915. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  916. {
  917. return RelativeTime (milliseconds * 0.001);
  918. }
  919. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  920. {
  921. return RelativeTime (milliseconds * 0.001);
  922. }
  923. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  924. {
  925. return RelativeTime (numberOfMinutes * 60.0);
  926. }
  927. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  928. {
  929. return RelativeTime (numberOfHours * (60.0 * 60.0));
  930. }
  931. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  932. {
  933. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  934. }
  935. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  936. {
  937. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  938. }
  939. int64 RelativeTime::inMilliseconds() const throw()
  940. {
  941. return (int64)(seconds * 1000.0);
  942. }
  943. double RelativeTime::inMinutes() const throw()
  944. {
  945. return seconds / 60.0;
  946. }
  947. double RelativeTime::inHours() const throw()
  948. {
  949. return seconds / (60.0 * 60.0);
  950. }
  951. double RelativeTime::inDays() const throw()
  952. {
  953. return seconds / (60.0 * 60.0 * 24.0);
  954. }
  955. double RelativeTime::inWeeks() const throw()
  956. {
  957. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  958. }
  959. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  960. {
  961. if (seconds < 0.001 && seconds > -0.001)
  962. return returnValueForZeroTime;
  963. String result;
  964. if (seconds < 0)
  965. result = T("-");
  966. int fieldsShown = 0;
  967. int n = abs ((int) inWeeks());
  968. if (n > 0)
  969. {
  970. result << n << ((n == 1) ? TRANS(" week ")
  971. : TRANS(" weeks "));
  972. ++fieldsShown;
  973. }
  974. n = abs ((int) inDays()) % 7;
  975. if (n > 0)
  976. {
  977. result << n << ((n == 1) ? TRANS(" day ")
  978. : TRANS(" days "));
  979. ++fieldsShown;
  980. }
  981. if (fieldsShown < 2)
  982. {
  983. n = abs ((int) inHours()) % 24;
  984. if (n > 0)
  985. {
  986. result << n << ((n == 1) ? TRANS(" hr ")
  987. : TRANS(" hrs "));
  988. ++fieldsShown;
  989. }
  990. if (fieldsShown < 2)
  991. {
  992. n = abs ((int) inMinutes()) % 60;
  993. if (n > 0)
  994. {
  995. result << n << ((n == 1) ? TRANS(" min ")
  996. : TRANS(" mins "));
  997. ++fieldsShown;
  998. }
  999. if (fieldsShown < 2)
  1000. {
  1001. n = abs ((int) inSeconds()) % 60;
  1002. if (n > 0)
  1003. {
  1004. result << n << ((n == 1) ? TRANS(" sec ")
  1005. : TRANS(" secs "));
  1006. ++fieldsShown;
  1007. }
  1008. if (fieldsShown < 1)
  1009. {
  1010. n = abs ((int) inMilliseconds()) % 1000;
  1011. if (n > 0)
  1012. {
  1013. result << n << TRANS(" ms");
  1014. ++fieldsShown;
  1015. }
  1016. }
  1017. }
  1018. }
  1019. }
  1020. return result.trimEnd();
  1021. }
  1022. const RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  1023. {
  1024. seconds = other.seconds;
  1025. return *this;
  1026. }
  1027. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  1028. {
  1029. return seconds == other.seconds;
  1030. }
  1031. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  1032. {
  1033. return seconds != other.seconds;
  1034. }
  1035. bool RelativeTime::operator> (const RelativeTime& other) const throw()
  1036. {
  1037. return seconds > other.seconds;
  1038. }
  1039. bool RelativeTime::operator< (const RelativeTime& other) const throw()
  1040. {
  1041. return seconds < other.seconds;
  1042. }
  1043. bool RelativeTime::operator>= (const RelativeTime& other) const throw()
  1044. {
  1045. return seconds >= other.seconds;
  1046. }
  1047. bool RelativeTime::operator<= (const RelativeTime& other) const throw()
  1048. {
  1049. return seconds <= other.seconds;
  1050. }
  1051. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1052. {
  1053. return RelativeTime (seconds + timeToAdd.seconds);
  1054. }
  1055. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1056. {
  1057. return RelativeTime (seconds - timeToSubtract.seconds);
  1058. }
  1059. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1060. {
  1061. return RelativeTime (seconds + secondsToAdd);
  1062. }
  1063. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1064. {
  1065. return RelativeTime (seconds - secondsToSubtract);
  1066. }
  1067. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1068. {
  1069. seconds += timeToAdd.seconds;
  1070. return *this;
  1071. }
  1072. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1073. {
  1074. seconds -= timeToSubtract.seconds;
  1075. return *this;
  1076. }
  1077. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1078. {
  1079. seconds += secondsToAdd;
  1080. return *this;
  1081. }
  1082. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1083. {
  1084. seconds -= secondsToSubtract;
  1085. return *this;
  1086. }
  1087. END_JUCE_NAMESPACE
  1088. /*** End of inlined file: juce_RelativeTime.cpp ***/
  1089. /*** Start of inlined file: juce_SystemStats.cpp ***/
  1090. BEGIN_JUCE_NAMESPACE
  1091. void juce_initialiseStrings();
  1092. const String SystemStats::getJUCEVersion() throw()
  1093. {
  1094. return "JUCE v" + String (JUCE_MAJOR_VERSION) + "." + String (JUCE_MINOR_VERSION);
  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. const 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. const 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::operator== (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 var::operator!= (const var& other) const throw()
  2984. {
  2985. return ! operator== (other);
  2986. }
  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->copyToUTF8 (0);
  2998. output.writeCompressedInt (len + 1);
  2999. output.writeByte (5);
  3000. HeapBlock <uint8> temp (len);
  3001. value.stringValue->copyToUTF8 (temp);
  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 uint8*) 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. const 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. zeromem (result, sizeof (result));
  3637. }
  3638. MD5::MD5 (const MD5& other)
  3639. {
  3640. memcpy (result, other.result, sizeof (result));
  3641. }
  3642. const 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. zeromem (result, sizeof (result));
  3702. }
  3703. MD5::~MD5()
  3704. {
  3705. }
  3706. MD5::ProcessContext::ProcessContext()
  3707. {
  3708. state[0] = 0x67452301;
  3709. state[1] = 0xefcdab89;
  3710. state[2] = 0x98badcfe;
  3711. state[3] = 0x10325476;
  3712. count[0] = 0;
  3713. count[1] = 0;
  3714. }
  3715. void MD5::ProcessContext::processBlock (const uint8* const data, size_t dataSize)
  3716. {
  3717. int bufferPos = ((count[0] >> 3) & 0x3F);
  3718. count[0] += (uint32) (dataSize << 3);
  3719. if (count[0] < ((uint32) dataSize << 3))
  3720. count[1]++;
  3721. count[1] += (uint32) (dataSize >> 29);
  3722. const size_t spaceLeft = 64 - bufferPos;
  3723. size_t i = 0;
  3724. if (dataSize >= spaceLeft)
  3725. {
  3726. memcpy (buffer + bufferPos, data, spaceLeft);
  3727. transform (buffer);
  3728. i = spaceLeft;
  3729. while (i + 64 <= dataSize)
  3730. {
  3731. transform (data + i);
  3732. i += 64;
  3733. }
  3734. bufferPos = 0;
  3735. }
  3736. memcpy (buffer + bufferPos, data + i, dataSize - i);
  3737. }
  3738. static void encode (uint8* const output,
  3739. const uint32* const input,
  3740. const int numBytes)
  3741. {
  3742. uint32* const o = (uint32*) output;
  3743. for (int i = 0; i < (numBytes >> 2); ++i)
  3744. o[i] = ByteOrder::swapIfBigEndian (input [i]);
  3745. }
  3746. static void decode (uint32* const output,
  3747. const uint8* const input,
  3748. const int numBytes)
  3749. {
  3750. for (int i = 0; i < (numBytes >> 2); ++i)
  3751. output[i] = ByteOrder::littleEndianInt ((const char*) input + (i << 2));
  3752. }
  3753. void MD5::ProcessContext::finish (uint8* const result)
  3754. {
  3755. unsigned char encodedLength[8];
  3756. encode (encodedLength, count, 8);
  3757. // Pad out to 56 mod 64.
  3758. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3759. const int paddingLength = (index < 56) ? (56 - index)
  3760. : (120 - index);
  3761. uint8 paddingBuffer [64];
  3762. zeromem (paddingBuffer, paddingLength);
  3763. paddingBuffer [0] = 0x80;
  3764. processBlock (paddingBuffer, paddingLength);
  3765. processBlock (encodedLength, 8);
  3766. encode (result, state, 16);
  3767. zeromem (buffer, sizeof (buffer));
  3768. }
  3769. #define S11 7
  3770. #define S12 12
  3771. #define S13 17
  3772. #define S14 22
  3773. #define S21 5
  3774. #define S22 9
  3775. #define S23 14
  3776. #define S24 20
  3777. #define S31 4
  3778. #define S32 11
  3779. #define S33 16
  3780. #define S34 23
  3781. #define S41 6
  3782. #define S42 10
  3783. #define S43 15
  3784. #define S44 21
  3785. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) { return (x & y) | (~x & z); }
  3786. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) { return (x & z) | (y & ~z); }
  3787. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) { return x ^ y ^ z; }
  3788. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) { return y ^ (x | ~z); }
  3789. static inline uint32 rotateLeft (const uint32 x, const uint32 n) { return (x << n) | (x >> (32 - n)); }
  3790. static inline void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3791. {
  3792. a += F (b, c, d) + x + ac;
  3793. a = rotateLeft (a, s) + b;
  3794. }
  3795. static inline void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3796. {
  3797. a += G (b, c, d) + x + ac;
  3798. a = rotateLeft (a, s) + b;
  3799. }
  3800. static inline void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3801. {
  3802. a += H (b, c, d) + x + ac;
  3803. a = rotateLeft (a, s) + b;
  3804. }
  3805. static inline void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3806. {
  3807. a += I (b, c, d) + x + ac;
  3808. a = rotateLeft (a, s) + b;
  3809. }
  3810. void MD5::ProcessContext::transform (const uint8* const bufferToTransform)
  3811. {
  3812. uint32 a = state[0];
  3813. uint32 b = state[1];
  3814. uint32 c = state[2];
  3815. uint32 d = state[3];
  3816. uint32 x[16];
  3817. decode (x, bufferToTransform, 64);
  3818. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  3819. FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  3820. FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  3821. FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  3822. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  3823. FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  3824. FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  3825. FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  3826. FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  3827. FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  3828. FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  3829. FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  3830. FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  3831. FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  3832. FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  3833. FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  3834. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  3835. GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  3836. GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  3837. GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  3838. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  3839. GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
  3840. GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  3841. GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  3842. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  3843. GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  3844. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  3845. GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  3846. GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  3847. GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  3848. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  3849. GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  3850. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  3851. HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  3852. HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  3853. HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  3854. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  3855. HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  3856. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  3857. HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  3858. HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  3859. HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  3860. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  3861. HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
  3862. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  3863. HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  3864. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  3865. HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  3866. II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  3867. II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  3868. II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  3869. II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  3870. II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  3871. II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  3872. II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  3873. II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  3874. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  3875. II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  3876. II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  3877. II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  3878. II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  3879. II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  3880. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  3881. II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  3882. state[0] += a;
  3883. state[1] += b;
  3884. state[2] += c;
  3885. state[3] += d;
  3886. zeromem (x, sizeof (x));
  3887. }
  3888. const MemoryBlock MD5::getRawChecksumData() const
  3889. {
  3890. return MemoryBlock (result, 16);
  3891. }
  3892. const String MD5::toHexString() const
  3893. {
  3894. return String::toHexString (result, 16, 0);
  3895. }
  3896. bool MD5::operator== (const MD5& other) const
  3897. {
  3898. return memcmp (result, other.result, 16) == 0;
  3899. }
  3900. bool MD5::operator!= (const MD5& other) const
  3901. {
  3902. return ! operator== (other);
  3903. }
  3904. END_JUCE_NAMESPACE
  3905. /*** End of inlined file: juce_MD5.cpp ***/
  3906. /*** Start of inlined file: juce_Primes.cpp ***/
  3907. BEGIN_JUCE_NAMESPACE
  3908. static void createSmallSieve (const int numBits, BitArray& result) throw()
  3909. {
  3910. result.setBit (numBits);
  3911. result.clearBit (numBits); // to enlarge the array
  3912. result.setBit (0);
  3913. int n = 2;
  3914. do
  3915. {
  3916. for (int i = n + n; i < numBits; i += n)
  3917. result.setBit (i);
  3918. n = result.findNextClearBit (n + 1);
  3919. }
  3920. while (n <= (numBits >> 1));
  3921. }
  3922. static void bigSieve (const BitArray& base,
  3923. const int numBits,
  3924. BitArray& result,
  3925. const BitArray& smallSieve,
  3926. const int smallSieveSize) throw()
  3927. {
  3928. jassert (! base[0]); // must be even!
  3929. result.setBit (numBits);
  3930. result.clearBit (numBits); // to enlarge the array
  3931. int index = smallSieve.findNextClearBit (0);
  3932. do
  3933. {
  3934. const int prime = (index << 1) + 1;
  3935. BitArray r (base);
  3936. BitArray remainder;
  3937. r.divideBy (prime, remainder);
  3938. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3939. if (r.isEmpty())
  3940. i += prime;
  3941. if ((i & 1) == 0)
  3942. i += prime;
  3943. i = (i - 1) >> 1;
  3944. while (i < numBits)
  3945. {
  3946. result.setBit (i);
  3947. i += prime;
  3948. }
  3949. index = smallSieve.findNextClearBit (index + 1);
  3950. }
  3951. while (index < smallSieveSize);
  3952. }
  3953. static bool findCandidate (const BitArray& base,
  3954. const BitArray& sieve,
  3955. const int numBits,
  3956. BitArray& result,
  3957. const int certainty) throw()
  3958. {
  3959. for (int i = 0; i < numBits; ++i)
  3960. {
  3961. if (! sieve[i])
  3962. {
  3963. result = base;
  3964. result.add (BitArray ((unsigned int) ((i << 1) + 1)));
  3965. if (Primes::isProbablyPrime (result, certainty))
  3966. return true;
  3967. }
  3968. }
  3969. return false;
  3970. }
  3971. const BitArray Primes::createProbablePrime (const int bitLength,
  3972. const int certainty,
  3973. const int* randomSeeds,
  3974. int numRandomSeeds) throw()
  3975. {
  3976. int defaultSeeds [16];
  3977. if (numRandomSeeds <= 0)
  3978. {
  3979. randomSeeds = defaultSeeds;
  3980. numRandomSeeds = numElementsInArray (defaultSeeds);
  3981. Random r (0);
  3982. for (int j = 10; --j >= 0;)
  3983. {
  3984. r.setSeedRandomly();
  3985. for (int i = numRandomSeeds; --i >= 0;)
  3986. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3987. }
  3988. }
  3989. BitArray smallSieve;
  3990. const int smallSieveSize = 15000;
  3991. createSmallSieve (smallSieveSize, smallSieve);
  3992. BitArray p;
  3993. for (int i = numRandomSeeds; --i >= 0;)
  3994. {
  3995. BitArray p2;
  3996. Random r (randomSeeds[i]);
  3997. r.fillBitsRandomly (p2, 0, bitLength);
  3998. p.xorWith (p2);
  3999. }
  4000. p.setBit (bitLength - 1);
  4001. p.clearBit (0);
  4002. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  4003. while (p.getHighestBit() < bitLength)
  4004. {
  4005. p.add (2 * searchLen);
  4006. BitArray sieve;
  4007. bigSieve (p, searchLen, sieve,
  4008. smallSieve, smallSieveSize);
  4009. BitArray candidate;
  4010. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  4011. return candidate;
  4012. }
  4013. jassertfalse
  4014. return BitArray();
  4015. }
  4016. static bool passesMillerRabin (const BitArray& n, int iterations) throw()
  4017. {
  4018. const BitArray one (1);
  4019. const BitArray two (2);
  4020. BitArray nMinusOne (n);
  4021. nMinusOne.subtract (one);
  4022. BitArray d (nMinusOne);
  4023. const int s = d.findNextSetBit (0);
  4024. d.shiftBits (-s);
  4025. BitArray smallPrimes;
  4026. int numBitsInSmallPrimes = 0;
  4027. for (;;)
  4028. {
  4029. numBitsInSmallPrimes += 256;
  4030. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  4031. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  4032. if (numPrimesFound > iterations + 1)
  4033. break;
  4034. }
  4035. int smallPrime = 2;
  4036. while (--iterations >= 0)
  4037. {
  4038. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  4039. BitArray r (smallPrime);
  4040. //r.createRandomNumber (nMinusOne);
  4041. r.exponentModulo (d, n);
  4042. if (! (r == one || r == nMinusOne))
  4043. {
  4044. for (int j = 0; j < s; ++j)
  4045. {
  4046. r.exponentModulo (two, n);
  4047. if (r == nMinusOne)
  4048. break;
  4049. }
  4050. if (r != nMinusOne)
  4051. return false;
  4052. }
  4053. }
  4054. return true;
  4055. }
  4056. bool Primes::isProbablyPrime (const BitArray& number,
  4057. const int certainty) throw()
  4058. {
  4059. if (! number[0])
  4060. return false;
  4061. if (number.getHighestBit() <= 10)
  4062. {
  4063. const int num = number.getBitRangeAsInt (0, 10);
  4064. for (int i = num / 2; --i > 1;)
  4065. if (num % i == 0)
  4066. return false;
  4067. return true;
  4068. }
  4069. else
  4070. {
  4071. const BitArray screen (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23);
  4072. if (number.findGreatestCommonDivisor (screen) != BitArray (1))
  4073. return false;
  4074. return passesMillerRabin (number, certainty);
  4075. }
  4076. }
  4077. END_JUCE_NAMESPACE
  4078. /*** End of inlined file: juce_Primes.cpp ***/
  4079. /*** Start of inlined file: juce_RSAKey.cpp ***/
  4080. BEGIN_JUCE_NAMESPACE
  4081. RSAKey::RSAKey() throw()
  4082. {
  4083. }
  4084. RSAKey::RSAKey (const String& s) throw()
  4085. {
  4086. if (s.containsChar (T(',')))
  4087. {
  4088. part1.parseString (s.upToFirstOccurrenceOf (T(","), false, false), 16);
  4089. part2.parseString (s.fromFirstOccurrenceOf (T(","), false, false), 16);
  4090. }
  4091. else
  4092. {
  4093. // the string needs to be two hex numbers, comma-separated..
  4094. jassertfalse;
  4095. }
  4096. }
  4097. RSAKey::~RSAKey() throw()
  4098. {
  4099. }
  4100. const String RSAKey::toString() const throw()
  4101. {
  4102. return part1.toString (16) + T(",") + part2.toString (16);
  4103. }
  4104. bool RSAKey::applyToValue (BitArray& value) const throw()
  4105. {
  4106. if (part1.isEmpty() || part2.isEmpty()
  4107. || value.compare (0) <= 0)
  4108. {
  4109. jassertfalse // using an uninitialised key
  4110. value.clear();
  4111. return false;
  4112. }
  4113. BitArray result;
  4114. while (! value.isEmpty())
  4115. {
  4116. result.multiplyBy (part2);
  4117. BitArray remainder;
  4118. value.divideBy (part2, remainder);
  4119. remainder.exponentModulo (part1, part2);
  4120. result.add (remainder);
  4121. }
  4122. value = result;
  4123. return true;
  4124. }
  4125. static const BitArray findBestCommonDivisor (const BitArray& p,
  4126. const BitArray& q) throw()
  4127. {
  4128. const BitArray one (1);
  4129. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  4130. // are fast to divide + multiply
  4131. for (int i = 2; i <= 65536; i *= 2)
  4132. {
  4133. const BitArray e (1 + i);
  4134. if (e.findGreatestCommonDivisor (p) == one
  4135. && e.findGreatestCommonDivisor (q) == one)
  4136. {
  4137. return e;
  4138. }
  4139. }
  4140. BitArray e (4);
  4141. while (! (e.findGreatestCommonDivisor (p) == one
  4142. && e.findGreatestCommonDivisor (q) == one))
  4143. {
  4144. e.add (one);
  4145. }
  4146. return e;
  4147. }
  4148. void RSAKey::createKeyPair (RSAKey& publicKey,
  4149. RSAKey& privateKey,
  4150. const int numBits,
  4151. const int* randomSeeds,
  4152. const int numRandomSeeds) throw()
  4153. {
  4154. jassert (numBits > 16); // not much point using less than this..
  4155. BitArray p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  4156. BitArray q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  4157. BitArray n (p);
  4158. n.multiplyBy (q); // n = pq
  4159. const BitArray one (1);
  4160. p.subtract (one);
  4161. q.subtract (one);
  4162. BitArray m (p);
  4163. m.multiplyBy (q); // m = (p - 1)(q - 1)
  4164. const BitArray e (findBestCommonDivisor (p, q));
  4165. BitArray d (e);
  4166. d.inverseModulo (m);
  4167. publicKey.part1 = e;
  4168. publicKey.part2 = n;
  4169. privateKey.part1 = d;
  4170. privateKey.part2 = n;
  4171. }
  4172. END_JUCE_NAMESPACE
  4173. /*** End of inlined file: juce_RSAKey.cpp ***/
  4174. /*** Start of inlined file: juce_InputStream.cpp ***/
  4175. BEGIN_JUCE_NAMESPACE
  4176. char InputStream::readByte()
  4177. {
  4178. char temp = 0;
  4179. read (&temp, 1);
  4180. return temp;
  4181. }
  4182. bool InputStream::readBool()
  4183. {
  4184. return readByte() != 0;
  4185. }
  4186. short InputStream::readShort()
  4187. {
  4188. char temp [2];
  4189. if (read (temp, 2) == 2)
  4190. return (short) ByteOrder::littleEndianShort (temp);
  4191. else
  4192. return 0;
  4193. }
  4194. short InputStream::readShortBigEndian()
  4195. {
  4196. char temp [2];
  4197. if (read (temp, 2) == 2)
  4198. return (short) ByteOrder::bigEndianShort (temp);
  4199. else
  4200. return 0;
  4201. }
  4202. int InputStream::readInt()
  4203. {
  4204. char temp [4];
  4205. if (read (temp, 4) == 4)
  4206. return (int) ByteOrder::littleEndianInt (temp);
  4207. else
  4208. return 0;
  4209. }
  4210. int InputStream::readIntBigEndian()
  4211. {
  4212. char temp [4];
  4213. if (read (temp, 4) == 4)
  4214. return (int) ByteOrder::bigEndianInt (temp);
  4215. else
  4216. return 0;
  4217. }
  4218. int InputStream::readCompressedInt()
  4219. {
  4220. const unsigned char sizeByte = readByte();
  4221. if (sizeByte == 0)
  4222. return 0;
  4223. const int numBytes = (sizeByte & 0x7f);
  4224. if (numBytes > 4)
  4225. {
  4226. jassertfalse // trying to read corrupt data - this method must only be used
  4227. // to read data that was written by OutputStream::writeCompressedInt()
  4228. return 0;
  4229. }
  4230. char bytes[4] = { 0, 0, 0, 0 };
  4231. if (read (bytes, numBytes) != numBytes)
  4232. return 0;
  4233. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4234. return (sizeByte >> 7) ? -num : num;
  4235. }
  4236. int64 InputStream::readInt64()
  4237. {
  4238. char temp [8];
  4239. if (read (temp, 8) == 8)
  4240. return (int64) ByteOrder::swapIfBigEndian (*(uint64*) temp);
  4241. else
  4242. return 0;
  4243. }
  4244. int64 InputStream::readInt64BigEndian()
  4245. {
  4246. char temp [8];
  4247. if (read (temp, 8) == 8)
  4248. return (int64) ByteOrder::swapIfLittleEndian (*(uint64*) temp);
  4249. else
  4250. return 0;
  4251. }
  4252. float InputStream::readFloat()
  4253. {
  4254. union { int asInt; float asFloat; } n;
  4255. n.asInt = readInt();
  4256. return n.asFloat;
  4257. }
  4258. float InputStream::readFloatBigEndian()
  4259. {
  4260. union { int asInt; float asFloat; } n;
  4261. n.asInt = readIntBigEndian();
  4262. return n.asFloat;
  4263. }
  4264. double InputStream::readDouble()
  4265. {
  4266. union { int64 asInt; double asDouble; } n;
  4267. n.asInt = readInt64();
  4268. return n.asDouble;
  4269. }
  4270. double InputStream::readDoubleBigEndian()
  4271. {
  4272. union { int64 asInt; double asDouble; } n;
  4273. n.asInt = readInt64BigEndian();
  4274. return n.asDouble;
  4275. }
  4276. const String InputStream::readString()
  4277. {
  4278. MemoryBlock buffer (256);
  4279. uint8* data = (uint8*) buffer.getData();
  4280. size_t i = 0;
  4281. while ((data[i] = readByte()) != 0)
  4282. {
  4283. if (++i >= buffer.getSize())
  4284. {
  4285. buffer.setSize (buffer.getSize() + 512);
  4286. data = (uint8*) buffer.getData();
  4287. }
  4288. }
  4289. return String::fromUTF8 (data, (int) i);
  4290. }
  4291. const String InputStream::readNextLine()
  4292. {
  4293. MemoryBlock buffer (256);
  4294. uint8* data = (uint8*) buffer.getData();
  4295. size_t i = 0;
  4296. while ((data[i] = readByte()) != 0)
  4297. {
  4298. if (data[i] == '\n')
  4299. break;
  4300. if (data[i] == '\r')
  4301. {
  4302. const int64 lastPos = getPosition();
  4303. if (readByte() != '\n')
  4304. setPosition (lastPos);
  4305. break;
  4306. }
  4307. if (++i >= buffer.getSize())
  4308. {
  4309. buffer.setSize (buffer.getSize() + 512);
  4310. data = (uint8*) buffer.getData();
  4311. }
  4312. }
  4313. return String::fromUTF8 (data, (int) i);
  4314. }
  4315. int InputStream::readIntoMemoryBlock (MemoryBlock& block,
  4316. int numBytes)
  4317. {
  4318. const int64 totalLength = getTotalLength();
  4319. if (totalLength >= 0)
  4320. {
  4321. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4322. totalLength - getPosition());
  4323. if (numBytes < 0)
  4324. numBytes = totalBytesRemaining;
  4325. else if (numBytes > 0)
  4326. numBytes = jmin (numBytes, totalBytesRemaining);
  4327. else
  4328. return 0;
  4329. }
  4330. const size_t originalBlockSize = block.getSize();
  4331. int totalBytesRead = 0;
  4332. if (numBytes > 0)
  4333. {
  4334. // know how many bytes we want, so we can resize the block first..
  4335. block.setSize (originalBlockSize + numBytes, false);
  4336. totalBytesRead = read (((char*) block.getData()) + originalBlockSize, numBytes);
  4337. }
  4338. else
  4339. {
  4340. // read until end of stram..
  4341. const int chunkSize = 32768;
  4342. for (;;)
  4343. {
  4344. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4345. const int bytesJustIn = read (((char*) block.getData())
  4346. + originalBlockSize
  4347. + totalBytesRead,
  4348. chunkSize);
  4349. if (bytesJustIn == 0)
  4350. break;
  4351. totalBytesRead += bytesJustIn;
  4352. }
  4353. }
  4354. // trim off any excess left at the end
  4355. block.setSize (originalBlockSize + totalBytesRead, false);
  4356. return totalBytesRead;
  4357. }
  4358. const String InputStream::readEntireStreamAsString()
  4359. {
  4360. MemoryBlock mb;
  4361. const int size = readIntoMemoryBlock (mb);
  4362. return String::createStringFromData ((const char*) mb.getData(), size);
  4363. }
  4364. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4365. {
  4366. if (numBytesToSkip > 0)
  4367. {
  4368. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4369. HeapBlock <char> temp (skipBufferSize);
  4370. while (numBytesToSkip > 0 && ! isExhausted())
  4371. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4372. }
  4373. }
  4374. END_JUCE_NAMESPACE
  4375. /*** End of inlined file: juce_InputStream.cpp ***/
  4376. /*** Start of inlined file: juce_OutputStream.cpp ***/
  4377. BEGIN_JUCE_NAMESPACE
  4378. #if JUCE_DEBUG
  4379. static CriticalSection activeStreamLock;
  4380. static VoidArray activeStreams;
  4381. void juce_CheckForDanglingStreams()
  4382. {
  4383. /*
  4384. It's always a bad idea to leak any object, but if you're leaking output
  4385. streams, then there's a good chance that you're failing to flush a file
  4386. to disk properly, which could result in corrupted data and other similar
  4387. nastiness..
  4388. */
  4389. jassert (activeStreams.size() == 0);
  4390. };
  4391. #endif
  4392. OutputStream::OutputStream() throw()
  4393. {
  4394. #if JUCE_DEBUG
  4395. activeStreamLock.enter();
  4396. activeStreams.add (this);
  4397. activeStreamLock.exit();
  4398. #endif
  4399. }
  4400. OutputStream::~OutputStream()
  4401. {
  4402. #if JUCE_DEBUG
  4403. activeStreamLock.enter();
  4404. activeStreams.removeValue (this);
  4405. activeStreamLock.exit();
  4406. #endif
  4407. }
  4408. void OutputStream::writeBool (bool b)
  4409. {
  4410. writeByte ((b) ? (char) 1
  4411. : (char) 0);
  4412. }
  4413. void OutputStream::writeByte (char byte)
  4414. {
  4415. write (&byte, 1);
  4416. }
  4417. void OutputStream::writeShort (short value)
  4418. {
  4419. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4420. write (&v, 2);
  4421. }
  4422. void OutputStream::writeShortBigEndian (short value)
  4423. {
  4424. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4425. write (&v, 2);
  4426. }
  4427. void OutputStream::writeInt (int value)
  4428. {
  4429. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4430. write (&v, 4);
  4431. }
  4432. void OutputStream::writeIntBigEndian (int value)
  4433. {
  4434. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4435. write (&v, 4);
  4436. }
  4437. void OutputStream::writeCompressedInt (int value)
  4438. {
  4439. unsigned int un = (value < 0) ? (unsigned int) -value
  4440. : (unsigned int) value;
  4441. uint8 data[5];
  4442. int num = 0;
  4443. while (un > 0)
  4444. {
  4445. data[++num] = (uint8) un;
  4446. un >>= 8;
  4447. }
  4448. data[0] = (uint8) num;
  4449. if (value < 0)
  4450. data[0] |= 0x80;
  4451. write (data, num + 1);
  4452. }
  4453. void OutputStream::writeInt64 (int64 value)
  4454. {
  4455. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4456. write (&v, 8);
  4457. }
  4458. void OutputStream::writeInt64BigEndian (int64 value)
  4459. {
  4460. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4461. write (&v, 8);
  4462. }
  4463. void OutputStream::writeFloat (float value)
  4464. {
  4465. union { int asInt; float asFloat; } n;
  4466. n.asFloat = value;
  4467. writeInt (n.asInt);
  4468. }
  4469. void OutputStream::writeFloatBigEndian (float value)
  4470. {
  4471. union { int asInt; float asFloat; } n;
  4472. n.asFloat = value;
  4473. writeIntBigEndian (n.asInt);
  4474. }
  4475. void OutputStream::writeDouble (double value)
  4476. {
  4477. union { int64 asInt; double asDouble; } n;
  4478. n.asDouble = value;
  4479. writeInt64 (n.asInt);
  4480. }
  4481. void OutputStream::writeDoubleBigEndian (double value)
  4482. {
  4483. union { int64 asInt; double asDouble; } n;
  4484. n.asDouble = value;
  4485. writeInt64BigEndian (n.asInt);
  4486. }
  4487. void OutputStream::writeString (const String& text)
  4488. {
  4489. const int numBytes = text.copyToUTF8 (0);
  4490. HeapBlock <uint8> temp (numBytes);
  4491. text.copyToUTF8 (temp);
  4492. write (temp, numBytes); // (numBytes includes the terminating null).
  4493. }
  4494. void OutputStream::printf (const char* pf, ...)
  4495. {
  4496. unsigned int bufSize = 256;
  4497. HeapBlock <char> buf (bufSize);
  4498. for (;;)
  4499. {
  4500. va_list list;
  4501. va_start (list, pf);
  4502. const int num = CharacterFunctions::vprintf (buf, bufSize, pf, list);
  4503. va_end (list);
  4504. if (num > 0)
  4505. {
  4506. write (buf, num);
  4507. break;
  4508. }
  4509. else if (num == 0)
  4510. {
  4511. break;
  4512. }
  4513. bufSize += 256;
  4514. buf.malloc (bufSize);
  4515. }
  4516. }
  4517. OutputStream& OutputStream::operator<< (const int number)
  4518. {
  4519. const String s (number);
  4520. write ((const char*) s, s.length());
  4521. return *this;
  4522. }
  4523. OutputStream& OutputStream::operator<< (const double number)
  4524. {
  4525. const String s (number);
  4526. write ((const char*) s, s.length());
  4527. return *this;
  4528. }
  4529. OutputStream& OutputStream::operator<< (const char character)
  4530. {
  4531. writeByte (character);
  4532. return *this;
  4533. }
  4534. OutputStream& OutputStream::operator<< (const char* const text)
  4535. {
  4536. write (text, (int) strlen (text));
  4537. return *this;
  4538. }
  4539. OutputStream& OutputStream::operator<< (const juce_wchar* const text)
  4540. {
  4541. const String s (text);
  4542. write ((const char*) s, s.length());
  4543. return *this;
  4544. }
  4545. OutputStream& OutputStream::operator<< (const String& text)
  4546. {
  4547. write ((const char*) text,
  4548. text.length());
  4549. return *this;
  4550. }
  4551. void OutputStream::writeText (const String& text,
  4552. const bool asUnicode,
  4553. const bool writeUnicodeHeaderBytes)
  4554. {
  4555. if (asUnicode)
  4556. {
  4557. if (writeUnicodeHeaderBytes)
  4558. write ("\x0ff\x0fe", 2);
  4559. const juce_wchar* src = (const juce_wchar*) text;
  4560. bool lastCharWasReturn = false;
  4561. while (*src != 0)
  4562. {
  4563. if (*src == L'\n' && ! lastCharWasReturn)
  4564. writeShort ((short) L'\r');
  4565. lastCharWasReturn = (*src == L'\r');
  4566. writeShort ((short) *src++);
  4567. }
  4568. }
  4569. else
  4570. {
  4571. const char* src = (const char*) text;
  4572. const char* t = src;
  4573. for (;;)
  4574. {
  4575. if (*t == '\n')
  4576. {
  4577. if (t > src)
  4578. write (src, (int) (t - src));
  4579. write ("\r\n", 2);
  4580. src = t + 1;
  4581. }
  4582. else if (*t == '\r')
  4583. {
  4584. if (t[1] == '\n')
  4585. ++t;
  4586. }
  4587. else if (*t == 0)
  4588. {
  4589. if (t > src)
  4590. write (src, (int) (t - src));
  4591. break;
  4592. }
  4593. ++t;
  4594. }
  4595. }
  4596. }
  4597. int OutputStream::writeFromInputStream (InputStream& source,
  4598. int numBytesToWrite)
  4599. {
  4600. if (numBytesToWrite < 0)
  4601. numBytesToWrite = 0x7fffffff;
  4602. int numWritten = 0;
  4603. while (numBytesToWrite > 0 && ! source.isExhausted())
  4604. {
  4605. char buffer [8192];
  4606. const int num = source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4607. if (num == 0)
  4608. break;
  4609. write (buffer, num);
  4610. numBytesToWrite -= num;
  4611. numWritten += num;
  4612. }
  4613. return numWritten;
  4614. }
  4615. END_JUCE_NAMESPACE
  4616. /*** End of inlined file: juce_OutputStream.cpp ***/
  4617. /*** Start of inlined file: juce_DirectoryIterator.cpp ***/
  4618. BEGIN_JUCE_NAMESPACE
  4619. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4620. bool* isDirectory, bool* isHidden, int64* fileSize,
  4621. Time* modTime, Time* creationTime, bool* isReadOnly);
  4622. bool juce_findFileNext (void* handle, String& resultFile,
  4623. bool* isDirectory, bool* isHidden, int64* fileSize,
  4624. Time* modTime, Time* creationTime, bool* isReadOnly);
  4625. void juce_findFileClose (void* handle);
  4626. DirectoryIterator::DirectoryIterator (const File& directory,
  4627. bool isRecursive,
  4628. const String& wc,
  4629. const int whatToLookFor_)
  4630. : wildCard (wc),
  4631. index (-1),
  4632. whatToLookFor (whatToLookFor_)
  4633. {
  4634. // you have to specify the type of files you're looking for!
  4635. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4636. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4637. String path (directory.getFullPathName());
  4638. if (! path.endsWithChar (File::separator))
  4639. path += File::separator;
  4640. String filename;
  4641. bool isDirectory, isHidden;
  4642. void* const handle = juce_findFileStart (path,
  4643. isRecursive ? T("*") : wc,
  4644. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4645. if (handle != 0)
  4646. {
  4647. do
  4648. {
  4649. if (! filename.containsOnly (T(".")))
  4650. {
  4651. bool addToList = false;
  4652. if (isDirectory)
  4653. {
  4654. if (isRecursive
  4655. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4656. || ! isHidden))
  4657. {
  4658. dirsFound.add (File (path + filename, 0));
  4659. }
  4660. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4661. }
  4662. else
  4663. {
  4664. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4665. }
  4666. // if it's recursive, we're not relying on the OS iterator
  4667. // to do the wildcard match, so do it now..
  4668. if (isRecursive && addToList)
  4669. addToList = filename.matchesWildcard (wc, true);
  4670. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4671. addToList = ! isHidden;
  4672. if (addToList)
  4673. filesFound.add (File (path + filename, 0));
  4674. }
  4675. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4676. juce_findFileClose (handle);
  4677. }
  4678. }
  4679. DirectoryIterator::~DirectoryIterator()
  4680. {
  4681. }
  4682. bool DirectoryIterator::next()
  4683. {
  4684. if (subIterator != 0)
  4685. {
  4686. if (subIterator->next())
  4687. return true;
  4688. subIterator = 0;
  4689. }
  4690. if (index >= filesFound.size() + dirsFound.size() - 1)
  4691. return false;
  4692. ++index;
  4693. if (index >= filesFound.size())
  4694. {
  4695. subIterator = new DirectoryIterator (dirsFound.getReference (index - filesFound.size()),
  4696. true, wildCard, whatToLookFor);
  4697. return next();
  4698. }
  4699. return true;
  4700. }
  4701. const File DirectoryIterator::getFile() const
  4702. {
  4703. if (subIterator != 0)
  4704. return subIterator->getFile();
  4705. return filesFound [index];
  4706. }
  4707. float DirectoryIterator::getEstimatedProgress() const
  4708. {
  4709. if (filesFound.size() + dirsFound.size() == 0)
  4710. {
  4711. return 0.0f;
  4712. }
  4713. else
  4714. {
  4715. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4716. : (float) index;
  4717. return detailedIndex / (filesFound.size() + dirsFound.size());
  4718. }
  4719. }
  4720. END_JUCE_NAMESPACE
  4721. /*** End of inlined file: juce_DirectoryIterator.cpp ***/
  4722. /*** Start of inlined file: juce_File.cpp ***/
  4723. #ifdef _MSC_VER
  4724. #pragma warning (disable: 4514)
  4725. #pragma warning (push)
  4726. #endif
  4727. #if ! JUCE_WINDOWS
  4728. #include <pwd.h>
  4729. #endif
  4730. BEGIN_JUCE_NAMESPACE
  4731. #ifdef _MSC_VER
  4732. #pragma warning (pop)
  4733. #endif
  4734. void* juce_fileOpen (const String& path, bool forWriting);
  4735. void juce_fileClose (void* handle);
  4736. int juce_fileWrite (void* handle, const void* buffer, int size);
  4737. int64 juce_fileGetPosition (void* handle);
  4738. int64 juce_fileSetPosition (void* handle, int64 pos);
  4739. void juce_fileFlush (void* handle);
  4740. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4741. bool juce_isDirectory (const String& fileName);
  4742. int64 juce_getFileSize (const String& fileName);
  4743. bool juce_canWriteToFile (const String& fileName);
  4744. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4745. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4746. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4747. bool juce_deleteFile (const String& fileName);
  4748. bool juce_copyFile (const String& source, const String& dest);
  4749. bool juce_moveFile (const String& source, const String& dest);
  4750. // this must also create all paths involved in the directory.
  4751. void juce_createDirectory (const String& fileName);
  4752. bool juce_launchFile (const String& fileName, const String& parameters);
  4753. const StringArray juce_getFileSystemRoots();
  4754. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4755. // starts a directory search operation with a wildcard, returning a handle for
  4756. // use in calls to juce_findFileNext.
  4757. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4758. // the other pointers, if non-null, are set based on the properties of the file.
  4759. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4760. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4761. Time* creationTime, bool* isReadOnly);
  4762. // returns false when no more files are found
  4763. bool juce_findFileNext (void* handle, String& resultFile,
  4764. bool* isDirectory, bool* isHidden, int64* fileSize,
  4765. Time* modTime, Time* creationTime, bool* isReadOnly);
  4766. void juce_findFileClose (void* handle);
  4767. static const String juce_addTrailingSeparator (const String& path)
  4768. {
  4769. return path.endsWithChar (File::separator) ? path
  4770. : path + File::separator;
  4771. }
  4772. static const String parseAbsolutePath (String path)
  4773. {
  4774. if (path.isEmpty())
  4775. return String::empty;
  4776. #if JUCE_WINDOWS
  4777. // Windows..
  4778. path = path.replaceCharacter (T('/'), T('\\'));
  4779. if (path.startsWithChar (File::separator))
  4780. {
  4781. if (path[1] != File::separator)
  4782. {
  4783. jassertfalse // using a filename that starts with a slash is a bit dodgy on
  4784. // Windows, because it needs a drive letter, which in this case
  4785. // we'll take from the CWD.. but this is a bit of an assumption that
  4786. // could be wrong..
  4787. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4788. }
  4789. }
  4790. else if (path.indexOfChar (T(':')) < 0)
  4791. {
  4792. if (path.isEmpty())
  4793. return String::empty;
  4794. jassertfalse // using a partial filename is a bad way to initialise a file, because
  4795. // we don't know what directory to put it in.
  4796. // Here we'll assume it's in the CWD, but this might not be what was
  4797. // intended..
  4798. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4799. }
  4800. #else
  4801. // Mac or Linux..
  4802. path = path.replaceCharacter (T('\\'), T('/'));
  4803. if (path.startsWithChar (T('~')))
  4804. {
  4805. const char* homeDir = 0;
  4806. if (path[1] == File::separator || path[1] == 0)
  4807. {
  4808. // expand a name of the form "~/abc"
  4809. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4810. + path.substring (1);
  4811. }
  4812. else
  4813. {
  4814. // expand a name of type "~dave/abc"
  4815. const String userName (path.substring (1)
  4816. .upToFirstOccurrenceOf (T("/"), false, false));
  4817. struct passwd* const pw = getpwnam (userName);
  4818. if (pw != 0)
  4819. {
  4820. String home (homeDir);
  4821. if (home.endsWithChar (File::separator))
  4822. home [home.length() - 1] = 0;
  4823. path = String (pw->pw_dir)
  4824. + path.substring (userName.length());
  4825. }
  4826. }
  4827. }
  4828. else if (! path.startsWithChar (File::separator))
  4829. {
  4830. while (path.startsWith (T("./")))
  4831. path = path.substring (2);
  4832. if (path.isEmpty())
  4833. return String::empty;
  4834. jassertfalse // using a partial filename is a bad way to initialise a file, because
  4835. // we don't know what directory to put it in.
  4836. // Here we'll assume it's in the CWD, but this might not be what was
  4837. // intended..
  4838. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4839. }
  4840. #endif
  4841. int len = path.length();
  4842. while (--len > 0 && path [len] == File::separator)
  4843. path [len] = 0;
  4844. return path;
  4845. }
  4846. const File File::nonexistent;
  4847. File::File (const String& fullPathName)
  4848. : fullPath (parseAbsolutePath (fullPathName))
  4849. {
  4850. }
  4851. File::File (const String& path, int)
  4852. : fullPath (path)
  4853. {
  4854. }
  4855. const File File::createFileWithoutCheckingPath (const String& path)
  4856. {
  4857. return File (path, 0);
  4858. }
  4859. File::File (const File& other)
  4860. : fullPath (other.fullPath)
  4861. {
  4862. }
  4863. const File& File::operator= (const String& newPath)
  4864. {
  4865. fullPath = parseAbsolutePath (newPath);
  4866. return *this;
  4867. }
  4868. const File& File::operator= (const File& other)
  4869. {
  4870. fullPath = other.fullPath;
  4871. return *this;
  4872. }
  4873. #if JUCE_LINUX
  4874. #define NAMES_ARE_CASE_SENSITIVE 1
  4875. #endif
  4876. bool File::areFileNamesCaseSensitive()
  4877. {
  4878. #if NAMES_ARE_CASE_SENSITIVE
  4879. return true;
  4880. #else
  4881. return false;
  4882. #endif
  4883. }
  4884. bool File::operator== (const File& other) const
  4885. {
  4886. // case-insensitive on Windows, but not on linux.
  4887. #if NAMES_ARE_CASE_SENSITIVE
  4888. return fullPath == other.fullPath;
  4889. #else
  4890. return fullPath.equalsIgnoreCase (other.fullPath);
  4891. #endif
  4892. }
  4893. bool File::operator!= (const File& other) const
  4894. {
  4895. return ! operator== (other);
  4896. }
  4897. bool File::exists() const
  4898. {
  4899. return juce_fileExists (fullPath, false);
  4900. }
  4901. bool File::existsAsFile() const
  4902. {
  4903. return juce_fileExists (fullPath, true);
  4904. }
  4905. bool File::isDirectory() const
  4906. {
  4907. return juce_isDirectory (fullPath);
  4908. }
  4909. bool File::hasWriteAccess() const
  4910. {
  4911. if (exists())
  4912. return juce_canWriteToFile (fullPath);
  4913. #if ! JUCE_WINDOWS
  4914. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4915. return getParentDirectory().hasWriteAccess();
  4916. else
  4917. return false;
  4918. #else
  4919. // on windows, it seems that even read-only directories can still be written into,
  4920. // so checking the parent directory's permissions would return the wrong result..
  4921. else
  4922. return true;
  4923. #endif
  4924. }
  4925. bool File::setReadOnly (const bool shouldBeReadOnly,
  4926. const bool applyRecursively) const
  4927. {
  4928. bool worked = true;
  4929. if (applyRecursively && isDirectory())
  4930. {
  4931. Array <File> subFiles;
  4932. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4933. for (int i = subFiles.size(); --i >= 0;)
  4934. worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked;
  4935. }
  4936. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4937. }
  4938. bool File::deleteFile() const
  4939. {
  4940. return (! exists())
  4941. || juce_deleteFile (fullPath);
  4942. }
  4943. bool File::deleteRecursively() const
  4944. {
  4945. bool worked = true;
  4946. if (isDirectory())
  4947. {
  4948. Array<File> subFiles;
  4949. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4950. for (int i = subFiles.size(); --i >= 0;)
  4951. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4952. }
  4953. return deleteFile() && worked;
  4954. }
  4955. bool File::moveFileTo (const File& newFile) const
  4956. {
  4957. if (newFile.fullPath == fullPath)
  4958. return true;
  4959. #if ! NAMES_ARE_CASE_SENSITIVE
  4960. if (*this != newFile)
  4961. #endif
  4962. if (! newFile.deleteFile())
  4963. return false;
  4964. return juce_moveFile (fullPath, newFile.fullPath);
  4965. }
  4966. bool File::copyFileTo (const File& newFile) const
  4967. {
  4968. if (*this == newFile)
  4969. return true;
  4970. if (! newFile.deleteFile())
  4971. return false;
  4972. return juce_copyFile (fullPath, newFile.fullPath);
  4973. }
  4974. bool File::copyDirectoryTo (const File& newDirectory) const
  4975. {
  4976. if (isDirectory() && newDirectory.createDirectory())
  4977. {
  4978. Array<File> subFiles;
  4979. findChildFiles (subFiles, File::findFiles, false);
  4980. int i;
  4981. for (i = 0; i < subFiles.size(); ++i)
  4982. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4983. return false;
  4984. subFiles.clear();
  4985. findChildFiles (subFiles, File::findDirectories, false);
  4986. for (i = 0; i < subFiles.size(); ++i)
  4987. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4988. return false;
  4989. return true;
  4990. }
  4991. return false;
  4992. }
  4993. const String File::getPathUpToLastSlash() const
  4994. {
  4995. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4996. if (lastSlash > 0)
  4997. return fullPath.substring (0, lastSlash);
  4998. else if (lastSlash == 0)
  4999. return separatorString;
  5000. else
  5001. return fullPath;
  5002. }
  5003. const File File::getParentDirectory() const
  5004. {
  5005. return File (getPathUpToLastSlash());
  5006. }
  5007. const String File::getFileName() const
  5008. {
  5009. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  5010. }
  5011. int File::hashCode() const
  5012. {
  5013. return fullPath.hashCode();
  5014. }
  5015. int64 File::hashCode64() const
  5016. {
  5017. return fullPath.hashCode64();
  5018. }
  5019. const String File::getFileNameWithoutExtension() const
  5020. {
  5021. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  5022. const int lastDot = fullPath.lastIndexOfChar (T('.'));
  5023. if (lastDot > lastSlash)
  5024. return fullPath.substring (lastSlash, lastDot);
  5025. else
  5026. return fullPath.substring (lastSlash);
  5027. }
  5028. bool File::isAChildOf (const File& potentialParent) const
  5029. {
  5030. if (potentialParent == File::nonexistent)
  5031. return false;
  5032. const String ourPath (getPathUpToLastSlash());
  5033. #if NAMES_ARE_CASE_SENSITIVE
  5034. if (potentialParent.fullPath == ourPath)
  5035. #else
  5036. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  5037. #endif
  5038. {
  5039. return true;
  5040. }
  5041. else if (potentialParent.fullPath.length() >= ourPath.length())
  5042. {
  5043. return false;
  5044. }
  5045. else
  5046. {
  5047. return getParentDirectory().isAChildOf (potentialParent);
  5048. }
  5049. }
  5050. bool File::isAbsolutePath (const String& path)
  5051. {
  5052. return path.startsWithChar (T('/')) || path.startsWithChar (T('\\'))
  5053. #if JUCE_WINDOWS
  5054. || (path.isNotEmpty() && ((const String&) path)[1] == T(':'));
  5055. #else
  5056. || path.startsWithChar (T('~'));
  5057. #endif
  5058. }
  5059. const File File::getChildFile (String relativePath) const
  5060. {
  5061. if (isAbsolutePath (relativePath))
  5062. {
  5063. // the path is really absolute..
  5064. return File (relativePath);
  5065. }
  5066. else
  5067. {
  5068. // it's relative, so remove any ../ or ./ bits at the start.
  5069. String path (fullPath);
  5070. if (relativePath[0] == T('.'))
  5071. {
  5072. #if JUCE_WINDOWS
  5073. relativePath = relativePath.replaceCharacter (T('/'), T('\\')).trimStart();
  5074. #else
  5075. relativePath = relativePath.replaceCharacter (T('\\'), T('/')).trimStart();
  5076. #endif
  5077. while (relativePath[0] == T('.'))
  5078. {
  5079. if (relativePath[1] == T('.'))
  5080. {
  5081. if (relativePath [2] == 0 || relativePath[2] == separator)
  5082. {
  5083. const int lastSlash = path.lastIndexOfChar (separator);
  5084. if (lastSlash >= 0)
  5085. path = path.substring (0, lastSlash);
  5086. relativePath = relativePath.substring (3);
  5087. }
  5088. else
  5089. {
  5090. break;
  5091. }
  5092. }
  5093. else if (relativePath[1] == separator)
  5094. {
  5095. relativePath = relativePath.substring (2);
  5096. }
  5097. else
  5098. {
  5099. break;
  5100. }
  5101. }
  5102. }
  5103. return File (juce_addTrailingSeparator (path) + relativePath);
  5104. }
  5105. }
  5106. const File File::getSiblingFile (const String& fileName) const
  5107. {
  5108. return getParentDirectory().getChildFile (fileName);
  5109. }
  5110. int64 File::getSize() const
  5111. {
  5112. return juce_getFileSize (fullPath);
  5113. }
  5114. const String File::descriptionOfSizeInBytes (const int64 bytes)
  5115. {
  5116. if (bytes == 1)
  5117. {
  5118. return "1 byte";
  5119. }
  5120. else if (bytes < 1024)
  5121. {
  5122. return String ((int) bytes) + " bytes";
  5123. }
  5124. else if (bytes < 1024 * 1024)
  5125. {
  5126. return String (bytes / 1024.0, 1) + " KB";
  5127. }
  5128. else if (bytes < 1024 * 1024 * 1024)
  5129. {
  5130. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  5131. }
  5132. else
  5133. {
  5134. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  5135. }
  5136. }
  5137. bool File::create() const
  5138. {
  5139. if (! exists())
  5140. {
  5141. const File parentDir (getParentDirectory());
  5142. if (parentDir == *this || ! parentDir.createDirectory())
  5143. return false;
  5144. void* const fh = juce_fileOpen (fullPath, true);
  5145. if (fh == 0)
  5146. return false;
  5147. juce_fileClose (fh);
  5148. }
  5149. return true;
  5150. }
  5151. bool File::createDirectory() const
  5152. {
  5153. if (! isDirectory())
  5154. {
  5155. const File parentDir (getParentDirectory());
  5156. if (parentDir == *this || ! parentDir.createDirectory())
  5157. return false;
  5158. String dir (fullPath);
  5159. while (dir.endsWithChar (separator))
  5160. dir [dir.length() - 1] = 0;
  5161. juce_createDirectory (dir);
  5162. return isDirectory();
  5163. }
  5164. return true;
  5165. }
  5166. const Time File::getCreationTime() const
  5167. {
  5168. int64 m, a, c;
  5169. juce_getFileTimes (fullPath, m, a, c);
  5170. return Time (c);
  5171. }
  5172. bool File::setCreationTime (const Time& t) const
  5173. {
  5174. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  5175. }
  5176. const Time File::getLastModificationTime() const
  5177. {
  5178. int64 m, a, c;
  5179. juce_getFileTimes (fullPath, m, a, c);
  5180. return Time (m);
  5181. }
  5182. bool File::setLastModificationTime (const Time& t) const
  5183. {
  5184. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  5185. }
  5186. const Time File::getLastAccessTime() const
  5187. {
  5188. int64 m, a, c;
  5189. juce_getFileTimes (fullPath, m, a, c);
  5190. return Time (a);
  5191. }
  5192. bool File::setLastAccessTime (const Time& t) const
  5193. {
  5194. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  5195. }
  5196. bool File::loadFileAsData (MemoryBlock& destBlock) const
  5197. {
  5198. if (! existsAsFile())
  5199. return false;
  5200. FileInputStream in (*this);
  5201. return getSize() == in.readIntoMemoryBlock (destBlock);
  5202. }
  5203. const String File::loadFileAsString() const
  5204. {
  5205. if (! existsAsFile())
  5206. return String::empty;
  5207. FileInputStream in (*this);
  5208. return in.readEntireStreamAsString();
  5209. }
  5210. static inline bool fileTypeMatches (const int whatToLookFor,
  5211. const bool isDir,
  5212. const bool isHidden)
  5213. {
  5214. return (whatToLookFor & (isDir ? File::findDirectories
  5215. : File::findFiles)) != 0
  5216. && ((! isHidden)
  5217. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  5218. }
  5219. int File::findChildFiles (Array<File>& results,
  5220. const int whatToLookFor,
  5221. const bool searchRecursively,
  5222. const String& wildCardPattern) const
  5223. {
  5224. // you have to specify the type of files you're looking for!
  5225. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5226. int total = 0;
  5227. // find child files or directories in this directory first..
  5228. if (isDirectory())
  5229. {
  5230. const String path (juce_addTrailingSeparator (fullPath));
  5231. String filename;
  5232. bool itemIsDirectory, itemIsHidden;
  5233. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5234. &itemIsDirectory, &itemIsHidden,
  5235. 0, 0, 0, 0);
  5236. if (handle != 0)
  5237. {
  5238. do
  5239. {
  5240. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5241. && ! filename.containsOnly (T(".")))
  5242. {
  5243. results.add (File (path + filename, 0));
  5244. ++total;
  5245. }
  5246. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5247. juce_findFileClose (handle);
  5248. }
  5249. }
  5250. else
  5251. {
  5252. // trying to search for files inside a non-directory?
  5253. //jassertfalse
  5254. }
  5255. // and recurse down if required.
  5256. if (searchRecursively)
  5257. {
  5258. Array<File> subDirectories;
  5259. findChildFiles (subDirectories, File::findDirectories, false);
  5260. for (int i = 0; i < subDirectories.size(); ++i)
  5261. {
  5262. total += subDirectories.getReference(i).findChildFiles (results, whatToLookFor,
  5263. true, wildCardPattern);
  5264. }
  5265. }
  5266. return total;
  5267. }
  5268. int File::getNumberOfChildFiles (const int whatToLookFor,
  5269. const String& wildCardPattern) const
  5270. {
  5271. // you have to specify the type of files you're looking for!
  5272. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5273. int count = 0;
  5274. if (isDirectory())
  5275. {
  5276. String filename;
  5277. bool itemIsDirectory, itemIsHidden;
  5278. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5279. &itemIsDirectory, &itemIsHidden,
  5280. 0, 0, 0, 0);
  5281. if (handle != 0)
  5282. {
  5283. do
  5284. {
  5285. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5286. && ! filename.containsOnly (T(".")))
  5287. {
  5288. ++count;
  5289. }
  5290. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5291. juce_findFileClose (handle);
  5292. }
  5293. }
  5294. else
  5295. {
  5296. // trying to search for files inside a non-directory?
  5297. jassertfalse
  5298. }
  5299. return count;
  5300. }
  5301. bool File::containsSubDirectories() const
  5302. {
  5303. bool result = false;
  5304. if (isDirectory())
  5305. {
  5306. String filename;
  5307. bool itemIsDirectory, itemIsHidden;
  5308. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5309. T("*"), filename,
  5310. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5311. if (handle != 0)
  5312. {
  5313. do
  5314. {
  5315. if (itemIsDirectory)
  5316. {
  5317. result = true;
  5318. break;
  5319. }
  5320. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5321. juce_findFileClose (handle);
  5322. }
  5323. }
  5324. return result;
  5325. }
  5326. const File File::getNonexistentChildFile (const String& prefix_,
  5327. const String& suffix,
  5328. bool putNumbersInBrackets) const
  5329. {
  5330. File f (getChildFile (prefix_ + suffix));
  5331. if (f.exists())
  5332. {
  5333. int num = 2;
  5334. String prefix (prefix_);
  5335. // remove any bracketed numbers that may already be on the end..
  5336. if (prefix.trim().endsWithChar (T(')')))
  5337. {
  5338. putNumbersInBrackets = true;
  5339. const int openBracks = prefix.lastIndexOfChar (T('('));
  5340. const int closeBracks = prefix.lastIndexOfChar (T(')'));
  5341. if (openBracks > 0
  5342. && closeBracks > openBracks
  5343. && prefix.substring (openBracks + 1, closeBracks).containsOnly (T("0123456789")))
  5344. {
  5345. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5346. prefix = prefix.substring (0, openBracks);
  5347. }
  5348. }
  5349. // also use brackets if it ends in a digit.
  5350. putNumbersInBrackets = putNumbersInBrackets
  5351. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5352. do
  5353. {
  5354. if (putNumbersInBrackets)
  5355. f = getChildFile (prefix + T('(') + String (num++) + T(')') + suffix);
  5356. else
  5357. f = getChildFile (prefix + String (num++) + suffix);
  5358. } while (f.exists());
  5359. }
  5360. return f;
  5361. }
  5362. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5363. {
  5364. if (exists())
  5365. {
  5366. return getParentDirectory()
  5367. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5368. getFileExtension(),
  5369. putNumbersInBrackets);
  5370. }
  5371. else
  5372. {
  5373. return *this;
  5374. }
  5375. }
  5376. const String File::getFileExtension() const
  5377. {
  5378. String ext;
  5379. if (! isDirectory())
  5380. {
  5381. const int indexOfDot = fullPath.lastIndexOfChar (T('.'));
  5382. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5383. ext = fullPath.substring (indexOfDot);
  5384. }
  5385. return ext;
  5386. }
  5387. bool File::hasFileExtension (const String& possibleSuffix) const
  5388. {
  5389. if (possibleSuffix.isEmpty())
  5390. return fullPath.lastIndexOfChar (T('.')) <= fullPath.lastIndexOfChar (separator);
  5391. const int semicolon = possibleSuffix.indexOfChar (0, T(';'));
  5392. if (semicolon >= 0)
  5393. {
  5394. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5395. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5396. }
  5397. else
  5398. {
  5399. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5400. {
  5401. if (possibleSuffix.startsWithChar (T('.')))
  5402. return true;
  5403. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5404. if (dotPos >= 0)
  5405. return fullPath [dotPos] == T('.');
  5406. }
  5407. }
  5408. return false;
  5409. }
  5410. const File File::withFileExtension (const String& newExtension) const
  5411. {
  5412. if (fullPath.isEmpty())
  5413. return File::nonexistent;
  5414. String filePart (getFileName());
  5415. int i = filePart.lastIndexOfChar (T('.'));
  5416. if (i < 0)
  5417. i = filePart.length();
  5418. String newExt (newExtension);
  5419. if (newExt.isNotEmpty() && ! newExt.startsWithChar (T('.')))
  5420. newExt = T(".") + newExt;
  5421. return getSiblingFile (filePart.substring (0, i) + newExt);
  5422. }
  5423. bool File::startAsProcess (const String& parameters) const
  5424. {
  5425. return exists()
  5426. && juce_launchFile (fullPath, parameters);
  5427. }
  5428. FileInputStream* File::createInputStream() const
  5429. {
  5430. if (existsAsFile())
  5431. return new FileInputStream (*this);
  5432. else
  5433. return 0;
  5434. }
  5435. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5436. {
  5437. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5438. if (out->failedToOpen())
  5439. return 0;
  5440. return out.release();
  5441. }
  5442. bool File::appendData (const void* const dataToAppend,
  5443. const int numberOfBytes) const
  5444. {
  5445. if (numberOfBytes > 0)
  5446. {
  5447. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5448. if (out == 0)
  5449. return false;
  5450. out->write (dataToAppend, numberOfBytes);
  5451. }
  5452. return true;
  5453. }
  5454. bool File::replaceWithData (const void* const dataToWrite,
  5455. const int numberOfBytes) const
  5456. {
  5457. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5458. if (numberOfBytes <= 0)
  5459. return deleteFile();
  5460. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5461. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5462. return tempFile.overwriteTargetFileWithTemporary();
  5463. }
  5464. bool File::appendText (const String& text,
  5465. const bool asUnicode,
  5466. const bool writeUnicodeHeaderBytes) const
  5467. {
  5468. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5469. if (out != 0)
  5470. {
  5471. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5472. return true;
  5473. }
  5474. return false;
  5475. }
  5476. bool File::replaceWithText (const String& textToWrite,
  5477. const bool asUnicode,
  5478. const bool writeUnicodeHeaderBytes) const
  5479. {
  5480. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5481. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5482. return tempFile.overwriteTargetFileWithTemporary();
  5483. }
  5484. const String File::createLegalPathName (const String& original)
  5485. {
  5486. String s (original);
  5487. String start;
  5488. if (s[1] == T(':'))
  5489. {
  5490. start = s.substring (0, 2);
  5491. s = s.substring (2);
  5492. }
  5493. return start + s.removeCharacters (T("\"#@,;:<>*^|?"))
  5494. .substring (0, 1024);
  5495. }
  5496. const String File::createLegalFileName (const String& original)
  5497. {
  5498. String s (original.removeCharacters (T("\"#@,;:<>*^|?\\/")));
  5499. const int maxLength = 128; // only the length of the filename, not the whole path
  5500. const int len = s.length();
  5501. if (len > maxLength)
  5502. {
  5503. const int lastDot = s.lastIndexOfChar (T('.'));
  5504. if (lastDot > jmax (0, len - 12))
  5505. {
  5506. s = s.substring (0, maxLength - (len - lastDot))
  5507. + s.substring (lastDot);
  5508. }
  5509. else
  5510. {
  5511. s = s.substring (0, maxLength);
  5512. }
  5513. }
  5514. return s;
  5515. }
  5516. const String File::getRelativePathFrom (const File& dir) const
  5517. {
  5518. String thisPath (fullPath);
  5519. {
  5520. int len = thisPath.length();
  5521. while (--len >= 0 && thisPath [len] == File::separator)
  5522. thisPath [len] = 0;
  5523. }
  5524. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5525. : dir.fullPath));
  5526. const int len = jmin (thisPath.length(), dirPath.length());
  5527. int commonBitLength = 0;
  5528. for (int i = 0; i < len; ++i)
  5529. {
  5530. #if NAMES_ARE_CASE_SENSITIVE
  5531. if (thisPath[i] != dirPath[i])
  5532. #else
  5533. if (CharacterFunctions::toLowerCase (thisPath[i])
  5534. != CharacterFunctions::toLowerCase (dirPath[i]))
  5535. #endif
  5536. {
  5537. break;
  5538. }
  5539. ++commonBitLength;
  5540. }
  5541. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5542. --commonBitLength;
  5543. // if the only common bit is the root, then just return the full path..
  5544. if (commonBitLength <= 0
  5545. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5546. return fullPath;
  5547. thisPath = thisPath.substring (commonBitLength);
  5548. dirPath = dirPath.substring (commonBitLength);
  5549. while (dirPath.isNotEmpty())
  5550. {
  5551. #if JUCE_WINDOWS
  5552. thisPath = T("..\\") + thisPath;
  5553. #else
  5554. thisPath = T("../") + thisPath;
  5555. #endif
  5556. const int sep = dirPath.indexOfChar (separator);
  5557. if (sep >= 0)
  5558. dirPath = dirPath.substring (sep + 1);
  5559. else
  5560. dirPath = String::empty;
  5561. }
  5562. return thisPath;
  5563. }
  5564. void File::findFileSystemRoots (Array<File>& destArray)
  5565. {
  5566. const StringArray roots (juce_getFileSystemRoots());
  5567. for (int i = 0; i < roots.size(); ++i)
  5568. destArray.add (File (roots[i]));
  5569. }
  5570. const String File::getVolumeLabel() const
  5571. {
  5572. int serialNum;
  5573. return juce_getVolumeLabel (fullPath, serialNum);
  5574. }
  5575. int File::getVolumeSerialNumber() const
  5576. {
  5577. int serialNum;
  5578. juce_getVolumeLabel (fullPath, serialNum);
  5579. return serialNum;
  5580. }
  5581. const File File::createTempFile (const String& fileNameEnding)
  5582. {
  5583. const File tempFile (getSpecialLocation (tempDirectory)
  5584. .getChildFile (T("temp_") + String (Random::getSystemRandom().nextInt()))
  5585. .withFileExtension (fileNameEnding));
  5586. if (tempFile.exists())
  5587. return createTempFile (fileNameEnding);
  5588. else
  5589. return tempFile;
  5590. }
  5591. END_JUCE_NAMESPACE
  5592. /*** End of inlined file: juce_File.cpp ***/
  5593. /*** Start of inlined file: juce_FileInputStream.cpp ***/
  5594. BEGIN_JUCE_NAMESPACE
  5595. void* juce_fileOpen (const String& path, bool forWriting);
  5596. void juce_fileClose (void* handle);
  5597. int juce_fileRead (void* handle, void* buffer, int size);
  5598. int64 juce_fileSetPosition (void* handle, int64 pos);
  5599. FileInputStream::FileInputStream (const File& f)
  5600. : file (f),
  5601. currentPosition (0),
  5602. needToSeek (true)
  5603. {
  5604. totalSize = f.getSize();
  5605. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5606. }
  5607. FileInputStream::~FileInputStream()
  5608. {
  5609. juce_fileClose (fileHandle);
  5610. }
  5611. int64 FileInputStream::getTotalLength()
  5612. {
  5613. return totalSize;
  5614. }
  5615. int FileInputStream::read (void* buffer, int bytesToRead)
  5616. {
  5617. int num = 0;
  5618. if (needToSeek)
  5619. {
  5620. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5621. return 0;
  5622. needToSeek = false;
  5623. }
  5624. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5625. currentPosition += num;
  5626. return num;
  5627. }
  5628. bool FileInputStream::isExhausted()
  5629. {
  5630. return currentPosition >= totalSize;
  5631. }
  5632. int64 FileInputStream::getPosition()
  5633. {
  5634. return currentPosition;
  5635. }
  5636. bool FileInputStream::setPosition (int64 pos)
  5637. {
  5638. pos = jlimit ((int64) 0, totalSize, pos);
  5639. needToSeek |= (currentPosition != pos);
  5640. currentPosition = pos;
  5641. return true;
  5642. }
  5643. END_JUCE_NAMESPACE
  5644. /*** End of inlined file: juce_FileInputStream.cpp ***/
  5645. /*** Start of inlined file: juce_FileOutputStream.cpp ***/
  5646. BEGIN_JUCE_NAMESPACE
  5647. void* juce_fileOpen (const String& path, bool forWriting);
  5648. void juce_fileClose (void* handle);
  5649. int juce_fileWrite (void* handle, const void* buffer, int size);
  5650. void juce_fileFlush (void* handle);
  5651. int64 juce_fileGetPosition (void* handle);
  5652. int64 juce_fileSetPosition (void* handle, int64 pos);
  5653. FileOutputStream::FileOutputStream (const File& f,
  5654. const int bufferSize_)
  5655. : file (f),
  5656. bufferSize (bufferSize_),
  5657. bytesInBuffer (0)
  5658. {
  5659. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5660. if (fileHandle != 0)
  5661. {
  5662. currentPosition = juce_fileGetPosition (fileHandle);
  5663. if (currentPosition < 0)
  5664. {
  5665. jassertfalse
  5666. juce_fileClose (fileHandle);
  5667. fileHandle = 0;
  5668. }
  5669. }
  5670. buffer.malloc (jmax (bufferSize_, 16));
  5671. }
  5672. FileOutputStream::~FileOutputStream()
  5673. {
  5674. flush();
  5675. juce_fileClose (fileHandle);
  5676. }
  5677. int64 FileOutputStream::getPosition()
  5678. {
  5679. return currentPosition;
  5680. }
  5681. bool FileOutputStream::setPosition (int64 newPosition)
  5682. {
  5683. if (newPosition != currentPosition)
  5684. {
  5685. flush();
  5686. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5687. }
  5688. return newPosition == currentPosition;
  5689. }
  5690. void FileOutputStream::flush()
  5691. {
  5692. if (bytesInBuffer > 0)
  5693. {
  5694. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5695. bytesInBuffer = 0;
  5696. }
  5697. juce_fileFlush (fileHandle);
  5698. }
  5699. bool FileOutputStream::write (const void* const src, const int numBytes)
  5700. {
  5701. if (bytesInBuffer + numBytes < bufferSize)
  5702. {
  5703. memcpy (buffer + bytesInBuffer, src, numBytes);
  5704. bytesInBuffer += numBytes;
  5705. currentPosition += numBytes;
  5706. }
  5707. else
  5708. {
  5709. if (bytesInBuffer > 0)
  5710. {
  5711. // flush the reservoir
  5712. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5713. bytesInBuffer = 0;
  5714. if (! wroteOk)
  5715. return false;
  5716. }
  5717. if (numBytes < bufferSize)
  5718. {
  5719. memcpy (buffer + bytesInBuffer, src, numBytes);
  5720. bytesInBuffer += numBytes;
  5721. currentPosition += numBytes;
  5722. }
  5723. else
  5724. {
  5725. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5726. currentPosition += bytesWritten;
  5727. return bytesWritten == numBytes;
  5728. }
  5729. }
  5730. return true;
  5731. }
  5732. END_JUCE_NAMESPACE
  5733. /*** End of inlined file: juce_FileOutputStream.cpp ***/
  5734. /*** Start of inlined file: juce_FileSearchPath.cpp ***/
  5735. BEGIN_JUCE_NAMESPACE
  5736. FileSearchPath::FileSearchPath()
  5737. {
  5738. }
  5739. FileSearchPath::FileSearchPath (const String& path)
  5740. {
  5741. init (path);
  5742. }
  5743. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5744. : directories (other.directories)
  5745. {
  5746. }
  5747. FileSearchPath::~FileSearchPath()
  5748. {
  5749. }
  5750. const FileSearchPath& FileSearchPath::operator= (const String& path)
  5751. {
  5752. init (path);
  5753. return *this;
  5754. }
  5755. void FileSearchPath::init (const String& path)
  5756. {
  5757. directories.clear();
  5758. directories.addTokens (path, T(";"), T("\""));
  5759. directories.trim();
  5760. directories.removeEmptyStrings();
  5761. for (int i = directories.size(); --i >= 0;)
  5762. directories.set (i, directories[i].unquoted());
  5763. }
  5764. int FileSearchPath::getNumPaths() const
  5765. {
  5766. return directories.size();
  5767. }
  5768. const File FileSearchPath::operator[] (const int index) const
  5769. {
  5770. return File (directories [index]);
  5771. }
  5772. const String FileSearchPath::toString() const
  5773. {
  5774. StringArray directories2 (directories);
  5775. for (int i = directories2.size(); --i >= 0;)
  5776. if (directories2[i].containsChar (T(';')))
  5777. directories2.set (i, directories2[i].quoted());
  5778. return directories2.joinIntoString (T(";"));
  5779. }
  5780. void FileSearchPath::add (const File& dir, const int insertIndex)
  5781. {
  5782. directories.insert (insertIndex, dir.getFullPathName());
  5783. }
  5784. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5785. {
  5786. for (int i = 0; i < directories.size(); ++i)
  5787. if (File (directories[i]) == dir)
  5788. return;
  5789. add (dir);
  5790. }
  5791. void FileSearchPath::remove (const int index)
  5792. {
  5793. directories.remove (index);
  5794. }
  5795. void FileSearchPath::addPath (const FileSearchPath& other)
  5796. {
  5797. for (int i = 0; i < other.getNumPaths(); ++i)
  5798. addIfNotAlreadyThere (other[i]);
  5799. }
  5800. void FileSearchPath::removeRedundantPaths()
  5801. {
  5802. for (int i = directories.size(); --i >= 0;)
  5803. {
  5804. const File d1 (directories[i]);
  5805. for (int j = directories.size(); --j >= 0;)
  5806. {
  5807. const File d2 (directories[j]);
  5808. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5809. {
  5810. directories.remove (i);
  5811. break;
  5812. }
  5813. }
  5814. }
  5815. }
  5816. void FileSearchPath::removeNonExistentPaths()
  5817. {
  5818. for (int i = directories.size(); --i >= 0;)
  5819. if (! File (directories[i]).isDirectory())
  5820. directories.remove (i);
  5821. }
  5822. int FileSearchPath::findChildFiles (Array<File>& results,
  5823. const int whatToLookFor,
  5824. const bool searchRecursively,
  5825. const String& wildCardPattern) const
  5826. {
  5827. int total = 0;
  5828. for (int i = 0; i < directories.size(); ++i)
  5829. total += operator[] (i).findChildFiles (results,
  5830. whatToLookFor,
  5831. searchRecursively,
  5832. wildCardPattern);
  5833. return total;
  5834. }
  5835. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5836. const bool checkRecursively) const
  5837. {
  5838. for (int i = directories.size(); --i >= 0;)
  5839. {
  5840. const File d (directories[i]);
  5841. if (checkRecursively)
  5842. {
  5843. if (fileToCheck.isAChildOf (d))
  5844. return true;
  5845. }
  5846. else
  5847. {
  5848. if (fileToCheck.getParentDirectory() == d)
  5849. return true;
  5850. }
  5851. }
  5852. return false;
  5853. }
  5854. END_JUCE_NAMESPACE
  5855. /*** End of inlined file: juce_FileSearchPath.cpp ***/
  5856. /*** Start of inlined file: juce_NamedPipe.cpp ***/
  5857. BEGIN_JUCE_NAMESPACE
  5858. NamedPipe::NamedPipe()
  5859. : internal (0)
  5860. {
  5861. }
  5862. NamedPipe::~NamedPipe()
  5863. {
  5864. close();
  5865. }
  5866. bool NamedPipe::openExisting (const String& pipeName)
  5867. {
  5868. currentPipeName = pipeName;
  5869. return openInternal (pipeName, false);
  5870. }
  5871. bool NamedPipe::createNewPipe (const String& pipeName)
  5872. {
  5873. currentPipeName = pipeName;
  5874. return openInternal (pipeName, true);
  5875. }
  5876. bool NamedPipe::isOpen() const
  5877. {
  5878. return internal != 0;
  5879. }
  5880. const String NamedPipe::getName() const
  5881. {
  5882. return currentPipeName;
  5883. }
  5884. // other methods for this class are implemented in the platform-specific files
  5885. END_JUCE_NAMESPACE
  5886. /*** End of inlined file: juce_NamedPipe.cpp ***/
  5887. /*** Start of inlined file: juce_TemporaryFile.cpp ***/
  5888. BEGIN_JUCE_NAMESPACE
  5889. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5890. {
  5891. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5892. T("temp_") + String (Random::getSystemRandom().nextInt()),
  5893. suffix,
  5894. optionFlags);
  5895. }
  5896. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5897. : targetFile (targetFile_)
  5898. {
  5899. // If you use this constructor, you need to give it a valid target file!
  5900. jassert (targetFile != File::nonexistent);
  5901. createTempFile (targetFile.getParentDirectory(),
  5902. targetFile.getFileNameWithoutExtension() + T("_temp") + String (Random::getSystemRandom().nextInt()),
  5903. targetFile.getFileExtension(),
  5904. optionFlags);
  5905. }
  5906. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5907. const String& suffix, const int optionFlags)
  5908. {
  5909. if ((optionFlags & useHiddenFile) != 0)
  5910. name = T(".") + name;
  5911. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5912. }
  5913. TemporaryFile::~TemporaryFile()
  5914. {
  5915. // Have a few attempts at deleting the file before giving up..
  5916. for (int i = 5; --i >= 0;)
  5917. {
  5918. if (temporaryFile.deleteFile())
  5919. return;
  5920. Thread::sleep (50);
  5921. }
  5922. // Failed to delete our temporary file! Check that you've deleted all the
  5923. // file output streams that were using it!
  5924. jassertfalse;
  5925. }
  5926. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5927. {
  5928. // This method only works if you created this object with the constructor
  5929. // that takes a target file!
  5930. jassert (targetFile != File::nonexistent);
  5931. if (temporaryFile.exists())
  5932. {
  5933. // Have a few attempts at overwriting the file before giving up..
  5934. for (int i = 5; --i >= 0;)
  5935. {
  5936. if (temporaryFile.moveFileTo (targetFile))
  5937. return true;
  5938. Thread::sleep (100);
  5939. }
  5940. // Failed to overwrite the new file! Make sure you've not left any
  5941. // file streams hanging around when you call this method!
  5942. jassertfalse
  5943. }
  5944. else
  5945. {
  5946. // There's no temporary file to use. If your write failed, you should
  5947. // probably check, and not bother calling this method.
  5948. jassertfalse
  5949. }
  5950. return false;
  5951. }
  5952. END_JUCE_NAMESPACE
  5953. /*** End of inlined file: juce_TemporaryFile.cpp ***/
  5954. /*** Start of inlined file: juce_Socket.cpp ***/
  5955. #if JUCE_WINDOWS
  5956. #include <winsock2.h>
  5957. #ifdef _MSC_VER
  5958. #pragma warning (disable : 4127 4389 4018)
  5959. #endif
  5960. #else
  5961. #if JUCE_LINUX
  5962. #include <sys/types.h>
  5963. #include <sys/socket.h>
  5964. #include <sys/errno.h>
  5965. #include <unistd.h>
  5966. #include <netinet/in.h>
  5967. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5968. #include <CoreServices/CoreServices.h>
  5969. #endif
  5970. #include <fcntl.h>
  5971. #include <netdb.h>
  5972. #include <arpa/inet.h>
  5973. #include <netinet/tcp.h>
  5974. #endif
  5975. BEGIN_JUCE_NAMESPACE
  5976. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5977. typedef socklen_t juce_socklen_t;
  5978. #else
  5979. typedef int juce_socklen_t;
  5980. #endif
  5981. #if JUCE_WINDOWS
  5982. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5983. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5984. static void initWin32Sockets()
  5985. {
  5986. static CriticalSection lock;
  5987. const ScopedLock sl (lock);
  5988. if (juce_CloseWin32SocketLib == 0)
  5989. {
  5990. WSADATA wsaData;
  5991. const WORD wVersionRequested = MAKEWORD (1, 1);
  5992. WSAStartup (wVersionRequested, &wsaData);
  5993. juce_CloseWin32SocketLib = &WSACleanup;
  5994. }
  5995. }
  5996. #endif
  5997. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5998. {
  5999. const int sndBufSize = 65536;
  6000. const int rcvBufSize = 65536;
  6001. const int one = 1;
  6002. return handle > 0
  6003. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  6004. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  6005. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  6006. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  6007. }
  6008. static bool bindSocketToPort (const int handle, const int port) throw()
  6009. {
  6010. if (handle <= 0 || port <= 0)
  6011. return false;
  6012. struct sockaddr_in servTmpAddr;
  6013. zerostruct (servTmpAddr);
  6014. servTmpAddr.sin_family = PF_INET;
  6015. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6016. servTmpAddr.sin_port = htons ((uint16) port);
  6017. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  6018. }
  6019. static int readSocket (const int handle,
  6020. void* const destBuffer, const int maxBytesToRead,
  6021. bool volatile& connected,
  6022. const bool blockUntilSpecifiedAmountHasArrived) throw()
  6023. {
  6024. int bytesRead = 0;
  6025. while (bytesRead < maxBytesToRead)
  6026. {
  6027. int bytesThisTime;
  6028. #if JUCE_WINDOWS
  6029. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  6030. #else
  6031. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  6032. && errno == EINTR
  6033. && connected)
  6034. {
  6035. }
  6036. #endif
  6037. if (bytesThisTime <= 0 || ! connected)
  6038. {
  6039. if (bytesRead == 0)
  6040. bytesRead = -1;
  6041. break;
  6042. }
  6043. bytesRead += bytesThisTime;
  6044. if (! blockUntilSpecifiedAmountHasArrived)
  6045. break;
  6046. }
  6047. return bytesRead;
  6048. }
  6049. static int waitForReadiness (const int handle, const bool forReading,
  6050. const int timeoutMsecs) throw()
  6051. {
  6052. struct timeval timeout;
  6053. struct timeval* timeoutp;
  6054. if (timeoutMsecs >= 0)
  6055. {
  6056. timeout.tv_sec = timeoutMsecs / 1000;
  6057. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  6058. timeoutp = &timeout;
  6059. }
  6060. else
  6061. {
  6062. timeoutp = 0;
  6063. }
  6064. fd_set rset, wset;
  6065. FD_ZERO (&rset);
  6066. FD_SET (handle, &rset);
  6067. FD_ZERO (&wset);
  6068. FD_SET (handle, &wset);
  6069. fd_set* const prset = forReading ? &rset : 0;
  6070. fd_set* const pwset = forReading ? 0 : &wset;
  6071. #if JUCE_WINDOWS
  6072. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  6073. return -1;
  6074. #else
  6075. {
  6076. int result;
  6077. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  6078. && errno == EINTR)
  6079. {
  6080. }
  6081. if (result < 0)
  6082. return -1;
  6083. }
  6084. #endif
  6085. {
  6086. int opt;
  6087. juce_socklen_t len = sizeof (opt);
  6088. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  6089. || opt != 0)
  6090. return -1;
  6091. }
  6092. if ((forReading && FD_ISSET (handle, &rset))
  6093. || ((! forReading) && FD_ISSET (handle, &wset)))
  6094. return 1;
  6095. return 0;
  6096. }
  6097. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  6098. {
  6099. #if JUCE_WINDOWS
  6100. u_long nonBlocking = shouldBlock ? 0 : 1;
  6101. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  6102. return false;
  6103. #else
  6104. int socketFlags = fcntl (handle, F_GETFL, 0);
  6105. if (socketFlags == -1)
  6106. return false;
  6107. if (shouldBlock)
  6108. socketFlags &= ~O_NONBLOCK;
  6109. else
  6110. socketFlags |= O_NONBLOCK;
  6111. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  6112. return false;
  6113. #endif
  6114. return true;
  6115. }
  6116. static bool connectSocket (int volatile& handle,
  6117. const bool isDatagram,
  6118. void** serverAddress,
  6119. const String& hostName,
  6120. const int portNumber,
  6121. const int timeOutMillisecs) throw()
  6122. {
  6123. struct hostent* const hostEnt = gethostbyname (hostName);
  6124. if (hostEnt == 0)
  6125. return false;
  6126. struct in_addr targetAddress;
  6127. memcpy (&targetAddress.s_addr,
  6128. *(hostEnt->h_addr_list),
  6129. sizeof (targetAddress.s_addr));
  6130. struct sockaddr_in servTmpAddr;
  6131. zerostruct (servTmpAddr);
  6132. servTmpAddr.sin_family = PF_INET;
  6133. servTmpAddr.sin_addr = targetAddress;
  6134. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6135. if (handle < 0)
  6136. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  6137. if (handle < 0)
  6138. return false;
  6139. if (isDatagram)
  6140. {
  6141. *serverAddress = new struct sockaddr_in();
  6142. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  6143. return true;
  6144. }
  6145. setSocketBlockingState (handle, false);
  6146. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  6147. if (result < 0)
  6148. {
  6149. #if JUCE_WINDOWS
  6150. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  6151. #else
  6152. if (errno == EINPROGRESS)
  6153. #endif
  6154. {
  6155. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  6156. {
  6157. setSocketBlockingState (handle, true);
  6158. return false;
  6159. }
  6160. }
  6161. }
  6162. setSocketBlockingState (handle, true);
  6163. resetSocketOptions (handle, false, false);
  6164. return true;
  6165. }
  6166. StreamingSocket::StreamingSocket()
  6167. : portNumber (0),
  6168. handle (-1),
  6169. connected (false),
  6170. isListener (false)
  6171. {
  6172. #if JUCE_WINDOWS
  6173. initWin32Sockets();
  6174. #endif
  6175. }
  6176. StreamingSocket::StreamingSocket (const String& hostName_,
  6177. const int portNumber_,
  6178. const int handle_)
  6179. : hostName (hostName_),
  6180. portNumber (portNumber_),
  6181. handle (handle_),
  6182. connected (true),
  6183. isListener (false)
  6184. {
  6185. #if JUCE_WINDOWS
  6186. initWin32Sockets();
  6187. #endif
  6188. resetSocketOptions (handle_, false, false);
  6189. }
  6190. StreamingSocket::~StreamingSocket()
  6191. {
  6192. close();
  6193. }
  6194. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6195. {
  6196. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6197. : -1;
  6198. }
  6199. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6200. {
  6201. if (isListener || ! connected)
  6202. return -1;
  6203. #if JUCE_WINDOWS
  6204. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  6205. #else
  6206. int result;
  6207. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  6208. && errno == EINTR)
  6209. {
  6210. }
  6211. return result;
  6212. #endif
  6213. }
  6214. int StreamingSocket::waitUntilReady (const bool readyForReading,
  6215. const int timeoutMsecs) const
  6216. {
  6217. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6218. : -1;
  6219. }
  6220. bool StreamingSocket::bindToPort (const int port)
  6221. {
  6222. return bindSocketToPort (handle, port);
  6223. }
  6224. bool StreamingSocket::connect (const String& remoteHostName,
  6225. const int remotePortNumber,
  6226. const int timeOutMillisecs)
  6227. {
  6228. if (isListener)
  6229. {
  6230. jassertfalse // a listener socket can't connect to another one!
  6231. return false;
  6232. }
  6233. if (connected)
  6234. close();
  6235. hostName = remoteHostName;
  6236. portNumber = remotePortNumber;
  6237. isListener = false;
  6238. connected = connectSocket (handle, false, 0, remoteHostName,
  6239. remotePortNumber, timeOutMillisecs);
  6240. if (! (connected && resetSocketOptions (handle, false, false)))
  6241. {
  6242. close();
  6243. return false;
  6244. }
  6245. return true;
  6246. }
  6247. void StreamingSocket::close()
  6248. {
  6249. #if JUCE_WINDOWS
  6250. closesocket (handle);
  6251. connected = false;
  6252. #else
  6253. if (connected)
  6254. {
  6255. connected = false;
  6256. if (isListener)
  6257. {
  6258. // need to do this to interrupt the accept() function..
  6259. StreamingSocket temp;
  6260. temp.connect ("localhost", portNumber, 1000);
  6261. }
  6262. }
  6263. ::close (handle);
  6264. #endif
  6265. hostName = String::empty;
  6266. portNumber = 0;
  6267. handle = -1;
  6268. isListener = false;
  6269. }
  6270. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6271. {
  6272. if (connected)
  6273. close();
  6274. hostName = "listener";
  6275. portNumber = newPortNumber;
  6276. isListener = true;
  6277. struct sockaddr_in servTmpAddr;
  6278. zerostruct (servTmpAddr);
  6279. servTmpAddr.sin_family = PF_INET;
  6280. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6281. if (localHostName.isNotEmpty())
  6282. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6283. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6284. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6285. if (handle < 0)
  6286. return false;
  6287. const int reuse = 1;
  6288. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6289. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6290. || listen (handle, SOMAXCONN) < 0)
  6291. {
  6292. close();
  6293. return false;
  6294. }
  6295. connected = true;
  6296. return true;
  6297. }
  6298. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6299. {
  6300. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6301. // prepare this socket as a listener.
  6302. if (connected && isListener)
  6303. {
  6304. struct sockaddr address;
  6305. juce_socklen_t len = sizeof (sockaddr);
  6306. const int newSocket = (int) accept (handle, &address, &len);
  6307. if (newSocket >= 0 && connected)
  6308. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6309. portNumber, newSocket);
  6310. }
  6311. return 0;
  6312. }
  6313. bool StreamingSocket::isLocal() const throw()
  6314. {
  6315. return hostName == T("127.0.0.1");
  6316. }
  6317. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6318. : portNumber (0),
  6319. handle (-1),
  6320. connected (true),
  6321. allowBroadcast (allowBroadcast_),
  6322. serverAddress (0)
  6323. {
  6324. #if JUCE_WINDOWS
  6325. initWin32Sockets();
  6326. #endif
  6327. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6328. bindToPort (localPortNumber);
  6329. }
  6330. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6331. const int handle_, const int localPortNumber)
  6332. : hostName (hostName_),
  6333. portNumber (portNumber_),
  6334. handle (handle_),
  6335. connected (true),
  6336. allowBroadcast (false),
  6337. serverAddress (0)
  6338. {
  6339. #if JUCE_WINDOWS
  6340. initWin32Sockets();
  6341. #endif
  6342. resetSocketOptions (handle_, true, allowBroadcast);
  6343. bindToPort (localPortNumber);
  6344. }
  6345. DatagramSocket::~DatagramSocket()
  6346. {
  6347. close();
  6348. delete ((struct sockaddr_in*) serverAddress);
  6349. serverAddress = 0;
  6350. }
  6351. void DatagramSocket::close()
  6352. {
  6353. #if JUCE_WINDOWS
  6354. closesocket (handle);
  6355. connected = false;
  6356. #else
  6357. connected = false;
  6358. ::close (handle);
  6359. #endif
  6360. hostName = String::empty;
  6361. portNumber = 0;
  6362. handle = -1;
  6363. }
  6364. bool DatagramSocket::bindToPort (const int port)
  6365. {
  6366. return bindSocketToPort (handle, port);
  6367. }
  6368. bool DatagramSocket::connect (const String& remoteHostName,
  6369. const int remotePortNumber,
  6370. const int timeOutMillisecs)
  6371. {
  6372. if (connected)
  6373. close();
  6374. hostName = remoteHostName;
  6375. portNumber = remotePortNumber;
  6376. connected = connectSocket (handle, true, &serverAddress,
  6377. remoteHostName, remotePortNumber,
  6378. timeOutMillisecs);
  6379. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6380. {
  6381. close();
  6382. return false;
  6383. }
  6384. return true;
  6385. }
  6386. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6387. {
  6388. struct sockaddr address;
  6389. juce_socklen_t len = sizeof (sockaddr);
  6390. while (waitUntilReady (true, -1) == 1)
  6391. {
  6392. char buf[1];
  6393. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6394. {
  6395. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6396. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6397. -1, -1);
  6398. }
  6399. }
  6400. return 0;
  6401. }
  6402. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6403. const int timeoutMsecs) const
  6404. {
  6405. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6406. : -1;
  6407. }
  6408. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6409. {
  6410. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6411. : -1;
  6412. }
  6413. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6414. {
  6415. // You need to call connect() first to set the server address..
  6416. jassert (serverAddress != 0 && connected);
  6417. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6418. numBytesToWrite, 0,
  6419. (const struct sockaddr*) serverAddress,
  6420. sizeof (struct sockaddr_in))
  6421. : -1;
  6422. }
  6423. bool DatagramSocket::isLocal() const throw()
  6424. {
  6425. return hostName == T("127.0.0.1");
  6426. }
  6427. END_JUCE_NAMESPACE
  6428. /*** End of inlined file: juce_Socket.cpp ***/
  6429. /*** Start of inlined file: juce_URL.cpp ***/
  6430. BEGIN_JUCE_NAMESPACE
  6431. URL::URL()
  6432. {
  6433. }
  6434. URL::URL (const String& url_)
  6435. : url (url_)
  6436. {
  6437. int i = url.indexOfChar (T('?'));
  6438. if (i >= 0)
  6439. {
  6440. do
  6441. {
  6442. const int nextAmp = url.indexOfChar (i + 1, T('&'));
  6443. const int equalsPos = url.indexOfChar (i + 1, T('='));
  6444. if (equalsPos > i + 1)
  6445. {
  6446. if (nextAmp < 0)
  6447. {
  6448. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6449. removeEscapeChars (url.substring (equalsPos + 1)));
  6450. }
  6451. else if (nextAmp > 0 && equalsPos < nextAmp)
  6452. {
  6453. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6454. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6455. }
  6456. }
  6457. i = nextAmp;
  6458. }
  6459. while (i >= 0);
  6460. url = url.upToFirstOccurrenceOf (T("?"), false, false);
  6461. }
  6462. }
  6463. URL::URL (const URL& other)
  6464. : url (other.url),
  6465. postData (other.postData),
  6466. parameters (other.parameters),
  6467. filesToUpload (other.filesToUpload),
  6468. mimeTypes (other.mimeTypes)
  6469. {
  6470. }
  6471. const URL& URL::operator= (const URL& other)
  6472. {
  6473. url = other.url;
  6474. postData = other.postData;
  6475. parameters = other.parameters;
  6476. filesToUpload = other.filesToUpload;
  6477. mimeTypes = other.mimeTypes;
  6478. return *this;
  6479. }
  6480. URL::~URL()
  6481. {
  6482. }
  6483. static const String getMangledParameters (const StringPairArray& parameters)
  6484. {
  6485. String p;
  6486. for (int i = 0; i < parameters.size(); ++i)
  6487. {
  6488. if (i > 0)
  6489. p += T("&");
  6490. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6491. << T("=")
  6492. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6493. }
  6494. return p;
  6495. }
  6496. const String URL::toString (const bool includeGetParameters) const
  6497. {
  6498. if (includeGetParameters && parameters.size() > 0)
  6499. return url + T("?") + getMangledParameters (parameters);
  6500. else
  6501. return url;
  6502. }
  6503. bool URL::isWellFormed() const
  6504. {
  6505. //xxx TODO
  6506. return url.isNotEmpty();
  6507. }
  6508. static int findStartOfDomain (const String& url)
  6509. {
  6510. int i = 0;
  6511. while (CharacterFunctions::isLetterOrDigit (url[i])
  6512. || CharacterFunctions::indexOfChar (T("+-."), url[i], false) >= 0)
  6513. ++i;
  6514. return url[i] == T(':') ? i + 1 : 0;
  6515. }
  6516. const String URL::getDomain() const
  6517. {
  6518. int start = findStartOfDomain (url);
  6519. while (url[start] == T('/'))
  6520. ++start;
  6521. const int end1 = url.indexOfChar (start, T('/'));
  6522. const int end2 = url.indexOfChar (start, T(':'));
  6523. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6524. : jmin (end1, end2);
  6525. return url.substring (start, end);
  6526. }
  6527. const String URL::getSubPath() const
  6528. {
  6529. int start = findStartOfDomain (url);
  6530. while (url[start] == T('/'))
  6531. ++start;
  6532. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6533. return startOfPath <= 0 ? String::empty
  6534. : url.substring (startOfPath);
  6535. }
  6536. const String URL::getScheme() const
  6537. {
  6538. return url.substring (0, findStartOfDomain (url) - 1);
  6539. }
  6540. const URL URL::withNewSubPath (const String& newPath) const
  6541. {
  6542. int start = findStartOfDomain (url);
  6543. while (url[start] == T('/'))
  6544. ++start;
  6545. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6546. URL u (*this);
  6547. if (startOfPath > 0)
  6548. u.url = url.substring (0, startOfPath);
  6549. if (! u.url.endsWithChar (T('/')))
  6550. u.url << '/';
  6551. if (newPath.startsWithChar (T('/')))
  6552. u.url << newPath.substring (1);
  6553. else
  6554. u.url << newPath;
  6555. return u;
  6556. }
  6557. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6558. {
  6559. if (possibleURL.startsWithIgnoreCase (T("http:"))
  6560. || possibleURL.startsWithIgnoreCase (T("ftp:")))
  6561. return true;
  6562. if (possibleURL.startsWithIgnoreCase (T("file:"))
  6563. || possibleURL.containsChar (T('@'))
  6564. || possibleURL.endsWithChar (T('.'))
  6565. || (! possibleURL.containsChar (T('.'))))
  6566. return false;
  6567. if (possibleURL.startsWithIgnoreCase (T("www."))
  6568. && possibleURL.substring (5).containsChar (T('.')))
  6569. return true;
  6570. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6571. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6572. if ((possibleURL + T("/")).containsIgnoreCase (T(".") + String (commonTLDs[i]) + T("/")))
  6573. return true;
  6574. return false;
  6575. }
  6576. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6577. {
  6578. const int atSign = possibleEmailAddress.indexOfChar (T('@'));
  6579. return atSign > 0
  6580. && possibleEmailAddress.lastIndexOfChar (T('.')) > (atSign + 1)
  6581. && (! possibleEmailAddress.endsWithChar (T('.')));
  6582. }
  6583. void* juce_openInternetFile (const String& url,
  6584. const String& headers,
  6585. const MemoryBlock& optionalPostData,
  6586. const bool isPost,
  6587. URL::OpenStreamProgressCallback* callback,
  6588. void* callbackContext,
  6589. int timeOutMs);
  6590. void juce_closeInternetFile (void* handle);
  6591. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6592. int juce_seekInInternetFile (void* handle, int newPosition);
  6593. int64 juce_getInternetFileContentLength (void* handle);
  6594. class WebInputStream : public InputStream
  6595. {
  6596. public:
  6597. WebInputStream (const URL& url,
  6598. const bool isPost_,
  6599. URL::OpenStreamProgressCallback* const progressCallback_,
  6600. void* const progressCallbackContext_,
  6601. const String& extraHeaders,
  6602. int timeOutMs_)
  6603. : position (0),
  6604. finished (false),
  6605. isPost (isPost_),
  6606. progressCallback (progressCallback_),
  6607. progressCallbackContext (progressCallbackContext_),
  6608. timeOutMs (timeOutMs_)
  6609. {
  6610. server = url.toString (! isPost);
  6611. if (isPost_)
  6612. createHeadersAndPostData (url);
  6613. headers += extraHeaders;
  6614. if (! headers.endsWithChar (T('\n')))
  6615. headers << "\r\n";
  6616. handle = juce_openInternetFile (server, headers, postData, isPost,
  6617. progressCallback_, progressCallbackContext_,
  6618. timeOutMs);
  6619. }
  6620. ~WebInputStream()
  6621. {
  6622. juce_closeInternetFile (handle);
  6623. }
  6624. bool isError() const
  6625. {
  6626. return handle == 0;
  6627. }
  6628. int64 getTotalLength()
  6629. {
  6630. return juce_getInternetFileContentLength (handle);
  6631. }
  6632. bool isExhausted()
  6633. {
  6634. return finished;
  6635. }
  6636. int read (void* dest, int bytes)
  6637. {
  6638. if (finished || isError())
  6639. {
  6640. return 0;
  6641. }
  6642. else
  6643. {
  6644. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6645. position += bytesRead;
  6646. if (bytesRead == 0)
  6647. finished = true;
  6648. return bytesRead;
  6649. }
  6650. }
  6651. int64 getPosition()
  6652. {
  6653. return position;
  6654. }
  6655. bool setPosition (int64 wantedPos)
  6656. {
  6657. if (wantedPos != position)
  6658. {
  6659. finished = false;
  6660. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6661. if (actualPos == wantedPos)
  6662. {
  6663. position = wantedPos;
  6664. }
  6665. else
  6666. {
  6667. if (wantedPos < position)
  6668. {
  6669. juce_closeInternetFile (handle);
  6670. position = 0;
  6671. finished = false;
  6672. handle = juce_openInternetFile (server, headers, postData, isPost,
  6673. progressCallback, progressCallbackContext,
  6674. timeOutMs);
  6675. }
  6676. skipNextBytes (wantedPos - position);
  6677. }
  6678. }
  6679. return true;
  6680. }
  6681. juce_UseDebuggingNewOperator
  6682. private:
  6683. String server, headers;
  6684. MemoryBlock postData;
  6685. int64 position;
  6686. bool finished;
  6687. const bool isPost;
  6688. void* handle;
  6689. URL::OpenStreamProgressCallback* const progressCallback;
  6690. void* const progressCallbackContext;
  6691. const int timeOutMs;
  6692. void createHeadersAndPostData (const URL& url)
  6693. {
  6694. if (url.getFilesToUpload().size() > 0)
  6695. {
  6696. // need to upload some files, so do it as multi-part...
  6697. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6698. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6699. appendUTF8ToPostData ("--" + boundary);
  6700. int i;
  6701. for (i = 0; i < url.getParameters().size(); ++i)
  6702. {
  6703. String s;
  6704. s << "\r\nContent-Disposition: form-data; name=\""
  6705. << url.getParameters().getAllKeys() [i]
  6706. << "\"\r\n\r\n"
  6707. << url.getParameters().getAllValues() [i]
  6708. << "\r\n--"
  6709. << boundary;
  6710. appendUTF8ToPostData (s);
  6711. }
  6712. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6713. {
  6714. const File f (url.getFilesToUpload().getAllValues() [i]);
  6715. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6716. String s;
  6717. s << "\r\nContent-Disposition: form-data; name=\""
  6718. << paramName
  6719. << "\"; filename=\""
  6720. << f.getFileName()
  6721. << "\"\r\n";
  6722. const String mimeType (url.getMimeTypesOfUploadFiles()
  6723. .getValue (paramName, String::empty));
  6724. if (mimeType.isNotEmpty())
  6725. s << "Content-Type: " << mimeType << "\r\n";
  6726. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6727. appendUTF8ToPostData (s);
  6728. f.loadFileAsData (postData);
  6729. s = "\r\n--" + boundary;
  6730. appendUTF8ToPostData (s);
  6731. }
  6732. appendUTF8ToPostData ("--\r\n");
  6733. }
  6734. else
  6735. {
  6736. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6737. appendUTF8ToPostData (url.getPostData());
  6738. // just a short text attachment, so use simple url encoding..
  6739. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6740. + String ((unsigned int) postData.getSize())
  6741. + "\r\n";
  6742. }
  6743. }
  6744. void appendUTF8ToPostData (const String& text)
  6745. {
  6746. postData.append (text.toUTF8(),
  6747. (int) strlen (text.toUTF8()));
  6748. }
  6749. WebInputStream (const WebInputStream&);
  6750. const WebInputStream& operator= (const WebInputStream&);
  6751. };
  6752. InputStream* URL::createInputStream (const bool usePostCommand,
  6753. OpenStreamProgressCallback* const progressCallback,
  6754. void* const progressCallbackContext,
  6755. const String& extraHeaders,
  6756. const int timeOutMs) const
  6757. {
  6758. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6759. progressCallback, progressCallbackContext,
  6760. extraHeaders,
  6761. timeOutMs));
  6762. return wi->isError() ? 0 : wi.release();
  6763. }
  6764. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6765. const bool usePostCommand) const
  6766. {
  6767. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6768. if (in != 0)
  6769. {
  6770. in->readIntoMemoryBlock (destData, -1);
  6771. return true;
  6772. }
  6773. return false;
  6774. }
  6775. const String URL::readEntireTextStream (const bool usePostCommand) const
  6776. {
  6777. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6778. if (in != 0)
  6779. return in->readEntireStreamAsString();
  6780. return String::empty;
  6781. }
  6782. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6783. {
  6784. XmlDocument doc (readEntireTextStream (usePostCommand));
  6785. return doc.getDocumentElement();
  6786. }
  6787. const URL URL::withParameter (const String& parameterName,
  6788. const String& parameterValue) const
  6789. {
  6790. URL u (*this);
  6791. u.parameters.set (parameterName, parameterValue);
  6792. return u;
  6793. }
  6794. const URL URL::withFileToUpload (const String& parameterName,
  6795. const File& fileToUpload,
  6796. const String& mimeType) const
  6797. {
  6798. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6799. URL u (*this);
  6800. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6801. u.mimeTypes.set (parameterName, mimeType);
  6802. return u;
  6803. }
  6804. const URL URL::withPOSTData (const String& postData_) const
  6805. {
  6806. URL u (*this);
  6807. u.postData = postData_;
  6808. return u;
  6809. }
  6810. const StringPairArray& URL::getParameters() const
  6811. {
  6812. return parameters;
  6813. }
  6814. const StringPairArray& URL::getFilesToUpload() const
  6815. {
  6816. return filesToUpload;
  6817. }
  6818. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6819. {
  6820. return mimeTypes;
  6821. }
  6822. const String URL::removeEscapeChars (const String& s)
  6823. {
  6824. const int len = s.length();
  6825. HeapBlock <uint8> resultUTF8 (len * 4);
  6826. uint8* r = resultUTF8;
  6827. for (int i = 0; i < len; ++i)
  6828. {
  6829. char c = (char) s[i];
  6830. if (c == 0)
  6831. break;
  6832. if (c == '+')
  6833. {
  6834. c = ' ';
  6835. }
  6836. else if (c == '%')
  6837. {
  6838. c = (char) s.substring (i + 1, i + 3).getHexValue32();
  6839. i += 2;
  6840. }
  6841. *r++ = c;
  6842. }
  6843. return String::fromUTF8 (resultUTF8);
  6844. }
  6845. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6846. {
  6847. String result;
  6848. result.preallocateStorage (s.length() + 8);
  6849. const char* utf8 = s.toUTF8();
  6850. const char* legalChars = isParameter ? "_-.*!'()"
  6851. : "_-$.*!'(),";
  6852. while (*utf8 != 0)
  6853. {
  6854. const char c = *utf8++;
  6855. if (CharacterFunctions::isLetterOrDigit (c)
  6856. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6857. {
  6858. result << c;
  6859. }
  6860. else
  6861. {
  6862. const int v = (int) (uint8) c;
  6863. if (v < 0x10)
  6864. result << T("%0");
  6865. else
  6866. result << T('%');
  6867. result << String::toHexString (v);
  6868. }
  6869. }
  6870. return result;
  6871. }
  6872. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6873. bool URL::launchInDefaultBrowser() const
  6874. {
  6875. String u (toString (true));
  6876. if (u.contains (T("@")) && ! u.contains (T(":")))
  6877. u = "mailto:" + u;
  6878. return juce_launchFile (u, String::empty);
  6879. }
  6880. END_JUCE_NAMESPACE
  6881. /*** End of inlined file: juce_URL.cpp ***/
  6882. /*** Start of inlined file: juce_BufferedInputStream.cpp ***/
  6883. BEGIN_JUCE_NAMESPACE
  6884. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6885. const int bufferSize_,
  6886. const bool deleteSourceWhenDestroyed)
  6887. : source (source_),
  6888. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6889. bufferSize (jmax (256, bufferSize_)),
  6890. position (source_->getPosition()),
  6891. lastReadPos (0),
  6892. bufferOverlap (128)
  6893. {
  6894. const int sourceSize = (int) source_->getTotalLength();
  6895. if (sourceSize >= 0)
  6896. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6897. bufferStart = position;
  6898. buffer.malloc (bufferSize);
  6899. }
  6900. BufferedInputStream::~BufferedInputStream()
  6901. {
  6902. }
  6903. int64 BufferedInputStream::getTotalLength()
  6904. {
  6905. return source->getTotalLength();
  6906. }
  6907. int64 BufferedInputStream::getPosition()
  6908. {
  6909. return position;
  6910. }
  6911. bool BufferedInputStream::setPosition (int64 newPosition)
  6912. {
  6913. position = jmax ((int64) 0, newPosition);
  6914. return true;
  6915. }
  6916. bool BufferedInputStream::isExhausted()
  6917. {
  6918. return (position >= lastReadPos)
  6919. && source->isExhausted();
  6920. }
  6921. void BufferedInputStream::ensureBuffered()
  6922. {
  6923. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6924. if (position < bufferStart || position >= bufferEndOverlap)
  6925. {
  6926. int bytesRead;
  6927. if (position < lastReadPos
  6928. && position >= bufferEndOverlap
  6929. && position >= bufferStart)
  6930. {
  6931. const int bytesToKeep = (int) (lastReadPos - position);
  6932. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6933. bufferStart = position;
  6934. bytesRead = source->read (buffer + bytesToKeep,
  6935. bufferSize - bytesToKeep);
  6936. lastReadPos += bytesRead;
  6937. bytesRead += bytesToKeep;
  6938. }
  6939. else
  6940. {
  6941. bufferStart = position;
  6942. source->setPosition (bufferStart);
  6943. bytesRead = source->read (buffer, bufferSize);
  6944. lastReadPos = bufferStart + bytesRead;
  6945. }
  6946. while (bytesRead < bufferSize)
  6947. buffer [bytesRead++] = 0;
  6948. }
  6949. }
  6950. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6951. {
  6952. if (position >= bufferStart
  6953. && position + maxBytesToRead <= lastReadPos)
  6954. {
  6955. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6956. position += maxBytesToRead;
  6957. return maxBytesToRead;
  6958. }
  6959. else
  6960. {
  6961. if (position < bufferStart || position >= lastReadPos)
  6962. ensureBuffered();
  6963. int bytesRead = 0;
  6964. while (maxBytesToRead > 0)
  6965. {
  6966. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6967. if (bytesAvailable > 0)
  6968. {
  6969. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6970. maxBytesToRead -= bytesAvailable;
  6971. bytesRead += bytesAvailable;
  6972. position += bytesAvailable;
  6973. destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
  6974. }
  6975. const int64 oldLastReadPos = lastReadPos;
  6976. ensureBuffered();
  6977. if (oldLastReadPos == lastReadPos)
  6978. break; // if ensureBuffered() failed to read any more data, bail out
  6979. if (isExhausted())
  6980. break;
  6981. }
  6982. return bytesRead;
  6983. }
  6984. }
  6985. const String BufferedInputStream::readString()
  6986. {
  6987. if (position >= bufferStart
  6988. && position < lastReadPos)
  6989. {
  6990. const int maxChars = (int) (lastReadPos - position);
  6991. const char* const src = buffer + (int) (position - bufferStart);
  6992. for (int i = 0; i < maxChars; ++i)
  6993. {
  6994. if (src[i] == 0)
  6995. {
  6996. position += i + 1;
  6997. return String::fromUTF8 ((const uint8*) src, i);
  6998. }
  6999. }
  7000. }
  7001. return InputStream::readString();
  7002. }
  7003. END_JUCE_NAMESPACE
  7004. /*** End of inlined file: juce_BufferedInputStream.cpp ***/
  7005. /*** Start of inlined file: juce_FileInputSource.cpp ***/
  7006. BEGIN_JUCE_NAMESPACE
  7007. FileInputSource::FileInputSource (const File& file_)
  7008. : file (file_)
  7009. {
  7010. }
  7011. FileInputSource::~FileInputSource()
  7012. {
  7013. }
  7014. InputStream* FileInputSource::createInputStream()
  7015. {
  7016. return file.createInputStream();
  7017. }
  7018. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  7019. {
  7020. return file.getSiblingFile (relatedItemPath).createInputStream();
  7021. }
  7022. int64 FileInputSource::hashCode() const
  7023. {
  7024. return file.hashCode();
  7025. }
  7026. END_JUCE_NAMESPACE
  7027. /*** End of inlined file: juce_FileInputSource.cpp ***/
  7028. /*** Start of inlined file: juce_MemoryInputStream.cpp ***/
  7029. BEGIN_JUCE_NAMESPACE
  7030. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  7031. const size_t sourceDataSize,
  7032. const bool keepInternalCopy)
  7033. : data ((const char*) sourceData),
  7034. dataSize (sourceDataSize),
  7035. position (0)
  7036. {
  7037. if (keepInternalCopy)
  7038. {
  7039. internalCopy.append (data, sourceDataSize);
  7040. data = (const char*) internalCopy.getData();
  7041. }
  7042. }
  7043. MemoryInputStream::~MemoryInputStream()
  7044. {
  7045. }
  7046. int64 MemoryInputStream::getTotalLength()
  7047. {
  7048. return dataSize;
  7049. }
  7050. int MemoryInputStream::read (void* buffer, int howMany)
  7051. {
  7052. jassert (howMany >= 0);
  7053. const int num = jmin (howMany, (int) (dataSize - position));
  7054. memcpy (buffer, data + position, num);
  7055. position += num;
  7056. return (int) num;
  7057. }
  7058. bool MemoryInputStream::isExhausted()
  7059. {
  7060. return (position >= dataSize);
  7061. }
  7062. bool MemoryInputStream::setPosition (int64 pos)
  7063. {
  7064. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  7065. return true;
  7066. }
  7067. int64 MemoryInputStream::getPosition()
  7068. {
  7069. return position;
  7070. }
  7071. END_JUCE_NAMESPACE
  7072. /*** End of inlined file: juce_MemoryInputStream.cpp ***/
  7073. /*** Start of inlined file: juce_MemoryOutputStream.cpp ***/
  7074. BEGIN_JUCE_NAMESPACE
  7075. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  7076. const size_t blockSizeToIncreaseBy,
  7077. MemoryBlock* const memoryBlockToWriteTo) throw()
  7078. : data (memoryBlockToWriteTo),
  7079. position (0),
  7080. size (0),
  7081. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  7082. {
  7083. if (data == 0)
  7084. dataToDelete = data = new MemoryBlock (initialSize);
  7085. else
  7086. data->setSize (initialSize, false);
  7087. }
  7088. MemoryOutputStream::~MemoryOutputStream() throw()
  7089. {
  7090. flush();
  7091. }
  7092. void MemoryOutputStream::flush()
  7093. {
  7094. if (dataToDelete == 0)
  7095. data->setSize (size, false);
  7096. }
  7097. void MemoryOutputStream::reset() throw()
  7098. {
  7099. position = 0;
  7100. size = 0;
  7101. }
  7102. bool MemoryOutputStream::write (const void* buffer, int howMany)
  7103. {
  7104. if (howMany > 0)
  7105. {
  7106. size_t storageNeeded = position + howMany;
  7107. if (storageNeeded >= data->getSize())
  7108. {
  7109. // if we need more space, increase the block by at least 10%..
  7110. storageNeeded += jmax (blockSize, storageNeeded / 10);
  7111. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  7112. data->ensureSize (storageNeeded);
  7113. }
  7114. data->copyFrom (buffer, (int) position, howMany);
  7115. position += howMany;
  7116. size = jmax (size, position);
  7117. }
  7118. return true;
  7119. }
  7120. const char* MemoryOutputStream::getData() const throw()
  7121. {
  7122. if (data->getSize() > size)
  7123. ((char*) data->getData()) [size] = 0;
  7124. return (const char*) data->getData();
  7125. }
  7126. size_t MemoryOutputStream::getDataSize() const throw()
  7127. {
  7128. return size;
  7129. }
  7130. int64 MemoryOutputStream::getPosition()
  7131. {
  7132. return position;
  7133. }
  7134. bool MemoryOutputStream::setPosition (int64 newPosition)
  7135. {
  7136. if (newPosition <= (int64) size)
  7137. {
  7138. // ok to seek backwards
  7139. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  7140. return true;
  7141. }
  7142. else
  7143. {
  7144. // trying to make it bigger isn't a good thing to do..
  7145. return false;
  7146. }
  7147. }
  7148. END_JUCE_NAMESPACE
  7149. /*** End of inlined file: juce_MemoryOutputStream.cpp ***/
  7150. /*** Start of inlined file: juce_SubregionStream.cpp ***/
  7151. BEGIN_JUCE_NAMESPACE
  7152. SubregionStream::SubregionStream (InputStream* const sourceStream,
  7153. const int64 startPositionInSourceStream_,
  7154. const int64 lengthOfSourceStream_,
  7155. const bool deleteSourceWhenDestroyed) throw()
  7156. : source (sourceStream),
  7157. startPositionInSourceStream (startPositionInSourceStream_),
  7158. lengthOfSourceStream (lengthOfSourceStream_)
  7159. {
  7160. if (deleteSourceWhenDestroyed)
  7161. sourceToDelete = source;
  7162. setPosition (0);
  7163. }
  7164. SubregionStream::~SubregionStream() throw()
  7165. {
  7166. }
  7167. int64 SubregionStream::getTotalLength()
  7168. {
  7169. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  7170. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  7171. : srcLen;
  7172. }
  7173. int64 SubregionStream::getPosition()
  7174. {
  7175. return source->getPosition() - startPositionInSourceStream;
  7176. }
  7177. bool SubregionStream::setPosition (int64 newPosition)
  7178. {
  7179. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  7180. }
  7181. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  7182. {
  7183. if (lengthOfSourceStream < 0)
  7184. {
  7185. return source->read (destBuffer, maxBytesToRead);
  7186. }
  7187. else
  7188. {
  7189. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  7190. if (maxBytesToRead <= 0)
  7191. return 0;
  7192. return source->read (destBuffer, maxBytesToRead);
  7193. }
  7194. }
  7195. bool SubregionStream::isExhausted()
  7196. {
  7197. if (lengthOfSourceStream >= 0)
  7198. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  7199. else
  7200. return source->isExhausted();
  7201. }
  7202. END_JUCE_NAMESPACE
  7203. /*** End of inlined file: juce_SubregionStream.cpp ***/
  7204. /*** Start of inlined file: juce_PerformanceCounter.cpp ***/
  7205. BEGIN_JUCE_NAMESPACE
  7206. PerformanceCounter::PerformanceCounter (const String& name_,
  7207. int runsPerPrintout,
  7208. const File& loggingFile)
  7209. : name (name_),
  7210. numRuns (0),
  7211. runsPerPrint (runsPerPrintout),
  7212. totalTime (0),
  7213. outputFile (loggingFile)
  7214. {
  7215. if (outputFile != File::nonexistent)
  7216. {
  7217. String s ("**** Counter for \"");
  7218. s << name_ << "\" started at: "
  7219. << Time::getCurrentTime().toString (true, true)
  7220. << "\r\n";
  7221. outputFile.appendText (s, false, false);
  7222. }
  7223. }
  7224. PerformanceCounter::~PerformanceCounter()
  7225. {
  7226. printStatistics();
  7227. }
  7228. void PerformanceCounter::start()
  7229. {
  7230. started = Time::getHighResolutionTicks();
  7231. }
  7232. void PerformanceCounter::stop()
  7233. {
  7234. const int64 now = Time::getHighResolutionTicks();
  7235. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7236. if (++numRuns == runsPerPrint)
  7237. printStatistics();
  7238. }
  7239. void PerformanceCounter::printStatistics()
  7240. {
  7241. if (numRuns > 0)
  7242. {
  7243. String s ("Performance count for \"");
  7244. s << name << "\" - average over " << numRuns << " run(s) = ";
  7245. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7246. if (micros > 10000)
  7247. s << (micros/1000) << " millisecs";
  7248. else
  7249. s << micros << " microsecs";
  7250. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7251. Logger::outputDebugString (s);
  7252. s << "\r\n";
  7253. if (outputFile != File::nonexistent)
  7254. outputFile.appendText (s, false, false);
  7255. numRuns = 0;
  7256. totalTime = 0;
  7257. }
  7258. }
  7259. END_JUCE_NAMESPACE
  7260. /*** End of inlined file: juce_PerformanceCounter.cpp ***/
  7261. /*** Start of inlined file: juce_Uuid.cpp ***/
  7262. BEGIN_JUCE_NAMESPACE
  7263. Uuid::Uuid()
  7264. {
  7265. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7266. // to make it very very unlikely that two UUIDs will ever be the same..
  7267. static int64 macAddresses[2];
  7268. static bool hasCheckedMacAddresses = false;
  7269. if (! hasCheckedMacAddresses)
  7270. {
  7271. hasCheckedMacAddresses = true;
  7272. SystemStats::getMACAddresses (macAddresses, 2);
  7273. }
  7274. value.asInt64[0] = macAddresses[0];
  7275. value.asInt64[1] = macAddresses[1];
  7276. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7277. // whose seed will carry over between calls to this method.
  7278. Random r (macAddresses[0] ^ macAddresses[1]
  7279. ^ Random::getSystemRandom().nextInt64());
  7280. for (int i = 4; --i >= 0;)
  7281. {
  7282. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7283. value.asInt[i] ^= r.nextInt();
  7284. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7285. }
  7286. }
  7287. Uuid::~Uuid() throw()
  7288. {
  7289. }
  7290. Uuid::Uuid (const Uuid& other)
  7291. : value (other.value)
  7292. {
  7293. }
  7294. Uuid& Uuid::operator= (const Uuid& other)
  7295. {
  7296. value = other.value;
  7297. return *this;
  7298. }
  7299. bool Uuid::operator== (const Uuid& other) const
  7300. {
  7301. return memcmp (value.asBytes, other.value.asBytes, 16) == 0;
  7302. }
  7303. bool Uuid::operator!= (const Uuid& other) const
  7304. {
  7305. return ! operator== (other);
  7306. }
  7307. bool Uuid::isNull() const throw()
  7308. {
  7309. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7310. }
  7311. const String Uuid::toString() const
  7312. {
  7313. return String::toHexString (value.asBytes, 16, 0);
  7314. }
  7315. Uuid::Uuid (const String& uuidString)
  7316. {
  7317. operator= (uuidString);
  7318. }
  7319. Uuid& Uuid::operator= (const String& uuidString)
  7320. {
  7321. int destIndex = 0;
  7322. int i = 0;
  7323. for (;;)
  7324. {
  7325. int byte = 0;
  7326. for (int loop = 2; --loop >= 0;)
  7327. {
  7328. byte <<= 4;
  7329. for (;;)
  7330. {
  7331. const tchar c = uuidString [i++];
  7332. if (c >= T('0') && c <= T('9'))
  7333. {
  7334. byte |= c - T('0');
  7335. break;
  7336. }
  7337. else if (c >= T('a') && c <= T('z'))
  7338. {
  7339. byte |= c - (T('a') - 10);
  7340. break;
  7341. }
  7342. else if (c >= T('A') && c <= T('Z'))
  7343. {
  7344. byte |= c - (T('A') - 10);
  7345. break;
  7346. }
  7347. else if (c == 0)
  7348. {
  7349. while (destIndex < 16)
  7350. value.asBytes [destIndex++] = 0;
  7351. return *this;
  7352. }
  7353. }
  7354. }
  7355. value.asBytes [destIndex++] = (uint8) byte;
  7356. }
  7357. }
  7358. Uuid::Uuid (const uint8* const rawData)
  7359. {
  7360. operator= (rawData);
  7361. }
  7362. Uuid& Uuid::operator= (const uint8* const rawData)
  7363. {
  7364. if (rawData != 0)
  7365. memcpy (value.asBytes, rawData, 16);
  7366. else
  7367. zeromem (value.asBytes, 16);
  7368. return *this;
  7369. }
  7370. END_JUCE_NAMESPACE
  7371. /*** End of inlined file: juce_Uuid.cpp ***/
  7372. /*** Start of inlined file: juce_ZipFile.cpp ***/
  7373. BEGIN_JUCE_NAMESPACE
  7374. class ZipFile::ZipEntryInfo
  7375. {
  7376. public:
  7377. ZipFile::ZipEntry entry;
  7378. int streamOffset;
  7379. int compressedSize;
  7380. bool compressed;
  7381. };
  7382. class ZipFile::ZipInputStream : public InputStream
  7383. {
  7384. public:
  7385. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7386. : file (file_),
  7387. zipEntryInfo (zei),
  7388. pos (0),
  7389. headerSize (0),
  7390. inputStream (0)
  7391. {
  7392. inputStream = file_.inputStream;
  7393. if (file_.inputSource != 0)
  7394. {
  7395. inputStream = file.inputSource->createInputStream();
  7396. }
  7397. else
  7398. {
  7399. #ifdef JUCE_DEBUG
  7400. file_.numOpenStreams++;
  7401. #endif
  7402. }
  7403. char buffer [30];
  7404. if (inputStream != 0
  7405. && inputStream->setPosition (zei.streamOffset)
  7406. && inputStream->read (buffer, 30) == 30
  7407. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7408. {
  7409. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7410. + ByteOrder::littleEndianShort (buffer + 28);
  7411. }
  7412. }
  7413. ~ZipInputStream() throw()
  7414. {
  7415. #ifdef JUCE_DEBUG
  7416. if (inputStream != 0 && inputStream == file.inputStream)
  7417. file.numOpenStreams--;
  7418. #endif
  7419. if (inputStream != file.inputStream)
  7420. delete inputStream;
  7421. }
  7422. int64 getTotalLength() throw()
  7423. {
  7424. return zipEntryInfo.compressedSize;
  7425. }
  7426. int read (void* buffer, int howMany) throw()
  7427. {
  7428. if (headerSize <= 0)
  7429. return 0;
  7430. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7431. if (inputStream == 0)
  7432. return 0;
  7433. int num;
  7434. if (inputStream == file.inputStream)
  7435. {
  7436. const ScopedLock sl (file.lock);
  7437. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7438. num = inputStream->read (buffer, howMany);
  7439. }
  7440. else
  7441. {
  7442. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7443. num = inputStream->read (buffer, howMany);
  7444. }
  7445. pos += num;
  7446. return num;
  7447. }
  7448. bool isExhausted() throw()
  7449. {
  7450. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7451. }
  7452. int64 getPosition() throw()
  7453. {
  7454. return pos;
  7455. }
  7456. bool setPosition (int64 newPos) throw()
  7457. {
  7458. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7459. return true;
  7460. }
  7461. private:
  7462. ZipFile& file;
  7463. ZipEntryInfo zipEntryInfo;
  7464. int64 pos;
  7465. int headerSize;
  7466. InputStream* inputStream;
  7467. ZipInputStream (const ZipInputStream&);
  7468. const ZipInputStream& operator= (const ZipInputStream&);
  7469. };
  7470. ZipFile::ZipFile (InputStream* const source_,
  7471. const bool deleteStreamWhenDestroyed) throw()
  7472. : inputStream (source_)
  7473. #ifdef JUCE_DEBUG
  7474. , numOpenStreams (0)
  7475. #endif
  7476. {
  7477. if (deleteStreamWhenDestroyed)
  7478. streamToDelete = inputStream;
  7479. init();
  7480. }
  7481. ZipFile::ZipFile (const File& file)
  7482. : inputStream (0)
  7483. #ifdef JUCE_DEBUG
  7484. , numOpenStreams (0)
  7485. #endif
  7486. {
  7487. inputSource = new FileInputSource (file);
  7488. init();
  7489. }
  7490. ZipFile::ZipFile (InputSource* const inputSource_)
  7491. : inputStream (0),
  7492. inputSource (inputSource_)
  7493. #ifdef JUCE_DEBUG
  7494. , numOpenStreams (0)
  7495. #endif
  7496. {
  7497. init();
  7498. }
  7499. ZipFile::~ZipFile() throw()
  7500. {
  7501. #ifdef JUCE_DEBUG
  7502. entries.clear();
  7503. // If you hit this assertion, it means you've created a stream to read
  7504. // one of the items in the zipfile, but you've forgotten to delete that
  7505. // stream object before deleting the file.. Streams can't be kept open
  7506. // after the file is deleted because they need to share the input
  7507. // stream that the file uses to read itself.
  7508. jassert (numOpenStreams == 0);
  7509. #endif
  7510. }
  7511. int ZipFile::getNumEntries() const throw()
  7512. {
  7513. return entries.size();
  7514. }
  7515. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7516. {
  7517. ZipEntryInfo* const zei = (ZipEntryInfo*) entries [index];
  7518. return (zei != 0) ? &(zei->entry)
  7519. : 0;
  7520. }
  7521. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7522. {
  7523. for (int i = 0; i < entries.size(); ++i)
  7524. if (entries.getUnchecked (i)->entry.filename == fileName)
  7525. return i;
  7526. return -1;
  7527. }
  7528. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7529. {
  7530. return getEntry (getIndexOfFileName (fileName));
  7531. }
  7532. InputStream* ZipFile::createStreamForEntry (const int index)
  7533. {
  7534. ZipEntryInfo* const zei = entries[index];
  7535. InputStream* stream = 0;
  7536. if (zei != 0)
  7537. {
  7538. stream = new ZipInputStream (*this, *zei);
  7539. if (zei->compressed)
  7540. {
  7541. stream = new GZIPDecompressorInputStream (stream, true, true,
  7542. zei->entry.uncompressedSize);
  7543. // (much faster to unzip in big blocks using a buffer..)
  7544. stream = new BufferedInputStream (stream, 32768, true);
  7545. }
  7546. }
  7547. return stream;
  7548. }
  7549. class ZipFile::ZipFilenameComparator
  7550. {
  7551. public:
  7552. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7553. {
  7554. return first->entry.filename.compare (second->entry.filename);
  7555. }
  7556. };
  7557. void ZipFile::sortEntriesByFilename()
  7558. {
  7559. ZipFilenameComparator sorter;
  7560. entries.sort (sorter);
  7561. }
  7562. void ZipFile::init()
  7563. {
  7564. ScopedPointer <InputStream> toDelete;
  7565. InputStream* in = inputStream;
  7566. if (inputSource != 0)
  7567. {
  7568. in = inputSource->createInputStream();
  7569. toDelete = in;
  7570. }
  7571. if (in != 0)
  7572. {
  7573. int numEntries = 0;
  7574. int pos = findEndOfZipEntryTable (in, numEntries);
  7575. if (pos >= 0 && pos < in->getTotalLength())
  7576. {
  7577. const int size = (int) (in->getTotalLength() - pos);
  7578. in->setPosition (pos);
  7579. MemoryBlock headerData;
  7580. if (in->readIntoMemoryBlock (headerData, size) == size)
  7581. {
  7582. pos = 0;
  7583. for (int i = 0; i < numEntries; ++i)
  7584. {
  7585. if (pos + 46 > size)
  7586. break;
  7587. const char* const buffer = ((const char*) headerData.getData()) + pos;
  7588. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7589. if (pos + 46 + fileNameLen > size)
  7590. break;
  7591. ZipEntryInfo* const zei = new ZipEntryInfo();
  7592. zei->entry.filename = String::fromUTF8 ((const uint8*) buffer + 46, fileNameLen);
  7593. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7594. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7595. const int year = 1980 + (date >> 9);
  7596. const int month = ((date >> 5) & 15) - 1;
  7597. const int day = date & 31;
  7598. const int hours = time >> 11;
  7599. const int minutes = (time >> 5) & 63;
  7600. const int seconds = (time & 31) << 1;
  7601. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7602. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7603. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7604. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7605. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7606. entries.add (zei);
  7607. pos += 46 + fileNameLen
  7608. + ByteOrder::littleEndianShort (buffer + 30)
  7609. + ByteOrder::littleEndianShort (buffer + 32);
  7610. }
  7611. }
  7612. }
  7613. }
  7614. }
  7615. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7616. {
  7617. BufferedInputStream in (input, 8192, false);
  7618. in.setPosition (in.getTotalLength());
  7619. int64 pos = in.getPosition();
  7620. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7621. char buffer [32];
  7622. zeromem (buffer, sizeof (buffer));
  7623. while (pos > lowestPos)
  7624. {
  7625. in.setPosition (pos - 22);
  7626. pos = in.getPosition();
  7627. memcpy (buffer + 22, buffer, 4);
  7628. if (in.read (buffer, 22) != 22)
  7629. return 0;
  7630. for (int i = 0; i < 22; ++i)
  7631. {
  7632. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7633. {
  7634. in.setPosition (pos + i);
  7635. in.read (buffer, 22);
  7636. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7637. return ByteOrder::littleEndianInt (buffer + 16);
  7638. }
  7639. }
  7640. }
  7641. return 0;
  7642. }
  7643. void ZipFile::uncompressTo (const File& targetDirectory,
  7644. const bool shouldOverwriteFiles)
  7645. {
  7646. for (int i = 0; i < entries.size(); ++i)
  7647. {
  7648. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7649. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7650. if (zei.filename.endsWithChar (T('/')))
  7651. {
  7652. targetFile.createDirectory(); // (entry is a directory, not a file)
  7653. }
  7654. else
  7655. {
  7656. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7657. if (in != 0)
  7658. {
  7659. if (shouldOverwriteFiles)
  7660. targetFile.deleteFile();
  7661. if ((! targetFile.exists())
  7662. && targetFile.getParentDirectory().createDirectory())
  7663. {
  7664. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7665. if (out != 0)
  7666. {
  7667. out->writeFromInputStream (*in, -1);
  7668. out = 0;
  7669. targetFile.setCreationTime (zei.fileTime);
  7670. targetFile.setLastModificationTime (zei.fileTime);
  7671. targetFile.setLastAccessTime (zei.fileTime);
  7672. }
  7673. }
  7674. }
  7675. }
  7676. }
  7677. }
  7678. END_JUCE_NAMESPACE
  7679. /*** End of inlined file: juce_ZipFile.cpp ***/
  7680. /*** Start of inlined file: juce_CharacterFunctions.cpp ***/
  7681. #ifdef _MSC_VER
  7682. #pragma warning (disable: 4514 4996)
  7683. #pragma warning (push)
  7684. #endif
  7685. #include <cwctype>
  7686. #include <cctype>
  7687. #include <ctime>
  7688. #ifdef _MSC_VER
  7689. #pragma warning (pop)
  7690. #endif
  7691. BEGIN_JUCE_NAMESPACE
  7692. int CharacterFunctions::length (const char* const s) throw()
  7693. {
  7694. return (int) strlen (s);
  7695. }
  7696. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7697. {
  7698. return (int) wcslen (s);
  7699. }
  7700. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7701. {
  7702. strncpy (dest, src, maxChars);
  7703. }
  7704. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7705. {
  7706. wcsncpy (dest, src, maxChars);
  7707. }
  7708. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7709. {
  7710. mbstowcs (dest, src, maxChars);
  7711. }
  7712. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7713. {
  7714. wcstombs (dest, src, maxChars);
  7715. }
  7716. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7717. {
  7718. return (int) wcstombs (0, src, 0);
  7719. }
  7720. void CharacterFunctions::append (char* dest, const char* src) throw()
  7721. {
  7722. strcat (dest, src);
  7723. }
  7724. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7725. {
  7726. wcscat (dest, src);
  7727. }
  7728. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7729. {
  7730. return strcmp (s1, s2);
  7731. }
  7732. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7733. {
  7734. jassert (s1 != 0 && s2 != 0);
  7735. return wcscmp (s1, s2);
  7736. }
  7737. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7738. {
  7739. jassert (s1 != 0 && s2 != 0);
  7740. return strncmp (s1, s2, maxChars);
  7741. }
  7742. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7743. {
  7744. jassert (s1 != 0 && s2 != 0);
  7745. return wcsncmp (s1, s2, maxChars);
  7746. }
  7747. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7748. {
  7749. jassert (s1 != 0 && s2 != 0);
  7750. #if JUCE_WIN32
  7751. return stricmp (s1, s2);
  7752. #else
  7753. return strcasecmp (s1, s2);
  7754. #endif
  7755. }
  7756. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7757. {
  7758. jassert (s1 != 0 && s2 != 0);
  7759. #if JUCE_WIN32
  7760. return _wcsicmp (s1, s2);
  7761. #else
  7762. for (;;)
  7763. {
  7764. if (*s1 != *s2)
  7765. {
  7766. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7767. if (diff != 0)
  7768. return diff < 0 ? -1 : 1;
  7769. }
  7770. else if (*s1 == 0)
  7771. break;
  7772. ++s1;
  7773. ++s2;
  7774. }
  7775. return 0;
  7776. #endif
  7777. }
  7778. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7779. {
  7780. jassert (s1 != 0 && s2 != 0);
  7781. #if JUCE_WIN32
  7782. return strnicmp (s1, s2, maxChars);
  7783. #else
  7784. return strncasecmp (s1, s2, maxChars);
  7785. #endif
  7786. }
  7787. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7788. {
  7789. jassert (s1 != 0 && s2 != 0);
  7790. #if JUCE_WIN32
  7791. return _wcsnicmp (s1, s2, maxChars);
  7792. #else
  7793. while (--maxChars >= 0)
  7794. {
  7795. if (*s1 != *s2)
  7796. {
  7797. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7798. if (diff != 0)
  7799. return diff < 0 ? -1 : 1;
  7800. }
  7801. else if (*s1 == 0)
  7802. break;
  7803. ++s1;
  7804. ++s2;
  7805. }
  7806. return 0;
  7807. #endif
  7808. }
  7809. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7810. {
  7811. return strstr (haystack, needle);
  7812. }
  7813. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7814. {
  7815. return wcsstr (haystack, needle);
  7816. }
  7817. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7818. {
  7819. if (haystack != 0)
  7820. {
  7821. int i = 0;
  7822. if (ignoreCase)
  7823. {
  7824. const char n1 = toLowerCase (needle);
  7825. const char n2 = toUpperCase (needle);
  7826. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7827. {
  7828. while (haystack[i] != 0)
  7829. {
  7830. if (haystack[i] == n1 || haystack[i] == n2)
  7831. return i;
  7832. ++i;
  7833. }
  7834. return -1;
  7835. }
  7836. jassert (n1 == needle);
  7837. }
  7838. while (haystack[i] != 0)
  7839. {
  7840. if (haystack[i] == needle)
  7841. return i;
  7842. ++i;
  7843. }
  7844. }
  7845. return -1;
  7846. }
  7847. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7848. {
  7849. if (haystack != 0)
  7850. {
  7851. int i = 0;
  7852. if (ignoreCase)
  7853. {
  7854. const juce_wchar n1 = toLowerCase (needle);
  7855. const juce_wchar n2 = toUpperCase (needle);
  7856. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7857. {
  7858. while (haystack[i] != 0)
  7859. {
  7860. if (haystack[i] == n1 || haystack[i] == n2)
  7861. return i;
  7862. ++i;
  7863. }
  7864. return -1;
  7865. }
  7866. jassert (n1 == needle);
  7867. }
  7868. while (haystack[i] != 0)
  7869. {
  7870. if (haystack[i] == needle)
  7871. return i;
  7872. ++i;
  7873. }
  7874. }
  7875. return -1;
  7876. }
  7877. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7878. {
  7879. jassert (haystack != 0);
  7880. int i = 0;
  7881. while (haystack[i] != 0)
  7882. {
  7883. if (haystack[i] == needle)
  7884. return i;
  7885. ++i;
  7886. }
  7887. return -1;
  7888. }
  7889. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7890. {
  7891. jassert (haystack != 0);
  7892. int i = 0;
  7893. while (haystack[i] != 0)
  7894. {
  7895. if (haystack[i] == needle)
  7896. return i;
  7897. ++i;
  7898. }
  7899. return -1;
  7900. }
  7901. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7902. {
  7903. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7904. }
  7905. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7906. {
  7907. if (allowedChars == 0)
  7908. return 0;
  7909. int i = 0;
  7910. for (;;)
  7911. {
  7912. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7913. break;
  7914. ++i;
  7915. }
  7916. return i;
  7917. }
  7918. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7919. {
  7920. return (int) strftime (dest, maxChars, format, tm);
  7921. }
  7922. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7923. {
  7924. return (int) wcsftime (dest, maxChars, format, tm);
  7925. }
  7926. int CharacterFunctions::getIntValue (const char* const s) throw()
  7927. {
  7928. return atoi (s);
  7929. }
  7930. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7931. {
  7932. #if JUCE_WIN32
  7933. return _wtoi (s);
  7934. #else
  7935. int v = 0;
  7936. while (isWhitespace (*s))
  7937. ++s;
  7938. const bool isNeg = *s == T('-');
  7939. if (isNeg)
  7940. ++s;
  7941. for (;;)
  7942. {
  7943. const wchar_t c = *s++;
  7944. if (c >= T('0') && c <= T('9'))
  7945. v = v * 10 + (int) (c - T('0'));
  7946. else
  7947. break;
  7948. }
  7949. return isNeg ? -v : v;
  7950. #endif
  7951. }
  7952. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7953. {
  7954. #if JUCE_LINUX
  7955. return atoll (s);
  7956. #elif defined (JUCE_WIN32)
  7957. return _atoi64 (s);
  7958. #else
  7959. int64 v = 0;
  7960. while (isWhitespace (*s))
  7961. ++s;
  7962. const bool isNeg = *s == T('-');
  7963. if (isNeg)
  7964. ++s;
  7965. for (;;)
  7966. {
  7967. const char c = *s++;
  7968. if (c >= '0' && c <= '9')
  7969. v = v * 10 + (int64) (c - '0');
  7970. else
  7971. break;
  7972. }
  7973. return isNeg ? -v : v;
  7974. #endif
  7975. }
  7976. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7977. {
  7978. #if JUCE_WIN32
  7979. return _wtoi64 (s);
  7980. #else
  7981. int64 v = 0;
  7982. while (isWhitespace (*s))
  7983. ++s;
  7984. const bool isNeg = *s == T('-');
  7985. if (isNeg)
  7986. ++s;
  7987. for (;;)
  7988. {
  7989. const juce_wchar c = *s++;
  7990. if (c >= T('0') && c <= T('9'))
  7991. v = v * 10 + (int64) (c - T('0'));
  7992. else
  7993. break;
  7994. }
  7995. return isNeg ? -v : v;
  7996. #endif
  7997. }
  7998. static double juce_mulexp10 (const double value, int exponent) throw()
  7999. {
  8000. if (exponent == 0)
  8001. return value;
  8002. if (value == 0)
  8003. return 0;
  8004. const bool negative = (exponent < 0);
  8005. if (negative)
  8006. exponent = -exponent;
  8007. double result = 1.0, power = 10.0;
  8008. for (int bit = 1; exponent != 0; bit <<= 1)
  8009. {
  8010. if ((exponent & bit) != 0)
  8011. {
  8012. exponent ^= bit;
  8013. result *= power;
  8014. if (exponent == 0)
  8015. break;
  8016. }
  8017. power *= power;
  8018. }
  8019. return negative ? (value / result) : (value * result);
  8020. }
  8021. template <class CharType>
  8022. double juce_atof (const CharType* const original) throw()
  8023. {
  8024. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  8025. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  8026. int exponent = 0, decPointIndex = 0, digit = 0;
  8027. int lastDigit = 0, numSignificantDigits = 0;
  8028. bool isNegative = false, digitsFound = false;
  8029. const int maxSignificantDigits = 15 + 2;
  8030. const CharType* s = original;
  8031. while (CharacterFunctions::isWhitespace (*s))
  8032. ++s;
  8033. switch (*s)
  8034. {
  8035. case '-': isNegative = true; // fall-through..
  8036. case '+': ++s;
  8037. }
  8038. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  8039. return atof (String (original)); // Let the c library deal with NAN and INF
  8040. for (;;)
  8041. {
  8042. if (CharacterFunctions::isDigit (*s))
  8043. {
  8044. lastDigit = digit;
  8045. digit = *s++ - '0';
  8046. digitsFound = true;
  8047. if (decPointIndex != 0)
  8048. exponentAdjustment[1]++;
  8049. if (numSignificantDigits == 0 && digit == 0)
  8050. continue;
  8051. if (++numSignificantDigits > maxSignificantDigits)
  8052. {
  8053. if (digit > 5)
  8054. ++accumulator [decPointIndex];
  8055. else if (digit == 5 && (lastDigit & 1) != 0)
  8056. ++accumulator [decPointIndex];
  8057. if (decPointIndex > 0)
  8058. exponentAdjustment[1]--;
  8059. else
  8060. exponentAdjustment[0]++;
  8061. while (CharacterFunctions::isDigit (*s))
  8062. {
  8063. ++s;
  8064. if (decPointIndex == 0)
  8065. exponentAdjustment[0]++;
  8066. }
  8067. }
  8068. else
  8069. {
  8070. const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
  8071. if (accumulator [decPointIndex] > maxAccumulatorValue)
  8072. {
  8073. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  8074. + accumulator [decPointIndex];
  8075. accumulator [decPointIndex] = 0;
  8076. exponentAccumulator [decPointIndex] = 0;
  8077. }
  8078. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  8079. exponentAccumulator [decPointIndex]++;
  8080. }
  8081. }
  8082. else if (decPointIndex == 0 && *s == '.')
  8083. {
  8084. ++s;
  8085. decPointIndex = 1;
  8086. if (numSignificantDigits > maxSignificantDigits)
  8087. {
  8088. while (CharacterFunctions::isDigit (*s))
  8089. ++s;
  8090. break;
  8091. }
  8092. }
  8093. else
  8094. {
  8095. break;
  8096. }
  8097. }
  8098. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  8099. if (decPointIndex != 0)
  8100. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  8101. if ((*s == 'e' || *s == 'E') && digitsFound)
  8102. {
  8103. bool negativeExponent = false;
  8104. switch (*++s)
  8105. {
  8106. case '-': negativeExponent = true; // fall-through..
  8107. case '+': ++s;
  8108. }
  8109. while (CharacterFunctions::isDigit (*s))
  8110. exponent = (exponent * 10) + (*s++ - '0');
  8111. if (negativeExponent)
  8112. exponent = -exponent;
  8113. }
  8114. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  8115. if (decPointIndex != 0)
  8116. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  8117. return isNegative ? -r : r;
  8118. }
  8119. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  8120. {
  8121. return juce_atof <char> (s);
  8122. }
  8123. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  8124. {
  8125. return juce_atof <juce_wchar> (s);
  8126. }
  8127. char CharacterFunctions::toUpperCase (const char character) throw()
  8128. {
  8129. return (char) toupper (character);
  8130. }
  8131. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  8132. {
  8133. return towupper (character);
  8134. }
  8135. void CharacterFunctions::toUpperCase (char* s) throw()
  8136. {
  8137. #if JUCE_WIN32
  8138. strupr (s);
  8139. #else
  8140. while (*s != 0)
  8141. {
  8142. *s = toUpperCase (*s);
  8143. ++s;
  8144. }
  8145. #endif
  8146. }
  8147. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  8148. {
  8149. #if JUCE_WIN32
  8150. _wcsupr (s);
  8151. #else
  8152. while (*s != 0)
  8153. {
  8154. *s = toUpperCase (*s);
  8155. ++s;
  8156. }
  8157. #endif
  8158. }
  8159. bool CharacterFunctions::isUpperCase (const char character) throw()
  8160. {
  8161. return isupper (character) != 0;
  8162. }
  8163. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  8164. {
  8165. #if JUCE_WIN32
  8166. return iswupper (character) != 0;
  8167. #else
  8168. return toLowerCase (character) != character;
  8169. #endif
  8170. }
  8171. char CharacterFunctions::toLowerCase (const char character) throw()
  8172. {
  8173. return (char) tolower (character);
  8174. }
  8175. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  8176. {
  8177. return towlower (character);
  8178. }
  8179. void CharacterFunctions::toLowerCase (char* s) throw()
  8180. {
  8181. #if JUCE_WIN32
  8182. strlwr (s);
  8183. #else
  8184. while (*s != 0)
  8185. {
  8186. *s = toLowerCase (*s);
  8187. ++s;
  8188. }
  8189. #endif
  8190. }
  8191. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  8192. {
  8193. #if JUCE_WIN32
  8194. _wcslwr (s);
  8195. #else
  8196. while (*s != 0)
  8197. {
  8198. *s = toLowerCase (*s);
  8199. ++s;
  8200. }
  8201. #endif
  8202. }
  8203. bool CharacterFunctions::isLowerCase (const char character) throw()
  8204. {
  8205. return islower (character) != 0;
  8206. }
  8207. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  8208. {
  8209. #if JUCE_WIN32
  8210. return iswlower (character) != 0;
  8211. #else
  8212. return toUpperCase (character) != character;
  8213. #endif
  8214. }
  8215. bool CharacterFunctions::isWhitespace (const char character) throw()
  8216. {
  8217. return character == T(' ') || (character <= 13 && character >= 9);
  8218. }
  8219. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  8220. {
  8221. return iswspace (character) != 0;
  8222. }
  8223. bool CharacterFunctions::isDigit (const char character) throw()
  8224. {
  8225. return (character >= '0' && character <= '9');
  8226. }
  8227. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8228. {
  8229. return iswdigit (character) != 0;
  8230. }
  8231. bool CharacterFunctions::isLetter (const char character) throw()
  8232. {
  8233. return (character >= 'a' && character <= 'z')
  8234. || (character >= 'A' && character <= 'Z');
  8235. }
  8236. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8237. {
  8238. return iswalpha (character) != 0;
  8239. }
  8240. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8241. {
  8242. return (character >= 'a' && character <= 'z')
  8243. || (character >= 'A' && character <= 'Z')
  8244. || (character >= '0' && character <= '9');
  8245. }
  8246. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8247. {
  8248. return iswalnum (character) != 0;
  8249. }
  8250. int CharacterFunctions::getHexDigitValue (const tchar digit) throw()
  8251. {
  8252. if (digit >= T('0') && digit <= T('9'))
  8253. return digit - T('0');
  8254. else if (digit >= T('a') && digit <= T('f'))
  8255. return digit - (T('a') - 10);
  8256. else if (digit >= T('A') && digit <= T('F'))
  8257. return digit - (T('A') - 10);
  8258. return -1;
  8259. }
  8260. int CharacterFunctions::printf (char* const dest, const int maxLength, const char* const format, ...) throw()
  8261. {
  8262. va_list list;
  8263. va_start (list, format);
  8264. return vprintf (dest, maxLength, format, list);
  8265. }
  8266. int CharacterFunctions::printf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, ...) throw()
  8267. {
  8268. va_list list;
  8269. va_start (list, format);
  8270. return vprintf (dest, maxLength, format, list);
  8271. }
  8272. int CharacterFunctions::vprintf (char* const dest, const int maxLength, const char* const format, va_list& args) throw()
  8273. {
  8274. #if JUCE_WIN32
  8275. return (int) _vsnprintf (dest, maxLength, format, args);
  8276. #else
  8277. return (int) vsnprintf (dest, maxLength, format, args);
  8278. #endif
  8279. }
  8280. int CharacterFunctions::vprintf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, va_list& args) throw()
  8281. {
  8282. #if defined (JUCE_WIN32)
  8283. return (int) _vsnwprintf (dest, maxLength, format, args);
  8284. #else
  8285. return (int) vswprintf (dest, maxLength, format, args);
  8286. #endif
  8287. }
  8288. END_JUCE_NAMESPACE
  8289. /*** End of inlined file: juce_CharacterFunctions.cpp ***/
  8290. /*** Start of inlined file: juce_LocalisedStrings.cpp ***/
  8291. BEGIN_JUCE_NAMESPACE
  8292. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8293. {
  8294. loadFromText (fileContents);
  8295. }
  8296. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8297. {
  8298. loadFromText (fileToLoad.loadFileAsString());
  8299. }
  8300. LocalisedStrings::~LocalisedStrings()
  8301. {
  8302. }
  8303. const String LocalisedStrings::translate (const String& text) const
  8304. {
  8305. return translations.getValue (text, text);
  8306. }
  8307. static int findCloseQuote (const String& text, int startPos)
  8308. {
  8309. tchar lastChar = 0;
  8310. for (;;)
  8311. {
  8312. const tchar c = text [startPos];
  8313. if (c == 0 || (c == T('"') && lastChar != T('\\')))
  8314. break;
  8315. lastChar = c;
  8316. ++startPos;
  8317. }
  8318. return startPos;
  8319. }
  8320. static const String unescapeString (const String& s)
  8321. {
  8322. return s.replace (T("\\\""), T("\""))
  8323. .replace (T("\\\'"), T("\'"))
  8324. .replace (T("\\t"), T("\t"))
  8325. .replace (T("\\r"), T("\r"))
  8326. .replace (T("\\n"), T("\n"));
  8327. }
  8328. void LocalisedStrings::loadFromText (const String& fileContents)
  8329. {
  8330. StringArray lines;
  8331. lines.addLines (fileContents);
  8332. for (int i = 0; i < lines.size(); ++i)
  8333. {
  8334. String line (lines[i].trim());
  8335. if (line.startsWithChar (T('"')))
  8336. {
  8337. int closeQuote = findCloseQuote (line, 1);
  8338. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8339. if (originalText.isNotEmpty())
  8340. {
  8341. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8342. closeQuote = findCloseQuote (line, openingQuote + 1);
  8343. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8344. if (newText.isNotEmpty())
  8345. translations.set (originalText, newText);
  8346. }
  8347. }
  8348. else if (line.startsWithIgnoreCase (T("language:")))
  8349. {
  8350. languageName = line.substring (9).trim();
  8351. }
  8352. else if (line.startsWithIgnoreCase (T("countries:")))
  8353. {
  8354. countryCodes.addTokens (line.substring (10).trim(), true);
  8355. countryCodes.trim();
  8356. countryCodes.removeEmptyStrings();
  8357. }
  8358. }
  8359. }
  8360. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8361. {
  8362. translations.setIgnoresCase (shouldIgnoreCase);
  8363. }
  8364. static CriticalSection currentMappingsLock;
  8365. static LocalisedStrings* currentMappings = 0;
  8366. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8367. {
  8368. const ScopedLock sl (currentMappingsLock);
  8369. delete currentMappings;
  8370. currentMappings = newTranslations;
  8371. }
  8372. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8373. {
  8374. return currentMappings;
  8375. }
  8376. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8377. {
  8378. const ScopedLock sl (currentMappingsLock);
  8379. if (currentMappings != 0)
  8380. return currentMappings->translate (text);
  8381. return text;
  8382. }
  8383. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8384. {
  8385. return translateWithCurrentMappings (String (text));
  8386. }
  8387. END_JUCE_NAMESPACE
  8388. /*** End of inlined file: juce_LocalisedStrings.cpp ***/
  8389. /*** Start of inlined file: juce_String.cpp ***/
  8390. #ifdef _MSC_VER
  8391. #pragma warning (disable: 4514)
  8392. #pragma warning (push)
  8393. #endif
  8394. #include <locale>
  8395. #if JUCE_MSVC
  8396. #include <float.h>
  8397. #endif
  8398. BEGIN_JUCE_NAMESPACE
  8399. #ifdef _MSC_VER
  8400. #pragma warning (pop)
  8401. #endif
  8402. static const char* const emptyCharString = "\0\0\0\0JUCE";
  8403. static const int safeEmptyStringRefCount = 0x3fffffff;
  8404. String::InternalRefCountedStringHolder String::emptyString = { safeEmptyStringRefCount, 0, { 0 } };
  8405. static tchar decimalPoint = T('.');
  8406. void juce_initialiseStrings()
  8407. {
  8408. decimalPoint = String::fromUTF8 ((const uint8*) localeconv()->decimal_point) [0];
  8409. }
  8410. void String::createInternal (const int numChars) throw()
  8411. {
  8412. jassert (numChars > 0);
  8413. text = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8414. + numChars * sizeof (tchar));
  8415. text->refCount = 1;
  8416. text->allocatedNumChars = numChars;
  8417. text->text[0] = 0;
  8418. }
  8419. void String::createInternal (const tchar* const t, const tchar* const textEnd) throw()
  8420. {
  8421. jassert (*(textEnd - 1) == 0); // must have a null terminator
  8422. const int numChars = (int) (textEnd - t);
  8423. createInternal (numChars - 1);
  8424. memcpy (text->text, t, numChars * sizeof (tchar));
  8425. }
  8426. void String::appendInternal (const tchar* const newText,
  8427. const int numExtraChars) throw()
  8428. {
  8429. if (numExtraChars > 0)
  8430. {
  8431. const int oldLen = CharacterFunctions::length (text->text);
  8432. const int newTotalLen = oldLen + numExtraChars;
  8433. if (text->refCount > 1)
  8434. {
  8435. // it's in use by other strings as well, so we need to make a private copy before messing with it..
  8436. InternalRefCountedStringHolder* const newTextHolder
  8437. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8438. + newTotalLen * sizeof (tchar));
  8439. newTextHolder->refCount = 1;
  8440. newTextHolder->allocatedNumChars = newTotalLen;
  8441. memcpy (newTextHolder->text, text->text, oldLen * sizeof (tchar));
  8442. memcpy (newTextHolder->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8443. InternalRefCountedStringHolder* const old = text;
  8444. text = newTextHolder;
  8445. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8446. juce_free (old);
  8447. }
  8448. else
  8449. {
  8450. // no other strings using it, so just expand it if needed..
  8451. if (newTotalLen > text->allocatedNumChars)
  8452. {
  8453. text = (InternalRefCountedStringHolder*)
  8454. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8455. + newTotalLen * sizeof (tchar));
  8456. text->allocatedNumChars = newTotalLen;
  8457. }
  8458. memcpy (text->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8459. }
  8460. text->text [newTotalLen] = 0;
  8461. }
  8462. }
  8463. void String::dupeInternalIfMultiplyReferenced() throw()
  8464. {
  8465. if (text->refCount > 1)
  8466. {
  8467. InternalRefCountedStringHolder* const old = text;
  8468. const int len = old->allocatedNumChars;
  8469. InternalRefCountedStringHolder* const newTextHolder
  8470. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8471. + len * sizeof (tchar));
  8472. newTextHolder->refCount = 1;
  8473. newTextHolder->allocatedNumChars = len;
  8474. memcpy (newTextHolder->text, old->text, (len + 1) * sizeof (tchar));
  8475. text = newTextHolder;
  8476. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8477. juce_free (old);
  8478. }
  8479. }
  8480. const String String::empty;
  8481. String::String() throw()
  8482. : text (&emptyString)
  8483. {
  8484. }
  8485. String::String (const String& other) throw()
  8486. : text (other.text)
  8487. {
  8488. Atomic::increment (text->refCount);
  8489. }
  8490. String::String (const int numChars,
  8491. const int /*dummyVariable*/) throw()
  8492. {
  8493. createInternal (numChars);
  8494. }
  8495. String::String (const char* const t) throw()
  8496. {
  8497. if (t != 0 && *t != 0)
  8498. {
  8499. const int len = CharacterFunctions::length (t);
  8500. createInternal (len);
  8501. #if JUCE_STRINGS_ARE_UNICODE
  8502. CharacterFunctions::copy (text->text, t, len + 1);
  8503. #else
  8504. memcpy (text->text, t, len + 1);
  8505. #endif
  8506. }
  8507. else
  8508. {
  8509. text = &emptyString;
  8510. emptyString.refCount = safeEmptyStringRefCount;
  8511. }
  8512. }
  8513. String::String (const juce_wchar* const t) throw()
  8514. {
  8515. if (t != 0 && *t != 0)
  8516. {
  8517. #if JUCE_STRINGS_ARE_UNICODE
  8518. const int len = CharacterFunctions::length (t);
  8519. createInternal (len);
  8520. memcpy (text->text, t, (len + 1) * sizeof (tchar));
  8521. #else
  8522. const int len = CharacterFunctions::bytesRequiredForCopy (t);
  8523. createInternal (len);
  8524. CharacterFunctions::copy (text->text, t, len + 1);
  8525. #endif
  8526. }
  8527. else
  8528. {
  8529. text = &emptyString;
  8530. emptyString.refCount = safeEmptyStringRefCount;
  8531. }
  8532. }
  8533. String::String (const char* const t,
  8534. const size_t maxChars) throw()
  8535. {
  8536. int i;
  8537. for (i = 0; (size_t) i < maxChars; ++i)
  8538. if (t[i] == 0)
  8539. break;
  8540. if (i > 0)
  8541. {
  8542. createInternal (i);
  8543. #if JUCE_STRINGS_ARE_UNICODE
  8544. CharacterFunctions::copy (text->text, t, i);
  8545. #else
  8546. memcpy (text->text, t, i);
  8547. #endif
  8548. text->text [i] = 0;
  8549. }
  8550. else
  8551. {
  8552. text = &emptyString;
  8553. emptyString.refCount = safeEmptyStringRefCount;
  8554. }
  8555. }
  8556. String::String (const juce_wchar* const t,
  8557. const size_t maxChars) throw()
  8558. {
  8559. int i;
  8560. for (i = 0; (size_t) i < maxChars; ++i)
  8561. if (t[i] == 0)
  8562. break;
  8563. if (i > 0)
  8564. {
  8565. createInternal (i);
  8566. #if JUCE_STRINGS_ARE_UNICODE
  8567. memcpy (text->text, t, i * sizeof (tchar));
  8568. #else
  8569. CharacterFunctions::copy (text->text, t, i);
  8570. #endif
  8571. text->text [i] = 0;
  8572. }
  8573. else
  8574. {
  8575. text = &emptyString;
  8576. emptyString.refCount = safeEmptyStringRefCount;
  8577. }
  8578. }
  8579. const String String::charToString (const tchar character) throw()
  8580. {
  8581. tchar temp[2];
  8582. temp[0] = character;
  8583. temp[1] = 0;
  8584. return String (temp);
  8585. }
  8586. // pass in a pointer to the END of a buffer..
  8587. static tchar* int64ToCharString (tchar* t, const int64 n) throw()
  8588. {
  8589. *--t = 0;
  8590. int64 v = (n >= 0) ? n : -n;
  8591. do
  8592. {
  8593. *--t = (tchar) (T('0') + (int) (v % 10));
  8594. v /= 10;
  8595. } while (v > 0);
  8596. if (n < 0)
  8597. *--t = T('-');
  8598. return t;
  8599. }
  8600. static tchar* intToCharString (tchar* t, const int n) throw()
  8601. {
  8602. if (n == (int) 0x80000000) // (would cause an overflow)
  8603. return int64ToCharString (t, n);
  8604. *--t = 0;
  8605. int v = abs (n);
  8606. do
  8607. {
  8608. *--t = (tchar) (T('0') + (v % 10));
  8609. v /= 10;
  8610. } while (v > 0);
  8611. if (n < 0)
  8612. *--t = T('-');
  8613. return t;
  8614. }
  8615. static tchar* uintToCharString (tchar* t, unsigned int v) throw()
  8616. {
  8617. *--t = 0;
  8618. do
  8619. {
  8620. *--t = (tchar) (T('0') + (v % 10));
  8621. v /= 10;
  8622. } while (v > 0);
  8623. return t;
  8624. }
  8625. String::String (const int number) throw()
  8626. {
  8627. tchar buffer [16];
  8628. tchar* const end = buffer + 16;
  8629. createInternal (intToCharString (end, number), end);
  8630. }
  8631. String::String (const unsigned int number) throw()
  8632. {
  8633. tchar buffer [16];
  8634. tchar* const end = buffer + 16;
  8635. createInternal (uintToCharString (end, number), end);
  8636. }
  8637. String::String (const short number) throw()
  8638. {
  8639. tchar buffer [16];
  8640. tchar* const end = buffer + 16;
  8641. createInternal (intToCharString (end, (int) number), end);
  8642. }
  8643. String::String (const unsigned short number) throw()
  8644. {
  8645. tchar buffer [16];
  8646. tchar* const end = buffer + 16;
  8647. createInternal (uintToCharString (end, (unsigned int) number), end);
  8648. }
  8649. String::String (const int64 number) throw()
  8650. {
  8651. tchar buffer [32];
  8652. tchar* const end = buffer + 32;
  8653. createInternal (int64ToCharString (end, number), end);
  8654. }
  8655. String::String (const uint64 number) throw()
  8656. {
  8657. tchar buffer [32];
  8658. tchar* const end = buffer + 32;
  8659. tchar* t = end;
  8660. *--t = 0;
  8661. int64 v = number;
  8662. do
  8663. {
  8664. *--t = (tchar) (T('0') + (int) (v % 10));
  8665. v /= 10;
  8666. } while (v > 0);
  8667. createInternal (t, end);
  8668. }
  8669. // a double-to-string routine that actually uses the number of dec. places you asked for
  8670. // without resorting to exponent notation if the number's too big or small (which is what printf does).
  8671. void String::doubleToStringWithDecPlaces (double n, int numDecPlaces) throw()
  8672. {
  8673. const int bufSize = 80;
  8674. tchar buffer [bufSize];
  8675. int len;
  8676. tchar* t;
  8677. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8678. {
  8679. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8680. t = buffer + bufSize;
  8681. *--t = (tchar) 0;
  8682. while (numDecPlaces >= 0 || v > 0)
  8683. {
  8684. if (numDecPlaces == 0)
  8685. *--t = decimalPoint;
  8686. *--t = (tchar) (T('0') + (v % 10));
  8687. v /= 10;
  8688. --numDecPlaces;
  8689. }
  8690. if (n < 0)
  8691. *--t = T('-');
  8692. len = (int) ((buffer + bufSize) - t);
  8693. }
  8694. else
  8695. {
  8696. len = CharacterFunctions::printf (buffer, bufSize, T("%.9g"), n) + 1;
  8697. t = buffer;
  8698. }
  8699. if (len > 1)
  8700. {
  8701. jassert (len < numElementsInArray (buffer));
  8702. createInternal (len - 1);
  8703. memcpy (text->text, t, len * sizeof (tchar));
  8704. }
  8705. else
  8706. {
  8707. jassert (*t == 0);
  8708. text = &emptyString;
  8709. emptyString.refCount = safeEmptyStringRefCount;
  8710. }
  8711. }
  8712. String::String (const float number,
  8713. const int numberOfDecimalPlaces) throw()
  8714. {
  8715. doubleToStringWithDecPlaces ((double) number,
  8716. numberOfDecimalPlaces);
  8717. }
  8718. String::String (const double number,
  8719. const int numberOfDecimalPlaces) throw()
  8720. {
  8721. doubleToStringWithDecPlaces (number,
  8722. numberOfDecimalPlaces);
  8723. }
  8724. String::~String() throw()
  8725. {
  8726. emptyString.refCount = safeEmptyStringRefCount;
  8727. if (Atomic::decrementAndReturn (text->refCount) == 0)
  8728. juce_free (text);
  8729. }
  8730. void String::preallocateStorage (const size_t numChars) throw()
  8731. {
  8732. if (numChars > (size_t) text->allocatedNumChars)
  8733. {
  8734. dupeInternalIfMultiplyReferenced();
  8735. text = (InternalRefCountedStringHolder*) juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8736. + numChars * sizeof (tchar));
  8737. text->allocatedNumChars = (int) numChars;
  8738. }
  8739. }
  8740. #if JUCE_STRINGS_ARE_UNICODE
  8741. String::operator const char*() const throw()
  8742. {
  8743. if (isEmpty())
  8744. {
  8745. return (const char*) emptyCharString;
  8746. }
  8747. else
  8748. {
  8749. String* const mutableThis = const_cast <String*> (this);
  8750. mutableThis->dupeInternalIfMultiplyReferenced();
  8751. int len = CharacterFunctions::bytesRequiredForCopy (text->text) + 1;
  8752. mutableThis->text = (InternalRefCountedStringHolder*)
  8753. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8754. + (len * sizeof (juce_wchar) + len));
  8755. char* otherCopy = (char*) (text->text + len);
  8756. --len;
  8757. CharacterFunctions::copy (otherCopy, text->text, len);
  8758. otherCopy [len] = 0;
  8759. return otherCopy;
  8760. }
  8761. }
  8762. #else
  8763. String::operator const juce_wchar*() const throw()
  8764. {
  8765. if (isEmpty())
  8766. {
  8767. return (const juce_wchar*) emptyCharString;
  8768. }
  8769. else
  8770. {
  8771. String* const mutableThis = const_cast <String*> (this);
  8772. mutableThis->dupeInternalIfMultiplyReferenced();
  8773. int len = CharacterFunctions::length (text->text) + 1;
  8774. mutableThis->text = (InternalRefCountedStringHolder*)
  8775. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8776. + (len * sizeof (juce_wchar) + len));
  8777. juce_wchar* otherCopy = (juce_wchar*) (text->text + len);
  8778. --len;
  8779. CharacterFunctions::copy (otherCopy, text->text, len);
  8780. otherCopy [len] = 0;
  8781. return otherCopy;
  8782. }
  8783. }
  8784. #endif
  8785. void String::copyToBuffer (char* const destBuffer,
  8786. const int bufferSizeBytes) const throw()
  8787. {
  8788. #if JUCE_STRINGS_ARE_UNICODE
  8789. const int len = jmin (bufferSizeBytes, CharacterFunctions::bytesRequiredForCopy (text->text));
  8790. CharacterFunctions::copy (destBuffer, text->text, len);
  8791. #else
  8792. const int len = jmin (bufferSizeBytes, length());
  8793. memcpy (destBuffer, text->text, len * sizeof (tchar));
  8794. #endif
  8795. destBuffer [len] = 0;
  8796. }
  8797. void String::copyToBuffer (juce_wchar* const destBuffer,
  8798. const int maxCharsToCopy) const throw()
  8799. {
  8800. const int len = jmin (maxCharsToCopy, length());
  8801. #if JUCE_STRINGS_ARE_UNICODE
  8802. memcpy (destBuffer, text->text, len * sizeof (juce_wchar));
  8803. #else
  8804. CharacterFunctions::copy (destBuffer, text->text, len);
  8805. #endif
  8806. destBuffer [len] = 0;
  8807. }
  8808. int String::length() const throw()
  8809. {
  8810. return CharacterFunctions::length (text->text);
  8811. }
  8812. int String::hashCode() const throw()
  8813. {
  8814. const tchar* t = text->text;
  8815. int result = 0;
  8816. while (*t != (tchar) 0)
  8817. result = 31 * result + *t++;
  8818. return result;
  8819. }
  8820. int64 String::hashCode64() const throw()
  8821. {
  8822. const tchar* t = text->text;
  8823. int64 result = 0;
  8824. while (*t != (tchar) 0)
  8825. result = 101 * result + *t++;
  8826. return result;
  8827. }
  8828. const String& String::operator= (const tchar* const otherText) throw()
  8829. {
  8830. operator= (String (otherText));
  8831. return *this;
  8832. }
  8833. const String& String::operator= (const String& other) throw()
  8834. {
  8835. if (this != &other)
  8836. {
  8837. InternalRefCountedStringHolder* newText = other.text;
  8838. Atomic::increment (newText->refCount);
  8839. InternalRefCountedStringHolder* oldText
  8840. = (InternalRefCountedStringHolder*) Atomic::swapPointers ((void* volatile*) &text, newText);
  8841. if (Atomic::decrementAndReturn (oldText->refCount) == 0)
  8842. juce_free (oldText);
  8843. }
  8844. return *this;
  8845. }
  8846. bool String::operator== (const String& other) const throw()
  8847. {
  8848. return text == other.text
  8849. || CharacterFunctions::compare (text->text, other.text->text) == 0;
  8850. }
  8851. bool String::operator== (const tchar* const t) const throw()
  8852. {
  8853. return t != 0 ? CharacterFunctions::compare (text->text, t) == 0
  8854. : isEmpty();
  8855. }
  8856. bool String::equalsIgnoreCase (const tchar* t) const throw()
  8857. {
  8858. return t != 0 ? CharacterFunctions::compareIgnoreCase (text->text, t) == 0
  8859. : isEmpty();
  8860. }
  8861. bool String::equalsIgnoreCase (const String& other) const throw()
  8862. {
  8863. return text == other.text
  8864. || CharacterFunctions::compareIgnoreCase (text->text, other.text->text) == 0;
  8865. }
  8866. bool String::operator!= (const String& other) const throw()
  8867. {
  8868. return text != other.text
  8869. && CharacterFunctions::compare (text->text, other.text->text) != 0;
  8870. }
  8871. bool String::operator!= (const tchar* const t) const throw()
  8872. {
  8873. return t != 0 ? (CharacterFunctions::compare (text->text, t) != 0)
  8874. : isNotEmpty();
  8875. }
  8876. bool String::operator> (const String& other) const throw()
  8877. {
  8878. return compare (other) > 0;
  8879. }
  8880. bool String::operator< (const tchar* const other) const throw()
  8881. {
  8882. return compare (other) < 0;
  8883. }
  8884. bool String::operator>= (const String& other) const throw()
  8885. {
  8886. return compare (other) >= 0;
  8887. }
  8888. bool String::operator<= (const tchar* const other) const throw()
  8889. {
  8890. return compare (other) <= 0;
  8891. }
  8892. int String::compare (const tchar* const other) const throw()
  8893. {
  8894. return other != 0 ? CharacterFunctions::compare (text->text, other)
  8895. : isEmpty();
  8896. }
  8897. int String::compareIgnoreCase (const tchar* const other) const throw()
  8898. {
  8899. return other != 0 ? CharacterFunctions::compareIgnoreCase (text->text, other)
  8900. : isEmpty();
  8901. }
  8902. int String::compareLexicographically (const tchar* other) const throw()
  8903. {
  8904. if (other == 0)
  8905. return isEmpty();
  8906. const tchar* s1 = text->text;
  8907. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8908. ++s1;
  8909. while (*other != 0 && ! CharacterFunctions::isLetterOrDigit (*other))
  8910. ++other;
  8911. return CharacterFunctions::compareIgnoreCase (s1, other);
  8912. }
  8913. const String String::operator+ (const String& other) const throw()
  8914. {
  8915. if (*(other.text->text) == 0)
  8916. return *this;
  8917. if (isEmpty())
  8918. return other;
  8919. const int len = CharacterFunctions::length (text->text);
  8920. const int otherLen = CharacterFunctions::length (other.text->text);
  8921. String result (len + otherLen, (int) 0);
  8922. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8923. memcpy (result.text->text + len, other.text->text, otherLen * sizeof (tchar));
  8924. result.text->text [len + otherLen] = 0;
  8925. return result;
  8926. }
  8927. const String String::operator+ (const tchar* const textToAppend) const throw()
  8928. {
  8929. if (textToAppend == 0 || *textToAppend == 0)
  8930. return *this;
  8931. const int len = CharacterFunctions::length (text->text);
  8932. const int otherLen = CharacterFunctions::length (textToAppend);
  8933. String result (len + otherLen, (int) 0);
  8934. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8935. memcpy (result.text->text + len, textToAppend, otherLen * sizeof (tchar));
  8936. result.text->text [len + otherLen] = 0;
  8937. return result;
  8938. }
  8939. const String String::operator+ (const tchar characterToAppend) const throw()
  8940. {
  8941. if (characterToAppend == 0)
  8942. return *this;
  8943. const int len = CharacterFunctions::length (text->text);
  8944. String result ((int) (len + 1), (int) 0);
  8945. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8946. result.text->text[len] = characterToAppend;
  8947. result.text->text[len + 1] = 0;
  8948. return result;
  8949. }
  8950. const String JUCE_PUBLIC_FUNCTION operator+ (const char* const string1,
  8951. const String& string2) throw()
  8952. {
  8953. String s (string1);
  8954. s += string2;
  8955. return s;
  8956. }
  8957. const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar* const string1,
  8958. const String& string2) throw()
  8959. {
  8960. String s (string1);
  8961. s += string2;
  8962. return s;
  8963. }
  8964. const String& String::operator+= (const tchar* const t) throw()
  8965. {
  8966. if (t != 0)
  8967. appendInternal (t, CharacterFunctions::length (t));
  8968. return *this;
  8969. }
  8970. const String& String::operator+= (const String& other) throw()
  8971. {
  8972. if (isEmpty())
  8973. operator= (other);
  8974. else
  8975. appendInternal (other.text->text,
  8976. CharacterFunctions::length (other.text->text));
  8977. return *this;
  8978. }
  8979. const String& String::operator+= (const char ch) throw()
  8980. {
  8981. char asString[2];
  8982. asString[0] = ch;
  8983. asString[1] = 0;
  8984. #if JUCE_STRINGS_ARE_UNICODE
  8985. operator+= (String (asString));
  8986. #else
  8987. appendInternal (asString, 1);
  8988. #endif
  8989. return *this;
  8990. }
  8991. const String& String::operator+= (const juce_wchar ch) throw()
  8992. {
  8993. juce_wchar asString[2];
  8994. asString[0] = ch;
  8995. asString[1] = 0;
  8996. #if JUCE_STRINGS_ARE_UNICODE
  8997. appendInternal (asString, 1);
  8998. #else
  8999. operator+= (String (asString));
  9000. #endif
  9001. return *this;
  9002. }
  9003. void String::append (const tchar* const other,
  9004. const int howMany) throw()
  9005. {
  9006. if (howMany > 0)
  9007. {
  9008. int i;
  9009. for (i = 0; i < howMany; ++i)
  9010. if (other[i] == 0)
  9011. break;
  9012. appendInternal (other, i);
  9013. }
  9014. }
  9015. String& String::operator<< (const int number) throw()
  9016. {
  9017. tchar buffer [64];
  9018. tchar* const end = buffer + 64;
  9019. const tchar* const t = intToCharString (end, number);
  9020. appendInternal (t, (int) (end - t) - 1);
  9021. return *this;
  9022. }
  9023. String& String::operator<< (const unsigned int number) throw()
  9024. {
  9025. tchar buffer [64];
  9026. tchar* const end = buffer + 64;
  9027. const tchar* const t = uintToCharString (end, number);
  9028. appendInternal (t, (int) (end - t) - 1);
  9029. return *this;
  9030. }
  9031. String& String::operator<< (const short number) throw()
  9032. {
  9033. tchar buffer [64];
  9034. tchar* const end = buffer + 64;
  9035. const tchar* const t = intToCharString (end, (int) number);
  9036. appendInternal (t, (int) (end - t) - 1);
  9037. return *this;
  9038. }
  9039. String& String::operator<< (const long number) throw()
  9040. {
  9041. return operator<< ((int) number);
  9042. }
  9043. String& String::operator<< (const unsigned long number) throw()
  9044. {
  9045. return operator<< ((unsigned int) number);
  9046. }
  9047. String& String::operator<< (const double number) throw()
  9048. {
  9049. operator+= (String (number));
  9050. return *this;
  9051. }
  9052. String& String::operator<< (const float number) throw()
  9053. {
  9054. operator+= (String (number));
  9055. return *this;
  9056. }
  9057. String& String::operator<< (const char character) throw()
  9058. {
  9059. operator+= (character);
  9060. return *this;
  9061. }
  9062. String& String::operator<< (const juce_wchar character) throw()
  9063. {
  9064. operator+= (character);
  9065. return *this;
  9066. }
  9067. String& String::operator<< (const char* const t) throw()
  9068. {
  9069. #if JUCE_STRINGS_ARE_UNICODE
  9070. operator+= (String (t));
  9071. #else
  9072. operator+= (t);
  9073. #endif
  9074. return *this;
  9075. }
  9076. String& String::operator<< (const juce_wchar* const t) throw()
  9077. {
  9078. #if JUCE_STRINGS_ARE_UNICODE
  9079. operator+= (t);
  9080. #else
  9081. operator+= (String (t));
  9082. #endif
  9083. return *this;
  9084. }
  9085. String& String::operator<< (const String& t) throw()
  9086. {
  9087. operator+= (t);
  9088. return *this;
  9089. }
  9090. int String::indexOfChar (const tchar character) const throw()
  9091. {
  9092. const tchar* t = text->text;
  9093. for (;;)
  9094. {
  9095. if (*t == character)
  9096. return (int) (t - text->text);
  9097. if (*t++ == 0)
  9098. return -1;
  9099. }
  9100. }
  9101. int String::lastIndexOfChar (const tchar character) const throw()
  9102. {
  9103. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  9104. if (text->text[i] == character)
  9105. return i;
  9106. return -1;
  9107. }
  9108. int String::indexOf (const tchar* const t) const throw()
  9109. {
  9110. const tchar* const r = CharacterFunctions::find (text->text, t);
  9111. return (r == 0) ? -1
  9112. : (int) (r - text->text);
  9113. }
  9114. int String::indexOfChar (const int startIndex,
  9115. const tchar character) const throw()
  9116. {
  9117. if (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text))
  9118. return -1;
  9119. const tchar* t = text->text + jmax (0, startIndex);
  9120. for (;;)
  9121. {
  9122. if (*t == character)
  9123. return (int) (t - text->text);
  9124. if (*t++ == 0)
  9125. return -1;
  9126. }
  9127. }
  9128. int String::indexOfAnyOf (const tchar* const charactersToLookFor,
  9129. const int startIndex,
  9130. const bool ignoreCase) const throw()
  9131. {
  9132. if (charactersToLookFor == 0
  9133. || (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text)))
  9134. return -1;
  9135. const tchar* t = text->text + jmax (0, startIndex);
  9136. while (*t != 0)
  9137. {
  9138. if (CharacterFunctions::indexOfChar (charactersToLookFor, *t, ignoreCase) >= 0)
  9139. return (int) (t - text->text);
  9140. ++t;
  9141. }
  9142. return -1;
  9143. }
  9144. int String::indexOf (const int startIndex,
  9145. const tchar* const other) const throw()
  9146. {
  9147. if (other == 0 || startIndex >= CharacterFunctions::length (text->text))
  9148. return -1;
  9149. const tchar* const found = CharacterFunctions::find (text->text + jmax (0, startIndex),
  9150. other);
  9151. return (found == 0) ? -1
  9152. : (int) (found - text->text);
  9153. }
  9154. int String::indexOfIgnoreCase (const tchar* const other) const throw()
  9155. {
  9156. if (other != 0 && *other != 0)
  9157. {
  9158. const int len = CharacterFunctions::length (other);
  9159. const int end = CharacterFunctions::length (text->text) - len;
  9160. for (int i = 0; i <= end; ++i)
  9161. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9162. return i;
  9163. }
  9164. return -1;
  9165. }
  9166. int String::indexOfIgnoreCase (const int startIndex,
  9167. const tchar* const other) const throw()
  9168. {
  9169. if (other != 0 && *other != 0)
  9170. {
  9171. const int len = CharacterFunctions::length (other);
  9172. const int end = length() - len;
  9173. for (int i = jmax (0, startIndex); i <= end; ++i)
  9174. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9175. return i;
  9176. }
  9177. return -1;
  9178. }
  9179. int String::lastIndexOf (const tchar* const other) const throw()
  9180. {
  9181. if (other != 0 && *other != 0)
  9182. {
  9183. const int len = CharacterFunctions::length (other);
  9184. int i = length() - len;
  9185. if (i >= 0)
  9186. {
  9187. const tchar* n = text->text + i;
  9188. while (i >= 0)
  9189. {
  9190. if (CharacterFunctions::compare (n--, other, len) == 0)
  9191. return i;
  9192. --i;
  9193. }
  9194. }
  9195. }
  9196. return -1;
  9197. }
  9198. int String::lastIndexOfIgnoreCase (const tchar* const other) const throw()
  9199. {
  9200. if (other != 0 && *other != 0)
  9201. {
  9202. const int len = CharacterFunctions::length (other);
  9203. int i = length() - len;
  9204. if (i >= 0)
  9205. {
  9206. const tchar* n = text->text + i;
  9207. while (i >= 0)
  9208. {
  9209. if (CharacterFunctions::compareIgnoreCase (n--, other, len) == 0)
  9210. return i;
  9211. --i;
  9212. }
  9213. }
  9214. }
  9215. return -1;
  9216. }
  9217. int String::lastIndexOfAnyOf (const tchar* const charactersToLookFor,
  9218. const bool ignoreCase) const throw()
  9219. {
  9220. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  9221. if (CharacterFunctions::indexOfChar (charactersToLookFor, text->text [i], ignoreCase) >= 0)
  9222. return i;
  9223. return -1;
  9224. }
  9225. bool String::contains (const tchar* const other) const throw()
  9226. {
  9227. return indexOf (other) >= 0;
  9228. }
  9229. bool String::containsChar (const tchar character) const throw()
  9230. {
  9231. return indexOfChar (character) >= 0;
  9232. }
  9233. bool String::containsIgnoreCase (const tchar* const t) const throw()
  9234. {
  9235. return indexOfIgnoreCase (t) >= 0;
  9236. }
  9237. int String::indexOfWholeWord (const tchar* const word) const throw()
  9238. {
  9239. if (word != 0 && *word != 0)
  9240. {
  9241. const int wordLen = CharacterFunctions::length (word);
  9242. const int end = length() - wordLen;
  9243. const tchar* t = text->text;
  9244. for (int i = 0; i <= end; ++i)
  9245. {
  9246. if (CharacterFunctions::compare (t, word, wordLen) == 0
  9247. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9248. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9249. {
  9250. return i;
  9251. }
  9252. ++t;
  9253. }
  9254. }
  9255. return -1;
  9256. }
  9257. int String::indexOfWholeWordIgnoreCase (const tchar* const word) const throw()
  9258. {
  9259. if (word != 0 && *word != 0)
  9260. {
  9261. const int wordLen = CharacterFunctions::length (word);
  9262. const int end = length() - wordLen;
  9263. const tchar* t = text->text;
  9264. for (int i = 0; i <= end; ++i)
  9265. {
  9266. if (CharacterFunctions::compareIgnoreCase (t, word, wordLen) == 0
  9267. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9268. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9269. {
  9270. return i;
  9271. }
  9272. ++t;
  9273. }
  9274. }
  9275. return -1;
  9276. }
  9277. bool String::containsWholeWord (const tchar* const wordToLookFor) const throw()
  9278. {
  9279. return indexOfWholeWord (wordToLookFor) >= 0;
  9280. }
  9281. bool String::containsWholeWordIgnoreCase (const tchar* const wordToLookFor) const throw()
  9282. {
  9283. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  9284. }
  9285. static int indexOfMatch (const tchar* const wildcard,
  9286. const tchar* const test,
  9287. const bool ignoreCase) throw()
  9288. {
  9289. int start = 0;
  9290. while (test [start] != 0)
  9291. {
  9292. int i = 0;
  9293. for (;;)
  9294. {
  9295. const tchar wc = wildcard [i];
  9296. const tchar c = test [i + start];
  9297. if (wc == c
  9298. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9299. || (wc == T('?') && c != 0))
  9300. {
  9301. if (wc == 0)
  9302. return start;
  9303. ++i;
  9304. }
  9305. else
  9306. {
  9307. if (wc == T('*') && (wildcard [i + 1] == 0
  9308. || indexOfMatch (wildcard + i + 1,
  9309. test + start + i,
  9310. ignoreCase) >= 0))
  9311. {
  9312. return start;
  9313. }
  9314. break;
  9315. }
  9316. }
  9317. ++start;
  9318. }
  9319. return -1;
  9320. }
  9321. bool String::matchesWildcard (const tchar* wildcard, const bool ignoreCase) const throw()
  9322. {
  9323. int i = 0;
  9324. for (;;)
  9325. {
  9326. const tchar wc = wildcard [i];
  9327. const tchar c = text->text [i];
  9328. if (wc == c
  9329. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9330. || (wc == T('?') && c != 0))
  9331. {
  9332. if (wc == 0)
  9333. return true;
  9334. ++i;
  9335. }
  9336. else
  9337. {
  9338. return wc == T('*') && (wildcard [i + 1] == 0
  9339. || indexOfMatch (wildcard + i + 1,
  9340. text->text + i,
  9341. ignoreCase) >= 0);
  9342. }
  9343. }
  9344. }
  9345. void String::printf (const tchar* const pf, ...) throw()
  9346. {
  9347. va_list list;
  9348. va_start (list, pf);
  9349. vprintf (pf, list);
  9350. }
  9351. const String String::formatted (const tchar* const pf, ...) throw()
  9352. {
  9353. va_list list;
  9354. va_start (list, pf);
  9355. String result;
  9356. result.vprintf (pf, list);
  9357. return result;
  9358. }
  9359. void String::vprintf (const tchar* const pf, va_list& args) throw()
  9360. {
  9361. int bufferSize = 256;
  9362. String result (bufferSize, 0);
  9363. do
  9364. {
  9365. #if JUCE_LINUX && JUCE_64BIT
  9366. va_list tempArgs;
  9367. va_copy (tempArgs, args);
  9368. const int num = CharacterFunctions::vprintf (result.text->text, bufferSize - 1, pf, tempArgs);
  9369. va_end (tempArgs);
  9370. #else
  9371. const int num = CharacterFunctions::vprintf (result.text->text, bufferSize - 1, pf, args);
  9372. #endif
  9373. if (num > 0)
  9374. {
  9375. *this = result;
  9376. break;
  9377. }
  9378. else if (num == 0)
  9379. {
  9380. *this = String::empty;
  9381. break;
  9382. }
  9383. bufferSize += 256;
  9384. result.preallocateStorage (bufferSize);
  9385. }
  9386. while (bufferSize < 65536); // this is a sanity check to avoid situations where vprintf repeatedly
  9387. // returns -1 because of an error rather than because it needs more space.
  9388. }
  9389. const String String::repeatedString (const tchar* const stringToRepeat,
  9390. int numberOfTimesToRepeat) throw()
  9391. {
  9392. const int len = CharacterFunctions::length (stringToRepeat);
  9393. String result ((int) (len * numberOfTimesToRepeat + 1), (int) 0);
  9394. tchar* n = result.text->text;
  9395. n[0] = 0;
  9396. while (--numberOfTimesToRepeat >= 0)
  9397. {
  9398. CharacterFunctions::append (n, stringToRepeat);
  9399. n += len;
  9400. }
  9401. return result;
  9402. }
  9403. const String String::replaceSection (int index,
  9404. int numCharsToReplace,
  9405. const tchar* const stringToInsert) const throw()
  9406. {
  9407. if (index < 0)
  9408. {
  9409. // a negative index to replace from?
  9410. jassertfalse
  9411. index = 0;
  9412. }
  9413. if (numCharsToReplace < 0)
  9414. {
  9415. // replacing a negative number of characters?
  9416. numCharsToReplace = 0;
  9417. jassertfalse;
  9418. }
  9419. const int len = length();
  9420. if (index + numCharsToReplace > len)
  9421. {
  9422. if (index > len)
  9423. {
  9424. // replacing beyond the end of the string?
  9425. index = len;
  9426. jassertfalse
  9427. }
  9428. numCharsToReplace = len - index;
  9429. }
  9430. const int newStringLen = (stringToInsert != 0) ? CharacterFunctions::length (stringToInsert) : 0;
  9431. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9432. if (newTotalLen <= 0)
  9433. return String::empty;
  9434. String result (newTotalLen, (int) 0);
  9435. memcpy (result.text->text,
  9436. text->text,
  9437. index * sizeof (tchar));
  9438. if (newStringLen > 0)
  9439. memcpy (result.text->text + index,
  9440. stringToInsert,
  9441. newStringLen * sizeof (tchar));
  9442. const int endStringLen = newTotalLen - (index + newStringLen);
  9443. if (endStringLen > 0)
  9444. memcpy (result.text->text + (index + newStringLen),
  9445. text->text + (index + numCharsToReplace),
  9446. endStringLen * sizeof (tchar));
  9447. result.text->text [newTotalLen] = 0;
  9448. return result;
  9449. }
  9450. const String String::replace (const tchar* const stringToReplace,
  9451. const tchar* const stringToInsert,
  9452. const bool ignoreCase) const throw()
  9453. {
  9454. const int stringToReplaceLen = CharacterFunctions::length (stringToReplace);
  9455. const int stringToInsertLen = CharacterFunctions::length (stringToInsert);
  9456. int i = 0;
  9457. String result (*this);
  9458. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9459. : result.indexOf (i, stringToReplace))) >= 0)
  9460. {
  9461. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9462. i += stringToInsertLen;
  9463. }
  9464. return result;
  9465. }
  9466. const String String::replaceCharacter (const tchar charToReplace,
  9467. const tchar charToInsert) const throw()
  9468. {
  9469. const int index = indexOfChar (charToReplace);
  9470. if (index < 0)
  9471. return *this;
  9472. String result (*this);
  9473. result.dupeInternalIfMultiplyReferenced();
  9474. tchar* t = result.text->text + index;
  9475. while (*t != 0)
  9476. {
  9477. if (*t == charToReplace)
  9478. *t = charToInsert;
  9479. ++t;
  9480. }
  9481. return result;
  9482. }
  9483. const String String::replaceCharacters (const String& charactersToReplace,
  9484. const tchar* const charactersToInsertInstead) const throw()
  9485. {
  9486. String result (*this);
  9487. result.dupeInternalIfMultiplyReferenced();
  9488. tchar* t = result.text->text;
  9489. const int len2 = CharacterFunctions::length (charactersToInsertInstead);
  9490. // the two strings passed in are supposed to be the same length!
  9491. jassert (len2 == charactersToReplace.length());
  9492. while (*t != 0)
  9493. {
  9494. const int index = charactersToReplace.indexOfChar (*t);
  9495. if (((unsigned int) index) < (unsigned int) len2)
  9496. *t = charactersToInsertInstead [index];
  9497. ++t;
  9498. }
  9499. return result;
  9500. }
  9501. bool String::startsWith (const tchar* const other) const throw()
  9502. {
  9503. return other != 0
  9504. && CharacterFunctions::compare (text->text, other, CharacterFunctions::length (other)) == 0;
  9505. }
  9506. bool String::startsWithIgnoreCase (const tchar* const other) const throw()
  9507. {
  9508. return other != 0
  9509. && CharacterFunctions::compareIgnoreCase (text->text, other, CharacterFunctions::length (other)) == 0;
  9510. }
  9511. bool String::startsWithChar (const tchar character) const throw()
  9512. {
  9513. jassert (character != 0); // strings can't contain a null character!
  9514. return text->text[0] == character;
  9515. }
  9516. bool String::endsWithChar (const tchar character) const throw()
  9517. {
  9518. jassert (character != 0); // strings can't contain a null character!
  9519. return text->text[0] != 0
  9520. && text->text [length() - 1] == character;
  9521. }
  9522. bool String::endsWith (const tchar* const other) const throw()
  9523. {
  9524. if (other == 0)
  9525. return false;
  9526. const int thisLen = length();
  9527. const int otherLen = CharacterFunctions::length (other);
  9528. return thisLen >= otherLen
  9529. && CharacterFunctions::compare (text->text + thisLen - otherLen, other) == 0;
  9530. }
  9531. bool String::endsWithIgnoreCase (const tchar* const other) const throw()
  9532. {
  9533. if (other == 0)
  9534. return false;
  9535. const int thisLen = length();
  9536. const int otherLen = CharacterFunctions::length (other);
  9537. return thisLen >= otherLen
  9538. && CharacterFunctions::compareIgnoreCase (text->text + thisLen - otherLen, other) == 0;
  9539. }
  9540. const String String::toUpperCase() const throw()
  9541. {
  9542. String result (*this);
  9543. result.dupeInternalIfMultiplyReferenced();
  9544. CharacterFunctions::toUpperCase (result.text->text);
  9545. return result;
  9546. }
  9547. const String String::toLowerCase() const throw()
  9548. {
  9549. String result (*this);
  9550. result.dupeInternalIfMultiplyReferenced();
  9551. CharacterFunctions::toLowerCase (result.text->text);
  9552. return result;
  9553. }
  9554. tchar& String::operator[] (const int index) throw()
  9555. {
  9556. jassert (((unsigned int) index) <= (unsigned int) length());
  9557. dupeInternalIfMultiplyReferenced();
  9558. return text->text [index];
  9559. }
  9560. tchar String::getLastCharacter() const throw()
  9561. {
  9562. return (isEmpty()) ? ((tchar) 0)
  9563. : text->text [CharacterFunctions::length (text->text) - 1];
  9564. }
  9565. const String String::substring (int start, int end) const throw()
  9566. {
  9567. if (start < 0)
  9568. start = 0;
  9569. else if (end <= start)
  9570. return empty;
  9571. int len = 0;
  9572. const tchar* const t = text->text;
  9573. while (len <= end && t [len] != 0)
  9574. ++len;
  9575. if (end >= len)
  9576. {
  9577. if (start == 0)
  9578. return *this;
  9579. end = len;
  9580. }
  9581. return String (text->text + start,
  9582. end - start);
  9583. }
  9584. const String String::substring (const int start) const throw()
  9585. {
  9586. if (start <= 0)
  9587. return *this;
  9588. const int len = CharacterFunctions::length (text->text);
  9589. if (start >= len)
  9590. return empty;
  9591. else
  9592. return String (text->text + start,
  9593. len - start);
  9594. }
  9595. const String String::dropLastCharacters (const int numberToDrop) const throw()
  9596. {
  9597. return String (text->text,
  9598. jmax (0, CharacterFunctions::length (text->text) - numberToDrop));
  9599. }
  9600. const String String::getLastCharacters (const int numCharacters) const throw()
  9601. {
  9602. return String (text->text + jmax (0, CharacterFunctions::length (text->text) - jmax (0, numCharacters)));
  9603. }
  9604. const String String::fromFirstOccurrenceOf (const tchar* const sub,
  9605. const bool includeSubString,
  9606. const bool ignoreCase) const throw()
  9607. {
  9608. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9609. : indexOf (sub);
  9610. if (i < 0)
  9611. return empty;
  9612. else
  9613. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9614. }
  9615. const String String::fromLastOccurrenceOf (const tchar* const sub,
  9616. const bool includeSubString,
  9617. const bool ignoreCase) const throw()
  9618. {
  9619. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9620. : lastIndexOf (sub);
  9621. if (i < 0)
  9622. return *this;
  9623. else
  9624. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9625. }
  9626. const String String::upToFirstOccurrenceOf (const tchar* const sub,
  9627. const bool includeSubString,
  9628. const bool ignoreCase) const throw()
  9629. {
  9630. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9631. : indexOf (sub);
  9632. if (i < 0)
  9633. return *this;
  9634. else
  9635. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9636. }
  9637. const String String::upToLastOccurrenceOf (const tchar* const sub,
  9638. const bool includeSubString,
  9639. const bool ignoreCase) const throw()
  9640. {
  9641. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9642. : lastIndexOf (sub);
  9643. if (i < 0)
  9644. return *this;
  9645. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9646. }
  9647. bool String::isQuotedString() const throw()
  9648. {
  9649. const String trimmed (trimStart());
  9650. return trimmed[0] == T('"')
  9651. || trimmed[0] == T('\'');
  9652. }
  9653. const String String::unquoted() const throw()
  9654. {
  9655. String s (*this);
  9656. if (s[0] == T('"') || s[0] == T('\''))
  9657. s = s.substring (1);
  9658. const int lastCharIndex = s.length() - 1;
  9659. if (lastCharIndex >= 0
  9660. && (s [lastCharIndex] == T('"') || s[lastCharIndex] == T('\'')))
  9661. s [lastCharIndex] = 0;
  9662. return s;
  9663. }
  9664. const String String::quoted (const tchar quoteCharacter) const throw()
  9665. {
  9666. if (isEmpty())
  9667. return charToString (quoteCharacter) + quoteCharacter;
  9668. String t (*this);
  9669. if (! t.startsWithChar (quoteCharacter))
  9670. t = charToString (quoteCharacter) + t;
  9671. if (! t.endsWithChar (quoteCharacter))
  9672. t += quoteCharacter;
  9673. return t;
  9674. }
  9675. const String String::trim() const throw()
  9676. {
  9677. if (isEmpty())
  9678. return empty;
  9679. int start = 0;
  9680. while (CharacterFunctions::isWhitespace (text->text [start]))
  9681. ++start;
  9682. const int len = CharacterFunctions::length (text->text);
  9683. int end = len - 1;
  9684. while ((end >= start) && CharacterFunctions::isWhitespace (text->text [end]))
  9685. --end;
  9686. ++end;
  9687. if (end <= start)
  9688. return empty;
  9689. else if (start > 0 || end < len)
  9690. return String (text->text + start, end - start);
  9691. else
  9692. return *this;
  9693. }
  9694. const String String::trimStart() const throw()
  9695. {
  9696. if (isEmpty())
  9697. return empty;
  9698. const tchar* t = text->text;
  9699. while (CharacterFunctions::isWhitespace (*t))
  9700. ++t;
  9701. if (t == text->text)
  9702. return *this;
  9703. else
  9704. return String (t);
  9705. }
  9706. const String String::trimEnd() const throw()
  9707. {
  9708. if (isEmpty())
  9709. return empty;
  9710. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9711. while ((endT >= text->text) && CharacterFunctions::isWhitespace (*endT))
  9712. --endT;
  9713. return String (text->text, (int) (++endT - text->text));
  9714. }
  9715. const String String::trimCharactersAtStart (const tchar* charactersToTrim) const throw()
  9716. {
  9717. jassert (charactersToTrim != 0);
  9718. if (isEmpty())
  9719. return empty;
  9720. const tchar* t = text->text;
  9721. while (CharacterFunctions::indexOfCharFast (charactersToTrim, *t) >= 0)
  9722. ++t;
  9723. if (t == text->text)
  9724. return *this;
  9725. else
  9726. return String (t);
  9727. }
  9728. const String String::trimCharactersAtEnd (const tchar* charactersToTrim) const throw()
  9729. {
  9730. jassert (charactersToTrim != 0);
  9731. if (isEmpty())
  9732. return empty;
  9733. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9734. while ((endT >= text->text) && CharacterFunctions::indexOfCharFast (charactersToTrim, *endT) >= 0)
  9735. --endT;
  9736. return String (text->text, (int) (++endT - text->text));
  9737. }
  9738. const String String::retainCharacters (const tchar* const charactersToRetain) const throw()
  9739. {
  9740. jassert (charactersToRetain != 0);
  9741. if (isEmpty())
  9742. return empty;
  9743. String result (text->allocatedNumChars, (int) 0);
  9744. tchar* dst = result.text->text;
  9745. const tchar* src = text->text;
  9746. while (*src != 0)
  9747. {
  9748. if (CharacterFunctions::indexOfCharFast (charactersToRetain, *src) >= 0)
  9749. *dst++ = *src;
  9750. ++src;
  9751. }
  9752. *dst = 0;
  9753. return result;
  9754. }
  9755. const String String::removeCharacters (const tchar* const charactersToRemove) const throw()
  9756. {
  9757. jassert (charactersToRemove != 0);
  9758. if (isEmpty())
  9759. return empty;
  9760. String result (text->allocatedNumChars, (int) 0);
  9761. tchar* dst = result.text->text;
  9762. const tchar* src = text->text;
  9763. while (*src != 0)
  9764. {
  9765. if (CharacterFunctions::indexOfCharFast (charactersToRemove, *src) < 0)
  9766. *dst++ = *src;
  9767. ++src;
  9768. }
  9769. *dst = 0;
  9770. return result;
  9771. }
  9772. const String String::initialSectionContainingOnly (const tchar* const permittedCharacters) const throw()
  9773. {
  9774. return substring (0, CharacterFunctions::getIntialSectionContainingOnly (text->text, permittedCharacters));
  9775. }
  9776. const String String::initialSectionNotContaining (const tchar* const charactersToStopAt) const throw()
  9777. {
  9778. jassert (charactersToStopAt != 0);
  9779. const tchar* const t = text->text;
  9780. int i = 0;
  9781. while (t[i] != 0)
  9782. {
  9783. if (CharacterFunctions::indexOfCharFast (charactersToStopAt, t[i]) >= 0)
  9784. return String (text->text, i);
  9785. ++i;
  9786. }
  9787. return empty;
  9788. }
  9789. bool String::containsOnly (const tchar* const chars) const throw()
  9790. {
  9791. jassert (chars != 0);
  9792. const tchar* t = text->text;
  9793. while (*t != 0)
  9794. if (CharacterFunctions::indexOfCharFast (chars, *t++) < 0)
  9795. return false;
  9796. return true;
  9797. }
  9798. bool String::containsAnyOf (const tchar* const chars) const throw()
  9799. {
  9800. jassert (chars != 0);
  9801. const tchar* t = text->text;
  9802. while (*t != 0)
  9803. if (CharacterFunctions::indexOfCharFast (chars, *t++) >= 0)
  9804. return true;
  9805. return false;
  9806. }
  9807. bool String::containsNonWhitespaceChars() const throw()
  9808. {
  9809. const tchar* t = text->text;
  9810. while (*t != 0)
  9811. if (! CharacterFunctions::isWhitespace (*t++))
  9812. return true;
  9813. return false;
  9814. }
  9815. int String::getIntValue() const throw()
  9816. {
  9817. return CharacterFunctions::getIntValue (text->text);
  9818. }
  9819. int String::getTrailingIntValue() const throw()
  9820. {
  9821. int n = 0;
  9822. int mult = 1;
  9823. const tchar* t = text->text + length();
  9824. while (--t >= text->text)
  9825. {
  9826. const tchar c = *t;
  9827. if (! CharacterFunctions::isDigit (c))
  9828. {
  9829. if (c == T('-'))
  9830. n = -n;
  9831. break;
  9832. }
  9833. n += mult * (c - T('0'));
  9834. mult *= 10;
  9835. }
  9836. return n;
  9837. }
  9838. int64 String::getLargeIntValue() const throw()
  9839. {
  9840. return CharacterFunctions::getInt64Value (text->text);
  9841. }
  9842. float String::getFloatValue() const throw()
  9843. {
  9844. return (float) CharacterFunctions::getDoubleValue (text->text);
  9845. }
  9846. double String::getDoubleValue() const throw()
  9847. {
  9848. return CharacterFunctions::getDoubleValue (text->text);
  9849. }
  9850. static const tchar* const hexDigits = T("0123456789abcdef");
  9851. const String String::toHexString (const int number) throw()
  9852. {
  9853. tchar buffer[32];
  9854. tchar* const end = buffer + 32;
  9855. tchar* t = end;
  9856. *--t = 0;
  9857. unsigned int v = (unsigned int) number;
  9858. do
  9859. {
  9860. *--t = hexDigits [v & 15];
  9861. v >>= 4;
  9862. } while (v != 0);
  9863. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9864. }
  9865. const String String::toHexString (const int64 number) throw()
  9866. {
  9867. tchar buffer[32];
  9868. tchar* const end = buffer + 32;
  9869. tchar* t = end;
  9870. *--t = 0;
  9871. uint64 v = (uint64) number;
  9872. do
  9873. {
  9874. *--t = hexDigits [(int) (v & 15)];
  9875. v >>= 4;
  9876. } while (v != 0);
  9877. return String (t, (int) (((char*) end) - (char*) t));
  9878. }
  9879. const String String::toHexString (const short number) throw()
  9880. {
  9881. return toHexString ((int) (unsigned short) number);
  9882. }
  9883. const String String::toHexString (const unsigned char* data,
  9884. const int size,
  9885. const int groupSize) throw()
  9886. {
  9887. if (size <= 0)
  9888. return empty;
  9889. int numChars = (size * 2) + 2;
  9890. if (groupSize > 0)
  9891. numChars += size / groupSize;
  9892. String s (numChars, (int) 0);
  9893. tchar* d = s.text->text;
  9894. for (int i = 0; i < size; ++i)
  9895. {
  9896. *d++ = hexDigits [(*data) >> 4];
  9897. *d++ = hexDigits [(*data) & 0xf];
  9898. ++data;
  9899. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9900. *d++ = T(' ');
  9901. }
  9902. *d = 0;
  9903. return s;
  9904. }
  9905. int String::getHexValue32() const throw()
  9906. {
  9907. int result = 0;
  9908. const tchar* c = text->text;
  9909. for (;;)
  9910. {
  9911. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9912. if (hexValue >= 0)
  9913. result = (result << 4) | hexValue;
  9914. else if (*c == 0)
  9915. break;
  9916. ++c;
  9917. }
  9918. return result;
  9919. }
  9920. int64 String::getHexValue64() const throw()
  9921. {
  9922. int64 result = 0;
  9923. const tchar* c = text->text;
  9924. for (;;)
  9925. {
  9926. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9927. if (hexValue >= 0)
  9928. result = (result << 4) | hexValue;
  9929. else if (*c == 0)
  9930. break;
  9931. ++c;
  9932. }
  9933. return result;
  9934. }
  9935. const String String::createStringFromData (const void* const data_,
  9936. const int size) throw()
  9937. {
  9938. const char* const data = (const char*) data_;
  9939. if (size <= 0 || data == 0)
  9940. {
  9941. return empty;
  9942. }
  9943. else if (size < 2)
  9944. {
  9945. return charToString (data[0]);
  9946. }
  9947. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9948. || (data[0] == (char)-1 && data[1] == (char)-2))
  9949. {
  9950. // assume it's 16-bit unicode
  9951. const bool bigEndian = (data[0] == (char)-2);
  9952. const int numChars = size / 2 - 1;
  9953. String result;
  9954. result.preallocateStorage (numChars + 2);
  9955. const uint16* const src = (const uint16*) (data + 2);
  9956. tchar* const dst = const_cast <tchar*> ((const tchar*) result);
  9957. if (bigEndian)
  9958. {
  9959. for (int i = 0; i < numChars; ++i)
  9960. dst[i] = (tchar) ByteOrder::swapIfLittleEndian (src[i]);
  9961. }
  9962. else
  9963. {
  9964. for (int i = 0; i < numChars; ++i)
  9965. dst[i] = (tchar) ByteOrder::swapIfBigEndian (src[i]);
  9966. }
  9967. dst [numChars] = 0;
  9968. return result;
  9969. }
  9970. else
  9971. {
  9972. return String::fromUTF8 ((const uint8*) data, size);
  9973. }
  9974. }
  9975. const char* String::toUTF8() const throw()
  9976. {
  9977. if (isEmpty())
  9978. {
  9979. return (const char*) emptyCharString;
  9980. }
  9981. else
  9982. {
  9983. String* const mutableThis = const_cast <String*> (this);
  9984. mutableThis->dupeInternalIfMultiplyReferenced();
  9985. const int currentLen = CharacterFunctions::length (text->text) + 1;
  9986. const int utf8BytesNeeded = copyToUTF8 (0);
  9987. mutableThis->text = (InternalRefCountedStringHolder*)
  9988. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  9989. + (currentLen * sizeof (juce_wchar) + utf8BytesNeeded));
  9990. char* const otherCopy = (char*) (text->text + currentLen);
  9991. copyToUTF8 ((uint8*) otherCopy);
  9992. return otherCopy;
  9993. }
  9994. }
  9995. int String::copyToUTF8 (uint8* const buffer, const int maxBufferSizeBytes) const throw()
  9996. {
  9997. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9998. #if JUCE_STRINGS_ARE_UNICODE
  9999. int num = 0, index = 0;
  10000. for (;;)
  10001. {
  10002. const uint32 c = (uint32) text->text [index++];
  10003. if (c >= 0x80)
  10004. {
  10005. int numExtraBytes = 1;
  10006. if (c >= 0x800)
  10007. {
  10008. ++numExtraBytes;
  10009. if (c >= 0x10000)
  10010. {
  10011. ++numExtraBytes;
  10012. if (c >= 0x200000)
  10013. {
  10014. ++numExtraBytes;
  10015. if (c >= 0x4000000)
  10016. ++numExtraBytes;
  10017. }
  10018. }
  10019. }
  10020. if (buffer != 0)
  10021. {
  10022. if (num + numExtraBytes >= maxBufferSizeBytes)
  10023. {
  10024. buffer [num++] = 0;
  10025. break;
  10026. }
  10027. else
  10028. {
  10029. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  10030. while (--numExtraBytes >= 0)
  10031. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  10032. }
  10033. }
  10034. else
  10035. {
  10036. num += numExtraBytes + 1;
  10037. }
  10038. }
  10039. else
  10040. {
  10041. if (buffer != 0)
  10042. {
  10043. if (num + 1 >= maxBufferSizeBytes)
  10044. {
  10045. buffer [num++] = 0;
  10046. break;
  10047. }
  10048. buffer [num] = (uint8) c;
  10049. }
  10050. ++num;
  10051. }
  10052. if (c == 0)
  10053. break;
  10054. }
  10055. return num;
  10056. #else
  10057. const int numBytes = jmin (maxBufferSizeBytes, length() + 1);
  10058. if (buffer != 0)
  10059. copyToBuffer ((char*) buffer, maxBufferSizeBytes);
  10060. return numBytes;
  10061. #endif
  10062. }
  10063. const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) throw()
  10064. {
  10065. if (buffer == 0)
  10066. return empty;
  10067. if (bufferSizeBytes < 0)
  10068. bufferSizeBytes = std::numeric_limits<int>::max();
  10069. size_t numBytes;
  10070. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  10071. if (buffer [numBytes] == 0)
  10072. break;
  10073. String result ((int) numBytes + 1, 0);
  10074. tchar* dest = result.text->text;
  10075. size_t i = 0;
  10076. while (i < numBytes)
  10077. {
  10078. const uint8 c = buffer [i++];
  10079. if ((c & 0x80) != 0)
  10080. {
  10081. int mask = 0x7f;
  10082. int bit = 0x40;
  10083. int numExtraValues = 0;
  10084. while (bit != 0 && (c & bit) != 0)
  10085. {
  10086. bit >>= 1;
  10087. mask >>= 1;
  10088. ++numExtraValues;
  10089. }
  10090. int n = (c & mask);
  10091. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  10092. {
  10093. const uint8 nextByte = buffer[i];
  10094. if ((nextByte & 0xc0) != 0x80)
  10095. break;
  10096. n <<= 6;
  10097. n |= (nextByte & 0x3f);
  10098. ++i;
  10099. }
  10100. *dest++ = (tchar) n;
  10101. }
  10102. else
  10103. {
  10104. *dest++ = (tchar) c;
  10105. }
  10106. }
  10107. *dest = 0;
  10108. return result;
  10109. }
  10110. String::Concatenator::Concatenator (String& stringToAppendTo)
  10111. : result (stringToAppendTo),
  10112. nextIndex (stringToAppendTo.length())
  10113. {
  10114. }
  10115. String::Concatenator::~Concatenator()
  10116. {
  10117. }
  10118. void String::Concatenator::append (const String& s)
  10119. {
  10120. const int len = s.length();
  10121. if (len > 0)
  10122. {
  10123. result.preallocateStorage (nextIndex + len);
  10124. s.copyToBuffer (const_cast <tchar*> ((const tchar*) result) + nextIndex, len);
  10125. nextIndex += len;
  10126. }
  10127. }
  10128. END_JUCE_NAMESPACE
  10129. /*** End of inlined file: juce_String.cpp ***/
  10130. /*** Start of inlined file: juce_StringArray.cpp ***/
  10131. BEGIN_JUCE_NAMESPACE
  10132. StringArray::StringArray() throw()
  10133. {
  10134. }
  10135. StringArray::StringArray (const StringArray& other)
  10136. : strings (other.strings)
  10137. {
  10138. }
  10139. StringArray::StringArray (const juce_wchar** const initialStrings,
  10140. const int numberOfStrings)
  10141. {
  10142. for (int i = 0; i < numberOfStrings; ++i)
  10143. add (initialStrings [i]);
  10144. }
  10145. StringArray::StringArray (const char** const initialStrings,
  10146. const int numberOfStrings)
  10147. {
  10148. for (int i = 0; i < numberOfStrings; ++i)
  10149. add (initialStrings [i]);
  10150. }
  10151. StringArray::StringArray (const juce_wchar** const initialStrings)
  10152. {
  10153. int i = 0;
  10154. while (initialStrings[i] != 0)
  10155. add (initialStrings [i++]);
  10156. }
  10157. StringArray::StringArray (const char** const initialStrings)
  10158. {
  10159. int i = 0;
  10160. while (initialStrings[i] != 0)
  10161. add (initialStrings [i++]);
  10162. }
  10163. const StringArray& StringArray::operator= (const StringArray& other)
  10164. {
  10165. strings = other.strings;
  10166. return *this;
  10167. }
  10168. StringArray::~StringArray()
  10169. {
  10170. }
  10171. bool StringArray::operator== (const StringArray& other) const
  10172. {
  10173. if (other.size() != size())
  10174. return false;
  10175. for (int i = size(); --i >= 0;)
  10176. if (other.strings.getReference(i) != strings.getReference(i))
  10177. return false;
  10178. return true;
  10179. }
  10180. bool StringArray::operator!= (const StringArray& other) const
  10181. {
  10182. return ! operator== (other);
  10183. }
  10184. void StringArray::clear()
  10185. {
  10186. strings.clear();
  10187. }
  10188. const String& StringArray::operator[] (const int index) const throw()
  10189. {
  10190. if (((unsigned int) index) < (unsigned int) strings.size())
  10191. return strings.getReference (index);
  10192. return String::empty;
  10193. }
  10194. void StringArray::add (const String& newString)
  10195. {
  10196. strings.add (newString);
  10197. }
  10198. void StringArray::insert (const int index, const String& newString)
  10199. {
  10200. strings.insert (index, newString);
  10201. }
  10202. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  10203. {
  10204. if (! contains (newString, ignoreCase))
  10205. add (newString);
  10206. }
  10207. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  10208. {
  10209. if (startIndex < 0)
  10210. {
  10211. jassertfalse
  10212. startIndex = 0;
  10213. }
  10214. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  10215. numElementsToAdd = otherArray.size() - startIndex;
  10216. while (--numElementsToAdd >= 0)
  10217. strings.add (otherArray.strings.getReference (startIndex++));
  10218. }
  10219. void StringArray::set (const int index, const String& newString)
  10220. {
  10221. strings.set (index, newString);
  10222. }
  10223. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  10224. {
  10225. if (ignoreCase)
  10226. {
  10227. for (int i = size(); --i >= 0;)
  10228. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10229. return true;
  10230. }
  10231. else
  10232. {
  10233. for (int i = size(); --i >= 0;)
  10234. if (stringToLookFor == strings.getReference(i))
  10235. return true;
  10236. }
  10237. return false;
  10238. }
  10239. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  10240. {
  10241. if (i < 0)
  10242. i = 0;
  10243. const int numElements = size();
  10244. if (ignoreCase)
  10245. {
  10246. while (i < numElements)
  10247. {
  10248. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10249. return i;
  10250. ++i;
  10251. }
  10252. }
  10253. else
  10254. {
  10255. while (i < numElements)
  10256. {
  10257. if (stringToLookFor == strings.getReference (i))
  10258. return i;
  10259. ++i;
  10260. }
  10261. }
  10262. return -1;
  10263. }
  10264. void StringArray::remove (const int index)
  10265. {
  10266. strings.remove (index);
  10267. }
  10268. void StringArray::removeString (const String& stringToRemove,
  10269. const bool ignoreCase)
  10270. {
  10271. if (ignoreCase)
  10272. {
  10273. for (int i = size(); --i >= 0;)
  10274. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  10275. strings.remove (i);
  10276. }
  10277. else
  10278. {
  10279. for (int i = size(); --i >= 0;)
  10280. if (stringToRemove == strings.getReference (i))
  10281. strings.remove (i);
  10282. }
  10283. }
  10284. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  10285. {
  10286. if (removeWhitespaceStrings)
  10287. {
  10288. for (int i = size(); --i >= 0;)
  10289. if (! strings.getReference(i).containsNonWhitespaceChars())
  10290. strings.remove (i);
  10291. }
  10292. else
  10293. {
  10294. for (int i = size(); --i >= 0;)
  10295. if (strings.getReference(i).isEmpty())
  10296. strings.remove (i);
  10297. }
  10298. }
  10299. void StringArray::trim()
  10300. {
  10301. for (int i = size(); --i >= 0;)
  10302. {
  10303. String& s = strings.getReference(i);
  10304. s = s.trim();
  10305. }
  10306. }
  10307. class InternalStringArrayComparator_CaseSensitive
  10308. {
  10309. public:
  10310. static int compareElements (String& first, String& second) { return first.compare (second); }
  10311. };
  10312. class InternalStringArrayComparator_CaseInsensitive
  10313. {
  10314. public:
  10315. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10316. };
  10317. void StringArray::sort (const bool ignoreCase)
  10318. {
  10319. if (ignoreCase)
  10320. {
  10321. InternalStringArrayComparator_CaseInsensitive comp;
  10322. strings.sort (comp);
  10323. }
  10324. else
  10325. {
  10326. InternalStringArrayComparator_CaseSensitive comp;
  10327. strings.sort (comp);
  10328. }
  10329. }
  10330. void StringArray::move (const int currentIndex, int newIndex) throw()
  10331. {
  10332. strings.move (currentIndex, newIndex);
  10333. }
  10334. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10335. {
  10336. const int last = (numberToJoin < 0) ? size()
  10337. : jmin (size(), start + numberToJoin);
  10338. if (start < 0)
  10339. start = 0;
  10340. if (start >= last)
  10341. return String::empty;
  10342. if (start == last - 1)
  10343. return strings.getReference (start);
  10344. const int separatorLen = separator.length();
  10345. int charsNeeded = separatorLen * (last - start - 1);
  10346. for (int i = start; i < last; ++i)
  10347. charsNeeded += strings.getReference(i).length();
  10348. String result;
  10349. result.preallocateStorage (charsNeeded);
  10350. tchar* dest = (tchar*) (const tchar*) result;
  10351. while (start < last)
  10352. {
  10353. const String& s = strings.getReference (start);
  10354. const int len = s.length();
  10355. if (len > 0)
  10356. {
  10357. s.copyToBuffer (dest, len);
  10358. dest += len;
  10359. }
  10360. if (++start < last && separatorLen > 0)
  10361. {
  10362. separator.copyToBuffer (dest, separatorLen);
  10363. dest += separatorLen;
  10364. }
  10365. }
  10366. *dest = 0;
  10367. return result;
  10368. }
  10369. int StringArray::addTokens (const tchar* const text, const bool preserveQuotedStrings)
  10370. {
  10371. return addTokens (text,
  10372. T(" \n\r\t"),
  10373. preserveQuotedStrings ? T("\"") : 0);
  10374. }
  10375. int StringArray::addTokens (const tchar* const text, const tchar* breakCharacters, const tchar* quoteCharacters)
  10376. {
  10377. int num = 0;
  10378. if (text != 0 && *text != 0)
  10379. {
  10380. if (breakCharacters == 0)
  10381. breakCharacters = T("");
  10382. if (quoteCharacters == 0)
  10383. quoteCharacters = T("");
  10384. bool insideQuotes = false;
  10385. tchar currentQuoteChar = 0;
  10386. int i = 0;
  10387. int tokenStart = 0;
  10388. for (;;)
  10389. {
  10390. const tchar c = text[i];
  10391. bool isBreak = (c == 0);
  10392. if (! (insideQuotes || isBreak))
  10393. {
  10394. const tchar* b = breakCharacters;
  10395. while (*b != 0)
  10396. {
  10397. if (*b++ == c)
  10398. {
  10399. isBreak = true;
  10400. break;
  10401. }
  10402. }
  10403. }
  10404. if (! isBreak)
  10405. {
  10406. bool isQuote = false;
  10407. const tchar* q = quoteCharacters;
  10408. while (*q != 0)
  10409. {
  10410. if (*q++ == c)
  10411. {
  10412. isQuote = true;
  10413. break;
  10414. }
  10415. }
  10416. if (isQuote)
  10417. {
  10418. if (insideQuotes)
  10419. {
  10420. // only break out of quotes-mode if we find a matching quote to the
  10421. // one that we opened with..
  10422. if (currentQuoteChar == c)
  10423. insideQuotes = false;
  10424. }
  10425. else
  10426. {
  10427. insideQuotes = true;
  10428. currentQuoteChar = c;
  10429. }
  10430. }
  10431. }
  10432. else
  10433. {
  10434. add (String (text + tokenStart, i - tokenStart));
  10435. ++num;
  10436. tokenStart = i + 1;
  10437. }
  10438. if (c == 0)
  10439. break;
  10440. ++i;
  10441. }
  10442. }
  10443. return num;
  10444. }
  10445. int StringArray::addLines (const tchar* text)
  10446. {
  10447. int numLines = 0;
  10448. if (text != 0)
  10449. {
  10450. while (*text != 0)
  10451. {
  10452. const tchar* const startOfLine = text;
  10453. while (*text != 0)
  10454. {
  10455. if (*text == T('\r'))
  10456. {
  10457. ++text;
  10458. if (*text == T('\n'))
  10459. ++text;
  10460. break;
  10461. }
  10462. if (*text == T('\n'))
  10463. {
  10464. ++text;
  10465. break;
  10466. }
  10467. ++text;
  10468. }
  10469. const tchar* endOfLine = text;
  10470. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10471. --endOfLine;
  10472. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10473. --endOfLine;
  10474. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10475. ++numLines;
  10476. }
  10477. }
  10478. return numLines;
  10479. }
  10480. void StringArray::removeDuplicates (const bool ignoreCase)
  10481. {
  10482. for (int i = 0; i < size() - 1; ++i)
  10483. {
  10484. const String s (strings.getReference(i));
  10485. int nextIndex = i + 1;
  10486. for (;;)
  10487. {
  10488. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10489. if (nextIndex < 0)
  10490. break;
  10491. strings.remove (nextIndex);
  10492. }
  10493. }
  10494. }
  10495. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10496. const bool appendNumberToFirstInstance,
  10497. const tchar* const preNumberString,
  10498. const tchar* const postNumberString)
  10499. {
  10500. for (int i = 0; i < size() - 1; ++i)
  10501. {
  10502. String& s = strings.getReference(i);
  10503. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10504. if (nextIndex >= 0)
  10505. {
  10506. const String original (s);
  10507. int number = 0;
  10508. if (appendNumberToFirstInstance)
  10509. s = original + preNumberString + String (++number) + postNumberString;
  10510. else
  10511. ++number;
  10512. while (nextIndex >= 0)
  10513. {
  10514. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10515. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10516. }
  10517. }
  10518. }
  10519. }
  10520. void StringArray::minimiseStorageOverheads()
  10521. {
  10522. strings.minimiseStorageOverheads();
  10523. }
  10524. END_JUCE_NAMESPACE
  10525. /*** End of inlined file: juce_StringArray.cpp ***/
  10526. /*** Start of inlined file: juce_StringPairArray.cpp ***/
  10527. BEGIN_JUCE_NAMESPACE
  10528. StringPairArray::StringPairArray (const bool ignoreCase_) throw()
  10529. : ignoreCase (ignoreCase_)
  10530. {
  10531. }
  10532. StringPairArray::StringPairArray (const StringPairArray& other) throw()
  10533. : keys (other.keys),
  10534. values (other.values),
  10535. ignoreCase (other.ignoreCase)
  10536. {
  10537. }
  10538. StringPairArray::~StringPairArray() throw()
  10539. {
  10540. }
  10541. const StringPairArray& StringPairArray::operator= (const StringPairArray& other) throw()
  10542. {
  10543. keys = other.keys;
  10544. values = other.values;
  10545. return *this;
  10546. }
  10547. bool StringPairArray::operator== (const StringPairArray& other) const throw()
  10548. {
  10549. for (int i = keys.size(); --i >= 0;)
  10550. if (other [keys[i]] != values[i])
  10551. return false;
  10552. return true;
  10553. }
  10554. bool StringPairArray::operator!= (const StringPairArray& other) const throw()
  10555. {
  10556. return ! operator== (other);
  10557. }
  10558. const String& StringPairArray::operator[] (const String& key) const throw()
  10559. {
  10560. return values [keys.indexOf (key, ignoreCase)];
  10561. }
  10562. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10563. {
  10564. const int i = keys.indexOf (key, ignoreCase);
  10565. if (i >= 0)
  10566. return values[i];
  10567. return defaultReturnValue;
  10568. }
  10569. void StringPairArray::set (const String& key,
  10570. const String& value) throw()
  10571. {
  10572. const int i = keys.indexOf (key, ignoreCase);
  10573. if (i >= 0)
  10574. {
  10575. values.set (i, value);
  10576. }
  10577. else
  10578. {
  10579. keys.add (key);
  10580. values.add (value);
  10581. }
  10582. }
  10583. void StringPairArray::addArray (const StringPairArray& other)
  10584. {
  10585. for (int i = 0; i < other.size(); ++i)
  10586. set (other.keys[i], other.values[i]);
  10587. }
  10588. void StringPairArray::clear() throw()
  10589. {
  10590. keys.clear();
  10591. values.clear();
  10592. }
  10593. void StringPairArray::remove (const String& key) throw()
  10594. {
  10595. remove (keys.indexOf (key, ignoreCase));
  10596. }
  10597. void StringPairArray::remove (const int index) throw()
  10598. {
  10599. keys.remove (index);
  10600. values.remove (index);
  10601. }
  10602. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase) throw()
  10603. {
  10604. ignoreCase = shouldIgnoreCase;
  10605. }
  10606. const String StringPairArray::getDescription() const
  10607. {
  10608. String s;
  10609. for (int i = 0; i < keys.size(); ++i)
  10610. {
  10611. s << keys[i] << T(" = ") << values[i];
  10612. if (i < keys.size())
  10613. s << T(", ");
  10614. }
  10615. return s;
  10616. }
  10617. void StringPairArray::minimiseStorageOverheads() throw()
  10618. {
  10619. keys.minimiseStorageOverheads();
  10620. values.minimiseStorageOverheads();
  10621. }
  10622. END_JUCE_NAMESPACE
  10623. /*** End of inlined file: juce_StringPairArray.cpp ***/
  10624. /*** Start of inlined file: juce_XmlDocument.cpp ***/
  10625. BEGIN_JUCE_NAMESPACE
  10626. XmlDocument::XmlDocument (const String& documentText) throw()
  10627. : originalText (documentText),
  10628. ignoreEmptyTextElements (true)
  10629. {
  10630. }
  10631. XmlDocument::XmlDocument (const File& file)
  10632. {
  10633. inputSource = new FileInputSource (file);
  10634. }
  10635. XmlDocument::~XmlDocument() throw()
  10636. {
  10637. }
  10638. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10639. {
  10640. inputSource = newSource;
  10641. }
  10642. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10643. {
  10644. ignoreEmptyTextElements = shouldBeIgnored;
  10645. }
  10646. bool XmlDocument::isXmlIdentifierCharSlow (const tchar c) throw()
  10647. {
  10648. return CharacterFunctions::isLetterOrDigit (c)
  10649. || c == T('_')
  10650. || c == T('-')
  10651. || c == T(':')
  10652. || c == T('.');
  10653. }
  10654. inline bool XmlDocument::isXmlIdentifierChar (const tchar c) const throw()
  10655. {
  10656. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10657. : isXmlIdentifierCharSlow (c);
  10658. }
  10659. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10660. {
  10661. String textToParse (originalText);
  10662. if (textToParse.isEmpty() && inputSource != 0)
  10663. {
  10664. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10665. if (in != 0)
  10666. {
  10667. MemoryBlock data;
  10668. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10669. if (data.getSize() >= 2
  10670. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10671. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10672. {
  10673. textToParse = String::createStringFromData ((const char*) data.getData(), (int) data.getSize());
  10674. }
  10675. else
  10676. {
  10677. textToParse = String::fromUTF8 ((const uint8*) data.getData(), (int) data.getSize());
  10678. }
  10679. if (! onlyReadOuterDocumentElement)
  10680. originalText = textToParse;
  10681. }
  10682. }
  10683. input = textToParse;
  10684. lastError = String::empty;
  10685. errorOccurred = false;
  10686. outOfData = false;
  10687. needToLoadDTD = true;
  10688. for (int i = 0; i < 128; ++i)
  10689. identifierLookupTable[i] = isXmlIdentifierCharSlow ((tchar) i);
  10690. if (textToParse.isEmpty())
  10691. {
  10692. lastError = "not enough input";
  10693. }
  10694. else
  10695. {
  10696. skipHeader();
  10697. if (input != 0)
  10698. {
  10699. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10700. if (! errorOccurred)
  10701. return result.release();
  10702. }
  10703. else
  10704. {
  10705. lastError = "incorrect xml header";
  10706. }
  10707. }
  10708. return 0;
  10709. }
  10710. const String& XmlDocument::getLastParseError() const throw()
  10711. {
  10712. return lastError;
  10713. }
  10714. void XmlDocument::setLastError (const String& desc, const bool carryOn) throw()
  10715. {
  10716. lastError = desc;
  10717. errorOccurred = ! carryOn;
  10718. }
  10719. const String XmlDocument::getFileContents (const String& filename) const
  10720. {
  10721. if (inputSource != 0)
  10722. {
  10723. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10724. if (in != 0)
  10725. return in->readEntireStreamAsString();
  10726. }
  10727. return String::empty;
  10728. }
  10729. tchar XmlDocument::readNextChar() throw()
  10730. {
  10731. if (*input != 0)
  10732. {
  10733. return *input++;
  10734. }
  10735. else
  10736. {
  10737. outOfData = true;
  10738. return 0;
  10739. }
  10740. }
  10741. int XmlDocument::findNextTokenLength() throw()
  10742. {
  10743. int len = 0;
  10744. tchar c = *input;
  10745. while (isXmlIdentifierChar (c))
  10746. c = input [++len];
  10747. return len;
  10748. }
  10749. void XmlDocument::skipHeader() throw()
  10750. {
  10751. const tchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10752. if (found != 0)
  10753. {
  10754. input = found;
  10755. input = CharacterFunctions::find (input, T("?>"));
  10756. if (input == 0)
  10757. return;
  10758. input += 2;
  10759. }
  10760. skipNextWhiteSpace();
  10761. const tchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10762. if (docType == 0)
  10763. return;
  10764. input = docType + 9;
  10765. int n = 1;
  10766. while (n > 0)
  10767. {
  10768. const tchar c = readNextChar();
  10769. if (outOfData)
  10770. return;
  10771. if (c == T('<'))
  10772. ++n;
  10773. else if (c == T('>'))
  10774. --n;
  10775. }
  10776. docType += 9;
  10777. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10778. }
  10779. void XmlDocument::skipNextWhiteSpace() throw()
  10780. {
  10781. for (;;)
  10782. {
  10783. tchar c = *input;
  10784. while (CharacterFunctions::isWhitespace (c))
  10785. c = *++input;
  10786. if (c == 0)
  10787. {
  10788. outOfData = true;
  10789. break;
  10790. }
  10791. else if (c == T('<'))
  10792. {
  10793. if (input[1] == T('!')
  10794. && input[2] == T('-')
  10795. && input[3] == T('-'))
  10796. {
  10797. const tchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10798. if (closeComment == 0)
  10799. {
  10800. outOfData = true;
  10801. break;
  10802. }
  10803. input = closeComment + 3;
  10804. continue;
  10805. }
  10806. else if (input[1] == T('?'))
  10807. {
  10808. const tchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10809. if (closeBracket == 0)
  10810. {
  10811. outOfData = true;
  10812. break;
  10813. }
  10814. input = closeBracket + 2;
  10815. continue;
  10816. }
  10817. }
  10818. break;
  10819. }
  10820. }
  10821. void XmlDocument::readQuotedString (String& result) throw()
  10822. {
  10823. const tchar quote = readNextChar();
  10824. while (! outOfData)
  10825. {
  10826. const tchar c = readNextChar();
  10827. if (c == quote)
  10828. break;
  10829. if (c == T('&'))
  10830. {
  10831. --input;
  10832. readEntity (result);
  10833. }
  10834. else
  10835. {
  10836. --input;
  10837. const tchar* const start = input;
  10838. for (;;)
  10839. {
  10840. const tchar character = *input;
  10841. if (character == quote)
  10842. {
  10843. result.append (start, (int) (input - start));
  10844. ++input;
  10845. return;
  10846. }
  10847. else if (character == T('&'))
  10848. {
  10849. result.append (start, (int) (input - start));
  10850. break;
  10851. }
  10852. else if (character == 0)
  10853. {
  10854. outOfData = true;
  10855. setLastError ("unmatched quotes", false);
  10856. break;
  10857. }
  10858. ++input;
  10859. }
  10860. }
  10861. }
  10862. }
  10863. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) throw()
  10864. {
  10865. XmlElement* node = 0;
  10866. skipNextWhiteSpace();
  10867. if (outOfData)
  10868. return 0;
  10869. input = CharacterFunctions::find (input, T("<"));
  10870. if (input != 0)
  10871. {
  10872. ++input;
  10873. int tagLen = findNextTokenLength();
  10874. if (tagLen == 0)
  10875. {
  10876. // no tag name - but allow for a gap after the '<' before giving an error
  10877. skipNextWhiteSpace();
  10878. tagLen = findNextTokenLength();
  10879. if (tagLen == 0)
  10880. {
  10881. setLastError ("tag name missing", false);
  10882. return node;
  10883. }
  10884. }
  10885. node = new XmlElement (String (input, tagLen));
  10886. input += tagLen;
  10887. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10888. // look for attributes
  10889. for (;;)
  10890. {
  10891. skipNextWhiteSpace();
  10892. const tchar c = *input;
  10893. // empty tag..
  10894. if (c == T('/') && input[1] == T('>'))
  10895. {
  10896. input += 2;
  10897. break;
  10898. }
  10899. // parse the guts of the element..
  10900. if (c == T('>'))
  10901. {
  10902. ++input;
  10903. skipNextWhiteSpace();
  10904. if (alsoParseSubElements)
  10905. readChildElements (node);
  10906. break;
  10907. }
  10908. // get an attribute..
  10909. if (isXmlIdentifierChar (c))
  10910. {
  10911. const int attNameLen = findNextTokenLength();
  10912. if (attNameLen > 0)
  10913. {
  10914. const tchar* attNameStart = input;
  10915. input += attNameLen;
  10916. skipNextWhiteSpace();
  10917. if (readNextChar() == T('='))
  10918. {
  10919. skipNextWhiteSpace();
  10920. const tchar nextChar = *input;
  10921. if (nextChar == T('"') || nextChar == T('\''))
  10922. {
  10923. XmlElement::XmlAttributeNode* const newAtt
  10924. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10925. String::empty);
  10926. readQuotedString (newAtt->value);
  10927. if (lastAttribute == 0)
  10928. node->attributes = newAtt;
  10929. else
  10930. lastAttribute->next = newAtt;
  10931. lastAttribute = newAtt;
  10932. continue;
  10933. }
  10934. }
  10935. }
  10936. }
  10937. else
  10938. {
  10939. if (! outOfData)
  10940. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10941. }
  10942. break;
  10943. }
  10944. }
  10945. return node;
  10946. }
  10947. void XmlDocument::readChildElements (XmlElement* parent) throw()
  10948. {
  10949. XmlElement* lastChildNode = 0;
  10950. for (;;)
  10951. {
  10952. skipNextWhiteSpace();
  10953. if (outOfData)
  10954. {
  10955. setLastError ("unmatched tags", false);
  10956. break;
  10957. }
  10958. if (*input == T('<'))
  10959. {
  10960. if (input[1] == T('/'))
  10961. {
  10962. // our close tag..
  10963. input = CharacterFunctions::find (input, T(">"));
  10964. ++input;
  10965. break;
  10966. }
  10967. else if (input[1] == T('!')
  10968. && input[2] == T('[')
  10969. && input[3] == T('C')
  10970. && input[4] == T('D')
  10971. && input[5] == T('A')
  10972. && input[6] == T('T')
  10973. && input[7] == T('A')
  10974. && input[8] == T('['))
  10975. {
  10976. input += 9;
  10977. const tchar* const inputStart = input;
  10978. int len = 0;
  10979. for (;;)
  10980. {
  10981. if (*input == 0)
  10982. {
  10983. setLastError ("unterminated CDATA section", false);
  10984. outOfData = true;
  10985. break;
  10986. }
  10987. else if (input[0] == T(']')
  10988. && input[1] == T(']')
  10989. && input[2] == T('>'))
  10990. {
  10991. input += 3;
  10992. break;
  10993. }
  10994. ++input;
  10995. ++len;
  10996. }
  10997. XmlElement* const e = new XmlElement ((int) 0);
  10998. e->setText (String (inputStart, len));
  10999. if (lastChildNode != 0)
  11000. lastChildNode->nextElement = e;
  11001. else
  11002. parent->addChildElement (e);
  11003. lastChildNode = e;
  11004. }
  11005. else
  11006. {
  11007. // this is some other element, so parse and add it..
  11008. XmlElement* const n = readNextElement (true);
  11009. if (n != 0)
  11010. {
  11011. if (lastChildNode == 0)
  11012. parent->addChildElement (n);
  11013. else
  11014. lastChildNode->nextElement = n;
  11015. lastChildNode = n;
  11016. }
  11017. else
  11018. {
  11019. return;
  11020. }
  11021. }
  11022. }
  11023. else
  11024. {
  11025. // read character block..
  11026. XmlElement* const e = new XmlElement ((int)0);
  11027. if (lastChildNode != 0)
  11028. lastChildNode->nextElement = e;
  11029. else
  11030. parent->addChildElement (e);
  11031. lastChildNode = e;
  11032. String textElementContent;
  11033. for (;;)
  11034. {
  11035. const tchar c = *input;
  11036. if (c == T('<'))
  11037. break;
  11038. if (c == 0)
  11039. {
  11040. setLastError ("unmatched tags", false);
  11041. outOfData = true;
  11042. return;
  11043. }
  11044. if (c == T('&'))
  11045. {
  11046. String entity;
  11047. readEntity (entity);
  11048. if (entity.startsWithChar (T('<')) && entity [1] != 0)
  11049. {
  11050. const tchar* const oldInput = input;
  11051. const bool oldOutOfData = outOfData;
  11052. input = (const tchar*) entity;
  11053. outOfData = false;
  11054. for (;;)
  11055. {
  11056. XmlElement* const n = readNextElement (true);
  11057. if (n == 0)
  11058. break;
  11059. if (lastChildNode == 0)
  11060. parent->addChildElement (n);
  11061. else
  11062. lastChildNode->nextElement = n;
  11063. lastChildNode = n;
  11064. }
  11065. input = oldInput;
  11066. outOfData = oldOutOfData;
  11067. }
  11068. else
  11069. {
  11070. textElementContent += entity;
  11071. }
  11072. }
  11073. else
  11074. {
  11075. const tchar* start = input;
  11076. int len = 0;
  11077. for (;;)
  11078. {
  11079. const tchar nextChar = *input;
  11080. if (nextChar == T('<') || nextChar == T('&'))
  11081. {
  11082. break;
  11083. }
  11084. else if (nextChar == 0)
  11085. {
  11086. setLastError ("unmatched tags", false);
  11087. outOfData = true;
  11088. return;
  11089. }
  11090. ++input;
  11091. ++len;
  11092. }
  11093. textElementContent.append (start, len);
  11094. }
  11095. }
  11096. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  11097. : textElementContent.isNotEmpty())
  11098. e->setText (textElementContent);
  11099. }
  11100. }
  11101. }
  11102. void XmlDocument::readEntity (String& result) throw()
  11103. {
  11104. // skip over the ampersand
  11105. ++input;
  11106. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  11107. {
  11108. input += 4;
  11109. result += T("&");
  11110. }
  11111. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  11112. {
  11113. input += 5;
  11114. result += T("\"");
  11115. }
  11116. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  11117. {
  11118. input += 5;
  11119. result += T("\'");
  11120. }
  11121. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  11122. {
  11123. input += 3;
  11124. result += T("<");
  11125. }
  11126. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  11127. {
  11128. input += 3;
  11129. result += T(">");
  11130. }
  11131. else if (*input == T('#'))
  11132. {
  11133. int charCode = 0;
  11134. ++input;
  11135. if (*input == T('x') || *input == T('X'))
  11136. {
  11137. ++input;
  11138. int numChars = 0;
  11139. while (input[0] != T(';'))
  11140. {
  11141. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  11142. if (hexValue < 0 || ++numChars > 8)
  11143. {
  11144. setLastError ("illegal escape sequence", true);
  11145. break;
  11146. }
  11147. charCode = (charCode << 4) | hexValue;
  11148. ++input;
  11149. }
  11150. ++input;
  11151. }
  11152. else if (input[0] >= T('0') && input[0] <= T('9'))
  11153. {
  11154. int numChars = 0;
  11155. while (input[0] != T(';'))
  11156. {
  11157. if (++numChars > 12)
  11158. {
  11159. setLastError ("illegal escape sequence", true);
  11160. break;
  11161. }
  11162. charCode = charCode * 10 + (input[0] - T('0'));
  11163. ++input;
  11164. }
  11165. ++input;
  11166. }
  11167. else
  11168. {
  11169. setLastError ("illegal escape sequence", true);
  11170. result += T("&");
  11171. return;
  11172. }
  11173. result << (tchar) charCode;
  11174. }
  11175. else
  11176. {
  11177. const tchar* const entityNameStart = input;
  11178. const tchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  11179. if (closingSemiColon == 0)
  11180. {
  11181. outOfData = true;
  11182. result += T("&");
  11183. }
  11184. else
  11185. {
  11186. input = closingSemiColon + 1;
  11187. result += expandExternalEntity (String (entityNameStart,
  11188. (int) (closingSemiColon - entityNameStart)));
  11189. }
  11190. }
  11191. }
  11192. const String XmlDocument::expandEntity (const String& ent)
  11193. {
  11194. if (ent.equalsIgnoreCase (T("amp")))
  11195. {
  11196. return T("&");
  11197. }
  11198. else if (ent.equalsIgnoreCase (T("quot")))
  11199. {
  11200. return T("\"");
  11201. }
  11202. else if (ent.equalsIgnoreCase (T("apos")))
  11203. {
  11204. return T("\'");
  11205. }
  11206. else if (ent.equalsIgnoreCase (T("lt")))
  11207. {
  11208. return T("<");
  11209. }
  11210. else if (ent.equalsIgnoreCase (T("gt")))
  11211. {
  11212. return T(">");
  11213. }
  11214. else if (ent[0] == T('#'))
  11215. {
  11216. if (ent[1] == T('x') || ent[1] == T('X'))
  11217. {
  11218. return String::charToString ((tchar) ent.substring (2).getHexValue32());
  11219. }
  11220. else if (ent[1] >= T('0') && ent[1] <= T('9'))
  11221. {
  11222. return String::charToString ((tchar) ent.substring (1).getIntValue());
  11223. }
  11224. setLastError ("illegal escape sequence", false);
  11225. return T("&");
  11226. }
  11227. else
  11228. {
  11229. return expandExternalEntity (ent);
  11230. }
  11231. }
  11232. const String XmlDocument::expandExternalEntity (const String& entity)
  11233. {
  11234. if (needToLoadDTD)
  11235. {
  11236. if (dtdText.isNotEmpty())
  11237. {
  11238. while (dtdText.endsWithChar (T('>')))
  11239. dtdText = dtdText.dropLastCharacters (1);
  11240. tokenisedDTD.addTokens (dtdText, true);
  11241. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase (T("system"))
  11242. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  11243. {
  11244. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  11245. tokenisedDTD.clear();
  11246. tokenisedDTD.addTokens (getFileContents (fn), true);
  11247. }
  11248. else
  11249. {
  11250. tokenisedDTD.clear();
  11251. const int openBracket = dtdText.indexOfChar (T('['));
  11252. if (openBracket > 0)
  11253. {
  11254. const int closeBracket = dtdText.lastIndexOfChar (T(']'));
  11255. if (closeBracket > openBracket)
  11256. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  11257. closeBracket), true);
  11258. }
  11259. }
  11260. for (int i = tokenisedDTD.size(); --i >= 0;)
  11261. {
  11262. if (tokenisedDTD[i].startsWithChar (T('%'))
  11263. && tokenisedDTD[i].endsWithChar (T(';')))
  11264. {
  11265. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  11266. StringArray newToks;
  11267. newToks.addTokens (parsed, true);
  11268. tokenisedDTD.remove (i);
  11269. for (int j = newToks.size(); --j >= 0;)
  11270. tokenisedDTD.insert (i, newToks[j]);
  11271. }
  11272. }
  11273. }
  11274. needToLoadDTD = false;
  11275. }
  11276. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11277. {
  11278. if (tokenisedDTD[i] == entity)
  11279. {
  11280. if (tokenisedDTD[i - 1].equalsIgnoreCase (T("<!entity")))
  11281. {
  11282. String ent (tokenisedDTD [i + 1]);
  11283. while (ent.endsWithChar (T('>')))
  11284. ent = ent.dropLastCharacters (1);
  11285. ent = ent.trim().unquoted();
  11286. // check for sub-entities..
  11287. int ampersand = ent.indexOfChar (T('&'));
  11288. while (ampersand >= 0)
  11289. {
  11290. const int semiColon = ent.indexOf (i + 1, T(";"));
  11291. if (semiColon < 0)
  11292. {
  11293. setLastError ("entity without terminating semi-colon", false);
  11294. break;
  11295. }
  11296. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  11297. ent = ent.substring (0, ampersand)
  11298. + resolved
  11299. + ent.substring (semiColon + 1);
  11300. ampersand = ent.indexOfChar (semiColon + 1, T('&'));
  11301. }
  11302. return ent;
  11303. }
  11304. }
  11305. }
  11306. setLastError ("unknown entity", true);
  11307. return entity;
  11308. }
  11309. const String XmlDocument::getParameterEntity (const String& entity)
  11310. {
  11311. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11312. {
  11313. if (tokenisedDTD[i] == entity)
  11314. {
  11315. if (tokenisedDTD [i - 1] == T("%")
  11316. && tokenisedDTD [i - 2].equalsIgnoreCase (T("<!entity")))
  11317. {
  11318. String ent (tokenisedDTD [i + 1]);
  11319. while (ent.endsWithChar (T('>')))
  11320. ent = ent.dropLastCharacters (1);
  11321. if (ent.equalsIgnoreCase (T("system")))
  11322. {
  11323. String filename (tokenisedDTD [i + 2]);
  11324. while (filename.endsWithChar (T('>')))
  11325. filename = filename.dropLastCharacters (1);
  11326. return getFileContents (filename);
  11327. }
  11328. else
  11329. {
  11330. return ent.trim().unquoted();
  11331. }
  11332. }
  11333. }
  11334. }
  11335. return entity;
  11336. }
  11337. END_JUCE_NAMESPACE
  11338. /*** End of inlined file: juce_XmlDocument.cpp ***/
  11339. /*** Start of inlined file: juce_XmlElement.cpp ***/
  11340. BEGIN_JUCE_NAMESPACE
  11341. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11342. : name (other.name),
  11343. value (other.value),
  11344. next (0)
  11345. {
  11346. }
  11347. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_,
  11348. const String& value_) throw()
  11349. : name (name_),
  11350. value (value_),
  11351. next (0)
  11352. {
  11353. }
  11354. XmlElement::XmlElement (const String& tagName_) throw()
  11355. : tagName (tagName_),
  11356. firstChildElement (0),
  11357. nextElement (0),
  11358. attributes (0)
  11359. {
  11360. // the tag name mustn't be empty, or it'll look like a text element!
  11361. jassert (tagName_.containsNonWhitespaceChars())
  11362. }
  11363. XmlElement::XmlElement (int /*dummy*/) throw()
  11364. : firstChildElement (0),
  11365. nextElement (0),
  11366. attributes (0)
  11367. {
  11368. }
  11369. XmlElement::XmlElement (const XmlElement& other) throw()
  11370. : tagName (other.tagName),
  11371. firstChildElement (0),
  11372. nextElement (0),
  11373. attributes (0)
  11374. {
  11375. copyChildrenAndAttributesFrom (other);
  11376. }
  11377. const XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11378. {
  11379. if (this != &other)
  11380. {
  11381. removeAllAttributes();
  11382. deleteAllChildElements();
  11383. tagName = other.tagName;
  11384. copyChildrenAndAttributesFrom (other);
  11385. }
  11386. return *this;
  11387. }
  11388. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11389. {
  11390. XmlElement* child = other.firstChildElement;
  11391. XmlElement* lastChild = 0;
  11392. while (child != 0)
  11393. {
  11394. XmlElement* const copiedChild = new XmlElement (*child);
  11395. if (lastChild != 0)
  11396. lastChild->nextElement = copiedChild;
  11397. else
  11398. firstChildElement = copiedChild;
  11399. lastChild = copiedChild;
  11400. child = child->nextElement;
  11401. }
  11402. const XmlAttributeNode* att = other.attributes;
  11403. XmlAttributeNode* lastAtt = 0;
  11404. while (att != 0)
  11405. {
  11406. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11407. if (lastAtt != 0)
  11408. lastAtt->next = newAtt;
  11409. else
  11410. attributes = newAtt;
  11411. lastAtt = newAtt;
  11412. att = att->next;
  11413. }
  11414. }
  11415. XmlElement::~XmlElement() throw()
  11416. {
  11417. XmlElement* child = firstChildElement;
  11418. while (child != 0)
  11419. {
  11420. XmlElement* const nextChild = child->nextElement;
  11421. delete child;
  11422. child = nextChild;
  11423. }
  11424. XmlAttributeNode* att = attributes;
  11425. while (att != 0)
  11426. {
  11427. XmlAttributeNode* const nextAtt = att->next;
  11428. delete att;
  11429. att = nextAtt;
  11430. }
  11431. }
  11432. static bool isLegalXmlChar (const juce_wchar character)
  11433. {
  11434. if ((character >= 'a' && character <= 'z')
  11435. || (character >= 'A' && character <= 'Z')
  11436. || (character >= '0' && character <= '9'))
  11437. return true;
  11438. const char* t = " .,;:-()_+=?!'#@[]/\\*%~{}";
  11439. do
  11440. {
  11441. if (((juce_wchar) (uint8) *t) == character)
  11442. return true;
  11443. }
  11444. while (*++t != 0);
  11445. return false;
  11446. }
  11447. static void escapeIllegalXmlChars (OutputStream& outputStream,
  11448. const String& text,
  11449. const bool changeNewLines) throw()
  11450. {
  11451. const juce_wchar* t = (const juce_wchar*) text;
  11452. for (;;)
  11453. {
  11454. const juce_wchar character = *t++;
  11455. if (character == 0)
  11456. {
  11457. break;
  11458. }
  11459. else if (isLegalXmlChar (character))
  11460. {
  11461. outputStream.writeByte ((char) character);
  11462. }
  11463. else
  11464. {
  11465. switch (character)
  11466. {
  11467. case '&':
  11468. outputStream.write ("&amp;", 5);
  11469. break;
  11470. case '"':
  11471. outputStream.write ("&quot;", 6);
  11472. break;
  11473. case '>':
  11474. outputStream.write ("&gt;", 4);
  11475. break;
  11476. case '<':
  11477. outputStream.write ("&lt;", 4);
  11478. break;
  11479. case '\n':
  11480. if (changeNewLines)
  11481. outputStream.write ("&#10;", 5);
  11482. else
  11483. outputStream.writeByte ((char) character);
  11484. break;
  11485. case '\r':
  11486. if (changeNewLines)
  11487. outputStream.write ("&#13;", 5);
  11488. else
  11489. outputStream.writeByte ((char) character);
  11490. break;
  11491. default:
  11492. {
  11493. String encoded (T("&#"));
  11494. encoded << String ((int) (unsigned int) character).trim()
  11495. << T(';');
  11496. outputStream.write ((const char*) encoded, encoded.length());
  11497. }
  11498. }
  11499. }
  11500. }
  11501. }
  11502. static void writeSpaces (OutputStream& out, int numSpaces) throw()
  11503. {
  11504. if (numSpaces > 0)
  11505. {
  11506. const char* const blanks = " ";
  11507. const int blankSize = (int) sizeof (blanks) - 1;
  11508. while (numSpaces > blankSize)
  11509. {
  11510. out.write (blanks, blankSize);
  11511. numSpaces -= blankSize;
  11512. }
  11513. out.write (blanks, numSpaces);
  11514. }
  11515. }
  11516. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11517. const int indentationLevel,
  11518. const int lineWrapLength) const throw()
  11519. {
  11520. writeSpaces (outputStream, indentationLevel);
  11521. if (! isTextElement())
  11522. {
  11523. outputStream.writeByte ('<');
  11524. const int nameLen = tagName.length();
  11525. outputStream.write ((const char*) tagName, nameLen);
  11526. const int attIndent = indentationLevel + nameLen + 1;
  11527. int lineLen = 0;
  11528. const XmlAttributeNode* att = attributes;
  11529. while (att != 0)
  11530. {
  11531. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11532. {
  11533. outputStream.write ("\r\n", 2);
  11534. writeSpaces (outputStream, attIndent);
  11535. lineLen = 0;
  11536. }
  11537. const int attNameLen = att->name.length();
  11538. outputStream.writeByte (' ');
  11539. outputStream.write ((const char*) (att->name), attNameLen);
  11540. outputStream.write ("=\"", 2);
  11541. escapeIllegalXmlChars (outputStream, att->value, true);
  11542. outputStream.writeByte ('"');
  11543. lineLen += 4 + attNameLen + att->value.length();
  11544. att = att->next;
  11545. }
  11546. if (firstChildElement != 0)
  11547. {
  11548. XmlElement* child = firstChildElement;
  11549. if (child->nextElement == 0 && child->isTextElement())
  11550. {
  11551. outputStream.writeByte ('>');
  11552. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11553. }
  11554. else
  11555. {
  11556. if (indentationLevel >= 0)
  11557. outputStream.write (">\r\n", 3);
  11558. else
  11559. outputStream.writeByte ('>');
  11560. bool lastWasTextNode = false;
  11561. while (child != 0)
  11562. {
  11563. if (child->isTextElement())
  11564. {
  11565. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11566. writeSpaces (outputStream, indentationLevel + 2);
  11567. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11568. lastWasTextNode = true;
  11569. }
  11570. else
  11571. {
  11572. if (indentationLevel >= 0)
  11573. {
  11574. if (lastWasTextNode)
  11575. outputStream.write ("\r\n", 2);
  11576. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11577. }
  11578. else
  11579. {
  11580. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11581. }
  11582. lastWasTextNode = false;
  11583. }
  11584. child = child->nextElement;
  11585. }
  11586. if (indentationLevel >= 0)
  11587. {
  11588. if (lastWasTextNode)
  11589. outputStream.write ("\r\n", 2);
  11590. writeSpaces (outputStream, indentationLevel);
  11591. }
  11592. }
  11593. outputStream.write ("</", 2);
  11594. outputStream.write ((const char*) tagName, nameLen);
  11595. if (indentationLevel >= 0)
  11596. outputStream.write (">\r\n", 3);
  11597. else
  11598. outputStream.writeByte ('>');
  11599. }
  11600. else
  11601. {
  11602. if (indentationLevel >= 0)
  11603. outputStream.write ("/>\r\n", 4);
  11604. else
  11605. outputStream.write ("/>", 2);
  11606. }
  11607. }
  11608. else
  11609. {
  11610. if (indentationLevel >= 0)
  11611. writeSpaces (outputStream, indentationLevel + 2);
  11612. escapeIllegalXmlChars (outputStream, getText(), false);
  11613. }
  11614. }
  11615. const String XmlElement::createDocument (const String& dtdToUse,
  11616. const bool allOnOneLine,
  11617. const bool includeXmlHeader,
  11618. const String& encodingType,
  11619. const int lineWrapLength) const throw()
  11620. {
  11621. MemoryOutputStream mem (2048, 4096);
  11622. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11623. return String (mem.getData(), mem.getDataSize());
  11624. }
  11625. void XmlElement::writeToStream (OutputStream& output,
  11626. const String& dtdToUse,
  11627. const bool allOnOneLine,
  11628. const bool includeXmlHeader,
  11629. const String& encodingType,
  11630. const int lineWrapLength) const throw()
  11631. {
  11632. if (includeXmlHeader)
  11633. {
  11634. output << "<?xml version=\"1.0\" encoding=\"" << encodingType;
  11635. if (allOnOneLine)
  11636. output << "\"?> ";
  11637. else
  11638. output << "\"?>\r\n\r\n";
  11639. }
  11640. if (dtdToUse.isNotEmpty())
  11641. {
  11642. output << dtdToUse;
  11643. if (allOnOneLine)
  11644. output << " ";
  11645. else
  11646. output << "\r\n";
  11647. }
  11648. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11649. }
  11650. bool XmlElement::writeToFile (const File& file,
  11651. const String& dtdToUse,
  11652. const String& encodingType,
  11653. const int lineWrapLength) const throw()
  11654. {
  11655. if (file.hasWriteAccess())
  11656. {
  11657. TemporaryFile tempFile (file);
  11658. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11659. if (out != 0)
  11660. {
  11661. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11662. out = 0;
  11663. return tempFile.overwriteTargetFileWithTemporary();
  11664. }
  11665. }
  11666. return false;
  11667. }
  11668. bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
  11669. {
  11670. #ifdef JUCE_DEBUG
  11671. // if debugging, check that the case is actually the same, because
  11672. // valid xml is case-sensitive, and although this lets it pass, it's
  11673. // better not to..
  11674. if (tagName.equalsIgnoreCase (tagNameWanted))
  11675. {
  11676. jassert (tagName == tagNameWanted);
  11677. return true;
  11678. }
  11679. else
  11680. {
  11681. return false;
  11682. }
  11683. #else
  11684. return tagName.equalsIgnoreCase (tagNameWanted);
  11685. #endif
  11686. }
  11687. XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
  11688. {
  11689. XmlElement* e = nextElement;
  11690. while (e != 0 && ! e->hasTagName (requiredTagName))
  11691. e = e->nextElement;
  11692. return e;
  11693. }
  11694. int XmlElement::getNumAttributes() const throw()
  11695. {
  11696. const XmlAttributeNode* att = attributes;
  11697. int count = 0;
  11698. while (att != 0)
  11699. {
  11700. att = att->next;
  11701. ++count;
  11702. }
  11703. return count;
  11704. }
  11705. const String& XmlElement::getAttributeName (const int index) const throw()
  11706. {
  11707. const XmlAttributeNode* att = attributes;
  11708. int count = 0;
  11709. while (att != 0)
  11710. {
  11711. if (count == index)
  11712. return att->name;
  11713. att = att->next;
  11714. ++count;
  11715. }
  11716. return String::empty;
  11717. }
  11718. const String& XmlElement::getAttributeValue (const int index) const throw()
  11719. {
  11720. const XmlAttributeNode* att = attributes;
  11721. int count = 0;
  11722. while (att != 0)
  11723. {
  11724. if (count == index)
  11725. return att->value;
  11726. att = att->next;
  11727. ++count;
  11728. }
  11729. return String::empty;
  11730. }
  11731. bool XmlElement::hasAttribute (const String& attributeName) const throw()
  11732. {
  11733. const XmlAttributeNode* att = attributes;
  11734. while (att != 0)
  11735. {
  11736. if (att->name.equalsIgnoreCase (attributeName))
  11737. return true;
  11738. att = att->next;
  11739. }
  11740. return false;
  11741. }
  11742. const String XmlElement::getStringAttribute (const String& attributeName,
  11743. const String& defaultReturnValue) const throw()
  11744. {
  11745. const XmlAttributeNode* att = attributes;
  11746. while (att != 0)
  11747. {
  11748. if (att->name.equalsIgnoreCase (attributeName))
  11749. return att->value;
  11750. att = att->next;
  11751. }
  11752. return defaultReturnValue;
  11753. }
  11754. int XmlElement::getIntAttribute (const String& attributeName,
  11755. const int defaultReturnValue) const throw()
  11756. {
  11757. const XmlAttributeNode* att = attributes;
  11758. while (att != 0)
  11759. {
  11760. if (att->name.equalsIgnoreCase (attributeName))
  11761. return att->value.getIntValue();
  11762. att = att->next;
  11763. }
  11764. return defaultReturnValue;
  11765. }
  11766. double XmlElement::getDoubleAttribute (const String& attributeName,
  11767. const double defaultReturnValue) const throw()
  11768. {
  11769. const XmlAttributeNode* att = attributes;
  11770. while (att != 0)
  11771. {
  11772. if (att->name.equalsIgnoreCase (attributeName))
  11773. return att->value.getDoubleValue();
  11774. att = att->next;
  11775. }
  11776. return defaultReturnValue;
  11777. }
  11778. bool XmlElement::getBoolAttribute (const String& attributeName,
  11779. const bool defaultReturnValue) const throw()
  11780. {
  11781. const XmlAttributeNode* att = attributes;
  11782. while (att != 0)
  11783. {
  11784. if (att->name.equalsIgnoreCase (attributeName))
  11785. {
  11786. tchar firstChar = att->value[0];
  11787. if (CharacterFunctions::isWhitespace (firstChar))
  11788. firstChar = att->value.trimStart() [0];
  11789. return firstChar == T('1')
  11790. || firstChar == T('t')
  11791. || firstChar == T('y')
  11792. || firstChar == T('T')
  11793. || firstChar == T('Y');
  11794. }
  11795. att = att->next;
  11796. }
  11797. return defaultReturnValue;
  11798. }
  11799. bool XmlElement::compareAttribute (const String& attributeName,
  11800. const String& stringToCompareAgainst,
  11801. const bool ignoreCase) const throw()
  11802. {
  11803. const XmlAttributeNode* att = attributes;
  11804. while (att != 0)
  11805. {
  11806. if (att->name.equalsIgnoreCase (attributeName))
  11807. {
  11808. if (ignoreCase)
  11809. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11810. else
  11811. return att->value == stringToCompareAgainst;
  11812. }
  11813. att = att->next;
  11814. }
  11815. return false;
  11816. }
  11817. void XmlElement::setAttribute (const String& attributeName,
  11818. const String& value) throw()
  11819. {
  11820. #ifdef JUCE_DEBUG
  11821. // check the identifier being passed in is legal..
  11822. const tchar* t = attributeName;
  11823. while (*t != 0)
  11824. {
  11825. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11826. || *t == T('_')
  11827. || *t == T('-')
  11828. || *t == T(':'));
  11829. ++t;
  11830. }
  11831. #endif
  11832. if (attributes == 0)
  11833. {
  11834. attributes = new XmlAttributeNode (attributeName, value);
  11835. }
  11836. else
  11837. {
  11838. XmlAttributeNode* att = attributes;
  11839. for (;;)
  11840. {
  11841. if (att->name.equalsIgnoreCase (attributeName))
  11842. {
  11843. att->value = value;
  11844. break;
  11845. }
  11846. else if (att->next == 0)
  11847. {
  11848. att->next = new XmlAttributeNode (attributeName, value);
  11849. break;
  11850. }
  11851. att = att->next;
  11852. }
  11853. }
  11854. }
  11855. void XmlElement::setAttribute (const String& attributeName,
  11856. const int number) throw()
  11857. {
  11858. setAttribute (attributeName, String (number));
  11859. }
  11860. void XmlElement::setAttribute (const String& attributeName,
  11861. const double number) throw()
  11862. {
  11863. setAttribute (attributeName, String (number));
  11864. }
  11865. void XmlElement::removeAttribute (const String& attributeName) throw()
  11866. {
  11867. XmlAttributeNode* att = attributes;
  11868. XmlAttributeNode* lastAtt = 0;
  11869. while (att != 0)
  11870. {
  11871. if (att->name.equalsIgnoreCase (attributeName))
  11872. {
  11873. if (lastAtt == 0)
  11874. attributes = att->next;
  11875. else
  11876. lastAtt->next = att->next;
  11877. delete att;
  11878. break;
  11879. }
  11880. lastAtt = att;
  11881. att = att->next;
  11882. }
  11883. }
  11884. void XmlElement::removeAllAttributes() throw()
  11885. {
  11886. while (attributes != 0)
  11887. {
  11888. XmlAttributeNode* const nextAtt = attributes->next;
  11889. delete attributes;
  11890. attributes = nextAtt;
  11891. }
  11892. }
  11893. int XmlElement::getNumChildElements() const throw()
  11894. {
  11895. int count = 0;
  11896. const XmlElement* child = firstChildElement;
  11897. while (child != 0)
  11898. {
  11899. ++count;
  11900. child = child->nextElement;
  11901. }
  11902. return count;
  11903. }
  11904. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11905. {
  11906. int count = 0;
  11907. XmlElement* child = firstChildElement;
  11908. while (child != 0 && count < index)
  11909. {
  11910. child = child->nextElement;
  11911. ++count;
  11912. }
  11913. return child;
  11914. }
  11915. XmlElement* XmlElement::getChildByName (const String& childName) const throw()
  11916. {
  11917. XmlElement* child = firstChildElement;
  11918. while (child != 0)
  11919. {
  11920. if (child->hasTagName (childName))
  11921. break;
  11922. child = child->nextElement;
  11923. }
  11924. return child;
  11925. }
  11926. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11927. {
  11928. if (newNode != 0)
  11929. {
  11930. if (firstChildElement == 0)
  11931. {
  11932. firstChildElement = newNode;
  11933. }
  11934. else
  11935. {
  11936. XmlElement* child = firstChildElement;
  11937. while (child->nextElement != 0)
  11938. child = child->nextElement;
  11939. child->nextElement = newNode;
  11940. // if this is non-zero, then something's probably
  11941. // gone wrong..
  11942. jassert (newNode->nextElement == 0);
  11943. }
  11944. }
  11945. }
  11946. void XmlElement::insertChildElement (XmlElement* const newNode,
  11947. int indexToInsertAt) throw()
  11948. {
  11949. if (newNode != 0)
  11950. {
  11951. removeChildElement (newNode, false);
  11952. if (indexToInsertAt == 0)
  11953. {
  11954. newNode->nextElement = firstChildElement;
  11955. firstChildElement = newNode;
  11956. }
  11957. else
  11958. {
  11959. if (firstChildElement == 0)
  11960. {
  11961. firstChildElement = newNode;
  11962. }
  11963. else
  11964. {
  11965. if (indexToInsertAt < 0)
  11966. indexToInsertAt = std::numeric_limits<int>::max();
  11967. XmlElement* child = firstChildElement;
  11968. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11969. child = child->nextElement;
  11970. newNode->nextElement = child->nextElement;
  11971. child->nextElement = newNode;
  11972. }
  11973. }
  11974. }
  11975. }
  11976. XmlElement* XmlElement::createNewChildElement (const String& tagName)
  11977. {
  11978. XmlElement* const newElement = new XmlElement (tagName);
  11979. addChildElement (newElement);
  11980. return newElement;
  11981. }
  11982. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11983. XmlElement* const newNode) throw()
  11984. {
  11985. if (newNode != 0)
  11986. {
  11987. XmlElement* child = firstChildElement;
  11988. XmlElement* previousNode = 0;
  11989. while (child != 0)
  11990. {
  11991. if (child == currentChildElement)
  11992. {
  11993. if (child != newNode)
  11994. {
  11995. if (previousNode == 0)
  11996. firstChildElement = newNode;
  11997. else
  11998. previousNode->nextElement = newNode;
  11999. newNode->nextElement = child->nextElement;
  12000. delete child;
  12001. }
  12002. return true;
  12003. }
  12004. previousNode = child;
  12005. child = child->nextElement;
  12006. }
  12007. }
  12008. return false;
  12009. }
  12010. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  12011. const bool shouldDeleteTheChild) throw()
  12012. {
  12013. if (childToRemove != 0)
  12014. {
  12015. if (firstChildElement == childToRemove)
  12016. {
  12017. firstChildElement = childToRemove->nextElement;
  12018. childToRemove->nextElement = 0;
  12019. }
  12020. else
  12021. {
  12022. XmlElement* child = firstChildElement;
  12023. XmlElement* last = 0;
  12024. while (child != 0)
  12025. {
  12026. if (child == childToRemove)
  12027. {
  12028. if (last == 0)
  12029. firstChildElement = child->nextElement;
  12030. else
  12031. last->nextElement = child->nextElement;
  12032. childToRemove->nextElement = 0;
  12033. break;
  12034. }
  12035. last = child;
  12036. child = child->nextElement;
  12037. }
  12038. }
  12039. if (shouldDeleteTheChild)
  12040. delete childToRemove;
  12041. }
  12042. }
  12043. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  12044. const bool ignoreOrderOfAttributes) const throw()
  12045. {
  12046. if (this != other)
  12047. {
  12048. if (other == 0 || tagName != other->tagName)
  12049. {
  12050. return false;
  12051. }
  12052. if (ignoreOrderOfAttributes)
  12053. {
  12054. int totalAtts = 0;
  12055. const XmlAttributeNode* att = attributes;
  12056. while (att != 0)
  12057. {
  12058. if (! other->compareAttribute (att->name, att->value))
  12059. return false;
  12060. att = att->next;
  12061. ++totalAtts;
  12062. }
  12063. if (totalAtts != other->getNumAttributes())
  12064. return false;
  12065. }
  12066. else
  12067. {
  12068. const XmlAttributeNode* thisAtt = attributes;
  12069. const XmlAttributeNode* otherAtt = other->attributes;
  12070. for (;;)
  12071. {
  12072. if (thisAtt == 0 || otherAtt == 0)
  12073. {
  12074. if (thisAtt == otherAtt) // both 0, so it's a match
  12075. break;
  12076. return false;
  12077. }
  12078. if (thisAtt->name != otherAtt->name
  12079. || thisAtt->value != otherAtt->value)
  12080. {
  12081. return false;
  12082. }
  12083. thisAtt = thisAtt->next;
  12084. otherAtt = otherAtt->next;
  12085. }
  12086. }
  12087. const XmlElement* thisChild = firstChildElement;
  12088. const XmlElement* otherChild = other->firstChildElement;
  12089. for (;;)
  12090. {
  12091. if (thisChild == 0 || otherChild == 0)
  12092. {
  12093. if (thisChild == otherChild) // both 0, so it's a match
  12094. break;
  12095. return false;
  12096. }
  12097. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  12098. return false;
  12099. thisChild = thisChild->nextElement;
  12100. otherChild = otherChild->nextElement;
  12101. }
  12102. }
  12103. return true;
  12104. }
  12105. void XmlElement::deleteAllChildElements() throw()
  12106. {
  12107. while (firstChildElement != 0)
  12108. {
  12109. XmlElement* const nextChild = firstChildElement->nextElement;
  12110. delete firstChildElement;
  12111. firstChildElement = nextChild;
  12112. }
  12113. }
  12114. void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
  12115. {
  12116. XmlElement* child = firstChildElement;
  12117. while (child != 0)
  12118. {
  12119. if (child->hasTagName (name))
  12120. {
  12121. XmlElement* const nextChild = child->nextElement;
  12122. removeChildElement (child, true);
  12123. child = nextChild;
  12124. }
  12125. else
  12126. {
  12127. child = child->nextElement;
  12128. }
  12129. }
  12130. }
  12131. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  12132. {
  12133. const XmlElement* child = firstChildElement;
  12134. while (child != 0)
  12135. {
  12136. if (child == possibleChild)
  12137. return true;
  12138. child = child->nextElement;
  12139. }
  12140. return false;
  12141. }
  12142. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  12143. {
  12144. if (this == elementToLookFor || elementToLookFor == 0)
  12145. return 0;
  12146. XmlElement* child = firstChildElement;
  12147. while (child != 0)
  12148. {
  12149. if (elementToLookFor == child)
  12150. return this;
  12151. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  12152. if (found != 0)
  12153. return found;
  12154. child = child->nextElement;
  12155. }
  12156. return 0;
  12157. }
  12158. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  12159. {
  12160. XmlElement* e = firstChildElement;
  12161. while (e != 0)
  12162. {
  12163. *elems++ = e;
  12164. e = e->nextElement;
  12165. }
  12166. }
  12167. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  12168. {
  12169. XmlElement* e = firstChildElement = elems[0];
  12170. for (int i = 1; i < num; ++i)
  12171. {
  12172. e->nextElement = elems[i];
  12173. e = e->nextElement;
  12174. }
  12175. e->nextElement = 0;
  12176. }
  12177. bool XmlElement::isTextElement() const throw()
  12178. {
  12179. return tagName.isEmpty();
  12180. }
  12181. static const tchar* const juce_xmltextContentAttributeName = T("text");
  12182. const String XmlElement::getText() const throw()
  12183. {
  12184. jassert (isTextElement()); // you're trying to get the text from an element that
  12185. // isn't actually a text element.. If this contains text sub-nodes, you
  12186. // probably want to use getAllSubText instead.
  12187. return getStringAttribute (juce_xmltextContentAttributeName);
  12188. }
  12189. void XmlElement::setText (const String& newText) throw()
  12190. {
  12191. if (isTextElement())
  12192. {
  12193. setAttribute (juce_xmltextContentAttributeName, newText);
  12194. }
  12195. else
  12196. {
  12197. jassertfalse // you can only change the text in a text element, not a normal one.
  12198. }
  12199. }
  12200. const String XmlElement::getAllSubText() const throw()
  12201. {
  12202. String result;
  12203. String::Concatenator concatenator (result);
  12204. const XmlElement* child = firstChildElement;
  12205. while (child != 0)
  12206. {
  12207. if (child->isTextElement())
  12208. concatenator.append (child->getText());
  12209. child = child->nextElement;
  12210. }
  12211. return result;
  12212. }
  12213. const String XmlElement::getChildElementAllSubText (const String& childTagName,
  12214. const String& defaultReturnValue) const throw()
  12215. {
  12216. const XmlElement* const child = getChildByName (childTagName);
  12217. if (child != 0)
  12218. return child->getAllSubText();
  12219. return defaultReturnValue;
  12220. }
  12221. XmlElement* XmlElement::createTextElement (const String& text) throw()
  12222. {
  12223. XmlElement* const e = new XmlElement ((int) 0);
  12224. e->setAttribute (juce_xmltextContentAttributeName, text);
  12225. return e;
  12226. }
  12227. void XmlElement::addTextElement (const String& text) throw()
  12228. {
  12229. addChildElement (createTextElement (text));
  12230. }
  12231. void XmlElement::deleteAllTextElements() throw()
  12232. {
  12233. XmlElement* child = firstChildElement;
  12234. while (child != 0)
  12235. {
  12236. XmlElement* const next = child->nextElement;
  12237. if (child->isTextElement())
  12238. removeChildElement (child, true);
  12239. child = next;
  12240. }
  12241. }
  12242. END_JUCE_NAMESPACE
  12243. /*** End of inlined file: juce_XmlElement.cpp ***/
  12244. /*** Start of inlined file: juce_InterProcessLock.cpp ***/
  12245. BEGIN_JUCE_NAMESPACE
  12246. // (implemented in the platform-specific code files)
  12247. END_JUCE_NAMESPACE
  12248. /*** End of inlined file: juce_InterProcessLock.cpp ***/
  12249. /*** Start of inlined file: juce_ReadWriteLock.cpp ***/
  12250. BEGIN_JUCE_NAMESPACE
  12251. ReadWriteLock::ReadWriteLock() throw()
  12252. : numWaitingWriters (0),
  12253. numWriters (0),
  12254. writerThreadId (0)
  12255. {
  12256. }
  12257. ReadWriteLock::~ReadWriteLock() throw()
  12258. {
  12259. jassert (readerThreads.size() == 0);
  12260. jassert (numWriters == 0);
  12261. }
  12262. void ReadWriteLock::enterRead() const throw()
  12263. {
  12264. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12265. const ScopedLock sl (accessLock);
  12266. for (;;)
  12267. {
  12268. jassert (readerThreads.size() % 2 == 0);
  12269. int i;
  12270. for (i = 0; i < readerThreads.size(); i += 2)
  12271. if (readerThreads.getUnchecked(i) == threadId)
  12272. break;
  12273. if (i < readerThreads.size()
  12274. || numWriters + numWaitingWriters == 0
  12275. || (threadId == writerThreadId && numWriters > 0))
  12276. {
  12277. if (i < readerThreads.size())
  12278. {
  12279. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  12280. }
  12281. else
  12282. {
  12283. readerThreads.add (threadId);
  12284. readerThreads.add ((Thread::ThreadID) 1);
  12285. }
  12286. return;
  12287. }
  12288. const ScopedUnlock ul (accessLock);
  12289. waitEvent.wait (100);
  12290. }
  12291. }
  12292. void ReadWriteLock::exitRead() const throw()
  12293. {
  12294. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12295. const ScopedLock sl (accessLock);
  12296. for (int i = 0; i < readerThreads.size(); i += 2)
  12297. {
  12298. if (readerThreads.getUnchecked(i) == threadId)
  12299. {
  12300. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  12301. if (newCount == 0)
  12302. {
  12303. readerThreads.removeRange (i, 2);
  12304. waitEvent.signal();
  12305. }
  12306. else
  12307. {
  12308. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  12309. }
  12310. return;
  12311. }
  12312. }
  12313. jassertfalse // unlocking a lock that wasn't locked..
  12314. }
  12315. void ReadWriteLock::enterWrite() const throw()
  12316. {
  12317. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12318. const ScopedLock sl (accessLock);
  12319. for (;;)
  12320. {
  12321. if (readerThreads.size() + numWriters == 0
  12322. || threadId == writerThreadId
  12323. || (readerThreads.size() == 2
  12324. && readerThreads.getUnchecked(0) == threadId))
  12325. {
  12326. writerThreadId = threadId;
  12327. ++numWriters;
  12328. break;
  12329. }
  12330. ++numWaitingWriters;
  12331. accessLock.exit();
  12332. waitEvent.wait (100);
  12333. accessLock.enter();
  12334. --numWaitingWriters;
  12335. }
  12336. }
  12337. bool ReadWriteLock::tryEnterWrite() const throw()
  12338. {
  12339. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12340. const ScopedLock sl (accessLock);
  12341. if (readerThreads.size() + numWriters == 0
  12342. || threadId == writerThreadId
  12343. || (readerThreads.size() == 2
  12344. && readerThreads.getUnchecked(0) == threadId))
  12345. {
  12346. writerThreadId = threadId;
  12347. ++numWriters;
  12348. return true;
  12349. }
  12350. return false;
  12351. }
  12352. void ReadWriteLock::exitWrite() const throw()
  12353. {
  12354. const ScopedLock sl (accessLock);
  12355. // check this thread actually had the lock..
  12356. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  12357. if (--numWriters == 0)
  12358. {
  12359. writerThreadId = 0;
  12360. waitEvent.signal();
  12361. }
  12362. }
  12363. END_JUCE_NAMESPACE
  12364. /*** End of inlined file: juce_ReadWriteLock.cpp ***/
  12365. /*** Start of inlined file: juce_Thread.cpp ***/
  12366. BEGIN_JUCE_NAMESPACE
  12367. // these functions are implemented in the platform-specific code.
  12368. void* juce_createThread (void* userData);
  12369. void juce_killThread (void* handle);
  12370. bool juce_setThreadPriority (void* handle, int priority);
  12371. void juce_setCurrentThreadName (const String& name);
  12372. #if JUCE_WIN32
  12373. void juce_CloseThreadHandle (void* handle);
  12374. #endif
  12375. static VoidArray runningThreads;
  12376. static CriticalSection runningThreadsLock;
  12377. void Thread::threadEntryPoint (Thread* const thread)
  12378. {
  12379. {
  12380. const ScopedLock sl (runningThreadsLock);
  12381. runningThreads.add (thread);
  12382. }
  12383. JUCE_TRY
  12384. {
  12385. thread->threadId_ = Thread::getCurrentThreadId();
  12386. if (thread->threadName_.isNotEmpty())
  12387. juce_setCurrentThreadName (thread->threadName_);
  12388. if (thread->startSuspensionEvent_.wait (10000))
  12389. {
  12390. if (thread->affinityMask_ != 0)
  12391. setCurrentThreadAffinityMask (thread->affinityMask_);
  12392. thread->run();
  12393. }
  12394. }
  12395. JUCE_CATCH_ALL_ASSERT
  12396. {
  12397. const ScopedLock sl (runningThreadsLock);
  12398. jassert (runningThreads.contains (thread));
  12399. runningThreads.removeValue (thread);
  12400. }
  12401. #if JUCE_WIN32
  12402. juce_CloseThreadHandle (thread->threadHandle_);
  12403. #endif
  12404. thread->threadHandle_ = 0;
  12405. thread->threadId_ = 0;
  12406. }
  12407. // used to wrap the incoming call from the platform-specific code
  12408. void JUCE_API juce_threadEntryPoint (void* userData)
  12409. {
  12410. Thread::threadEntryPoint ((Thread*) userData);
  12411. }
  12412. Thread::Thread (const String& threadName)
  12413. : threadName_ (threadName),
  12414. threadHandle_ (0),
  12415. threadPriority_ (5),
  12416. threadId_ (0),
  12417. affinityMask_ (0),
  12418. threadShouldExit_ (false)
  12419. {
  12420. }
  12421. Thread::~Thread()
  12422. {
  12423. stopThread (100);
  12424. }
  12425. void Thread::startThread()
  12426. {
  12427. const ScopedLock sl (startStopLock);
  12428. threadShouldExit_ = false;
  12429. if (threadHandle_ == 0)
  12430. {
  12431. threadHandle_ = juce_createThread ((void*) this);
  12432. juce_setThreadPriority (threadHandle_, threadPriority_);
  12433. startSuspensionEvent_.signal();
  12434. }
  12435. }
  12436. void Thread::startThread (const int priority)
  12437. {
  12438. const ScopedLock sl (startStopLock);
  12439. if (threadHandle_ == 0)
  12440. {
  12441. threadPriority_ = priority;
  12442. startThread();
  12443. }
  12444. else
  12445. {
  12446. setPriority (priority);
  12447. }
  12448. }
  12449. bool Thread::isThreadRunning() const
  12450. {
  12451. return threadHandle_ != 0;
  12452. }
  12453. void Thread::signalThreadShouldExit()
  12454. {
  12455. threadShouldExit_ = true;
  12456. }
  12457. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12458. {
  12459. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12460. jassert (getThreadId() != getCurrentThreadId());
  12461. const int sleepMsPerIteration = 5;
  12462. int count = timeOutMilliseconds / sleepMsPerIteration;
  12463. while (isThreadRunning())
  12464. {
  12465. if (timeOutMilliseconds > 0 && --count < 0)
  12466. return false;
  12467. sleep (sleepMsPerIteration);
  12468. }
  12469. return true;
  12470. }
  12471. void Thread::stopThread (const int timeOutMilliseconds)
  12472. {
  12473. // agh! You can't stop the thread that's calling this method! How on earth
  12474. // would that work??
  12475. jassert (getCurrentThreadId() != getThreadId());
  12476. const ScopedLock sl (startStopLock);
  12477. if (isThreadRunning())
  12478. {
  12479. signalThreadShouldExit();
  12480. notify();
  12481. if (timeOutMilliseconds != 0)
  12482. waitForThreadToExit (timeOutMilliseconds);
  12483. if (isThreadRunning())
  12484. {
  12485. // very bad karma if this point is reached, as
  12486. // there are bound to be locks and events left in
  12487. // silly states when a thread is killed by force..
  12488. jassertfalse
  12489. Logger::writeToLog ("!! killing thread by force !!");
  12490. juce_killThread (threadHandle_);
  12491. threadHandle_ = 0;
  12492. threadId_ = 0;
  12493. const ScopedLock sl2 (runningThreadsLock);
  12494. runningThreads.removeValue (this);
  12495. }
  12496. }
  12497. }
  12498. bool Thread::setPriority (const int priority)
  12499. {
  12500. const ScopedLock sl (startStopLock);
  12501. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12502. if (worked)
  12503. threadPriority_ = priority;
  12504. return worked;
  12505. }
  12506. bool Thread::setCurrentThreadPriority (const int priority)
  12507. {
  12508. return juce_setThreadPriority (0, priority);
  12509. }
  12510. void Thread::setAffinityMask (const uint32 affinityMask)
  12511. {
  12512. affinityMask_ = affinityMask;
  12513. }
  12514. bool Thread::wait (const int timeOutMilliseconds) const
  12515. {
  12516. return defaultEvent_.wait (timeOutMilliseconds);
  12517. }
  12518. void Thread::notify() const
  12519. {
  12520. defaultEvent_.signal();
  12521. }
  12522. int Thread::getNumRunningThreads()
  12523. {
  12524. return runningThreads.size();
  12525. }
  12526. Thread* Thread::getCurrentThread()
  12527. {
  12528. const ThreadID thisId = getCurrentThreadId();
  12529. const ScopedLock sl (runningThreadsLock);
  12530. for (int i = runningThreads.size(); --i >= 0;)
  12531. {
  12532. Thread* const t = (Thread*) runningThreads.getUnchecked(i);
  12533. if (t->threadId_ == thisId)
  12534. return t;
  12535. }
  12536. return 0;
  12537. }
  12538. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12539. {
  12540. {
  12541. const ScopedLock sl (runningThreadsLock);
  12542. for (int i = runningThreads.size(); --i >= 0;)
  12543. ((Thread*) runningThreads.getUnchecked(i))->signalThreadShouldExit();
  12544. }
  12545. for (;;)
  12546. {
  12547. runningThreadsLock.enter();
  12548. Thread* const t = (Thread*) runningThreads[0];
  12549. runningThreadsLock.exit();
  12550. if (t == 0)
  12551. break;
  12552. t->stopThread (timeOutMilliseconds);
  12553. }
  12554. }
  12555. END_JUCE_NAMESPACE
  12556. /*** End of inlined file: juce_Thread.cpp ***/
  12557. /*** Start of inlined file: juce_ThreadPool.cpp ***/
  12558. BEGIN_JUCE_NAMESPACE
  12559. ThreadPoolJob::ThreadPoolJob (const String& name)
  12560. : jobName (name),
  12561. pool (0),
  12562. shouldStop (false),
  12563. isActive (false),
  12564. shouldBeDeleted (false)
  12565. {
  12566. }
  12567. ThreadPoolJob::~ThreadPoolJob()
  12568. {
  12569. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12570. // to remove it first!
  12571. jassert (pool == 0 || ! pool->contains (this));
  12572. }
  12573. const String ThreadPoolJob::getJobName() const
  12574. {
  12575. return jobName;
  12576. }
  12577. void ThreadPoolJob::setJobName (const String& newName)
  12578. {
  12579. jobName = newName;
  12580. }
  12581. void ThreadPoolJob::signalJobShouldExit()
  12582. {
  12583. shouldStop = true;
  12584. }
  12585. class ThreadPool::ThreadPoolThread : public Thread
  12586. {
  12587. public:
  12588. ThreadPoolThread (ThreadPool& pool_)
  12589. : Thread (T("Pool")),
  12590. pool (pool_),
  12591. busy (false)
  12592. {
  12593. }
  12594. ~ThreadPoolThread()
  12595. {
  12596. }
  12597. void run()
  12598. {
  12599. while (! threadShouldExit())
  12600. {
  12601. if (! pool.runNextJob())
  12602. wait (500);
  12603. }
  12604. }
  12605. private:
  12606. ThreadPool& pool;
  12607. bool volatile busy;
  12608. ThreadPoolThread (const ThreadPoolThread&);
  12609. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12610. };
  12611. ThreadPool::ThreadPool (const int numThreads,
  12612. const bool startThreadsOnlyWhenNeeded,
  12613. const int stopThreadsWhenNotUsedTimeoutMs)
  12614. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12615. priority (5)
  12616. {
  12617. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12618. for (int i = jmax (1, numThreads); --i >= 0;)
  12619. threads.add (new ThreadPoolThread (*this));
  12620. if (! startThreadsOnlyWhenNeeded)
  12621. for (int i = threads.size(); --i >= 0;)
  12622. threads.getUnchecked(i)->startThread (priority);
  12623. }
  12624. ThreadPool::~ThreadPool()
  12625. {
  12626. removeAllJobs (true, 4000);
  12627. int i;
  12628. for (i = threads.size(); --i >= 0;)
  12629. threads.getUnchecked(i)->signalThreadShouldExit();
  12630. for (i = threads.size(); --i >= 0;)
  12631. threads.getUnchecked(i)->stopThread (500);
  12632. }
  12633. void ThreadPool::addJob (ThreadPoolJob* const job)
  12634. {
  12635. jassert (job != 0);
  12636. jassert (job->pool == 0);
  12637. if (job->pool == 0)
  12638. {
  12639. job->pool = this;
  12640. job->shouldStop = false;
  12641. job->isActive = false;
  12642. {
  12643. const ScopedLock sl (lock);
  12644. jobs.add (job);
  12645. int numRunning = 0;
  12646. for (int i = threads.size(); --i >= 0;)
  12647. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12648. ++numRunning;
  12649. if (numRunning < threads.size())
  12650. {
  12651. bool startedOne = false;
  12652. int n = 1000;
  12653. while (--n >= 0 && ! startedOne)
  12654. {
  12655. for (int i = threads.size(); --i >= 0;)
  12656. {
  12657. if (! threads.getUnchecked(i)->isThreadRunning())
  12658. {
  12659. threads.getUnchecked(i)->startThread (priority);
  12660. startedOne = true;
  12661. break;
  12662. }
  12663. }
  12664. if (! startedOne)
  12665. Thread::sleep (2);
  12666. }
  12667. }
  12668. }
  12669. for (int i = threads.size(); --i >= 0;)
  12670. threads.getUnchecked(i)->notify();
  12671. }
  12672. }
  12673. int ThreadPool::getNumJobs() const
  12674. {
  12675. return jobs.size();
  12676. }
  12677. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12678. {
  12679. const ScopedLock sl (lock);
  12680. return (ThreadPoolJob*) jobs [index];
  12681. }
  12682. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12683. {
  12684. const ScopedLock sl (lock);
  12685. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12686. }
  12687. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12688. {
  12689. const ScopedLock sl (lock);
  12690. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12691. }
  12692. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12693. const int timeOutMs) const
  12694. {
  12695. if (job != 0)
  12696. {
  12697. const uint32 start = Time::getMillisecondCounter();
  12698. while (contains (job))
  12699. {
  12700. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12701. return false;
  12702. jobFinishedSignal.wait (2);
  12703. }
  12704. }
  12705. return true;
  12706. }
  12707. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12708. const bool interruptIfRunning,
  12709. const int timeOutMs)
  12710. {
  12711. if (job != 0)
  12712. {
  12713. lock.enter();
  12714. if (jobs.contains (job))
  12715. {
  12716. if (job->isActive)
  12717. {
  12718. if (interruptIfRunning)
  12719. job->signalJobShouldExit();
  12720. lock.exit();
  12721. return waitForJobToFinish (job, timeOutMs);
  12722. }
  12723. else
  12724. {
  12725. jobs.removeValue (job);
  12726. }
  12727. }
  12728. lock.exit();
  12729. }
  12730. return true;
  12731. }
  12732. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12733. const int timeOutMs,
  12734. const bool deleteInactiveJobs,
  12735. ThreadPool::JobSelector* selectedJobsToRemove)
  12736. {
  12737. Array <ThreadPoolJob*> jobsToWaitFor;
  12738. {
  12739. const ScopedLock sl (lock);
  12740. for (int i = jobs.size(); --i >= 0;)
  12741. {
  12742. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12743. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12744. {
  12745. if (job->isActive)
  12746. {
  12747. jobsToWaitFor.add (job);
  12748. if (interruptRunningJobs)
  12749. job->signalJobShouldExit();
  12750. }
  12751. else
  12752. {
  12753. jobs.remove (i);
  12754. if (deleteInactiveJobs)
  12755. delete job;
  12756. }
  12757. }
  12758. }
  12759. }
  12760. const uint32 start = Time::getMillisecondCounter();
  12761. for (;;)
  12762. {
  12763. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12764. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12765. jobsToWaitFor.remove (i);
  12766. if (jobsToWaitFor.size() == 0)
  12767. break;
  12768. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12769. return false;
  12770. jobFinishedSignal.wait (20);
  12771. }
  12772. return true;
  12773. }
  12774. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12775. {
  12776. StringArray s;
  12777. const ScopedLock sl (lock);
  12778. for (int i = 0; i < jobs.size(); ++i)
  12779. {
  12780. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12781. if (job->isActive || ! onlyReturnActiveJobs)
  12782. s.add (job->getJobName());
  12783. }
  12784. return s;
  12785. }
  12786. bool ThreadPool::setThreadPriorities (const int newPriority)
  12787. {
  12788. bool ok = true;
  12789. if (priority != newPriority)
  12790. {
  12791. priority = newPriority;
  12792. for (int i = threads.size(); --i >= 0;)
  12793. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12794. ok = false;
  12795. }
  12796. return ok;
  12797. }
  12798. bool ThreadPool::runNextJob()
  12799. {
  12800. ThreadPoolJob* job = 0;
  12801. {
  12802. const ScopedLock sl (lock);
  12803. for (int i = 0; i < jobs.size(); ++i)
  12804. {
  12805. job = jobs[i];
  12806. if (job != 0 && ! (job->isActive || job->shouldStop))
  12807. break;
  12808. job = 0;
  12809. }
  12810. if (job != 0)
  12811. job->isActive = true;
  12812. }
  12813. if (job != 0)
  12814. {
  12815. JUCE_TRY
  12816. {
  12817. ThreadPoolJob::JobStatus result = job->runJob();
  12818. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12819. const ScopedLock sl (lock);
  12820. if (jobs.contains (job))
  12821. {
  12822. job->isActive = false;
  12823. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12824. {
  12825. job->pool = 0;
  12826. job->shouldStop = true;
  12827. jobs.removeValue (job);
  12828. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12829. delete job;
  12830. jobFinishedSignal.signal();
  12831. }
  12832. else
  12833. {
  12834. // move the job to the end of the queue if it wants another go
  12835. jobs.move (jobs.indexOf (job), -1);
  12836. }
  12837. }
  12838. }
  12839. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12840. catch (...)
  12841. {
  12842. const ScopedLock sl (lock);
  12843. jobs.removeValue (job);
  12844. }
  12845. #endif
  12846. }
  12847. else
  12848. {
  12849. if (threadStopTimeout > 0
  12850. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12851. {
  12852. const ScopedLock sl (lock);
  12853. if (jobs.size() == 0)
  12854. for (int i = threads.size(); --i >= 0;)
  12855. threads.getUnchecked(i)->signalThreadShouldExit();
  12856. }
  12857. else
  12858. {
  12859. return false;
  12860. }
  12861. }
  12862. return true;
  12863. }
  12864. END_JUCE_NAMESPACE
  12865. /*** End of inlined file: juce_ThreadPool.cpp ***/
  12866. /*** Start of inlined file: juce_TimeSliceThread.cpp ***/
  12867. BEGIN_JUCE_NAMESPACE
  12868. TimeSliceThread::TimeSliceThread (const String& threadName)
  12869. : Thread (threadName),
  12870. index (0),
  12871. clientBeingCalled (0),
  12872. clientsChanged (false)
  12873. {
  12874. }
  12875. TimeSliceThread::~TimeSliceThread()
  12876. {
  12877. stopThread (2000);
  12878. }
  12879. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12880. {
  12881. const ScopedLock sl (listLock);
  12882. clients.addIfNotAlreadyThere (client);
  12883. clientsChanged = true;
  12884. notify();
  12885. }
  12886. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12887. {
  12888. const ScopedLock sl1 (listLock);
  12889. clientsChanged = true;
  12890. // if there's a chance we're in the middle of calling this client, we need to
  12891. // also lock the outer lock..
  12892. if (clientBeingCalled == client)
  12893. {
  12894. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12895. const ScopedLock sl2 (callbackLock);
  12896. const ScopedLock sl3 (listLock);
  12897. clients.removeValue (client);
  12898. }
  12899. else
  12900. {
  12901. clients.removeValue (client);
  12902. }
  12903. }
  12904. int TimeSliceThread::getNumClients() const
  12905. {
  12906. return clients.size();
  12907. }
  12908. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12909. {
  12910. const ScopedLock sl (listLock);
  12911. return clients [i];
  12912. }
  12913. void TimeSliceThread::run()
  12914. {
  12915. int numCallsSinceBusy = 0;
  12916. while (! threadShouldExit())
  12917. {
  12918. int timeToWait = 500;
  12919. {
  12920. const ScopedLock sl (callbackLock);
  12921. {
  12922. const ScopedLock sl2 (listLock);
  12923. if (clients.size() > 0)
  12924. {
  12925. index = (index + 1) % clients.size();
  12926. clientBeingCalled = clients [index];
  12927. }
  12928. else
  12929. {
  12930. index = 0;
  12931. clientBeingCalled = 0;
  12932. }
  12933. if (clientsChanged)
  12934. {
  12935. clientsChanged = false;
  12936. numCallsSinceBusy = 0;
  12937. }
  12938. }
  12939. if (clientBeingCalled != 0)
  12940. {
  12941. if (clientBeingCalled->useTimeSlice())
  12942. numCallsSinceBusy = 0;
  12943. else
  12944. ++numCallsSinceBusy;
  12945. if (numCallsSinceBusy >= clients.size())
  12946. timeToWait = 500;
  12947. else if (index == 0)
  12948. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12949. else
  12950. timeToWait = 0;
  12951. }
  12952. }
  12953. if (timeToWait > 0)
  12954. wait (timeToWait);
  12955. }
  12956. }
  12957. END_JUCE_NAMESPACE
  12958. /*** End of inlined file: juce_TimeSliceThread.cpp ***/
  12959. #endif
  12960. #if JUCE_BUILD_MISC
  12961. /*** Start of inlined file: juce_ValueTree.cpp ***/
  12962. BEGIN_JUCE_NAMESPACE
  12963. class ValueTreeSetPropertyAction : public UndoableAction
  12964. {
  12965. public:
  12966. ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_,
  12967. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12968. : target (target_), name (name_), newValue (newValue_),
  12969. isAddingNewProperty (isAddingNewProperty_),
  12970. isDeletingProperty (isDeletingProperty_)
  12971. {
  12972. if (! isAddingNewProperty)
  12973. oldValue = target_->getProperty (name_);
  12974. }
  12975. ~ValueTreeSetPropertyAction() {}
  12976. bool perform()
  12977. {
  12978. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12979. if (isDeletingProperty)
  12980. target->removeProperty (name, 0);
  12981. else
  12982. target->setProperty (name, newValue, 0);
  12983. return true;
  12984. }
  12985. bool undo()
  12986. {
  12987. if (isAddingNewProperty)
  12988. target->removeProperty (name, 0);
  12989. else
  12990. target->setProperty (name, oldValue, 0);
  12991. return true;
  12992. }
  12993. int getSizeInUnits()
  12994. {
  12995. return (int) sizeof (*this); //xxx should be more accurate
  12996. }
  12997. private:
  12998. const ValueTree::SharedObjectPtr target;
  12999. const var::identifier name;
  13000. const var newValue;
  13001. var oldValue;
  13002. const bool isAddingNewProperty, isDeletingProperty;
  13003. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  13004. const ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  13005. };
  13006. class ValueTreeChildChangeAction : public UndoableAction
  13007. {
  13008. public:
  13009. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  13010. const ValueTree::SharedObjectPtr& newChild_)
  13011. : target (target_),
  13012. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  13013. childIndex (childIndex_),
  13014. isDeleting (newChild_ == 0)
  13015. {
  13016. jassert (child != 0);
  13017. }
  13018. ~ValueTreeChildChangeAction() {}
  13019. bool perform()
  13020. {
  13021. if (isDeleting)
  13022. target->removeChild (childIndex, 0);
  13023. else
  13024. target->addChild (child, childIndex, 0);
  13025. return true;
  13026. }
  13027. bool undo()
  13028. {
  13029. if (isDeleting)
  13030. target->addChild (child, childIndex, 0);
  13031. else
  13032. target->removeChild (childIndex, 0);
  13033. return true;
  13034. }
  13035. int getSizeInUnits()
  13036. {
  13037. return (int) sizeof (*this); //xxx should be more accurate
  13038. }
  13039. private:
  13040. const ValueTree::SharedObjectPtr target, child;
  13041. const int childIndex;
  13042. const bool isDeleting;
  13043. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  13044. const ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  13045. };
  13046. ValueTree::SharedObject::SharedObject (const String& type_)
  13047. : type (type_), parent (0)
  13048. {
  13049. }
  13050. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  13051. : type (other.type), properties (other.properties), parent (0)
  13052. {
  13053. for (int i = 0; i < other.children.size(); ++i)
  13054. children.add (new SharedObject (*other.children.getUnchecked(i)));
  13055. }
  13056. ValueTree::SharedObject::~SharedObject()
  13057. {
  13058. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  13059. for (int i = children.size(); --i >= 0;)
  13060. {
  13061. const SharedObjectPtr c (children.getUnchecked(i));
  13062. c->parent = 0;
  13063. children.remove (i);
  13064. c->sendParentChangeMessage();
  13065. }
  13066. }
  13067. void ValueTree::deliverPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  13068. {
  13069. for (int i = listeners.size(); --i >= 0;)
  13070. {
  13071. ValueTree::Listener* const l = listeners[i];
  13072. if (l != 0)
  13073. l->valueTreePropertyChanged (tree, property);
  13074. }
  13075. }
  13076. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  13077. {
  13078. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  13079. {
  13080. ValueTree* const v = valueTreesWithListeners[i];
  13081. if (v != 0)
  13082. v->deliverPropertyChangeMessage (tree, property);
  13083. }
  13084. }
  13085. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  13086. {
  13087. ValueTree tree (this);
  13088. ValueTree::SharedObject* t = this;
  13089. while (t != 0)
  13090. {
  13091. t->sendPropertyChangeMessage (tree, property);
  13092. t = t->parent;
  13093. }
  13094. }
  13095. void ValueTree::deliverChildChangeMessage (ValueTree& tree)
  13096. {
  13097. for (int i = listeners.size(); --i >= 0;)
  13098. {
  13099. ValueTree::Listener* const l = listeners[i];
  13100. if (l != 0)
  13101. l->valueTreeChildrenChanged (tree);
  13102. }
  13103. }
  13104. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  13105. {
  13106. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  13107. {
  13108. ValueTree* const v = valueTreesWithListeners[i];
  13109. if (v != 0)
  13110. v->deliverChildChangeMessage (tree);
  13111. }
  13112. }
  13113. void ValueTree::SharedObject::sendChildChangeMessage()
  13114. {
  13115. ValueTree tree (this);
  13116. ValueTree::SharedObject* t = this;
  13117. while (t != 0)
  13118. {
  13119. t->sendChildChangeMessage (tree);
  13120. t = t->parent;
  13121. }
  13122. }
  13123. void ValueTree::deliverParentChangeMessage (ValueTree& tree)
  13124. {
  13125. for (int i = listeners.size(); --i >= 0;)
  13126. {
  13127. ValueTree::Listener* const l = listeners[i];
  13128. if (l != 0)
  13129. l->valueTreeParentChanged (tree);
  13130. }
  13131. }
  13132. void ValueTree::SharedObject::sendParentChangeMessage()
  13133. {
  13134. ValueTree tree (this);
  13135. int i;
  13136. for (i = children.size(); --i >= 0;)
  13137. {
  13138. SharedObject* const t = children[i];
  13139. if (t != 0)
  13140. t->sendParentChangeMessage();
  13141. }
  13142. for (i = valueTreesWithListeners.size(); --i >= 0;)
  13143. {
  13144. ValueTree* const v = valueTreesWithListeners[i];
  13145. if (v != 0)
  13146. v->deliverParentChangeMessage (tree);
  13147. }
  13148. }
  13149. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  13150. {
  13151. return properties [name];
  13152. }
  13153. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13154. {
  13155. if (undoManager == 0)
  13156. {
  13157. if (properties.set (name, newValue))
  13158. sendPropertyChangeMessage (name);
  13159. }
  13160. else
  13161. {
  13162. var* const existingValue = properties.getItem (name);
  13163. if (existingValue != 0)
  13164. {
  13165. if (*existingValue != newValue)
  13166. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  13167. }
  13168. else
  13169. {
  13170. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  13171. }
  13172. }
  13173. }
  13174. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  13175. {
  13176. return properties.contains (name);
  13177. }
  13178. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13179. {
  13180. if (undoManager == 0)
  13181. {
  13182. if (properties.remove (name))
  13183. sendPropertyChangeMessage (name);
  13184. }
  13185. else
  13186. {
  13187. if (properties.contains (name))
  13188. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var::null, false, true));
  13189. }
  13190. }
  13191. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  13192. {
  13193. if (undoManager == 0)
  13194. {
  13195. while (properties.size() > 0)
  13196. {
  13197. const var::identifier name (properties.getName (properties.size() - 1));
  13198. properties.remove (name);
  13199. sendPropertyChangeMessage (name);
  13200. }
  13201. }
  13202. else
  13203. {
  13204. for (int i = properties.size(); --i >= 0;)
  13205. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getName(i), var::null, false, true));
  13206. }
  13207. }
  13208. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  13209. {
  13210. for (int i = 0; i < children.size(); ++i)
  13211. if (children.getUnchecked(i)->type == typeToMatch)
  13212. return (SharedObject*) children.getUnchecked(i);
  13213. return (SharedObject*) 0;
  13214. }
  13215. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13216. {
  13217. for (int i = 0; i < children.size(); ++i)
  13218. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  13219. return (SharedObject*) children.getUnchecked(i);
  13220. return (SharedObject*) 0;
  13221. }
  13222. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  13223. {
  13224. const SharedObject* p = parent;
  13225. while (p != 0)
  13226. {
  13227. if (p == possibleParent)
  13228. return true;
  13229. p = p->parent;
  13230. }
  13231. return false;
  13232. }
  13233. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  13234. {
  13235. if (child != 0 && child->parent != this)
  13236. {
  13237. if (child != this && ! isAChildOf (child))
  13238. {
  13239. // You should always make sure that a child is removed from its previous parent before
  13240. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  13241. // undomanager should be used when removing it from its current parent..
  13242. jassert (child->parent == 0);
  13243. if (child->parent != 0)
  13244. {
  13245. jassert (child->parent->children.indexOf (child) >= 0);
  13246. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  13247. }
  13248. if (undoManager == 0)
  13249. {
  13250. children.insert (index, child);
  13251. child->parent = this;
  13252. sendChildChangeMessage();
  13253. child->sendParentChangeMessage();
  13254. }
  13255. else
  13256. {
  13257. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  13258. }
  13259. }
  13260. else
  13261. {
  13262. // You're attempting to create a recursive loop! A node
  13263. // can't be a child of one of its own children!
  13264. jassertfalse
  13265. }
  13266. }
  13267. }
  13268. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  13269. {
  13270. const SharedObjectPtr child (children [childIndex]);
  13271. if (child != 0)
  13272. {
  13273. if (undoManager == 0)
  13274. {
  13275. children.remove (childIndex);
  13276. child->parent = 0;
  13277. sendChildChangeMessage();
  13278. child->sendParentChangeMessage();
  13279. }
  13280. else
  13281. {
  13282. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  13283. }
  13284. }
  13285. }
  13286. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  13287. {
  13288. while (children.size() > 0)
  13289. removeChild (children.size() - 1, undoManager);
  13290. }
  13291. ValueTree::ValueTree (const String& type_)
  13292. : object (new ValueTree::SharedObject (type_))
  13293. {
  13294. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  13295. }
  13296. ValueTree::ValueTree (SharedObject* const object_)
  13297. : object (object_)
  13298. {
  13299. }
  13300. ValueTree::ValueTree (const ValueTree& other)
  13301. : object (other.object)
  13302. {
  13303. }
  13304. const ValueTree& ValueTree::operator= (const ValueTree& other)
  13305. {
  13306. if (listeners.size() > 0)
  13307. {
  13308. if (object != 0)
  13309. object->valueTreesWithListeners.removeValue (this);
  13310. if (other.object != 0)
  13311. other.object->valueTreesWithListeners.add (this);
  13312. }
  13313. object = other.object;
  13314. return *this;
  13315. }
  13316. ValueTree::~ValueTree()
  13317. {
  13318. if (listeners.size() > 0 && object != 0)
  13319. object->valueTreesWithListeners.removeValue (this);
  13320. }
  13321. bool ValueTree::operator== (const ValueTree& other) const
  13322. {
  13323. return object == other.object;
  13324. }
  13325. bool ValueTree::operator!= (const ValueTree& other) const
  13326. {
  13327. return object != other.object;
  13328. }
  13329. ValueTree ValueTree::createCopy() const
  13330. {
  13331. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  13332. }
  13333. bool ValueTree::hasType (const String& typeName) const
  13334. {
  13335. return object != 0 && object->type == typeName;
  13336. }
  13337. const String ValueTree::getType() const
  13338. {
  13339. return object != 0 ? object->type : String::empty;
  13340. }
  13341. ValueTree ValueTree::getParent() const
  13342. {
  13343. return object != 0 ? ValueTree (object->parent) : ValueTree ((SharedObject*) 0);
  13344. }
  13345. const var& ValueTree::operator[] (const var::identifier& name) const
  13346. {
  13347. return object == 0 ? var::null : object->getProperty (name);
  13348. }
  13349. const var& ValueTree::getProperty (const var::identifier& name) const
  13350. {
  13351. return object == 0 ? var::null : object->getProperty (name);
  13352. }
  13353. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13354. {
  13355. jassert (name.name.isNotEmpty());
  13356. if (object != 0 && name.name.isNotEmpty())
  13357. object->setProperty (name, newValue, undoManager);
  13358. }
  13359. bool ValueTree::hasProperty (const var::identifier& name) const
  13360. {
  13361. return object != 0 && object->hasProperty (name);
  13362. }
  13363. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13364. {
  13365. if (object != 0)
  13366. object->removeProperty (name, undoManager);
  13367. }
  13368. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  13369. {
  13370. if (object != 0)
  13371. object->removeAllProperties (undoManager);
  13372. }
  13373. int ValueTree::getNumProperties() const
  13374. {
  13375. return object == 0 ? 0 : object->properties.size();
  13376. }
  13377. const var::identifier ValueTree::getPropertyName (int index) const
  13378. {
  13379. return (object == 0) ? var::identifier()
  13380. : object->properties.getName (index);
  13381. }
  13382. class ValueTreePropertyValueSource : public Value::ValueSource,
  13383. public ValueTree::Listener
  13384. {
  13385. public:
  13386. ValueTreePropertyValueSource (const ValueTree& tree_,
  13387. const var::identifier& property_,
  13388. UndoManager* const undoManager_)
  13389. : tree (tree_),
  13390. property (property_),
  13391. undoManager (undoManager_)
  13392. {
  13393. tree.addListener (this);
  13394. }
  13395. ~ValueTreePropertyValueSource()
  13396. {
  13397. tree.removeListener (this);
  13398. }
  13399. const var getValue() const
  13400. {
  13401. return tree [property];
  13402. }
  13403. void setValue (const var& newValue)
  13404. {
  13405. tree.setProperty (property, newValue, undoManager);
  13406. }
  13407. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13408. {
  13409. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13410. sendChangeMessage (false);
  13411. }
  13412. void valueTreeChildrenChanged (ValueTree&) {}
  13413. void valueTreeParentChanged (ValueTree&) {}
  13414. private:
  13415. ValueTree tree;
  13416. const var::identifier property;
  13417. UndoManager* const undoManager;
  13418. const ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13419. };
  13420. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13421. {
  13422. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13423. }
  13424. int ValueTree::getNumChildren() const
  13425. {
  13426. return object == 0 ? 0 : object->children.size();
  13427. }
  13428. ValueTree ValueTree::getChild (int index) const
  13429. {
  13430. return object != 0 ? (SharedObject*) object->children [index] : ValueTree ((SharedObject*) 0);
  13431. }
  13432. ValueTree ValueTree::getChildWithName (const String& type) const
  13433. {
  13434. return object != 0 ? object->getChildWithName (type) : ValueTree ((SharedObject*) 0);
  13435. }
  13436. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13437. {
  13438. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree ((SharedObject*) 0);
  13439. }
  13440. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13441. {
  13442. return object != 0 && object->isAChildOf (possibleParent.object);
  13443. }
  13444. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13445. {
  13446. if (object != 0)
  13447. object->addChild (child.object, index, undoManager);
  13448. }
  13449. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13450. {
  13451. if (object != 0)
  13452. object->removeChild (childIndex, undoManager);
  13453. }
  13454. void ValueTree::removeChild (ValueTree& child, UndoManager* const undoManager)
  13455. {
  13456. if (object != 0)
  13457. object->removeChild (object->children.indexOf (child.object), undoManager);
  13458. }
  13459. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13460. {
  13461. if (object != 0)
  13462. object->removeAllChildren (undoManager);
  13463. }
  13464. void ValueTree::addListener (Listener* listener)
  13465. {
  13466. if (listener != 0)
  13467. {
  13468. if (listeners.size() == 0 && object != 0)
  13469. object->valueTreesWithListeners.add (this);
  13470. listeners.add (listener);
  13471. }
  13472. }
  13473. void ValueTree::removeListener (Listener* listener)
  13474. {
  13475. listeners.removeValue (listener);
  13476. if (listeners.size() == 0 && object != 0)
  13477. object->valueTreesWithListeners.removeValue (this);
  13478. }
  13479. XmlElement* ValueTree::SharedObject::createXml() const
  13480. {
  13481. XmlElement* xml = new XmlElement (type);
  13482. int i;
  13483. for (i = 0; i < properties.size(); ++i)
  13484. {
  13485. var::identifier name (properties.getName(i));
  13486. const var& v = properties [name];
  13487. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13488. xml->setAttribute (name.name, v.toString());
  13489. }
  13490. for (i = 0; i < children.size(); ++i)
  13491. xml->addChildElement (children.getUnchecked(i)->createXml());
  13492. return xml;
  13493. }
  13494. XmlElement* ValueTree::createXml() const
  13495. {
  13496. return object != 0 ? object->createXml() : 0;
  13497. }
  13498. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13499. {
  13500. ValueTree v (xml.getTagName());
  13501. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13502. for (int i = 0; i < numAtts; ++i)
  13503. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13504. forEachXmlChildElement (xml, e)
  13505. {
  13506. v.addChild (fromXml (*e), -1, 0);
  13507. }
  13508. return v;
  13509. }
  13510. void ValueTree::writeToStream (OutputStream& output)
  13511. {
  13512. output.writeString (getType());
  13513. const int numProps = getNumProperties();
  13514. output.writeCompressedInt (numProps);
  13515. int i;
  13516. for (i = 0; i < numProps; ++i)
  13517. {
  13518. const var::identifier name (getPropertyName(i));
  13519. output.writeString (name.name);
  13520. getProperty(name).writeToStream (output);
  13521. }
  13522. const int numChildren = getNumChildren();
  13523. output.writeCompressedInt (numChildren);
  13524. for (i = 0; i < numChildren; ++i)
  13525. getChild (i).writeToStream (output);
  13526. }
  13527. ValueTree ValueTree::readFromStream (InputStream& input)
  13528. {
  13529. String type (input.readString());
  13530. if (type.isEmpty())
  13531. return ValueTree ((SharedObject*) 0);
  13532. ValueTree v (type);
  13533. const int numProps = input.readCompressedInt();
  13534. if (numProps < 0)
  13535. {
  13536. jassertfalse // trying to read corrupted data!
  13537. return v;
  13538. }
  13539. int i;
  13540. for (i = 0; i < numProps; ++i)
  13541. {
  13542. const String name (input.readString());
  13543. jassert (name.isNotEmpty());
  13544. const var value (var::readFromStream (input));
  13545. v.setProperty (name, value, 0);
  13546. }
  13547. const int numChildren = input.readCompressedInt();
  13548. for (i = 0; i < numChildren; ++i)
  13549. v.addChild (readFromStream (input), -1, 0);
  13550. return v;
  13551. }
  13552. END_JUCE_NAMESPACE
  13553. /*** End of inlined file: juce_ValueTree.cpp ***/
  13554. /*** Start of inlined file: juce_Value.cpp ***/
  13555. BEGIN_JUCE_NAMESPACE
  13556. Value::ValueSource::ValueSource()
  13557. {
  13558. }
  13559. Value::ValueSource::~ValueSource()
  13560. {
  13561. }
  13562. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13563. {
  13564. if (synchronous)
  13565. {
  13566. for (int i = valuesWithListeners.size(); --i >= 0;)
  13567. {
  13568. Value* const v = valuesWithListeners[i];
  13569. if (v != 0)
  13570. v->callListeners();
  13571. }
  13572. }
  13573. else
  13574. {
  13575. triggerAsyncUpdate();
  13576. }
  13577. }
  13578. void Value::ValueSource::handleAsyncUpdate()
  13579. {
  13580. sendChangeMessage (true);
  13581. }
  13582. class SimpleValueSource : public Value::ValueSource
  13583. {
  13584. public:
  13585. SimpleValueSource()
  13586. {
  13587. }
  13588. SimpleValueSource (const var& initialValue)
  13589. : value (initialValue)
  13590. {
  13591. }
  13592. ~SimpleValueSource()
  13593. {
  13594. }
  13595. const var getValue() const
  13596. {
  13597. return value;
  13598. }
  13599. void setValue (const var& newValue)
  13600. {
  13601. if (newValue != value)
  13602. {
  13603. value = newValue;
  13604. sendChangeMessage (false);
  13605. }
  13606. }
  13607. private:
  13608. var value;
  13609. SimpleValueSource (const SimpleValueSource&);
  13610. const SimpleValueSource& operator= (const SimpleValueSource&);
  13611. };
  13612. Value::Value()
  13613. : value (new SimpleValueSource())
  13614. {
  13615. }
  13616. Value::Value (ValueSource* const value_)
  13617. : value (value_)
  13618. {
  13619. jassert (value_ != 0);
  13620. }
  13621. Value::Value (const var& initialValue)
  13622. : value (new SimpleValueSource (initialValue))
  13623. {
  13624. }
  13625. Value::Value (const Value& other)
  13626. : value (other.value)
  13627. {
  13628. }
  13629. const Value& Value::operator= (const Value& other)
  13630. {
  13631. value = other.value;
  13632. return *this;
  13633. }
  13634. Value::~Value()
  13635. {
  13636. if (listeners.size() > 0)
  13637. value->valuesWithListeners.removeValue (this);
  13638. }
  13639. const var Value::getValue() const
  13640. {
  13641. return value->getValue();
  13642. }
  13643. void Value::setValue (const var& newValue)
  13644. {
  13645. value->setValue (newValue);
  13646. }
  13647. const String Value::toString() const
  13648. {
  13649. return value->getValue().toString();
  13650. }
  13651. const Value& Value::operator= (const var& newValue)
  13652. {
  13653. value->setValue (newValue);
  13654. return *this;
  13655. }
  13656. void Value::referTo (const Value& valueToReferTo)
  13657. {
  13658. if (valueToReferTo.value != value)
  13659. {
  13660. if (listeners.size() > 0)
  13661. {
  13662. value->valuesWithListeners.removeValue (this);
  13663. valueToReferTo.value->valuesWithListeners.add (this);
  13664. }
  13665. value = valueToReferTo.value;
  13666. callListeners();
  13667. }
  13668. }
  13669. bool Value::refersToSameSourceAs (const Value& other) const
  13670. {
  13671. return value == other.value;
  13672. }
  13673. bool Value::operator== (const Value& other) const
  13674. {
  13675. return value == other.value || value->getValue() == other.getValue();
  13676. }
  13677. bool Value::operator!= (const Value& other) const
  13678. {
  13679. return value != other.value && value->getValue() != other.getValue();
  13680. }
  13681. void Value::addListener (Listener* const listener)
  13682. {
  13683. if (listener != 0)
  13684. {
  13685. if (listeners.size() == 0)
  13686. value->valuesWithListeners.add (this);
  13687. listeners.add (listener);
  13688. }
  13689. }
  13690. void Value::removeListener (Listener* const listener)
  13691. {
  13692. listeners.removeValue (listener);
  13693. if (listeners.size() == 0)
  13694. value->valuesWithListeners.removeValue (this);
  13695. }
  13696. void Value::callListeners()
  13697. {
  13698. Value valueCopy (*this); // Use a copy in case this object gets deleted by a callback
  13699. for (int i = listeners.size(); --i >= 0;)
  13700. {
  13701. Listener* const l = listeners[i];
  13702. if (l != 0)
  13703. l->valueChanged (valueCopy);
  13704. }
  13705. }
  13706. END_JUCE_NAMESPACE
  13707. /*** End of inlined file: juce_Value.cpp ***/
  13708. /*** Start of inlined file: juce_Application.cpp ***/
  13709. #if JUCE_MSVC
  13710. #pragma warning (push)
  13711. #pragma warning (disable: 4245 4514 4100)
  13712. #include <crtdbg.h>
  13713. #pragma warning (pop)
  13714. #endif
  13715. BEGIN_JUCE_NAMESPACE
  13716. void juce_setCurrentThreadName (const String& name);
  13717. static JUCEApplication* appInstance = 0;
  13718. JUCEApplication::JUCEApplication()
  13719. : appReturnValue (0),
  13720. stillInitialising (true),
  13721. appLock (0)
  13722. {
  13723. }
  13724. JUCEApplication::~JUCEApplication()
  13725. {
  13726. if (appLock != 0)
  13727. {
  13728. appLock->exit();
  13729. delete appLock;
  13730. }
  13731. }
  13732. JUCEApplication* JUCEApplication::getInstance() throw()
  13733. {
  13734. return appInstance;
  13735. }
  13736. bool JUCEApplication::isInitialising() const throw()
  13737. {
  13738. return stillInitialising;
  13739. }
  13740. const String JUCEApplication::getApplicationVersion()
  13741. {
  13742. return String::empty;
  13743. }
  13744. bool JUCEApplication::moreThanOneInstanceAllowed()
  13745. {
  13746. return true;
  13747. }
  13748. void JUCEApplication::anotherInstanceStarted (const String&)
  13749. {
  13750. }
  13751. void JUCEApplication::systemRequestedQuit()
  13752. {
  13753. quit();
  13754. }
  13755. void JUCEApplication::quit()
  13756. {
  13757. MessageManager::getInstance()->stopDispatchLoop();
  13758. }
  13759. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13760. {
  13761. appReturnValue = newReturnValue;
  13762. }
  13763. void JUCEApplication::unhandledException (const std::exception*,
  13764. const String&,
  13765. const int)
  13766. {
  13767. jassertfalse
  13768. }
  13769. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13770. const char* const sourceFile,
  13771. const int lineNumber)
  13772. {
  13773. if (appInstance != 0)
  13774. appInstance->unhandledException (e, sourceFile, lineNumber);
  13775. }
  13776. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13777. {
  13778. return 0;
  13779. }
  13780. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13781. {
  13782. commands.add (StandardApplicationCommandIDs::quit);
  13783. }
  13784. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13785. {
  13786. if (commandID == StandardApplicationCommandIDs::quit)
  13787. {
  13788. result.setInfo (TRANS("Quit"),
  13789. TRANS("Quits the application"),
  13790. "Application",
  13791. 0);
  13792. result.defaultKeypresses.add (KeyPress (T('q'), ModifierKeys::commandModifier, 0));
  13793. }
  13794. }
  13795. bool JUCEApplication::perform (const InvocationInfo& info)
  13796. {
  13797. if (info.commandID == StandardApplicationCommandIDs::quit)
  13798. {
  13799. systemRequestedQuit();
  13800. return true;
  13801. }
  13802. return false;
  13803. }
  13804. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13805. {
  13806. if (! app->initialiseApp (commandLine))
  13807. return 0;
  13808. // now loop until a quit message is received..
  13809. JUCE_TRY
  13810. {
  13811. MessageManager::getInstance()->runDispatchLoop();
  13812. }
  13813. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13814. catch (const std::exception& e)
  13815. {
  13816. app->unhandledException (&e, __FILE__, __LINE__);
  13817. }
  13818. catch (...)
  13819. {
  13820. app->unhandledException (0, __FILE__, __LINE__);
  13821. }
  13822. #endif
  13823. return shutdownAppAndClearUp();
  13824. }
  13825. bool JUCEApplication::initialiseApp (String& commandLine)
  13826. {
  13827. jassert (appInstance == 0);
  13828. appInstance = this;
  13829. commandLineParameters = commandLine.trim();
  13830. commandLine = String::empty;
  13831. initialiseJuce_GUI();
  13832. #if ! JUCE_IPHONE
  13833. jassert (appLock == 0); // initialiseApp must only be called once!
  13834. if (! moreThanOneInstanceAllowed())
  13835. {
  13836. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13837. if (! appLock->enter(0))
  13838. {
  13839. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13840. delete appInstance;
  13841. appInstance = 0;
  13842. DBG ("Another instance is running - quitting...");
  13843. return false;
  13844. }
  13845. }
  13846. #endif
  13847. // let the app do its setting-up..
  13848. initialise (commandLineParameters);
  13849. // register for broadcast new app messages
  13850. MessageManager::getInstance()->registerBroadcastListener (this);
  13851. stillInitialising = false;
  13852. return true;
  13853. }
  13854. int JUCEApplication::shutdownAppAndClearUp()
  13855. {
  13856. jassert (appInstance != 0);
  13857. JUCEApplication* const app = appInstance;
  13858. int returnValue = 0;
  13859. MessageManager::getInstance()->deregisterBroadcastListener (app);
  13860. static bool reentrancyCheck = false;
  13861. if (! reentrancyCheck)
  13862. {
  13863. reentrancyCheck = true;
  13864. JUCE_TRY
  13865. {
  13866. // give the app a chance to clean up..
  13867. app->shutdown();
  13868. }
  13869. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13870. catch (const std::exception& e)
  13871. {
  13872. app->unhandledException (&e, __FILE__, __LINE__);
  13873. }
  13874. catch (...)
  13875. {
  13876. app->unhandledException (0, __FILE__, __LINE__);
  13877. }
  13878. #endif
  13879. JUCE_TRY
  13880. {
  13881. shutdownJuce_GUI();
  13882. returnValue = app->getApplicationReturnValue();
  13883. appInstance = 0;
  13884. delete app;
  13885. }
  13886. JUCE_CATCH_ALL_ASSERT
  13887. reentrancyCheck = false;
  13888. }
  13889. return returnValue;
  13890. }
  13891. #if JUCE_IPHONE
  13892. extern int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app);
  13893. #endif
  13894. #if ! JUCE_WINDOWS
  13895. extern const char* juce_Argv0;
  13896. #endif
  13897. int JUCEApplication::main (int argc, char* argv[],
  13898. JUCEApplication* const newApp)
  13899. {
  13900. #if ! JUCE_WINDOWS
  13901. juce_Argv0 = argv[0];
  13902. #endif
  13903. #if JUCE_IPHONE
  13904. const ScopedAutoReleasePool pool;
  13905. return juce_IPhoneMain (argc, argv, newApp);
  13906. #else
  13907. #if JUCE_MAC
  13908. const ScopedAutoReleasePool pool;
  13909. #endif
  13910. String cmd;
  13911. for (int i = 1; i < argc; ++i)
  13912. cmd << String::fromUTF8 ((const uint8*) argv[i]) << T(' ');
  13913. return JUCEApplication::main (cmd, newApp);
  13914. #endif
  13915. }
  13916. void JUCEApplication::actionListenerCallback (const String& message)
  13917. {
  13918. if (message.startsWith (getApplicationName() + "/"))
  13919. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13920. }
  13921. static bool juceInitialisedGUI = false;
  13922. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13923. {
  13924. if (! juceInitialisedGUI)
  13925. {
  13926. #if JUCE_MAC || JUCE_IPHONE
  13927. const ScopedAutoReleasePool pool;
  13928. #endif
  13929. juceInitialisedGUI = true;
  13930. initialiseJuce_NonGUI();
  13931. MessageManager::getInstance();
  13932. LookAndFeel::setDefaultLookAndFeel (0);
  13933. juce_setCurrentThreadName ("Juce Message Thread");
  13934. #if JUCE_WINDOWS && JUCE_DEBUG
  13935. // This section is just for catching people who mess up their project settings and
  13936. // turn RTTI off..
  13937. try
  13938. {
  13939. TextButton tb (String::empty);
  13940. Component* c = &tb;
  13941. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13942. c = dynamic_cast <Button*> (c);
  13943. }
  13944. catch (...)
  13945. {
  13946. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13947. // got as far as this catch statement, then why haven't you got exception catching
  13948. // turned on in the debugger???
  13949. jassertfalse
  13950. }
  13951. #endif
  13952. }
  13953. }
  13954. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13955. {
  13956. if (juceInitialisedGUI)
  13957. {
  13958. #if JUCE_MAC
  13959. const ScopedAutoReleasePool pool;
  13960. #endif
  13961. {
  13962. DeletedAtShutdown::deleteAll();
  13963. LookAndFeel::clearDefaultLookAndFeel();
  13964. }
  13965. delete MessageManager::getInstance();
  13966. shutdownJuce_NonGUI();
  13967. juceInitialisedGUI = false;
  13968. }
  13969. }
  13970. END_JUCE_NAMESPACE
  13971. /*** End of inlined file: juce_Application.cpp ***/
  13972. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13973. BEGIN_JUCE_NAMESPACE
  13974. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13975. : commandID (commandID_),
  13976. flags (0)
  13977. {
  13978. }
  13979. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13980. const String& description_,
  13981. const String& categoryName_,
  13982. const int flags_) throw()
  13983. {
  13984. shortName = shortName_;
  13985. description = description_;
  13986. categoryName = categoryName_;
  13987. flags = flags_;
  13988. }
  13989. void ApplicationCommandInfo::setActive (const bool b) throw()
  13990. {
  13991. if (b)
  13992. flags &= ~isDisabled;
  13993. else
  13994. flags |= isDisabled;
  13995. }
  13996. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13997. {
  13998. if (b)
  13999. flags |= isTicked;
  14000. else
  14001. flags &= ~isTicked;
  14002. }
  14003. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  14004. {
  14005. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  14006. }
  14007. END_JUCE_NAMESPACE
  14008. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  14009. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  14010. BEGIN_JUCE_NAMESPACE
  14011. ApplicationCommandManager::ApplicationCommandManager()
  14012. : firstTarget (0)
  14013. {
  14014. keyMappings = new KeyPressMappingSet (this);
  14015. Desktop::getInstance().addFocusChangeListener (this);
  14016. }
  14017. ApplicationCommandManager::~ApplicationCommandManager()
  14018. {
  14019. Desktop::getInstance().removeFocusChangeListener (this);
  14020. keyMappings = 0;
  14021. }
  14022. void ApplicationCommandManager::clearCommands()
  14023. {
  14024. commands.clear();
  14025. keyMappings->clearAllKeyPresses();
  14026. triggerAsyncUpdate();
  14027. }
  14028. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  14029. {
  14030. // zero isn't a valid command ID!
  14031. jassert (newCommand.commandID != 0);
  14032. // the name isn't optional!
  14033. jassert (newCommand.shortName.isNotEmpty());
  14034. if (getCommandForID (newCommand.commandID) == 0)
  14035. {
  14036. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  14037. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  14038. commands.add (newInfo);
  14039. keyMappings->resetToDefaultMapping (newCommand.commandID);
  14040. triggerAsyncUpdate();
  14041. }
  14042. else
  14043. {
  14044. // trying to re-register the same command with different parameters?
  14045. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  14046. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  14047. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  14048. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  14049. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  14050. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  14051. }
  14052. }
  14053. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  14054. {
  14055. if (target != 0)
  14056. {
  14057. Array <CommandID> commandIDs;
  14058. target->getAllCommands (commandIDs);
  14059. for (int i = 0; i < commandIDs.size(); ++i)
  14060. {
  14061. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  14062. target->getCommandInfo (info.commandID, info);
  14063. registerCommand (info);
  14064. }
  14065. }
  14066. }
  14067. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  14068. {
  14069. for (int i = commands.size(); --i >= 0;)
  14070. {
  14071. if (commands.getUnchecked (i)->commandID == commandID)
  14072. {
  14073. commands.remove (i);
  14074. triggerAsyncUpdate();
  14075. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  14076. for (int j = keys.size(); --j >= 0;)
  14077. keyMappings->removeKeyPress (keys.getReference (j));
  14078. }
  14079. }
  14080. }
  14081. void ApplicationCommandManager::commandStatusChanged()
  14082. {
  14083. triggerAsyncUpdate();
  14084. }
  14085. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  14086. {
  14087. for (int i = commands.size(); --i >= 0;)
  14088. if (commands.getUnchecked(i)->commandID == commandID)
  14089. return commands.getUnchecked(i);
  14090. return 0;
  14091. }
  14092. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  14093. {
  14094. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14095. return (ci != 0) ? ci->shortName : String::empty;
  14096. }
  14097. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  14098. {
  14099. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14100. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  14101. : String::empty;
  14102. }
  14103. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  14104. {
  14105. StringArray s;
  14106. for (int i = 0; i < commands.size(); ++i)
  14107. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  14108. return s;
  14109. }
  14110. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  14111. {
  14112. Array <CommandID> results;
  14113. for (int i = 0; i < commands.size(); ++i)
  14114. if (commands.getUnchecked(i)->categoryName == categoryName)
  14115. results.add (commands.getUnchecked(i)->commandID);
  14116. return results;
  14117. }
  14118. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14119. {
  14120. ApplicationCommandTarget::InvocationInfo info (commandID);
  14121. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14122. return invoke (info, asynchronously);
  14123. }
  14124. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  14125. {
  14126. // This call isn't thread-safe for use from a non-UI thread without locking the message
  14127. // manager first..
  14128. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  14129. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  14130. if (target == 0)
  14131. return false;
  14132. ApplicationCommandInfo commandInfo (0);
  14133. target->getCommandInfo (info_.commandID, commandInfo);
  14134. ApplicationCommandTarget::InvocationInfo info (info_);
  14135. info.commandFlags = commandInfo.flags;
  14136. sendListenerInvokeCallback (info);
  14137. const bool ok = target->invoke (info, asynchronously);
  14138. commandStatusChanged();
  14139. return ok;
  14140. }
  14141. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  14142. {
  14143. return firstTarget != 0 ? firstTarget
  14144. : findDefaultComponentTarget();
  14145. }
  14146. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  14147. {
  14148. firstTarget = newTarget;
  14149. }
  14150. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  14151. ApplicationCommandInfo& upToDateInfo)
  14152. {
  14153. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  14154. if (target == 0)
  14155. target = JUCEApplication::getInstance();
  14156. if (target != 0)
  14157. target = target->getTargetForCommand (commandID);
  14158. if (target != 0)
  14159. target->getCommandInfo (commandID, upToDateInfo);
  14160. return target;
  14161. }
  14162. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  14163. {
  14164. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  14165. if (target == 0 && c != 0)
  14166. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14167. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14168. return target;
  14169. }
  14170. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  14171. {
  14172. Component* c = Component::getCurrentlyFocusedComponent();
  14173. if (c == 0)
  14174. {
  14175. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  14176. if (activeWindow != 0)
  14177. {
  14178. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  14179. if (c == 0)
  14180. c = activeWindow;
  14181. }
  14182. }
  14183. if (c == 0 && Process::isForegroundProcess())
  14184. {
  14185. // getting a bit desperate now - try all desktop comps..
  14186. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  14187. {
  14188. ApplicationCommandTarget* const target
  14189. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  14190. ->getPeer()->getLastFocusedSubcomponent());
  14191. if (target != 0)
  14192. return target;
  14193. }
  14194. }
  14195. if (c != 0)
  14196. {
  14197. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  14198. // if we're focused on a ResizableWindow, chances are that it's the content
  14199. // component that really should get the event. And if not, the event will
  14200. // still be passed up to the top level window anyway, so let's send it to the
  14201. // content comp.
  14202. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  14203. c = resizableWindow->getContentComponent();
  14204. ApplicationCommandTarget* const target = findTargetForComponent (c);
  14205. if (target != 0)
  14206. return target;
  14207. }
  14208. return JUCEApplication::getInstance();
  14209. }
  14210. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  14211. {
  14212. jassert (listener != 0);
  14213. if (listener != 0)
  14214. listeners.add (listener);
  14215. }
  14216. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  14217. {
  14218. listeners.removeValue (listener);
  14219. }
  14220. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info) const
  14221. {
  14222. for (int i = listeners.size(); --i >= 0;)
  14223. {
  14224. ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandInvoked (info);
  14225. i = jmin (i, listeners.size());
  14226. }
  14227. }
  14228. void ApplicationCommandManager::handleAsyncUpdate()
  14229. {
  14230. for (int i = listeners.size(); --i >= 0;)
  14231. {
  14232. ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandListChanged();
  14233. i = jmin (i, listeners.size());
  14234. }
  14235. }
  14236. void ApplicationCommandManager::globalFocusChanged (Component*)
  14237. {
  14238. commandStatusChanged();
  14239. }
  14240. END_JUCE_NAMESPACE
  14241. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  14242. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14243. BEGIN_JUCE_NAMESPACE
  14244. ApplicationCommandTarget::ApplicationCommandTarget()
  14245. {
  14246. }
  14247. ApplicationCommandTarget::~ApplicationCommandTarget()
  14248. {
  14249. messageInvoker = 0;
  14250. }
  14251. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  14252. {
  14253. if (isCommandActive (info.commandID))
  14254. {
  14255. if (async)
  14256. {
  14257. if (messageInvoker == 0)
  14258. messageInvoker = new CommandTargetMessageInvoker (this);
  14259. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  14260. return true;
  14261. }
  14262. else
  14263. {
  14264. const bool success = perform (info);
  14265. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  14266. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  14267. // returns the command's info.
  14268. return success;
  14269. }
  14270. }
  14271. return false;
  14272. }
  14273. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  14274. {
  14275. Component* c = dynamic_cast <Component*> (this);
  14276. if (c != 0)
  14277. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14278. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14279. return 0;
  14280. }
  14281. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  14282. {
  14283. ApplicationCommandTarget* target = this;
  14284. int depth = 0;
  14285. while (target != 0)
  14286. {
  14287. Array <CommandID> commandIDs;
  14288. target->getAllCommands (commandIDs);
  14289. if (commandIDs.contains (commandID))
  14290. return target;
  14291. target = target->getNextCommandTarget();
  14292. ++depth;
  14293. jassert (depth < 100); // could be a recursive command chain??
  14294. jassert (target != this); // definitely a recursive command chain!
  14295. if (depth > 100 || target == this)
  14296. break;
  14297. }
  14298. if (target == 0)
  14299. {
  14300. target = JUCEApplication::getInstance();
  14301. if (target != 0)
  14302. {
  14303. Array <CommandID> commandIDs;
  14304. target->getAllCommands (commandIDs);
  14305. if (commandIDs.contains (commandID))
  14306. return target;
  14307. }
  14308. }
  14309. return 0;
  14310. }
  14311. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  14312. {
  14313. ApplicationCommandInfo info (commandID);
  14314. info.flags = ApplicationCommandInfo::isDisabled;
  14315. getCommandInfo (commandID, info);
  14316. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  14317. }
  14318. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  14319. {
  14320. ApplicationCommandTarget* target = this;
  14321. int depth = 0;
  14322. while (target != 0)
  14323. {
  14324. if (target->tryToInvoke (info, async))
  14325. return true;
  14326. target = target->getNextCommandTarget();
  14327. ++depth;
  14328. jassert (depth < 100); // could be a recursive command chain??
  14329. jassert (target != this); // definitely a recursive command chain!
  14330. if (depth > 100 || target == this)
  14331. break;
  14332. }
  14333. if (target == 0)
  14334. {
  14335. target = JUCEApplication::getInstance();
  14336. if (target != 0)
  14337. return target->tryToInvoke (info, async);
  14338. }
  14339. return false;
  14340. }
  14341. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14342. {
  14343. ApplicationCommandTarget::InvocationInfo info (commandID);
  14344. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14345. return invoke (info, asynchronously);
  14346. }
  14347. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  14348. : commandID (commandID_),
  14349. commandFlags (0),
  14350. invocationMethod (direct),
  14351. originatingComponent (0),
  14352. isKeyDown (false),
  14353. millisecsSinceKeyPressed (0)
  14354. {
  14355. }
  14356. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  14357. : owner (owner_)
  14358. {
  14359. }
  14360. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  14361. {
  14362. }
  14363. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  14364. {
  14365. const ScopedPointer <InvocationInfo> info ((InvocationInfo*) message.pointerParameter);
  14366. owner->tryToInvoke (*info, false);
  14367. }
  14368. END_JUCE_NAMESPACE
  14369. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14370. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  14371. BEGIN_JUCE_NAMESPACE
  14372. juce_ImplementSingleton (ApplicationProperties)
  14373. ApplicationProperties::ApplicationProperties() throw()
  14374. : msBeforeSaving (3000),
  14375. options (PropertiesFile::storeAsBinary),
  14376. commonSettingsAreReadOnly (0)
  14377. {
  14378. }
  14379. ApplicationProperties::~ApplicationProperties()
  14380. {
  14381. closeFiles();
  14382. clearSingletonInstance();
  14383. }
  14384. void ApplicationProperties::setStorageParameters (const String& applicationName,
  14385. const String& fileNameSuffix,
  14386. const String& folderName_,
  14387. const int millisecondsBeforeSaving,
  14388. const int propertiesFileOptions) throw()
  14389. {
  14390. appName = applicationName;
  14391. fileSuffix = fileNameSuffix;
  14392. folderName = folderName_;
  14393. msBeforeSaving = millisecondsBeforeSaving;
  14394. options = propertiesFileOptions;
  14395. }
  14396. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  14397. const bool testCommonSettings,
  14398. const bool showWarningDialogOnFailure)
  14399. {
  14400. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14401. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14402. if (! (userOk && commonOk))
  14403. {
  14404. if (showWarningDialogOnFailure)
  14405. {
  14406. String filenames;
  14407. if (userProps != 0 && ! userOk)
  14408. filenames << '\n' << userProps->getFile().getFullPathName();
  14409. if (commonProps != 0 && ! commonOk)
  14410. filenames << '\n' << commonProps->getFile().getFullPathName();
  14411. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14412. appName + TRANS(" - Unable to save settings"),
  14413. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14414. + appName + TRANS(" needs to be able to write to the following files:\n")
  14415. + filenames
  14416. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14417. }
  14418. return false;
  14419. }
  14420. return true;
  14421. }
  14422. void ApplicationProperties::openFiles() throw()
  14423. {
  14424. // You need to call setStorageParameters() before trying to get hold of the
  14425. // properties!
  14426. jassert (appName.isNotEmpty());
  14427. if (appName.isNotEmpty())
  14428. {
  14429. if (userProps == 0)
  14430. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14431. false, msBeforeSaving, options);
  14432. if (commonProps == 0)
  14433. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14434. true, msBeforeSaving, options);
  14435. userProps->setFallbackPropertySet (commonProps);
  14436. }
  14437. }
  14438. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14439. {
  14440. if (userProps == 0)
  14441. openFiles();
  14442. return userProps;
  14443. }
  14444. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14445. {
  14446. if (commonProps == 0)
  14447. openFiles();
  14448. if (returnUserPropsIfReadOnly)
  14449. {
  14450. if (commonSettingsAreReadOnly == 0)
  14451. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14452. if (commonSettingsAreReadOnly > 0)
  14453. return userProps;
  14454. }
  14455. return commonProps;
  14456. }
  14457. bool ApplicationProperties::saveIfNeeded()
  14458. {
  14459. return (userProps == 0 || userProps->saveIfNeeded())
  14460. && (commonProps == 0 || commonProps->saveIfNeeded());
  14461. }
  14462. void ApplicationProperties::closeFiles()
  14463. {
  14464. userProps = 0;
  14465. commonProps = 0;
  14466. }
  14467. END_JUCE_NAMESPACE
  14468. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  14469. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  14470. BEGIN_JUCE_NAMESPACE
  14471. static VoidArray objectsToDelete;
  14472. static CriticalSection lock;
  14473. DeletedAtShutdown::DeletedAtShutdown()
  14474. {
  14475. const ScopedLock sl (lock);
  14476. objectsToDelete.add (this);
  14477. }
  14478. DeletedAtShutdown::~DeletedAtShutdown()
  14479. {
  14480. const ScopedLock sl (lock);
  14481. objectsToDelete.removeValue (this);
  14482. }
  14483. void DeletedAtShutdown::deleteAll()
  14484. {
  14485. // make a local copy of the array, so it can't get into a loop if something
  14486. // creates another DeletedAtShutdown object during its destructor.
  14487. lock.enter();
  14488. const VoidArray localCopy (objectsToDelete);
  14489. lock.exit();
  14490. for (int i = localCopy.size(); --i >= 0;)
  14491. {
  14492. JUCE_TRY
  14493. {
  14494. DeletedAtShutdown* deletee = (DeletedAtShutdown*) localCopy.getUnchecked(i);
  14495. // double-check that it's not already been deleted during another object's destructor.
  14496. {
  14497. const ScopedLock sl (lock);
  14498. if (! objectsToDelete.contains (deletee))
  14499. deletee = 0;
  14500. }
  14501. delete deletee;
  14502. }
  14503. JUCE_CATCH_EXCEPTION
  14504. }
  14505. // if no objects got re-created during shutdown, this should have been emptied by their
  14506. // destructors
  14507. jassert (objectsToDelete.size() == 0);
  14508. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14509. }
  14510. END_JUCE_NAMESPACE
  14511. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14512. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14513. BEGIN_JUCE_NAMESPACE
  14514. static const int propFileMagicNumber = ((int) ByteOrder::littleEndianInt ("PROP"));
  14515. static const int propFileMagicNumberCompressed = ((int) ByteOrder::littleEndianInt ("CPRP"));
  14516. static const tchar* const propertyFileXmlTag = T("PROPERTIES");
  14517. static const tchar* const propertyTagName = T("VALUE");
  14518. PropertiesFile::PropertiesFile (const File& f,
  14519. const int millisecondsBeforeSaving,
  14520. const int options_)
  14521. : PropertySet (ignoreCaseOfKeyNames),
  14522. file (f),
  14523. timerInterval (millisecondsBeforeSaving),
  14524. options (options_),
  14525. needsWriting (false)
  14526. {
  14527. // You need to correctly specify just one storage format for the file
  14528. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14529. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14530. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14531. ScopedPointer <InputStream> fileStream (f.createInputStream());
  14532. if (fileStream != 0)
  14533. {
  14534. int magicNumber = fileStream->readInt();
  14535. if (magicNumber == propFileMagicNumberCompressed)
  14536. {
  14537. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true),
  14538. true);
  14539. magicNumber = propFileMagicNumber;
  14540. }
  14541. if (magicNumber == propFileMagicNumber)
  14542. {
  14543. BufferedInputStream in (fileStream.release(), 2048, true);
  14544. int numValues = in.readInt();
  14545. while (--numValues >= 0 && ! in.isExhausted())
  14546. {
  14547. const String key (in.readString());
  14548. const String value (in.readString());
  14549. jassert (key.isNotEmpty());
  14550. if (key.isNotEmpty())
  14551. getAllProperties().set (key, value);
  14552. }
  14553. }
  14554. else
  14555. {
  14556. // Not a binary props file - let's see if it's XML..
  14557. fileStream = 0;
  14558. XmlDocument parser (f);
  14559. ScopedPointer <XmlElement> doc (parser.getDocumentElement (true));
  14560. if (doc != 0 && doc->hasTagName (propertyFileXmlTag))
  14561. {
  14562. doc = parser.getDocumentElement();
  14563. if (doc != 0)
  14564. {
  14565. forEachXmlChildElementWithTagName (*doc, e, propertyTagName)
  14566. {
  14567. const String name (e->getStringAttribute (T("name")));
  14568. if (name.isNotEmpty())
  14569. {
  14570. getAllProperties().set (name,
  14571. e->getFirstChildElement() != 0
  14572. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14573. : e->getStringAttribute (T("val")));
  14574. }
  14575. }
  14576. }
  14577. else
  14578. {
  14579. // must be a pretty broken XML file we're trying to parse here!
  14580. jassertfalse
  14581. }
  14582. }
  14583. }
  14584. }
  14585. }
  14586. PropertiesFile::~PropertiesFile()
  14587. {
  14588. saveIfNeeded();
  14589. }
  14590. bool PropertiesFile::saveIfNeeded()
  14591. {
  14592. const ScopedLock sl (getLock());
  14593. return (! needsWriting) || save();
  14594. }
  14595. bool PropertiesFile::needsToBeSaved() const
  14596. {
  14597. const ScopedLock sl (getLock());
  14598. return needsWriting;
  14599. }
  14600. bool PropertiesFile::save()
  14601. {
  14602. const ScopedLock sl (getLock());
  14603. stopTimer();
  14604. if (file == File::nonexistent
  14605. || file.isDirectory()
  14606. || ! file.getParentDirectory().createDirectory())
  14607. return false;
  14608. if ((options & storeAsXML) != 0)
  14609. {
  14610. XmlElement doc (propertyFileXmlTag);
  14611. for (int i = 0; i < getAllProperties().size(); ++i)
  14612. {
  14613. XmlElement* const e = doc.createNewChildElement (propertyTagName);
  14614. e->setAttribute (T("name"), getAllProperties().getAllKeys() [i]);
  14615. // if the value seems to contain xml, store it as such..
  14616. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14617. XmlElement* const childElement = xmlContent.getDocumentElement();
  14618. if (childElement != 0)
  14619. e->addChildElement (childElement);
  14620. else
  14621. e->setAttribute (T("val"), getAllProperties().getAllValues() [i]);
  14622. }
  14623. return doc.writeToFile (file, String::empty);
  14624. }
  14625. else
  14626. {
  14627. TemporaryFile tempFile (file);
  14628. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14629. if (out != 0)
  14630. {
  14631. if ((options & storeAsCompressedBinary) != 0)
  14632. {
  14633. out->writeInt (propFileMagicNumberCompressed);
  14634. out->flush();
  14635. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14636. }
  14637. else
  14638. {
  14639. // have you set up the storage option flags correctly?
  14640. jassert ((options & storeAsBinary) != 0);
  14641. out->writeInt (propFileMagicNumber);
  14642. }
  14643. const int numProperties = getAllProperties().size();
  14644. out->writeInt (numProperties);
  14645. for (int i = 0; i < numProperties; ++i)
  14646. {
  14647. out->writeString (getAllProperties().getAllKeys() [i]);
  14648. out->writeString (getAllProperties().getAllValues() [i]);
  14649. }
  14650. out = 0;
  14651. if (tempFile.overwriteTargetFileWithTemporary())
  14652. {
  14653. needsWriting = false;
  14654. return true;
  14655. }
  14656. }
  14657. }
  14658. return false;
  14659. }
  14660. void PropertiesFile::timerCallback()
  14661. {
  14662. saveIfNeeded();
  14663. }
  14664. void PropertiesFile::propertyChanged()
  14665. {
  14666. sendChangeMessage (this);
  14667. needsWriting = true;
  14668. if (timerInterval > 0)
  14669. startTimer (timerInterval);
  14670. else if (timerInterval == 0)
  14671. saveIfNeeded();
  14672. }
  14673. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14674. const String& fileNameSuffix,
  14675. const String& folderName,
  14676. const bool commonToAllUsers)
  14677. {
  14678. // mustn't have illegal characters in this name..
  14679. jassert (applicationName == File::createLegalFileName (applicationName));
  14680. #if JUCE_MAC || JUCE_IPHONE
  14681. File dir (commonToAllUsers ? "/Library/Preferences"
  14682. : "~/Library/Preferences");
  14683. if (folderName.isNotEmpty())
  14684. dir = dir.getChildFile (folderName);
  14685. #endif
  14686. #ifdef JUCE_LINUX
  14687. const File dir ((commonToAllUsers ? T("/var/") : T("~/"))
  14688. + (folderName.isNotEmpty() ? folderName
  14689. : (T(".") + applicationName)));
  14690. #endif
  14691. #if JUCE_WIN32
  14692. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14693. : File::userApplicationDataDirectory));
  14694. if (dir == File::nonexistent)
  14695. return File::nonexistent;
  14696. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14697. : applicationName);
  14698. #endif
  14699. return dir.getChildFile (applicationName)
  14700. .withFileExtension (fileNameSuffix);
  14701. }
  14702. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14703. const String& fileNameSuffix,
  14704. const String& folderName,
  14705. const bool commonToAllUsers,
  14706. const int millisecondsBeforeSaving,
  14707. const int propertiesFileOptions)
  14708. {
  14709. const File file (getDefaultAppSettingsFile (applicationName,
  14710. fileNameSuffix,
  14711. folderName,
  14712. commonToAllUsers));
  14713. jassert (file != File::nonexistent);
  14714. if (file == File::nonexistent)
  14715. return 0;
  14716. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions);
  14717. }
  14718. END_JUCE_NAMESPACE
  14719. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14720. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14721. BEGIN_JUCE_NAMESPACE
  14722. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14723. const String& fileWildcard_,
  14724. const String& openFileDialogTitle_,
  14725. const String& saveFileDialogTitle_)
  14726. : changedSinceSave (false),
  14727. fileExtension (fileExtension_),
  14728. fileWildcard (fileWildcard_),
  14729. openFileDialogTitle (openFileDialogTitle_),
  14730. saveFileDialogTitle (saveFileDialogTitle_)
  14731. {
  14732. }
  14733. FileBasedDocument::~FileBasedDocument()
  14734. {
  14735. }
  14736. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14737. {
  14738. changedSinceSave = hasChanged;
  14739. }
  14740. void FileBasedDocument::changed()
  14741. {
  14742. changedSinceSave = true;
  14743. sendChangeMessage (this);
  14744. }
  14745. void FileBasedDocument::setFile (const File& newFile)
  14746. {
  14747. if (documentFile != newFile)
  14748. {
  14749. documentFile = newFile;
  14750. changedSinceSave = true;
  14751. }
  14752. }
  14753. bool FileBasedDocument::loadFrom (const File& newFile,
  14754. const bool showMessageOnFailure)
  14755. {
  14756. MouseCursor::showWaitCursor();
  14757. const File oldFile (documentFile);
  14758. documentFile = newFile;
  14759. String error;
  14760. if (newFile.existsAsFile())
  14761. {
  14762. error = loadDocument (newFile);
  14763. if (error.isEmpty())
  14764. {
  14765. setChangedFlag (false);
  14766. MouseCursor::hideWaitCursor();
  14767. setLastDocumentOpened (newFile);
  14768. return true;
  14769. }
  14770. }
  14771. else
  14772. {
  14773. error = "The file doesn't exist";
  14774. }
  14775. documentFile = oldFile;
  14776. MouseCursor::hideWaitCursor();
  14777. if (showMessageOnFailure)
  14778. {
  14779. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14780. TRANS("Failed to open file..."),
  14781. TRANS("There was an error while trying to load the file:\n\n")
  14782. + newFile.getFullPathName()
  14783. + T("\n\n")
  14784. + error);
  14785. }
  14786. return false;
  14787. }
  14788. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14789. {
  14790. FileChooser fc (openFileDialogTitle,
  14791. getLastDocumentOpened(),
  14792. fileWildcard);
  14793. if (fc.browseForFileToOpen())
  14794. return loadFrom (fc.getResult(), showMessageOnFailure);
  14795. return false;
  14796. }
  14797. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14798. const bool showMessageOnFailure)
  14799. {
  14800. return saveAs (documentFile,
  14801. false,
  14802. askUserForFileIfNotSpecified,
  14803. showMessageOnFailure);
  14804. }
  14805. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14806. const bool warnAboutOverwritingExistingFiles,
  14807. const bool askUserForFileIfNotSpecified,
  14808. const bool showMessageOnFailure)
  14809. {
  14810. if (newFile == File::nonexistent)
  14811. {
  14812. if (askUserForFileIfNotSpecified)
  14813. {
  14814. return saveAsInteractive (true);
  14815. }
  14816. else
  14817. {
  14818. // can't save to an unspecified file
  14819. jassertfalse
  14820. return failedToWriteToFile;
  14821. }
  14822. }
  14823. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14824. {
  14825. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14826. TRANS("File already exists"),
  14827. TRANS("There's already a file called:\n\n")
  14828. + newFile.getFullPathName()
  14829. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14830. TRANS("overwrite"),
  14831. TRANS("cancel")))
  14832. {
  14833. return userCancelledSave;
  14834. }
  14835. }
  14836. MouseCursor::showWaitCursor();
  14837. const File oldFile (documentFile);
  14838. documentFile = newFile;
  14839. String error (saveDocument (newFile));
  14840. if (error.isEmpty())
  14841. {
  14842. setChangedFlag (false);
  14843. MouseCursor::hideWaitCursor();
  14844. return savedOk;
  14845. }
  14846. documentFile = oldFile;
  14847. MouseCursor::hideWaitCursor();
  14848. if (showMessageOnFailure)
  14849. {
  14850. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14851. TRANS("Error writing to file..."),
  14852. TRANS("An error occurred while trying to save \"")
  14853. + getDocumentTitle()
  14854. + TRANS("\" to the file:\n\n")
  14855. + newFile.getFullPathName()
  14856. + T("\n\n")
  14857. + error);
  14858. }
  14859. return failedToWriteToFile;
  14860. }
  14861. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14862. {
  14863. if (! hasChangedSinceSaved())
  14864. return savedOk;
  14865. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14866. TRANS("Closing document..."),
  14867. TRANS("Do you want to save the changes to \"")
  14868. + getDocumentTitle() + T("\"?"),
  14869. TRANS("save"),
  14870. TRANS("discard changes"),
  14871. TRANS("cancel"));
  14872. if (r == 1)
  14873. {
  14874. // save changes
  14875. return save (true, true);
  14876. }
  14877. else if (r == 2)
  14878. {
  14879. // discard changes
  14880. return savedOk;
  14881. }
  14882. return userCancelledSave;
  14883. }
  14884. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14885. {
  14886. File f;
  14887. if (documentFile.existsAsFile())
  14888. f = documentFile;
  14889. else
  14890. f = getLastDocumentOpened();
  14891. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14892. if (legalFilename.isEmpty())
  14893. legalFilename = "unnamed";
  14894. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14895. f = f.getSiblingFile (legalFilename);
  14896. else
  14897. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14898. f = f.withFileExtension (fileExtension)
  14899. .getNonexistentSibling (true);
  14900. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14901. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14902. {
  14903. setLastDocumentOpened (fc.getResult());
  14904. File chosen (fc.getResult());
  14905. if (chosen.getFileExtension().isEmpty())
  14906. {
  14907. chosen = chosen.withFileExtension (fileExtension);
  14908. if (chosen.exists())
  14909. {
  14910. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14911. TRANS("File already exists"),
  14912. TRANS("There's already a file called:\n\n")
  14913. + chosen.getFullPathName()
  14914. + T("\n\nAre you sure you want to overwrite it?"),
  14915. TRANS("overwrite"),
  14916. TRANS("cancel")))
  14917. {
  14918. return userCancelledSave;
  14919. }
  14920. }
  14921. }
  14922. return saveAs (chosen, false, false, true);
  14923. }
  14924. return userCancelledSave;
  14925. }
  14926. END_JUCE_NAMESPACE
  14927. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14928. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14929. BEGIN_JUCE_NAMESPACE
  14930. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14931. : maxNumberOfItems (10)
  14932. {
  14933. }
  14934. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14935. {
  14936. }
  14937. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14938. {
  14939. maxNumberOfItems = jmax (1, newMaxNumber);
  14940. while (getNumFiles() > maxNumberOfItems)
  14941. files.remove (getNumFiles() - 1);
  14942. }
  14943. int RecentlyOpenedFilesList::getNumFiles() const
  14944. {
  14945. return files.size();
  14946. }
  14947. const File RecentlyOpenedFilesList::getFile (const int index) const
  14948. {
  14949. return File (files [index]);
  14950. }
  14951. void RecentlyOpenedFilesList::clear()
  14952. {
  14953. files.clear();
  14954. }
  14955. void RecentlyOpenedFilesList::addFile (const File& file)
  14956. {
  14957. const String path (file.getFullPathName());
  14958. files.removeString (path, true);
  14959. files.insert (0, path);
  14960. setMaxNumberOfItems (maxNumberOfItems);
  14961. }
  14962. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14963. {
  14964. for (int i = getNumFiles(); --i >= 0;)
  14965. if (! getFile(i).exists())
  14966. files.remove (i);
  14967. }
  14968. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14969. const int baseItemId,
  14970. const bool showFullPaths,
  14971. const bool dontAddNonExistentFiles,
  14972. const File** filesToAvoid)
  14973. {
  14974. int num = 0;
  14975. for (int i = 0; i < getNumFiles(); ++i)
  14976. {
  14977. const File f (getFile(i));
  14978. if ((! dontAddNonExistentFiles) || f.exists())
  14979. {
  14980. bool needsAvoiding = false;
  14981. if (filesToAvoid != 0)
  14982. {
  14983. const File** avoid = filesToAvoid;
  14984. while (*avoid != 0)
  14985. {
  14986. if (f == **avoid)
  14987. {
  14988. needsAvoiding = true;
  14989. break;
  14990. }
  14991. ++avoid;
  14992. }
  14993. }
  14994. if (! needsAvoiding)
  14995. {
  14996. menuToAddTo.addItem (baseItemId + i,
  14997. showFullPaths ? f.getFullPathName()
  14998. : f.getFileName());
  14999. ++num;
  15000. }
  15001. }
  15002. }
  15003. return num;
  15004. }
  15005. const String RecentlyOpenedFilesList::toString() const
  15006. {
  15007. return files.joinIntoString (T("\n"));
  15008. }
  15009. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  15010. {
  15011. clear();
  15012. files.addLines (stringifiedVersion);
  15013. setMaxNumberOfItems (maxNumberOfItems);
  15014. }
  15015. END_JUCE_NAMESPACE
  15016. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  15017. /*** Start of inlined file: juce_UndoManager.cpp ***/
  15018. BEGIN_JUCE_NAMESPACE
  15019. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  15020. const int minimumTransactions)
  15021. : totalUnitsStored (0),
  15022. nextIndex (0),
  15023. newTransaction (true),
  15024. reentrancyCheck (false)
  15025. {
  15026. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  15027. minimumTransactions);
  15028. }
  15029. UndoManager::~UndoManager()
  15030. {
  15031. clearUndoHistory();
  15032. }
  15033. void UndoManager::clearUndoHistory()
  15034. {
  15035. transactions.clear();
  15036. transactionNames.clear();
  15037. totalUnitsStored = 0;
  15038. nextIndex = 0;
  15039. sendChangeMessage (this);
  15040. }
  15041. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  15042. {
  15043. return totalUnitsStored;
  15044. }
  15045. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  15046. const int minimumTransactions)
  15047. {
  15048. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  15049. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  15050. }
  15051. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  15052. {
  15053. if (command != 0)
  15054. {
  15055. if (actionName.isNotEmpty())
  15056. currentTransactionName = actionName;
  15057. if (reentrancyCheck)
  15058. {
  15059. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  15060. // undo() methods, or else these actions won't actually get done.
  15061. return false;
  15062. }
  15063. else
  15064. {
  15065. bool success = false;
  15066. JUCE_TRY
  15067. {
  15068. success = command->perform();
  15069. }
  15070. JUCE_CATCH_EXCEPTION
  15071. jassert (success);
  15072. if (success)
  15073. {
  15074. if (nextIndex > 0 && ! newTransaction)
  15075. {
  15076. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  15077. jassert (commandSet != 0);
  15078. if (commandSet == 0)
  15079. return false;
  15080. commandSet->add (command);
  15081. }
  15082. else
  15083. {
  15084. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  15085. commandSet->add (command);
  15086. transactions.insert (nextIndex, commandSet);
  15087. transactionNames.insert (nextIndex, currentTransactionName);
  15088. ++nextIndex;
  15089. }
  15090. totalUnitsStored += command->getSizeInUnits();
  15091. newTransaction = false;
  15092. }
  15093. while (nextIndex < transactions.size())
  15094. {
  15095. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  15096. for (int i = lastSet->size(); --i >= 0;)
  15097. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  15098. transactions.removeLast();
  15099. transactionNames.remove (transactionNames.size() - 1);
  15100. }
  15101. while (nextIndex > 0
  15102. && totalUnitsStored > maxNumUnitsToKeep
  15103. && transactions.size() > minimumTransactionsToKeep)
  15104. {
  15105. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  15106. for (int i = firstSet->size(); --i >= 0;)
  15107. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  15108. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  15109. transactions.remove (0);
  15110. transactionNames.remove (0);
  15111. --nextIndex;
  15112. }
  15113. sendChangeMessage (this);
  15114. return success;
  15115. }
  15116. }
  15117. return false;
  15118. }
  15119. void UndoManager::beginNewTransaction (const String& actionName)
  15120. {
  15121. newTransaction = true;
  15122. currentTransactionName = actionName;
  15123. }
  15124. void UndoManager::setCurrentTransactionName (const String& newName)
  15125. {
  15126. currentTransactionName = newName;
  15127. }
  15128. bool UndoManager::canUndo() const
  15129. {
  15130. return nextIndex > 0;
  15131. }
  15132. bool UndoManager::canRedo() const
  15133. {
  15134. return nextIndex < transactions.size();
  15135. }
  15136. const String UndoManager::getUndoDescription() const
  15137. {
  15138. return transactionNames [nextIndex - 1];
  15139. }
  15140. const String UndoManager::getRedoDescription() const
  15141. {
  15142. return transactionNames [nextIndex];
  15143. }
  15144. bool UndoManager::undo()
  15145. {
  15146. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15147. if (commandSet == 0)
  15148. return false;
  15149. reentrancyCheck = true;
  15150. bool failed = false;
  15151. for (int i = commandSet->size(); --i >= 0;)
  15152. {
  15153. if (! commandSet->getUnchecked(i)->undo())
  15154. {
  15155. jassertfalse
  15156. failed = true;
  15157. break;
  15158. }
  15159. }
  15160. reentrancyCheck = false;
  15161. if (failed)
  15162. {
  15163. clearUndoHistory();
  15164. }
  15165. else
  15166. {
  15167. --nextIndex;
  15168. }
  15169. beginNewTransaction();
  15170. sendChangeMessage (this);
  15171. return true;
  15172. }
  15173. bool UndoManager::redo()
  15174. {
  15175. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  15176. if (commandSet == 0)
  15177. return false;
  15178. reentrancyCheck = true;
  15179. bool failed = false;
  15180. for (int i = 0; i < commandSet->size(); ++i)
  15181. {
  15182. if (! commandSet->getUnchecked(i)->perform())
  15183. {
  15184. jassertfalse
  15185. failed = true;
  15186. break;
  15187. }
  15188. }
  15189. reentrancyCheck = false;
  15190. if (failed)
  15191. {
  15192. clearUndoHistory();
  15193. }
  15194. else
  15195. {
  15196. ++nextIndex;
  15197. }
  15198. beginNewTransaction();
  15199. sendChangeMessage (this);
  15200. return true;
  15201. }
  15202. bool UndoManager::undoCurrentTransactionOnly()
  15203. {
  15204. return newTransaction ? false
  15205. : undo();
  15206. }
  15207. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  15208. {
  15209. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15210. if (commandSet != 0 && ! newTransaction)
  15211. {
  15212. for (int i = 0; i < commandSet->size(); ++i)
  15213. actionsFound.add (commandSet->getUnchecked(i));
  15214. }
  15215. }
  15216. int UndoManager::getNumActionsInCurrentTransaction() const
  15217. {
  15218. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15219. if (commandSet != 0 && ! newTransaction)
  15220. return commandSet->size();
  15221. return 0;
  15222. }
  15223. END_JUCE_NAMESPACE
  15224. /*** End of inlined file: juce_UndoManager.cpp ***/
  15225. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  15226. BEGIN_JUCE_NAMESPACE
  15227. static const char* const aiffFormatName = "AIFF file";
  15228. static const tchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  15229. class AiffAudioFormatReader : public AudioFormatReader
  15230. {
  15231. public:
  15232. int bytesPerFrame;
  15233. int64 dataChunkStart;
  15234. bool littleEndian;
  15235. AiffAudioFormatReader (InputStream* in)
  15236. : AudioFormatReader (in, TRANS (aiffFormatName))
  15237. {
  15238. if (input->readInt() == chunkName ("FORM"))
  15239. {
  15240. const int len = input->readIntBigEndian();
  15241. const int64 end = input->getPosition() + len;
  15242. const int nextType = input->readInt();
  15243. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  15244. {
  15245. bool hasGotVer = false;
  15246. bool hasGotData = false;
  15247. bool hasGotType = false;
  15248. while (input->getPosition() < end)
  15249. {
  15250. const int type = input->readInt();
  15251. const uint32 length = (uint32) input->readIntBigEndian();
  15252. const int64 chunkEnd = input->getPosition() + length;
  15253. if (type == chunkName ("FVER"))
  15254. {
  15255. hasGotVer = true;
  15256. const int ver = input->readIntBigEndian();
  15257. if (ver != 0 && ver != (int)0xa2805140)
  15258. break;
  15259. }
  15260. else if (type == chunkName ("COMM"))
  15261. {
  15262. hasGotType = true;
  15263. numChannels = (unsigned int)input->readShortBigEndian();
  15264. lengthInSamples = input->readIntBigEndian();
  15265. bitsPerSample = input->readShortBigEndian();
  15266. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  15267. unsigned char sampleRateBytes[10];
  15268. input->read (sampleRateBytes, 10);
  15269. const int byte0 = sampleRateBytes[0];
  15270. if ((byte0 & 0x80) != 0
  15271. || byte0 <= 0x3F || byte0 > 0x40
  15272. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  15273. break;
  15274. unsigned int sampRate = ByteOrder::bigEndianInt ((char*) sampleRateBytes + 2);
  15275. sampRate >>= (16414 - ByteOrder::bigEndianShort ((char*) sampleRateBytes));
  15276. sampleRate = (int) sampRate;
  15277. if (length <= 18)
  15278. {
  15279. // some types don't have a chunk large enough to include a compression
  15280. // type, so assume it's just big-endian pcm
  15281. littleEndian = false;
  15282. }
  15283. else
  15284. {
  15285. const int compType = input->readInt();
  15286. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  15287. {
  15288. littleEndian = false;
  15289. }
  15290. else if (compType == chunkName ("sowt"))
  15291. {
  15292. littleEndian = true;
  15293. }
  15294. else
  15295. {
  15296. sampleRate = 0;
  15297. break;
  15298. }
  15299. }
  15300. }
  15301. else if (type == chunkName ("SSND"))
  15302. {
  15303. hasGotData = true;
  15304. const int offset = input->readIntBigEndian();
  15305. dataChunkStart = input->getPosition() + 4 + offset;
  15306. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  15307. }
  15308. else if ((hasGotVer && hasGotData && hasGotType)
  15309. || chunkEnd < input->getPosition()
  15310. || input->isExhausted())
  15311. {
  15312. break;
  15313. }
  15314. input->setPosition (chunkEnd);
  15315. }
  15316. }
  15317. }
  15318. }
  15319. ~AiffAudioFormatReader()
  15320. {
  15321. }
  15322. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15323. int64 startSampleInFile, int numSamples)
  15324. {
  15325. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  15326. if (samplesAvailable < numSamples)
  15327. {
  15328. for (int i = numDestChannels; --i >= 0;)
  15329. if (destSamples[i] != 0)
  15330. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  15331. numSamples = (int) samplesAvailable;
  15332. }
  15333. if (numSamples <= 0)
  15334. return true;
  15335. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  15336. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  15337. char tempBuffer [tempBufSize];
  15338. while (numSamples > 0)
  15339. {
  15340. int* left = destSamples[0];
  15341. if (left != 0)
  15342. left += startOffsetInDestBuffer;
  15343. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  15344. if (right != 0)
  15345. right += startOffsetInDestBuffer;
  15346. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  15347. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  15348. if (bytesRead < numThisTime * bytesPerFrame)
  15349. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  15350. if (bitsPerSample == 16)
  15351. {
  15352. if (littleEndian)
  15353. {
  15354. const short* src = (const short*) tempBuffer;
  15355. if (numChannels > 1)
  15356. {
  15357. if (left == 0)
  15358. {
  15359. for (int i = numThisTime; --i >= 0;)
  15360. {
  15361. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15362. ++src;
  15363. }
  15364. }
  15365. else if (right == 0)
  15366. {
  15367. for (int i = numThisTime; --i >= 0;)
  15368. {
  15369. ++src;
  15370. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15371. }
  15372. }
  15373. else
  15374. {
  15375. for (int i = numThisTime; --i >= 0;)
  15376. {
  15377. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15378. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15379. }
  15380. }
  15381. }
  15382. else
  15383. {
  15384. for (int i = numThisTime; --i >= 0;)
  15385. {
  15386. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15387. }
  15388. }
  15389. }
  15390. else
  15391. {
  15392. const char* src = (const char*) tempBuffer;
  15393. if (numChannels > 1)
  15394. {
  15395. if (left == 0)
  15396. {
  15397. for (int i = numThisTime; --i >= 0;)
  15398. {
  15399. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15400. src += 4;
  15401. }
  15402. }
  15403. else if (right == 0)
  15404. {
  15405. for (int i = numThisTime; --i >= 0;)
  15406. {
  15407. src += 2;
  15408. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15409. src += 2;
  15410. }
  15411. }
  15412. else
  15413. {
  15414. for (int i = numThisTime; --i >= 0;)
  15415. {
  15416. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15417. src += 2;
  15418. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15419. src += 2;
  15420. }
  15421. }
  15422. }
  15423. else
  15424. {
  15425. for (int i = numThisTime; --i >= 0;)
  15426. {
  15427. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15428. src += 2;
  15429. }
  15430. }
  15431. }
  15432. }
  15433. else if (bitsPerSample == 24)
  15434. {
  15435. const char* src = (const char*)tempBuffer;
  15436. if (littleEndian)
  15437. {
  15438. if (numChannels > 1)
  15439. {
  15440. if (left == 0)
  15441. {
  15442. for (int i = numThisTime; --i >= 0;)
  15443. {
  15444. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15445. src += 6;
  15446. }
  15447. }
  15448. else if (right == 0)
  15449. {
  15450. for (int i = numThisTime; --i >= 0;)
  15451. {
  15452. src += 3;
  15453. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15454. src += 3;
  15455. }
  15456. }
  15457. else
  15458. {
  15459. for (int i = numThisTime; --i >= 0;)
  15460. {
  15461. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15462. src += 3;
  15463. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15464. src += 3;
  15465. }
  15466. }
  15467. }
  15468. else
  15469. {
  15470. for (int i = numThisTime; --i >= 0;)
  15471. {
  15472. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15473. src += 3;
  15474. }
  15475. }
  15476. }
  15477. else
  15478. {
  15479. if (numChannels > 1)
  15480. {
  15481. if (left == 0)
  15482. {
  15483. for (int i = numThisTime; --i >= 0;)
  15484. {
  15485. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15486. src += 6;
  15487. }
  15488. }
  15489. else if (right == 0)
  15490. {
  15491. for (int i = numThisTime; --i >= 0;)
  15492. {
  15493. src += 3;
  15494. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15495. src += 3;
  15496. }
  15497. }
  15498. else
  15499. {
  15500. for (int i = numThisTime; --i >= 0;)
  15501. {
  15502. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15503. src += 3;
  15504. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15505. src += 3;
  15506. }
  15507. }
  15508. }
  15509. else
  15510. {
  15511. for (int i = numThisTime; --i >= 0;)
  15512. {
  15513. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15514. src += 3;
  15515. }
  15516. }
  15517. }
  15518. }
  15519. else if (bitsPerSample == 32)
  15520. {
  15521. const unsigned int* src = (const unsigned int*) tempBuffer;
  15522. unsigned int* l = (unsigned int*) left;
  15523. unsigned int* r = (unsigned int*) right;
  15524. if (littleEndian)
  15525. {
  15526. if (numChannels > 1)
  15527. {
  15528. if (l == 0)
  15529. {
  15530. for (int i = numThisTime; --i >= 0;)
  15531. {
  15532. ++src;
  15533. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15534. }
  15535. }
  15536. else if (r == 0)
  15537. {
  15538. for (int i = numThisTime; --i >= 0;)
  15539. {
  15540. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15541. ++src;
  15542. }
  15543. }
  15544. else
  15545. {
  15546. for (int i = numThisTime; --i >= 0;)
  15547. {
  15548. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15549. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15550. }
  15551. }
  15552. }
  15553. else
  15554. {
  15555. for (int i = numThisTime; --i >= 0;)
  15556. {
  15557. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15558. }
  15559. }
  15560. }
  15561. else
  15562. {
  15563. if (numChannels > 1)
  15564. {
  15565. if (l == 0)
  15566. {
  15567. for (int i = numThisTime; --i >= 0;)
  15568. {
  15569. ++src;
  15570. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15571. }
  15572. }
  15573. else if (r == 0)
  15574. {
  15575. for (int i = numThisTime; --i >= 0;)
  15576. {
  15577. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15578. ++src;
  15579. }
  15580. }
  15581. else
  15582. {
  15583. for (int i = numThisTime; --i >= 0;)
  15584. {
  15585. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15586. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15587. }
  15588. }
  15589. }
  15590. else
  15591. {
  15592. for (int i = numThisTime; --i >= 0;)
  15593. {
  15594. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15595. }
  15596. }
  15597. }
  15598. left = (int*) l;
  15599. right = (int*) r;
  15600. }
  15601. else if (bitsPerSample == 8)
  15602. {
  15603. const char* src = (const char*) tempBuffer;
  15604. if (numChannels > 1)
  15605. {
  15606. if (left == 0)
  15607. {
  15608. for (int i = numThisTime; --i >= 0;)
  15609. {
  15610. *right++ = ((int) *src++) << 24;
  15611. ++src;
  15612. }
  15613. }
  15614. else if (right == 0)
  15615. {
  15616. for (int i = numThisTime; --i >= 0;)
  15617. {
  15618. ++src;
  15619. *left++ = ((int) *src++) << 24;
  15620. }
  15621. }
  15622. else
  15623. {
  15624. for (int i = numThisTime; --i >= 0;)
  15625. {
  15626. *left++ = ((int) *src++) << 24;
  15627. *right++ = ((int) *src++) << 24;
  15628. }
  15629. }
  15630. }
  15631. else
  15632. {
  15633. for (int i = numThisTime; --i >= 0;)
  15634. {
  15635. *left++ = ((int) *src++) << 24;
  15636. }
  15637. }
  15638. }
  15639. startOffsetInDestBuffer += numThisTime;
  15640. numSamples -= numThisTime;
  15641. }
  15642. if (numSamples > 0)
  15643. {
  15644. for (int i = numDestChannels; --i >= 0;)
  15645. if (destSamples[i] != 0)
  15646. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15647. sizeof (int) * numSamples);
  15648. }
  15649. return true;
  15650. }
  15651. juce_UseDebuggingNewOperator
  15652. private:
  15653. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15654. const AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15655. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15656. };
  15657. class AiffAudioFormatWriter : public AudioFormatWriter
  15658. {
  15659. MemoryBlock tempBlock;
  15660. uint32 lengthInSamples, bytesWritten;
  15661. int64 headerPosition;
  15662. bool writeFailed;
  15663. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15664. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15665. const AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15666. void writeHeader()
  15667. {
  15668. const bool couldSeekOk = output->setPosition (headerPosition);
  15669. (void) couldSeekOk;
  15670. // if this fails, you've given it an output stream that can't seek! It needs
  15671. // to be able to seek back to write the header
  15672. jassert (couldSeekOk);
  15673. const int headerLen = 54;
  15674. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15675. audioBytes += (audioBytes & 1);
  15676. output->writeInt (chunkName ("FORM"));
  15677. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15678. output->writeInt (chunkName ("AIFF"));
  15679. output->writeInt (chunkName ("COMM"));
  15680. output->writeIntBigEndian (18);
  15681. output->writeShortBigEndian ((short) numChannels);
  15682. output->writeIntBigEndian (lengthInSamples);
  15683. output->writeShortBigEndian ((short) bitsPerSample);
  15684. uint8 sampleRateBytes[10];
  15685. zeromem (sampleRateBytes, 10);
  15686. if (sampleRate <= 1)
  15687. {
  15688. sampleRateBytes[0] = 0x3f;
  15689. sampleRateBytes[1] = 0xff;
  15690. sampleRateBytes[2] = 0x80;
  15691. }
  15692. else
  15693. {
  15694. int mask = 0x40000000;
  15695. sampleRateBytes[0] = 0x40;
  15696. if (sampleRate >= mask)
  15697. {
  15698. jassertfalse
  15699. sampleRateBytes[1] = 0x1d;
  15700. }
  15701. else
  15702. {
  15703. int n = (int) sampleRate;
  15704. int i;
  15705. for (i = 0; i <= 32 ; ++i)
  15706. {
  15707. if ((n & mask) != 0)
  15708. break;
  15709. mask >>= 1;
  15710. }
  15711. n = n << (i + 1);
  15712. sampleRateBytes[1] = (uint8) (29 - i);
  15713. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15714. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15715. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15716. sampleRateBytes[5] = (uint8) (n & 0xff);
  15717. }
  15718. }
  15719. output->write (sampleRateBytes, 10);
  15720. output->writeInt (chunkName ("SSND"));
  15721. output->writeIntBigEndian (audioBytes + 8);
  15722. output->writeInt (0);
  15723. output->writeInt (0);
  15724. jassert (output->getPosition() == headerLen);
  15725. }
  15726. public:
  15727. AiffAudioFormatWriter (OutputStream* out,
  15728. const double sampleRate_,
  15729. const unsigned int chans,
  15730. const int bits)
  15731. : AudioFormatWriter (out,
  15732. TRANS (aiffFormatName),
  15733. sampleRate_,
  15734. chans,
  15735. bits),
  15736. lengthInSamples (0),
  15737. bytesWritten (0),
  15738. writeFailed (false)
  15739. {
  15740. headerPosition = out->getPosition();
  15741. writeHeader();
  15742. }
  15743. ~AiffAudioFormatWriter()
  15744. {
  15745. if ((bytesWritten & 1) != 0)
  15746. output->writeByte (0);
  15747. writeHeader();
  15748. }
  15749. bool write (const int** data, int numSamples)
  15750. {
  15751. if (writeFailed)
  15752. return false;
  15753. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15754. tempBlock.ensureSize (bytes, false);
  15755. char* buffer = (char*) tempBlock.getData();
  15756. const int* left = data[0];
  15757. const int* right = data[1];
  15758. if (right == 0)
  15759. right = left;
  15760. if (bitsPerSample == 16)
  15761. {
  15762. short* b = (short*) buffer;
  15763. if (numChannels > 1)
  15764. {
  15765. for (int i = numSamples; --i >= 0;)
  15766. {
  15767. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15768. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15769. }
  15770. }
  15771. else
  15772. {
  15773. for (int i = numSamples; --i >= 0;)
  15774. {
  15775. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15776. }
  15777. }
  15778. }
  15779. else if (bitsPerSample == 24)
  15780. {
  15781. char* b = (char*) buffer;
  15782. if (numChannels > 1)
  15783. {
  15784. for (int i = numSamples; --i >= 0;)
  15785. {
  15786. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15787. b += 3;
  15788. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15789. b += 3;
  15790. }
  15791. }
  15792. else
  15793. {
  15794. for (int i = numSamples; --i >= 0;)
  15795. {
  15796. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15797. b += 3;
  15798. }
  15799. }
  15800. }
  15801. else if (bitsPerSample == 32)
  15802. {
  15803. uint32* b = (uint32*) buffer;
  15804. if (numChannels > 1)
  15805. {
  15806. for (int i = numSamples; --i >= 0;)
  15807. {
  15808. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15809. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15810. }
  15811. }
  15812. else
  15813. {
  15814. for (int i = numSamples; --i >= 0;)
  15815. {
  15816. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15817. }
  15818. }
  15819. }
  15820. else if (bitsPerSample == 8)
  15821. {
  15822. char* b = (char*) buffer;
  15823. if (numChannels > 1)
  15824. {
  15825. for (int i = numSamples; --i >= 0;)
  15826. {
  15827. *b++ = (char) (*left++ >> 24);
  15828. *b++ = (char) (*right++ >> 24);
  15829. }
  15830. }
  15831. else
  15832. {
  15833. for (int i = numSamples; --i >= 0;)
  15834. {
  15835. *b++ = (char) (*left++ >> 24);
  15836. }
  15837. }
  15838. }
  15839. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15840. || ! output->write (buffer, bytes))
  15841. {
  15842. // failed to write to disk, so let's try writing the header.
  15843. // If it's just run out of disk space, then if it does manage
  15844. // to write the header, we'll still have a useable file..
  15845. writeHeader();
  15846. writeFailed = true;
  15847. return false;
  15848. }
  15849. else
  15850. {
  15851. bytesWritten += bytes;
  15852. lengthInSamples += numSamples;
  15853. return true;
  15854. }
  15855. }
  15856. juce_UseDebuggingNewOperator
  15857. };
  15858. AiffAudioFormat::AiffAudioFormat()
  15859. : AudioFormat (TRANS (aiffFormatName), (const tchar**) aiffExtensions)
  15860. {
  15861. }
  15862. AiffAudioFormat::~AiffAudioFormat()
  15863. {
  15864. }
  15865. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15866. {
  15867. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15868. return Array <int> (rates);
  15869. }
  15870. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15871. {
  15872. const int depths[] = { 8, 16, 24, 0 };
  15873. return Array <int> (depths);
  15874. }
  15875. bool AiffAudioFormat::canDoStereo()
  15876. {
  15877. return true;
  15878. }
  15879. bool AiffAudioFormat::canDoMono()
  15880. {
  15881. return true;
  15882. }
  15883. #if JUCE_MAC
  15884. bool AiffAudioFormat::canHandleFile (const File& f)
  15885. {
  15886. if (AudioFormat::canHandleFile (f))
  15887. return true;
  15888. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15889. return type == 'AIFF' || type == 'AIFC'
  15890. || type == 'aiff' || type == 'aifc';
  15891. }
  15892. #endif
  15893. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15894. const bool deleteStreamIfOpeningFails)
  15895. {
  15896. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15897. if (w->sampleRate != 0)
  15898. return w.release();
  15899. if (! deleteStreamIfOpeningFails)
  15900. w->input = 0;
  15901. return 0;
  15902. }
  15903. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15904. double sampleRate,
  15905. unsigned int chans,
  15906. int bitsPerSample,
  15907. const StringPairArray& /*metadataValues*/,
  15908. int /*qualityOptionIndex*/)
  15909. {
  15910. if (getPossibleBitDepths().contains (bitsPerSample))
  15911. {
  15912. return new AiffAudioFormatWriter (out,
  15913. sampleRate,
  15914. chans,
  15915. bitsPerSample);
  15916. }
  15917. return 0;
  15918. }
  15919. END_JUCE_NAMESPACE
  15920. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15921. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15922. BEGIN_JUCE_NAMESPACE
  15923. #if JUCE_MAC && JUCE_USE_CDREADER
  15924. // Mac version doesn't need any native code because it's all done with files..
  15925. // Windows + Linux versions are in the platform-dependent code sections.
  15926. static void findCDs (Array<File>& cds)
  15927. {
  15928. File volumes ("/Volumes");
  15929. volumes.findChildFiles (cds, File::findDirectories, false);
  15930. for (int i = cds.size(); --i >= 0;)
  15931. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15932. cds.remove (i);
  15933. }
  15934. const StringArray AudioCDReader::getAvailableCDNames()
  15935. {
  15936. Array<File> cds;
  15937. findCDs (cds);
  15938. StringArray names;
  15939. for (int i = 0; i < cds.size(); ++i)
  15940. names.add (cds.getReference(i).getFileName());
  15941. return names;
  15942. }
  15943. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15944. {
  15945. Array<File> cds;
  15946. findCDs (cds);
  15947. if (cds[index] != File::nonexistent)
  15948. return new AudioCDReader (cds[index]);
  15949. else
  15950. return 0;
  15951. }
  15952. AudioCDReader::AudioCDReader (const File& volume)
  15953. : AudioFormatReader (0, "CD Audio"),
  15954. volumeDir (volume),
  15955. currentReaderTrack (-1),
  15956. reader (0)
  15957. {
  15958. sampleRate = 44100.0;
  15959. bitsPerSample = 16;
  15960. numChannels = 2;
  15961. usesFloatingPointData = false;
  15962. refreshTrackLengths();
  15963. }
  15964. AudioCDReader::~AudioCDReader()
  15965. {
  15966. }
  15967. static int getTrackNumber (const File& file)
  15968. {
  15969. return file.getFileName()
  15970. .initialSectionContainingOnly (T("0123456789"))
  15971. .getIntValue();
  15972. }
  15973. int AudioCDReader::compareElements (const File& first, const File& second)
  15974. {
  15975. const int firstTrack = getTrackNumber (first);
  15976. const int secondTrack = getTrackNumber (second);
  15977. jassert (firstTrack > 0 && secondTrack > 0);
  15978. return firstTrack - secondTrack;
  15979. }
  15980. void AudioCDReader::refreshTrackLengths()
  15981. {
  15982. tracks.clear();
  15983. trackStartSamples.clear();
  15984. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, T("*.aiff"));
  15985. tracks.sort (*this);
  15986. AiffAudioFormat format;
  15987. int sample = 0;
  15988. for (int i = 0; i < tracks.size(); ++i)
  15989. {
  15990. trackStartSamples.add (sample);
  15991. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15992. if (in != 0)
  15993. {
  15994. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15995. if (r != 0)
  15996. sample += (int) r->lengthInSamples;
  15997. }
  15998. }
  15999. trackStartSamples.add (sample);
  16000. lengthInSamples = sample;
  16001. }
  16002. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16003. int64 startSampleInFile, int numSamples)
  16004. {
  16005. while (numSamples > 0)
  16006. {
  16007. int track = -1;
  16008. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  16009. {
  16010. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  16011. {
  16012. track = i;
  16013. break;
  16014. }
  16015. }
  16016. if (track < 0)
  16017. return false;
  16018. if (track != currentReaderTrack)
  16019. {
  16020. reader = 0;
  16021. FileInputStream* const in = tracks [track].createInputStream();
  16022. if (in != 0)
  16023. {
  16024. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  16025. AiffAudioFormat format;
  16026. reader = format.createReaderFor (bin, true);
  16027. if (reader == 0)
  16028. currentReaderTrack = -1;
  16029. else
  16030. currentReaderTrack = track;
  16031. }
  16032. }
  16033. if (reader == 0)
  16034. return false;
  16035. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  16036. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  16037. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  16038. numSamples -= numAvailable;
  16039. startSampleInFile += numAvailable;
  16040. }
  16041. return true;
  16042. }
  16043. bool AudioCDReader::isCDStillPresent() const
  16044. {
  16045. return volumeDir.exists();
  16046. }
  16047. int AudioCDReader::getNumTracks() const
  16048. {
  16049. return tracks.size();
  16050. }
  16051. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  16052. {
  16053. return trackStartSamples [trackNum];
  16054. }
  16055. bool AudioCDReader::isTrackAudio (int trackNum) const
  16056. {
  16057. return tracks [trackNum] != File::nonexistent;
  16058. }
  16059. void AudioCDReader::enableIndexScanning (bool b)
  16060. {
  16061. // any way to do this on a Mac??
  16062. }
  16063. int AudioCDReader::getLastIndex() const
  16064. {
  16065. return 0;
  16066. }
  16067. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  16068. {
  16069. return Array <int>();
  16070. }
  16071. int AudioCDReader::getCDDBId()
  16072. {
  16073. return 0; //xxx
  16074. }
  16075. #endif
  16076. END_JUCE_NAMESPACE
  16077. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  16078. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  16079. BEGIN_JUCE_NAMESPACE
  16080. AudioFormatReader::AudioFormatReader (InputStream* const in,
  16081. const String& formatName_)
  16082. : sampleRate (0),
  16083. bitsPerSample (0),
  16084. lengthInSamples (0),
  16085. numChannels (0),
  16086. usesFloatingPointData (false),
  16087. input (in),
  16088. formatName (formatName_)
  16089. {
  16090. }
  16091. AudioFormatReader::~AudioFormatReader()
  16092. {
  16093. delete input;
  16094. }
  16095. bool AudioFormatReader::read (int** destSamples,
  16096. int numDestChannels,
  16097. int64 startSampleInSource,
  16098. int numSamplesToRead,
  16099. const bool fillLeftoverChannelsWithCopies)
  16100. {
  16101. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  16102. int startOffsetInDestBuffer = 0;
  16103. if (startSampleInSource < 0)
  16104. {
  16105. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  16106. for (int i = numDestChannels; --i >= 0;)
  16107. if (destSamples[i] != 0)
  16108. zeromem (destSamples[i], sizeof (int) * silence);
  16109. startOffsetInDestBuffer += silence;
  16110. numSamplesToRead -= silence;
  16111. startSampleInSource = 0;
  16112. }
  16113. if (numSamplesToRead <= 0)
  16114. return true;
  16115. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  16116. startSampleInSource, numSamplesToRead))
  16117. return false;
  16118. if (numDestChannels > (int) numChannels)
  16119. {
  16120. if (fillLeftoverChannelsWithCopies)
  16121. {
  16122. int* lastFullChannel = destSamples[0];
  16123. for (int i = numDestChannels; --i > 0;)
  16124. {
  16125. if (destSamples[i] != 0)
  16126. {
  16127. lastFullChannel = destSamples[i];
  16128. break;
  16129. }
  16130. }
  16131. if (lastFullChannel != 0)
  16132. for (int i = numChannels; i < numDestChannels; ++i)
  16133. if (destSamples[i] != 0)
  16134. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  16135. }
  16136. else
  16137. {
  16138. for (int i = numChannels; i < numDestChannels; ++i)
  16139. if (destSamples[i] != 0)
  16140. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  16141. }
  16142. }
  16143. return true;
  16144. }
  16145. static void findMaxMin (const float* src, const int num,
  16146. float& maxVal, float& minVal)
  16147. {
  16148. float mn = src[0];
  16149. float mx = mn;
  16150. for (int i = 1; i < num; ++i)
  16151. {
  16152. const float s = src[i];
  16153. if (s > mx)
  16154. mx = s;
  16155. if (s < mn)
  16156. mn = s;
  16157. }
  16158. maxVal = mx;
  16159. minVal = mn;
  16160. }
  16161. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  16162. int64 numSamples,
  16163. float& lowestLeft, float& highestLeft,
  16164. float& lowestRight, float& highestRight)
  16165. {
  16166. if (numSamples <= 0)
  16167. {
  16168. lowestLeft = 0;
  16169. lowestRight = 0;
  16170. highestLeft = 0;
  16171. highestRight = 0;
  16172. return;
  16173. }
  16174. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  16175. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16176. int* tempBuffer[3];
  16177. tempBuffer[0] = (int*) tempSpace.getData();
  16178. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16179. tempBuffer[2] = 0;
  16180. if (usesFloatingPointData)
  16181. {
  16182. float lmin = 1.0e6f;
  16183. float lmax = -lmin;
  16184. float rmin = lmin;
  16185. float rmax = lmax;
  16186. while (numSamples > 0)
  16187. {
  16188. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16189. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16190. numSamples -= numToDo;
  16191. startSampleInFile += numToDo;
  16192. float bufmin, bufmax;
  16193. findMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  16194. lmin = jmin (lmin, bufmin);
  16195. lmax = jmax (lmax, bufmax);
  16196. if (numChannels > 1)
  16197. {
  16198. findMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  16199. rmin = jmin (rmin, bufmin);
  16200. rmax = jmax (rmax, bufmax);
  16201. }
  16202. }
  16203. if (numChannels <= 1)
  16204. {
  16205. rmax = lmax;
  16206. rmin = lmin;
  16207. }
  16208. lowestLeft = lmin;
  16209. highestLeft = lmax;
  16210. lowestRight = rmin;
  16211. highestRight = rmax;
  16212. }
  16213. else
  16214. {
  16215. int lmax = std::numeric_limits<int>::min();
  16216. int lmin = std::numeric_limits<int>::max();
  16217. int rmax = std::numeric_limits<int>::min();
  16218. int rmin = std::numeric_limits<int>::max();
  16219. while (numSamples > 0)
  16220. {
  16221. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16222. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16223. numSamples -= numToDo;
  16224. startSampleInFile += numToDo;
  16225. for (int j = numChannels; --j >= 0;)
  16226. {
  16227. int bufMax = std::numeric_limits<int>::min();
  16228. int bufMin = std::numeric_limits<int>::max();
  16229. const int* const b = tempBuffer[j];
  16230. for (int i = 0; i < numToDo; ++i)
  16231. {
  16232. const int samp = b[i];
  16233. if (samp < bufMin)
  16234. bufMin = samp;
  16235. if (samp > bufMax)
  16236. bufMax = samp;
  16237. }
  16238. if (j == 0)
  16239. {
  16240. lmax = jmax (lmax, bufMax);
  16241. lmin = jmin (lmin, bufMin);
  16242. }
  16243. else
  16244. {
  16245. rmax = jmax (rmax, bufMax);
  16246. rmin = jmin (rmin, bufMin);
  16247. }
  16248. }
  16249. }
  16250. if (numChannels <= 1)
  16251. {
  16252. rmax = lmax;
  16253. rmin = lmin;
  16254. }
  16255. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  16256. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  16257. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  16258. highestRight = rmax / (float) std::numeric_limits<int>::max();
  16259. }
  16260. }
  16261. int64 AudioFormatReader::searchForLevel (int64 startSample,
  16262. int64 numSamplesToSearch,
  16263. const double magnitudeRangeMinimum,
  16264. const double magnitudeRangeMaximum,
  16265. const int minimumConsecutiveSamples)
  16266. {
  16267. if (numSamplesToSearch == 0)
  16268. return -1;
  16269. const int bufferSize = 4096;
  16270. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16271. int* tempBuffer[3];
  16272. tempBuffer[0] = (int*) tempSpace.getData();
  16273. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16274. tempBuffer[2] = 0;
  16275. int consecutive = 0;
  16276. int64 firstMatchPos = -1;
  16277. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  16278. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  16279. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  16280. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  16281. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  16282. while (numSamplesToSearch != 0)
  16283. {
  16284. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  16285. int64 bufferStart = startSample;
  16286. if (numSamplesToSearch < 0)
  16287. bufferStart -= numThisTime;
  16288. if (bufferStart >= (int) lengthInSamples)
  16289. break;
  16290. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  16291. int num = numThisTime;
  16292. while (--num >= 0)
  16293. {
  16294. if (numSamplesToSearch < 0)
  16295. --startSample;
  16296. bool matches = false;
  16297. const int index = (int) (startSample - bufferStart);
  16298. if (usesFloatingPointData)
  16299. {
  16300. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  16301. if (sample1 >= magnitudeRangeMinimum
  16302. && sample1 <= magnitudeRangeMaximum)
  16303. {
  16304. matches = true;
  16305. }
  16306. else if (numChannels > 1)
  16307. {
  16308. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  16309. matches = (sample2 >= magnitudeRangeMinimum
  16310. && sample2 <= magnitudeRangeMaximum);
  16311. }
  16312. }
  16313. else
  16314. {
  16315. const int sample1 = abs (tempBuffer[0] [index]);
  16316. if (sample1 >= intMagnitudeRangeMinimum
  16317. && sample1 <= intMagnitudeRangeMaximum)
  16318. {
  16319. matches = true;
  16320. }
  16321. else if (numChannels > 1)
  16322. {
  16323. const int sample2 = abs (tempBuffer[1][index]);
  16324. matches = (sample2 >= intMagnitudeRangeMinimum
  16325. && sample2 <= intMagnitudeRangeMaximum);
  16326. }
  16327. }
  16328. if (matches)
  16329. {
  16330. if (firstMatchPos < 0)
  16331. firstMatchPos = startSample;
  16332. if (++consecutive >= minimumConsecutiveSamples)
  16333. {
  16334. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  16335. return -1;
  16336. return firstMatchPos;
  16337. }
  16338. }
  16339. else
  16340. {
  16341. consecutive = 0;
  16342. firstMatchPos = -1;
  16343. }
  16344. if (numSamplesToSearch > 0)
  16345. ++startSample;
  16346. }
  16347. if (numSamplesToSearch > 0)
  16348. numSamplesToSearch -= numThisTime;
  16349. else
  16350. numSamplesToSearch += numThisTime;
  16351. }
  16352. return -1;
  16353. }
  16354. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  16355. const String& formatName_,
  16356. const double rate,
  16357. const unsigned int numChannels_,
  16358. const unsigned int bitsPerSample_)
  16359. : sampleRate (rate),
  16360. numChannels (numChannels_),
  16361. bitsPerSample (bitsPerSample_),
  16362. usesFloatingPointData (false),
  16363. output (out),
  16364. formatName (formatName_)
  16365. {
  16366. }
  16367. AudioFormatWriter::~AudioFormatWriter()
  16368. {
  16369. delete output;
  16370. }
  16371. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16372. int64 startSample,
  16373. int64 numSamplesToRead)
  16374. {
  16375. const int bufferSize = 16384;
  16376. const int maxChans = 128;
  16377. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16378. int* buffers [maxChans];
  16379. for (int i = maxChans; --i >= 0;)
  16380. buffers[i] = 0;
  16381. if (numSamplesToRead < 0)
  16382. numSamplesToRead = reader.lengthInSamples;
  16383. while (numSamplesToRead > 0)
  16384. {
  16385. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16386. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16387. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16388. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16389. return false;
  16390. if (reader.usesFloatingPointData != isFloatingPoint())
  16391. {
  16392. int** bufferChan = buffers;
  16393. while (*bufferChan != 0)
  16394. {
  16395. int* b = *bufferChan++;
  16396. if (isFloatingPoint())
  16397. {
  16398. // int -> float
  16399. const double factor = 1.0 / std::numeric_limits<int>::max();
  16400. for (int i = 0; i < numToDo; ++i)
  16401. ((float*) b)[i] = (float) (factor * b[i]);
  16402. }
  16403. else
  16404. {
  16405. // float -> int
  16406. for (int i = 0; i < numToDo; ++i)
  16407. {
  16408. const double samp = *(const float*) b;
  16409. if (samp <= -1.0)
  16410. *b++ = std::numeric_limits<int>::min();
  16411. else if (samp >= 1.0)
  16412. *b++ = std::numeric_limits<int>::max();
  16413. else
  16414. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16415. }
  16416. }
  16417. }
  16418. }
  16419. if (! write ((const int**) buffers, numToDo))
  16420. return false;
  16421. numSamplesToRead -= numToDo;
  16422. startSample += numToDo;
  16423. }
  16424. return true;
  16425. }
  16426. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16427. int numSamplesToRead,
  16428. const int samplesPerBlock)
  16429. {
  16430. const int maxChans = 128;
  16431. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16432. int* buffers [maxChans];
  16433. while (numSamplesToRead > 0)
  16434. {
  16435. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16436. AudioSourceChannelInfo info;
  16437. info.buffer = &tempBuffer;
  16438. info.startSample = 0;
  16439. info.numSamples = numToDo;
  16440. info.clearActiveBufferRegion();
  16441. source.getNextAudioBlock (info);
  16442. int i;
  16443. for (i = maxChans; --i >= 0;)
  16444. buffers[i] = 0;
  16445. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16446. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16447. if (! isFloatingPoint())
  16448. {
  16449. int** bufferChan = buffers;
  16450. while (*bufferChan != 0)
  16451. {
  16452. int* b = *bufferChan++;
  16453. // float -> int
  16454. for (int j = numToDo; --j >= 0;)
  16455. {
  16456. const double samp = *(const float*) b;
  16457. if (samp <= -1.0)
  16458. *b++ = std::numeric_limits<int>::min();
  16459. else if (samp >= 1.0)
  16460. *b++ = std::numeric_limits<int>::max();
  16461. else
  16462. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16463. }
  16464. }
  16465. }
  16466. if (! write ((const int**) buffers, numToDo))
  16467. return false;
  16468. numSamplesToRead -= numToDo;
  16469. }
  16470. return true;
  16471. }
  16472. AudioFormat::AudioFormat (const String& name,
  16473. const tchar** const extensions)
  16474. : formatName (name),
  16475. fileExtensions (extensions)
  16476. {
  16477. }
  16478. AudioFormat::~AudioFormat()
  16479. {
  16480. }
  16481. const String& AudioFormat::getFormatName() const
  16482. {
  16483. return formatName;
  16484. }
  16485. const StringArray& AudioFormat::getFileExtensions() const
  16486. {
  16487. return fileExtensions;
  16488. }
  16489. bool AudioFormat::canHandleFile (const File& f)
  16490. {
  16491. for (int i = 0; i < fileExtensions.size(); ++i)
  16492. if (f.hasFileExtension (fileExtensions[i]))
  16493. return true;
  16494. return false;
  16495. }
  16496. bool AudioFormat::isCompressed()
  16497. {
  16498. return false;
  16499. }
  16500. const StringArray AudioFormat::getQualityOptions()
  16501. {
  16502. return StringArray();
  16503. }
  16504. END_JUCE_NAMESPACE
  16505. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16506. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16507. BEGIN_JUCE_NAMESPACE
  16508. AudioFormatManager::AudioFormatManager()
  16509. : defaultFormatIndex (0)
  16510. {
  16511. }
  16512. AudioFormatManager::~AudioFormatManager()
  16513. {
  16514. clearFormats();
  16515. clearSingletonInstance();
  16516. }
  16517. juce_ImplementSingleton (AudioFormatManager);
  16518. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16519. const bool makeThisTheDefaultFormat)
  16520. {
  16521. jassert (newFormat != 0);
  16522. if (newFormat != 0)
  16523. {
  16524. #ifdef JUCE_DEBUG
  16525. for (int i = getNumKnownFormats(); --i >= 0;)
  16526. {
  16527. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16528. {
  16529. jassertfalse // trying to add the same format twice!
  16530. }
  16531. }
  16532. #endif
  16533. if (makeThisTheDefaultFormat)
  16534. defaultFormatIndex = knownFormats.size();
  16535. knownFormats.add (newFormat);
  16536. }
  16537. }
  16538. void AudioFormatManager::registerBasicFormats()
  16539. {
  16540. #if JUCE_MAC
  16541. registerFormat (new AiffAudioFormat(), true);
  16542. registerFormat (new WavAudioFormat(), false);
  16543. #else
  16544. registerFormat (new WavAudioFormat(), true);
  16545. registerFormat (new AiffAudioFormat(), false);
  16546. #endif
  16547. #if JUCE_USE_FLAC
  16548. registerFormat (new FlacAudioFormat(), false);
  16549. #endif
  16550. #if JUCE_USE_OGGVORBIS
  16551. registerFormat (new OggVorbisAudioFormat(), false);
  16552. #endif
  16553. }
  16554. void AudioFormatManager::clearFormats()
  16555. {
  16556. for (int i = getNumKnownFormats(); --i >= 0;)
  16557. delete getKnownFormat(i);
  16558. knownFormats.clear();
  16559. defaultFormatIndex = 0;
  16560. }
  16561. int AudioFormatManager::getNumKnownFormats() const
  16562. {
  16563. return knownFormats.size();
  16564. }
  16565. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16566. {
  16567. return (AudioFormat*) knownFormats [index];
  16568. }
  16569. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16570. {
  16571. return getKnownFormat (defaultFormatIndex);
  16572. }
  16573. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16574. {
  16575. String e (fileExtension);
  16576. if (! e.startsWithChar (T('.')))
  16577. e = T(".") + e;
  16578. for (int i = 0; i < getNumKnownFormats(); ++i)
  16579. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16580. return getKnownFormat(i);
  16581. return 0;
  16582. }
  16583. const String AudioFormatManager::getWildcardForAllFormats() const
  16584. {
  16585. StringArray allExtensions;
  16586. int i;
  16587. for (i = 0; i < getNumKnownFormats(); ++i)
  16588. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16589. allExtensions.trim();
  16590. allExtensions.removeEmptyStrings();
  16591. String s;
  16592. for (i = 0; i < allExtensions.size(); ++i)
  16593. {
  16594. s << T('*');
  16595. if (! allExtensions[i].startsWithChar (T('.')))
  16596. s << T('.');
  16597. s << allExtensions[i];
  16598. if (i < allExtensions.size() - 1)
  16599. s << T(';');
  16600. }
  16601. return s;
  16602. }
  16603. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16604. {
  16605. // you need to actually register some formats before the manager can
  16606. // use them to open a file!
  16607. jassert (knownFormats.size() > 0);
  16608. for (int i = 0; i < getNumKnownFormats(); ++i)
  16609. {
  16610. AudioFormat* const af = getKnownFormat(i);
  16611. if (af->canHandleFile (file))
  16612. {
  16613. InputStream* const in = file.createInputStream();
  16614. if (in != 0)
  16615. {
  16616. AudioFormatReader* const r = af->createReaderFor (in, true);
  16617. if (r != 0)
  16618. return r;
  16619. }
  16620. }
  16621. }
  16622. return 0;
  16623. }
  16624. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16625. {
  16626. // you need to actually register some formats before the manager can
  16627. // use them to open a file!
  16628. jassert (knownFormats.size() > 0);
  16629. ScopedPointer <InputStream> in (audioFileStream);
  16630. if (in != 0)
  16631. {
  16632. const int64 originalStreamPos = in->getPosition();
  16633. for (int i = 0; i < getNumKnownFormats(); ++i)
  16634. {
  16635. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16636. if (r != 0)
  16637. {
  16638. in.release();
  16639. return r;
  16640. }
  16641. in->setPosition (originalStreamPos);
  16642. // the stream that is passed-in must be capable of being repositioned so
  16643. // that all the formats can have a go at opening it.
  16644. jassert (in->getPosition() == originalStreamPos);
  16645. }
  16646. }
  16647. return 0;
  16648. }
  16649. END_JUCE_NAMESPACE
  16650. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16651. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16652. BEGIN_JUCE_NAMESPACE
  16653. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16654. const int64 startSample_,
  16655. const int64 length_,
  16656. const bool deleteSourceWhenDeleted_)
  16657. : AudioFormatReader (0, source_->getFormatName()),
  16658. source (source_),
  16659. startSample (startSample_),
  16660. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16661. {
  16662. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16663. sampleRate = source->sampleRate;
  16664. bitsPerSample = source->bitsPerSample;
  16665. lengthInSamples = length;
  16666. numChannels = source->numChannels;
  16667. usesFloatingPointData = source->usesFloatingPointData;
  16668. }
  16669. AudioSubsectionReader::~AudioSubsectionReader()
  16670. {
  16671. if (deleteSourceWhenDeleted)
  16672. delete source;
  16673. }
  16674. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16675. int64 startSampleInFile, int numSamples)
  16676. {
  16677. if (startSampleInFile + numSamples > length)
  16678. {
  16679. for (int i = numDestChannels; --i >= 0;)
  16680. if (destSamples[i] != 0)
  16681. zeromem (destSamples[i], sizeof (int) * numSamples);
  16682. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16683. if (numSamples <= 0)
  16684. return true;
  16685. }
  16686. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16687. startSampleInFile + startSample, numSamples);
  16688. }
  16689. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16690. int64 numSamples,
  16691. float& lowestLeft,
  16692. float& highestLeft,
  16693. float& lowestRight,
  16694. float& highestRight)
  16695. {
  16696. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16697. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16698. source->readMaxLevels (startSampleInFile + startSample,
  16699. numSamples,
  16700. lowestLeft,
  16701. highestLeft,
  16702. lowestRight,
  16703. highestRight);
  16704. }
  16705. END_JUCE_NAMESPACE
  16706. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16707. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16708. BEGIN_JUCE_NAMESPACE
  16709. const int timeBeforeDeletingReader = 2000;
  16710. struct AudioThumbnailDataFormat
  16711. {
  16712. char thumbnailMagic[4];
  16713. int samplesPerThumbSample;
  16714. int64 totalSamples; // source samples
  16715. int64 numFinishedSamples; // source samples
  16716. int numThumbnailSamples;
  16717. int numChannels;
  16718. int sampleRate;
  16719. char future[16];
  16720. char data[1];
  16721. };
  16722. #if JUCE_BIG_ENDIAN
  16723. static void swap (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16724. static void swap (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16725. #endif
  16726. static void swapEndiannessIfNeeded (AudioThumbnailDataFormat* const d)
  16727. {
  16728. (void) d;
  16729. #if JUCE_BIG_ENDIAN
  16730. swap (d->samplesPerThumbSample);
  16731. swap (d->totalSamples);
  16732. swap (d->numFinishedSamples);
  16733. swap (d->numThumbnailSamples);
  16734. swap (d->numChannels);
  16735. swap (d->sampleRate);
  16736. #endif
  16737. }
  16738. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16739. AudioFormatManager& formatManagerToUse_,
  16740. AudioThumbnailCache& cacheToUse)
  16741. : formatManagerToUse (formatManagerToUse_),
  16742. cache (cacheToUse),
  16743. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16744. {
  16745. clear();
  16746. }
  16747. AudioThumbnail::~AudioThumbnail()
  16748. {
  16749. cache.removeThumbnail (this);
  16750. const ScopedLock sl (readerLock);
  16751. reader = 0;
  16752. }
  16753. void AudioThumbnail::setSource (InputSource* const newSource)
  16754. {
  16755. cache.removeThumbnail (this);
  16756. timerCallback(); // stops the timer and deletes the reader
  16757. source = newSource;
  16758. clear();
  16759. if (newSource != 0
  16760. && ! (cache.loadThumb (*this, newSource->hashCode())
  16761. && isFullyLoaded()))
  16762. {
  16763. {
  16764. const ScopedLock sl (readerLock);
  16765. reader = createReader();
  16766. }
  16767. if (reader != 0)
  16768. {
  16769. initialiseFromAudioFile (*reader);
  16770. cache.addThumbnail (this);
  16771. }
  16772. }
  16773. sendChangeMessage (this);
  16774. }
  16775. bool AudioThumbnail::useTimeSlice()
  16776. {
  16777. const ScopedLock sl (readerLock);
  16778. if (isFullyLoaded())
  16779. {
  16780. if (reader != 0)
  16781. startTimer (timeBeforeDeletingReader);
  16782. cache.removeThumbnail (this);
  16783. return false;
  16784. }
  16785. if (reader == 0)
  16786. reader = createReader();
  16787. if (reader != 0)
  16788. {
  16789. readNextBlockFromAudioFile (*reader);
  16790. stopTimer();
  16791. sendChangeMessage (this);
  16792. const bool justFinished = isFullyLoaded();
  16793. if (justFinished)
  16794. cache.storeThumb (*this, source->hashCode());
  16795. return ! justFinished;
  16796. }
  16797. return false;
  16798. }
  16799. AudioFormatReader* AudioThumbnail::createReader() const
  16800. {
  16801. if (source != 0)
  16802. {
  16803. InputStream* const audioFileStream = source->createInputStream();
  16804. if (audioFileStream != 0)
  16805. return formatManagerToUse.createReaderFor (audioFileStream);
  16806. }
  16807. return 0;
  16808. }
  16809. void AudioThumbnail::timerCallback()
  16810. {
  16811. stopTimer();
  16812. const ScopedLock sl (readerLock);
  16813. reader = 0;
  16814. }
  16815. void AudioThumbnail::clear()
  16816. {
  16817. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16818. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16819. d->thumbnailMagic[0] = 'j';
  16820. d->thumbnailMagic[1] = 'a';
  16821. d->thumbnailMagic[2] = 't';
  16822. d->thumbnailMagic[3] = 'm';
  16823. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16824. d->totalSamples = 0;
  16825. d->numFinishedSamples = 0;
  16826. d->numThumbnailSamples = 0;
  16827. d->numChannels = 0;
  16828. d->sampleRate = 0;
  16829. numSamplesCached = 0;
  16830. cacheNeedsRefilling = true;
  16831. }
  16832. void AudioThumbnail::loadFrom (InputStream& input)
  16833. {
  16834. const ScopedLock sl (readerLock);
  16835. data.setSize (0);
  16836. input.readIntoMemoryBlock (data);
  16837. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16838. swapEndiannessIfNeeded (d);
  16839. if (! (d->thumbnailMagic[0] == 'j'
  16840. && d->thumbnailMagic[1] == 'a'
  16841. && d->thumbnailMagic[2] == 't'
  16842. && d->thumbnailMagic[3] == 'm'))
  16843. {
  16844. clear();
  16845. }
  16846. numSamplesCached = 0;
  16847. cacheNeedsRefilling = true;
  16848. }
  16849. void AudioThumbnail::saveTo (OutputStream& output) const
  16850. {
  16851. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16852. swapEndiannessIfNeeded (d);
  16853. output.write (data.getData(), (int) data.getSize());
  16854. swapEndiannessIfNeeded (d);
  16855. }
  16856. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16857. {
  16858. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16859. d->totalSamples = fileReader.lengthInSamples;
  16860. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16861. d->numFinishedSamples = 0;
  16862. d->sampleRate = roundToInt (fileReader.sampleRate);
  16863. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16864. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16865. d = (AudioThumbnailDataFormat*) data.getData();
  16866. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16867. return d->totalSamples > 0;
  16868. }
  16869. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16870. {
  16871. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16872. if (d->numFinishedSamples < d->totalSamples)
  16873. {
  16874. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16875. generateSection (fileReader,
  16876. d->numFinishedSamples,
  16877. numToDo);
  16878. d->numFinishedSamples += numToDo;
  16879. }
  16880. cacheNeedsRefilling = true;
  16881. return (d->numFinishedSamples < d->totalSamples);
  16882. }
  16883. int AudioThumbnail::getNumChannels() const throw()
  16884. {
  16885. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16886. jassert (d != 0);
  16887. return d->numChannels;
  16888. }
  16889. double AudioThumbnail::getTotalLength() const throw()
  16890. {
  16891. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16892. jassert (d != 0);
  16893. if (d->sampleRate > 0)
  16894. return d->totalSamples / (double)d->sampleRate;
  16895. else
  16896. return 0.0;
  16897. }
  16898. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16899. int64 startSample,
  16900. int numSamples)
  16901. {
  16902. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16903. jassert (d != 0);
  16904. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16905. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16906. char* l = getChannelData (0);
  16907. char* r = getChannelData (1);
  16908. for (int i = firstDataPos; i < lastDataPos; ++i)
  16909. {
  16910. const int sourceStart = i * d->samplesPerThumbSample;
  16911. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16912. float lowestLeft, highestLeft, lowestRight, highestRight;
  16913. fileReader.readMaxLevels (sourceStart,
  16914. sourceEnd - sourceStart,
  16915. lowestLeft,
  16916. highestLeft,
  16917. lowestRight,
  16918. highestRight);
  16919. int n = i * 2;
  16920. if (r != 0)
  16921. {
  16922. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16923. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16924. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16925. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16926. }
  16927. else
  16928. {
  16929. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16930. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16931. }
  16932. }
  16933. }
  16934. char* AudioThumbnail::getChannelData (int channel) const
  16935. {
  16936. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16937. jassert (d != 0);
  16938. if (channel >= 0 && channel < d->numChannels)
  16939. return d->data + (channel * 2 * d->numThumbnailSamples);
  16940. return 0;
  16941. }
  16942. bool AudioThumbnail::isFullyLoaded() const throw()
  16943. {
  16944. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16945. jassert (d != 0);
  16946. return d->numFinishedSamples >= d->totalSamples;
  16947. }
  16948. void AudioThumbnail::refillCache (const int numSamples,
  16949. double startTime,
  16950. const double timePerPixel)
  16951. {
  16952. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16953. jassert (d != 0);
  16954. if (numSamples <= 0
  16955. || timePerPixel <= 0.0
  16956. || d->sampleRate <= 0)
  16957. {
  16958. numSamplesCached = 0;
  16959. cacheNeedsRefilling = true;
  16960. return;
  16961. }
  16962. if (numSamples == numSamplesCached
  16963. && numChannelsCached == d->numChannels
  16964. && startTime == cachedStart
  16965. && timePerPixel == cachedTimePerPixel
  16966. && ! cacheNeedsRefilling)
  16967. {
  16968. return;
  16969. }
  16970. numSamplesCached = numSamples;
  16971. numChannelsCached = d->numChannels;
  16972. cachedStart = startTime;
  16973. cachedTimePerPixel = timePerPixel;
  16974. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16975. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16976. const ScopedLock sl (readerLock);
  16977. cacheNeedsRefilling = false;
  16978. if (needExtraDetail && reader == 0)
  16979. reader = createReader();
  16980. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16981. {
  16982. startTimer (timeBeforeDeletingReader);
  16983. char* cacheData = (char*) cachedLevels.getData();
  16984. int sample = roundToInt (startTime * d->sampleRate);
  16985. for (int i = numSamples; --i >= 0;)
  16986. {
  16987. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16988. if (sample >= 0)
  16989. {
  16990. if (sample >= reader->lengthInSamples)
  16991. break;
  16992. float lmin, lmax, rmin, rmax;
  16993. reader->readMaxLevels (sample,
  16994. jmax (1, nextSample - sample),
  16995. lmin, lmax, rmin, rmax);
  16996. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16997. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16998. if (numChannelsCached > 1)
  16999. {
  17000. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  17001. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  17002. }
  17003. cacheData += 2 * numChannelsCached;
  17004. }
  17005. startTime += timePerPixel;
  17006. sample = nextSample;
  17007. }
  17008. }
  17009. else
  17010. {
  17011. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  17012. {
  17013. char* const channelData = getChannelData (channelNum);
  17014. char* cacheData = ((char*) cachedLevels.getData()) + channelNum * 2;
  17015. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  17016. startTime = cachedStart;
  17017. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  17018. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  17019. for (int i = numSamples; --i >= 0;)
  17020. {
  17021. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  17022. if (sample >= 0 && channelData != 0)
  17023. {
  17024. char mx = -128;
  17025. char mn = 127;
  17026. while (sample <= nextSample)
  17027. {
  17028. if (sample >= numFinished)
  17029. break;
  17030. const int n = sample << 1;
  17031. const char sampMin = channelData [n];
  17032. const char sampMax = channelData [n + 1];
  17033. if (sampMin < mn)
  17034. mn = sampMin;
  17035. if (sampMax > mx)
  17036. mx = sampMax;
  17037. ++sample;
  17038. }
  17039. if (mn <= mx)
  17040. {
  17041. cacheData[0] = mn;
  17042. cacheData[1] = mx;
  17043. }
  17044. else
  17045. {
  17046. cacheData[0] = 1;
  17047. cacheData[1] = 0;
  17048. }
  17049. }
  17050. else
  17051. {
  17052. cacheData[0] = 1;
  17053. cacheData[1] = 0;
  17054. }
  17055. cacheData += numChannelsCached * 2;
  17056. startTime += timePerPixel;
  17057. sample = nextSample;
  17058. }
  17059. }
  17060. }
  17061. }
  17062. void AudioThumbnail::drawChannel (Graphics& g,
  17063. int x, int y, int w, int h,
  17064. double startTime,
  17065. double endTime,
  17066. int channelNum,
  17067. const float verticalZoomFactor)
  17068. {
  17069. refillCache (w, startTime, (endTime - startTime) / w);
  17070. if (numSamplesCached >= w
  17071. && channelNum >= 0
  17072. && channelNum < numChannelsCached)
  17073. {
  17074. const float topY = (float) y;
  17075. const float bottomY = topY + h;
  17076. const float midY = topY + h * 0.5f;
  17077. const float vscale = verticalZoomFactor * h / 256.0f;
  17078. const Rectangle<int> clip (g.getClipBounds());
  17079. const int skipLeft = jlimit (0, w, clip.getX() - x);
  17080. w -= skipLeft;
  17081. x += skipLeft;
  17082. const char* cacheData = ((const char*) cachedLevels.getData())
  17083. + (channelNum << 1)
  17084. + skipLeft * (numChannelsCached << 1);
  17085. while (--w >= 0)
  17086. {
  17087. const char mn = cacheData[0];
  17088. const char mx = cacheData[1];
  17089. cacheData += numChannelsCached << 1;
  17090. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  17091. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  17092. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  17093. ++x;
  17094. if (x >= clip.getRight())
  17095. break;
  17096. }
  17097. }
  17098. }
  17099. END_JUCE_NAMESPACE
  17100. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  17101. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  17102. BEGIN_JUCE_NAMESPACE
  17103. struct ThumbnailCacheEntry
  17104. {
  17105. int64 hash;
  17106. uint32 lastUsed;
  17107. MemoryBlock data;
  17108. juce_UseDebuggingNewOperator
  17109. };
  17110. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  17111. : TimeSliceThread (T("thumb cache")),
  17112. maxNumThumbsToStore (maxNumThumbsToStore_)
  17113. {
  17114. startThread (2);
  17115. }
  17116. AudioThumbnailCache::~AudioThumbnailCache()
  17117. {
  17118. }
  17119. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  17120. {
  17121. for (int i = thumbs.size(); --i >= 0;)
  17122. {
  17123. if (thumbs[i]->hash == hashCode)
  17124. {
  17125. MemoryInputStream in ((const char*) thumbs[i]->data.getData(),
  17126. thumbs[i]->data.getSize(),
  17127. false);
  17128. thumb.loadFrom (in);
  17129. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  17130. return true;
  17131. }
  17132. }
  17133. return false;
  17134. }
  17135. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  17136. const int64 hashCode)
  17137. {
  17138. MemoryOutputStream out;
  17139. thumb.saveTo (out);
  17140. ThumbnailCacheEntry* te = 0;
  17141. for (int i = thumbs.size(); --i >= 0;)
  17142. {
  17143. if (thumbs[i]->hash == hashCode)
  17144. {
  17145. te = thumbs[i];
  17146. break;
  17147. }
  17148. }
  17149. if (te == 0)
  17150. {
  17151. te = new ThumbnailCacheEntry();
  17152. te->hash = hashCode;
  17153. if (thumbs.size() < maxNumThumbsToStore)
  17154. {
  17155. thumbs.add (te);
  17156. }
  17157. else
  17158. {
  17159. int oldest = 0;
  17160. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  17161. int i;
  17162. for (i = thumbs.size(); --i >= 0;)
  17163. if (thumbs[i]->lastUsed < oldestTime)
  17164. oldest = i;
  17165. thumbs.set (i, te);
  17166. }
  17167. }
  17168. te->lastUsed = Time::getMillisecondCounter();
  17169. te->data.setSize (0);
  17170. te->data.append (out.getData(), out.getDataSize());
  17171. }
  17172. void AudioThumbnailCache::clear()
  17173. {
  17174. thumbs.clear();
  17175. }
  17176. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  17177. {
  17178. addTimeSliceClient (thumb);
  17179. }
  17180. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  17181. {
  17182. removeTimeSliceClient (thumb);
  17183. }
  17184. END_JUCE_NAMESPACE
  17185. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  17186. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17187. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  17188. #if ! JUCE_WINDOWS
  17189. #include <QuickTime/Movies.h>
  17190. #include <QuickTime/QTML.h>
  17191. #include <QuickTime/QuickTimeComponents.h>
  17192. #include <QuickTime/MediaHandlers.h>
  17193. #include <QuickTime/ImageCodec.h>
  17194. #else
  17195. #if JUCE_MSVC
  17196. #pragma warning (push)
  17197. #pragma warning (disable : 4100)
  17198. #endif
  17199. #include <Movies.h>
  17200. #include <QTML.h>
  17201. #include <QuickTimeComponents.h>
  17202. #include <MediaHandlers.h>
  17203. #include <ImageCodec.h>
  17204. #if JUCE_MSVC
  17205. #pragma warning (pop)
  17206. #endif
  17207. #endif
  17208. BEGIN_JUCE_NAMESPACE
  17209. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  17210. static const char* const quickTimeFormatName = "QuickTime file";
  17211. static const tchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  17212. class QTAudioReader : public AudioFormatReader
  17213. {
  17214. public:
  17215. QTAudioReader (InputStream* const input_, const int trackNum_)
  17216. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  17217. ok (false),
  17218. movie (0),
  17219. trackNum (trackNum_),
  17220. lastSampleRead (0),
  17221. lastThreadId (0),
  17222. extractor (0),
  17223. dataHandle (0)
  17224. {
  17225. bufferList.calloc (256, 1);
  17226. #ifdef WIN32
  17227. if (InitializeQTML (0) != noErr)
  17228. return;
  17229. #endif
  17230. if (EnterMovies() != noErr)
  17231. return;
  17232. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  17233. if (! opened)
  17234. return;
  17235. {
  17236. const int numTracks = GetMovieTrackCount (movie);
  17237. int trackCount = 0;
  17238. for (int i = 1; i <= numTracks; ++i)
  17239. {
  17240. track = GetMovieIndTrack (movie, i);
  17241. media = GetTrackMedia (track);
  17242. OSType mediaType;
  17243. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  17244. if (mediaType == SoundMediaType
  17245. && trackCount++ == trackNum_)
  17246. {
  17247. ok = true;
  17248. break;
  17249. }
  17250. }
  17251. }
  17252. if (! ok)
  17253. return;
  17254. ok = false;
  17255. lengthInSamples = GetMediaDecodeDuration (media);
  17256. usesFloatingPointData = false;
  17257. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  17258. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  17259. / GetMediaTimeScale (media);
  17260. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  17261. unsigned long output_layout_size;
  17262. err = MovieAudioExtractionGetPropertyInfo (extractor,
  17263. kQTPropertyClass_MovieAudioExtraction_Audio,
  17264. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17265. 0, &output_layout_size, 0);
  17266. if (err != noErr)
  17267. return;
  17268. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  17269. qt_audio_channel_layout.calloc (output_layout_size, 1);
  17270. err = MovieAudioExtractionGetProperty (extractor,
  17271. kQTPropertyClass_MovieAudioExtraction_Audio,
  17272. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17273. output_layout_size, qt_audio_channel_layout, 0);
  17274. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  17275. err = MovieAudioExtractionSetProperty (extractor,
  17276. kQTPropertyClass_MovieAudioExtraction_Audio,
  17277. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17278. output_layout_size,
  17279. qt_audio_channel_layout);
  17280. err = MovieAudioExtractionGetProperty (extractor,
  17281. kQTPropertyClass_MovieAudioExtraction_Audio,
  17282. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17283. sizeof (inputStreamDesc),
  17284. &inputStreamDesc, 0);
  17285. if (err != noErr)
  17286. return;
  17287. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  17288. | kAudioFormatFlagIsPacked
  17289. | kAudioFormatFlagsNativeEndian;
  17290. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  17291. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  17292. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  17293. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  17294. err = MovieAudioExtractionSetProperty (extractor,
  17295. kQTPropertyClass_MovieAudioExtraction_Audio,
  17296. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17297. sizeof (inputStreamDesc),
  17298. &inputStreamDesc);
  17299. if (err != noErr)
  17300. return;
  17301. Boolean allChannelsDiscrete = false;
  17302. err = MovieAudioExtractionSetProperty (extractor,
  17303. kQTPropertyClass_MovieAudioExtraction_Movie,
  17304. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  17305. sizeof (allChannelsDiscrete),
  17306. &allChannelsDiscrete);
  17307. if (err != noErr)
  17308. return;
  17309. bufferList->mNumberBuffers = 1;
  17310. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  17311. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  17312. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  17313. sampleRate = inputStreamDesc.mSampleRate;
  17314. bitsPerSample = 16;
  17315. numChannels = inputStreamDesc.mChannelsPerFrame;
  17316. detachThread();
  17317. ok = true;
  17318. }
  17319. ~QTAudioReader()
  17320. {
  17321. if (dataHandle != 0)
  17322. DisposeHandle (dataHandle);
  17323. if (extractor != 0)
  17324. {
  17325. MovieAudioExtractionEnd (extractor);
  17326. extractor = 0;
  17327. }
  17328. checkThreadIsAttached();
  17329. DisposeMovie (movie);
  17330. juce_free (bufferList->mBuffers[0].mData);
  17331. #if JUCE_MAC
  17332. ExitMoviesOnThread ();
  17333. #endif
  17334. }
  17335. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17336. int64 startSampleInFile, int numSamples)
  17337. {
  17338. checkThreadIsAttached();
  17339. while (numSamples > 0)
  17340. {
  17341. if (! loadFrame ((int) startSampleInFile))
  17342. return false;
  17343. const int numToDo = jmin (numSamples, samplesPerFrame);
  17344. for (int j = numDestChannels; --j >= 0;)
  17345. {
  17346. if (destSamples[j] != 0)
  17347. {
  17348. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  17349. for (int i = 0; i < numToDo; ++i)
  17350. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  17351. }
  17352. }
  17353. startOffsetInDestBuffer += numToDo;
  17354. startSampleInFile += numToDo;
  17355. numSamples -= numToDo;
  17356. }
  17357. detachThread();
  17358. return true;
  17359. }
  17360. bool loadFrame (const int sampleNum)
  17361. {
  17362. if (lastSampleRead != sampleNum)
  17363. {
  17364. TimeRecord time;
  17365. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17366. time.base = 0;
  17367. time.value.hi = 0;
  17368. time.value.lo = (UInt32) sampleNum;
  17369. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17370. kQTPropertyClass_MovieAudioExtraction_Movie,
  17371. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17372. sizeof (time), &time);
  17373. if (err != noErr)
  17374. return false;
  17375. }
  17376. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17377. UInt32 outFlags = 0;
  17378. UInt32 actualNumSamples = samplesPerFrame;
  17379. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17380. bufferList, &outFlags);
  17381. lastSampleRead = sampleNum + samplesPerFrame;
  17382. return err == noErr;
  17383. }
  17384. juce_UseDebuggingNewOperator
  17385. bool ok;
  17386. private:
  17387. Movie movie;
  17388. Media media;
  17389. Track track;
  17390. const int trackNum;
  17391. double trackUnitsPerFrame;
  17392. int samplesPerFrame;
  17393. int lastSampleRead;
  17394. Thread::ThreadID lastThreadId;
  17395. MovieAudioExtractionRef extractor;
  17396. AudioStreamBasicDescription inputStreamDesc;
  17397. HeapBlock <AudioBufferList> bufferList;
  17398. Handle dataHandle;
  17399. void checkThreadIsAttached()
  17400. {
  17401. #if JUCE_MAC
  17402. if (Thread::getCurrentThreadId() != lastThreadId)
  17403. EnterMoviesOnThread (0);
  17404. AttachMovieToCurrentThread (movie);
  17405. #endif
  17406. }
  17407. void detachThread()
  17408. {
  17409. #if JUCE_MAC
  17410. DetachMovieFromCurrentThread (movie);
  17411. #endif
  17412. }
  17413. };
  17414. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17415. : AudioFormat (TRANS (quickTimeFormatName), (const tchar**) quickTimeExtensions)
  17416. {
  17417. }
  17418. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17419. {
  17420. }
  17421. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17422. {
  17423. return Array<int>();
  17424. }
  17425. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17426. {
  17427. return Array<int>();
  17428. }
  17429. bool QuickTimeAudioFormat::canDoStereo()
  17430. {
  17431. return true;
  17432. }
  17433. bool QuickTimeAudioFormat::canDoMono()
  17434. {
  17435. return true;
  17436. }
  17437. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17438. const bool deleteStreamIfOpeningFails)
  17439. {
  17440. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17441. if (r->ok)
  17442. return r.release();
  17443. if (! deleteStreamIfOpeningFails)
  17444. r->input = 0;
  17445. return 0;
  17446. }
  17447. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17448. double /*sampleRateToUse*/,
  17449. unsigned int /*numberOfChannels*/,
  17450. int /*bitsPerSample*/,
  17451. const StringPairArray& /*metadataValues*/,
  17452. int /*qualityOptionIndex*/)
  17453. {
  17454. jassertfalse // not yet implemented!
  17455. return 0;
  17456. }
  17457. END_JUCE_NAMESPACE
  17458. #endif
  17459. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17460. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17461. BEGIN_JUCE_NAMESPACE
  17462. static const char* const wavFormatName = "WAV file";
  17463. static const tchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17464. const tchar* const WavAudioFormat::bwavDescription = T("bwav description");
  17465. const tchar* const WavAudioFormat::bwavOriginator = T("bwav originator");
  17466. const tchar* const WavAudioFormat::bwavOriginatorRef = T("bwav originator ref");
  17467. const tchar* const WavAudioFormat::bwavOriginationDate = T("bwav origination date");
  17468. const tchar* const WavAudioFormat::bwavOriginationTime = T("bwav origination time");
  17469. const tchar* const WavAudioFormat::bwavTimeReference = T("bwav time reference");
  17470. const tchar* const WavAudioFormat::bwavCodingHistory = T("bwav coding history");
  17471. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17472. const String& originator,
  17473. const String& originatorRef,
  17474. const Time& date,
  17475. const int64 timeReferenceSamples,
  17476. const String& codingHistory)
  17477. {
  17478. StringPairArray m;
  17479. m.set (bwavDescription, description);
  17480. m.set (bwavOriginator, originator);
  17481. m.set (bwavOriginatorRef, originatorRef);
  17482. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17483. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17484. m.set (bwavTimeReference, String (timeReferenceSamples));
  17485. m.set (bwavCodingHistory, codingHistory);
  17486. return m;
  17487. }
  17488. #if JUCE_MSVC
  17489. #pragma pack (push, 1)
  17490. #define PACKED
  17491. #elif JUCE_GCC
  17492. #define PACKED __attribute__((packed))
  17493. #else
  17494. #define PACKED
  17495. #endif
  17496. struct BWAVChunk
  17497. {
  17498. uint8 description [256];
  17499. uint8 originator [32];
  17500. uint8 originatorRef [32];
  17501. uint8 originationDate [10];
  17502. uint8 originationTime [8];
  17503. uint32 timeRefLow;
  17504. uint32 timeRefHigh;
  17505. uint16 version;
  17506. uint8 umid[64];
  17507. uint8 reserved[190];
  17508. uint8 codingHistory[1];
  17509. void copyTo (StringPairArray& values) const
  17510. {
  17511. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17512. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17513. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17514. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17515. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17516. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17517. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17518. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17519. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17520. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17521. }
  17522. static MemoryBlock createFrom (const StringPairArray& values)
  17523. {
  17524. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (0) - 1;
  17525. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17526. data.fillWith (0);
  17527. BWAVChunk* b = (BWAVChunk*) 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. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17531. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17532. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17533. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17534. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17535. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17536. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17537. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17538. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory);
  17539. if (b->description[0] != 0
  17540. || b->originator[0] != 0
  17541. || b->originationDate[0] != 0
  17542. || b->originationTime[0] != 0
  17543. || b->codingHistory[0] != 0
  17544. || time != 0)
  17545. {
  17546. return data;
  17547. }
  17548. return MemoryBlock();
  17549. }
  17550. } PACKED;
  17551. struct SMPLChunk
  17552. {
  17553. struct SampleLoop
  17554. {
  17555. uint32 identifier;
  17556. uint32 type;
  17557. uint32 start;
  17558. uint32 end;
  17559. uint32 fraction;
  17560. uint32 playCount;
  17561. } PACKED;
  17562. uint32 manufacturer;
  17563. uint32 product;
  17564. uint32 samplePeriod;
  17565. uint32 midiUnityNote;
  17566. uint32 midiPitchFraction;
  17567. uint32 smpteFormat;
  17568. uint32 smpteOffset;
  17569. uint32 numSampleLoops;
  17570. uint32 samplerData;
  17571. SampleLoop loops[1];
  17572. void copyTo (StringPairArray& values, const int totalSize) const
  17573. {
  17574. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17575. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17576. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17577. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17578. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17579. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17580. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17581. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17582. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17583. for (uint32 i = 0; i < numSampleLoops; ++i)
  17584. {
  17585. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17586. break;
  17587. const String prefix ("Loop" + String(i));
  17588. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17589. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17590. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17591. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17592. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17593. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17594. }
  17595. }
  17596. static MemoryBlock createFrom (const StringPairArray& values)
  17597. {
  17598. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17599. if (numLoops <= 0)
  17600. return MemoryBlock();
  17601. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17602. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17603. data.fillWith (0);
  17604. SMPLChunk* s = (SMPLChunk*) data.getData();
  17605. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17606. // as they get called in the right order..
  17607. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17608. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17609. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17610. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17611. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17612. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17613. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17614. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17615. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17616. for (int i = 0; i < numLoops; ++i)
  17617. {
  17618. const String prefix ("Loop" + String(i));
  17619. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17620. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17621. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17622. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17623. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17624. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17625. }
  17626. return data;
  17627. }
  17628. } PACKED;
  17629. #if JUCE_MSVC
  17630. #pragma pack (pop)
  17631. #endif
  17632. #undef PACKED
  17633. class WavAudioFormatReader : public AudioFormatReader
  17634. {
  17635. int bytesPerFrame;
  17636. int64 dataChunkStart, dataLength;
  17637. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17638. WavAudioFormatReader (const WavAudioFormatReader&);
  17639. const WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17640. public:
  17641. int64 bwavChunkStart, bwavSize;
  17642. WavAudioFormatReader (InputStream* const in)
  17643. : AudioFormatReader (in, TRANS (wavFormatName)),
  17644. dataLength (0),
  17645. bwavChunkStart (0),
  17646. bwavSize (0)
  17647. {
  17648. if (input->readInt() == chunkName ("RIFF"))
  17649. {
  17650. const uint32 len = (uint32) input->readInt();
  17651. const int64 end = input->getPosition() + len;
  17652. bool hasGotType = false;
  17653. bool hasGotData = false;
  17654. if (input->readInt() == chunkName ("WAVE"))
  17655. {
  17656. while (input->getPosition() < end
  17657. && ! input->isExhausted())
  17658. {
  17659. const int chunkType = input->readInt();
  17660. uint32 length = (uint32) input->readInt();
  17661. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17662. if (chunkType == chunkName ("fmt "))
  17663. {
  17664. // read the format chunk
  17665. const short format = input->readShort();
  17666. const short numChans = input->readShort();
  17667. sampleRate = input->readInt();
  17668. const int bytesPerSec = input->readInt();
  17669. numChannels = numChans;
  17670. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17671. bitsPerSample = 8 * bytesPerFrame / numChans;
  17672. if (format == 3)
  17673. usesFloatingPointData = true;
  17674. else if (format != 1)
  17675. bytesPerFrame = 0;
  17676. hasGotType = true;
  17677. }
  17678. else if (chunkType == chunkName ("data"))
  17679. {
  17680. // get the data chunk's position
  17681. dataLength = length;
  17682. dataChunkStart = input->getPosition();
  17683. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17684. hasGotData = true;
  17685. }
  17686. else if (chunkType == chunkName ("bext"))
  17687. {
  17688. bwavChunkStart = input->getPosition();
  17689. bwavSize = length;
  17690. // Broadcast-wav extension chunk..
  17691. HeapBlock <BWAVChunk> bwav;
  17692. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17693. input->read (bwav, length);
  17694. bwav->copyTo (metadataValues);
  17695. }
  17696. else if (chunkType == chunkName ("smpl"))
  17697. {
  17698. HeapBlock <SMPLChunk> smpl;
  17699. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17700. input->read (smpl, length);
  17701. smpl->copyTo (metadataValues, length);
  17702. }
  17703. else if (chunkEnd <= input->getPosition())
  17704. {
  17705. break;
  17706. }
  17707. input->setPosition (chunkEnd);
  17708. }
  17709. }
  17710. }
  17711. }
  17712. ~WavAudioFormatReader()
  17713. {
  17714. }
  17715. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17716. int64 startSampleInFile, int numSamples)
  17717. {
  17718. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17719. if (samplesAvailable < numSamples)
  17720. {
  17721. for (int i = numDestChannels; --i >= 0;)
  17722. if (destSamples[i] != 0)
  17723. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17724. numSamples = (int) samplesAvailable;
  17725. }
  17726. if (numSamples <= 0)
  17727. return true;
  17728. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17729. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17730. char tempBuffer [tempBufSize];
  17731. while (numSamples > 0)
  17732. {
  17733. int* left = destSamples[0];
  17734. if (left != 0)
  17735. left += startOffsetInDestBuffer;
  17736. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17737. if (right != 0)
  17738. right += startOffsetInDestBuffer;
  17739. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17740. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17741. if (bytesRead < numThisTime * bytesPerFrame)
  17742. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17743. if (bitsPerSample == 16)
  17744. {
  17745. const short* src = (const short*) tempBuffer;
  17746. if (numChannels > 1)
  17747. {
  17748. if (left == 0)
  17749. {
  17750. for (int i = numThisTime; --i >= 0;)
  17751. {
  17752. ++src;
  17753. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17754. }
  17755. }
  17756. else if (right == 0)
  17757. {
  17758. for (int i = numThisTime; --i >= 0;)
  17759. {
  17760. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17761. ++src;
  17762. }
  17763. }
  17764. else
  17765. {
  17766. for (int i = numThisTime; --i >= 0;)
  17767. {
  17768. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17769. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17770. }
  17771. }
  17772. }
  17773. else
  17774. {
  17775. for (int i = numThisTime; --i >= 0;)
  17776. {
  17777. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17778. }
  17779. }
  17780. }
  17781. else if (bitsPerSample == 24)
  17782. {
  17783. const char* src = (const char*) tempBuffer;
  17784. if (numChannels > 1)
  17785. {
  17786. if (left == 0)
  17787. {
  17788. for (int i = numThisTime; --i >= 0;)
  17789. {
  17790. src += 3;
  17791. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17792. src += 3;
  17793. }
  17794. }
  17795. else if (right == 0)
  17796. {
  17797. for (int i = numThisTime; --i >= 0;)
  17798. {
  17799. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17800. src += 6;
  17801. }
  17802. }
  17803. else
  17804. {
  17805. for (int i = 0; i < numThisTime; ++i)
  17806. {
  17807. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17808. src += 3;
  17809. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17810. src += 3;
  17811. }
  17812. }
  17813. }
  17814. else
  17815. {
  17816. for (int i = 0; i < numThisTime; ++i)
  17817. {
  17818. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17819. src += 3;
  17820. }
  17821. }
  17822. }
  17823. else if (bitsPerSample == 32)
  17824. {
  17825. const unsigned int* src = (const unsigned int*) tempBuffer;
  17826. unsigned int* l = (unsigned int*) left;
  17827. unsigned int* r = (unsigned int*) right;
  17828. if (numChannels > 1)
  17829. {
  17830. if (l == 0)
  17831. {
  17832. for (int i = numThisTime; --i >= 0;)
  17833. {
  17834. ++src;
  17835. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17836. }
  17837. }
  17838. else if (r == 0)
  17839. {
  17840. for (int i = numThisTime; --i >= 0;)
  17841. {
  17842. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17843. ++src;
  17844. }
  17845. }
  17846. else
  17847. {
  17848. for (int i = numThisTime; --i >= 0;)
  17849. {
  17850. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17851. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17852. }
  17853. }
  17854. }
  17855. else
  17856. {
  17857. for (int i = numThisTime; --i >= 0;)
  17858. {
  17859. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17860. }
  17861. }
  17862. left = (int*)l;
  17863. right = (int*)r;
  17864. }
  17865. else if (bitsPerSample == 8)
  17866. {
  17867. const unsigned char* src = (const unsigned char*) tempBuffer;
  17868. if (numChannels > 1)
  17869. {
  17870. if (left == 0)
  17871. {
  17872. for (int i = numThisTime; --i >= 0;)
  17873. {
  17874. ++src;
  17875. *right++ = ((int) *src++ - 128) << 24;
  17876. }
  17877. }
  17878. else if (right == 0)
  17879. {
  17880. for (int i = numThisTime; --i >= 0;)
  17881. {
  17882. *left++ = ((int) *src++ - 128) << 24;
  17883. ++src;
  17884. }
  17885. }
  17886. else
  17887. {
  17888. for (int i = numThisTime; --i >= 0;)
  17889. {
  17890. *left++ = ((int) *src++ - 128) << 24;
  17891. *right++ = ((int) *src++ - 128) << 24;
  17892. }
  17893. }
  17894. }
  17895. else
  17896. {
  17897. for (int i = numThisTime; --i >= 0;)
  17898. {
  17899. *left++ = ((int)*src++ - 128) << 24;
  17900. }
  17901. }
  17902. }
  17903. startOffsetInDestBuffer += numThisTime;
  17904. numSamples -= numThisTime;
  17905. }
  17906. if (numSamples > 0)
  17907. {
  17908. for (int i = numDestChannels; --i >= 0;)
  17909. if (destSamples[i] != 0)
  17910. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17911. sizeof (int) * numSamples);
  17912. }
  17913. return true;
  17914. }
  17915. juce_UseDebuggingNewOperator
  17916. };
  17917. class WavAudioFormatWriter : public AudioFormatWriter
  17918. {
  17919. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17920. uint32 lengthInSamples, bytesWritten;
  17921. int64 headerPosition;
  17922. bool writeFailed;
  17923. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17924. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17925. const WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17926. void writeHeader()
  17927. {
  17928. const bool seekedOk = output->setPosition (headerPosition);
  17929. (void) seekedOk;
  17930. // if this fails, you've given it an output stream that can't seek! It needs
  17931. // to be able to seek back to write the header
  17932. jassert (seekedOk);
  17933. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17934. output->writeInt (chunkName ("RIFF"));
  17935. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17936. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17937. output->writeInt (chunkName ("WAVE"));
  17938. output->writeInt (chunkName ("fmt "));
  17939. output->writeInt (16);
  17940. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17941. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17942. output->writeShort ((short) numChannels);
  17943. output->writeInt ((int) sampleRate);
  17944. output->writeInt (bytesPerFrame * (int) sampleRate);
  17945. output->writeShort ((short) bytesPerFrame);
  17946. output->writeShort ((short) bitsPerSample);
  17947. if (bwavChunk.getSize() > 0)
  17948. {
  17949. output->writeInt (chunkName ("bext"));
  17950. output->writeInt ((int) bwavChunk.getSize());
  17951. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17952. }
  17953. if (smplChunk.getSize() > 0)
  17954. {
  17955. output->writeInt (chunkName ("smpl"));
  17956. output->writeInt (smplChunk.getSize());
  17957. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17958. }
  17959. output->writeInt (chunkName ("data"));
  17960. output->writeInt (lengthInSamples * bytesPerFrame);
  17961. usesFloatingPointData = (bitsPerSample == 32);
  17962. }
  17963. public:
  17964. WavAudioFormatWriter (OutputStream* const out,
  17965. const double sampleRate_,
  17966. const unsigned int numChannels_,
  17967. const int bits,
  17968. const StringPairArray& metadataValues)
  17969. : AudioFormatWriter (out,
  17970. TRANS (wavFormatName),
  17971. sampleRate_,
  17972. numChannels_,
  17973. bits),
  17974. lengthInSamples (0),
  17975. bytesWritten (0),
  17976. writeFailed (false)
  17977. {
  17978. if (metadataValues.size() > 0)
  17979. {
  17980. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17981. smplChunk = SMPLChunk::createFrom (metadataValues);
  17982. }
  17983. headerPosition = out->getPosition();
  17984. writeHeader();
  17985. }
  17986. ~WavAudioFormatWriter()
  17987. {
  17988. writeHeader();
  17989. }
  17990. bool write (const int** data, int numSamples)
  17991. {
  17992. if (writeFailed)
  17993. return false;
  17994. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17995. tempBlock.ensureSize (bytes, false);
  17996. char* buffer = (char*) tempBlock.getData();
  17997. const int* left = data[0];
  17998. const int* right = data[1];
  17999. if (right == 0)
  18000. right = left;
  18001. if (bitsPerSample == 16)
  18002. {
  18003. short* b = (short*) buffer;
  18004. if (numChannels > 1)
  18005. {
  18006. for (int i = numSamples; --i >= 0;)
  18007. {
  18008. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  18009. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  18010. }
  18011. }
  18012. else
  18013. {
  18014. for (int i = numSamples; --i >= 0;)
  18015. {
  18016. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  18017. }
  18018. }
  18019. }
  18020. else if (bitsPerSample == 24)
  18021. {
  18022. char* b = (char*) buffer;
  18023. if (numChannels > 1)
  18024. {
  18025. for (int i = numSamples; --i >= 0;)
  18026. {
  18027. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  18028. b += 3;
  18029. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  18030. b += 3;
  18031. }
  18032. }
  18033. else
  18034. {
  18035. for (int i = numSamples; --i >= 0;)
  18036. {
  18037. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  18038. b += 3;
  18039. }
  18040. }
  18041. }
  18042. else if (bitsPerSample == 32)
  18043. {
  18044. unsigned int* b = (unsigned int*) buffer;
  18045. if (numChannels > 1)
  18046. {
  18047. for (int i = numSamples; --i >= 0;)
  18048. {
  18049. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  18050. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  18051. }
  18052. }
  18053. else
  18054. {
  18055. for (int i = numSamples; --i >= 0;)
  18056. {
  18057. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  18058. }
  18059. }
  18060. }
  18061. else if (bitsPerSample == 8)
  18062. {
  18063. unsigned char* b = (unsigned char*) buffer;
  18064. if (numChannels > 1)
  18065. {
  18066. for (int i = numSamples; --i >= 0;)
  18067. {
  18068. *b++ = (unsigned char) (128 + (*left++ >> 24));
  18069. *b++ = (unsigned char) (128 + (*right++ >> 24));
  18070. }
  18071. }
  18072. else
  18073. {
  18074. for (int i = numSamples; --i >= 0;)
  18075. {
  18076. *b++ = (unsigned char) (128 + (*left++ >> 24));
  18077. }
  18078. }
  18079. }
  18080. if (bytesWritten + bytes >= (uint32) 0xfff00000
  18081. || ! output->write (buffer, bytes))
  18082. {
  18083. // failed to write to disk, so let's try writing the header.
  18084. // If it's just run out of disk space, then if it does manage
  18085. // to write the header, we'll still have a useable file..
  18086. writeHeader();
  18087. writeFailed = true;
  18088. return false;
  18089. }
  18090. else
  18091. {
  18092. bytesWritten += bytes;
  18093. lengthInSamples += numSamples;
  18094. return true;
  18095. }
  18096. }
  18097. juce_UseDebuggingNewOperator
  18098. };
  18099. WavAudioFormat::WavAudioFormat()
  18100. : AudioFormat (TRANS (wavFormatName), (const tchar**) wavExtensions)
  18101. {
  18102. }
  18103. WavAudioFormat::~WavAudioFormat()
  18104. {
  18105. }
  18106. const Array <int> WavAudioFormat::getPossibleSampleRates()
  18107. {
  18108. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  18109. return Array <int> (rates);
  18110. }
  18111. const Array <int> WavAudioFormat::getPossibleBitDepths()
  18112. {
  18113. const int depths[] = { 8, 16, 24, 32, 0 };
  18114. return Array <int> (depths);
  18115. }
  18116. bool WavAudioFormat::canDoStereo()
  18117. {
  18118. return true;
  18119. }
  18120. bool WavAudioFormat::canDoMono()
  18121. {
  18122. return true;
  18123. }
  18124. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  18125. const bool deleteStreamIfOpeningFails)
  18126. {
  18127. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  18128. if (r->sampleRate != 0)
  18129. return r.release();
  18130. if (! deleteStreamIfOpeningFails)
  18131. r->input = 0;
  18132. return 0;
  18133. }
  18134. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  18135. double sampleRate,
  18136. unsigned int numChannels,
  18137. int bitsPerSample,
  18138. const StringPairArray& metadataValues,
  18139. int /*qualityOptionIndex*/)
  18140. {
  18141. if (getPossibleBitDepths().contains (bitsPerSample))
  18142. {
  18143. return new WavAudioFormatWriter (out,
  18144. sampleRate,
  18145. numChannels,
  18146. bitsPerSample,
  18147. metadataValues);
  18148. }
  18149. return 0;
  18150. }
  18151. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  18152. {
  18153. TemporaryFile tempFile (file);
  18154. WavAudioFormat wav;
  18155. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  18156. if (reader != 0)
  18157. {
  18158. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  18159. if (outStream != 0)
  18160. {
  18161. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  18162. reader->numChannels, reader->bitsPerSample,
  18163. metadata, 0));
  18164. if (writer != 0)
  18165. {
  18166. outStream.release();
  18167. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  18168. writer = 0;
  18169. reader = 0;
  18170. return ok && tempFile.overwriteTargetFileWithTemporary();
  18171. }
  18172. }
  18173. }
  18174. return false;
  18175. }
  18176. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  18177. {
  18178. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  18179. if (reader != 0)
  18180. {
  18181. const int64 bwavPos = reader->bwavChunkStart;
  18182. const int64 bwavSize = reader->bwavSize;
  18183. reader = 0;
  18184. if (bwavSize > 0)
  18185. {
  18186. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  18187. if (chunk.getSize() <= (size_t) bwavSize)
  18188. {
  18189. // the new one will fit in the space available, so write it directly..
  18190. const int64 oldSize = wavFile.getSize();
  18191. {
  18192. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  18193. out->setPosition (bwavPos);
  18194. out->write (chunk.getData(), (int) chunk.getSize());
  18195. out->setPosition (oldSize);
  18196. }
  18197. jassert (wavFile.getSize() == oldSize);
  18198. return true;
  18199. }
  18200. }
  18201. }
  18202. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  18203. }
  18204. END_JUCE_NAMESPACE
  18205. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  18206. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18207. BEGIN_JUCE_NAMESPACE
  18208. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  18209. const bool deleteReaderWhenThisIsDeleted)
  18210. : reader (reader_),
  18211. deleteReader (deleteReaderWhenThisIsDeleted),
  18212. nextPlayPos (0),
  18213. looping (false)
  18214. {
  18215. jassert (reader != 0);
  18216. }
  18217. AudioFormatReaderSource::~AudioFormatReaderSource()
  18218. {
  18219. releaseResources();
  18220. if (deleteReader)
  18221. delete reader;
  18222. }
  18223. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  18224. {
  18225. nextPlayPos = newPosition;
  18226. }
  18227. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  18228. {
  18229. looping = shouldLoop;
  18230. }
  18231. int AudioFormatReaderSource::getNextReadPosition() const
  18232. {
  18233. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  18234. : nextPlayPos;
  18235. }
  18236. int AudioFormatReaderSource::getTotalLength() const
  18237. {
  18238. return (int) reader->lengthInSamples;
  18239. }
  18240. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  18241. double /*sampleRate*/)
  18242. {
  18243. }
  18244. void AudioFormatReaderSource::releaseResources()
  18245. {
  18246. }
  18247. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18248. {
  18249. if (info.numSamples > 0)
  18250. {
  18251. const int start = nextPlayPos;
  18252. if (looping)
  18253. {
  18254. const int newStart = start % (int) reader->lengthInSamples;
  18255. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  18256. if (newEnd > newStart)
  18257. {
  18258. info.buffer->readFromAudioReader (reader,
  18259. info.startSample,
  18260. newEnd - newStart,
  18261. newStart,
  18262. true, true);
  18263. }
  18264. else
  18265. {
  18266. const int endSamps = (int) reader->lengthInSamples - newStart;
  18267. info.buffer->readFromAudioReader (reader,
  18268. info.startSample,
  18269. endSamps,
  18270. newStart,
  18271. true, true);
  18272. info.buffer->readFromAudioReader (reader,
  18273. info.startSample + endSamps,
  18274. newEnd,
  18275. 0,
  18276. true, true);
  18277. }
  18278. nextPlayPos = newEnd;
  18279. }
  18280. else
  18281. {
  18282. info.buffer->readFromAudioReader (reader,
  18283. info.startSample,
  18284. info.numSamples,
  18285. start,
  18286. true, true);
  18287. nextPlayPos += info.numSamples;
  18288. }
  18289. }
  18290. }
  18291. END_JUCE_NAMESPACE
  18292. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18293. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  18294. BEGIN_JUCE_NAMESPACE
  18295. AudioSourcePlayer::AudioSourcePlayer()
  18296. : source (0),
  18297. sampleRate (0),
  18298. bufferSize (0),
  18299. tempBuffer (2, 8),
  18300. lastGain (1.0f),
  18301. gain (1.0f)
  18302. {
  18303. }
  18304. AudioSourcePlayer::~AudioSourcePlayer()
  18305. {
  18306. setSource (0);
  18307. }
  18308. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18309. {
  18310. if (source != newSource)
  18311. {
  18312. AudioSource* const oldSource = source;
  18313. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18314. newSource->prepareToPlay (bufferSize, sampleRate);
  18315. {
  18316. const ScopedLock sl (readLock);
  18317. source = newSource;
  18318. }
  18319. if (oldSource != 0)
  18320. oldSource->releaseResources();
  18321. }
  18322. }
  18323. void AudioSourcePlayer::setGain (const float newGain) throw()
  18324. {
  18325. gain = newGain;
  18326. }
  18327. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18328. int totalNumInputChannels,
  18329. float** outputChannelData,
  18330. int totalNumOutputChannels,
  18331. int numSamples)
  18332. {
  18333. // these should have been prepared by audioDeviceAboutToStart()...
  18334. jassert (sampleRate > 0 && bufferSize > 0);
  18335. const ScopedLock sl (readLock);
  18336. if (source != 0)
  18337. {
  18338. AudioSourceChannelInfo info;
  18339. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18340. // messy stuff needed to compact the channels down into an array
  18341. // of non-zero pointers..
  18342. for (i = 0; i < totalNumInputChannels; ++i)
  18343. {
  18344. if (inputChannelData[i] != 0)
  18345. {
  18346. inputChans [numInputs++] = inputChannelData[i];
  18347. if (numInputs >= numElementsInArray (inputChans))
  18348. break;
  18349. }
  18350. }
  18351. for (i = 0; i < totalNumOutputChannels; ++i)
  18352. {
  18353. if (outputChannelData[i] != 0)
  18354. {
  18355. outputChans [numOutputs++] = outputChannelData[i];
  18356. if (numOutputs >= numElementsInArray (outputChans))
  18357. break;
  18358. }
  18359. }
  18360. if (numInputs > numOutputs)
  18361. {
  18362. // if there aren't enough output channels for the number of
  18363. // inputs, we need to create some temporary extra ones (can't
  18364. // use the input data in case it gets written to)
  18365. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18366. false, false, true);
  18367. for (i = 0; i < numOutputs; ++i)
  18368. {
  18369. channels[numActiveChans] = outputChans[i];
  18370. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18371. ++numActiveChans;
  18372. }
  18373. for (i = numOutputs; i < numInputs; ++i)
  18374. {
  18375. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18376. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18377. ++numActiveChans;
  18378. }
  18379. }
  18380. else
  18381. {
  18382. for (i = 0; i < numInputs; ++i)
  18383. {
  18384. channels[numActiveChans] = outputChans[i];
  18385. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18386. ++numActiveChans;
  18387. }
  18388. for (i = numInputs; i < numOutputs; ++i)
  18389. {
  18390. channels[numActiveChans] = outputChans[i];
  18391. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18392. ++numActiveChans;
  18393. }
  18394. }
  18395. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18396. info.buffer = &buffer;
  18397. info.startSample = 0;
  18398. info.numSamples = numSamples;
  18399. source->getNextAudioBlock (info);
  18400. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18401. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18402. lastGain = gain;
  18403. }
  18404. else
  18405. {
  18406. for (int i = 0; i < totalNumOutputChannels; ++i)
  18407. if (outputChannelData[i] != 0)
  18408. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18409. }
  18410. }
  18411. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18412. {
  18413. sampleRate = device->getCurrentSampleRate();
  18414. bufferSize = device->getCurrentBufferSizeSamples();
  18415. zeromem (channels, sizeof (channels));
  18416. if (source != 0)
  18417. source->prepareToPlay (bufferSize, sampleRate);
  18418. }
  18419. void AudioSourcePlayer::audioDeviceStopped()
  18420. {
  18421. if (source != 0)
  18422. source->releaseResources();
  18423. sampleRate = 0.0;
  18424. bufferSize = 0;
  18425. tempBuffer.setSize (2, 8);
  18426. }
  18427. END_JUCE_NAMESPACE
  18428. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18429. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18430. BEGIN_JUCE_NAMESPACE
  18431. AudioTransportSource::AudioTransportSource()
  18432. : source (0),
  18433. resamplerSource (0),
  18434. bufferingSource (0),
  18435. positionableSource (0),
  18436. masterSource (0),
  18437. gain (1.0f),
  18438. lastGain (1.0f),
  18439. playing (false),
  18440. stopped (true),
  18441. sampleRate (44100.0),
  18442. sourceSampleRate (0.0),
  18443. blockSize (128),
  18444. readAheadBufferSize (0),
  18445. isPrepared (false),
  18446. inputStreamEOF (false)
  18447. {
  18448. }
  18449. AudioTransportSource::~AudioTransportSource()
  18450. {
  18451. setSource (0);
  18452. releaseResources();
  18453. }
  18454. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18455. int readAheadBufferSize_,
  18456. double sourceSampleRateToCorrectFor)
  18457. {
  18458. if (source == newSource)
  18459. {
  18460. if (source == 0)
  18461. return;
  18462. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18463. }
  18464. readAheadBufferSize = readAheadBufferSize_;
  18465. sourceSampleRate = sourceSampleRateToCorrectFor;
  18466. ResamplingAudioSource* newResamplerSource = 0;
  18467. BufferingAudioSource* newBufferingSource = 0;
  18468. PositionableAudioSource* newPositionableSource = 0;
  18469. AudioSource* newMasterSource = 0;
  18470. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18471. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18472. AudioSource* oldMasterSource = masterSource;
  18473. if (newSource != 0)
  18474. {
  18475. newPositionableSource = newSource;
  18476. if (readAheadBufferSize_ > 0)
  18477. newPositionableSource = newBufferingSource
  18478. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18479. newPositionableSource->setNextReadPosition (0);
  18480. if (sourceSampleRateToCorrectFor != 0)
  18481. newMasterSource = newResamplerSource
  18482. = new ResamplingAudioSource (newPositionableSource, false);
  18483. else
  18484. newMasterSource = newPositionableSource;
  18485. if (isPrepared)
  18486. {
  18487. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18488. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18489. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18490. }
  18491. }
  18492. {
  18493. const ScopedLock sl (callbackLock);
  18494. source = newSource;
  18495. resamplerSource = newResamplerSource;
  18496. bufferingSource = newBufferingSource;
  18497. masterSource = newMasterSource;
  18498. positionableSource = newPositionableSource;
  18499. playing = false;
  18500. }
  18501. if (oldMasterSource != 0)
  18502. oldMasterSource->releaseResources();
  18503. }
  18504. void AudioTransportSource::start()
  18505. {
  18506. if ((! playing) && masterSource != 0)
  18507. {
  18508. callbackLock.enter();
  18509. playing = true;
  18510. stopped = false;
  18511. inputStreamEOF = false;
  18512. callbackLock.exit();
  18513. sendChangeMessage (this);
  18514. }
  18515. }
  18516. void AudioTransportSource::stop()
  18517. {
  18518. if (playing)
  18519. {
  18520. callbackLock.enter();
  18521. playing = false;
  18522. callbackLock.exit();
  18523. int n = 500;
  18524. while (--n >= 0 && ! stopped)
  18525. Thread::sleep (2);
  18526. sendChangeMessage (this);
  18527. }
  18528. }
  18529. void AudioTransportSource::setPosition (double newPosition)
  18530. {
  18531. if (sampleRate > 0.0)
  18532. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18533. }
  18534. double AudioTransportSource::getCurrentPosition() const
  18535. {
  18536. if (sampleRate > 0.0)
  18537. return getNextReadPosition() / sampleRate;
  18538. else
  18539. return 0.0;
  18540. }
  18541. void AudioTransportSource::setNextReadPosition (int newPosition)
  18542. {
  18543. if (positionableSource != 0)
  18544. {
  18545. if (sampleRate > 0 && sourceSampleRate > 0)
  18546. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18547. positionableSource->setNextReadPosition (newPosition);
  18548. }
  18549. }
  18550. int AudioTransportSource::getNextReadPosition() const
  18551. {
  18552. if (positionableSource != 0)
  18553. {
  18554. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18555. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18556. }
  18557. return 0;
  18558. }
  18559. int AudioTransportSource::getTotalLength() const
  18560. {
  18561. const ScopedLock sl (callbackLock);
  18562. if (positionableSource != 0)
  18563. {
  18564. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18565. return roundToInt (positionableSource->getTotalLength() * ratio);
  18566. }
  18567. return 0;
  18568. }
  18569. bool AudioTransportSource::isLooping() const
  18570. {
  18571. const ScopedLock sl (callbackLock);
  18572. return positionableSource != 0
  18573. && positionableSource->isLooping();
  18574. }
  18575. void AudioTransportSource::setGain (const float newGain) throw()
  18576. {
  18577. gain = newGain;
  18578. }
  18579. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18580. double sampleRate_)
  18581. {
  18582. const ScopedLock sl (callbackLock);
  18583. sampleRate = sampleRate_;
  18584. blockSize = samplesPerBlockExpected;
  18585. if (masterSource != 0)
  18586. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18587. if (resamplerSource != 0 && sourceSampleRate != 0)
  18588. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18589. isPrepared = true;
  18590. }
  18591. void AudioTransportSource::releaseResources()
  18592. {
  18593. const ScopedLock sl (callbackLock);
  18594. if (masterSource != 0)
  18595. masterSource->releaseResources();
  18596. isPrepared = false;
  18597. }
  18598. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18599. {
  18600. const ScopedLock sl (callbackLock);
  18601. inputStreamEOF = false;
  18602. if (masterSource != 0 && ! stopped)
  18603. {
  18604. masterSource->getNextAudioBlock (info);
  18605. if (! playing)
  18606. {
  18607. // just stopped playing, so fade out the last block..
  18608. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18609. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18610. if (info.numSamples > 256)
  18611. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18612. }
  18613. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18614. && ! positionableSource->isLooping())
  18615. {
  18616. playing = false;
  18617. inputStreamEOF = true;
  18618. sendChangeMessage (this);
  18619. }
  18620. stopped = ! playing;
  18621. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18622. {
  18623. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18624. lastGain, gain);
  18625. }
  18626. }
  18627. else
  18628. {
  18629. info.clearActiveBufferRegion();
  18630. stopped = true;
  18631. }
  18632. lastGain = gain;
  18633. }
  18634. END_JUCE_NAMESPACE
  18635. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18636. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18637. BEGIN_JUCE_NAMESPACE
  18638. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18639. public Thread,
  18640. private Timer
  18641. {
  18642. public:
  18643. SharedBufferingAudioSourceThread()
  18644. : Thread ("Audio Buffer")
  18645. {
  18646. }
  18647. ~SharedBufferingAudioSourceThread()
  18648. {
  18649. stopThread (10000);
  18650. clearSingletonInstance();
  18651. }
  18652. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18653. void addSource (BufferingAudioSource* source)
  18654. {
  18655. const ScopedLock sl (lock);
  18656. if (! sources.contains ((void*) source))
  18657. {
  18658. sources.add ((void*) source);
  18659. startThread();
  18660. stopTimer();
  18661. }
  18662. notify();
  18663. }
  18664. void removeSource (BufferingAudioSource* source)
  18665. {
  18666. const ScopedLock sl (lock);
  18667. sources.removeValue ((void*) source);
  18668. if (sources.size() == 0)
  18669. startTimer (5000);
  18670. }
  18671. private:
  18672. VoidArray sources;
  18673. CriticalSection lock;
  18674. void run()
  18675. {
  18676. while (! threadShouldExit())
  18677. {
  18678. bool busy = false;
  18679. for (int i = sources.size(); --i >= 0;)
  18680. {
  18681. if (threadShouldExit())
  18682. return;
  18683. const ScopedLock sl (lock);
  18684. BufferingAudioSource* const b = (BufferingAudioSource*) sources[i];
  18685. if (b != 0 && b->readNextBufferChunk())
  18686. busy = true;
  18687. }
  18688. if (! busy)
  18689. wait (500);
  18690. }
  18691. }
  18692. void timerCallback()
  18693. {
  18694. stopTimer();
  18695. if (sources.size() == 0)
  18696. deleteInstance();
  18697. }
  18698. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18699. const SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18700. };
  18701. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18702. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18703. const bool deleteSourceWhenDeleted_,
  18704. int numberOfSamplesToBuffer_)
  18705. : source (source_),
  18706. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18707. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18708. buffer (2, 0),
  18709. bufferValidStart (0),
  18710. bufferValidEnd (0),
  18711. nextPlayPos (0),
  18712. wasSourceLooping (false)
  18713. {
  18714. jassert (source_ != 0);
  18715. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18716. // not using a larger buffer..
  18717. }
  18718. BufferingAudioSource::~BufferingAudioSource()
  18719. {
  18720. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18721. if (thread != 0)
  18722. thread->removeSource (this);
  18723. if (deleteSourceWhenDeleted)
  18724. delete source;
  18725. }
  18726. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18727. {
  18728. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18729. sampleRate = sampleRate_;
  18730. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18731. buffer.clear();
  18732. bufferValidStart = 0;
  18733. bufferValidEnd = 0;
  18734. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18735. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18736. buffer.getNumSamples() / 2))
  18737. {
  18738. SharedBufferingAudioSourceThread::getInstance()->notify();
  18739. Thread::sleep (5);
  18740. }
  18741. }
  18742. void BufferingAudioSource::releaseResources()
  18743. {
  18744. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18745. if (thread != 0)
  18746. thread->removeSource (this);
  18747. buffer.setSize (2, 0);
  18748. source->releaseResources();
  18749. }
  18750. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18751. {
  18752. const ScopedLock sl (bufferStartPosLock);
  18753. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18754. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18755. if (validStart == validEnd)
  18756. {
  18757. // total cache miss
  18758. info.clearActiveBufferRegion();
  18759. }
  18760. else
  18761. {
  18762. if (validStart > 0)
  18763. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18764. if (validEnd < info.numSamples)
  18765. info.buffer->clear (info.startSample + validEnd,
  18766. info.numSamples - validEnd); // partial cache miss at end
  18767. if (validStart < validEnd)
  18768. {
  18769. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18770. {
  18771. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18772. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18773. if (startBufferIndex < endBufferIndex)
  18774. {
  18775. info.buffer->copyFrom (chan, info.startSample + validStart,
  18776. buffer,
  18777. chan, startBufferIndex,
  18778. validEnd - validStart);
  18779. }
  18780. else
  18781. {
  18782. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18783. info.buffer->copyFrom (chan, info.startSample + validStart,
  18784. buffer,
  18785. chan, startBufferIndex,
  18786. initialSize);
  18787. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18788. buffer,
  18789. chan, 0,
  18790. (validEnd - validStart) - initialSize);
  18791. }
  18792. }
  18793. }
  18794. nextPlayPos += info.numSamples;
  18795. if (source->isLooping() && nextPlayPos > 0)
  18796. nextPlayPos %= source->getTotalLength();
  18797. }
  18798. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18799. if (thread != 0)
  18800. thread->notify();
  18801. }
  18802. int BufferingAudioSource::getNextReadPosition() const
  18803. {
  18804. return (source->isLooping() && nextPlayPos > 0)
  18805. ? nextPlayPos % source->getTotalLength()
  18806. : nextPlayPos;
  18807. }
  18808. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18809. {
  18810. const ScopedLock sl (bufferStartPosLock);
  18811. nextPlayPos = newPosition;
  18812. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18813. if (thread != 0)
  18814. thread->notify();
  18815. }
  18816. bool BufferingAudioSource::readNextBufferChunk()
  18817. {
  18818. bufferStartPosLock.enter();
  18819. if (wasSourceLooping != isLooping())
  18820. {
  18821. wasSourceLooping = isLooping();
  18822. bufferValidStart = 0;
  18823. bufferValidEnd = 0;
  18824. }
  18825. int newBVS = jmax (0, nextPlayPos);
  18826. int newBVE = newBVS + buffer.getNumSamples() - 4;
  18827. int sectionToReadStart = 0;
  18828. int sectionToReadEnd = 0;
  18829. const int maxChunkSize = 2048;
  18830. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18831. {
  18832. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18833. sectionToReadStart = newBVS;
  18834. sectionToReadEnd = newBVE;
  18835. bufferValidStart = 0;
  18836. bufferValidEnd = 0;
  18837. }
  18838. else if (abs (newBVS - bufferValidStart) > 512
  18839. || abs (newBVE - bufferValidEnd) > 512)
  18840. {
  18841. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18842. sectionToReadStart = bufferValidEnd;
  18843. sectionToReadEnd = newBVE;
  18844. bufferValidStart = newBVS;
  18845. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18846. }
  18847. bufferStartPosLock.exit();
  18848. if (sectionToReadStart != sectionToReadEnd)
  18849. {
  18850. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18851. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18852. if (bufferIndexStart < bufferIndexEnd)
  18853. {
  18854. readBufferSection (sectionToReadStart,
  18855. sectionToReadEnd - sectionToReadStart,
  18856. bufferIndexStart);
  18857. }
  18858. else
  18859. {
  18860. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18861. readBufferSection (sectionToReadStart,
  18862. initialSize,
  18863. bufferIndexStart);
  18864. readBufferSection (sectionToReadStart + initialSize,
  18865. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18866. 0);
  18867. }
  18868. const ScopedLock sl2 (bufferStartPosLock);
  18869. bufferValidStart = newBVS;
  18870. bufferValidEnd = newBVE;
  18871. return true;
  18872. }
  18873. else
  18874. {
  18875. return false;
  18876. }
  18877. }
  18878. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18879. {
  18880. if (source->getNextReadPosition() != start)
  18881. source->setNextReadPosition (start);
  18882. AudioSourceChannelInfo info;
  18883. info.buffer = &buffer;
  18884. info.startSample = bufferOffset;
  18885. info.numSamples = length;
  18886. source->getNextAudioBlock (info);
  18887. }
  18888. END_JUCE_NAMESPACE
  18889. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18890. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18891. BEGIN_JUCE_NAMESPACE
  18892. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18893. const bool deleteSourceWhenDeleted_)
  18894. : requiredNumberOfChannels (2),
  18895. source (source_),
  18896. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18897. buffer (2, 16)
  18898. {
  18899. remappedInfo.buffer = &buffer;
  18900. remappedInfo.startSample = 0;
  18901. }
  18902. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18903. {
  18904. if (deleteSourceWhenDeleted)
  18905. delete source;
  18906. }
  18907. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18908. {
  18909. const ScopedLock sl (lock);
  18910. requiredNumberOfChannels = requiredNumberOfChannels_;
  18911. }
  18912. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18913. {
  18914. const ScopedLock sl (lock);
  18915. remappedInputs.clear();
  18916. remappedOutputs.clear();
  18917. }
  18918. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18919. {
  18920. const ScopedLock sl (lock);
  18921. while (remappedInputs.size() < destIndex)
  18922. remappedInputs.add (-1);
  18923. remappedInputs.set (destIndex, sourceIndex);
  18924. }
  18925. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18926. {
  18927. const ScopedLock sl (lock);
  18928. while (remappedOutputs.size() < sourceIndex)
  18929. remappedOutputs.add (-1);
  18930. remappedOutputs.set (sourceIndex, destIndex);
  18931. }
  18932. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18933. {
  18934. const ScopedLock sl (lock);
  18935. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18936. return remappedInputs.getUnchecked (inputChannelIndex);
  18937. return -1;
  18938. }
  18939. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18940. {
  18941. const ScopedLock sl (lock);
  18942. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18943. return remappedOutputs .getUnchecked (outputChannelIndex);
  18944. return -1;
  18945. }
  18946. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18947. {
  18948. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18949. }
  18950. void ChannelRemappingAudioSource::releaseResources()
  18951. {
  18952. source->releaseResources();
  18953. }
  18954. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18955. {
  18956. const ScopedLock sl (lock);
  18957. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18958. const int numChans = bufferToFill.buffer->getNumChannels();
  18959. int i;
  18960. for (i = 0; i < buffer.getNumChannels(); ++i)
  18961. {
  18962. const int remappedChan = getRemappedInputChannel (i);
  18963. if (remappedChan >= 0 && remappedChan < numChans)
  18964. {
  18965. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18966. remappedChan,
  18967. bufferToFill.startSample,
  18968. bufferToFill.numSamples);
  18969. }
  18970. else
  18971. {
  18972. buffer.clear (i, 0, bufferToFill.numSamples);
  18973. }
  18974. }
  18975. remappedInfo.numSamples = bufferToFill.numSamples;
  18976. source->getNextAudioBlock (remappedInfo);
  18977. bufferToFill.clearActiveBufferRegion();
  18978. for (i = 0; i < requiredNumberOfChannels; ++i)
  18979. {
  18980. const int remappedChan = getRemappedOutputChannel (i);
  18981. if (remappedChan >= 0 && remappedChan < numChans)
  18982. {
  18983. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18984. buffer, i, 0, bufferToFill.numSamples);
  18985. }
  18986. }
  18987. }
  18988. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18989. {
  18990. XmlElement* e = new XmlElement (T("MAPPINGS"));
  18991. String ins, outs;
  18992. int i;
  18993. const ScopedLock sl (lock);
  18994. for (i = 0; i < remappedInputs.size(); ++i)
  18995. ins << remappedInputs.getUnchecked(i) << T(' ');
  18996. for (i = 0; i < remappedOutputs.size(); ++i)
  18997. outs << remappedOutputs.getUnchecked(i) << T(' ');
  18998. e->setAttribute (T("inputs"), ins.trimEnd());
  18999. e->setAttribute (T("outputs"), outs.trimEnd());
  19000. return e;
  19001. }
  19002. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  19003. {
  19004. if (e.hasTagName (T("MAPPINGS")))
  19005. {
  19006. const ScopedLock sl (lock);
  19007. clearAllMappings();
  19008. StringArray ins, outs;
  19009. ins.addTokens (e.getStringAttribute (T("inputs")), false);
  19010. outs.addTokens (e.getStringAttribute (T("outputs")), false);
  19011. int i;
  19012. for (i = 0; i < ins.size(); ++i)
  19013. remappedInputs.add (ins[i].getIntValue());
  19014. for (i = 0; i < outs.size(); ++i)
  19015. remappedOutputs.add (outs[i].getIntValue());
  19016. }
  19017. }
  19018. END_JUCE_NAMESPACE
  19019. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  19020. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  19021. BEGIN_JUCE_NAMESPACE
  19022. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  19023. const bool deleteInputWhenDeleted_)
  19024. : input (inputSource),
  19025. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  19026. {
  19027. jassert (inputSource != 0);
  19028. for (int i = 2; --i >= 0;)
  19029. iirFilters.add (new IIRFilter());
  19030. }
  19031. IIRFilterAudioSource::~IIRFilterAudioSource()
  19032. {
  19033. if (deleteInputWhenDeleted)
  19034. delete input;
  19035. }
  19036. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  19037. {
  19038. for (int i = iirFilters.size(); --i >= 0;)
  19039. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  19040. }
  19041. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  19042. {
  19043. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  19044. for (int i = iirFilters.size(); --i >= 0;)
  19045. iirFilters.getUnchecked(i)->reset();
  19046. }
  19047. void IIRFilterAudioSource::releaseResources()
  19048. {
  19049. input->releaseResources();
  19050. }
  19051. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  19052. {
  19053. input->getNextAudioBlock (bufferToFill);
  19054. const int numChannels = bufferToFill.buffer->getNumChannels();
  19055. while (numChannels > iirFilters.size())
  19056. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  19057. for (int i = 0; i < numChannels; ++i)
  19058. iirFilters.getUnchecked(i)
  19059. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  19060. bufferToFill.numSamples);
  19061. }
  19062. END_JUCE_NAMESPACE
  19063. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  19064. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  19065. BEGIN_JUCE_NAMESPACE
  19066. MixerAudioSource::MixerAudioSource()
  19067. : tempBuffer (2, 0),
  19068. currentSampleRate (0.0),
  19069. bufferSizeExpected (0)
  19070. {
  19071. }
  19072. MixerAudioSource::~MixerAudioSource()
  19073. {
  19074. removeAllInputs();
  19075. }
  19076. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  19077. {
  19078. if (input != 0 && ! inputs.contains (input))
  19079. {
  19080. lock.enter();
  19081. double localRate = currentSampleRate;
  19082. int localBufferSize = bufferSizeExpected;
  19083. lock.exit();
  19084. if (localRate != 0.0)
  19085. input->prepareToPlay (localBufferSize, localRate);
  19086. const ScopedLock sl (lock);
  19087. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  19088. inputs.add (input);
  19089. }
  19090. }
  19091. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  19092. {
  19093. if (input != 0)
  19094. {
  19095. lock.enter();
  19096. const int index = inputs.indexOf ((void*) input);
  19097. if (index >= 0)
  19098. {
  19099. inputsToDelete.shiftBits (index, 1);
  19100. inputs.remove (index);
  19101. }
  19102. lock.exit();
  19103. if (index >= 0)
  19104. {
  19105. input->releaseResources();
  19106. if (deleteInput)
  19107. delete input;
  19108. }
  19109. }
  19110. }
  19111. void MixerAudioSource::removeAllInputs()
  19112. {
  19113. lock.enter();
  19114. VoidArray inputsCopy (inputs);
  19115. BitArray inputsToDeleteCopy (inputsToDelete);
  19116. inputs.clear();
  19117. lock.exit();
  19118. for (int i = inputsCopy.size(); --i >= 0;)
  19119. if (inputsToDeleteCopy[i])
  19120. delete (AudioSource*) inputsCopy[i];
  19121. }
  19122. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  19123. {
  19124. tempBuffer.setSize (2, samplesPerBlockExpected);
  19125. const ScopedLock sl (lock);
  19126. currentSampleRate = sampleRate;
  19127. bufferSizeExpected = samplesPerBlockExpected;
  19128. for (int i = inputs.size(); --i >= 0;)
  19129. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  19130. sampleRate);
  19131. }
  19132. void MixerAudioSource::releaseResources()
  19133. {
  19134. const ScopedLock sl (lock);
  19135. for (int i = inputs.size(); --i >= 0;)
  19136. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  19137. tempBuffer.setSize (2, 0);
  19138. currentSampleRate = 0;
  19139. bufferSizeExpected = 0;
  19140. }
  19141. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19142. {
  19143. const ScopedLock sl (lock);
  19144. if (inputs.size() > 0)
  19145. {
  19146. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  19147. if (inputs.size() > 1)
  19148. {
  19149. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  19150. info.buffer->getNumSamples());
  19151. AudioSourceChannelInfo info2;
  19152. info2.buffer = &tempBuffer;
  19153. info2.numSamples = info.numSamples;
  19154. info2.startSample = 0;
  19155. for (int i = 1; i < inputs.size(); ++i)
  19156. {
  19157. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  19158. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  19159. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  19160. }
  19161. }
  19162. }
  19163. else
  19164. {
  19165. info.clearActiveBufferRegion();
  19166. }
  19167. }
  19168. END_JUCE_NAMESPACE
  19169. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  19170. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  19171. BEGIN_JUCE_NAMESPACE
  19172. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  19173. const bool deleteInputWhenDeleted_)
  19174. : input (inputSource),
  19175. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  19176. ratio (1.0),
  19177. lastRatio (1.0),
  19178. buffer (2, 0),
  19179. sampsInBuffer (0)
  19180. {
  19181. jassert (input != 0);
  19182. }
  19183. ResamplingAudioSource::~ResamplingAudioSource()
  19184. {
  19185. if (deleteInputWhenDeleted)
  19186. delete input;
  19187. }
  19188. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  19189. {
  19190. jassert (samplesInPerOutputSample > 0);
  19191. const ScopedLock sl (ratioLock);
  19192. ratio = jmax (0.0, samplesInPerOutputSample);
  19193. }
  19194. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  19195. double sampleRate)
  19196. {
  19197. const ScopedLock sl (ratioLock);
  19198. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  19199. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  19200. buffer.clear();
  19201. sampsInBuffer = 0;
  19202. bufferPos = 0;
  19203. subSampleOffset = 0.0;
  19204. createLowPass (ratio);
  19205. resetFilters();
  19206. }
  19207. void ResamplingAudioSource::releaseResources()
  19208. {
  19209. input->releaseResources();
  19210. buffer.setSize (2, 0);
  19211. }
  19212. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19213. {
  19214. const ScopedLock sl (ratioLock);
  19215. if (lastRatio != ratio)
  19216. {
  19217. createLowPass (ratio);
  19218. lastRatio = ratio;
  19219. }
  19220. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  19221. int bufferSize = buffer.getNumSamples();
  19222. if (bufferSize < sampsNeeded + 8)
  19223. {
  19224. bufferPos %= bufferSize;
  19225. bufferSize = sampsNeeded + 32;
  19226. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  19227. }
  19228. bufferPos %= bufferSize;
  19229. int endOfBufferPos = bufferPos + sampsInBuffer;
  19230. while (sampsNeeded > sampsInBuffer)
  19231. {
  19232. endOfBufferPos %= bufferSize;
  19233. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  19234. bufferSize - endOfBufferPos);
  19235. AudioSourceChannelInfo readInfo;
  19236. readInfo.buffer = &buffer;
  19237. readInfo.numSamples = numToDo;
  19238. readInfo.startSample = endOfBufferPos;
  19239. input->getNextAudioBlock (readInfo);
  19240. if (ratio > 1.0001)
  19241. {
  19242. // for down-sampling, pre-apply the filter..
  19243. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19244. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  19245. }
  19246. sampsInBuffer += numToDo;
  19247. endOfBufferPos += numToDo;
  19248. }
  19249. float* dl = info.buffer->getSampleData (0, info.startSample);
  19250. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  19251. const float* const bl = buffer.getSampleData (0, 0);
  19252. const float* const br = buffer.getSampleData (1, 0);
  19253. int nextPos = (bufferPos + 1) % bufferSize;
  19254. for (int m = info.numSamples; --m >= 0;)
  19255. {
  19256. const float alpha = (float) subSampleOffset;
  19257. const float invAlpha = 1.0f - alpha;
  19258. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  19259. if (dr != 0)
  19260. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  19261. subSampleOffset += ratio;
  19262. jassert (sampsInBuffer > 0);
  19263. while (subSampleOffset >= 1.0)
  19264. {
  19265. if (++bufferPos >= bufferSize)
  19266. bufferPos = 0;
  19267. --sampsInBuffer;
  19268. nextPos = (bufferPos + 1) % bufferSize;
  19269. subSampleOffset -= 1.0;
  19270. }
  19271. }
  19272. if (ratio < 0.9999)
  19273. {
  19274. // for up-sampling, apply the filter after transposing..
  19275. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19276. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  19277. }
  19278. else if (ratio <= 1.0001)
  19279. {
  19280. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  19281. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19282. {
  19283. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  19284. FilterState& fs = filterStates[i];
  19285. if (info.numSamples > 1)
  19286. {
  19287. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  19288. }
  19289. else
  19290. {
  19291. fs.y2 = fs.y1;
  19292. fs.x2 = fs.x1;
  19293. }
  19294. fs.y1 = fs.x1 = *endOfBuffer;
  19295. }
  19296. }
  19297. jassert (sampsInBuffer >= 0);
  19298. }
  19299. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19300. {
  19301. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19302. : 0.5 * frequencyRatio;
  19303. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19304. const double nSquared = n * n;
  19305. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19306. setFilterCoefficients (c1,
  19307. c1 * 2.0f,
  19308. c1,
  19309. 1.0,
  19310. c1 * 2.0 * (1.0 - nSquared),
  19311. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19312. }
  19313. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19314. {
  19315. const double a = 1.0 / c4;
  19316. c1 *= a;
  19317. c2 *= a;
  19318. c3 *= a;
  19319. c5 *= a;
  19320. c6 *= a;
  19321. coefficients[0] = c1;
  19322. coefficients[1] = c2;
  19323. coefficients[2] = c3;
  19324. coefficients[3] = c4;
  19325. coefficients[4] = c5;
  19326. coefficients[5] = c6;
  19327. }
  19328. void ResamplingAudioSource::resetFilters()
  19329. {
  19330. zeromem (filterStates, sizeof (filterStates));
  19331. }
  19332. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19333. {
  19334. while (--num >= 0)
  19335. {
  19336. const double in = *samples;
  19337. double out = coefficients[0] * in
  19338. + coefficients[1] * fs.x1
  19339. + coefficients[2] * fs.x2
  19340. - coefficients[4] * fs.y1
  19341. - coefficients[5] * fs.y2;
  19342. #if JUCE_INTEL
  19343. if (! (out < -1.0e-8 || out > 1.0e-8))
  19344. out = 0;
  19345. #endif
  19346. fs.x2 = fs.x1;
  19347. fs.x1 = in;
  19348. fs.y2 = fs.y1;
  19349. fs.y1 = out;
  19350. *samples++ = (float) out;
  19351. }
  19352. }
  19353. END_JUCE_NAMESPACE
  19354. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19355. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19356. BEGIN_JUCE_NAMESPACE
  19357. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19358. : frequency (1000.0),
  19359. sampleRate (44100.0),
  19360. currentPhase (0.0),
  19361. phasePerSample (0.0),
  19362. amplitude (0.5f)
  19363. {
  19364. }
  19365. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19366. {
  19367. }
  19368. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19369. {
  19370. amplitude = newAmplitude;
  19371. }
  19372. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19373. {
  19374. frequency = newFrequencyHz;
  19375. phasePerSample = 0.0;
  19376. }
  19377. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19378. double sampleRate_)
  19379. {
  19380. currentPhase = 0.0;
  19381. phasePerSample = 0.0;
  19382. sampleRate = sampleRate_;
  19383. }
  19384. void ToneGeneratorAudioSource::releaseResources()
  19385. {
  19386. }
  19387. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19388. {
  19389. if (phasePerSample == 0.0)
  19390. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19391. for (int i = 0; i < info.numSamples; ++i)
  19392. {
  19393. const float sample = amplitude * (float) sin (currentPhase);
  19394. currentPhase += phasePerSample;
  19395. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19396. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19397. }
  19398. }
  19399. END_JUCE_NAMESPACE
  19400. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19401. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19402. BEGIN_JUCE_NAMESPACE
  19403. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19404. : sampleRate (0),
  19405. bufferSize (0),
  19406. useDefaultInputChannels (true),
  19407. useDefaultOutputChannels (true)
  19408. {
  19409. }
  19410. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19411. {
  19412. return outputDeviceName == other.outputDeviceName
  19413. && inputDeviceName == other.inputDeviceName
  19414. && sampleRate == other.sampleRate
  19415. && bufferSize == other.bufferSize
  19416. && inputChannels == other.inputChannels
  19417. && useDefaultInputChannels == other.useDefaultInputChannels
  19418. && outputChannels == other.outputChannels
  19419. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19420. }
  19421. AudioDeviceManager::AudioDeviceManager()
  19422. : currentAudioDevice (0),
  19423. numInputChansNeeded (0),
  19424. numOutputChansNeeded (2),
  19425. listNeedsScanning (true),
  19426. useInputNames (false),
  19427. inputLevelMeasurementEnabledCount (0),
  19428. inputLevel (0),
  19429. tempBuffer (2, 2),
  19430. defaultMidiOutput (0),
  19431. cpuUsageMs (0),
  19432. timeToCpuScale (0)
  19433. {
  19434. callbackHandler.owner = this;
  19435. }
  19436. AudioDeviceManager::~AudioDeviceManager()
  19437. {
  19438. currentAudioDevice = 0;
  19439. defaultMidiOutput = 0;
  19440. }
  19441. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19442. {
  19443. if (availableDeviceTypes.size() == 0)
  19444. {
  19445. createAudioDeviceTypes (availableDeviceTypes);
  19446. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19447. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19448. if (availableDeviceTypes.size() > 0)
  19449. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19450. }
  19451. }
  19452. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19453. {
  19454. scanDevicesIfNeeded();
  19455. return availableDeviceTypes;
  19456. }
  19457. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19458. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19459. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19460. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19461. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19462. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19463. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19464. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19465. {
  19466. #if JUCE_WINDOWS
  19467. #if JUCE_WASAPI
  19468. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19469. list.add (juce_createAudioIODeviceType_WASAPI());
  19470. #endif
  19471. #if JUCE_DIRECTSOUND
  19472. list.add (juce_createAudioIODeviceType_DirectSound());
  19473. #endif
  19474. #if JUCE_ASIO
  19475. list.add (juce_createAudioIODeviceType_ASIO());
  19476. #endif
  19477. #endif
  19478. #if JUCE_MAC
  19479. list.add (juce_createAudioIODeviceType_CoreAudio());
  19480. #endif
  19481. #if JUCE_IPHONE
  19482. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19483. #endif
  19484. #if JUCE_LINUX && JUCE_ALSA
  19485. list.add (juce_createAudioIODeviceType_ALSA());
  19486. #endif
  19487. #if JUCE_LINUX && JUCE_JACK
  19488. list.add (juce_createAudioIODeviceType_JACK());
  19489. #endif
  19490. }
  19491. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19492. const int numOutputChannelsNeeded,
  19493. const XmlElement* const e,
  19494. const bool selectDefaultDeviceOnFailure,
  19495. const String& preferredDefaultDeviceName,
  19496. const AudioDeviceSetup* preferredSetupOptions)
  19497. {
  19498. scanDevicesIfNeeded();
  19499. numInputChansNeeded = numInputChannelsNeeded;
  19500. numOutputChansNeeded = numOutputChannelsNeeded;
  19501. if (e != 0 && e->hasTagName (T("DEVICESETUP")))
  19502. {
  19503. lastExplicitSettings = new XmlElement (*e);
  19504. String error;
  19505. AudioDeviceSetup setup;
  19506. if (preferredSetupOptions != 0)
  19507. setup = *preferredSetupOptions;
  19508. if (e->getStringAttribute (T("audioDeviceName")).isNotEmpty())
  19509. {
  19510. setup.inputDeviceName = setup.outputDeviceName
  19511. = e->getStringAttribute (T("audioDeviceName"));
  19512. }
  19513. else
  19514. {
  19515. setup.inputDeviceName = e->getStringAttribute (T("audioInputDeviceName"));
  19516. setup.outputDeviceName = e->getStringAttribute (T("audioOutputDeviceName"));
  19517. }
  19518. currentDeviceType = e->getStringAttribute (T("deviceType"));
  19519. if (currentDeviceType.isEmpty())
  19520. {
  19521. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19522. if (type != 0)
  19523. currentDeviceType = type->getTypeName();
  19524. else if (availableDeviceTypes.size() > 0)
  19525. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19526. }
  19527. setup.bufferSize = e->getIntAttribute (T("audioDeviceBufferSize"));
  19528. setup.sampleRate = e->getDoubleAttribute (T("audioDeviceRate"));
  19529. setup.inputChannels.parseString (e->getStringAttribute (T("audioDeviceInChans"), T("11")), 2);
  19530. setup.outputChannels.parseString (e->getStringAttribute (T("audioDeviceOutChans"), T("11")), 2);
  19531. setup.useDefaultInputChannels = ! e->hasAttribute (T("audioDeviceInChans"));
  19532. setup.useDefaultOutputChannels = ! e->hasAttribute (T("audioDeviceOutChans"));
  19533. error = setAudioDeviceSetup (setup, true);
  19534. midiInsFromXml.clear();
  19535. forEachXmlChildElementWithTagName (*e, c, T("MIDIINPUT"))
  19536. midiInsFromXml.add (c->getStringAttribute (T("name")));
  19537. const StringArray allMidiIns (MidiInput::getDevices());
  19538. for (int i = allMidiIns.size(); --i >= 0;)
  19539. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19540. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19541. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19542. false, preferredDefaultDeviceName);
  19543. setDefaultMidiOutput (e->getStringAttribute (T("defaultMidiOutput")));
  19544. return error;
  19545. }
  19546. else
  19547. {
  19548. AudioDeviceSetup setup;
  19549. if (preferredSetupOptions != 0)
  19550. {
  19551. setup = *preferredSetupOptions;
  19552. }
  19553. else if (preferredDefaultDeviceName.isNotEmpty())
  19554. {
  19555. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19556. {
  19557. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19558. StringArray outs (type->getDeviceNames (false));
  19559. int i;
  19560. for (i = 0; i < outs.size(); ++i)
  19561. {
  19562. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19563. {
  19564. setup.outputDeviceName = outs[i];
  19565. break;
  19566. }
  19567. }
  19568. StringArray ins (type->getDeviceNames (true));
  19569. for (i = 0; i < ins.size(); ++i)
  19570. {
  19571. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19572. {
  19573. setup.inputDeviceName = ins[i];
  19574. break;
  19575. }
  19576. }
  19577. }
  19578. }
  19579. insertDefaultDeviceNames (setup);
  19580. return setAudioDeviceSetup (setup, false);
  19581. }
  19582. }
  19583. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19584. {
  19585. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19586. if (type != 0)
  19587. {
  19588. if (setup.outputDeviceName.isEmpty())
  19589. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19590. if (setup.inputDeviceName.isEmpty())
  19591. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19592. }
  19593. }
  19594. XmlElement* AudioDeviceManager::createStateXml() const
  19595. {
  19596. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19597. }
  19598. void AudioDeviceManager::scanDevicesIfNeeded()
  19599. {
  19600. if (listNeedsScanning)
  19601. {
  19602. listNeedsScanning = false;
  19603. createDeviceTypesIfNeeded();
  19604. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19605. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19606. }
  19607. }
  19608. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19609. {
  19610. scanDevicesIfNeeded();
  19611. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19612. {
  19613. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19614. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19615. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19616. {
  19617. return type;
  19618. }
  19619. }
  19620. return 0;
  19621. }
  19622. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19623. {
  19624. setup = currentSetup;
  19625. }
  19626. void AudioDeviceManager::deleteCurrentDevice()
  19627. {
  19628. currentAudioDevice = 0;
  19629. currentSetup.inputDeviceName = String::empty;
  19630. currentSetup.outputDeviceName = String::empty;
  19631. }
  19632. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19633. const bool treatAsChosenDevice)
  19634. {
  19635. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19636. {
  19637. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19638. && currentDeviceType != type)
  19639. {
  19640. currentDeviceType = type;
  19641. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19642. insertDefaultDeviceNames (s);
  19643. setAudioDeviceSetup (s, treatAsChosenDevice);
  19644. sendChangeMessage (this);
  19645. break;
  19646. }
  19647. }
  19648. }
  19649. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19650. {
  19651. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19652. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19653. return availableDeviceTypes[i];
  19654. return availableDeviceTypes[0];
  19655. }
  19656. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19657. const bool treatAsChosenDevice)
  19658. {
  19659. jassert (&newSetup != &currentSetup); // this will have no effect
  19660. if (newSetup == currentSetup && currentAudioDevice != 0)
  19661. return String::empty;
  19662. if (! (newSetup == currentSetup))
  19663. sendChangeMessage (this);
  19664. stopDevice();
  19665. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19666. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19667. String error;
  19668. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19669. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19670. {
  19671. deleteCurrentDevice();
  19672. if (treatAsChosenDevice)
  19673. updateXml();
  19674. return String::empty;
  19675. }
  19676. if (currentSetup.inputDeviceName != newInputDeviceName
  19677. || currentSetup.outputDeviceName != newOutputDeviceName
  19678. || currentAudioDevice == 0)
  19679. {
  19680. deleteCurrentDevice();
  19681. scanDevicesIfNeeded();
  19682. if (newOutputDeviceName.isNotEmpty()
  19683. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19684. {
  19685. return "No such device: " + newOutputDeviceName;
  19686. }
  19687. if (newInputDeviceName.isNotEmpty()
  19688. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19689. {
  19690. return "No such device: " + newInputDeviceName;
  19691. }
  19692. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19693. if (currentAudioDevice == 0)
  19694. 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!";
  19695. else
  19696. error = currentAudioDevice->getLastError();
  19697. if (error.isNotEmpty())
  19698. {
  19699. deleteCurrentDevice();
  19700. return error;
  19701. }
  19702. if (newSetup.useDefaultInputChannels)
  19703. {
  19704. inputChannels.clear();
  19705. inputChannels.setRange (0, numInputChansNeeded, true);
  19706. }
  19707. if (newSetup.useDefaultOutputChannels)
  19708. {
  19709. outputChannels.clear();
  19710. outputChannels.setRange (0, numOutputChansNeeded, true);
  19711. }
  19712. if (newInputDeviceName.isEmpty())
  19713. inputChannels.clear();
  19714. if (newOutputDeviceName.isEmpty())
  19715. outputChannels.clear();
  19716. }
  19717. if (! newSetup.useDefaultInputChannels)
  19718. inputChannels = newSetup.inputChannels;
  19719. if (! newSetup.useDefaultOutputChannels)
  19720. outputChannels = newSetup.outputChannels;
  19721. currentSetup = newSetup;
  19722. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19723. error = currentAudioDevice->open (inputChannels,
  19724. outputChannels,
  19725. currentSetup.sampleRate,
  19726. currentSetup.bufferSize);
  19727. if (error.isEmpty())
  19728. {
  19729. currentDeviceType = currentAudioDevice->getTypeName();
  19730. currentAudioDevice->start (&callbackHandler);
  19731. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19732. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19733. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19734. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19735. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19736. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19737. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19738. if (treatAsChosenDevice)
  19739. updateXml();
  19740. }
  19741. else
  19742. {
  19743. deleteCurrentDevice();
  19744. }
  19745. return error;
  19746. }
  19747. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19748. {
  19749. jassert (currentAudioDevice != 0);
  19750. if (rate > 0)
  19751. {
  19752. bool ok = false;
  19753. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19754. {
  19755. const double sr = currentAudioDevice->getSampleRate (i);
  19756. if (sr == rate)
  19757. ok = true;
  19758. }
  19759. if (! ok)
  19760. rate = 0;
  19761. }
  19762. if (rate == 0)
  19763. {
  19764. double lowestAbove44 = 0.0;
  19765. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19766. {
  19767. const double sr = currentAudioDevice->getSampleRate (i);
  19768. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19769. lowestAbove44 = sr;
  19770. }
  19771. if (lowestAbove44 == 0.0)
  19772. rate = currentAudioDevice->getSampleRate (0);
  19773. else
  19774. rate = lowestAbove44;
  19775. }
  19776. return rate;
  19777. }
  19778. void AudioDeviceManager::stopDevice()
  19779. {
  19780. if (currentAudioDevice != 0)
  19781. currentAudioDevice->stop();
  19782. testSound = 0;
  19783. }
  19784. void AudioDeviceManager::closeAudioDevice()
  19785. {
  19786. stopDevice();
  19787. currentAudioDevice = 0;
  19788. }
  19789. void AudioDeviceManager::restartLastAudioDevice()
  19790. {
  19791. if (currentAudioDevice == 0)
  19792. {
  19793. if (currentSetup.inputDeviceName.isEmpty()
  19794. && currentSetup.outputDeviceName.isEmpty())
  19795. {
  19796. // This method will only reload the last device that was running
  19797. // before closeAudioDevice() was called - you need to actually open
  19798. // one first, with setAudioDevice().
  19799. jassertfalse
  19800. return;
  19801. }
  19802. AudioDeviceSetup s (currentSetup);
  19803. setAudioDeviceSetup (s, false);
  19804. }
  19805. }
  19806. void AudioDeviceManager::updateXml()
  19807. {
  19808. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19809. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19810. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19811. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19812. if (currentAudioDevice != 0)
  19813. {
  19814. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19815. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19816. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19817. if (! currentSetup.useDefaultInputChannels)
  19818. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19819. if (! currentSetup.useDefaultOutputChannels)
  19820. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19821. }
  19822. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19823. {
  19824. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19825. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19826. }
  19827. if (midiInsFromXml.size() > 0)
  19828. {
  19829. // Add any midi devices that have been enabled before, but which aren't currently
  19830. // open because the device has been disconnected.
  19831. const StringArray availableMidiDevices (MidiInput::getDevices());
  19832. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19833. {
  19834. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19835. {
  19836. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19837. m->setAttribute ("name", midiInsFromXml[i]);
  19838. }
  19839. }
  19840. }
  19841. if (defaultMidiOutputName.isNotEmpty())
  19842. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19843. }
  19844. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19845. {
  19846. {
  19847. const ScopedLock sl (audioCallbackLock);
  19848. if (callbacks.contains (newCallback))
  19849. return;
  19850. }
  19851. if (currentAudioDevice != 0 && newCallback != 0)
  19852. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19853. const ScopedLock sl (audioCallbackLock);
  19854. callbacks.add (newCallback);
  19855. }
  19856. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19857. {
  19858. if (callback != 0)
  19859. {
  19860. bool needsDeinitialising = currentAudioDevice != 0;
  19861. {
  19862. const ScopedLock sl (audioCallbackLock);
  19863. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19864. callbacks.removeValue (callback);
  19865. }
  19866. if (needsDeinitialising)
  19867. callback->audioDeviceStopped();
  19868. }
  19869. }
  19870. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19871. int numInputChannels,
  19872. float** outputChannelData,
  19873. int numOutputChannels,
  19874. int numSamples)
  19875. {
  19876. const ScopedLock sl (audioCallbackLock);
  19877. if (inputLevelMeasurementEnabledCount > 0)
  19878. {
  19879. for (int j = 0; j < numSamples; ++j)
  19880. {
  19881. float s = 0;
  19882. for (int i = 0; i < numInputChannels; ++i)
  19883. s += fabsf (inputChannelData[i][j]);
  19884. s /= numInputChannels;
  19885. const double decayFactor = 0.99992;
  19886. if (s > inputLevel)
  19887. inputLevel = s;
  19888. else if (inputLevel > 0.001f)
  19889. inputLevel *= decayFactor;
  19890. else
  19891. inputLevel = 0;
  19892. }
  19893. }
  19894. if (callbacks.size() > 0)
  19895. {
  19896. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19897. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19898. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19899. outputChannelData, numOutputChannels, numSamples);
  19900. float** const tempChans = tempBuffer.getArrayOfChannels();
  19901. for (int i = callbacks.size(); --i > 0;)
  19902. {
  19903. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19904. tempChans, numOutputChannels, numSamples);
  19905. for (int chan = 0; chan < numOutputChannels; ++chan)
  19906. {
  19907. const float* const src = tempChans [chan];
  19908. float* const dst = outputChannelData [chan];
  19909. if (src != 0 && dst != 0)
  19910. for (int j = 0; j < numSamples; ++j)
  19911. dst[j] += src[j];
  19912. }
  19913. }
  19914. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19915. const double filterAmount = 0.2;
  19916. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19917. }
  19918. else
  19919. {
  19920. for (int i = 0; i < numOutputChannels; ++i)
  19921. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19922. }
  19923. if (testSound != 0)
  19924. {
  19925. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19926. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19927. for (int i = 0; i < numOutputChannels; ++i)
  19928. for (int j = 0; j < numSamps; ++j)
  19929. outputChannelData [i][j] += src[j];
  19930. testSoundPosition += numSamps;
  19931. if (testSoundPosition >= testSound->getNumSamples())
  19932. testSound = 0;
  19933. }
  19934. }
  19935. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19936. {
  19937. cpuUsageMs = 0;
  19938. const double sampleRate = device->getCurrentSampleRate();
  19939. const int blockSize = device->getCurrentBufferSizeSamples();
  19940. if (sampleRate > 0.0 && blockSize > 0)
  19941. {
  19942. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19943. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19944. }
  19945. {
  19946. const ScopedLock sl (audioCallbackLock);
  19947. for (int i = callbacks.size(); --i >= 0;)
  19948. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19949. }
  19950. sendChangeMessage (this);
  19951. }
  19952. void AudioDeviceManager::audioDeviceStoppedInt()
  19953. {
  19954. cpuUsageMs = 0;
  19955. timeToCpuScale = 0;
  19956. sendChangeMessage (this);
  19957. const ScopedLock sl (audioCallbackLock);
  19958. for (int i = callbacks.size(); --i >= 0;)
  19959. callbacks.getUnchecked(i)->audioDeviceStopped();
  19960. }
  19961. double AudioDeviceManager::getCpuUsage() const
  19962. {
  19963. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19964. }
  19965. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19966. const bool enabled)
  19967. {
  19968. if (enabled != isMidiInputEnabled (name))
  19969. {
  19970. if (enabled)
  19971. {
  19972. const int index = MidiInput::getDevices().indexOf (name);
  19973. if (index >= 0)
  19974. {
  19975. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19976. if (min != 0)
  19977. {
  19978. enabledMidiInputs.add (min);
  19979. min->start();
  19980. }
  19981. }
  19982. }
  19983. else
  19984. {
  19985. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19986. if (enabledMidiInputs[i]->getName() == name)
  19987. enabledMidiInputs.remove (i);
  19988. }
  19989. updateXml();
  19990. sendChangeMessage (this);
  19991. }
  19992. }
  19993. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19994. {
  19995. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19996. if (enabledMidiInputs[i]->getName() == name)
  19997. return true;
  19998. return false;
  19999. }
  20000. void AudioDeviceManager::addMidiInputCallback (const String& name,
  20001. MidiInputCallback* callback)
  20002. {
  20003. removeMidiInputCallback (name, callback);
  20004. if (name.isEmpty())
  20005. {
  20006. midiCallbacks.add (callback);
  20007. midiCallbackDevices.add (0);
  20008. }
  20009. else
  20010. {
  20011. for (int i = enabledMidiInputs.size(); --i >= 0;)
  20012. {
  20013. if (enabledMidiInputs[i]->getName() == name)
  20014. {
  20015. const ScopedLock sl (midiCallbackLock);
  20016. midiCallbacks.add (callback);
  20017. midiCallbackDevices.add (enabledMidiInputs[i]);
  20018. break;
  20019. }
  20020. }
  20021. }
  20022. }
  20023. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  20024. MidiInputCallback* /*callback*/)
  20025. {
  20026. const ScopedLock sl (midiCallbackLock);
  20027. for (int i = midiCallbacks.size(); --i >= 0;)
  20028. {
  20029. String devName;
  20030. if (midiCallbackDevices.getUnchecked(i) != 0)
  20031. devName = midiCallbackDevices.getUnchecked(i)->getName();
  20032. if (devName == name)
  20033. {
  20034. midiCallbacks.remove (i);
  20035. midiCallbackDevices.remove (i);
  20036. }
  20037. }
  20038. }
  20039. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  20040. const MidiMessage& message)
  20041. {
  20042. if (! message.isActiveSense())
  20043. {
  20044. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  20045. const ScopedLock sl (midiCallbackLock);
  20046. for (int i = midiCallbackDevices.size(); --i >= 0;)
  20047. {
  20048. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  20049. if (md == source || (md == 0 && isDefaultSource))
  20050. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  20051. }
  20052. }
  20053. }
  20054. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  20055. {
  20056. if (defaultMidiOutputName != deviceName)
  20057. {
  20058. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  20059. {
  20060. const ScopedLock sl (audioCallbackLock);
  20061. oldCallbacks = callbacks;
  20062. callbacks.clear();
  20063. }
  20064. if (currentAudioDevice != 0)
  20065. for (int i = oldCallbacks.size(); --i >= 0;)
  20066. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  20067. defaultMidiOutput = 0;
  20068. defaultMidiOutputName = deviceName;
  20069. if (deviceName.isNotEmpty())
  20070. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  20071. if (currentAudioDevice != 0)
  20072. for (int i = oldCallbacks.size(); --i >= 0;)
  20073. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  20074. {
  20075. const ScopedLock sl (audioCallbackLock);
  20076. callbacks = oldCallbacks;
  20077. }
  20078. updateXml();
  20079. sendChangeMessage (this);
  20080. }
  20081. }
  20082. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  20083. int numInputChannels,
  20084. float** outputChannelData,
  20085. int numOutputChannels,
  20086. int numSamples)
  20087. {
  20088. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  20089. }
  20090. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  20091. {
  20092. owner->audioDeviceAboutToStartInt (device);
  20093. }
  20094. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  20095. {
  20096. owner->audioDeviceStoppedInt();
  20097. }
  20098. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  20099. {
  20100. owner->handleIncomingMidiMessageInt (source, message);
  20101. }
  20102. void AudioDeviceManager::playTestSound()
  20103. {
  20104. {
  20105. audioCallbackLock.enter();
  20106. ScopedPointer <AudioSampleBuffer> oldSound (testSound);
  20107. audioCallbackLock.exit();
  20108. }
  20109. testSoundPosition = 0;
  20110. if (currentAudioDevice != 0)
  20111. {
  20112. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  20113. const int soundLength = (int) sampleRate;
  20114. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  20115. float* samples = newSound->getSampleData (0);
  20116. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  20117. const float amplitude = 0.5f;
  20118. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  20119. for (int i = 0; i < soundLength; ++i)
  20120. samples[i] = amplitude * (float) sin (i * phasePerSample);
  20121. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  20122. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  20123. const ScopedLock sl (audioCallbackLock);
  20124. testSound = newSound;
  20125. }
  20126. }
  20127. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  20128. {
  20129. const ScopedLock sl (audioCallbackLock);
  20130. if (enableMeasurement)
  20131. ++inputLevelMeasurementEnabledCount;
  20132. else
  20133. --inputLevelMeasurementEnabledCount;
  20134. inputLevel = 0;
  20135. }
  20136. double AudioDeviceManager::getCurrentInputLevel() const
  20137. {
  20138. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  20139. return inputLevel;
  20140. }
  20141. END_JUCE_NAMESPACE
  20142. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  20143. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  20144. BEGIN_JUCE_NAMESPACE
  20145. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  20146. : name (deviceName),
  20147. typeName (typeName_)
  20148. {
  20149. }
  20150. AudioIODevice::~AudioIODevice()
  20151. {
  20152. }
  20153. bool AudioIODevice::hasControlPanel() const
  20154. {
  20155. return false;
  20156. }
  20157. bool AudioIODevice::showControlPanel()
  20158. {
  20159. jassertfalse // this should only be called for devices which return true from
  20160. // their hasControlPanel() method.
  20161. return false;
  20162. }
  20163. END_JUCE_NAMESPACE
  20164. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  20165. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  20166. BEGIN_JUCE_NAMESPACE
  20167. AudioIODeviceType::AudioIODeviceType (const tchar* const name)
  20168. : typeName (name)
  20169. {
  20170. }
  20171. AudioIODeviceType::~AudioIODeviceType()
  20172. {
  20173. }
  20174. END_JUCE_NAMESPACE
  20175. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  20176. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  20177. BEGIN_JUCE_NAMESPACE
  20178. MidiOutput::MidiOutput() throw()
  20179. : Thread ("midi out"),
  20180. internal (0),
  20181. firstMessage (0)
  20182. {
  20183. }
  20184. MidiOutput::PendingMessage::PendingMessage (const uint8* const data,
  20185. const int len,
  20186. const double sampleNumber) throw()
  20187. : message (data, len, sampleNumber)
  20188. {
  20189. }
  20190. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  20191. const double millisecondCounterToStartAt,
  20192. double samplesPerSecondForBuffer) throw()
  20193. {
  20194. // You've got to call startBackgroundThread() for this to actually work..
  20195. jassert (isThreadRunning());
  20196. // this needs to be a value in the future - RTFM for this method!
  20197. jassert (millisecondCounterToStartAt > 0);
  20198. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  20199. MidiBuffer::Iterator i (buffer);
  20200. const uint8* data;
  20201. int len, time;
  20202. while (i.getNextEvent (data, len, time))
  20203. {
  20204. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  20205. PendingMessage* const m
  20206. = new PendingMessage (data, len, eventTime);
  20207. const ScopedLock sl (lock);
  20208. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  20209. {
  20210. m->next = firstMessage;
  20211. firstMessage = m;
  20212. }
  20213. else
  20214. {
  20215. PendingMessage* mm = firstMessage;
  20216. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  20217. mm = mm->next;
  20218. m->next = mm->next;
  20219. mm->next = m;
  20220. }
  20221. }
  20222. notify();
  20223. }
  20224. void MidiOutput::clearAllPendingMessages() throw()
  20225. {
  20226. const ScopedLock sl (lock);
  20227. while (firstMessage != 0)
  20228. {
  20229. PendingMessage* const m = firstMessage;
  20230. firstMessage = firstMessage->next;
  20231. delete m;
  20232. }
  20233. }
  20234. void MidiOutput::startBackgroundThread() throw()
  20235. {
  20236. startThread (9);
  20237. }
  20238. void MidiOutput::stopBackgroundThread() throw()
  20239. {
  20240. stopThread (5000);
  20241. }
  20242. void MidiOutput::run()
  20243. {
  20244. while (! threadShouldExit())
  20245. {
  20246. uint32 now = Time::getMillisecondCounter();
  20247. uint32 eventTime = 0;
  20248. uint32 timeToWait = 500;
  20249. lock.enter();
  20250. PendingMessage* message = firstMessage;
  20251. if (message != 0)
  20252. {
  20253. eventTime = roundToInt (message->message.getTimeStamp());
  20254. if (eventTime > now + 20)
  20255. {
  20256. timeToWait = eventTime - (now + 20);
  20257. message = 0;
  20258. }
  20259. else
  20260. {
  20261. firstMessage = message->next;
  20262. }
  20263. }
  20264. lock.exit();
  20265. if (message != 0)
  20266. {
  20267. if (eventTime > now)
  20268. {
  20269. Time::waitForMillisecondCounter (eventTime);
  20270. if (threadShouldExit())
  20271. break;
  20272. }
  20273. if (eventTime > now - 200)
  20274. sendMessageNow (message->message);
  20275. delete message;
  20276. }
  20277. else
  20278. {
  20279. jassert (timeToWait < 1000 * 30);
  20280. wait (timeToWait);
  20281. }
  20282. }
  20283. clearAllPendingMessages();
  20284. }
  20285. END_JUCE_NAMESPACE
  20286. /*** End of inlined file: juce_MidiOutput.cpp ***/
  20287. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  20288. BEGIN_JUCE_NAMESPACE
  20289. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20290. {
  20291. const double maxVal = (double) 0x7fff;
  20292. char* intData = (char*) dest;
  20293. if (dest != (void*) source || destBytesPerSample <= 4)
  20294. {
  20295. for (int i = 0; i < numSamples; ++i)
  20296. {
  20297. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20298. intData += destBytesPerSample;
  20299. }
  20300. }
  20301. else
  20302. {
  20303. intData += destBytesPerSample * numSamples;
  20304. for (int i = numSamples; --i >= 0;)
  20305. {
  20306. intData -= destBytesPerSample;
  20307. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20308. }
  20309. }
  20310. }
  20311. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20312. {
  20313. const double maxVal = (double) 0x7fff;
  20314. char* intData = (char*) dest;
  20315. if (dest != (void*) source || destBytesPerSample <= 4)
  20316. {
  20317. for (int i = 0; i < numSamples; ++i)
  20318. {
  20319. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20320. intData += destBytesPerSample;
  20321. }
  20322. }
  20323. else
  20324. {
  20325. intData += destBytesPerSample * numSamples;
  20326. for (int i = numSamples; --i >= 0;)
  20327. {
  20328. intData -= destBytesPerSample;
  20329. *(uint16*)intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20330. }
  20331. }
  20332. }
  20333. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20334. {
  20335. const double maxVal = (double) 0x7fffff;
  20336. char* intData = (char*) dest;
  20337. if (dest != (void*) source || destBytesPerSample <= 4)
  20338. {
  20339. for (int i = 0; i < numSamples; ++i)
  20340. {
  20341. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20342. intData += destBytesPerSample;
  20343. }
  20344. }
  20345. else
  20346. {
  20347. intData += destBytesPerSample * numSamples;
  20348. for (int i = numSamples; --i >= 0;)
  20349. {
  20350. intData -= destBytesPerSample;
  20351. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20352. }
  20353. }
  20354. }
  20355. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20356. {
  20357. const double maxVal = (double) 0x7fffff;
  20358. char* intData = (char*) dest;
  20359. if (dest != (void*) source || destBytesPerSample <= 4)
  20360. {
  20361. for (int i = 0; i < numSamples; ++i)
  20362. {
  20363. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20364. intData += destBytesPerSample;
  20365. }
  20366. }
  20367. else
  20368. {
  20369. intData += destBytesPerSample * numSamples;
  20370. for (int i = numSamples; --i >= 0;)
  20371. {
  20372. intData -= destBytesPerSample;
  20373. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20374. }
  20375. }
  20376. }
  20377. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20378. {
  20379. const double maxVal = (double) 0x7fffffff;
  20380. char* intData = (char*) dest;
  20381. if (dest != (void*) source || destBytesPerSample <= 4)
  20382. {
  20383. for (int i = 0; i < numSamples; ++i)
  20384. {
  20385. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20386. intData += destBytesPerSample;
  20387. }
  20388. }
  20389. else
  20390. {
  20391. intData += destBytesPerSample * numSamples;
  20392. for (int i = numSamples; --i >= 0;)
  20393. {
  20394. intData -= destBytesPerSample;
  20395. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20396. }
  20397. }
  20398. }
  20399. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20400. {
  20401. const double maxVal = (double) 0x7fffffff;
  20402. char* intData = (char*) dest;
  20403. if (dest != (void*) source || destBytesPerSample <= 4)
  20404. {
  20405. for (int i = 0; i < numSamples; ++i)
  20406. {
  20407. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20408. intData += destBytesPerSample;
  20409. }
  20410. }
  20411. else
  20412. {
  20413. intData += destBytesPerSample * numSamples;
  20414. for (int i = numSamples; --i >= 0;)
  20415. {
  20416. intData -= destBytesPerSample;
  20417. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20418. }
  20419. }
  20420. }
  20421. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20422. {
  20423. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20424. char* d = (char*) dest;
  20425. for (int i = 0; i < numSamples; ++i)
  20426. {
  20427. *(float*) d = source[i];
  20428. #if JUCE_BIG_ENDIAN
  20429. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20430. #endif
  20431. d += destBytesPerSample;
  20432. }
  20433. }
  20434. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20435. {
  20436. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20437. char* d = (char*) dest;
  20438. for (int i = 0; i < numSamples; ++i)
  20439. {
  20440. *(float*) d = source[i];
  20441. #if JUCE_LITTLE_ENDIAN
  20442. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20443. #endif
  20444. d += destBytesPerSample;
  20445. }
  20446. }
  20447. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20448. {
  20449. const float scale = 1.0f / 0x7fff;
  20450. const char* intData = (const char*) source;
  20451. if (source != (void*) dest || srcBytesPerSample >= 4)
  20452. {
  20453. for (int i = 0; i < numSamples; ++i)
  20454. {
  20455. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20456. intData += srcBytesPerSample;
  20457. }
  20458. }
  20459. else
  20460. {
  20461. intData += srcBytesPerSample * numSamples;
  20462. for (int i = numSamples; --i >= 0;)
  20463. {
  20464. intData -= srcBytesPerSample;
  20465. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20466. }
  20467. }
  20468. }
  20469. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20470. {
  20471. const float scale = 1.0f / 0x7fff;
  20472. const char* intData = (const char*) source;
  20473. if (source != (void*) dest || srcBytesPerSample >= 4)
  20474. {
  20475. for (int i = 0; i < numSamples; ++i)
  20476. {
  20477. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20478. intData += srcBytesPerSample;
  20479. }
  20480. }
  20481. else
  20482. {
  20483. intData += srcBytesPerSample * numSamples;
  20484. for (int i = numSamples; --i >= 0;)
  20485. {
  20486. intData -= srcBytesPerSample;
  20487. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20488. }
  20489. }
  20490. }
  20491. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20492. {
  20493. const float scale = 1.0f / 0x7fffff;
  20494. const char* intData = (const char*) source;
  20495. if (source != (void*) dest || srcBytesPerSample >= 4)
  20496. {
  20497. for (int i = 0; i < numSamples; ++i)
  20498. {
  20499. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20500. intData += srcBytesPerSample;
  20501. }
  20502. }
  20503. else
  20504. {
  20505. intData += srcBytesPerSample * numSamples;
  20506. for (int i = numSamples; --i >= 0;)
  20507. {
  20508. intData -= srcBytesPerSample;
  20509. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20510. }
  20511. }
  20512. }
  20513. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20514. {
  20515. const float scale = 1.0f / 0x7fffff;
  20516. const char* intData = (const char*) source;
  20517. if (source != (void*) dest || srcBytesPerSample >= 4)
  20518. {
  20519. for (int i = 0; i < numSamples; ++i)
  20520. {
  20521. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20522. intData += srcBytesPerSample;
  20523. }
  20524. }
  20525. else
  20526. {
  20527. intData += srcBytesPerSample * numSamples;
  20528. for (int i = numSamples; --i >= 0;)
  20529. {
  20530. intData -= srcBytesPerSample;
  20531. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20532. }
  20533. }
  20534. }
  20535. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20536. {
  20537. const float scale = 1.0f / 0x7fffffff;
  20538. const char* intData = (const char*) source;
  20539. if (source != (void*) dest || srcBytesPerSample >= 4)
  20540. {
  20541. for (int i = 0; i < numSamples; ++i)
  20542. {
  20543. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20544. intData += srcBytesPerSample;
  20545. }
  20546. }
  20547. else
  20548. {
  20549. intData += srcBytesPerSample * numSamples;
  20550. for (int i = numSamples; --i >= 0;)
  20551. {
  20552. intData -= srcBytesPerSample;
  20553. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20554. }
  20555. }
  20556. }
  20557. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20558. {
  20559. const float scale = 1.0f / 0x7fffffff;
  20560. const char* intData = (const char*) source;
  20561. if (source != (void*) dest || srcBytesPerSample >= 4)
  20562. {
  20563. for (int i = 0; i < numSamples; ++i)
  20564. {
  20565. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20566. intData += srcBytesPerSample;
  20567. }
  20568. }
  20569. else
  20570. {
  20571. intData += srcBytesPerSample * numSamples;
  20572. for (int i = numSamples; --i >= 0;)
  20573. {
  20574. intData -= srcBytesPerSample;
  20575. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20576. }
  20577. }
  20578. }
  20579. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20580. {
  20581. const char* s = (const char*) source;
  20582. for (int i = 0; i < numSamples; ++i)
  20583. {
  20584. dest[i] = *(float*)s;
  20585. #if JUCE_BIG_ENDIAN
  20586. uint32* const d = (uint32*) (dest + i);
  20587. *d = ByteOrder::swap (*d);
  20588. #endif
  20589. s += srcBytesPerSample;
  20590. }
  20591. }
  20592. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20593. {
  20594. const char* s = (const char*) source;
  20595. for (int i = 0; i < numSamples; ++i)
  20596. {
  20597. dest[i] = *(float*)s;
  20598. #if JUCE_LITTLE_ENDIAN
  20599. uint32* const d = (uint32*) (dest + i);
  20600. *d = ByteOrder::swap (*d);
  20601. #endif
  20602. s += srcBytesPerSample;
  20603. }
  20604. }
  20605. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20606. const float* const source,
  20607. void* const dest,
  20608. const int numSamples)
  20609. {
  20610. switch (destFormat)
  20611. {
  20612. case int16LE:
  20613. convertFloatToInt16LE (source, dest, numSamples);
  20614. break;
  20615. case int16BE:
  20616. convertFloatToInt16BE (source, dest, numSamples);
  20617. break;
  20618. case int24LE:
  20619. convertFloatToInt24LE (source, dest, numSamples);
  20620. break;
  20621. case int24BE:
  20622. convertFloatToInt24BE (source, dest, numSamples);
  20623. break;
  20624. case int32LE:
  20625. convertFloatToInt32LE (source, dest, numSamples);
  20626. break;
  20627. case int32BE:
  20628. convertFloatToInt32BE (source, dest, numSamples);
  20629. break;
  20630. case float32LE:
  20631. convertFloatToFloat32LE (source, dest, numSamples);
  20632. break;
  20633. case float32BE:
  20634. convertFloatToFloat32BE (source, dest, numSamples);
  20635. break;
  20636. default:
  20637. jassertfalse
  20638. break;
  20639. }
  20640. }
  20641. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20642. const void* const source,
  20643. float* const dest,
  20644. const int numSamples)
  20645. {
  20646. switch (sourceFormat)
  20647. {
  20648. case int16LE:
  20649. convertInt16LEToFloat (source, dest, numSamples);
  20650. break;
  20651. case int16BE:
  20652. convertInt16BEToFloat (source, dest, numSamples);
  20653. break;
  20654. case int24LE:
  20655. convertInt24LEToFloat (source, dest, numSamples);
  20656. break;
  20657. case int24BE:
  20658. convertInt24BEToFloat (source, dest, numSamples);
  20659. break;
  20660. case int32LE:
  20661. convertInt32LEToFloat (source, dest, numSamples);
  20662. break;
  20663. case int32BE:
  20664. convertInt32BEToFloat (source, dest, numSamples);
  20665. break;
  20666. case float32LE:
  20667. convertFloat32LEToFloat (source, dest, numSamples);
  20668. break;
  20669. case float32BE:
  20670. convertFloat32BEToFloat (source, dest, numSamples);
  20671. break;
  20672. default:
  20673. jassertfalse
  20674. break;
  20675. }
  20676. }
  20677. void AudioDataConverters::interleaveSamples (const float** const source,
  20678. float* const dest,
  20679. const int numSamples,
  20680. const int numChannels)
  20681. {
  20682. for (int chan = 0; chan < numChannels; ++chan)
  20683. {
  20684. int i = chan;
  20685. const float* src = source [chan];
  20686. for (int j = 0; j < numSamples; ++j)
  20687. {
  20688. dest [i] = src [j];
  20689. i += numChannels;
  20690. }
  20691. }
  20692. }
  20693. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20694. float** const dest,
  20695. const int numSamples,
  20696. const int numChannels)
  20697. {
  20698. for (int chan = 0; chan < numChannels; ++chan)
  20699. {
  20700. int i = chan;
  20701. float* dst = dest [chan];
  20702. for (int j = 0; j < numSamples; ++j)
  20703. {
  20704. dst [j] = source [i];
  20705. i += numChannels;
  20706. }
  20707. }
  20708. }
  20709. END_JUCE_NAMESPACE
  20710. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20711. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20712. BEGIN_JUCE_NAMESPACE
  20713. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20714. const int numSamples) throw()
  20715. : numChannels (numChannels_),
  20716. size (numSamples)
  20717. {
  20718. jassert (numSamples >= 0);
  20719. jassert (numChannels_ > 0);
  20720. allocateData();
  20721. }
  20722. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20723. : numChannels (other.numChannels),
  20724. size (other.size)
  20725. {
  20726. allocateData();
  20727. const size_t numBytes = size * sizeof (float);
  20728. for (int i = 0; i < numChannels; ++i)
  20729. memcpy (channels[i], other.channels[i], numBytes);
  20730. }
  20731. void AudioSampleBuffer::allocateData()
  20732. {
  20733. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20734. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20735. allocatedData.malloc (allocatedBytes);
  20736. channels = (float**) allocatedData;
  20737. float* chan = (float*) (allocatedData + channelListSize);
  20738. for (int i = 0; i < numChannels; ++i)
  20739. {
  20740. channels[i] = chan;
  20741. chan += size;
  20742. }
  20743. channels [numChannels] = 0;
  20744. }
  20745. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20746. const int numChannels_,
  20747. const int numSamples) throw()
  20748. : numChannels (numChannels_),
  20749. size (numSamples),
  20750. allocatedBytes (0)
  20751. {
  20752. jassert (numChannels_ > 0);
  20753. allocateChannels (dataToReferTo);
  20754. }
  20755. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20756. const int newNumChannels,
  20757. const int newNumSamples) throw()
  20758. {
  20759. jassert (newNumChannels > 0);
  20760. allocatedBytes = 0;
  20761. allocatedData.free();
  20762. numChannels = newNumChannels;
  20763. size = newNumSamples;
  20764. allocateChannels (dataToReferTo);
  20765. }
  20766. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20767. {
  20768. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20769. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20770. {
  20771. channels = (float**) preallocatedChannelSpace;
  20772. }
  20773. else
  20774. {
  20775. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20776. channels = (float**) allocatedData;
  20777. }
  20778. for (int i = 0; i < numChannels; ++i)
  20779. {
  20780. // you have to pass in the same number of valid pointers as numChannels
  20781. jassert (dataToReferTo[i] != 0);
  20782. channels[i] = dataToReferTo[i];
  20783. }
  20784. channels [numChannels] = 0;
  20785. }
  20786. const AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20787. {
  20788. if (this != &other)
  20789. {
  20790. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20791. const size_t numBytes = size * sizeof (float);
  20792. for (int i = 0; i < numChannels; ++i)
  20793. memcpy (channels[i], other.channels[i], numBytes);
  20794. }
  20795. return *this;
  20796. }
  20797. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20798. {
  20799. }
  20800. void AudioSampleBuffer::setSize (const int newNumChannels,
  20801. const int newNumSamples,
  20802. const bool keepExistingContent,
  20803. const bool clearExtraSpace,
  20804. const bool avoidReallocating) throw()
  20805. {
  20806. jassert (newNumChannels > 0);
  20807. if (newNumSamples != size || newNumChannels != numChannels)
  20808. {
  20809. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20810. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20811. if (keepExistingContent)
  20812. {
  20813. HeapBlock <char> newData;
  20814. newData.allocate (newTotalBytes, clearExtraSpace);
  20815. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20816. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20817. float** const newChannels = (float**) newData;
  20818. float* newChan = (float*) (newData + channelListSize);
  20819. for (int i = 0; i < numChansToCopy; ++i)
  20820. {
  20821. memcpy (newChan, channels[i], numBytesToCopy);
  20822. newChannels[i] = newChan;
  20823. newChan += newNumSamples;
  20824. }
  20825. allocatedData.swapWith (newData);
  20826. allocatedBytes = (int) newTotalBytes;
  20827. channels = (float**) allocatedData;
  20828. }
  20829. else
  20830. {
  20831. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20832. {
  20833. if (clearExtraSpace)
  20834. zeromem (allocatedData, newTotalBytes);
  20835. }
  20836. else
  20837. {
  20838. allocatedBytes = newTotalBytes;
  20839. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20840. channels = (float**) allocatedData;
  20841. }
  20842. float* chan = (float*) (allocatedData + channelListSize);
  20843. for (int i = 0; i < newNumChannels; ++i)
  20844. {
  20845. channels[i] = chan;
  20846. chan += newNumSamples;
  20847. }
  20848. }
  20849. channels [newNumChannels] = 0;
  20850. size = newNumSamples;
  20851. numChannels = newNumChannels;
  20852. }
  20853. }
  20854. void AudioSampleBuffer::clear() throw()
  20855. {
  20856. for (int i = 0; i < numChannels; ++i)
  20857. zeromem (channels[i], size * sizeof (float));
  20858. }
  20859. void AudioSampleBuffer::clear (const int startSample,
  20860. const int numSamples) throw()
  20861. {
  20862. jassert (startSample >= 0 && startSample + numSamples <= size);
  20863. for (int i = 0; i < numChannels; ++i)
  20864. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20865. }
  20866. void AudioSampleBuffer::clear (const int channel,
  20867. const int startSample,
  20868. const int numSamples) throw()
  20869. {
  20870. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20871. jassert (startSample >= 0 && startSample + numSamples <= size);
  20872. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20873. }
  20874. void AudioSampleBuffer::applyGain (const int channel,
  20875. const int startSample,
  20876. int numSamples,
  20877. const float gain) throw()
  20878. {
  20879. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20880. jassert (startSample >= 0 && startSample + numSamples <= size);
  20881. if (gain != 1.0f)
  20882. {
  20883. float* d = channels [channel] + startSample;
  20884. if (gain == 0.0f)
  20885. {
  20886. zeromem (d, sizeof (float) * numSamples);
  20887. }
  20888. else
  20889. {
  20890. while (--numSamples >= 0)
  20891. *d++ *= gain;
  20892. }
  20893. }
  20894. }
  20895. void AudioSampleBuffer::applyGainRamp (const int channel,
  20896. const int startSample,
  20897. int numSamples,
  20898. float startGain,
  20899. float endGain) throw()
  20900. {
  20901. if (startGain == endGain)
  20902. {
  20903. applyGain (channel, startSample, numSamples, startGain);
  20904. }
  20905. else
  20906. {
  20907. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20908. jassert (startSample >= 0 && startSample + numSamples <= size);
  20909. const float increment = (endGain - startGain) / numSamples;
  20910. float* d = channels [channel] + startSample;
  20911. while (--numSamples >= 0)
  20912. {
  20913. *d++ *= startGain;
  20914. startGain += increment;
  20915. }
  20916. }
  20917. }
  20918. void AudioSampleBuffer::applyGain (const int startSample,
  20919. const int numSamples,
  20920. const float gain) throw()
  20921. {
  20922. for (int i = 0; i < numChannels; ++i)
  20923. applyGain (i, startSample, numSamples, gain);
  20924. }
  20925. void AudioSampleBuffer::addFrom (const int destChannel,
  20926. const int destStartSample,
  20927. const AudioSampleBuffer& source,
  20928. const int sourceChannel,
  20929. const int sourceStartSample,
  20930. int numSamples,
  20931. const float gain) throw()
  20932. {
  20933. jassert (&source != this || sourceChannel != destChannel);
  20934. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20935. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20936. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20937. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20938. if (gain != 0.0f && numSamples > 0)
  20939. {
  20940. float* d = channels [destChannel] + destStartSample;
  20941. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20942. if (gain != 1.0f)
  20943. {
  20944. while (--numSamples >= 0)
  20945. *d++ += gain * *s++;
  20946. }
  20947. else
  20948. {
  20949. while (--numSamples >= 0)
  20950. *d++ += *s++;
  20951. }
  20952. }
  20953. }
  20954. void AudioSampleBuffer::addFrom (const int destChannel,
  20955. const int destStartSample,
  20956. const float* source,
  20957. int numSamples,
  20958. const float gain) throw()
  20959. {
  20960. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20961. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20962. jassert (source != 0);
  20963. if (gain != 0.0f && numSamples > 0)
  20964. {
  20965. float* d = channels [destChannel] + destStartSample;
  20966. if (gain != 1.0f)
  20967. {
  20968. while (--numSamples >= 0)
  20969. *d++ += gain * *source++;
  20970. }
  20971. else
  20972. {
  20973. while (--numSamples >= 0)
  20974. *d++ += *source++;
  20975. }
  20976. }
  20977. }
  20978. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20979. const int destStartSample,
  20980. const float* source,
  20981. int numSamples,
  20982. float startGain,
  20983. const float endGain) throw()
  20984. {
  20985. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20986. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20987. jassert (source != 0);
  20988. if (startGain == endGain)
  20989. {
  20990. addFrom (destChannel,
  20991. destStartSample,
  20992. source,
  20993. numSamples,
  20994. startGain);
  20995. }
  20996. else
  20997. {
  20998. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20999. {
  21000. const float increment = (endGain - startGain) / numSamples;
  21001. float* d = channels [destChannel] + destStartSample;
  21002. while (--numSamples >= 0)
  21003. {
  21004. *d++ += startGain * *source++;
  21005. startGain += increment;
  21006. }
  21007. }
  21008. }
  21009. }
  21010. void AudioSampleBuffer::copyFrom (const int destChannel,
  21011. const int destStartSample,
  21012. const AudioSampleBuffer& source,
  21013. const int sourceChannel,
  21014. const int sourceStartSample,
  21015. int numSamples) throw()
  21016. {
  21017. jassert (&source != this || sourceChannel != destChannel);
  21018. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21019. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21020. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  21021. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  21022. if (numSamples > 0)
  21023. {
  21024. memcpy (channels [destChannel] + destStartSample,
  21025. source.channels [sourceChannel] + sourceStartSample,
  21026. sizeof (float) * numSamples);
  21027. }
  21028. }
  21029. void AudioSampleBuffer::copyFrom (const int destChannel,
  21030. const int destStartSample,
  21031. const float* source,
  21032. int numSamples) throw()
  21033. {
  21034. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21035. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21036. jassert (source != 0);
  21037. if (numSamples > 0)
  21038. {
  21039. memcpy (channels [destChannel] + destStartSample,
  21040. source,
  21041. sizeof (float) * numSamples);
  21042. }
  21043. }
  21044. void AudioSampleBuffer::copyFrom (const int destChannel,
  21045. const int destStartSample,
  21046. const float* source,
  21047. int numSamples,
  21048. const float gain) throw()
  21049. {
  21050. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21051. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21052. jassert (source != 0);
  21053. if (numSamples > 0)
  21054. {
  21055. float* d = channels [destChannel] + destStartSample;
  21056. if (gain != 1.0f)
  21057. {
  21058. if (gain == 0)
  21059. {
  21060. zeromem (d, sizeof (float) * numSamples);
  21061. }
  21062. else
  21063. {
  21064. while (--numSamples >= 0)
  21065. *d++ = gain * *source++;
  21066. }
  21067. }
  21068. else
  21069. {
  21070. memcpy (d, source, sizeof (float) * numSamples);
  21071. }
  21072. }
  21073. }
  21074. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  21075. const int destStartSample,
  21076. const float* source,
  21077. int numSamples,
  21078. float startGain,
  21079. float endGain) throw()
  21080. {
  21081. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21082. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21083. jassert (source != 0);
  21084. if (startGain == endGain)
  21085. {
  21086. copyFrom (destChannel,
  21087. destStartSample,
  21088. source,
  21089. numSamples,
  21090. startGain);
  21091. }
  21092. else
  21093. {
  21094. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  21095. {
  21096. const float increment = (endGain - startGain) / numSamples;
  21097. float* d = channels [destChannel] + destStartSample;
  21098. while (--numSamples >= 0)
  21099. {
  21100. *d++ = startGain * *source++;
  21101. startGain += increment;
  21102. }
  21103. }
  21104. }
  21105. }
  21106. void AudioSampleBuffer::findMinMax (const int channel,
  21107. const int startSample,
  21108. int numSamples,
  21109. float& minVal,
  21110. float& maxVal) const throw()
  21111. {
  21112. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21113. jassert (startSample >= 0 && startSample + numSamples <= size);
  21114. if (numSamples <= 0)
  21115. {
  21116. minVal = 0.0f;
  21117. maxVal = 0.0f;
  21118. }
  21119. else
  21120. {
  21121. const float* d = channels [channel] + startSample;
  21122. float mn = *d++;
  21123. float mx = mn;
  21124. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  21125. {
  21126. const float samp = *d++;
  21127. if (samp > mx)
  21128. mx = samp;
  21129. if (samp < mn)
  21130. mn = samp;
  21131. }
  21132. maxVal = mx;
  21133. minVal = mn;
  21134. }
  21135. }
  21136. float AudioSampleBuffer::getMagnitude (const int channel,
  21137. const int startSample,
  21138. const int numSamples) const throw()
  21139. {
  21140. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21141. jassert (startSample >= 0 && startSample + numSamples <= size);
  21142. float mn, mx;
  21143. findMinMax (channel, startSample, numSamples, mn, mx);
  21144. return jmax (mn, -mn, mx, -mx);
  21145. }
  21146. float AudioSampleBuffer::getMagnitude (const int startSample,
  21147. const int numSamples) const throw()
  21148. {
  21149. float mag = 0.0f;
  21150. for (int i = 0; i < numChannels; ++i)
  21151. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  21152. return mag;
  21153. }
  21154. float AudioSampleBuffer::getRMSLevel (const int channel,
  21155. const int startSample,
  21156. const int numSamples) const throw()
  21157. {
  21158. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21159. jassert (startSample >= 0 && startSample + numSamples <= size);
  21160. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  21161. return 0.0f;
  21162. const float* const data = channels [channel] + startSample;
  21163. double sum = 0.0;
  21164. for (int i = 0; i < numSamples; ++i)
  21165. {
  21166. const float sample = data [i];
  21167. sum += sample * sample;
  21168. }
  21169. return (float) sqrt (sum / numSamples);
  21170. }
  21171. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  21172. const int startSample,
  21173. const int numSamples,
  21174. const int readerStartSample,
  21175. const bool useLeftChan,
  21176. const bool useRightChan) throw()
  21177. {
  21178. jassert (reader != 0);
  21179. jassert (startSample >= 0 && startSample + numSamples <= size);
  21180. if (numSamples > 0)
  21181. {
  21182. int* chans[3];
  21183. if (useLeftChan == useRightChan)
  21184. {
  21185. chans[0] = (int*) getSampleData (0, startSample);
  21186. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  21187. }
  21188. else if (useLeftChan || (reader->numChannels == 1))
  21189. {
  21190. chans[0] = (int*) getSampleData (0, startSample);
  21191. chans[1] = 0;
  21192. }
  21193. else if (useRightChan)
  21194. {
  21195. chans[0] = 0;
  21196. chans[1] = (int*) getSampleData (0, startSample);
  21197. }
  21198. chans[2] = 0;
  21199. reader->read (chans, 2, readerStartSample, numSamples, true);
  21200. if (! reader->usesFloatingPointData)
  21201. {
  21202. for (int j = 0; j < 2; ++j)
  21203. {
  21204. float* const d = (float*) (chans[j]);
  21205. if (d != 0)
  21206. {
  21207. const float multiplier = 1.0f / 0x7fffffff;
  21208. for (int i = 0; i < numSamples; ++i)
  21209. d[i] = *(int*)(d + i) * multiplier;
  21210. }
  21211. }
  21212. }
  21213. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  21214. {
  21215. // if this is a stereo buffer and the source was mono, dupe the first channel..
  21216. memcpy (getSampleData (1, startSample),
  21217. getSampleData (0, startSample),
  21218. sizeof (float) * numSamples);
  21219. }
  21220. }
  21221. }
  21222. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  21223. const int startSample,
  21224. const int numSamples) const throw()
  21225. {
  21226. jassert (startSample >= 0 && startSample + numSamples <= size);
  21227. if (numSamples > 0)
  21228. {
  21229. int* chans [3];
  21230. if (writer->isFloatingPoint())
  21231. {
  21232. chans[0] = (int*) getSampleData (0, startSample);
  21233. if (numChannels > 1)
  21234. chans[1] = (int*) getSampleData (1, startSample);
  21235. else
  21236. chans[1] = 0;
  21237. chans[2] = 0;
  21238. writer->write ((const int**) chans, numSamples);
  21239. }
  21240. else
  21241. {
  21242. HeapBlock <int> tempBuffer (numSamples * 2);
  21243. chans[0] = tempBuffer;
  21244. if (numChannels > 1)
  21245. chans[1] = chans[0] + numSamples;
  21246. else
  21247. chans[1] = 0;
  21248. chans[2] = 0;
  21249. for (int j = 0; j < 2; ++j)
  21250. {
  21251. int* const dest = chans[j];
  21252. if (dest != 0)
  21253. {
  21254. const float* const src = channels [j] + startSample;
  21255. for (int i = 0; i < numSamples; ++i)
  21256. {
  21257. const double samp = src[i];
  21258. if (samp <= -1.0)
  21259. dest[i] = std::numeric_limits<int>::min();
  21260. else if (samp >= 1.0)
  21261. dest[i] = std::numeric_limits<int>::max();
  21262. else
  21263. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  21264. }
  21265. }
  21266. }
  21267. writer->write ((const int**) chans, numSamples);
  21268. }
  21269. }
  21270. }
  21271. END_JUCE_NAMESPACE
  21272. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  21273. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  21274. BEGIN_JUCE_NAMESPACE
  21275. IIRFilter::IIRFilter() throw()
  21276. : active (false)
  21277. {
  21278. reset();
  21279. }
  21280. IIRFilter::IIRFilter (const IIRFilter& other) throw()
  21281. : active (other.active)
  21282. {
  21283. const ScopedLock sl (other.processLock);
  21284. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21285. reset();
  21286. }
  21287. IIRFilter::~IIRFilter() throw()
  21288. {
  21289. }
  21290. void IIRFilter::reset() throw()
  21291. {
  21292. const ScopedLock sl (processLock);
  21293. x1 = 0;
  21294. x2 = 0;
  21295. y1 = 0;
  21296. y2 = 0;
  21297. }
  21298. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21299. {
  21300. float out = coefficients[0] * in
  21301. + coefficients[1] * x1
  21302. + coefficients[2] * x2
  21303. - coefficients[4] * y1
  21304. - coefficients[5] * y2;
  21305. #if JUCE_INTEL
  21306. if (! (out < -1.0e-8 || out > 1.0e-8))
  21307. out = 0;
  21308. #endif
  21309. x2 = x1;
  21310. x1 = in;
  21311. y2 = y1;
  21312. y1 = out;
  21313. return out;
  21314. }
  21315. void IIRFilter::processSamples (float* const samples,
  21316. const int numSamples) throw()
  21317. {
  21318. const ScopedLock sl (processLock);
  21319. if (active)
  21320. {
  21321. for (int i = 0; i < numSamples; ++i)
  21322. {
  21323. const float in = samples[i];
  21324. float out = coefficients[0] * in
  21325. + coefficients[1] * x1
  21326. + coefficients[2] * x2
  21327. - coefficients[4] * y1
  21328. - coefficients[5] * y2;
  21329. #if JUCE_INTEL
  21330. if (! (out < -1.0e-8 || out > 1.0e-8))
  21331. out = 0;
  21332. #endif
  21333. x2 = x1;
  21334. x1 = in;
  21335. y2 = y1;
  21336. y1 = out;
  21337. samples[i] = out;
  21338. }
  21339. }
  21340. }
  21341. void IIRFilter::makeLowPass (const double sampleRate,
  21342. const double frequency) throw()
  21343. {
  21344. jassert (sampleRate > 0);
  21345. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21346. const double nSquared = n * n;
  21347. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21348. setCoefficients (c1,
  21349. c1 * 2.0f,
  21350. c1,
  21351. 1.0,
  21352. c1 * 2.0 * (1.0 - nSquared),
  21353. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21354. }
  21355. void IIRFilter::makeHighPass (const double sampleRate,
  21356. const double frequency) throw()
  21357. {
  21358. const double n = tan (double_Pi * frequency / sampleRate);
  21359. const double nSquared = n * n;
  21360. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21361. setCoefficients (c1,
  21362. c1 * -2.0f,
  21363. c1,
  21364. 1.0,
  21365. c1 * 2.0 * (nSquared - 1.0),
  21366. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21367. }
  21368. void IIRFilter::makeLowShelf (const double sampleRate,
  21369. const double cutOffFrequency,
  21370. const double Q,
  21371. const float gainFactor) throw()
  21372. {
  21373. jassert (sampleRate > 0);
  21374. jassert (Q > 0);
  21375. const double A = jmax (0.0f, gainFactor);
  21376. const double aminus1 = A - 1.0;
  21377. const double aplus1 = A + 1.0;
  21378. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21379. const double coso = cos (omega);
  21380. const double beta = sin (omega) * sqrt (A) / Q;
  21381. const double aminus1TimesCoso = aminus1 * coso;
  21382. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21383. A * 2.0 * (aminus1 - aplus1 * coso),
  21384. A * (aplus1 - aminus1TimesCoso - beta),
  21385. aplus1 + aminus1TimesCoso + beta,
  21386. -2.0 * (aminus1 + aplus1 * coso),
  21387. aplus1 + aminus1TimesCoso - beta);
  21388. }
  21389. void IIRFilter::makeHighShelf (const double sampleRate,
  21390. const double cutOffFrequency,
  21391. const double Q,
  21392. const float gainFactor) throw()
  21393. {
  21394. jassert (sampleRate > 0);
  21395. jassert (Q > 0);
  21396. const double A = jmax (0.0f, gainFactor);
  21397. const double aminus1 = A - 1.0;
  21398. const double aplus1 = A + 1.0;
  21399. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21400. const double coso = cos (omega);
  21401. const double beta = sin (omega) * sqrt (A) / Q;
  21402. const double aminus1TimesCoso = aminus1 * coso;
  21403. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21404. A * -2.0 * (aminus1 + aplus1 * coso),
  21405. A * (aplus1 + aminus1TimesCoso - beta),
  21406. aplus1 - aminus1TimesCoso + beta,
  21407. 2.0 * (aminus1 - aplus1 * coso),
  21408. aplus1 - aminus1TimesCoso - beta);
  21409. }
  21410. void IIRFilter::makeBandPass (const double sampleRate,
  21411. const double centreFrequency,
  21412. const double Q,
  21413. const float gainFactor) throw()
  21414. {
  21415. jassert (sampleRate > 0);
  21416. jassert (Q > 0);
  21417. const double A = jmax (0.0f, gainFactor);
  21418. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21419. const double alpha = 0.5 * sin (omega) / Q;
  21420. const double c2 = -2.0 * cos (omega);
  21421. const double alphaTimesA = alpha * A;
  21422. const double alphaOverA = alpha / A;
  21423. setCoefficients (1.0 + alphaTimesA,
  21424. c2,
  21425. 1.0 - alphaTimesA,
  21426. 1.0 + alphaOverA,
  21427. c2,
  21428. 1.0 - alphaOverA);
  21429. }
  21430. void IIRFilter::makeInactive() throw()
  21431. {
  21432. const ScopedLock sl (processLock);
  21433. active = false;
  21434. }
  21435. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21436. {
  21437. const ScopedLock sl (processLock);
  21438. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21439. active = other.active;
  21440. }
  21441. void IIRFilter::setCoefficients (double c1,
  21442. double c2,
  21443. double c3,
  21444. double c4,
  21445. double c5,
  21446. double c6) throw()
  21447. {
  21448. const double a = 1.0 / c4;
  21449. c1 *= a;
  21450. c2 *= a;
  21451. c3 *= a;
  21452. c5 *= a;
  21453. c6 *= a;
  21454. const ScopedLock sl (processLock);
  21455. coefficients[0] = (float) c1;
  21456. coefficients[1] = (float) c2;
  21457. coefficients[2] = (float) c3;
  21458. coefficients[3] = (float) c4;
  21459. coefficients[4] = (float) c5;
  21460. coefficients[5] = (float) c6;
  21461. active = true;
  21462. }
  21463. END_JUCE_NAMESPACE
  21464. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21465. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21466. BEGIN_JUCE_NAMESPACE
  21467. MidiBuffer::MidiBuffer() throw()
  21468. : bytesUsed (0)
  21469. {
  21470. }
  21471. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21472. : bytesUsed (0)
  21473. {
  21474. addEvent (message, 0);
  21475. }
  21476. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21477. : data (other.data),
  21478. bytesUsed (other.bytesUsed)
  21479. {
  21480. }
  21481. const MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21482. {
  21483. bytesUsed = other.bytesUsed;
  21484. data = other.data;
  21485. return *this;
  21486. }
  21487. void MidiBuffer::swap (MidiBuffer& other)
  21488. {
  21489. data.swapWith (other.data);
  21490. swapVariables <int> (bytesUsed, other.bytesUsed);
  21491. }
  21492. MidiBuffer::~MidiBuffer() throw()
  21493. {
  21494. }
  21495. void MidiBuffer::clear() throw()
  21496. {
  21497. bytesUsed = 0;
  21498. }
  21499. void MidiBuffer::clear (const int startSample,
  21500. const int numSamples) throw()
  21501. {
  21502. uint8* const start = findEventAfter (data, startSample - 1);
  21503. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21504. if (end > start)
  21505. {
  21506. const size_t bytesToMove = (size_t) (bytesUsed - (end - (uint8*) data.getData()));
  21507. if (bytesToMove > 0)
  21508. memmove (start, end, bytesToMove);
  21509. bytesUsed -= (int) (end - start);
  21510. }
  21511. }
  21512. void MidiBuffer::addEvent (const MidiMessage& m,
  21513. const int sampleNumber) throw()
  21514. {
  21515. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21516. }
  21517. static int findActualEventLength (const uint8* const data,
  21518. const int maxBytes) throw()
  21519. {
  21520. unsigned int byte = (unsigned int) *data;
  21521. int size = 0;
  21522. if (byte == 0xf0 || byte == 0xf7)
  21523. {
  21524. const uint8* d = data + 1;
  21525. while (d < data + maxBytes)
  21526. if (*d++ == 0xf7)
  21527. break;
  21528. size = (int) (d - data);
  21529. }
  21530. else if (byte == 0xff)
  21531. {
  21532. int n;
  21533. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21534. size = jmin (maxBytes, n + 2 + bytesLeft);
  21535. }
  21536. else if (byte >= 0x80)
  21537. {
  21538. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21539. }
  21540. return size;
  21541. }
  21542. void MidiBuffer::addEvent (const uint8* const newData,
  21543. const int maxBytes,
  21544. const int sampleNumber) throw()
  21545. {
  21546. const int numBytes = findActualEventLength (newData, maxBytes);
  21547. if (numBytes > 0)
  21548. {
  21549. int spaceNeeded = bytesUsed + numBytes + 6;
  21550. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21551. uint8* d = findEventAfter ((uint8*) data.getData(), sampleNumber);
  21552. const size_t bytesToMove = (size_t) (bytesUsed - (d - (uint8*) data.getData()));
  21553. if (bytesToMove > 0)
  21554. memmove (d + numBytes + 6,
  21555. d,
  21556. bytesToMove);
  21557. *(int*) d = sampleNumber;
  21558. d += 4;
  21559. *(uint16*) d = (uint16) numBytes;
  21560. d += 2;
  21561. memcpy (d, newData, numBytes);
  21562. bytesUsed += numBytes + 6;
  21563. }
  21564. }
  21565. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21566. const int startSample,
  21567. const int numSamples,
  21568. const int sampleDeltaToAdd) throw()
  21569. {
  21570. Iterator i (otherBuffer);
  21571. i.setNextSamplePosition (startSample);
  21572. const uint8* eventData;
  21573. int eventSize, position;
  21574. while (i.getNextEvent (eventData, eventSize, position)
  21575. && (position < startSample + numSamples || numSamples < 0))
  21576. {
  21577. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21578. }
  21579. }
  21580. bool MidiBuffer::isEmpty() const throw()
  21581. {
  21582. return bytesUsed == 0;
  21583. }
  21584. int MidiBuffer::getNumEvents() const throw()
  21585. {
  21586. int n = 0;
  21587. const uint8* d = (uint8*) data.getData();
  21588. const uint8* const end = d + bytesUsed;
  21589. while (d < end)
  21590. {
  21591. d += 4;
  21592. d += 2 + *(const uint16*) d;
  21593. ++n;
  21594. }
  21595. return n;
  21596. }
  21597. int MidiBuffer::getFirstEventTime() const throw()
  21598. {
  21599. return (bytesUsed > 0) ? *(const int*) data.getData() : 0;
  21600. }
  21601. int MidiBuffer::getLastEventTime() const throw()
  21602. {
  21603. if (bytesUsed == 0)
  21604. return 0;
  21605. const uint8* d = (uint8*) data.getData();
  21606. const uint8* const endData = d + bytesUsed;
  21607. for (;;)
  21608. {
  21609. const uint8* nextOne = d + 6 + * (const uint16*) (d + 4);
  21610. if (nextOne >= endData)
  21611. return *(const int*) d;
  21612. d = nextOne;
  21613. }
  21614. }
  21615. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21616. {
  21617. const uint8* const endData = ((uint8*) data.getData()) + bytesUsed;
  21618. while (d < endData && *(int*) d <= samplePosition)
  21619. {
  21620. d += 4;
  21621. d += 2 + *(uint16*) d;
  21622. }
  21623. return d;
  21624. }
  21625. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21626. : buffer (buffer_),
  21627. data ((uint8*) buffer_.data.getData())
  21628. {
  21629. }
  21630. MidiBuffer::Iterator::~Iterator() throw()
  21631. {
  21632. }
  21633. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21634. {
  21635. data = buffer.data;
  21636. const uint8* dataEnd = ((uint8*) buffer.data.getData()) + buffer.bytesUsed;
  21637. while (data < dataEnd && *(int*) data < samplePosition)
  21638. {
  21639. data += 4;
  21640. data += 2 + *(uint16*) data;
  21641. }
  21642. }
  21643. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData,
  21644. int& numBytes,
  21645. int& samplePosition) throw()
  21646. {
  21647. if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed)
  21648. return false;
  21649. samplePosition = *(int*) data;
  21650. data += 4;
  21651. numBytes = *(uint16*) data;
  21652. data += 2;
  21653. midiData = data;
  21654. data += numBytes;
  21655. return true;
  21656. }
  21657. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result,
  21658. int& samplePosition) throw()
  21659. {
  21660. if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed)
  21661. return false;
  21662. samplePosition = *(int*) data;
  21663. data += 4;
  21664. const int numBytes = *(uint16*) data;
  21665. data += 2;
  21666. result = MidiMessage (data, numBytes, samplePosition);
  21667. data += numBytes;
  21668. return true;
  21669. }
  21670. END_JUCE_NAMESPACE
  21671. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21672. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21673. BEGIN_JUCE_NAMESPACE
  21674. struct TempoInfo
  21675. {
  21676. double bpm, timestamp;
  21677. };
  21678. struct TimeSigInfo
  21679. {
  21680. int numerator, denominator;
  21681. double timestamp;
  21682. };
  21683. MidiFile::MidiFile() throw()
  21684. : timeFormat ((short) (unsigned short) 0xe728)
  21685. {
  21686. }
  21687. MidiFile::~MidiFile() throw()
  21688. {
  21689. clear();
  21690. }
  21691. void MidiFile::clear() throw()
  21692. {
  21693. tracks.clear();
  21694. }
  21695. int MidiFile::getNumTracks() const throw()
  21696. {
  21697. return tracks.size();
  21698. }
  21699. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21700. {
  21701. return tracks [index];
  21702. }
  21703. void MidiFile::addTrack (const MidiMessageSequence& trackSequence) throw()
  21704. {
  21705. tracks.add (new MidiMessageSequence (trackSequence));
  21706. }
  21707. short MidiFile::getTimeFormat() const throw()
  21708. {
  21709. return timeFormat;
  21710. }
  21711. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21712. {
  21713. timeFormat = (short)ticks;
  21714. }
  21715. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21716. const int subframeResolution) throw()
  21717. {
  21718. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21719. }
  21720. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21721. {
  21722. for (int i = tracks.size(); --i >= 0;)
  21723. {
  21724. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21725. for (int j = 0; j < numEvents; ++j)
  21726. {
  21727. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21728. if (m.isTempoMetaEvent())
  21729. tempoChangeEvents.addEvent (m);
  21730. }
  21731. }
  21732. }
  21733. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21734. {
  21735. for (int i = tracks.size(); --i >= 0;)
  21736. {
  21737. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21738. for (int j = 0; j < numEvents; ++j)
  21739. {
  21740. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21741. if (m.isTimeSignatureMetaEvent())
  21742. timeSigEvents.addEvent (m);
  21743. }
  21744. }
  21745. }
  21746. double MidiFile::getLastTimestamp() const
  21747. {
  21748. double t = 0.0;
  21749. for (int i = tracks.size(); --i >= 0;)
  21750. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21751. return t;
  21752. }
  21753. static bool parseMidiHeader (const char* &data,
  21754. short& timeFormat,
  21755. short& fileType,
  21756. short& numberOfTracks)
  21757. {
  21758. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21759. data += 4;
  21760. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21761. {
  21762. bool ok = false;
  21763. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21764. {
  21765. for (int i = 0; i < 8; ++i)
  21766. {
  21767. ch = ByteOrder::bigEndianInt (data);
  21768. data += 4;
  21769. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21770. {
  21771. ok = true;
  21772. break;
  21773. }
  21774. }
  21775. }
  21776. if (! ok)
  21777. return false;
  21778. }
  21779. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21780. data += 4;
  21781. fileType = (short) ByteOrder::bigEndianShort (data);
  21782. data += 2;
  21783. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21784. data += 2;
  21785. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21786. data += 2;
  21787. bytesRemaining -= 6;
  21788. data += bytesRemaining;
  21789. return true;
  21790. }
  21791. bool MidiFile::readFrom (InputStream& sourceStream)
  21792. {
  21793. clear();
  21794. MemoryBlock data;
  21795. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21796. // (put a sanity-check on the file size, as midi files are generally small)
  21797. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21798. {
  21799. size_t size = data.getSize();
  21800. const char* d = (char*) data.getData();
  21801. short fileType, expectedTracks;
  21802. if (size > 16 && parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21803. {
  21804. size -= (int) (d - (char*) data.getData());
  21805. int track = 0;
  21806. while (size > 0 && track < expectedTracks)
  21807. {
  21808. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21809. d += 4;
  21810. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21811. d += 4;
  21812. if (chunkSize <= 0)
  21813. break;
  21814. if (size < 0)
  21815. return false;
  21816. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21817. {
  21818. readNextTrack (d, chunkSize);
  21819. }
  21820. size -= chunkSize + 8;
  21821. d += chunkSize;
  21822. ++track;
  21823. }
  21824. return true;
  21825. }
  21826. }
  21827. return false;
  21828. }
  21829. // a comparator that puts all the note-offs before note-ons that have the same time
  21830. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21831. const MidiMessageSequence::MidiEventHolder* const second) throw()
  21832. {
  21833. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21834. if (diff == 0)
  21835. {
  21836. if (first->message.isNoteOff() && second->message.isNoteOn())
  21837. return -1;
  21838. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21839. return 1;
  21840. else
  21841. return 0;
  21842. }
  21843. else
  21844. {
  21845. return (diff > 0) ? 1 : -1;
  21846. }
  21847. }
  21848. void MidiFile::readNextTrack (const char* data, int size)
  21849. {
  21850. double time = 0;
  21851. char lastStatusByte = 0;
  21852. MidiMessageSequence result;
  21853. while (size > 0)
  21854. {
  21855. int bytesUsed;
  21856. const int delay = MidiMessage::readVariableLengthVal ((const uint8*) data, bytesUsed);
  21857. data += bytesUsed;
  21858. size -= bytesUsed;
  21859. time += delay;
  21860. int messSize = 0;
  21861. const MidiMessage mm ((const uint8*) data, size, messSize, lastStatusByte, time);
  21862. if (messSize <= 0)
  21863. break;
  21864. size -= messSize;
  21865. data += messSize;
  21866. result.addEvent (mm);
  21867. const char firstByte = *(mm.getRawData());
  21868. if ((firstByte & 0xf0) != 0xf0)
  21869. lastStatusByte = firstByte;
  21870. }
  21871. // use a sort that puts all the note-offs before note-ons that have the same time
  21872. result.list.sort (*this, true);
  21873. result.updateMatchedPairs();
  21874. addTrack (result);
  21875. }
  21876. static double convertTicksToSeconds (const double time,
  21877. const MidiMessageSequence& tempoEvents,
  21878. const int timeFormat)
  21879. {
  21880. if (timeFormat > 0)
  21881. {
  21882. int numer = 4, denom = 4;
  21883. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21884. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21885. double secsPerTick = 0.5 * tickLen;
  21886. const int numEvents = tempoEvents.getNumEvents();
  21887. for (int i = 0; i < numEvents; ++i)
  21888. {
  21889. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21890. if (time <= m.getTimeStamp())
  21891. break;
  21892. if (timeFormat > 0)
  21893. {
  21894. correctedTempoTime = correctedTempoTime
  21895. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21896. }
  21897. else
  21898. {
  21899. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21900. }
  21901. tempoTime = m.getTimeStamp();
  21902. if (m.isTempoMetaEvent())
  21903. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21904. else if (m.isTimeSignatureMetaEvent())
  21905. m.getTimeSignatureInfo (numer, denom);
  21906. while (i + 1 < numEvents)
  21907. {
  21908. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21909. if (m2.getTimeStamp() == tempoTime)
  21910. {
  21911. ++i;
  21912. if (m2.isTempoMetaEvent())
  21913. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21914. else if (m2.isTimeSignatureMetaEvent())
  21915. m2.getTimeSignatureInfo (numer, denom);
  21916. }
  21917. else
  21918. {
  21919. break;
  21920. }
  21921. }
  21922. }
  21923. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21924. }
  21925. else
  21926. {
  21927. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21928. }
  21929. }
  21930. void MidiFile::convertTimestampTicksToSeconds()
  21931. {
  21932. MidiMessageSequence tempoEvents;
  21933. findAllTempoEvents (tempoEvents);
  21934. findAllTimeSigEvents (tempoEvents);
  21935. for (int i = 0; i < tracks.size(); ++i)
  21936. {
  21937. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21938. for (int j = ms.getNumEvents(); --j >= 0;)
  21939. {
  21940. MidiMessage& m = ms.getEventPointer(j)->message;
  21941. m.setTimeStamp (convertTicksToSeconds (m.getTimeStamp(),
  21942. tempoEvents,
  21943. timeFormat));
  21944. }
  21945. }
  21946. }
  21947. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21948. {
  21949. unsigned int buffer = v & 0x7F;
  21950. while ((v >>= 7) != 0)
  21951. {
  21952. buffer <<= 8;
  21953. buffer |= ((v & 0x7F) | 0x80);
  21954. }
  21955. for (;;)
  21956. {
  21957. out.writeByte ((char) buffer);
  21958. if (buffer & 0x80)
  21959. buffer >>= 8;
  21960. else
  21961. break;
  21962. }
  21963. }
  21964. bool MidiFile::writeTo (OutputStream& out)
  21965. {
  21966. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21967. out.writeIntBigEndian (6);
  21968. out.writeShortBigEndian (1); // type
  21969. out.writeShortBigEndian ((short) tracks.size());
  21970. out.writeShortBigEndian (timeFormat);
  21971. for (int i = 0; i < tracks.size(); ++i)
  21972. writeTrack (out, i);
  21973. out.flush();
  21974. return true;
  21975. }
  21976. void MidiFile::writeTrack (OutputStream& mainOut,
  21977. const int trackNum)
  21978. {
  21979. MemoryOutputStream out;
  21980. const MidiMessageSequence& ms = *tracks[trackNum];
  21981. int lastTick = 0;
  21982. char lastStatusByte = 0;
  21983. for (int i = 0; i < ms.getNumEvents(); ++i)
  21984. {
  21985. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21986. const int tick = roundToInt (mm.getTimeStamp());
  21987. const int delta = jmax (0, tick - lastTick);
  21988. writeVariableLengthInt (out, delta);
  21989. lastTick = tick;
  21990. const char statusByte = *(mm.getRawData());
  21991. if ((statusByte == lastStatusByte)
  21992. && ((statusByte & 0xf0) != 0xf0)
  21993. && i > 0
  21994. && mm.getRawDataSize() > 1)
  21995. {
  21996. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21997. }
  21998. else
  21999. {
  22000. out.write (mm.getRawData(), mm.getRawDataSize());
  22001. }
  22002. lastStatusByte = statusByte;
  22003. }
  22004. out.writeByte (0);
  22005. const MidiMessage m (MidiMessage::endOfTrack());
  22006. out.write (m.getRawData(),
  22007. m.getRawDataSize());
  22008. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  22009. mainOut.writeIntBigEndian ((int) out.getDataSize());
  22010. mainOut.write (out.getData(), (int) out.getDataSize());
  22011. }
  22012. END_JUCE_NAMESPACE
  22013. /*** End of inlined file: juce_MidiFile.cpp ***/
  22014. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  22015. BEGIN_JUCE_NAMESPACE
  22016. MidiKeyboardState::MidiKeyboardState()
  22017. {
  22018. zeromem (noteStates, sizeof (noteStates));
  22019. }
  22020. MidiKeyboardState::~MidiKeyboardState()
  22021. {
  22022. }
  22023. void MidiKeyboardState::reset()
  22024. {
  22025. const ScopedLock sl (lock);
  22026. zeromem (noteStates, sizeof (noteStates));
  22027. eventsToAdd.clear();
  22028. }
  22029. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  22030. {
  22031. jassert (midiChannel >= 0 && midiChannel <= 16);
  22032. return ((unsigned int) n) < 128
  22033. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  22034. }
  22035. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  22036. {
  22037. return ((unsigned int) n) < 128
  22038. && (noteStates[n] & midiChannelMask) != 0;
  22039. }
  22040. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  22041. {
  22042. jassert (midiChannel >= 0 && midiChannel <= 16);
  22043. jassert (((unsigned int) midiNoteNumber) < 128);
  22044. const ScopedLock sl (lock);
  22045. if (((unsigned int) midiNoteNumber) < 128)
  22046. {
  22047. const int timeNow = (int) Time::getMillisecondCounter();
  22048. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  22049. eventsToAdd.clear (0, timeNow - 500);
  22050. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  22051. }
  22052. }
  22053. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  22054. {
  22055. if (((unsigned int) midiNoteNumber) < 128)
  22056. {
  22057. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  22058. for (int i = listeners.size(); --i >= 0;)
  22059. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  22060. ->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  22061. }
  22062. }
  22063. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  22064. {
  22065. const ScopedLock sl (lock);
  22066. if (isNoteOn (midiChannel, midiNoteNumber))
  22067. {
  22068. const int timeNow = (int) Time::getMillisecondCounter();
  22069. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  22070. eventsToAdd.clear (0, timeNow - 500);
  22071. noteOffInternal (midiChannel, midiNoteNumber);
  22072. }
  22073. }
  22074. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  22075. {
  22076. if (isNoteOn (midiChannel, midiNoteNumber))
  22077. {
  22078. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  22079. for (int i = listeners.size(); --i >= 0;)
  22080. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  22081. ->handleNoteOff (this, midiChannel, midiNoteNumber);
  22082. }
  22083. }
  22084. void MidiKeyboardState::allNotesOff (const int midiChannel)
  22085. {
  22086. const ScopedLock sl (lock);
  22087. if (midiChannel <= 0)
  22088. {
  22089. for (int i = 1; i <= 16; ++i)
  22090. allNotesOff (i);
  22091. }
  22092. else
  22093. {
  22094. for (int i = 0; i < 128; ++i)
  22095. noteOff (midiChannel, i);
  22096. }
  22097. }
  22098. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  22099. {
  22100. if (message.isNoteOn())
  22101. {
  22102. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  22103. }
  22104. else if (message.isNoteOff())
  22105. {
  22106. noteOffInternal (message.getChannel(), message.getNoteNumber());
  22107. }
  22108. else if (message.isAllNotesOff())
  22109. {
  22110. for (int i = 0; i < 128; ++i)
  22111. noteOffInternal (message.getChannel(), i);
  22112. }
  22113. }
  22114. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  22115. const int startSample,
  22116. const int numSamples,
  22117. const bool injectIndirectEvents)
  22118. {
  22119. MidiBuffer::Iterator i (buffer);
  22120. MidiMessage message (0xf4, 0.0);
  22121. int time;
  22122. const ScopedLock sl (lock);
  22123. while (i.getNextEvent (message, time))
  22124. processNextMidiEvent (message);
  22125. if (injectIndirectEvents)
  22126. {
  22127. MidiBuffer::Iterator i2 (eventsToAdd);
  22128. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  22129. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  22130. while (i2.getNextEvent (message, time))
  22131. {
  22132. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  22133. buffer.addEvent (message, startSample + pos);
  22134. }
  22135. }
  22136. eventsToAdd.clear();
  22137. }
  22138. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  22139. {
  22140. const ScopedLock sl (lock);
  22141. listeners.addIfNotAlreadyThere (listener);
  22142. }
  22143. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  22144. {
  22145. const ScopedLock sl (lock);
  22146. listeners.removeValue (listener);
  22147. }
  22148. END_JUCE_NAMESPACE
  22149. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  22150. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  22151. BEGIN_JUCE_NAMESPACE
  22152. int MidiMessage::readVariableLengthVal (const uint8* data,
  22153. int& numBytesUsed) throw()
  22154. {
  22155. numBytesUsed = 0;
  22156. int v = 0;
  22157. int i;
  22158. do
  22159. {
  22160. i = (int) *data++;
  22161. if (++numBytesUsed > 6)
  22162. break;
  22163. v = (v << 7) + (i & 0x7f);
  22164. } while (i & 0x80);
  22165. return v;
  22166. }
  22167. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  22168. {
  22169. // this method only works for valid starting bytes of a short midi message
  22170. jassert (firstByte >= 0x80
  22171. && firstByte != 0xf0
  22172. && firstByte != 0xf7);
  22173. static const char messageLengths[] =
  22174. {
  22175. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22176. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22177. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22178. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22179. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22180. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22181. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22182. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  22183. };
  22184. return messageLengths [firstByte & 0x7f];
  22185. }
  22186. MidiMessage::MidiMessage (const uint8* const d,
  22187. const int dataSize,
  22188. const double t) throw()
  22189. : timeStamp (t),
  22190. message (0),
  22191. size (dataSize)
  22192. {
  22193. jassert (dataSize > 0);
  22194. if (dataSize <= 4)
  22195. data = (uint8*) &message;
  22196. else
  22197. data = (uint8*) juce_malloc (dataSize);
  22198. memcpy (data, d, dataSize);
  22199. // check that the length matches the data..
  22200. jassert (size > 3 || *d >= 0xf0 || getMessageLengthFromFirstByte (*d) == size);
  22201. }
  22202. MidiMessage::MidiMessage (const int byte1,
  22203. const double t) throw()
  22204. : timeStamp (t),
  22205. data ((uint8*) &message),
  22206. size (1)
  22207. {
  22208. data[0] = (uint8) byte1;
  22209. // check that the length matches the data..
  22210. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  22211. }
  22212. MidiMessage::MidiMessage (const int byte1,
  22213. const int byte2,
  22214. const double t) throw()
  22215. : timeStamp (t),
  22216. data ((uint8*) &message),
  22217. size (2)
  22218. {
  22219. data[0] = (uint8) byte1;
  22220. data[1] = (uint8) byte2;
  22221. // check that the length matches the data..
  22222. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  22223. }
  22224. MidiMessage::MidiMessage (const int byte1,
  22225. const int byte2,
  22226. const int byte3,
  22227. const double t) throw()
  22228. : timeStamp (t),
  22229. data ((uint8*) &message),
  22230. size (3)
  22231. {
  22232. data[0] = (uint8) byte1;
  22233. data[1] = (uint8) byte2;
  22234. data[2] = (uint8) byte3;
  22235. // check that the length matches the data..
  22236. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  22237. }
  22238. MidiMessage::MidiMessage (const MidiMessage& other) throw()
  22239. : timeStamp (other.timeStamp),
  22240. message (other.message),
  22241. size (other.size)
  22242. {
  22243. if (other.data != (uint8*) &other.message)
  22244. {
  22245. data = (uint8*) juce_malloc (size);
  22246. memcpy (data, other.data, size);
  22247. }
  22248. else
  22249. {
  22250. data = (uint8*) &message;
  22251. }
  22252. }
  22253. MidiMessage::MidiMessage (const MidiMessage& other,
  22254. const double newTimeStamp) throw()
  22255. : timeStamp (newTimeStamp),
  22256. message (other.message),
  22257. size (other.size)
  22258. {
  22259. if (other.data != (uint8*) &other.message)
  22260. {
  22261. data = (uint8*) juce_malloc (size);
  22262. memcpy (data, other.data, size);
  22263. }
  22264. else
  22265. {
  22266. data = (uint8*) &message;
  22267. }
  22268. }
  22269. MidiMessage::MidiMessage (const uint8* src,
  22270. int sz,
  22271. int& numBytesUsed,
  22272. const uint8 lastStatusByte,
  22273. double t) throw()
  22274. : timeStamp (t),
  22275. data ((uint8*) &message),
  22276. message (0)
  22277. {
  22278. unsigned int byte = (unsigned int) *src;
  22279. if (byte < 0x80)
  22280. {
  22281. byte = (unsigned int) (uint8) lastStatusByte;
  22282. numBytesUsed = -1;
  22283. }
  22284. else
  22285. {
  22286. numBytesUsed = 0;
  22287. --sz;
  22288. ++src;
  22289. }
  22290. if (byte >= 0x80)
  22291. {
  22292. if (byte == 0xf0)
  22293. {
  22294. const uint8* d = (const uint8*) src;
  22295. while (d < src + sz)
  22296. {
  22297. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  22298. {
  22299. if (*d == 0xf7) // include an 0xf7 if we hit one
  22300. ++d;
  22301. break;
  22302. }
  22303. ++d;
  22304. }
  22305. size = 1 + (int) (d - src);
  22306. data = (uint8*) juce_malloc (size);
  22307. *data = (uint8) byte;
  22308. memcpy (data + 1, src, size - 1);
  22309. }
  22310. else if (byte == 0xff)
  22311. {
  22312. int n;
  22313. const int bytesLeft = readVariableLengthVal (src + 1, n);
  22314. size = jmin (sz + 1, n + 2 + bytesLeft);
  22315. data = (uint8*) juce_malloc (size);
  22316. *data = (uint8) byte;
  22317. memcpy (data + 1, src, size - 1);
  22318. }
  22319. else
  22320. {
  22321. size = getMessageLengthFromFirstByte ((uint8) byte);
  22322. *data = (uint8) byte;
  22323. if (size > 1)
  22324. {
  22325. data[1] = src[0];
  22326. if (size > 2)
  22327. data[2] = src[1];
  22328. }
  22329. }
  22330. numBytesUsed += size;
  22331. }
  22332. else
  22333. {
  22334. message = 0;
  22335. size = 0;
  22336. }
  22337. }
  22338. const MidiMessage& MidiMessage::operator= (const MidiMessage& other) throw()
  22339. {
  22340. if (this != &other)
  22341. {
  22342. timeStamp = other.timeStamp;
  22343. size = other.size;
  22344. message = other.message;
  22345. if (data != (uint8*) &message)
  22346. juce_free (data);
  22347. if (other.data != (uint8*) &other.message)
  22348. {
  22349. data = (uint8*) juce_malloc (size);
  22350. memcpy (data, other.data, size);
  22351. }
  22352. else
  22353. {
  22354. data = (uint8*) &message;
  22355. }
  22356. }
  22357. return *this;
  22358. }
  22359. MidiMessage::~MidiMessage() throw()
  22360. {
  22361. if (data != (uint8*) &message)
  22362. juce_free (data);
  22363. }
  22364. int MidiMessage::getChannel() const throw()
  22365. {
  22366. if ((data[0] & 0xf0) != 0xf0)
  22367. return (data[0] & 0xf) + 1;
  22368. else
  22369. return 0;
  22370. }
  22371. bool MidiMessage::isForChannel (const int channel) const throw()
  22372. {
  22373. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22374. return ((data[0] & 0xf) == channel - 1)
  22375. && ((data[0] & 0xf0) != 0xf0);
  22376. }
  22377. void MidiMessage::setChannel (const int channel) throw()
  22378. {
  22379. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22380. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22381. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22382. | (uint8)(channel - 1));
  22383. }
  22384. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22385. {
  22386. return ((data[0] & 0xf0) == 0x90)
  22387. && (returnTrueForVelocity0 || data[2] != 0);
  22388. }
  22389. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22390. {
  22391. return ((data[0] & 0xf0) == 0x80)
  22392. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22393. }
  22394. bool MidiMessage::isNoteOnOrOff() const throw()
  22395. {
  22396. const int d = data[0] & 0xf0;
  22397. return (d == 0x90) || (d == 0x80);
  22398. }
  22399. int MidiMessage::getNoteNumber() const throw()
  22400. {
  22401. return data[1];
  22402. }
  22403. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22404. {
  22405. if (isNoteOnOrOff())
  22406. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22407. }
  22408. uint8 MidiMessage::getVelocity() const throw()
  22409. {
  22410. if (isNoteOnOrOff())
  22411. return data[2];
  22412. else
  22413. return 0;
  22414. }
  22415. float MidiMessage::getFloatVelocity() const throw()
  22416. {
  22417. return getVelocity() * (1.0f / 127.0f);
  22418. }
  22419. void MidiMessage::setVelocity (const float newVelocity) throw()
  22420. {
  22421. if (isNoteOnOrOff())
  22422. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22423. }
  22424. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22425. {
  22426. if (isNoteOnOrOff())
  22427. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22428. }
  22429. bool MidiMessage::isAftertouch() const throw()
  22430. {
  22431. return (data[0] & 0xf0) == 0xa0;
  22432. }
  22433. int MidiMessage::getAfterTouchValue() const throw()
  22434. {
  22435. return data[2];
  22436. }
  22437. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22438. const int noteNum,
  22439. const int aftertouchValue) throw()
  22440. {
  22441. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22442. jassert (((unsigned int) noteNum) <= 127);
  22443. jassert (((unsigned int) aftertouchValue) <= 127);
  22444. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22445. noteNum & 0x7f,
  22446. aftertouchValue & 0x7f);
  22447. }
  22448. bool MidiMessage::isChannelPressure() const throw()
  22449. {
  22450. return (data[0] & 0xf0) == 0xd0;
  22451. }
  22452. int MidiMessage::getChannelPressureValue() const throw()
  22453. {
  22454. jassert (isChannelPressure());
  22455. return data[1];
  22456. }
  22457. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22458. const int pressure) throw()
  22459. {
  22460. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22461. jassert (((unsigned int) pressure) <= 127);
  22462. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22463. pressure & 0x7f);
  22464. }
  22465. bool MidiMessage::isProgramChange() const throw()
  22466. {
  22467. return (data[0] & 0xf0) == 0xc0;
  22468. }
  22469. int MidiMessage::getProgramChangeNumber() const throw()
  22470. {
  22471. return data[1];
  22472. }
  22473. const MidiMessage MidiMessage::programChange (const int channel,
  22474. const int programNumber) throw()
  22475. {
  22476. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22477. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22478. programNumber & 0x7f);
  22479. }
  22480. bool MidiMessage::isPitchWheel() const throw()
  22481. {
  22482. return (data[0] & 0xf0) == 0xe0;
  22483. }
  22484. int MidiMessage::getPitchWheelValue() const throw()
  22485. {
  22486. return data[1] | (data[2] << 7);
  22487. }
  22488. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22489. const int position) throw()
  22490. {
  22491. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22492. jassert (((unsigned int) position) <= 0x3fff);
  22493. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22494. position & 127,
  22495. (position >> 7) & 127);
  22496. }
  22497. bool MidiMessage::isController() const throw()
  22498. {
  22499. return (data[0] & 0xf0) == 0xb0;
  22500. }
  22501. int MidiMessage::getControllerNumber() const throw()
  22502. {
  22503. jassert (isController());
  22504. return data[1];
  22505. }
  22506. int MidiMessage::getControllerValue() const throw()
  22507. {
  22508. jassert (isController());
  22509. return data[2];
  22510. }
  22511. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22512. const int controllerType,
  22513. const int value) throw()
  22514. {
  22515. // the channel must be between 1 and 16 inclusive
  22516. jassert (channel > 0 && channel <= 16);
  22517. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22518. controllerType & 127,
  22519. value & 127);
  22520. }
  22521. const MidiMessage MidiMessage::noteOn (const int channel,
  22522. const int noteNumber,
  22523. const float velocity) throw()
  22524. {
  22525. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22526. }
  22527. const MidiMessage MidiMessage::noteOn (const int channel,
  22528. const int noteNumber,
  22529. const uint8 velocity) throw()
  22530. {
  22531. jassert (channel > 0 && channel <= 16);
  22532. jassert (((unsigned int) noteNumber) <= 127);
  22533. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22534. noteNumber & 127,
  22535. jlimit (0, 127, roundToInt (velocity)));
  22536. }
  22537. const MidiMessage MidiMessage::noteOff (const int channel,
  22538. const int noteNumber) throw()
  22539. {
  22540. jassert (channel > 0 && channel <= 16);
  22541. jassert (((unsigned int) noteNumber) <= 127);
  22542. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22543. }
  22544. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22545. {
  22546. jassert (channel > 0 && channel <= 16);
  22547. return controllerEvent (channel, 123, 0);
  22548. }
  22549. bool MidiMessage::isAllNotesOff() const throw()
  22550. {
  22551. return (data[0] & 0xf0) == 0xb0
  22552. && data[1] == 123;
  22553. }
  22554. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22555. {
  22556. return controllerEvent (channel, 120, 0);
  22557. }
  22558. bool MidiMessage::isAllSoundOff() const throw()
  22559. {
  22560. return (data[0] & 0xf0) == 0xb0
  22561. && data[1] == 120;
  22562. }
  22563. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22564. {
  22565. return controllerEvent (channel, 121, 0);
  22566. }
  22567. const MidiMessage MidiMessage::masterVolume (const float volume) throw()
  22568. {
  22569. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22570. uint8 buf[8];
  22571. buf[0] = 0xf0;
  22572. buf[1] = 0x7f;
  22573. buf[2] = 0x7f;
  22574. buf[3] = 0x04;
  22575. buf[4] = 0x01;
  22576. buf[5] = (uint8) (vol & 0x7f);
  22577. buf[6] = (uint8) (vol >> 7);
  22578. buf[7] = 0xf7;
  22579. return MidiMessage (buf, 8);
  22580. }
  22581. bool MidiMessage::isSysEx() const throw()
  22582. {
  22583. return *data == 0xf0;
  22584. }
  22585. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData,
  22586. const int dataSize) throw()
  22587. {
  22588. MemoryBlock mm (dataSize + 2);
  22589. uint8* const m = (uint8*) mm.getData();
  22590. m[0] = 0xf0;
  22591. memcpy (m + 1, sysexData, dataSize);
  22592. m[dataSize + 1] = 0xf7;
  22593. return MidiMessage (m, dataSize + 2);
  22594. }
  22595. const uint8* MidiMessage::getSysExData() const throw()
  22596. {
  22597. return (isSysEx()) ? getRawData() + 1
  22598. : 0;
  22599. }
  22600. int MidiMessage::getSysExDataSize() const throw()
  22601. {
  22602. return (isSysEx()) ? size - 2
  22603. : 0;
  22604. }
  22605. bool MidiMessage::isMetaEvent() const throw()
  22606. {
  22607. return *data == 0xff;
  22608. }
  22609. bool MidiMessage::isActiveSense() const throw()
  22610. {
  22611. return *data == 0xfe;
  22612. }
  22613. int MidiMessage::getMetaEventType() const throw()
  22614. {
  22615. if (*data != 0xff)
  22616. return -1;
  22617. else
  22618. return data[1];
  22619. }
  22620. int MidiMessage::getMetaEventLength() const throw()
  22621. {
  22622. if (*data == 0xff)
  22623. {
  22624. int n;
  22625. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22626. }
  22627. return 0;
  22628. }
  22629. const uint8* MidiMessage::getMetaEventData() const throw()
  22630. {
  22631. int n;
  22632. const uint8* d = data + 2;
  22633. readVariableLengthVal (d, n);
  22634. return d + n;
  22635. }
  22636. bool MidiMessage::isTrackMetaEvent() const throw()
  22637. {
  22638. return getMetaEventType() == 0;
  22639. }
  22640. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22641. {
  22642. return getMetaEventType() == 47;
  22643. }
  22644. bool MidiMessage::isTextMetaEvent() const throw()
  22645. {
  22646. const int t = getMetaEventType();
  22647. return t > 0 && t < 16;
  22648. }
  22649. const String MidiMessage::getTextFromTextMetaEvent() const throw()
  22650. {
  22651. return String ((const char*) getMetaEventData(),
  22652. getMetaEventLength());
  22653. }
  22654. bool MidiMessage::isTrackNameEvent() const throw()
  22655. {
  22656. return (data[1] == 3)
  22657. && (*data == 0xff);
  22658. }
  22659. bool MidiMessage::isTempoMetaEvent() const throw()
  22660. {
  22661. return (data[1] == 81)
  22662. && (*data == 0xff);
  22663. }
  22664. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22665. {
  22666. return (data[1] == 0x20)
  22667. && (*data == 0xff)
  22668. && (data[2] == 1);
  22669. }
  22670. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22671. {
  22672. return data[3] + 1;
  22673. }
  22674. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22675. {
  22676. if (! isTempoMetaEvent())
  22677. return 0.0;
  22678. const uint8* const d = getMetaEventData();
  22679. return (((unsigned int) d[0] << 16)
  22680. | ((unsigned int) d[1] << 8)
  22681. | d[2])
  22682. / 1000000.0;
  22683. }
  22684. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22685. {
  22686. if (timeFormat > 0)
  22687. {
  22688. if (! isTempoMetaEvent())
  22689. return 0.5 / timeFormat;
  22690. return getTempoSecondsPerQuarterNote() / timeFormat;
  22691. }
  22692. else
  22693. {
  22694. const int frameCode = (-timeFormat) >> 8;
  22695. double framesPerSecond;
  22696. switch (frameCode)
  22697. {
  22698. case 24: framesPerSecond = 24.0; break;
  22699. case 25: framesPerSecond = 25.0; break;
  22700. case 29: framesPerSecond = 29.97; break;
  22701. case 30: framesPerSecond = 30.0; break;
  22702. default: framesPerSecond = 30.0; break;
  22703. }
  22704. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22705. }
  22706. }
  22707. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22708. {
  22709. uint8 d[8];
  22710. d[0] = 0xff;
  22711. d[1] = 81;
  22712. d[2] = 3;
  22713. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22714. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22715. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22716. return MidiMessage (d, 6, 0.0);
  22717. }
  22718. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22719. {
  22720. return (data[1] == 0x58)
  22721. && (*data == (uint8) 0xff);
  22722. }
  22723. void MidiMessage::getTimeSignatureInfo (int& numerator,
  22724. int& denominator) const throw()
  22725. {
  22726. if (isTimeSignatureMetaEvent())
  22727. {
  22728. const uint8* const d = getMetaEventData();
  22729. numerator = d[0];
  22730. denominator = 1 << d[1];
  22731. }
  22732. else
  22733. {
  22734. numerator = 4;
  22735. denominator = 4;
  22736. }
  22737. }
  22738. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator,
  22739. const int denominator) throw()
  22740. {
  22741. uint8 d[8];
  22742. d[0] = 0xff;
  22743. d[1] = 0x58;
  22744. d[2] = 0x04;
  22745. d[3] = (uint8) numerator;
  22746. int n = 1;
  22747. int powerOfTwo = 0;
  22748. while (n < denominator)
  22749. {
  22750. n <<= 1;
  22751. ++powerOfTwo;
  22752. }
  22753. d[4] = (uint8) powerOfTwo;
  22754. d[5] = 0x01;
  22755. d[6] = 96;
  22756. return MidiMessage (d, 7, 0.0);
  22757. }
  22758. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22759. {
  22760. uint8 d[8];
  22761. d[0] = 0xff;
  22762. d[1] = 0x20;
  22763. d[2] = 0x01;
  22764. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22765. return MidiMessage (d, 4, 0.0);
  22766. }
  22767. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22768. {
  22769. return getMetaEventType() == 89;
  22770. }
  22771. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22772. {
  22773. return (int) *getMetaEventData();
  22774. }
  22775. const MidiMessage MidiMessage::endOfTrack() throw()
  22776. {
  22777. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22778. }
  22779. bool MidiMessage::isSongPositionPointer() const throw()
  22780. {
  22781. return *data == 0xf2;
  22782. }
  22783. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22784. {
  22785. return data[1] | (data[2] << 7);
  22786. }
  22787. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22788. {
  22789. return MidiMessage (0xf2,
  22790. positionInMidiBeats & 127,
  22791. (positionInMidiBeats >> 7) & 127);
  22792. }
  22793. bool MidiMessage::isMidiStart() const throw()
  22794. {
  22795. return *data == 0xfa;
  22796. }
  22797. const MidiMessage MidiMessage::midiStart() throw()
  22798. {
  22799. return MidiMessage (0xfa);
  22800. }
  22801. bool MidiMessage::isMidiContinue() const throw()
  22802. {
  22803. return *data == 0xfb;
  22804. }
  22805. const MidiMessage MidiMessage::midiContinue() throw()
  22806. {
  22807. return MidiMessage (0xfb);
  22808. }
  22809. bool MidiMessage::isMidiStop() const throw()
  22810. {
  22811. return *data == 0xfc;
  22812. }
  22813. const MidiMessage MidiMessage::midiStop() throw()
  22814. {
  22815. return MidiMessage (0xfc);
  22816. }
  22817. bool MidiMessage::isMidiClock() const throw()
  22818. {
  22819. return *data == 0xf8;
  22820. }
  22821. const MidiMessage MidiMessage::midiClock() throw()
  22822. {
  22823. return MidiMessage (0xf8);
  22824. }
  22825. bool MidiMessage::isQuarterFrame() const throw()
  22826. {
  22827. return *data == 0xf1;
  22828. }
  22829. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22830. {
  22831. return ((int) data[1]) >> 4;
  22832. }
  22833. int MidiMessage::getQuarterFrameValue() const throw()
  22834. {
  22835. return ((int) data[1]) & 0x0f;
  22836. }
  22837. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22838. const int value) throw()
  22839. {
  22840. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22841. }
  22842. bool MidiMessage::isFullFrame() const throw()
  22843. {
  22844. return data[0] == 0xf0
  22845. && data[1] == 0x7f
  22846. && size >= 10
  22847. && data[3] == 0x01
  22848. && data[4] == 0x01;
  22849. }
  22850. void MidiMessage::getFullFrameParameters (int& hours,
  22851. int& minutes,
  22852. int& seconds,
  22853. int& frames,
  22854. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22855. {
  22856. jassert (isFullFrame());
  22857. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22858. hours = data[5] & 0x1f;
  22859. minutes = data[6];
  22860. seconds = data[7];
  22861. frames = data[8];
  22862. }
  22863. const MidiMessage MidiMessage::fullFrame (const int hours,
  22864. const int minutes,
  22865. const int seconds,
  22866. const int frames,
  22867. MidiMessage::SmpteTimecodeType timecodeType)
  22868. {
  22869. uint8 d[10];
  22870. d[0] = 0xf0;
  22871. d[1] = 0x7f;
  22872. d[2] = 0x7f;
  22873. d[3] = 0x01;
  22874. d[4] = 0x01;
  22875. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22876. d[6] = (uint8) minutes;
  22877. d[7] = (uint8) seconds;
  22878. d[8] = (uint8) frames;
  22879. d[9] = 0xf7;
  22880. return MidiMessage (d, 10, 0.0);
  22881. }
  22882. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22883. {
  22884. return data[0] == 0xf0
  22885. && data[1] == 0x7f
  22886. && data[3] == 0x06
  22887. && size > 5;
  22888. }
  22889. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22890. {
  22891. jassert (isMidiMachineControlMessage());
  22892. return (MidiMachineControlCommand) data[4];
  22893. }
  22894. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22895. {
  22896. uint8 d[6];
  22897. d[0] = 0xf0;
  22898. d[1] = 0x7f;
  22899. d[2] = 0x00;
  22900. d[3] = 0x06;
  22901. d[4] = (uint8) command;
  22902. d[5] = 0xf7;
  22903. return MidiMessage (d, 6, 0.0);
  22904. }
  22905. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22906. int& minutes,
  22907. int& seconds,
  22908. int& frames) const throw()
  22909. {
  22910. if (size >= 12
  22911. && data[0] == 0xf0
  22912. && data[1] == 0x7f
  22913. && data[3] == 0x06
  22914. && data[4] == 0x44
  22915. && data[5] == 0x06
  22916. && data[6] == 0x01)
  22917. {
  22918. hours = data[7] % 24; // (that some machines send out hours > 24)
  22919. minutes = data[8];
  22920. seconds = data[9];
  22921. frames = data[10];
  22922. return true;
  22923. }
  22924. return false;
  22925. }
  22926. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22927. int minutes,
  22928. int seconds,
  22929. int frames)
  22930. {
  22931. uint8 d[12];
  22932. d[0] = 0xf0;
  22933. d[1] = 0x7f;
  22934. d[2] = 0x00;
  22935. d[3] = 0x06;
  22936. d[4] = 0x44;
  22937. d[5] = 0x06;
  22938. d[6] = 0x01;
  22939. d[7] = (uint8) hours;
  22940. d[8] = (uint8) minutes;
  22941. d[9] = (uint8) seconds;
  22942. d[10] = (uint8) frames;
  22943. d[11] = 0xf7;
  22944. return MidiMessage (d, 12, 0.0);
  22945. }
  22946. const String MidiMessage::getMidiNoteName (int note,
  22947. bool useSharps,
  22948. bool includeOctaveNumber,
  22949. int octaveNumForMiddleC) throw()
  22950. {
  22951. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22952. "F", "F#", "G", "G#", "A",
  22953. "A#", "B" };
  22954. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22955. "F", "Gb", "G", "Ab", "A",
  22956. "Bb", "B" };
  22957. if (((unsigned int) note) < 128)
  22958. {
  22959. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22960. : flatNoteNames [note % 12]);
  22961. if (includeOctaveNumber)
  22962. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22963. else
  22964. return s;
  22965. }
  22966. return String::empty;
  22967. }
  22968. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22969. {
  22970. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22971. return 440.0 * pow (2.0, noteNumber / 12.0);
  22972. }
  22973. const String MidiMessage::getGMInstrumentName (int n) throw()
  22974. {
  22975. const char *names[] =
  22976. {
  22977. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22978. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22979. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22980. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22981. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22982. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22983. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22984. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22985. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22986. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22987. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22988. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22989. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22990. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22991. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22992. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22993. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22994. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22995. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22996. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22997. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22998. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22999. "Applause", "Gunshot"
  23000. };
  23001. return (((unsigned int) n) < 128) ? names[n]
  23002. : (const char*)0;
  23003. }
  23004. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  23005. {
  23006. const char* names[] =
  23007. {
  23008. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  23009. "Bass", "Strings", "Ensemble", "Brass",
  23010. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  23011. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  23012. };
  23013. return (((unsigned int) n) <= 15) ? names[n]
  23014. : (const char*)0;
  23015. }
  23016. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  23017. {
  23018. const char* names[] =
  23019. {
  23020. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  23021. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  23022. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  23023. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  23024. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  23025. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  23026. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  23027. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  23028. "Mute Triangle", "Open Triangle"
  23029. };
  23030. return (n >= 35 && n <= 81) ? names [n - 35]
  23031. : (const char*)0;
  23032. }
  23033. const String MidiMessage::getControllerName (int n) throw()
  23034. {
  23035. const char* names[] =
  23036. {
  23037. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  23038. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  23039. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  23040. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  23041. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  23042. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  23043. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  23044. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  23045. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  23046. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  23047. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  23048. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  23049. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  23050. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  23051. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  23052. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  23053. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  23054. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  23055. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  23056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  23057. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  23058. "Poly Operation"
  23059. };
  23060. return (((unsigned int) n) < 128) ? names[n]
  23061. : (const char*)0;
  23062. }
  23063. END_JUCE_NAMESPACE
  23064. /*** End of inlined file: juce_MidiMessage.cpp ***/
  23065. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  23066. BEGIN_JUCE_NAMESPACE
  23067. MidiMessageCollector::MidiMessageCollector()
  23068. : lastCallbackTime (0),
  23069. sampleRate (44100.0001)
  23070. {
  23071. }
  23072. MidiMessageCollector::~MidiMessageCollector()
  23073. {
  23074. }
  23075. void MidiMessageCollector::reset (const double sampleRate_)
  23076. {
  23077. jassert (sampleRate_ > 0);
  23078. const ScopedLock sl (midiCallbackLock);
  23079. sampleRate = sampleRate_;
  23080. incomingMessages.clear();
  23081. lastCallbackTime = Time::getMillisecondCounterHiRes();
  23082. }
  23083. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  23084. {
  23085. // you need to call reset() to set the correct sample rate before using this object
  23086. jassert (sampleRate != 44100.0001);
  23087. // the messages that come in here need to be time-stamped correctly - see MidiInput
  23088. // for details of what the number should be.
  23089. jassert (message.getTimeStamp() != 0);
  23090. const ScopedLock sl (midiCallbackLock);
  23091. const int sampleNumber
  23092. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  23093. incomingMessages.addEvent (message, sampleNumber);
  23094. // if the messages don't get used for over a second, we'd better
  23095. // get rid of any old ones to avoid the queue getting too big
  23096. if (sampleNumber > sampleRate)
  23097. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  23098. }
  23099. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  23100. const int numSamples)
  23101. {
  23102. // you need to call reset() to set the correct sample rate before using this object
  23103. jassert (sampleRate != 44100.0001);
  23104. const double timeNow = Time::getMillisecondCounterHiRes();
  23105. const double msElapsed = timeNow - lastCallbackTime;
  23106. const ScopedLock sl (midiCallbackLock);
  23107. lastCallbackTime = timeNow;
  23108. if (! incomingMessages.isEmpty())
  23109. {
  23110. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  23111. int startSample = 0;
  23112. int scale = 1 << 16;
  23113. const uint8* midiData;
  23114. int numBytes, samplePosition;
  23115. MidiBuffer::Iterator iter (incomingMessages);
  23116. if (numSourceSamples > numSamples)
  23117. {
  23118. // if our list of events is longer than the buffer we're being
  23119. // asked for, scale them down to squeeze them all in..
  23120. const int maxBlockLengthToUse = numSamples << 5;
  23121. if (numSourceSamples > maxBlockLengthToUse)
  23122. {
  23123. startSample = numSourceSamples - maxBlockLengthToUse;
  23124. numSourceSamples = maxBlockLengthToUse;
  23125. iter.setNextSamplePosition (startSample);
  23126. }
  23127. scale = (numSamples << 10) / numSourceSamples;
  23128. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23129. {
  23130. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  23131. destBuffer.addEvent (midiData, numBytes,
  23132. jlimit (0, numSamples - 1, samplePosition));
  23133. }
  23134. }
  23135. else
  23136. {
  23137. // if our event list is shorter than the number we need, put them
  23138. // towards the end of the buffer
  23139. startSample = numSamples - numSourceSamples;
  23140. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23141. {
  23142. destBuffer.addEvent (midiData, numBytes,
  23143. jlimit (0, numSamples - 1, samplePosition + startSample));
  23144. }
  23145. }
  23146. incomingMessages.clear();
  23147. }
  23148. }
  23149. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  23150. {
  23151. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  23152. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23153. addMessageToQueue (m);
  23154. }
  23155. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  23156. {
  23157. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  23158. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23159. addMessageToQueue (m);
  23160. }
  23161. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  23162. {
  23163. addMessageToQueue (message);
  23164. }
  23165. END_JUCE_NAMESPACE
  23166. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  23167. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  23168. BEGIN_JUCE_NAMESPACE
  23169. MidiMessageSequence::MidiMessageSequence()
  23170. {
  23171. }
  23172. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  23173. {
  23174. list.ensureStorageAllocated (other.list.size());
  23175. for (int i = 0; i < other.list.size(); ++i)
  23176. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  23177. }
  23178. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  23179. {
  23180. MidiMessageSequence otherCopy (other);
  23181. swapWith (otherCopy);
  23182. return *this;
  23183. }
  23184. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  23185. {
  23186. list.swapWithArray (other.list);
  23187. }
  23188. MidiMessageSequence::~MidiMessageSequence()
  23189. {
  23190. }
  23191. void MidiMessageSequence::clear()
  23192. {
  23193. list.clear();
  23194. }
  23195. int MidiMessageSequence::getNumEvents() const
  23196. {
  23197. return list.size();
  23198. }
  23199. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  23200. {
  23201. return list [index];
  23202. }
  23203. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  23204. {
  23205. const MidiEventHolder* const meh = list [index];
  23206. if (meh != 0 && meh->noteOffObject != 0)
  23207. return meh->noteOffObject->message.getTimeStamp();
  23208. else
  23209. return 0.0;
  23210. }
  23211. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  23212. {
  23213. const MidiEventHolder* const meh = list [index];
  23214. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  23215. }
  23216. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  23217. {
  23218. return list.indexOf (event);
  23219. }
  23220. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  23221. {
  23222. const int numEvents = list.size();
  23223. int i;
  23224. for (i = 0; i < numEvents; ++i)
  23225. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  23226. break;
  23227. return i;
  23228. }
  23229. double MidiMessageSequence::getStartTime() const
  23230. {
  23231. if (list.size() > 0)
  23232. return list.getUnchecked(0)->message.getTimeStamp();
  23233. else
  23234. return 0;
  23235. }
  23236. double MidiMessageSequence::getEndTime() const
  23237. {
  23238. if (list.size() > 0)
  23239. return list.getLast()->message.getTimeStamp();
  23240. else
  23241. return 0;
  23242. }
  23243. double MidiMessageSequence::getEventTime (const int index) const
  23244. {
  23245. if (((unsigned int) index) < (unsigned int) list.size())
  23246. return list.getUnchecked (index)->message.getTimeStamp();
  23247. return 0.0;
  23248. }
  23249. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  23250. double timeAdjustment)
  23251. {
  23252. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  23253. timeAdjustment += newMessage.getTimeStamp();
  23254. newOne->message.setTimeStamp (timeAdjustment);
  23255. int i;
  23256. for (i = list.size(); --i >= 0;)
  23257. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  23258. break;
  23259. list.insert (i + 1, newOne);
  23260. }
  23261. void MidiMessageSequence::deleteEvent (const int index,
  23262. const bool deleteMatchingNoteUp)
  23263. {
  23264. if (((unsigned int) index) < (unsigned int) list.size())
  23265. {
  23266. if (deleteMatchingNoteUp)
  23267. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  23268. list.remove (index);
  23269. }
  23270. }
  23271. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  23272. double timeAdjustment,
  23273. double firstAllowableTime,
  23274. double endOfAllowableDestTimes)
  23275. {
  23276. firstAllowableTime -= timeAdjustment;
  23277. endOfAllowableDestTimes -= timeAdjustment;
  23278. for (int i = 0; i < other.list.size(); ++i)
  23279. {
  23280. const MidiMessage& m = other.list.getUnchecked(i)->message;
  23281. const double t = m.getTimeStamp();
  23282. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  23283. {
  23284. MidiEventHolder* const newOne = new MidiEventHolder (m);
  23285. newOne->message.setTimeStamp (timeAdjustment + t);
  23286. list.add (newOne);
  23287. }
  23288. }
  23289. sort();
  23290. }
  23291. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  23292. const MidiMessageSequence::MidiEventHolder* const second) throw()
  23293. {
  23294. const double diff = first->message.getTimeStamp()
  23295. - second->message.getTimeStamp();
  23296. return (diff > 0) - (diff < 0);
  23297. }
  23298. void MidiMessageSequence::sort()
  23299. {
  23300. list.sort (*this, true);
  23301. }
  23302. void MidiMessageSequence::updateMatchedPairs()
  23303. {
  23304. for (int i = 0; i < list.size(); ++i)
  23305. {
  23306. const MidiMessage& m1 = list.getUnchecked(i)->message;
  23307. if (m1.isNoteOn())
  23308. {
  23309. list.getUnchecked(i)->noteOffObject = 0;
  23310. const int note = m1.getNoteNumber();
  23311. const int chan = m1.getChannel();
  23312. const int len = list.size();
  23313. for (int j = i + 1; j < len; ++j)
  23314. {
  23315. const MidiMessage& m = list.getUnchecked(j)->message;
  23316. if (m.getNoteNumber() == note && m.getChannel() == chan)
  23317. {
  23318. if (m.isNoteOff())
  23319. {
  23320. list.getUnchecked(i)->noteOffObject = list[j];
  23321. break;
  23322. }
  23323. else if (m.isNoteOn())
  23324. {
  23325. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23326. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23327. list.getUnchecked(i)->noteOffObject = list[j];
  23328. break;
  23329. }
  23330. }
  23331. }
  23332. }
  23333. }
  23334. }
  23335. void MidiMessageSequence::addTimeToMessages (const double delta)
  23336. {
  23337. for (int i = list.size(); --i >= 0;)
  23338. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23339. + delta);
  23340. }
  23341. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23342. MidiMessageSequence& destSequence,
  23343. const bool alsoIncludeMetaEvents) const
  23344. {
  23345. for (int i = 0; i < list.size(); ++i)
  23346. {
  23347. const MidiMessage& mm = list.getUnchecked(i)->message;
  23348. if (mm.isForChannel (channelNumberToExtract)
  23349. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23350. {
  23351. destSequence.addEvent (mm);
  23352. }
  23353. }
  23354. }
  23355. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23356. {
  23357. for (int i = 0; i < list.size(); ++i)
  23358. {
  23359. const MidiMessage& mm = list.getUnchecked(i)->message;
  23360. if (mm.isSysEx())
  23361. destSequence.addEvent (mm);
  23362. }
  23363. }
  23364. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23365. {
  23366. for (int i = list.size(); --i >= 0;)
  23367. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23368. list.remove(i);
  23369. }
  23370. void MidiMessageSequence::deleteSysExMessages()
  23371. {
  23372. for (int i = list.size(); --i >= 0;)
  23373. if (list.getUnchecked(i)->message.isSysEx())
  23374. list.remove(i);
  23375. }
  23376. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23377. const double time,
  23378. OwnedArray<MidiMessage>& dest)
  23379. {
  23380. bool doneProg = false;
  23381. bool donePitchWheel = false;
  23382. Array <int> doneControllers;
  23383. doneControllers.ensureStorageAllocated (32);
  23384. for (int i = list.size(); --i >= 0;)
  23385. {
  23386. const MidiMessage& mm = list.getUnchecked(i)->message;
  23387. if (mm.isForChannel (channelNumber)
  23388. && mm.getTimeStamp() <= time)
  23389. {
  23390. if (mm.isProgramChange())
  23391. {
  23392. if (! doneProg)
  23393. {
  23394. dest.add (new MidiMessage (mm, 0.0));
  23395. doneProg = true;
  23396. }
  23397. }
  23398. else if (mm.isController())
  23399. {
  23400. if (! doneControllers.contains (mm.getControllerNumber()))
  23401. {
  23402. dest.add (new MidiMessage (mm, 0.0));
  23403. doneControllers.add (mm.getControllerNumber());
  23404. }
  23405. }
  23406. else if (mm.isPitchWheel())
  23407. {
  23408. if (! donePitchWheel)
  23409. {
  23410. dest.add (new MidiMessage (mm, 0.0));
  23411. donePitchWheel = true;
  23412. }
  23413. }
  23414. }
  23415. }
  23416. }
  23417. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23418. : message (message_),
  23419. noteOffObject (0)
  23420. {
  23421. }
  23422. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23423. {
  23424. }
  23425. END_JUCE_NAMESPACE
  23426. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23427. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23428. BEGIN_JUCE_NAMESPACE
  23429. AudioPluginFormat::AudioPluginFormat() throw()
  23430. {
  23431. }
  23432. AudioPluginFormat::~AudioPluginFormat()
  23433. {
  23434. }
  23435. END_JUCE_NAMESPACE
  23436. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23437. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23438. BEGIN_JUCE_NAMESPACE
  23439. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23440. {
  23441. }
  23442. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23443. {
  23444. clearSingletonInstance();
  23445. }
  23446. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23447. void AudioPluginFormatManager::addDefaultFormats()
  23448. {
  23449. #ifdef JUCE_DEBUG
  23450. // you should only call this method once!
  23451. for (int i = formats.size(); --i >= 0;)
  23452. {
  23453. #if JUCE_PLUGINHOST_VST
  23454. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23455. #endif
  23456. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23457. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23458. #endif
  23459. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23460. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23461. #endif
  23462. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23463. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23464. #endif
  23465. }
  23466. #endif
  23467. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23468. formats.add (new AudioUnitPluginFormat());
  23469. #endif
  23470. #if JUCE_PLUGINHOST_VST
  23471. formats.add (new VSTPluginFormat());
  23472. #endif
  23473. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23474. formats.add (new DirectXPluginFormat());
  23475. #endif
  23476. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23477. formats.add (new LADSPAPluginFormat());
  23478. #endif
  23479. }
  23480. int AudioPluginFormatManager::getNumFormats() throw()
  23481. {
  23482. return formats.size();
  23483. }
  23484. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23485. {
  23486. return formats [index];
  23487. }
  23488. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23489. {
  23490. formats.add (format);
  23491. }
  23492. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23493. String& errorMessage) const
  23494. {
  23495. AudioPluginInstance* result = 0;
  23496. for (int i = 0; i < formats.size(); ++i)
  23497. {
  23498. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23499. if (result != 0)
  23500. break;
  23501. }
  23502. if (result == 0)
  23503. {
  23504. if (! doesPluginStillExist (description))
  23505. errorMessage = TRANS ("This plug-in file no longer exists");
  23506. else
  23507. errorMessage = TRANS ("This plug-in failed to load correctly");
  23508. }
  23509. return result;
  23510. }
  23511. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23512. {
  23513. for (int i = 0; i < formats.size(); ++i)
  23514. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23515. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23516. return false;
  23517. }
  23518. END_JUCE_NAMESPACE
  23519. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23520. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23521. #define JUCE_PLUGIN_HOST 1
  23522. BEGIN_JUCE_NAMESPACE
  23523. AudioPluginInstance::AudioPluginInstance()
  23524. {
  23525. }
  23526. AudioPluginInstance::~AudioPluginInstance()
  23527. {
  23528. }
  23529. END_JUCE_NAMESPACE
  23530. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23531. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23532. BEGIN_JUCE_NAMESPACE
  23533. KnownPluginList::KnownPluginList()
  23534. {
  23535. }
  23536. KnownPluginList::~KnownPluginList()
  23537. {
  23538. }
  23539. void KnownPluginList::clear()
  23540. {
  23541. if (types.size() > 0)
  23542. {
  23543. types.clear();
  23544. sendChangeMessage (this);
  23545. }
  23546. }
  23547. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23548. {
  23549. for (int i = 0; i < types.size(); ++i)
  23550. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23551. return types.getUnchecked(i);
  23552. return 0;
  23553. }
  23554. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23555. {
  23556. for (int i = 0; i < types.size(); ++i)
  23557. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23558. return types.getUnchecked(i);
  23559. return 0;
  23560. }
  23561. bool KnownPluginList::addType (const PluginDescription& type)
  23562. {
  23563. for (int i = types.size(); --i >= 0;)
  23564. {
  23565. if (types.getUnchecked(i)->isDuplicateOf (type))
  23566. {
  23567. // strange - found a duplicate plugin with different info..
  23568. jassert (types.getUnchecked(i)->name == type.name);
  23569. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23570. *types.getUnchecked(i) = type;
  23571. return false;
  23572. }
  23573. }
  23574. types.add (new PluginDescription (type));
  23575. sendChangeMessage (this);
  23576. return true;
  23577. }
  23578. void KnownPluginList::removeType (const int index) throw()
  23579. {
  23580. types.remove (index);
  23581. sendChangeMessage (this);
  23582. }
  23583. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23584. {
  23585. if (fileOrIdentifier.startsWithChar (T('/'))
  23586. || fileOrIdentifier[1] == T(':'))
  23587. {
  23588. return File (fileOrIdentifier).getLastModificationTime();
  23589. }
  23590. return Time (0);
  23591. }
  23592. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23593. {
  23594. return t1 != t2 || t1 == Time (0);
  23595. }
  23596. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23597. {
  23598. if (getTypeForFile (fileOrIdentifier) == 0)
  23599. return false;
  23600. for (int i = types.size(); --i >= 0;)
  23601. {
  23602. const PluginDescription* const d = types.getUnchecked(i);
  23603. if (d->fileOrIdentifier == fileOrIdentifier
  23604. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23605. {
  23606. return false;
  23607. }
  23608. }
  23609. return true;
  23610. }
  23611. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23612. const bool dontRescanIfAlreadyInList,
  23613. OwnedArray <PluginDescription>& typesFound,
  23614. AudioPluginFormat& format)
  23615. {
  23616. bool addedOne = false;
  23617. if (dontRescanIfAlreadyInList
  23618. && getTypeForFile (fileOrIdentifier) != 0)
  23619. {
  23620. bool needsRescanning = false;
  23621. for (int i = types.size(); --i >= 0;)
  23622. {
  23623. const PluginDescription* const d = types.getUnchecked(i);
  23624. if (d->fileOrIdentifier == fileOrIdentifier)
  23625. {
  23626. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23627. needsRescanning = true;
  23628. else
  23629. typesFound.add (new PluginDescription (*d));
  23630. }
  23631. }
  23632. if (! needsRescanning)
  23633. return false;
  23634. }
  23635. OwnedArray <PluginDescription> found;
  23636. format.findAllTypesForFile (found, fileOrIdentifier);
  23637. for (int i = 0; i < found.size(); ++i)
  23638. {
  23639. PluginDescription* const desc = found.getUnchecked(i);
  23640. jassert (desc != 0);
  23641. if (addType (*desc))
  23642. addedOne = true;
  23643. typesFound.add (new PluginDescription (*desc));
  23644. }
  23645. return addedOne;
  23646. }
  23647. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23648. OwnedArray <PluginDescription>& typesFound)
  23649. {
  23650. for (int i = 0; i < files.size(); ++i)
  23651. {
  23652. bool loaded = false;
  23653. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23654. {
  23655. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23656. if (scanAndAddFile (files[i], true, typesFound, *format))
  23657. loaded = true;
  23658. }
  23659. if (! loaded)
  23660. {
  23661. const File f (files[i]);
  23662. if (f.isDirectory())
  23663. {
  23664. StringArray s;
  23665. {
  23666. Array<File> subFiles;
  23667. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23668. for (int j = 0; j < subFiles.size(); ++j)
  23669. s.add (subFiles.getReference(j).getFullPathName());
  23670. }
  23671. scanAndAddDragAndDroppedFiles (s, typesFound);
  23672. }
  23673. }
  23674. }
  23675. }
  23676. class PluginSorter
  23677. {
  23678. public:
  23679. KnownPluginList::SortMethod method;
  23680. PluginSorter() throw() {}
  23681. int compareElements (const PluginDescription* const first,
  23682. const PluginDescription* const second) const throw()
  23683. {
  23684. int diff = 0;
  23685. if (method == KnownPluginList::sortByCategory)
  23686. diff = first->category.compareLexicographically (second->category);
  23687. else if (method == KnownPluginList::sortByManufacturer)
  23688. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23689. else if (method == KnownPluginList::sortByFileSystemLocation)
  23690. diff = first->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23691. .upToLastOccurrenceOf (T("/"), false, false)
  23692. .compare (second->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23693. .upToLastOccurrenceOf (T("/"), false, false));
  23694. if (diff == 0)
  23695. diff = first->name.compareLexicographically (second->name);
  23696. return diff;
  23697. }
  23698. };
  23699. void KnownPluginList::sort (const SortMethod method)
  23700. {
  23701. if (method != defaultOrder)
  23702. {
  23703. PluginSorter sorter;
  23704. sorter.method = method;
  23705. types.sort (sorter, true);
  23706. sendChangeMessage (this);
  23707. }
  23708. }
  23709. XmlElement* KnownPluginList::createXml() const
  23710. {
  23711. XmlElement* const e = new XmlElement (T("KNOWNPLUGINS"));
  23712. for (int i = 0; i < types.size(); ++i)
  23713. e->addChildElement (types.getUnchecked(i)->createXml());
  23714. return e;
  23715. }
  23716. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23717. {
  23718. clear();
  23719. if (xml.hasTagName (T("KNOWNPLUGINS")))
  23720. {
  23721. forEachXmlChildElement (xml, e)
  23722. {
  23723. PluginDescription info;
  23724. if (info.loadFromXml (*e))
  23725. addType (info);
  23726. }
  23727. }
  23728. }
  23729. const int menuIdBase = 0x324503f4;
  23730. // This is used to turn a bunch of paths into a nested menu structure.
  23731. struct PluginFilesystemTree
  23732. {
  23733. private:
  23734. String folder;
  23735. OwnedArray <PluginFilesystemTree> subFolders;
  23736. Array <PluginDescription*> plugins;
  23737. void addPlugin (PluginDescription* const pd, const String& path)
  23738. {
  23739. if (path.isEmpty())
  23740. {
  23741. plugins.add (pd);
  23742. }
  23743. else
  23744. {
  23745. const String firstSubFolder (path.upToFirstOccurrenceOf (T("/"), false, false));
  23746. const String remainingPath (path.fromFirstOccurrenceOf (T("/"), false, false));
  23747. for (int i = subFolders.size(); --i >= 0;)
  23748. {
  23749. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23750. {
  23751. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23752. return;
  23753. }
  23754. }
  23755. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23756. newFolder->folder = firstSubFolder;
  23757. subFolders.add (newFolder);
  23758. newFolder->addPlugin (pd, remainingPath);
  23759. }
  23760. }
  23761. // removes any deeply nested folders that don't contain any actual plugins
  23762. void optimise()
  23763. {
  23764. for (int i = subFolders.size(); --i >= 0;)
  23765. {
  23766. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23767. sub->optimise();
  23768. if (sub->plugins.size() == 0)
  23769. {
  23770. for (int j = 0; j < sub->subFolders.size(); ++j)
  23771. subFolders.add (sub->subFolders.getUnchecked(j));
  23772. sub->subFolders.clear (false);
  23773. subFolders.remove (i);
  23774. }
  23775. }
  23776. }
  23777. public:
  23778. void buildTree (const Array <PluginDescription*>& allPlugins)
  23779. {
  23780. for (int i = 0; i < allPlugins.size(); ++i)
  23781. {
  23782. String path (allPlugins.getUnchecked(i)
  23783. ->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23784. .upToLastOccurrenceOf (T("/"), false, false));
  23785. if (path.substring (1, 2) == T(":"))
  23786. path = path.substring (2);
  23787. addPlugin (allPlugins.getUnchecked(i), path);
  23788. }
  23789. optimise();
  23790. }
  23791. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23792. {
  23793. int i;
  23794. for (i = 0; i < subFolders.size(); ++i)
  23795. {
  23796. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23797. PopupMenu subMenu;
  23798. sub->addToMenu (subMenu, allPlugins);
  23799. #if JUCE_MAC
  23800. // avoid the special AU formatting nonsense on Mac..
  23801. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (T(":"), false, false), subMenu);
  23802. #else
  23803. m.addSubMenu (sub->folder, subMenu);
  23804. #endif
  23805. }
  23806. for (i = 0; i < plugins.size(); ++i)
  23807. {
  23808. PluginDescription* const plugin = plugins.getUnchecked(i);
  23809. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23810. plugin->name, true, false);
  23811. }
  23812. }
  23813. };
  23814. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23815. {
  23816. Array <PluginDescription*> sorted;
  23817. {
  23818. PluginSorter sorter;
  23819. sorter.method = sortMethod;
  23820. for (int i = 0; i < types.size(); ++i)
  23821. sorted.addSorted (sorter, types.getUnchecked(i));
  23822. }
  23823. if (sortMethod == sortByCategory
  23824. || sortMethod == sortByManufacturer)
  23825. {
  23826. String lastSubMenuName;
  23827. PopupMenu sub;
  23828. for (int i = 0; i < sorted.size(); ++i)
  23829. {
  23830. const PluginDescription* const pd = sorted.getUnchecked(i);
  23831. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23832. : pd->manufacturerName);
  23833. if (! thisSubMenuName.containsNonWhitespaceChars())
  23834. thisSubMenuName = T("Other");
  23835. if (thisSubMenuName != lastSubMenuName)
  23836. {
  23837. if (sub.getNumItems() > 0)
  23838. {
  23839. menu.addSubMenu (lastSubMenuName, sub);
  23840. sub.clear();
  23841. }
  23842. lastSubMenuName = thisSubMenuName;
  23843. }
  23844. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23845. }
  23846. if (sub.getNumItems() > 0)
  23847. menu.addSubMenu (lastSubMenuName, sub);
  23848. }
  23849. else if (sortMethod == sortByFileSystemLocation)
  23850. {
  23851. PluginFilesystemTree root;
  23852. root.buildTree (sorted);
  23853. root.addToMenu (menu, types);
  23854. }
  23855. else
  23856. {
  23857. for (int i = 0; i < sorted.size(); ++i)
  23858. {
  23859. const PluginDescription* const pd = sorted.getUnchecked(i);
  23860. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23861. }
  23862. }
  23863. }
  23864. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23865. {
  23866. const int i = menuResultCode - menuIdBase;
  23867. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23868. }
  23869. END_JUCE_NAMESPACE
  23870. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23871. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23872. BEGIN_JUCE_NAMESPACE
  23873. PluginDescription::PluginDescription() throw()
  23874. : uid (0),
  23875. isInstrument (false),
  23876. numInputChannels (0),
  23877. numOutputChannels (0)
  23878. {
  23879. }
  23880. PluginDescription::~PluginDescription() throw()
  23881. {
  23882. }
  23883. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23884. : name (other.name),
  23885. pluginFormatName (other.pluginFormatName),
  23886. category (other.category),
  23887. manufacturerName (other.manufacturerName),
  23888. version (other.version),
  23889. fileOrIdentifier (other.fileOrIdentifier),
  23890. lastFileModTime (other.lastFileModTime),
  23891. uid (other.uid),
  23892. isInstrument (other.isInstrument),
  23893. numInputChannels (other.numInputChannels),
  23894. numOutputChannels (other.numOutputChannels)
  23895. {
  23896. }
  23897. const PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23898. {
  23899. name = other.name;
  23900. pluginFormatName = other.pluginFormatName;
  23901. category = other.category;
  23902. manufacturerName = other.manufacturerName;
  23903. version = other.version;
  23904. fileOrIdentifier = other.fileOrIdentifier;
  23905. uid = other.uid;
  23906. isInstrument = other.isInstrument;
  23907. lastFileModTime = other.lastFileModTime;
  23908. numInputChannels = other.numInputChannels;
  23909. numOutputChannels = other.numOutputChannels;
  23910. return *this;
  23911. }
  23912. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23913. {
  23914. return fileOrIdentifier == other.fileOrIdentifier
  23915. && uid == other.uid;
  23916. }
  23917. const String PluginDescription::createIdentifierString() const throw()
  23918. {
  23919. return pluginFormatName
  23920. + T("-") + name
  23921. + T("-") + String::toHexString (fileOrIdentifier.hashCode())
  23922. + T("-") + String::toHexString (uid);
  23923. }
  23924. XmlElement* PluginDescription::createXml() const
  23925. {
  23926. XmlElement* const e = new XmlElement (T("PLUGIN"));
  23927. e->setAttribute (T("name"), name);
  23928. e->setAttribute (T("format"), pluginFormatName);
  23929. e->setAttribute (T("category"), category);
  23930. e->setAttribute (T("manufacturer"), manufacturerName);
  23931. e->setAttribute (T("version"), version);
  23932. e->setAttribute (T("file"), fileOrIdentifier);
  23933. e->setAttribute (T("uid"), String::toHexString (uid));
  23934. e->setAttribute (T("isInstrument"), isInstrument);
  23935. e->setAttribute (T("fileTime"), String::toHexString (lastFileModTime.toMilliseconds()));
  23936. e->setAttribute (T("numInputs"), numInputChannels);
  23937. e->setAttribute (T("numOutputs"), numOutputChannels);
  23938. return e;
  23939. }
  23940. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23941. {
  23942. if (xml.hasTagName (T("PLUGIN")))
  23943. {
  23944. name = xml.getStringAttribute (T("name"));
  23945. pluginFormatName = xml.getStringAttribute (T("format"));
  23946. category = xml.getStringAttribute (T("category"));
  23947. manufacturerName = xml.getStringAttribute (T("manufacturer"));
  23948. version = xml.getStringAttribute (T("version"));
  23949. fileOrIdentifier = xml.getStringAttribute (T("file"));
  23950. uid = xml.getStringAttribute (T("uid")).getHexValue32();
  23951. isInstrument = xml.getBoolAttribute (T("isInstrument"), false);
  23952. lastFileModTime = Time (xml.getStringAttribute (T("fileTime")).getHexValue64());
  23953. numInputChannels = xml.getIntAttribute (T("numInputs"));
  23954. numOutputChannels = xml.getIntAttribute (T("numOutputs"));
  23955. return true;
  23956. }
  23957. return false;
  23958. }
  23959. END_JUCE_NAMESPACE
  23960. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23961. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23962. BEGIN_JUCE_NAMESPACE
  23963. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23964. AudioPluginFormat& formatToLookFor,
  23965. FileSearchPath directoriesToSearch,
  23966. const bool recursive,
  23967. const File& deadMansPedalFile_)
  23968. : list (listToAddTo),
  23969. format (formatToLookFor),
  23970. deadMansPedalFile (deadMansPedalFile_),
  23971. nextIndex (0),
  23972. progress (0)
  23973. {
  23974. directoriesToSearch.removeRedundantPaths();
  23975. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23976. // If any plugins have crashed recently when being loaded, move them to the
  23977. // end of the list to give the others a chance to load correctly..
  23978. const StringArray crashedPlugins (getDeadMansPedalFile());
  23979. for (int i = 0; i < crashedPlugins.size(); ++i)
  23980. {
  23981. const String f = crashedPlugins[i];
  23982. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23983. if (f == filesOrIdentifiersToScan[j])
  23984. filesOrIdentifiersToScan.move (j, -1);
  23985. }
  23986. }
  23987. PluginDirectoryScanner::~PluginDirectoryScanner()
  23988. {
  23989. }
  23990. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23991. {
  23992. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23993. }
  23994. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23995. {
  23996. String file (filesOrIdentifiersToScan [nextIndex]);
  23997. if (file.isNotEmpty())
  23998. {
  23999. if (! list.isListingUpToDate (file))
  24000. {
  24001. OwnedArray <PluginDescription> typesFound;
  24002. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  24003. StringArray crashedPlugins (getDeadMansPedalFile());
  24004. crashedPlugins.removeString (file);
  24005. crashedPlugins.add (file);
  24006. setDeadMansPedalFile (crashedPlugins);
  24007. list.scanAndAddFile (file,
  24008. dontRescanIfAlreadyInList,
  24009. typesFound,
  24010. format);
  24011. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  24012. crashedPlugins.removeString (file);
  24013. setDeadMansPedalFile (crashedPlugins);
  24014. if (typesFound.size() == 0)
  24015. failedFiles.add (file);
  24016. }
  24017. ++nextIndex;
  24018. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  24019. }
  24020. return nextIndex < filesOrIdentifiersToScan.size();
  24021. }
  24022. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  24023. {
  24024. StringArray lines;
  24025. if (deadMansPedalFile != File::nonexistent)
  24026. {
  24027. lines.addLines (deadMansPedalFile.loadFileAsString());
  24028. lines.removeEmptyStrings();
  24029. }
  24030. return lines;
  24031. }
  24032. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  24033. {
  24034. if (deadMansPedalFile != File::nonexistent)
  24035. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  24036. }
  24037. END_JUCE_NAMESPACE
  24038. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  24039. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  24040. BEGIN_JUCE_NAMESPACE
  24041. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  24042. const File& deadMansPedalFile_,
  24043. PropertiesFile* const propertiesToUse_)
  24044. : list (listToEdit),
  24045. deadMansPedalFile (deadMansPedalFile_),
  24046. propertiesToUse (propertiesToUse_)
  24047. {
  24048. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  24049. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  24050. optionsButton->addButtonListener (this);
  24051. optionsButton->setTriggeredOnMouseDown (true);
  24052. setSize (400, 600);
  24053. list.addChangeListener (this);
  24054. }
  24055. PluginListComponent::~PluginListComponent()
  24056. {
  24057. list.removeChangeListener (this);
  24058. deleteAllChildren();
  24059. }
  24060. void PluginListComponent::resized()
  24061. {
  24062. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  24063. optionsButton->changeWidthToFitText (24);
  24064. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  24065. }
  24066. void PluginListComponent::changeListenerCallback (void*)
  24067. {
  24068. listBox->updateContent();
  24069. listBox->repaint();
  24070. }
  24071. int PluginListComponent::getNumRows()
  24072. {
  24073. return list.getNumTypes();
  24074. }
  24075. void PluginListComponent::paintListBoxItem (int row,
  24076. Graphics& g,
  24077. int width, int height,
  24078. bool rowIsSelected)
  24079. {
  24080. if (rowIsSelected)
  24081. g.fillAll (findColour (TextEditor::highlightColourId));
  24082. const PluginDescription* const pd = list.getType (row);
  24083. if (pd != 0)
  24084. {
  24085. GlyphArrangement ga;
  24086. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  24087. g.setColour (Colours::black);
  24088. ga.draw (g);
  24089. float x, y, r, b;
  24090. ga.getBoundingBox (0, -1, x, y, r, b, false);
  24091. String desc;
  24092. desc << pd->pluginFormatName
  24093. << (pd->isInstrument ? " instrument" : " effect")
  24094. << " - "
  24095. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  24096. << " / "
  24097. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  24098. if (pd->manufacturerName.isNotEmpty())
  24099. desc << " - " << pd->manufacturerName;
  24100. if (pd->version.isNotEmpty())
  24101. desc << " - " << pd->version;
  24102. if (pd->category.isNotEmpty())
  24103. desc << " - category: '" << pd->category << '\'';
  24104. g.setColour (Colours::grey);
  24105. ga.clear();
  24106. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, r + 10.0f, height * 0.8f, width - r - 12.0f, true);
  24107. ga.draw (g);
  24108. }
  24109. }
  24110. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  24111. {
  24112. list.removeType (lastRowSelected);
  24113. }
  24114. void PluginListComponent::buttonClicked (Button* b)
  24115. {
  24116. if (optionsButton == b)
  24117. {
  24118. PopupMenu menu;
  24119. menu.addItem (1, TRANS("Clear list"));
  24120. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  24121. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  24122. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  24123. menu.addSeparator();
  24124. menu.addItem (2, TRANS("Sort alphabetically"));
  24125. menu.addItem (3, TRANS("Sort by category"));
  24126. menu.addItem (4, TRANS("Sort by manufacturer"));
  24127. menu.addSeparator();
  24128. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  24129. {
  24130. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  24131. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  24132. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  24133. }
  24134. const int r = menu.showAt (optionsButton);
  24135. if (r == 1)
  24136. {
  24137. list.clear();
  24138. }
  24139. else if (r == 2)
  24140. {
  24141. list.sort (KnownPluginList::sortAlphabetically);
  24142. }
  24143. else if (r == 3)
  24144. {
  24145. list.sort (KnownPluginList::sortByCategory);
  24146. }
  24147. else if (r == 4)
  24148. {
  24149. list.sort (KnownPluginList::sortByManufacturer);
  24150. }
  24151. else if (r == 5)
  24152. {
  24153. const SparseSet <int> selected (listBox->getSelectedRows());
  24154. for (int i = list.getNumTypes(); --i >= 0;)
  24155. if (selected.contains (i))
  24156. list.removeType (i);
  24157. }
  24158. else if (r == 6)
  24159. {
  24160. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  24161. if (desc != 0)
  24162. {
  24163. if (File (desc->fileOrIdentifier).existsAsFile())
  24164. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  24165. }
  24166. }
  24167. else if (r == 7)
  24168. {
  24169. for (int i = list.getNumTypes(); --i >= 0;)
  24170. {
  24171. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  24172. {
  24173. list.removeType (i);
  24174. }
  24175. }
  24176. }
  24177. else if (r != 0)
  24178. {
  24179. typeToScan = r - 10;
  24180. startTimer (1);
  24181. }
  24182. }
  24183. }
  24184. void PluginListComponent::timerCallback()
  24185. {
  24186. stopTimer();
  24187. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  24188. }
  24189. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  24190. {
  24191. return true;
  24192. }
  24193. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  24194. {
  24195. OwnedArray <PluginDescription> typesFound;
  24196. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  24197. }
  24198. void PluginListComponent::scanFor (AudioPluginFormat* format)
  24199. {
  24200. if (format == 0)
  24201. return;
  24202. FileSearchPath path (format->getDefaultLocationsToSearch());
  24203. if (propertiesToUse != 0)
  24204. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24205. {
  24206. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  24207. FileSearchPathListComponent pathList;
  24208. pathList.setSize (500, 300);
  24209. pathList.setPath (path);
  24210. aw.addCustomComponent (&pathList);
  24211. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  24212. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24213. if (aw.runModalLoop() == 0)
  24214. return;
  24215. path = pathList.getPath();
  24216. }
  24217. if (propertiesToUse != 0)
  24218. {
  24219. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24220. propertiesToUse->saveIfNeeded();
  24221. }
  24222. double progress = 0.0;
  24223. AlertWindow aw (TRANS("Scanning for plugins..."),
  24224. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  24225. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24226. aw.addProgressBarComponent (progress);
  24227. aw.enterModalState();
  24228. MessageManager::getInstance()->runDispatchLoopUntil (300);
  24229. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  24230. for (;;)
  24231. {
  24232. aw.setMessage (TRANS("Testing:\n\n")
  24233. + scanner.getNextPluginFileThatWillBeScanned());
  24234. MessageManager::getInstance()->runDispatchLoopUntil (20);
  24235. if (! scanner.scanNextFile (true))
  24236. break;
  24237. if (! aw.isCurrentlyModal())
  24238. break;
  24239. progress = scanner.getProgress();
  24240. }
  24241. if (scanner.getFailedFiles().size() > 0)
  24242. {
  24243. StringArray shortNames;
  24244. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  24245. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  24246. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  24247. TRANS("Scan complete"),
  24248. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  24249. + shortNames.joinIntoString (", "));
  24250. }
  24251. }
  24252. END_JUCE_NAMESPACE
  24253. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  24254. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  24255. #if JUCE_PLUGINHOST_AU && (! (defined (LINUX) || defined (_WIN32)))
  24256. #include <AudioUnit/AudioUnit.h>
  24257. #include <AudioUnit/AUCocoaUIView.h>
  24258. #include <CoreAudioKit/AUGenericView.h>
  24259. #if JUCE_SUPPORT_CARBON
  24260. #include <AudioToolbox/AudioUnitUtilities.h>
  24261. #include <AudioUnit/AudioUnitCarbonView.h>
  24262. #endif
  24263. BEGIN_JUCE_NAMESPACE
  24264. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  24265. #endif
  24266. #if JUCE_MAC
  24267. // Change this to disable logging of various activities
  24268. #ifndef AU_LOGGING
  24269. #define AU_LOGGING 1
  24270. #endif
  24271. #if AU_LOGGING
  24272. #define log(a) Logger::writeToLog(a);
  24273. #else
  24274. #define log(a)
  24275. #endif
  24276. static int insideCallback = 0;
  24277. static const String osTypeToString (OSType type) throw()
  24278. {
  24279. char s[4];
  24280. s[0] = (char) (((uint32) type) >> 24);
  24281. s[1] = (char) (((uint32) type) >> 16);
  24282. s[2] = (char) (((uint32) type) >> 8);
  24283. s[3] = (char) ((uint32) type);
  24284. return String (s, 4);
  24285. }
  24286. static OSType stringToOSType (const String& s1) throw()
  24287. {
  24288. const String s (s1 + " ");
  24289. return (((OSType) (unsigned char) s[0]) << 24)
  24290. | (((OSType) (unsigned char) s[1]) << 16)
  24291. | (((OSType) (unsigned char) s[2]) << 8)
  24292. | ((OSType) (unsigned char) s[3]);
  24293. }
  24294. static const tchar* auIdentifierPrefix = T("AudioUnit:");
  24295. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  24296. {
  24297. jassert (osTypeToString ('abcd') == T("abcd")); // agh, must have got the endianness wrong..
  24298. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  24299. String s (auIdentifierPrefix);
  24300. if (desc.componentType == kAudioUnitType_MusicDevice)
  24301. s << "Synths/";
  24302. else if (desc.componentType == kAudioUnitType_MusicEffect
  24303. || desc.componentType == kAudioUnitType_Effect)
  24304. s << "Effects/";
  24305. else if (desc.componentType == kAudioUnitType_Generator)
  24306. s << "Generators/";
  24307. else if (desc.componentType == kAudioUnitType_Panner)
  24308. s << "Panners/";
  24309. s << osTypeToString (desc.componentType)
  24310. << T(",")
  24311. << osTypeToString (desc.componentSubType)
  24312. << T(",")
  24313. << osTypeToString (desc.componentManufacturer);
  24314. return s;
  24315. }
  24316. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  24317. {
  24318. Handle componentNameHandle = NewHandle (sizeof (void*));
  24319. Handle componentInfoHandle = NewHandle (sizeof (void*));
  24320. if (componentNameHandle != 0 && componentInfoHandle != 0)
  24321. {
  24322. ComponentDescription desc;
  24323. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24324. {
  24325. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24326. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24327. if (nameString != 0 && nameString[0] != 0)
  24328. {
  24329. const String all ((const char*) nameString + 1, nameString[0]);
  24330. DBG ("name: "+ all);
  24331. manufacturer = all.upToFirstOccurrenceOf (T(":"), false, false).trim();
  24332. name = all.fromFirstOccurrenceOf (T(":"), false, false).trim();
  24333. }
  24334. if (infoString != 0 && infoString[0] != 0)
  24335. {
  24336. const String all ((const char*) infoString + 1, infoString[0]);
  24337. DBG ("info: " + all);
  24338. }
  24339. if (name.isEmpty())
  24340. name = "<Unknown>";
  24341. }
  24342. DisposeHandle (componentNameHandle);
  24343. DisposeHandle (componentInfoHandle);
  24344. }
  24345. }
  24346. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24347. String& name, String& version, String& manufacturer)
  24348. {
  24349. zerostruct (desc);
  24350. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24351. {
  24352. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (T(':')),
  24353. fileOrIdentifier.lastIndexOfChar (T('/'))) + 1));
  24354. StringArray tokens;
  24355. tokens.addTokens (s, T(","), 0);
  24356. tokens.trim();
  24357. tokens.removeEmptyStrings();
  24358. if (tokens.size() == 3)
  24359. {
  24360. desc.componentType = stringToOSType (tokens[0]);
  24361. desc.componentSubType = stringToOSType (tokens[1]);
  24362. desc.componentManufacturer = stringToOSType (tokens[2]);
  24363. ComponentRecord* comp = FindNextComponent (0, &desc);
  24364. if (comp != 0)
  24365. {
  24366. getAUDetails (comp, name, manufacturer);
  24367. return true;
  24368. }
  24369. }
  24370. }
  24371. return false;
  24372. }
  24373. class AudioUnitPluginWindowCarbon;
  24374. class AudioUnitPluginWindowCocoa;
  24375. class AudioUnitPluginInstance : public AudioPluginInstance
  24376. {
  24377. public:
  24378. ~AudioUnitPluginInstance();
  24379. // AudioPluginInstance methods:
  24380. void fillInPluginDescription (PluginDescription& desc) const
  24381. {
  24382. desc.name = pluginName;
  24383. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24384. desc.uid = ((int) componentDesc.componentType)
  24385. ^ ((int) componentDesc.componentSubType)
  24386. ^ ((int) componentDesc.componentManufacturer);
  24387. desc.lastFileModTime = 0;
  24388. desc.pluginFormatName = "AudioUnit";
  24389. desc.category = getCategory();
  24390. desc.manufacturerName = manufacturer;
  24391. desc.version = version;
  24392. desc.numInputChannels = getNumInputChannels();
  24393. desc.numOutputChannels = getNumOutputChannels();
  24394. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24395. }
  24396. const String getName() const { return pluginName; }
  24397. bool acceptsMidi() const { return wantsMidiMessages; }
  24398. bool producesMidi() const { return false; }
  24399. // AudioProcessor methods:
  24400. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24401. void releaseResources();
  24402. void processBlock (AudioSampleBuffer& buffer,
  24403. MidiBuffer& midiMessages);
  24404. AudioProcessorEditor* createEditor();
  24405. const String getInputChannelName (const int index) const;
  24406. bool isInputChannelStereoPair (int index) const;
  24407. const String getOutputChannelName (const int index) const;
  24408. bool isOutputChannelStereoPair (int index) const;
  24409. int getNumParameters();
  24410. float getParameter (int index);
  24411. void setParameter (int index, float newValue);
  24412. const String getParameterName (int index);
  24413. const String getParameterText (int index);
  24414. bool isParameterAutomatable (int index) const;
  24415. int getNumPrograms();
  24416. int getCurrentProgram();
  24417. void setCurrentProgram (int index);
  24418. const String getProgramName (int index);
  24419. void changeProgramName (int index, const String& newName);
  24420. void getStateInformation (MemoryBlock& destData);
  24421. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24422. void setStateInformation (const void* data, int sizeInBytes);
  24423. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24424. juce_UseDebuggingNewOperator
  24425. private:
  24426. friend class AudioUnitPluginWindowCarbon;
  24427. friend class AudioUnitPluginWindowCocoa;
  24428. friend class AudioUnitPluginFormat;
  24429. ComponentDescription componentDesc;
  24430. String pluginName, manufacturer, version;
  24431. String fileOrIdentifier;
  24432. CriticalSection lock;
  24433. bool initialised, wantsMidiMessages, wasPlaying;
  24434. HeapBlock <AudioBufferList> outputBufferList;
  24435. AudioTimeStamp timeStamp;
  24436. AudioSampleBuffer* currentBuffer;
  24437. AudioUnit audioUnit;
  24438. Array <int> parameterIds;
  24439. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24440. void initialise();
  24441. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24442. const AudioTimeStamp* inTimeStamp,
  24443. UInt32 inBusNumber,
  24444. UInt32 inNumberFrames,
  24445. AudioBufferList* ioData) const;
  24446. static OSStatus renderGetInputCallback (void* inRefCon,
  24447. AudioUnitRenderActionFlags* ioActionFlags,
  24448. const AudioTimeStamp* inTimeStamp,
  24449. UInt32 inBusNumber,
  24450. UInt32 inNumberFrames,
  24451. AudioBufferList* ioData)
  24452. {
  24453. return ((AudioUnitPluginInstance*) inRefCon)
  24454. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24455. }
  24456. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24457. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24458. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24459. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24460. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24461. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24462. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24463. {
  24464. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24465. }
  24466. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24467. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24468. Float64* outCurrentMeasureDownBeat)
  24469. {
  24470. return ((AudioUnitPluginInstance*) inHostUserData)
  24471. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24472. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24473. }
  24474. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24475. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24476. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24477. {
  24478. return ((AudioUnitPluginInstance*) inHostUserData)
  24479. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24480. outCurrentSampleInTimeLine, outIsCycling,
  24481. outCycleStartBeat, outCycleEndBeat);
  24482. }
  24483. void getNumChannels (int& numIns, int& numOuts)
  24484. {
  24485. numIns = 0;
  24486. numOuts = 0;
  24487. AUChannelInfo supportedChannels [128];
  24488. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24489. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24490. 0, supportedChannels, &supportedChannelsSize) == noErr
  24491. && supportedChannelsSize > 0)
  24492. {
  24493. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24494. {
  24495. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24496. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24497. }
  24498. }
  24499. else
  24500. {
  24501. // (this really means the plugin will take any number of ins/outs as long
  24502. // as they are the same)
  24503. numIns = numOuts = 2;
  24504. }
  24505. }
  24506. const String getCategory() const;
  24507. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24508. };
  24509. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24510. : fileOrIdentifier (fileOrIdentifier),
  24511. initialised (false),
  24512. wantsMidiMessages (false),
  24513. audioUnit (0),
  24514. currentBuffer (0)
  24515. {
  24516. try
  24517. {
  24518. ++insideCallback;
  24519. log (T("Opening AU: ") + fileOrIdentifier);
  24520. if (getComponentDescFromFile (fileOrIdentifier))
  24521. {
  24522. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24523. if (comp != 0)
  24524. {
  24525. audioUnit = (AudioUnit) OpenComponent (comp);
  24526. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24527. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24528. }
  24529. }
  24530. --insideCallback;
  24531. }
  24532. catch (...)
  24533. {
  24534. --insideCallback;
  24535. }
  24536. }
  24537. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24538. {
  24539. {
  24540. const ScopedLock sl (lock);
  24541. jassert (insideCallback == 0);
  24542. if (audioUnit != 0)
  24543. {
  24544. AudioUnitUninitialize (audioUnit);
  24545. CloseComponent (audioUnit);
  24546. audioUnit = 0;
  24547. }
  24548. }
  24549. }
  24550. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24551. {
  24552. zerostruct (componentDesc);
  24553. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24554. return true;
  24555. const File file (fileOrIdentifier);
  24556. if (! file.hasFileExtension (T(".component")))
  24557. return false;
  24558. const char* const utf8 = fileOrIdentifier.toUTF8();
  24559. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24560. strlen (utf8), file.isDirectory());
  24561. if (url != 0)
  24562. {
  24563. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24564. CFRelease (url);
  24565. if (bundleRef != 0)
  24566. {
  24567. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24568. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24569. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24570. if (pluginName.isEmpty())
  24571. pluginName = file.getFileNameWithoutExtension();
  24572. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24573. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24574. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24575. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24576. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24577. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24578. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24579. UseResFile (resFileId);
  24580. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24581. {
  24582. Handle h = Get1IndResource ('thng', i);
  24583. if (h != 0)
  24584. {
  24585. HLock (h);
  24586. const uint32* const types = (const uint32*) *h;
  24587. if (types[0] == kAudioUnitType_MusicDevice
  24588. || types[0] == kAudioUnitType_MusicEffect
  24589. || types[0] == kAudioUnitType_Effect
  24590. || types[0] == kAudioUnitType_Generator
  24591. || types[0] == kAudioUnitType_Panner)
  24592. {
  24593. componentDesc.componentType = types[0];
  24594. componentDesc.componentSubType = types[1];
  24595. componentDesc.componentManufacturer = types[2];
  24596. break;
  24597. }
  24598. HUnlock (h);
  24599. ReleaseResource (h);
  24600. }
  24601. }
  24602. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24603. CFRelease (bundleRef);
  24604. }
  24605. }
  24606. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24607. }
  24608. void AudioUnitPluginInstance::initialise()
  24609. {
  24610. if (initialised || audioUnit == 0)
  24611. return;
  24612. log (T("Initialising AU: ") + pluginName);
  24613. parameterIds.clear();
  24614. {
  24615. UInt32 paramListSize = 0;
  24616. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24617. 0, 0, &paramListSize);
  24618. if (paramListSize > 0)
  24619. {
  24620. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24621. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24622. 0, &parameterIds.getReference(0), &paramListSize);
  24623. }
  24624. }
  24625. {
  24626. AURenderCallbackStruct info;
  24627. zerostruct (info);
  24628. info.inputProcRefCon = this;
  24629. info.inputProc = renderGetInputCallback;
  24630. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24631. 0, &info, sizeof (info));
  24632. }
  24633. {
  24634. HostCallbackInfo info;
  24635. zerostruct (info);
  24636. info.hostUserData = this;
  24637. info.beatAndTempoProc = getBeatAndTempoCallback;
  24638. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24639. info.transportStateProc = getTransportStateCallback;
  24640. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24641. 0, &info, sizeof (info));
  24642. }
  24643. int numIns, numOuts;
  24644. getNumChannels (numIns, numOuts);
  24645. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24646. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24647. setLatencySamples (0);
  24648. }
  24649. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24650. int samplesPerBlockExpected)
  24651. {
  24652. initialise();
  24653. if (initialised)
  24654. {
  24655. int numIns, numOuts;
  24656. getNumChannels (numIns, numOuts);
  24657. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24658. Float64 latencySecs = 0.0;
  24659. UInt32 latencySize = sizeof (latencySecs);
  24660. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24661. 0, &latencySecs, &latencySize);
  24662. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24663. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24664. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24665. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24666. AudioStreamBasicDescription stream;
  24667. zerostruct (stream);
  24668. stream.mSampleRate = sampleRate_;
  24669. stream.mFormatID = kAudioFormatLinearPCM;
  24670. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24671. stream.mFramesPerPacket = 1;
  24672. stream.mBytesPerPacket = 4;
  24673. stream.mBytesPerFrame = 4;
  24674. stream.mBitsPerChannel = 32;
  24675. stream.mChannelsPerFrame = numIns;
  24676. OSStatus err = AudioUnitSetProperty (audioUnit,
  24677. kAudioUnitProperty_StreamFormat,
  24678. kAudioUnitScope_Input,
  24679. 0, &stream, sizeof (stream));
  24680. stream.mChannelsPerFrame = numOuts;
  24681. err = AudioUnitSetProperty (audioUnit,
  24682. kAudioUnitProperty_StreamFormat,
  24683. kAudioUnitScope_Output,
  24684. 0, &stream, sizeof (stream));
  24685. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24686. outputBufferList->mNumberBuffers = numOuts;
  24687. for (int i = numOuts; --i >= 0;)
  24688. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24689. zerostruct (timeStamp);
  24690. timeStamp.mSampleTime = 0;
  24691. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24692. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24693. currentBuffer = 0;
  24694. wasPlaying = false;
  24695. }
  24696. }
  24697. void AudioUnitPluginInstance::releaseResources()
  24698. {
  24699. if (initialised)
  24700. {
  24701. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24702. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24703. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24704. outputBufferList.free();
  24705. currentBuffer = 0;
  24706. }
  24707. }
  24708. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24709. const AudioTimeStamp* inTimeStamp,
  24710. UInt32 inBusNumber,
  24711. UInt32 inNumberFrames,
  24712. AudioBufferList* ioData) const
  24713. {
  24714. if (inBusNumber == 0
  24715. && currentBuffer != 0)
  24716. {
  24717. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24718. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24719. {
  24720. if (i < currentBuffer->getNumChannels())
  24721. {
  24722. memcpy (ioData->mBuffers[i].mData,
  24723. currentBuffer->getSampleData (i, 0),
  24724. sizeof (float) * inNumberFrames);
  24725. }
  24726. else
  24727. {
  24728. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24729. }
  24730. }
  24731. }
  24732. return noErr;
  24733. }
  24734. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24735. MidiBuffer& midiMessages)
  24736. {
  24737. const int numSamples = buffer.getNumSamples();
  24738. if (initialised)
  24739. {
  24740. AudioUnitRenderActionFlags flags = 0;
  24741. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24742. for (int i = getNumOutputChannels(); --i >= 0;)
  24743. {
  24744. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24745. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24746. }
  24747. currentBuffer = &buffer;
  24748. if (wantsMidiMessages)
  24749. {
  24750. const uint8* midiEventData;
  24751. int midiEventSize, midiEventPosition;
  24752. MidiBuffer::Iterator i (midiMessages);
  24753. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24754. {
  24755. if (midiEventSize <= 3)
  24756. MusicDeviceMIDIEvent (audioUnit,
  24757. midiEventData[0], midiEventData[1], midiEventData[2],
  24758. midiEventPosition);
  24759. else
  24760. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24761. }
  24762. midiMessages.clear();
  24763. }
  24764. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24765. 0, numSamples, outputBufferList);
  24766. timeStamp.mSampleTime += numSamples;
  24767. }
  24768. else
  24769. {
  24770. // Not initialised, so just bypass..
  24771. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24772. buffer.clear (i, 0, buffer.getNumSamples());
  24773. }
  24774. }
  24775. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24776. {
  24777. AudioPlayHead* const ph = getPlayHead();
  24778. AudioPlayHead::CurrentPositionInfo result;
  24779. if (ph != 0 && ph->getCurrentPosition (result))
  24780. {
  24781. if (outCurrentBeat != 0)
  24782. *outCurrentBeat = result.ppqPosition;
  24783. if (outCurrentTempo != 0)
  24784. *outCurrentTempo = result.bpm;
  24785. }
  24786. else
  24787. {
  24788. if (outCurrentBeat != 0)
  24789. *outCurrentBeat = 0;
  24790. if (outCurrentTempo != 0)
  24791. *outCurrentTempo = 120.0;
  24792. }
  24793. return noErr;
  24794. }
  24795. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24796. Float32* outTimeSig_Numerator,
  24797. UInt32* outTimeSig_Denominator,
  24798. Float64* outCurrentMeasureDownBeat) const
  24799. {
  24800. AudioPlayHead* const ph = getPlayHead();
  24801. AudioPlayHead::CurrentPositionInfo result;
  24802. if (ph != 0 && ph->getCurrentPosition (result))
  24803. {
  24804. if (outTimeSig_Numerator != 0)
  24805. *outTimeSig_Numerator = result.timeSigNumerator;
  24806. if (outTimeSig_Denominator != 0)
  24807. *outTimeSig_Denominator = result.timeSigDenominator;
  24808. if (outDeltaSampleOffsetToNextBeat != 0)
  24809. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24810. if (outCurrentMeasureDownBeat != 0)
  24811. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24812. }
  24813. else
  24814. {
  24815. if (outDeltaSampleOffsetToNextBeat != 0)
  24816. *outDeltaSampleOffsetToNextBeat = 0;
  24817. if (outTimeSig_Numerator != 0)
  24818. *outTimeSig_Numerator = 4;
  24819. if (outTimeSig_Denominator != 0)
  24820. *outTimeSig_Denominator = 4;
  24821. if (outCurrentMeasureDownBeat != 0)
  24822. *outCurrentMeasureDownBeat = 0;
  24823. }
  24824. return noErr;
  24825. }
  24826. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24827. Boolean* outTransportStateChanged,
  24828. Float64* outCurrentSampleInTimeLine,
  24829. Boolean* outIsCycling,
  24830. Float64* outCycleStartBeat,
  24831. Float64* outCycleEndBeat)
  24832. {
  24833. AudioPlayHead* const ph = getPlayHead();
  24834. AudioPlayHead::CurrentPositionInfo result;
  24835. if (ph != 0 && ph->getCurrentPosition (result))
  24836. {
  24837. if (outIsPlaying != 0)
  24838. *outIsPlaying = result.isPlaying;
  24839. if (outTransportStateChanged != 0)
  24840. {
  24841. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24842. wasPlaying = result.isPlaying;
  24843. }
  24844. if (outCurrentSampleInTimeLine != 0)
  24845. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24846. if (outIsCycling != 0)
  24847. *outIsCycling = false;
  24848. if (outCycleStartBeat != 0)
  24849. *outCycleStartBeat = 0;
  24850. if (outCycleEndBeat != 0)
  24851. *outCycleEndBeat = 0;
  24852. }
  24853. else
  24854. {
  24855. if (outIsPlaying != 0)
  24856. *outIsPlaying = false;
  24857. if (outTransportStateChanged != 0)
  24858. *outTransportStateChanged = false;
  24859. if (outCurrentSampleInTimeLine != 0)
  24860. *outCurrentSampleInTimeLine = 0;
  24861. if (outIsCycling != 0)
  24862. *outIsCycling = false;
  24863. if (outCycleStartBeat != 0)
  24864. *outCycleStartBeat = 0;
  24865. if (outCycleEndBeat != 0)
  24866. *outCycleEndBeat = 0;
  24867. }
  24868. return noErr;
  24869. }
  24870. static VoidArray activeWindows;
  24871. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24872. {
  24873. public:
  24874. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24875. : AudioProcessorEditor (&plugin_),
  24876. plugin (plugin_),
  24877. wrapper (0)
  24878. {
  24879. addAndMakeVisible (wrapper = new NSViewComponent());
  24880. activeWindows.add (this);
  24881. setOpaque (true);
  24882. setVisible (true);
  24883. setSize (100, 100);
  24884. createView (createGenericViewIfNeeded);
  24885. }
  24886. ~AudioUnitPluginWindowCocoa()
  24887. {
  24888. const bool wasValid = isValid();
  24889. wrapper->setView (0);
  24890. activeWindows.removeValue (this);
  24891. if (wasValid)
  24892. plugin.editorBeingDeleted (this);
  24893. delete wrapper;
  24894. }
  24895. bool isValid() const { return wrapper->getView() != 0; }
  24896. void paint (Graphics& g)
  24897. {
  24898. g.fillAll (Colours::white);
  24899. }
  24900. void resized()
  24901. {
  24902. wrapper->setSize (getWidth(), getHeight());
  24903. }
  24904. private:
  24905. AudioUnitPluginInstance& plugin;
  24906. NSViewComponent* wrapper;
  24907. bool createView (const bool createGenericViewIfNeeded)
  24908. {
  24909. NSView* pluginView = 0;
  24910. UInt32 dataSize = 0;
  24911. Boolean isWritable = false;
  24912. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24913. 0, &dataSize, &isWritable) == noErr
  24914. && dataSize != 0
  24915. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24916. 0, &dataSize, &isWritable) == noErr)
  24917. {
  24918. HeapBlock <AudioUnitCocoaViewInfo> info;
  24919. info.calloc (dataSize, 1);
  24920. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24921. 0, info, &dataSize) == noErr)
  24922. {
  24923. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24924. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24925. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24926. Class viewClass = [viewBundle classNamed: viewClassName];
  24927. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24928. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24929. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24930. {
  24931. id factory = [[[viewClass alloc] init] autorelease];
  24932. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24933. withSize: NSMakeSize (getWidth(), getHeight())];
  24934. }
  24935. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24936. {
  24937. CFRelease (info->mCocoaAUViewClass[i]);
  24938. CFRelease (info->mCocoaAUViewBundleLocation);
  24939. }
  24940. }
  24941. }
  24942. if (createGenericViewIfNeeded && (pluginView == 0))
  24943. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24944. wrapper->setView (pluginView);
  24945. if (pluginView != 0)
  24946. setSize ([pluginView frame].size.width,
  24947. [pluginView frame].size.height);
  24948. return pluginView != 0;
  24949. }
  24950. };
  24951. #if JUCE_SUPPORT_CARBON
  24952. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24953. {
  24954. public:
  24955. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24956. : AudioProcessorEditor (&plugin_),
  24957. plugin (plugin_),
  24958. viewComponent (0)
  24959. {
  24960. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24961. activeWindows.add (this);
  24962. setOpaque (true);
  24963. setVisible (true);
  24964. setSize (400, 300);
  24965. ComponentDescription viewList [16];
  24966. UInt32 viewListSize = sizeof (viewList);
  24967. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24968. 0, &viewList, &viewListSize);
  24969. componentRecord = FindNextComponent (0, &viewList[0]);
  24970. }
  24971. ~AudioUnitPluginWindowCarbon()
  24972. {
  24973. deleteAndZero (innerWrapper);
  24974. activeWindows.removeValue (this);
  24975. if (isValid())
  24976. plugin.editorBeingDeleted (this);
  24977. }
  24978. bool isValid() const throw() { return componentRecord != 0; }
  24979. void paint (Graphics& g)
  24980. {
  24981. g.fillAll (Colours::black);
  24982. }
  24983. void resized()
  24984. {
  24985. innerWrapper->setSize (getWidth(), getHeight());
  24986. }
  24987. bool keyStateChanged (const bool)
  24988. {
  24989. return false;
  24990. }
  24991. bool keyPressed (const KeyPress&)
  24992. {
  24993. return false;
  24994. }
  24995. void broughtToFront()
  24996. {
  24997. activeWindows.removeValue (this);
  24998. activeWindows.add (this);
  24999. }
  25000. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  25001. AudioUnitCarbonView getViewComponent()
  25002. {
  25003. if (viewComponent == 0 && componentRecord != 0)
  25004. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  25005. return viewComponent;
  25006. }
  25007. void closeViewComponent()
  25008. {
  25009. if (viewComponent != 0)
  25010. {
  25011. CloseComponent (viewComponent);
  25012. viewComponent = 0;
  25013. }
  25014. }
  25015. juce_UseDebuggingNewOperator
  25016. private:
  25017. AudioUnitPluginInstance& plugin;
  25018. ComponentRecord* componentRecord;
  25019. AudioUnitCarbonView viewComponent;
  25020. class InnerWrapperComponent : public CarbonViewWrapperComponent
  25021. {
  25022. public:
  25023. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  25024. : owner (owner_)
  25025. {
  25026. }
  25027. ~InnerWrapperComponent()
  25028. {
  25029. deleteWindow();
  25030. }
  25031. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  25032. {
  25033. log (T("Opening AU GUI: ") + owner->plugin.getName());
  25034. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  25035. if (viewComponent == 0)
  25036. return 0;
  25037. Float32Point pos = { 0, 0 };
  25038. Float32Point size = { 250, 200 };
  25039. HIViewRef pluginView = 0;
  25040. AudioUnitCarbonViewCreate (viewComponent,
  25041. owner->getAudioUnit(),
  25042. windowRef,
  25043. rootView,
  25044. &pos,
  25045. &size,
  25046. (ControlRef*) &pluginView);
  25047. return pluginView;
  25048. }
  25049. void removeView (HIViewRef)
  25050. {
  25051. log (T("Closing AU GUI: ") + owner->plugin.getName());
  25052. owner->closeViewComponent();
  25053. }
  25054. private:
  25055. AudioUnitPluginWindowCarbon* const owner;
  25056. };
  25057. friend class InnerWrapperComponent;
  25058. InnerWrapperComponent* innerWrapper;
  25059. };
  25060. #endif
  25061. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  25062. {
  25063. ScopedPointer <AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  25064. if (! ((AudioUnitPluginWindowCocoa*) w)->isValid())
  25065. w = 0;
  25066. #if JUCE_SUPPORT_CARBON
  25067. if (w == 0)
  25068. {
  25069. w = new AudioUnitPluginWindowCarbon (*this);
  25070. if (! ((AudioUnitPluginWindowCarbon*) w)->isValid())
  25071. w = 0;
  25072. }
  25073. #endif
  25074. if (w == 0)
  25075. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  25076. return w.release();
  25077. }
  25078. const String AudioUnitPluginInstance::getCategory() const
  25079. {
  25080. const char* result = 0;
  25081. switch (componentDesc.componentType)
  25082. {
  25083. case kAudioUnitType_Effect:
  25084. case kAudioUnitType_MusicEffect:
  25085. result = "Effect";
  25086. break;
  25087. case kAudioUnitType_MusicDevice:
  25088. result = "Synth";
  25089. break;
  25090. case kAudioUnitType_Generator:
  25091. result = "Generator";
  25092. break;
  25093. case kAudioUnitType_Panner:
  25094. result = "Panner";
  25095. break;
  25096. default:
  25097. break;
  25098. }
  25099. return result;
  25100. }
  25101. int AudioUnitPluginInstance::getNumParameters()
  25102. {
  25103. return parameterIds.size();
  25104. }
  25105. float AudioUnitPluginInstance::getParameter (int index)
  25106. {
  25107. const ScopedLock sl (lock);
  25108. Float32 value = 0.0f;
  25109. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25110. {
  25111. AudioUnitGetParameter (audioUnit,
  25112. (UInt32) parameterIds.getUnchecked (index),
  25113. kAudioUnitScope_Global, 0,
  25114. &value);
  25115. }
  25116. return value;
  25117. }
  25118. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  25119. {
  25120. const ScopedLock sl (lock);
  25121. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25122. {
  25123. AudioUnitSetParameter (audioUnit,
  25124. (UInt32) parameterIds.getUnchecked (index),
  25125. kAudioUnitScope_Global, 0,
  25126. newValue, 0);
  25127. }
  25128. }
  25129. const String AudioUnitPluginInstance::getParameterName (int index)
  25130. {
  25131. AudioUnitParameterInfo info;
  25132. zerostruct (info);
  25133. UInt32 sz = sizeof (info);
  25134. String name;
  25135. if (AudioUnitGetProperty (audioUnit,
  25136. kAudioUnitProperty_ParameterInfo,
  25137. kAudioUnitScope_Global,
  25138. parameterIds [index], &info, &sz) == noErr)
  25139. {
  25140. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  25141. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  25142. else
  25143. name = String (info.name, sizeof (info.name));
  25144. }
  25145. return name;
  25146. }
  25147. const String AudioUnitPluginInstance::getParameterText (int index)
  25148. {
  25149. return String (getParameter (index));
  25150. }
  25151. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  25152. {
  25153. AudioUnitParameterInfo info;
  25154. UInt32 sz = sizeof (info);
  25155. if (AudioUnitGetProperty (audioUnit,
  25156. kAudioUnitProperty_ParameterInfo,
  25157. kAudioUnitScope_Global,
  25158. parameterIds [index], &info, &sz) == noErr)
  25159. {
  25160. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  25161. }
  25162. return true;
  25163. }
  25164. int AudioUnitPluginInstance::getNumPrograms()
  25165. {
  25166. CFArrayRef presets;
  25167. UInt32 sz = sizeof (CFArrayRef);
  25168. int num = 0;
  25169. if (AudioUnitGetProperty (audioUnit,
  25170. kAudioUnitProperty_FactoryPresets,
  25171. kAudioUnitScope_Global,
  25172. 0, &presets, &sz) == noErr)
  25173. {
  25174. num = (int) CFArrayGetCount (presets);
  25175. CFRelease (presets);
  25176. }
  25177. return num;
  25178. }
  25179. int AudioUnitPluginInstance::getCurrentProgram()
  25180. {
  25181. AUPreset current;
  25182. current.presetNumber = 0;
  25183. UInt32 sz = sizeof (AUPreset);
  25184. AudioUnitGetProperty (audioUnit,
  25185. kAudioUnitProperty_FactoryPresets,
  25186. kAudioUnitScope_Global,
  25187. 0, &current, &sz);
  25188. return current.presetNumber;
  25189. }
  25190. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  25191. {
  25192. AUPreset current;
  25193. current.presetNumber = newIndex;
  25194. current.presetName = 0;
  25195. AudioUnitSetProperty (audioUnit,
  25196. kAudioUnitProperty_FactoryPresets,
  25197. kAudioUnitScope_Global,
  25198. 0, &current, sizeof (AUPreset));
  25199. }
  25200. const String AudioUnitPluginInstance::getProgramName (int index)
  25201. {
  25202. String s;
  25203. CFArrayRef presets;
  25204. UInt32 sz = sizeof (CFArrayRef);
  25205. if (AudioUnitGetProperty (audioUnit,
  25206. kAudioUnitProperty_FactoryPresets,
  25207. kAudioUnitScope_Global,
  25208. 0, &presets, &sz) == noErr)
  25209. {
  25210. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  25211. {
  25212. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  25213. if (p != 0 && p->presetNumber == index)
  25214. {
  25215. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  25216. break;
  25217. }
  25218. }
  25219. CFRelease (presets);
  25220. }
  25221. return s;
  25222. }
  25223. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  25224. {
  25225. jassertfalse // xxx not implemented!
  25226. }
  25227. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  25228. {
  25229. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  25230. return T("Input ") + String (index + 1);
  25231. return String::empty;
  25232. }
  25233. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  25234. {
  25235. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  25236. return false;
  25237. return true;
  25238. }
  25239. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  25240. {
  25241. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  25242. return T("Output ") + String (index + 1);
  25243. return String::empty;
  25244. }
  25245. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  25246. {
  25247. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  25248. return false;
  25249. return true;
  25250. }
  25251. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  25252. {
  25253. getCurrentProgramStateInformation (destData);
  25254. }
  25255. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  25256. {
  25257. CFPropertyListRef propertyList = 0;
  25258. UInt32 sz = sizeof (CFPropertyListRef);
  25259. if (AudioUnitGetProperty (audioUnit,
  25260. kAudioUnitProperty_ClassInfo,
  25261. kAudioUnitScope_Global,
  25262. 0, &propertyList, &sz) == noErr)
  25263. {
  25264. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  25265. CFWriteStreamOpen (stream);
  25266. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  25267. CFWriteStreamClose (stream);
  25268. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  25269. destData.setSize (bytesWritten);
  25270. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  25271. CFRelease (data);
  25272. CFRelease (stream);
  25273. CFRelease (propertyList);
  25274. }
  25275. }
  25276. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  25277. {
  25278. setCurrentProgramStateInformation (data, sizeInBytes);
  25279. }
  25280. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  25281. {
  25282. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  25283. (const UInt8*) data,
  25284. sizeInBytes,
  25285. kCFAllocatorNull);
  25286. CFReadStreamOpen (stream);
  25287. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  25288. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  25289. stream,
  25290. 0,
  25291. kCFPropertyListImmutable,
  25292. &format,
  25293. 0);
  25294. CFRelease (stream);
  25295. if (propertyList != 0)
  25296. AudioUnitSetProperty (audioUnit,
  25297. kAudioUnitProperty_ClassInfo,
  25298. kAudioUnitScope_Global,
  25299. 0, &propertyList, sizeof (propertyList));
  25300. }
  25301. AudioUnitPluginFormat::AudioUnitPluginFormat()
  25302. {
  25303. }
  25304. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  25305. {
  25306. }
  25307. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  25308. const String& fileOrIdentifier)
  25309. {
  25310. if (! fileMightContainThisPluginType (fileOrIdentifier))
  25311. return;
  25312. PluginDescription desc;
  25313. desc.fileOrIdentifier = fileOrIdentifier;
  25314. desc.uid = 0;
  25315. try
  25316. {
  25317. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  25318. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  25319. if (auInstance != 0)
  25320. {
  25321. auInstance->fillInPluginDescription (desc);
  25322. results.add (new PluginDescription (desc));
  25323. }
  25324. }
  25325. catch (...)
  25326. {
  25327. // crashed while loading...
  25328. }
  25329. }
  25330. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25331. {
  25332. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25333. {
  25334. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25335. if (result->audioUnit != 0)
  25336. {
  25337. result->initialise();
  25338. return result.release();
  25339. }
  25340. }
  25341. return 0;
  25342. }
  25343. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25344. const bool /*recursive*/)
  25345. {
  25346. StringArray result;
  25347. ComponentRecord* comp = 0;
  25348. ComponentDescription desc;
  25349. zerostruct (desc);
  25350. for (;;)
  25351. {
  25352. zerostruct (desc);
  25353. comp = FindNextComponent (comp, &desc);
  25354. if (comp == 0)
  25355. break;
  25356. GetComponentInfo (comp, &desc, 0, 0, 0);
  25357. if (desc.componentType == kAudioUnitType_MusicDevice
  25358. || desc.componentType == kAudioUnitType_MusicEffect
  25359. || desc.componentType == kAudioUnitType_Effect
  25360. || desc.componentType == kAudioUnitType_Generator
  25361. || desc.componentType == kAudioUnitType_Panner)
  25362. {
  25363. const String s (createAUPluginIdentifier (desc));
  25364. DBG (s);
  25365. result.add (s);
  25366. }
  25367. }
  25368. return result;
  25369. }
  25370. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25371. {
  25372. ComponentDescription desc;
  25373. String name, version, manufacturer;
  25374. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25375. return FindNextComponent (0, &desc) != 0;
  25376. const File f (fileOrIdentifier);
  25377. return f.hasFileExtension (T(".component"))
  25378. && f.isDirectory();
  25379. }
  25380. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25381. {
  25382. ComponentDescription desc;
  25383. String name, version, manufacturer;
  25384. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25385. if (name.isEmpty())
  25386. name = fileOrIdentifier;
  25387. return name;
  25388. }
  25389. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25390. {
  25391. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25392. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25393. else
  25394. return File (desc.fileOrIdentifier).exists();
  25395. }
  25396. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25397. {
  25398. return FileSearchPath ("/(Default AudioUnit locations)");
  25399. }
  25400. #endif
  25401. END_JUCE_NAMESPACE
  25402. #undef log
  25403. #endif
  25404. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25405. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25406. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25407. #define JUCE_MAC_VST_INCLUDED 1
  25408. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25409. #if JUCE_PLUGINHOST_VST
  25410. #if (defined (_WIN32) || defined (_WIN64))
  25411. #undef _WIN32_WINNT
  25412. #define _WIN32_WINNT 0x500
  25413. #undef STRICT
  25414. #define STRICT
  25415. #include <windows.h>
  25416. #include <float.h>
  25417. #pragma warning (disable : 4312 4355)
  25418. #elif defined (LINUX) || defined (__linux__)
  25419. #include <float.h>
  25420. #include <sys/time.h>
  25421. #include <X11/Xlib.h>
  25422. #include <X11/Xutil.h>
  25423. #include <X11/Xatom.h>
  25424. #undef Font
  25425. #undef KeyPress
  25426. #undef Drawable
  25427. #undef Time
  25428. #else
  25429. #ifndef JUCE_MAC_VST_INCLUDED
  25430. // On the mac, this file needs to be compiled indirectly, by using
  25431. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25432. #error
  25433. #endif
  25434. #include <Cocoa/Cocoa.h>
  25435. #include <Carbon/Carbon.h>
  25436. #endif
  25437. #if ! (JUCE_MAC && JUCE_64BIT)
  25438. BEGIN_JUCE_NAMESPACE
  25439. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25440. #endif
  25441. #undef PRAGMA_ALIGN_SUPPORTED
  25442. #define VST_FORCE_DEPRECATED 0
  25443. #ifdef _MSC_VER
  25444. #pragma warning (push)
  25445. #pragma warning (disable: 4996)
  25446. #endif
  25447. #include "pluginterfaces/vst2.x/aeffectx.h"
  25448. #ifdef _MSC_VER
  25449. #pragma warning (pop)
  25450. #endif
  25451. #if JUCE_LINUX
  25452. #define Font JUCE_NAMESPACE::Font
  25453. #define KeyPress JUCE_NAMESPACE::KeyPress
  25454. #define Drawable JUCE_NAMESPACE::Drawable
  25455. #define Time JUCE_NAMESPACE::Time
  25456. #endif
  25457. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25458. #ifdef __aeffect__
  25459. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25460. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25461. class VSTMidiEventList
  25462. {
  25463. public:
  25464. VSTMidiEventList()
  25465. : numEventsUsed (0), numEventsAllocated (0)
  25466. {
  25467. }
  25468. ~VSTMidiEventList()
  25469. {
  25470. freeEvents();
  25471. }
  25472. void clear()
  25473. {
  25474. numEventsUsed = 0;
  25475. if (events != 0)
  25476. events->numEvents = 0;
  25477. }
  25478. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25479. {
  25480. ensureSize (numEventsUsed + 1);
  25481. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25482. events->numEvents = ++numEventsUsed;
  25483. if (numBytes <= 4)
  25484. {
  25485. if (e->type == kVstSysExType)
  25486. {
  25487. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25488. e->type = kVstMidiType;
  25489. e->byteSize = sizeof (VstMidiEvent);
  25490. e->noteLength = 0;
  25491. e->noteOffset = 0;
  25492. e->detune = 0;
  25493. e->noteOffVelocity = 0;
  25494. }
  25495. e->deltaFrames = frameOffset;
  25496. memcpy (e->midiData, midiData, numBytes);
  25497. }
  25498. else
  25499. {
  25500. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25501. if (se->type == kVstSysExType)
  25502. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25503. else
  25504. se->sysexDump = (char*) juce_malloc (numBytes);
  25505. memcpy (se->sysexDump, midiData, numBytes);
  25506. se->type = kVstSysExType;
  25507. se->byteSize = sizeof (VstMidiSysexEvent);
  25508. se->deltaFrames = frameOffset;
  25509. se->flags = 0;
  25510. se->dumpBytes = numBytes;
  25511. se->resvd1 = 0;
  25512. se->resvd2 = 0;
  25513. }
  25514. }
  25515. // Handy method to pull the events out of an event buffer supplied by the host
  25516. // or plugin.
  25517. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25518. {
  25519. for (int i = 0; i < events->numEvents; ++i)
  25520. {
  25521. const VstEvent* const e = events->events[i];
  25522. if (e != 0)
  25523. {
  25524. if (e->type == kVstMidiType)
  25525. {
  25526. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25527. 4, e->deltaFrames);
  25528. }
  25529. else if (e->type == kVstSysExType)
  25530. {
  25531. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25532. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25533. e->deltaFrames);
  25534. }
  25535. }
  25536. }
  25537. }
  25538. void ensureSize (int numEventsNeeded)
  25539. {
  25540. if (numEventsNeeded > numEventsAllocated)
  25541. {
  25542. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25543. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25544. if (events == 0)
  25545. events.calloc (size, 1);
  25546. else
  25547. events.realloc (size, 1);
  25548. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25549. {
  25550. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25551. (int) sizeof (VstMidiSysexEvent)));
  25552. e->type = kVstMidiType;
  25553. e->byteSize = sizeof (VstMidiEvent);
  25554. events->events[i] = (VstEvent*) e;
  25555. }
  25556. numEventsAllocated = numEventsNeeded;
  25557. }
  25558. }
  25559. void freeEvents()
  25560. {
  25561. if (events != 0)
  25562. {
  25563. for (int i = numEventsAllocated; --i >= 0;)
  25564. {
  25565. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25566. if (e->type == kVstSysExType)
  25567. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25568. juce_free (e);
  25569. }
  25570. events.free();
  25571. numEventsUsed = 0;
  25572. numEventsAllocated = 0;
  25573. }
  25574. }
  25575. HeapBlock <VstEvents> events;
  25576. private:
  25577. int numEventsUsed, numEventsAllocated;
  25578. };
  25579. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25580. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25581. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25582. #if ! JUCE_WIN32
  25583. #define _fpreset()
  25584. #define _clearfp()
  25585. #endif
  25586. extern void juce_callAnyTimersSynchronously();
  25587. const int fxbVersionNum = 1;
  25588. struct fxProgram
  25589. {
  25590. long chunkMagic; // 'CcnK'
  25591. long byteSize; // of this chunk, excl. magic + byteSize
  25592. long fxMagic; // 'FxCk'
  25593. long version;
  25594. long fxID; // fx unique id
  25595. long fxVersion;
  25596. long numParams;
  25597. char prgName[28];
  25598. float params[1]; // variable no. of parameters
  25599. };
  25600. struct fxSet
  25601. {
  25602. long chunkMagic; // 'CcnK'
  25603. long byteSize; // of this chunk, excl. magic + byteSize
  25604. long fxMagic; // 'FxBk'
  25605. long version;
  25606. long fxID; // fx unique id
  25607. long fxVersion;
  25608. long numPrograms;
  25609. char future[128];
  25610. fxProgram programs[1]; // variable no. of programs
  25611. };
  25612. struct fxChunkSet
  25613. {
  25614. long chunkMagic; // 'CcnK'
  25615. long byteSize; // of this chunk, excl. magic + byteSize
  25616. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25617. long version;
  25618. long fxID; // fx unique id
  25619. long fxVersion;
  25620. long numPrograms;
  25621. char future[128];
  25622. long chunkSize;
  25623. char chunk[8]; // variable
  25624. };
  25625. struct fxProgramSet
  25626. {
  25627. long chunkMagic; // 'CcnK'
  25628. long byteSize; // of this chunk, excl. magic + byteSize
  25629. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25630. long version;
  25631. long fxID; // fx unique id
  25632. long fxVersion;
  25633. long numPrograms;
  25634. char name[28];
  25635. long chunkSize;
  25636. char chunk[8]; // variable
  25637. };
  25638. static long vst_swap (const long x) throw()
  25639. {
  25640. #ifdef JUCE_LITTLE_ENDIAN
  25641. return (long) ByteOrder::swap ((uint32) x);
  25642. #else
  25643. return x;
  25644. #endif
  25645. }
  25646. static float vst_swapFloat (const float x) throw()
  25647. {
  25648. #ifdef JUCE_LITTLE_ENDIAN
  25649. union { uint32 asInt; float asFloat; } n;
  25650. n.asFloat = x;
  25651. n.asInt = ByteOrder::swap (n.asInt);
  25652. return n.asFloat;
  25653. #else
  25654. return x;
  25655. #endif
  25656. }
  25657. typedef AEffect* (*MainCall) (audioMasterCallback);
  25658. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25659. static int shellUIDToCreate = 0;
  25660. static int insideVSTCallback = 0;
  25661. class VSTPluginWindow;
  25662. // Change this to disable logging of various VST activities
  25663. #ifndef VST_LOGGING
  25664. #define VST_LOGGING 1
  25665. #endif
  25666. #if VST_LOGGING
  25667. #define log(a) Logger::writeToLog(a);
  25668. #else
  25669. #define log(a)
  25670. #endif
  25671. #if JUCE_MAC && JUCE_PPC
  25672. static void* NewCFMFromMachO (void* const machofp) throw()
  25673. {
  25674. void* result = juce_malloc (8);
  25675. ((void**) result)[0] = machofp;
  25676. ((void**) result)[1] = result;
  25677. return result;
  25678. }
  25679. #endif
  25680. #if JUCE_LINUX
  25681. extern Display* display;
  25682. extern XContext improbableNumber;
  25683. typedef void (*EventProcPtr) (XEvent* ev);
  25684. static bool xErrorTriggered;
  25685. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25686. {
  25687. xErrorTriggered = true;
  25688. return 0;
  25689. }
  25690. static int getPropertyFromXWindow (Window handle, Atom atom)
  25691. {
  25692. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25693. xErrorTriggered = false;
  25694. int userSize;
  25695. unsigned long bytes, userCount;
  25696. unsigned char* data;
  25697. Atom userType;
  25698. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25699. &userType, &userSize, &userCount, &bytes, &data);
  25700. XSetErrorHandler (oldErrorHandler);
  25701. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25702. : 0;
  25703. }
  25704. static Window getChildWindow (Window windowToCheck)
  25705. {
  25706. Window rootWindow, parentWindow;
  25707. Window* childWindows;
  25708. unsigned int numChildren;
  25709. XQueryTree (display,
  25710. windowToCheck,
  25711. &rootWindow,
  25712. &parentWindow,
  25713. &childWindows,
  25714. &numChildren);
  25715. if (numChildren > 0)
  25716. return childWindows [0];
  25717. return 0;
  25718. }
  25719. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25720. {
  25721. if (e.mods.isLeftButtonDown())
  25722. {
  25723. ev.xbutton.button = Button1;
  25724. ev.xbutton.state |= Button1Mask;
  25725. }
  25726. else if (e.mods.isRightButtonDown())
  25727. {
  25728. ev.xbutton.button = Button3;
  25729. ev.xbutton.state |= Button3Mask;
  25730. }
  25731. else if (e.mods.isMiddleButtonDown())
  25732. {
  25733. ev.xbutton.button = Button2;
  25734. ev.xbutton.state |= Button2Mask;
  25735. }
  25736. }
  25737. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25738. {
  25739. if (e.mods.isLeftButtonDown())
  25740. ev.xmotion.state |= Button1Mask;
  25741. else if (e.mods.isRightButtonDown())
  25742. ev.xmotion.state |= Button3Mask;
  25743. else if (e.mods.isMiddleButtonDown())
  25744. ev.xmotion.state |= Button2Mask;
  25745. }
  25746. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25747. {
  25748. if (e.mods.isLeftButtonDown())
  25749. ev.xcrossing.state |= Button1Mask;
  25750. else if (e.mods.isRightButtonDown())
  25751. ev.xcrossing.state |= Button3Mask;
  25752. else if (e.mods.isMiddleButtonDown())
  25753. ev.xcrossing.state |= Button2Mask;
  25754. }
  25755. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25756. {
  25757. if (increment < 0)
  25758. {
  25759. ev.xbutton.button = Button5;
  25760. ev.xbutton.state |= Button5Mask;
  25761. }
  25762. else if (increment > 0)
  25763. {
  25764. ev.xbutton.button = Button4;
  25765. ev.xbutton.state |= Button4Mask;
  25766. }
  25767. }
  25768. #endif
  25769. static VoidArray activeModules;
  25770. class ModuleHandle : public ReferenceCountedObject
  25771. {
  25772. public:
  25773. File file;
  25774. MainCall moduleMain;
  25775. String pluginName;
  25776. static ModuleHandle* findOrCreateModule (const File& file)
  25777. {
  25778. for (int i = activeModules.size(); --i >= 0;)
  25779. {
  25780. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25781. if (module->file == file)
  25782. return module;
  25783. }
  25784. _fpreset(); // (doesn't do any harm)
  25785. ++insideVSTCallback;
  25786. shellUIDToCreate = 0;
  25787. log ("Attempting to load VST: " + file.getFullPathName());
  25788. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25789. if (! m->open())
  25790. m = 0;
  25791. --insideVSTCallback;
  25792. _fpreset(); // (doesn't do any harm)
  25793. return m.release();
  25794. }
  25795. ModuleHandle (const File& file_)
  25796. : file (file_),
  25797. moduleMain (0),
  25798. #if JUCE_WIN32 || JUCE_LINUX
  25799. hModule (0)
  25800. #elif JUCE_MAC
  25801. fragId (0),
  25802. resHandle (0),
  25803. bundleRef (0),
  25804. resFileId (0)
  25805. #endif
  25806. {
  25807. activeModules.add (this);
  25808. #if JUCE_WIN32 || JUCE_LINUX
  25809. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25810. #elif JUCE_MAC
  25811. FSRef ref;
  25812. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25813. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25814. #endif
  25815. }
  25816. ~ModuleHandle()
  25817. {
  25818. activeModules.removeValue (this);
  25819. close();
  25820. }
  25821. juce_UseDebuggingNewOperator
  25822. #if JUCE_WIN32 || JUCE_LINUX
  25823. void* hModule;
  25824. String fullParentDirectoryPathName;
  25825. bool open()
  25826. {
  25827. #if JUCE_WIN32
  25828. static bool timePeriodSet = false;
  25829. if (! timePeriodSet)
  25830. {
  25831. timePeriodSet = true;
  25832. timeBeginPeriod (2);
  25833. }
  25834. #endif
  25835. pluginName = file.getFileNameWithoutExtension();
  25836. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25837. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25838. if (moduleMain == 0)
  25839. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25840. return moduleMain != 0;
  25841. }
  25842. void close()
  25843. {
  25844. _fpreset(); // (doesn't do any harm)
  25845. PlatformUtilities::freeDynamicLibrary (hModule);
  25846. }
  25847. void closeEffect (AEffect* eff)
  25848. {
  25849. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25850. }
  25851. #else
  25852. CFragConnectionID fragId;
  25853. Handle resHandle;
  25854. CFBundleRef bundleRef;
  25855. FSSpec parentDirFSSpec;
  25856. short resFileId;
  25857. bool open()
  25858. {
  25859. bool ok = false;
  25860. const String filename (file.getFullPathName());
  25861. if (file.hasFileExtension (T(".vst")))
  25862. {
  25863. const char* const utf8 = filename.toUTF8();
  25864. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25865. strlen (utf8), file.isDirectory());
  25866. if (url != 0)
  25867. {
  25868. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25869. CFRelease (url);
  25870. if (bundleRef != 0)
  25871. {
  25872. if (CFBundleLoadExecutable (bundleRef))
  25873. {
  25874. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25875. if (moduleMain == 0)
  25876. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25877. if (moduleMain != 0)
  25878. {
  25879. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25880. if (name != 0)
  25881. {
  25882. if (CFGetTypeID (name) == CFStringGetTypeID())
  25883. {
  25884. char buffer[1024];
  25885. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25886. pluginName = buffer;
  25887. }
  25888. }
  25889. if (pluginName.isEmpty())
  25890. pluginName = file.getFileNameWithoutExtension();
  25891. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25892. ok = true;
  25893. }
  25894. }
  25895. if (! ok)
  25896. {
  25897. CFBundleUnloadExecutable (bundleRef);
  25898. CFRelease (bundleRef);
  25899. bundleRef = 0;
  25900. }
  25901. }
  25902. }
  25903. }
  25904. #if JUCE_PPC
  25905. else
  25906. {
  25907. FSRef fn;
  25908. if (FSPathMakeRef ((UInt8*) (const char*) filename, &fn, 0) == noErr)
  25909. {
  25910. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25911. if (resFileId != -1)
  25912. {
  25913. const int numEffs = Count1Resources ('aEff');
  25914. for (int i = 0; i < numEffs; ++i)
  25915. {
  25916. resHandle = Get1IndResource ('aEff', i + 1);
  25917. if (resHandle != 0)
  25918. {
  25919. OSType type;
  25920. Str255 name;
  25921. SInt16 id;
  25922. GetResInfo (resHandle, &id, &type, name);
  25923. pluginName = String ((const char*) name + 1, name[0]);
  25924. DetachResource (resHandle);
  25925. HLock (resHandle);
  25926. Ptr ptr;
  25927. Str255 errorText;
  25928. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25929. name, kPrivateCFragCopy,
  25930. &fragId, &ptr, errorText);
  25931. if (err == noErr)
  25932. {
  25933. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25934. ok = true;
  25935. }
  25936. else
  25937. {
  25938. HUnlock (resHandle);
  25939. }
  25940. break;
  25941. }
  25942. }
  25943. if (! ok)
  25944. CloseResFile (resFileId);
  25945. }
  25946. }
  25947. }
  25948. #endif
  25949. return ok;
  25950. }
  25951. void close()
  25952. {
  25953. #if JUCE_PPC
  25954. if (fragId != 0)
  25955. {
  25956. if (moduleMain != 0)
  25957. disposeMachOFromCFM ((void*) moduleMain);
  25958. CloseConnection (&fragId);
  25959. HUnlock (resHandle);
  25960. if (resFileId != 0)
  25961. CloseResFile (resFileId);
  25962. }
  25963. else
  25964. #endif
  25965. if (bundleRef != 0)
  25966. {
  25967. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25968. if (CFGetRetainCount (bundleRef) == 1)
  25969. CFBundleUnloadExecutable (bundleRef);
  25970. if (CFGetRetainCount (bundleRef) > 0)
  25971. CFRelease (bundleRef);
  25972. }
  25973. }
  25974. void closeEffect (AEffect* eff)
  25975. {
  25976. #if JUCE_PPC
  25977. if (fragId != 0)
  25978. {
  25979. VoidArray thingsToDelete;
  25980. thingsToDelete.add ((void*) eff->dispatcher);
  25981. thingsToDelete.add ((void*) eff->process);
  25982. thingsToDelete.add ((void*) eff->setParameter);
  25983. thingsToDelete.add ((void*) eff->getParameter);
  25984. thingsToDelete.add ((void*) eff->processReplacing);
  25985. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25986. for (int i = thingsToDelete.size(); --i >= 0;)
  25987. disposeMachOFromCFM (thingsToDelete[i]);
  25988. }
  25989. else
  25990. #endif
  25991. {
  25992. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25993. }
  25994. }
  25995. #if JUCE_PPC
  25996. static void* newMachOFromCFM (void* cfmfp)
  25997. {
  25998. if (cfmfp == 0)
  25999. return 0;
  26000. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  26001. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  26002. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  26003. mfp[2] = 0x800c0000;
  26004. mfp[3] = 0x804c0004;
  26005. mfp[4] = 0x7c0903a6;
  26006. mfp[5] = 0x4e800420;
  26007. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  26008. return mfp;
  26009. }
  26010. static void disposeMachOFromCFM (void* ptr)
  26011. {
  26012. juce_free (ptr);
  26013. }
  26014. void coerceAEffectFunctionCalls (AEffect* eff)
  26015. {
  26016. if (fragId != 0)
  26017. {
  26018. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  26019. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  26020. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  26021. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  26022. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  26023. }
  26024. }
  26025. #endif
  26026. #endif
  26027. };
  26028. class VSTPluginInstance : public AudioPluginInstance,
  26029. private Timer,
  26030. private AsyncUpdater
  26031. {
  26032. public:
  26033. ~VSTPluginInstance();
  26034. // AudioPluginInstance methods:
  26035. void fillInPluginDescription (PluginDescription& desc) const
  26036. {
  26037. desc.name = name;
  26038. desc.fileOrIdentifier = module->file.getFullPathName();
  26039. desc.uid = getUID();
  26040. desc.lastFileModTime = module->file.getLastModificationTime();
  26041. desc.pluginFormatName = "VST";
  26042. desc.category = getCategory();
  26043. {
  26044. char buffer [kVstMaxVendorStrLen + 8];
  26045. zerostruct (buffer);
  26046. dispatch (effGetVendorString, 0, 0, buffer, 0);
  26047. desc.manufacturerName = buffer;
  26048. }
  26049. desc.version = getVersion();
  26050. desc.numInputChannels = getNumInputChannels();
  26051. desc.numOutputChannels = getNumOutputChannels();
  26052. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  26053. }
  26054. const String getName() const { return name; }
  26055. int getUID() const throw();
  26056. bool acceptsMidi() const { return wantsMidiMessages; }
  26057. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  26058. // AudioProcessor methods:
  26059. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  26060. void releaseResources();
  26061. void processBlock (AudioSampleBuffer& buffer,
  26062. MidiBuffer& midiMessages);
  26063. AudioProcessorEditor* createEditor();
  26064. const String getInputChannelName (const int index) const;
  26065. bool isInputChannelStereoPair (int index) const;
  26066. const String getOutputChannelName (const int index) const;
  26067. bool isOutputChannelStereoPair (int index) const;
  26068. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  26069. float getParameter (int index);
  26070. void setParameter (int index, float newValue);
  26071. const String getParameterName (int index);
  26072. const String getParameterText (int index);
  26073. bool isParameterAutomatable (int index) const;
  26074. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  26075. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  26076. void setCurrentProgram (int index);
  26077. const String getProgramName (int index);
  26078. void changeProgramName (int index, const String& newName);
  26079. void getStateInformation (MemoryBlock& destData);
  26080. void getCurrentProgramStateInformation (MemoryBlock& destData);
  26081. void setStateInformation (const void* data, int sizeInBytes);
  26082. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  26083. void timerCallback();
  26084. void handleAsyncUpdate();
  26085. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  26086. juce_UseDebuggingNewOperator
  26087. private:
  26088. friend class VSTPluginWindow;
  26089. friend class VSTPluginFormat;
  26090. AEffect* effect;
  26091. String name;
  26092. CriticalSection lock;
  26093. bool wantsMidiMessages, initialised, isPowerOn;
  26094. mutable StringArray programNames;
  26095. AudioSampleBuffer tempBuffer;
  26096. CriticalSection midiInLock;
  26097. MidiBuffer incomingMidi;
  26098. VSTMidiEventList midiEventsToSend;
  26099. VstTimeInfo vstHostTime;
  26100. HeapBlock <float*> channels;
  26101. ReferenceCountedObjectPtr <ModuleHandle> module;
  26102. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  26103. bool restoreProgramSettings (const fxProgram* const prog);
  26104. const String getCurrentProgramName();
  26105. void setParamsInProgramBlock (fxProgram* const prog) throw();
  26106. void updateStoredProgramNames();
  26107. void initialise();
  26108. void handleMidiFromPlugin (const VstEvents* const events);
  26109. void createTempParameterStore (MemoryBlock& dest);
  26110. void restoreFromTempParameterStore (const MemoryBlock& mb);
  26111. const String getParameterLabel (int index) const;
  26112. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  26113. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  26114. void setChunkData (const char* data, int size, bool isPreset);
  26115. bool loadFromFXBFile (const void* data, int numBytes);
  26116. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  26117. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  26118. const String getVersion() const throw();
  26119. const String getCategory() const throw();
  26120. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  26121. void setPower (const bool on);
  26122. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  26123. };
  26124. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  26125. : effect (0),
  26126. wantsMidiMessages (false),
  26127. initialised (false),
  26128. isPowerOn (false),
  26129. tempBuffer (1, 1),
  26130. module (module_)
  26131. {
  26132. try
  26133. {
  26134. _fpreset();
  26135. ++insideVSTCallback;
  26136. name = module->pluginName;
  26137. log (T("Creating VST instance: ") + name);
  26138. #if JUCE_MAC
  26139. if (module->resFileId != 0)
  26140. UseResFile (module->resFileId);
  26141. #if JUCE_PPC
  26142. if (module->fragId != 0)
  26143. {
  26144. static void* audioMasterCoerced = 0;
  26145. if (audioMasterCoerced == 0)
  26146. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  26147. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  26148. }
  26149. else
  26150. #endif
  26151. #endif
  26152. {
  26153. effect = module->moduleMain (&audioMaster);
  26154. }
  26155. --insideVSTCallback;
  26156. if (effect != 0 && effect->magic == kEffectMagic)
  26157. {
  26158. #if JUCE_PPC
  26159. module->coerceAEffectFunctionCalls (effect);
  26160. #endif
  26161. jassert (effect->resvd2 == 0);
  26162. jassert (effect->object != 0);
  26163. _fpreset(); // some dodgy plugs fuck around with this
  26164. }
  26165. else
  26166. {
  26167. effect = 0;
  26168. }
  26169. }
  26170. catch (...)
  26171. {
  26172. --insideVSTCallback;
  26173. }
  26174. }
  26175. VSTPluginInstance::~VSTPluginInstance()
  26176. {
  26177. {
  26178. const ScopedLock sl (lock);
  26179. jassert (insideVSTCallback == 0);
  26180. if (effect != 0 && effect->magic == kEffectMagic)
  26181. {
  26182. try
  26183. {
  26184. #if JUCE_MAC
  26185. if (module->resFileId != 0)
  26186. UseResFile (module->resFileId);
  26187. #endif
  26188. // Must delete any editors before deleting the plugin instance!
  26189. jassert (getActiveEditor() == 0);
  26190. _fpreset(); // some dodgy plugs fuck around with this
  26191. module->closeEffect (effect);
  26192. }
  26193. catch (...)
  26194. {}
  26195. }
  26196. module = 0;
  26197. effect = 0;
  26198. }
  26199. }
  26200. void VSTPluginInstance::initialise()
  26201. {
  26202. if (initialised || effect == 0)
  26203. return;
  26204. log (T("Initialising VST: ") + module->pluginName);
  26205. initialised = true;
  26206. dispatch (effIdentify, 0, 0, 0, 0);
  26207. // this code would ask the plugin for its name, but so few plugins
  26208. // actually bother implementing this correctly, that it's better to
  26209. // just ignore it and use the file name instead.
  26210. if (getSampleRate() > 0)
  26211. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  26212. if (getBlockSize() > 0)
  26213. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  26214. dispatch (effOpen, 0, 0, 0, 0);
  26215. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26216. getSampleRate(), getBlockSize());
  26217. if (getNumPrograms() > 1)
  26218. setCurrentProgram (0);
  26219. else
  26220. dispatch (effSetProgram, 0, 0, 0, 0);
  26221. int i;
  26222. for (i = effect->numInputs; --i >= 0;)
  26223. dispatch (effConnectInput, i, 1, 0, 0);
  26224. for (i = effect->numOutputs; --i >= 0;)
  26225. dispatch (effConnectOutput, i, 1, 0, 0);
  26226. updateStoredProgramNames();
  26227. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  26228. setLatencySamples (effect->initialDelay);
  26229. }
  26230. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  26231. int samplesPerBlockExpected)
  26232. {
  26233. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26234. sampleRate_, samplesPerBlockExpected);
  26235. setLatencySamples (effect->initialDelay);
  26236. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  26237. vstHostTime.tempo = 120.0;
  26238. vstHostTime.timeSigNumerator = 4;
  26239. vstHostTime.timeSigDenominator = 4;
  26240. vstHostTime.sampleRate = sampleRate_;
  26241. vstHostTime.samplePos = 0;
  26242. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  26243. initialise();
  26244. if (initialised)
  26245. {
  26246. wantsMidiMessages = wantsMidiMessages
  26247. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  26248. if (wantsMidiMessages)
  26249. midiEventsToSend.ensureSize (256);
  26250. else
  26251. midiEventsToSend.freeEvents();
  26252. incomingMidi.clear();
  26253. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  26254. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  26255. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  26256. if (! isPowerOn)
  26257. setPower (true);
  26258. // dodgy hack to force some plugins to initialise the sample rate..
  26259. if ((! hasEditor()) && getNumParameters() > 0)
  26260. {
  26261. const float old = getParameter (0);
  26262. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  26263. setParameter (0, old);
  26264. }
  26265. dispatch (effStartProcess, 0, 0, 0, 0);
  26266. }
  26267. }
  26268. void VSTPluginInstance::releaseResources()
  26269. {
  26270. if (initialised)
  26271. {
  26272. dispatch (effStopProcess, 0, 0, 0, 0);
  26273. setPower (false);
  26274. }
  26275. tempBuffer.setSize (1, 1);
  26276. incomingMidi.clear();
  26277. midiEventsToSend.freeEvents();
  26278. channels.free();
  26279. }
  26280. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  26281. MidiBuffer& midiMessages)
  26282. {
  26283. const int numSamples = buffer.getNumSamples();
  26284. if (initialised)
  26285. {
  26286. AudioPlayHead* playHead = getPlayHead();
  26287. if (playHead != 0)
  26288. {
  26289. AudioPlayHead::CurrentPositionInfo position;
  26290. playHead->getCurrentPosition (position);
  26291. vstHostTime.tempo = position.bpm;
  26292. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  26293. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  26294. vstHostTime.ppqPos = position.ppqPosition;
  26295. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  26296. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  26297. if (position.isPlaying)
  26298. vstHostTime.flags |= kVstTransportPlaying;
  26299. else
  26300. vstHostTime.flags &= ~kVstTransportPlaying;
  26301. }
  26302. #if JUCE_WIN32
  26303. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  26304. #elif JUCE_LINUX
  26305. timeval micro;
  26306. gettimeofday (&micro, 0);
  26307. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  26308. #elif JUCE_MAC
  26309. UnsignedWide micro;
  26310. Microseconds (&micro);
  26311. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  26312. #endif
  26313. if (wantsMidiMessages)
  26314. {
  26315. midiEventsToSend.clear();
  26316. midiEventsToSend.ensureSize (1);
  26317. MidiBuffer::Iterator iter (midiMessages);
  26318. const uint8* midiData;
  26319. int numBytesOfMidiData, samplePosition;
  26320. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  26321. {
  26322. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  26323. jlimit (0, numSamples - 1, samplePosition));
  26324. }
  26325. try
  26326. {
  26327. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26328. }
  26329. catch (...)
  26330. {}
  26331. }
  26332. int i;
  26333. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26334. for (i = 0; i < maxChans; ++i)
  26335. channels[i] = buffer.getSampleData (i);
  26336. channels [maxChans] = 0;
  26337. _clearfp();
  26338. if ((effect->flags & effFlagsCanReplacing) != 0)
  26339. {
  26340. try
  26341. {
  26342. effect->processReplacing (effect, channels, channels, numSamples);
  26343. }
  26344. catch (...)
  26345. {}
  26346. }
  26347. else
  26348. {
  26349. tempBuffer.setSize (effect->numOutputs, numSamples);
  26350. tempBuffer.clear();
  26351. float* outs [64];
  26352. for (i = effect->numOutputs; --i >= 0;)
  26353. outs[i] = tempBuffer.getSampleData (i);
  26354. outs [effect->numOutputs] = 0;
  26355. try
  26356. {
  26357. effect->process (effect, channels, outs, numSamples);
  26358. }
  26359. catch (...)
  26360. {}
  26361. for (i = effect->numOutputs; --i >= 0;)
  26362. buffer.copyFrom (i, 0, outs[i], numSamples);
  26363. }
  26364. }
  26365. else
  26366. {
  26367. // Not initialised, so just bypass..
  26368. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26369. buffer.clear (i, 0, buffer.getNumSamples());
  26370. }
  26371. {
  26372. // copy any incoming midi..
  26373. const ScopedLock sl (midiInLock);
  26374. midiMessages = incomingMidi;
  26375. incomingMidi.clear();
  26376. }
  26377. }
  26378. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26379. {
  26380. if (events != 0)
  26381. {
  26382. const ScopedLock sl (midiInLock);
  26383. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26384. }
  26385. }
  26386. static Array <VSTPluginWindow*> activeVSTWindows;
  26387. class VSTPluginWindow : public AudioProcessorEditor,
  26388. #if ! JUCE_MAC
  26389. public ComponentMovementWatcher,
  26390. #endif
  26391. public Timer
  26392. {
  26393. public:
  26394. VSTPluginWindow (VSTPluginInstance& plugin_)
  26395. : AudioProcessorEditor (&plugin_),
  26396. #if ! JUCE_MAC
  26397. ComponentMovementWatcher (this),
  26398. #endif
  26399. plugin (plugin_),
  26400. isOpen (false),
  26401. wasShowing (false),
  26402. pluginRefusesToResize (false),
  26403. pluginWantsKeys (false),
  26404. alreadyInside (false),
  26405. recursiveResize (false)
  26406. {
  26407. #if JUCE_WIN32
  26408. sizeCheckCount = 0;
  26409. pluginHWND = 0;
  26410. #elif JUCE_LINUX
  26411. pluginWindow = None;
  26412. pluginProc = None;
  26413. #else
  26414. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26415. #endif
  26416. activeVSTWindows.add (this);
  26417. setSize (1, 1);
  26418. setOpaque (true);
  26419. setVisible (true);
  26420. }
  26421. ~VSTPluginWindow()
  26422. {
  26423. #if JUCE_MAC
  26424. innerWrapper = 0;
  26425. #else
  26426. closePluginWindow();
  26427. #endif
  26428. activeVSTWindows.removeValue (this);
  26429. plugin.editorBeingDeleted (this);
  26430. }
  26431. #if ! JUCE_MAC
  26432. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26433. {
  26434. if (recursiveResize)
  26435. return;
  26436. Component* const topComp = getTopLevelComponent();
  26437. if (topComp->getPeer() != 0)
  26438. {
  26439. int x = 0, y = 0;
  26440. relativePositionToOtherComponent (topComp, x, y);
  26441. recursiveResize = true;
  26442. #if JUCE_WIN32
  26443. if (pluginHWND != 0)
  26444. MoveWindow (pluginHWND, x, y, getWidth(), getHeight(), TRUE);
  26445. #elif JUCE_LINUX
  26446. if (pluginWindow != 0)
  26447. {
  26448. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26449. XMoveWindow (display, pluginWindow, x, y);
  26450. XMapRaised (display, pluginWindow);
  26451. }
  26452. #endif
  26453. recursiveResize = false;
  26454. }
  26455. }
  26456. void componentVisibilityChanged (Component&)
  26457. {
  26458. const bool isShowingNow = isShowing();
  26459. if (wasShowing != isShowingNow)
  26460. {
  26461. wasShowing = isShowingNow;
  26462. if (isShowingNow)
  26463. openPluginWindow();
  26464. else
  26465. closePluginWindow();
  26466. }
  26467. componentMovedOrResized (true, true);
  26468. }
  26469. void componentPeerChanged()
  26470. {
  26471. closePluginWindow();
  26472. openPluginWindow();
  26473. }
  26474. #endif
  26475. bool keyStateChanged (const bool)
  26476. {
  26477. return pluginWantsKeys;
  26478. }
  26479. bool keyPressed (const KeyPress&)
  26480. {
  26481. return pluginWantsKeys;
  26482. }
  26483. #if JUCE_MAC
  26484. void paint (Graphics& g)
  26485. {
  26486. g.fillAll (Colours::black);
  26487. }
  26488. #else
  26489. void paint (Graphics& g)
  26490. {
  26491. if (isOpen)
  26492. {
  26493. ComponentPeer* const peer = getPeer();
  26494. if (peer != 0)
  26495. {
  26496. peer->addMaskedRegion (getScreenX() - peer->getScreenX(),
  26497. getScreenY() - peer->getScreenY(),
  26498. getWidth(), getHeight());
  26499. #if JUCE_LINUX
  26500. if (pluginWindow != 0)
  26501. {
  26502. const Rectangle<int> clip (g.getClipBounds());
  26503. XEvent ev;
  26504. zerostruct (ev);
  26505. ev.xexpose.type = Expose;
  26506. ev.xexpose.display = display;
  26507. ev.xexpose.window = pluginWindow;
  26508. ev.xexpose.x = clip.getX();
  26509. ev.xexpose.y = clip.getY();
  26510. ev.xexpose.width = clip.getWidth();
  26511. ev.xexpose.height = clip.getHeight();
  26512. sendEventToChild (&ev);
  26513. }
  26514. #endif
  26515. }
  26516. }
  26517. else
  26518. {
  26519. g.fillAll (Colours::black);
  26520. }
  26521. }
  26522. #endif
  26523. void timerCallback()
  26524. {
  26525. #if JUCE_WIN32
  26526. if (--sizeCheckCount <= 0)
  26527. {
  26528. sizeCheckCount = 10;
  26529. checkPluginWindowSize();
  26530. }
  26531. #endif
  26532. try
  26533. {
  26534. static bool reentrant = false;
  26535. if (! reentrant)
  26536. {
  26537. reentrant = true;
  26538. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26539. reentrant = false;
  26540. }
  26541. }
  26542. catch (...)
  26543. {}
  26544. }
  26545. void mouseDown (const MouseEvent& e)
  26546. {
  26547. #if JUCE_LINUX
  26548. if (pluginWindow == 0)
  26549. return;
  26550. toFront (true);
  26551. XEvent ev;
  26552. zerostruct (ev);
  26553. ev.xbutton.display = display;
  26554. ev.xbutton.type = ButtonPress;
  26555. ev.xbutton.window = pluginWindow;
  26556. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26557. ev.xbutton.time = CurrentTime;
  26558. ev.xbutton.x = e.x;
  26559. ev.xbutton.y = e.y;
  26560. ev.xbutton.x_root = e.getScreenX();
  26561. ev.xbutton.y_root = e.getScreenY();
  26562. translateJuceToXButtonModifiers (e, ev);
  26563. sendEventToChild (&ev);
  26564. #elif JUCE_WIN32
  26565. (void) e;
  26566. toFront (true);
  26567. #endif
  26568. }
  26569. void broughtToFront()
  26570. {
  26571. activeVSTWindows.removeValue (this);
  26572. activeVSTWindows.add (this);
  26573. #if JUCE_MAC
  26574. dispatch (effEditTop, 0, 0, 0, 0);
  26575. #endif
  26576. }
  26577. juce_UseDebuggingNewOperator
  26578. private:
  26579. VSTPluginInstance& plugin;
  26580. bool isOpen, wasShowing, recursiveResize;
  26581. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26582. #if JUCE_WIN32
  26583. HWND pluginHWND;
  26584. void* originalWndProc;
  26585. int sizeCheckCount;
  26586. #elif JUCE_LINUX
  26587. Window pluginWindow;
  26588. EventProcPtr pluginProc;
  26589. #endif
  26590. #if JUCE_MAC
  26591. void openPluginWindow (WindowRef parentWindow)
  26592. {
  26593. if (isOpen || parentWindow == 0)
  26594. return;
  26595. isOpen = true;
  26596. ERect* rect = 0;
  26597. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26598. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26599. // do this before and after like in the steinberg example
  26600. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26601. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26602. // Install keyboard hooks
  26603. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26604. // double-check it's not too tiny
  26605. int w = 250, h = 150;
  26606. if (rect != 0)
  26607. {
  26608. w = rect->right - rect->left;
  26609. h = rect->bottom - rect->top;
  26610. if (w == 0 || h == 0)
  26611. {
  26612. w = 250;
  26613. h = 150;
  26614. }
  26615. }
  26616. w = jmax (w, 32);
  26617. h = jmax (h, 32);
  26618. setSize (w, h);
  26619. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26620. repaint();
  26621. }
  26622. #else
  26623. void openPluginWindow()
  26624. {
  26625. if (isOpen || getWindowHandle() == 0)
  26626. return;
  26627. log (T("Opening VST UI: ") + plugin.name);
  26628. isOpen = true;
  26629. ERect* rect = 0;
  26630. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26631. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26632. // do this before and after like in the steinberg example
  26633. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26634. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26635. // Install keyboard hooks
  26636. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26637. #if JUCE_WIN32
  26638. originalWndProc = 0;
  26639. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26640. if (pluginHWND == 0)
  26641. {
  26642. isOpen = false;
  26643. setSize (300, 150);
  26644. return;
  26645. }
  26646. #pragma warning (push)
  26647. #pragma warning (disable: 4244)
  26648. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26649. if (! pluginWantsKeys)
  26650. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) vstHookWndProc);
  26651. #pragma warning (pop)
  26652. int w, h;
  26653. RECT r;
  26654. GetWindowRect (pluginHWND, &r);
  26655. w = r.right - r.left;
  26656. h = r.bottom - r.top;
  26657. if (rect != 0)
  26658. {
  26659. const int rw = rect->right - rect->left;
  26660. const int rh = rect->bottom - rect->top;
  26661. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26662. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26663. {
  26664. // very dodgy logic to decide which size is right.
  26665. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26666. {
  26667. SetWindowPos (pluginHWND, 0,
  26668. 0, 0, rw, rh,
  26669. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26670. GetWindowRect (pluginHWND, &r);
  26671. w = r.right - r.left;
  26672. h = r.bottom - r.top;
  26673. pluginRefusesToResize = (w != rw) || (h != rh);
  26674. w = rw;
  26675. h = rh;
  26676. }
  26677. }
  26678. }
  26679. #elif JUCE_LINUX
  26680. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26681. if (pluginWindow != 0)
  26682. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26683. XInternAtom (display, "_XEventProc", False));
  26684. int w = 250, h = 150;
  26685. if (rect != 0)
  26686. {
  26687. w = rect->right - rect->left;
  26688. h = rect->bottom - rect->top;
  26689. if (w == 0 || h == 0)
  26690. {
  26691. w = 250;
  26692. h = 150;
  26693. }
  26694. }
  26695. if (pluginWindow != 0)
  26696. XMapRaised (display, pluginWindow);
  26697. #endif
  26698. // double-check it's not too tiny
  26699. w = jmax (w, 32);
  26700. h = jmax (h, 32);
  26701. setSize (w, h);
  26702. #if JUCE_WIN32
  26703. checkPluginWindowSize();
  26704. #endif
  26705. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26706. repaint();
  26707. }
  26708. #endif
  26709. #if ! JUCE_MAC
  26710. void closePluginWindow()
  26711. {
  26712. if (isOpen)
  26713. {
  26714. log (T("Closing VST UI: ") + plugin.getName());
  26715. isOpen = false;
  26716. dispatch (effEditClose, 0, 0, 0, 0);
  26717. #if JUCE_WIN32
  26718. #pragma warning (push)
  26719. #pragma warning (disable: 4244)
  26720. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26721. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) originalWndProc);
  26722. #pragma warning (pop)
  26723. stopTimer();
  26724. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26725. DestroyWindow (pluginHWND);
  26726. pluginHWND = 0;
  26727. #elif JUCE_LINUX
  26728. stopTimer();
  26729. pluginWindow = 0;
  26730. pluginProc = 0;
  26731. #endif
  26732. }
  26733. }
  26734. #endif
  26735. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26736. {
  26737. return plugin.dispatch (opcode, index, value, ptr, opt);
  26738. }
  26739. #if JUCE_WIN32
  26740. void checkPluginWindowSize() throw()
  26741. {
  26742. RECT r;
  26743. GetWindowRect (pluginHWND, &r);
  26744. const int w = r.right - r.left;
  26745. const int h = r.bottom - r.top;
  26746. if (isShowing() && w > 0 && h > 0
  26747. && (w != getWidth() || h != getHeight())
  26748. && ! pluginRefusesToResize)
  26749. {
  26750. setSize (w, h);
  26751. sizeCheckCount = 0;
  26752. }
  26753. }
  26754. // hooks to get keyboard events from VST windows..
  26755. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26756. {
  26757. for (int i = activeVSTWindows.size(); --i >= 0;)
  26758. {
  26759. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26760. if (w->pluginHWND == hW)
  26761. {
  26762. if (message == WM_CHAR
  26763. || message == WM_KEYDOWN
  26764. || message == WM_SYSKEYDOWN
  26765. || message == WM_KEYUP
  26766. || message == WM_SYSKEYUP
  26767. || message == WM_APPCOMMAND)
  26768. {
  26769. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26770. message, wParam, lParam);
  26771. }
  26772. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26773. (HWND) w->pluginHWND,
  26774. message,
  26775. wParam,
  26776. lParam);
  26777. }
  26778. }
  26779. return DefWindowProc (hW, message, wParam, lParam);
  26780. }
  26781. #endif
  26782. #if JUCE_LINUX
  26783. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26784. void sendEventToChild (XEvent* event)
  26785. {
  26786. if (pluginProc != 0)
  26787. {
  26788. // if the plugin publishes an event procedure, pass the event directly..
  26789. pluginProc (event);
  26790. }
  26791. else if (pluginWindow != 0)
  26792. {
  26793. // if the plugin has a window, then send the event to the window so that
  26794. // its message thread will pick it up..
  26795. XSendEvent (display, pluginWindow, False, 0L, event);
  26796. XFlush (display);
  26797. }
  26798. }
  26799. void mouseEnter (const MouseEvent& e)
  26800. {
  26801. if (pluginWindow != 0)
  26802. {
  26803. XEvent ev;
  26804. zerostruct (ev);
  26805. ev.xcrossing.display = display;
  26806. ev.xcrossing.type = EnterNotify;
  26807. ev.xcrossing.window = pluginWindow;
  26808. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26809. ev.xcrossing.time = CurrentTime;
  26810. ev.xcrossing.x = e.x;
  26811. ev.xcrossing.y = e.y;
  26812. ev.xcrossing.x_root = e.getScreenX();
  26813. ev.xcrossing.y_root = e.getScreenY();
  26814. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26815. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26816. translateJuceToXCrossingModifiers (e, ev);
  26817. sendEventToChild (&ev);
  26818. }
  26819. }
  26820. void mouseExit (const MouseEvent& e)
  26821. {
  26822. if (pluginWindow != 0)
  26823. {
  26824. XEvent ev;
  26825. zerostruct (ev);
  26826. ev.xcrossing.display = display;
  26827. ev.xcrossing.type = LeaveNotify;
  26828. ev.xcrossing.window = pluginWindow;
  26829. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26830. ev.xcrossing.time = CurrentTime;
  26831. ev.xcrossing.x = e.x;
  26832. ev.xcrossing.y = e.y;
  26833. ev.xcrossing.x_root = e.getScreenX();
  26834. ev.xcrossing.y_root = e.getScreenY();
  26835. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26836. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26837. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26838. translateJuceToXCrossingModifiers (e, ev);
  26839. sendEventToChild (&ev);
  26840. }
  26841. }
  26842. void mouseMove (const MouseEvent& e)
  26843. {
  26844. if (pluginWindow != 0)
  26845. {
  26846. XEvent ev;
  26847. zerostruct (ev);
  26848. ev.xmotion.display = display;
  26849. ev.xmotion.type = MotionNotify;
  26850. ev.xmotion.window = pluginWindow;
  26851. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26852. ev.xmotion.time = CurrentTime;
  26853. ev.xmotion.is_hint = NotifyNormal;
  26854. ev.xmotion.x = e.x;
  26855. ev.xmotion.y = e.y;
  26856. ev.xmotion.x_root = e.getScreenX();
  26857. ev.xmotion.y_root = e.getScreenY();
  26858. sendEventToChild (&ev);
  26859. }
  26860. }
  26861. void mouseDrag (const MouseEvent& e)
  26862. {
  26863. if (pluginWindow != 0)
  26864. {
  26865. XEvent ev;
  26866. zerostruct (ev);
  26867. ev.xmotion.display = display;
  26868. ev.xmotion.type = MotionNotify;
  26869. ev.xmotion.window = pluginWindow;
  26870. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26871. ev.xmotion.time = CurrentTime;
  26872. ev.xmotion.x = e.x ;
  26873. ev.xmotion.y = e.y;
  26874. ev.xmotion.x_root = e.getScreenX();
  26875. ev.xmotion.y_root = e.getScreenY();
  26876. ev.xmotion.is_hint = NotifyNormal;
  26877. translateJuceToXMotionModifiers (e, ev);
  26878. sendEventToChild (&ev);
  26879. }
  26880. }
  26881. void mouseUp (const MouseEvent& e)
  26882. {
  26883. if (pluginWindow != 0)
  26884. {
  26885. XEvent ev;
  26886. zerostruct (ev);
  26887. ev.xbutton.display = display;
  26888. ev.xbutton.type = ButtonRelease;
  26889. ev.xbutton.window = pluginWindow;
  26890. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26891. ev.xbutton.time = CurrentTime;
  26892. ev.xbutton.x = e.x;
  26893. ev.xbutton.y = e.y;
  26894. ev.xbutton.x_root = e.getScreenX();
  26895. ev.xbutton.y_root = e.getScreenY();
  26896. translateJuceToXButtonModifiers (e, ev);
  26897. sendEventToChild (&ev);
  26898. }
  26899. }
  26900. void mouseWheelMove (const MouseEvent& e,
  26901. float incrementX,
  26902. float incrementY)
  26903. {
  26904. if (pluginWindow != 0)
  26905. {
  26906. XEvent ev;
  26907. zerostruct (ev);
  26908. ev.xbutton.display = display;
  26909. ev.xbutton.type = ButtonPress;
  26910. ev.xbutton.window = pluginWindow;
  26911. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26912. ev.xbutton.time = CurrentTime;
  26913. ev.xbutton.x = e.x;
  26914. ev.xbutton.y = e.y;
  26915. ev.xbutton.x_root = e.getScreenX();
  26916. ev.xbutton.y_root = e.getScreenY();
  26917. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26918. sendEventToChild (&ev);
  26919. // TODO - put a usleep here ?
  26920. ev.xbutton.type = ButtonRelease;
  26921. sendEventToChild (&ev);
  26922. }
  26923. }
  26924. #endif
  26925. #if JUCE_MAC
  26926. #if ! JUCE_SUPPORT_CARBON
  26927. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26928. #endif
  26929. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26930. {
  26931. public:
  26932. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26933. : owner (owner_),
  26934. alreadyInside (false)
  26935. {
  26936. }
  26937. ~InnerWrapperComponent()
  26938. {
  26939. deleteWindow();
  26940. }
  26941. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26942. {
  26943. owner->openPluginWindow (windowRef);
  26944. return 0;
  26945. }
  26946. void removeView (HIViewRef)
  26947. {
  26948. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26949. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26950. }
  26951. bool getEmbeddedViewSize (int& w, int& h)
  26952. {
  26953. ERect* rect = 0;
  26954. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26955. w = rect->right - rect->left;
  26956. h = rect->bottom - rect->top;
  26957. return true;
  26958. }
  26959. void mouseDown (int x, int y)
  26960. {
  26961. if (! alreadyInside)
  26962. {
  26963. alreadyInside = true;
  26964. getTopLevelComponent()->toFront (true);
  26965. owner->dispatch (effEditMouse, x, y, 0, 0);
  26966. alreadyInside = false;
  26967. }
  26968. else
  26969. {
  26970. PostEvent (::mouseDown, 0);
  26971. }
  26972. }
  26973. void paint()
  26974. {
  26975. ComponentPeer* const peer = getPeer();
  26976. if (peer != 0)
  26977. {
  26978. ERect r;
  26979. r.left = getScreenX() - peer->getScreenX();
  26980. r.right = r.left + getWidth();
  26981. r.top = getScreenY() - peer->getScreenY();
  26982. r.bottom = r.top + getHeight();
  26983. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26984. }
  26985. }
  26986. private:
  26987. VSTPluginWindow* const owner;
  26988. bool alreadyInside;
  26989. };
  26990. friend class InnerWrapperComponent;
  26991. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26992. void resized()
  26993. {
  26994. innerWrapper->setSize (getWidth(), getHeight());
  26995. }
  26996. #endif
  26997. };
  26998. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26999. {
  27000. if (hasEditor())
  27001. return new VSTPluginWindow (*this);
  27002. return 0;
  27003. }
  27004. void VSTPluginInstance::handleAsyncUpdate()
  27005. {
  27006. // indicates that something about the plugin has changed..
  27007. updateHostDisplay();
  27008. }
  27009. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  27010. {
  27011. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  27012. {
  27013. changeProgramName (getCurrentProgram(), prog->prgName);
  27014. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  27015. setParameter (i, vst_swapFloat (prog->params[i]));
  27016. return true;
  27017. }
  27018. return false;
  27019. }
  27020. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  27021. const int dataSize)
  27022. {
  27023. if (dataSize < 28)
  27024. return false;
  27025. const fxSet* const set = (const fxSet*) data;
  27026. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  27027. || vst_swap (set->version) > fxbVersionNum)
  27028. return false;
  27029. if (vst_swap (set->fxMagic) == 'FxBk')
  27030. {
  27031. // bank of programs
  27032. if (vst_swap (set->numPrograms) >= 0)
  27033. {
  27034. const int oldProg = getCurrentProgram();
  27035. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  27036. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27037. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  27038. {
  27039. if (i != oldProg)
  27040. {
  27041. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  27042. if (((const char*) prog) - ((const char*) set) >= dataSize)
  27043. return false;
  27044. if (vst_swap (set->numPrograms) > 0)
  27045. setCurrentProgram (i);
  27046. if (! restoreProgramSettings (prog))
  27047. return false;
  27048. }
  27049. }
  27050. if (vst_swap (set->numPrograms) > 0)
  27051. setCurrentProgram (oldProg);
  27052. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  27053. if (((const char*) prog) - ((const char*) set) >= dataSize)
  27054. return false;
  27055. if (! restoreProgramSettings (prog))
  27056. return false;
  27057. }
  27058. }
  27059. else if (vst_swap (set->fxMagic) == 'FxCk')
  27060. {
  27061. // single program
  27062. const fxProgram* const prog = (const fxProgram*) data;
  27063. if (vst_swap (prog->chunkMagic) != 'CcnK')
  27064. return false;
  27065. changeProgramName (getCurrentProgram(), prog->prgName);
  27066. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  27067. setParameter (i, vst_swapFloat (prog->params[i]));
  27068. }
  27069. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  27070. {
  27071. // non-preset chunk
  27072. const fxChunkSet* const cset = (const fxChunkSet*) data;
  27073. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  27074. return false;
  27075. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  27076. }
  27077. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  27078. {
  27079. // preset chunk
  27080. const fxProgramSet* const cset = (const fxProgramSet*) data;
  27081. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  27082. return false;
  27083. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  27084. changeProgramName (getCurrentProgram(), cset->name);
  27085. }
  27086. else
  27087. {
  27088. return false;
  27089. }
  27090. return true;
  27091. }
  27092. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  27093. {
  27094. const int numParams = getNumParameters();
  27095. prog->chunkMagic = vst_swap ('CcnK');
  27096. prog->byteSize = 0;
  27097. prog->fxMagic = vst_swap ('FxCk');
  27098. prog->version = vst_swap (fxbVersionNum);
  27099. prog->fxID = vst_swap (getUID());
  27100. prog->fxVersion = vst_swap (getVersionNumber());
  27101. prog->numParams = vst_swap (numParams);
  27102. getCurrentProgramName().copyToBuffer (prog->prgName, sizeof (prog->prgName) - 1);
  27103. for (int i = 0; i < numParams; ++i)
  27104. prog->params[i] = vst_swapFloat (getParameter (i));
  27105. }
  27106. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  27107. {
  27108. const int numPrograms = getNumPrograms();
  27109. const int numParams = getNumParameters();
  27110. if (usesChunks())
  27111. {
  27112. if (isFXB)
  27113. {
  27114. MemoryBlock chunk;
  27115. getChunkData (chunk, false, maxSizeMB);
  27116. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  27117. dest.setSize (totalLen, true);
  27118. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  27119. set->chunkMagic = vst_swap ('CcnK');
  27120. set->byteSize = 0;
  27121. set->fxMagic = vst_swap ('FBCh');
  27122. set->version = vst_swap (fxbVersionNum);
  27123. set->fxID = vst_swap (getUID());
  27124. set->fxVersion = vst_swap (getVersionNumber());
  27125. set->numPrograms = vst_swap (numPrograms);
  27126. set->chunkSize = vst_swap ((long) chunk.getSize());
  27127. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27128. }
  27129. else
  27130. {
  27131. MemoryBlock chunk;
  27132. getChunkData (chunk, true, maxSizeMB);
  27133. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  27134. dest.setSize (totalLen, true);
  27135. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  27136. set->chunkMagic = vst_swap ('CcnK');
  27137. set->byteSize = 0;
  27138. set->fxMagic = vst_swap ('FPCh');
  27139. set->version = vst_swap (fxbVersionNum);
  27140. set->fxID = vst_swap (getUID());
  27141. set->fxVersion = vst_swap (getVersionNumber());
  27142. set->numPrograms = vst_swap (numPrograms);
  27143. set->chunkSize = vst_swap ((long) chunk.getSize());
  27144. getCurrentProgramName().copyToBuffer (set->name, sizeof (set->name) - 1);
  27145. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27146. }
  27147. }
  27148. else
  27149. {
  27150. if (isFXB)
  27151. {
  27152. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27153. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  27154. dest.setSize (len, true);
  27155. fxSet* const set = (fxSet*) dest.getData();
  27156. set->chunkMagic = vst_swap ('CcnK');
  27157. set->byteSize = 0;
  27158. set->fxMagic = vst_swap ('FxBk');
  27159. set->version = vst_swap (fxbVersionNum);
  27160. set->fxID = vst_swap (getUID());
  27161. set->fxVersion = vst_swap (getVersionNumber());
  27162. set->numPrograms = vst_swap (numPrograms);
  27163. const int oldProgram = getCurrentProgram();
  27164. MemoryBlock oldSettings;
  27165. createTempParameterStore (oldSettings);
  27166. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  27167. for (int i = 0; i < numPrograms; ++i)
  27168. {
  27169. if (i != oldProgram)
  27170. {
  27171. setCurrentProgram (i);
  27172. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  27173. }
  27174. }
  27175. setCurrentProgram (oldProgram);
  27176. restoreFromTempParameterStore (oldSettings);
  27177. }
  27178. else
  27179. {
  27180. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27181. dest.setSize (totalLen, true);
  27182. setParamsInProgramBlock ((fxProgram*) dest.getData());
  27183. }
  27184. }
  27185. return true;
  27186. }
  27187. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  27188. {
  27189. if (usesChunks())
  27190. {
  27191. void* data = 0;
  27192. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  27193. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  27194. {
  27195. mb.setSize (bytes);
  27196. mb.copyFrom (data, 0, bytes);
  27197. }
  27198. }
  27199. }
  27200. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  27201. {
  27202. if (size > 0 && usesChunks())
  27203. {
  27204. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  27205. if (! isPreset)
  27206. updateStoredProgramNames();
  27207. }
  27208. }
  27209. void VSTPluginInstance::timerCallback()
  27210. {
  27211. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  27212. stopTimer();
  27213. }
  27214. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  27215. {
  27216. const ScopedLock sl (lock);
  27217. ++insideVSTCallback;
  27218. int result = 0;
  27219. try
  27220. {
  27221. if (effect != 0)
  27222. {
  27223. #if JUCE_MAC
  27224. if (module->resFileId != 0)
  27225. UseResFile (module->resFileId);
  27226. CGrafPtr oldPort;
  27227. if (getActiveEditor() != 0)
  27228. {
  27229. int x = 0, y = 0;
  27230. getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), x, y);
  27231. GetPort (&oldPort);
  27232. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  27233. SetOrigin (-x, -y);
  27234. }
  27235. #endif
  27236. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  27237. #if JUCE_MAC
  27238. if (getActiveEditor() != 0)
  27239. SetPort (oldPort);
  27240. module->resFileId = CurResFile();
  27241. #endif
  27242. --insideVSTCallback;
  27243. return result;
  27244. }
  27245. }
  27246. catch (...)
  27247. {
  27248. //char s[512];
  27249. //sprintf (s, "dispatcher (%d, %d, %d, %x, %f)", opcode, index, value, (int)ptr, opt);
  27250. }
  27251. --insideVSTCallback;
  27252. return result;
  27253. }
  27254. // handles non plugin-specific callbacks..
  27255. static const int defaultVSTSampleRateValue = 16384;
  27256. static const int defaultVSTBlockSizeValue = 512;
  27257. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27258. {
  27259. (void) index;
  27260. (void) value;
  27261. (void) opt;
  27262. switch (opcode)
  27263. {
  27264. case audioMasterCanDo:
  27265. {
  27266. static const char* canDos[] = { "supplyIdle",
  27267. "sendVstEvents",
  27268. "sendVstMidiEvent",
  27269. "sendVstTimeInfo",
  27270. "receiveVstEvents",
  27271. "receiveVstMidiEvent",
  27272. "supportShell",
  27273. "shellCategory" };
  27274. for (int i = 0; i < numElementsInArray (canDos); ++i)
  27275. if (strcmp (canDos[i], (const char*) ptr) == 0)
  27276. return 1;
  27277. return 0;
  27278. }
  27279. case audioMasterVersion:
  27280. return 0x2400;
  27281. case audioMasterCurrentId:
  27282. return shellUIDToCreate;
  27283. case audioMasterGetNumAutomatableParameters:
  27284. return 0;
  27285. case audioMasterGetAutomationState:
  27286. return 1;
  27287. case audioMasterGetVendorVersion:
  27288. return 0x0101;
  27289. case audioMasterGetVendorString:
  27290. case audioMasterGetProductString:
  27291. {
  27292. String hostName ("Juce VST Host");
  27293. if (JUCEApplication::getInstance() != 0)
  27294. hostName = JUCEApplication::getInstance()->getApplicationName();
  27295. hostName.copyToBuffer ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  27296. }
  27297. break;
  27298. case audioMasterGetSampleRate:
  27299. return (VstIntPtr) defaultVSTSampleRateValue;
  27300. case audioMasterGetBlockSize:
  27301. return (VstIntPtr) defaultVSTBlockSizeValue;
  27302. case audioMasterSetOutputSampleRate:
  27303. return 0;
  27304. default:
  27305. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  27306. break;
  27307. }
  27308. return 0;
  27309. }
  27310. // handles callbacks for a specific plugin
  27311. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27312. {
  27313. switch (opcode)
  27314. {
  27315. case audioMasterAutomate:
  27316. sendParamChangeMessageToListeners (index, opt);
  27317. break;
  27318. case audioMasterProcessEvents:
  27319. handleMidiFromPlugin ((const VstEvents*) ptr);
  27320. break;
  27321. case audioMasterGetTime:
  27322. #ifdef _MSC_VER
  27323. #pragma warning (push)
  27324. #pragma warning (disable: 4311)
  27325. #endif
  27326. return (VstIntPtr) &vstHostTime;
  27327. #ifdef _MSC_VER
  27328. #pragma warning (pop)
  27329. #endif
  27330. break;
  27331. case audioMasterIdle:
  27332. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27333. {
  27334. ++insideVSTCallback;
  27335. #if JUCE_MAC
  27336. if (getActiveEditor() != 0)
  27337. dispatch (effEditIdle, 0, 0, 0, 0);
  27338. #endif
  27339. juce_callAnyTimersSynchronously();
  27340. handleUpdateNowIfNeeded();
  27341. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27342. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27343. --insideVSTCallback;
  27344. }
  27345. break;
  27346. case audioMasterUpdateDisplay:
  27347. triggerAsyncUpdate();
  27348. break;
  27349. case audioMasterTempoAt:
  27350. // returns (10000 * bpm)
  27351. break;
  27352. case audioMasterNeedIdle:
  27353. startTimer (50);
  27354. break;
  27355. case audioMasterSizeWindow:
  27356. if (getActiveEditor() != 0)
  27357. getActiveEditor()->setSize (index, value);
  27358. return 1;
  27359. case audioMasterGetSampleRate:
  27360. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27361. case audioMasterGetBlockSize:
  27362. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27363. case audioMasterWantMidi:
  27364. wantsMidiMessages = true;
  27365. break;
  27366. case audioMasterGetDirectory:
  27367. #if JUCE_MAC
  27368. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27369. #else
  27370. return (VstIntPtr) (pointer_sized_uint) (const char*) module->fullParentDirectoryPathName;
  27371. #endif
  27372. case audioMasterGetAutomationState:
  27373. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27374. break;
  27375. // none of these are handled (yet)..
  27376. case audioMasterBeginEdit:
  27377. case audioMasterEndEdit:
  27378. case audioMasterSetTime:
  27379. case audioMasterPinConnected:
  27380. case audioMasterGetParameterQuantization:
  27381. case audioMasterIOChanged:
  27382. case audioMasterGetInputLatency:
  27383. case audioMasterGetOutputLatency:
  27384. case audioMasterGetPreviousPlug:
  27385. case audioMasterGetNextPlug:
  27386. case audioMasterWillReplaceOrAccumulate:
  27387. case audioMasterGetCurrentProcessLevel:
  27388. case audioMasterOfflineStart:
  27389. case audioMasterOfflineRead:
  27390. case audioMasterOfflineWrite:
  27391. case audioMasterOfflineGetCurrentPass:
  27392. case audioMasterOfflineGetCurrentMetaPass:
  27393. case audioMasterVendorSpecific:
  27394. case audioMasterSetIcon:
  27395. case audioMasterGetLanguage:
  27396. case audioMasterOpenWindow:
  27397. case audioMasterCloseWindow:
  27398. break;
  27399. default:
  27400. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27401. }
  27402. return 0;
  27403. }
  27404. // entry point for all callbacks from the plugin
  27405. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27406. {
  27407. try
  27408. {
  27409. if (effect != 0 && effect->resvd2 != 0)
  27410. {
  27411. return ((VSTPluginInstance*)(effect->resvd2))
  27412. ->handleCallback (opcode, index, value, ptr, opt);
  27413. }
  27414. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27415. }
  27416. catch (...)
  27417. {
  27418. return 0;
  27419. }
  27420. }
  27421. const String VSTPluginInstance::getVersion() const throw()
  27422. {
  27423. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27424. String s;
  27425. if (v == 0 || v == -1)
  27426. v = getVersionNumber();
  27427. if (v != 0)
  27428. {
  27429. int versionBits[4];
  27430. int n = 0;
  27431. while (v != 0)
  27432. {
  27433. versionBits [n++] = (v & 0xff);
  27434. v >>= 8;
  27435. }
  27436. s << 'V';
  27437. while (n > 0)
  27438. {
  27439. s << versionBits [--n];
  27440. if (n > 0)
  27441. s << '.';
  27442. }
  27443. }
  27444. return s;
  27445. }
  27446. int VSTPluginInstance::getUID() const throw()
  27447. {
  27448. int uid = effect != 0 ? effect->uniqueID : 0;
  27449. if (uid == 0)
  27450. uid = module->file.hashCode();
  27451. return uid;
  27452. }
  27453. const String VSTPluginInstance::getCategory() const throw()
  27454. {
  27455. const char* result = 0;
  27456. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27457. {
  27458. case kPlugCategEffect:
  27459. result = "Effect";
  27460. break;
  27461. case kPlugCategSynth:
  27462. result = "Synth";
  27463. break;
  27464. case kPlugCategAnalysis:
  27465. result = "Anaylsis";
  27466. break;
  27467. case kPlugCategMastering:
  27468. result = "Mastering";
  27469. break;
  27470. case kPlugCategSpacializer:
  27471. result = "Spacial";
  27472. break;
  27473. case kPlugCategRoomFx:
  27474. result = "Reverb";
  27475. break;
  27476. case kPlugSurroundFx:
  27477. result = "Surround";
  27478. break;
  27479. case kPlugCategRestoration:
  27480. result = "Restoration";
  27481. break;
  27482. case kPlugCategGenerator:
  27483. result = "Tone generation";
  27484. break;
  27485. default:
  27486. break;
  27487. }
  27488. return result;
  27489. }
  27490. float VSTPluginInstance::getParameter (int index)
  27491. {
  27492. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27493. {
  27494. try
  27495. {
  27496. const ScopedLock sl (lock);
  27497. return effect->getParameter (effect, index);
  27498. }
  27499. catch (...)
  27500. {
  27501. }
  27502. }
  27503. return 0.0f;
  27504. }
  27505. void VSTPluginInstance::setParameter (int index, float newValue)
  27506. {
  27507. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27508. {
  27509. try
  27510. {
  27511. const ScopedLock sl (lock);
  27512. if (effect->getParameter (effect, index) != newValue)
  27513. effect->setParameter (effect, index, newValue);
  27514. }
  27515. catch (...)
  27516. {
  27517. }
  27518. }
  27519. }
  27520. const String VSTPluginInstance::getParameterName (int index)
  27521. {
  27522. if (effect != 0)
  27523. {
  27524. jassert (index >= 0 && index < effect->numParams);
  27525. char nm [256];
  27526. zerostruct (nm);
  27527. dispatch (effGetParamName, index, 0, nm, 0);
  27528. return String (nm).trim();
  27529. }
  27530. return String::empty;
  27531. }
  27532. const String VSTPluginInstance::getParameterLabel (int index) const
  27533. {
  27534. if (effect != 0)
  27535. {
  27536. jassert (index >= 0 && index < effect->numParams);
  27537. char nm [256];
  27538. zerostruct (nm);
  27539. dispatch (effGetParamLabel, index, 0, nm, 0);
  27540. return String (nm).trim();
  27541. }
  27542. return String::empty;
  27543. }
  27544. const String VSTPluginInstance::getParameterText (int index)
  27545. {
  27546. if (effect != 0)
  27547. {
  27548. jassert (index >= 0 && index < effect->numParams);
  27549. char nm [256];
  27550. zerostruct (nm);
  27551. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27552. return String (nm).trim();
  27553. }
  27554. return String::empty;
  27555. }
  27556. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27557. {
  27558. if (effect != 0)
  27559. {
  27560. jassert (index >= 0 && index < effect->numParams);
  27561. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27562. }
  27563. return false;
  27564. }
  27565. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27566. {
  27567. dest.setSize (64 + 4 * getNumParameters());
  27568. dest.fillWith (0);
  27569. getCurrentProgramName().copyToBuffer ((char*) dest.getData(), 63);
  27570. float* const p = (float*) (((char*) dest.getData()) + 64);
  27571. for (int i = 0; i < getNumParameters(); ++i)
  27572. p[i] = getParameter(i);
  27573. }
  27574. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27575. {
  27576. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27577. float* p = (float*) (((char*) m.getData()) + 64);
  27578. for (int i = 0; i < getNumParameters(); ++i)
  27579. setParameter (i, p[i]);
  27580. }
  27581. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27582. {
  27583. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27584. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27585. }
  27586. const String VSTPluginInstance::getProgramName (int index)
  27587. {
  27588. if (index == getCurrentProgram())
  27589. {
  27590. return getCurrentProgramName();
  27591. }
  27592. else if (effect != 0)
  27593. {
  27594. char nm [256];
  27595. zerostruct (nm);
  27596. if (dispatch (effGetProgramNameIndexed,
  27597. jlimit (0, getNumPrograms(), index),
  27598. -1, nm, 0) != 0)
  27599. {
  27600. return String (nm).trim();
  27601. }
  27602. }
  27603. return programNames [index];
  27604. }
  27605. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27606. {
  27607. if (index == getCurrentProgram())
  27608. {
  27609. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27610. dispatch (effSetProgramName, 0, 0, (void*) (const char*) newName.substring (0, 24), 0.0f);
  27611. }
  27612. else
  27613. {
  27614. jassertfalse // xxx not implemented!
  27615. }
  27616. }
  27617. void VSTPluginInstance::updateStoredProgramNames()
  27618. {
  27619. if (effect != 0 && getNumPrograms() > 0)
  27620. {
  27621. char nm [256];
  27622. zerostruct (nm);
  27623. // only do this if the plugin can't use indexed names..
  27624. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27625. {
  27626. const int oldProgram = getCurrentProgram();
  27627. MemoryBlock oldSettings;
  27628. createTempParameterStore (oldSettings);
  27629. for (int i = 0; i < getNumPrograms(); ++i)
  27630. {
  27631. setCurrentProgram (i);
  27632. getCurrentProgramName(); // (this updates the list)
  27633. }
  27634. setCurrentProgram (oldProgram);
  27635. restoreFromTempParameterStore (oldSettings);
  27636. }
  27637. }
  27638. }
  27639. const String VSTPluginInstance::getCurrentProgramName()
  27640. {
  27641. if (effect != 0)
  27642. {
  27643. char nm [256];
  27644. zerostruct (nm);
  27645. dispatch (effGetProgramName, 0, 0, nm, 0);
  27646. const int index = getCurrentProgram();
  27647. if (programNames[index].isEmpty())
  27648. {
  27649. while (programNames.size() < index)
  27650. programNames.add (String::empty);
  27651. programNames.set (index, String (nm).trim());
  27652. }
  27653. return String (nm).trim();
  27654. }
  27655. return String::empty;
  27656. }
  27657. const String VSTPluginInstance::getInputChannelName (const int index) const
  27658. {
  27659. if (index >= 0 && index < getNumInputChannels())
  27660. {
  27661. VstPinProperties pinProps;
  27662. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27663. return String (pinProps.label, sizeof (pinProps.label));
  27664. }
  27665. return String::empty;
  27666. }
  27667. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27668. {
  27669. if (index < 0 || index >= getNumInputChannels())
  27670. return false;
  27671. VstPinProperties pinProps;
  27672. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27673. return (pinProps.flags & kVstPinIsStereo) != 0;
  27674. return true;
  27675. }
  27676. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27677. {
  27678. if (index >= 0 && index < getNumOutputChannels())
  27679. {
  27680. VstPinProperties pinProps;
  27681. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27682. return String (pinProps.label, sizeof (pinProps.label));
  27683. }
  27684. return String::empty;
  27685. }
  27686. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27687. {
  27688. if (index < 0 || index >= getNumOutputChannels())
  27689. return false;
  27690. VstPinProperties pinProps;
  27691. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27692. return (pinProps.flags & kVstPinIsStereo) != 0;
  27693. return true;
  27694. }
  27695. void VSTPluginInstance::setPower (const bool on)
  27696. {
  27697. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27698. isPowerOn = on;
  27699. }
  27700. const int defaultMaxSizeMB = 64;
  27701. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27702. {
  27703. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27704. }
  27705. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27706. {
  27707. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27708. }
  27709. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27710. {
  27711. loadFromFXBFile (data, sizeInBytes);
  27712. }
  27713. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27714. {
  27715. loadFromFXBFile (data, sizeInBytes);
  27716. }
  27717. VSTPluginFormat::VSTPluginFormat()
  27718. {
  27719. }
  27720. VSTPluginFormat::~VSTPluginFormat()
  27721. {
  27722. }
  27723. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27724. const String& fileOrIdentifier)
  27725. {
  27726. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27727. return;
  27728. PluginDescription desc;
  27729. desc.fileOrIdentifier = fileOrIdentifier;
  27730. desc.uid = 0;
  27731. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27732. if (instance == 0)
  27733. return;
  27734. try
  27735. {
  27736. #if JUCE_MAC
  27737. if (instance->module->resFileId != 0)
  27738. UseResFile (instance->module->resFileId);
  27739. #endif
  27740. instance->fillInPluginDescription (desc);
  27741. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27742. if (category != kPlugCategShell)
  27743. {
  27744. // Normal plugin...
  27745. results.add (new PluginDescription (desc));
  27746. ++insideVSTCallback;
  27747. instance->dispatch (effOpen, 0, 0, 0, 0);
  27748. --insideVSTCallback;
  27749. }
  27750. else
  27751. {
  27752. // It's a shell plugin, so iterate all the subtypes...
  27753. char shellEffectName [64];
  27754. for (;;)
  27755. {
  27756. zerostruct (shellEffectName);
  27757. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27758. if (uid == 0)
  27759. {
  27760. break;
  27761. }
  27762. else
  27763. {
  27764. desc.uid = uid;
  27765. desc.name = shellEffectName;
  27766. bool alreadyThere = false;
  27767. for (int i = results.size(); --i >= 0;)
  27768. {
  27769. PluginDescription* const d = results.getUnchecked(i);
  27770. if (d->isDuplicateOf (desc))
  27771. {
  27772. alreadyThere = true;
  27773. break;
  27774. }
  27775. }
  27776. if (! alreadyThere)
  27777. results.add (new PluginDescription (desc));
  27778. }
  27779. }
  27780. }
  27781. }
  27782. catch (...)
  27783. {
  27784. // crashed while loading...
  27785. }
  27786. }
  27787. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27788. {
  27789. ScopedPointer <VSTPluginInstance> result;
  27790. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27791. {
  27792. File file (desc.fileOrIdentifier);
  27793. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27794. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27795. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27796. if (module != 0)
  27797. {
  27798. shellUIDToCreate = desc.uid;
  27799. result = new VSTPluginInstance (module);
  27800. if (result->effect != 0)
  27801. {
  27802. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27803. result->initialise();
  27804. }
  27805. else
  27806. {
  27807. result = 0;
  27808. }
  27809. }
  27810. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27811. }
  27812. return result.release();
  27813. }
  27814. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27815. {
  27816. const File f (fileOrIdentifier);
  27817. #if JUCE_MAC
  27818. if (f.isDirectory() && f.hasFileExtension (T(".vst")))
  27819. return true;
  27820. #if JUCE_PPC
  27821. FSRef fileRef;
  27822. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27823. {
  27824. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27825. if (resFileId != -1)
  27826. {
  27827. const int numEffects = Count1Resources ('aEff');
  27828. CloseResFile (resFileId);
  27829. if (numEffects > 0)
  27830. return true;
  27831. }
  27832. }
  27833. #endif
  27834. return false;
  27835. #elif JUCE_WIN32
  27836. return f.existsAsFile()
  27837. && f.hasFileExtension (T(".dll"));
  27838. #elif JUCE_LINUX
  27839. return f.existsAsFile()
  27840. && f.hasFileExtension (T(".so"));
  27841. #endif
  27842. }
  27843. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27844. {
  27845. return fileOrIdentifier;
  27846. }
  27847. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27848. {
  27849. return File (desc.fileOrIdentifier).exists();
  27850. }
  27851. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27852. {
  27853. StringArray results;
  27854. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27855. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27856. return results;
  27857. }
  27858. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27859. {
  27860. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27861. // .component or .vst directories.
  27862. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27863. while (iter.next())
  27864. {
  27865. const File f (iter.getFile());
  27866. bool isPlugin = false;
  27867. if (fileMightContainThisPluginType (f.getFullPathName()))
  27868. {
  27869. isPlugin = true;
  27870. results.add (f.getFullPathName());
  27871. }
  27872. if (recursive && (! isPlugin) && f.isDirectory())
  27873. recursiveFileSearch (results, f, true);
  27874. }
  27875. }
  27876. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27877. {
  27878. #if JUCE_MAC
  27879. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27880. #elif JUCE_WIN32
  27881. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27882. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27883. #elif JUCE_LINUX
  27884. return FileSearchPath ("/usr/lib/vst");
  27885. #endif
  27886. }
  27887. END_JUCE_NAMESPACE
  27888. #endif
  27889. #undef log
  27890. #endif
  27891. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27892. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27893. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27894. BEGIN_JUCE_NAMESPACE
  27895. AudioProcessor::AudioProcessor()
  27896. : playHead (0),
  27897. activeEditor (0),
  27898. sampleRate (0),
  27899. blockSize (0),
  27900. numInputChannels (0),
  27901. numOutputChannels (0),
  27902. latencySamples (0),
  27903. suspended (false),
  27904. nonRealtime (false)
  27905. {
  27906. }
  27907. AudioProcessor::~AudioProcessor()
  27908. {
  27909. // ooh, nasty - the editor should have been deleted before the filter
  27910. // that it refers to is deleted..
  27911. jassert (activeEditor == 0);
  27912. #ifdef JUCE_DEBUG
  27913. // This will fail if you've called beginParameterChangeGesture() for one
  27914. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27915. jassert (changingParams.countNumberOfSetBits() == 0);
  27916. #endif
  27917. }
  27918. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27919. {
  27920. playHead = newPlayHead;
  27921. }
  27922. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27923. {
  27924. const ScopedLock sl (listenerLock);
  27925. listeners.addIfNotAlreadyThere (newListener);
  27926. }
  27927. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27928. {
  27929. const ScopedLock sl (listenerLock);
  27930. listeners.removeValue (listenerToRemove);
  27931. }
  27932. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27933. const int numOuts,
  27934. const double sampleRate_,
  27935. const int blockSize_) throw()
  27936. {
  27937. numInputChannels = numIns;
  27938. numOutputChannels = numOuts;
  27939. sampleRate = sampleRate_;
  27940. blockSize = blockSize_;
  27941. }
  27942. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27943. {
  27944. nonRealtime = nonRealtime_;
  27945. }
  27946. void AudioProcessor::setLatencySamples (const int newLatency)
  27947. {
  27948. if (latencySamples != newLatency)
  27949. {
  27950. latencySamples = newLatency;
  27951. updateHostDisplay();
  27952. }
  27953. }
  27954. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27955. const float newValue)
  27956. {
  27957. setParameter (parameterIndex, newValue);
  27958. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27959. }
  27960. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27961. {
  27962. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27963. for (int i = listeners.size(); --i >= 0;)
  27964. {
  27965. listenerLock.enter();
  27966. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27967. listenerLock.exit();
  27968. if (l != 0)
  27969. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27970. }
  27971. }
  27972. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27973. {
  27974. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27975. #ifdef JUCE_DEBUG
  27976. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27977. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27978. jassert (! changingParams [parameterIndex]);
  27979. changingParams.setBit (parameterIndex);
  27980. #endif
  27981. for (int i = listeners.size(); --i >= 0;)
  27982. {
  27983. listenerLock.enter();
  27984. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27985. listenerLock.exit();
  27986. if (l != 0)
  27987. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27988. }
  27989. }
  27990. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27991. {
  27992. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27993. #ifdef JUCE_DEBUG
  27994. // This means you've called endParameterChangeGesture without having previously called
  27995. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27996. // calls matched correctly.
  27997. jassert (changingParams [parameterIndex]);
  27998. changingParams.clearBit (parameterIndex);
  27999. #endif
  28000. for (int i = listeners.size(); --i >= 0;)
  28001. {
  28002. listenerLock.enter();
  28003. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  28004. listenerLock.exit();
  28005. if (l != 0)
  28006. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  28007. }
  28008. }
  28009. void AudioProcessor::updateHostDisplay()
  28010. {
  28011. for (int i = listeners.size(); --i >= 0;)
  28012. {
  28013. listenerLock.enter();
  28014. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  28015. listenerLock.exit();
  28016. if (l != 0)
  28017. l->audioProcessorChanged (this);
  28018. }
  28019. }
  28020. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  28021. {
  28022. return true;
  28023. }
  28024. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  28025. {
  28026. return false;
  28027. }
  28028. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  28029. {
  28030. const ScopedLock sl (callbackLock);
  28031. suspended = shouldBeSuspended;
  28032. }
  28033. void AudioProcessor::reset()
  28034. {
  28035. }
  28036. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  28037. {
  28038. const ScopedLock sl (callbackLock);
  28039. jassert (activeEditor == editor);
  28040. if (activeEditor == editor)
  28041. activeEditor = 0;
  28042. }
  28043. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  28044. {
  28045. if (activeEditor != 0)
  28046. return activeEditor;
  28047. AudioProcessorEditor* const ed = createEditor();
  28048. if (ed != 0)
  28049. {
  28050. // you must give your editor comp a size before returning it..
  28051. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  28052. const ScopedLock sl (callbackLock);
  28053. activeEditor = ed;
  28054. }
  28055. return ed;
  28056. }
  28057. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  28058. {
  28059. getStateInformation (destData);
  28060. }
  28061. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  28062. {
  28063. setStateInformation (data, sizeInBytes);
  28064. }
  28065. // magic number to identify memory blocks that we've stored as XML
  28066. const uint32 magicXmlNumber = 0x21324356;
  28067. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  28068. JUCE_NAMESPACE::MemoryBlock& destData)
  28069. {
  28070. const String xmlString (xml.createDocument (String::empty, true, false));
  28071. const int stringLength = xmlString.length();
  28072. destData.setSize (stringLength + 10);
  28073. char* const d = (char*) destData.getData();
  28074. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  28075. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  28076. xmlString.copyToBuffer (d + 8, stringLength);
  28077. }
  28078. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  28079. const int sizeInBytes)
  28080. {
  28081. if (sizeInBytes > 8
  28082. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  28083. {
  28084. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  28085. if (stringLength > 0)
  28086. {
  28087. XmlDocument doc (String (((const char*) data) + 8,
  28088. jmin ((sizeInBytes - 8), stringLength)));
  28089. return doc.getDocumentElement();
  28090. }
  28091. }
  28092. return 0;
  28093. }
  28094. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  28095. {
  28096. }
  28097. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  28098. {
  28099. }
  28100. END_JUCE_NAMESPACE
  28101. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  28102. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  28103. BEGIN_JUCE_NAMESPACE
  28104. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  28105. : owner (owner_)
  28106. {
  28107. // the filter must be valid..
  28108. jassert (owner != 0);
  28109. }
  28110. AudioProcessorEditor::~AudioProcessorEditor()
  28111. {
  28112. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  28113. // filter for some reason..
  28114. jassert (owner->getActiveEditor() != this);
  28115. }
  28116. END_JUCE_NAMESPACE
  28117. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  28118. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  28119. BEGIN_JUCE_NAMESPACE
  28120. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  28121. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  28122. : id (id_),
  28123. processor (processor_),
  28124. isPrepared (false)
  28125. {
  28126. jassert (processor_ != 0);
  28127. }
  28128. AudioProcessorGraph::Node::~Node()
  28129. {
  28130. delete processor;
  28131. }
  28132. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  28133. AudioProcessorGraph* const graph)
  28134. {
  28135. if (! isPrepared)
  28136. {
  28137. isPrepared = true;
  28138. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28139. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  28140. if (ioProc != 0)
  28141. ioProc->setParentGraph (graph);
  28142. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  28143. processor->getNumOutputChannels(),
  28144. sampleRate, blockSize);
  28145. processor->prepareToPlay (sampleRate, blockSize);
  28146. }
  28147. }
  28148. void AudioProcessorGraph::Node::unprepare()
  28149. {
  28150. if (isPrepared)
  28151. {
  28152. isPrepared = false;
  28153. processor->releaseResources();
  28154. }
  28155. }
  28156. AudioProcessorGraph::AudioProcessorGraph()
  28157. : lastNodeId (0),
  28158. renderingBuffers (1, 1),
  28159. currentAudioOutputBuffer (1, 1)
  28160. {
  28161. }
  28162. AudioProcessorGraph::~AudioProcessorGraph()
  28163. {
  28164. clearRenderingSequence();
  28165. clear();
  28166. }
  28167. const String AudioProcessorGraph::getName() const
  28168. {
  28169. return "Audio Graph";
  28170. }
  28171. void AudioProcessorGraph::clear()
  28172. {
  28173. nodes.clear();
  28174. connections.clear();
  28175. triggerAsyncUpdate();
  28176. }
  28177. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  28178. {
  28179. for (int i = nodes.size(); --i >= 0;)
  28180. if (nodes.getUnchecked(i)->id == nodeId)
  28181. return nodes.getUnchecked(i);
  28182. return 0;
  28183. }
  28184. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  28185. uint32 nodeId)
  28186. {
  28187. if (newProcessor == 0)
  28188. {
  28189. jassertfalse
  28190. return 0;
  28191. }
  28192. if (nodeId == 0)
  28193. {
  28194. nodeId = ++lastNodeId;
  28195. }
  28196. else
  28197. {
  28198. // you can't add a node with an id that already exists in the graph..
  28199. jassert (getNodeForId (nodeId) == 0);
  28200. removeNode (nodeId);
  28201. }
  28202. lastNodeId = nodeId;
  28203. Node* const n = new Node (nodeId, newProcessor);
  28204. nodes.add (n);
  28205. triggerAsyncUpdate();
  28206. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28207. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  28208. if (ioProc != 0)
  28209. ioProc->setParentGraph (this);
  28210. return n;
  28211. }
  28212. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  28213. {
  28214. disconnectNode (nodeId);
  28215. for (int i = nodes.size(); --i >= 0;)
  28216. {
  28217. if (nodes.getUnchecked(i)->id == nodeId)
  28218. {
  28219. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28220. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  28221. if (ioProc != 0)
  28222. ioProc->setParentGraph (0);
  28223. nodes.remove (i);
  28224. triggerAsyncUpdate();
  28225. return true;
  28226. }
  28227. }
  28228. return false;
  28229. }
  28230. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  28231. const int sourceChannelIndex,
  28232. const uint32 destNodeId,
  28233. const int destChannelIndex) const
  28234. {
  28235. for (int i = connections.size(); --i >= 0;)
  28236. {
  28237. const Connection* const c = connections.getUnchecked(i);
  28238. if (c->sourceNodeId == sourceNodeId
  28239. && c->destNodeId == destNodeId
  28240. && c->sourceChannelIndex == sourceChannelIndex
  28241. && c->destChannelIndex == destChannelIndex)
  28242. {
  28243. return c;
  28244. }
  28245. }
  28246. return 0;
  28247. }
  28248. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  28249. const uint32 possibleDestNodeId) const
  28250. {
  28251. for (int i = connections.size(); --i >= 0;)
  28252. {
  28253. const Connection* const c = connections.getUnchecked(i);
  28254. if (c->sourceNodeId == possibleSourceNodeId
  28255. && c->destNodeId == possibleDestNodeId)
  28256. {
  28257. return true;
  28258. }
  28259. }
  28260. return false;
  28261. }
  28262. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  28263. const int sourceChannelIndex,
  28264. const uint32 destNodeId,
  28265. const int destChannelIndex) const
  28266. {
  28267. if (sourceChannelIndex < 0
  28268. || destChannelIndex < 0
  28269. || sourceNodeId == destNodeId
  28270. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  28271. return false;
  28272. const Node* const source = getNodeForId (sourceNodeId);
  28273. if (source == 0
  28274. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  28275. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  28276. return false;
  28277. const Node* const dest = getNodeForId (destNodeId);
  28278. if (dest == 0
  28279. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  28280. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  28281. return false;
  28282. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  28283. destNodeId, destChannelIndex) == 0;
  28284. }
  28285. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  28286. const int sourceChannelIndex,
  28287. const uint32 destNodeId,
  28288. const int destChannelIndex)
  28289. {
  28290. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  28291. return false;
  28292. Connection* const c = new Connection();
  28293. c->sourceNodeId = sourceNodeId;
  28294. c->sourceChannelIndex = sourceChannelIndex;
  28295. c->destNodeId = destNodeId;
  28296. c->destChannelIndex = destChannelIndex;
  28297. connections.add (c);
  28298. triggerAsyncUpdate();
  28299. return true;
  28300. }
  28301. void AudioProcessorGraph::removeConnection (const int index)
  28302. {
  28303. connections.remove (index);
  28304. triggerAsyncUpdate();
  28305. }
  28306. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28307. const uint32 destNodeId, const int destChannelIndex)
  28308. {
  28309. bool doneAnything = false;
  28310. for (int i = connections.size(); --i >= 0;)
  28311. {
  28312. const Connection* const c = connections.getUnchecked(i);
  28313. if (c->sourceNodeId == sourceNodeId
  28314. && c->destNodeId == destNodeId
  28315. && c->sourceChannelIndex == sourceChannelIndex
  28316. && c->destChannelIndex == destChannelIndex)
  28317. {
  28318. removeConnection (i);
  28319. doneAnything = true;
  28320. triggerAsyncUpdate();
  28321. }
  28322. }
  28323. return doneAnything;
  28324. }
  28325. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28326. {
  28327. bool doneAnything = false;
  28328. for (int i = connections.size(); --i >= 0;)
  28329. {
  28330. const Connection* const c = connections.getUnchecked(i);
  28331. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28332. {
  28333. removeConnection (i);
  28334. doneAnything = true;
  28335. triggerAsyncUpdate();
  28336. }
  28337. }
  28338. return doneAnything;
  28339. }
  28340. bool AudioProcessorGraph::removeIllegalConnections()
  28341. {
  28342. bool doneAnything = false;
  28343. for (int i = connections.size(); --i >= 0;)
  28344. {
  28345. const Connection* const c = connections.getUnchecked(i);
  28346. const Node* const source = getNodeForId (c->sourceNodeId);
  28347. const Node* const dest = getNodeForId (c->destNodeId);
  28348. if (source == 0 || dest == 0
  28349. || (c->sourceChannelIndex != midiChannelIndex
  28350. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28351. || (c->sourceChannelIndex == midiChannelIndex
  28352. && ! source->processor->producesMidi())
  28353. || (c->destChannelIndex != midiChannelIndex
  28354. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28355. || (c->destChannelIndex == midiChannelIndex
  28356. && ! dest->processor->acceptsMidi()))
  28357. {
  28358. removeConnection (i);
  28359. doneAnything = true;
  28360. triggerAsyncUpdate();
  28361. }
  28362. }
  28363. return doneAnything;
  28364. }
  28365. namespace GraphRenderingOps
  28366. {
  28367. class AudioGraphRenderingOp
  28368. {
  28369. public:
  28370. AudioGraphRenderingOp() {}
  28371. virtual ~AudioGraphRenderingOp() {}
  28372. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28373. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28374. const int numSamples) = 0;
  28375. juce_UseDebuggingNewOperator
  28376. };
  28377. class ClearChannelOp : public AudioGraphRenderingOp
  28378. {
  28379. public:
  28380. ClearChannelOp (const int channelNum_)
  28381. : channelNum (channelNum_)
  28382. {}
  28383. ~ClearChannelOp() {}
  28384. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28385. {
  28386. sharedBufferChans.clear (channelNum, 0, numSamples);
  28387. }
  28388. private:
  28389. const int channelNum;
  28390. ClearChannelOp (const ClearChannelOp&);
  28391. const ClearChannelOp& operator= (const ClearChannelOp&);
  28392. };
  28393. class CopyChannelOp : public AudioGraphRenderingOp
  28394. {
  28395. public:
  28396. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28397. : srcChannelNum (srcChannelNum_),
  28398. dstChannelNum (dstChannelNum_)
  28399. {}
  28400. ~CopyChannelOp() {}
  28401. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28402. {
  28403. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28404. }
  28405. private:
  28406. const int srcChannelNum, dstChannelNum;
  28407. CopyChannelOp (const CopyChannelOp&);
  28408. const CopyChannelOp& operator= (const CopyChannelOp&);
  28409. };
  28410. class AddChannelOp : public AudioGraphRenderingOp
  28411. {
  28412. public:
  28413. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28414. : srcChannelNum (srcChannelNum_),
  28415. dstChannelNum (dstChannelNum_)
  28416. {}
  28417. ~AddChannelOp() {}
  28418. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28419. {
  28420. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28421. }
  28422. private:
  28423. const int srcChannelNum, dstChannelNum;
  28424. AddChannelOp (const AddChannelOp&);
  28425. const AddChannelOp& operator= (const AddChannelOp&);
  28426. };
  28427. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28428. {
  28429. public:
  28430. ClearMidiBufferOp (const int bufferNum_)
  28431. : bufferNum (bufferNum_)
  28432. {}
  28433. ~ClearMidiBufferOp() {}
  28434. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28435. {
  28436. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28437. }
  28438. private:
  28439. const int bufferNum;
  28440. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28441. const ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28442. };
  28443. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28444. {
  28445. public:
  28446. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28447. : srcBufferNum (srcBufferNum_),
  28448. dstBufferNum (dstBufferNum_)
  28449. {}
  28450. ~CopyMidiBufferOp() {}
  28451. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28452. {
  28453. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28454. }
  28455. private:
  28456. const int srcBufferNum, dstBufferNum;
  28457. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28458. const CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28459. };
  28460. class AddMidiBufferOp : public AudioGraphRenderingOp
  28461. {
  28462. public:
  28463. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28464. : srcBufferNum (srcBufferNum_),
  28465. dstBufferNum (dstBufferNum_)
  28466. {}
  28467. ~AddMidiBufferOp() {}
  28468. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28469. {
  28470. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28471. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28472. }
  28473. private:
  28474. const int srcBufferNum, dstBufferNum;
  28475. AddMidiBufferOp (const AddMidiBufferOp&);
  28476. const AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28477. };
  28478. class ProcessBufferOp : public AudioGraphRenderingOp
  28479. {
  28480. public:
  28481. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28482. const Array <int>& audioChannelsToUse_,
  28483. const int totalChans_,
  28484. const int midiBufferToUse_)
  28485. : node (node_),
  28486. processor (node_->processor),
  28487. audioChannelsToUse (audioChannelsToUse_),
  28488. totalChans (jmax (1, totalChans_)),
  28489. midiBufferToUse (midiBufferToUse_)
  28490. {
  28491. channels.calloc (totalChans);
  28492. while (audioChannelsToUse.size() < totalChans)
  28493. audioChannelsToUse.add (0);
  28494. }
  28495. ~ProcessBufferOp()
  28496. {
  28497. }
  28498. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28499. {
  28500. for (int i = totalChans; --i >= 0;)
  28501. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28502. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28503. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28504. }
  28505. const AudioProcessorGraph::Node::Ptr node;
  28506. AudioProcessor* const processor;
  28507. private:
  28508. Array <int> audioChannelsToUse;
  28509. HeapBlock <float*> channels;
  28510. int totalChans;
  28511. int midiBufferToUse;
  28512. ProcessBufferOp (const ProcessBufferOp&);
  28513. const ProcessBufferOp& operator= (const ProcessBufferOp&);
  28514. };
  28515. class RenderingOpSequenceCalculator
  28516. {
  28517. public:
  28518. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28519. const VoidArray& orderedNodes_,
  28520. VoidArray& renderingOps)
  28521. : graph (graph_),
  28522. orderedNodes (orderedNodes_)
  28523. {
  28524. nodeIds.add (-2); // first buffer is read-only zeros
  28525. channels.add (0);
  28526. midiNodeIds.add (-2);
  28527. for (int i = 0; i < orderedNodes.size(); ++i)
  28528. {
  28529. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28530. renderingOps, i);
  28531. markAnyUnusedBuffersAsFree (i);
  28532. }
  28533. }
  28534. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28535. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28536. juce_UseDebuggingNewOperator
  28537. private:
  28538. AudioProcessorGraph& graph;
  28539. const VoidArray& orderedNodes;
  28540. Array <int> nodeIds, channels, midiNodeIds;
  28541. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28542. VoidArray& renderingOps,
  28543. const int ourRenderingIndex)
  28544. {
  28545. const int numIns = node->processor->getNumInputChannels();
  28546. const int numOuts = node->processor->getNumOutputChannels();
  28547. const int totalChans = jmax (numIns, numOuts);
  28548. Array <int> audioChannelsToUse;
  28549. int midiBufferToUse = -1;
  28550. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28551. {
  28552. // get a list of all the inputs to this node
  28553. Array <int> sourceNodes, sourceOutputChans;
  28554. for (int i = graph.getNumConnections(); --i >= 0;)
  28555. {
  28556. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28557. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28558. {
  28559. sourceNodes.add (c->sourceNodeId);
  28560. sourceOutputChans.add (c->sourceChannelIndex);
  28561. }
  28562. }
  28563. int bufIndex = -1;
  28564. if (sourceNodes.size() == 0)
  28565. {
  28566. // unconnected input channel
  28567. if (inputChan >= numOuts)
  28568. {
  28569. bufIndex = getReadOnlyEmptyBuffer();
  28570. jassert (bufIndex >= 0);
  28571. }
  28572. else
  28573. {
  28574. bufIndex = getFreeBuffer (false);
  28575. renderingOps.add (new ClearChannelOp (bufIndex));
  28576. }
  28577. }
  28578. else if (sourceNodes.size() == 1)
  28579. {
  28580. // channel with a straightforward single input..
  28581. const int srcNode = sourceNodes.getUnchecked(0);
  28582. const int srcChan = sourceOutputChans.getUnchecked(0);
  28583. bufIndex = getBufferContaining (srcNode, srcChan);
  28584. if (bufIndex < 0)
  28585. {
  28586. // if not found, this is probably a feedback loop
  28587. bufIndex = getReadOnlyEmptyBuffer();
  28588. jassert (bufIndex >= 0);
  28589. }
  28590. if (inputChan < numOuts
  28591. && isBufferNeededLater (ourRenderingIndex,
  28592. inputChan,
  28593. srcNode, srcChan))
  28594. {
  28595. // can't mess up this channel because it's needed later by another node, so we
  28596. // need to use a copy of it..
  28597. const int newFreeBuffer = getFreeBuffer (false);
  28598. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28599. bufIndex = newFreeBuffer;
  28600. }
  28601. }
  28602. else
  28603. {
  28604. // channel with a mix of several inputs..
  28605. // try to find a re-usable channel from our inputs..
  28606. int reusableInputIndex = -1;
  28607. for (int i = 0; i < sourceNodes.size(); ++i)
  28608. {
  28609. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28610. sourceOutputChans.getUnchecked(i));
  28611. if (sourceBufIndex >= 0
  28612. && ! isBufferNeededLater (ourRenderingIndex,
  28613. inputChan,
  28614. sourceNodes.getUnchecked(i),
  28615. sourceOutputChans.getUnchecked(i)))
  28616. {
  28617. // we've found one of our input chans that can be re-used..
  28618. reusableInputIndex = i;
  28619. bufIndex = sourceBufIndex;
  28620. break;
  28621. }
  28622. }
  28623. if (reusableInputIndex < 0)
  28624. {
  28625. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28626. bufIndex = getFreeBuffer (false);
  28627. jassert (bufIndex != 0);
  28628. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28629. sourceOutputChans.getUnchecked (0));
  28630. if (srcIndex < 0)
  28631. {
  28632. // if not found, this is probably a feedback loop
  28633. renderingOps.add (new ClearChannelOp (bufIndex));
  28634. }
  28635. else
  28636. {
  28637. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28638. }
  28639. reusableInputIndex = 0;
  28640. }
  28641. for (int j = 0; j < sourceNodes.size(); ++j)
  28642. {
  28643. if (j != reusableInputIndex)
  28644. {
  28645. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28646. sourceOutputChans.getUnchecked(j));
  28647. if (srcIndex >= 0)
  28648. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28649. }
  28650. }
  28651. }
  28652. jassert (bufIndex >= 0);
  28653. audioChannelsToUse.add (bufIndex);
  28654. if (inputChan < numOuts)
  28655. markBufferAsContaining (bufIndex, node->id, inputChan);
  28656. }
  28657. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28658. {
  28659. const int bufIndex = getFreeBuffer (false);
  28660. jassert (bufIndex != 0);
  28661. audioChannelsToUse.add (bufIndex);
  28662. markBufferAsContaining (bufIndex, node->id, outputChan);
  28663. }
  28664. // Now the same thing for midi..
  28665. Array <int> midiSourceNodes;
  28666. for (int i = graph.getNumConnections(); --i >= 0;)
  28667. {
  28668. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28669. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28670. midiSourceNodes.add (c->sourceNodeId);
  28671. }
  28672. if (midiSourceNodes.size() == 0)
  28673. {
  28674. // No midi inputs..
  28675. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28676. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28677. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28678. }
  28679. else if (midiSourceNodes.size() == 1)
  28680. {
  28681. // One midi input..
  28682. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28683. AudioProcessorGraph::midiChannelIndex);
  28684. if (midiBufferToUse >= 0)
  28685. {
  28686. if (isBufferNeededLater (ourRenderingIndex,
  28687. AudioProcessorGraph::midiChannelIndex,
  28688. midiSourceNodes.getUnchecked(0),
  28689. AudioProcessorGraph::midiChannelIndex))
  28690. {
  28691. // can't mess up this channel because it's needed later by another node, so we
  28692. // need to use a copy of it..
  28693. const int newFreeBuffer = getFreeBuffer (true);
  28694. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28695. midiBufferToUse = newFreeBuffer;
  28696. }
  28697. }
  28698. else
  28699. {
  28700. // probably a feedback loop, so just use an empty one..
  28701. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28702. }
  28703. }
  28704. else
  28705. {
  28706. // More than one midi input being mixed..
  28707. int reusableInputIndex = -1;
  28708. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28709. {
  28710. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28711. AudioProcessorGraph::midiChannelIndex);
  28712. if (sourceBufIndex >= 0
  28713. && ! isBufferNeededLater (ourRenderingIndex,
  28714. AudioProcessorGraph::midiChannelIndex,
  28715. midiSourceNodes.getUnchecked(i),
  28716. AudioProcessorGraph::midiChannelIndex))
  28717. {
  28718. // we've found one of our input buffers that can be re-used..
  28719. reusableInputIndex = i;
  28720. midiBufferToUse = sourceBufIndex;
  28721. break;
  28722. }
  28723. }
  28724. if (reusableInputIndex < 0)
  28725. {
  28726. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28727. midiBufferToUse = getFreeBuffer (true);
  28728. jassert (midiBufferToUse >= 0);
  28729. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28730. AudioProcessorGraph::midiChannelIndex);
  28731. if (srcIndex >= 0)
  28732. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28733. else
  28734. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28735. reusableInputIndex = 0;
  28736. }
  28737. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28738. {
  28739. if (j != reusableInputIndex)
  28740. {
  28741. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28742. AudioProcessorGraph::midiChannelIndex);
  28743. if (srcIndex >= 0)
  28744. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28745. }
  28746. }
  28747. }
  28748. if (node->processor->producesMidi())
  28749. markBufferAsContaining (midiBufferToUse, node->id,
  28750. AudioProcessorGraph::midiChannelIndex);
  28751. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28752. totalChans, midiBufferToUse));
  28753. }
  28754. int getFreeBuffer (const bool forMidi)
  28755. {
  28756. if (forMidi)
  28757. {
  28758. for (int i = 1; i < midiNodeIds.size(); ++i)
  28759. if (midiNodeIds.getUnchecked(i) < 0)
  28760. return i;
  28761. midiNodeIds.add (-1);
  28762. return midiNodeIds.size() - 1;
  28763. }
  28764. else
  28765. {
  28766. for (int i = 1; i < nodeIds.size(); ++i)
  28767. if (nodeIds.getUnchecked(i) < 0)
  28768. return i;
  28769. nodeIds.add (-1);
  28770. channels.add (0);
  28771. return nodeIds.size() - 1;
  28772. }
  28773. }
  28774. int getReadOnlyEmptyBuffer() const
  28775. {
  28776. return 0;
  28777. }
  28778. int getBufferContaining (const int nodeId, const int outputChannel) const
  28779. {
  28780. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28781. {
  28782. for (int i = midiNodeIds.size(); --i >= 0;)
  28783. if (midiNodeIds.getUnchecked(i) == nodeId)
  28784. return i;
  28785. }
  28786. else
  28787. {
  28788. for (int i = nodeIds.size(); --i >= 0;)
  28789. if (nodeIds.getUnchecked(i) == nodeId
  28790. && channels.getUnchecked(i) == outputChannel)
  28791. return i;
  28792. }
  28793. return -1;
  28794. }
  28795. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28796. {
  28797. int i;
  28798. for (i = 0; i < nodeIds.size(); ++i)
  28799. {
  28800. if (nodeIds.getUnchecked(i) >= 0
  28801. && ! isBufferNeededLater (stepIndex, -1,
  28802. nodeIds.getUnchecked(i),
  28803. channels.getUnchecked(i)))
  28804. {
  28805. nodeIds.set (i, -1);
  28806. }
  28807. }
  28808. for (i = 0; i < midiNodeIds.size(); ++i)
  28809. {
  28810. if (midiNodeIds.getUnchecked(i) >= 0
  28811. && ! isBufferNeededLater (stepIndex, -1,
  28812. midiNodeIds.getUnchecked(i),
  28813. AudioProcessorGraph::midiChannelIndex))
  28814. {
  28815. midiNodeIds.set (i, -1);
  28816. }
  28817. }
  28818. }
  28819. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28820. int inputChannelOfIndexToIgnore,
  28821. const int nodeId,
  28822. const int outputChanIndex) const
  28823. {
  28824. while (stepIndexToSearchFrom < orderedNodes.size())
  28825. {
  28826. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28827. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28828. {
  28829. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28830. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28831. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28832. return true;
  28833. }
  28834. else
  28835. {
  28836. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28837. if (i != inputChannelOfIndexToIgnore
  28838. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28839. node->id, i) != 0)
  28840. return true;
  28841. }
  28842. inputChannelOfIndexToIgnore = -1;
  28843. ++stepIndexToSearchFrom;
  28844. }
  28845. return false;
  28846. }
  28847. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28848. {
  28849. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28850. {
  28851. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28852. midiNodeIds.set (bufferNum, nodeId);
  28853. }
  28854. else
  28855. {
  28856. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28857. nodeIds.set (bufferNum, nodeId);
  28858. channels.set (bufferNum, outputIndex);
  28859. }
  28860. }
  28861. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28862. const RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28863. };
  28864. }
  28865. void AudioProcessorGraph::clearRenderingSequence()
  28866. {
  28867. const ScopedLock sl (renderLock);
  28868. for (int i = renderingOps.size(); --i >= 0;)
  28869. {
  28870. GraphRenderingOps::AudioGraphRenderingOp* const r
  28871. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28872. renderingOps.remove (i);
  28873. delete r;
  28874. }
  28875. }
  28876. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28877. const uint32 possibleDestinationId,
  28878. const int recursionCheck) const
  28879. {
  28880. if (recursionCheck > 0)
  28881. {
  28882. for (int i = connections.size(); --i >= 0;)
  28883. {
  28884. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28885. if (c->destNodeId == possibleDestinationId
  28886. && (c->sourceNodeId == possibleInputId
  28887. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28888. return true;
  28889. }
  28890. }
  28891. return false;
  28892. }
  28893. void AudioProcessorGraph::buildRenderingSequence()
  28894. {
  28895. VoidArray newRenderingOps;
  28896. int numRenderingBuffersNeeded = 2;
  28897. int numMidiBuffersNeeded = 1;
  28898. {
  28899. MessageManagerLock mml;
  28900. VoidArray orderedNodes;
  28901. int i;
  28902. for (i = 0; i < nodes.size(); ++i)
  28903. {
  28904. Node* const node = nodes.getUnchecked(i);
  28905. node->prepare (getSampleRate(), getBlockSize(), this);
  28906. int j = 0;
  28907. for (; j < orderedNodes.size(); ++j)
  28908. if (isAnInputTo (node->id,
  28909. ((Node*) orderedNodes.getUnchecked (j))->id,
  28910. nodes.size() + 1))
  28911. break;
  28912. orderedNodes.insert (j, node);
  28913. }
  28914. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28915. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28916. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28917. }
  28918. VoidArray oldRenderingOps (renderingOps);
  28919. {
  28920. // swap over to the new rendering sequence..
  28921. const ScopedLock sl (renderLock);
  28922. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28923. renderingBuffers.clear();
  28924. for (int i = midiBuffers.size(); --i >= 0;)
  28925. midiBuffers.getUnchecked(i)->clear();
  28926. while (midiBuffers.size() < numMidiBuffersNeeded)
  28927. midiBuffers.add (new MidiBuffer());
  28928. renderingOps = newRenderingOps;
  28929. }
  28930. for (int i = oldRenderingOps.size(); --i >= 0;)
  28931. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28932. }
  28933. void AudioProcessorGraph::handleAsyncUpdate()
  28934. {
  28935. buildRenderingSequence();
  28936. }
  28937. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28938. {
  28939. currentAudioInputBuffer = 0;
  28940. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28941. currentMidiInputBuffer = 0;
  28942. currentMidiOutputBuffer.clear();
  28943. clearRenderingSequence();
  28944. buildRenderingSequence();
  28945. }
  28946. void AudioProcessorGraph::releaseResources()
  28947. {
  28948. for (int i = 0; i < nodes.size(); ++i)
  28949. nodes.getUnchecked(i)->unprepare();
  28950. renderingBuffers.setSize (1, 1);
  28951. midiBuffers.clear();
  28952. currentAudioInputBuffer = 0;
  28953. currentAudioOutputBuffer.setSize (1, 1);
  28954. currentMidiInputBuffer = 0;
  28955. currentMidiOutputBuffer.clear();
  28956. }
  28957. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28958. {
  28959. const int numSamples = buffer.getNumSamples();
  28960. const ScopedLock sl (renderLock);
  28961. currentAudioInputBuffer = &buffer;
  28962. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28963. currentAudioOutputBuffer.clear();
  28964. currentMidiInputBuffer = &midiMessages;
  28965. currentMidiOutputBuffer.clear();
  28966. int i;
  28967. for (i = 0; i < renderingOps.size(); ++i)
  28968. {
  28969. GraphRenderingOps::AudioGraphRenderingOp* const op
  28970. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28971. op->perform (renderingBuffers, midiBuffers, numSamples);
  28972. }
  28973. for (i = 0; i < buffer.getNumChannels(); ++i)
  28974. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28975. midiMessages.clear();
  28976. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28977. }
  28978. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28979. {
  28980. return "Input " + String (channelIndex + 1);
  28981. }
  28982. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28983. {
  28984. return "Output " + String (channelIndex + 1);
  28985. }
  28986. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28987. {
  28988. return true;
  28989. }
  28990. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28991. {
  28992. return true;
  28993. }
  28994. bool AudioProcessorGraph::acceptsMidi() const
  28995. {
  28996. return true;
  28997. }
  28998. bool AudioProcessorGraph::producesMidi() const
  28999. {
  29000. return true;
  29001. }
  29002. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  29003. {
  29004. }
  29005. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  29006. {
  29007. }
  29008. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  29009. : type (type_),
  29010. graph (0)
  29011. {
  29012. }
  29013. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  29014. {
  29015. }
  29016. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  29017. {
  29018. switch (type)
  29019. {
  29020. case audioOutputNode:
  29021. return "Audio Output";
  29022. case audioInputNode:
  29023. return "Audio Input";
  29024. case midiOutputNode:
  29025. return "Midi Output";
  29026. case midiInputNode:
  29027. return "Midi Input";
  29028. default:
  29029. break;
  29030. }
  29031. return String::empty;
  29032. }
  29033. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  29034. {
  29035. d.name = getName();
  29036. d.uid = d.name.hashCode();
  29037. d.category = "I/O devices";
  29038. d.pluginFormatName = "Internal";
  29039. d.manufacturerName = "Raw Material Software";
  29040. d.version = "1.0";
  29041. d.isInstrument = false;
  29042. d.numInputChannels = getNumInputChannels();
  29043. if (type == audioOutputNode && graph != 0)
  29044. d.numInputChannels = graph->getNumInputChannels();
  29045. d.numOutputChannels = getNumOutputChannels();
  29046. if (type == audioInputNode && graph != 0)
  29047. d.numOutputChannels = graph->getNumOutputChannels();
  29048. }
  29049. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  29050. {
  29051. jassert (graph != 0);
  29052. }
  29053. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  29054. {
  29055. }
  29056. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  29057. MidiBuffer& midiMessages)
  29058. {
  29059. jassert (graph != 0);
  29060. switch (type)
  29061. {
  29062. case audioOutputNode:
  29063. {
  29064. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  29065. buffer.getNumChannels()); --i >= 0;)
  29066. {
  29067. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  29068. }
  29069. break;
  29070. }
  29071. case audioInputNode:
  29072. {
  29073. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  29074. buffer.getNumChannels()); --i >= 0;)
  29075. {
  29076. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  29077. }
  29078. break;
  29079. }
  29080. case midiOutputNode:
  29081. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  29082. break;
  29083. case midiInputNode:
  29084. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  29085. break;
  29086. default:
  29087. break;
  29088. }
  29089. }
  29090. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  29091. {
  29092. return type == midiOutputNode;
  29093. }
  29094. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  29095. {
  29096. return type == midiInputNode;
  29097. }
  29098. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  29099. {
  29100. switch (type)
  29101. {
  29102. case audioOutputNode:
  29103. return "Output " + String (channelIndex + 1);
  29104. case midiOutputNode:
  29105. return "Midi Output";
  29106. default:
  29107. break;
  29108. }
  29109. return String::empty;
  29110. }
  29111. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  29112. {
  29113. switch (type)
  29114. {
  29115. case audioInputNode:
  29116. return "Input " + String (channelIndex + 1);
  29117. case midiInputNode:
  29118. return "Midi Input";
  29119. default:
  29120. break;
  29121. }
  29122. return String::empty;
  29123. }
  29124. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  29125. {
  29126. return type == audioInputNode || type == audioOutputNode;
  29127. }
  29128. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  29129. {
  29130. return isInputChannelStereoPair (index);
  29131. }
  29132. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  29133. {
  29134. return type == audioInputNode || type == midiInputNode;
  29135. }
  29136. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  29137. {
  29138. return type == audioOutputNode || type == midiOutputNode;
  29139. }
  29140. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  29141. {
  29142. return 0;
  29143. }
  29144. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  29145. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  29146. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  29147. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  29148. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  29149. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  29150. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  29151. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  29152. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  29153. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  29154. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  29155. {
  29156. }
  29157. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  29158. {
  29159. }
  29160. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  29161. {
  29162. graph = newGraph;
  29163. if (graph != 0)
  29164. {
  29165. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  29166. type == audioInputNode ? graph->getNumInputChannels() : 0,
  29167. getSampleRate(),
  29168. getBlockSize());
  29169. updateHostDisplay();
  29170. }
  29171. }
  29172. END_JUCE_NAMESPACE
  29173. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  29174. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29175. BEGIN_JUCE_NAMESPACE
  29176. AudioProcessorPlayer::AudioProcessorPlayer()
  29177. : processor (0),
  29178. sampleRate (0),
  29179. blockSize (0),
  29180. isPrepared (false),
  29181. numInputChans (0),
  29182. numOutputChans (0),
  29183. tempBuffer (1, 1)
  29184. {
  29185. }
  29186. AudioProcessorPlayer::~AudioProcessorPlayer()
  29187. {
  29188. setProcessor (0);
  29189. }
  29190. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  29191. {
  29192. if (processor != processorToPlay)
  29193. {
  29194. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  29195. {
  29196. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  29197. sampleRate, blockSize);
  29198. processorToPlay->prepareToPlay (sampleRate, blockSize);
  29199. }
  29200. lock.enter();
  29201. AudioProcessor* const oldOne = isPrepared ? processor : 0;
  29202. processor = processorToPlay;
  29203. isPrepared = true;
  29204. lock.exit();
  29205. if (oldOne != 0)
  29206. oldOne->releaseResources();
  29207. }
  29208. }
  29209. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  29210. int numInputChannels,
  29211. float** outputChannelData,
  29212. int numOutputChannels,
  29213. int numSamples)
  29214. {
  29215. // these should have been prepared by audioDeviceAboutToStart()...
  29216. jassert (sampleRate > 0 && blockSize > 0);
  29217. incomingMidi.clear();
  29218. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  29219. int i, totalNumChans = 0;
  29220. if (numInputChannels > numOutputChannels)
  29221. {
  29222. // if there aren't enough output channels for the number of
  29223. // inputs, we need to create some temporary extra ones (can't
  29224. // use the input data in case it gets written to)
  29225. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  29226. false, false, true);
  29227. for (i = 0; i < numOutputChannels; ++i)
  29228. {
  29229. channels[totalNumChans] = outputChannelData[i];
  29230. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29231. ++totalNumChans;
  29232. }
  29233. for (i = numOutputChannels; i < numInputChannels; ++i)
  29234. {
  29235. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  29236. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29237. ++totalNumChans;
  29238. }
  29239. }
  29240. else
  29241. {
  29242. for (i = 0; i < numInputChannels; ++i)
  29243. {
  29244. channels[totalNumChans] = outputChannelData[i];
  29245. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29246. ++totalNumChans;
  29247. }
  29248. for (i = numInputChannels; i < numOutputChannels; ++i)
  29249. {
  29250. channels[totalNumChans] = outputChannelData[i];
  29251. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  29252. ++totalNumChans;
  29253. }
  29254. }
  29255. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  29256. const ScopedLock sl (lock);
  29257. if (processor != 0)
  29258. processor->processBlock (buffer, incomingMidi);
  29259. }
  29260. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  29261. {
  29262. const ScopedLock sl (lock);
  29263. sampleRate = device->getCurrentSampleRate();
  29264. blockSize = device->getCurrentBufferSizeSamples();
  29265. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  29266. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  29267. messageCollector.reset (sampleRate);
  29268. zeromem (channels, sizeof (channels));
  29269. if (processor != 0)
  29270. {
  29271. if (isPrepared)
  29272. processor->releaseResources();
  29273. AudioProcessor* const oldProcessor = processor;
  29274. setProcessor (0);
  29275. setProcessor (oldProcessor);
  29276. }
  29277. }
  29278. void AudioProcessorPlayer::audioDeviceStopped()
  29279. {
  29280. const ScopedLock sl (lock);
  29281. if (processor != 0 && isPrepared)
  29282. processor->releaseResources();
  29283. sampleRate = 0.0;
  29284. blockSize = 0;
  29285. isPrepared = false;
  29286. tempBuffer.setSize (1, 1);
  29287. }
  29288. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  29289. {
  29290. messageCollector.addMessageToQueue (message);
  29291. }
  29292. END_JUCE_NAMESPACE
  29293. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29294. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29295. BEGIN_JUCE_NAMESPACE
  29296. class ProcessorParameterPropertyComp : public PropertyComponent,
  29297. public AudioProcessorListener,
  29298. public AsyncUpdater
  29299. {
  29300. public:
  29301. ProcessorParameterPropertyComp (const String& name,
  29302. AudioProcessor* const owner_,
  29303. const int index_)
  29304. : PropertyComponent (name),
  29305. owner (owner_),
  29306. index (index_)
  29307. {
  29308. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29309. owner_->addListener (this);
  29310. }
  29311. ~ProcessorParameterPropertyComp()
  29312. {
  29313. owner->removeListener (this);
  29314. deleteAllChildren();
  29315. }
  29316. void refresh()
  29317. {
  29318. slider->setValue (owner->getParameter (index), false);
  29319. }
  29320. void audioProcessorChanged (AudioProcessor*) {}
  29321. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29322. {
  29323. if (parameterIndex == index)
  29324. triggerAsyncUpdate();
  29325. }
  29326. void handleAsyncUpdate()
  29327. {
  29328. refresh();
  29329. }
  29330. juce_UseDebuggingNewOperator
  29331. private:
  29332. AudioProcessor* const owner;
  29333. const int index;
  29334. Slider* slider;
  29335. class ParamSlider : public Slider
  29336. {
  29337. public:
  29338. ParamSlider (AudioProcessor* const owner_, const int index_)
  29339. : Slider (String::empty),
  29340. owner (owner_),
  29341. index (index_)
  29342. {
  29343. setRange (0.0, 1.0, 0.0);
  29344. setSliderStyle (Slider::LinearBar);
  29345. setTextBoxIsEditable (false);
  29346. setScrollWheelEnabled (false);
  29347. }
  29348. ~ParamSlider()
  29349. {
  29350. }
  29351. void valueChanged()
  29352. {
  29353. const float newVal = (float) getValue();
  29354. if (owner->getParameter (index) != newVal)
  29355. owner->setParameter (index, newVal);
  29356. }
  29357. const String getTextFromValue (double /*value*/)
  29358. {
  29359. return owner->getParameterText (index);
  29360. }
  29361. juce_UseDebuggingNewOperator
  29362. private:
  29363. AudioProcessor* const owner;
  29364. const int index;
  29365. ParamSlider (const ParamSlider&);
  29366. const ParamSlider& operator= (const ParamSlider&);
  29367. };
  29368. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29369. const ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29370. };
  29371. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29372. : AudioProcessorEditor (owner_)
  29373. {
  29374. setOpaque (true);
  29375. addAndMakeVisible (panel = new PropertyPanel());
  29376. Array <PropertyComponent*> params;
  29377. const int numParams = owner_->getNumParameters();
  29378. int totalHeight = 0;
  29379. for (int i = 0; i < numParams; ++i)
  29380. {
  29381. String name (owner_->getParameterName (i));
  29382. if (name.trim().isEmpty())
  29383. name = "Unnamed";
  29384. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29385. params.add (pc);
  29386. totalHeight += pc->getPreferredHeight();
  29387. }
  29388. panel->addProperties (params);
  29389. setSize (400, jlimit (25, 400, totalHeight));
  29390. }
  29391. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29392. {
  29393. deleteAllChildren();
  29394. }
  29395. void GenericAudioProcessorEditor::paint (Graphics& g)
  29396. {
  29397. g.fillAll (Colours::white);
  29398. }
  29399. void GenericAudioProcessorEditor::resized()
  29400. {
  29401. panel->setSize (getWidth(), getHeight());
  29402. }
  29403. END_JUCE_NAMESPACE
  29404. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29405. /*** Start of inlined file: juce_Sampler.cpp ***/
  29406. BEGIN_JUCE_NAMESPACE
  29407. SamplerSound::SamplerSound (const String& name_,
  29408. AudioFormatReader& source,
  29409. const BitArray& midiNotes_,
  29410. const int midiNoteForNormalPitch,
  29411. const double attackTimeSecs,
  29412. const double releaseTimeSecs,
  29413. const double maxSampleLengthSeconds)
  29414. : name (name_),
  29415. midiNotes (midiNotes_),
  29416. midiRootNote (midiNoteForNormalPitch)
  29417. {
  29418. sourceSampleRate = source.sampleRate;
  29419. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29420. {
  29421. length = 0;
  29422. attackSamples = 0;
  29423. releaseSamples = 0;
  29424. }
  29425. else
  29426. {
  29427. length = jmin ((int) source.lengthInSamples,
  29428. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29429. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29430. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29431. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29432. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29433. }
  29434. }
  29435. SamplerSound::~SamplerSound()
  29436. {
  29437. }
  29438. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29439. {
  29440. return midiNotes [midiNoteNumber];
  29441. }
  29442. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29443. {
  29444. return true;
  29445. }
  29446. SamplerVoice::SamplerVoice()
  29447. : pitchRatio (0.0),
  29448. sourceSamplePosition (0.0),
  29449. lgain (0.0f),
  29450. rgain (0.0f),
  29451. isInAttack (false),
  29452. isInRelease (false)
  29453. {
  29454. }
  29455. SamplerVoice::~SamplerVoice()
  29456. {
  29457. }
  29458. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29459. {
  29460. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29461. }
  29462. void SamplerVoice::startNote (const int midiNoteNumber,
  29463. const float velocity,
  29464. SynthesiserSound* s,
  29465. const int /*currentPitchWheelPosition*/)
  29466. {
  29467. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29468. jassert (sound != 0); // this object can only play SamplerSounds!
  29469. if (sound != 0)
  29470. {
  29471. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29472. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29473. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29474. sourceSamplePosition = 0.0;
  29475. lgain = velocity;
  29476. rgain = velocity;
  29477. isInAttack = (sound->attackSamples > 0);
  29478. isInRelease = false;
  29479. if (isInAttack)
  29480. {
  29481. attackReleaseLevel = 0.0f;
  29482. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29483. }
  29484. else
  29485. {
  29486. attackReleaseLevel = 1.0f;
  29487. attackDelta = 0.0f;
  29488. }
  29489. if (sound->releaseSamples > 0)
  29490. {
  29491. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29492. }
  29493. else
  29494. {
  29495. releaseDelta = 0.0f;
  29496. }
  29497. }
  29498. }
  29499. void SamplerVoice::stopNote (const bool allowTailOff)
  29500. {
  29501. if (allowTailOff)
  29502. {
  29503. isInAttack = false;
  29504. isInRelease = true;
  29505. }
  29506. else
  29507. {
  29508. clearCurrentNote();
  29509. }
  29510. }
  29511. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29512. {
  29513. }
  29514. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29515. const int /*newValue*/)
  29516. {
  29517. }
  29518. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29519. {
  29520. const SamplerSound* const playingSound = (SamplerSound*) (SynthesiserSound*) getCurrentlyPlayingSound();
  29521. if (playingSound != 0)
  29522. {
  29523. const float* const inL = playingSound->data->getSampleData (0, 0);
  29524. const float* const inR = playingSound->data->getNumChannels() > 1
  29525. ? playingSound->data->getSampleData (1, 0) : 0;
  29526. float* outL = outputBuffer.getSampleData (0, startSample);
  29527. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29528. while (--numSamples >= 0)
  29529. {
  29530. const int pos = (int) sourceSamplePosition;
  29531. const float alpha = (float) (sourceSamplePosition - pos);
  29532. const float invAlpha = 1.0f - alpha;
  29533. // just using a very simple linear interpolation here..
  29534. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29535. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29536. : l;
  29537. l *= lgain;
  29538. r *= rgain;
  29539. if (isInAttack)
  29540. {
  29541. l *= attackReleaseLevel;
  29542. r *= attackReleaseLevel;
  29543. attackReleaseLevel += attackDelta;
  29544. if (attackReleaseLevel >= 1.0f)
  29545. {
  29546. attackReleaseLevel = 1.0f;
  29547. isInAttack = false;
  29548. }
  29549. }
  29550. else if (isInRelease)
  29551. {
  29552. l *= attackReleaseLevel;
  29553. r *= attackReleaseLevel;
  29554. attackReleaseLevel += releaseDelta;
  29555. if (attackReleaseLevel <= 0.0f)
  29556. {
  29557. stopNote (false);
  29558. break;
  29559. }
  29560. }
  29561. if (outR != 0)
  29562. {
  29563. *outL++ += l;
  29564. *outR++ += r;
  29565. }
  29566. else
  29567. {
  29568. *outL++ += (l + r) * 0.5f;
  29569. }
  29570. sourceSamplePosition += pitchRatio;
  29571. if (sourceSamplePosition > playingSound->length)
  29572. {
  29573. stopNote (false);
  29574. break;
  29575. }
  29576. }
  29577. }
  29578. }
  29579. END_JUCE_NAMESPACE
  29580. /*** End of inlined file: juce_Sampler.cpp ***/
  29581. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29582. BEGIN_JUCE_NAMESPACE
  29583. SynthesiserSound::SynthesiserSound()
  29584. {
  29585. }
  29586. SynthesiserSound::~SynthesiserSound()
  29587. {
  29588. }
  29589. SynthesiserVoice::SynthesiserVoice()
  29590. : currentSampleRate (44100.0),
  29591. currentlyPlayingNote (-1),
  29592. noteOnTime (0),
  29593. currentlyPlayingSound (0)
  29594. {
  29595. }
  29596. SynthesiserVoice::~SynthesiserVoice()
  29597. {
  29598. }
  29599. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29600. {
  29601. return currentlyPlayingSound != 0
  29602. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29603. }
  29604. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29605. {
  29606. currentSampleRate = newRate;
  29607. }
  29608. void SynthesiserVoice::clearCurrentNote()
  29609. {
  29610. currentlyPlayingNote = -1;
  29611. currentlyPlayingSound = 0;
  29612. }
  29613. Synthesiser::Synthesiser()
  29614. : sampleRate (0),
  29615. lastNoteOnCounter (0),
  29616. shouldStealNotes (true)
  29617. {
  29618. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29619. lastPitchWheelValues[i] = 0x2000;
  29620. }
  29621. Synthesiser::~Synthesiser()
  29622. {
  29623. }
  29624. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29625. {
  29626. const ScopedLock sl (lock);
  29627. return voices [index];
  29628. }
  29629. void Synthesiser::clearVoices()
  29630. {
  29631. const ScopedLock sl (lock);
  29632. voices.clear();
  29633. }
  29634. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29635. {
  29636. const ScopedLock sl (lock);
  29637. voices.add (newVoice);
  29638. }
  29639. void Synthesiser::removeVoice (const int index)
  29640. {
  29641. const ScopedLock sl (lock);
  29642. voices.remove (index);
  29643. }
  29644. void Synthesiser::clearSounds()
  29645. {
  29646. const ScopedLock sl (lock);
  29647. sounds.clear();
  29648. }
  29649. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29650. {
  29651. const ScopedLock sl (lock);
  29652. sounds.add (newSound);
  29653. }
  29654. void Synthesiser::removeSound (const int index)
  29655. {
  29656. const ScopedLock sl (lock);
  29657. sounds.remove (index);
  29658. }
  29659. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29660. {
  29661. shouldStealNotes = shouldStealNotes_;
  29662. }
  29663. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29664. {
  29665. if (sampleRate != newRate)
  29666. {
  29667. const ScopedLock sl (lock);
  29668. allNotesOff (0, false);
  29669. sampleRate = newRate;
  29670. for (int i = voices.size(); --i >= 0;)
  29671. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29672. }
  29673. }
  29674. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29675. const MidiBuffer& midiData,
  29676. int startSample,
  29677. int numSamples)
  29678. {
  29679. // must set the sample rate before using this!
  29680. jassert (sampleRate != 0);
  29681. const ScopedLock sl (lock);
  29682. MidiBuffer::Iterator midiIterator (midiData);
  29683. midiIterator.setNextSamplePosition (startSample);
  29684. MidiMessage m (0xf4, 0.0);
  29685. while (numSamples > 0)
  29686. {
  29687. int midiEventPos;
  29688. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29689. && midiEventPos < startSample + numSamples;
  29690. const int numThisTime = useEvent ? midiEventPos - startSample
  29691. : numSamples;
  29692. if (numThisTime > 0)
  29693. {
  29694. for (int i = voices.size(); --i >= 0;)
  29695. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29696. }
  29697. if (useEvent)
  29698. {
  29699. if (m.isNoteOn())
  29700. {
  29701. const int channel = m.getChannel();
  29702. noteOn (channel,
  29703. m.getNoteNumber(),
  29704. m.getFloatVelocity());
  29705. }
  29706. else if (m.isNoteOff())
  29707. {
  29708. noteOff (m.getChannel(),
  29709. m.getNoteNumber(),
  29710. true);
  29711. }
  29712. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29713. {
  29714. allNotesOff (m.getChannel(), true);
  29715. }
  29716. else if (m.isPitchWheel())
  29717. {
  29718. const int channel = m.getChannel();
  29719. const int wheelPos = m.getPitchWheelValue();
  29720. lastPitchWheelValues [channel - 1] = wheelPos;
  29721. handlePitchWheel (channel, wheelPos);
  29722. }
  29723. else if (m.isController())
  29724. {
  29725. handleController (m.getChannel(),
  29726. m.getControllerNumber(),
  29727. m.getControllerValue());
  29728. }
  29729. }
  29730. startSample += numThisTime;
  29731. numSamples -= numThisTime;
  29732. }
  29733. }
  29734. void Synthesiser::noteOn (const int midiChannel,
  29735. const int midiNoteNumber,
  29736. const float velocity)
  29737. {
  29738. const ScopedLock sl (lock);
  29739. for (int i = sounds.size(); --i >= 0;)
  29740. {
  29741. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29742. if (sound->appliesToNote (midiNoteNumber)
  29743. && sound->appliesToChannel (midiChannel))
  29744. {
  29745. startVoice (findFreeVoice (sound, shouldStealNotes),
  29746. sound, midiChannel, midiNoteNumber, velocity);
  29747. }
  29748. }
  29749. }
  29750. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29751. SynthesiserSound* const sound,
  29752. const int midiChannel,
  29753. const int midiNoteNumber,
  29754. const float velocity)
  29755. {
  29756. if (voice != 0 && sound != 0)
  29757. {
  29758. if (voice->currentlyPlayingSound != 0)
  29759. voice->stopNote (false);
  29760. voice->startNote (midiNoteNumber,
  29761. velocity,
  29762. sound,
  29763. lastPitchWheelValues [midiChannel - 1]);
  29764. voice->currentlyPlayingNote = midiNoteNumber;
  29765. voice->noteOnTime = ++lastNoteOnCounter;
  29766. voice->currentlyPlayingSound = sound;
  29767. }
  29768. }
  29769. void Synthesiser::noteOff (const int midiChannel,
  29770. const int midiNoteNumber,
  29771. const bool allowTailOff)
  29772. {
  29773. const ScopedLock sl (lock);
  29774. for (int i = voices.size(); --i >= 0;)
  29775. {
  29776. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29777. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29778. {
  29779. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29780. if (sound != 0
  29781. && sound->appliesToNote (midiNoteNumber)
  29782. && sound->appliesToChannel (midiChannel))
  29783. {
  29784. voice->stopNote (allowTailOff);
  29785. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29786. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29787. }
  29788. }
  29789. }
  29790. }
  29791. void Synthesiser::allNotesOff (const int midiChannel,
  29792. const bool allowTailOff)
  29793. {
  29794. const ScopedLock sl (lock);
  29795. for (int i = voices.size(); --i >= 0;)
  29796. {
  29797. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29798. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29799. voice->stopNote (allowTailOff);
  29800. }
  29801. }
  29802. void Synthesiser::handlePitchWheel (const int midiChannel,
  29803. const int wheelValue)
  29804. {
  29805. const ScopedLock sl (lock);
  29806. for (int i = voices.size(); --i >= 0;)
  29807. {
  29808. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29809. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29810. {
  29811. voice->pitchWheelMoved (wheelValue);
  29812. }
  29813. }
  29814. }
  29815. void Synthesiser::handleController (const int midiChannel,
  29816. const int controllerNumber,
  29817. const int controllerValue)
  29818. {
  29819. const ScopedLock sl (lock);
  29820. for (int i = voices.size(); --i >= 0;)
  29821. {
  29822. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29823. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29824. voice->controllerMoved (controllerNumber, controllerValue);
  29825. }
  29826. }
  29827. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29828. const bool stealIfNoneAvailable) const
  29829. {
  29830. const ScopedLock sl (lock);
  29831. for (int i = voices.size(); --i >= 0;)
  29832. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29833. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29834. return voices.getUnchecked (i);
  29835. if (stealIfNoneAvailable)
  29836. {
  29837. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29838. SynthesiserVoice* oldest = 0;
  29839. for (int i = voices.size(); --i >= 0;)
  29840. {
  29841. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29842. if (voice->canPlaySound (soundToPlay)
  29843. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29844. oldest = voice;
  29845. }
  29846. jassert (oldest != 0);
  29847. return oldest;
  29848. }
  29849. return 0;
  29850. }
  29851. END_JUCE_NAMESPACE
  29852. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29853. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29854. BEGIN_JUCE_NAMESPACE
  29855. ActionBroadcaster::ActionBroadcaster() throw()
  29856. {
  29857. // are you trying to create this object before or after juce has been intialised??
  29858. jassert (MessageManager::instance != 0);
  29859. }
  29860. ActionBroadcaster::~ActionBroadcaster()
  29861. {
  29862. // all event-based objects must be deleted BEFORE juce is shut down!
  29863. jassert (MessageManager::instance != 0);
  29864. }
  29865. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29866. {
  29867. actionListenerList.addActionListener (listener);
  29868. }
  29869. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29870. {
  29871. jassert (actionListenerList.isValidMessageListener());
  29872. if (actionListenerList.isValidMessageListener())
  29873. actionListenerList.removeActionListener (listener);
  29874. }
  29875. void ActionBroadcaster::removeAllActionListeners()
  29876. {
  29877. actionListenerList.removeAllActionListeners();
  29878. }
  29879. void ActionBroadcaster::sendActionMessage (const String& message) const
  29880. {
  29881. actionListenerList.sendActionMessage (message);
  29882. }
  29883. END_JUCE_NAMESPACE
  29884. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29885. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29886. BEGIN_JUCE_NAMESPACE
  29887. // special message of our own with a string in it
  29888. class ActionMessage : public Message
  29889. {
  29890. public:
  29891. const String message;
  29892. ActionMessage (const String& messageText,
  29893. void* const listener_) throw()
  29894. : message (messageText)
  29895. {
  29896. pointerParameter = listener_;
  29897. }
  29898. ~ActionMessage() throw()
  29899. {
  29900. }
  29901. private:
  29902. ActionMessage (const ActionMessage&);
  29903. const ActionMessage& operator= (const ActionMessage&);
  29904. };
  29905. ActionListenerList::ActionListenerList() throw()
  29906. {
  29907. }
  29908. ActionListenerList::~ActionListenerList() throw()
  29909. {
  29910. }
  29911. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29912. {
  29913. const ScopedLock sl (actionListenerLock_);
  29914. jassert (listener != 0);
  29915. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29916. if (listener != 0)
  29917. actionListeners_.add (listener);
  29918. }
  29919. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29920. {
  29921. const ScopedLock sl (actionListenerLock_);
  29922. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29923. actionListeners_.removeValue (listener);
  29924. }
  29925. void ActionListenerList::removeAllActionListeners() throw()
  29926. {
  29927. const ScopedLock sl (actionListenerLock_);
  29928. actionListeners_.clear();
  29929. }
  29930. void ActionListenerList::sendActionMessage (const String& message) const
  29931. {
  29932. const ScopedLock sl (actionListenerLock_);
  29933. for (int i = actionListeners_.size(); --i >= 0;)
  29934. {
  29935. postMessage (new ActionMessage (message,
  29936. (ActionListener*) actionListeners_.getUnchecked(i)));
  29937. }
  29938. }
  29939. void ActionListenerList::handleMessage (const Message& message)
  29940. {
  29941. const ActionMessage& am = (const ActionMessage&) message;
  29942. if (actionListeners_.contains (am.pointerParameter))
  29943. ((ActionListener*) am.pointerParameter)->actionListenerCallback (am.message);
  29944. }
  29945. END_JUCE_NAMESPACE
  29946. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29947. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29948. BEGIN_JUCE_NAMESPACE
  29949. AsyncUpdater::AsyncUpdater() throw()
  29950. : asyncMessagePending (false)
  29951. {
  29952. internalAsyncHandler.owner = this;
  29953. }
  29954. AsyncUpdater::~AsyncUpdater()
  29955. {
  29956. }
  29957. void AsyncUpdater::triggerAsyncUpdate() throw()
  29958. {
  29959. if (! asyncMessagePending)
  29960. {
  29961. asyncMessagePending = true;
  29962. internalAsyncHandler.postMessage (new Message());
  29963. }
  29964. }
  29965. void AsyncUpdater::cancelPendingUpdate() throw()
  29966. {
  29967. asyncMessagePending = false;
  29968. }
  29969. void AsyncUpdater::handleUpdateNowIfNeeded()
  29970. {
  29971. if (asyncMessagePending)
  29972. {
  29973. asyncMessagePending = false;
  29974. handleAsyncUpdate();
  29975. }
  29976. }
  29977. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29978. {
  29979. owner->handleUpdateNowIfNeeded();
  29980. }
  29981. END_JUCE_NAMESPACE
  29982. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29983. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29984. BEGIN_JUCE_NAMESPACE
  29985. ChangeBroadcaster::ChangeBroadcaster() throw()
  29986. {
  29987. // are you trying to create this object before or after juce has been intialised??
  29988. jassert (MessageManager::instance != 0);
  29989. }
  29990. ChangeBroadcaster::~ChangeBroadcaster()
  29991. {
  29992. // all event-based objects must be deleted BEFORE juce is shut down!
  29993. jassert (MessageManager::instance != 0);
  29994. }
  29995. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29996. {
  29997. changeListenerList.addChangeListener (listener);
  29998. }
  29999. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  30000. {
  30001. jassert (changeListenerList.isValidMessageListener());
  30002. if (changeListenerList.isValidMessageListener())
  30003. changeListenerList.removeChangeListener (listener);
  30004. }
  30005. void ChangeBroadcaster::removeAllChangeListeners() throw()
  30006. {
  30007. changeListenerList.removeAllChangeListeners();
  30008. }
  30009. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  30010. {
  30011. changeListenerList.sendChangeMessage (objectThatHasChanged);
  30012. }
  30013. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  30014. {
  30015. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  30016. }
  30017. void ChangeBroadcaster::dispatchPendingMessages()
  30018. {
  30019. changeListenerList.dispatchPendingMessages();
  30020. }
  30021. END_JUCE_NAMESPACE
  30022. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  30023. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  30024. BEGIN_JUCE_NAMESPACE
  30025. ChangeListenerList::ChangeListenerList() throw()
  30026. : lastChangedObject (0),
  30027. messagePending (false)
  30028. {
  30029. }
  30030. ChangeListenerList::~ChangeListenerList() throw()
  30031. {
  30032. }
  30033. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  30034. {
  30035. const ScopedLock sl (lock);
  30036. jassert (listener != 0);
  30037. if (listener != 0)
  30038. listeners.add (listener);
  30039. }
  30040. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  30041. {
  30042. const ScopedLock sl (lock);
  30043. listeners.removeValue (listener);
  30044. }
  30045. void ChangeListenerList::removeAllChangeListeners() throw()
  30046. {
  30047. const ScopedLock sl (lock);
  30048. listeners.clear();
  30049. }
  30050. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  30051. {
  30052. const ScopedLock sl (lock);
  30053. if ((! messagePending) && (listeners.size() > 0))
  30054. {
  30055. lastChangedObject = objectThatHasChanged;
  30056. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  30057. messagePending = true;
  30058. }
  30059. }
  30060. void ChangeListenerList::handleMessage (const Message& message)
  30061. {
  30062. sendSynchronousChangeMessage (message.pointerParameter);
  30063. }
  30064. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  30065. {
  30066. const ScopedLock sl (lock);
  30067. messagePending = false;
  30068. for (int i = listeners.size(); --i >= 0;)
  30069. {
  30070. ChangeListener* const l = (ChangeListener*) listeners.getUnchecked (i);
  30071. {
  30072. const ScopedUnlock tempUnlocker (lock);
  30073. l->changeListenerCallback (objectThatHasChanged);
  30074. }
  30075. i = jmin (i, listeners.size());
  30076. }
  30077. }
  30078. void ChangeListenerList::dispatchPendingMessages()
  30079. {
  30080. if (messagePending)
  30081. sendSynchronousChangeMessage (lastChangedObject);
  30082. }
  30083. END_JUCE_NAMESPACE
  30084. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  30085. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  30086. BEGIN_JUCE_NAMESPACE
  30087. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  30088. const uint32 magicMessageHeaderNumber)
  30089. : Thread ("Juce IPC connection"),
  30090. callbackConnectionState (false),
  30091. useMessageThread (callbacksOnMessageThread),
  30092. magicMessageHeader (magicMessageHeaderNumber),
  30093. pipeReceiveMessageTimeout (-1)
  30094. {
  30095. }
  30096. InterprocessConnection::~InterprocessConnection()
  30097. {
  30098. callbackConnectionState = false;
  30099. disconnect();
  30100. }
  30101. bool InterprocessConnection::connectToSocket (const String& hostName,
  30102. const int portNumber,
  30103. const int timeOutMillisecs)
  30104. {
  30105. disconnect();
  30106. const ScopedLock sl (pipeAndSocketLock);
  30107. socket = new StreamingSocket();
  30108. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  30109. {
  30110. connectionMadeInt();
  30111. startThread();
  30112. return true;
  30113. }
  30114. else
  30115. {
  30116. socket = 0;
  30117. return false;
  30118. }
  30119. }
  30120. bool InterprocessConnection::connectToPipe (const String& pipeName,
  30121. const int pipeReceiveMessageTimeoutMs)
  30122. {
  30123. disconnect();
  30124. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30125. if (newPipe->openExisting (pipeName))
  30126. {
  30127. const ScopedLock sl (pipeAndSocketLock);
  30128. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30129. initialiseWithPipe (newPipe.release());
  30130. return true;
  30131. }
  30132. return false;
  30133. }
  30134. bool InterprocessConnection::createPipe (const String& pipeName,
  30135. const int pipeReceiveMessageTimeoutMs)
  30136. {
  30137. disconnect();
  30138. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30139. if (newPipe->createNewPipe (pipeName))
  30140. {
  30141. const ScopedLock sl (pipeAndSocketLock);
  30142. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30143. initialiseWithPipe (newPipe.release());
  30144. return true;
  30145. }
  30146. return false;
  30147. }
  30148. void InterprocessConnection::disconnect()
  30149. {
  30150. if (socket != 0)
  30151. socket->close();
  30152. if (pipe != 0)
  30153. {
  30154. pipe->cancelPendingReads();
  30155. pipe->close();
  30156. }
  30157. stopThread (4000);
  30158. {
  30159. const ScopedLock sl (pipeAndSocketLock);
  30160. socket = 0;
  30161. pipe = 0;
  30162. }
  30163. connectionLostInt();
  30164. }
  30165. bool InterprocessConnection::isConnected() const
  30166. {
  30167. const ScopedLock sl (pipeAndSocketLock);
  30168. return ((socket != 0 && socket->isConnected())
  30169. || (pipe != 0 && pipe->isOpen()))
  30170. && isThreadRunning();
  30171. }
  30172. const String InterprocessConnection::getConnectedHostName() const
  30173. {
  30174. if (pipe != 0)
  30175. {
  30176. return "localhost";
  30177. }
  30178. else if (socket != 0)
  30179. {
  30180. if (! socket->isLocal())
  30181. return socket->getHostName();
  30182. return "localhost";
  30183. }
  30184. return String::empty;
  30185. }
  30186. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  30187. {
  30188. uint32 messageHeader[2];
  30189. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  30190. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  30191. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  30192. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  30193. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  30194. size_t bytesWritten = 0;
  30195. const ScopedLock sl (pipeAndSocketLock);
  30196. if (socket != 0)
  30197. {
  30198. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  30199. }
  30200. else if (pipe != 0)
  30201. {
  30202. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  30203. }
  30204. if (bytesWritten < 0)
  30205. {
  30206. // error..
  30207. return false;
  30208. }
  30209. return (bytesWritten == messageData.getSize());
  30210. }
  30211. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  30212. {
  30213. jassert (socket == 0);
  30214. socket = socket_;
  30215. connectionMadeInt();
  30216. startThread();
  30217. }
  30218. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  30219. {
  30220. jassert (pipe == 0);
  30221. pipe = pipe_;
  30222. connectionMadeInt();
  30223. startThread();
  30224. }
  30225. const int messageMagicNumber = 0xb734128b;
  30226. void InterprocessConnection::handleMessage (const Message& message)
  30227. {
  30228. if (message.intParameter1 == messageMagicNumber)
  30229. {
  30230. switch (message.intParameter2)
  30231. {
  30232. case 0:
  30233. {
  30234. ScopedPointer <MemoryBlock> data ((MemoryBlock*) message.pointerParameter);
  30235. messageReceived (*data);
  30236. break;
  30237. }
  30238. case 1:
  30239. connectionMade();
  30240. break;
  30241. case 2:
  30242. connectionLost();
  30243. break;
  30244. }
  30245. }
  30246. }
  30247. void InterprocessConnection::connectionMadeInt()
  30248. {
  30249. if (! callbackConnectionState)
  30250. {
  30251. callbackConnectionState = true;
  30252. if (useMessageThread)
  30253. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  30254. else
  30255. connectionMade();
  30256. }
  30257. }
  30258. void InterprocessConnection::connectionLostInt()
  30259. {
  30260. if (callbackConnectionState)
  30261. {
  30262. callbackConnectionState = false;
  30263. if (useMessageThread)
  30264. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  30265. else
  30266. connectionLost();
  30267. }
  30268. }
  30269. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  30270. {
  30271. jassert (callbackConnectionState);
  30272. if (useMessageThread)
  30273. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  30274. else
  30275. messageReceived (data);
  30276. }
  30277. bool InterprocessConnection::readNextMessageInt()
  30278. {
  30279. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  30280. uint32 messageHeader[2];
  30281. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  30282. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  30283. if (bytes == sizeof (messageHeader)
  30284. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  30285. {
  30286. const int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  30287. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  30288. {
  30289. MemoryBlock messageData (bytesInMessage, true);
  30290. int bytesRead = 0;
  30291. while (bytesRead < bytesInMessage)
  30292. {
  30293. if (threadShouldExit())
  30294. return false;
  30295. const int numThisTime = jmin (bytesInMessage, 65536);
  30296. const int bytesIn = (socket != 0) ? socket->read (((char*) messageData.getData()) + bytesRead, numThisTime, true)
  30297. : pipe->read (((char*) messageData.getData()) + bytesRead, numThisTime,
  30298. pipeReceiveMessageTimeout);
  30299. if (bytesIn <= 0)
  30300. break;
  30301. bytesRead += bytesIn;
  30302. }
  30303. if (bytesRead >= 0)
  30304. deliverDataInt (messageData);
  30305. }
  30306. }
  30307. else if (bytes < 0)
  30308. {
  30309. {
  30310. const ScopedLock sl (pipeAndSocketLock);
  30311. socket = 0;
  30312. }
  30313. connectionLostInt();
  30314. return false;
  30315. }
  30316. return true;
  30317. }
  30318. void InterprocessConnection::run()
  30319. {
  30320. while (! threadShouldExit())
  30321. {
  30322. if (socket != 0)
  30323. {
  30324. const int ready = socket->waitUntilReady (true, 0);
  30325. if (ready < 0)
  30326. {
  30327. {
  30328. const ScopedLock sl (pipeAndSocketLock);
  30329. socket = 0;
  30330. }
  30331. connectionLostInt();
  30332. break;
  30333. }
  30334. else if (ready > 0)
  30335. {
  30336. if (! readNextMessageInt())
  30337. break;
  30338. }
  30339. else
  30340. {
  30341. Thread::sleep (2);
  30342. }
  30343. }
  30344. else if (pipe != 0)
  30345. {
  30346. if (! pipe->isOpen())
  30347. {
  30348. {
  30349. const ScopedLock sl (pipeAndSocketLock);
  30350. pipe = 0;
  30351. }
  30352. connectionLostInt();
  30353. break;
  30354. }
  30355. else
  30356. {
  30357. if (! readNextMessageInt())
  30358. break;
  30359. }
  30360. }
  30361. else
  30362. {
  30363. break;
  30364. }
  30365. }
  30366. }
  30367. END_JUCE_NAMESPACE
  30368. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30369. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30370. BEGIN_JUCE_NAMESPACE
  30371. InterprocessConnectionServer::InterprocessConnectionServer()
  30372. : Thread ("Juce IPC server")
  30373. {
  30374. }
  30375. InterprocessConnectionServer::~InterprocessConnectionServer()
  30376. {
  30377. stop();
  30378. }
  30379. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30380. {
  30381. stop();
  30382. socket = new StreamingSocket();
  30383. if (socket->createListener (portNumber))
  30384. {
  30385. startThread();
  30386. return true;
  30387. }
  30388. socket = 0;
  30389. return false;
  30390. }
  30391. void InterprocessConnectionServer::stop()
  30392. {
  30393. signalThreadShouldExit();
  30394. if (socket != 0)
  30395. socket->close();
  30396. stopThread (4000);
  30397. socket = 0;
  30398. }
  30399. void InterprocessConnectionServer::run()
  30400. {
  30401. while ((! threadShouldExit()) && socket != 0)
  30402. {
  30403. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30404. if (clientSocket != 0)
  30405. {
  30406. InterprocessConnection* newConnection = createConnectionObject();
  30407. if (newConnection != 0)
  30408. newConnection->initialiseWithSocket (clientSocket.release());
  30409. }
  30410. }
  30411. }
  30412. END_JUCE_NAMESPACE
  30413. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30414. /*** Start of inlined file: juce_Message.cpp ***/
  30415. BEGIN_JUCE_NAMESPACE
  30416. Message::Message() throw()
  30417. {
  30418. }
  30419. Message::~Message() throw()
  30420. {
  30421. }
  30422. Message::Message (const int intParameter1_,
  30423. const int intParameter2_,
  30424. const int intParameter3_,
  30425. void* const pointerParameter_) throw()
  30426. : intParameter1 (intParameter1_),
  30427. intParameter2 (intParameter2_),
  30428. intParameter3 (intParameter3_),
  30429. pointerParameter (pointerParameter_)
  30430. {
  30431. }
  30432. END_JUCE_NAMESPACE
  30433. /*** End of inlined file: juce_Message.cpp ***/
  30434. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30435. BEGIN_JUCE_NAMESPACE
  30436. MessageListener::MessageListener() throw()
  30437. {
  30438. // are you trying to create a messagelistener before or after juce has been intialised??
  30439. jassert (MessageManager::instance != 0);
  30440. if (MessageManager::instance != 0)
  30441. MessageManager::instance->messageListeners.add (this);
  30442. }
  30443. MessageListener::~MessageListener()
  30444. {
  30445. if (MessageManager::instance != 0)
  30446. MessageManager::instance->messageListeners.removeValue (this);
  30447. }
  30448. void MessageListener::postMessage (Message* const message) const throw()
  30449. {
  30450. message->messageRecipient = const_cast <MessageListener*> (this);
  30451. if (MessageManager::instance == 0)
  30452. MessageManager::getInstance();
  30453. MessageManager::instance->postMessageToQueue (message);
  30454. }
  30455. bool MessageListener::isValidMessageListener() const throw()
  30456. {
  30457. return (MessageManager::instance != 0)
  30458. && MessageManager::instance->messageListeners.contains (this);
  30459. }
  30460. END_JUCE_NAMESPACE
  30461. /*** End of inlined file: juce_MessageListener.cpp ***/
  30462. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30463. BEGIN_JUCE_NAMESPACE
  30464. // platform-specific functions..
  30465. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30466. bool juce_postMessageToSystemQueue (void* message);
  30467. MessageManager* MessageManager::instance = 0;
  30468. static const int quitMessageId = 0xfffff321;
  30469. MessageManager::MessageManager() throw()
  30470. : quitMessagePosted (false),
  30471. quitMessageReceived (false),
  30472. threadWithLock (0)
  30473. {
  30474. messageThreadId = Thread::getCurrentThreadId();
  30475. }
  30476. MessageManager::~MessageManager() throw()
  30477. {
  30478. broadcastListeners = 0;
  30479. doPlatformSpecificShutdown();
  30480. jassert (instance == this);
  30481. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30482. }
  30483. MessageManager* MessageManager::getInstance() throw()
  30484. {
  30485. if (instance == 0)
  30486. {
  30487. instance = new MessageManager();
  30488. doPlatformSpecificInitialisation();
  30489. }
  30490. return instance;
  30491. }
  30492. void MessageManager::postMessageToQueue (Message* const message)
  30493. {
  30494. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30495. delete message;
  30496. }
  30497. CallbackMessage::CallbackMessage() throw() {}
  30498. CallbackMessage::~CallbackMessage() throw() {}
  30499. void CallbackMessage::post()
  30500. {
  30501. if (MessageManager::instance != 0)
  30502. MessageManager::instance->postCallbackMessage (this);
  30503. }
  30504. void MessageManager::postCallbackMessage (Message* const message)
  30505. {
  30506. message->messageRecipient = 0;
  30507. postMessageToQueue (message);
  30508. }
  30509. // not for public use..
  30510. void MessageManager::deliverMessage (void* message)
  30511. {
  30512. const ScopedPointer <Message> m ((Message*) message);
  30513. MessageListener* const recipient = m->messageRecipient;
  30514. JUCE_TRY
  30515. {
  30516. if (messageListeners.contains (recipient))
  30517. {
  30518. recipient->handleMessage (*m);
  30519. }
  30520. else if (recipient == 0)
  30521. {
  30522. if (m->intParameter1 == quitMessageId)
  30523. {
  30524. quitMessageReceived = true;
  30525. }
  30526. else
  30527. {
  30528. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> ((Message*) m);
  30529. if (cm != 0)
  30530. cm->messageCallback();
  30531. }
  30532. }
  30533. }
  30534. JUCE_CATCH_EXCEPTION
  30535. }
  30536. #if ! (JUCE_MAC || JUCE_IPHONE)
  30537. void MessageManager::runDispatchLoop()
  30538. {
  30539. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30540. runDispatchLoopUntil (-1);
  30541. }
  30542. void MessageManager::stopDispatchLoop()
  30543. {
  30544. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30545. m->messageRecipient = 0;
  30546. postMessageToQueue (m);
  30547. quitMessagePosted = true;
  30548. }
  30549. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30550. {
  30551. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30552. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30553. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30554. && ! quitMessageReceived)
  30555. {
  30556. JUCE_TRY
  30557. {
  30558. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30559. {
  30560. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30561. if (msToWait > 0)
  30562. Thread::sleep (jmin (5, msToWait));
  30563. }
  30564. }
  30565. JUCE_CATCH_EXCEPTION
  30566. }
  30567. return ! quitMessageReceived;
  30568. }
  30569. #endif
  30570. void MessageManager::deliverBroadcastMessage (const String& value)
  30571. {
  30572. if (broadcastListeners != 0)
  30573. broadcastListeners->sendActionMessage (value);
  30574. }
  30575. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30576. {
  30577. if (broadcastListeners == 0)
  30578. broadcastListeners = new ActionListenerList();
  30579. broadcastListeners->addActionListener (listener);
  30580. }
  30581. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30582. {
  30583. if (broadcastListeners != 0)
  30584. broadcastListeners->removeActionListener (listener);
  30585. }
  30586. bool MessageManager::isThisTheMessageThread() const throw()
  30587. {
  30588. return Thread::getCurrentThreadId() == messageThreadId;
  30589. }
  30590. void MessageManager::setCurrentMessageThread (const Thread::ThreadID threadId) throw()
  30591. {
  30592. messageThreadId = threadId;
  30593. }
  30594. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30595. {
  30596. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30597. return thisThread == messageThreadId || thisThread == threadWithLock;
  30598. }
  30599. class SharedLockingEvents : public ReferenceCountedObject
  30600. {
  30601. public:
  30602. SharedLockingEvents() throw() {}
  30603. ~SharedLockingEvents() {}
  30604. WaitableEvent lockedEvent, releaseEvent;
  30605. };
  30606. class MMLockMessage : public CallbackMessage
  30607. {
  30608. public:
  30609. MMLockMessage (SharedLockingEvents* const events_) throw()
  30610. : events (events_)
  30611. {}
  30612. ~MMLockMessage() throw() {}
  30613. ReferenceCountedObjectPtr <SharedLockingEvents> events;
  30614. void messageCallback()
  30615. {
  30616. events->lockedEvent.signal();
  30617. events->releaseEvent.wait();
  30618. }
  30619. juce_UseDebuggingNewOperator
  30620. MMLockMessage (const MMLockMessage&);
  30621. const MMLockMessage& operator= (const MMLockMessage&);
  30622. };
  30623. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30624. : locked (false),
  30625. needsUnlocking (false)
  30626. {
  30627. init (threadToCheck, 0);
  30628. }
  30629. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30630. : locked (false),
  30631. needsUnlocking (false)
  30632. {
  30633. init (0, jobToCheckForExitSignal);
  30634. }
  30635. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30636. {
  30637. if (MessageManager::instance != 0)
  30638. {
  30639. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30640. {
  30641. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30642. }
  30643. else
  30644. {
  30645. if (threadToCheck == 0 && job == 0)
  30646. {
  30647. MessageManager::instance->lockingLock.enter();
  30648. }
  30649. else
  30650. {
  30651. while (! MessageManager::instance->lockingLock.tryEnter())
  30652. {
  30653. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30654. || (job != 0 && job->shouldExit()))
  30655. return;
  30656. Thread::sleep (1);
  30657. }
  30658. }
  30659. SharedLockingEvents* const events = new SharedLockingEvents();
  30660. sharedEvents = events;
  30661. events->incReferenceCount();
  30662. (new MMLockMessage (events))->post();
  30663. while (! events->lockedEvent.wait (50))
  30664. {
  30665. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30666. || (job != 0 && job->shouldExit()))
  30667. {
  30668. events->releaseEvent.signal();
  30669. events->decReferenceCount();
  30670. MessageManager::instance->lockingLock.exit();
  30671. return;
  30672. }
  30673. }
  30674. jassert (MessageManager::instance->threadWithLock == 0);
  30675. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30676. locked = true;
  30677. needsUnlocking = true;
  30678. }
  30679. }
  30680. }
  30681. MessageManagerLock::~MessageManagerLock() throw()
  30682. {
  30683. if (needsUnlocking && MessageManager::instance != 0)
  30684. {
  30685. jassert (MessageManager::instance->currentThreadHasLockedMessageManager());
  30686. ((SharedLockingEvents*) sharedEvents)->releaseEvent.signal();
  30687. ((SharedLockingEvents*) sharedEvents)->decReferenceCount();
  30688. MessageManager::instance->threadWithLock = 0;
  30689. MessageManager::instance->lockingLock.exit();
  30690. }
  30691. }
  30692. END_JUCE_NAMESPACE
  30693. /*** End of inlined file: juce_MessageManager.cpp ***/
  30694. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30695. BEGIN_JUCE_NAMESPACE
  30696. class MultiTimer::MultiTimerCallback : public Timer
  30697. {
  30698. public:
  30699. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30700. : timerId (timerId_),
  30701. owner (owner_)
  30702. {
  30703. }
  30704. ~MultiTimerCallback()
  30705. {
  30706. }
  30707. void timerCallback()
  30708. {
  30709. owner.timerCallback (timerId);
  30710. }
  30711. const int timerId;
  30712. private:
  30713. MultiTimer& owner;
  30714. };
  30715. MultiTimer::MultiTimer() throw()
  30716. {
  30717. }
  30718. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30719. {
  30720. }
  30721. MultiTimer::~MultiTimer()
  30722. {
  30723. const ScopedLock sl (timerListLock);
  30724. timers.clear();
  30725. }
  30726. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30727. {
  30728. const ScopedLock sl (timerListLock);
  30729. for (int i = timers.size(); --i >= 0;)
  30730. {
  30731. MultiTimerCallback* const t = timers.getUnchecked(i);
  30732. if (t->timerId == timerId)
  30733. {
  30734. t->startTimer (intervalInMilliseconds);
  30735. return;
  30736. }
  30737. }
  30738. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30739. timers.add (newTimer);
  30740. newTimer->startTimer (intervalInMilliseconds);
  30741. }
  30742. void MultiTimer::stopTimer (const int timerId) throw()
  30743. {
  30744. const ScopedLock sl (timerListLock);
  30745. for (int i = timers.size(); --i >= 0;)
  30746. {
  30747. MultiTimerCallback* const t = timers.getUnchecked(i);
  30748. if (t->timerId == timerId)
  30749. t->stopTimer();
  30750. }
  30751. }
  30752. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30753. {
  30754. const ScopedLock sl (timerListLock);
  30755. for (int i = timers.size(); --i >= 0;)
  30756. {
  30757. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30758. if (t->timerId == timerId)
  30759. return t->isTimerRunning();
  30760. }
  30761. return false;
  30762. }
  30763. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30764. {
  30765. const ScopedLock sl (timerListLock);
  30766. for (int i = timers.size(); --i >= 0;)
  30767. {
  30768. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30769. if (t->timerId == timerId)
  30770. return t->getTimerInterval();
  30771. }
  30772. return 0;
  30773. }
  30774. END_JUCE_NAMESPACE
  30775. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30776. /*** Start of inlined file: juce_Timer.cpp ***/
  30777. BEGIN_JUCE_NAMESPACE
  30778. class InternalTimerThread : private Thread,
  30779. private MessageListener,
  30780. private DeletedAtShutdown,
  30781. private AsyncUpdater
  30782. {
  30783. public:
  30784. InternalTimerThread()
  30785. : Thread ("Juce Timer"),
  30786. firstTimer (0),
  30787. callbackNeeded (false)
  30788. {
  30789. triggerAsyncUpdate();
  30790. }
  30791. ~InternalTimerThread() throw()
  30792. {
  30793. stopThread (4000);
  30794. jassert (instance == this || instance == 0);
  30795. if (instance == this)
  30796. instance = 0;
  30797. }
  30798. void run()
  30799. {
  30800. uint32 lastTime = Time::getMillisecondCounter();
  30801. while (! threadShouldExit())
  30802. {
  30803. const uint32 now = Time::getMillisecondCounter();
  30804. if (now <= lastTime)
  30805. {
  30806. wait (2);
  30807. continue;
  30808. }
  30809. const int elapsed = now - lastTime;
  30810. lastTime = now;
  30811. lock.enter();
  30812. decrementAllCounters (elapsed);
  30813. const int timeUntilFirstTimer = (firstTimer != 0) ? firstTimer->countdownMs
  30814. : 1000;
  30815. lock.exit();
  30816. if (timeUntilFirstTimer <= 0)
  30817. {
  30818. if (callbackNeeded.set (true))
  30819. {
  30820. postMessage (new Message());
  30821. const uint32 messageDeliveryTimeout = now + 2000;
  30822. while (callbackNeeded.get())
  30823. {
  30824. wait (4);
  30825. if (threadShouldExit())
  30826. return;
  30827. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30828. break;
  30829. }
  30830. }
  30831. }
  30832. else
  30833. {
  30834. // don't wait for too long because running this loop also helps keep the
  30835. // Time::getApproximateMillisecondTimer value stay up-to-date
  30836. wait (jlimit (1, 50, timeUntilFirstTimer));
  30837. }
  30838. }
  30839. }
  30840. void handleMessage (const Message&)
  30841. {
  30842. const ScopedLock sl (lock);
  30843. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30844. {
  30845. Timer* const t = firstTimer;
  30846. t->countdownMs = t->periodMs;
  30847. removeTimer (t);
  30848. addTimer (t);
  30849. const ScopedUnlock ul (lock);
  30850. JUCE_TRY
  30851. {
  30852. t->timerCallback();
  30853. }
  30854. JUCE_CATCH_EXCEPTION
  30855. }
  30856. callbackNeeded.set (false);
  30857. }
  30858. static void callAnyTimersSynchronously()
  30859. {
  30860. if (InternalTimerThread::instance != 0)
  30861. {
  30862. const Message m;
  30863. InternalTimerThread::instance->handleMessage (m);
  30864. }
  30865. }
  30866. static inline void add (Timer* const tim) throw()
  30867. {
  30868. if (instance == 0)
  30869. instance = new InternalTimerThread();
  30870. const ScopedLock sl (instance->lock);
  30871. instance->addTimer (tim);
  30872. }
  30873. static inline void remove (Timer* const tim) throw()
  30874. {
  30875. if (instance != 0)
  30876. {
  30877. const ScopedLock sl (instance->lock);
  30878. instance->removeTimer (tim);
  30879. }
  30880. }
  30881. static inline void resetCounter (Timer* const tim,
  30882. const int newCounter) throw()
  30883. {
  30884. if (instance != 0)
  30885. {
  30886. tim->countdownMs = newCounter;
  30887. tim->periodMs = newCounter;
  30888. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30889. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30890. {
  30891. const ScopedLock sl (instance->lock);
  30892. instance->removeTimer (tim);
  30893. instance->addTimer (tim);
  30894. }
  30895. }
  30896. }
  30897. private:
  30898. friend class Timer;
  30899. static InternalTimerThread* instance;
  30900. static CriticalSection lock;
  30901. Timer* volatile firstTimer;
  30902. class AtomicBool
  30903. {
  30904. public:
  30905. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30906. ~AtomicBool() throw() {}
  30907. bool get() const throw() { return value != 0; }
  30908. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30909. private:
  30910. int32 value;
  30911. AtomicBool (const AtomicBool&);
  30912. AtomicBool& operator= (const AtomicBool&);
  30913. };
  30914. AtomicBool callbackNeeded;
  30915. void addTimer (Timer* const t) throw()
  30916. {
  30917. #ifdef JUCE_DEBUG
  30918. Timer* tt = firstTimer;
  30919. while (tt != 0)
  30920. {
  30921. // trying to add a timer that's already here - shouldn't get to this point,
  30922. // so if you get this assertion, let me know!
  30923. jassert (tt != t);
  30924. tt = tt->next;
  30925. }
  30926. jassert (t->previous == 0 && t->next == 0);
  30927. #endif
  30928. Timer* i = firstTimer;
  30929. if (i == 0 || i->countdownMs > t->countdownMs)
  30930. {
  30931. t->next = firstTimer;
  30932. firstTimer = t;
  30933. }
  30934. else
  30935. {
  30936. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30937. i = i->next;
  30938. jassert (i != 0);
  30939. t->next = i->next;
  30940. t->previous = i;
  30941. i->next = t;
  30942. }
  30943. if (t->next != 0)
  30944. t->next->previous = t;
  30945. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30946. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30947. notify();
  30948. }
  30949. void removeTimer (Timer* const t) throw()
  30950. {
  30951. #ifdef JUCE_DEBUG
  30952. Timer* tt = firstTimer;
  30953. bool found = false;
  30954. while (tt != 0)
  30955. {
  30956. if (tt == t)
  30957. {
  30958. found = true;
  30959. break;
  30960. }
  30961. tt = tt->next;
  30962. }
  30963. // trying to remove a timer that's not here - shouldn't get to this point,
  30964. // so if you get this assertion, let me know!
  30965. jassert (found);
  30966. #endif
  30967. if (t->previous != 0)
  30968. {
  30969. jassert (firstTimer != t);
  30970. t->previous->next = t->next;
  30971. }
  30972. else
  30973. {
  30974. jassert (firstTimer == t);
  30975. firstTimer = t->next;
  30976. }
  30977. if (t->next != 0)
  30978. t->next->previous = t->previous;
  30979. t->next = 0;
  30980. t->previous = 0;
  30981. }
  30982. void decrementAllCounters (const int numMillisecs) const
  30983. {
  30984. Timer* t = firstTimer;
  30985. while (t != 0)
  30986. {
  30987. t->countdownMs -= numMillisecs;
  30988. t = t->next;
  30989. }
  30990. }
  30991. void handleAsyncUpdate()
  30992. {
  30993. startThread (7);
  30994. }
  30995. InternalTimerThread (const InternalTimerThread&);
  30996. InternalTimerThread& operator= (const InternalTimerThread&);
  30997. };
  30998. InternalTimerThread* InternalTimerThread::instance = 0;
  30999. CriticalSection InternalTimerThread::lock;
  31000. void juce_callAnyTimersSynchronously()
  31001. {
  31002. InternalTimerThread::callAnyTimersSynchronously();
  31003. }
  31004. #ifdef JUCE_DEBUG
  31005. static SortedSet <Timer*> activeTimers;
  31006. #endif
  31007. Timer::Timer() throw()
  31008. : countdownMs (0),
  31009. periodMs (0),
  31010. previous (0),
  31011. next (0)
  31012. {
  31013. #ifdef JUCE_DEBUG
  31014. activeTimers.add (this);
  31015. #endif
  31016. }
  31017. Timer::Timer (const Timer&) throw()
  31018. : countdownMs (0),
  31019. periodMs (0),
  31020. previous (0),
  31021. next (0)
  31022. {
  31023. #ifdef JUCE_DEBUG
  31024. activeTimers.add (this);
  31025. #endif
  31026. }
  31027. Timer::~Timer()
  31028. {
  31029. stopTimer();
  31030. #ifdef JUCE_DEBUG
  31031. activeTimers.removeValue (this);
  31032. #endif
  31033. }
  31034. void Timer::startTimer (const int interval) throw()
  31035. {
  31036. const ScopedLock sl (InternalTimerThread::lock);
  31037. #ifdef JUCE_DEBUG
  31038. // this isn't a valid object! Your timer might be a dangling pointer or something..
  31039. jassert (activeTimers.contains (this));
  31040. #endif
  31041. if (periodMs == 0)
  31042. {
  31043. countdownMs = interval;
  31044. periodMs = jmax (1, interval);
  31045. InternalTimerThread::add (this);
  31046. }
  31047. else
  31048. {
  31049. InternalTimerThread::resetCounter (this, interval);
  31050. }
  31051. }
  31052. void Timer::stopTimer() throw()
  31053. {
  31054. const ScopedLock sl (InternalTimerThread::lock);
  31055. #ifdef JUCE_DEBUG
  31056. // this isn't a valid object! Your timer might be a dangling pointer or something..
  31057. jassert (activeTimers.contains (this));
  31058. #endif
  31059. if (periodMs > 0)
  31060. {
  31061. InternalTimerThread::remove (this);
  31062. periodMs = 0;
  31063. }
  31064. }
  31065. END_JUCE_NAMESPACE
  31066. /*** End of inlined file: juce_Timer.cpp ***/
  31067. #endif
  31068. #if JUCE_BUILD_GUI
  31069. /*** Start of inlined file: juce_Component.cpp ***/
  31070. BEGIN_JUCE_NAMESPACE
  31071. Component* Component::componentUnderMouse = 0;
  31072. Component* Component::currentlyFocusedComponent = 0;
  31073. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  31074. static Array <int> modalReturnValues;
  31075. static const int customCommandMessage = 0x7fff0001;
  31076. static const int exitModalStateMessage = 0x7fff0002;
  31077. static int unboundedMouseOffsetX = 0;
  31078. static int unboundedMouseOffsetY = 0;
  31079. static bool isUnboundedMouseModeOn = false;
  31080. static bool isCursorVisibleUntilOffscreen;
  31081. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  31082. static uint32 nextComponentUID = 0;
  31083. Component::Component() throw()
  31084. : parentComponent_ (0),
  31085. componentUID (++nextComponentUID),
  31086. numDeepMouseListeners (0),
  31087. lookAndFeel_ (0),
  31088. effect_ (0),
  31089. bufferedImage_ (0),
  31090. mouseListeners_ (0),
  31091. keyListeners_ (0),
  31092. componentListeners_ (0),
  31093. componentFlags_ (0)
  31094. {
  31095. }
  31096. Component::Component (const String& name) throw()
  31097. : componentName_ (name),
  31098. parentComponent_ (0),
  31099. componentUID (++nextComponentUID),
  31100. numDeepMouseListeners (0),
  31101. lookAndFeel_ (0),
  31102. effect_ (0),
  31103. bufferedImage_ (0),
  31104. mouseListeners_ (0),
  31105. keyListeners_ (0),
  31106. componentListeners_ (0),
  31107. componentFlags_ (0)
  31108. {
  31109. }
  31110. Component::~Component()
  31111. {
  31112. if (parentComponent_ != 0)
  31113. {
  31114. parentComponent_->removeChildComponent (this);
  31115. }
  31116. else if ((currentlyFocusedComponent == this)
  31117. || isParentOf (currentlyFocusedComponent))
  31118. {
  31119. giveAwayFocus();
  31120. }
  31121. if (componentUnderMouse == this)
  31122. componentUnderMouse = 0;
  31123. if (flags.hasHeavyweightPeerFlag)
  31124. removeFromDesktop();
  31125. modalComponentStack.removeValue (this);
  31126. for (int i = childComponentList_.size(); --i >= 0;)
  31127. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  31128. delete bufferedImage_;
  31129. delete mouseListeners_;
  31130. delete keyListeners_;
  31131. delete componentListeners_;
  31132. }
  31133. void Component::setName (const String& name)
  31134. {
  31135. // if component methods are being called from threads other than the message
  31136. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31137. checkMessageManagerIsLocked
  31138. if (componentName_ != name)
  31139. {
  31140. componentName_ = name;
  31141. if (flags.hasHeavyweightPeerFlag)
  31142. {
  31143. ComponentPeer* const peer = getPeer();
  31144. jassert (peer != 0);
  31145. if (peer != 0)
  31146. peer->setTitle (name);
  31147. }
  31148. if (componentListeners_ != 0)
  31149. {
  31150. const ComponentDeletionWatcher deletionChecker (this);
  31151. for (int i = componentListeners_->size(); --i >= 0;)
  31152. {
  31153. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31154. ->componentNameChanged (*this);
  31155. if (deletionChecker.hasBeenDeleted())
  31156. return;
  31157. i = jmin (i, componentListeners_->size());
  31158. }
  31159. }
  31160. }
  31161. }
  31162. void Component::setVisible (bool shouldBeVisible)
  31163. {
  31164. if (flags.visibleFlag != shouldBeVisible)
  31165. {
  31166. // if component methods are being called from threads other than the message
  31167. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31168. checkMessageManagerIsLocked
  31169. const ComponentDeletionWatcher deletionChecker (this);
  31170. flags.visibleFlag = shouldBeVisible;
  31171. internalRepaint (0, 0, getWidth(), getHeight());
  31172. sendFakeMouseMove();
  31173. if (! shouldBeVisible)
  31174. {
  31175. if (currentlyFocusedComponent == this
  31176. || isParentOf (currentlyFocusedComponent))
  31177. {
  31178. if (parentComponent_ != 0)
  31179. parentComponent_->grabKeyboardFocus();
  31180. else
  31181. giveAwayFocus();
  31182. }
  31183. }
  31184. sendVisibilityChangeMessage();
  31185. if ((! deletionChecker.hasBeenDeleted()) && flags.hasHeavyweightPeerFlag)
  31186. {
  31187. ComponentPeer* const peer = getPeer();
  31188. jassert (peer != 0);
  31189. if (peer != 0)
  31190. {
  31191. peer->setVisible (shouldBeVisible);
  31192. internalHierarchyChanged();
  31193. }
  31194. }
  31195. }
  31196. }
  31197. void Component::visibilityChanged()
  31198. {
  31199. }
  31200. void Component::sendVisibilityChangeMessage()
  31201. {
  31202. const ComponentDeletionWatcher deletionChecker (this);
  31203. visibilityChanged();
  31204. if ((! deletionChecker.hasBeenDeleted()) && componentListeners_ != 0)
  31205. {
  31206. for (int i = componentListeners_->size(); --i >= 0;)
  31207. {
  31208. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31209. ->componentVisibilityChanged (*this);
  31210. if (deletionChecker.hasBeenDeleted())
  31211. return;
  31212. i = jmin (i, componentListeners_->size());
  31213. }
  31214. }
  31215. }
  31216. bool Component::isShowing() const throw()
  31217. {
  31218. if (flags.visibleFlag)
  31219. {
  31220. if (parentComponent_ != 0)
  31221. {
  31222. return parentComponent_->isShowing();
  31223. }
  31224. else
  31225. {
  31226. const ComponentPeer* const peer = getPeer();
  31227. return peer != 0 && ! peer->isMinimised();
  31228. }
  31229. }
  31230. return false;
  31231. }
  31232. class FadeOutProxyComponent : public Component,
  31233. public Timer
  31234. {
  31235. public:
  31236. FadeOutProxyComponent (Component* comp,
  31237. const int fadeLengthMs,
  31238. const int deltaXToMove,
  31239. const int deltaYToMove,
  31240. const float scaleFactorAtEnd)
  31241. : lastTime (0),
  31242. alpha (1.0f),
  31243. scale (1.0f)
  31244. {
  31245. image = comp->createComponentSnapshot (Rectangle<int> (0, 0, comp->getWidth(), comp->getHeight()));
  31246. setBounds (comp->getBounds());
  31247. comp->getParentComponent()->addAndMakeVisible (this);
  31248. toBehind (comp);
  31249. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  31250. centreX = comp->getX() + comp->getWidth() * 0.5f;
  31251. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  31252. centreY = comp->getY() + comp->getHeight() * 0.5f;
  31253. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  31254. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  31255. setInterceptsMouseClicks (false, false);
  31256. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  31257. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  31258. }
  31259. ~FadeOutProxyComponent()
  31260. {
  31261. delete image;
  31262. }
  31263. void paint (Graphics& g)
  31264. {
  31265. g.setOpacity (alpha);
  31266. g.drawImage (image,
  31267. 0, 0, getWidth(), getHeight(),
  31268. 0, 0, image->getWidth(), image->getHeight());
  31269. }
  31270. void timerCallback()
  31271. {
  31272. const uint32 now = Time::getMillisecondCounter();
  31273. if (lastTime == 0)
  31274. lastTime = now;
  31275. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  31276. lastTime = now;
  31277. alpha += alphaChangePerMs * msPassed;
  31278. if (alpha > 0)
  31279. {
  31280. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  31281. {
  31282. centreX += xChangePerMs * msPassed;
  31283. centreY += yChangePerMs * msPassed;
  31284. scale += scaleChangePerMs * msPassed;
  31285. const int w = roundToInt (image->getWidth() * scale);
  31286. const int h = roundToInt (image->getHeight() * scale);
  31287. setBounds (roundToInt (centreX) - w / 2,
  31288. roundToInt (centreY) - h / 2,
  31289. w, h);
  31290. }
  31291. repaint();
  31292. }
  31293. else
  31294. {
  31295. delete this;
  31296. }
  31297. }
  31298. juce_UseDebuggingNewOperator
  31299. private:
  31300. Image* image;
  31301. uint32 lastTime;
  31302. float alpha, alphaChangePerMs;
  31303. float centreX, xChangePerMs;
  31304. float centreY, yChangePerMs;
  31305. float scale, scaleChangePerMs;
  31306. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31307. const FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31308. };
  31309. void Component::fadeOutComponent (const int millisecondsToFade,
  31310. const int deltaXToMove,
  31311. const int deltaYToMove,
  31312. const float scaleFactorAtEnd)
  31313. {
  31314. //xxx won't work for comps without parents
  31315. if (isShowing() && millisecondsToFade > 0)
  31316. new FadeOutProxyComponent (this, millisecondsToFade,
  31317. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31318. setVisible (false);
  31319. }
  31320. bool Component::isValidComponent() const throw()
  31321. {
  31322. return (this != 0) && isValidMessageListener();
  31323. }
  31324. void* Component::getWindowHandle() const throw()
  31325. {
  31326. const ComponentPeer* const peer = getPeer();
  31327. if (peer != 0)
  31328. return peer->getNativeHandle();
  31329. return 0;
  31330. }
  31331. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31332. {
  31333. // if component methods are being called from threads other than the message
  31334. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31335. checkMessageManagerIsLocked
  31336. if (isOpaque())
  31337. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31338. else
  31339. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31340. int currentStyleFlags = 0;
  31341. // don't use getPeer(), so that we only get the peer that's specifically
  31342. // for this comp, and not for one of its parents.
  31343. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31344. if (peer != 0)
  31345. currentStyleFlags = peer->getStyleFlags();
  31346. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31347. {
  31348. const ComponentDeletionWatcher deletionChecker (this);
  31349. #if JUCE_LINUX
  31350. // it's wise to give the component a non-zero size before
  31351. // putting it on the desktop, as X windows get confused by this, and
  31352. // a (1, 1) minimum size is enforced here.
  31353. setSize (jmax (1, getWidth()),
  31354. jmax (1, getHeight()));
  31355. #endif
  31356. int x = 0, y = 0;
  31357. relativePositionToGlobal (x, y);
  31358. bool wasFullscreen = false;
  31359. bool wasMinimised = false;
  31360. ComponentBoundsConstrainer* currentConstainer = 0;
  31361. Rectangle<int> oldNonFullScreenBounds;
  31362. if (peer != 0)
  31363. {
  31364. wasFullscreen = peer->isFullScreen();
  31365. wasMinimised = peer->isMinimised();
  31366. currentConstainer = peer->getConstrainer();
  31367. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31368. removeFromDesktop();
  31369. setTopLeftPosition (x, y);
  31370. }
  31371. if (parentComponent_ != 0)
  31372. parentComponent_->removeChildComponent (this);
  31373. if (! deletionChecker.hasBeenDeleted())
  31374. {
  31375. flags.hasHeavyweightPeerFlag = true;
  31376. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31377. Desktop::getInstance().addDesktopComponent (this);
  31378. bounds_.setPosition (x, y);
  31379. peer->setBounds (x, y, getWidth(), getHeight(), false);
  31380. peer->setVisible (isVisible());
  31381. if (wasFullscreen)
  31382. {
  31383. peer->setFullScreen (true);
  31384. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31385. }
  31386. if (wasMinimised)
  31387. peer->setMinimised (true);
  31388. if (isAlwaysOnTop())
  31389. peer->setAlwaysOnTop (true);
  31390. peer->setConstrainer (currentConstainer);
  31391. repaint();
  31392. }
  31393. internalHierarchyChanged();
  31394. }
  31395. }
  31396. void Component::removeFromDesktop()
  31397. {
  31398. // if component methods are being called from threads other than the message
  31399. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31400. checkMessageManagerIsLocked
  31401. if (flags.hasHeavyweightPeerFlag)
  31402. {
  31403. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31404. flags.hasHeavyweightPeerFlag = false;
  31405. jassert (peer != 0);
  31406. delete peer;
  31407. Desktop::getInstance().removeDesktopComponent (this);
  31408. }
  31409. }
  31410. bool Component::isOnDesktop() const throw()
  31411. {
  31412. return flags.hasHeavyweightPeerFlag;
  31413. }
  31414. void Component::userTriedToCloseWindow()
  31415. {
  31416. /* This means that the user's trying to get rid of your window with the 'close window' system
  31417. menu option (on windows) or possibly the task manager - you should really handle this
  31418. and delete or hide your component in an appropriate way.
  31419. If you want to ignore the event and don't want to trigger this assertion, just override
  31420. this method and do nothing.
  31421. */
  31422. jassertfalse
  31423. }
  31424. void Component::minimisationStateChanged (bool)
  31425. {
  31426. }
  31427. void Component::setOpaque (const bool shouldBeOpaque) throw()
  31428. {
  31429. if (shouldBeOpaque != flags.opaqueFlag)
  31430. {
  31431. flags.opaqueFlag = shouldBeOpaque;
  31432. if (flags.hasHeavyweightPeerFlag)
  31433. {
  31434. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31435. if (peer != 0)
  31436. {
  31437. // to make it recreate the heavyweight window
  31438. addToDesktop (peer->getStyleFlags());
  31439. }
  31440. }
  31441. repaint();
  31442. }
  31443. }
  31444. bool Component::isOpaque() const throw()
  31445. {
  31446. return flags.opaqueFlag;
  31447. }
  31448. void Component::setBufferedToImage (const bool shouldBeBuffered) throw()
  31449. {
  31450. if (shouldBeBuffered != flags.bufferToImageFlag)
  31451. {
  31452. deleteAndZero (bufferedImage_);
  31453. flags.bufferToImageFlag = shouldBeBuffered;
  31454. }
  31455. }
  31456. void Component::toFront (const bool setAsForeground)
  31457. {
  31458. // if component methods are being called from threads other than the message
  31459. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31460. checkMessageManagerIsLocked
  31461. if (flags.hasHeavyweightPeerFlag)
  31462. {
  31463. ComponentPeer* const peer = getPeer();
  31464. if (peer != 0)
  31465. {
  31466. peer->toFront (setAsForeground);
  31467. if (setAsForeground && ! hasKeyboardFocus (true))
  31468. grabKeyboardFocus();
  31469. }
  31470. }
  31471. else if (parentComponent_ != 0)
  31472. {
  31473. if (parentComponent_->childComponentList_.getLast() != this)
  31474. {
  31475. const int index = parentComponent_->childComponentList_.indexOf (this);
  31476. if (index >= 0)
  31477. {
  31478. int insertIndex = -1;
  31479. if (! flags.alwaysOnTopFlag)
  31480. {
  31481. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31482. while (insertIndex > 0
  31483. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31484. {
  31485. --insertIndex;
  31486. }
  31487. }
  31488. if (index != insertIndex)
  31489. {
  31490. parentComponent_->childComponentList_.move (index, insertIndex);
  31491. sendFakeMouseMove();
  31492. repaintParent();
  31493. }
  31494. }
  31495. }
  31496. if (setAsForeground)
  31497. {
  31498. internalBroughtToFront();
  31499. grabKeyboardFocus();
  31500. }
  31501. }
  31502. }
  31503. void Component::toBehind (Component* const other)
  31504. {
  31505. if (other != 0)
  31506. {
  31507. // the two components must belong to the same parent..
  31508. jassert (parentComponent_ == other->parentComponent_);
  31509. if (parentComponent_ != 0)
  31510. {
  31511. const int index = parentComponent_->childComponentList_.indexOf (this);
  31512. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31513. if (index >= 0
  31514. && otherIndex >= 0
  31515. && index != otherIndex - 1
  31516. && other != this)
  31517. {
  31518. if (index < otherIndex)
  31519. --otherIndex;
  31520. parentComponent_->childComponentList_.move (index, otherIndex);
  31521. sendFakeMouseMove();
  31522. repaintParent();
  31523. }
  31524. }
  31525. else if (isOnDesktop())
  31526. {
  31527. jassert (other->isOnDesktop());
  31528. if (other->isOnDesktop())
  31529. {
  31530. ComponentPeer* const us = getPeer();
  31531. ComponentPeer* const them = other->getPeer();
  31532. jassert (us != 0 && them != 0);
  31533. if (us != 0 && them != 0)
  31534. us->toBehind (them);
  31535. }
  31536. }
  31537. }
  31538. }
  31539. void Component::toBack()
  31540. {
  31541. if (isOnDesktop())
  31542. {
  31543. jassertfalse //xxx need to add this to native window
  31544. }
  31545. else if (parentComponent_ != 0
  31546. && parentComponent_->childComponentList_.getFirst() != this)
  31547. {
  31548. const int index = parentComponent_->childComponentList_.indexOf (this);
  31549. if (index > 0)
  31550. {
  31551. int insertIndex = 0;
  31552. if (flags.alwaysOnTopFlag)
  31553. {
  31554. while (insertIndex < parentComponent_->childComponentList_.size()
  31555. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31556. {
  31557. ++insertIndex;
  31558. }
  31559. }
  31560. if (index != insertIndex)
  31561. {
  31562. parentComponent_->childComponentList_.move (index, insertIndex);
  31563. sendFakeMouseMove();
  31564. repaintParent();
  31565. }
  31566. }
  31567. }
  31568. }
  31569. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31570. {
  31571. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31572. {
  31573. flags.alwaysOnTopFlag = shouldStayOnTop;
  31574. if (isOnDesktop())
  31575. {
  31576. ComponentPeer* const peer = getPeer();
  31577. jassert (peer != 0);
  31578. if (peer != 0)
  31579. {
  31580. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31581. {
  31582. // some kinds of peer can't change their always-on-top status, so
  31583. // for these, we'll need to create a new window
  31584. const int oldFlags = peer->getStyleFlags();
  31585. removeFromDesktop();
  31586. addToDesktop (oldFlags);
  31587. }
  31588. }
  31589. }
  31590. if (shouldStayOnTop)
  31591. toFront (false);
  31592. internalHierarchyChanged();
  31593. }
  31594. }
  31595. bool Component::isAlwaysOnTop() const throw()
  31596. {
  31597. return flags.alwaysOnTopFlag;
  31598. }
  31599. int Component::proportionOfWidth (const float proportion) const throw()
  31600. {
  31601. return roundToInt (proportion * bounds_.getWidth());
  31602. }
  31603. int Component::proportionOfHeight (const float proportion) const throw()
  31604. {
  31605. return roundToInt (proportion * bounds_.getHeight());
  31606. }
  31607. int Component::getParentWidth() const throw()
  31608. {
  31609. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31610. : getParentMonitorArea().getWidth();
  31611. }
  31612. int Component::getParentHeight() const throw()
  31613. {
  31614. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31615. : getParentMonitorArea().getHeight();
  31616. }
  31617. int Component::getScreenX() const throw()
  31618. {
  31619. return (parentComponent_ != 0) ? parentComponent_->getScreenX() + getX()
  31620. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenX()
  31621. : getX());
  31622. }
  31623. int Component::getScreenY() const throw()
  31624. {
  31625. return (parentComponent_ != 0) ? parentComponent_->getScreenY() + getY()
  31626. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenY()
  31627. : getY());
  31628. }
  31629. void Component::relativePositionToGlobal (int& x, int& y) const throw()
  31630. {
  31631. const Component* c = this;
  31632. do
  31633. {
  31634. if (c->flags.hasHeavyweightPeerFlag)
  31635. {
  31636. c->getPeer()->relativePositionToGlobal (x, y);
  31637. break;
  31638. }
  31639. x += c->getX();
  31640. y += c->getY();
  31641. c = c->parentComponent_;
  31642. }
  31643. while (c != 0);
  31644. }
  31645. void Component::globalPositionToRelative (int& x, int& y) const throw()
  31646. {
  31647. if (flags.hasHeavyweightPeerFlag)
  31648. {
  31649. getPeer()->globalPositionToRelative (x, y);
  31650. }
  31651. else
  31652. {
  31653. if (parentComponent_ != 0)
  31654. parentComponent_->globalPositionToRelative (x, y);
  31655. x -= getX();
  31656. y -= getY();
  31657. }
  31658. }
  31659. void Component::relativePositionToOtherComponent (const Component* const targetComponent, int& x, int& y) const throw()
  31660. {
  31661. if (targetComponent != 0)
  31662. {
  31663. const Component* c = this;
  31664. do
  31665. {
  31666. if (c == targetComponent)
  31667. return;
  31668. if (c->flags.hasHeavyweightPeerFlag)
  31669. {
  31670. c->getPeer()->relativePositionToGlobal (x, y);
  31671. break;
  31672. }
  31673. x += c->getX();
  31674. y += c->getY();
  31675. c = c->parentComponent_;
  31676. }
  31677. while (c != 0);
  31678. targetComponent->globalPositionToRelative (x, y);
  31679. }
  31680. }
  31681. void Component::setBounds (int x, int y, int w, int h)
  31682. {
  31683. // if component methods are being called from threads other than the message
  31684. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31685. checkMessageManagerIsLocked
  31686. if (w < 0) w = 0;
  31687. if (h < 0) h = 0;
  31688. const bool wasResized = (getWidth() != w || getHeight() != h);
  31689. const bool wasMoved = (getX() != x || getY() != y);
  31690. #ifdef JUCE_DEBUG
  31691. // It's a very bad idea to try to resize a window during its paint() method!
  31692. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31693. #endif
  31694. if (wasMoved || wasResized)
  31695. {
  31696. if (flags.visibleFlag)
  31697. {
  31698. // send a fake mouse move to trigger enter/exit messages if needed..
  31699. sendFakeMouseMove();
  31700. if (! flags.hasHeavyweightPeerFlag)
  31701. repaintParent();
  31702. }
  31703. bounds_.setBounds (x, y, w, h);
  31704. if (wasResized)
  31705. repaint();
  31706. else if (! flags.hasHeavyweightPeerFlag)
  31707. repaintParent();
  31708. if (flags.hasHeavyweightPeerFlag)
  31709. {
  31710. ComponentPeer* const peer = getPeer();
  31711. if (peer != 0)
  31712. {
  31713. if (wasMoved && wasResized)
  31714. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31715. else if (wasMoved)
  31716. peer->setPosition (getX(), getY());
  31717. else if (wasResized)
  31718. peer->setSize (getWidth(), getHeight());
  31719. }
  31720. }
  31721. sendMovedResizedMessages (wasMoved, wasResized);
  31722. }
  31723. }
  31724. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31725. {
  31726. JUCE_TRY
  31727. {
  31728. if (wasMoved)
  31729. moved();
  31730. if (wasResized)
  31731. {
  31732. resized();
  31733. for (int i = childComponentList_.size(); --i >= 0;)
  31734. {
  31735. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31736. i = jmin (i, childComponentList_.size());
  31737. }
  31738. }
  31739. if (parentComponent_ != 0)
  31740. parentComponent_->childBoundsChanged (this);
  31741. if (componentListeners_ != 0)
  31742. {
  31743. const ComponentDeletionWatcher deletionChecker (this);
  31744. for (int i = componentListeners_->size(); --i >= 0;)
  31745. {
  31746. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31747. ->componentMovedOrResized (*this, wasMoved, wasResized);
  31748. if (deletionChecker.hasBeenDeleted())
  31749. return;
  31750. i = jmin (i, componentListeners_->size());
  31751. }
  31752. }
  31753. }
  31754. JUCE_CATCH_EXCEPTION
  31755. }
  31756. void Component::setSize (const int w, const int h)
  31757. {
  31758. setBounds (getX(), getY(), w, h);
  31759. }
  31760. void Component::setTopLeftPosition (const int x, const int y)
  31761. {
  31762. setBounds (x, y, getWidth(), getHeight());
  31763. }
  31764. void Component::setTopRightPosition (const int x, const int y)
  31765. {
  31766. setTopLeftPosition (x - getWidth(), y);
  31767. }
  31768. void Component::setBounds (const Rectangle<int>& r)
  31769. {
  31770. setBounds (r.getX(),
  31771. r.getY(),
  31772. r.getWidth(),
  31773. r.getHeight());
  31774. }
  31775. void Component::setBoundsRelative (const float x, const float y,
  31776. const float w, const float h)
  31777. {
  31778. const int pw = getParentWidth();
  31779. const int ph = getParentHeight();
  31780. setBounds (roundToInt (x * pw),
  31781. roundToInt (y * ph),
  31782. roundToInt (w * pw),
  31783. roundToInt (h * ph));
  31784. }
  31785. void Component::setCentrePosition (const int x, const int y)
  31786. {
  31787. setTopLeftPosition (x - getWidth() / 2,
  31788. y - getHeight() / 2);
  31789. }
  31790. void Component::setCentreRelative (const float x, const float y)
  31791. {
  31792. setCentrePosition (roundToInt (getParentWidth() * x),
  31793. roundToInt (getParentHeight() * y));
  31794. }
  31795. void Component::centreWithSize (const int width, const int height)
  31796. {
  31797. setBounds ((getParentWidth() - width) / 2,
  31798. (getParentHeight() - height) / 2,
  31799. width,
  31800. height);
  31801. }
  31802. void Component::setBoundsInset (const BorderSize& borders)
  31803. {
  31804. setBounds (borders.getLeft(),
  31805. borders.getTop(),
  31806. getParentWidth() - (borders.getLeftAndRight()),
  31807. getParentHeight() - (borders.getTopAndBottom()));
  31808. }
  31809. void Component::setBoundsToFit (int x, int y, int width, int height,
  31810. const Justification& justification,
  31811. const bool onlyReduceInSize)
  31812. {
  31813. // it's no good calling this method unless both the component and
  31814. // target rectangle have a finite size.
  31815. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31816. if (getWidth() > 0 && getHeight() > 0
  31817. && width > 0 && height > 0)
  31818. {
  31819. int newW, newH;
  31820. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31821. {
  31822. newW = getWidth();
  31823. newH = getHeight();
  31824. }
  31825. else
  31826. {
  31827. const double imageRatio = getHeight() / (double) getWidth();
  31828. const double targetRatio = height / (double) width;
  31829. if (imageRatio <= targetRatio)
  31830. {
  31831. newW = width;
  31832. newH = jmin (height, roundToInt (newW * imageRatio));
  31833. }
  31834. else
  31835. {
  31836. newH = height;
  31837. newW = jmin (width, roundToInt (newH / imageRatio));
  31838. }
  31839. }
  31840. if (newW > 0 && newH > 0)
  31841. {
  31842. int newX, newY;
  31843. justification.applyToRectangle (newX, newY, newW, newH,
  31844. x, y, width, height);
  31845. setBounds (newX, newY, newW, newH);
  31846. }
  31847. }
  31848. }
  31849. bool Component::hitTest (int x, int y)
  31850. {
  31851. if (! flags.ignoresMouseClicksFlag)
  31852. return true;
  31853. if (flags.allowChildMouseClicksFlag)
  31854. {
  31855. for (int i = getNumChildComponents(); --i >= 0;)
  31856. {
  31857. Component* const c = getChildComponent (i);
  31858. if (c->isVisible()
  31859. && c->bounds_.contains (x, y)
  31860. && c->hitTest (x - c->getX(),
  31861. y - c->getY()))
  31862. {
  31863. return true;
  31864. }
  31865. }
  31866. }
  31867. return false;
  31868. }
  31869. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31870. const bool allowClicksOnChildComponents) throw()
  31871. {
  31872. flags.ignoresMouseClicksFlag = ! allowClicks;
  31873. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31874. }
  31875. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31876. bool& allowsClicksOnChildComponents) const throw()
  31877. {
  31878. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31879. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31880. }
  31881. bool Component::contains (const int x, const int y)
  31882. {
  31883. if (((unsigned int) x) < (unsigned int) getWidth()
  31884. && ((unsigned int) y) < (unsigned int) getHeight()
  31885. && hitTest (x, y))
  31886. {
  31887. if (parentComponent_ != 0)
  31888. {
  31889. return parentComponent_->contains (x + getX(),
  31890. y + getY());
  31891. }
  31892. else if (flags.hasHeavyweightPeerFlag)
  31893. {
  31894. const ComponentPeer* const peer = getPeer();
  31895. if (peer != 0)
  31896. return peer->contains (x, y, true);
  31897. }
  31898. }
  31899. return false;
  31900. }
  31901. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31902. {
  31903. if (! contains (x, y))
  31904. return false;
  31905. Component* p = this;
  31906. while (p->parentComponent_ != 0)
  31907. {
  31908. x += p->getX();
  31909. y += p->getY();
  31910. p = p->parentComponent_;
  31911. }
  31912. const Component* const c = p->getComponentAt (x, y);
  31913. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31914. }
  31915. Component* Component::getComponentAt (const int x, const int y)
  31916. {
  31917. if (flags.visibleFlag
  31918. && ((unsigned int) x) < (unsigned int) getWidth()
  31919. && ((unsigned int) y) < (unsigned int) getHeight()
  31920. && hitTest (x, y))
  31921. {
  31922. for (int i = childComponentList_.size(); --i >= 0;)
  31923. {
  31924. Component* const child = childComponentList_.getUnchecked(i);
  31925. Component* const c = child->getComponentAt (x - child->getX(),
  31926. y - child->getY());
  31927. if (c != 0)
  31928. return c;
  31929. }
  31930. return this;
  31931. }
  31932. return 0;
  31933. }
  31934. void Component::addChildComponent (Component* const child, int zOrder)
  31935. {
  31936. // if component methods are being called from threads other than the message
  31937. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31938. checkMessageManagerIsLocked
  31939. if (child != 0 && child->parentComponent_ != this)
  31940. {
  31941. if (child->parentComponent_ != 0)
  31942. child->parentComponent_->removeChildComponent (child);
  31943. else
  31944. child->removeFromDesktop();
  31945. child->parentComponent_ = this;
  31946. if (child->isVisible())
  31947. child->repaintParent();
  31948. if (! child->isAlwaysOnTop())
  31949. {
  31950. if (zOrder < 0 || zOrder > childComponentList_.size())
  31951. zOrder = childComponentList_.size();
  31952. while (zOrder > 0)
  31953. {
  31954. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31955. break;
  31956. --zOrder;
  31957. }
  31958. }
  31959. childComponentList_.insert (zOrder, child);
  31960. child->internalHierarchyChanged();
  31961. internalChildrenChanged();
  31962. }
  31963. }
  31964. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31965. {
  31966. if (child != 0)
  31967. {
  31968. child->setVisible (true);
  31969. addChildComponent (child, zOrder);
  31970. }
  31971. }
  31972. void Component::removeChildComponent (Component* const child)
  31973. {
  31974. removeChildComponent (childComponentList_.indexOf (child));
  31975. }
  31976. Component* Component::removeChildComponent (const int index)
  31977. {
  31978. // if component methods are being called from threads other than the message
  31979. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31980. checkMessageManagerIsLocked
  31981. Component* const child = childComponentList_ [index];
  31982. if (child != 0)
  31983. {
  31984. sendFakeMouseMove();
  31985. child->repaintParent();
  31986. childComponentList_.remove (index);
  31987. child->parentComponent_ = 0;
  31988. JUCE_TRY
  31989. {
  31990. if ((currentlyFocusedComponent == child)
  31991. || child->isParentOf (currentlyFocusedComponent))
  31992. {
  31993. // get rid first to force the grabKeyboardFocus to change to us.
  31994. giveAwayFocus();
  31995. grabKeyboardFocus();
  31996. }
  31997. }
  31998. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31999. catch (const std::exception& e)
  32000. {
  32001. currentlyFocusedComponent = 0;
  32002. Desktop::getInstance().triggerFocusCallback();
  32003. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32004. }
  32005. catch (...)
  32006. {
  32007. currentlyFocusedComponent = 0;
  32008. Desktop::getInstance().triggerFocusCallback();
  32009. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32010. }
  32011. #endif
  32012. child->internalHierarchyChanged();
  32013. internalChildrenChanged();
  32014. }
  32015. return child;
  32016. }
  32017. void Component::removeAllChildren()
  32018. {
  32019. for (int i = childComponentList_.size(); --i >= 0;)
  32020. removeChildComponent (i);
  32021. }
  32022. void Component::deleteAllChildren()
  32023. {
  32024. for (int i = childComponentList_.size(); --i >= 0;)
  32025. delete (removeChildComponent (i));
  32026. }
  32027. int Component::getNumChildComponents() const throw()
  32028. {
  32029. return childComponentList_.size();
  32030. }
  32031. Component* Component::getChildComponent (const int index) const throw()
  32032. {
  32033. return childComponentList_ [index];
  32034. }
  32035. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  32036. {
  32037. return childComponentList_.indexOf (const_cast <Component*> (child));
  32038. }
  32039. Component* Component::getTopLevelComponent() const throw()
  32040. {
  32041. const Component* comp = this;
  32042. while (comp->parentComponent_ != 0)
  32043. comp = comp->parentComponent_;
  32044. return (Component*) comp;
  32045. }
  32046. bool Component::isParentOf (const Component* possibleChild) const throw()
  32047. {
  32048. while (possibleChild->isValidComponent())
  32049. {
  32050. possibleChild = possibleChild->parentComponent_;
  32051. if (possibleChild == this)
  32052. return true;
  32053. }
  32054. return false;
  32055. }
  32056. void Component::parentHierarchyChanged()
  32057. {
  32058. }
  32059. void Component::childrenChanged()
  32060. {
  32061. }
  32062. void Component::internalChildrenChanged()
  32063. {
  32064. const ComponentDeletionWatcher deletionChecker (this);
  32065. const bool hasListeners = componentListeners_ != 0;
  32066. childrenChanged();
  32067. if (hasListeners)
  32068. {
  32069. if (deletionChecker.hasBeenDeleted())
  32070. return;
  32071. for (int i = componentListeners_->size(); --i >= 0;)
  32072. {
  32073. ((ComponentListener*) componentListeners_->getUnchecked (i))
  32074. ->componentChildrenChanged (*this);
  32075. if (deletionChecker.hasBeenDeleted())
  32076. return;
  32077. i = jmin (i, componentListeners_->size());
  32078. }
  32079. }
  32080. }
  32081. void Component::internalHierarchyChanged()
  32082. {
  32083. parentHierarchyChanged();
  32084. const ComponentDeletionWatcher deletionChecker (this);
  32085. if (componentListeners_ != 0)
  32086. {
  32087. for (int i = componentListeners_->size(); --i >= 0;)
  32088. {
  32089. ((ComponentListener*) componentListeners_->getUnchecked (i))
  32090. ->componentParentHierarchyChanged (*this);
  32091. if (deletionChecker.hasBeenDeleted())
  32092. return;
  32093. i = jmin (i, componentListeners_->size());
  32094. }
  32095. }
  32096. for (int i = childComponentList_.size(); --i >= 0;)
  32097. {
  32098. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  32099. // you really shouldn't delete the parent component during a callback telling you
  32100. // that it's changed..
  32101. jassert (! deletionChecker.hasBeenDeleted());
  32102. if (deletionChecker.hasBeenDeleted())
  32103. return;
  32104. i = jmin (i, childComponentList_.size());
  32105. }
  32106. }
  32107. void* Component::runModalLoopCallback (void* userData)
  32108. {
  32109. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  32110. }
  32111. int Component::runModalLoop()
  32112. {
  32113. if (! MessageManager::getInstance()->isThisTheMessageThread())
  32114. {
  32115. // use a callback so this can be called from non-gui threads
  32116. return (int) (pointer_sized_int)
  32117. MessageManager::getInstance()
  32118. ->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
  32119. }
  32120. Component* const prevFocused = getCurrentlyFocusedComponent();
  32121. ScopedPointer <ComponentDeletionWatcher> deletionChecker;
  32122. if (prevFocused != 0)
  32123. deletionChecker = new ComponentDeletionWatcher (prevFocused);
  32124. if (! isCurrentlyModal())
  32125. enterModalState();
  32126. JUCE_TRY
  32127. {
  32128. while (flags.currentlyModalFlag && flags.visibleFlag)
  32129. {
  32130. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  32131. break;
  32132. // check whether this component was deleted during the last message
  32133. if (! isValidMessageListener())
  32134. break;
  32135. }
  32136. }
  32137. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  32138. catch (const std::exception& e)
  32139. {
  32140. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32141. return 0;
  32142. }
  32143. catch (...)
  32144. {
  32145. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32146. return 0;
  32147. }
  32148. #endif
  32149. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32150. int returnValue = 0;
  32151. if (modalIndex >= 0)
  32152. {
  32153. modalComponentReturnValueKeys.remove (modalIndex);
  32154. returnValue = modalReturnValues.remove (modalIndex);
  32155. }
  32156. modalComponentStack.removeValue (this);
  32157. if (deletionChecker != 0 && ! deletionChecker->hasBeenDeleted())
  32158. prevFocused->grabKeyboardFocus();
  32159. return returnValue;
  32160. }
  32161. void Component::enterModalState (const bool takeKeyboardFocus_)
  32162. {
  32163. // if component methods are being called from threads other than the message
  32164. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32165. checkMessageManagerIsLocked
  32166. // Check for an attempt to make a component modal when it already is!
  32167. // This can cause nasty problems..
  32168. jassert (! flags.currentlyModalFlag);
  32169. if (! isCurrentlyModal())
  32170. {
  32171. modalComponentStack.add (this);
  32172. modalComponentReturnValueKeys.add (this);
  32173. modalReturnValues.add (0);
  32174. flags.currentlyModalFlag = true;
  32175. setVisible (true);
  32176. if (takeKeyboardFocus_)
  32177. grabKeyboardFocus();
  32178. }
  32179. }
  32180. void Component::exitModalState (const int returnValue)
  32181. {
  32182. if (isCurrentlyModal())
  32183. {
  32184. if (MessageManager::getInstance()->isThisTheMessageThread())
  32185. {
  32186. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32187. if (modalIndex >= 0)
  32188. {
  32189. modalReturnValues.set (modalIndex, returnValue);
  32190. }
  32191. else
  32192. {
  32193. modalComponentReturnValueKeys.add (this);
  32194. modalReturnValues.add (returnValue);
  32195. }
  32196. modalComponentStack.removeValue (this);
  32197. flags.currentlyModalFlag = false;
  32198. bringModalComponentToFront();
  32199. }
  32200. else
  32201. {
  32202. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  32203. }
  32204. }
  32205. }
  32206. bool Component::isCurrentlyModal() const throw()
  32207. {
  32208. return flags.currentlyModalFlag
  32209. && getCurrentlyModalComponent() == this;
  32210. }
  32211. bool Component::isCurrentlyBlockedByAnotherModalComponent() const throw()
  32212. {
  32213. Component* const mc = getCurrentlyModalComponent();
  32214. return mc != 0
  32215. && mc != this
  32216. && (! mc->isParentOf (this))
  32217. && ! mc->canModalEventBeSentToComponent (this);
  32218. }
  32219. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  32220. {
  32221. return modalComponentStack.size();
  32222. }
  32223. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  32224. {
  32225. Component* const c = (Component*) (modalComponentStack [modalComponentStack.size() - index - 1]);
  32226. return c->isValidComponent() ? c : 0;
  32227. }
  32228. void Component::bringModalComponentToFront()
  32229. {
  32230. ComponentPeer* lastOne = 0;
  32231. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  32232. {
  32233. Component* const c = getCurrentlyModalComponent (i);
  32234. if (c == 0)
  32235. break;
  32236. ComponentPeer* peer = c->getPeer();
  32237. if (peer != 0 && peer != lastOne)
  32238. {
  32239. if (lastOne == 0)
  32240. {
  32241. peer->toFront (true);
  32242. peer->grabFocus();
  32243. }
  32244. else
  32245. peer->toBehind (lastOne);
  32246. lastOne = peer;
  32247. }
  32248. }
  32249. }
  32250. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  32251. {
  32252. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  32253. }
  32254. bool Component::isBroughtToFrontOnMouseClick() const throw()
  32255. {
  32256. return flags.bringToFrontOnClickFlag;
  32257. }
  32258. void Component::setMouseCursor (const MouseCursor& cursor) throw()
  32259. {
  32260. cursor_ = cursor;
  32261. if (flags.visibleFlag)
  32262. {
  32263. int mx, my;
  32264. getMouseXYRelative (mx, my);
  32265. if (flags.draggingFlag || reallyContains (mx, my, 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 && (unboundedMouseOffsetX != 0
  32286. || unboundedMouseOffsetY != 0
  32287. || ! isCursorVisibleUntilOffscreen))
  32288. {
  32289. mc = MouseCursor::NoCursor;
  32290. forcedUpdate = true;
  32291. }
  32292. static void* currentCursorHandle = 0;
  32293. if (forcedUpdate || mc.getHandle() != currentCursorHandle)
  32294. {
  32295. currentCursorHandle = mc.getHandle();
  32296. mc.showInWindow (peer);
  32297. }
  32298. }
  32299. }
  32300. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  32301. {
  32302. flags.repaintOnMouseActivityFlag = shouldRepaint;
  32303. }
  32304. void Component::repaintParent() throw()
  32305. {
  32306. if (flags.visibleFlag)
  32307. internalRepaint (0, 0, getWidth(), getHeight());
  32308. }
  32309. void Component::repaint() throw()
  32310. {
  32311. repaint (0, 0, getWidth(), getHeight());
  32312. }
  32313. void Component::repaint (const int x, const int y,
  32314. const int w, const int h) throw()
  32315. {
  32316. deleteAndZero (bufferedImage_);
  32317. if (flags.visibleFlag)
  32318. internalRepaint (x, y, w, h);
  32319. }
  32320. void Component::internalRepaint (int x, int y, int w, int h)
  32321. {
  32322. // if component methods are being called from threads other than the message
  32323. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32324. checkMessageManagerIsLocked
  32325. if (x < 0)
  32326. {
  32327. w += x;
  32328. x = 0;
  32329. }
  32330. if (x + w > getWidth())
  32331. w = getWidth() - x;
  32332. if (w > 0)
  32333. {
  32334. if (y < 0)
  32335. {
  32336. h += y;
  32337. y = 0;
  32338. }
  32339. if (y + h > getHeight())
  32340. h = getHeight() - y;
  32341. if (h > 0)
  32342. {
  32343. if (parentComponent_ != 0)
  32344. {
  32345. x += getX();
  32346. y += getY();
  32347. if (parentComponent_->flags.visibleFlag)
  32348. parentComponent_->internalRepaint (x, y, w, h);
  32349. }
  32350. else if (flags.hasHeavyweightPeerFlag)
  32351. {
  32352. ComponentPeer* const peer = getPeer();
  32353. if (peer != 0)
  32354. peer->repaint (x, y, w, h);
  32355. }
  32356. }
  32357. }
  32358. }
  32359. void Component::paintEntireComponent (Graphics& originalContext)
  32360. {
  32361. jassert (! originalContext.isClipEmpty());
  32362. #ifdef JUCE_DEBUG
  32363. flags.isInsidePaintCall = true;
  32364. #endif
  32365. Graphics* g = &originalContext;
  32366. Image* effectImage = 0;
  32367. if (effect_ != 0)
  32368. {
  32369. effectImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32370. getWidth(), getHeight(),
  32371. ! flags.opaqueFlag);
  32372. g = new Graphics (*effectImage);
  32373. }
  32374. g->saveState();
  32375. clipObscuredRegions (*g, g->getClipBounds(), 0, 0);
  32376. if (! g->isClipEmpty())
  32377. {
  32378. if (bufferedImage_ != 0)
  32379. {
  32380. g->setColour (Colours::black);
  32381. g->drawImageAt (bufferedImage_, 0, 0);
  32382. }
  32383. else
  32384. {
  32385. if (flags.bufferToImageFlag)
  32386. {
  32387. if (bufferedImage_ == 0)
  32388. {
  32389. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32390. getWidth(), getHeight(), ! flags.opaqueFlag);
  32391. Graphics imG (*bufferedImage_);
  32392. paint (imG);
  32393. }
  32394. g->setColour (Colours::black);
  32395. g->drawImageAt (bufferedImage_, 0, 0);
  32396. }
  32397. else
  32398. {
  32399. paint (*g);
  32400. g->resetToDefaultState();
  32401. }
  32402. }
  32403. }
  32404. g->restoreState();
  32405. for (int i = 0; i < childComponentList_.size(); ++i)
  32406. {
  32407. Component* const child = childComponentList_.getUnchecked (i);
  32408. if (child->isVisible())
  32409. {
  32410. g->saveState();
  32411. if (g->reduceClipRegion (child->getX(), child->getY(),
  32412. child->getWidth(), child->getHeight()))
  32413. {
  32414. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32415. {
  32416. const Component* const sibling = childComponentList_.getUnchecked (j);
  32417. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32418. g->excludeClipRegion (sibling->getX(), sibling->getY(),
  32419. sibling->getWidth(), sibling->getHeight());
  32420. }
  32421. if (! g->isClipEmpty())
  32422. {
  32423. g->setOrigin (child->getX(), child->getY());
  32424. child->paintEntireComponent (*g);
  32425. }
  32426. }
  32427. g->restoreState();
  32428. }
  32429. }
  32430. JUCE_TRY
  32431. {
  32432. g->saveState();
  32433. paintOverChildren (*g);
  32434. g->restoreState();
  32435. }
  32436. JUCE_CATCH_EXCEPTION
  32437. if (effect_ != 0)
  32438. {
  32439. delete g;
  32440. effect_->applyEffect (*effectImage, originalContext);
  32441. delete effectImage;
  32442. }
  32443. #ifdef JUCE_DEBUG
  32444. flags.isInsidePaintCall = false;
  32445. #endif
  32446. }
  32447. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32448. const bool clipImageToComponentBounds)
  32449. {
  32450. Rectangle<int> r (areaToGrab);
  32451. if (clipImageToComponentBounds)
  32452. r = r.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  32453. Image* const componentImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32454. jmax (1, r.getWidth()),
  32455. jmax (1, r.getHeight()),
  32456. true);
  32457. Graphics imageContext (*componentImage);
  32458. imageContext.setOrigin (-r.getX(),
  32459. -r.getY());
  32460. paintEntireComponent (imageContext);
  32461. return componentImage;
  32462. }
  32463. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32464. {
  32465. if (effect_ != effect)
  32466. {
  32467. effect_ = effect;
  32468. repaint();
  32469. }
  32470. }
  32471. LookAndFeel& Component::getLookAndFeel() const throw()
  32472. {
  32473. const Component* c = this;
  32474. do
  32475. {
  32476. if (c->lookAndFeel_ != 0)
  32477. return *(c->lookAndFeel_);
  32478. c = c->parentComponent_;
  32479. }
  32480. while (c != 0);
  32481. return LookAndFeel::getDefaultLookAndFeel();
  32482. }
  32483. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32484. {
  32485. if (lookAndFeel_ != newLookAndFeel)
  32486. {
  32487. lookAndFeel_ = newLookAndFeel;
  32488. sendLookAndFeelChange();
  32489. }
  32490. }
  32491. void Component::lookAndFeelChanged()
  32492. {
  32493. }
  32494. void Component::sendLookAndFeelChange()
  32495. {
  32496. repaint();
  32497. lookAndFeelChanged();
  32498. // (it's not a great idea to do anything that would delete this component
  32499. // during the lookAndFeelChanged() callback)
  32500. jassert (isValidComponent());
  32501. const ComponentDeletionWatcher deletionChecker (this);
  32502. for (int i = childComponentList_.size(); --i >= 0;)
  32503. {
  32504. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32505. if (deletionChecker.hasBeenDeleted())
  32506. return;
  32507. i = jmin (i, childComponentList_.size());
  32508. }
  32509. }
  32510. static const var::identifier getColourPropertyId (const int colourId)
  32511. {
  32512. String s;
  32513. s.preallocateStorage (18);
  32514. s << T("jcclr_") << colourId;
  32515. return s;
  32516. }
  32517. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const throw()
  32518. {
  32519. var* v = properties.getItem (getColourPropertyId (colourId));
  32520. if (v != 0)
  32521. return Colour ((int) *v);
  32522. if (inheritFromParent && parentComponent_ != 0)
  32523. return parentComponent_->findColour (colourId, true);
  32524. return getLookAndFeel().findColour (colourId);
  32525. }
  32526. bool Component::isColourSpecified (const int colourId) const throw()
  32527. {
  32528. return properties.contains (getColourPropertyId (colourId));
  32529. }
  32530. void Component::removeColour (const int colourId)
  32531. {
  32532. if (properties.remove (getColourPropertyId (colourId)))
  32533. colourChanged();
  32534. }
  32535. void Component::setColour (const int colourId, const Colour& colour)
  32536. {
  32537. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32538. colourChanged();
  32539. }
  32540. void Component::copyAllExplicitColoursTo (Component& target) const throw()
  32541. {
  32542. bool changed = false;
  32543. for (int i = properties.size(); --i >= 0;)
  32544. {
  32545. const var::identifier name (properties.getName(i));
  32546. if (name.name.startsWith (T("jcclr_")))
  32547. if (target.properties.set (name, properties [name]))
  32548. changed = true;
  32549. }
  32550. if (changed)
  32551. target.colourChanged();
  32552. }
  32553. void Component::colourChanged()
  32554. {
  32555. }
  32556. const Rectangle<int> Component::getUnclippedArea() const
  32557. {
  32558. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32559. Component* p = parentComponent_;
  32560. int px = getX();
  32561. int py = getY();
  32562. while (p != 0)
  32563. {
  32564. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32565. return Rectangle<int>();
  32566. px += p->getX();
  32567. py += p->getY();
  32568. p = p->parentComponent_;
  32569. }
  32570. return Rectangle<int> (x, y, w, h);
  32571. }
  32572. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32573. const int deltaX, const int deltaY) const throw()
  32574. {
  32575. for (int i = childComponentList_.size(); --i >= 0;)
  32576. {
  32577. const Component* const c = childComponentList_.getUnchecked(i);
  32578. if (c->isVisible())
  32579. {
  32580. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32581. if (! newClip.isEmpty())
  32582. {
  32583. if (c->isOpaque())
  32584. {
  32585. g.excludeClipRegion (deltaX + newClip.getX(),
  32586. deltaY + newClip.getY(),
  32587. newClip.getWidth(),
  32588. newClip.getHeight());
  32589. }
  32590. else
  32591. {
  32592. newClip.translate (-c->getX(), -c->getY());
  32593. c->clipObscuredRegions (g, newClip,
  32594. c->getX() + deltaX,
  32595. c->getY() + deltaY);
  32596. }
  32597. }
  32598. }
  32599. }
  32600. }
  32601. void Component::getVisibleArea (RectangleList& result,
  32602. const bool includeSiblings) const
  32603. {
  32604. result.clear();
  32605. const Rectangle<int> unclipped (getUnclippedArea());
  32606. if (! unclipped.isEmpty())
  32607. {
  32608. result.add (unclipped);
  32609. if (includeSiblings)
  32610. {
  32611. const Component* const c = getTopLevelComponent();
  32612. int x = 0, y = 0;
  32613. c->relativePositionToOtherComponent (this, x, y);
  32614. c->subtractObscuredRegions (result, x, y,
  32615. Rectangle<int> (0, 0, c->getWidth(), c->getHeight()),
  32616. this);
  32617. }
  32618. subtractObscuredRegions (result, 0, 0, unclipped, 0);
  32619. result.consolidate();
  32620. }
  32621. }
  32622. void Component::subtractObscuredRegions (RectangleList& result,
  32623. const int deltaX,
  32624. const int deltaY,
  32625. const Rectangle<int>& clipRect,
  32626. const Component* const compToAvoid) const throw()
  32627. {
  32628. for (int i = childComponentList_.size(); --i >= 0;)
  32629. {
  32630. const Component* const c = childComponentList_.getUnchecked(i);
  32631. if (c != compToAvoid && c->isVisible())
  32632. {
  32633. if (c->isOpaque())
  32634. {
  32635. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32636. childBounds.translate (deltaX, deltaY);
  32637. result.subtract (childBounds);
  32638. }
  32639. else
  32640. {
  32641. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32642. newClip.translate (-c->getX(), -c->getY());
  32643. c->subtractObscuredRegions (result,
  32644. c->getX() + deltaX,
  32645. c->getY() + deltaY,
  32646. newClip,
  32647. compToAvoid);
  32648. }
  32649. }
  32650. }
  32651. }
  32652. void Component::mouseEnter (const MouseEvent&)
  32653. {
  32654. // base class does nothing
  32655. }
  32656. void Component::mouseExit (const MouseEvent&)
  32657. {
  32658. // base class does nothing
  32659. }
  32660. void Component::mouseDown (const MouseEvent&)
  32661. {
  32662. // base class does nothing
  32663. }
  32664. void Component::mouseUp (const MouseEvent&)
  32665. {
  32666. // base class does nothing
  32667. }
  32668. void Component::mouseDrag (const MouseEvent&)
  32669. {
  32670. // base class does nothing
  32671. }
  32672. void Component::mouseMove (const MouseEvent&)
  32673. {
  32674. // base class does nothing
  32675. }
  32676. void Component::mouseDoubleClick (const MouseEvent&)
  32677. {
  32678. // base class does nothing
  32679. }
  32680. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32681. {
  32682. // the base class just passes this event up to its parent..
  32683. if (parentComponent_ != 0)
  32684. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32685. wheelIncrementX, wheelIncrementY);
  32686. }
  32687. void Component::resized()
  32688. {
  32689. // base class does nothing
  32690. }
  32691. void Component::moved()
  32692. {
  32693. // base class does nothing
  32694. }
  32695. void Component::childBoundsChanged (Component*)
  32696. {
  32697. // base class does nothing
  32698. }
  32699. void Component::parentSizeChanged()
  32700. {
  32701. // base class does nothing
  32702. }
  32703. void Component::addComponentListener (ComponentListener* const newListener) throw()
  32704. {
  32705. if (componentListeners_ == 0)
  32706. componentListeners_ = new VoidArray();
  32707. componentListeners_->addIfNotAlreadyThere (newListener);
  32708. }
  32709. void Component::removeComponentListener (ComponentListener* const listenerToRemove) throw()
  32710. {
  32711. jassert (isValidComponent());
  32712. if (componentListeners_ != 0)
  32713. componentListeners_->removeValue (listenerToRemove);
  32714. }
  32715. void Component::inputAttemptWhenModal()
  32716. {
  32717. bringModalComponentToFront();
  32718. getLookAndFeel().playAlertSound();
  32719. }
  32720. bool Component::canModalEventBeSentToComponent (const Component*)
  32721. {
  32722. return false;
  32723. }
  32724. void Component::internalModalInputAttempt()
  32725. {
  32726. Component* const current = getCurrentlyModalComponent();
  32727. if (current != 0)
  32728. current->inputAttemptWhenModal();
  32729. }
  32730. void Component::paint (Graphics&)
  32731. {
  32732. // all painting is done in the subclasses
  32733. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32734. }
  32735. void Component::paintOverChildren (Graphics&)
  32736. {
  32737. // all painting is done in the subclasses
  32738. }
  32739. void Component::handleMessage (const Message& message)
  32740. {
  32741. if (message.intParameter1 == exitModalStateMessage)
  32742. {
  32743. exitModalState (message.intParameter2);
  32744. }
  32745. else if (message.intParameter1 == customCommandMessage)
  32746. {
  32747. handleCommandMessage (message.intParameter2);
  32748. }
  32749. }
  32750. void Component::postCommandMessage (const int commandId) throw()
  32751. {
  32752. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32753. }
  32754. void Component::handleCommandMessage (int)
  32755. {
  32756. // used by subclasses
  32757. }
  32758. void Component::addMouseListener (MouseListener* const newListener,
  32759. const bool wantsEventsForAllNestedChildComponents) throw()
  32760. {
  32761. // if component methods are being called from threads other than the message
  32762. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32763. checkMessageManagerIsLocked
  32764. if (mouseListeners_ == 0)
  32765. mouseListeners_ = new VoidArray();
  32766. if (! mouseListeners_->contains (newListener))
  32767. {
  32768. if (wantsEventsForAllNestedChildComponents)
  32769. {
  32770. mouseListeners_->insert (0, newListener);
  32771. ++numDeepMouseListeners;
  32772. }
  32773. else
  32774. {
  32775. mouseListeners_->add (newListener);
  32776. }
  32777. }
  32778. }
  32779. void Component::removeMouseListener (MouseListener* const listenerToRemove) throw()
  32780. {
  32781. // if component methods are being called from threads other than the message
  32782. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32783. checkMessageManagerIsLocked
  32784. if (mouseListeners_ != 0)
  32785. {
  32786. const int index = mouseListeners_->indexOf (listenerToRemove);
  32787. if (index >= 0)
  32788. {
  32789. if (index < numDeepMouseListeners)
  32790. --numDeepMouseListeners;
  32791. mouseListeners_->remove (index);
  32792. }
  32793. }
  32794. }
  32795. void Component::internalMouseEnter (int x, int y, int64 time)
  32796. {
  32797. if (isCurrentlyBlockedByAnotherModalComponent())
  32798. {
  32799. // if something else is modal, always just show a normal mouse cursor
  32800. if (componentUnderMouse == this)
  32801. {
  32802. ComponentPeer* const peer = getPeer();
  32803. if (peer != 0)
  32804. {
  32805. MouseCursor mc (MouseCursor::NormalCursor);
  32806. mc.showInWindow (peer);
  32807. }
  32808. }
  32809. return;
  32810. }
  32811. if (isValidComponent() && ! flags.mouseInsideFlag)
  32812. {
  32813. flags.mouseInsideFlag = true;
  32814. flags.mouseOverFlag = true;
  32815. flags.draggingFlag = false;
  32816. const ComponentDeletionWatcher deletionChecker (this);
  32817. if (flags.repaintOnMouseActivityFlag)
  32818. repaint();
  32819. const MouseEvent me (x, y,
  32820. ModifierKeys::getCurrentModifiers(),
  32821. this,
  32822. Time (time),
  32823. x, y,
  32824. Time (time),
  32825. 0, false);
  32826. mouseEnter (me);
  32827. if (deletionChecker.hasBeenDeleted())
  32828. return;
  32829. Desktop::getInstance().resetTimer();
  32830. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32831. {
  32832. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseEnter (me);
  32833. if (deletionChecker.hasBeenDeleted())
  32834. return;
  32835. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32836. }
  32837. if (mouseListeners_ != 0)
  32838. {
  32839. for (int i = mouseListeners_->size(); --i >= 0;)
  32840. {
  32841. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32842. if (deletionChecker.hasBeenDeleted())
  32843. return;
  32844. i = jmin (i, mouseListeners_->size());
  32845. }
  32846. }
  32847. const Component* p = parentComponent_;
  32848. while (p != 0)
  32849. {
  32850. const ComponentDeletionWatcher parentDeletionChecker (p);
  32851. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32852. {
  32853. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32854. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32855. return;
  32856. i = jmin (i, p->numDeepMouseListeners);
  32857. }
  32858. p = p->parentComponent_;
  32859. }
  32860. }
  32861. if (componentUnderMouse == this)
  32862. internalUpdateMouseCursor (true);
  32863. }
  32864. void Component::internalMouseExit (int x, int y, int64 time)
  32865. {
  32866. const ComponentDeletionWatcher deletionChecker (this);
  32867. if (flags.draggingFlag)
  32868. {
  32869. internalMouseUp (ModifierKeys::getCurrentModifiers().getRawFlags(), x, y, time);
  32870. if (deletionChecker.hasBeenDeleted())
  32871. return;
  32872. }
  32873. enableUnboundedMouseMovement (false);
  32874. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32875. {
  32876. flags.mouseInsideFlag = false;
  32877. flags.mouseOverFlag = false;
  32878. flags.draggingFlag = false;
  32879. if (flags.repaintOnMouseActivityFlag)
  32880. repaint();
  32881. const MouseEvent me (x, y,
  32882. ModifierKeys::getCurrentModifiers(),
  32883. this,
  32884. Time (time),
  32885. x, y,
  32886. Time (time),
  32887. 0, false);
  32888. mouseExit (me);
  32889. if (deletionChecker.hasBeenDeleted())
  32890. return;
  32891. Desktop::getInstance().resetTimer();
  32892. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32893. {
  32894. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseExit (me);
  32895. if (deletionChecker.hasBeenDeleted())
  32896. return;
  32897. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32898. }
  32899. if (mouseListeners_ != 0)
  32900. {
  32901. for (int i = mouseListeners_->size(); --i >= 0;)
  32902. {
  32903. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32904. if (deletionChecker.hasBeenDeleted())
  32905. return;
  32906. i = jmin (i, mouseListeners_->size());
  32907. }
  32908. }
  32909. const Component* p = parentComponent_;
  32910. while (p != 0)
  32911. {
  32912. const ComponentDeletionWatcher parentDeletionChecker (p);
  32913. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32914. {
  32915. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32916. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32917. return;
  32918. i = jmin (i, p->numDeepMouseListeners);
  32919. }
  32920. p = p->parentComponent_;
  32921. }
  32922. }
  32923. }
  32924. class InternalDragRepeater : public Timer
  32925. {
  32926. public:
  32927. InternalDragRepeater() {}
  32928. ~InternalDragRepeater() {}
  32929. void timerCallback()
  32930. {
  32931. Component* const c = Component::getComponentUnderMouse();
  32932. if (c != 0 && c->isMouseButtonDown())
  32933. {
  32934. int x, y;
  32935. c->getMouseXYRelative (x, y);
  32936. // the offsets have been added on, so must be taken off before calling the
  32937. // drag.. otherwise they'll be added twice
  32938. x -= unboundedMouseOffsetX;
  32939. y -= unboundedMouseOffsetY;
  32940. c->internalMouseDrag (x, y, Time::currentTimeMillis());
  32941. }
  32942. }
  32943. juce_UseDebuggingNewOperator
  32944. private:
  32945. InternalDragRepeater (const InternalDragRepeater&);
  32946. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32947. };
  32948. static InternalDragRepeater* dragRepeater = 0;
  32949. void Component::beginDragAutoRepeat (const int interval)
  32950. {
  32951. if (interval > 0)
  32952. {
  32953. if (dragRepeater == 0)
  32954. dragRepeater = new InternalDragRepeater();
  32955. if (dragRepeater->getTimerInterval() != interval)
  32956. dragRepeater->startTimer (interval);
  32957. }
  32958. else
  32959. {
  32960. deleteAndZero (dragRepeater);
  32961. }
  32962. }
  32963. void Component::internalMouseDown (const int x, const int y, const int64 time)
  32964. {
  32965. Desktop& desktop = Desktop::getInstance();
  32966. int gx = x, gy = y;
  32967. relativePositionToGlobal (gx, gy);
  32968. desktop.registerMouseDown (Point<int> (gx, gy), time, this);
  32969. const ComponentDeletionWatcher deletionChecker (this);
  32970. if (isCurrentlyBlockedByAnotherModalComponent())
  32971. {
  32972. internalModalInputAttempt();
  32973. if (deletionChecker.hasBeenDeleted())
  32974. return;
  32975. // If processing the input attempt has exited the modal loop, we'll allow the event
  32976. // to be delivered..
  32977. if (isCurrentlyBlockedByAnotherModalComponent())
  32978. {
  32979. // allow blocked mouse-events to go to global listeners..
  32980. const MouseEvent me (x, y,
  32981. ModifierKeys::getCurrentModifiers(),
  32982. this,
  32983. Time (time),
  32984. x, y,
  32985. desktop.getLastMouseDownTime(),
  32986. desktop.getNumberOfMultipleClicks(),
  32987. false);
  32988. desktop.resetTimer();
  32989. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  32990. {
  32991. ((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
  32992. if (deletionChecker.hasBeenDeleted())
  32993. return;
  32994. i = jmin (i, desktop.mouseListeners.size());
  32995. }
  32996. return;
  32997. }
  32998. }
  32999. {
  33000. Component* c = this;
  33001. while (c != 0)
  33002. {
  33003. if (c->isBroughtToFrontOnMouseClick())
  33004. {
  33005. c->toFront (true);
  33006. if (deletionChecker.hasBeenDeleted())
  33007. return;
  33008. }
  33009. c = c->parentComponent_;
  33010. }
  33011. }
  33012. if (! flags.dontFocusOnMouseClickFlag)
  33013. grabFocusInternal (focusChangedByMouseClick);
  33014. if (! deletionChecker.hasBeenDeleted())
  33015. {
  33016. flags.draggingFlag = true;
  33017. flags.mouseOverFlag = true;
  33018. if (flags.repaintOnMouseActivityFlag)
  33019. repaint();
  33020. const MouseEvent me (x, y,
  33021. ModifierKeys::getCurrentModifiers(),
  33022. this,
  33023. desktop.getLastMouseDownTime(),
  33024. x, y,
  33025. desktop.getLastMouseDownTime(),
  33026. desktop.getNumberOfMultipleClicks(),
  33027. false);
  33028. mouseDown (me);
  33029. if (deletionChecker.hasBeenDeleted())
  33030. return;
  33031. desktop.resetTimer();
  33032. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33033. {
  33034. ((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
  33035. if (deletionChecker.hasBeenDeleted())
  33036. return;
  33037. i = jmin (i, desktop.mouseListeners.size());
  33038. }
  33039. if (mouseListeners_ != 0)
  33040. {
  33041. for (int i = mouseListeners_->size(); --i >= 0;)
  33042. {
  33043. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  33044. if (deletionChecker.hasBeenDeleted())
  33045. return;
  33046. i = jmin (i, mouseListeners_->size());
  33047. }
  33048. }
  33049. const Component* p = parentComponent_;
  33050. while (p != 0)
  33051. {
  33052. const ComponentDeletionWatcher parentDeletionChecker (p);
  33053. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33054. {
  33055. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  33056. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33057. return;
  33058. i = jmin (i, p->numDeepMouseListeners);
  33059. }
  33060. p = p->parentComponent_;
  33061. }
  33062. }
  33063. }
  33064. void Component::internalMouseUp (const int oldModifiers, int x, int y, const int64 time)
  33065. {
  33066. if (isValidComponent() && flags.draggingFlag)
  33067. {
  33068. Desktop& desktop = Desktop::getInstance();
  33069. flags.draggingFlag = false;
  33070. deleteAndZero (dragRepeater);
  33071. x += unboundedMouseOffsetX;
  33072. y += unboundedMouseOffsetY;
  33073. int gx = x, gy = y;
  33074. relativePositionToGlobal (gx, gy);
  33075. desktop.registerMouseDrag (Point<int> (gx, gy));
  33076. const ComponentDeletionWatcher deletionChecker (this);
  33077. if (flags.repaintOnMouseActivityFlag)
  33078. repaint();
  33079. int mdx, mdy;
  33080. Desktop::getLastMouseDownPosition (mdx, mdy);
  33081. globalPositionToRelative (mdx, mdy);
  33082. const Time lastMouseDownTime (desktop.getLastMouseDownTime());
  33083. const MouseEvent me (x, y,
  33084. oldModifiers,
  33085. this,
  33086. Time (time),
  33087. mdx, mdy,
  33088. lastMouseDownTime,
  33089. desktop.getNumberOfMultipleClicks(),
  33090. desktop.mouseMovedSignificantlySincePressed
  33091. || time > lastMouseDownTime.toMilliseconds() + 300);
  33092. mouseUp (me);
  33093. if (deletionChecker.hasBeenDeleted())
  33094. return;
  33095. desktop.resetTimer();
  33096. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33097. {
  33098. ((MouseListener*) desktop.mouseListeners[i])->mouseUp (me);
  33099. if (deletionChecker.hasBeenDeleted())
  33100. return;
  33101. i = jmin (i, desktop.mouseListeners.size());
  33102. }
  33103. if (mouseListeners_ != 0)
  33104. {
  33105. for (int i = mouseListeners_->size(); --i >= 0;)
  33106. {
  33107. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  33108. if (deletionChecker.hasBeenDeleted())
  33109. return;
  33110. i = jmin (i, mouseListeners_->size());
  33111. }
  33112. }
  33113. {
  33114. const Component* p = parentComponent_;
  33115. while (p != 0)
  33116. {
  33117. const ComponentDeletionWatcher parentDeletionChecker (p);
  33118. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33119. {
  33120. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  33121. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33122. return;
  33123. i = jmin (i, p->numDeepMouseListeners);
  33124. }
  33125. p = p->parentComponent_;
  33126. }
  33127. }
  33128. // check for double-click
  33129. if (me.getNumberOfClicks() >= 2)
  33130. {
  33131. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  33132. mouseDoubleClick (me);
  33133. int i;
  33134. for (i = desktop.mouseListeners.size(); --i >= 0;)
  33135. {
  33136. ((MouseListener*) desktop.mouseListeners[i])->mouseDoubleClick (me);
  33137. if (deletionChecker.hasBeenDeleted())
  33138. return;
  33139. i = jmin (i, desktop.mouseListeners.size());
  33140. }
  33141. for (i = numListeners; --i >= 0;)
  33142. {
  33143. if (deletionChecker.hasBeenDeleted() || mouseListeners_ == 0)
  33144. return;
  33145. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  33146. if (ml != 0)
  33147. ml->mouseDoubleClick (me);
  33148. }
  33149. if (deletionChecker.hasBeenDeleted())
  33150. return;
  33151. const Component* p = parentComponent_;
  33152. while (p != 0)
  33153. {
  33154. const ComponentDeletionWatcher parentDeletionChecker (p);
  33155. for (i = p->numDeepMouseListeners; --i >= 0;)
  33156. {
  33157. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  33158. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33159. return;
  33160. i = jmin (i, p->numDeepMouseListeners);
  33161. }
  33162. p = p->parentComponent_;
  33163. }
  33164. }
  33165. }
  33166. enableUnboundedMouseMovement (false);
  33167. }
  33168. void Component::internalMouseDrag (int x, int y, const int64 time)
  33169. {
  33170. if (isValidComponent() && flags.draggingFlag)
  33171. {
  33172. Desktop& desktop = Desktop::getInstance();
  33173. flags.mouseOverFlag = reallyContains (x, y, false);
  33174. x += unboundedMouseOffsetX;
  33175. y += unboundedMouseOffsetY;
  33176. int gx = x, gy = y;
  33177. relativePositionToGlobal (gx, gy);
  33178. desktop.registerMouseDrag (Point<int> (gx, gy));
  33179. const ComponentDeletionWatcher deletionChecker (this);
  33180. int mdx, mdy;
  33181. Desktop::getLastMouseDownPosition (mdx, mdy);
  33182. globalPositionToRelative (mdx, mdy);
  33183. const Time lastMouseDownTime (desktop.getLastMouseDownTime());
  33184. const MouseEvent me (x, y,
  33185. ModifierKeys::getCurrentModifiers(),
  33186. this,
  33187. Time (time),
  33188. mdx, mdy,
  33189. lastMouseDownTime,
  33190. desktop.getNumberOfMultipleClicks(),
  33191. desktop.mouseMovedSignificantlySincePressed
  33192. || time > lastMouseDownTime.toMilliseconds() + 300);
  33193. mouseDrag (me);
  33194. if (deletionChecker.hasBeenDeleted())
  33195. return;
  33196. desktop.resetTimer();
  33197. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33198. {
  33199. ((MouseListener*) desktop.mouseListeners[i])->mouseDrag (me);
  33200. if (deletionChecker.hasBeenDeleted())
  33201. return;
  33202. i = jmin (i, desktop.mouseListeners.size());
  33203. }
  33204. if (mouseListeners_ != 0)
  33205. {
  33206. for (int i = mouseListeners_->size(); --i >= 0;)
  33207. {
  33208. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  33209. if (deletionChecker.hasBeenDeleted())
  33210. return;
  33211. i = jmin (i, mouseListeners_->size());
  33212. }
  33213. }
  33214. const Component* p = parentComponent_;
  33215. while (p != 0)
  33216. {
  33217. const ComponentDeletionWatcher parentDeletionChecker (p);
  33218. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33219. {
  33220. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  33221. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33222. return;
  33223. i = jmin (i, p->numDeepMouseListeners);
  33224. }
  33225. p = p->parentComponent_;
  33226. }
  33227. if (this == componentUnderMouse)
  33228. {
  33229. if (isUnboundedMouseModeOn)
  33230. {
  33231. Rectangle<int> screenArea (getParentMonitorArea().expanded (-2, -2));
  33232. int mx, my;
  33233. Desktop::getMousePosition (mx, my);
  33234. if (! screenArea.contains (mx, my))
  33235. {
  33236. int deltaX = 0, deltaY = 0;
  33237. if (mx <= screenArea.getX() || mx >= screenArea.getRight())
  33238. deltaX = getScreenX() + getWidth() / 2 - mx;
  33239. if (my <= screenArea.getY() || my >= screenArea.getBottom())
  33240. deltaY = getScreenY() + getHeight() / 2 - my;
  33241. unboundedMouseOffsetX -= deltaX;
  33242. unboundedMouseOffsetY -= deltaY;
  33243. Desktop::setMousePosition (mx + deltaX,
  33244. my + deltaY);
  33245. }
  33246. else if (isCursorVisibleUntilOffscreen
  33247. && (unboundedMouseOffsetX != 0 || unboundedMouseOffsetY != 0)
  33248. && screenArea.contains (mx + unboundedMouseOffsetX,
  33249. my + unboundedMouseOffsetY))
  33250. {
  33251. mx += unboundedMouseOffsetX;
  33252. my += unboundedMouseOffsetY;
  33253. unboundedMouseOffsetX = 0;
  33254. unboundedMouseOffsetY = 0;
  33255. Desktop::setMousePosition (mx, my);
  33256. }
  33257. }
  33258. internalUpdateMouseCursor (false);
  33259. }
  33260. }
  33261. }
  33262. void Component::internalMouseMove (const int x, const int y, const int64 time)
  33263. {
  33264. const ComponentDeletionWatcher deletionChecker (this);
  33265. if (isValidComponent())
  33266. {
  33267. Desktop& desktop = Desktop::getInstance();
  33268. const MouseEvent me (x, y,
  33269. ModifierKeys::getCurrentModifiers(),
  33270. this,
  33271. Time (time),
  33272. x, y,
  33273. Time (time),
  33274. 0, false);
  33275. if (isCurrentlyBlockedByAnotherModalComponent())
  33276. {
  33277. // allow blocked mouse-events to go to global listeners..
  33278. desktop.sendMouseMove();
  33279. }
  33280. else
  33281. {
  33282. if (this == componentUnderMouse)
  33283. internalUpdateMouseCursor (false);
  33284. flags.mouseOverFlag = true;
  33285. mouseMove (me);
  33286. if (deletionChecker.hasBeenDeleted())
  33287. return;
  33288. desktop.resetTimer();
  33289. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33290. {
  33291. ((MouseListener*) desktop.mouseListeners[i])->mouseMove (me);
  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))->mouseMove (me);
  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)))->mouseMove (me);
  33313. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33314. return;
  33315. i = jmin (i, p->numDeepMouseListeners);
  33316. }
  33317. p = p->parentComponent_;
  33318. }
  33319. }
  33320. }
  33321. }
  33322. void Component::internalMouseWheel (const int intAmountX, const int intAmountY, const int64 time)
  33323. {
  33324. Desktop& desktop = Desktop::getInstance();
  33325. const ComponentDeletionWatcher deletionChecker (this);
  33326. const float wheelIncrementX = intAmountX * (1.0f / 256.0f);
  33327. const float wheelIncrementY = intAmountY * (1.0f / 256.0f);
  33328. int mx, my;
  33329. getMouseXYRelative (mx, my);
  33330. const MouseEvent me (mx, my,
  33331. ModifierKeys::getCurrentModifiers(),
  33332. this,
  33333. Time (time),
  33334. mx, my,
  33335. Time (time),
  33336. 0, false);
  33337. if (isCurrentlyBlockedByAnotherModalComponent())
  33338. {
  33339. // allow blocked mouse-events to go to global listeners..
  33340. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33341. {
  33342. ((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33343. if (deletionChecker.hasBeenDeleted())
  33344. return;
  33345. i = jmin (i, desktop.mouseListeners.size());
  33346. }
  33347. }
  33348. else
  33349. {
  33350. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33351. if (deletionChecker.hasBeenDeleted())
  33352. return;
  33353. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33354. {
  33355. ((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33356. if (deletionChecker.hasBeenDeleted())
  33357. return;
  33358. i = jmin (i, desktop.mouseListeners.size());
  33359. }
  33360. if (mouseListeners_ != 0)
  33361. {
  33362. for (int i = mouseListeners_->size(); --i >= 0;)
  33363. {
  33364. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33365. if (deletionChecker.hasBeenDeleted())
  33366. return;
  33367. i = jmin (i, mouseListeners_->size());
  33368. }
  33369. }
  33370. const Component* p = parentComponent_;
  33371. while (p != 0)
  33372. {
  33373. const ComponentDeletionWatcher parentDeletionChecker (p);
  33374. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33375. {
  33376. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33377. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33378. return;
  33379. i = jmin (i, p->numDeepMouseListeners);
  33380. }
  33381. p = p->parentComponent_;
  33382. }
  33383. sendFakeMouseMove();
  33384. }
  33385. }
  33386. void Component::sendFakeMouseMove() const
  33387. {
  33388. ComponentPeer* const peer = getPeer();
  33389. if (peer != 0)
  33390. peer->sendFakeMouseMove();
  33391. }
  33392. void Component::broughtToFront()
  33393. {
  33394. }
  33395. void Component::internalBroughtToFront()
  33396. {
  33397. if (isValidComponent())
  33398. {
  33399. if (flags.hasHeavyweightPeerFlag)
  33400. Desktop::getInstance().componentBroughtToFront (this);
  33401. const ComponentDeletionWatcher deletionChecker (this);
  33402. broughtToFront();
  33403. if (deletionChecker.hasBeenDeleted())
  33404. return;
  33405. if (componentListeners_ != 0)
  33406. {
  33407. for (int i = componentListeners_->size(); --i >= 0;)
  33408. {
  33409. ((ComponentListener*) componentListeners_->getUnchecked (i))
  33410. ->componentBroughtToFront (*this);
  33411. if (deletionChecker.hasBeenDeleted())
  33412. return;
  33413. i = jmin (i, componentListeners_->size());
  33414. }
  33415. }
  33416. // when brought to the front and there's a modal component blocking this one,
  33417. // we need to bring the modal one to the front instead..
  33418. Component* const cm = getCurrentlyModalComponent();
  33419. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  33420. bringModalComponentToFront();
  33421. }
  33422. }
  33423. void Component::focusGained (FocusChangeType)
  33424. {
  33425. // base class does nothing
  33426. }
  33427. void Component::internalFocusGain (const FocusChangeType cause)
  33428. {
  33429. const ComponentDeletionWatcher deletionChecker (this);
  33430. focusGained (cause);
  33431. if (! deletionChecker.hasBeenDeleted())
  33432. internalChildFocusChange (cause);
  33433. }
  33434. void Component::focusLost (FocusChangeType)
  33435. {
  33436. // base class does nothing
  33437. }
  33438. void Component::internalFocusLoss (const FocusChangeType cause)
  33439. {
  33440. const ComponentDeletionWatcher deletionChecker (this);
  33441. focusLost (focusChangedDirectly);
  33442. if (! deletionChecker.hasBeenDeleted())
  33443. internalChildFocusChange (cause);
  33444. }
  33445. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  33446. {
  33447. // base class does nothing
  33448. }
  33449. void Component::internalChildFocusChange (FocusChangeType cause)
  33450. {
  33451. const bool childIsNowFocused = hasKeyboardFocus (true);
  33452. if (flags.childCompFocusedFlag != childIsNowFocused)
  33453. {
  33454. flags.childCompFocusedFlag = childIsNowFocused;
  33455. const ComponentDeletionWatcher deletionChecker (this);
  33456. focusOfChildComponentChanged (cause);
  33457. if (deletionChecker.hasBeenDeleted())
  33458. return;
  33459. }
  33460. if (parentComponent_ != 0)
  33461. parentComponent_->internalChildFocusChange (cause);
  33462. }
  33463. bool Component::isEnabled() const throw()
  33464. {
  33465. return (! flags.isDisabledFlag)
  33466. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33467. }
  33468. void Component::setEnabled (const bool shouldBeEnabled)
  33469. {
  33470. if (flags.isDisabledFlag == shouldBeEnabled)
  33471. {
  33472. flags.isDisabledFlag = ! shouldBeEnabled;
  33473. // if any parent components are disabled, setting our flag won't make a difference,
  33474. // so no need to send a change message
  33475. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33476. sendEnablementChangeMessage();
  33477. }
  33478. }
  33479. void Component::sendEnablementChangeMessage()
  33480. {
  33481. const ComponentDeletionWatcher deletionChecker (this);
  33482. enablementChanged();
  33483. if (deletionChecker.hasBeenDeleted())
  33484. return;
  33485. for (int i = getNumChildComponents(); --i >= 0;)
  33486. {
  33487. Component* const c = getChildComponent (i);
  33488. if (c != 0)
  33489. {
  33490. c->sendEnablementChangeMessage();
  33491. if (deletionChecker.hasBeenDeleted())
  33492. return;
  33493. }
  33494. }
  33495. }
  33496. void Component::enablementChanged()
  33497. {
  33498. }
  33499. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33500. {
  33501. flags.wantsFocusFlag = wantsFocus;
  33502. }
  33503. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33504. {
  33505. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33506. }
  33507. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33508. {
  33509. return ! flags.dontFocusOnMouseClickFlag;
  33510. }
  33511. bool Component::getWantsKeyboardFocus() const throw()
  33512. {
  33513. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33514. }
  33515. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33516. {
  33517. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33518. }
  33519. bool Component::isFocusContainer() const throw()
  33520. {
  33521. return flags.isFocusContainerFlag;
  33522. }
  33523. int Component::getExplicitFocusOrder() const throw()
  33524. {
  33525. return properties ["_jexfo"];
  33526. }
  33527. void Component::setExplicitFocusOrder (const int newFocusOrderIndex) throw()
  33528. {
  33529. properties.set ("_jexfo", newFocusOrderIndex);
  33530. }
  33531. KeyboardFocusTraverser* Component::createFocusTraverser()
  33532. {
  33533. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33534. return new KeyboardFocusTraverser();
  33535. return parentComponent_->createFocusTraverser();
  33536. }
  33537. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33538. {
  33539. // give the focus to this component
  33540. if (currentlyFocusedComponent != this)
  33541. {
  33542. JUCE_TRY
  33543. {
  33544. // get the focus onto our desktop window
  33545. ComponentPeer* const peer = getPeer();
  33546. if (peer != 0)
  33547. {
  33548. const ComponentDeletionWatcher deletionChecker (this);
  33549. peer->grabFocus();
  33550. if (peer->isFocused() && currentlyFocusedComponent != this)
  33551. {
  33552. Component* const componentLosingFocus = currentlyFocusedComponent;
  33553. currentlyFocusedComponent = this;
  33554. Desktop::getInstance().triggerFocusCallback();
  33555. // call this after setting currentlyFocusedComponent so that the one that's
  33556. // losing it has a chance to see where focus is going
  33557. if (componentLosingFocus->isValidComponent())
  33558. componentLosingFocus->internalFocusLoss (cause);
  33559. if (currentlyFocusedComponent == this)
  33560. {
  33561. focusGained (cause);
  33562. if (! deletionChecker.hasBeenDeleted())
  33563. internalChildFocusChange (cause);
  33564. }
  33565. }
  33566. }
  33567. }
  33568. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33569. catch (const std::exception& e)
  33570. {
  33571. currentlyFocusedComponent = 0;
  33572. Desktop::getInstance().triggerFocusCallback();
  33573. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33574. }
  33575. catch (...)
  33576. {
  33577. currentlyFocusedComponent = 0;
  33578. Desktop::getInstance().triggerFocusCallback();
  33579. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33580. }
  33581. #endif
  33582. }
  33583. }
  33584. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33585. {
  33586. if (isShowing())
  33587. {
  33588. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33589. {
  33590. takeKeyboardFocus (cause);
  33591. }
  33592. else
  33593. {
  33594. if (isParentOf (currentlyFocusedComponent)
  33595. && currentlyFocusedComponent->isShowing())
  33596. {
  33597. // do nothing if the focused component is actually a child of ours..
  33598. }
  33599. else
  33600. {
  33601. // find the default child component..
  33602. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33603. if (traverser != 0)
  33604. {
  33605. Component* const defaultComp = traverser->getDefaultComponent (this);
  33606. traverser = 0;
  33607. if (defaultComp != 0)
  33608. {
  33609. defaultComp->grabFocusInternal (cause, false);
  33610. return;
  33611. }
  33612. }
  33613. if (canTryParent && parentComponent_ != 0)
  33614. {
  33615. // if no children want it and we're allowed to try our parent comp,
  33616. // then pass up to parent, which will try our siblings.
  33617. parentComponent_->grabFocusInternal (cause, true);
  33618. }
  33619. }
  33620. }
  33621. }
  33622. }
  33623. void Component::grabKeyboardFocus()
  33624. {
  33625. // if component methods are being called from threads other than the message
  33626. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33627. checkMessageManagerIsLocked
  33628. grabFocusInternal (focusChangedDirectly);
  33629. }
  33630. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33631. {
  33632. // if component methods are being called from threads other than the message
  33633. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33634. checkMessageManagerIsLocked
  33635. if (parentComponent_ != 0)
  33636. {
  33637. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33638. if (traverser != 0)
  33639. {
  33640. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33641. : traverser->getPreviousComponent (this);
  33642. traverser = 0;
  33643. if (nextComp != 0)
  33644. {
  33645. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33646. {
  33647. const ComponentDeletionWatcher deletionChecker (nextComp);
  33648. internalModalInputAttempt();
  33649. if (deletionChecker.hasBeenDeleted()
  33650. || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33651. return;
  33652. }
  33653. nextComp->grabFocusInternal (focusChangedByTabKey);
  33654. return;
  33655. }
  33656. }
  33657. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33658. }
  33659. }
  33660. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const throw()
  33661. {
  33662. return (currentlyFocusedComponent == this)
  33663. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33664. }
  33665. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33666. {
  33667. return currentlyFocusedComponent;
  33668. }
  33669. void Component::giveAwayFocus()
  33670. {
  33671. // use a copy so we can clear the value before the call
  33672. Component* const componentLosingFocus = currentlyFocusedComponent;
  33673. currentlyFocusedComponent = 0;
  33674. Desktop::getInstance().triggerFocusCallback();
  33675. if (componentLosingFocus->isValidComponent())
  33676. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33677. }
  33678. bool Component::isMouseOver() const throw()
  33679. {
  33680. return flags.mouseOverFlag;
  33681. }
  33682. bool Component::isMouseButtonDown() const throw()
  33683. {
  33684. return flags.draggingFlag;
  33685. }
  33686. bool Component::isMouseOverOrDragging() const throw()
  33687. {
  33688. return flags.mouseOverFlag || flags.draggingFlag;
  33689. }
  33690. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33691. {
  33692. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33693. }
  33694. void Component::getMouseXYRelative (int& mx, int& my) const throw()
  33695. {
  33696. Desktop::getMousePosition (mx, my);
  33697. globalPositionToRelative (mx, my);
  33698. mx += unboundedMouseOffsetX;
  33699. my += unboundedMouseOffsetY;
  33700. }
  33701. void Component::enableUnboundedMouseMovement (bool enable,
  33702. bool keepCursorVisibleUntilOffscreen) throw()
  33703. {
  33704. enable = enable && isMouseButtonDown();
  33705. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  33706. if (enable != isUnboundedMouseModeOn)
  33707. {
  33708. if ((! enable) && ((! isCursorVisibleUntilOffscreen)
  33709. || unboundedMouseOffsetX != 0
  33710. || unboundedMouseOffsetY != 0))
  33711. {
  33712. // when released, return the mouse to within the component's bounds
  33713. int mx, my;
  33714. getMouseXYRelative (mx, my);
  33715. mx = jlimit (0, getWidth(), mx);
  33716. my = jlimit (0, getHeight(), my);
  33717. relativePositionToGlobal (mx, my);
  33718. Desktop::setMousePosition (mx, my);
  33719. }
  33720. isUnboundedMouseModeOn = enable;
  33721. unboundedMouseOffsetX = 0;
  33722. unboundedMouseOffsetY = 0;
  33723. internalUpdateMouseCursor (true);
  33724. }
  33725. }
  33726. Component* JUCE_CALLTYPE Component::getComponentUnderMouse() throw()
  33727. {
  33728. return componentUnderMouse;
  33729. }
  33730. const Rectangle<int> Component::getParentMonitorArea() const throw()
  33731. {
  33732. int centreX = getWidth() / 2;
  33733. int centreY = getHeight() / 2;
  33734. relativePositionToGlobal (centreX, centreY);
  33735. return Desktop::getInstance().getMonitorAreaContaining (centreX, centreY);
  33736. }
  33737. void Component::addKeyListener (KeyListener* const newListener) throw()
  33738. {
  33739. if (keyListeners_ == 0)
  33740. keyListeners_ = new VoidArray();
  33741. keyListeners_->addIfNotAlreadyThere (newListener);
  33742. }
  33743. void Component::removeKeyListener (KeyListener* const listenerToRemove) throw()
  33744. {
  33745. if (keyListeners_ != 0)
  33746. keyListeners_->removeValue (listenerToRemove);
  33747. }
  33748. bool Component::keyPressed (const KeyPress&)
  33749. {
  33750. return false;
  33751. }
  33752. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33753. {
  33754. return false;
  33755. }
  33756. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33757. {
  33758. if (parentComponent_ != 0)
  33759. parentComponent_->modifierKeysChanged (modifiers);
  33760. }
  33761. void Component::internalModifierKeysChanged()
  33762. {
  33763. sendFakeMouseMove();
  33764. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33765. }
  33766. ComponentPeer* Component::getPeer() const throw()
  33767. {
  33768. if (flags.hasHeavyweightPeerFlag)
  33769. return ComponentPeer::getPeerFor (this);
  33770. else if (parentComponent_ != 0)
  33771. return parentComponent_->getPeer();
  33772. else
  33773. return 0;
  33774. }
  33775. ComponentDeletionWatcher::ComponentDeletionWatcher (const Component* const componentToWatch_) throw()
  33776. : componentToWatch (componentToWatch_),
  33777. componentUID (componentToWatch_->getComponentUID())
  33778. {
  33779. // not possible to check on an already-deleted object..
  33780. jassert (componentToWatch_->isValidComponent());
  33781. }
  33782. ComponentDeletionWatcher::~ComponentDeletionWatcher() throw() {}
  33783. bool ComponentDeletionWatcher::hasBeenDeleted() const throw()
  33784. {
  33785. return ! (componentToWatch->isValidComponent()
  33786. && componentToWatch->getComponentUID() == componentUID);
  33787. }
  33788. const Component* ComponentDeletionWatcher::getComponent() const throw()
  33789. {
  33790. return hasBeenDeleted() ? 0 : componentToWatch;
  33791. }
  33792. END_JUCE_NAMESPACE
  33793. /*** End of inlined file: juce_Component.cpp ***/
  33794. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33795. BEGIN_JUCE_NAMESPACE
  33796. void ComponentListener::componentMovedOrResized (Component&, bool, bool)
  33797. {
  33798. }
  33799. void ComponentListener::componentBroughtToFront (Component&)
  33800. {
  33801. }
  33802. void ComponentListener::componentVisibilityChanged (Component&)
  33803. {
  33804. }
  33805. void ComponentListener::componentChildrenChanged (Component&)
  33806. {
  33807. }
  33808. void ComponentListener::componentParentHierarchyChanged (Component&)
  33809. {
  33810. }
  33811. void ComponentListener::componentNameChanged (Component&)
  33812. {
  33813. }
  33814. END_JUCE_NAMESPACE
  33815. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33816. /*** Start of inlined file: juce_Desktop.cpp ***/
  33817. BEGIN_JUCE_NAMESPACE
  33818. Desktop::Desktop() throw()
  33819. : lastFakeMouseMoveX (0),
  33820. lastFakeMouseMoveY (0),
  33821. mouseClickCounter (0),
  33822. mouseMovedSignificantlySincePressed (false),
  33823. kioskModeComponent (0)
  33824. {
  33825. zerostruct (mouseDowns);
  33826. refreshMonitorSizes();
  33827. }
  33828. Desktop::~Desktop() throw()
  33829. {
  33830. jassert (instance == this);
  33831. instance = 0;
  33832. // doh! If you don't delete all your windows before exiting, you're going to
  33833. // be leaking memory!
  33834. jassert (desktopComponents.size() == 0);
  33835. }
  33836. Desktop& JUCE_CALLTYPE Desktop::getInstance() throw()
  33837. {
  33838. if (instance == 0)
  33839. instance = new Desktop();
  33840. return *instance;
  33841. }
  33842. Desktop* Desktop::instance = 0;
  33843. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33844. const bool clipToWorkArea);
  33845. void Desktop::refreshMonitorSizes() throw()
  33846. {
  33847. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33848. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33849. monitorCoordsClipped.clear();
  33850. monitorCoordsUnclipped.clear();
  33851. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33852. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33853. jassert (monitorCoordsClipped.size() > 0
  33854. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33855. if (oldClipped != monitorCoordsClipped
  33856. || oldUnclipped != monitorCoordsUnclipped)
  33857. {
  33858. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33859. {
  33860. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33861. if (p != 0)
  33862. p->handleScreenSizeChange();
  33863. }
  33864. }
  33865. }
  33866. int Desktop::getNumDisplayMonitors() const throw()
  33867. {
  33868. return monitorCoordsClipped.size();
  33869. }
  33870. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33871. {
  33872. return clippedToWorkArea ? monitorCoordsClipped [index]
  33873. : monitorCoordsUnclipped [index];
  33874. }
  33875. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33876. {
  33877. RectangleList rl;
  33878. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33879. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33880. return rl;
  33881. }
  33882. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33883. {
  33884. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33885. }
  33886. const Rectangle<int> Desktop::getMonitorAreaContaining (int cx, int cy, const bool clippedToWorkArea) const throw()
  33887. {
  33888. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33889. double bestDistance = 1.0e10;
  33890. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33891. {
  33892. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33893. if (rect.contains (cx, cy))
  33894. return rect;
  33895. const double distance = juce_hypot ((double) (rect.getCentreX() - cx),
  33896. (double) (rect.getCentreY() - cy));
  33897. if (distance < bestDistance)
  33898. {
  33899. bestDistance = distance;
  33900. best = rect;
  33901. }
  33902. }
  33903. return best;
  33904. }
  33905. int Desktop::getNumComponents() const throw()
  33906. {
  33907. return desktopComponents.size();
  33908. }
  33909. Component* Desktop::getComponent (const int index) const throw()
  33910. {
  33911. return desktopComponents [index];
  33912. }
  33913. Component* Desktop::findComponentAt (const int screenX,
  33914. const int screenY) const
  33915. {
  33916. for (int i = desktopComponents.size(); --i >= 0;)
  33917. {
  33918. Component* const c = desktopComponents.getUnchecked(i);
  33919. int x = screenX, y = screenY;
  33920. c->globalPositionToRelative (x, y);
  33921. if (c->contains (x, y))
  33922. return c->getComponentAt (x, y);
  33923. }
  33924. return 0;
  33925. }
  33926. void Desktop::addDesktopComponent (Component* const c) throw()
  33927. {
  33928. jassert (c != 0);
  33929. jassert (! desktopComponents.contains (c));
  33930. desktopComponents.addIfNotAlreadyThere (c);
  33931. }
  33932. void Desktop::removeDesktopComponent (Component* const c) throw()
  33933. {
  33934. desktopComponents.removeValue (c);
  33935. }
  33936. void Desktop::componentBroughtToFront (Component* const c) throw()
  33937. {
  33938. const int index = desktopComponents.indexOf (c);
  33939. jassert (index >= 0);
  33940. if (index >= 0)
  33941. {
  33942. int newIndex = -1;
  33943. if (! c->isAlwaysOnTop())
  33944. {
  33945. newIndex = desktopComponents.size();
  33946. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33947. --newIndex;
  33948. --newIndex;
  33949. }
  33950. desktopComponents.move (index, newIndex);
  33951. }
  33952. }
  33953. void Desktop::getLastMouseDownPosition (int& x, int& y) throw()
  33954. {
  33955. const Desktop& d = getInstance();
  33956. x = d.mouseDowns[0].position.getX();
  33957. y = d.mouseDowns[0].position.getY();
  33958. }
  33959. int Desktop::getMouseButtonClickCounter() throw()
  33960. {
  33961. return getInstance().mouseClickCounter;
  33962. }
  33963. void Desktop::incrementMouseClickCounter() throw()
  33964. {
  33965. ++mouseClickCounter;
  33966. }
  33967. const Time Desktop::getLastMouseDownTime() const throw()
  33968. {
  33969. return Time (mouseDowns[0].time);
  33970. }
  33971. void Desktop::registerMouseDown (const Point<int>& position, int64 time, Component* component) throw()
  33972. {
  33973. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  33974. mouseDowns[i] = mouseDowns[i - 1];
  33975. mouseDowns[0].position = position;
  33976. mouseDowns[0].time = time;
  33977. mouseDowns[0].component = component;
  33978. mouseMovedSignificantlySincePressed = false;
  33979. }
  33980. void Desktop::registerMouseDrag (const Point<int>& position) throw()
  33981. {
  33982. mouseMovedSignificantlySincePressed
  33983. = mouseMovedSignificantlySincePressed
  33984. || abs (mouseDowns[0].position.getX() - position.getX()) >= 4
  33985. || abs (mouseDowns[0].position.getY() - position.getY()) >= 4;
  33986. }
  33987. int Desktop::getNumberOfMultipleClicks() const throw()
  33988. {
  33989. int numClicks = 0;
  33990. if (mouseDowns[0].time != 0)
  33991. {
  33992. if (! mouseMovedSignificantlySincePressed)
  33993. ++numClicks;
  33994. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  33995. {
  33996. if (mouseDowns[0].time - mouseDowns[i].time
  33997. < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  33998. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  33999. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  34000. && mouseDowns[0].component == mouseDowns[i].component)
  34001. {
  34002. ++numClicks;
  34003. }
  34004. else
  34005. {
  34006. break;
  34007. }
  34008. }
  34009. }
  34010. return numClicks;
  34011. }
  34012. void Desktop::addGlobalMouseListener (MouseListener* const listener) throw()
  34013. {
  34014. jassert (listener != 0);
  34015. if (listener != 0)
  34016. {
  34017. mouseListeners.add (listener);
  34018. resetTimer();
  34019. }
  34020. }
  34021. void Desktop::removeGlobalMouseListener (MouseListener* const listener) throw()
  34022. {
  34023. mouseListeners.removeValue (listener);
  34024. resetTimer();
  34025. }
  34026. void Desktop::addFocusChangeListener (FocusChangeListener* const listener) throw()
  34027. {
  34028. jassert (listener != 0);
  34029. if (listener != 0)
  34030. focusListeners.add (listener);
  34031. }
  34032. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener) throw()
  34033. {
  34034. focusListeners.removeValue (listener);
  34035. }
  34036. void Desktop::triggerFocusCallback() throw()
  34037. {
  34038. triggerAsyncUpdate();
  34039. }
  34040. void Desktop::handleAsyncUpdate()
  34041. {
  34042. for (int i = focusListeners.size(); --i >= 0;)
  34043. {
  34044. ((FocusChangeListener*) focusListeners.getUnchecked (i))->globalFocusChanged (Component::getCurrentlyFocusedComponent());
  34045. i = jmin (i, focusListeners.size());
  34046. }
  34047. }
  34048. void Desktop::timerCallback()
  34049. {
  34050. int x, y;
  34051. getMousePosition (x, y);
  34052. if (lastFakeMouseMoveX != x || lastFakeMouseMoveY != y)
  34053. sendMouseMove();
  34054. }
  34055. void Desktop::sendMouseMove()
  34056. {
  34057. if (mouseListeners.size() > 0)
  34058. {
  34059. startTimer (20);
  34060. int x, y;
  34061. getMousePosition (x, y);
  34062. lastFakeMouseMoveX = x;
  34063. lastFakeMouseMoveY = y;
  34064. Component* const target = findComponentAt (x, y);
  34065. if (target != 0)
  34066. {
  34067. target->globalPositionToRelative (x, y);
  34068. ComponentDeletionWatcher deletionChecker (target);
  34069. const MouseEvent me (x, y,
  34070. ModifierKeys::getCurrentModifiers(),
  34071. target,
  34072. Time::getCurrentTime(),
  34073. x, y,
  34074. Time::getCurrentTime(),
  34075. 0, false);
  34076. for (int i = mouseListeners.size(); --i >= 0;)
  34077. {
  34078. if (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  34079. ((MouseListener*) mouseListeners[i])->mouseDrag (me);
  34080. else
  34081. ((MouseListener*) mouseListeners[i])->mouseMove (me);
  34082. if (deletionChecker.hasBeenDeleted())
  34083. return;
  34084. i = jmin (i, mouseListeners.size());
  34085. }
  34086. }
  34087. }
  34088. }
  34089. void Desktop::resetTimer() throw()
  34090. {
  34091. if (mouseListeners.size() == 0)
  34092. stopTimer();
  34093. else
  34094. startTimer (100);
  34095. getMousePosition (lastFakeMouseMoveX, lastFakeMouseMoveY);
  34096. }
  34097. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  34098. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  34099. {
  34100. if (kioskModeComponent != componentToUse)
  34101. {
  34102. // agh! Don't delete a component without first stopping it being the kiosk comp
  34103. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  34104. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  34105. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  34106. if (kioskModeComponent->isValidComponent())
  34107. {
  34108. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  34109. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  34110. }
  34111. kioskModeComponent = componentToUse;
  34112. if (kioskModeComponent != 0)
  34113. {
  34114. jassert (kioskModeComponent->isValidComponent());
  34115. // Only components that are already on the desktop can be put into kiosk mode!
  34116. jassert (kioskModeComponent->isOnDesktop());
  34117. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  34118. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  34119. }
  34120. }
  34121. }
  34122. END_JUCE_NAMESPACE
  34123. /*** End of inlined file: juce_Desktop.cpp ***/
  34124. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  34125. BEGIN_JUCE_NAMESPACE
  34126. ArrowButton::ArrowButton (const String& name,
  34127. float arrowDirectionInRadians,
  34128. const Colour& arrowColour)
  34129. : Button (name),
  34130. colour (arrowColour)
  34131. {
  34132. path.lineTo (0.0f, 1.0f);
  34133. path.lineTo (1.0f, 0.5f);
  34134. path.closeSubPath();
  34135. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  34136. 0.5f, 0.5f));
  34137. setComponentEffect (&shadow);
  34138. buttonStateChanged();
  34139. }
  34140. ArrowButton::~ArrowButton()
  34141. {
  34142. }
  34143. void ArrowButton::paintButton (Graphics& g,
  34144. bool /*isMouseOverButton*/,
  34145. bool /*isButtonDown*/)
  34146. {
  34147. g.setColour (colour);
  34148. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  34149. (float) offset,
  34150. (float) (getWidth() - 3),
  34151. (float) (getHeight() - 3),
  34152. false));
  34153. }
  34154. void ArrowButton::buttonStateChanged()
  34155. {
  34156. offset = (isDown()) ? 1 : 0;
  34157. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  34158. 0.3f, -1, 0);
  34159. }
  34160. END_JUCE_NAMESPACE
  34161. /*** End of inlined file: juce_ArrowButton.cpp ***/
  34162. /*** Start of inlined file: juce_Button.cpp ***/
  34163. BEGIN_JUCE_NAMESPACE
  34164. class Button::RepeatTimer : public Timer
  34165. {
  34166. public:
  34167. RepeatTimer (Button& owner_) : owner (owner_) {}
  34168. void timerCallback() { owner.repeatTimerCallback(); }
  34169. juce_UseDebuggingNewOperator
  34170. private:
  34171. Button& owner;
  34172. RepeatTimer (const RepeatTimer&);
  34173. RepeatTimer& operator= (const RepeatTimer&);
  34174. };
  34175. Button::Button (const String& name)
  34176. : Component (name),
  34177. keySource (0),
  34178. text (name),
  34179. buttonPressTime (0),
  34180. lastTimeCallbackTime (0),
  34181. commandManagerToUse (0),
  34182. autoRepeatDelay (-1),
  34183. autoRepeatSpeed (0),
  34184. autoRepeatMinimumDelay (-1),
  34185. radioGroupId (0),
  34186. commandID (0),
  34187. connectedEdgeFlags (0),
  34188. buttonState (buttonNormal),
  34189. lastToggleState (false),
  34190. clickTogglesState (false),
  34191. needsToRelease (false),
  34192. needsRepainting (false),
  34193. isKeyDown (false),
  34194. triggerOnMouseDown (false),
  34195. generateTooltip (false)
  34196. {
  34197. setWantsKeyboardFocus (true);
  34198. isOn.addListener (this);
  34199. }
  34200. Button::~Button()
  34201. {
  34202. isOn.removeListener (this);
  34203. if (commandManagerToUse != 0)
  34204. commandManagerToUse->removeListener (this);
  34205. repeatTimer = 0;
  34206. clearShortcuts();
  34207. }
  34208. void Button::setButtonText (const String& newText)
  34209. {
  34210. if (text != newText)
  34211. {
  34212. text = newText;
  34213. repaint();
  34214. }
  34215. }
  34216. void Button::setTooltip (const String& newTooltip)
  34217. {
  34218. SettableTooltipClient::setTooltip (newTooltip);
  34219. generateTooltip = false;
  34220. }
  34221. const String Button::getTooltip()
  34222. {
  34223. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  34224. {
  34225. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  34226. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  34227. for (int i = 0; i < keyPresses.size(); ++i)
  34228. {
  34229. const String key (keyPresses.getReference(i).getTextDescription());
  34230. tt << " [";
  34231. if (key.length() == 1)
  34232. tt << TRANS("shortcut") << ": '" << key << "']";
  34233. else
  34234. tt << key << ']';
  34235. }
  34236. return tt;
  34237. }
  34238. return SettableTooltipClient::getTooltip();
  34239. }
  34240. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  34241. {
  34242. if (connectedEdgeFlags != connectedEdgeFlags_)
  34243. {
  34244. connectedEdgeFlags = connectedEdgeFlags_;
  34245. repaint();
  34246. }
  34247. }
  34248. void Button::setToggleState (const bool shouldBeOn,
  34249. const bool sendChangeNotification)
  34250. {
  34251. if (shouldBeOn != lastToggleState)
  34252. {
  34253. const ComponentDeletionWatcher deletionWatcher (this);
  34254. isOn = shouldBeOn;
  34255. lastToggleState = shouldBeOn;
  34256. repaint();
  34257. if (sendChangeNotification)
  34258. sendClickMessage (ModifierKeys());
  34259. if ((! deletionWatcher.hasBeenDeleted()) && lastToggleState)
  34260. turnOffOtherButtonsInGroup (sendChangeNotification);
  34261. }
  34262. }
  34263. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  34264. {
  34265. clickTogglesState = shouldToggle;
  34266. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34267. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34268. // it is that this button represents, and the button will update its state to reflect this
  34269. // in the applicationCommandListChanged() method.
  34270. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34271. }
  34272. bool Button::getClickingTogglesState() const throw()
  34273. {
  34274. return clickTogglesState;
  34275. }
  34276. void Button::valueChanged (Value& value)
  34277. {
  34278. if (value.refersToSameSourceAs (isOn))
  34279. setToggleState (isOn.getValue(), true);
  34280. }
  34281. void Button::setRadioGroupId (const int newGroupId)
  34282. {
  34283. if (radioGroupId != newGroupId)
  34284. {
  34285. radioGroupId = newGroupId;
  34286. if (lastToggleState)
  34287. turnOffOtherButtonsInGroup (true);
  34288. }
  34289. }
  34290. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  34291. {
  34292. Component* const p = getParentComponent();
  34293. if (p != 0 && radioGroupId != 0)
  34294. {
  34295. const ComponentDeletionWatcher deletionWatcher (this);
  34296. for (int i = p->getNumChildComponents(); --i >= 0;)
  34297. {
  34298. Component* const c = p->getChildComponent (i);
  34299. if (c != this)
  34300. {
  34301. Button* const b = dynamic_cast <Button*> (c);
  34302. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  34303. {
  34304. b->setToggleState (false, sendChangeNotification);
  34305. if (deletionWatcher.hasBeenDeleted())
  34306. return;
  34307. }
  34308. }
  34309. }
  34310. }
  34311. }
  34312. void Button::enablementChanged()
  34313. {
  34314. updateState (0);
  34315. repaint();
  34316. }
  34317. Button::ButtonState Button::updateState (const MouseEvent* const e)
  34318. {
  34319. ButtonState state = buttonNormal;
  34320. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  34321. {
  34322. int mx, my;
  34323. if (e == 0)
  34324. {
  34325. getMouseXYRelative (mx, my);
  34326. }
  34327. else
  34328. {
  34329. const MouseEvent e2 (e->getEventRelativeTo (this));
  34330. mx = e2.x;
  34331. my = e2.y;
  34332. }
  34333. const bool over = reallyContains (mx, my, true);
  34334. const bool down = isMouseButtonDown();
  34335. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  34336. state = buttonDown;
  34337. else if (over)
  34338. state = buttonOver;
  34339. }
  34340. setState (state);
  34341. return state;
  34342. }
  34343. void Button::setState (const ButtonState newState)
  34344. {
  34345. if (buttonState != newState)
  34346. {
  34347. buttonState = newState;
  34348. repaint();
  34349. if (buttonState == buttonDown)
  34350. {
  34351. buttonPressTime = Time::getApproximateMillisecondCounter();
  34352. lastTimeCallbackTime = buttonPressTime;
  34353. }
  34354. sendStateMessage();
  34355. }
  34356. }
  34357. bool Button::isDown() const throw()
  34358. {
  34359. return buttonState == buttonDown;
  34360. }
  34361. bool Button::isOver() const throw()
  34362. {
  34363. return buttonState != buttonNormal;
  34364. }
  34365. void Button::buttonStateChanged()
  34366. {
  34367. }
  34368. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  34369. {
  34370. const uint32 now = Time::getApproximateMillisecondCounter();
  34371. return now > buttonPressTime ? now - buttonPressTime : 0;
  34372. }
  34373. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  34374. {
  34375. triggerOnMouseDown = isTriggeredOnMouseDown;
  34376. }
  34377. void Button::clicked()
  34378. {
  34379. }
  34380. void Button::clicked (const ModifierKeys& /*modifiers*/)
  34381. {
  34382. clicked();
  34383. }
  34384. static const int clickMessageId = 0x2f3f4f99;
  34385. void Button::triggerClick()
  34386. {
  34387. postCommandMessage (clickMessageId);
  34388. }
  34389. void Button::internalClickCallback (const ModifierKeys& modifiers)
  34390. {
  34391. if (clickTogglesState)
  34392. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  34393. sendClickMessage (modifiers);
  34394. }
  34395. void Button::flashButtonState()
  34396. {
  34397. if (isEnabled())
  34398. {
  34399. needsToRelease = true;
  34400. setState (buttonDown);
  34401. getRepeatTimer().startTimer (100);
  34402. }
  34403. }
  34404. void Button::handleCommandMessage (int commandId)
  34405. {
  34406. if (commandId == clickMessageId)
  34407. {
  34408. if (isEnabled())
  34409. {
  34410. flashButtonState();
  34411. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34412. }
  34413. }
  34414. else
  34415. {
  34416. Component::handleCommandMessage (commandId);
  34417. }
  34418. }
  34419. void Button::addButtonListener (ButtonListener* const newListener)
  34420. {
  34421. jassert (newListener != 0);
  34422. jassert (! buttonListeners.contains (newListener)); // trying to add a listener to the list twice!
  34423. if (newListener != 0)
  34424. buttonListeners.add (newListener);
  34425. }
  34426. void Button::removeButtonListener (ButtonListener* const listener)
  34427. {
  34428. jassert (buttonListeners.contains (listener)); // trying to remove a listener that isn't on the list!
  34429. buttonListeners.removeValue (listener);
  34430. }
  34431. void Button::sendClickMessage (const ModifierKeys& modifiers)
  34432. {
  34433. const ComponentDeletionWatcher cdw (this);
  34434. if (commandManagerToUse != 0 && commandID != 0)
  34435. {
  34436. ApplicationCommandTarget::InvocationInfo info (commandID);
  34437. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  34438. info.originatingComponent = this;
  34439. commandManagerToUse->invoke (info, true);
  34440. }
  34441. clicked (modifiers);
  34442. if (! cdw.hasBeenDeleted())
  34443. {
  34444. for (int i = buttonListeners.size(); --i >= 0;)
  34445. {
  34446. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34447. if (bl != 0)
  34448. {
  34449. bl->buttonClicked (this);
  34450. if (cdw.hasBeenDeleted())
  34451. return;
  34452. }
  34453. }
  34454. }
  34455. }
  34456. void Button::sendStateMessage()
  34457. {
  34458. const ComponentDeletionWatcher cdw (this);
  34459. buttonStateChanged();
  34460. if (cdw.hasBeenDeleted())
  34461. return;
  34462. for (int i = buttonListeners.size(); --i >= 0;)
  34463. {
  34464. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34465. if (bl != 0)
  34466. {
  34467. bl->buttonStateChanged (this);
  34468. if (cdw.hasBeenDeleted())
  34469. return;
  34470. }
  34471. }
  34472. }
  34473. void Button::paint (Graphics& g)
  34474. {
  34475. if (needsToRelease && isEnabled())
  34476. {
  34477. needsToRelease = false;
  34478. needsRepainting = true;
  34479. }
  34480. paintButton (g, isOver(), isDown());
  34481. }
  34482. void Button::mouseEnter (const MouseEvent& e)
  34483. {
  34484. updateState (&e);
  34485. }
  34486. void Button::mouseExit (const MouseEvent& e)
  34487. {
  34488. updateState (&e);
  34489. }
  34490. void Button::mouseDown (const MouseEvent& e)
  34491. {
  34492. updateState (&e);
  34493. if (isDown())
  34494. {
  34495. if (autoRepeatDelay >= 0)
  34496. getRepeatTimer().startTimer (autoRepeatDelay);
  34497. if (triggerOnMouseDown)
  34498. internalClickCallback (e.mods);
  34499. }
  34500. }
  34501. void Button::mouseUp (const MouseEvent& e)
  34502. {
  34503. const bool wasDown = isDown();
  34504. updateState (&e);
  34505. if (wasDown && isOver() && ! triggerOnMouseDown)
  34506. internalClickCallback (e.mods);
  34507. }
  34508. void Button::mouseDrag (const MouseEvent& e)
  34509. {
  34510. const ButtonState oldState = buttonState;
  34511. updateState (&e);
  34512. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  34513. getRepeatTimer().startTimer (autoRepeatSpeed);
  34514. }
  34515. void Button::focusGained (FocusChangeType)
  34516. {
  34517. updateState (0);
  34518. repaint();
  34519. }
  34520. void Button::focusLost (FocusChangeType)
  34521. {
  34522. updateState (0);
  34523. repaint();
  34524. }
  34525. void Button::setVisible (bool shouldBeVisible)
  34526. {
  34527. if (shouldBeVisible != isVisible())
  34528. {
  34529. Component::setVisible (shouldBeVisible);
  34530. if (! shouldBeVisible)
  34531. needsToRelease = false;
  34532. updateState (0);
  34533. }
  34534. else
  34535. {
  34536. Component::setVisible (shouldBeVisible);
  34537. }
  34538. }
  34539. void Button::parentHierarchyChanged()
  34540. {
  34541. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  34542. if (newKeySource != keySource)
  34543. {
  34544. if (keySource->isValidComponent())
  34545. keySource->removeKeyListener (this);
  34546. keySource = newKeySource;
  34547. if (keySource->isValidComponent())
  34548. keySource->addKeyListener (this);
  34549. }
  34550. }
  34551. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  34552. const int commandID_,
  34553. const bool generateTooltip_)
  34554. {
  34555. commandID = commandID_;
  34556. generateTooltip = generateTooltip_;
  34557. if (commandManagerToUse != commandManagerToUse_)
  34558. {
  34559. if (commandManagerToUse != 0)
  34560. commandManagerToUse->removeListener (this);
  34561. commandManagerToUse = commandManagerToUse_;
  34562. if (commandManagerToUse != 0)
  34563. commandManagerToUse->addListener (this);
  34564. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34565. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34566. // it is that this button represents, and the button will update its state to reflect this
  34567. // in the applicationCommandListChanged() method.
  34568. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34569. }
  34570. if (commandManagerToUse != 0)
  34571. applicationCommandListChanged();
  34572. else
  34573. setEnabled (true);
  34574. }
  34575. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  34576. {
  34577. if (info.commandID == commandID
  34578. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  34579. {
  34580. flashButtonState();
  34581. }
  34582. }
  34583. void Button::applicationCommandListChanged()
  34584. {
  34585. if (commandManagerToUse != 0)
  34586. {
  34587. ApplicationCommandInfo info (0);
  34588. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  34589. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  34590. if (target != 0)
  34591. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  34592. }
  34593. }
  34594. void Button::addShortcut (const KeyPress& key)
  34595. {
  34596. if (key.isValid())
  34597. {
  34598. jassert (! isRegisteredForShortcut (key)); // already registered!
  34599. shortcuts.add (key);
  34600. parentHierarchyChanged();
  34601. }
  34602. }
  34603. void Button::clearShortcuts()
  34604. {
  34605. shortcuts.clear();
  34606. parentHierarchyChanged();
  34607. }
  34608. bool Button::isShortcutPressed() const
  34609. {
  34610. if (! isCurrentlyBlockedByAnotherModalComponent())
  34611. {
  34612. for (int i = shortcuts.size(); --i >= 0;)
  34613. if (shortcuts.getReference(i).isCurrentlyDown())
  34614. return true;
  34615. }
  34616. return false;
  34617. }
  34618. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  34619. {
  34620. for (int i = shortcuts.size(); --i >= 0;)
  34621. if (key == shortcuts.getReference(i))
  34622. return true;
  34623. return false;
  34624. }
  34625. bool Button::keyStateChanged (const bool, Component*)
  34626. {
  34627. if (! isEnabled())
  34628. return false;
  34629. const bool wasDown = isKeyDown;
  34630. isKeyDown = isShortcutPressed();
  34631. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34632. getRepeatTimer().startTimer (autoRepeatDelay);
  34633. updateState (0);
  34634. if (isEnabled() && wasDown && ! isKeyDown)
  34635. {
  34636. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34637. // (return immediately - this button may now have been deleted)
  34638. return true;
  34639. }
  34640. return wasDown || isKeyDown;
  34641. }
  34642. bool Button::keyPressed (const KeyPress&, Component*)
  34643. {
  34644. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34645. return isShortcutPressed();
  34646. }
  34647. bool Button::keyPressed (const KeyPress& key)
  34648. {
  34649. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34650. {
  34651. triggerClick();
  34652. return true;
  34653. }
  34654. return false;
  34655. }
  34656. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34657. const int repeatMillisecs,
  34658. const int minimumDelayInMillisecs) throw()
  34659. {
  34660. autoRepeatDelay = initialDelayMillisecs;
  34661. autoRepeatSpeed = repeatMillisecs;
  34662. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34663. }
  34664. void Button::repeatTimerCallback()
  34665. {
  34666. if (needsRepainting)
  34667. {
  34668. getRepeatTimer().stopTimer();
  34669. updateState (0);
  34670. needsRepainting = false;
  34671. }
  34672. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34673. {
  34674. int repeatSpeed = autoRepeatSpeed;
  34675. if (autoRepeatMinimumDelay >= 0)
  34676. {
  34677. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34678. timeHeldDown *= timeHeldDown;
  34679. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34680. }
  34681. repeatSpeed = jmax (1, repeatSpeed);
  34682. getRepeatTimer().startTimer (repeatSpeed);
  34683. const uint32 now = Time::getApproximateMillisecondCounter();
  34684. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34685. lastTimeCallbackTime = now;
  34686. const ComponentDeletionWatcher cdw (this);
  34687. for (int i = numTimesToCallback; --i >= 0;)
  34688. {
  34689. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34690. if (cdw.hasBeenDeleted() || ! isDown())
  34691. return;
  34692. }
  34693. }
  34694. else if (! needsToRelease)
  34695. {
  34696. getRepeatTimer().stopTimer();
  34697. }
  34698. }
  34699. Button::RepeatTimer& Button::getRepeatTimer()
  34700. {
  34701. if (repeatTimer == 0)
  34702. repeatTimer = new RepeatTimer (*this);
  34703. return *repeatTimer;
  34704. }
  34705. END_JUCE_NAMESPACE
  34706. /*** End of inlined file: juce_Button.cpp ***/
  34707. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34708. BEGIN_JUCE_NAMESPACE
  34709. DrawableButton::DrawableButton (const String& name,
  34710. const DrawableButton::ButtonStyle buttonStyle)
  34711. : Button (name),
  34712. style (buttonStyle),
  34713. edgeIndent (3)
  34714. {
  34715. if (buttonStyle == ImageOnButtonBackground)
  34716. {
  34717. backgroundOff = Colour (0xffbbbbff);
  34718. backgroundOn = Colour (0xff3333ff);
  34719. }
  34720. else
  34721. {
  34722. backgroundOff = Colours::transparentBlack;
  34723. backgroundOn = Colour (0xaabbbbff);
  34724. }
  34725. }
  34726. DrawableButton::~DrawableButton()
  34727. {
  34728. deleteImages();
  34729. }
  34730. void DrawableButton::deleteImages()
  34731. {
  34732. }
  34733. void DrawableButton::setImages (const Drawable* normal,
  34734. const Drawable* over,
  34735. const Drawable* down,
  34736. const Drawable* disabled,
  34737. const Drawable* normalOn,
  34738. const Drawable* overOn,
  34739. const Drawable* downOn,
  34740. const Drawable* disabledOn)
  34741. {
  34742. deleteImages();
  34743. jassert (normal != 0); // you really need to give it at least a normal image..
  34744. if (normal != 0)
  34745. normalImage = normal->createCopy();
  34746. if (over != 0)
  34747. overImage = over->createCopy();
  34748. if (down != 0)
  34749. downImage = down->createCopy();
  34750. if (disabled != 0)
  34751. disabledImage = disabled->createCopy();
  34752. if (normalOn != 0)
  34753. normalImageOn = normalOn->createCopy();
  34754. if (overOn != 0)
  34755. overImageOn = overOn->createCopy();
  34756. if (downOn != 0)
  34757. downImageOn = downOn->createCopy();
  34758. if (disabledOn != 0)
  34759. disabledImageOn = disabledOn->createCopy();
  34760. repaint();
  34761. }
  34762. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34763. {
  34764. if (style != newStyle)
  34765. {
  34766. style = newStyle;
  34767. repaint();
  34768. }
  34769. }
  34770. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34771. const Colour& toggledOnColour)
  34772. {
  34773. if (backgroundOff != toggledOffColour
  34774. || backgroundOn != toggledOnColour)
  34775. {
  34776. backgroundOff = toggledOffColour;
  34777. backgroundOn = toggledOnColour;
  34778. repaint();
  34779. }
  34780. }
  34781. const Colour& DrawableButton::getBackgroundColour() const throw()
  34782. {
  34783. return getToggleState() ? backgroundOn
  34784. : backgroundOff;
  34785. }
  34786. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34787. {
  34788. edgeIndent = numPixelsIndent;
  34789. repaint();
  34790. }
  34791. void DrawableButton::paintButton (Graphics& g,
  34792. bool isMouseOverButton,
  34793. bool isButtonDown)
  34794. {
  34795. Rectangle<int> imageSpace;
  34796. if (style == ImageOnButtonBackground)
  34797. {
  34798. const int insetX = getWidth() / 4;
  34799. const int insetY = getHeight() / 4;
  34800. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34801. getLookAndFeel().drawButtonBackground (g, *this,
  34802. getBackgroundColour(),
  34803. isMouseOverButton,
  34804. isButtonDown);
  34805. }
  34806. else
  34807. {
  34808. g.fillAll (getBackgroundColour());
  34809. const int textH = (style == ImageAboveTextLabel)
  34810. ? jmin (16, proportionOfHeight (0.25f))
  34811. : 0;
  34812. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34813. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34814. imageSpace.setBounds (indentX, indentY,
  34815. getWidth() - indentX * 2,
  34816. getHeight() - indentY * 2 - textH);
  34817. if (textH > 0)
  34818. {
  34819. g.setFont ((float) textH);
  34820. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34821. g.drawFittedText (getButtonText(),
  34822. 2, getHeight() - textH - 1,
  34823. getWidth() - 4, textH,
  34824. Justification::centred, 1);
  34825. }
  34826. }
  34827. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34828. g.setOpacity (1.0f);
  34829. const Drawable* imageToDraw = 0;
  34830. if (isEnabled())
  34831. {
  34832. imageToDraw = getCurrentImage();
  34833. }
  34834. else
  34835. {
  34836. imageToDraw = getToggleState() ? disabledImageOn
  34837. : disabledImage;
  34838. if (imageToDraw == 0)
  34839. {
  34840. g.setOpacity (0.4f);
  34841. imageToDraw = getNormalImage();
  34842. }
  34843. }
  34844. if (imageToDraw != 0)
  34845. {
  34846. if (style == ImageRaw)
  34847. {
  34848. imageToDraw->draw (g, 1.0f);
  34849. }
  34850. else
  34851. {
  34852. imageToDraw->drawWithin (g,
  34853. imageSpace.getX(),
  34854. imageSpace.getY(),
  34855. imageSpace.getWidth(),
  34856. imageSpace.getHeight(),
  34857. RectanglePlacement::centred,
  34858. 1.0f);
  34859. }
  34860. }
  34861. }
  34862. const Drawable* DrawableButton::getCurrentImage() const throw()
  34863. {
  34864. if (isDown())
  34865. return getDownImage();
  34866. if (isOver())
  34867. return getOverImage();
  34868. return getNormalImage();
  34869. }
  34870. const Drawable* DrawableButton::getNormalImage() const throw()
  34871. {
  34872. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34873. : normalImage;
  34874. }
  34875. const Drawable* DrawableButton::getOverImage() const throw()
  34876. {
  34877. const Drawable* d = normalImage;
  34878. if (getToggleState())
  34879. {
  34880. if (overImageOn != 0)
  34881. d = overImageOn;
  34882. else if (normalImageOn != 0)
  34883. d = normalImageOn;
  34884. else if (overImage != 0)
  34885. d = overImage;
  34886. }
  34887. else
  34888. {
  34889. if (overImage != 0)
  34890. d = overImage;
  34891. }
  34892. return d;
  34893. }
  34894. const Drawable* DrawableButton::getDownImage() const throw()
  34895. {
  34896. const Drawable* d = normalImage;
  34897. if (getToggleState())
  34898. {
  34899. if (downImageOn != 0)
  34900. d = downImageOn;
  34901. else if (overImageOn != 0)
  34902. d = overImageOn;
  34903. else if (normalImageOn != 0)
  34904. d = normalImageOn;
  34905. else if (downImage != 0)
  34906. d = downImage;
  34907. else
  34908. d = getOverImage();
  34909. }
  34910. else
  34911. {
  34912. if (downImage != 0)
  34913. d = downImage;
  34914. else
  34915. d = getOverImage();
  34916. }
  34917. return d;
  34918. }
  34919. END_JUCE_NAMESPACE
  34920. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34921. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34922. BEGIN_JUCE_NAMESPACE
  34923. HyperlinkButton::HyperlinkButton (const String& linkText,
  34924. const URL& linkURL)
  34925. : Button (linkText),
  34926. url (linkURL),
  34927. font (14.0f, Font::underlined),
  34928. resizeFont (true),
  34929. justification (Justification::centred)
  34930. {
  34931. setMouseCursor (MouseCursor::PointingHandCursor);
  34932. setTooltip (linkURL.toString (false));
  34933. }
  34934. HyperlinkButton::~HyperlinkButton()
  34935. {
  34936. }
  34937. void HyperlinkButton::setFont (const Font& newFont,
  34938. const bool resizeToMatchComponentHeight,
  34939. const Justification& justificationType)
  34940. {
  34941. font = newFont;
  34942. resizeFont = resizeToMatchComponentHeight;
  34943. justification = justificationType;
  34944. repaint();
  34945. }
  34946. void HyperlinkButton::setURL (const URL& newURL) throw()
  34947. {
  34948. url = newURL;
  34949. setTooltip (newURL.toString (false));
  34950. }
  34951. const Font HyperlinkButton::getFontToUse() const
  34952. {
  34953. Font f (font);
  34954. if (resizeFont)
  34955. f.setHeight (getHeight() * 0.7f);
  34956. return f;
  34957. }
  34958. void HyperlinkButton::changeWidthToFitText()
  34959. {
  34960. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34961. }
  34962. void HyperlinkButton::colourChanged()
  34963. {
  34964. repaint();
  34965. }
  34966. void HyperlinkButton::clicked()
  34967. {
  34968. if (url.isWellFormed())
  34969. url.launchInDefaultBrowser();
  34970. }
  34971. void HyperlinkButton::paintButton (Graphics& g,
  34972. bool isMouseOverButton,
  34973. bool isButtonDown)
  34974. {
  34975. const Colour textColour (findColour (textColourId));
  34976. if (isEnabled())
  34977. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34978. : textColour);
  34979. else
  34980. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34981. g.setFont (getFontToUse());
  34982. g.drawText (getButtonText(),
  34983. 2, 0, getWidth() - 2, getHeight(),
  34984. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34985. true);
  34986. }
  34987. END_JUCE_NAMESPACE
  34988. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34989. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34990. BEGIN_JUCE_NAMESPACE
  34991. ImageButton::ImageButton (const String& text_)
  34992. : Button (text_),
  34993. scaleImageToFit (true),
  34994. preserveProportions (true),
  34995. alphaThreshold (0),
  34996. imageX (0),
  34997. imageY (0),
  34998. imageW (0),
  34999. imageH (0),
  35000. normalImage (0),
  35001. overImage (0),
  35002. downImage (0)
  35003. {
  35004. }
  35005. ImageButton::~ImageButton()
  35006. {
  35007. deleteImages();
  35008. }
  35009. void ImageButton::deleteImages()
  35010. {
  35011. ImageCache::releaseOrDelete (normalImage);
  35012. ImageCache::releaseOrDelete (overImage);
  35013. ImageCache::releaseOrDelete (downImage);
  35014. }
  35015. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  35016. const bool rescaleImagesWhenButtonSizeChanges,
  35017. const bool preserveImageProportions,
  35018. Image* const normalImage_,
  35019. const float imageOpacityWhenNormal,
  35020. const Colour& overlayColourWhenNormal,
  35021. Image* const overImage_,
  35022. const float imageOpacityWhenOver,
  35023. const Colour& overlayColourWhenOver,
  35024. Image* const downImage_,
  35025. const float imageOpacityWhenDown,
  35026. const Colour& overlayColourWhenDown,
  35027. const float hitTestAlphaThreshold)
  35028. {
  35029. deleteImages();
  35030. normalImage = normalImage_;
  35031. overImage = overImage_;
  35032. downImage = downImage_;
  35033. if (resizeButtonNowToFitThisImage && normalImage != 0)
  35034. {
  35035. imageW = normalImage->getWidth();
  35036. imageH = normalImage->getHeight();
  35037. setSize (imageW, imageH);
  35038. }
  35039. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  35040. preserveProportions = preserveImageProportions;
  35041. normalOpacity = imageOpacityWhenNormal;
  35042. normalOverlay = overlayColourWhenNormal;
  35043. overOpacity = imageOpacityWhenOver;
  35044. overOverlay = overlayColourWhenOver;
  35045. downOpacity = imageOpacityWhenDown;
  35046. downOverlay = overlayColourWhenDown;
  35047. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  35048. repaint();
  35049. }
  35050. Image* ImageButton::getCurrentImage() const
  35051. {
  35052. if (isDown() || getToggleState())
  35053. return getDownImage();
  35054. if (isOver())
  35055. return getOverImage();
  35056. return getNormalImage();
  35057. }
  35058. Image* ImageButton::getNormalImage() const throw()
  35059. {
  35060. return normalImage;
  35061. }
  35062. Image* ImageButton::getOverImage() const throw()
  35063. {
  35064. return (overImage != 0) ? overImage
  35065. : normalImage;
  35066. }
  35067. Image* ImageButton::getDownImage() const throw()
  35068. {
  35069. return (downImage != 0) ? downImage
  35070. : getOverImage();
  35071. }
  35072. void ImageButton::paintButton (Graphics& g,
  35073. bool isMouseOverButton,
  35074. bool isButtonDown)
  35075. {
  35076. if (! isEnabled())
  35077. {
  35078. isMouseOverButton = false;
  35079. isButtonDown = false;
  35080. }
  35081. Image* const im = getCurrentImage();
  35082. if (im != 0)
  35083. {
  35084. const int iw = im->getWidth();
  35085. const int ih = im->getHeight();
  35086. imageW = getWidth();
  35087. imageH = getHeight();
  35088. imageX = (imageW - iw) >> 1;
  35089. imageY = (imageH - ih) >> 1;
  35090. if (scaleImageToFit)
  35091. {
  35092. if (preserveProportions)
  35093. {
  35094. int newW, newH;
  35095. const float imRatio = ih / (float)iw;
  35096. const float destRatio = imageH / (float)imageW;
  35097. if (imRatio > destRatio)
  35098. {
  35099. newW = roundToInt (imageH / imRatio);
  35100. newH = imageH;
  35101. }
  35102. else
  35103. {
  35104. newW = imageW;
  35105. newH = roundToInt (imageW * imRatio);
  35106. }
  35107. imageX = (imageW - newW) / 2;
  35108. imageY = (imageH - newH) / 2;
  35109. imageW = newW;
  35110. imageH = newH;
  35111. }
  35112. else
  35113. {
  35114. imageX = 0;
  35115. imageY = 0;
  35116. }
  35117. }
  35118. if (! scaleImageToFit)
  35119. {
  35120. imageW = iw;
  35121. imageH = ih;
  35122. }
  35123. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  35124. isButtonDown ? downOverlay
  35125. : (isMouseOverButton ? overOverlay
  35126. : normalOverlay),
  35127. isButtonDown ? downOpacity
  35128. : (isMouseOverButton ? overOpacity
  35129. : normalOpacity),
  35130. *this);
  35131. }
  35132. }
  35133. bool ImageButton::hitTest (int x, int y)
  35134. {
  35135. if (alphaThreshold == 0)
  35136. return true;
  35137. Image* const im = getCurrentImage();
  35138. return im == 0
  35139. || (imageW > 0 && imageH > 0
  35140. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  35141. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  35142. }
  35143. END_JUCE_NAMESPACE
  35144. /*** End of inlined file: juce_ImageButton.cpp ***/
  35145. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  35146. BEGIN_JUCE_NAMESPACE
  35147. ShapeButton::ShapeButton (const String& text_,
  35148. const Colour& normalColour_,
  35149. const Colour& overColour_,
  35150. const Colour& downColour_)
  35151. : Button (text_),
  35152. normalColour (normalColour_),
  35153. overColour (overColour_),
  35154. downColour (downColour_),
  35155. maintainShapeProportions (false),
  35156. outlineWidth (0.0f)
  35157. {
  35158. }
  35159. ShapeButton::~ShapeButton()
  35160. {
  35161. }
  35162. void ShapeButton::setColours (const Colour& newNormalColour,
  35163. const Colour& newOverColour,
  35164. const Colour& newDownColour)
  35165. {
  35166. normalColour = newNormalColour;
  35167. overColour = newOverColour;
  35168. downColour = newDownColour;
  35169. }
  35170. void ShapeButton::setOutline (const Colour& newOutlineColour,
  35171. const float newOutlineWidth)
  35172. {
  35173. outlineColour = newOutlineColour;
  35174. outlineWidth = newOutlineWidth;
  35175. }
  35176. void ShapeButton::setShape (const Path& newShape,
  35177. const bool resizeNowToFitThisShape,
  35178. const bool maintainShapeProportions_,
  35179. const bool hasShadow)
  35180. {
  35181. shape = newShape;
  35182. maintainShapeProportions = maintainShapeProportions_;
  35183. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  35184. setComponentEffect ((hasShadow) ? &shadow : 0);
  35185. if (resizeNowToFitThisShape)
  35186. {
  35187. Rectangle<float> bounds (shape.getBounds());
  35188. if (hasShadow)
  35189. bounds.expand (4.0f, 4.0f);
  35190. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  35191. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  35192. 1 + (int) (bounds.getHeight() + outlineWidth));
  35193. }
  35194. }
  35195. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  35196. {
  35197. if (! isEnabled())
  35198. {
  35199. isMouseOverButton = false;
  35200. isButtonDown = false;
  35201. }
  35202. g.setColour ((isButtonDown) ? downColour
  35203. : (isMouseOverButton) ? overColour
  35204. : normalColour);
  35205. int w = getWidth();
  35206. int h = getHeight();
  35207. if (getComponentEffect() != 0)
  35208. {
  35209. w -= 4;
  35210. h -= 4;
  35211. }
  35212. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  35213. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  35214. w - offset - outlineWidth,
  35215. h - offset - outlineWidth,
  35216. maintainShapeProportions));
  35217. g.fillPath (shape, trans);
  35218. if (outlineWidth > 0.0f)
  35219. {
  35220. g.setColour (outlineColour);
  35221. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  35222. }
  35223. }
  35224. END_JUCE_NAMESPACE
  35225. /*** End of inlined file: juce_ShapeButton.cpp ***/
  35226. /*** Start of inlined file: juce_TextButton.cpp ***/
  35227. BEGIN_JUCE_NAMESPACE
  35228. TextButton::TextButton (const String& name,
  35229. const String& toolTip)
  35230. : Button (name)
  35231. {
  35232. setTooltip (toolTip);
  35233. }
  35234. TextButton::~TextButton()
  35235. {
  35236. }
  35237. void TextButton::paintButton (Graphics& g,
  35238. bool isMouseOverButton,
  35239. bool isButtonDown)
  35240. {
  35241. getLookAndFeel().drawButtonBackground (g, *this,
  35242. findColour (getToggleState() ? buttonOnColourId
  35243. : buttonColourId),
  35244. isMouseOverButton,
  35245. isButtonDown);
  35246. getLookAndFeel().drawButtonText (g, *this,
  35247. isMouseOverButton,
  35248. isButtonDown);
  35249. }
  35250. void TextButton::colourChanged()
  35251. {
  35252. repaint();
  35253. }
  35254. const Font TextButton::getFont()
  35255. {
  35256. return Font (jmin (15.0f, getHeight() * 0.6f));
  35257. }
  35258. void TextButton::changeWidthToFitText (const int newHeight)
  35259. {
  35260. if (newHeight >= 0)
  35261. setSize (jmax (1, getWidth()), newHeight);
  35262. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  35263. getHeight());
  35264. }
  35265. END_JUCE_NAMESPACE
  35266. /*** End of inlined file: juce_TextButton.cpp ***/
  35267. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  35268. BEGIN_JUCE_NAMESPACE
  35269. ToggleButton::ToggleButton (const String& buttonText)
  35270. : Button (buttonText)
  35271. {
  35272. setClickingTogglesState (true);
  35273. }
  35274. ToggleButton::~ToggleButton()
  35275. {
  35276. }
  35277. void ToggleButton::paintButton (Graphics& g,
  35278. bool isMouseOverButton,
  35279. bool isButtonDown)
  35280. {
  35281. getLookAndFeel().drawToggleButton (g, *this,
  35282. isMouseOverButton,
  35283. isButtonDown);
  35284. }
  35285. void ToggleButton::changeWidthToFitText()
  35286. {
  35287. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  35288. }
  35289. void ToggleButton::colourChanged()
  35290. {
  35291. repaint();
  35292. }
  35293. END_JUCE_NAMESPACE
  35294. /*** End of inlined file: juce_ToggleButton.cpp ***/
  35295. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  35296. BEGIN_JUCE_NAMESPACE
  35297. ToolbarButton::ToolbarButton (const int itemId_,
  35298. const String& buttonText,
  35299. Drawable* const normalImage_,
  35300. Drawable* const toggledOnImage_)
  35301. : ToolbarItemComponent (itemId_, buttonText, true),
  35302. normalImage (normalImage_),
  35303. toggledOnImage (toggledOnImage_)
  35304. {
  35305. }
  35306. ToolbarButton::~ToolbarButton()
  35307. {
  35308. }
  35309. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  35310. bool /*isToolbarVertical*/,
  35311. int& preferredSize,
  35312. int& minSize, int& maxSize)
  35313. {
  35314. preferredSize = minSize = maxSize = toolbarDepth;
  35315. return true;
  35316. }
  35317. void ToolbarButton::paintButtonArea (Graphics& g,
  35318. int width, int height,
  35319. bool /*isMouseOver*/,
  35320. bool /*isMouseDown*/)
  35321. {
  35322. Drawable* d = normalImage;
  35323. if (getToggleState() && toggledOnImage != 0)
  35324. d = toggledOnImage;
  35325. if (! isEnabled())
  35326. {
  35327. Image im (Image::ARGB, width, height, true);
  35328. Graphics g2 (im);
  35329. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35330. im.desaturate();
  35331. g.drawImageAt (&im, 0, 0);
  35332. }
  35333. else
  35334. {
  35335. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35336. }
  35337. }
  35338. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  35339. {
  35340. }
  35341. END_JUCE_NAMESPACE
  35342. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  35343. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  35344. BEGIN_JUCE_NAMESPACE
  35345. class CodeDocumentLine
  35346. {
  35347. public:
  35348. CodeDocumentLine (const tchar* const line_,
  35349. const int lineLength_,
  35350. const int numNewLineChars,
  35351. const int lineStartInFile_)
  35352. : line (line_, lineLength_),
  35353. lineStartInFile (lineStartInFile_),
  35354. lineLength (lineLength_),
  35355. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  35356. {
  35357. }
  35358. ~CodeDocumentLine()
  35359. {
  35360. }
  35361. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  35362. {
  35363. const tchar* const t = (const tchar*) text;
  35364. int pos = 0;
  35365. while (t [pos] != 0)
  35366. {
  35367. const int startOfLine = pos;
  35368. int numNewLineChars = 0;
  35369. while (t[pos] != 0)
  35370. {
  35371. if (t[pos] == T('\r'))
  35372. {
  35373. ++numNewLineChars;
  35374. ++pos;
  35375. if (t[pos] == T('\n'))
  35376. {
  35377. ++numNewLineChars;
  35378. ++pos;
  35379. }
  35380. break;
  35381. }
  35382. if (t[pos] == T('\n'))
  35383. {
  35384. ++numNewLineChars;
  35385. ++pos;
  35386. break;
  35387. }
  35388. ++pos;
  35389. }
  35390. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  35391. numNewLineChars, startOfLine));
  35392. }
  35393. jassert (pos == text.length());
  35394. }
  35395. bool endsWithLineBreak() const throw()
  35396. {
  35397. return lineLengthWithoutNewLines != lineLength;
  35398. }
  35399. void updateLength() throw()
  35400. {
  35401. lineLengthWithoutNewLines = lineLength = line.length();
  35402. while (lineLengthWithoutNewLines > 0
  35403. && (line [lineLengthWithoutNewLines - 1] == '\n'
  35404. || line [lineLengthWithoutNewLines - 1] == '\r'))
  35405. {
  35406. --lineLengthWithoutNewLines;
  35407. }
  35408. }
  35409. String line;
  35410. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  35411. };
  35412. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  35413. : document (document_),
  35414. currentLine (document_->lines[0]),
  35415. line (0),
  35416. position (0)
  35417. {
  35418. }
  35419. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  35420. : document (other.document),
  35421. currentLine (other.currentLine),
  35422. line (other.line),
  35423. position (other.position)
  35424. {
  35425. }
  35426. const CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  35427. {
  35428. document = other.document;
  35429. currentLine = other.currentLine;
  35430. line = other.line;
  35431. position = other.position;
  35432. return *this;
  35433. }
  35434. CodeDocument::Iterator::~Iterator() throw()
  35435. {
  35436. }
  35437. juce_wchar CodeDocument::Iterator::nextChar()
  35438. {
  35439. if (currentLine == 0)
  35440. return 0;
  35441. jassert (currentLine == document->lines.getUnchecked (line));
  35442. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  35443. skip();
  35444. return result;
  35445. }
  35446. void CodeDocument::Iterator::skip()
  35447. {
  35448. if (currentLine != 0)
  35449. {
  35450. jassert (currentLine == document->lines.getUnchecked (line));
  35451. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  35452. {
  35453. ++line;
  35454. currentLine = document->lines [line];
  35455. }
  35456. }
  35457. }
  35458. void CodeDocument::Iterator::skipToEndOfLine()
  35459. {
  35460. if (currentLine != 0)
  35461. {
  35462. jassert (currentLine == document->lines.getUnchecked (line));
  35463. ++line;
  35464. currentLine = document->lines [line];
  35465. if (currentLine != 0)
  35466. position = currentLine->lineStartInFile;
  35467. else
  35468. position = document->getNumCharacters();
  35469. }
  35470. }
  35471. juce_wchar CodeDocument::Iterator::peekNextChar() const
  35472. {
  35473. if (currentLine == 0)
  35474. return 0;
  35475. jassert (currentLine == document->lines.getUnchecked (line));
  35476. return currentLine->line [position - currentLine->lineStartInFile];
  35477. }
  35478. void CodeDocument::Iterator::skipWhitespace()
  35479. {
  35480. while (CharacterFunctions::isWhitespace (peekNextChar()))
  35481. skip();
  35482. }
  35483. bool CodeDocument::Iterator::isEOF() const throw()
  35484. {
  35485. return currentLine == 0;
  35486. }
  35487. CodeDocument::Position::Position() throw()
  35488. : owner (0), characterPos (0), line (0),
  35489. indexInLine (0), positionMaintained (false)
  35490. {
  35491. }
  35492. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35493. const int line_, const int indexInLine_) throw()
  35494. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35495. characterPos (0), line (line_),
  35496. indexInLine (indexInLine_), positionMaintained (false)
  35497. {
  35498. setLineAndIndex (line_, indexInLine_);
  35499. }
  35500. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35501. const int characterPos_) throw()
  35502. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35503. positionMaintained (false)
  35504. {
  35505. setPosition (characterPos_);
  35506. }
  35507. CodeDocument::Position::Position (const Position& other) throw()
  35508. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  35509. indexInLine (other.indexInLine), positionMaintained (false)
  35510. {
  35511. jassert (*this == other);
  35512. }
  35513. CodeDocument::Position::~Position() throw()
  35514. {
  35515. setPositionMaintained (false);
  35516. }
  35517. const CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  35518. {
  35519. if (this != &other)
  35520. {
  35521. const bool wasPositionMaintained = positionMaintained;
  35522. if (owner != other.owner)
  35523. setPositionMaintained (false);
  35524. owner = other.owner;
  35525. line = other.line;
  35526. indexInLine = other.indexInLine;
  35527. characterPos = other.characterPos;
  35528. setPositionMaintained (wasPositionMaintained);
  35529. jassert (*this == other);
  35530. }
  35531. return *this;
  35532. }
  35533. bool CodeDocument::Position::operator== (const Position& other) const throw()
  35534. {
  35535. jassert ((characterPos == other.characterPos)
  35536. == (line == other.line && indexInLine == other.indexInLine));
  35537. return characterPos == other.characterPos
  35538. && line == other.line
  35539. && indexInLine == other.indexInLine
  35540. && owner == other.owner;
  35541. }
  35542. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  35543. {
  35544. return ! operator== (other);
  35545. }
  35546. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  35547. {
  35548. jassert (owner != 0);
  35549. if (owner->lines.size() == 0)
  35550. {
  35551. line = 0;
  35552. indexInLine = 0;
  35553. characterPos = 0;
  35554. }
  35555. else
  35556. {
  35557. if (newLine >= owner->lines.size())
  35558. {
  35559. line = owner->lines.size() - 1;
  35560. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35561. jassert (l != 0);
  35562. indexInLine = l->lineLengthWithoutNewLines;
  35563. characterPos = l->lineStartInFile + indexInLine;
  35564. }
  35565. else
  35566. {
  35567. line = jmax (0, newLine);
  35568. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35569. jassert (l != 0);
  35570. if (l->lineLengthWithoutNewLines > 0)
  35571. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  35572. else
  35573. indexInLine = 0;
  35574. characterPos = l->lineStartInFile + indexInLine;
  35575. }
  35576. }
  35577. }
  35578. void CodeDocument::Position::setPosition (const int newPosition) throw()
  35579. {
  35580. jassert (owner != 0);
  35581. line = 0;
  35582. indexInLine = 0;
  35583. characterPos = 0;
  35584. if (newPosition > 0)
  35585. {
  35586. int lineStart = 0;
  35587. int lineEnd = owner->lines.size();
  35588. for (;;)
  35589. {
  35590. if (lineEnd - lineStart < 4)
  35591. {
  35592. for (int i = lineStart; i < lineEnd; ++i)
  35593. {
  35594. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35595. int index = newPosition - l->lineStartInFile;
  35596. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35597. {
  35598. line = i;
  35599. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35600. characterPos = l->lineStartInFile + indexInLine;
  35601. }
  35602. }
  35603. break;
  35604. }
  35605. else
  35606. {
  35607. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35608. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35609. if (newPosition >= mid->lineStartInFile)
  35610. lineStart = midIndex;
  35611. else
  35612. lineEnd = midIndex;
  35613. }
  35614. }
  35615. }
  35616. }
  35617. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35618. {
  35619. jassert (owner != 0);
  35620. if (characterDelta == 1)
  35621. {
  35622. setPosition (getPosition());
  35623. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35624. if (line < owner->lines.size())
  35625. {
  35626. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35627. if (indexInLine + characterDelta < l->lineLength
  35628. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35629. ++characterDelta;
  35630. }
  35631. }
  35632. setPosition (characterPos + characterDelta);
  35633. }
  35634. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35635. {
  35636. CodeDocument::Position p (*this);
  35637. p.moveBy (characterDelta);
  35638. return p;
  35639. }
  35640. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35641. {
  35642. CodeDocument::Position p (*this);
  35643. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35644. return p;
  35645. }
  35646. const tchar CodeDocument::Position::getCharacter() const throw()
  35647. {
  35648. const CodeDocumentLine* const l = owner->lines [line];
  35649. return l == 0 ? 0 : l->line [getIndexInLine()];
  35650. }
  35651. const String CodeDocument::Position::getLineText() const throw()
  35652. {
  35653. const CodeDocumentLine* const l = owner->lines [line];
  35654. return l == 0 ? String::empty : l->line;
  35655. }
  35656. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35657. {
  35658. if (isMaintained != positionMaintained)
  35659. {
  35660. positionMaintained = isMaintained;
  35661. if (owner != 0)
  35662. {
  35663. if (isMaintained)
  35664. {
  35665. jassert (! owner->positionsToMaintain.contains (this));
  35666. owner->positionsToMaintain.add (this);
  35667. }
  35668. else
  35669. {
  35670. jassert (owner->positionsToMaintain.contains (this));
  35671. owner->positionsToMaintain.removeValue (this);
  35672. }
  35673. }
  35674. }
  35675. }
  35676. CodeDocument::CodeDocument()
  35677. : undoManager (std::numeric_limits<int>::max(), 10000),
  35678. currentActionIndex (0),
  35679. indexOfSavedState (-1),
  35680. maximumLineLength (-1),
  35681. newLineChars ("\r\n")
  35682. {
  35683. }
  35684. CodeDocument::~CodeDocument()
  35685. {
  35686. }
  35687. const String CodeDocument::getAllContent() const throw()
  35688. {
  35689. return getTextBetween (Position (this, 0),
  35690. Position (this, lines.size(), 0));
  35691. }
  35692. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35693. {
  35694. if (end.getPosition() <= start.getPosition())
  35695. return String::empty;
  35696. const int startLine = start.getLineNumber();
  35697. const int endLine = end.getLineNumber();
  35698. if (startLine == endLine)
  35699. {
  35700. CodeDocumentLine* const line = lines [startLine];
  35701. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35702. }
  35703. String result;
  35704. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35705. String::Concatenator concatenator (result);
  35706. const int maxLine = jmin (lines.size() - 1, endLine);
  35707. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35708. {
  35709. const CodeDocumentLine* line = lines.getUnchecked(i);
  35710. int len = line->lineLength;
  35711. if (i == startLine)
  35712. {
  35713. const int index = start.getIndexInLine();
  35714. concatenator.append (line->line.substring (index, len));
  35715. }
  35716. else if (i == endLine)
  35717. {
  35718. len = end.getIndexInLine();
  35719. concatenator.append (line->line.substring (0, len));
  35720. }
  35721. else
  35722. {
  35723. concatenator.append (line->line);
  35724. }
  35725. }
  35726. return result;
  35727. }
  35728. int CodeDocument::getNumCharacters() const throw()
  35729. {
  35730. const CodeDocumentLine* const lastLine = lines.getLast();
  35731. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35732. }
  35733. const String CodeDocument::getLine (const int lineIndex) const throw()
  35734. {
  35735. const CodeDocumentLine* const line = lines [lineIndex];
  35736. return (line == 0) ? String::empty : line->line;
  35737. }
  35738. int CodeDocument::getMaximumLineLength() throw()
  35739. {
  35740. if (maximumLineLength < 0)
  35741. {
  35742. maximumLineLength = 0;
  35743. for (int i = lines.size(); --i >= 0;)
  35744. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35745. }
  35746. return maximumLineLength;
  35747. }
  35748. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35749. {
  35750. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35751. }
  35752. void CodeDocument::insertText (const Position& position, const String& text)
  35753. {
  35754. insert (text, position.getPosition(), true);
  35755. }
  35756. void CodeDocument::replaceAllContent (const String& newContent)
  35757. {
  35758. remove (0, getNumCharacters(), true);
  35759. insert (newContent, 0, true);
  35760. }
  35761. bool CodeDocument::loadFromStream (InputStream& stream)
  35762. {
  35763. replaceAllContent (stream.readEntireStreamAsString());
  35764. setSavePoint();
  35765. clearUndoHistory();
  35766. return true;
  35767. }
  35768. bool CodeDocument::writeToStream (OutputStream& stream)
  35769. {
  35770. for (int i = 0; i < lines.size(); ++i)
  35771. {
  35772. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35773. const char* utf8 = temp.toUTF8();
  35774. if (! stream.write (utf8, (int) strlen (utf8)))
  35775. return false;
  35776. }
  35777. return true;
  35778. }
  35779. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35780. {
  35781. jassert (newLine == T("\r\n") || newLine == T("\n") || newLine == T("\r"));
  35782. newLineChars = newLine;
  35783. }
  35784. void CodeDocument::newTransaction()
  35785. {
  35786. undoManager.beginNewTransaction (String::empty);
  35787. }
  35788. void CodeDocument::undo()
  35789. {
  35790. newTransaction();
  35791. undoManager.undo();
  35792. }
  35793. void CodeDocument::redo()
  35794. {
  35795. undoManager.redo();
  35796. }
  35797. void CodeDocument::clearUndoHistory()
  35798. {
  35799. undoManager.clearUndoHistory();
  35800. }
  35801. void CodeDocument::setSavePoint() throw()
  35802. {
  35803. indexOfSavedState = currentActionIndex;
  35804. }
  35805. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35806. {
  35807. return currentActionIndex != indexOfSavedState;
  35808. }
  35809. static int getCodeCharacterCategory (const tchar character) throw()
  35810. {
  35811. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35812. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35813. }
  35814. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35815. {
  35816. Position p (position);
  35817. const int maxDistance = 256;
  35818. int i = 0;
  35819. while (i < maxDistance
  35820. && CharacterFunctions::isWhitespace (p.getCharacter())
  35821. && (i == 0 || (p.getCharacter() != T('\n')
  35822. && p.getCharacter() != T('\r'))))
  35823. {
  35824. ++i;
  35825. p.moveBy (1);
  35826. }
  35827. if (i == 0)
  35828. {
  35829. const int type = getCodeCharacterCategory (p.getCharacter());
  35830. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35831. {
  35832. ++i;
  35833. p.moveBy (1);
  35834. }
  35835. while (i < maxDistance
  35836. && CharacterFunctions::isWhitespace (p.getCharacter())
  35837. && (i == 0 || (p.getCharacter() != T('\n')
  35838. && p.getCharacter() != T('\r'))))
  35839. {
  35840. ++i;
  35841. p.moveBy (1);
  35842. }
  35843. }
  35844. return p;
  35845. }
  35846. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35847. {
  35848. Position p (position);
  35849. const int maxDistance = 256;
  35850. int i = 0;
  35851. bool stoppedAtLineStart = false;
  35852. while (i < maxDistance)
  35853. {
  35854. const tchar c = p.movedBy (-1).getCharacter();
  35855. if (c == T('\r') || c == T('\n'))
  35856. {
  35857. stoppedAtLineStart = true;
  35858. if (i > 0)
  35859. break;
  35860. }
  35861. if (! CharacterFunctions::isWhitespace (c))
  35862. break;
  35863. p.moveBy (-1);
  35864. ++i;
  35865. }
  35866. if (i < maxDistance && ! stoppedAtLineStart)
  35867. {
  35868. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35869. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35870. {
  35871. p.moveBy (-1);
  35872. ++i;
  35873. }
  35874. }
  35875. return p;
  35876. }
  35877. void CodeDocument::checkLastLineStatus()
  35878. {
  35879. while (lines.size() > 0
  35880. && lines.getLast()->lineLength == 0
  35881. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35882. {
  35883. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35884. lines.removeLast();
  35885. }
  35886. const CodeDocumentLine* const lastLine = lines.getLast();
  35887. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35888. {
  35889. // check that there's an empty line at the end if the preceding one ends in a newline..
  35890. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35891. }
  35892. }
  35893. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35894. {
  35895. listeners.addIfNotAlreadyThere (listener);
  35896. }
  35897. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35898. {
  35899. listeners.removeValue (listener);
  35900. }
  35901. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35902. {
  35903. const Position startPos (this, startLine, 0);
  35904. const Position endPos (this, endLine, 0);
  35905. for (int i = listeners.size(); --i >= 0;)
  35906. {
  35907. Listener* const l = (Listener*) listeners[i];
  35908. if (l != 0)
  35909. l->codeDocumentChanged (startPos, endPos);
  35910. }
  35911. }
  35912. class CodeDocumentInsertAction : public UndoableAction
  35913. {
  35914. CodeDocument& owner;
  35915. const String text;
  35916. int insertPos;
  35917. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35918. const CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35919. public:
  35920. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35921. : owner (owner_),
  35922. text (text_),
  35923. insertPos (insertPos_)
  35924. {
  35925. }
  35926. ~CodeDocumentInsertAction() {}
  35927. bool perform()
  35928. {
  35929. owner.currentActionIndex++;
  35930. owner.insert (text, insertPos, false);
  35931. return true;
  35932. }
  35933. bool undo()
  35934. {
  35935. owner.currentActionIndex--;
  35936. owner.remove (insertPos, insertPos + text.length(), false);
  35937. return true;
  35938. }
  35939. int getSizeInUnits() { return text.length() + 32; }
  35940. };
  35941. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35942. {
  35943. if (text.isEmpty())
  35944. return;
  35945. if (undoable)
  35946. {
  35947. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35948. }
  35949. else
  35950. {
  35951. Position pos (this, insertPos);
  35952. const int firstAffectedLine = pos.getLineNumber();
  35953. int lastAffectedLine = firstAffectedLine + 1;
  35954. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35955. String textInsideOriginalLine (text);
  35956. if (firstLine != 0)
  35957. {
  35958. const int index = pos.getIndexInLine();
  35959. textInsideOriginalLine = firstLine->line.substring (0, index)
  35960. + textInsideOriginalLine
  35961. + firstLine->line.substring (index);
  35962. }
  35963. maximumLineLength = -1;
  35964. Array <CodeDocumentLine*> newLines;
  35965. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35966. jassert (newLines.size() > 0);
  35967. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35968. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35969. lines.set (firstAffectedLine, newFirstLine);
  35970. if (newLines.size() > 1)
  35971. {
  35972. for (int i = 1; i < newLines.size(); ++i)
  35973. {
  35974. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35975. lines.insert (firstAffectedLine + i, l);
  35976. }
  35977. lastAffectedLine = lines.size();
  35978. }
  35979. int i, lineStart = newFirstLine->lineStartInFile;
  35980. for (i = firstAffectedLine; i < lines.size(); ++i)
  35981. {
  35982. CodeDocumentLine* const l = lines.getUnchecked (i);
  35983. l->lineStartInFile = lineStart;
  35984. lineStart += l->lineLength;
  35985. }
  35986. checkLastLineStatus();
  35987. const int newTextLength = text.length();
  35988. for (i = 0; i < positionsToMaintain.size(); ++i)
  35989. {
  35990. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35991. if (p->getPosition() >= insertPos)
  35992. p->setPosition (p->getPosition() + newTextLength);
  35993. }
  35994. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35995. }
  35996. }
  35997. class CodeDocumentDeleteAction : public UndoableAction
  35998. {
  35999. CodeDocument& owner;
  36000. int startPos, endPos;
  36001. String removedText;
  36002. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  36003. const CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  36004. public:
  36005. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  36006. : owner (owner_),
  36007. startPos (startPos_),
  36008. endPos (endPos_)
  36009. {
  36010. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  36011. CodeDocument::Position (&owner, endPos));
  36012. }
  36013. ~CodeDocumentDeleteAction() {}
  36014. bool perform()
  36015. {
  36016. owner.currentActionIndex++;
  36017. owner.remove (startPos, endPos, false);
  36018. return true;
  36019. }
  36020. bool undo()
  36021. {
  36022. owner.currentActionIndex--;
  36023. owner.insert (removedText, startPos, false);
  36024. return true;
  36025. }
  36026. int getSizeInUnits() { return removedText.length() + 32; }
  36027. };
  36028. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  36029. {
  36030. if (endPos <= startPos)
  36031. return;
  36032. if (undoable)
  36033. {
  36034. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  36035. }
  36036. else
  36037. {
  36038. Position startPosition (this, startPos);
  36039. Position endPosition (this, endPos);
  36040. maximumLineLength = -1;
  36041. const int firstAffectedLine = startPosition.getLineNumber();
  36042. const int endLine = endPosition.getLineNumber();
  36043. int lastAffectedLine = firstAffectedLine + 1;
  36044. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  36045. if (firstAffectedLine == endLine)
  36046. {
  36047. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  36048. + firstLine->line.substring (endPosition.getIndexInLine());
  36049. firstLine->updateLength();
  36050. }
  36051. else
  36052. {
  36053. lastAffectedLine = lines.size();
  36054. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  36055. jassert (lastLine != 0);
  36056. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  36057. + lastLine->line.substring (endPosition.getIndexInLine());
  36058. firstLine->updateLength();
  36059. int numLinesToRemove = endLine - firstAffectedLine;
  36060. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  36061. }
  36062. int i;
  36063. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  36064. {
  36065. CodeDocumentLine* const l = lines.getUnchecked (i);
  36066. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  36067. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  36068. }
  36069. checkLastLineStatus();
  36070. const int totalChars = getNumCharacters();
  36071. for (i = 0; i < positionsToMaintain.size(); ++i)
  36072. {
  36073. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  36074. if (p->getPosition() > startPosition.getPosition())
  36075. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  36076. if (p->getPosition() > totalChars)
  36077. p->setPosition (totalChars);
  36078. }
  36079. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  36080. }
  36081. }
  36082. END_JUCE_NAMESPACE
  36083. /*** End of inlined file: juce_CodeDocument.cpp ***/
  36084. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  36085. BEGIN_JUCE_NAMESPACE
  36086. class CaretComponent : public Component,
  36087. public Timer
  36088. {
  36089. public:
  36090. CaretComponent()
  36091. {
  36092. setAlwaysOnTop (true);
  36093. setInterceptsMouseClicks (false, false);
  36094. }
  36095. ~CaretComponent()
  36096. {
  36097. }
  36098. void paint (Graphics& g)
  36099. {
  36100. if (getParentComponent()->hasKeyboardFocus (true))
  36101. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  36102. }
  36103. void timerCallback()
  36104. {
  36105. setVisible (! isVisible());
  36106. }
  36107. void updatePosition (CodeEditorComponent& owner)
  36108. {
  36109. startTimer (400);
  36110. setVisible (true);
  36111. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  36112. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  36113. }
  36114. };
  36115. class CodeEditorComponent::CodeEditorLine
  36116. {
  36117. public:
  36118. CodeEditorLine() throw()
  36119. {
  36120. }
  36121. ~CodeEditorLine() throw()
  36122. {
  36123. }
  36124. bool update (CodeDocument& document, int lineNum,
  36125. CodeDocument::Iterator& source,
  36126. CodeTokeniser* analyser, const int spacesPerTab,
  36127. const CodeDocument::Position& selectionStart,
  36128. const CodeDocument::Position& selectionEnd)
  36129. {
  36130. Array <SyntaxToken> newTokens;
  36131. newTokens.ensureStorageAllocated (8);
  36132. if (analyser == 0)
  36133. {
  36134. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  36135. }
  36136. else if (lineNum < document.getNumLines())
  36137. {
  36138. const CodeDocument::Position pos (&document, lineNum, 0);
  36139. createTokens (pos.getPosition(), pos.getLineText(),
  36140. source, analyser, newTokens);
  36141. }
  36142. replaceTabsWithSpaces (newTokens, spacesPerTab);
  36143. int newHighlightStart = 0;
  36144. int newHighlightEnd = 0;
  36145. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  36146. {
  36147. const String line (document.getLine (lineNum));
  36148. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  36149. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  36150. line, spacesPerTab);
  36151. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  36152. line, spacesPerTab);
  36153. }
  36154. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  36155. {
  36156. highlightColumnStart = newHighlightStart;
  36157. highlightColumnEnd = newHighlightEnd;
  36158. }
  36159. else
  36160. {
  36161. if (tokens.size() == newTokens.size())
  36162. {
  36163. bool allTheSame = true;
  36164. for (int i = newTokens.size(); --i >= 0;)
  36165. {
  36166. if (tokens.getReference(i) != newTokens.getReference(i))
  36167. {
  36168. allTheSame = false;
  36169. break;
  36170. }
  36171. }
  36172. if (allTheSame)
  36173. return false;
  36174. }
  36175. }
  36176. tokens.swapWithArray (newTokens);
  36177. return true;
  36178. }
  36179. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  36180. float x, const int y, const int baselineOffset, const int lineHeight,
  36181. const Colour& highlightColour) const throw()
  36182. {
  36183. if (highlightColumnStart < highlightColumnEnd)
  36184. {
  36185. g.setColour (highlightColour);
  36186. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  36187. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  36188. }
  36189. int lastType = std::numeric_limits<int>::min();
  36190. for (int i = 0; i < tokens.size(); ++i)
  36191. {
  36192. SyntaxToken& token = tokens.getReference(i);
  36193. if (lastType != token.tokenType)
  36194. {
  36195. lastType = token.tokenType;
  36196. g.setColour (owner.getColourForTokenType (lastType));
  36197. }
  36198. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  36199. if (i < tokens.size() - 1)
  36200. {
  36201. if (token.width < 0)
  36202. token.width = font.getStringWidthFloat (token.text);
  36203. x += token.width;
  36204. }
  36205. }
  36206. }
  36207. private:
  36208. struct SyntaxToken
  36209. {
  36210. String text;
  36211. int tokenType;
  36212. float width;
  36213. SyntaxToken (const String& text_, const int type) throw()
  36214. : text (text_), tokenType (type), width (-1.0f)
  36215. {
  36216. }
  36217. bool operator!= (const SyntaxToken& other) const throw()
  36218. {
  36219. return text != other.text || tokenType != other.tokenType;
  36220. }
  36221. };
  36222. Array <SyntaxToken> tokens;
  36223. int highlightColumnStart, highlightColumnEnd;
  36224. static void createTokens (int startPosition, const String& lineText,
  36225. CodeDocument::Iterator& source,
  36226. CodeTokeniser* analyser,
  36227. Array <SyntaxToken>& newTokens)
  36228. {
  36229. CodeDocument::Iterator lastIterator (source);
  36230. const int lineLength = lineText.length();
  36231. for (;;)
  36232. {
  36233. int tokenType = analyser->readNextToken (source);
  36234. int tokenStart = lastIterator.getPosition();
  36235. int tokenEnd = source.getPosition();
  36236. if (tokenEnd <= tokenStart)
  36237. break;
  36238. tokenEnd -= startPosition;
  36239. if (tokenEnd > 0)
  36240. {
  36241. tokenStart -= startPosition;
  36242. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  36243. tokenType));
  36244. if (tokenEnd >= lineLength)
  36245. break;
  36246. }
  36247. lastIterator = source;
  36248. }
  36249. source = lastIterator;
  36250. }
  36251. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  36252. {
  36253. int x = 0;
  36254. for (int i = 0; i < tokens.size(); ++i)
  36255. {
  36256. SyntaxToken& t = tokens.getReference(i);
  36257. for (;;)
  36258. {
  36259. int tabPos = t.text.indexOfChar (T('\t'));
  36260. if (tabPos < 0)
  36261. break;
  36262. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  36263. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (T(" "), spacesNeeded));
  36264. }
  36265. x += t.text.length();
  36266. }
  36267. }
  36268. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  36269. {
  36270. jassert (index <= line.length());
  36271. int col = 0;
  36272. for (int i = 0; i < index; ++i)
  36273. {
  36274. if (line[i] != T('\t'))
  36275. ++col;
  36276. else
  36277. col += spacesPerTab - (col % spacesPerTab);
  36278. }
  36279. return col;
  36280. }
  36281. };
  36282. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  36283. CodeTokeniser* const codeTokeniser_)
  36284. : document (document_),
  36285. firstLineOnScreen (0),
  36286. gutter (5),
  36287. spacesPerTab (4),
  36288. lineHeight (0),
  36289. linesOnScreen (0),
  36290. columnsOnScreen (0),
  36291. scrollbarThickness (16),
  36292. columnToTryToMaintain (-1),
  36293. useSpacesForTabs (false),
  36294. xOffset (0),
  36295. codeTokeniser (codeTokeniser_)
  36296. {
  36297. caretPos = CodeDocument::Position (&document_, 0, 0);
  36298. caretPos.setPositionMaintained (true);
  36299. selectionStart = CodeDocument::Position (&document_, 0, 0);
  36300. selectionStart.setPositionMaintained (true);
  36301. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  36302. selectionEnd.setPositionMaintained (true);
  36303. setOpaque (true);
  36304. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  36305. setWantsKeyboardFocus (true);
  36306. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  36307. verticalScrollBar->setSingleStepSize (1.0);
  36308. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  36309. horizontalScrollBar->setSingleStepSize (1.0);
  36310. addAndMakeVisible (caret = new CaretComponent());
  36311. Font f (12.0f);
  36312. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  36313. setFont (f);
  36314. resetToDefaultColours();
  36315. verticalScrollBar->addListener (this);
  36316. horizontalScrollBar->addListener (this);
  36317. document.addListener (this);
  36318. }
  36319. CodeEditorComponent::~CodeEditorComponent()
  36320. {
  36321. document.removeListener (this);
  36322. deleteAllChildren();
  36323. }
  36324. void CodeEditorComponent::loadContent (const String& newContent)
  36325. {
  36326. clearCachedIterators (0);
  36327. document.replaceAllContent (newContent);
  36328. document.clearUndoHistory();
  36329. document.setSavePoint();
  36330. caretPos.setPosition (0);
  36331. selectionStart.setPosition (0);
  36332. selectionEnd.setPosition (0);
  36333. scrollToLine (0);
  36334. }
  36335. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  36336. const CodeDocument::Position& affectedTextEnd)
  36337. {
  36338. clearCachedIterators (affectedTextStart.getLineNumber());
  36339. triggerAsyncUpdate();
  36340. ((CaretComponent*) caret)->updatePosition (*this);
  36341. columnToTryToMaintain = -1;
  36342. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  36343. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  36344. deselectAll();
  36345. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  36346. || caretPos.getPosition() < affectedTextStart.getPosition())
  36347. moveCaretTo (affectedTextStart, false);
  36348. updateScrollBars();
  36349. }
  36350. void CodeEditorComponent::resized()
  36351. {
  36352. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  36353. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  36354. lines.clear();
  36355. rebuildLineTokens();
  36356. ((CaretComponent*) caret)->updatePosition (*this);
  36357. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  36358. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  36359. updateScrollBars();
  36360. }
  36361. void CodeEditorComponent::paint (Graphics& g)
  36362. {
  36363. handleUpdateNowIfNeeded();
  36364. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  36365. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  36366. g.setFont (font);
  36367. const int baselineOffset = (int) font.getAscent();
  36368. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  36369. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  36370. const Rectangle<int> clip (g.getClipBounds());
  36371. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  36372. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  36373. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  36374. {
  36375. lines.getUnchecked(j)->draw (*this, g, font,
  36376. (float) (gutter - xOffset * charWidth),
  36377. lineHeight * j, baselineOffset, lineHeight,
  36378. highlightColour);
  36379. }
  36380. }
  36381. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  36382. {
  36383. if (scrollbarThickness != thickness)
  36384. {
  36385. scrollbarThickness = thickness;
  36386. resized();
  36387. }
  36388. }
  36389. void CodeEditorComponent::handleAsyncUpdate()
  36390. {
  36391. rebuildLineTokens();
  36392. }
  36393. void CodeEditorComponent::rebuildLineTokens()
  36394. {
  36395. cancelPendingUpdate();
  36396. const int numNeeded = linesOnScreen + 1;
  36397. int minLineToRepaint = numNeeded;
  36398. int maxLineToRepaint = 0;
  36399. if (numNeeded != lines.size())
  36400. {
  36401. lines.clear();
  36402. for (int i = numNeeded; --i >= 0;)
  36403. lines.add (new CodeEditorLine());
  36404. minLineToRepaint = 0;
  36405. maxLineToRepaint = numNeeded;
  36406. }
  36407. jassert (numNeeded == lines.size());
  36408. CodeDocument::Iterator source (&document);
  36409. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  36410. for (int i = 0; i < numNeeded; ++i)
  36411. {
  36412. CodeEditorLine* const line = lines.getUnchecked(i);
  36413. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  36414. selectionStart, selectionEnd))
  36415. {
  36416. minLineToRepaint = jmin (minLineToRepaint, i);
  36417. maxLineToRepaint = jmax (maxLineToRepaint, i);
  36418. }
  36419. }
  36420. if (minLineToRepaint <= maxLineToRepaint)
  36421. {
  36422. repaint (gutter, lineHeight * minLineToRepaint - 1,
  36423. verticalScrollBar->getX() - gutter,
  36424. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  36425. }
  36426. }
  36427. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  36428. {
  36429. caretPos = newPos;
  36430. columnToTryToMaintain = -1;
  36431. if (highlighting)
  36432. {
  36433. if (dragType == notDragging)
  36434. {
  36435. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  36436. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  36437. dragType = draggingSelectionStart;
  36438. else
  36439. dragType = draggingSelectionEnd;
  36440. }
  36441. if (dragType == draggingSelectionStart)
  36442. {
  36443. selectionStart = caretPos;
  36444. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36445. {
  36446. const CodeDocument::Position temp (selectionStart);
  36447. selectionStart = selectionEnd;
  36448. selectionEnd = temp;
  36449. dragType = draggingSelectionEnd;
  36450. }
  36451. }
  36452. else
  36453. {
  36454. selectionEnd = caretPos;
  36455. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36456. {
  36457. const CodeDocument::Position temp (selectionStart);
  36458. selectionStart = selectionEnd;
  36459. selectionEnd = temp;
  36460. dragType = draggingSelectionStart;
  36461. }
  36462. }
  36463. triggerAsyncUpdate();
  36464. }
  36465. else
  36466. {
  36467. deselectAll();
  36468. }
  36469. ((CaretComponent*) caret)->updatePosition (*this);
  36470. scrollToKeepCaretOnScreen();
  36471. updateScrollBars();
  36472. }
  36473. void CodeEditorComponent::deselectAll()
  36474. {
  36475. if (selectionStart != selectionEnd)
  36476. triggerAsyncUpdate();
  36477. selectionStart = caretPos;
  36478. selectionEnd = caretPos;
  36479. }
  36480. void CodeEditorComponent::updateScrollBars()
  36481. {
  36482. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  36483. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  36484. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  36485. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  36486. }
  36487. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  36488. {
  36489. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  36490. newFirstLineOnScreen);
  36491. if (newFirstLineOnScreen != firstLineOnScreen)
  36492. {
  36493. firstLineOnScreen = newFirstLineOnScreen;
  36494. ((CaretComponent*) caret)->updatePosition (*this);
  36495. updateCachedIterators (firstLineOnScreen);
  36496. triggerAsyncUpdate();
  36497. }
  36498. }
  36499. void CodeEditorComponent::scrollToColumnInternal (double column)
  36500. {
  36501. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  36502. if (xOffset != newOffset)
  36503. {
  36504. xOffset = newOffset;
  36505. ((CaretComponent*) caret)->updatePosition (*this);
  36506. repaint();
  36507. }
  36508. }
  36509. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  36510. {
  36511. scrollToLineInternal (newFirstLineOnScreen);
  36512. updateScrollBars();
  36513. }
  36514. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  36515. {
  36516. scrollToColumnInternal (newFirstColumnOnScreen);
  36517. updateScrollBars();
  36518. }
  36519. void CodeEditorComponent::scrollBy (int deltaLines)
  36520. {
  36521. scrollToLine (firstLineOnScreen + deltaLines);
  36522. }
  36523. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  36524. {
  36525. if (caretPos.getLineNumber() < firstLineOnScreen)
  36526. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  36527. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36528. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  36529. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36530. if (column >= xOffset + columnsOnScreen - 1)
  36531. scrollToColumn (column + 1 - columnsOnScreen);
  36532. else if (column < xOffset)
  36533. scrollToColumn (column);
  36534. }
  36535. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  36536. {
  36537. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  36538. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  36539. roundToInt (charWidth),
  36540. lineHeight);
  36541. }
  36542. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  36543. {
  36544. const int line = y / lineHeight + firstLineOnScreen;
  36545. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  36546. const int index = columnToIndex (line, column);
  36547. return CodeDocument::Position (&document, line, index);
  36548. }
  36549. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  36550. {
  36551. document.deleteSection (selectionStart, selectionEnd);
  36552. if (newText.isNotEmpty())
  36553. document.insertText (caretPos, newText);
  36554. scrollToKeepCaretOnScreen();
  36555. }
  36556. void CodeEditorComponent::insertTabAtCaret()
  36557. {
  36558. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  36559. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  36560. {
  36561. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  36562. }
  36563. if (useSpacesForTabs)
  36564. {
  36565. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36566. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  36567. insertTextAtCaret (String::repeatedString (T(" "), spacesNeeded));
  36568. }
  36569. else
  36570. {
  36571. insertTextAtCaret (T("\t"));
  36572. }
  36573. }
  36574. void CodeEditorComponent::cut()
  36575. {
  36576. insertTextAtCaret (String::empty);
  36577. }
  36578. void CodeEditorComponent::copy()
  36579. {
  36580. newTransaction();
  36581. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  36582. if (selection.isNotEmpty())
  36583. SystemClipboard::copyTextToClipboard (selection);
  36584. }
  36585. void CodeEditorComponent::copyThenCut()
  36586. {
  36587. copy();
  36588. cut();
  36589. newTransaction();
  36590. }
  36591. void CodeEditorComponent::paste()
  36592. {
  36593. newTransaction();
  36594. const String clip (SystemClipboard::getTextFromClipboard());
  36595. if (clip.isNotEmpty())
  36596. insertTextAtCaret (clip);
  36597. newTransaction();
  36598. }
  36599. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36600. {
  36601. newTransaction();
  36602. if (moveInWholeWordSteps)
  36603. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36604. else
  36605. moveCaretTo (caretPos.movedBy (-1), selecting);
  36606. }
  36607. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36608. {
  36609. newTransaction();
  36610. if (moveInWholeWordSteps)
  36611. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36612. else
  36613. moveCaretTo (caretPos.movedBy (1), selecting);
  36614. }
  36615. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  36616. {
  36617. CodeDocument::Position pos (caretPos);
  36618. const int newLineNum = pos.getLineNumber() + delta;
  36619. if (columnToTryToMaintain < 0)
  36620. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  36621. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  36622. const int colToMaintain = columnToTryToMaintain;
  36623. moveCaretTo (pos, selecting);
  36624. columnToTryToMaintain = colToMaintain;
  36625. }
  36626. void CodeEditorComponent::cursorDown (const bool selecting)
  36627. {
  36628. newTransaction();
  36629. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36630. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36631. else
  36632. moveLineDelta (1, selecting);
  36633. }
  36634. void CodeEditorComponent::cursorUp (const bool selecting)
  36635. {
  36636. newTransaction();
  36637. if (caretPos.getLineNumber() == 0)
  36638. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36639. else
  36640. moveLineDelta (-1, selecting);
  36641. }
  36642. void CodeEditorComponent::pageDown (const bool selecting)
  36643. {
  36644. newTransaction();
  36645. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36646. moveLineDelta (linesOnScreen, selecting);
  36647. }
  36648. void CodeEditorComponent::pageUp (const bool selecting)
  36649. {
  36650. newTransaction();
  36651. scrollBy (-linesOnScreen);
  36652. moveLineDelta (-linesOnScreen, selecting);
  36653. }
  36654. void CodeEditorComponent::scrollUp()
  36655. {
  36656. newTransaction();
  36657. scrollBy (1);
  36658. if (caretPos.getLineNumber() < firstLineOnScreen)
  36659. moveLineDelta (1, false);
  36660. }
  36661. void CodeEditorComponent::scrollDown()
  36662. {
  36663. newTransaction();
  36664. scrollBy (-1);
  36665. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36666. moveLineDelta (-1, false);
  36667. }
  36668. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36669. {
  36670. newTransaction();
  36671. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36672. }
  36673. static int findFirstNonWhitespaceChar (const String& line) throw()
  36674. {
  36675. const int len = line.length();
  36676. for (int i = 0; i < len; ++i)
  36677. if (! CharacterFunctions::isWhitespace (line [i]))
  36678. return i;
  36679. return 0;
  36680. }
  36681. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36682. {
  36683. newTransaction();
  36684. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36685. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36686. index = 0;
  36687. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36688. }
  36689. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36690. {
  36691. newTransaction();
  36692. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36693. }
  36694. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36695. {
  36696. newTransaction();
  36697. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36698. }
  36699. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36700. {
  36701. if (moveInWholeWordSteps)
  36702. {
  36703. cut(); // in case something is already highlighted
  36704. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36705. }
  36706. else
  36707. {
  36708. if (selectionStart == selectionEnd)
  36709. selectionStart.moveBy (-1);
  36710. }
  36711. cut();
  36712. }
  36713. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36714. {
  36715. if (moveInWholeWordSteps)
  36716. {
  36717. cut(); // in case something is already highlighted
  36718. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36719. }
  36720. else
  36721. {
  36722. if (selectionStart == selectionEnd)
  36723. selectionEnd.moveBy (1);
  36724. else
  36725. newTransaction();
  36726. }
  36727. cut();
  36728. }
  36729. void CodeEditorComponent::selectAll()
  36730. {
  36731. newTransaction();
  36732. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36733. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36734. }
  36735. void CodeEditorComponent::undo()
  36736. {
  36737. document.undo();
  36738. scrollToKeepCaretOnScreen();
  36739. }
  36740. void CodeEditorComponent::redo()
  36741. {
  36742. document.redo();
  36743. scrollToKeepCaretOnScreen();
  36744. }
  36745. void CodeEditorComponent::newTransaction()
  36746. {
  36747. document.newTransaction();
  36748. startTimer (600);
  36749. }
  36750. void CodeEditorComponent::timerCallback()
  36751. {
  36752. newTransaction();
  36753. }
  36754. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36755. {
  36756. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36757. }
  36758. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36759. {
  36760. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36761. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36762. }
  36763. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36764. {
  36765. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36766. CodeDocument::Position (&document, range.getEnd()));
  36767. }
  36768. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36769. {
  36770. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36771. const bool shiftDown = key.getModifiers().isShiftDown();
  36772. if (key.isKeyCode (KeyPress::leftKey))
  36773. {
  36774. cursorLeft (moveInWholeWordSteps, shiftDown);
  36775. }
  36776. else if (key.isKeyCode (KeyPress::rightKey))
  36777. {
  36778. cursorRight (moveInWholeWordSteps, shiftDown);
  36779. }
  36780. else if (key.isKeyCode (KeyPress::upKey))
  36781. {
  36782. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36783. scrollDown();
  36784. #if JUCE_MAC
  36785. else if (key.getModifiers().isCommandDown())
  36786. goToStartOfDocument (shiftDown);
  36787. #endif
  36788. else
  36789. cursorUp (shiftDown);
  36790. }
  36791. else if (key.isKeyCode (KeyPress::downKey))
  36792. {
  36793. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36794. scrollUp();
  36795. #if JUCE_MAC
  36796. else if (key.getModifiers().isCommandDown())
  36797. goToEndOfDocument (shiftDown);
  36798. #endif
  36799. else
  36800. cursorDown (shiftDown);
  36801. }
  36802. else if (key.isKeyCode (KeyPress::pageDownKey))
  36803. {
  36804. pageDown (shiftDown);
  36805. }
  36806. else if (key.isKeyCode (KeyPress::pageUpKey))
  36807. {
  36808. pageUp (shiftDown);
  36809. }
  36810. else if (key.isKeyCode (KeyPress::homeKey))
  36811. {
  36812. if (moveInWholeWordSteps)
  36813. goToStartOfDocument (shiftDown);
  36814. else
  36815. goToStartOfLine (shiftDown);
  36816. }
  36817. else if (key.isKeyCode (KeyPress::endKey))
  36818. {
  36819. if (moveInWholeWordSteps)
  36820. goToEndOfDocument (shiftDown);
  36821. else
  36822. goToEndOfLine (shiftDown);
  36823. }
  36824. else if (key.isKeyCode (KeyPress::backspaceKey))
  36825. {
  36826. backspace (moveInWholeWordSteps);
  36827. }
  36828. else if (key.isKeyCode (KeyPress::deleteKey))
  36829. {
  36830. deleteForward (moveInWholeWordSteps);
  36831. }
  36832. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  36833. {
  36834. copy();
  36835. }
  36836. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  36837. {
  36838. copyThenCut();
  36839. }
  36840. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0))
  36841. {
  36842. paste();
  36843. }
  36844. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  36845. {
  36846. undo();
  36847. }
  36848. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0)
  36849. || key == KeyPress (T('z'), ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36850. {
  36851. redo();
  36852. }
  36853. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  36854. {
  36855. selectAll();
  36856. }
  36857. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36858. {
  36859. insertTabAtCaret();
  36860. }
  36861. else if (key == KeyPress::returnKey)
  36862. {
  36863. newTransaction();
  36864. insertTextAtCaret (document.getNewLineCharacters());
  36865. }
  36866. else if (key.isKeyCode (KeyPress::escapeKey))
  36867. {
  36868. newTransaction();
  36869. }
  36870. else if (key.getTextCharacter() >= ' ')
  36871. {
  36872. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36873. }
  36874. else
  36875. {
  36876. return false;
  36877. }
  36878. return true;
  36879. }
  36880. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36881. {
  36882. newTransaction();
  36883. dragType = notDragging;
  36884. if (! e.mods.isPopupMenu())
  36885. {
  36886. beginDragAutoRepeat (100);
  36887. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36888. }
  36889. else
  36890. {
  36891. }
  36892. }
  36893. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36894. {
  36895. if (! e.mods.isPopupMenu())
  36896. moveCaretTo (getPositionAt (e.x, e.y), true);
  36897. }
  36898. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36899. {
  36900. newTransaction();
  36901. beginDragAutoRepeat (0);
  36902. dragType = notDragging;
  36903. }
  36904. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36905. {
  36906. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36907. CodeDocument::Position tokenEnd (tokenStart);
  36908. if (e.getNumberOfClicks() > 2)
  36909. {
  36910. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36911. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36912. }
  36913. else
  36914. {
  36915. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36916. tokenEnd.moveBy (1);
  36917. tokenStart = tokenEnd;
  36918. while (tokenStart.getIndexInLine() > 0
  36919. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36920. tokenStart.moveBy (-1);
  36921. }
  36922. moveCaretTo (tokenEnd, false);
  36923. moveCaretTo (tokenStart, true);
  36924. }
  36925. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36926. {
  36927. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36928. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36929. }
  36930. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  36931. {
  36932. if (scrollBarThatHasMoved == verticalScrollBar)
  36933. scrollToLineInternal ((int) newRangeStart);
  36934. else
  36935. scrollToColumnInternal (newRangeStart);
  36936. }
  36937. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36938. {
  36939. useSpacesForTabs = insertSpaces;
  36940. if (spacesPerTab != numSpaces)
  36941. {
  36942. spacesPerTab = numSpaces;
  36943. triggerAsyncUpdate();
  36944. }
  36945. }
  36946. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36947. {
  36948. const String line (document.getLine (lineNum));
  36949. jassert (index <= line.length());
  36950. int col = 0;
  36951. for (int i = 0; i < index; ++i)
  36952. {
  36953. if (line[i] != T('\t'))
  36954. ++col;
  36955. else
  36956. col += getTabSize() - (col % getTabSize());
  36957. }
  36958. return col;
  36959. }
  36960. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36961. {
  36962. const String line (document.getLine (lineNum));
  36963. const int lineLength = line.length();
  36964. int i, col = 0;
  36965. for (i = 0; i < lineLength; ++i)
  36966. {
  36967. if (line[i] != T('\t'))
  36968. ++col;
  36969. else
  36970. col += getTabSize() - (col % getTabSize());
  36971. if (col > column)
  36972. break;
  36973. }
  36974. return i;
  36975. }
  36976. void CodeEditorComponent::setFont (const Font& newFont)
  36977. {
  36978. font = newFont;
  36979. charWidth = font.getStringWidthFloat (T("0"));
  36980. lineHeight = roundToInt (font.getHeight());
  36981. resized();
  36982. }
  36983. void CodeEditorComponent::resetToDefaultColours()
  36984. {
  36985. coloursForTokenCategories.clear();
  36986. if (codeTokeniser != 0)
  36987. {
  36988. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36989. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36990. }
  36991. }
  36992. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36993. {
  36994. jassert (tokenType < 256);
  36995. while (coloursForTokenCategories.size() < tokenType)
  36996. coloursForTokenCategories.add (Colours::black);
  36997. coloursForTokenCategories.set (tokenType, colour);
  36998. repaint();
  36999. }
  37000. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  37001. {
  37002. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  37003. return findColour (CodeEditorComponent::defaultTextColourId);
  37004. return coloursForTokenCategories.getReference (tokenType);
  37005. }
  37006. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  37007. {
  37008. int i;
  37009. for (i = cachedIterators.size(); --i >= 0;)
  37010. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  37011. break;
  37012. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  37013. }
  37014. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  37015. {
  37016. const int maxNumCachedPositions = 5000;
  37017. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  37018. if (cachedIterators.size() == 0)
  37019. cachedIterators.add (new CodeDocument::Iterator (&document));
  37020. if (codeTokeniser == 0)
  37021. return;
  37022. for (;;)
  37023. {
  37024. CodeDocument::Iterator* last = cachedIterators.getLast();
  37025. if (last->getLine() >= maxLineNum)
  37026. break;
  37027. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  37028. cachedIterators.add (t);
  37029. const int targetLine = last->getLine() + linesBetweenCachedSources;
  37030. for (;;)
  37031. {
  37032. codeTokeniser->readNextToken (*t);
  37033. if (t->getLine() >= targetLine)
  37034. break;
  37035. if (t->isEOF())
  37036. return;
  37037. }
  37038. }
  37039. }
  37040. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  37041. {
  37042. if (codeTokeniser == 0)
  37043. return;
  37044. for (int i = cachedIterators.size(); --i >= 0;)
  37045. {
  37046. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  37047. if (t->getPosition() <= position)
  37048. {
  37049. source = *t;
  37050. break;
  37051. }
  37052. }
  37053. while (source.getPosition() < position)
  37054. {
  37055. const CodeDocument::Iterator original (source);
  37056. codeTokeniser->readNextToken (source);
  37057. if (source.getPosition() > position || source.isEOF())
  37058. {
  37059. source = original;
  37060. break;
  37061. }
  37062. }
  37063. }
  37064. END_JUCE_NAMESPACE
  37065. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  37066. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  37067. BEGIN_JUCE_NAMESPACE
  37068. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  37069. {
  37070. }
  37071. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  37072. {
  37073. }
  37074. namespace CppTokeniser
  37075. {
  37076. static bool isIdentifierStart (const tchar c) throw()
  37077. {
  37078. return CharacterFunctions::isLetter (c)
  37079. || c == T('_') || c == T('@');
  37080. }
  37081. static bool isIdentifierBody (const tchar c) throw()
  37082. {
  37083. return CharacterFunctions::isLetter (c)
  37084. || CharacterFunctions::isDigit (c)
  37085. || c == T('_') || c == T('@');
  37086. }
  37087. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  37088. {
  37089. static const tchar* keywords2Char[] =
  37090. { T("if"), T("do"), T("or"), 0 };
  37091. static const tchar* keywords3Char[] =
  37092. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  37093. static const tchar* keywords4Char[] =
  37094. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  37095. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  37096. static const tchar* keywords5Char[] =
  37097. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  37098. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  37099. static const tchar* keywords6Char[] =
  37100. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  37101. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  37102. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  37103. static const tchar* keywordsOther[] =
  37104. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  37105. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  37106. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  37107. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  37108. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  37109. int tokenLength = 0;
  37110. tchar possibleIdentifier [19];
  37111. while (isIdentifierBody (source.peekNextChar()))
  37112. {
  37113. const tchar c = source.nextChar();
  37114. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  37115. possibleIdentifier [tokenLength] = c;
  37116. ++tokenLength;
  37117. }
  37118. if (tokenLength > 1 && tokenLength <= 16)
  37119. {
  37120. possibleIdentifier [tokenLength] = 0;
  37121. const tchar** k;
  37122. switch (tokenLength)
  37123. {
  37124. case 2: k = keywords2Char; break;
  37125. case 3: k = keywords3Char; break;
  37126. case 4: k = keywords4Char; break;
  37127. case 5: k = keywords5Char; break;
  37128. case 6: k = keywords6Char; break;
  37129. default: k = keywordsOther; break;
  37130. }
  37131. int i = 0;
  37132. while (k[i] != 0)
  37133. {
  37134. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  37135. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  37136. ++i;
  37137. }
  37138. }
  37139. return CPlusPlusCodeTokeniser::tokenType_identifier;
  37140. }
  37141. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  37142. {
  37143. const juce_wchar c = source.peekNextChar();
  37144. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  37145. source.skip();
  37146. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  37147. return false;
  37148. return true;
  37149. }
  37150. static bool isHexDigit (const juce_wchar c) throw()
  37151. {
  37152. return (c >= '0' && c <= '9')
  37153. || (c >= 'a' && c <= 'f')
  37154. || (c >= 'A' && c <= 'F');
  37155. }
  37156. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  37157. {
  37158. if (source.nextChar() != '0')
  37159. return false;
  37160. juce_wchar c = source.nextChar();
  37161. if (c != 'x' && c != 'X')
  37162. return false;
  37163. int numDigits = 0;
  37164. while (isHexDigit (source.peekNextChar()))
  37165. {
  37166. ++numDigits;
  37167. source.skip();
  37168. }
  37169. if (numDigits == 0)
  37170. return false;
  37171. return skipNumberSuffix (source);
  37172. }
  37173. static bool isOctalDigit (const juce_wchar c) throw()
  37174. {
  37175. return c >= '0' && c <= '7';
  37176. }
  37177. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  37178. {
  37179. if (source.nextChar() != '0')
  37180. return false;
  37181. if (! isOctalDigit (source.nextChar()))
  37182. return false;
  37183. while (isOctalDigit (source.peekNextChar()))
  37184. source.skip();
  37185. return skipNumberSuffix (source);
  37186. }
  37187. static bool isDecimalDigit (const juce_wchar c) throw()
  37188. {
  37189. return c >= '0' && c <= '9';
  37190. }
  37191. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  37192. {
  37193. int numChars = 0;
  37194. while (isDecimalDigit (source.peekNextChar()))
  37195. {
  37196. ++numChars;
  37197. source.skip();
  37198. }
  37199. if (numChars == 0)
  37200. return false;
  37201. return skipNumberSuffix (source);
  37202. }
  37203. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  37204. {
  37205. int numDigits = 0;
  37206. while (isDecimalDigit (source.peekNextChar()))
  37207. {
  37208. source.skip();
  37209. ++numDigits;
  37210. }
  37211. const bool hasPoint = (source.peekNextChar() == '.');
  37212. if (hasPoint)
  37213. {
  37214. source.skip();
  37215. while (isDecimalDigit (source.peekNextChar()))
  37216. {
  37217. source.skip();
  37218. ++numDigits;
  37219. }
  37220. }
  37221. if (numDigits == 0)
  37222. return false;
  37223. juce_wchar c = source.peekNextChar();
  37224. const bool hasExponent = (c == 'e' || c == 'E');
  37225. if (hasExponent)
  37226. {
  37227. source.skip();
  37228. c = source.peekNextChar();
  37229. if (c == '+' || c == '-')
  37230. source.skip();
  37231. int numExpDigits = 0;
  37232. while (isDecimalDigit (source.peekNextChar()))
  37233. {
  37234. source.skip();
  37235. ++numExpDigits;
  37236. }
  37237. if (numExpDigits == 0)
  37238. return false;
  37239. }
  37240. c = source.peekNextChar();
  37241. if (c == 'f' || c == 'F')
  37242. source.skip();
  37243. else if (! (hasExponent || hasPoint))
  37244. return false;
  37245. return true;
  37246. }
  37247. static int parseNumber (CodeDocument::Iterator& source)
  37248. {
  37249. const CodeDocument::Iterator original (source);
  37250. if (parseFloatLiteral (source))
  37251. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  37252. source = original;
  37253. if (parseHexLiteral (source))
  37254. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37255. source = original;
  37256. if (parseOctalLiteral (source))
  37257. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37258. source = original;
  37259. if (parseDecimalLiteral (source))
  37260. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37261. source = original;
  37262. source.skip();
  37263. return CPlusPlusCodeTokeniser::tokenType_error;
  37264. }
  37265. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  37266. {
  37267. const juce_wchar quote = source.nextChar();
  37268. for (;;)
  37269. {
  37270. const juce_wchar c = source.nextChar();
  37271. if (c == quote || c == 0)
  37272. break;
  37273. if (c == '\\')
  37274. source.skip();
  37275. }
  37276. }
  37277. static void skipComment (CodeDocument::Iterator& source) throw()
  37278. {
  37279. bool lastWasStar = false;
  37280. for (;;)
  37281. {
  37282. const juce_wchar c = source.nextChar();
  37283. if (c == 0 || (c == T('/') && lastWasStar))
  37284. break;
  37285. lastWasStar = (c == '*');
  37286. }
  37287. }
  37288. }
  37289. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  37290. {
  37291. int result = tokenType_error;
  37292. source.skipWhitespace();
  37293. tchar firstChar = source.peekNextChar();
  37294. switch (firstChar)
  37295. {
  37296. case 0:
  37297. source.skip();
  37298. break;
  37299. case T('0'):
  37300. case T('1'):
  37301. case T('2'):
  37302. case T('3'):
  37303. case T('4'):
  37304. case T('5'):
  37305. case T('6'):
  37306. case T('7'):
  37307. case T('8'):
  37308. case T('9'):
  37309. result = CppTokeniser::parseNumber (source);
  37310. break;
  37311. case T('.'):
  37312. result = CppTokeniser::parseNumber (source);
  37313. if (result == tokenType_error)
  37314. result = tokenType_punctuation;
  37315. break;
  37316. case T(','):
  37317. case T(';'):
  37318. case T(':'):
  37319. source.skip();
  37320. result = tokenType_punctuation;
  37321. break;
  37322. case T('('):
  37323. case T(')'):
  37324. case T('{'):
  37325. case T('}'):
  37326. case T('['):
  37327. case T(']'):
  37328. source.skip();
  37329. result = tokenType_bracket;
  37330. break;
  37331. case T('"'):
  37332. case T('\''):
  37333. CppTokeniser::skipQuotedString (source);
  37334. result = tokenType_stringLiteral;
  37335. break;
  37336. case T('+'):
  37337. result = tokenType_operator;
  37338. source.skip();
  37339. if (source.peekNextChar() == T('+'))
  37340. source.skip();
  37341. else if (source.peekNextChar() == T('='))
  37342. source.skip();
  37343. break;
  37344. case T('-'):
  37345. source.skip();
  37346. result = CppTokeniser::parseNumber (source);
  37347. if (result == tokenType_error)
  37348. {
  37349. result = tokenType_operator;
  37350. if (source.peekNextChar() == T('-'))
  37351. source.skip();
  37352. else if (source.peekNextChar() == T('='))
  37353. source.skip();
  37354. }
  37355. break;
  37356. case T('*'):
  37357. case T('%'):
  37358. case T('='):
  37359. case T('!'):
  37360. result = tokenType_operator;
  37361. source.skip();
  37362. if (source.peekNextChar() == T('='))
  37363. source.skip();
  37364. break;
  37365. case T('/'):
  37366. result = tokenType_operator;
  37367. source.skip();
  37368. if (source.peekNextChar() == T('='))
  37369. {
  37370. source.skip();
  37371. }
  37372. else if (source.peekNextChar() == T('/'))
  37373. {
  37374. result = tokenType_comment;
  37375. source.skipToEndOfLine();
  37376. }
  37377. else if (source.peekNextChar() == T('*'))
  37378. {
  37379. source.skip();
  37380. result = tokenType_comment;
  37381. CppTokeniser::skipComment (source);
  37382. }
  37383. break;
  37384. case T('?'):
  37385. case T('~'):
  37386. source.skip();
  37387. result = tokenType_operator;
  37388. break;
  37389. case T('<'):
  37390. source.skip();
  37391. result = tokenType_operator;
  37392. if (source.peekNextChar() == T('='))
  37393. {
  37394. source.skip();
  37395. }
  37396. else if (source.peekNextChar() == T('<'))
  37397. {
  37398. source.skip();
  37399. if (source.peekNextChar() == T('='))
  37400. source.skip();
  37401. }
  37402. break;
  37403. case T('>'):
  37404. source.skip();
  37405. result = tokenType_operator;
  37406. if (source.peekNextChar() == T('='))
  37407. {
  37408. source.skip();
  37409. }
  37410. else if (source.peekNextChar() == T('<'))
  37411. {
  37412. source.skip();
  37413. if (source.peekNextChar() == T('='))
  37414. source.skip();
  37415. }
  37416. break;
  37417. case T('|'):
  37418. source.skip();
  37419. result = tokenType_operator;
  37420. if (source.peekNextChar() == T('='))
  37421. {
  37422. source.skip();
  37423. }
  37424. else if (source.peekNextChar() == T('|'))
  37425. {
  37426. source.skip();
  37427. if (source.peekNextChar() == T('='))
  37428. source.skip();
  37429. }
  37430. break;
  37431. case T('&'):
  37432. source.skip();
  37433. result = tokenType_operator;
  37434. if (source.peekNextChar() == T('='))
  37435. {
  37436. source.skip();
  37437. }
  37438. else if (source.peekNextChar() == T('&'))
  37439. {
  37440. source.skip();
  37441. if (source.peekNextChar() == T('='))
  37442. source.skip();
  37443. }
  37444. break;
  37445. case T('^'):
  37446. source.skip();
  37447. result = tokenType_operator;
  37448. if (source.peekNextChar() == T('='))
  37449. {
  37450. source.skip();
  37451. }
  37452. else if (source.peekNextChar() == T('^'))
  37453. {
  37454. source.skip();
  37455. if (source.peekNextChar() == T('='))
  37456. source.skip();
  37457. }
  37458. break;
  37459. case T('#'):
  37460. result = tokenType_preprocessor;
  37461. source.skipToEndOfLine();
  37462. break;
  37463. default:
  37464. if (CppTokeniser::isIdentifierStart (firstChar))
  37465. result = CppTokeniser::parseIdentifier (source);
  37466. else
  37467. source.skip();
  37468. break;
  37469. }
  37470. //jassert (result != tokenType_unknown);
  37471. return result;
  37472. }
  37473. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  37474. {
  37475. StringArray s;
  37476. s.add ("Error");
  37477. s.add ("Comment");
  37478. s.add ("C++ keyword");
  37479. s.add ("Identifier");
  37480. s.add ("Integer literal");
  37481. s.add ("Float literal");
  37482. s.add ("String literal");
  37483. s.add ("Operator");
  37484. s.add ("Bracket");
  37485. s.add ("Punctuation");
  37486. s.add ("Preprocessor line");
  37487. return s;
  37488. }
  37489. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  37490. {
  37491. const uint32 colours[] =
  37492. {
  37493. 0xffcc0000, // error
  37494. 0xff00aa00, // comment
  37495. 0xff0000cc, // keyword
  37496. 0xff000000, // identifier
  37497. 0xff880000, // int literal
  37498. 0xff885500, // float literal
  37499. 0xff990099, // string literal
  37500. 0xff225500, // operator
  37501. 0xff000055, // bracket
  37502. 0xff004400, // punctuation
  37503. 0xff660000 // preprocessor
  37504. };
  37505. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  37506. return Colour (colours [tokenType]);
  37507. return Colours::black;
  37508. }
  37509. END_JUCE_NAMESPACE
  37510. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  37511. /*** Start of inlined file: juce_ComboBox.cpp ***/
  37512. BEGIN_JUCE_NAMESPACE
  37513. ComboBox::ComboBox (const String& name)
  37514. : Component (name),
  37515. lastCurrentId (0),
  37516. isButtonDown (false),
  37517. separatorPending (false),
  37518. menuActive (false),
  37519. label (0)
  37520. {
  37521. noChoicesMessage = TRANS("(no choices)");
  37522. setRepaintsOnMouseActivity (true);
  37523. lookAndFeelChanged();
  37524. currentId.addListener (this);
  37525. }
  37526. ComboBox::~ComboBox()
  37527. {
  37528. currentId.removeListener (this);
  37529. if (menuActive)
  37530. PopupMenu::dismissAllActiveMenus();
  37531. deleteAllChildren();
  37532. }
  37533. void ComboBox::setEditableText (const bool isEditable)
  37534. {
  37535. label->setEditable (isEditable, isEditable, false);
  37536. setWantsKeyboardFocus (! isEditable);
  37537. resized();
  37538. }
  37539. bool ComboBox::isTextEditable() const throw()
  37540. {
  37541. return label->isEditable();
  37542. }
  37543. void ComboBox::setJustificationType (const Justification& justification) throw()
  37544. {
  37545. label->setJustificationType (justification);
  37546. }
  37547. const Justification ComboBox::getJustificationType() const throw()
  37548. {
  37549. return label->getJustificationType();
  37550. }
  37551. void ComboBox::setTooltip (const String& newTooltip)
  37552. {
  37553. SettableTooltipClient::setTooltip (newTooltip);
  37554. label->setTooltip (newTooltip);
  37555. }
  37556. void ComboBox::addItem (const String& newItemText,
  37557. const int newItemId) throw()
  37558. {
  37559. // you can't add empty strings to the list..
  37560. jassert (newItemText.isNotEmpty());
  37561. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  37562. jassert (newItemId != 0);
  37563. // you shouldn't use duplicate item IDs!
  37564. jassert (getItemForId (newItemId) == 0);
  37565. if (newItemText.isNotEmpty() && newItemId != 0)
  37566. {
  37567. if (separatorPending)
  37568. {
  37569. separatorPending = false;
  37570. ItemInfo* const item = new ItemInfo();
  37571. item->itemId = 0;
  37572. item->isEnabled = false;
  37573. item->isHeading = false;
  37574. items.add (item);
  37575. }
  37576. ItemInfo* const item = new ItemInfo();
  37577. item->name = newItemText;
  37578. item->itemId = newItemId;
  37579. item->isEnabled = true;
  37580. item->isHeading = false;
  37581. items.add (item);
  37582. }
  37583. }
  37584. void ComboBox::addSeparator() throw()
  37585. {
  37586. separatorPending = (items.size() > 0);
  37587. }
  37588. void ComboBox::addSectionHeading (const String& headingName) throw()
  37589. {
  37590. // you can't add empty strings to the list..
  37591. jassert (headingName.isNotEmpty());
  37592. if (headingName.isNotEmpty())
  37593. {
  37594. if (separatorPending)
  37595. {
  37596. separatorPending = false;
  37597. ItemInfo* const item = new ItemInfo();
  37598. item->itemId = 0;
  37599. item->isEnabled = false;
  37600. item->isHeading = false;
  37601. items.add (item);
  37602. }
  37603. ItemInfo* const item = new ItemInfo();
  37604. item->name = headingName;
  37605. item->itemId = 0;
  37606. item->isEnabled = true;
  37607. item->isHeading = true;
  37608. items.add (item);
  37609. }
  37610. }
  37611. void ComboBox::setItemEnabled (const int itemId,
  37612. const bool shouldBeEnabled) throw()
  37613. {
  37614. ItemInfo* const item = getItemForId (itemId);
  37615. if (item != 0)
  37616. item->isEnabled = shouldBeEnabled;
  37617. }
  37618. void ComboBox::changeItemText (const int itemId,
  37619. const String& newText) throw()
  37620. {
  37621. ItemInfo* const item = getItemForId (itemId);
  37622. jassert (item != 0);
  37623. if (item != 0)
  37624. item->name = newText;
  37625. }
  37626. void ComboBox::clear (const bool dontSendChangeMessage)
  37627. {
  37628. items.clear();
  37629. separatorPending = false;
  37630. if (! label->isEditable())
  37631. setSelectedItemIndex (-1, dontSendChangeMessage);
  37632. }
  37633. bool ComboBox::ItemInfo::isSeparator() const throw()
  37634. {
  37635. return name.isEmpty();
  37636. }
  37637. bool ComboBox::ItemInfo::isRealItem() const throw()
  37638. {
  37639. return ! (isHeading || name.isEmpty());
  37640. }
  37641. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37642. {
  37643. if (itemId != 0)
  37644. {
  37645. for (int i = items.size(); --i >= 0;)
  37646. if (items.getUnchecked(i)->itemId == itemId)
  37647. return items.getUnchecked(i);
  37648. }
  37649. return 0;
  37650. }
  37651. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37652. {
  37653. int n = 0;
  37654. for (int i = 0; i < items.size(); ++i)
  37655. {
  37656. ItemInfo* const item = items.getUnchecked(i);
  37657. if (item->isRealItem())
  37658. if (n++ == index)
  37659. return item;
  37660. }
  37661. return 0;
  37662. }
  37663. int ComboBox::getNumItems() const throw()
  37664. {
  37665. int n = 0;
  37666. for (int i = items.size(); --i >= 0;)
  37667. if (items.getUnchecked(i)->isRealItem())
  37668. ++n;
  37669. return n;
  37670. }
  37671. const String ComboBox::getItemText (const int index) const throw()
  37672. {
  37673. const ItemInfo* const item = getItemForIndex (index);
  37674. if (item != 0)
  37675. return item->name;
  37676. return String::empty;
  37677. }
  37678. int ComboBox::getItemId (const int index) const throw()
  37679. {
  37680. const ItemInfo* const item = getItemForIndex (index);
  37681. return (item != 0) ? item->itemId : 0;
  37682. }
  37683. int ComboBox::indexOfItemId (const int itemId) const throw()
  37684. {
  37685. int n = 0;
  37686. for (int i = 0; i < items.size(); ++i)
  37687. {
  37688. const ItemInfo* const item = items.getUnchecked(i);
  37689. if (item->isRealItem())
  37690. {
  37691. if (item->itemId == itemId)
  37692. return n;
  37693. ++n;
  37694. }
  37695. }
  37696. return -1;
  37697. }
  37698. int ComboBox::getSelectedItemIndex() const throw()
  37699. {
  37700. int index = indexOfItemId (currentId.getValue());
  37701. if (getText() != getItemText (index))
  37702. index = -1;
  37703. return index;
  37704. }
  37705. void ComboBox::setSelectedItemIndex (const int index,
  37706. const bool dontSendChangeMessage) throw()
  37707. {
  37708. setSelectedId (getItemId (index), dontSendChangeMessage);
  37709. }
  37710. int ComboBox::getSelectedId() const throw()
  37711. {
  37712. const ItemInfo* const item = getItemForId (currentId.getValue());
  37713. return (item != 0 && getText() == item->name)
  37714. ? item->itemId
  37715. : 0;
  37716. }
  37717. void ComboBox::setSelectedId (const int newItemId,
  37718. const bool dontSendChangeMessage) throw()
  37719. {
  37720. const ItemInfo* const item = getItemForId (newItemId);
  37721. const String newItemText (item != 0 ? item->name : String::empty);
  37722. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37723. {
  37724. if (! dontSendChangeMessage)
  37725. triggerAsyncUpdate();
  37726. label->setText (newItemText, false);
  37727. lastCurrentId = newItemId;
  37728. currentId = newItemId;
  37729. repaint(); // for the benefit of the 'none selected' text
  37730. }
  37731. }
  37732. void ComboBox::valueChanged (Value&)
  37733. {
  37734. if (lastCurrentId != (int) currentId.getValue())
  37735. setSelectedId (currentId.getValue(), false);
  37736. }
  37737. const String ComboBox::getText() const throw()
  37738. {
  37739. return label->getText();
  37740. }
  37741. void ComboBox::setText (const String& newText,
  37742. const bool dontSendChangeMessage) throw()
  37743. {
  37744. for (int i = items.size(); --i >= 0;)
  37745. {
  37746. const ItemInfo* const item = items.getUnchecked(i);
  37747. if (item->isRealItem()
  37748. && item->name == newText)
  37749. {
  37750. setSelectedId (item->itemId, dontSendChangeMessage);
  37751. return;
  37752. }
  37753. }
  37754. lastCurrentId = 0;
  37755. currentId = 0;
  37756. if (label->getText() != newText)
  37757. {
  37758. label->setText (newText, false);
  37759. if (! dontSendChangeMessage)
  37760. triggerAsyncUpdate();
  37761. }
  37762. repaint();
  37763. }
  37764. void ComboBox::showEditor()
  37765. {
  37766. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37767. label->showEditor();
  37768. }
  37769. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37770. {
  37771. textWhenNothingSelected = newMessage;
  37772. repaint();
  37773. }
  37774. const String ComboBox::getTextWhenNothingSelected() const throw()
  37775. {
  37776. return textWhenNothingSelected;
  37777. }
  37778. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37779. {
  37780. noChoicesMessage = newMessage;
  37781. }
  37782. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37783. {
  37784. return noChoicesMessage;
  37785. }
  37786. void ComboBox::paint (Graphics& g)
  37787. {
  37788. getLookAndFeel().drawComboBox (g,
  37789. getWidth(),
  37790. getHeight(),
  37791. isButtonDown,
  37792. label->getRight(),
  37793. 0,
  37794. getWidth() - label->getRight(),
  37795. getHeight(),
  37796. *this);
  37797. if (textWhenNothingSelected.isNotEmpty()
  37798. && label->getText().isEmpty()
  37799. && ! label->isBeingEdited())
  37800. {
  37801. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37802. g.setFont (label->getFont());
  37803. g.drawFittedText (textWhenNothingSelected,
  37804. label->getX() + 2, label->getY() + 1,
  37805. label->getWidth() - 4, label->getHeight() - 2,
  37806. label->getJustificationType(),
  37807. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37808. }
  37809. }
  37810. void ComboBox::resized()
  37811. {
  37812. if (getHeight() > 0 && getWidth() > 0)
  37813. getLookAndFeel().positionComboBoxText (*this, *label);
  37814. }
  37815. void ComboBox::enablementChanged()
  37816. {
  37817. repaint();
  37818. }
  37819. void ComboBox::lookAndFeelChanged()
  37820. {
  37821. repaint();
  37822. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37823. if (label != 0)
  37824. {
  37825. newLabel->setEditable (label->isEditable());
  37826. newLabel->setJustificationType (label->getJustificationType());
  37827. newLabel->setTooltip (label->getTooltip());
  37828. newLabel->setText (label->getText(), false);
  37829. }
  37830. delete label;
  37831. label = newLabel;
  37832. addAndMakeVisible (newLabel);
  37833. newLabel->addListener (this);
  37834. newLabel->addMouseListener (this, false);
  37835. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37836. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37837. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37838. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37839. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37840. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37841. resized();
  37842. }
  37843. void ComboBox::colourChanged()
  37844. {
  37845. lookAndFeelChanged();
  37846. }
  37847. bool ComboBox::keyPressed (const KeyPress& key)
  37848. {
  37849. bool used = false;
  37850. if (key.isKeyCode (KeyPress::upKey)
  37851. || key.isKeyCode (KeyPress::leftKey))
  37852. {
  37853. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37854. used = true;
  37855. }
  37856. else if (key.isKeyCode (KeyPress::downKey)
  37857. || key.isKeyCode (KeyPress::rightKey))
  37858. {
  37859. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37860. used = true;
  37861. }
  37862. else if (key.isKeyCode (KeyPress::returnKey))
  37863. {
  37864. showPopup();
  37865. used = true;
  37866. }
  37867. return used;
  37868. }
  37869. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37870. {
  37871. // only forward key events that aren't used by this component
  37872. return isKeyDown
  37873. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37874. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37875. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37876. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37877. }
  37878. void ComboBox::focusGained (FocusChangeType)
  37879. {
  37880. repaint();
  37881. }
  37882. void ComboBox::focusLost (FocusChangeType)
  37883. {
  37884. repaint();
  37885. }
  37886. void ComboBox::labelTextChanged (Label*)
  37887. {
  37888. triggerAsyncUpdate();
  37889. }
  37890. void ComboBox::showPopup()
  37891. {
  37892. if (! menuActive)
  37893. {
  37894. const int selectedId = getSelectedId();
  37895. ComponentDeletionWatcher deletionWatcher (this);
  37896. PopupMenu menu;
  37897. menu.setLookAndFeel (&getLookAndFeel());
  37898. for (int i = 0; i < items.size(); ++i)
  37899. {
  37900. const ItemInfo* const item = items.getUnchecked(i);
  37901. if (item->isSeparator())
  37902. menu.addSeparator();
  37903. else if (item->isHeading)
  37904. menu.addSectionHeader (item->name);
  37905. else
  37906. menu.addItem (item->itemId, item->name,
  37907. item->isEnabled, item->itemId == selectedId);
  37908. }
  37909. if (items.size() == 0)
  37910. menu.addItem (1, noChoicesMessage, false);
  37911. const int itemHeight = jlimit (12, 24, getHeight());
  37912. menuActive = true;
  37913. const int resultId = menu.showAt (this, selectedId,
  37914. getWidth(), 1, itemHeight);
  37915. if (deletionWatcher.hasBeenDeleted())
  37916. return;
  37917. menuActive = false;
  37918. if (resultId != 0)
  37919. setSelectedId (resultId);
  37920. }
  37921. }
  37922. void ComboBox::mouseDown (const MouseEvent& e)
  37923. {
  37924. beginDragAutoRepeat (300);
  37925. isButtonDown = isEnabled();
  37926. if (isButtonDown
  37927. && (e.eventComponent == this || ! label->isEditable()))
  37928. {
  37929. showPopup();
  37930. }
  37931. }
  37932. void ComboBox::mouseDrag (const MouseEvent& e)
  37933. {
  37934. beginDragAutoRepeat (50);
  37935. if (isButtonDown && ! e.mouseWasClicked())
  37936. showPopup();
  37937. }
  37938. void ComboBox::mouseUp (const MouseEvent& e2)
  37939. {
  37940. if (isButtonDown)
  37941. {
  37942. isButtonDown = false;
  37943. repaint();
  37944. const MouseEvent e (e2.getEventRelativeTo (this));
  37945. if (reallyContains (e.x, e.y, true)
  37946. && (e2.eventComponent == this || ! label->isEditable()))
  37947. {
  37948. showPopup();
  37949. }
  37950. }
  37951. }
  37952. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37953. {
  37954. jassert (listener != 0);
  37955. if (listener != 0)
  37956. listeners.add (listener);
  37957. }
  37958. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37959. {
  37960. listeners.removeValue (listener);
  37961. }
  37962. void ComboBox::handleAsyncUpdate()
  37963. {
  37964. for (int i = listeners.size(); --i >= 0;)
  37965. {
  37966. ((ComboBoxListener*) listeners.getUnchecked (i))->comboBoxChanged (this);
  37967. i = jmin (i, listeners.size());
  37968. }
  37969. }
  37970. END_JUCE_NAMESPACE
  37971. /*** End of inlined file: juce_ComboBox.cpp ***/
  37972. /*** Start of inlined file: juce_Label.cpp ***/
  37973. BEGIN_JUCE_NAMESPACE
  37974. Label::Label (const String& componentName,
  37975. const String& labelText)
  37976. : Component (componentName),
  37977. textValue (labelText),
  37978. lastTextValue (labelText),
  37979. font (15.0f),
  37980. justification (Justification::centredLeft),
  37981. ownerComponent (0),
  37982. horizontalBorderSize (5),
  37983. verticalBorderSize (1),
  37984. minimumHorizontalScale (0.7f),
  37985. editSingleClick (false),
  37986. editDoubleClick (false),
  37987. lossOfFocusDiscardsChanges (false)
  37988. {
  37989. setColour (TextEditor::textColourId, Colours::black);
  37990. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37991. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37992. textValue.addListener (this);
  37993. }
  37994. Label::~Label()
  37995. {
  37996. textValue.removeListener (this);
  37997. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37998. ownerComponent->removeComponentListener (this);
  37999. editor = 0;
  38000. }
  38001. void Label::setText (const String& newText,
  38002. const bool broadcastChangeMessage)
  38003. {
  38004. hideEditor (true);
  38005. if (lastTextValue != newText)
  38006. {
  38007. lastTextValue = newText;
  38008. textValue = newText;
  38009. repaint();
  38010. textWasChanged();
  38011. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  38012. componentMovedOrResized (*ownerComponent, true, true);
  38013. if (broadcastChangeMessage)
  38014. callChangeListeners();
  38015. }
  38016. }
  38017. const String Label::getText (const bool returnActiveEditorContents) const throw()
  38018. {
  38019. return (returnActiveEditorContents && isBeingEdited())
  38020. ? editor->getText()
  38021. : textValue.toString();
  38022. }
  38023. void Label::valueChanged (Value&)
  38024. {
  38025. if (lastTextValue != textValue.toString())
  38026. setText (textValue.toString(), true);
  38027. }
  38028. void Label::setFont (const Font& newFont) throw()
  38029. {
  38030. font = newFont;
  38031. repaint();
  38032. }
  38033. const Font& Label::getFont() const throw()
  38034. {
  38035. return font;
  38036. }
  38037. void Label::setEditable (const bool editOnSingleClick,
  38038. const bool editOnDoubleClick,
  38039. const bool lossOfFocusDiscardsChanges_) throw()
  38040. {
  38041. editSingleClick = editOnSingleClick;
  38042. editDoubleClick = editOnDoubleClick;
  38043. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  38044. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  38045. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  38046. }
  38047. void Label::setJustificationType (const Justification& justification_) throw()
  38048. {
  38049. justification = justification_;
  38050. repaint();
  38051. }
  38052. void Label::setBorderSize (int h, int v)
  38053. {
  38054. horizontalBorderSize = h;
  38055. verticalBorderSize = v;
  38056. repaint();
  38057. }
  38058. void Label::attachToComponent (Component* owner,
  38059. const bool onLeft)
  38060. {
  38061. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  38062. ownerComponent->removeComponentListener (this);
  38063. deletionWatcher = 0;
  38064. ownerComponent = owner;
  38065. leftOfOwnerComp = onLeft;
  38066. if (ownerComponent != 0)
  38067. {
  38068. deletionWatcher = new ComponentDeletionWatcher (owner);
  38069. setVisible (owner->isVisible());
  38070. ownerComponent->addComponentListener (this);
  38071. componentParentHierarchyChanged (*ownerComponent);
  38072. componentMovedOrResized (*ownerComponent, true, true);
  38073. }
  38074. }
  38075. void Label::componentMovedOrResized (Component& component,
  38076. bool /*wasMoved*/,
  38077. bool /*wasResized*/)
  38078. {
  38079. if (leftOfOwnerComp)
  38080. {
  38081. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  38082. component.getHeight());
  38083. setTopRightPosition (component.getX(), component.getY());
  38084. }
  38085. else
  38086. {
  38087. setSize (component.getWidth(),
  38088. 8 + roundToInt (getFont().getHeight()));
  38089. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  38090. }
  38091. }
  38092. void Label::componentParentHierarchyChanged (Component& component)
  38093. {
  38094. if (component.getParentComponent() != 0)
  38095. component.getParentComponent()->addChildComponent (this);
  38096. }
  38097. void Label::componentVisibilityChanged (Component& component)
  38098. {
  38099. setVisible (component.isVisible());
  38100. }
  38101. void Label::textWasEdited()
  38102. {
  38103. }
  38104. void Label::textWasChanged()
  38105. {
  38106. }
  38107. void Label::showEditor()
  38108. {
  38109. if (editor == 0)
  38110. {
  38111. addAndMakeVisible (editor = createEditorComponent());
  38112. editor->setText (getText(), false);
  38113. editor->addListener (this);
  38114. editor->grabKeyboardFocus();
  38115. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  38116. editor->addListener (this);
  38117. resized();
  38118. repaint();
  38119. editorShown (editor);
  38120. enterModalState();
  38121. editor->grabKeyboardFocus();
  38122. }
  38123. }
  38124. void Label::editorShown (TextEditor* /*editorComponent*/)
  38125. {
  38126. }
  38127. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  38128. {
  38129. }
  38130. bool Label::updateFromTextEditorContents()
  38131. {
  38132. jassert (editor != 0);
  38133. const String newText (editor->getText());
  38134. if (textValue.toString() != newText)
  38135. {
  38136. lastTextValue = newText;
  38137. textValue = newText;
  38138. repaint();
  38139. textWasChanged();
  38140. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  38141. componentMovedOrResized (*ownerComponent, true, true);
  38142. return true;
  38143. }
  38144. return false;
  38145. }
  38146. void Label::hideEditor (const bool discardCurrentEditorContents)
  38147. {
  38148. if (editor != 0)
  38149. {
  38150. editorAboutToBeHidden (editor);
  38151. const bool changed = (! discardCurrentEditorContents)
  38152. && updateFromTextEditorContents();
  38153. editor = 0;
  38154. repaint();
  38155. if (changed)
  38156. textWasEdited();
  38157. exitModalState (0);
  38158. if (changed && isValidComponent())
  38159. callChangeListeners();
  38160. }
  38161. }
  38162. void Label::inputAttemptWhenModal()
  38163. {
  38164. if (editor != 0)
  38165. {
  38166. if (lossOfFocusDiscardsChanges)
  38167. textEditorEscapeKeyPressed (*editor);
  38168. else
  38169. textEditorReturnKeyPressed (*editor);
  38170. }
  38171. }
  38172. bool Label::isBeingEdited() const throw()
  38173. {
  38174. return editor != 0;
  38175. }
  38176. TextEditor* Label::createEditorComponent()
  38177. {
  38178. TextEditor* const ed = new TextEditor (getName());
  38179. ed->setFont (font);
  38180. // copy these colours from our own settings..
  38181. const int cols[] = { TextEditor::backgroundColourId,
  38182. TextEditor::textColourId,
  38183. TextEditor::highlightColourId,
  38184. TextEditor::highlightedTextColourId,
  38185. TextEditor::caretColourId,
  38186. TextEditor::outlineColourId,
  38187. TextEditor::focusedOutlineColourId,
  38188. TextEditor::shadowColourId };
  38189. for (int i = 0; i < numElementsInArray (cols); ++i)
  38190. ed->setColour (cols[i], findColour (cols[i]));
  38191. return ed;
  38192. }
  38193. void Label::paint (Graphics& g)
  38194. {
  38195. getLookAndFeel().drawLabel (g, *this);
  38196. }
  38197. void Label::mouseUp (const MouseEvent& e)
  38198. {
  38199. if (editSingleClick
  38200. && e.mouseWasClicked()
  38201. && contains (e.x, e.y)
  38202. && ! e.mods.isPopupMenu())
  38203. {
  38204. showEditor();
  38205. }
  38206. }
  38207. void Label::mouseDoubleClick (const MouseEvent& e)
  38208. {
  38209. if (editDoubleClick && ! e.mods.isPopupMenu())
  38210. showEditor();
  38211. }
  38212. void Label::resized()
  38213. {
  38214. if (editor != 0)
  38215. editor->setBoundsInset (BorderSize (0));
  38216. }
  38217. void Label::focusGained (FocusChangeType cause)
  38218. {
  38219. if (editSingleClick && cause == focusChangedByTabKey)
  38220. showEditor();
  38221. }
  38222. void Label::enablementChanged()
  38223. {
  38224. repaint();
  38225. }
  38226. void Label::colourChanged()
  38227. {
  38228. repaint();
  38229. }
  38230. void Label::setMinimumHorizontalScale (const float newScale)
  38231. {
  38232. if (minimumHorizontalScale != newScale)
  38233. {
  38234. minimumHorizontalScale = newScale;
  38235. repaint();
  38236. }
  38237. }
  38238. // We'll use a custom focus traverser here to make sure focus goes from the
  38239. // text editor to another component rather than back to the label itself.
  38240. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  38241. {
  38242. public:
  38243. LabelKeyboardFocusTraverser() {}
  38244. Component* getNextComponent (Component* current)
  38245. {
  38246. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  38247. ? current->getParentComponent() : current);
  38248. }
  38249. Component* getPreviousComponent (Component* current)
  38250. {
  38251. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  38252. ? current->getParentComponent() : current);
  38253. }
  38254. };
  38255. KeyboardFocusTraverser* Label::createFocusTraverser()
  38256. {
  38257. return new LabelKeyboardFocusTraverser();
  38258. }
  38259. void Label::addListener (LabelListener* const listener) throw()
  38260. {
  38261. jassert (listener != 0);
  38262. if (listener != 0)
  38263. listeners.add (listener);
  38264. }
  38265. void Label::removeListener (LabelListener* const listener) throw()
  38266. {
  38267. listeners.removeValue (listener);
  38268. }
  38269. void Label::callChangeListeners()
  38270. {
  38271. for (int i = listeners.size(); --i >= 0;)
  38272. {
  38273. ((LabelListener*) listeners.getUnchecked (i))->labelTextChanged (this);
  38274. i = jmin (i, listeners.size());
  38275. }
  38276. }
  38277. void Label::textEditorTextChanged (TextEditor& ed)
  38278. {
  38279. if (editor != 0)
  38280. {
  38281. jassert (&ed == editor);
  38282. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  38283. {
  38284. if (lossOfFocusDiscardsChanges)
  38285. textEditorEscapeKeyPressed (ed);
  38286. else
  38287. textEditorReturnKeyPressed (ed);
  38288. }
  38289. }
  38290. }
  38291. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  38292. {
  38293. if (editor != 0)
  38294. {
  38295. jassert (&ed == editor);
  38296. (void) ed;
  38297. const bool changed = updateFromTextEditorContents();
  38298. hideEditor (true);
  38299. if (changed)
  38300. {
  38301. textWasEdited();
  38302. if (isValidComponent())
  38303. callChangeListeners();
  38304. }
  38305. }
  38306. }
  38307. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  38308. {
  38309. if (editor != 0)
  38310. {
  38311. jassert (&ed == editor);
  38312. (void) ed;
  38313. editor->setText (textValue.toString(), false);
  38314. hideEditor (true);
  38315. }
  38316. }
  38317. void Label::textEditorFocusLost (TextEditor& ed)
  38318. {
  38319. textEditorTextChanged (ed);
  38320. }
  38321. END_JUCE_NAMESPACE
  38322. /*** End of inlined file: juce_Label.cpp ***/
  38323. /*** Start of inlined file: juce_ListBox.cpp ***/
  38324. BEGIN_JUCE_NAMESPACE
  38325. class ListBoxRowComponent : public Component,
  38326. public TooltipClient
  38327. {
  38328. public:
  38329. ListBoxRowComponent (ListBox& owner_)
  38330. : owner (owner_),
  38331. row (-1),
  38332. selected (false),
  38333. isDragging (false)
  38334. {
  38335. }
  38336. ~ListBoxRowComponent()
  38337. {
  38338. deleteAllChildren();
  38339. }
  38340. void paint (Graphics& g)
  38341. {
  38342. if (owner.getModel() != 0)
  38343. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  38344. }
  38345. void update (const int row_, const bool selected_)
  38346. {
  38347. if (row != row_ || selected != selected_)
  38348. {
  38349. repaint();
  38350. row = row_;
  38351. selected = selected_;
  38352. }
  38353. if (owner.getModel() != 0)
  38354. {
  38355. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  38356. if (customComp != 0)
  38357. {
  38358. addAndMakeVisible (customComp);
  38359. customComp->setBounds (0, 0, getWidth(), getHeight());
  38360. for (int i = getNumChildComponents(); --i >= 0;)
  38361. if (getChildComponent (i) != customComp)
  38362. delete getChildComponent (i);
  38363. }
  38364. else
  38365. {
  38366. deleteAllChildren();
  38367. }
  38368. }
  38369. }
  38370. void mouseDown (const MouseEvent& e)
  38371. {
  38372. isDragging = false;
  38373. selectRowOnMouseUp = false;
  38374. if (isEnabled())
  38375. {
  38376. if (! selected)
  38377. {
  38378. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38379. if (owner.getModel() != 0)
  38380. owner.getModel()->listBoxItemClicked (row, e);
  38381. }
  38382. else
  38383. {
  38384. selectRowOnMouseUp = true;
  38385. }
  38386. }
  38387. }
  38388. void mouseUp (const MouseEvent& e)
  38389. {
  38390. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  38391. {
  38392. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38393. if (owner.getModel() != 0)
  38394. owner.getModel()->listBoxItemClicked (row, e);
  38395. }
  38396. }
  38397. void mouseDoubleClick (const MouseEvent& e)
  38398. {
  38399. if (owner.getModel() != 0 && isEnabled())
  38400. owner.getModel()->listBoxItemDoubleClicked (row, e);
  38401. }
  38402. void mouseDrag (const MouseEvent& e)
  38403. {
  38404. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  38405. {
  38406. const SparseSet <int> selectedRows (owner.getSelectedRows());
  38407. if (selectedRows.size() > 0)
  38408. {
  38409. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  38410. if (dragDescription.isNotEmpty())
  38411. {
  38412. isDragging = true;
  38413. owner.startDragAndDrop (e, dragDescription);
  38414. }
  38415. }
  38416. }
  38417. }
  38418. void resized()
  38419. {
  38420. if (getNumChildComponents() > 0)
  38421. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  38422. }
  38423. const String getTooltip()
  38424. {
  38425. if (owner.getModel() != 0)
  38426. return owner.getModel()->getTooltipForRow (row);
  38427. return String::empty;
  38428. }
  38429. juce_UseDebuggingNewOperator
  38430. bool neededFlag;
  38431. private:
  38432. ListBox& owner;
  38433. int row;
  38434. bool selected, isDragging, selectRowOnMouseUp;
  38435. ListBoxRowComponent (const ListBoxRowComponent&);
  38436. const ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  38437. };
  38438. class ListViewport : public Viewport
  38439. {
  38440. public:
  38441. int firstIndex, firstWholeIndex, lastWholeIndex;
  38442. bool hasUpdated;
  38443. ListViewport (ListBox& owner_)
  38444. : owner (owner_)
  38445. {
  38446. setWantsKeyboardFocus (false);
  38447. setViewedComponent (new Component());
  38448. getViewedComponent()->addMouseListener (this, false);
  38449. getViewedComponent()->setWantsKeyboardFocus (false);
  38450. }
  38451. ~ListViewport()
  38452. {
  38453. getViewedComponent()->removeMouseListener (this);
  38454. getViewedComponent()->deleteAllChildren();
  38455. }
  38456. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  38457. {
  38458. return (ListBoxRowComponent*) getViewedComponent()
  38459. ->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents()));
  38460. }
  38461. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  38462. {
  38463. const int index = getIndexOfChildComponent (rowComponent);
  38464. const int num = getViewedComponent()->getNumChildComponents();
  38465. for (int i = num; --i >= 0;)
  38466. if (((firstIndex + i) % jmax (1, num)) == index)
  38467. return firstIndex + i;
  38468. return -1;
  38469. }
  38470. Component* getComponentForRowIfOnscreen (const int row) const throw()
  38471. {
  38472. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  38473. ? getComponentForRow (row) : 0;
  38474. }
  38475. void visibleAreaChanged (int, int, int, int)
  38476. {
  38477. updateVisibleArea (true);
  38478. if (owner.getModel() != 0)
  38479. owner.getModel()->listWasScrolled();
  38480. }
  38481. void updateVisibleArea (const bool makeSureItUpdatesContent)
  38482. {
  38483. hasUpdated = false;
  38484. const int newX = getViewedComponent()->getX();
  38485. int newY = getViewedComponent()->getY();
  38486. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  38487. const int newH = owner.totalItems * owner.getRowHeight();
  38488. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  38489. newY = getMaximumVisibleHeight() - newH;
  38490. getViewedComponent()->setBounds (newX, newY, newW, newH);
  38491. if (makeSureItUpdatesContent && ! hasUpdated)
  38492. updateContents();
  38493. }
  38494. void updateContents()
  38495. {
  38496. hasUpdated = true;
  38497. const int rowHeight = owner.getRowHeight();
  38498. if (rowHeight > 0)
  38499. {
  38500. const int y = getViewPositionY();
  38501. const int w = getViewedComponent()->getWidth();
  38502. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  38503. while (numNeeded > getViewedComponent()->getNumChildComponents())
  38504. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  38505. jassert (numNeeded >= 0);
  38506. while (numNeeded < getViewedComponent()->getNumChildComponents())
  38507. {
  38508. Component* const rowToRemove
  38509. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  38510. delete rowToRemove;
  38511. }
  38512. firstIndex = y / rowHeight;
  38513. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  38514. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  38515. for (int i = 0; i < numNeeded; ++i)
  38516. {
  38517. const int row = i + firstIndex;
  38518. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  38519. if (rowComp != 0)
  38520. {
  38521. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  38522. rowComp->update (row, owner.isRowSelected (row));
  38523. }
  38524. }
  38525. }
  38526. if (owner.headerComponent != 0)
  38527. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  38528. owner.outlineThickness,
  38529. jmax (owner.getWidth() - owner.outlineThickness * 2,
  38530. getViewedComponent()->getWidth()),
  38531. owner.headerComponent->getHeight());
  38532. }
  38533. void paint (Graphics& g)
  38534. {
  38535. if (isOpaque())
  38536. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  38537. }
  38538. bool keyPressed (const KeyPress& key)
  38539. {
  38540. if (key.isKeyCode (KeyPress::upKey)
  38541. || key.isKeyCode (KeyPress::downKey)
  38542. || key.isKeyCode (KeyPress::pageUpKey)
  38543. || key.isKeyCode (KeyPress::pageDownKey)
  38544. || key.isKeyCode (KeyPress::homeKey)
  38545. || key.isKeyCode (KeyPress::endKey))
  38546. {
  38547. // we want to avoid these keypresses going to the viewport, and instead allow
  38548. // them to pass up to our listbox..
  38549. return false;
  38550. }
  38551. return Viewport::keyPressed (key);
  38552. }
  38553. juce_UseDebuggingNewOperator
  38554. private:
  38555. ListBox& owner;
  38556. ListViewport (const ListViewport&);
  38557. const ListViewport& operator= (const ListViewport&);
  38558. };
  38559. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  38560. : Component (name),
  38561. model (model_),
  38562. headerComponent (0),
  38563. totalItems (0),
  38564. rowHeight (22),
  38565. minimumRowWidth (0),
  38566. outlineThickness (0),
  38567. lastRowSelected (-1),
  38568. mouseMoveSelects (false),
  38569. multipleSelection (false),
  38570. hasDoneInitialUpdate (false)
  38571. {
  38572. addAndMakeVisible (viewport = new ListViewport (*this));
  38573. setWantsKeyboardFocus (true);
  38574. colourChanged();
  38575. }
  38576. ListBox::~ListBox()
  38577. {
  38578. deleteAllChildren();
  38579. }
  38580. void ListBox::setModel (ListBoxModel* const newModel)
  38581. {
  38582. if (model != newModel)
  38583. {
  38584. model = newModel;
  38585. updateContent();
  38586. }
  38587. }
  38588. void ListBox::setMultipleSelectionEnabled (bool b)
  38589. {
  38590. multipleSelection = b;
  38591. }
  38592. void ListBox::setMouseMoveSelectsRows (bool b)
  38593. {
  38594. mouseMoveSelects = b;
  38595. if (b)
  38596. addMouseListener (this, true);
  38597. }
  38598. void ListBox::paint (Graphics& g)
  38599. {
  38600. if (! hasDoneInitialUpdate)
  38601. updateContent();
  38602. g.fillAll (findColour (backgroundColourId));
  38603. }
  38604. void ListBox::paintOverChildren (Graphics& g)
  38605. {
  38606. if (outlineThickness > 0)
  38607. {
  38608. g.setColour (findColour (outlineColourId));
  38609. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38610. }
  38611. }
  38612. void ListBox::resized()
  38613. {
  38614. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38615. outlineThickness,
  38616. outlineThickness,
  38617. outlineThickness));
  38618. viewport->setSingleStepSizes (20, getRowHeight());
  38619. viewport->updateVisibleArea (false);
  38620. }
  38621. void ListBox::visibilityChanged()
  38622. {
  38623. viewport->updateVisibleArea (true);
  38624. }
  38625. Viewport* ListBox::getViewport() const throw()
  38626. {
  38627. return viewport;
  38628. }
  38629. void ListBox::updateContent()
  38630. {
  38631. hasDoneInitialUpdate = true;
  38632. totalItems = (model != 0) ? model->getNumRows() : 0;
  38633. bool selectionChanged = false;
  38634. if (selected [selected.size() - 1] >= totalItems)
  38635. {
  38636. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38637. lastRowSelected = getSelectedRow (0);
  38638. selectionChanged = true;
  38639. }
  38640. viewport->updateVisibleArea (isVisible());
  38641. viewport->resized();
  38642. if (selectionChanged && model != 0)
  38643. model->selectedRowsChanged (lastRowSelected);
  38644. }
  38645. void ListBox::selectRow (const int row,
  38646. bool dontScroll,
  38647. bool deselectOthersFirst)
  38648. {
  38649. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38650. }
  38651. void ListBox::selectRowInternal (const int row,
  38652. bool dontScroll,
  38653. bool deselectOthersFirst,
  38654. bool isMouseClick)
  38655. {
  38656. if (! multipleSelection)
  38657. deselectOthersFirst = true;
  38658. if ((! isRowSelected (row))
  38659. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38660. {
  38661. if (((unsigned int) row) < (unsigned int) totalItems)
  38662. {
  38663. if (deselectOthersFirst)
  38664. selected.clear();
  38665. selected.addRange (row, 1);
  38666. if (getHeight() == 0 || getWidth() == 0)
  38667. dontScroll = true;
  38668. viewport->hasUpdated = false;
  38669. if (row < viewport->firstWholeIndex && ! dontScroll)
  38670. {
  38671. viewport->setViewPosition (viewport->getViewPositionX(),
  38672. row * getRowHeight());
  38673. }
  38674. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38675. {
  38676. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38677. if (row >= lastRowSelected + rowsOnScreen
  38678. && rowsOnScreen < totalItems - 1
  38679. && ! isMouseClick)
  38680. {
  38681. viewport->setViewPosition (viewport->getViewPositionX(),
  38682. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38683. * getRowHeight());
  38684. }
  38685. else
  38686. {
  38687. viewport->setViewPosition (viewport->getViewPositionX(),
  38688. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38689. }
  38690. }
  38691. if (! viewport->hasUpdated)
  38692. viewport->updateContents();
  38693. lastRowSelected = row;
  38694. model->selectedRowsChanged (row);
  38695. }
  38696. else
  38697. {
  38698. if (deselectOthersFirst)
  38699. deselectAllRows();
  38700. }
  38701. }
  38702. }
  38703. void ListBox::deselectRow (const int row)
  38704. {
  38705. if (selected.contains (row))
  38706. {
  38707. selected.removeRange (row, 1);
  38708. if (row == lastRowSelected)
  38709. lastRowSelected = getSelectedRow (0);
  38710. viewport->updateContents();
  38711. model->selectedRowsChanged (lastRowSelected);
  38712. }
  38713. }
  38714. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38715. const bool sendNotificationEventToModel)
  38716. {
  38717. selected = setOfRowsToBeSelected;
  38718. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38719. if (! isRowSelected (lastRowSelected))
  38720. lastRowSelected = getSelectedRow (0);
  38721. viewport->updateContents();
  38722. if ((model != 0) && sendNotificationEventToModel)
  38723. model->selectedRowsChanged (lastRowSelected);
  38724. }
  38725. const SparseSet<int> ListBox::getSelectedRows() const
  38726. {
  38727. return selected;
  38728. }
  38729. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38730. {
  38731. if (multipleSelection && (firstRow != lastRow))
  38732. {
  38733. const int numRows = totalItems - 1;
  38734. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38735. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38736. selected.addRange (jmin (firstRow, lastRow),
  38737. abs (firstRow - lastRow) + 1);
  38738. selected.removeRange (lastRow, 1);
  38739. }
  38740. selectRowInternal (lastRow, false, false, true);
  38741. }
  38742. void ListBox::flipRowSelection (const int row)
  38743. {
  38744. if (isRowSelected (row))
  38745. deselectRow (row);
  38746. else
  38747. selectRowInternal (row, false, false, true);
  38748. }
  38749. void ListBox::deselectAllRows()
  38750. {
  38751. if (! selected.isEmpty())
  38752. {
  38753. selected.clear();
  38754. lastRowSelected = -1;
  38755. viewport->updateContents();
  38756. if (model != 0)
  38757. model->selectedRowsChanged (lastRowSelected);
  38758. }
  38759. }
  38760. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38761. const ModifierKeys& mods)
  38762. {
  38763. if (multipleSelection && mods.isCommandDown())
  38764. {
  38765. flipRowSelection (row);
  38766. }
  38767. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38768. {
  38769. selectRangeOfRows (lastRowSelected, row);
  38770. }
  38771. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38772. {
  38773. selectRowInternal (row, false, true, true);
  38774. }
  38775. }
  38776. int ListBox::getNumSelectedRows() const
  38777. {
  38778. return selected.size();
  38779. }
  38780. int ListBox::getSelectedRow (const int index) const
  38781. {
  38782. return (((unsigned int) index) < (unsigned int) selected.size())
  38783. ? selected [index] : -1;
  38784. }
  38785. bool ListBox::isRowSelected (const int row) const
  38786. {
  38787. return selected.contains (row);
  38788. }
  38789. int ListBox::getLastRowSelected() const
  38790. {
  38791. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38792. }
  38793. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38794. {
  38795. if (((unsigned int) x) < (unsigned int) getWidth())
  38796. {
  38797. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38798. if (((unsigned int) row) < (unsigned int) totalItems)
  38799. return row;
  38800. }
  38801. return -1;
  38802. }
  38803. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38804. {
  38805. if (((unsigned int) x) < (unsigned int) getWidth())
  38806. {
  38807. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38808. return jlimit (0, totalItems, row);
  38809. }
  38810. return -1;
  38811. }
  38812. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38813. {
  38814. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38815. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38816. }
  38817. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38818. {
  38819. return viewport->getRowNumberOfComponent (rowComponent);
  38820. }
  38821. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38822. const bool relativeToComponentTopLeft) const throw()
  38823. {
  38824. const int rowHeight = getRowHeight();
  38825. int y = viewport->getY() + rowHeight * rowNumber;
  38826. if (relativeToComponentTopLeft)
  38827. y -= viewport->getViewPositionY();
  38828. return Rectangle<int> (viewport->getX(), y,
  38829. viewport->getViewedComponent()->getWidth(), rowHeight);
  38830. }
  38831. void ListBox::setVerticalPosition (const double proportion)
  38832. {
  38833. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38834. viewport->setViewPosition (viewport->getViewPositionX(),
  38835. jmax (0, roundToInt (proportion * offscreen)));
  38836. }
  38837. double ListBox::getVerticalPosition() const
  38838. {
  38839. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38840. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38841. : 0;
  38842. }
  38843. int ListBox::getVisibleRowWidth() const throw()
  38844. {
  38845. return viewport->getViewWidth();
  38846. }
  38847. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38848. {
  38849. if (row < viewport->firstWholeIndex)
  38850. {
  38851. viewport->setViewPosition (viewport->getViewPositionX(),
  38852. row * getRowHeight());
  38853. }
  38854. else if (row >= viewport->lastWholeIndex)
  38855. {
  38856. viewport->setViewPosition (viewport->getViewPositionX(),
  38857. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38858. }
  38859. }
  38860. bool ListBox::keyPressed (const KeyPress& key)
  38861. {
  38862. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38863. const bool multiple = multipleSelection
  38864. && (lastRowSelected >= 0)
  38865. && (key.getModifiers().isShiftDown()
  38866. || key.getModifiers().isCtrlDown()
  38867. || key.getModifiers().isCommandDown());
  38868. if (key.isKeyCode (KeyPress::upKey))
  38869. {
  38870. if (multiple)
  38871. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38872. else
  38873. selectRow (jmax (0, lastRowSelected - 1));
  38874. }
  38875. else if (key.isKeyCode (KeyPress::returnKey)
  38876. && isRowSelected (lastRowSelected))
  38877. {
  38878. if (model != 0)
  38879. model->returnKeyPressed (lastRowSelected);
  38880. }
  38881. else if (key.isKeyCode (KeyPress::pageUpKey))
  38882. {
  38883. if (multiple)
  38884. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38885. else
  38886. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38887. }
  38888. else if (key.isKeyCode (KeyPress::pageDownKey))
  38889. {
  38890. if (multiple)
  38891. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38892. else
  38893. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38894. }
  38895. else if (key.isKeyCode (KeyPress::homeKey))
  38896. {
  38897. if (multiple && key.getModifiers().isShiftDown())
  38898. selectRangeOfRows (lastRowSelected, 0);
  38899. else
  38900. selectRow (0);
  38901. }
  38902. else if (key.isKeyCode (KeyPress::endKey))
  38903. {
  38904. if (multiple && key.getModifiers().isShiftDown())
  38905. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38906. else
  38907. selectRow (totalItems - 1);
  38908. }
  38909. else if (key.isKeyCode (KeyPress::downKey))
  38910. {
  38911. if (multiple)
  38912. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38913. else
  38914. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38915. }
  38916. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38917. && isRowSelected (lastRowSelected))
  38918. {
  38919. if (model != 0)
  38920. model->deleteKeyPressed (lastRowSelected);
  38921. }
  38922. else if (multiple && key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  38923. {
  38924. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38925. }
  38926. else
  38927. {
  38928. return false;
  38929. }
  38930. return true;
  38931. }
  38932. bool ListBox::keyStateChanged (const bool isKeyDown)
  38933. {
  38934. return isKeyDown
  38935. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38936. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38937. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38938. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38939. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38940. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38941. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38942. }
  38943. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38944. {
  38945. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38946. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38947. }
  38948. void ListBox::mouseMove (const MouseEvent& e)
  38949. {
  38950. if (mouseMoveSelects)
  38951. {
  38952. const MouseEvent e2 (e.getEventRelativeTo (this));
  38953. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38954. lastMouseX = e2.x;
  38955. lastMouseY = e2.y;
  38956. }
  38957. }
  38958. void ListBox::mouseExit (const MouseEvent& e)
  38959. {
  38960. mouseMove (e);
  38961. }
  38962. void ListBox::mouseUp (const MouseEvent& e)
  38963. {
  38964. if (e.mouseWasClicked() && model != 0)
  38965. model->backgroundClicked();
  38966. }
  38967. void ListBox::setRowHeight (const int newHeight)
  38968. {
  38969. rowHeight = jmax (1, newHeight);
  38970. viewport->setSingleStepSizes (20, rowHeight);
  38971. updateContent();
  38972. }
  38973. int ListBox::getNumRowsOnScreen() const throw()
  38974. {
  38975. return viewport->getMaximumVisibleHeight() / rowHeight;
  38976. }
  38977. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38978. {
  38979. minimumRowWidth = newMinimumWidth;
  38980. updateContent();
  38981. }
  38982. int ListBox::getVisibleContentWidth() const throw()
  38983. {
  38984. return viewport->getMaximumVisibleWidth();
  38985. }
  38986. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38987. {
  38988. return viewport->getVerticalScrollBar();
  38989. }
  38990. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38991. {
  38992. return viewport->getHorizontalScrollBar();
  38993. }
  38994. void ListBox::colourChanged()
  38995. {
  38996. setOpaque (findColour (backgroundColourId).isOpaque());
  38997. viewport->setOpaque (isOpaque());
  38998. repaint();
  38999. }
  39000. void ListBox::setOutlineThickness (const int outlineThickness_)
  39001. {
  39002. outlineThickness = outlineThickness_;
  39003. resized();
  39004. }
  39005. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  39006. {
  39007. if (headerComponent != newHeaderComponent)
  39008. {
  39009. delete headerComponent;
  39010. headerComponent = newHeaderComponent;
  39011. addAndMakeVisible (newHeaderComponent);
  39012. ListBox::resized();
  39013. }
  39014. }
  39015. void ListBox::repaintRow (const int rowNumber) throw()
  39016. {
  39017. const Rectangle<int> r (getRowPosition (rowNumber, true));
  39018. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  39019. }
  39020. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  39021. {
  39022. Rectangle<int> imageArea;
  39023. const int firstRow = getRowContainingPosition (0, 0);
  39024. int i;
  39025. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  39026. {
  39027. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  39028. if (rowComp != 0 && isRowSelected (firstRow + i))
  39029. {
  39030. int x = 0, y = 0;
  39031. rowComp->relativePositionToOtherComponent (this, x, y);
  39032. const Rectangle<int> rowRect (x, y, rowComp->getWidth(), rowComp->getHeight());
  39033. if (imageArea.isEmpty())
  39034. imageArea = rowRect;
  39035. else
  39036. imageArea = imageArea.getUnion (rowRect);
  39037. }
  39038. }
  39039. imageArea = imageArea.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  39040. imageX = imageArea.getX();
  39041. imageY = imageArea.getY();
  39042. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  39043. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  39044. {
  39045. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  39046. if (rowComp != 0 && isRowSelected (firstRow + i))
  39047. {
  39048. int x = 0, y = 0;
  39049. rowComp->relativePositionToOtherComponent (this, x, y);
  39050. Graphics g (*snapshot);
  39051. g.setOrigin (x - imageX, y - imageY);
  39052. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  39053. rowComp->paintEntireComponent (g);
  39054. }
  39055. }
  39056. return snapshot;
  39057. }
  39058. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  39059. {
  39060. DragAndDropContainer* const dragContainer
  39061. = DragAndDropContainer::findParentDragContainerFor (this);
  39062. if (dragContainer != 0)
  39063. {
  39064. int x, y;
  39065. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  39066. dragImage->multiplyAllAlphas (0.6f);
  39067. MouseEvent e2 (e.getEventRelativeTo (this));
  39068. const Point<int> p (x - e2.x, y - e2.y);
  39069. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  39070. }
  39071. else
  39072. {
  39073. // to be able to do a drag-and-drop operation, the listbox needs to
  39074. // be inside a component which is also a DragAndDropContainer.
  39075. jassertfalse
  39076. }
  39077. }
  39078. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  39079. {
  39080. (void) existingComponentToUpdate;
  39081. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  39082. return 0;
  39083. }
  39084. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  39085. {
  39086. }
  39087. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  39088. {
  39089. }
  39090. void ListBoxModel::backgroundClicked()
  39091. {
  39092. }
  39093. void ListBoxModel::selectedRowsChanged (int)
  39094. {
  39095. }
  39096. void ListBoxModel::deleteKeyPressed (int)
  39097. {
  39098. }
  39099. void ListBoxModel::returnKeyPressed (int)
  39100. {
  39101. }
  39102. void ListBoxModel::listWasScrolled()
  39103. {
  39104. }
  39105. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  39106. {
  39107. return String::empty;
  39108. }
  39109. const String ListBoxModel::getTooltipForRow (int)
  39110. {
  39111. return String::empty;
  39112. }
  39113. END_JUCE_NAMESPACE
  39114. /*** End of inlined file: juce_ListBox.cpp ***/
  39115. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  39116. BEGIN_JUCE_NAMESPACE
  39117. ProgressBar::ProgressBar (double& progress_)
  39118. : progress (progress_),
  39119. displayPercentage (true),
  39120. lastCallbackTime (0)
  39121. {
  39122. currentValue = jlimit (0.0, 1.0, progress);
  39123. }
  39124. ProgressBar::~ProgressBar()
  39125. {
  39126. }
  39127. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  39128. {
  39129. displayPercentage = shouldDisplayPercentage;
  39130. repaint();
  39131. }
  39132. void ProgressBar::setTextToDisplay (const String& text)
  39133. {
  39134. displayPercentage = false;
  39135. displayedMessage = text;
  39136. }
  39137. void ProgressBar::lookAndFeelChanged()
  39138. {
  39139. setOpaque (findColour (backgroundColourId).isOpaque());
  39140. }
  39141. void ProgressBar::colourChanged()
  39142. {
  39143. lookAndFeelChanged();
  39144. }
  39145. void ProgressBar::paint (Graphics& g)
  39146. {
  39147. String text;
  39148. if (displayPercentage)
  39149. {
  39150. if (currentValue >= 0 && currentValue <= 1.0)
  39151. text << roundToInt (currentValue * 100.0) << T("%");
  39152. }
  39153. else
  39154. {
  39155. text = displayedMessage;
  39156. }
  39157. getLookAndFeel().drawProgressBar (g, *this,
  39158. getWidth(), getHeight(),
  39159. currentValue, text);
  39160. }
  39161. void ProgressBar::visibilityChanged()
  39162. {
  39163. if (isVisible())
  39164. startTimer (30);
  39165. else
  39166. stopTimer();
  39167. }
  39168. void ProgressBar::timerCallback()
  39169. {
  39170. double newProgress = progress;
  39171. const uint32 now = Time::getMillisecondCounter();
  39172. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  39173. lastCallbackTime = now;
  39174. if (currentValue != newProgress
  39175. || newProgress < 0 || newProgress >= 1.0
  39176. || currentMessage != displayedMessage)
  39177. {
  39178. if (currentValue < newProgress
  39179. && newProgress >= 0 && newProgress < 1.0
  39180. && currentValue >= 0 && currentValue < 1.0)
  39181. {
  39182. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  39183. newProgress);
  39184. }
  39185. currentValue = newProgress;
  39186. currentMessage = displayedMessage;
  39187. repaint();
  39188. }
  39189. }
  39190. END_JUCE_NAMESPACE
  39191. /*** End of inlined file: juce_ProgressBar.cpp ***/
  39192. /*** Start of inlined file: juce_Slider.cpp ***/
  39193. BEGIN_JUCE_NAMESPACE
  39194. class SliderPopupDisplayComponent : public BubbleComponent
  39195. {
  39196. public:
  39197. SliderPopupDisplayComponent (Slider* const owner_)
  39198. : owner (owner_),
  39199. font (15.0f, Font::bold)
  39200. {
  39201. setAlwaysOnTop (true);
  39202. }
  39203. ~SliderPopupDisplayComponent()
  39204. {
  39205. }
  39206. void paintContent (Graphics& g, int w, int h)
  39207. {
  39208. g.setFont (font);
  39209. g.setColour (Colours::black);
  39210. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  39211. }
  39212. void getContentSize (int& w, int& h)
  39213. {
  39214. w = font.getStringWidth (text) + 18;
  39215. h = (int) (font.getHeight() * 1.6f);
  39216. }
  39217. void updatePosition (const String& newText)
  39218. {
  39219. if (text != newText)
  39220. {
  39221. text = newText;
  39222. repaint();
  39223. }
  39224. BubbleComponent::setPosition (owner);
  39225. }
  39226. juce_UseDebuggingNewOperator
  39227. private:
  39228. Slider* owner;
  39229. Font font;
  39230. String text;
  39231. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  39232. const SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  39233. };
  39234. Slider::Slider (const String& name)
  39235. : Component (name),
  39236. lastCurrentValue (0),
  39237. lastValueMin (0),
  39238. lastValueMax (0),
  39239. minimum (0),
  39240. maximum (10),
  39241. interval (0),
  39242. skewFactor (1.0),
  39243. velocityModeSensitivity (1.0),
  39244. velocityModeOffset (0.0),
  39245. velocityModeThreshold (1),
  39246. rotaryStart (float_Pi * 1.2f),
  39247. rotaryEnd (float_Pi * 2.8f),
  39248. numDecimalPlaces (7),
  39249. sliderRegionStart (0),
  39250. sliderRegionSize (1),
  39251. sliderBeingDragged (-1),
  39252. pixelsForFullDragExtent (250),
  39253. style (LinearHorizontal),
  39254. textBoxPos (TextBoxLeft),
  39255. textBoxWidth (80),
  39256. textBoxHeight (20),
  39257. incDecButtonMode (incDecButtonsNotDraggable),
  39258. editableText (true),
  39259. doubleClickToValue (false),
  39260. isVelocityBased (false),
  39261. userKeyOverridesVelocity (true),
  39262. rotaryStop (true),
  39263. incDecButtonsSideBySide (false),
  39264. sendChangeOnlyOnRelease (false),
  39265. popupDisplayEnabled (false),
  39266. menuEnabled (false),
  39267. menuShown (false),
  39268. scrollWheelEnabled (true),
  39269. snapsToMousePos (true),
  39270. valueBox (0),
  39271. incButton (0),
  39272. decButton (0),
  39273. popupDisplay (0),
  39274. parentForPopupDisplay (0)
  39275. {
  39276. setWantsKeyboardFocus (false);
  39277. setRepaintsOnMouseActivity (true);
  39278. lookAndFeelChanged();
  39279. updateText();
  39280. currentValue.addListener (this);
  39281. valueMin.addListener (this);
  39282. valueMax.addListener (this);
  39283. }
  39284. Slider::~Slider()
  39285. {
  39286. currentValue.removeListener (this);
  39287. valueMin.removeListener (this);
  39288. valueMax.removeListener (this);
  39289. popupDisplay = 0;
  39290. deleteAllChildren();
  39291. }
  39292. void Slider::handleAsyncUpdate()
  39293. {
  39294. cancelPendingUpdate();
  39295. for (int i = listeners.size(); --i >= 0;)
  39296. {
  39297. ((SliderListener*) listeners.getUnchecked (i))->sliderValueChanged (this);
  39298. i = jmin (i, listeners.size());
  39299. }
  39300. }
  39301. void Slider::sendDragStart()
  39302. {
  39303. startedDragging();
  39304. for (int i = listeners.size(); --i >= 0;)
  39305. {
  39306. ((SliderListener*) listeners.getUnchecked (i))->sliderDragStarted (this);
  39307. i = jmin (i, listeners.size());
  39308. }
  39309. }
  39310. void Slider::sendDragEnd()
  39311. {
  39312. stoppedDragging();
  39313. sliderBeingDragged = -1;
  39314. for (int i = listeners.size(); --i >= 0;)
  39315. {
  39316. ((SliderListener*) listeners.getUnchecked (i))->sliderDragEnded (this);
  39317. i = jmin (i, listeners.size());
  39318. }
  39319. }
  39320. void Slider::addListener (SliderListener* const listener)
  39321. {
  39322. jassert (listener != 0);
  39323. if (listener != 0)
  39324. listeners.add (listener);
  39325. }
  39326. void Slider::removeListener (SliderListener* const listener)
  39327. {
  39328. listeners.removeValue (listener);
  39329. }
  39330. void Slider::setSliderStyle (const SliderStyle newStyle)
  39331. {
  39332. if (style != newStyle)
  39333. {
  39334. style = newStyle;
  39335. repaint();
  39336. lookAndFeelChanged();
  39337. }
  39338. }
  39339. void Slider::setRotaryParameters (const float startAngleRadians,
  39340. const float endAngleRadians,
  39341. const bool stopAtEnd)
  39342. {
  39343. // make sure the values are sensible..
  39344. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  39345. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  39346. jassert (rotaryStart < rotaryEnd);
  39347. rotaryStart = startAngleRadians;
  39348. rotaryEnd = endAngleRadians;
  39349. rotaryStop = stopAtEnd;
  39350. }
  39351. void Slider::setVelocityBasedMode (const bool velBased)
  39352. {
  39353. isVelocityBased = velBased;
  39354. }
  39355. void Slider::setVelocityModeParameters (const double sensitivity,
  39356. const int threshold,
  39357. const double offset,
  39358. const bool userCanPressKeyToSwapMode)
  39359. {
  39360. jassert (threshold >= 0);
  39361. jassert (sensitivity > 0);
  39362. jassert (offset >= 0);
  39363. velocityModeSensitivity = sensitivity;
  39364. velocityModeOffset = offset;
  39365. velocityModeThreshold = threshold;
  39366. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  39367. }
  39368. void Slider::setSkewFactor (const double factor)
  39369. {
  39370. skewFactor = factor;
  39371. }
  39372. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  39373. {
  39374. if (maximum > minimum)
  39375. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  39376. / (maximum - minimum));
  39377. }
  39378. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  39379. {
  39380. jassert (distanceForFullScaleDrag > 0);
  39381. pixelsForFullDragExtent = distanceForFullScaleDrag;
  39382. }
  39383. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  39384. {
  39385. if (incDecButtonMode != mode)
  39386. {
  39387. incDecButtonMode = mode;
  39388. lookAndFeelChanged();
  39389. }
  39390. }
  39391. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  39392. const bool isReadOnly,
  39393. const int textEntryBoxWidth,
  39394. const int textEntryBoxHeight)
  39395. {
  39396. textBoxPos = newPosition;
  39397. editableText = ! isReadOnly;
  39398. textBoxWidth = textEntryBoxWidth;
  39399. textBoxHeight = textEntryBoxHeight;
  39400. repaint();
  39401. lookAndFeelChanged();
  39402. }
  39403. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  39404. {
  39405. editableText = shouldBeEditable;
  39406. if (valueBox != 0)
  39407. valueBox->setEditable (shouldBeEditable && isEnabled());
  39408. }
  39409. void Slider::showTextBox()
  39410. {
  39411. jassert (editableText); // this should probably be avoided in read-only sliders.
  39412. if (valueBox != 0)
  39413. valueBox->showEditor();
  39414. }
  39415. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  39416. {
  39417. if (valueBox != 0)
  39418. {
  39419. valueBox->hideEditor (discardCurrentEditorContents);
  39420. if (discardCurrentEditorContents)
  39421. updateText();
  39422. }
  39423. }
  39424. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  39425. {
  39426. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  39427. }
  39428. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  39429. {
  39430. snapsToMousePos = shouldSnapToMouse;
  39431. }
  39432. void Slider::setPopupDisplayEnabled (const bool enabled,
  39433. Component* const parentComponentToUse)
  39434. {
  39435. popupDisplayEnabled = enabled;
  39436. parentForPopupDisplay = parentComponentToUse;
  39437. }
  39438. void Slider::colourChanged()
  39439. {
  39440. lookAndFeelChanged();
  39441. }
  39442. void Slider::lookAndFeelChanged()
  39443. {
  39444. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  39445. : getTextFromValue (currentValue.getValue()));
  39446. deleteAllChildren();
  39447. valueBox = 0;
  39448. LookAndFeel& lf = getLookAndFeel();
  39449. if (textBoxPos != NoTextBox)
  39450. {
  39451. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  39452. valueBox->setWantsKeyboardFocus (false);
  39453. valueBox->setText (previousTextBoxContent, false);
  39454. valueBox->setEditable (editableText && isEnabled());
  39455. valueBox->addListener (this);
  39456. if (style == LinearBar)
  39457. valueBox->addMouseListener (this, false);
  39458. valueBox->setTooltip (getTooltip());
  39459. }
  39460. if (style == IncDecButtons)
  39461. {
  39462. addAndMakeVisible (incButton = lf.createSliderButton (true));
  39463. incButton->addButtonListener (this);
  39464. addAndMakeVisible (decButton = lf.createSliderButton (false));
  39465. decButton->addButtonListener (this);
  39466. if (incDecButtonMode != incDecButtonsNotDraggable)
  39467. {
  39468. incButton->addMouseListener (this, false);
  39469. decButton->addMouseListener (this, false);
  39470. }
  39471. else
  39472. {
  39473. incButton->setRepeatSpeed (300, 100, 20);
  39474. incButton->addMouseListener (decButton, false);
  39475. decButton->setRepeatSpeed (300, 100, 20);
  39476. decButton->addMouseListener (incButton, false);
  39477. }
  39478. incButton->setTooltip (getTooltip());
  39479. decButton->setTooltip (getTooltip());
  39480. }
  39481. setComponentEffect (lf.getSliderEffect());
  39482. resized();
  39483. repaint();
  39484. }
  39485. void Slider::setRange (const double newMin,
  39486. const double newMax,
  39487. const double newInt)
  39488. {
  39489. if (minimum != newMin
  39490. || maximum != newMax
  39491. || interval != newInt)
  39492. {
  39493. minimum = newMin;
  39494. maximum = newMax;
  39495. interval = newInt;
  39496. // figure out the number of DPs needed to display all values at this
  39497. // interval setting.
  39498. numDecimalPlaces = 7;
  39499. if (newInt != 0)
  39500. {
  39501. int v = abs ((int) (newInt * 10000000));
  39502. while ((v % 10) == 0)
  39503. {
  39504. --numDecimalPlaces;
  39505. v /= 10;
  39506. }
  39507. }
  39508. // keep the current values inside the new range..
  39509. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39510. {
  39511. setValue (getValue(), false, false);
  39512. }
  39513. else
  39514. {
  39515. setMinValue (getMinValue(), false, false);
  39516. setMaxValue (getMaxValue(), false, false);
  39517. }
  39518. updateText();
  39519. }
  39520. }
  39521. void Slider::triggerChangeMessage (const bool synchronous)
  39522. {
  39523. if (synchronous)
  39524. handleAsyncUpdate();
  39525. else
  39526. triggerAsyncUpdate();
  39527. valueChanged();
  39528. }
  39529. void Slider::valueChanged (Value& value)
  39530. {
  39531. if (value.refersToSameSourceAs (currentValue))
  39532. {
  39533. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39534. setValue (currentValue.getValue(), false, false);
  39535. }
  39536. else if (value.refersToSameSourceAs (valueMin))
  39537. setMinValue (valueMin.getValue(), false, false, true);
  39538. else if (value.refersToSameSourceAs (valueMax))
  39539. setMaxValue (valueMax.getValue(), false, false, true);
  39540. }
  39541. double Slider::getValue() const
  39542. {
  39543. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  39544. // methods to get the two values.
  39545. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39546. return currentValue.getValue();
  39547. }
  39548. void Slider::setValue (double newValue,
  39549. const bool sendUpdateMessage,
  39550. const bool sendMessageSynchronously)
  39551. {
  39552. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  39553. // methods to set the two values.
  39554. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39555. newValue = constrainedValue (newValue);
  39556. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39557. {
  39558. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  39559. newValue = jlimit ((double) valueMin.getValue(),
  39560. (double) valueMax.getValue(),
  39561. newValue);
  39562. }
  39563. if (newValue != lastCurrentValue)
  39564. {
  39565. if (valueBox != 0)
  39566. valueBox->hideEditor (true);
  39567. lastCurrentValue = newValue;
  39568. currentValue = newValue;
  39569. updateText();
  39570. repaint();
  39571. if (popupDisplay != 0)
  39572. {
  39573. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39574. popupDisplay->repaint();
  39575. }
  39576. if (sendUpdateMessage)
  39577. triggerChangeMessage (sendMessageSynchronously);
  39578. }
  39579. }
  39580. double Slider::getMinValue() const
  39581. {
  39582. // The minimum value only applies to sliders that are in two- or three-value mode.
  39583. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39584. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39585. return valueMin.getValue();
  39586. }
  39587. double Slider::getMaxValue() const
  39588. {
  39589. // The maximum value only applies to sliders that are in two- or three-value mode.
  39590. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39591. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39592. return valueMax.getValue();
  39593. }
  39594. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39595. {
  39596. // The minimum value only applies to sliders that are in two- or three-value mode.
  39597. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39598. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39599. newValue = constrainedValue (newValue);
  39600. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39601. {
  39602. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  39603. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39604. newValue = jmin ((double) valueMax.getValue(), newValue);
  39605. }
  39606. else
  39607. {
  39608. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39609. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39610. newValue = jmin (lastCurrentValue, newValue);
  39611. }
  39612. if (lastValueMin != newValue)
  39613. {
  39614. lastValueMin = newValue;
  39615. valueMin = newValue;
  39616. repaint();
  39617. if (popupDisplay != 0)
  39618. {
  39619. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39620. popupDisplay->repaint();
  39621. }
  39622. if (sendUpdateMessage)
  39623. triggerChangeMessage (sendMessageSynchronously);
  39624. }
  39625. }
  39626. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39627. {
  39628. // The maximum value only applies to sliders that are in two- or three-value mode.
  39629. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39630. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39631. newValue = constrainedValue (newValue);
  39632. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39633. {
  39634. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39635. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39636. newValue = jmax ((double) valueMin.getValue(), newValue);
  39637. }
  39638. else
  39639. {
  39640. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39641. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39642. newValue = jmax (lastCurrentValue, newValue);
  39643. }
  39644. if (lastValueMax != newValue)
  39645. {
  39646. lastValueMax = newValue;
  39647. valueMax = newValue;
  39648. repaint();
  39649. if (popupDisplay != 0)
  39650. {
  39651. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (valueMax.getValue()));
  39652. popupDisplay->repaint();
  39653. }
  39654. if (sendUpdateMessage)
  39655. triggerChangeMessage (sendMessageSynchronously);
  39656. }
  39657. }
  39658. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39659. const double valueToSetOnDoubleClick)
  39660. {
  39661. doubleClickToValue = isDoubleClickEnabled;
  39662. doubleClickReturnValue = valueToSetOnDoubleClick;
  39663. }
  39664. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39665. {
  39666. isEnabled_ = doubleClickToValue;
  39667. return doubleClickReturnValue;
  39668. }
  39669. void Slider::updateText()
  39670. {
  39671. if (valueBox != 0)
  39672. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39673. }
  39674. void Slider::setTextValueSuffix (const String& suffix)
  39675. {
  39676. if (textSuffix != suffix)
  39677. {
  39678. textSuffix = suffix;
  39679. updateText();
  39680. }
  39681. }
  39682. const String Slider::getTextFromValue (double v)
  39683. {
  39684. if (numDecimalPlaces > 0)
  39685. return String (v, numDecimalPlaces) + textSuffix;
  39686. else
  39687. return String (roundToInt (v)) + textSuffix;
  39688. }
  39689. double Slider::getValueFromText (const String& text)
  39690. {
  39691. String t (text.trimStart());
  39692. if (t.endsWith (textSuffix))
  39693. t = t.substring (0, t.length() - textSuffix.length());
  39694. while (t.startsWithChar (T('+')))
  39695. t = t.substring (1).trimStart();
  39696. return t.initialSectionContainingOnly (T("0123456789.,-"))
  39697. .getDoubleValue();
  39698. }
  39699. double Slider::proportionOfLengthToValue (double proportion)
  39700. {
  39701. if (skewFactor != 1.0 && proportion > 0.0)
  39702. proportion = exp (log (proportion) / skewFactor);
  39703. return minimum + (maximum - minimum) * proportion;
  39704. }
  39705. double Slider::valueToProportionOfLength (double value)
  39706. {
  39707. const double n = (value - minimum) / (maximum - minimum);
  39708. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39709. }
  39710. double Slider::snapValue (double attemptedValue, const bool)
  39711. {
  39712. return attemptedValue;
  39713. }
  39714. void Slider::startedDragging()
  39715. {
  39716. }
  39717. void Slider::stoppedDragging()
  39718. {
  39719. }
  39720. void Slider::valueChanged()
  39721. {
  39722. }
  39723. void Slider::enablementChanged()
  39724. {
  39725. repaint();
  39726. }
  39727. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39728. {
  39729. menuEnabled = menuEnabled_;
  39730. }
  39731. void Slider::setScrollWheelEnabled (const bool enabled)
  39732. {
  39733. scrollWheelEnabled = enabled;
  39734. }
  39735. void Slider::labelTextChanged (Label* label)
  39736. {
  39737. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39738. if (newValue != (double) currentValue.getValue())
  39739. {
  39740. sendDragStart();
  39741. setValue (newValue, true, true);
  39742. sendDragEnd();
  39743. }
  39744. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39745. }
  39746. void Slider::buttonClicked (Button* button)
  39747. {
  39748. if (style == IncDecButtons)
  39749. {
  39750. sendDragStart();
  39751. if (button == incButton)
  39752. setValue (snapValue (getValue() + interval, false), true, true);
  39753. else if (button == decButton)
  39754. setValue (snapValue (getValue() - interval, false), true, true);
  39755. sendDragEnd();
  39756. }
  39757. }
  39758. double Slider::constrainedValue (double value) const
  39759. {
  39760. if (interval > 0)
  39761. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39762. if (value <= minimum || maximum <= minimum)
  39763. value = minimum;
  39764. else if (value >= maximum)
  39765. value = maximum;
  39766. return value;
  39767. }
  39768. float Slider::getLinearSliderPos (const double value)
  39769. {
  39770. double sliderPosProportional;
  39771. if (maximum > minimum)
  39772. {
  39773. if (value < minimum)
  39774. {
  39775. sliderPosProportional = 0.0;
  39776. }
  39777. else if (value > maximum)
  39778. {
  39779. sliderPosProportional = 1.0;
  39780. }
  39781. else
  39782. {
  39783. sliderPosProportional = valueToProportionOfLength (value);
  39784. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39785. }
  39786. }
  39787. else
  39788. {
  39789. sliderPosProportional = 0.5;
  39790. }
  39791. if (isVertical() || style == IncDecButtons)
  39792. sliderPosProportional = 1.0 - sliderPosProportional;
  39793. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39794. }
  39795. bool Slider::isHorizontal() const
  39796. {
  39797. return style == LinearHorizontal
  39798. || style == LinearBar
  39799. || style == TwoValueHorizontal
  39800. || style == ThreeValueHorizontal;
  39801. }
  39802. bool Slider::isVertical() const
  39803. {
  39804. return style == LinearVertical
  39805. || style == TwoValueVertical
  39806. || style == ThreeValueVertical;
  39807. }
  39808. bool Slider::incDecDragDirectionIsHorizontal() const
  39809. {
  39810. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39811. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39812. }
  39813. float Slider::getPositionOfValue (const double value)
  39814. {
  39815. if (isHorizontal() || isVertical())
  39816. {
  39817. return getLinearSliderPos (value);
  39818. }
  39819. else
  39820. {
  39821. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39822. return 0.0f;
  39823. }
  39824. }
  39825. void Slider::paint (Graphics& g)
  39826. {
  39827. if (style != IncDecButtons)
  39828. {
  39829. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39830. {
  39831. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39832. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39833. getLookAndFeel().drawRotarySlider (g,
  39834. sliderRect.getX(),
  39835. sliderRect.getY(),
  39836. sliderRect.getWidth(),
  39837. sliderRect.getHeight(),
  39838. sliderPos,
  39839. rotaryStart, rotaryEnd,
  39840. *this);
  39841. }
  39842. else
  39843. {
  39844. getLookAndFeel().drawLinearSlider (g,
  39845. sliderRect.getX(),
  39846. sliderRect.getY(),
  39847. sliderRect.getWidth(),
  39848. sliderRect.getHeight(),
  39849. getLinearSliderPos (lastCurrentValue),
  39850. getLinearSliderPos (lastValueMin),
  39851. getLinearSliderPos (lastValueMax),
  39852. style,
  39853. *this);
  39854. }
  39855. if (style == LinearBar && valueBox == 0)
  39856. {
  39857. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39858. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39859. }
  39860. }
  39861. }
  39862. void Slider::resized()
  39863. {
  39864. int minXSpace = 0;
  39865. int minYSpace = 0;
  39866. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39867. minXSpace = 30;
  39868. else
  39869. minYSpace = 15;
  39870. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39871. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39872. if (style == LinearBar)
  39873. {
  39874. if (valueBox != 0)
  39875. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39876. }
  39877. else
  39878. {
  39879. if (textBoxPos == NoTextBox)
  39880. {
  39881. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39882. }
  39883. else if (textBoxPos == TextBoxLeft)
  39884. {
  39885. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39886. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39887. }
  39888. else if (textBoxPos == TextBoxRight)
  39889. {
  39890. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39891. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39892. }
  39893. else if (textBoxPos == TextBoxAbove)
  39894. {
  39895. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39896. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39897. }
  39898. else if (textBoxPos == TextBoxBelow)
  39899. {
  39900. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39901. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39902. }
  39903. }
  39904. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39905. if (style == LinearBar)
  39906. {
  39907. const int barIndent = 1;
  39908. sliderRegionStart = barIndent;
  39909. sliderRegionSize = getWidth() - barIndent * 2;
  39910. sliderRect.setBounds (sliderRegionStart, barIndent,
  39911. sliderRegionSize, getHeight() - barIndent * 2);
  39912. }
  39913. else if (isHorizontal())
  39914. {
  39915. sliderRegionStart = sliderRect.getX() + indent;
  39916. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39917. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39918. sliderRegionSize, sliderRect.getHeight());
  39919. }
  39920. else if (isVertical())
  39921. {
  39922. sliderRegionStart = sliderRect.getY() + indent;
  39923. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39924. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39925. sliderRect.getWidth(), sliderRegionSize);
  39926. }
  39927. else
  39928. {
  39929. sliderRegionStart = 0;
  39930. sliderRegionSize = 100;
  39931. }
  39932. if (style == IncDecButtons)
  39933. {
  39934. Rectangle<int> buttonRect (sliderRect);
  39935. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39936. buttonRect.expand (-2, 0);
  39937. else
  39938. buttonRect.expand (0, -2);
  39939. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39940. if (incDecButtonsSideBySide)
  39941. {
  39942. decButton->setBounds (buttonRect.getX(),
  39943. buttonRect.getY(),
  39944. buttonRect.getWidth() / 2,
  39945. buttonRect.getHeight());
  39946. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39947. incButton->setBounds (buttonRect.getCentreX(),
  39948. buttonRect.getY(),
  39949. buttonRect.getWidth() / 2,
  39950. buttonRect.getHeight());
  39951. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39952. }
  39953. else
  39954. {
  39955. incButton->setBounds (buttonRect.getX(),
  39956. buttonRect.getY(),
  39957. buttonRect.getWidth(),
  39958. buttonRect.getHeight() / 2);
  39959. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39960. decButton->setBounds (buttonRect.getX(),
  39961. buttonRect.getCentreY(),
  39962. buttonRect.getWidth(),
  39963. buttonRect.getHeight() / 2);
  39964. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39965. }
  39966. }
  39967. }
  39968. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39969. {
  39970. repaint();
  39971. }
  39972. void Slider::mouseDown (const MouseEvent& e)
  39973. {
  39974. mouseWasHidden = false;
  39975. incDecDragged = false;
  39976. mouseXWhenLastDragged = e.x;
  39977. mouseYWhenLastDragged = e.y;
  39978. mouseDragStartX = e.getMouseDownX();
  39979. mouseDragStartY = e.getMouseDownY();
  39980. if (isEnabled())
  39981. {
  39982. if (e.mods.isPopupMenu() && menuEnabled)
  39983. {
  39984. menuShown = true;
  39985. PopupMenu m;
  39986. m.setLookAndFeel (&getLookAndFeel());
  39987. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39988. m.addSeparator();
  39989. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39990. {
  39991. PopupMenu rotaryMenu;
  39992. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39993. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39994. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39995. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39996. }
  39997. const int r = m.show();
  39998. if (r == 1)
  39999. {
  40000. setVelocityBasedMode (! isVelocityBased);
  40001. }
  40002. else if (r == 2)
  40003. {
  40004. setSliderStyle (Rotary);
  40005. }
  40006. else if (r == 3)
  40007. {
  40008. setSliderStyle (RotaryHorizontalDrag);
  40009. }
  40010. else if (r == 4)
  40011. {
  40012. setSliderStyle (RotaryVerticalDrag);
  40013. }
  40014. }
  40015. else if (maximum > minimum)
  40016. {
  40017. menuShown = false;
  40018. if (valueBox != 0)
  40019. valueBox->hideEditor (true);
  40020. sliderBeingDragged = 0;
  40021. if (style == TwoValueHorizontal
  40022. || style == TwoValueVertical
  40023. || style == ThreeValueHorizontal
  40024. || style == ThreeValueVertical)
  40025. {
  40026. const float mousePos = (float) (isVertical() ? e.y : e.x);
  40027. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  40028. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  40029. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  40030. if (style == TwoValueHorizontal || style == TwoValueVertical)
  40031. {
  40032. if (maxPosDistance <= minPosDistance)
  40033. sliderBeingDragged = 2;
  40034. else
  40035. sliderBeingDragged = 1;
  40036. }
  40037. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  40038. {
  40039. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  40040. sliderBeingDragged = 1;
  40041. else if (normalPosDistance >= maxPosDistance)
  40042. sliderBeingDragged = 2;
  40043. }
  40044. }
  40045. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40046. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  40047. * valueToProportionOfLength (currentValue.getValue());
  40048. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  40049. : ((sliderBeingDragged == 1) ? valueMin
  40050. : currentValue)).getValue();
  40051. valueOnMouseDown = valueWhenLastDragged;
  40052. if (popupDisplayEnabled)
  40053. {
  40054. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  40055. popupDisplay = popup;
  40056. if (parentForPopupDisplay != 0)
  40057. {
  40058. parentForPopupDisplay->addChildComponent (popup);
  40059. }
  40060. else
  40061. {
  40062. popup->addToDesktop (0);
  40063. }
  40064. popup->setVisible (true);
  40065. }
  40066. sendDragStart();
  40067. mouseDrag (e);
  40068. }
  40069. }
  40070. }
  40071. void Slider::mouseUp (const MouseEvent&)
  40072. {
  40073. if (isEnabled()
  40074. && (! menuShown)
  40075. && (maximum > minimum)
  40076. && (style != IncDecButtons || incDecDragged))
  40077. {
  40078. restoreMouseIfHidden();
  40079. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  40080. triggerChangeMessage (false);
  40081. sendDragEnd();
  40082. popupDisplay = 0;
  40083. if (style == IncDecButtons)
  40084. {
  40085. incButton->setState (Button::buttonNormal);
  40086. decButton->setState (Button::buttonNormal);
  40087. }
  40088. }
  40089. }
  40090. void Slider::restoreMouseIfHidden()
  40091. {
  40092. if (mouseWasHidden)
  40093. {
  40094. mouseWasHidden = false;
  40095. Component* c = Component::getComponentUnderMouse();
  40096. if (c == 0)
  40097. c = this;
  40098. c->enableUnboundedMouseMovement (false);
  40099. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  40100. : ((sliderBeingDragged == 1) ? getMinValue()
  40101. : (double) currentValue.getValue());
  40102. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  40103. {
  40104. int x, y, downX, downY;
  40105. Desktop::getMousePosition (x, y);
  40106. Desktop::getLastMouseDownPosition (downX, downY);
  40107. if (style == RotaryHorizontalDrag)
  40108. {
  40109. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  40110. x = roundToInt (pixelsForFullDragExtent * posDiff + downX);
  40111. y = downY;
  40112. }
  40113. else
  40114. {
  40115. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  40116. x = downX;
  40117. y = roundToInt (pixelsForFullDragExtent * posDiff + downY);
  40118. }
  40119. Desktop::setMousePosition (x, y);
  40120. }
  40121. else
  40122. {
  40123. const int pixelPos = (int) getLinearSliderPos (pos);
  40124. int x = isHorizontal() ? pixelPos : (getWidth() / 2);
  40125. int y = isVertical() ? pixelPos : (getHeight() / 2);
  40126. relativePositionToGlobal (x, y);
  40127. Desktop::setMousePosition (x, y);
  40128. }
  40129. }
  40130. }
  40131. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  40132. {
  40133. if (isEnabled()
  40134. && style != IncDecButtons
  40135. && style != Rotary
  40136. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  40137. {
  40138. restoreMouseIfHidden();
  40139. }
  40140. }
  40141. static double smallestAngleBetween (double a1, double a2)
  40142. {
  40143. return jmin (fabs (a1 - a2),
  40144. fabs (a1 + double_Pi * 2.0 - a2),
  40145. fabs (a2 + double_Pi * 2.0 - a1));
  40146. }
  40147. void Slider::mouseDrag (const MouseEvent& e)
  40148. {
  40149. if (isEnabled()
  40150. && (! menuShown)
  40151. && (maximum > minimum))
  40152. {
  40153. if (style == Rotary)
  40154. {
  40155. int dx = e.x - sliderRect.getCentreX();
  40156. int dy = e.y - sliderRect.getCentreY();
  40157. if (dx * dx + dy * dy > 25)
  40158. {
  40159. double angle = atan2 ((double) dx, (double) -dy);
  40160. while (angle < 0.0)
  40161. angle += double_Pi * 2.0;
  40162. if (rotaryStop && ! e.mouseWasClicked())
  40163. {
  40164. if (fabs (angle - lastAngle) > double_Pi)
  40165. {
  40166. if (angle >= lastAngle)
  40167. angle -= double_Pi * 2.0;
  40168. else
  40169. angle += double_Pi * 2.0;
  40170. }
  40171. if (angle >= lastAngle)
  40172. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  40173. else
  40174. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  40175. }
  40176. else
  40177. {
  40178. while (angle < rotaryStart)
  40179. angle += double_Pi * 2.0;
  40180. if (angle > rotaryEnd)
  40181. {
  40182. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  40183. angle = rotaryStart;
  40184. else
  40185. angle = rotaryEnd;
  40186. }
  40187. }
  40188. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  40189. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  40190. lastAngle = angle;
  40191. }
  40192. }
  40193. else
  40194. {
  40195. if (style == LinearBar && e.mouseWasClicked()
  40196. && valueBox != 0 && valueBox->isEditable())
  40197. return;
  40198. if (style == IncDecButtons && ! incDecDragged)
  40199. {
  40200. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  40201. return;
  40202. incDecDragged = true;
  40203. mouseDragStartX = e.x;
  40204. mouseDragStartY = e.y;
  40205. }
  40206. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  40207. : false))
  40208. || ((maximum - minimum) / sliderRegionSize < interval))
  40209. {
  40210. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  40211. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  40212. if (style == RotaryHorizontalDrag
  40213. || style == RotaryVerticalDrag
  40214. || style == IncDecButtons
  40215. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  40216. && ! snapsToMousePos))
  40217. {
  40218. const int mouseDiff = (style == RotaryHorizontalDrag
  40219. || style == LinearHorizontal
  40220. || style == LinearBar
  40221. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40222. ? e.x - mouseDragStartX
  40223. : mouseDragStartY - e.y;
  40224. double newPos = valueToProportionOfLength (valueOnMouseDown)
  40225. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  40226. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  40227. if (style == IncDecButtons)
  40228. {
  40229. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  40230. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  40231. }
  40232. }
  40233. else
  40234. {
  40235. if (isVertical())
  40236. scaledMousePos = 1.0 - scaledMousePos;
  40237. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  40238. }
  40239. }
  40240. else
  40241. {
  40242. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  40243. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40244. ? e.x - mouseXWhenLastDragged
  40245. : e.y - mouseYWhenLastDragged;
  40246. const double maxSpeed = jmax (200, sliderRegionSize);
  40247. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  40248. if (speed != 0)
  40249. {
  40250. speed = 0.2 * velocityModeSensitivity
  40251. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  40252. + jmax (0.0, (double) (speed - velocityModeThreshold))
  40253. / maxSpeed))));
  40254. if (mouseDiff < 0)
  40255. speed = -speed;
  40256. if (isVertical() || style == RotaryVerticalDrag
  40257. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  40258. speed = -speed;
  40259. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  40260. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  40261. e.originalComponent->enableUnboundedMouseMovement (true, false);
  40262. mouseWasHidden = true;
  40263. }
  40264. }
  40265. }
  40266. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  40267. if (sliderBeingDragged == 0)
  40268. {
  40269. setValue (snapValue (valueWhenLastDragged, true),
  40270. ! sendChangeOnlyOnRelease, true);
  40271. }
  40272. else if (sliderBeingDragged == 1)
  40273. {
  40274. setMinValue (snapValue (valueWhenLastDragged, true),
  40275. ! sendChangeOnlyOnRelease, false, true);
  40276. if (e.mods.isShiftDown())
  40277. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  40278. else
  40279. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40280. }
  40281. else
  40282. {
  40283. jassert (sliderBeingDragged == 2);
  40284. setMaxValue (snapValue (valueWhenLastDragged, true),
  40285. ! sendChangeOnlyOnRelease, false, true);
  40286. if (e.mods.isShiftDown())
  40287. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  40288. else
  40289. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40290. }
  40291. mouseXWhenLastDragged = e.x;
  40292. mouseYWhenLastDragged = e.y;
  40293. }
  40294. }
  40295. void Slider::mouseDoubleClick (const MouseEvent&)
  40296. {
  40297. if (doubleClickToValue
  40298. && isEnabled()
  40299. && style != IncDecButtons
  40300. && minimum <= doubleClickReturnValue
  40301. && maximum >= doubleClickReturnValue)
  40302. {
  40303. sendDragStart();
  40304. setValue (doubleClickReturnValue, true, true);
  40305. sendDragEnd();
  40306. }
  40307. }
  40308. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  40309. {
  40310. if (scrollWheelEnabled && isEnabled()
  40311. && style != TwoValueHorizontal
  40312. && style != TwoValueVertical)
  40313. {
  40314. if (maximum > minimum && ! isMouseButtonDownAnywhere())
  40315. {
  40316. if (valueBox != 0)
  40317. valueBox->hideEditor (false);
  40318. const double value = (double) currentValue.getValue();
  40319. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  40320. const double currentPos = valueToProportionOfLength (value);
  40321. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  40322. double delta = (newValue != value)
  40323. ? jmax (fabs (newValue - value), interval) : 0;
  40324. if (value > newValue)
  40325. delta = -delta;
  40326. sendDragStart();
  40327. setValue (snapValue (value + delta, false), true, true);
  40328. sendDragEnd();
  40329. }
  40330. }
  40331. else
  40332. {
  40333. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  40334. }
  40335. }
  40336. void SliderListener::sliderDragStarted (Slider*)
  40337. {
  40338. }
  40339. void SliderListener::sliderDragEnded (Slider*)
  40340. {
  40341. }
  40342. END_JUCE_NAMESPACE
  40343. /*** End of inlined file: juce_Slider.cpp ***/
  40344. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  40345. BEGIN_JUCE_NAMESPACE
  40346. class DragOverlayComp : public Component
  40347. {
  40348. public:
  40349. DragOverlayComp (Image* const image_)
  40350. : image (image_)
  40351. {
  40352. image->multiplyAllAlphas (0.8f);
  40353. setAlwaysOnTop (true);
  40354. }
  40355. ~DragOverlayComp()
  40356. {
  40357. }
  40358. void paint (Graphics& g)
  40359. {
  40360. g.drawImageAt (image, 0, 0);
  40361. }
  40362. private:
  40363. ScopedPointer <Image> image;
  40364. DragOverlayComp (const DragOverlayComp&);
  40365. const DragOverlayComp& operator= (const DragOverlayComp&);
  40366. };
  40367. TableHeaderComponent::TableHeaderComponent()
  40368. : columnsChanged (false),
  40369. columnsResized (false),
  40370. sortChanged (false),
  40371. menuActive (true),
  40372. stretchToFit (false),
  40373. columnIdBeingResized (0),
  40374. columnIdBeingDragged (0),
  40375. columnIdUnderMouse (0),
  40376. lastDeliberateWidth (0)
  40377. {
  40378. }
  40379. TableHeaderComponent::~TableHeaderComponent()
  40380. {
  40381. dragOverlayComp = 0;
  40382. }
  40383. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  40384. {
  40385. menuActive = hasMenu;
  40386. }
  40387. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  40388. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  40389. {
  40390. if (onlyCountVisibleColumns)
  40391. {
  40392. int num = 0;
  40393. for (int i = columns.size(); --i >= 0;)
  40394. if (columns.getUnchecked(i)->isVisible())
  40395. ++num;
  40396. return num;
  40397. }
  40398. else
  40399. {
  40400. return columns.size();
  40401. }
  40402. }
  40403. const String TableHeaderComponent::getColumnName (const int columnId) const
  40404. {
  40405. const ColumnInfo* const ci = getInfoForId (columnId);
  40406. return ci != 0 ? ci->name : String::empty;
  40407. }
  40408. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  40409. {
  40410. ColumnInfo* const ci = getInfoForId (columnId);
  40411. if (ci != 0 && ci->name != newName)
  40412. {
  40413. ci->name = newName;
  40414. sendColumnsChanged();
  40415. }
  40416. }
  40417. void TableHeaderComponent::addColumn (const String& columnName,
  40418. const int columnId,
  40419. const int width,
  40420. const int minimumWidth,
  40421. const int maximumWidth,
  40422. const int propertyFlags,
  40423. const int insertIndex)
  40424. {
  40425. // can't have a duplicate or null ID!
  40426. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  40427. jassert (width > 0);
  40428. ColumnInfo* const ci = new ColumnInfo();
  40429. ci->name = columnName;
  40430. ci->id = columnId;
  40431. ci->width = width;
  40432. ci->lastDeliberateWidth = width;
  40433. ci->minimumWidth = minimumWidth;
  40434. ci->maximumWidth = maximumWidth;
  40435. if (ci->maximumWidth < 0)
  40436. ci->maximumWidth = std::numeric_limits<int>::max();
  40437. jassert (ci->maximumWidth >= ci->minimumWidth);
  40438. ci->propertyFlags = propertyFlags;
  40439. columns.insert (insertIndex, ci);
  40440. sendColumnsChanged();
  40441. }
  40442. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  40443. {
  40444. const int index = getIndexOfColumnId (columnIdToRemove, false);
  40445. if (index >= 0)
  40446. {
  40447. columns.remove (index);
  40448. sortChanged = true;
  40449. sendColumnsChanged();
  40450. }
  40451. }
  40452. void TableHeaderComponent::removeAllColumns()
  40453. {
  40454. if (columns.size() > 0)
  40455. {
  40456. columns.clear();
  40457. sendColumnsChanged();
  40458. }
  40459. }
  40460. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  40461. {
  40462. const int currentIndex = getIndexOfColumnId (columnId, false);
  40463. newIndex = visibleIndexToTotalIndex (newIndex);
  40464. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  40465. {
  40466. columns.move (currentIndex, newIndex);
  40467. sendColumnsChanged();
  40468. }
  40469. }
  40470. int TableHeaderComponent::getColumnWidth (const int columnId) const
  40471. {
  40472. const ColumnInfo* const ci = getInfoForId (columnId);
  40473. return ci != 0 ? ci->width : 0;
  40474. }
  40475. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  40476. {
  40477. ColumnInfo* const ci = getInfoForId (columnId);
  40478. if (ci != 0 && ci->width != newWidth)
  40479. {
  40480. const int numColumns = getNumColumns (true);
  40481. ci->lastDeliberateWidth = ci->width
  40482. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  40483. if (stretchToFit)
  40484. {
  40485. const int index = getIndexOfColumnId (columnId, true) + 1;
  40486. if (((unsigned int) index) < (unsigned int) numColumns)
  40487. {
  40488. const int x = getColumnPosition (index).getX();
  40489. if (lastDeliberateWidth == 0)
  40490. lastDeliberateWidth = getTotalWidth();
  40491. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  40492. }
  40493. }
  40494. repaint();
  40495. columnsResized = true;
  40496. triggerAsyncUpdate();
  40497. }
  40498. }
  40499. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  40500. {
  40501. int n = 0;
  40502. for (int i = 0; i < columns.size(); ++i)
  40503. {
  40504. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  40505. {
  40506. if (columns.getUnchecked(i)->id == columnId)
  40507. return n;
  40508. ++n;
  40509. }
  40510. }
  40511. return -1;
  40512. }
  40513. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  40514. {
  40515. if (onlyCountVisibleColumns)
  40516. index = visibleIndexToTotalIndex (index);
  40517. const ColumnInfo* const ci = columns [index];
  40518. return (ci != 0) ? ci->id : 0;
  40519. }
  40520. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  40521. {
  40522. int x = 0, width = 0, n = 0;
  40523. for (int i = 0; i < columns.size(); ++i)
  40524. {
  40525. x += width;
  40526. if (columns.getUnchecked(i)->isVisible())
  40527. {
  40528. width = columns.getUnchecked(i)->width;
  40529. if (n++ == index)
  40530. break;
  40531. }
  40532. else
  40533. {
  40534. width = 0;
  40535. }
  40536. }
  40537. return Rectangle<int> (x, 0, width, getHeight());
  40538. }
  40539. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  40540. {
  40541. if (xToFind >= 0)
  40542. {
  40543. int x = 0;
  40544. for (int i = 0; i < columns.size(); ++i)
  40545. {
  40546. const ColumnInfo* const ci = columns.getUnchecked(i);
  40547. if (ci->isVisible())
  40548. {
  40549. x += ci->width;
  40550. if (xToFind < x)
  40551. return ci->id;
  40552. }
  40553. }
  40554. }
  40555. return 0;
  40556. }
  40557. int TableHeaderComponent::getTotalWidth() const
  40558. {
  40559. int w = 0;
  40560. for (int i = columns.size(); --i >= 0;)
  40561. if (columns.getUnchecked(i)->isVisible())
  40562. w += columns.getUnchecked(i)->width;
  40563. return w;
  40564. }
  40565. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  40566. {
  40567. stretchToFit = shouldStretchToFit;
  40568. lastDeliberateWidth = getTotalWidth();
  40569. resized();
  40570. }
  40571. bool TableHeaderComponent::isStretchToFitActive() const
  40572. {
  40573. return stretchToFit;
  40574. }
  40575. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  40576. {
  40577. if (stretchToFit && getWidth() > 0
  40578. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  40579. {
  40580. lastDeliberateWidth = targetTotalWidth;
  40581. resizeColumnsToFit (0, targetTotalWidth);
  40582. }
  40583. }
  40584. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  40585. {
  40586. targetTotalWidth = jmax (targetTotalWidth, 0);
  40587. StretchableObjectResizer sor;
  40588. int i;
  40589. for (i = firstColumnIndex; i < columns.size(); ++i)
  40590. {
  40591. ColumnInfo* const ci = columns.getUnchecked(i);
  40592. if (ci->isVisible())
  40593. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  40594. }
  40595. sor.resizeToFit (targetTotalWidth);
  40596. int visIndex = 0;
  40597. for (i = firstColumnIndex; i < columns.size(); ++i)
  40598. {
  40599. ColumnInfo* const ci = columns.getUnchecked(i);
  40600. if (ci->isVisible())
  40601. {
  40602. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  40603. (int) floor (sor.getItemSize (visIndex++)));
  40604. if (newWidth != ci->width)
  40605. {
  40606. ci->width = newWidth;
  40607. repaint();
  40608. columnsResized = true;
  40609. triggerAsyncUpdate();
  40610. }
  40611. }
  40612. }
  40613. }
  40614. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40615. {
  40616. ColumnInfo* const ci = getInfoForId (columnId);
  40617. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40618. {
  40619. if (shouldBeVisible)
  40620. ci->propertyFlags |= visible;
  40621. else
  40622. ci->propertyFlags &= ~visible;
  40623. sendColumnsChanged();
  40624. resized();
  40625. }
  40626. }
  40627. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40628. {
  40629. const ColumnInfo* const ci = getInfoForId (columnId);
  40630. return ci != 0 && ci->isVisible();
  40631. }
  40632. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40633. {
  40634. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40635. {
  40636. for (int i = columns.size(); --i >= 0;)
  40637. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40638. ColumnInfo* const ci = getInfoForId (columnId);
  40639. if (ci != 0)
  40640. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40641. reSortTable();
  40642. }
  40643. }
  40644. int TableHeaderComponent::getSortColumnId() const
  40645. {
  40646. for (int i = columns.size(); --i >= 0;)
  40647. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40648. return columns.getUnchecked(i)->id;
  40649. return 0;
  40650. }
  40651. bool TableHeaderComponent::isSortedForwards() const
  40652. {
  40653. for (int i = columns.size(); --i >= 0;)
  40654. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40655. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40656. return true;
  40657. }
  40658. void TableHeaderComponent::reSortTable()
  40659. {
  40660. sortChanged = true;
  40661. repaint();
  40662. triggerAsyncUpdate();
  40663. }
  40664. const String TableHeaderComponent::toString() const
  40665. {
  40666. String s;
  40667. XmlElement doc ("TABLELAYOUT");
  40668. doc.setAttribute ("sortedCol", getSortColumnId());
  40669. doc.setAttribute ("sortForwards", isSortedForwards());
  40670. for (int i = 0; i < columns.size(); ++i)
  40671. {
  40672. const ColumnInfo* const ci = columns.getUnchecked (i);
  40673. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40674. e->setAttribute ("id", ci->id);
  40675. e->setAttribute ("visible", ci->isVisible());
  40676. e->setAttribute ("width", ci->width);
  40677. }
  40678. return doc.createDocument (String::empty, true, false);
  40679. }
  40680. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40681. {
  40682. XmlDocument doc (storedVersion);
  40683. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40684. int index = 0;
  40685. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40686. {
  40687. forEachXmlChildElement (*storedXml, col)
  40688. {
  40689. const int tabId = col->getIntAttribute ("id");
  40690. ColumnInfo* const ci = getInfoForId (tabId);
  40691. if (ci != 0)
  40692. {
  40693. columns.move (columns.indexOf (ci), index);
  40694. ci->width = col->getIntAttribute ("width");
  40695. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40696. }
  40697. ++index;
  40698. }
  40699. columnsResized = true;
  40700. sendColumnsChanged();
  40701. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40702. storedXml->getBoolAttribute ("sortForwards", true));
  40703. }
  40704. }
  40705. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40706. {
  40707. listeners.addIfNotAlreadyThere (newListener);
  40708. }
  40709. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40710. {
  40711. listeners.removeValue (listenerToRemove);
  40712. }
  40713. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40714. {
  40715. const ColumnInfo* const ci = getInfoForId (columnId);
  40716. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40717. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40718. }
  40719. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40720. {
  40721. for (int i = 0; i < columns.size(); ++i)
  40722. {
  40723. const ColumnInfo* const ci = columns.getUnchecked(i);
  40724. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40725. menu.addItem (ci->id, ci->name,
  40726. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40727. isColumnVisible (ci->id));
  40728. }
  40729. }
  40730. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40731. {
  40732. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40733. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40734. }
  40735. void TableHeaderComponent::paint (Graphics& g)
  40736. {
  40737. LookAndFeel& lf = getLookAndFeel();
  40738. lf.drawTableHeaderBackground (g, *this);
  40739. const Rectangle<int> clip (g.getClipBounds());
  40740. int x = 0;
  40741. for (int i = 0; i < columns.size(); ++i)
  40742. {
  40743. const ColumnInfo* const ci = columns.getUnchecked(i);
  40744. if (ci->isVisible())
  40745. {
  40746. if (x + ci->width > clip.getX()
  40747. && (ci->id != columnIdBeingDragged
  40748. || dragOverlayComp == 0
  40749. || ! dragOverlayComp->isVisible()))
  40750. {
  40751. g.saveState();
  40752. g.setOrigin (x, 0);
  40753. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40754. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40755. ci->id == columnIdUnderMouse,
  40756. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40757. ci->propertyFlags);
  40758. g.restoreState();
  40759. }
  40760. x += ci->width;
  40761. if (x >= clip.getRight())
  40762. break;
  40763. }
  40764. }
  40765. }
  40766. void TableHeaderComponent::resized()
  40767. {
  40768. }
  40769. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40770. {
  40771. updateColumnUnderMouse (e.x, e.y);
  40772. }
  40773. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40774. {
  40775. updateColumnUnderMouse (e.x, e.y);
  40776. }
  40777. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40778. {
  40779. updateColumnUnderMouse (e.x, e.y);
  40780. }
  40781. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40782. {
  40783. repaint();
  40784. columnIdBeingResized = 0;
  40785. columnIdBeingDragged = 0;
  40786. if (columnIdUnderMouse != 0)
  40787. {
  40788. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40789. if (e.mods.isPopupMenu())
  40790. columnClicked (columnIdUnderMouse, e.mods);
  40791. }
  40792. if (menuActive && e.mods.isPopupMenu())
  40793. showColumnChooserMenu (columnIdUnderMouse);
  40794. }
  40795. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40796. {
  40797. if (columnIdBeingResized == 0
  40798. && columnIdBeingDragged == 0
  40799. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40800. {
  40801. dragOverlayComp = 0;
  40802. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40803. if (columnIdBeingResized != 0)
  40804. {
  40805. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40806. initialColumnWidth = ci->width;
  40807. }
  40808. else
  40809. {
  40810. beginDrag (e);
  40811. }
  40812. }
  40813. if (columnIdBeingResized != 0)
  40814. {
  40815. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40816. if (ci != 0)
  40817. {
  40818. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40819. initialColumnWidth + e.getDistanceFromDragStartX());
  40820. if (stretchToFit)
  40821. {
  40822. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40823. int minWidthOnRight = 0;
  40824. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40825. if (columns.getUnchecked (i)->isVisible())
  40826. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40827. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40828. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40829. }
  40830. setColumnWidth (columnIdBeingResized, w);
  40831. }
  40832. }
  40833. else if (columnIdBeingDragged != 0)
  40834. {
  40835. if (e.y >= -50 && e.y < getHeight() + 50)
  40836. {
  40837. if (dragOverlayComp != 0)
  40838. {
  40839. dragOverlayComp->setVisible (true);
  40840. dragOverlayComp->setBounds (jlimit (0,
  40841. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40842. e.x - draggingColumnOffset),
  40843. 0,
  40844. dragOverlayComp->getWidth(),
  40845. getHeight());
  40846. for (int i = columns.size(); --i >= 0;)
  40847. {
  40848. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40849. int newIndex = currentIndex;
  40850. if (newIndex > 0)
  40851. {
  40852. // if the previous column isn't draggable, we can't move our column
  40853. // past it, because that'd change the undraggable column's position..
  40854. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40855. if ((previous->propertyFlags & draggable) != 0)
  40856. {
  40857. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40858. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40859. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40860. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40861. {
  40862. --newIndex;
  40863. }
  40864. }
  40865. }
  40866. if (newIndex < columns.size() - 1)
  40867. {
  40868. // if the next column isn't draggable, we can't move our column
  40869. // past it, because that'd change the undraggable column's position..
  40870. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40871. if ((nextCol->propertyFlags & draggable) != 0)
  40872. {
  40873. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40874. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40875. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40876. > abs (dragOverlayComp->getRight() - rightOfNext))
  40877. {
  40878. ++newIndex;
  40879. }
  40880. }
  40881. }
  40882. if (newIndex != currentIndex)
  40883. moveColumn (columnIdBeingDragged, newIndex);
  40884. else
  40885. break;
  40886. }
  40887. }
  40888. }
  40889. else
  40890. {
  40891. endDrag (draggingColumnOriginalIndex);
  40892. }
  40893. }
  40894. }
  40895. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40896. {
  40897. if (columnIdBeingDragged == 0)
  40898. {
  40899. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40900. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40901. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40902. {
  40903. columnIdBeingDragged = 0;
  40904. }
  40905. else
  40906. {
  40907. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40908. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40909. const int temp = columnIdBeingDragged;
  40910. columnIdBeingDragged = 0;
  40911. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40912. columnIdBeingDragged = temp;
  40913. dragOverlayComp->setBounds (columnRect);
  40914. for (int i = listeners.size(); --i >= 0;)
  40915. {
  40916. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40917. i = jmin (i, listeners.size() - 1);
  40918. }
  40919. }
  40920. }
  40921. }
  40922. void TableHeaderComponent::endDrag (const int finalIndex)
  40923. {
  40924. if (columnIdBeingDragged != 0)
  40925. {
  40926. moveColumn (columnIdBeingDragged, finalIndex);
  40927. columnIdBeingDragged = 0;
  40928. repaint();
  40929. for (int i = listeners.size(); --i >= 0;)
  40930. {
  40931. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40932. i = jmin (i, listeners.size() - 1);
  40933. }
  40934. }
  40935. }
  40936. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40937. {
  40938. mouseDrag (e);
  40939. for (int i = columns.size(); --i >= 0;)
  40940. if (columns.getUnchecked (i)->isVisible())
  40941. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40942. columnIdBeingResized = 0;
  40943. repaint();
  40944. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40945. updateColumnUnderMouse (e.x, e.y);
  40946. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40947. columnClicked (columnIdUnderMouse, e.mods);
  40948. dragOverlayComp = 0;
  40949. }
  40950. const MouseCursor TableHeaderComponent::getMouseCursor()
  40951. {
  40952. int x, y;
  40953. getMouseXYRelative (x, y);
  40954. if (columnIdBeingResized != 0 || (getResizeDraggerAt (x) != 0 && ! isMouseButtonDown()))
  40955. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40956. return Component::getMouseCursor();
  40957. }
  40958. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40959. {
  40960. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40961. }
  40962. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40963. {
  40964. for (int i = columns.size(); --i >= 0;)
  40965. if (columns.getUnchecked(i)->id == id)
  40966. return columns.getUnchecked(i);
  40967. return 0;
  40968. }
  40969. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40970. {
  40971. int n = 0;
  40972. for (int i = 0; i < columns.size(); ++i)
  40973. {
  40974. if (columns.getUnchecked(i)->isVisible())
  40975. {
  40976. if (n == visibleIndex)
  40977. return i;
  40978. ++n;
  40979. }
  40980. }
  40981. return -1;
  40982. }
  40983. void TableHeaderComponent::sendColumnsChanged()
  40984. {
  40985. if (stretchToFit && lastDeliberateWidth > 0)
  40986. resizeAllColumnsToFit (lastDeliberateWidth);
  40987. repaint();
  40988. columnsChanged = true;
  40989. triggerAsyncUpdate();
  40990. }
  40991. void TableHeaderComponent::handleAsyncUpdate()
  40992. {
  40993. const bool changed = columnsChanged || sortChanged;
  40994. const bool sized = columnsResized || changed;
  40995. const bool sorted = sortChanged;
  40996. columnsChanged = false;
  40997. columnsResized = false;
  40998. sortChanged = false;
  40999. if (sorted)
  41000. {
  41001. for (int i = listeners.size(); --i >= 0;)
  41002. {
  41003. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  41004. i = jmin (i, listeners.size() - 1);
  41005. }
  41006. }
  41007. if (changed)
  41008. {
  41009. for (int i = listeners.size(); --i >= 0;)
  41010. {
  41011. listeners.getUnchecked(i)->tableColumnsChanged (this);
  41012. i = jmin (i, listeners.size() - 1);
  41013. }
  41014. }
  41015. if (sized)
  41016. {
  41017. for (int i = listeners.size(); --i >= 0;)
  41018. {
  41019. listeners.getUnchecked(i)->tableColumnsResized (this);
  41020. i = jmin (i, listeners.size() - 1);
  41021. }
  41022. }
  41023. }
  41024. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  41025. {
  41026. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  41027. {
  41028. const int draggableDistance = 3;
  41029. int x = 0;
  41030. for (int i = 0; i < columns.size(); ++i)
  41031. {
  41032. const ColumnInfo* const ci = columns.getUnchecked(i);
  41033. if (ci->isVisible())
  41034. {
  41035. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  41036. && (ci->propertyFlags & resizable) != 0)
  41037. return ci->id;
  41038. x += ci->width;
  41039. }
  41040. }
  41041. }
  41042. return 0;
  41043. }
  41044. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  41045. {
  41046. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  41047. ? getColumnIdAtX (x) : 0;
  41048. if (newCol != columnIdUnderMouse)
  41049. {
  41050. columnIdUnderMouse = newCol;
  41051. repaint();
  41052. }
  41053. }
  41054. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  41055. {
  41056. PopupMenu m;
  41057. addMenuItems (m, columnIdClicked);
  41058. if (m.getNumItems() > 0)
  41059. {
  41060. m.setLookAndFeel (&getLookAndFeel());
  41061. const int result = m.show();
  41062. if (result != 0)
  41063. reactToMenuItem (result, columnIdClicked);
  41064. }
  41065. }
  41066. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  41067. {
  41068. }
  41069. END_JUCE_NAMESPACE
  41070. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  41071. /*** Start of inlined file: juce_TableListBox.cpp ***/
  41072. BEGIN_JUCE_NAMESPACE
  41073. static const char* const tableColumnPropertyTag = "_tableColumnID";
  41074. class TableListRowComp : public Component,
  41075. public TooltipClient
  41076. {
  41077. public:
  41078. TableListRowComp (TableListBox& owner_)
  41079. : owner (owner_),
  41080. row (-1),
  41081. isSelected (false)
  41082. {
  41083. }
  41084. ~TableListRowComp()
  41085. {
  41086. deleteAllChildren();
  41087. }
  41088. void paint (Graphics& g)
  41089. {
  41090. TableListBoxModel* const model = owner.getModel();
  41091. if (model != 0)
  41092. {
  41093. const TableHeaderComponent* const header = owner.getHeader();
  41094. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  41095. const int numColumns = header->getNumColumns (true);
  41096. for (int i = 0; i < numColumns; ++i)
  41097. {
  41098. if (! columnsWithComponents [i])
  41099. {
  41100. const int columnId = header->getColumnIdOfIndex (i, true);
  41101. Rectangle<int> columnRect (header->getColumnPosition (i));
  41102. columnRect.setSize (columnRect.getWidth(), getHeight());
  41103. g.saveState();
  41104. g.reduceClipRegion (columnRect);
  41105. g.setOrigin (columnRect.getX(), 0);
  41106. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  41107. g.restoreState();
  41108. }
  41109. }
  41110. }
  41111. }
  41112. void update (const int newRow, const bool isNowSelected)
  41113. {
  41114. if (newRow != row || isNowSelected != isSelected)
  41115. {
  41116. row = newRow;
  41117. isSelected = isNowSelected;
  41118. repaint();
  41119. }
  41120. if (row < owner.getNumRows())
  41121. {
  41122. jassert (row >= 0);
  41123. const var::identifier tagPropertyName ("_tableLastUseNum");
  41124. const int newTag = Random::getSystemRandom().nextInt();
  41125. const TableHeaderComponent* const header = owner.getHeader();
  41126. const int numColumns = header->getNumColumns (true);
  41127. int i;
  41128. columnsWithComponents.clear();
  41129. if (owner.getModel() != 0)
  41130. {
  41131. for (i = 0; i < numColumns; ++i)
  41132. {
  41133. const int columnId = header->getColumnIdOfIndex (i, true);
  41134. Component* const newComp
  41135. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  41136. findChildComponentForColumn (columnId));
  41137. if (newComp != 0)
  41138. {
  41139. addAndMakeVisible (newComp);
  41140. newComp->getProperties().set (tagPropertyName, newTag);
  41141. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  41142. const Rectangle<int> columnRect (header->getColumnPosition (i));
  41143. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41144. columnsWithComponents.setBit (i);
  41145. }
  41146. }
  41147. }
  41148. for (i = getNumChildComponents(); --i >= 0;)
  41149. {
  41150. Component* const c = getChildComponent (i);
  41151. if ((int) c->getProperties() [tagPropertyName] != newTag)
  41152. delete c;
  41153. }
  41154. }
  41155. else
  41156. {
  41157. columnsWithComponents.clear();
  41158. deleteAllChildren();
  41159. }
  41160. }
  41161. void resized()
  41162. {
  41163. for (int i = getNumChildComponents(); --i >= 0;)
  41164. {
  41165. Component* const c = getChildComponent (i);
  41166. const int columnId = c->getProperties() [tableColumnPropertyTag];
  41167. if (columnId != 0)
  41168. {
  41169. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  41170. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41171. }
  41172. }
  41173. }
  41174. void mouseDown (const MouseEvent& e)
  41175. {
  41176. isDragging = false;
  41177. selectRowOnMouseUp = false;
  41178. if (isEnabled())
  41179. {
  41180. if (! isSelected)
  41181. {
  41182. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41183. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41184. if (columnId != 0 && owner.getModel() != 0)
  41185. owner.getModel()->cellClicked (row, columnId, e);
  41186. }
  41187. else
  41188. {
  41189. selectRowOnMouseUp = true;
  41190. }
  41191. }
  41192. }
  41193. void mouseDrag (const MouseEvent& e)
  41194. {
  41195. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  41196. {
  41197. const SparseSet <int> selectedRows (owner.getSelectedRows());
  41198. if (selectedRows.size() > 0)
  41199. {
  41200. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  41201. if (dragDescription.isNotEmpty())
  41202. {
  41203. isDragging = true;
  41204. owner.startDragAndDrop (e, dragDescription);
  41205. }
  41206. }
  41207. }
  41208. }
  41209. void mouseUp (const MouseEvent& e)
  41210. {
  41211. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  41212. {
  41213. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41214. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41215. if (columnId != 0 && owner.getModel() != 0)
  41216. owner.getModel()->cellClicked (row, columnId, e);
  41217. }
  41218. }
  41219. void mouseDoubleClick (const MouseEvent& e)
  41220. {
  41221. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41222. if (columnId != 0 && owner.getModel() != 0)
  41223. owner.getModel()->cellDoubleClicked (row, columnId, e);
  41224. }
  41225. const String getTooltip()
  41226. {
  41227. int x, y;
  41228. getMouseXYRelative (x, y);
  41229. const int columnId = owner.getHeader()->getColumnIdAtX (x);
  41230. if (columnId != 0 && owner.getModel() != 0)
  41231. return owner.getModel()->getCellTooltip (row, columnId);
  41232. return String::empty;
  41233. }
  41234. juce_UseDebuggingNewOperator
  41235. private:
  41236. TableListBox& owner;
  41237. int row;
  41238. bool isSelected, isDragging, selectRowOnMouseUp;
  41239. BitArray columnsWithComponents;
  41240. Component* findChildComponentForColumn (const int columnId) const
  41241. {
  41242. for (int i = getNumChildComponents(); --i >= 0;)
  41243. {
  41244. Component* const c = getChildComponent (i);
  41245. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  41246. return c;
  41247. }
  41248. return 0;
  41249. }
  41250. TableListRowComp (const TableListRowComp&);
  41251. const TableListRowComp& operator= (const TableListRowComp&);
  41252. };
  41253. class TableListBoxHeader : public TableHeaderComponent
  41254. {
  41255. public:
  41256. TableListBoxHeader (TableListBox& owner_)
  41257. : owner (owner_)
  41258. {
  41259. }
  41260. ~TableListBoxHeader()
  41261. {
  41262. }
  41263. void addMenuItems (PopupMenu& menu, const int columnIdClicked)
  41264. {
  41265. if (owner.isAutoSizeMenuOptionShown())
  41266. {
  41267. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  41268. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  41269. menu.addSeparator();
  41270. }
  41271. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  41272. }
  41273. void reactToMenuItem (const int menuReturnId, const int columnIdClicked)
  41274. {
  41275. if (menuReturnId == 0xf836743)
  41276. {
  41277. owner.autoSizeColumn (columnIdClicked);
  41278. }
  41279. else if (menuReturnId == 0xf836744)
  41280. {
  41281. owner.autoSizeAllColumns();
  41282. }
  41283. else
  41284. {
  41285. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  41286. }
  41287. }
  41288. juce_UseDebuggingNewOperator
  41289. private:
  41290. TableListBox& owner;
  41291. TableListBoxHeader (const TableListBoxHeader&);
  41292. const TableListBoxHeader& operator= (const TableListBoxHeader&);
  41293. };
  41294. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  41295. : ListBox (name, 0),
  41296. model (model_),
  41297. autoSizeOptionsShown (true)
  41298. {
  41299. ListBox::model = this;
  41300. header = new TableListBoxHeader (*this);
  41301. header->setSize (100, 28);
  41302. header->addListener (this);
  41303. setHeaderComponent (header);
  41304. }
  41305. TableListBox::~TableListBox()
  41306. {
  41307. deleteAllChildren();
  41308. }
  41309. void TableListBox::setModel (TableListBoxModel* const newModel)
  41310. {
  41311. if (model != newModel)
  41312. {
  41313. model = newModel;
  41314. updateContent();
  41315. }
  41316. }
  41317. int TableListBox::getHeaderHeight() const
  41318. {
  41319. return header->getHeight();
  41320. }
  41321. void TableListBox::setHeaderHeight (const int newHeight)
  41322. {
  41323. header->setSize (header->getWidth(), newHeight);
  41324. resized();
  41325. }
  41326. void TableListBox::autoSizeColumn (const int columnId)
  41327. {
  41328. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  41329. if (width > 0)
  41330. header->setColumnWidth (columnId, width);
  41331. }
  41332. void TableListBox::autoSizeAllColumns()
  41333. {
  41334. for (int i = 0; i < header->getNumColumns (true); ++i)
  41335. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  41336. }
  41337. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  41338. {
  41339. autoSizeOptionsShown = shouldBeShown;
  41340. }
  41341. bool TableListBox::isAutoSizeMenuOptionShown() const
  41342. {
  41343. return autoSizeOptionsShown;
  41344. }
  41345. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  41346. const int rowNumber,
  41347. const bool relativeToComponentTopLeft) const
  41348. {
  41349. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41350. if (relativeToComponentTopLeft)
  41351. headerCell.translate (header->getX(), 0);
  41352. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  41353. return Rectangle<int> (headerCell.getX(), row.getY(),
  41354. headerCell.getWidth(), row.getHeight());
  41355. }
  41356. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  41357. {
  41358. ScrollBar* const scrollbar = getHorizontalScrollBar();
  41359. if (scrollbar != 0)
  41360. {
  41361. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41362. double x = scrollbar->getCurrentRangeStart();
  41363. const double w = scrollbar->getCurrentRangeSize();
  41364. if (pos.getX() < x)
  41365. x = pos.getX();
  41366. else if (pos.getRight() > x + w)
  41367. x += jmax (0.0, pos.getRight() - (x + w));
  41368. scrollbar->setCurrentRangeStart (x);
  41369. }
  41370. }
  41371. int TableListBox::getNumRows()
  41372. {
  41373. return model != 0 ? model->getNumRows() : 0;
  41374. }
  41375. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  41376. {
  41377. }
  41378. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  41379. {
  41380. if (existingComponentToUpdate == 0)
  41381. existingComponentToUpdate = new TableListRowComp (*this);
  41382. ((TableListRowComp*) existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  41383. return existingComponentToUpdate;
  41384. }
  41385. void TableListBox::selectedRowsChanged (int row)
  41386. {
  41387. if (model != 0)
  41388. model->selectedRowsChanged (row);
  41389. }
  41390. void TableListBox::deleteKeyPressed (int row)
  41391. {
  41392. if (model != 0)
  41393. model->deleteKeyPressed (row);
  41394. }
  41395. void TableListBox::returnKeyPressed (int row)
  41396. {
  41397. if (model != 0)
  41398. model->returnKeyPressed (row);
  41399. }
  41400. void TableListBox::backgroundClicked()
  41401. {
  41402. if (model != 0)
  41403. model->backgroundClicked();
  41404. }
  41405. void TableListBox::listWasScrolled()
  41406. {
  41407. if (model != 0)
  41408. model->listWasScrolled();
  41409. }
  41410. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  41411. {
  41412. setMinimumContentWidth (header->getTotalWidth());
  41413. repaint();
  41414. updateColumnComponents();
  41415. }
  41416. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  41417. {
  41418. setMinimumContentWidth (header->getTotalWidth());
  41419. repaint();
  41420. updateColumnComponents();
  41421. }
  41422. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  41423. {
  41424. if (model != 0)
  41425. model->sortOrderChanged (header->getSortColumnId(),
  41426. header->isSortedForwards());
  41427. }
  41428. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  41429. {
  41430. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  41431. repaint();
  41432. }
  41433. void TableListBox::resized()
  41434. {
  41435. ListBox::resized();
  41436. header->resizeAllColumnsToFit (getVisibleContentWidth());
  41437. setMinimumContentWidth (header->getTotalWidth());
  41438. }
  41439. void TableListBox::updateColumnComponents() const
  41440. {
  41441. const int firstRow = getRowContainingPosition (0, 0);
  41442. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  41443. {
  41444. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  41445. if (rowComp != 0)
  41446. rowComp->resized();
  41447. }
  41448. }
  41449. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  41450. {
  41451. }
  41452. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  41453. {
  41454. }
  41455. void TableListBoxModel::backgroundClicked()
  41456. {
  41457. }
  41458. void TableListBoxModel::sortOrderChanged (int, const bool)
  41459. {
  41460. }
  41461. int TableListBoxModel::getColumnAutoSizeWidth (int)
  41462. {
  41463. return 0;
  41464. }
  41465. void TableListBoxModel::selectedRowsChanged (int)
  41466. {
  41467. }
  41468. void TableListBoxModel::deleteKeyPressed (int)
  41469. {
  41470. }
  41471. void TableListBoxModel::returnKeyPressed (int)
  41472. {
  41473. }
  41474. void TableListBoxModel::listWasScrolled()
  41475. {
  41476. }
  41477. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  41478. {
  41479. return String::empty;
  41480. }
  41481. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  41482. {
  41483. return String::empty;
  41484. }
  41485. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  41486. {
  41487. (void) existingComponentToUpdate;
  41488. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  41489. return 0;
  41490. }
  41491. END_JUCE_NAMESPACE
  41492. /*** End of inlined file: juce_TableListBox.cpp ***/
  41493. /*** Start of inlined file: juce_TextEditor.cpp ***/
  41494. BEGIN_JUCE_NAMESPACE
  41495. // a word or space that can't be broken down any further
  41496. struct TextAtom
  41497. {
  41498. String atomText;
  41499. float width;
  41500. uint16 numChars;
  41501. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  41502. bool isNewLine() const { return atomText[0] == T('\r') || atomText[0] == T('\n'); }
  41503. const String getText (const tchar passwordCharacter) const
  41504. {
  41505. if (passwordCharacter == 0)
  41506. return atomText;
  41507. else
  41508. return String::repeatedString (String::charToString (passwordCharacter),
  41509. atomText.length());
  41510. }
  41511. const String getTrimmedText (const tchar passwordCharacter) const
  41512. {
  41513. if (passwordCharacter == 0)
  41514. return atomText.substring (0, numChars);
  41515. else if (isNewLine())
  41516. return String::empty;
  41517. else
  41518. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  41519. }
  41520. };
  41521. // a run of text with a single font and colour
  41522. class UniformTextSection
  41523. {
  41524. public:
  41525. UniformTextSection (const String& text,
  41526. const Font& font_,
  41527. const Colour& colour_,
  41528. const tchar passwordCharacter)
  41529. : font (font_),
  41530. colour (colour_)
  41531. {
  41532. initialiseAtoms (text, passwordCharacter);
  41533. }
  41534. UniformTextSection (const UniformTextSection& other)
  41535. : font (other.font),
  41536. colour (other.colour)
  41537. {
  41538. atoms.ensureStorageAllocated (other.atoms.size());
  41539. for (int i = 0; i < other.atoms.size(); ++i)
  41540. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  41541. }
  41542. ~UniformTextSection()
  41543. {
  41544. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  41545. }
  41546. void clear()
  41547. {
  41548. for (int i = atoms.size(); --i >= 0;)
  41549. delete getAtom(i);
  41550. atoms.clear();
  41551. }
  41552. int getNumAtoms() const
  41553. {
  41554. return atoms.size();
  41555. }
  41556. TextAtom* getAtom (const int index) const
  41557. {
  41558. return (TextAtom*) atoms.getUnchecked (index);
  41559. }
  41560. void append (const UniformTextSection& other, const tchar passwordCharacter)
  41561. {
  41562. if (other.atoms.size() > 0)
  41563. {
  41564. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  41565. int i = 0;
  41566. if (lastAtom != 0)
  41567. {
  41568. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  41569. {
  41570. TextAtom* const first = other.getAtom(0);
  41571. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  41572. {
  41573. lastAtom->atomText += first->atomText;
  41574. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  41575. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  41576. delete first;
  41577. ++i;
  41578. }
  41579. }
  41580. }
  41581. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  41582. while (i < other.atoms.size())
  41583. {
  41584. atoms.add (other.getAtom(i));
  41585. ++i;
  41586. }
  41587. }
  41588. }
  41589. UniformTextSection* split (const int indexToBreakAt,
  41590. const tchar passwordCharacter)
  41591. {
  41592. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  41593. font, colour,
  41594. passwordCharacter);
  41595. int index = 0;
  41596. for (int i = 0; i < atoms.size(); ++i)
  41597. {
  41598. TextAtom* const atom = getAtom(i);
  41599. const int nextIndex = index + atom->numChars;
  41600. if (index == indexToBreakAt)
  41601. {
  41602. int j;
  41603. for (j = i; j < atoms.size(); ++j)
  41604. section2->atoms.add (getAtom (j));
  41605. for (j = atoms.size(); --j >= i;)
  41606. atoms.remove (j);
  41607. break;
  41608. }
  41609. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  41610. {
  41611. TextAtom* const secondAtom = new TextAtom();
  41612. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  41613. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  41614. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  41615. section2->atoms.add (secondAtom);
  41616. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  41617. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41618. atom->numChars = (uint16) (indexToBreakAt - index);
  41619. int j;
  41620. for (j = i + 1; j < atoms.size(); ++j)
  41621. section2->atoms.add (getAtom (j));
  41622. for (j = atoms.size(); --j > i;)
  41623. atoms.remove (j);
  41624. break;
  41625. }
  41626. index = nextIndex;
  41627. }
  41628. return section2;
  41629. }
  41630. void appendAllText (String::Concatenator& concatenator) const
  41631. {
  41632. for (int i = 0; i < atoms.size(); ++i)
  41633. concatenator.append (getAtom(i)->atomText);
  41634. }
  41635. void appendSubstring (String::Concatenator& concatenator,
  41636. const Range<int>& range) const
  41637. {
  41638. int index = 0;
  41639. for (int i = 0; i < atoms.size(); ++i)
  41640. {
  41641. const TextAtom* const atom = getAtom (i);
  41642. const int nextIndex = index + atom->numChars;
  41643. if (range.getStart() < nextIndex)
  41644. {
  41645. if (range.getEnd() <= index)
  41646. break;
  41647. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  41648. if (! r.isEmpty())
  41649. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  41650. }
  41651. index = nextIndex;
  41652. }
  41653. }
  41654. int getTotalLength() const
  41655. {
  41656. int total = 0;
  41657. for (int i = atoms.size(); --i >= 0;)
  41658. total += getAtom(i)->numChars;
  41659. return total;
  41660. }
  41661. void setFont (const Font& newFont,
  41662. const tchar passwordCharacter)
  41663. {
  41664. if (font != newFont)
  41665. {
  41666. font = newFont;
  41667. for (int i = atoms.size(); --i >= 0;)
  41668. {
  41669. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41670. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41671. }
  41672. }
  41673. }
  41674. juce_UseDebuggingNewOperator
  41675. Font font;
  41676. Colour colour;
  41677. private:
  41678. VoidArray atoms;
  41679. void initialiseAtoms (const String& textToParse,
  41680. const tchar passwordCharacter)
  41681. {
  41682. int i = 0;
  41683. const int len = textToParse.length();
  41684. const tchar* const text = (const tchar*) textToParse;
  41685. while (i < len)
  41686. {
  41687. int start = i;
  41688. // create a whitespace atom unless it starts with non-ws
  41689. if (CharacterFunctions::isWhitespace (text[i])
  41690. && text[i] != T('\r')
  41691. && text[i] != T('\n'))
  41692. {
  41693. while (i < len
  41694. && CharacterFunctions::isWhitespace (text[i])
  41695. && text[i] != T('\r')
  41696. && text[i] != T('\n'))
  41697. {
  41698. ++i;
  41699. }
  41700. }
  41701. else
  41702. {
  41703. if (text[i] == T('\r'))
  41704. {
  41705. ++i;
  41706. if ((i < len) && (text[i] == T('\n')))
  41707. {
  41708. ++start;
  41709. ++i;
  41710. }
  41711. }
  41712. else if (text[i] == T('\n'))
  41713. {
  41714. ++i;
  41715. }
  41716. else
  41717. {
  41718. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41719. ++i;
  41720. }
  41721. }
  41722. TextAtom* const atom = new TextAtom();
  41723. atom->atomText = String (text + start, i - start);
  41724. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41725. atom->numChars = (uint16) (i - start);
  41726. atoms.add (atom);
  41727. }
  41728. }
  41729. const UniformTextSection& operator= (const UniformTextSection& other);
  41730. };
  41731. class TextEditorIterator
  41732. {
  41733. public:
  41734. TextEditorIterator (const VoidArray& sections_,
  41735. const float wordWrapWidth_,
  41736. const tchar passwordCharacter_)
  41737. : indexInText (0),
  41738. lineY (0),
  41739. lineHeight (0),
  41740. maxDescent (0),
  41741. atomX (0),
  41742. atomRight (0),
  41743. atom (0),
  41744. currentSection (0),
  41745. sections (sections_),
  41746. sectionIndex (0),
  41747. atomIndex (0),
  41748. wordWrapWidth (wordWrapWidth_),
  41749. passwordCharacter (passwordCharacter_)
  41750. {
  41751. jassert (wordWrapWidth_ > 0);
  41752. if (sections.size() > 0)
  41753. {
  41754. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41755. if (currentSection != 0)
  41756. beginNewLine();
  41757. }
  41758. }
  41759. TextEditorIterator (const TextEditorIterator& other)
  41760. : indexInText (other.indexInText),
  41761. lineY (other.lineY),
  41762. lineHeight (other.lineHeight),
  41763. maxDescent (other.maxDescent),
  41764. atomX (other.atomX),
  41765. atomRight (other.atomRight),
  41766. atom (other.atom),
  41767. currentSection (other.currentSection),
  41768. sections (other.sections),
  41769. sectionIndex (other.sectionIndex),
  41770. atomIndex (other.atomIndex),
  41771. wordWrapWidth (other.wordWrapWidth),
  41772. passwordCharacter (other.passwordCharacter),
  41773. tempAtom (other.tempAtom)
  41774. {
  41775. }
  41776. ~TextEditorIterator()
  41777. {
  41778. }
  41779. bool next()
  41780. {
  41781. if (atom == &tempAtom)
  41782. {
  41783. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41784. if (numRemaining > 0)
  41785. {
  41786. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41787. atomX = 0;
  41788. if (tempAtom.numChars > 0)
  41789. lineY += lineHeight;
  41790. indexInText += tempAtom.numChars;
  41791. GlyphArrangement g;
  41792. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41793. int split;
  41794. for (split = 0; split < g.getNumGlyphs(); ++split)
  41795. if (shouldWrap (g.getGlyph (split).getRight()))
  41796. break;
  41797. if (split > 0 && split <= numRemaining)
  41798. {
  41799. tempAtom.numChars = (uint16) split;
  41800. tempAtom.width = g.getGlyph (split - 1).getRight();
  41801. atomRight = atomX + tempAtom.width;
  41802. return true;
  41803. }
  41804. }
  41805. }
  41806. bool forceNewLine = false;
  41807. if (sectionIndex >= sections.size())
  41808. {
  41809. moveToEndOfLastAtom();
  41810. return false;
  41811. }
  41812. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41813. {
  41814. if (atomIndex >= currentSection->getNumAtoms())
  41815. {
  41816. if (++sectionIndex >= sections.size())
  41817. {
  41818. moveToEndOfLastAtom();
  41819. return false;
  41820. }
  41821. atomIndex = 0;
  41822. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41823. }
  41824. else
  41825. {
  41826. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41827. if (! lastAtom->isWhitespace())
  41828. {
  41829. // handle the case where the last atom in a section is actually part of the same
  41830. // word as the first atom of the next section...
  41831. float right = atomRight + lastAtom->width;
  41832. float lineHeight2 = lineHeight;
  41833. float maxDescent2 = maxDescent;
  41834. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41835. {
  41836. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41837. if (s->getNumAtoms() == 0)
  41838. break;
  41839. const TextAtom* const nextAtom = s->getAtom (0);
  41840. if (nextAtom->isWhitespace())
  41841. break;
  41842. right += nextAtom->width;
  41843. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41844. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41845. if (shouldWrap (right))
  41846. {
  41847. lineHeight = lineHeight2;
  41848. maxDescent = maxDescent2;
  41849. forceNewLine = true;
  41850. break;
  41851. }
  41852. if (s->getNumAtoms() > 1)
  41853. break;
  41854. }
  41855. }
  41856. }
  41857. }
  41858. if (atom != 0)
  41859. {
  41860. atomX = atomRight;
  41861. indexInText += atom->numChars;
  41862. if (atom->isNewLine())
  41863. beginNewLine();
  41864. }
  41865. atom = currentSection->getAtom (atomIndex);
  41866. atomRight = atomX + atom->width;
  41867. ++atomIndex;
  41868. if (shouldWrap (atomRight) || forceNewLine)
  41869. {
  41870. if (atom->isWhitespace())
  41871. {
  41872. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41873. atomRight = jmin (atomRight, wordWrapWidth);
  41874. }
  41875. else
  41876. {
  41877. atomRight = atom->width;
  41878. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41879. {
  41880. tempAtom = *atom;
  41881. tempAtom.width = 0;
  41882. tempAtom.numChars = 0;
  41883. atom = &tempAtom;
  41884. if (atomX > 0)
  41885. beginNewLine();
  41886. return next();
  41887. }
  41888. beginNewLine();
  41889. return true;
  41890. }
  41891. }
  41892. return true;
  41893. }
  41894. void beginNewLine()
  41895. {
  41896. atomX = 0;
  41897. lineY += lineHeight;
  41898. int tempSectionIndex = sectionIndex;
  41899. int tempAtomIndex = atomIndex;
  41900. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41901. lineHeight = section->font.getHeight();
  41902. maxDescent = section->font.getDescent();
  41903. float x = (atom != 0) ? atom->width : 0;
  41904. while (! shouldWrap (x))
  41905. {
  41906. if (tempSectionIndex >= sections.size())
  41907. break;
  41908. bool checkSize = false;
  41909. if (tempAtomIndex >= section->getNumAtoms())
  41910. {
  41911. if (++tempSectionIndex >= sections.size())
  41912. break;
  41913. tempAtomIndex = 0;
  41914. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41915. checkSize = true;
  41916. }
  41917. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41918. if (nextAtom == 0)
  41919. break;
  41920. x += nextAtom->width;
  41921. if (shouldWrap (x) || nextAtom->isNewLine())
  41922. break;
  41923. if (checkSize)
  41924. {
  41925. lineHeight = jmax (lineHeight, section->font.getHeight());
  41926. maxDescent = jmax (maxDescent, section->font.getDescent());
  41927. }
  41928. ++tempAtomIndex;
  41929. }
  41930. }
  41931. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41932. {
  41933. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41934. {
  41935. if (lastSection != currentSection)
  41936. {
  41937. lastSection = currentSection;
  41938. g.setColour (currentSection->colour);
  41939. g.setFont (currentSection->font);
  41940. }
  41941. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41942. GlyphArrangement ga;
  41943. ga.addLineOfText (currentSection->font,
  41944. atom->getTrimmedText (passwordCharacter),
  41945. atomX,
  41946. (float) roundToInt (lineY + lineHeight - maxDescent));
  41947. ga.draw (g);
  41948. }
  41949. }
  41950. void drawSelection (Graphics& g,
  41951. const Range<int>& selection) const
  41952. {
  41953. const int startX = roundToInt (indexToX (selection.getStart()));
  41954. const int endX = roundToInt (indexToX (selection.getEnd()));
  41955. const int y = roundToInt (lineY);
  41956. const int nextY = roundToInt (lineY + lineHeight);
  41957. g.fillRect (startX, y, endX - startX, nextY - y);
  41958. }
  41959. void drawSelectedText (Graphics& g,
  41960. const Range<int>& selection,
  41961. const Colour& selectedTextColour) const
  41962. {
  41963. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41964. {
  41965. GlyphArrangement ga;
  41966. ga.addLineOfText (currentSection->font,
  41967. atom->getTrimmedText (passwordCharacter),
  41968. atomX,
  41969. (float) roundToInt (lineY + lineHeight - maxDescent));
  41970. if (selection.getEnd() < indexInText + atom->numChars)
  41971. {
  41972. GlyphArrangement ga2 (ga);
  41973. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41974. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41975. g.setColour (currentSection->colour);
  41976. ga2.draw (g);
  41977. }
  41978. if (selection.getStart() > indexInText)
  41979. {
  41980. GlyphArrangement ga2 (ga);
  41981. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41982. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41983. g.setColour (currentSection->colour);
  41984. ga2.draw (g);
  41985. }
  41986. g.setColour (selectedTextColour);
  41987. ga.draw (g);
  41988. }
  41989. }
  41990. float indexToX (const int indexToFind) const
  41991. {
  41992. if (indexToFind <= indexInText)
  41993. return atomX;
  41994. if (indexToFind >= indexInText + atom->numChars)
  41995. return atomRight;
  41996. GlyphArrangement g;
  41997. g.addLineOfText (currentSection->font,
  41998. atom->getText (passwordCharacter),
  41999. atomX, 0.0f);
  42000. if (indexToFind - indexInText >= g.getNumGlyphs())
  42001. return atomRight;
  42002. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  42003. }
  42004. int xToIndex (const float xToFind) const
  42005. {
  42006. if (xToFind <= atomX || atom->isNewLine())
  42007. return indexInText;
  42008. if (xToFind >= atomRight)
  42009. return indexInText + atom->numChars;
  42010. GlyphArrangement g;
  42011. g.addLineOfText (currentSection->font,
  42012. atom->getText (passwordCharacter),
  42013. atomX, 0.0f);
  42014. int j;
  42015. for (j = 0; j < g.getNumGlyphs(); ++j)
  42016. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  42017. break;
  42018. return indexInText + j;
  42019. }
  42020. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  42021. {
  42022. while (next())
  42023. {
  42024. if (indexInText + atom->numChars > index)
  42025. {
  42026. cx = indexToX (index);
  42027. cy = lineY;
  42028. lineHeight_ = lineHeight;
  42029. return true;
  42030. }
  42031. }
  42032. cx = atomX;
  42033. cy = lineY;
  42034. lineHeight_ = lineHeight;
  42035. return false;
  42036. }
  42037. juce_UseDebuggingNewOperator
  42038. int indexInText;
  42039. float lineY, lineHeight, maxDescent;
  42040. float atomX, atomRight;
  42041. const TextAtom* atom;
  42042. const UniformTextSection* currentSection;
  42043. private:
  42044. const VoidArray& sections;
  42045. int sectionIndex, atomIndex;
  42046. const float wordWrapWidth;
  42047. const tchar passwordCharacter;
  42048. TextAtom tempAtom;
  42049. const TextEditorIterator& operator= (const TextEditorIterator&);
  42050. void moveToEndOfLastAtom()
  42051. {
  42052. if (atom != 0)
  42053. {
  42054. atomX = atomRight;
  42055. if (atom->isNewLine())
  42056. {
  42057. atomX = 0.0f;
  42058. lineY += lineHeight;
  42059. }
  42060. }
  42061. }
  42062. bool shouldWrap (const float x) const
  42063. {
  42064. return (x - 0.0001f) >= wordWrapWidth;
  42065. }
  42066. };
  42067. class TextEditorInsertAction : public UndoableAction
  42068. {
  42069. TextEditor& owner;
  42070. const String text;
  42071. const int insertIndex, oldCaretPos, newCaretPos;
  42072. const Font font;
  42073. const Colour colour;
  42074. TextEditorInsertAction (const TextEditorInsertAction&);
  42075. const TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  42076. public:
  42077. TextEditorInsertAction (TextEditor& owner_,
  42078. const String& text_,
  42079. const int insertIndex_,
  42080. const Font& font_,
  42081. const Colour& colour_,
  42082. const int oldCaretPos_,
  42083. const int newCaretPos_)
  42084. : owner (owner_),
  42085. text (text_),
  42086. insertIndex (insertIndex_),
  42087. oldCaretPos (oldCaretPos_),
  42088. newCaretPos (newCaretPos_),
  42089. font (font_),
  42090. colour (colour_)
  42091. {
  42092. }
  42093. ~TextEditorInsertAction()
  42094. {
  42095. }
  42096. bool perform()
  42097. {
  42098. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  42099. return true;
  42100. }
  42101. bool undo()
  42102. {
  42103. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  42104. return true;
  42105. }
  42106. int getSizeInUnits()
  42107. {
  42108. return text.length() + 16;
  42109. }
  42110. };
  42111. class TextEditorRemoveAction : public UndoableAction
  42112. {
  42113. TextEditor& owner;
  42114. const Range<int> range;
  42115. const int oldCaretPos, newCaretPos;
  42116. VoidArray removedSections;
  42117. TextEditorRemoveAction (const TextEditorRemoveAction&);
  42118. const TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  42119. public:
  42120. TextEditorRemoveAction (TextEditor& owner_,
  42121. const Range<int> range_,
  42122. const int oldCaretPos_,
  42123. const int newCaretPos_,
  42124. const VoidArray& removedSections_)
  42125. : owner (owner_),
  42126. range (range_),
  42127. oldCaretPos (oldCaretPos_),
  42128. newCaretPos (newCaretPos_),
  42129. removedSections (removedSections_)
  42130. {
  42131. }
  42132. ~TextEditorRemoveAction()
  42133. {
  42134. for (int i = removedSections.size(); --i >= 0;)
  42135. {
  42136. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42137. section->clear();
  42138. delete section;
  42139. }
  42140. }
  42141. bool perform()
  42142. {
  42143. owner.remove (range, 0, newCaretPos);
  42144. return true;
  42145. }
  42146. bool undo()
  42147. {
  42148. owner.reinsert (range.getStart(), removedSections);
  42149. owner.moveCursorTo (oldCaretPos, false);
  42150. return true;
  42151. }
  42152. int getSizeInUnits()
  42153. {
  42154. int n = 0;
  42155. for (int i = removedSections.size(); --i >= 0;)
  42156. {
  42157. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42158. n += section->getTotalLength();
  42159. }
  42160. return n + 16;
  42161. }
  42162. };
  42163. class TextHolderComponent : public Component,
  42164. public Timer,
  42165. public Value::Listener
  42166. {
  42167. TextEditor& owner;
  42168. TextHolderComponent (const TextHolderComponent&);
  42169. const TextHolderComponent& operator= (const TextHolderComponent&);
  42170. public:
  42171. TextHolderComponent (TextEditor& owner_)
  42172. : owner (owner_)
  42173. {
  42174. setWantsKeyboardFocus (false);
  42175. setInterceptsMouseClicks (false, true);
  42176. owner.getTextValue().addListener (this);
  42177. }
  42178. ~TextHolderComponent()
  42179. {
  42180. owner.getTextValue().removeListener (this);
  42181. }
  42182. void paint (Graphics& g)
  42183. {
  42184. owner.drawContent (g);
  42185. }
  42186. void timerCallback()
  42187. {
  42188. owner.timerCallbackInt();
  42189. }
  42190. const MouseCursor getMouseCursor()
  42191. {
  42192. return owner.getMouseCursor();
  42193. }
  42194. void valueChanged (Value&)
  42195. {
  42196. owner.textWasChangedByValue();
  42197. }
  42198. };
  42199. class TextEditorViewport : public Viewport
  42200. {
  42201. TextEditor* const owner;
  42202. float lastWordWrapWidth;
  42203. TextEditorViewport (const TextEditorViewport&);
  42204. const TextEditorViewport& operator= (const TextEditorViewport&);
  42205. public:
  42206. TextEditorViewport (TextEditor* const owner_)
  42207. : owner (owner_),
  42208. lastWordWrapWidth (0)
  42209. {
  42210. }
  42211. ~TextEditorViewport()
  42212. {
  42213. }
  42214. void visibleAreaChanged (int, int, int, int)
  42215. {
  42216. const float wordWrapWidth = owner->getWordWrapWidth();
  42217. if (wordWrapWidth != lastWordWrapWidth)
  42218. {
  42219. lastWordWrapWidth = wordWrapWidth;
  42220. owner->updateTextHolderSize();
  42221. }
  42222. }
  42223. };
  42224. namespace TextEditorDefs
  42225. {
  42226. const int flashSpeedIntervalMs = 380;
  42227. const int textChangeMessageId = 0x10003001;
  42228. const int returnKeyMessageId = 0x10003002;
  42229. const int escapeKeyMessageId = 0x10003003;
  42230. const int focusLossMessageId = 0x10003004;
  42231. const int maxActionsPerTransaction = 100;
  42232. }
  42233. TextEditor::TextEditor (const String& name,
  42234. const tchar passwordCharacter_)
  42235. : Component (name),
  42236. borderSize (1, 1, 1, 3),
  42237. readOnly (false),
  42238. multiline (false),
  42239. wordWrap (false),
  42240. returnKeyStartsNewLine (false),
  42241. caretVisible (true),
  42242. popupMenuEnabled (true),
  42243. selectAllTextWhenFocused (false),
  42244. scrollbarVisible (true),
  42245. wasFocused (false),
  42246. caretFlashState (true),
  42247. keepCursorOnScreen (true),
  42248. tabKeyUsed (false),
  42249. menuActive (false),
  42250. valueTextNeedsUpdating (false),
  42251. cursorX (0),
  42252. cursorY (0),
  42253. cursorHeight (0),
  42254. maxTextLength (0),
  42255. leftIndent (4),
  42256. topIndent (4),
  42257. lastTransactionTime (0),
  42258. currentFont (14.0f),
  42259. totalNumChars (0),
  42260. caretPosition (0),
  42261. passwordCharacter (passwordCharacter_),
  42262. dragType (notDragging)
  42263. {
  42264. setOpaque (true);
  42265. addAndMakeVisible (viewport = new TextEditorViewport (this));
  42266. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  42267. viewport->setWantsKeyboardFocus (false);
  42268. viewport->setScrollBarsShown (false, false);
  42269. setMouseCursor (MouseCursor::IBeamCursor);
  42270. setWantsKeyboardFocus (true);
  42271. }
  42272. TextEditor::~TextEditor()
  42273. {
  42274. textValue.referTo (Value());
  42275. clearInternal (0);
  42276. viewport = 0;
  42277. textHolder = 0;
  42278. }
  42279. void TextEditor::newTransaction()
  42280. {
  42281. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42282. undoManager.beginNewTransaction();
  42283. }
  42284. void TextEditor::doUndoRedo (const bool isRedo)
  42285. {
  42286. if (! isReadOnly())
  42287. {
  42288. if ((isRedo) ? undoManager.redo()
  42289. : undoManager.undo())
  42290. {
  42291. scrollToMakeSureCursorIsVisible();
  42292. repaint();
  42293. textChanged();
  42294. }
  42295. }
  42296. }
  42297. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  42298. const bool shouldWordWrap)
  42299. {
  42300. multiline = shouldBeMultiLine;
  42301. wordWrap = shouldWordWrap && shouldBeMultiLine;
  42302. setScrollbarsShown (scrollbarVisible);
  42303. viewport->setViewPosition (0, 0);
  42304. resized();
  42305. scrollToMakeSureCursorIsVisible();
  42306. }
  42307. bool TextEditor::isMultiLine() const
  42308. {
  42309. return multiline;
  42310. }
  42311. void TextEditor::setScrollbarsShown (bool enabled)
  42312. {
  42313. scrollbarVisible = enabled;
  42314. enabled = enabled && isMultiLine();
  42315. viewport->setScrollBarsShown (enabled, enabled);
  42316. }
  42317. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  42318. {
  42319. readOnly = shouldBeReadOnly;
  42320. enablementChanged();
  42321. }
  42322. bool TextEditor::isReadOnly() const
  42323. {
  42324. return readOnly || ! isEnabled();
  42325. }
  42326. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  42327. {
  42328. returnKeyStartsNewLine = shouldStartNewLine;
  42329. }
  42330. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  42331. {
  42332. tabKeyUsed = shouldTabKeyBeUsed;
  42333. }
  42334. void TextEditor::setPopupMenuEnabled (const bool b)
  42335. {
  42336. popupMenuEnabled = b;
  42337. }
  42338. void TextEditor::setSelectAllWhenFocused (const bool b)
  42339. {
  42340. selectAllTextWhenFocused = b;
  42341. }
  42342. const Font TextEditor::getFont() const
  42343. {
  42344. return currentFont;
  42345. }
  42346. void TextEditor::setFont (const Font& newFont)
  42347. {
  42348. currentFont = newFont;
  42349. scrollToMakeSureCursorIsVisible();
  42350. }
  42351. void TextEditor::applyFontToAllText (const Font& newFont)
  42352. {
  42353. currentFont = newFont;
  42354. const Colour overallColour (findColour (textColourId));
  42355. for (int i = sections.size(); --i >= 0;)
  42356. {
  42357. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  42358. uts->setFont (newFont, passwordCharacter);
  42359. uts->colour = overallColour;
  42360. }
  42361. coalesceSimilarSections();
  42362. updateTextHolderSize();
  42363. scrollToMakeSureCursorIsVisible();
  42364. repaint();
  42365. }
  42366. void TextEditor::colourChanged()
  42367. {
  42368. setOpaque (findColour (backgroundColourId).isOpaque());
  42369. repaint();
  42370. }
  42371. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  42372. {
  42373. caretVisible = shouldCaretBeVisible;
  42374. if (shouldCaretBeVisible)
  42375. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42376. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  42377. : MouseCursor::NormalCursor);
  42378. }
  42379. void TextEditor::setInputRestrictions (const int maxLen,
  42380. const String& chars)
  42381. {
  42382. maxTextLength = jmax (0, maxLen);
  42383. allowedCharacters = chars;
  42384. }
  42385. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  42386. {
  42387. textToShowWhenEmpty = text;
  42388. colourForTextWhenEmpty = colourToUse;
  42389. }
  42390. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  42391. {
  42392. if (passwordCharacter != newPasswordCharacter)
  42393. {
  42394. passwordCharacter = newPasswordCharacter;
  42395. resized();
  42396. repaint();
  42397. }
  42398. }
  42399. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  42400. {
  42401. viewport->setScrollBarThickness (newThicknessPixels);
  42402. }
  42403. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  42404. {
  42405. viewport->setScrollBarButtonVisibility (buttonsVisible);
  42406. }
  42407. void TextEditor::clear()
  42408. {
  42409. clearInternal (0);
  42410. updateTextHolderSize();
  42411. undoManager.clearUndoHistory();
  42412. }
  42413. void TextEditor::setText (const String& newText,
  42414. const bool sendTextChangeMessage)
  42415. {
  42416. const int newLength = newText.length();
  42417. if (newLength != getTotalNumChars() || getText() != newText)
  42418. {
  42419. const int oldCursorPos = caretPosition;
  42420. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  42421. clearInternal (0);
  42422. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  42423. // if you're adding text with line-feeds to a single-line text editor, it
  42424. // ain't gonna look right!
  42425. jassert (multiline || ! newText.containsAnyOf (T("\r\n")));
  42426. if (cursorWasAtEnd && ! isMultiLine())
  42427. moveCursorTo (getTotalNumChars(), false);
  42428. else
  42429. moveCursorTo (oldCursorPos, false);
  42430. if (sendTextChangeMessage)
  42431. textChanged();
  42432. repaint();
  42433. }
  42434. updateTextHolderSize();
  42435. scrollToMakeSureCursorIsVisible();
  42436. undoManager.clearUndoHistory();
  42437. }
  42438. Value& TextEditor::getTextValue()
  42439. {
  42440. if (valueTextNeedsUpdating)
  42441. {
  42442. valueTextNeedsUpdating = false;
  42443. textValue = getText();
  42444. }
  42445. return textValue;
  42446. }
  42447. void TextEditor::textWasChangedByValue()
  42448. {
  42449. if (textValue.getValueSource().getReferenceCount() > 1)
  42450. setText (textValue.getValue());
  42451. }
  42452. void TextEditor::textChanged()
  42453. {
  42454. updateTextHolderSize();
  42455. postCommandMessage (TextEditorDefs::textChangeMessageId);
  42456. if (textValue.getValueSource().getReferenceCount() > 1)
  42457. {
  42458. valueTextNeedsUpdating = false;
  42459. textValue = getText();
  42460. }
  42461. }
  42462. void TextEditor::returnPressed()
  42463. {
  42464. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  42465. }
  42466. void TextEditor::escapePressed()
  42467. {
  42468. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  42469. }
  42470. void TextEditor::addListener (TextEditorListener* const newListener)
  42471. {
  42472. jassert (newListener != 0)
  42473. if (newListener != 0)
  42474. listeners.add (newListener);
  42475. }
  42476. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  42477. {
  42478. listeners.removeValue (listenerToRemove);
  42479. }
  42480. void TextEditor::timerCallbackInt()
  42481. {
  42482. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  42483. if (caretFlashState != newState)
  42484. {
  42485. caretFlashState = newState;
  42486. if (caretFlashState)
  42487. wasFocused = true;
  42488. if (caretVisible
  42489. && hasKeyboardFocus (false)
  42490. && ! isReadOnly())
  42491. {
  42492. repaintCaret();
  42493. }
  42494. }
  42495. const unsigned int now = Time::getApproximateMillisecondCounter();
  42496. if (now > lastTransactionTime + 200)
  42497. newTransaction();
  42498. }
  42499. void TextEditor::repaintCaret()
  42500. {
  42501. if (! findColour (caretColourId).isTransparent())
  42502. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  42503. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  42504. 4,
  42505. roundToInt (cursorHeight) + 2);
  42506. }
  42507. void TextEditor::repaintText (const Range<int>& range)
  42508. {
  42509. if (! range.isEmpty())
  42510. {
  42511. float x = 0, y = 0, lh = currentFont.getHeight();
  42512. const float wordWrapWidth = getWordWrapWidth();
  42513. if (wordWrapWidth > 0)
  42514. {
  42515. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42516. i.getCharPosition (range.getStart(), x, y, lh);
  42517. const int y1 = (int) y;
  42518. int y2;
  42519. if (range.getEnd() >= getTotalNumChars())
  42520. {
  42521. y2 = getHeight();
  42522. }
  42523. else
  42524. {
  42525. i.getCharPosition (range.getEnd(), x, y, lh);
  42526. y2 = (int) (y + lh * 2.0f);
  42527. }
  42528. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  42529. }
  42530. }
  42531. }
  42532. void TextEditor::moveCaret (int newCaretPos)
  42533. {
  42534. if (newCaretPos < 0)
  42535. newCaretPos = 0;
  42536. else if (newCaretPos > getTotalNumChars())
  42537. newCaretPos = getTotalNumChars();
  42538. if (newCaretPos != getCaretPosition())
  42539. {
  42540. repaintCaret();
  42541. caretFlashState = true;
  42542. caretPosition = newCaretPos;
  42543. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42544. scrollToMakeSureCursorIsVisible();
  42545. repaintCaret();
  42546. }
  42547. }
  42548. void TextEditor::setCaretPosition (const int newIndex)
  42549. {
  42550. moveCursorTo (newIndex, false);
  42551. }
  42552. int TextEditor::getCaretPosition() const
  42553. {
  42554. return caretPosition;
  42555. }
  42556. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  42557. const int desiredCaretY)
  42558. {
  42559. updateCaretPosition();
  42560. int vx = roundToInt (cursorX) - desiredCaretX;
  42561. int vy = roundToInt (cursorY) - desiredCaretY;
  42562. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  42563. {
  42564. vx += desiredCaretX - proportionOfWidth (0.2f);
  42565. }
  42566. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42567. {
  42568. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42569. }
  42570. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  42571. if (! isMultiLine())
  42572. {
  42573. vy = viewport->getViewPositionY();
  42574. }
  42575. else
  42576. {
  42577. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  42578. const int curH = roundToInt (cursorHeight);
  42579. if (desiredCaretY < 0)
  42580. {
  42581. vy = jmax (0, desiredCaretY + vy);
  42582. }
  42583. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42584. {
  42585. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42586. }
  42587. }
  42588. viewport->setViewPosition (vx, vy);
  42589. }
  42590. const Rectangle<int> TextEditor::getCaretRectangle()
  42591. {
  42592. updateCaretPosition();
  42593. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  42594. roundToInt (cursorY) - viewport->getY(),
  42595. 1, roundToInt (cursorHeight));
  42596. }
  42597. float TextEditor::getWordWrapWidth() const
  42598. {
  42599. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  42600. : 1.0e10f;
  42601. }
  42602. void TextEditor::updateTextHolderSize()
  42603. {
  42604. const float wordWrapWidth = getWordWrapWidth();
  42605. if (wordWrapWidth > 0)
  42606. {
  42607. float maxWidth = 0.0f;
  42608. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42609. while (i.next())
  42610. maxWidth = jmax (maxWidth, i.atomRight);
  42611. const int w = leftIndent + roundToInt (maxWidth);
  42612. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  42613. currentFont.getHeight()));
  42614. textHolder->setSize (w + 1, h + 1);
  42615. }
  42616. }
  42617. int TextEditor::getTextWidth() const
  42618. {
  42619. return textHolder->getWidth();
  42620. }
  42621. int TextEditor::getTextHeight() const
  42622. {
  42623. return textHolder->getHeight();
  42624. }
  42625. void TextEditor::setIndents (const int newLeftIndent,
  42626. const int newTopIndent)
  42627. {
  42628. leftIndent = newLeftIndent;
  42629. topIndent = newTopIndent;
  42630. }
  42631. void TextEditor::setBorder (const BorderSize& border)
  42632. {
  42633. borderSize = border;
  42634. resized();
  42635. }
  42636. const BorderSize TextEditor::getBorder() const
  42637. {
  42638. return borderSize;
  42639. }
  42640. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42641. {
  42642. keepCursorOnScreen = shouldScrollToShowCursor;
  42643. }
  42644. void TextEditor::updateCaretPosition()
  42645. {
  42646. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42647. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42648. }
  42649. void TextEditor::scrollToMakeSureCursorIsVisible()
  42650. {
  42651. updateCaretPosition();
  42652. if (keepCursorOnScreen)
  42653. {
  42654. int x = viewport->getViewPositionX();
  42655. int y = viewport->getViewPositionY();
  42656. const int relativeCursorX = roundToInt (cursorX) - x;
  42657. const int relativeCursorY = roundToInt (cursorY) - y;
  42658. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42659. {
  42660. x += relativeCursorX - proportionOfWidth (0.2f);
  42661. }
  42662. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42663. {
  42664. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42665. }
  42666. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42667. if (! isMultiLine())
  42668. {
  42669. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42670. }
  42671. else
  42672. {
  42673. const int curH = roundToInt (cursorHeight);
  42674. if (relativeCursorY < 0)
  42675. {
  42676. y = jmax (0, relativeCursorY + y);
  42677. }
  42678. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42679. {
  42680. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42681. }
  42682. }
  42683. viewport->setViewPosition (x, y);
  42684. }
  42685. }
  42686. void TextEditor::moveCursorTo (const int newPosition,
  42687. const bool isSelecting)
  42688. {
  42689. if (isSelecting)
  42690. {
  42691. moveCaret (newPosition);
  42692. const Range<int> oldSelection (selection);
  42693. if (dragType == notDragging)
  42694. {
  42695. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42696. dragType = draggingSelectionStart;
  42697. else
  42698. dragType = draggingSelectionEnd;
  42699. }
  42700. if (dragType == draggingSelectionStart)
  42701. {
  42702. if (getCaretPosition() >= selection.getEnd())
  42703. dragType = draggingSelectionEnd;
  42704. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42705. }
  42706. else
  42707. {
  42708. if (getCaretPosition() < selection.getStart())
  42709. dragType = draggingSelectionStart;
  42710. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42711. }
  42712. repaintText (selection.getUnionWith (oldSelection));
  42713. }
  42714. else
  42715. {
  42716. dragType = notDragging;
  42717. repaintText (selection);
  42718. moveCaret (newPosition);
  42719. selection = Range<int>::emptyRange (getCaretPosition());
  42720. }
  42721. }
  42722. int TextEditor::getTextIndexAt (const int x,
  42723. const int y)
  42724. {
  42725. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42726. (float) (y + viewport->getViewPositionY() - topIndent));
  42727. }
  42728. void TextEditor::insertTextAtCaret (const String& newText_)
  42729. {
  42730. String newText (newText_);
  42731. if (allowedCharacters.isNotEmpty())
  42732. newText = newText.retainCharacters (allowedCharacters);
  42733. if (! isMultiLine())
  42734. newText = newText.replaceCharacters (T("\r\n"), T(" "));
  42735. else
  42736. newText = newText.replace (T("\r\n"), T("\n"));
  42737. const int newCaretPos = selection.getStart() + newText.length();
  42738. const int insertIndex = selection.getStart();
  42739. remove (selection, &undoManager,
  42740. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42741. if (maxTextLength > 0)
  42742. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42743. if (newText.isNotEmpty())
  42744. insert (newText,
  42745. insertIndex,
  42746. currentFont,
  42747. findColour (textColourId),
  42748. &undoManager,
  42749. newCaretPos);
  42750. textChanged();
  42751. }
  42752. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42753. {
  42754. moveCursorTo (newSelection.getStart(), false);
  42755. moveCursorTo (newSelection.getEnd(), true);
  42756. }
  42757. void TextEditor::copy()
  42758. {
  42759. if (passwordCharacter == 0)
  42760. {
  42761. const String selection (getHighlightedText());
  42762. if (selection.isNotEmpty())
  42763. SystemClipboard::copyTextToClipboard (selection);
  42764. }
  42765. }
  42766. void TextEditor::paste()
  42767. {
  42768. if (! isReadOnly())
  42769. {
  42770. const String clip (SystemClipboard::getTextFromClipboard());
  42771. if (clip.isNotEmpty())
  42772. insertTextAtCaret (clip);
  42773. }
  42774. }
  42775. void TextEditor::cut()
  42776. {
  42777. if (! isReadOnly())
  42778. {
  42779. moveCaret (selection.getEnd());
  42780. insertTextAtCaret (String::empty);
  42781. }
  42782. }
  42783. void TextEditor::drawContent (Graphics& g)
  42784. {
  42785. const float wordWrapWidth = getWordWrapWidth();
  42786. if (wordWrapWidth > 0)
  42787. {
  42788. g.setOrigin (leftIndent, topIndent);
  42789. const Rectangle<int> clip (g.getClipBounds());
  42790. Colour selectedTextColour;
  42791. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42792. while (i.lineY + 200.0 < clip.getY() && i.next())
  42793. {}
  42794. if (! selection.isEmpty())
  42795. {
  42796. g.setColour (findColour (highlightColourId)
  42797. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42798. selectedTextColour = findColour (highlightedTextColourId);
  42799. TextEditorIterator i2 (i);
  42800. while (i2.next() && i2.lineY < clip.getBottom())
  42801. {
  42802. if (i2.lineY + i2.lineHeight >= clip.getY()
  42803. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42804. {
  42805. i2.drawSelection (g, selection);
  42806. }
  42807. }
  42808. }
  42809. const UniformTextSection* lastSection = 0;
  42810. while (i.next() && i.lineY < clip.getBottom())
  42811. {
  42812. if (i.lineY + i.lineHeight >= clip.getY())
  42813. {
  42814. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42815. {
  42816. i.drawSelectedText (g, selection, selectedTextColour);
  42817. lastSection = 0;
  42818. }
  42819. else
  42820. {
  42821. i.draw (g, lastSection);
  42822. }
  42823. }
  42824. }
  42825. }
  42826. }
  42827. void TextEditor::paint (Graphics& g)
  42828. {
  42829. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42830. }
  42831. void TextEditor::paintOverChildren (Graphics& g)
  42832. {
  42833. if (caretFlashState
  42834. && hasKeyboardFocus (false)
  42835. && caretVisible
  42836. && ! isReadOnly())
  42837. {
  42838. g.setColour (findColour (caretColourId));
  42839. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42840. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42841. 2.0f, cursorHeight);
  42842. }
  42843. if (textToShowWhenEmpty.isNotEmpty()
  42844. && (! hasKeyboardFocus (false))
  42845. && getTotalNumChars() == 0)
  42846. {
  42847. g.setColour (colourForTextWhenEmpty);
  42848. g.setFont (getFont());
  42849. if (isMultiLine())
  42850. {
  42851. g.drawText (textToShowWhenEmpty,
  42852. 0, 0, getWidth(), getHeight(),
  42853. Justification::centred, true);
  42854. }
  42855. else
  42856. {
  42857. g.drawText (textToShowWhenEmpty,
  42858. leftIndent, topIndent,
  42859. viewport->getWidth() - leftIndent,
  42860. viewport->getHeight() - topIndent,
  42861. Justification::centredLeft, true);
  42862. }
  42863. }
  42864. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42865. }
  42866. void TextEditor::mouseDown (const MouseEvent& e)
  42867. {
  42868. beginDragAutoRepeat (100);
  42869. newTransaction();
  42870. if (wasFocused || ! selectAllTextWhenFocused)
  42871. {
  42872. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42873. {
  42874. moveCursorTo (getTextIndexAt (e.x, e.y),
  42875. e.mods.isShiftDown());
  42876. }
  42877. else
  42878. {
  42879. PopupMenu m;
  42880. m.setLookAndFeel (&getLookAndFeel());
  42881. addPopupMenuItems (m, &e);
  42882. menuActive = true;
  42883. const int result = m.show();
  42884. menuActive = false;
  42885. if (result != 0)
  42886. performPopupMenuAction (result);
  42887. }
  42888. }
  42889. }
  42890. void TextEditor::mouseDrag (const MouseEvent& e)
  42891. {
  42892. if (wasFocused || ! selectAllTextWhenFocused)
  42893. {
  42894. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42895. {
  42896. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42897. }
  42898. }
  42899. }
  42900. void TextEditor::mouseUp (const MouseEvent& e)
  42901. {
  42902. newTransaction();
  42903. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42904. if (wasFocused || ! selectAllTextWhenFocused)
  42905. {
  42906. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42907. {
  42908. moveCaret (getTextIndexAt (e.x, e.y));
  42909. }
  42910. }
  42911. wasFocused = true;
  42912. }
  42913. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42914. {
  42915. int tokenEnd = getTextIndexAt (e.x, e.y);
  42916. int tokenStart = tokenEnd;
  42917. if (e.getNumberOfClicks() > 3)
  42918. {
  42919. tokenStart = 0;
  42920. tokenEnd = getTotalNumChars();
  42921. }
  42922. else
  42923. {
  42924. const String t (getText());
  42925. const int totalLength = getTotalNumChars();
  42926. while (tokenEnd < totalLength)
  42927. {
  42928. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42929. ++tokenEnd;
  42930. else
  42931. break;
  42932. }
  42933. tokenStart = tokenEnd;
  42934. while (tokenStart > 0)
  42935. {
  42936. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42937. --tokenStart;
  42938. else
  42939. break;
  42940. }
  42941. if (e.getNumberOfClicks() > 2)
  42942. {
  42943. while (tokenEnd < totalLength)
  42944. {
  42945. if (t [tokenEnd] != T('\r') && t [tokenEnd] != T('\n'))
  42946. ++tokenEnd;
  42947. else
  42948. break;
  42949. }
  42950. while (tokenStart > 0)
  42951. {
  42952. if (t [tokenStart - 1] != T('\r') && t [tokenStart - 1] != T('\n'))
  42953. --tokenStart;
  42954. else
  42955. break;
  42956. }
  42957. }
  42958. }
  42959. moveCursorTo (tokenEnd, false);
  42960. moveCursorTo (tokenStart, true);
  42961. }
  42962. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42963. {
  42964. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42965. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42966. }
  42967. bool TextEditor::keyPressed (const KeyPress& key)
  42968. {
  42969. if (isReadOnly() && key != KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  42970. return false;
  42971. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42972. if (key.isKeyCode (KeyPress::leftKey)
  42973. || key.isKeyCode (KeyPress::upKey))
  42974. {
  42975. newTransaction();
  42976. int newPos;
  42977. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42978. newPos = indexAtPosition (cursorX, cursorY - 1);
  42979. else if (moveInWholeWordSteps)
  42980. newPos = findWordBreakBefore (getCaretPosition());
  42981. else
  42982. newPos = getCaretPosition() - 1;
  42983. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42984. }
  42985. else if (key.isKeyCode (KeyPress::rightKey)
  42986. || key.isKeyCode (KeyPress::downKey))
  42987. {
  42988. newTransaction();
  42989. int newPos;
  42990. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42991. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42992. else if (moveInWholeWordSteps)
  42993. newPos = findWordBreakAfter (getCaretPosition());
  42994. else
  42995. newPos = getCaretPosition() + 1;
  42996. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42997. }
  42998. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42999. {
  43000. newTransaction();
  43001. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  43002. key.getModifiers().isShiftDown());
  43003. }
  43004. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  43005. {
  43006. newTransaction();
  43007. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  43008. key.getModifiers().isShiftDown());
  43009. }
  43010. else if (key.isKeyCode (KeyPress::homeKey))
  43011. {
  43012. newTransaction();
  43013. if (isMultiLine() && ! moveInWholeWordSteps)
  43014. moveCursorTo (indexAtPosition (0.0f, cursorY),
  43015. key.getModifiers().isShiftDown());
  43016. else
  43017. moveCursorTo (0, key.getModifiers().isShiftDown());
  43018. }
  43019. else if (key.isKeyCode (KeyPress::endKey))
  43020. {
  43021. newTransaction();
  43022. if (isMultiLine() && ! moveInWholeWordSteps)
  43023. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  43024. key.getModifiers().isShiftDown());
  43025. else
  43026. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  43027. }
  43028. else if (key.isKeyCode (KeyPress::backspaceKey))
  43029. {
  43030. if (moveInWholeWordSteps)
  43031. {
  43032. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  43033. }
  43034. else
  43035. {
  43036. if (selection.isEmpty() && selection.getStart() > 0)
  43037. selection.setStart (selection.getEnd() - 1);
  43038. }
  43039. cut();
  43040. }
  43041. else if (key.isKeyCode (KeyPress::deleteKey))
  43042. {
  43043. if (key.getModifiers().isShiftDown())
  43044. copy();
  43045. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  43046. selection.setEnd (selection.getStart() + 1);
  43047. cut();
  43048. }
  43049. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0)
  43050. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  43051. {
  43052. newTransaction();
  43053. copy();
  43054. }
  43055. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  43056. {
  43057. newTransaction();
  43058. copy();
  43059. cut();
  43060. }
  43061. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0)
  43062. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  43063. {
  43064. newTransaction();
  43065. paste();
  43066. }
  43067. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  43068. {
  43069. newTransaction();
  43070. doUndoRedo (false);
  43071. }
  43072. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0))
  43073. {
  43074. newTransaction();
  43075. doUndoRedo (true);
  43076. }
  43077. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  43078. {
  43079. newTransaction();
  43080. moveCursorTo (getTotalNumChars(), false);
  43081. moveCursorTo (0, true);
  43082. }
  43083. else if (key == KeyPress::returnKey)
  43084. {
  43085. newTransaction();
  43086. if (returnKeyStartsNewLine)
  43087. insertTextAtCaret (T("\n"));
  43088. else
  43089. returnPressed();
  43090. }
  43091. else if (key.isKeyCode (KeyPress::escapeKey))
  43092. {
  43093. newTransaction();
  43094. moveCursorTo (getCaretPosition(), false);
  43095. escapePressed();
  43096. }
  43097. else if (key.getTextCharacter() >= ' '
  43098. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  43099. {
  43100. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  43101. lastTransactionTime = Time::getApproximateMillisecondCounter();
  43102. }
  43103. else
  43104. {
  43105. return false;
  43106. }
  43107. return true;
  43108. }
  43109. bool TextEditor::keyStateChanged (const bool isKeyDown)
  43110. {
  43111. if (! isKeyDown)
  43112. return false;
  43113. #if JUCE_WIN32
  43114. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  43115. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  43116. #endif
  43117. // (overridden to avoid forwarding key events to the parent)
  43118. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  43119. }
  43120. const int baseMenuItemID = 0x7fff0000;
  43121. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  43122. {
  43123. const bool writable = ! isReadOnly();
  43124. if (passwordCharacter == 0)
  43125. {
  43126. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  43127. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  43128. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  43129. }
  43130. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  43131. m.addSeparator();
  43132. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  43133. m.addSeparator();
  43134. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  43135. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  43136. }
  43137. void TextEditor::performPopupMenuAction (const int menuItemID)
  43138. {
  43139. switch (menuItemID)
  43140. {
  43141. case baseMenuItemID + 1:
  43142. copy();
  43143. cut();
  43144. break;
  43145. case baseMenuItemID + 2:
  43146. copy();
  43147. break;
  43148. case baseMenuItemID + 3:
  43149. paste();
  43150. break;
  43151. case baseMenuItemID + 4:
  43152. cut();
  43153. break;
  43154. case baseMenuItemID + 5:
  43155. moveCursorTo (getTotalNumChars(), false);
  43156. moveCursorTo (0, true);
  43157. break;
  43158. case baseMenuItemID + 6:
  43159. doUndoRedo (false);
  43160. break;
  43161. case baseMenuItemID + 7:
  43162. doUndoRedo (true);
  43163. break;
  43164. default:
  43165. break;
  43166. }
  43167. }
  43168. void TextEditor::focusGained (FocusChangeType)
  43169. {
  43170. newTransaction();
  43171. caretFlashState = true;
  43172. if (selectAllTextWhenFocused)
  43173. {
  43174. moveCursorTo (0, false);
  43175. moveCursorTo (getTotalNumChars(), true);
  43176. }
  43177. repaint();
  43178. if (caretVisible)
  43179. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  43180. ComponentPeer* const peer = getPeer();
  43181. if (peer != 0 && ! isReadOnly())
  43182. peer->textInputRequired (getScreenX() - peer->getScreenX(),
  43183. getScreenY() - peer->getScreenY());
  43184. }
  43185. void TextEditor::focusLost (FocusChangeType)
  43186. {
  43187. newTransaction();
  43188. wasFocused = false;
  43189. textHolder->stopTimer();
  43190. caretFlashState = false;
  43191. postCommandMessage (TextEditorDefs::focusLossMessageId);
  43192. repaint();
  43193. }
  43194. void TextEditor::resized()
  43195. {
  43196. viewport->setBoundsInset (borderSize);
  43197. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  43198. updateTextHolderSize();
  43199. if (! isMultiLine())
  43200. {
  43201. scrollToMakeSureCursorIsVisible();
  43202. }
  43203. else
  43204. {
  43205. updateCaretPosition();
  43206. }
  43207. }
  43208. void TextEditor::handleCommandMessage (const int commandId)
  43209. {
  43210. const ComponentDeletionWatcher deletionChecker (this);
  43211. for (int i = listeners.size(); --i >= 0;)
  43212. {
  43213. TextEditorListener* const tl = (TextEditorListener*) listeners [i];
  43214. if (tl != 0)
  43215. {
  43216. switch (commandId)
  43217. {
  43218. case TextEditorDefs::textChangeMessageId:
  43219. tl->textEditorTextChanged (*this);
  43220. break;
  43221. case TextEditorDefs::returnKeyMessageId:
  43222. tl->textEditorReturnKeyPressed (*this);
  43223. break;
  43224. case TextEditorDefs::escapeKeyMessageId:
  43225. tl->textEditorEscapeKeyPressed (*this);
  43226. break;
  43227. case TextEditorDefs::focusLossMessageId:
  43228. tl->textEditorFocusLost (*this);
  43229. break;
  43230. default:
  43231. jassertfalse
  43232. break;
  43233. }
  43234. if (i > 0 && deletionChecker.hasBeenDeleted())
  43235. return;
  43236. }
  43237. }
  43238. }
  43239. void TextEditor::enablementChanged()
  43240. {
  43241. setMouseCursor (MouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  43242. : MouseCursor::IBeamCursor));
  43243. repaint();
  43244. }
  43245. void TextEditor::clearInternal (UndoManager* const um)
  43246. {
  43247. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  43248. }
  43249. void TextEditor::insert (const String& text,
  43250. const int insertIndex,
  43251. const Font& font,
  43252. const Colour& colour,
  43253. UndoManager* const um,
  43254. const int caretPositionToMoveTo)
  43255. {
  43256. if (text.isNotEmpty())
  43257. {
  43258. if (um != 0)
  43259. {
  43260. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43261. newTransaction();
  43262. um->perform (new TextEditorInsertAction (*this,
  43263. text,
  43264. insertIndex,
  43265. font,
  43266. colour,
  43267. caretPosition,
  43268. caretPositionToMoveTo));
  43269. }
  43270. else
  43271. {
  43272. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  43273. // a line gets moved due to word wrap
  43274. int index = 0;
  43275. int nextIndex = 0;
  43276. for (int i = 0; i < sections.size(); ++i)
  43277. {
  43278. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43279. if (insertIndex == index)
  43280. {
  43281. sections.insert (i, new UniformTextSection (text,
  43282. font, colour,
  43283. passwordCharacter));
  43284. break;
  43285. }
  43286. else if (insertIndex > index && insertIndex < nextIndex)
  43287. {
  43288. splitSection (i, insertIndex - index);
  43289. sections.insert (i + 1, new UniformTextSection (text,
  43290. font, colour,
  43291. passwordCharacter));
  43292. break;
  43293. }
  43294. index = nextIndex;
  43295. }
  43296. if (nextIndex == insertIndex)
  43297. sections.add (new UniformTextSection (text,
  43298. font, colour,
  43299. passwordCharacter));
  43300. coalesceSimilarSections();
  43301. totalNumChars = -1;
  43302. valueTextNeedsUpdating = true;
  43303. moveCursorTo (caretPositionToMoveTo, false);
  43304. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  43305. }
  43306. }
  43307. }
  43308. void TextEditor::reinsert (const int insertIndex,
  43309. const VoidArray& sectionsToInsert)
  43310. {
  43311. int index = 0;
  43312. int nextIndex = 0;
  43313. for (int i = 0; i < sections.size(); ++i)
  43314. {
  43315. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43316. if (insertIndex == index)
  43317. {
  43318. for (int j = sectionsToInsert.size(); --j >= 0;)
  43319. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43320. break;
  43321. }
  43322. else if (insertIndex > index && insertIndex < nextIndex)
  43323. {
  43324. splitSection (i, insertIndex - index);
  43325. for (int j = sectionsToInsert.size(); --j >= 0;)
  43326. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43327. break;
  43328. }
  43329. index = nextIndex;
  43330. }
  43331. if (nextIndex == insertIndex)
  43332. {
  43333. for (int j = 0; j < sectionsToInsert.size(); ++j)
  43334. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43335. }
  43336. coalesceSimilarSections();
  43337. totalNumChars = -1;
  43338. valueTextNeedsUpdating = true;
  43339. }
  43340. void TextEditor::remove (const Range<int>& range,
  43341. UndoManager* const um,
  43342. const int caretPositionToMoveTo)
  43343. {
  43344. if (! range.isEmpty())
  43345. {
  43346. int index = 0;
  43347. for (int i = 0; i < sections.size(); ++i)
  43348. {
  43349. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  43350. if (range.getStart() > index && range.getStart() < nextIndex)
  43351. {
  43352. splitSection (i, range.getStart() - index);
  43353. --i;
  43354. }
  43355. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  43356. {
  43357. splitSection (i, range.getEnd() - index);
  43358. --i;
  43359. }
  43360. else
  43361. {
  43362. index = nextIndex;
  43363. if (index > range.getEnd())
  43364. break;
  43365. }
  43366. }
  43367. index = 0;
  43368. if (um != 0)
  43369. {
  43370. VoidArray removedSections;
  43371. for (int i = 0; i < sections.size(); ++i)
  43372. {
  43373. if (range.getEnd() <= range.getStart())
  43374. break;
  43375. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43376. const int nextIndex = index + section->getTotalLength();
  43377. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  43378. removedSections.add (new UniformTextSection (*section));
  43379. index = nextIndex;
  43380. }
  43381. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43382. newTransaction();
  43383. um->perform (new TextEditorRemoveAction (*this,
  43384. range,
  43385. caretPosition,
  43386. caretPositionToMoveTo,
  43387. removedSections));
  43388. }
  43389. else
  43390. {
  43391. Range<int> remainingRange (range);
  43392. for (int i = 0; i < sections.size(); ++i)
  43393. {
  43394. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43395. const int nextIndex = index + section->getTotalLength();
  43396. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  43397. {
  43398. sections.remove(i);
  43399. section->clear();
  43400. delete section;
  43401. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  43402. if (remainingRange.isEmpty())
  43403. break;
  43404. --i;
  43405. }
  43406. else
  43407. {
  43408. index = nextIndex;
  43409. }
  43410. }
  43411. coalesceSimilarSections();
  43412. totalNumChars = -1;
  43413. valueTextNeedsUpdating = true;
  43414. moveCursorTo (caretPositionToMoveTo, false);
  43415. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  43416. }
  43417. }
  43418. }
  43419. const String TextEditor::getText() const
  43420. {
  43421. String t;
  43422. t.preallocateStorage (getTotalNumChars());
  43423. String::Concatenator concatenator (t);
  43424. for (int i = 0; i < sections.size(); ++i)
  43425. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  43426. return t;
  43427. }
  43428. const String TextEditor::getTextInRange (const Range<int>& range) const
  43429. {
  43430. String t;
  43431. if (! range.isEmpty())
  43432. {
  43433. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  43434. String::Concatenator concatenator (t);
  43435. int index = 0;
  43436. for (int i = 0; i < sections.size(); ++i)
  43437. {
  43438. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  43439. const int nextIndex = index + s->getTotalLength();
  43440. if (range.getStart() < nextIndex)
  43441. {
  43442. if (range.getEnd() <= index)
  43443. break;
  43444. s->appendSubstring (concatenator, range - index);
  43445. }
  43446. index = nextIndex;
  43447. }
  43448. }
  43449. return t;
  43450. }
  43451. const String TextEditor::getHighlightedText() const
  43452. {
  43453. return getTextInRange (selection);
  43454. }
  43455. int TextEditor::getTotalNumChars() const
  43456. {
  43457. if (totalNumChars < 0)
  43458. {
  43459. totalNumChars = 0;
  43460. for (int i = sections.size(); --i >= 0;)
  43461. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43462. }
  43463. return totalNumChars;
  43464. }
  43465. bool TextEditor::isEmpty() const
  43466. {
  43467. return getTotalNumChars() == 0;
  43468. }
  43469. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  43470. {
  43471. const float wordWrapWidth = getWordWrapWidth();
  43472. if (wordWrapWidth > 0 && sections.size() > 0)
  43473. {
  43474. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43475. i.getCharPosition (index, cx, cy, lineHeight);
  43476. }
  43477. else
  43478. {
  43479. cx = cy = 0;
  43480. lineHeight = currentFont.getHeight();
  43481. }
  43482. }
  43483. int TextEditor::indexAtPosition (const float x, const float y)
  43484. {
  43485. const float wordWrapWidth = getWordWrapWidth();
  43486. if (wordWrapWidth > 0)
  43487. {
  43488. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43489. while (i.next())
  43490. {
  43491. if (i.lineY + i.lineHeight > y)
  43492. {
  43493. if (i.lineY > y)
  43494. return jmax (0, i.indexInText - 1);
  43495. if (i.atomX >= x)
  43496. return i.indexInText;
  43497. if (x < i.atomRight)
  43498. return i.xToIndex (x);
  43499. }
  43500. }
  43501. }
  43502. return getTotalNumChars();
  43503. }
  43504. static int getCharacterCategory (const tchar character)
  43505. {
  43506. return CharacterFunctions::isLetterOrDigit (character)
  43507. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  43508. }
  43509. int TextEditor::findWordBreakAfter (const int position) const
  43510. {
  43511. const String t (getTextInRange (Range<int> (position, position + 512)));
  43512. const int totalLength = t.length();
  43513. int i = 0;
  43514. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43515. ++i;
  43516. const int type = getCharacterCategory (t[i]);
  43517. while (i < totalLength && type == getCharacterCategory (t[i]))
  43518. ++i;
  43519. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43520. ++i;
  43521. return position + i;
  43522. }
  43523. int TextEditor::findWordBreakBefore (const int position) const
  43524. {
  43525. if (position <= 0)
  43526. return 0;
  43527. const int startOfBuffer = jmax (0, position - 512);
  43528. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  43529. int i = position - startOfBuffer;
  43530. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  43531. --i;
  43532. if (i > 0)
  43533. {
  43534. const int type = getCharacterCategory (t [i - 1]);
  43535. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  43536. --i;
  43537. }
  43538. jassert (startOfBuffer + i >= 0);
  43539. return startOfBuffer + i;
  43540. }
  43541. void TextEditor::splitSection (const int sectionIndex,
  43542. const int charToSplitAt)
  43543. {
  43544. jassert (sections[sectionIndex] != 0);
  43545. sections.insert (sectionIndex + 1,
  43546. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  43547. ->split (charToSplitAt, passwordCharacter));
  43548. }
  43549. void TextEditor::coalesceSimilarSections()
  43550. {
  43551. for (int i = 0; i < sections.size() - 1; ++i)
  43552. {
  43553. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  43554. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  43555. if (s1->font == s2->font
  43556. && s1->colour == s2->colour)
  43557. {
  43558. s1->append (*s2, passwordCharacter);
  43559. sections.remove (i + 1);
  43560. delete s2;
  43561. --i;
  43562. }
  43563. }
  43564. }
  43565. END_JUCE_NAMESPACE
  43566. /*** End of inlined file: juce_TextEditor.cpp ***/
  43567. /*** Start of inlined file: juce_Toolbar.cpp ***/
  43568. BEGIN_JUCE_NAMESPACE
  43569. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  43570. class ToolbarSpacerComp : public ToolbarItemComponent
  43571. {
  43572. public:
  43573. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  43574. : ToolbarItemComponent (itemId_, String::empty, false),
  43575. fixedSize (fixedSize_),
  43576. drawBar (drawBar_)
  43577. {
  43578. }
  43579. ~ToolbarSpacerComp()
  43580. {
  43581. }
  43582. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  43583. int& preferredSize, int& minSize, int& maxSize)
  43584. {
  43585. if (fixedSize <= 0)
  43586. {
  43587. preferredSize = toolbarThickness * 2;
  43588. minSize = 4;
  43589. maxSize = 32768;
  43590. }
  43591. else
  43592. {
  43593. maxSize = roundToInt (toolbarThickness * fixedSize);
  43594. minSize = drawBar ? maxSize : jmin (4, maxSize);
  43595. preferredSize = maxSize;
  43596. if (getEditingMode() == editableOnPalette)
  43597. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  43598. }
  43599. return true;
  43600. }
  43601. void paintButtonArea (Graphics&, int, int, bool, bool)
  43602. {
  43603. }
  43604. void contentAreaChanged (const Rectangle<int>&)
  43605. {
  43606. }
  43607. int getResizeOrder() const throw()
  43608. {
  43609. return fixedSize <= 0 ? 0 : 1;
  43610. }
  43611. void paint (Graphics& g)
  43612. {
  43613. const int w = getWidth();
  43614. const int h = getHeight();
  43615. if (drawBar)
  43616. {
  43617. g.setColour (findColour (Toolbar::separatorColourId, true));
  43618. const float thickness = 0.2f;
  43619. if (isToolbarVertical())
  43620. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43621. else
  43622. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43623. }
  43624. if (getEditingMode() != normalMode && ! drawBar)
  43625. {
  43626. g.setColour (findColour (Toolbar::separatorColourId, true));
  43627. const int indentX = jmin (2, (w - 3) / 2);
  43628. const int indentY = jmin (2, (h - 3) / 2);
  43629. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43630. if (fixedSize <= 0)
  43631. {
  43632. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43633. if (isToolbarVertical())
  43634. {
  43635. x1 = w * 0.5f;
  43636. y1 = h * 0.4f;
  43637. x2 = x1;
  43638. y2 = indentX * 2.0f;
  43639. x3 = x1;
  43640. y3 = h * 0.6f;
  43641. x4 = x1;
  43642. y4 = h - y2;
  43643. hw = w * 0.15f;
  43644. hl = w * 0.2f;
  43645. }
  43646. else
  43647. {
  43648. x1 = w * 0.4f;
  43649. y1 = h * 0.5f;
  43650. x2 = indentX * 2.0f;
  43651. y2 = y1;
  43652. x3 = w * 0.6f;
  43653. y3 = y1;
  43654. x4 = w - x2;
  43655. y4 = y1;
  43656. hw = h * 0.15f;
  43657. hl = h * 0.2f;
  43658. }
  43659. Path p;
  43660. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43661. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43662. g.fillPath (p);
  43663. }
  43664. }
  43665. }
  43666. juce_UseDebuggingNewOperator
  43667. private:
  43668. const float fixedSize;
  43669. const bool drawBar;
  43670. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43671. const ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43672. };
  43673. class MissingItemsComponent : public PopupMenuCustomComponent
  43674. {
  43675. public:
  43676. MissingItemsComponent (Toolbar& owner_, const int height_)
  43677. : PopupMenuCustomComponent (true),
  43678. owner (owner_),
  43679. height (height_)
  43680. {
  43681. for (int i = owner_.items.size(); --i >= 0;)
  43682. {
  43683. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43684. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43685. {
  43686. oldIndexes.insert (0, i);
  43687. addAndMakeVisible (tc, 0);
  43688. }
  43689. }
  43690. layout (400);
  43691. }
  43692. ~MissingItemsComponent()
  43693. {
  43694. // deleting the toolbar while its menu it open??
  43695. jassert (owner.isValidComponent());
  43696. for (int i = 0; i < getNumChildComponents(); ++i)
  43697. {
  43698. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43699. if (tc != 0)
  43700. {
  43701. tc->setVisible (false);
  43702. const int index = oldIndexes.remove (i);
  43703. owner.addChildComponent (tc, index);
  43704. --i;
  43705. }
  43706. }
  43707. owner.resized();
  43708. }
  43709. void layout (const int preferredWidth)
  43710. {
  43711. const int indent = 8;
  43712. int x = indent;
  43713. int y = indent;
  43714. int maxX = 0;
  43715. for (int i = 0; i < getNumChildComponents(); ++i)
  43716. {
  43717. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43718. if (tc != 0)
  43719. {
  43720. int preferredSize = 1, minSize = 1, maxSize = 1;
  43721. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43722. {
  43723. if (x + preferredSize > preferredWidth && x > indent)
  43724. {
  43725. x = indent;
  43726. y += height;
  43727. }
  43728. tc->setBounds (x, y, preferredSize, height);
  43729. x += preferredSize;
  43730. maxX = jmax (maxX, x);
  43731. }
  43732. }
  43733. }
  43734. setSize (maxX + 8, y + height + 8);
  43735. }
  43736. void getIdealSize (int& idealWidth, int& idealHeight)
  43737. {
  43738. idealWidth = getWidth();
  43739. idealHeight = getHeight();
  43740. }
  43741. juce_UseDebuggingNewOperator
  43742. private:
  43743. Toolbar& owner;
  43744. const int height;
  43745. Array <int> oldIndexes;
  43746. MissingItemsComponent (const MissingItemsComponent&);
  43747. const MissingItemsComponent& operator= (const MissingItemsComponent&);
  43748. };
  43749. Toolbar::Toolbar()
  43750. : vertical (false),
  43751. isEditingActive (false),
  43752. toolbarStyle (Toolbar::iconsOnly)
  43753. {
  43754. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43755. missingItemsButton->setAlwaysOnTop (true);
  43756. missingItemsButton->addButtonListener (this);
  43757. }
  43758. Toolbar::~Toolbar()
  43759. {
  43760. animator.cancelAllAnimations (true);
  43761. deleteAllChildren();
  43762. }
  43763. void Toolbar::setVertical (const bool shouldBeVertical)
  43764. {
  43765. if (vertical != shouldBeVertical)
  43766. {
  43767. vertical = shouldBeVertical;
  43768. resized();
  43769. }
  43770. }
  43771. void Toolbar::clear()
  43772. {
  43773. for (int i = items.size(); --i >= 0;)
  43774. {
  43775. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43776. items.remove (i);
  43777. delete tc;
  43778. }
  43779. resized();
  43780. }
  43781. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43782. {
  43783. if (itemId == ToolbarItemFactory::separatorBarId)
  43784. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43785. else if (itemId == ToolbarItemFactory::spacerId)
  43786. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43787. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43788. return new ToolbarSpacerComp (itemId, 0, false);
  43789. return factory.createItem (itemId);
  43790. }
  43791. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43792. const int itemId,
  43793. const int insertIndex)
  43794. {
  43795. // An ID can't be zero - this might indicate a mistake somewhere?
  43796. jassert (itemId != 0);
  43797. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43798. if (tc != 0)
  43799. {
  43800. #ifdef JUCE_DEBUG
  43801. Array <int> allowedIds;
  43802. factory.getAllToolbarItemIds (allowedIds);
  43803. // If your factory can create an item for a given ID, it must also return
  43804. // that ID from its getAllToolbarItemIds() method!
  43805. jassert (allowedIds.contains (itemId));
  43806. #endif
  43807. items.insert (insertIndex, tc);
  43808. addAndMakeVisible (tc, insertIndex);
  43809. }
  43810. }
  43811. void Toolbar::addItem (ToolbarItemFactory& factory,
  43812. const int itemId,
  43813. const int insertIndex)
  43814. {
  43815. addItemInternal (factory, itemId, insertIndex);
  43816. resized();
  43817. }
  43818. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43819. {
  43820. Array <int> ids;
  43821. factoryToUse.getDefaultItemSet (ids);
  43822. clear();
  43823. for (int i = 0; i < ids.size(); ++i)
  43824. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43825. resized();
  43826. }
  43827. void Toolbar::removeToolbarItem (const int itemIndex)
  43828. {
  43829. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43830. if (tc != 0)
  43831. {
  43832. items.removeValue (tc);
  43833. delete tc;
  43834. resized();
  43835. }
  43836. }
  43837. int Toolbar::getNumItems() const throw()
  43838. {
  43839. return items.size();
  43840. }
  43841. int Toolbar::getItemId (const int itemIndex) const throw()
  43842. {
  43843. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43844. return tc != 0 ? tc->getItemId() : 0;
  43845. }
  43846. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43847. {
  43848. return items [itemIndex];
  43849. }
  43850. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43851. {
  43852. for (;;)
  43853. {
  43854. index += delta;
  43855. ToolbarItemComponent* const tc = getItemComponent (index);
  43856. if (tc == 0)
  43857. break;
  43858. if (tc->isActive)
  43859. return tc;
  43860. }
  43861. return 0;
  43862. }
  43863. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43864. {
  43865. if (toolbarStyle != newStyle)
  43866. {
  43867. toolbarStyle = newStyle;
  43868. updateAllItemPositions (false);
  43869. }
  43870. }
  43871. const String Toolbar::toString() const
  43872. {
  43873. String s (T("TB:"));
  43874. for (int i = 0; i < getNumItems(); ++i)
  43875. s << getItemId(i) << T(' ');
  43876. return s.trimEnd();
  43877. }
  43878. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43879. const String& savedVersion)
  43880. {
  43881. if (! savedVersion.startsWith (T("TB:")))
  43882. return false;
  43883. StringArray tokens;
  43884. tokens.addTokens (savedVersion.substring (3), false);
  43885. clear();
  43886. for (int i = 0; i < tokens.size(); ++i)
  43887. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43888. resized();
  43889. return true;
  43890. }
  43891. void Toolbar::paint (Graphics& g)
  43892. {
  43893. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43894. }
  43895. int Toolbar::getThickness() const throw()
  43896. {
  43897. return vertical ? getWidth() : getHeight();
  43898. }
  43899. int Toolbar::getLength() const throw()
  43900. {
  43901. return vertical ? getHeight() : getWidth();
  43902. }
  43903. void Toolbar::setEditingActive (const bool active)
  43904. {
  43905. if (isEditingActive != active)
  43906. {
  43907. isEditingActive = active;
  43908. updateAllItemPositions (false);
  43909. }
  43910. }
  43911. void Toolbar::resized()
  43912. {
  43913. updateAllItemPositions (false);
  43914. }
  43915. void Toolbar::updateAllItemPositions (const bool animate)
  43916. {
  43917. if (getWidth() > 0 && getHeight() > 0)
  43918. {
  43919. StretchableObjectResizer resizer;
  43920. int i;
  43921. for (i = 0; i < items.size(); ++i)
  43922. {
  43923. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43924. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43925. : ToolbarItemComponent::normalMode);
  43926. tc->setStyle (toolbarStyle);
  43927. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43928. int preferredSize = 1, minSize = 1, maxSize = 1;
  43929. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43930. preferredSize, minSize, maxSize))
  43931. {
  43932. tc->isActive = true;
  43933. resizer.addItem (preferredSize, minSize, maxSize,
  43934. spacer != 0 ? spacer->getResizeOrder() : 2);
  43935. }
  43936. else
  43937. {
  43938. tc->isActive = false;
  43939. tc->setVisible (false);
  43940. }
  43941. }
  43942. resizer.resizeToFit (getLength());
  43943. int totalLength = 0;
  43944. for (i = 0; i < resizer.getNumItems(); ++i)
  43945. totalLength += (int) resizer.getItemSize (i);
  43946. const bool itemsOffTheEnd = totalLength > getLength();
  43947. const int extrasButtonSize = getThickness() / 2;
  43948. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43949. missingItemsButton->setVisible (itemsOffTheEnd);
  43950. missingItemsButton->setEnabled (! isEditingActive);
  43951. if (vertical)
  43952. missingItemsButton->setCentrePosition (getWidth() / 2,
  43953. getHeight() - 4 - extrasButtonSize / 2);
  43954. else
  43955. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43956. getHeight() / 2);
  43957. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43958. : missingItemsButton->getX()) - 4
  43959. : getLength();
  43960. int pos = 0, activeIndex = 0;
  43961. for (i = 0; i < items.size(); ++i)
  43962. {
  43963. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43964. if (tc->isActive)
  43965. {
  43966. const int size = (int) resizer.getItemSize (activeIndex++);
  43967. Rectangle<int> newBounds;
  43968. if (vertical)
  43969. newBounds.setBounds (0, pos, getWidth(), size);
  43970. else
  43971. newBounds.setBounds (pos, 0, size, getHeight());
  43972. if (animate)
  43973. {
  43974. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43975. }
  43976. else
  43977. {
  43978. animator.cancelAnimation (tc, false);
  43979. tc->setBounds (newBounds);
  43980. }
  43981. pos += size;
  43982. tc->setVisible (pos <= maxLength
  43983. && ((! tc->isBeingDragged)
  43984. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43985. }
  43986. }
  43987. }
  43988. }
  43989. void Toolbar::buttonClicked (Button*)
  43990. {
  43991. jassert (missingItemsButton->isShowing());
  43992. if (missingItemsButton->isShowing())
  43993. {
  43994. PopupMenu m;
  43995. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43996. m.showAt (missingItemsButton);
  43997. }
  43998. }
  43999. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  44000. Component* /*sourceComponent*/)
  44001. {
  44002. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  44003. }
  44004. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  44005. {
  44006. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  44007. if (tc != 0)
  44008. {
  44009. if (getNumItems() == 0)
  44010. {
  44011. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  44012. {
  44013. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  44014. if (palette != 0)
  44015. palette->replaceComponent (tc);
  44016. }
  44017. else
  44018. {
  44019. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  44020. }
  44021. items.add (tc);
  44022. addChildComponent (tc);
  44023. updateAllItemPositions (false);
  44024. }
  44025. else
  44026. {
  44027. for (int i = getNumItems(); --i >= 0;)
  44028. {
  44029. int currentIndex = getIndexOfChildComponent (tc);
  44030. if (currentIndex < 0)
  44031. {
  44032. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  44033. {
  44034. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  44035. if (palette != 0)
  44036. palette->replaceComponent (tc);
  44037. }
  44038. else
  44039. {
  44040. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  44041. }
  44042. items.add (tc);
  44043. addChildComponent (tc);
  44044. currentIndex = getIndexOfChildComponent (tc);
  44045. updateAllItemPositions (true);
  44046. }
  44047. int newIndex = currentIndex;
  44048. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  44049. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  44050. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  44051. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  44052. if (prev != 0)
  44053. {
  44054. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  44055. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  44056. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  44057. {
  44058. newIndex = getIndexOfChildComponent (prev);
  44059. }
  44060. }
  44061. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  44062. if (next != 0)
  44063. {
  44064. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  44065. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  44066. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  44067. {
  44068. newIndex = getIndexOfChildComponent (next) + 1;
  44069. }
  44070. }
  44071. if (newIndex != currentIndex)
  44072. {
  44073. items.removeValue (tc);
  44074. removeChildComponent (tc);
  44075. addChildComponent (tc, newIndex);
  44076. items.insert (newIndex, tc);
  44077. updateAllItemPositions (true);
  44078. }
  44079. else
  44080. {
  44081. break;
  44082. }
  44083. }
  44084. }
  44085. }
  44086. }
  44087. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  44088. {
  44089. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  44090. if (tc != 0)
  44091. {
  44092. if (isParentOf (tc))
  44093. {
  44094. items.removeValue (tc);
  44095. removeChildComponent (tc);
  44096. updateAllItemPositions (true);
  44097. }
  44098. }
  44099. }
  44100. void Toolbar::itemDropped (const String&, Component*, int, int)
  44101. {
  44102. }
  44103. void Toolbar::mouseDown (const MouseEvent& e)
  44104. {
  44105. if (e.mods.isPopupMenu())
  44106. {
  44107. }
  44108. }
  44109. class ToolbarCustomisationDialog : public DialogWindow
  44110. {
  44111. public:
  44112. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  44113. Toolbar* const toolbar_,
  44114. const int optionFlags)
  44115. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  44116. toolbar (toolbar_)
  44117. {
  44118. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  44119. setResizable (true, true);
  44120. setResizeLimits (400, 300, 1500, 1000);
  44121. positionNearBar();
  44122. }
  44123. ~ToolbarCustomisationDialog()
  44124. {
  44125. setContentComponent (0, true);
  44126. }
  44127. void closeButtonPressed()
  44128. {
  44129. setVisible (false);
  44130. }
  44131. bool canModalEventBeSentToComponent (const Component* comp)
  44132. {
  44133. return toolbar->isParentOf (comp);
  44134. }
  44135. void positionNearBar()
  44136. {
  44137. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  44138. const int tbx = toolbar->getScreenX();
  44139. const int tby = toolbar->getScreenY();
  44140. const int gap = 8;
  44141. int x, y;
  44142. if (toolbar->isVertical())
  44143. {
  44144. y = tby;
  44145. if (tbx > screenSize.getCentreX())
  44146. x = tbx - getWidth() - gap;
  44147. else
  44148. x = tbx + toolbar->getWidth() + gap;
  44149. }
  44150. else
  44151. {
  44152. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  44153. if (tby > screenSize.getCentreY())
  44154. y = tby - getHeight() - gap;
  44155. else
  44156. y = tby + toolbar->getHeight() + gap;
  44157. }
  44158. setTopLeftPosition (x, y);
  44159. }
  44160. private:
  44161. Toolbar* const toolbar;
  44162. class CustomiserPanel : public Component,
  44163. private ComboBoxListener,
  44164. private ButtonListener
  44165. {
  44166. public:
  44167. CustomiserPanel (ToolbarItemFactory& factory_,
  44168. Toolbar* const toolbar_,
  44169. const int optionFlags)
  44170. : factory (factory_),
  44171. toolbar (toolbar_),
  44172. styleBox (0),
  44173. defaultButton (0)
  44174. {
  44175. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  44176. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  44177. | Toolbar::allowIconsWithTextChoice
  44178. | Toolbar::allowTextOnlyChoice)) != 0)
  44179. {
  44180. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  44181. styleBox->setEditableText (false);
  44182. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  44183. styleBox->addItem (TRANS("Show icons only"), 1);
  44184. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  44185. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  44186. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  44187. styleBox->addItem (TRANS("Show descriptions only"), 3);
  44188. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  44189. styleBox->setSelectedId (1);
  44190. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  44191. styleBox->setSelectedId (2);
  44192. else if (toolbar_->getStyle() == Toolbar::textOnly)
  44193. styleBox->setSelectedId (3);
  44194. styleBox->addListener (this);
  44195. }
  44196. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  44197. {
  44198. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  44199. defaultButton->addButtonListener (this);
  44200. }
  44201. addAndMakeVisible (instructions = new Label (String::empty,
  44202. 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.")));
  44203. instructions->setFont (Font (13.0f));
  44204. setSize (500, 300);
  44205. }
  44206. ~CustomiserPanel()
  44207. {
  44208. deleteAllChildren();
  44209. }
  44210. void comboBoxChanged (ComboBox*)
  44211. {
  44212. if (styleBox->getSelectedId() == 1)
  44213. toolbar->setStyle (Toolbar::iconsOnly);
  44214. else if (styleBox->getSelectedId() == 2)
  44215. toolbar->setStyle (Toolbar::iconsWithText);
  44216. else if (styleBox->getSelectedId() == 3)
  44217. toolbar->setStyle (Toolbar::textOnly);
  44218. palette->resized(); // to make it update the styles
  44219. }
  44220. void buttonClicked (Button*)
  44221. {
  44222. toolbar->addDefaultItems (factory);
  44223. }
  44224. void paint (Graphics& g)
  44225. {
  44226. Colour background;
  44227. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  44228. if (dw != 0)
  44229. background = dw->getBackgroundColour();
  44230. g.setColour (background.contrasting().withAlpha (0.3f));
  44231. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  44232. }
  44233. void resized()
  44234. {
  44235. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  44236. if (styleBox != 0)
  44237. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  44238. if (defaultButton != 0)
  44239. {
  44240. defaultButton->changeWidthToFitText (22);
  44241. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  44242. }
  44243. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  44244. }
  44245. private:
  44246. ToolbarItemFactory& factory;
  44247. Toolbar* const toolbar;
  44248. Label* instructions;
  44249. ToolbarItemPalette* palette;
  44250. ComboBox* styleBox;
  44251. TextButton* defaultButton;
  44252. };
  44253. };
  44254. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  44255. {
  44256. setEditingActive (true);
  44257. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  44258. dw.runModalLoop();
  44259. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  44260. setEditingActive (false);
  44261. }
  44262. END_JUCE_NAMESPACE
  44263. /*** End of inlined file: juce_Toolbar.cpp ***/
  44264. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  44265. BEGIN_JUCE_NAMESPACE
  44266. ToolbarItemFactory::ToolbarItemFactory()
  44267. {
  44268. }
  44269. ToolbarItemFactory::~ToolbarItemFactory()
  44270. {
  44271. }
  44272. class ItemDragAndDropOverlayComponent : public Component
  44273. {
  44274. public:
  44275. ItemDragAndDropOverlayComponent()
  44276. : isDragging (false)
  44277. {
  44278. setAlwaysOnTop (true);
  44279. setRepaintsOnMouseActivity (true);
  44280. setMouseCursor (MouseCursor::DraggingHandCursor);
  44281. }
  44282. ~ItemDragAndDropOverlayComponent()
  44283. {
  44284. }
  44285. void paint (Graphics& g)
  44286. {
  44287. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44288. if (isMouseOverOrDragging()
  44289. && tc != 0
  44290. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44291. {
  44292. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  44293. g.drawRect (0, 0, getWidth(), getHeight(),
  44294. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  44295. }
  44296. }
  44297. void mouseDown (const MouseEvent& e)
  44298. {
  44299. isDragging = false;
  44300. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44301. if (tc != 0)
  44302. {
  44303. tc->dragOffsetX = e.x;
  44304. tc->dragOffsetY = e.y;
  44305. }
  44306. }
  44307. void mouseDrag (const MouseEvent& e)
  44308. {
  44309. if (! (isDragging || e.mouseWasClicked()))
  44310. {
  44311. isDragging = true;
  44312. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  44313. if (dnd != 0)
  44314. {
  44315. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  44316. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44317. if (tc != 0)
  44318. {
  44319. tc->isBeingDragged = true;
  44320. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44321. tc->setVisible (false);
  44322. }
  44323. }
  44324. }
  44325. }
  44326. void mouseUp (const MouseEvent&)
  44327. {
  44328. isDragging = false;
  44329. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44330. if (tc != 0)
  44331. {
  44332. tc->isBeingDragged = false;
  44333. Toolbar* const tb = tc->getToolbar();
  44334. if (tb != 0)
  44335. tb->updateAllItemPositions (true);
  44336. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44337. delete tc;
  44338. }
  44339. }
  44340. void parentSizeChanged()
  44341. {
  44342. setBounds (0, 0, getParentWidth(), getParentHeight());
  44343. }
  44344. juce_UseDebuggingNewOperator
  44345. private:
  44346. bool isDragging;
  44347. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  44348. const ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  44349. };
  44350. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  44351. const String& labelText,
  44352. const bool isBeingUsedAsAButton_)
  44353. : Button (labelText),
  44354. itemId (itemId_),
  44355. mode (normalMode),
  44356. toolbarStyle (Toolbar::iconsOnly),
  44357. dragOffsetX (0),
  44358. dragOffsetY (0),
  44359. isActive (true),
  44360. isBeingDragged (false),
  44361. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  44362. {
  44363. // Your item ID can't be 0!
  44364. jassert (itemId_ != 0);
  44365. }
  44366. ToolbarItemComponent::~ToolbarItemComponent()
  44367. {
  44368. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44369. overlayComp = 0;
  44370. }
  44371. Toolbar* ToolbarItemComponent::getToolbar() const
  44372. {
  44373. return dynamic_cast <Toolbar*> (getParentComponent());
  44374. }
  44375. bool ToolbarItemComponent::isToolbarVertical() const
  44376. {
  44377. const Toolbar* const t = getToolbar();
  44378. return t != 0 && t->isVertical();
  44379. }
  44380. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  44381. {
  44382. if (toolbarStyle != newStyle)
  44383. {
  44384. toolbarStyle = newStyle;
  44385. repaint();
  44386. resized();
  44387. }
  44388. }
  44389. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  44390. {
  44391. if (isBeingUsedAsAButton)
  44392. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  44393. isMouseOver, isMouseDown, *this);
  44394. if (toolbarStyle != Toolbar::iconsOnly)
  44395. {
  44396. const int indent = contentArea.getX();
  44397. int y = indent;
  44398. int h = getHeight() - indent * 2;
  44399. if (toolbarStyle == Toolbar::iconsWithText)
  44400. {
  44401. y = contentArea.getBottom() + indent / 2;
  44402. h -= contentArea.getHeight();
  44403. }
  44404. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  44405. getButtonText(), *this);
  44406. }
  44407. if (! contentArea.isEmpty())
  44408. {
  44409. g.saveState();
  44410. g.setOrigin (contentArea.getX(), contentArea.getY());
  44411. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  44412. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  44413. g.restoreState();
  44414. }
  44415. }
  44416. void ToolbarItemComponent::resized()
  44417. {
  44418. if (toolbarStyle != Toolbar::textOnly)
  44419. {
  44420. const int indent = jmin (proportionOfWidth (0.08f),
  44421. proportionOfHeight (0.08f));
  44422. contentArea = Rectangle<int> (indent, indent,
  44423. getWidth() - indent * 2,
  44424. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  44425. : (getHeight() - indent * 2));
  44426. }
  44427. else
  44428. {
  44429. contentArea = Rectangle<int>();
  44430. }
  44431. contentAreaChanged (contentArea);
  44432. }
  44433. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  44434. {
  44435. if (mode != newMode)
  44436. {
  44437. mode = newMode;
  44438. repaint();
  44439. if (mode == normalMode)
  44440. {
  44441. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44442. overlayComp = 0;
  44443. }
  44444. else if (overlayComp == 0)
  44445. {
  44446. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  44447. overlayComp->parentSizeChanged();
  44448. }
  44449. resized();
  44450. }
  44451. }
  44452. END_JUCE_NAMESPACE
  44453. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  44454. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  44455. BEGIN_JUCE_NAMESPACE
  44456. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  44457. Toolbar* const toolbar_)
  44458. : factory (factory_),
  44459. toolbar (toolbar_)
  44460. {
  44461. Component* const itemHolder = new Component();
  44462. Array <int> allIds;
  44463. factory_.getAllToolbarItemIds (allIds);
  44464. for (int i = 0; i < allIds.size(); ++i)
  44465. {
  44466. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  44467. jassert (tc != 0);
  44468. if (tc != 0)
  44469. {
  44470. itemHolder->addAndMakeVisible (tc);
  44471. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  44472. }
  44473. }
  44474. viewport = new Viewport();
  44475. viewport->setViewedComponent (itemHolder);
  44476. addAndMakeVisible (viewport);
  44477. }
  44478. ToolbarItemPalette::~ToolbarItemPalette()
  44479. {
  44480. viewport->getViewedComponent()->deleteAllChildren();
  44481. deleteAllChildren();
  44482. }
  44483. void ToolbarItemPalette::resized()
  44484. {
  44485. viewport->setBoundsInset (BorderSize (1));
  44486. Component* const itemHolder = viewport->getViewedComponent();
  44487. const int indent = 8;
  44488. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  44489. const int height = toolbar->getThickness();
  44490. int x = indent;
  44491. int y = indent;
  44492. int maxX = 0;
  44493. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  44494. {
  44495. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  44496. if (tc != 0)
  44497. {
  44498. tc->setStyle (toolbar->getStyle());
  44499. int preferredSize = 1, minSize = 1, maxSize = 1;
  44500. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  44501. {
  44502. if (x + preferredSize > preferredWidth && x > indent)
  44503. {
  44504. x = indent;
  44505. y += height;
  44506. }
  44507. tc->setBounds (x, y, preferredSize, height);
  44508. x += preferredSize + 8;
  44509. maxX = jmax (maxX, x);
  44510. }
  44511. }
  44512. }
  44513. itemHolder->setSize (maxX, y + height + 8);
  44514. }
  44515. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  44516. {
  44517. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  44518. jassert (tc != 0);
  44519. if (tc != 0)
  44520. {
  44521. tc->setBounds (comp->getBounds());
  44522. tc->setStyle (toolbar->getStyle());
  44523. tc->setEditingMode (comp->getEditingMode());
  44524. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  44525. }
  44526. }
  44527. END_JUCE_NAMESPACE
  44528. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  44529. /*** Start of inlined file: juce_TreeView.cpp ***/
  44530. BEGIN_JUCE_NAMESPACE
  44531. class TreeViewContentComponent : public Component,
  44532. public TooltipClient
  44533. {
  44534. public:
  44535. TreeViewContentComponent (TreeView* const owner_)
  44536. : owner (owner_),
  44537. buttonUnderMouse (0),
  44538. isDragging (false)
  44539. {
  44540. }
  44541. ~TreeViewContentComponent()
  44542. {
  44543. deleteAllChildren();
  44544. }
  44545. void mouseDown (const MouseEvent& e)
  44546. {
  44547. updateButtonUnderMouse (e);
  44548. isDragging = false;
  44549. needSelectionOnMouseUp = false;
  44550. Rectangle<int> pos;
  44551. TreeViewItem* const item = findItemAt (e.y, pos);
  44552. if (item == 0)
  44553. return;
  44554. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  44555. // as selection clicks)
  44556. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  44557. {
  44558. if (e.x >= pos.getX() - owner->getIndentSize())
  44559. item->setOpen (! item->isOpen());
  44560. // (clicks to the left of an open/close button are ignored)
  44561. }
  44562. else
  44563. {
  44564. // mouse-down inside the body of the item..
  44565. if (! owner->isMultiSelectEnabled())
  44566. item->setSelected (true, true);
  44567. else if (item->isSelected())
  44568. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  44569. else
  44570. selectBasedOnModifiers (item, e.mods);
  44571. MouseEvent e2 (e);
  44572. e2.x -= pos.getX();
  44573. e2.y -= pos.getY();
  44574. if (e2.x >= 0)
  44575. item->itemClicked (e2);
  44576. }
  44577. }
  44578. void mouseUp (const MouseEvent& e)
  44579. {
  44580. updateButtonUnderMouse (e);
  44581. if (needSelectionOnMouseUp && e.mouseWasClicked())
  44582. {
  44583. Rectangle<int> pos;
  44584. TreeViewItem* const item = findItemAt (e.y, pos);
  44585. if (item != 0)
  44586. selectBasedOnModifiers (item, e.mods);
  44587. }
  44588. }
  44589. void mouseDoubleClick (const MouseEvent& e)
  44590. {
  44591. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  44592. {
  44593. Rectangle<int> pos;
  44594. TreeViewItem* const item = findItemAt (e.y, pos);
  44595. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  44596. {
  44597. MouseEvent e2 (e);
  44598. e2.x -= pos.getX();
  44599. e2.y -= pos.getY();
  44600. item->itemDoubleClicked (e2);
  44601. }
  44602. }
  44603. }
  44604. void mouseDrag (const MouseEvent& e)
  44605. {
  44606. if (isEnabled()
  44607. && ! (isDragging || e.mouseWasClicked()
  44608. || e.getDistanceFromDragStart() < 5
  44609. || e.mods.isPopupMenu()))
  44610. {
  44611. isDragging = true;
  44612. Rectangle<int> pos;
  44613. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  44614. if (item != 0 && e.getMouseDownX() >= pos.getX())
  44615. {
  44616. const String dragDescription (item->getDragSourceDescription());
  44617. if (dragDescription.isNotEmpty())
  44618. {
  44619. DragAndDropContainer* const dragContainer
  44620. = DragAndDropContainer::findParentDragContainerFor (this);
  44621. if (dragContainer != 0)
  44622. {
  44623. pos.setSize (pos.getWidth(), item->itemHeight);
  44624. Image* dragImage = Component::createComponentSnapshot (pos, true);
  44625. dragImage->multiplyAllAlphas (0.6f);
  44626. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  44627. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  44628. }
  44629. else
  44630. {
  44631. // to be able to do a drag-and-drop operation, the treeview needs to
  44632. // be inside a component which is also a DragAndDropContainer.
  44633. jassertfalse
  44634. }
  44635. }
  44636. }
  44637. }
  44638. }
  44639. void mouseMove (const MouseEvent& e)
  44640. {
  44641. updateButtonUnderMouse (e);
  44642. }
  44643. void mouseExit (const MouseEvent& e)
  44644. {
  44645. updateButtonUnderMouse (e);
  44646. }
  44647. void paint (Graphics& g);
  44648. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  44649. void updateComponents()
  44650. {
  44651. const int visibleTop = -getY();
  44652. const int visibleBottom = visibleTop + getParentHeight();
  44653. BitArray itemsToKeep;
  44654. TreeViewItem* item = owner->rootItem;
  44655. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44656. while (item != 0 && y < visibleBottom)
  44657. {
  44658. y += item->itemHeight;
  44659. if (y >= visibleTop)
  44660. {
  44661. const int index = rowComponentIds.indexOf (item->uid);
  44662. if (index < 0)
  44663. {
  44664. Component* const comp = item->createItemComponent();
  44665. if (comp != 0)
  44666. {
  44667. addAndMakeVisible (comp);
  44668. itemsToKeep.setBit (rowComponentItems.size());
  44669. rowComponentItems.add (item);
  44670. rowComponentIds.add (item->uid);
  44671. rowComponents.add (comp);
  44672. }
  44673. }
  44674. else
  44675. {
  44676. itemsToKeep.setBit (index);
  44677. }
  44678. }
  44679. item = item->getNextVisibleItem (true);
  44680. }
  44681. for (int i = rowComponentItems.size(); --i >= 0;)
  44682. {
  44683. Component* const comp = (Component*) rowComponents.getUnchecked(i);
  44684. bool keep = false;
  44685. if (isParentOf (comp))
  44686. {
  44687. if (itemsToKeep[i])
  44688. {
  44689. const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
  44690. Rectangle<int> pos (item->getItemPosition (false));
  44691. pos.setSize (pos.getWidth(), item->itemHeight);
  44692. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44693. {
  44694. keep = true;
  44695. comp->setBounds (pos);
  44696. }
  44697. }
  44698. if ((! keep)
  44699. && Component::isMouseButtonDownAnywhere()
  44700. && (comp == Component::getComponentUnderMouse()
  44701. || comp->isParentOf (Component::getComponentUnderMouse())))
  44702. {
  44703. keep = true;
  44704. comp->setSize (0, 0);
  44705. }
  44706. }
  44707. if (! keep)
  44708. {
  44709. delete comp;
  44710. rowComponents.remove (i);
  44711. rowComponentIds.remove (i);
  44712. rowComponentItems.remove (i);
  44713. }
  44714. }
  44715. }
  44716. void updateButtonUnderMouse (const MouseEvent& e)
  44717. {
  44718. TreeViewItem* newItem = 0;
  44719. if (owner->openCloseButtonsVisible)
  44720. {
  44721. Rectangle<int> pos;
  44722. TreeViewItem* item = findItemAt (e.y, pos);
  44723. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44724. {
  44725. newItem = item;
  44726. if (! newItem->mightContainSubItems())
  44727. newItem = 0;
  44728. }
  44729. }
  44730. if (buttonUnderMouse != newItem)
  44731. {
  44732. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44733. {
  44734. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44735. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44736. }
  44737. buttonUnderMouse = newItem;
  44738. if (buttonUnderMouse != 0)
  44739. {
  44740. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44741. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44742. }
  44743. }
  44744. }
  44745. bool isMouseOverButton (TreeViewItem* item) const throw()
  44746. {
  44747. return item == buttonUnderMouse;
  44748. }
  44749. void resized()
  44750. {
  44751. owner->itemsChanged();
  44752. }
  44753. const String getTooltip()
  44754. {
  44755. int x, y;
  44756. getMouseXYRelative (x, y);
  44757. Rectangle<int> pos;
  44758. TreeViewItem* const item = findItemAt (y, pos);
  44759. if (item != 0)
  44760. return item->getTooltip();
  44761. return owner->getTooltip();
  44762. }
  44763. juce_UseDebuggingNewOperator
  44764. private:
  44765. TreeView* const owner;
  44766. VoidArray rowComponentItems;
  44767. Array <int> rowComponentIds;
  44768. VoidArray rowComponents;
  44769. TreeViewItem* buttonUnderMouse;
  44770. bool isDragging, needSelectionOnMouseUp;
  44771. TreeViewContentComponent (const TreeViewContentComponent&);
  44772. const TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44773. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44774. {
  44775. TreeViewItem* firstSelected = 0;
  44776. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44777. {
  44778. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44779. jassert (lastSelected != 0);
  44780. int rowStart = firstSelected->getRowNumberInTree();
  44781. int rowEnd = lastSelected->getRowNumberInTree();
  44782. if (rowStart > rowEnd)
  44783. swapVariables (rowStart, rowEnd);
  44784. int ourRow = item->getRowNumberInTree();
  44785. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44786. if (ourRow > otherEnd)
  44787. swapVariables (ourRow, otherEnd);
  44788. for (int i = ourRow; i <= otherEnd; ++i)
  44789. owner->getItemOnRow (i)->setSelected (true, false);
  44790. }
  44791. else
  44792. {
  44793. const bool cmd = modifiers.isCommandDown();
  44794. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44795. }
  44796. }
  44797. bool containsItem (TreeViewItem* const item) const
  44798. {
  44799. for (int i = rowComponentItems.size(); --i >= 0;)
  44800. if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item)
  44801. return true;
  44802. return false;
  44803. }
  44804. };
  44805. class TreeViewport : public Viewport
  44806. {
  44807. public:
  44808. TreeViewport() throw() {}
  44809. ~TreeViewport() throw() {}
  44810. void updateComponents()
  44811. {
  44812. if (getViewedComponent() != 0)
  44813. ((TreeViewContentComponent*) getViewedComponent())->updateComponents();
  44814. repaint();
  44815. }
  44816. void visibleAreaChanged (int, int, int, int)
  44817. {
  44818. updateComponents();
  44819. }
  44820. juce_UseDebuggingNewOperator
  44821. private:
  44822. TreeViewport (const TreeViewport&);
  44823. const TreeViewport& operator= (const TreeViewport&);
  44824. };
  44825. TreeView::TreeView (const String& componentName)
  44826. : Component (componentName),
  44827. rootItem (0),
  44828. dragInsertPointHighlight (0),
  44829. dragTargetGroupHighlight (0),
  44830. indentSize (24),
  44831. defaultOpenness (false),
  44832. needsRecalculating (true),
  44833. rootItemVisible (true),
  44834. multiSelectEnabled (false),
  44835. openCloseButtonsVisible (true)
  44836. {
  44837. addAndMakeVisible (viewport = new TreeViewport());
  44838. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44839. viewport->setWantsKeyboardFocus (false);
  44840. setWantsKeyboardFocus (true);
  44841. }
  44842. TreeView::~TreeView()
  44843. {
  44844. if (rootItem != 0)
  44845. rootItem->setOwnerView (0);
  44846. deleteAllChildren();
  44847. }
  44848. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44849. {
  44850. if (rootItem != newRootItem)
  44851. {
  44852. if (newRootItem != 0)
  44853. {
  44854. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44855. if (newRootItem->ownerView != 0)
  44856. newRootItem->ownerView->setRootItem (0);
  44857. }
  44858. if (rootItem != 0)
  44859. rootItem->setOwnerView (0);
  44860. rootItem = newRootItem;
  44861. if (newRootItem != 0)
  44862. newRootItem->setOwnerView (this);
  44863. needsRecalculating = true;
  44864. handleAsyncUpdate();
  44865. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44866. {
  44867. rootItem->setOpen (false); // force a re-open
  44868. rootItem->setOpen (true);
  44869. }
  44870. }
  44871. }
  44872. void TreeView::deleteRootItem()
  44873. {
  44874. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44875. setRootItem (0);
  44876. }
  44877. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44878. {
  44879. rootItemVisible = shouldBeVisible;
  44880. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44881. {
  44882. rootItem->setOpen (false); // force a re-open
  44883. rootItem->setOpen (true);
  44884. }
  44885. itemsChanged();
  44886. }
  44887. void TreeView::colourChanged()
  44888. {
  44889. setOpaque (findColour (backgroundColourId).isOpaque());
  44890. repaint();
  44891. }
  44892. void TreeView::setIndentSize (const int newIndentSize)
  44893. {
  44894. if (indentSize != newIndentSize)
  44895. {
  44896. indentSize = newIndentSize;
  44897. resized();
  44898. }
  44899. }
  44900. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44901. {
  44902. if (defaultOpenness != isOpenByDefault)
  44903. {
  44904. defaultOpenness = isOpenByDefault;
  44905. itemsChanged();
  44906. }
  44907. }
  44908. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44909. {
  44910. multiSelectEnabled = canMultiSelect;
  44911. }
  44912. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44913. {
  44914. if (openCloseButtonsVisible != shouldBeVisible)
  44915. {
  44916. openCloseButtonsVisible = shouldBeVisible;
  44917. itemsChanged();
  44918. }
  44919. }
  44920. void TreeView::clearSelectedItems()
  44921. {
  44922. if (rootItem != 0)
  44923. rootItem->deselectAllRecursively();
  44924. }
  44925. int TreeView::getNumSelectedItems() const throw()
  44926. {
  44927. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44928. }
  44929. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44930. {
  44931. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44932. }
  44933. int TreeView::getNumRowsInTree() const
  44934. {
  44935. if (rootItem != 0)
  44936. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44937. return 0;
  44938. }
  44939. TreeViewItem* TreeView::getItemOnRow (int index) const
  44940. {
  44941. if (! rootItemVisible)
  44942. ++index;
  44943. if (rootItem != 0 && index >= 0)
  44944. return rootItem->getItemOnRow (index);
  44945. return 0;
  44946. }
  44947. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44948. {
  44949. TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent();
  44950. int x;
  44951. relativePositionToOtherComponent (tc, x, y);
  44952. Rectangle<int> pos;
  44953. return tc->findItemAt (y, pos);
  44954. }
  44955. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44956. {
  44957. if (rootItem == 0)
  44958. return 0;
  44959. return rootItem->findItemFromIdentifierString (identifierString);
  44960. }
  44961. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44962. {
  44963. XmlElement* e = 0;
  44964. if (rootItem != 0)
  44965. {
  44966. e = rootItem->getOpennessState();
  44967. if (e != 0 && alsoIncludeScrollPosition)
  44968. e->setAttribute (T("scrollPos"), viewport->getViewPositionY());
  44969. }
  44970. return e;
  44971. }
  44972. void TreeView::restoreOpennessState (const XmlElement& newState)
  44973. {
  44974. if (rootItem != 0)
  44975. {
  44976. rootItem->restoreOpennessState (newState);
  44977. if (newState.hasAttribute (T("scrollPos")))
  44978. viewport->setViewPosition (viewport->getViewPositionX(),
  44979. newState.getIntAttribute (T("scrollPos")));
  44980. }
  44981. }
  44982. void TreeView::paint (Graphics& g)
  44983. {
  44984. g.fillAll (findColour (backgroundColourId));
  44985. }
  44986. void TreeView::resized()
  44987. {
  44988. viewport->setBounds (0, 0, getWidth(), getHeight());
  44989. itemsChanged();
  44990. handleAsyncUpdate();
  44991. }
  44992. void TreeView::enablementChanged()
  44993. {
  44994. repaint();
  44995. }
  44996. void TreeView::moveSelectedRow (int delta)
  44997. {
  44998. if (delta == 0)
  44999. return;
  45000. int rowSelected = 0;
  45001. TreeViewItem* const firstSelected = getSelectedItem (0);
  45002. if (firstSelected != 0)
  45003. rowSelected = firstSelected->getRowNumberInTree();
  45004. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  45005. for (;;)
  45006. {
  45007. TreeViewItem* item = getItemOnRow (rowSelected);
  45008. if (item != 0)
  45009. {
  45010. if (! item->canBeSelected())
  45011. {
  45012. // if the row we want to highlight doesn't allow it, try skipping
  45013. // to the next item..
  45014. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  45015. rowSelected + (delta < 0 ? -1 : 1));
  45016. if (rowSelected != nextRowToTry)
  45017. {
  45018. rowSelected = nextRowToTry;
  45019. continue;
  45020. }
  45021. else
  45022. {
  45023. break;
  45024. }
  45025. }
  45026. item->setSelected (true, true);
  45027. scrollToKeepItemVisible (item);
  45028. }
  45029. break;
  45030. }
  45031. }
  45032. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  45033. {
  45034. if (item != 0 && item->ownerView == this)
  45035. {
  45036. handleAsyncUpdate();
  45037. item = item->getDeepestOpenParentItem();
  45038. int y = item->y;
  45039. int viewTop = viewport->getViewPositionY();
  45040. if (y < viewTop)
  45041. {
  45042. viewport->setViewPosition (viewport->getViewPositionX(), y);
  45043. }
  45044. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  45045. {
  45046. viewport->setViewPosition (viewport->getViewPositionX(),
  45047. (y + item->itemHeight) - viewport->getViewHeight());
  45048. }
  45049. }
  45050. }
  45051. bool TreeView::keyPressed (const KeyPress& key)
  45052. {
  45053. if (key.isKeyCode (KeyPress::upKey))
  45054. {
  45055. moveSelectedRow (-1);
  45056. }
  45057. else if (key.isKeyCode (KeyPress::downKey))
  45058. {
  45059. moveSelectedRow (1);
  45060. }
  45061. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  45062. {
  45063. if (rootItem != 0)
  45064. {
  45065. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  45066. if (key.isKeyCode (KeyPress::pageUpKey))
  45067. rowsOnScreen = -rowsOnScreen;
  45068. moveSelectedRow (rowsOnScreen);
  45069. }
  45070. }
  45071. else if (key.isKeyCode (KeyPress::homeKey))
  45072. {
  45073. moveSelectedRow (-0x3fffffff);
  45074. }
  45075. else if (key.isKeyCode (KeyPress::endKey))
  45076. {
  45077. moveSelectedRow (0x3fffffff);
  45078. }
  45079. else if (key.isKeyCode (KeyPress::returnKey))
  45080. {
  45081. TreeViewItem* const firstSelected = getSelectedItem (0);
  45082. if (firstSelected != 0)
  45083. firstSelected->setOpen (! firstSelected->isOpen());
  45084. }
  45085. else if (key.isKeyCode (KeyPress::leftKey))
  45086. {
  45087. TreeViewItem* const firstSelected = getSelectedItem (0);
  45088. if (firstSelected != 0)
  45089. {
  45090. if (firstSelected->isOpen())
  45091. {
  45092. firstSelected->setOpen (false);
  45093. }
  45094. else
  45095. {
  45096. TreeViewItem* parent = firstSelected->parentItem;
  45097. if ((! rootItemVisible) && parent == rootItem)
  45098. parent = 0;
  45099. if (parent != 0)
  45100. {
  45101. parent->setSelected (true, true);
  45102. scrollToKeepItemVisible (parent);
  45103. }
  45104. }
  45105. }
  45106. }
  45107. else if (key.isKeyCode (KeyPress::rightKey))
  45108. {
  45109. TreeViewItem* const firstSelected = getSelectedItem (0);
  45110. if (firstSelected != 0)
  45111. {
  45112. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  45113. moveSelectedRow (1);
  45114. else
  45115. firstSelected->setOpen (true);
  45116. }
  45117. }
  45118. else
  45119. {
  45120. return false;
  45121. }
  45122. return true;
  45123. }
  45124. void TreeView::itemsChanged() throw()
  45125. {
  45126. needsRecalculating = true;
  45127. repaint();
  45128. triggerAsyncUpdate();
  45129. }
  45130. void TreeView::handleAsyncUpdate()
  45131. {
  45132. if (needsRecalculating)
  45133. {
  45134. needsRecalculating = false;
  45135. const ScopedLock sl (nodeAlterationLock);
  45136. if (rootItem != 0)
  45137. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  45138. ((TreeViewport*) viewport)->updateComponents();
  45139. if (rootItem != 0)
  45140. {
  45141. viewport->getViewedComponent()
  45142. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  45143. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  45144. }
  45145. else
  45146. {
  45147. viewport->getViewedComponent()->setSize (0, 0);
  45148. }
  45149. }
  45150. }
  45151. class TreeViewDragInsertPointHighlight : public Component
  45152. {
  45153. public:
  45154. TreeViewDragInsertPointHighlight()
  45155. : lastItem (0)
  45156. {
  45157. setSize (100, 12);
  45158. setAlwaysOnTop (true);
  45159. setInterceptsMouseClicks (false, false);
  45160. }
  45161. ~TreeViewDragInsertPointHighlight() {}
  45162. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  45163. {
  45164. lastItem = item;
  45165. lastIndex = insertIndex;
  45166. const int offset = getHeight() / 2;
  45167. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  45168. }
  45169. void paint (Graphics& g)
  45170. {
  45171. Path p;
  45172. const float h = (float) getHeight();
  45173. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  45174. p.startNewSubPath (h - 2.0f, h / 2.0f);
  45175. p.lineTo ((float) getWidth(), h / 2.0f);
  45176. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45177. g.strokePath (p, PathStrokeType (2.0f));
  45178. }
  45179. TreeViewItem* lastItem;
  45180. int lastIndex;
  45181. };
  45182. class TreeViewDragTargetGroupHighlight : public Component
  45183. {
  45184. public:
  45185. TreeViewDragTargetGroupHighlight()
  45186. {
  45187. setAlwaysOnTop (true);
  45188. setInterceptsMouseClicks (false, false);
  45189. }
  45190. ~TreeViewDragTargetGroupHighlight() {}
  45191. void setTargetPosition (TreeViewItem* const item) throw()
  45192. {
  45193. Rectangle<int> r (item->getItemPosition (true));
  45194. r.setHeight (item->getItemHeight());
  45195. setBounds (r);
  45196. }
  45197. void paint (Graphics& g)
  45198. {
  45199. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45200. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  45201. }
  45202. };
  45203. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  45204. {
  45205. beginDragAutoRepeat (1000 / 30);
  45206. if (dragInsertPointHighlight == 0)
  45207. {
  45208. addAndMakeVisible (dragInsertPointHighlight = new TreeViewDragInsertPointHighlight());
  45209. addAndMakeVisible (dragTargetGroupHighlight = new TreeViewDragTargetGroupHighlight());
  45210. }
  45211. ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)
  45212. ->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  45213. ((TreeViewDragTargetGroupHighlight*) dragTargetGroupHighlight)
  45214. ->setTargetPosition (item);
  45215. }
  45216. void TreeView::hideDragHighlight() throw()
  45217. {
  45218. deleteAndZero (dragInsertPointHighlight);
  45219. deleteAndZero (dragTargetGroupHighlight);
  45220. }
  45221. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  45222. const StringArray& files, const String& sourceDescription,
  45223. Component* sourceComponent) const throw()
  45224. {
  45225. insertIndex = 0;
  45226. TreeViewItem* item = getItemAt (y);
  45227. if (item == 0)
  45228. return 0;
  45229. Rectangle<int> itemPos (item->getItemPosition (true));
  45230. insertIndex = item->getIndexInParent();
  45231. const int oldY = y;
  45232. y = itemPos.getY();
  45233. if (item->getNumSubItems() == 0 || ! item->isOpen())
  45234. {
  45235. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45236. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45237. {
  45238. // Check if we're trying to drag into an empty group item..
  45239. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  45240. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  45241. {
  45242. insertIndex = 0;
  45243. x = itemPos.getX() + getIndentSize();
  45244. y = itemPos.getBottom();
  45245. return item;
  45246. }
  45247. }
  45248. }
  45249. if (oldY > itemPos.getCentreY())
  45250. {
  45251. y += item->getItemHeight();
  45252. while (item->isLastOfSiblings() && item->parentItem != 0
  45253. && item->parentItem->parentItem != 0)
  45254. {
  45255. if (x > itemPos.getX())
  45256. break;
  45257. item = item->parentItem;
  45258. itemPos = item->getItemPosition (true);
  45259. insertIndex = item->getIndexInParent();
  45260. }
  45261. ++insertIndex;
  45262. }
  45263. x = itemPos.getX();
  45264. return item->parentItem;
  45265. }
  45266. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45267. {
  45268. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  45269. int insertIndex;
  45270. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45271. if (item != 0)
  45272. {
  45273. if (scrolled || dragInsertPointHighlight == 0
  45274. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastItem != item
  45275. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastIndex != insertIndex)
  45276. {
  45277. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45278. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45279. showDragHighlight (item, insertIndex, x, y);
  45280. else
  45281. hideDragHighlight();
  45282. }
  45283. }
  45284. else
  45285. {
  45286. hideDragHighlight();
  45287. }
  45288. }
  45289. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45290. {
  45291. hideDragHighlight();
  45292. int insertIndex;
  45293. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45294. if (item != 0)
  45295. {
  45296. if (files.size() > 0)
  45297. {
  45298. if (item->isInterestedInFileDrag (files))
  45299. item->filesDropped (files, insertIndex);
  45300. }
  45301. else
  45302. {
  45303. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45304. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  45305. }
  45306. }
  45307. }
  45308. bool TreeView::isInterestedInFileDrag (const StringArray&)
  45309. {
  45310. return true;
  45311. }
  45312. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  45313. {
  45314. fileDragMove (files, x, y);
  45315. }
  45316. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  45317. {
  45318. handleDrag (files, String::empty, 0, x, y);
  45319. }
  45320. void TreeView::fileDragExit (const StringArray&)
  45321. {
  45322. hideDragHighlight();
  45323. }
  45324. void TreeView::filesDropped (const StringArray& files, int x, int y)
  45325. {
  45326. handleDrop (files, String::empty, 0, x, y);
  45327. }
  45328. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45329. {
  45330. return true;
  45331. }
  45332. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45333. {
  45334. itemDragMove (sourceDescription, sourceComponent, x, y);
  45335. }
  45336. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45337. {
  45338. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  45339. }
  45340. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45341. {
  45342. hideDragHighlight();
  45343. }
  45344. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45345. {
  45346. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  45347. }
  45348. void TreeViewContentComponent::paint (Graphics& g)
  45349. {
  45350. if (owner->rootItem != 0)
  45351. {
  45352. owner->handleAsyncUpdate();
  45353. if (! owner->rootItemVisible)
  45354. g.setOrigin (0, -owner->rootItem->itemHeight);
  45355. owner->rootItem->paintRecursively (g, getWidth());
  45356. }
  45357. }
  45358. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  45359. {
  45360. if (owner->rootItem != 0)
  45361. {
  45362. owner->handleAsyncUpdate();
  45363. if (! owner->rootItemVisible)
  45364. y += owner->rootItem->itemHeight;
  45365. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  45366. if (ti != 0)
  45367. itemPosition = ti->getItemPosition (false);
  45368. return ti;
  45369. }
  45370. return 0;
  45371. }
  45372. enum TreeViewOpenness
  45373. {
  45374. opennessDefault = 0,
  45375. opennessClosed = 1,
  45376. opennessOpen = 2
  45377. };
  45378. TreeViewItem::TreeViewItem()
  45379. : ownerView (0),
  45380. parentItem (0),
  45381. y (0),
  45382. itemHeight (0),
  45383. totalHeight (0),
  45384. selected (false),
  45385. redrawNeeded (true),
  45386. drawLinesInside (true),
  45387. drawsInLeftMargin (false),
  45388. openness (opennessDefault)
  45389. {
  45390. static int nextUID = 0;
  45391. uid = nextUID++;
  45392. }
  45393. TreeViewItem::~TreeViewItem()
  45394. {
  45395. }
  45396. const String TreeViewItem::getUniqueName() const
  45397. {
  45398. return String::empty;
  45399. }
  45400. void TreeViewItem::itemOpennessChanged (bool)
  45401. {
  45402. }
  45403. int TreeViewItem::getNumSubItems() const throw()
  45404. {
  45405. return subItems.size();
  45406. }
  45407. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  45408. {
  45409. return subItems [index];
  45410. }
  45411. void TreeViewItem::clearSubItems()
  45412. {
  45413. if (subItems.size() > 0)
  45414. {
  45415. if (ownerView != 0)
  45416. {
  45417. const ScopedLock sl (ownerView->nodeAlterationLock);
  45418. subItems.clear();
  45419. treeHasChanged();
  45420. }
  45421. else
  45422. {
  45423. subItems.clear();
  45424. }
  45425. }
  45426. }
  45427. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  45428. {
  45429. if (newItem != 0)
  45430. {
  45431. newItem->parentItem = this;
  45432. newItem->setOwnerView (ownerView);
  45433. newItem->y = 0;
  45434. newItem->itemHeight = newItem->getItemHeight();
  45435. newItem->totalHeight = 0;
  45436. newItem->itemWidth = newItem->getItemWidth();
  45437. newItem->totalWidth = 0;
  45438. if (ownerView != 0)
  45439. {
  45440. const ScopedLock sl (ownerView->nodeAlterationLock);
  45441. subItems.insert (insertPosition, newItem);
  45442. treeHasChanged();
  45443. if (newItem->isOpen())
  45444. newItem->itemOpennessChanged (true);
  45445. }
  45446. else
  45447. {
  45448. subItems.insert (insertPosition, newItem);
  45449. if (newItem->isOpen())
  45450. newItem->itemOpennessChanged (true);
  45451. }
  45452. }
  45453. }
  45454. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  45455. {
  45456. if (ownerView != 0)
  45457. ownerView->nodeAlterationLock.enter();
  45458. if (((unsigned int) index) < (unsigned int) subItems.size())
  45459. {
  45460. subItems.remove (index, deleteItem);
  45461. treeHasChanged();
  45462. }
  45463. if (ownerView != 0)
  45464. ownerView->nodeAlterationLock.exit();
  45465. }
  45466. bool TreeViewItem::isOpen() const throw()
  45467. {
  45468. if (openness == opennessDefault)
  45469. return ownerView != 0 && ownerView->defaultOpenness;
  45470. else
  45471. return openness == opennessOpen;
  45472. }
  45473. void TreeViewItem::setOpen (const bool shouldBeOpen)
  45474. {
  45475. if (isOpen() != shouldBeOpen)
  45476. {
  45477. openness = shouldBeOpen ? opennessOpen
  45478. : opennessClosed;
  45479. treeHasChanged();
  45480. itemOpennessChanged (isOpen());
  45481. }
  45482. }
  45483. bool TreeViewItem::isSelected() const throw()
  45484. {
  45485. return selected;
  45486. }
  45487. void TreeViewItem::deselectAllRecursively()
  45488. {
  45489. setSelected (false, false);
  45490. for (int i = 0; i < subItems.size(); ++i)
  45491. subItems.getUnchecked(i)->deselectAllRecursively();
  45492. }
  45493. void TreeViewItem::setSelected (const bool shouldBeSelected,
  45494. const bool deselectOtherItemsFirst)
  45495. {
  45496. if (shouldBeSelected && ! canBeSelected())
  45497. return;
  45498. if (deselectOtherItemsFirst)
  45499. getTopLevelItem()->deselectAllRecursively();
  45500. if (shouldBeSelected != selected)
  45501. {
  45502. selected = shouldBeSelected;
  45503. if (ownerView != 0)
  45504. ownerView->repaint();
  45505. itemSelectionChanged (shouldBeSelected);
  45506. }
  45507. }
  45508. void TreeViewItem::paintItem (Graphics&, int, int)
  45509. {
  45510. }
  45511. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  45512. {
  45513. ownerView->getLookAndFeel()
  45514. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  45515. }
  45516. void TreeViewItem::itemClicked (const MouseEvent&)
  45517. {
  45518. }
  45519. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  45520. {
  45521. if (mightContainSubItems())
  45522. setOpen (! isOpen());
  45523. }
  45524. void TreeViewItem::itemSelectionChanged (bool)
  45525. {
  45526. }
  45527. const String TreeViewItem::getTooltip()
  45528. {
  45529. return String::empty;
  45530. }
  45531. const String TreeViewItem::getDragSourceDescription()
  45532. {
  45533. return String::empty;
  45534. }
  45535. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  45536. {
  45537. return false;
  45538. }
  45539. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  45540. {
  45541. }
  45542. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45543. {
  45544. return false;
  45545. }
  45546. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  45547. {
  45548. }
  45549. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  45550. {
  45551. const int indentX = getIndentX();
  45552. int width = itemWidth;
  45553. if (ownerView != 0 && width < 0)
  45554. width = ownerView->viewport->getViewWidth() - indentX;
  45555. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  45556. if (relativeToTreeViewTopLeft)
  45557. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  45558. r.getY() - ownerView->viewport->getViewPositionY());
  45559. return r;
  45560. }
  45561. void TreeViewItem::treeHasChanged() const throw()
  45562. {
  45563. if (ownerView != 0)
  45564. ownerView->itemsChanged();
  45565. }
  45566. void TreeViewItem::repaintItem() const
  45567. {
  45568. if (ownerView != 0 && areAllParentsOpen())
  45569. {
  45570. const Rectangle<int> r (getItemPosition (true));
  45571. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  45572. }
  45573. }
  45574. bool TreeViewItem::areAllParentsOpen() const throw()
  45575. {
  45576. return parentItem == 0
  45577. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  45578. }
  45579. void TreeViewItem::updatePositions (int newY)
  45580. {
  45581. y = newY;
  45582. itemHeight = getItemHeight();
  45583. totalHeight = itemHeight;
  45584. itemWidth = getItemWidth();
  45585. totalWidth = jmax (itemWidth, 0) + getIndentX();
  45586. if (isOpen())
  45587. {
  45588. newY += totalHeight;
  45589. for (int i = 0; i < subItems.size(); ++i)
  45590. {
  45591. TreeViewItem* const ti = subItems.getUnchecked(i);
  45592. ti->updatePositions (newY);
  45593. newY += ti->totalHeight;
  45594. totalHeight += ti->totalHeight;
  45595. totalWidth = jmax (totalWidth, ti->totalWidth);
  45596. }
  45597. }
  45598. }
  45599. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  45600. {
  45601. TreeViewItem* result = this;
  45602. TreeViewItem* item = this;
  45603. while (item->parentItem != 0)
  45604. {
  45605. item = item->parentItem;
  45606. if (! item->isOpen())
  45607. result = item;
  45608. }
  45609. return result;
  45610. }
  45611. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  45612. {
  45613. ownerView = newOwner;
  45614. for (int i = subItems.size(); --i >= 0;)
  45615. subItems.getUnchecked(i)->setOwnerView (newOwner);
  45616. }
  45617. int TreeViewItem::getIndentX() const throw()
  45618. {
  45619. const int indentWidth = ownerView->getIndentSize();
  45620. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45621. if (! ownerView->openCloseButtonsVisible)
  45622. x -= indentWidth;
  45623. TreeViewItem* p = parentItem;
  45624. while (p != 0)
  45625. {
  45626. x += indentWidth;
  45627. p = p->parentItem;
  45628. }
  45629. return x;
  45630. }
  45631. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45632. {
  45633. drawsInLeftMargin = canDrawInLeftMargin;
  45634. }
  45635. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45636. {
  45637. jassert (ownerView != 0);
  45638. if (ownerView == 0)
  45639. return;
  45640. const int indent = getIndentX();
  45641. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45642. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45643. const float halfH = itemHeight * 0.5f;
  45644. int depth = 0;
  45645. TreeViewItem* p = parentItem;
  45646. while (p != 0)
  45647. {
  45648. ++depth;
  45649. p = p->parentItem;
  45650. }
  45651. if (! ownerView->rootItemVisible)
  45652. --depth;
  45653. const int indentWidth = ownerView->getIndentSize();
  45654. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45655. {
  45656. float x = (depth + 0.5f) * indentWidth;
  45657. if (depth >= 0)
  45658. {
  45659. if (parentItem != 0 && parentItem->drawLinesInside)
  45660. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45661. if ((parentItem != 0 && parentItem->drawLinesInside)
  45662. || (parentItem == 0 && drawLinesInside))
  45663. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45664. }
  45665. p = parentItem;
  45666. int d = depth;
  45667. while (p != 0 && --d >= 0)
  45668. {
  45669. x -= (float) indentWidth;
  45670. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45671. && ! p->isLastOfSiblings())
  45672. {
  45673. g.drawLine (x, 0, x, (float) itemHeight);
  45674. }
  45675. p = p->parentItem;
  45676. }
  45677. if (mightContainSubItems())
  45678. {
  45679. g.saveState();
  45680. g.setOrigin (depth * indentWidth, 0);
  45681. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45682. paintOpenCloseButton (g, indentWidth, itemHeight,
  45683. ((TreeViewContentComponent*) ownerView->viewport->getViewedComponent())
  45684. ->isMouseOverButton (this));
  45685. g.restoreState();
  45686. }
  45687. }
  45688. {
  45689. g.saveState();
  45690. g.setOrigin (indent, 0);
  45691. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45692. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45693. paintItem (g, itemW, itemHeight);
  45694. g.restoreState();
  45695. }
  45696. if (isOpen())
  45697. {
  45698. const Rectangle<int> clip (g.getClipBounds());
  45699. for (int i = 0; i < subItems.size(); ++i)
  45700. {
  45701. TreeViewItem* const ti = subItems.getUnchecked(i);
  45702. const int relY = ti->y - y;
  45703. if (relY >= clip.getBottom())
  45704. break;
  45705. if (relY + ti->totalHeight >= clip.getY())
  45706. {
  45707. g.saveState();
  45708. g.setOrigin (0, relY);
  45709. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45710. ti->paintRecursively (g, width);
  45711. g.restoreState();
  45712. }
  45713. }
  45714. }
  45715. }
  45716. bool TreeViewItem::isLastOfSiblings() const throw()
  45717. {
  45718. return parentItem == 0
  45719. || parentItem->subItems.getLast() == this;
  45720. }
  45721. int TreeViewItem::getIndexInParent() const throw()
  45722. {
  45723. if (parentItem == 0)
  45724. return 0;
  45725. return parentItem->subItems.indexOf (this);
  45726. }
  45727. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45728. {
  45729. return (parentItem == 0) ? this
  45730. : parentItem->getTopLevelItem();
  45731. }
  45732. int TreeViewItem::getNumRows() const throw()
  45733. {
  45734. int num = 1;
  45735. if (isOpen())
  45736. {
  45737. for (int i = subItems.size(); --i >= 0;)
  45738. num += subItems.getUnchecked(i)->getNumRows();
  45739. }
  45740. return num;
  45741. }
  45742. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45743. {
  45744. if (index == 0)
  45745. return this;
  45746. if (index > 0 && isOpen())
  45747. {
  45748. --index;
  45749. for (int i = 0; i < subItems.size(); ++i)
  45750. {
  45751. TreeViewItem* const item = subItems.getUnchecked(i);
  45752. if (index == 0)
  45753. return item;
  45754. const int numRows = item->getNumRows();
  45755. if (numRows > index)
  45756. return item->getItemOnRow (index);
  45757. index -= numRows;
  45758. }
  45759. }
  45760. return 0;
  45761. }
  45762. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45763. {
  45764. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45765. {
  45766. const int h = itemHeight;
  45767. if (targetY < h)
  45768. return this;
  45769. if (isOpen())
  45770. {
  45771. targetY -= h;
  45772. for (int i = 0; i < subItems.size(); ++i)
  45773. {
  45774. TreeViewItem* const ti = subItems.getUnchecked(i);
  45775. if (targetY < ti->totalHeight)
  45776. return ti->findItemRecursively (targetY);
  45777. targetY -= ti->totalHeight;
  45778. }
  45779. }
  45780. }
  45781. return 0;
  45782. }
  45783. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45784. {
  45785. int total = 0;
  45786. if (isSelected())
  45787. ++total;
  45788. for (int i = subItems.size(); --i >= 0;)
  45789. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45790. return total;
  45791. }
  45792. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45793. {
  45794. if (isSelected())
  45795. {
  45796. if (index == 0)
  45797. return this;
  45798. --index;
  45799. }
  45800. if (index >= 0)
  45801. {
  45802. for (int i = 0; i < subItems.size(); ++i)
  45803. {
  45804. TreeViewItem* const item = subItems.getUnchecked(i);
  45805. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45806. if (found != 0)
  45807. return found;
  45808. index -= item->countSelectedItemsRecursively();
  45809. }
  45810. }
  45811. return 0;
  45812. }
  45813. int TreeViewItem::getRowNumberInTree() const throw()
  45814. {
  45815. if (parentItem != 0 && ownerView != 0)
  45816. {
  45817. int n = 1 + parentItem->getRowNumberInTree();
  45818. int ourIndex = parentItem->subItems.indexOf (this);
  45819. jassert (ourIndex >= 0);
  45820. while (--ourIndex >= 0)
  45821. n += parentItem->subItems [ourIndex]->getNumRows();
  45822. if (parentItem->parentItem == 0
  45823. && ! ownerView->rootItemVisible)
  45824. --n;
  45825. return n;
  45826. }
  45827. else
  45828. {
  45829. return 0;
  45830. }
  45831. }
  45832. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45833. {
  45834. drawLinesInside = drawLines;
  45835. }
  45836. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45837. {
  45838. if (recurse && isOpen() && subItems.size() > 0)
  45839. return subItems [0];
  45840. if (parentItem != 0)
  45841. {
  45842. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45843. if (nextIndex >= parentItem->subItems.size())
  45844. return parentItem->getNextVisibleItem (false);
  45845. return parentItem->subItems [nextIndex];
  45846. }
  45847. return 0;
  45848. }
  45849. const String TreeViewItem::getItemIdentifierString() const
  45850. {
  45851. String s;
  45852. if (parentItem != 0)
  45853. s = parentItem->getItemIdentifierString();
  45854. return s + T("/") + getUniqueName().replaceCharacter (T('/'), T('\\'));
  45855. }
  45856. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45857. {
  45858. const String uid (getUniqueName());
  45859. if (uid == identifierString)
  45860. return this;
  45861. if (identifierString.startsWith (uid + T("/")))
  45862. {
  45863. const String remainingPath (identifierString.substring (uid.length() + 1));
  45864. bool wasOpen = isOpen();
  45865. setOpen (true);
  45866. for (int i = subItems.size(); --i >= 0;)
  45867. {
  45868. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45869. if (item != 0)
  45870. return item;
  45871. }
  45872. setOpen (wasOpen);
  45873. }
  45874. return 0;
  45875. }
  45876. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45877. {
  45878. if (e.hasTagName (T("CLOSED")))
  45879. {
  45880. setOpen (false);
  45881. }
  45882. else if (e.hasTagName (T("OPEN")))
  45883. {
  45884. setOpen (true);
  45885. forEachXmlChildElement (e, n)
  45886. {
  45887. const String id (n->getStringAttribute (T("id")));
  45888. for (int i = 0; i < subItems.size(); ++i)
  45889. {
  45890. TreeViewItem* const ti = subItems.getUnchecked(i);
  45891. if (ti->getUniqueName() == id)
  45892. {
  45893. ti->restoreOpennessState (*n);
  45894. break;
  45895. }
  45896. }
  45897. }
  45898. }
  45899. }
  45900. XmlElement* TreeViewItem::getOpennessState() const throw()
  45901. {
  45902. const String name (getUniqueName());
  45903. if (name.isNotEmpty())
  45904. {
  45905. XmlElement* e;
  45906. if (isOpen())
  45907. {
  45908. e = new XmlElement (T("OPEN"));
  45909. for (int i = 0; i < subItems.size(); ++i)
  45910. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45911. }
  45912. else
  45913. {
  45914. e = new XmlElement (T("CLOSED"));
  45915. }
  45916. e->setAttribute (T("id"), name);
  45917. return e;
  45918. }
  45919. else
  45920. {
  45921. // trying to save the openness for an element that has no name - this won't
  45922. // work because it needs the names to identify what to open.
  45923. jassertfalse
  45924. }
  45925. return 0;
  45926. }
  45927. END_JUCE_NAMESPACE
  45928. /*** End of inlined file: juce_TreeView.cpp ***/
  45929. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45930. BEGIN_JUCE_NAMESPACE
  45931. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45932. : fileList (listToShow)
  45933. {
  45934. }
  45935. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45936. {
  45937. }
  45938. FileBrowserListener::~FileBrowserListener()
  45939. {
  45940. }
  45941. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw()
  45942. {
  45943. jassert (listener != 0);
  45944. if (listener != 0)
  45945. listeners.add (listener);
  45946. }
  45947. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw()
  45948. {
  45949. listeners.removeValue (listener);
  45950. }
  45951. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45952. {
  45953. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45954. for (int i = listeners.size(); --i >= 0;)
  45955. {
  45956. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  45957. if (deletionWatcher.hasBeenDeleted())
  45958. return;
  45959. i = jmin (i, listeners.size() - 1);
  45960. }
  45961. }
  45962. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45963. {
  45964. if (fileList.getDirectory().exists())
  45965. {
  45966. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45967. for (int i = listeners.size(); --i >= 0;)
  45968. {
  45969. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (file, e);
  45970. if (deletionWatcher.hasBeenDeleted())
  45971. return;
  45972. i = jmin (i, listeners.size() - 1);
  45973. }
  45974. }
  45975. }
  45976. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45977. {
  45978. if (fileList.getDirectory().exists())
  45979. {
  45980. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45981. for (int i = listeners.size(); --i >= 0;)
  45982. {
  45983. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (file);
  45984. if (deletionWatcher.hasBeenDeleted())
  45985. return;
  45986. i = jmin (i, listeners.size() - 1);
  45987. }
  45988. }
  45989. }
  45990. END_JUCE_NAMESPACE
  45991. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45992. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45993. BEGIN_JUCE_NAMESPACE
  45994. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45995. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45996. Time* creationTime, bool* isReadOnly);
  45997. bool juce_findFileNext (void* handle, String& resultFile,
  45998. bool* isDirectory, bool* isHidden, int64* fileSize,
  45999. Time* modTime, Time* creationTime, bool* isReadOnly);
  46000. void juce_findFileClose (void* handle);
  46001. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  46002. TimeSliceThread& thread_)
  46003. : fileFilter (fileFilter_),
  46004. thread (thread_),
  46005. includeDirectories (false),
  46006. includeFiles (false),
  46007. ignoreHiddenFiles (true),
  46008. fileFindHandle (0),
  46009. shouldStop (true)
  46010. {
  46011. }
  46012. DirectoryContentsList::~DirectoryContentsList()
  46013. {
  46014. clear();
  46015. }
  46016. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  46017. {
  46018. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  46019. }
  46020. const File& DirectoryContentsList::getDirectory() const
  46021. {
  46022. return root;
  46023. }
  46024. void DirectoryContentsList::setDirectory (const File& directory,
  46025. const bool includeDirectories_,
  46026. const bool includeFiles_)
  46027. {
  46028. if (directory != root
  46029. || includeDirectories != includeDirectories_
  46030. || includeFiles != includeFiles_)
  46031. {
  46032. clear();
  46033. root = directory;
  46034. includeDirectories = includeDirectories_;
  46035. includeFiles = includeFiles_;
  46036. refresh();
  46037. }
  46038. }
  46039. void DirectoryContentsList::clear()
  46040. {
  46041. shouldStop = true;
  46042. thread.removeTimeSliceClient (this);
  46043. if (fileFindHandle != 0)
  46044. {
  46045. juce_findFileClose (fileFindHandle);
  46046. fileFindHandle = 0;
  46047. }
  46048. if (files.size() > 0)
  46049. {
  46050. files.clear();
  46051. changed();
  46052. }
  46053. }
  46054. void DirectoryContentsList::refresh()
  46055. {
  46056. clear();
  46057. if (root.isDirectory())
  46058. {
  46059. String fileFound;
  46060. bool fileFoundIsDir, isHidden, isReadOnly;
  46061. int64 fileSize;
  46062. Time modTime, creationTime;
  46063. String path (root.getFullPathName());
  46064. if (! path.endsWithChar (File::separator))
  46065. path += File::separator;
  46066. jassert (fileFindHandle == 0);
  46067. fileFindHandle = juce_findFileStart (path, T("*"), fileFound,
  46068. &fileFoundIsDir,
  46069. &isHidden,
  46070. &fileSize,
  46071. &modTime,
  46072. &creationTime,
  46073. &isReadOnly);
  46074. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  46075. {
  46076. if (addFile (fileFound, fileFoundIsDir, isHidden,
  46077. fileSize, modTime, creationTime, isReadOnly))
  46078. {
  46079. changed();
  46080. }
  46081. }
  46082. shouldStop = false;
  46083. thread.addTimeSliceClient (this);
  46084. }
  46085. }
  46086. int DirectoryContentsList::getNumFiles() const
  46087. {
  46088. return files.size();
  46089. }
  46090. bool DirectoryContentsList::getFileInfo (const int index,
  46091. FileInfo& result) const
  46092. {
  46093. const ScopedLock sl (fileListLock);
  46094. const FileInfo* const info = files [index];
  46095. if (info != 0)
  46096. {
  46097. result = *info;
  46098. return true;
  46099. }
  46100. return false;
  46101. }
  46102. const File DirectoryContentsList::getFile (const int index) const
  46103. {
  46104. const ScopedLock sl (fileListLock);
  46105. const FileInfo* const info = files [index];
  46106. if (info != 0)
  46107. return root.getChildFile (info->filename);
  46108. return File::nonexistent;
  46109. }
  46110. bool DirectoryContentsList::isStillLoading() const
  46111. {
  46112. return fileFindHandle != 0;
  46113. }
  46114. void DirectoryContentsList::changed()
  46115. {
  46116. sendChangeMessage (this);
  46117. }
  46118. bool DirectoryContentsList::useTimeSlice()
  46119. {
  46120. const uint32 startTime = Time::getApproximateMillisecondCounter();
  46121. bool hasChanged = false;
  46122. for (int i = 100; --i >= 0;)
  46123. {
  46124. if (! checkNextFile (hasChanged))
  46125. {
  46126. if (hasChanged)
  46127. changed();
  46128. return false;
  46129. }
  46130. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  46131. break;
  46132. }
  46133. if (hasChanged)
  46134. changed();
  46135. return true;
  46136. }
  46137. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  46138. {
  46139. if (fileFindHandle != 0)
  46140. {
  46141. String fileFound;
  46142. bool fileFoundIsDir, isHidden, isReadOnly;
  46143. int64 fileSize;
  46144. Time modTime, creationTime;
  46145. if (juce_findFileNext (fileFindHandle, fileFound,
  46146. &fileFoundIsDir, &isHidden,
  46147. &fileSize,
  46148. &modTime,
  46149. &creationTime,
  46150. &isReadOnly))
  46151. {
  46152. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  46153. modTime, creationTime, isReadOnly))
  46154. {
  46155. hasChanged = true;
  46156. }
  46157. return true;
  46158. }
  46159. else
  46160. {
  46161. juce_findFileClose (fileFindHandle);
  46162. fileFindHandle = 0;
  46163. }
  46164. }
  46165. return false;
  46166. }
  46167. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  46168. const DirectoryContentsList::FileInfo* const second)
  46169. {
  46170. #if JUCE_WINDOWS
  46171. if (first->isDirectory != second->isDirectory)
  46172. return first->isDirectory ? -1 : 1;
  46173. #endif
  46174. return first->filename.compareIgnoreCase (second->filename);
  46175. }
  46176. bool DirectoryContentsList::addFile (const String& filename,
  46177. const bool isDir,
  46178. const bool isHidden,
  46179. const int64 fileSize,
  46180. const Time& modTime,
  46181. const Time& creationTime,
  46182. const bool isReadOnly)
  46183. {
  46184. if (filename == T("..")
  46185. || filename == T(".")
  46186. || (ignoreHiddenFiles && isHidden))
  46187. return false;
  46188. const File file (root.getChildFile (filename));
  46189. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  46190. && (fileFilter == 0
  46191. || ((! isDir) && fileFilter->isFileSuitable (file))
  46192. || (isDir && fileFilter->isDirectorySuitable (file))))
  46193. {
  46194. ScopedPointer <FileInfo> info (new FileInfo());
  46195. info->filename = filename;
  46196. info->fileSize = fileSize;
  46197. info->modificationTime = modTime;
  46198. info->creationTime = creationTime;
  46199. info->isDirectory = isDir;
  46200. info->isReadOnly = isReadOnly;
  46201. const ScopedLock sl (fileListLock);
  46202. for (int i = files.size(); --i >= 0;)
  46203. if (files.getUnchecked(i)->filename == info->filename)
  46204. return false;
  46205. files.addSorted (*this, info.release());
  46206. return true;
  46207. }
  46208. return false;
  46209. }
  46210. END_JUCE_NAMESPACE
  46211. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  46212. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  46213. BEGIN_JUCE_NAMESPACE
  46214. FileBrowserComponent::FileBrowserComponent (int flags_,
  46215. const File& initialFileOrDirectory,
  46216. const FileFilter* fileFilter_,
  46217. FilePreviewComponent* previewComp_)
  46218. : FileFilter (String::empty),
  46219. fileFilter (fileFilter_),
  46220. flags (flags_),
  46221. previewComp (previewComp_),
  46222. thread ("Juce FileBrowser")
  46223. {
  46224. // You need to specify one or other of the open/save flags..
  46225. jassert ((flags & (saveMode | openMode)) != 0);
  46226. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  46227. // You need to specify at least one of these flags..
  46228. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  46229. String filename;
  46230. if (initialFileOrDirectory == File::nonexistent)
  46231. {
  46232. currentRoot = File::getCurrentWorkingDirectory();
  46233. }
  46234. else if (initialFileOrDirectory.isDirectory())
  46235. {
  46236. currentRoot = initialFileOrDirectory;
  46237. }
  46238. else
  46239. {
  46240. chosenFiles.add (initialFileOrDirectory);
  46241. currentRoot = initialFileOrDirectory.getParentDirectory();
  46242. filename = initialFileOrDirectory.getFileName();
  46243. }
  46244. fileList = new DirectoryContentsList (this, thread);
  46245. if ((flags & useTreeView) != 0)
  46246. {
  46247. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  46248. if ((flags & canSelectMultipleItems) != 0)
  46249. tree->setMultiSelectEnabled (true);
  46250. addAndMakeVisible (tree);
  46251. fileListComponent = tree;
  46252. }
  46253. else
  46254. {
  46255. FileListComponent* const list = new FileListComponent (*fileList);
  46256. list->setOutlineThickness (1);
  46257. if ((flags & canSelectMultipleItems) != 0)
  46258. list->setMultipleSelectionEnabled (true);
  46259. addAndMakeVisible (list);
  46260. fileListComponent = list;
  46261. }
  46262. fileListComponent->addListener (this);
  46263. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  46264. currentPathBox->setEditableText (true);
  46265. StringArray rootNames, rootPaths;
  46266. const BitArray separators (getRoots (rootNames, rootPaths));
  46267. for (int i = 0; i < rootNames.size(); ++i)
  46268. {
  46269. if (separators [i])
  46270. currentPathBox->addSeparator();
  46271. currentPathBox->addItem (rootNames[i], i + 1);
  46272. }
  46273. currentPathBox->addSeparator();
  46274. currentPathBox->addListener (this);
  46275. addAndMakeVisible (filenameBox = new TextEditor());
  46276. filenameBox->setMultiLine (false);
  46277. filenameBox->setSelectAllWhenFocused (true);
  46278. filenameBox->setText (filename, false);
  46279. filenameBox->addListener (this);
  46280. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  46281. Label* label = new Label ("f", TRANS("file:"));
  46282. addAndMakeVisible (label);
  46283. label->attachToComponent (filenameBox, true);
  46284. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  46285. goUpButton->addButtonListener (this);
  46286. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  46287. if (previewComp != 0)
  46288. addAndMakeVisible (previewComp);
  46289. setRoot (currentRoot);
  46290. thread.startThread (4);
  46291. }
  46292. FileBrowserComponent::~FileBrowserComponent()
  46293. {
  46294. if (previewComp != 0)
  46295. removeChildComponent (previewComp);
  46296. deleteAllChildren();
  46297. fileList = 0;
  46298. thread.stopThread (10000);
  46299. }
  46300. void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw()
  46301. {
  46302. jassert (newListener != 0)
  46303. if (newListener != 0)
  46304. listeners.add (newListener);
  46305. }
  46306. void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw()
  46307. {
  46308. listeners.removeValue (listener);
  46309. }
  46310. bool FileBrowserComponent::isSaveMode() const throw()
  46311. {
  46312. return (flags & saveMode) != 0;
  46313. }
  46314. int FileBrowserComponent::getNumSelectedFiles() const throw()
  46315. {
  46316. if (chosenFiles.size() == 0 && currentFileIsValid())
  46317. return 1;
  46318. return chosenFiles.size();
  46319. }
  46320. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  46321. {
  46322. if (! filenameBox->isReadOnly())
  46323. return currentRoot.getChildFile (filenameBox->getText());
  46324. else
  46325. return chosenFiles[index];
  46326. }
  46327. bool FileBrowserComponent::currentFileIsValid() const
  46328. {
  46329. if (isSaveMode())
  46330. return ! getSelectedFile (0).isDirectory();
  46331. else
  46332. return getSelectedFile (0).exists();
  46333. }
  46334. const File FileBrowserComponent::getHighlightedFile() const throw()
  46335. {
  46336. return fileListComponent->getSelectedFile (0);
  46337. }
  46338. bool FileBrowserComponent::isFileSuitable (const File& file) const
  46339. {
  46340. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  46341. : false;
  46342. }
  46343. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  46344. {
  46345. return true;
  46346. }
  46347. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  46348. {
  46349. if (f.isDirectory())
  46350. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  46351. return (flags & canSelectFiles) != 0 && f.exists()
  46352. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  46353. }
  46354. const File FileBrowserComponent::getRoot() const
  46355. {
  46356. return currentRoot;
  46357. }
  46358. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  46359. {
  46360. if (currentRoot != newRootDirectory)
  46361. {
  46362. fileListComponent->scrollToTop();
  46363. String path (newRootDirectory.getFullPathName());
  46364. if (path.isEmpty())
  46365. path += File::separator;
  46366. StringArray rootNames, rootPaths;
  46367. getRoots (rootNames, rootPaths);
  46368. if (! rootPaths.contains (path, true))
  46369. {
  46370. bool alreadyListed = false;
  46371. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  46372. {
  46373. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  46374. {
  46375. alreadyListed = true;
  46376. break;
  46377. }
  46378. }
  46379. if (! alreadyListed)
  46380. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  46381. }
  46382. }
  46383. currentRoot = newRootDirectory;
  46384. fileList->setDirectory (currentRoot, true, true);
  46385. String currentRootName (currentRoot.getFullPathName());
  46386. if (currentRootName.isEmpty())
  46387. currentRootName += File::separator;
  46388. currentPathBox->setText (currentRootName, true);
  46389. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  46390. && currentRoot.getParentDirectory() != currentRoot);
  46391. }
  46392. void FileBrowserComponent::goUp()
  46393. {
  46394. setRoot (getRoot().getParentDirectory());
  46395. }
  46396. void FileBrowserComponent::refresh()
  46397. {
  46398. fileList->refresh();
  46399. }
  46400. const String FileBrowserComponent::getActionVerb() const
  46401. {
  46402. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  46403. }
  46404. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  46405. {
  46406. return previewComp;
  46407. }
  46408. void FileBrowserComponent::resized()
  46409. {
  46410. getLookAndFeel()
  46411. .layoutFileBrowserComponent (*this, fileListComponent,
  46412. previewComp, currentPathBox,
  46413. filenameBox, goUpButton);
  46414. }
  46415. void FileBrowserComponent::sendListenerChangeMessage()
  46416. {
  46417. ComponentDeletionWatcher deletionWatcher (this);
  46418. if (previewComp != 0)
  46419. previewComp->selectedFileChanged (getSelectedFile (0));
  46420. jassert (! deletionWatcher.hasBeenDeleted());
  46421. for (int i = listeners.size(); --i >= 0;)
  46422. {
  46423. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  46424. if (deletionWatcher.hasBeenDeleted())
  46425. return;
  46426. i = jmin (i, listeners.size() - 1);
  46427. }
  46428. }
  46429. void FileBrowserComponent::selectionChanged()
  46430. {
  46431. StringArray newFilenames;
  46432. bool resetChosenFiles = true;
  46433. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  46434. {
  46435. const File f (fileListComponent->getSelectedFile (i));
  46436. if (isFileOrDirSuitable (f))
  46437. {
  46438. if (resetChosenFiles)
  46439. {
  46440. chosenFiles.clear();
  46441. resetChosenFiles = false;
  46442. }
  46443. chosenFiles.add (f);
  46444. newFilenames.add (f.getRelativePathFrom (getRoot()));
  46445. }
  46446. }
  46447. if (newFilenames.size() > 0)
  46448. filenameBox->setText (newFilenames.joinIntoString (T(", ")), false);
  46449. sendListenerChangeMessage();
  46450. }
  46451. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  46452. {
  46453. ComponentDeletionWatcher deletionWatcher (this);
  46454. for (int i = listeners.size(); --i >= 0;)
  46455. {
  46456. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (f, e);
  46457. if (deletionWatcher.hasBeenDeleted())
  46458. return;
  46459. i = jmin (i, listeners.size() - 1);
  46460. }
  46461. }
  46462. void FileBrowserComponent::fileDoubleClicked (const File& f)
  46463. {
  46464. if (f.isDirectory())
  46465. {
  46466. setRoot (f);
  46467. }
  46468. else
  46469. {
  46470. ComponentDeletionWatcher deletionWatcher (this);
  46471. for (int i = listeners.size(); --i >= 0;)
  46472. {
  46473. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (f);
  46474. if (deletionWatcher.hasBeenDeleted())
  46475. return;
  46476. i = jmin (i, listeners.size() - 1);
  46477. }
  46478. }
  46479. }
  46480. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  46481. {
  46482. #if JUCE_LINUX || JUCE_WINDOWS
  46483. if (key.getModifiers().isCommandDown()
  46484. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  46485. {
  46486. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  46487. fileList->refresh();
  46488. return true;
  46489. }
  46490. #endif
  46491. return false;
  46492. }
  46493. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  46494. {
  46495. sendListenerChangeMessage();
  46496. }
  46497. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  46498. {
  46499. if (filenameBox->getText().containsChar (File::separator))
  46500. {
  46501. const File f (currentRoot.getChildFile (filenameBox->getText()));
  46502. if (f.isDirectory())
  46503. {
  46504. setRoot (f);
  46505. chosenFiles.clear();
  46506. filenameBox->setText (String::empty);
  46507. }
  46508. else
  46509. {
  46510. setRoot (f.getParentDirectory());
  46511. chosenFiles.clear();
  46512. chosenFiles.add (f);
  46513. filenameBox->setText (f.getFileName());
  46514. }
  46515. }
  46516. else
  46517. {
  46518. fileDoubleClicked (getSelectedFile (0));
  46519. }
  46520. }
  46521. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  46522. {
  46523. }
  46524. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  46525. {
  46526. if (! isSaveMode())
  46527. selectionChanged();
  46528. }
  46529. void FileBrowserComponent::buttonClicked (Button*)
  46530. {
  46531. goUp();
  46532. }
  46533. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  46534. {
  46535. const String newText (currentPathBox->getText().trim().unquoted());
  46536. if (newText.isNotEmpty())
  46537. {
  46538. const int index = currentPathBox->getSelectedId() - 1;
  46539. StringArray rootNames, rootPaths;
  46540. getRoots (rootNames, rootPaths);
  46541. if (rootPaths [index].isNotEmpty())
  46542. {
  46543. setRoot (File (rootPaths [index]));
  46544. }
  46545. else
  46546. {
  46547. File f (newText);
  46548. for (;;)
  46549. {
  46550. if (f.isDirectory())
  46551. {
  46552. setRoot (f);
  46553. break;
  46554. }
  46555. if (f.getParentDirectory() == f)
  46556. break;
  46557. f = f.getParentDirectory();
  46558. }
  46559. }
  46560. }
  46561. }
  46562. const BitArray FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  46563. {
  46564. BitArray separators;
  46565. #if JUCE_WINDOWS
  46566. Array<File> roots;
  46567. File::findFileSystemRoots (roots);
  46568. rootPaths.clear();
  46569. for (int i = 0; i < roots.size(); ++i)
  46570. {
  46571. const File& drive = roots.getReference(i);
  46572. String name (drive.getFullPathName());
  46573. rootPaths.add (name);
  46574. if (drive.isOnHardDisk())
  46575. {
  46576. String volume (drive.getVolumeLabel());
  46577. if (volume.isEmpty())
  46578. volume = TRANS("Hard Drive");
  46579. name << " [" << drive.getVolumeLabel() << ']';
  46580. }
  46581. else if (drive.isOnCDRomDrive())
  46582. {
  46583. name << TRANS(" [CD/DVD drive]");
  46584. }
  46585. rootNames.add (name);
  46586. }
  46587. separators.setBit (rootPaths.size());
  46588. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46589. rootNames.add ("Documents");
  46590. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46591. rootNames.add ("Desktop");
  46592. #endif
  46593. #if JUCE_MAC
  46594. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46595. rootNames.add ("Home folder");
  46596. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46597. rootNames.add ("Documents");
  46598. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46599. rootNames.add ("Desktop");
  46600. separators.setBit (rootPaths.size());
  46601. Array <File> volumes;
  46602. File vol ("/Volumes");
  46603. vol.findChildFiles (volumes, File::findDirectories, false);
  46604. for (int i = 0; i < volumes.size(); ++i)
  46605. {
  46606. const File& volume = volumes.getReference(i);
  46607. if (volume.isDirectory() && ! volume.getFileName().startsWithChar (T('.')))
  46608. {
  46609. rootPaths.add (volume.getFullPathName());
  46610. rootNames.add (volume.getFileName());
  46611. }
  46612. }
  46613. #endif
  46614. #if JUCE_LINUX
  46615. rootPaths.add ("/");
  46616. rootNames.add ("/");
  46617. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46618. rootNames.add ("Home folder");
  46619. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46620. rootNames.add ("Desktop");
  46621. #endif
  46622. return separators;
  46623. }
  46624. END_JUCE_NAMESPACE
  46625. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  46626. /*** Start of inlined file: juce_FileChooser.cpp ***/
  46627. BEGIN_JUCE_NAMESPACE
  46628. FileChooser::FileChooser (const String& chooserBoxTitle,
  46629. const File& currentFileOrDirectory,
  46630. const String& fileFilters,
  46631. const bool useNativeDialogBox_)
  46632. : title (chooserBoxTitle),
  46633. filters (fileFilters),
  46634. startingFile (currentFileOrDirectory),
  46635. useNativeDialogBox (useNativeDialogBox_)
  46636. {
  46637. #if JUCE_LINUX
  46638. useNativeDialogBox = false;
  46639. #endif
  46640. if (! fileFilters.containsNonWhitespaceChars())
  46641. filters = T("*");
  46642. }
  46643. FileChooser::~FileChooser()
  46644. {
  46645. }
  46646. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  46647. {
  46648. return showDialog (false, true, false, false, false, previewComponent);
  46649. }
  46650. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  46651. {
  46652. return showDialog (false, true, false, false, true, previewComponent);
  46653. }
  46654. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  46655. {
  46656. return showDialog (true, true, false, false, true, previewComponent);
  46657. }
  46658. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46659. {
  46660. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46661. }
  46662. bool FileChooser::browseForDirectory()
  46663. {
  46664. return showDialog (true, false, false, false, false, 0);
  46665. }
  46666. const File FileChooser::getResult() const
  46667. {
  46668. // if you've used a multiple-file select, you should use the getResults() method
  46669. // to retrieve all the files that were chosen.
  46670. jassert (results.size() <= 1);
  46671. return results.getFirst();
  46672. }
  46673. const Array<File>& FileChooser::getResults() const
  46674. {
  46675. return results;
  46676. }
  46677. bool FileChooser::showDialog (const bool selectsDirectories,
  46678. const bool selectsFiles,
  46679. const bool isSave,
  46680. const bool warnAboutOverwritingExistingFiles,
  46681. const bool selectMultipleFiles,
  46682. FilePreviewComponent* const previewComponent)
  46683. {
  46684. ScopedPointer <ComponentDeletionWatcher> currentlyFocusedChecker;
  46685. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  46686. if (currentlyFocused != 0)
  46687. currentlyFocusedChecker = new ComponentDeletionWatcher (currentlyFocused);
  46688. results.clear();
  46689. // the preview component needs to be the right size before you pass it in here..
  46690. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46691. && previewComponent->getHeight() > 10));
  46692. #if JUCE_WINDOWS
  46693. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46694. #elif JUCE_MAC
  46695. if (useNativeDialogBox && (previewComponent == 0))
  46696. #else
  46697. if (false)
  46698. #endif
  46699. {
  46700. showPlatformDialog (results, title, startingFile, filters,
  46701. selectsDirectories, selectsFiles, isSave,
  46702. warnAboutOverwritingExistingFiles,
  46703. selectMultipleFiles,
  46704. previewComponent);
  46705. }
  46706. else
  46707. {
  46708. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46709. selectsDirectories ? "*" : String::empty,
  46710. String::empty);
  46711. int flags = isSave ? FileBrowserComponent::saveMode
  46712. : FileBrowserComponent::openMode;
  46713. if (selectsFiles)
  46714. flags |= FileBrowserComponent::canSelectFiles;
  46715. if (selectsDirectories)
  46716. flags |= FileBrowserComponent::canSelectDirectories;
  46717. if (selectMultipleFiles)
  46718. flags |= FileBrowserComponent::canSelectMultipleItems;
  46719. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46720. FileChooserDialogBox box (title, String::empty,
  46721. browserComponent,
  46722. warnAboutOverwritingExistingFiles,
  46723. browserComponent.findColour (AlertWindow::backgroundColourId));
  46724. if (box.show())
  46725. {
  46726. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46727. results.add (browserComponent.getSelectedFile (i));
  46728. }
  46729. }
  46730. if (currentlyFocused != 0 && ! currentlyFocusedChecker->hasBeenDeleted())
  46731. currentlyFocused->grabKeyboardFocus();
  46732. return results.size() > 0;
  46733. }
  46734. FilePreviewComponent::FilePreviewComponent()
  46735. {
  46736. }
  46737. FilePreviewComponent::~FilePreviewComponent()
  46738. {
  46739. }
  46740. END_JUCE_NAMESPACE
  46741. /*** End of inlined file: juce_FileChooser.cpp ***/
  46742. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46743. BEGIN_JUCE_NAMESPACE
  46744. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46745. const String& instructions,
  46746. FileBrowserComponent& chooserComponent,
  46747. const bool warnAboutOverwritingExistingFiles_,
  46748. const Colour& backgroundColour)
  46749. : ResizableWindow (name, backgroundColour, true),
  46750. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46751. {
  46752. content = new ContentComponent();
  46753. content->setName (name);
  46754. content->instructions = instructions;
  46755. content->chooserComponent = &chooserComponent;
  46756. content->addAndMakeVisible (&chooserComponent);
  46757. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46758. content->addAndMakeVisible (content->okButton);
  46759. content->okButton->addButtonListener (this);
  46760. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46761. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46762. content->cancelButton = new TextButton (TRANS("Cancel"));
  46763. content->addAndMakeVisible (content->cancelButton);
  46764. content->cancelButton->addButtonListener (this);
  46765. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46766. setContentComponent (content);
  46767. setResizable (true, true);
  46768. setResizeLimits (300, 300, 1200, 1000);
  46769. content->chooserComponent->addListener (this);
  46770. }
  46771. FileChooserDialogBox::~FileChooserDialogBox()
  46772. {
  46773. content->chooserComponent->removeListener (this);
  46774. }
  46775. bool FileChooserDialogBox::show (int w, int h)
  46776. {
  46777. if (w <= 0)
  46778. {
  46779. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46780. if (previewComp != 0)
  46781. w = 400 + previewComp->getWidth();
  46782. else
  46783. w = 600;
  46784. }
  46785. if (h <= 0)
  46786. h = 500;
  46787. centreWithSize (w, h);
  46788. const bool ok = (runModalLoop() != 0);
  46789. setVisible (false);
  46790. return ok;
  46791. }
  46792. void FileChooserDialogBox::buttonClicked (Button* button)
  46793. {
  46794. if (button == content->okButton)
  46795. {
  46796. if (warnAboutOverwritingExistingFiles
  46797. && content->chooserComponent->isSaveMode()
  46798. && content->chooserComponent->getSelectedFile(0).exists())
  46799. {
  46800. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46801. TRANS("File already exists"),
  46802. TRANS("There's already a file called:\n\n")
  46803. + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46804. + T("\n\nAre you sure you want to overwrite it?"),
  46805. TRANS("overwrite"),
  46806. TRANS("cancel")))
  46807. {
  46808. return;
  46809. }
  46810. }
  46811. exitModalState (1);
  46812. }
  46813. else if (button == content->cancelButton)
  46814. closeButtonPressed();
  46815. }
  46816. void FileChooserDialogBox::closeButtonPressed()
  46817. {
  46818. setVisible (false);
  46819. }
  46820. void FileChooserDialogBox::selectionChanged()
  46821. {
  46822. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46823. }
  46824. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46825. {
  46826. }
  46827. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46828. {
  46829. selectionChanged();
  46830. content->okButton->triggerClick();
  46831. }
  46832. FileChooserDialogBox::ContentComponent::ContentComponent()
  46833. {
  46834. setInterceptsMouseClicks (false, true);
  46835. }
  46836. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46837. {
  46838. delete okButton;
  46839. delete cancelButton;
  46840. }
  46841. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46842. {
  46843. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46844. text.draw (g);
  46845. }
  46846. void FileChooserDialogBox::ContentComponent::resized()
  46847. {
  46848. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46849. float left, top, right, bottom;
  46850. text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false);
  46851. const int y = roundToInt (bottom) + 10;
  46852. const int buttonHeight = 26;
  46853. const int buttonY = getHeight() - buttonHeight - 8;
  46854. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46855. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46856. proportionOfWidth (0.2f), buttonHeight);
  46857. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46858. proportionOfWidth (0.2f), buttonHeight);
  46859. }
  46860. END_JUCE_NAMESPACE
  46861. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46862. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46863. BEGIN_JUCE_NAMESPACE
  46864. FileFilter::FileFilter (const String& filterDescription)
  46865. : description (filterDescription)
  46866. {
  46867. }
  46868. FileFilter::~FileFilter()
  46869. {
  46870. }
  46871. const String& FileFilter::getDescription() const throw()
  46872. {
  46873. return description;
  46874. }
  46875. END_JUCE_NAMESPACE
  46876. /*** End of inlined file: juce_FileFilter.cpp ***/
  46877. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46878. BEGIN_JUCE_NAMESPACE
  46879. Image* juce_createIconForFile (const File& file);
  46880. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46881. : ListBox (String::empty, 0),
  46882. DirectoryContentsDisplayComponent (listToShow)
  46883. {
  46884. setModel (this);
  46885. fileList.addChangeListener (this);
  46886. }
  46887. FileListComponent::~FileListComponent()
  46888. {
  46889. fileList.removeChangeListener (this);
  46890. deleteAllChildren();
  46891. }
  46892. int FileListComponent::getNumSelectedFiles() const
  46893. {
  46894. return getNumSelectedRows();
  46895. }
  46896. const File FileListComponent::getSelectedFile (int index) const
  46897. {
  46898. return fileList.getFile (getSelectedRow (index));
  46899. }
  46900. void FileListComponent::scrollToTop()
  46901. {
  46902. getVerticalScrollBar()->setCurrentRangeStart (0);
  46903. }
  46904. void FileListComponent::changeListenerCallback (void*)
  46905. {
  46906. updateContent();
  46907. if (lastDirectory != fileList.getDirectory())
  46908. {
  46909. lastDirectory = fileList.getDirectory();
  46910. deselectAllRows();
  46911. }
  46912. }
  46913. class FileListItemComponent : public Component,
  46914. public TimeSliceClient,
  46915. public AsyncUpdater
  46916. {
  46917. public:
  46918. FileListItemComponent (FileListComponent& owner_,
  46919. TimeSliceThread& thread_) throw()
  46920. : owner (owner_),
  46921. thread (thread_),
  46922. icon (0)
  46923. {
  46924. }
  46925. ~FileListItemComponent() throw()
  46926. {
  46927. thread.removeTimeSliceClient (this);
  46928. clearIcon();
  46929. }
  46930. void paint (Graphics& g)
  46931. {
  46932. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46933. file.getFileName(),
  46934. icon,
  46935. fileSize, modTime,
  46936. isDirectory, highlighted,
  46937. index);
  46938. }
  46939. void mouseDown (const MouseEvent& e)
  46940. {
  46941. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46942. owner.sendMouseClickMessage (file, e);
  46943. }
  46944. void mouseDoubleClick (const MouseEvent&)
  46945. {
  46946. owner.sendDoubleClickMessage (file);
  46947. }
  46948. void update (const File& root,
  46949. const DirectoryContentsList::FileInfo* const fileInfo,
  46950. const int index_,
  46951. const bool highlighted_) throw()
  46952. {
  46953. thread.removeTimeSliceClient (this);
  46954. if (highlighted_ != highlighted
  46955. || index_ != index)
  46956. {
  46957. index = index_;
  46958. highlighted = highlighted_;
  46959. repaint();
  46960. }
  46961. File newFile;
  46962. String newFileSize;
  46963. String newModTime;
  46964. if (fileInfo != 0)
  46965. {
  46966. newFile = root.getChildFile (fileInfo->filename);
  46967. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46968. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46969. }
  46970. if (newFile != file
  46971. || fileSize != newFileSize
  46972. || modTime != newModTime)
  46973. {
  46974. file = newFile;
  46975. fileSize = newFileSize;
  46976. modTime = newModTime;
  46977. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46978. repaint();
  46979. clearIcon();
  46980. }
  46981. if (file != File::nonexistent
  46982. && icon == 0 && ! isDirectory)
  46983. {
  46984. updateIcon (true);
  46985. if (icon == 0)
  46986. thread.addTimeSliceClient (this);
  46987. }
  46988. }
  46989. bool useTimeSlice()
  46990. {
  46991. updateIcon (false);
  46992. return false;
  46993. }
  46994. void handleAsyncUpdate()
  46995. {
  46996. repaint();
  46997. }
  46998. juce_UseDebuggingNewOperator
  46999. private:
  47000. FileListComponent& owner;
  47001. TimeSliceThread& thread;
  47002. bool highlighted;
  47003. int index;
  47004. File file;
  47005. String fileSize;
  47006. String modTime;
  47007. Image* icon;
  47008. bool isDirectory;
  47009. void clearIcon() throw()
  47010. {
  47011. ImageCache::release (icon);
  47012. icon = 0;
  47013. }
  47014. void updateIcon (const bool onlyUpdateIfCached) throw()
  47015. {
  47016. if (icon == 0)
  47017. {
  47018. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  47019. Image* im = ImageCache::getFromHashCode (hashCode);
  47020. if (im == 0 && ! onlyUpdateIfCached)
  47021. {
  47022. im = juce_createIconForFile (file);
  47023. if (im != 0)
  47024. ImageCache::addImageToCache (im, hashCode);
  47025. }
  47026. if (im != 0)
  47027. {
  47028. icon = im;
  47029. triggerAsyncUpdate();
  47030. }
  47031. }
  47032. }
  47033. };
  47034. int FileListComponent::getNumRows()
  47035. {
  47036. return fileList.getNumFiles();
  47037. }
  47038. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  47039. {
  47040. }
  47041. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  47042. {
  47043. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  47044. if (comp == 0)
  47045. {
  47046. delete existingComponentToUpdate;
  47047. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  47048. }
  47049. DirectoryContentsList::FileInfo fileInfo;
  47050. if (fileList.getFileInfo (row, fileInfo))
  47051. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  47052. else
  47053. comp->update (fileList.getDirectory(), 0, row, isSelected);
  47054. return comp;
  47055. }
  47056. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  47057. {
  47058. sendSelectionChangeMessage();
  47059. }
  47060. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  47061. {
  47062. }
  47063. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  47064. {
  47065. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  47066. }
  47067. END_JUCE_NAMESPACE
  47068. /*** End of inlined file: juce_FileListComponent.cpp ***/
  47069. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  47070. BEGIN_JUCE_NAMESPACE
  47071. FilenameComponent::FilenameComponent (const String& name,
  47072. const File& currentFile,
  47073. const bool canEditFilename,
  47074. const bool isDirectory,
  47075. const bool isForSaving,
  47076. const String& fileBrowserWildcard,
  47077. const String& enforcedSuffix_,
  47078. const String& textWhenNothingSelected)
  47079. : Component (name),
  47080. maxRecentFiles (30),
  47081. isDir (isDirectory),
  47082. isSaving (isForSaving),
  47083. isFileDragOver (false),
  47084. wildcard (fileBrowserWildcard),
  47085. enforcedSuffix (enforcedSuffix_)
  47086. {
  47087. addAndMakeVisible (filenameBox = new ComboBox (T("fn")));
  47088. filenameBox->setEditableText (canEditFilename);
  47089. filenameBox->addListener (this);
  47090. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  47091. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  47092. browseButton = 0;
  47093. setBrowseButtonText (T("..."));
  47094. setCurrentFile (currentFile, true);
  47095. }
  47096. FilenameComponent::~FilenameComponent()
  47097. {
  47098. deleteAllChildren();
  47099. }
  47100. void FilenameComponent::paintOverChildren (Graphics& g)
  47101. {
  47102. if (isFileDragOver)
  47103. {
  47104. g.setColour (Colours::red.withAlpha (0.2f));
  47105. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  47106. }
  47107. }
  47108. void FilenameComponent::resized()
  47109. {
  47110. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  47111. }
  47112. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  47113. {
  47114. browseButtonText = newBrowseButtonText;
  47115. lookAndFeelChanged();
  47116. }
  47117. void FilenameComponent::lookAndFeelChanged()
  47118. {
  47119. deleteAndZero (browseButton);
  47120. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  47121. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  47122. resized();
  47123. browseButton->addButtonListener (this);
  47124. }
  47125. void FilenameComponent::setTooltip (const String& newTooltip)
  47126. {
  47127. SettableTooltipClient::setTooltip (newTooltip);
  47128. filenameBox->setTooltip (newTooltip);
  47129. }
  47130. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47131. {
  47132. defaultBrowseFile = newDefaultDirectory;
  47133. }
  47134. void FilenameComponent::buttonClicked (Button*)
  47135. {
  47136. FileChooser fc (TRANS("Choose a new file"),
  47137. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  47138. : getCurrentFile(),
  47139. wildcard);
  47140. if (isDir ? fc.browseForDirectory()
  47141. : (isSaving ? fc.browseForFileToSave (false)
  47142. : fc.browseForFileToOpen()))
  47143. {
  47144. setCurrentFile (fc.getResult(), true);
  47145. }
  47146. }
  47147. void FilenameComponent::comboBoxChanged (ComboBox*)
  47148. {
  47149. setCurrentFile (getCurrentFile(), true);
  47150. }
  47151. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  47152. {
  47153. return true;
  47154. }
  47155. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  47156. {
  47157. isFileDragOver = false;
  47158. repaint();
  47159. const File f (filenames[0]);
  47160. if (f.exists() && (f.isDirectory() == isDir))
  47161. setCurrentFile (f, true);
  47162. }
  47163. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  47164. {
  47165. isFileDragOver = true;
  47166. repaint();
  47167. }
  47168. void FilenameComponent::fileDragExit (const StringArray&)
  47169. {
  47170. isFileDragOver = false;
  47171. repaint();
  47172. }
  47173. const File FilenameComponent::getCurrentFile() const
  47174. {
  47175. File f (filenameBox->getText());
  47176. if (enforcedSuffix.isNotEmpty())
  47177. f = f.withFileExtension (enforcedSuffix);
  47178. return f;
  47179. }
  47180. void FilenameComponent::setCurrentFile (File newFile,
  47181. const bool addToRecentlyUsedList,
  47182. const bool sendChangeNotification)
  47183. {
  47184. if (enforcedSuffix.isNotEmpty())
  47185. newFile = newFile.withFileExtension (enforcedSuffix);
  47186. if (newFile.getFullPathName() != lastFilename)
  47187. {
  47188. lastFilename = newFile.getFullPathName();
  47189. if (addToRecentlyUsedList)
  47190. addRecentlyUsedFile (newFile);
  47191. filenameBox->setText (lastFilename, true);
  47192. if (sendChangeNotification)
  47193. triggerAsyncUpdate();
  47194. }
  47195. }
  47196. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  47197. {
  47198. filenameBox->setEditableText (shouldBeEditable);
  47199. }
  47200. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  47201. {
  47202. StringArray names;
  47203. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  47204. names.add (filenameBox->getItemText (i));
  47205. return names;
  47206. }
  47207. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  47208. {
  47209. if (filenames != getRecentlyUsedFilenames())
  47210. {
  47211. filenameBox->clear();
  47212. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  47213. filenameBox->addItem (filenames[i], i + 1);
  47214. }
  47215. }
  47216. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  47217. {
  47218. maxRecentFiles = jmax (1, newMaximum);
  47219. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  47220. }
  47221. void FilenameComponent::addRecentlyUsedFile (const File& file)
  47222. {
  47223. StringArray files (getRecentlyUsedFilenames());
  47224. if (file.getFullPathName().isNotEmpty())
  47225. {
  47226. files.removeString (file.getFullPathName(), true);
  47227. files.insert (0, file.getFullPathName());
  47228. setRecentlyUsedFilenames (files);
  47229. }
  47230. }
  47231. void FilenameComponent::addListener (FilenameComponentListener* const listener) throw()
  47232. {
  47233. jassert (listener != 0);
  47234. if (listener != 0)
  47235. listeners.add (listener);
  47236. }
  47237. void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw()
  47238. {
  47239. listeners.removeValue (listener);
  47240. }
  47241. void FilenameComponent::handleAsyncUpdate()
  47242. {
  47243. for (int i = listeners.size(); --i >= 0;)
  47244. {
  47245. ((FilenameComponentListener*) listeners.getUnchecked (i))->filenameComponentChanged (this);
  47246. i = jmin (i, listeners.size());
  47247. }
  47248. }
  47249. END_JUCE_NAMESPACE
  47250. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  47251. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  47252. BEGIN_JUCE_NAMESPACE
  47253. FileSearchPathListComponent::FileSearchPathListComponent()
  47254. {
  47255. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  47256. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  47257. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  47258. listBox->setOutlineThickness (1);
  47259. addAndMakeVisible (addButton = new TextButton ("+"));
  47260. addButton->addButtonListener (this);
  47261. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47262. addAndMakeVisible (removeButton = new TextButton ("-"));
  47263. removeButton->addButtonListener (this);
  47264. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47265. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  47266. changeButton->addButtonListener (this);
  47267. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47268. upButton->addButtonListener (this);
  47269. {
  47270. Path arrowPath;
  47271. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  47272. DrawablePath arrowImage;
  47273. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47274. arrowImage.setPath (arrowPath);
  47275. ((DrawableButton*) upButton)->setImages (&arrowImage);
  47276. }
  47277. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47278. downButton->addButtonListener (this);
  47279. {
  47280. Path arrowPath;
  47281. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  47282. DrawablePath arrowImage;
  47283. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47284. arrowImage.setPath (arrowPath);
  47285. ((DrawableButton*) downButton)->setImages (&arrowImage);
  47286. }
  47287. updateButtons();
  47288. }
  47289. FileSearchPathListComponent::~FileSearchPathListComponent()
  47290. {
  47291. deleteAllChildren();
  47292. }
  47293. void FileSearchPathListComponent::updateButtons() throw()
  47294. {
  47295. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  47296. removeButton->setEnabled (anythingSelected);
  47297. changeButton->setEnabled (anythingSelected);
  47298. upButton->setEnabled (anythingSelected);
  47299. downButton->setEnabled (anythingSelected);
  47300. }
  47301. void FileSearchPathListComponent::changed() throw()
  47302. {
  47303. listBox->updateContent();
  47304. listBox->repaint();
  47305. updateButtons();
  47306. }
  47307. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  47308. {
  47309. if (newPath.toString() != path.toString())
  47310. {
  47311. path = newPath;
  47312. changed();
  47313. }
  47314. }
  47315. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47316. {
  47317. defaultBrowseTarget = newDefaultDirectory;
  47318. }
  47319. int FileSearchPathListComponent::getNumRows()
  47320. {
  47321. return path.getNumPaths();
  47322. }
  47323. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  47324. {
  47325. if (rowIsSelected)
  47326. g.fillAll (findColour (TextEditor::highlightColourId));
  47327. g.setColour (findColour (ListBox::textColourId));
  47328. Font f (height * 0.7f);
  47329. f.setHorizontalScale (0.9f);
  47330. g.setFont (f);
  47331. g.drawText (path [rowNumber].getFullPathName(),
  47332. 4, 0, width - 6, height,
  47333. Justification::centredLeft, true);
  47334. }
  47335. void FileSearchPathListComponent::deleteKeyPressed (int row)
  47336. {
  47337. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  47338. {
  47339. path.remove (row);
  47340. changed();
  47341. }
  47342. }
  47343. void FileSearchPathListComponent::returnKeyPressed (int row)
  47344. {
  47345. FileChooser chooser (TRANS("Change folder..."), path [row], T("*"));
  47346. if (chooser.browseForDirectory())
  47347. {
  47348. path.remove (row);
  47349. path.add (chooser.getResult(), row);
  47350. changed();
  47351. }
  47352. }
  47353. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  47354. {
  47355. returnKeyPressed (row);
  47356. }
  47357. void FileSearchPathListComponent::selectedRowsChanged (int)
  47358. {
  47359. updateButtons();
  47360. }
  47361. void FileSearchPathListComponent::paint (Graphics& g)
  47362. {
  47363. g.fillAll (findColour (backgroundColourId));
  47364. }
  47365. void FileSearchPathListComponent::resized()
  47366. {
  47367. const int buttonH = 22;
  47368. const int buttonY = getHeight() - buttonH - 4;
  47369. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  47370. addButton->setBounds (2, buttonY, buttonH, buttonH);
  47371. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  47372. ((TextButton*) changeButton)->changeWidthToFitText (buttonH);
  47373. downButton->setSize (buttonH * 2, buttonH);
  47374. upButton->setSize (buttonH * 2, buttonH);
  47375. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  47376. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  47377. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  47378. }
  47379. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  47380. {
  47381. return true;
  47382. }
  47383. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  47384. {
  47385. for (int i = filenames.size(); --i >= 0;)
  47386. {
  47387. const File f (filenames[i]);
  47388. if (f.isDirectory())
  47389. {
  47390. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  47391. path.add (f, row);
  47392. changed();
  47393. }
  47394. }
  47395. }
  47396. void FileSearchPathListComponent::buttonClicked (Button* button)
  47397. {
  47398. const int currentRow = listBox->getSelectedRow();
  47399. if (button == removeButton)
  47400. {
  47401. deleteKeyPressed (currentRow);
  47402. }
  47403. else if (button == addButton)
  47404. {
  47405. File start (defaultBrowseTarget);
  47406. if (start == File::nonexistent)
  47407. start = path [0];
  47408. if (start == File::nonexistent)
  47409. start = File::getCurrentWorkingDirectory();
  47410. FileChooser chooser (TRANS("Add a folder..."), start, T("*"));
  47411. if (chooser.browseForDirectory())
  47412. {
  47413. path.add (chooser.getResult(), currentRow);
  47414. }
  47415. }
  47416. else if (button == changeButton)
  47417. {
  47418. returnKeyPressed (currentRow);
  47419. }
  47420. else if (button == upButton)
  47421. {
  47422. if (currentRow > 0 && currentRow < path.getNumPaths())
  47423. {
  47424. const File f (path[currentRow]);
  47425. path.remove (currentRow);
  47426. path.add (f, currentRow - 1);
  47427. listBox->selectRow (currentRow - 1);
  47428. }
  47429. }
  47430. else if (button == downButton)
  47431. {
  47432. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  47433. {
  47434. const File f (path[currentRow]);
  47435. path.remove (currentRow);
  47436. path.add (f, currentRow + 1);
  47437. listBox->selectRow (currentRow + 1);
  47438. }
  47439. }
  47440. changed();
  47441. }
  47442. END_JUCE_NAMESPACE
  47443. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  47444. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  47445. BEGIN_JUCE_NAMESPACE
  47446. Image* juce_createIconForFile (const File& file);
  47447. class FileListTreeItem : public TreeViewItem,
  47448. public TimeSliceClient,
  47449. public AsyncUpdater,
  47450. public ChangeListener
  47451. {
  47452. public:
  47453. FileListTreeItem (FileTreeComponent& owner_,
  47454. DirectoryContentsList* const parentContentsList_,
  47455. const int indexInContentsList_,
  47456. const File& file_,
  47457. TimeSliceThread& thread_) throw()
  47458. : file (file_),
  47459. owner (owner_),
  47460. parentContentsList (parentContentsList_),
  47461. indexInContentsList (indexInContentsList_),
  47462. subContentsList (0),
  47463. canDeleteSubContentsList (false),
  47464. thread (thread_),
  47465. icon (0)
  47466. {
  47467. DirectoryContentsList::FileInfo fileInfo;
  47468. if (parentContentsList_ != 0
  47469. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  47470. {
  47471. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  47472. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  47473. isDirectory = fileInfo.isDirectory;
  47474. }
  47475. else
  47476. {
  47477. isDirectory = true;
  47478. }
  47479. }
  47480. ~FileListTreeItem() throw()
  47481. {
  47482. thread.removeTimeSliceClient (this);
  47483. clearSubItems();
  47484. ImageCache::release (icon);
  47485. if (canDeleteSubContentsList)
  47486. delete subContentsList;
  47487. }
  47488. bool mightContainSubItems() { return isDirectory; }
  47489. const String getUniqueName() const { return file.getFullPathName(); }
  47490. int getItemHeight() const { return 22; }
  47491. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  47492. void itemOpennessChanged (bool isNowOpen)
  47493. {
  47494. if (isNowOpen)
  47495. {
  47496. clearSubItems();
  47497. isDirectory = file.isDirectory();
  47498. if (isDirectory)
  47499. {
  47500. if (subContentsList == 0)
  47501. {
  47502. jassert (parentContentsList != 0);
  47503. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  47504. l->setDirectory (file, true, true);
  47505. setSubContentsList (l);
  47506. canDeleteSubContentsList = true;
  47507. }
  47508. changeListenerCallback (0);
  47509. }
  47510. }
  47511. }
  47512. void setSubContentsList (DirectoryContentsList* newList) throw()
  47513. {
  47514. jassert (subContentsList == 0);
  47515. subContentsList = newList;
  47516. newList->addChangeListener (this);
  47517. }
  47518. void changeListenerCallback (void*)
  47519. {
  47520. clearSubItems();
  47521. if (isOpen() && subContentsList != 0)
  47522. {
  47523. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  47524. {
  47525. FileListTreeItem* const item
  47526. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  47527. addSubItem (item);
  47528. }
  47529. }
  47530. }
  47531. void paintItem (Graphics& g, int width, int height)
  47532. {
  47533. if (file != File::nonexistent)
  47534. {
  47535. updateIcon (true);
  47536. if (icon == 0)
  47537. thread.addTimeSliceClient (this);
  47538. }
  47539. owner.getLookAndFeel()
  47540. .drawFileBrowserRow (g, width, height,
  47541. file.getFileName(),
  47542. icon,
  47543. fileSize, modTime,
  47544. isDirectory, isSelected(),
  47545. indexInContentsList);
  47546. }
  47547. void itemClicked (const MouseEvent& e)
  47548. {
  47549. owner.sendMouseClickMessage (file, e);
  47550. }
  47551. void itemDoubleClicked (const MouseEvent& e)
  47552. {
  47553. TreeViewItem::itemDoubleClicked (e);
  47554. owner.sendDoubleClickMessage (file);
  47555. }
  47556. void itemSelectionChanged (bool)
  47557. {
  47558. owner.sendSelectionChangeMessage();
  47559. }
  47560. bool useTimeSlice()
  47561. {
  47562. updateIcon (false);
  47563. thread.removeTimeSliceClient (this);
  47564. return false;
  47565. }
  47566. void handleAsyncUpdate()
  47567. {
  47568. owner.repaint();
  47569. }
  47570. const File file;
  47571. juce_UseDebuggingNewOperator
  47572. private:
  47573. FileTreeComponent& owner;
  47574. DirectoryContentsList* parentContentsList;
  47575. int indexInContentsList;
  47576. DirectoryContentsList* subContentsList;
  47577. bool isDirectory, canDeleteSubContentsList;
  47578. TimeSliceThread& thread;
  47579. Image* icon;
  47580. String fileSize;
  47581. String modTime;
  47582. void updateIcon (const bool onlyUpdateIfCached) throw()
  47583. {
  47584. if (icon == 0)
  47585. {
  47586. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  47587. Image* im = ImageCache::getFromHashCode (hashCode);
  47588. if (im == 0 && ! onlyUpdateIfCached)
  47589. {
  47590. im = juce_createIconForFile (file);
  47591. if (im != 0)
  47592. ImageCache::addImageToCache (im, hashCode);
  47593. }
  47594. if (im != 0)
  47595. {
  47596. icon = im;
  47597. triggerAsyncUpdate();
  47598. }
  47599. }
  47600. }
  47601. };
  47602. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  47603. : DirectoryContentsDisplayComponent (listToShow)
  47604. {
  47605. FileListTreeItem* const root
  47606. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  47607. listToShow.getTimeSliceThread());
  47608. root->setSubContentsList (&listToShow);
  47609. setRootItemVisible (false);
  47610. setRootItem (root);
  47611. }
  47612. FileTreeComponent::~FileTreeComponent()
  47613. {
  47614. deleteRootItem();
  47615. }
  47616. const File FileTreeComponent::getSelectedFile (const int index) const
  47617. {
  47618. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  47619. if (item != 0)
  47620. return item->file;
  47621. return File::nonexistent;
  47622. }
  47623. void FileTreeComponent::scrollToTop()
  47624. {
  47625. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  47626. }
  47627. void FileTreeComponent::setDragAndDropDescription (const String& description) throw()
  47628. {
  47629. dragAndDropDescription = description;
  47630. }
  47631. END_JUCE_NAMESPACE
  47632. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  47633. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  47634. BEGIN_JUCE_NAMESPACE
  47635. ImagePreviewComponent::ImagePreviewComponent()
  47636. {
  47637. }
  47638. ImagePreviewComponent::~ImagePreviewComponent()
  47639. {
  47640. }
  47641. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  47642. {
  47643. const int availableW = proportionOfWidth (0.97f);
  47644. const int availableH = getHeight() - 13 * 4;
  47645. const double scale = jmin (1.0,
  47646. availableW / (double) w,
  47647. availableH / (double) h);
  47648. w = roundToInt (scale * w);
  47649. h = roundToInt (scale * h);
  47650. }
  47651. void ImagePreviewComponent::selectedFileChanged (const File& file)
  47652. {
  47653. if (fileToLoad != file)
  47654. {
  47655. fileToLoad = file;
  47656. startTimer (100);
  47657. }
  47658. }
  47659. void ImagePreviewComponent::timerCallback()
  47660. {
  47661. stopTimer();
  47662. currentThumbnail = 0;
  47663. currentDetails = String::empty;
  47664. repaint();
  47665. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47666. if (in != 0)
  47667. {
  47668. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47669. if (format != 0)
  47670. {
  47671. currentThumbnail = format->decodeImage (*in);
  47672. if (currentThumbnail != 0)
  47673. {
  47674. int w = currentThumbnail->getWidth();
  47675. int h = currentThumbnail->getHeight();
  47676. currentDetails
  47677. << fileToLoad.getFileName() << "\n"
  47678. << format->getFormatName() << "\n"
  47679. << w << " x " << h << " pixels\n"
  47680. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47681. getThumbSize (w, h);
  47682. currentThumbnail = currentThumbnail->createCopy (w, h);
  47683. }
  47684. }
  47685. }
  47686. }
  47687. void ImagePreviewComponent::paint (Graphics& g)
  47688. {
  47689. if (currentThumbnail != 0)
  47690. {
  47691. g.setFont (13.0f);
  47692. int w = currentThumbnail->getWidth();
  47693. int h = currentThumbnail->getHeight();
  47694. getThumbSize (w, h);
  47695. const int numLines = 4;
  47696. const int totalH = 13 * numLines + h + 4;
  47697. const int y = (getHeight() - totalH) / 2;
  47698. g.drawImageWithin (currentThumbnail,
  47699. (getWidth() - w) / 2, y, w, h,
  47700. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47701. false);
  47702. g.drawFittedText (currentDetails,
  47703. 0, y + h + 4, getWidth(), 100,
  47704. Justification::centredTop, numLines);
  47705. }
  47706. }
  47707. END_JUCE_NAMESPACE
  47708. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47709. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47710. BEGIN_JUCE_NAMESPACE
  47711. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47712. const String& directoryWildcardPatterns,
  47713. const String& description_)
  47714. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47715. : (description_ + T(" (") + fileWildcardPatterns + T(")")))
  47716. {
  47717. parse (fileWildcardPatterns, fileWildcards);
  47718. parse (directoryWildcardPatterns, directoryWildcards);
  47719. }
  47720. WildcardFileFilter::~WildcardFileFilter()
  47721. {
  47722. }
  47723. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47724. {
  47725. return match (file, fileWildcards);
  47726. }
  47727. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47728. {
  47729. return match (file, directoryWildcards);
  47730. }
  47731. void WildcardFileFilter::parse (const String& pattern, StringArray& result) throw()
  47732. {
  47733. result.addTokens (pattern.toLowerCase(), T(";,"), T("\"'"));
  47734. result.trim();
  47735. result.removeEmptyStrings();
  47736. // special case for *.*, because people use it to mean "any file", but it
  47737. // would actually ignore files with no extension.
  47738. for (int i = result.size(); --i >= 0;)
  47739. if (result[i] == T("*.*"))
  47740. result.set (i, T("*"));
  47741. }
  47742. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) throw()
  47743. {
  47744. const String filename (file.getFileName());
  47745. for (int i = wildcards.size(); --i >= 0;)
  47746. if (filename.matchesWildcard (wildcards[i], true))
  47747. return true;
  47748. return false;
  47749. }
  47750. END_JUCE_NAMESPACE
  47751. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47752. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47753. BEGIN_JUCE_NAMESPACE
  47754. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47755. {
  47756. }
  47757. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47758. {
  47759. }
  47760. // This will sort a set of components, so that they are ordered in terms of
  47761. // left-to-right and then top-to-bottom.
  47762. class ScreenPositionComparator
  47763. {
  47764. public:
  47765. ScreenPositionComparator() {}
  47766. static int compareElements (const Component* const first, const Component* const second) throw()
  47767. {
  47768. int explicitOrder1 = first->getExplicitFocusOrder();
  47769. if (explicitOrder1 <= 0)
  47770. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47771. int explicitOrder2 = second->getExplicitFocusOrder();
  47772. if (explicitOrder2 <= 0)
  47773. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47774. if (explicitOrder1 != explicitOrder2)
  47775. return explicitOrder1 - explicitOrder2;
  47776. const int diff = first->getY() - second->getY();
  47777. return (diff == 0) ? first->getX() - second->getX()
  47778. : diff;
  47779. }
  47780. };
  47781. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47782. {
  47783. if (parent->getNumChildComponents() > 0)
  47784. {
  47785. Array <Component*> localComps;
  47786. ScreenPositionComparator comparator;
  47787. int i;
  47788. for (i = parent->getNumChildComponents(); --i >= 0;)
  47789. {
  47790. Component* const c = parent->getChildComponent (i);
  47791. if (c->isVisible() && c->isEnabled())
  47792. localComps.addSorted (comparator, c);
  47793. }
  47794. for (i = 0; i < localComps.size(); ++i)
  47795. {
  47796. Component* const c = localComps.getUnchecked (i);
  47797. if (c->getWantsKeyboardFocus())
  47798. comps.add (c);
  47799. if (! c->isFocusContainer())
  47800. findAllFocusableComponents (c, comps);
  47801. }
  47802. }
  47803. }
  47804. static Component* getIncrementedComponent (Component* const current, const int delta) throw()
  47805. {
  47806. Component* focusContainer = current->getParentComponent();
  47807. if (focusContainer != 0)
  47808. {
  47809. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47810. focusContainer = focusContainer->getParentComponent();
  47811. if (focusContainer != 0)
  47812. {
  47813. Array <Component*> comps;
  47814. findAllFocusableComponents (focusContainer, comps);
  47815. if (comps.size() > 0)
  47816. {
  47817. const int index = comps.indexOf (current);
  47818. return comps [(index + comps.size() + delta) % comps.size()];
  47819. }
  47820. }
  47821. }
  47822. return 0;
  47823. }
  47824. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47825. {
  47826. return getIncrementedComponent (current, 1);
  47827. }
  47828. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47829. {
  47830. return getIncrementedComponent (current, -1);
  47831. }
  47832. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47833. {
  47834. Array <Component*> comps;
  47835. if (parentComponent != 0)
  47836. findAllFocusableComponents (parentComponent, comps);
  47837. return comps.getFirst();
  47838. }
  47839. END_JUCE_NAMESPACE
  47840. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47841. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47842. BEGIN_JUCE_NAMESPACE
  47843. bool KeyListener::keyStateChanged (const bool, Component*)
  47844. {
  47845. return false;
  47846. }
  47847. END_JUCE_NAMESPACE
  47848. /*** End of inlined file: juce_KeyListener.cpp ***/
  47849. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47850. BEGIN_JUCE_NAMESPACE
  47851. // N.B. these two includes are put here deliberately to avoid problems with
  47852. // old GCCs failing on long include paths
  47853. const int maxKeys = 3;
  47854. class KeyMappingChangeButton : public Button
  47855. {
  47856. public:
  47857. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47858. const CommandID commandID_,
  47859. const String& keyName,
  47860. const int keyNum_)
  47861. : Button (keyName),
  47862. owner (owner_),
  47863. commandID (commandID_),
  47864. keyNum (keyNum_)
  47865. {
  47866. setWantsKeyboardFocus (false);
  47867. setTriggeredOnMouseDown (keyNum >= 0);
  47868. if (keyNum_ < 0)
  47869. setTooltip (TRANS("adds a new key-mapping"));
  47870. else
  47871. setTooltip (TRANS("click to change this key-mapping"));
  47872. }
  47873. ~KeyMappingChangeButton()
  47874. {
  47875. }
  47876. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47877. {
  47878. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47879. keyNum >= 0 ? getName() : String::empty);
  47880. }
  47881. void clicked()
  47882. {
  47883. if (keyNum >= 0)
  47884. {
  47885. // existing key clicked..
  47886. PopupMenu m;
  47887. m.addItem (1, TRANS("change this key-mapping"));
  47888. m.addSeparator();
  47889. m.addItem (2, TRANS("remove this key-mapping"));
  47890. const int res = m.show();
  47891. if (res == 1)
  47892. {
  47893. owner->assignNewKey (commandID, keyNum);
  47894. }
  47895. else if (res == 2)
  47896. {
  47897. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47898. }
  47899. }
  47900. else
  47901. {
  47902. // + button pressed..
  47903. owner->assignNewKey (commandID, -1);
  47904. }
  47905. }
  47906. void fitToContent (const int h) throw()
  47907. {
  47908. if (keyNum < 0)
  47909. {
  47910. setSize (h, h);
  47911. }
  47912. else
  47913. {
  47914. Font f (h * 0.6f);
  47915. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47916. }
  47917. }
  47918. juce_UseDebuggingNewOperator
  47919. private:
  47920. KeyMappingEditorComponent* const owner;
  47921. const CommandID commandID;
  47922. const int keyNum;
  47923. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47924. const KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47925. };
  47926. class KeyMappingItemComponent : public Component
  47927. {
  47928. public:
  47929. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47930. const CommandID commandID_)
  47931. : owner (owner_),
  47932. commandID (commandID_)
  47933. {
  47934. setInterceptsMouseClicks (false, true);
  47935. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47936. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47937. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47938. {
  47939. KeyMappingChangeButton* const kb
  47940. = new KeyMappingChangeButton (owner_, commandID,
  47941. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47942. kb->setEnabled (! isReadOnly);
  47943. addAndMakeVisible (kb);
  47944. }
  47945. KeyMappingChangeButton* const kb
  47946. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47947. addChildComponent (kb);
  47948. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47949. }
  47950. ~KeyMappingItemComponent()
  47951. {
  47952. deleteAllChildren();
  47953. }
  47954. void paint (Graphics& g)
  47955. {
  47956. g.setFont (getHeight() * 0.7f);
  47957. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47958. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47959. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47960. Justification::centredLeft, true);
  47961. }
  47962. void resized()
  47963. {
  47964. int x = getWidth() - 4;
  47965. for (int i = getNumChildComponents(); --i >= 0;)
  47966. {
  47967. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47968. kb->fitToContent (getHeight() - 2);
  47969. kb->setTopRightPosition (x, 1);
  47970. x -= kb->getWidth() + 5;
  47971. }
  47972. }
  47973. juce_UseDebuggingNewOperator
  47974. private:
  47975. KeyMappingEditorComponent* const owner;
  47976. const CommandID commandID;
  47977. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47978. const KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47979. };
  47980. class KeyMappingTreeViewItem : public TreeViewItem
  47981. {
  47982. public:
  47983. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47984. const CommandID commandID_)
  47985. : owner (owner_),
  47986. commandID (commandID_)
  47987. {
  47988. }
  47989. ~KeyMappingTreeViewItem()
  47990. {
  47991. }
  47992. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47993. bool mightContainSubItems() { return false; }
  47994. int getItemHeight() const { return 20; }
  47995. Component* createItemComponent()
  47996. {
  47997. return new KeyMappingItemComponent (owner, commandID);
  47998. }
  47999. juce_UseDebuggingNewOperator
  48000. private:
  48001. KeyMappingEditorComponent* const owner;
  48002. const CommandID commandID;
  48003. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  48004. const KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  48005. };
  48006. class KeyCategoryTreeViewItem : public TreeViewItem
  48007. {
  48008. public:
  48009. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  48010. const String& name)
  48011. : owner (owner_),
  48012. categoryName (name)
  48013. {
  48014. }
  48015. ~KeyCategoryTreeViewItem()
  48016. {
  48017. }
  48018. const String getUniqueName() const { return categoryName + "_cat"; }
  48019. bool mightContainSubItems() { return true; }
  48020. int getItemHeight() const { return 28; }
  48021. void paintItem (Graphics& g, int width, int height)
  48022. {
  48023. g.setFont (height * 0.6f, Font::bold);
  48024. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  48025. g.drawText (categoryName,
  48026. 2, 0, width - 2, height,
  48027. Justification::centredLeft, true);
  48028. }
  48029. void itemOpennessChanged (bool isNowOpen)
  48030. {
  48031. if (isNowOpen)
  48032. {
  48033. if (getNumSubItems() == 0)
  48034. {
  48035. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  48036. for (int i = 0; i < commands.size(); ++i)
  48037. {
  48038. if (owner->shouldCommandBeIncluded (commands[i]))
  48039. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  48040. }
  48041. }
  48042. }
  48043. else
  48044. {
  48045. clearSubItems();
  48046. }
  48047. }
  48048. juce_UseDebuggingNewOperator
  48049. private:
  48050. KeyMappingEditorComponent* owner;
  48051. String categoryName;
  48052. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  48053. const KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  48054. };
  48055. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  48056. const bool showResetToDefaultButton)
  48057. : mappings (mappingManager)
  48058. {
  48059. jassert (mappingManager != 0); // can't be null!
  48060. mappingManager->addChangeListener (this);
  48061. setLinesDrawnForSubItems (false);
  48062. resetButton = 0;
  48063. if (showResetToDefaultButton)
  48064. {
  48065. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  48066. resetButton->addButtonListener (this);
  48067. }
  48068. addAndMakeVisible (tree = new TreeView());
  48069. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  48070. tree->setRootItemVisible (false);
  48071. tree->setDefaultOpenness (true);
  48072. tree->setRootItem (this);
  48073. }
  48074. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  48075. {
  48076. mappings->removeChangeListener (this);
  48077. deleteAllChildren();
  48078. }
  48079. bool KeyMappingEditorComponent::mightContainSubItems()
  48080. {
  48081. return true;
  48082. }
  48083. const String KeyMappingEditorComponent::getUniqueName() const
  48084. {
  48085. return T("keys");
  48086. }
  48087. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  48088. const Colour& textColour)
  48089. {
  48090. setColour (backgroundColourId, mainBackground);
  48091. setColour (textColourId, textColour);
  48092. tree->setColour (TreeView::backgroundColourId, mainBackground);
  48093. }
  48094. void KeyMappingEditorComponent::parentHierarchyChanged()
  48095. {
  48096. changeListenerCallback (0);
  48097. }
  48098. void KeyMappingEditorComponent::resized()
  48099. {
  48100. int h = getHeight();
  48101. if (resetButton != 0)
  48102. {
  48103. const int buttonHeight = 20;
  48104. h -= buttonHeight + 8;
  48105. int x = getWidth() - 8;
  48106. const int y = h + 6;
  48107. resetButton->changeWidthToFitText (buttonHeight);
  48108. resetButton->setTopRightPosition (x, y);
  48109. }
  48110. tree->setBounds (0, 0, getWidth(), h);
  48111. }
  48112. void KeyMappingEditorComponent::buttonClicked (Button* button)
  48113. {
  48114. if (button == resetButton)
  48115. {
  48116. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  48117. TRANS("Reset to defaults"),
  48118. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  48119. TRANS("Reset")))
  48120. {
  48121. mappings->resetToDefaultMappings();
  48122. }
  48123. }
  48124. }
  48125. void KeyMappingEditorComponent::changeListenerCallback (void*)
  48126. {
  48127. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  48128. clearSubItems();
  48129. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  48130. for (int i = 0; i < categories.size(); ++i)
  48131. {
  48132. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  48133. int count = 0;
  48134. for (int j = 0; j < commands.size(); ++j)
  48135. if (shouldCommandBeIncluded (commands[j]))
  48136. ++count;
  48137. if (count > 0)
  48138. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  48139. }
  48140. if (openness != 0)
  48141. tree->restoreOpennessState (*openness);
  48142. }
  48143. class KeyEntryWindow : public AlertWindow
  48144. {
  48145. public:
  48146. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  48147. : AlertWindow (TRANS("New key-mapping"),
  48148. TRANS("Please press a key combination now..."),
  48149. AlertWindow::NoIcon),
  48150. owner (owner_)
  48151. {
  48152. addButton (TRANS("ok"), 1);
  48153. addButton (TRANS("cancel"), 0);
  48154. // (avoid return + escape keys getting processed by the buttons..)
  48155. for (int i = getNumChildComponents(); --i >= 0;)
  48156. getChildComponent (i)->setWantsKeyboardFocus (false);
  48157. setWantsKeyboardFocus (true);
  48158. grabKeyboardFocus();
  48159. }
  48160. ~KeyEntryWindow()
  48161. {
  48162. }
  48163. bool keyPressed (const KeyPress& key)
  48164. {
  48165. lastPress = key;
  48166. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  48167. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  48168. if (previousCommand != 0)
  48169. {
  48170. message << "\n\n"
  48171. << TRANS("(Currently assigned to \"")
  48172. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  48173. << "\")";
  48174. }
  48175. setMessage (message);
  48176. return true;
  48177. }
  48178. bool keyStateChanged (const bool)
  48179. {
  48180. return true;
  48181. }
  48182. KeyPress lastPress;
  48183. juce_UseDebuggingNewOperator
  48184. private:
  48185. KeyMappingEditorComponent* owner;
  48186. KeyEntryWindow (const KeyEntryWindow&);
  48187. const KeyEntryWindow& operator= (const KeyEntryWindow&);
  48188. };
  48189. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  48190. {
  48191. KeyEntryWindow entryWindow (this);
  48192. if (entryWindow.runModalLoop() != 0)
  48193. {
  48194. entryWindow.setVisible (false);
  48195. if (entryWindow.lastPress.isValid())
  48196. {
  48197. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  48198. if (previousCommand != 0)
  48199. {
  48200. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  48201. TRANS("Change key-mapping"),
  48202. TRANS("This key is already assigned to the command \"")
  48203. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  48204. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  48205. TRANS("re-assign"),
  48206. TRANS("cancel")))
  48207. {
  48208. return;
  48209. }
  48210. }
  48211. mappings->removeKeyPress (entryWindow.lastPress);
  48212. if (index >= 0)
  48213. mappings->removeKeyPress (commandID, index);
  48214. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  48215. }
  48216. }
  48217. }
  48218. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  48219. {
  48220. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48221. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  48222. }
  48223. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  48224. {
  48225. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48226. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  48227. }
  48228. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  48229. {
  48230. return key.getTextDescription();
  48231. }
  48232. END_JUCE_NAMESPACE
  48233. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  48234. /*** Start of inlined file: juce_KeyPress.cpp ***/
  48235. BEGIN_JUCE_NAMESPACE
  48236. KeyPress::KeyPress() throw()
  48237. : keyCode (0),
  48238. mods (0),
  48239. textCharacter (0)
  48240. {
  48241. }
  48242. KeyPress::KeyPress (const int keyCode_,
  48243. const ModifierKeys& mods_,
  48244. const juce_wchar textCharacter_) throw()
  48245. : keyCode (keyCode_),
  48246. mods (mods_),
  48247. textCharacter (textCharacter_)
  48248. {
  48249. }
  48250. KeyPress::KeyPress (const int keyCode_) throw()
  48251. : keyCode (keyCode_),
  48252. textCharacter (0)
  48253. {
  48254. }
  48255. KeyPress::KeyPress (const KeyPress& other) throw()
  48256. : keyCode (other.keyCode),
  48257. mods (other.mods),
  48258. textCharacter (other.textCharacter)
  48259. {
  48260. }
  48261. const KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  48262. {
  48263. keyCode = other.keyCode;
  48264. mods = other.mods;
  48265. textCharacter = other.textCharacter;
  48266. return *this;
  48267. }
  48268. bool KeyPress::operator== (const KeyPress& other) const throw()
  48269. {
  48270. return mods.getRawFlags() == other.mods.getRawFlags()
  48271. && (textCharacter == other.textCharacter
  48272. || textCharacter == 0
  48273. || other.textCharacter == 0)
  48274. && (keyCode == other.keyCode
  48275. || (keyCode < 256
  48276. && other.keyCode < 256
  48277. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  48278. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  48279. }
  48280. bool KeyPress::operator!= (const KeyPress& other) const throw()
  48281. {
  48282. return ! operator== (other);
  48283. }
  48284. bool KeyPress::isCurrentlyDown() const throw()
  48285. {
  48286. return isKeyCurrentlyDown (keyCode)
  48287. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  48288. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  48289. }
  48290. struct KeyNameAndCode
  48291. {
  48292. const char* name;
  48293. int code;
  48294. };
  48295. static const KeyNameAndCode keyNameTranslations[] =
  48296. {
  48297. { "spacebar", KeyPress::spaceKey },
  48298. { "return", KeyPress::returnKey },
  48299. { "escape", KeyPress::escapeKey },
  48300. { "backspace", KeyPress::backspaceKey },
  48301. { "cursor left", KeyPress::leftKey },
  48302. { "cursor right", KeyPress::rightKey },
  48303. { "cursor up", KeyPress::upKey },
  48304. { "cursor down", KeyPress::downKey },
  48305. { "page up", KeyPress::pageUpKey },
  48306. { "page down", KeyPress::pageDownKey },
  48307. { "home", KeyPress::homeKey },
  48308. { "end", KeyPress::endKey },
  48309. { "delete", KeyPress::deleteKey },
  48310. { "insert", KeyPress::insertKey },
  48311. { "tab", KeyPress::tabKey },
  48312. { "play", KeyPress::playKey },
  48313. { "stop", KeyPress::stopKey },
  48314. { "fast forward", KeyPress::fastForwardKey },
  48315. { "rewind", KeyPress::rewindKey }
  48316. };
  48317. static const tchar* const numberPadPrefix = T("numpad ");
  48318. const KeyPress KeyPress::createFromDescription (const String& desc) throw()
  48319. {
  48320. int modifiers = 0;
  48321. if (desc.containsWholeWordIgnoreCase (T("ctrl"))
  48322. || desc.containsWholeWordIgnoreCase (T("control"))
  48323. || desc.containsWholeWordIgnoreCase (T("ctl")))
  48324. modifiers |= ModifierKeys::ctrlModifier;
  48325. if (desc.containsWholeWordIgnoreCase (T("shift"))
  48326. || desc.containsWholeWordIgnoreCase (T("shft")))
  48327. modifiers |= ModifierKeys::shiftModifier;
  48328. if (desc.containsWholeWordIgnoreCase (T("alt"))
  48329. || desc.containsWholeWordIgnoreCase (T("option")))
  48330. modifiers |= ModifierKeys::altModifier;
  48331. if (desc.containsWholeWordIgnoreCase (T("command"))
  48332. || desc.containsWholeWordIgnoreCase (T("cmd")))
  48333. modifiers |= ModifierKeys::commandModifier;
  48334. int key = 0;
  48335. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48336. {
  48337. if (desc.containsWholeWordIgnoreCase (String (keyNameTranslations[i].name)))
  48338. {
  48339. key = keyNameTranslations[i].code;
  48340. break;
  48341. }
  48342. }
  48343. if (key == 0)
  48344. {
  48345. // see if it's a numpad key..
  48346. if (desc.containsIgnoreCase (numberPadPrefix))
  48347. {
  48348. const tchar lastChar = desc.trimEnd().getLastCharacter();
  48349. if (lastChar >= T('0') && lastChar <= T('9'))
  48350. key = numberPad0 + lastChar - T('0');
  48351. else if (lastChar == T('+'))
  48352. key = numberPadAdd;
  48353. else if (lastChar == T('-'))
  48354. key = numberPadSubtract;
  48355. else if (lastChar == T('*'))
  48356. key = numberPadMultiply;
  48357. else if (lastChar == T('/'))
  48358. key = numberPadDivide;
  48359. else if (lastChar == T('.'))
  48360. key = numberPadDecimalPoint;
  48361. else if (lastChar == T('='))
  48362. key = numberPadEquals;
  48363. else if (desc.endsWith (T("separator")))
  48364. key = numberPadSeparator;
  48365. else if (desc.endsWith (T("delete")))
  48366. key = numberPadDelete;
  48367. }
  48368. if (key == 0)
  48369. {
  48370. // see if it's a function key..
  48371. for (int i = 1; i <= 12; ++i)
  48372. if (desc.containsWholeWordIgnoreCase (T("f") + String (i)))
  48373. key = F1Key + i - 1;
  48374. if (key == 0)
  48375. {
  48376. // give up and use the hex code..
  48377. const int hexCode = desc.fromFirstOccurrenceOf (T("#"), false, false)
  48378. .toLowerCase()
  48379. .retainCharacters (T("0123456789abcdef"))
  48380. .getHexValue32();
  48381. if (hexCode > 0)
  48382. key = hexCode;
  48383. else
  48384. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  48385. }
  48386. }
  48387. }
  48388. return KeyPress (key, ModifierKeys (modifiers), 0);
  48389. }
  48390. const String KeyPress::getTextDescription() const throw()
  48391. {
  48392. String desc;
  48393. if (keyCode > 0)
  48394. {
  48395. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  48396. // want to store it as being a slash, not shift+whatever.
  48397. if (textCharacter == T('/'))
  48398. return "/";
  48399. if (mods.isCtrlDown())
  48400. desc << "ctrl + ";
  48401. if (mods.isShiftDown())
  48402. desc << "shift + ";
  48403. #if JUCE_MAC
  48404. // only do this on the mac, because on Windows ctrl and command are the same,
  48405. // and this would get confusing
  48406. if (mods.isCommandDown())
  48407. desc << "command + ";
  48408. if (mods.isAltDown())
  48409. desc << "option + ";
  48410. #else
  48411. if (mods.isAltDown())
  48412. desc << "alt + ";
  48413. #endif
  48414. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48415. if (keyCode == keyNameTranslations[i].code)
  48416. return desc + keyNameTranslations[i].name;
  48417. if (keyCode >= F1Key && keyCode <= F16Key)
  48418. desc << 'F' << (1 + keyCode - F1Key);
  48419. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  48420. desc << numberPadPrefix << (keyCode - numberPad0);
  48421. else if (keyCode >= 33 && keyCode < 176)
  48422. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  48423. else if (keyCode == numberPadAdd)
  48424. desc << numberPadPrefix << '+';
  48425. else if (keyCode == numberPadSubtract)
  48426. desc << numberPadPrefix << '-';
  48427. else if (keyCode == numberPadMultiply)
  48428. desc << numberPadPrefix << '*';
  48429. else if (keyCode == numberPadDivide)
  48430. desc << numberPadPrefix << '/';
  48431. else if (keyCode == numberPadSeparator)
  48432. desc << numberPadPrefix << "separator";
  48433. else if (keyCode == numberPadDecimalPoint)
  48434. desc << numberPadPrefix << '.';
  48435. else if (keyCode == numberPadDelete)
  48436. desc << numberPadPrefix << "delete";
  48437. else
  48438. desc << '#' << String::toHexString (keyCode);
  48439. }
  48440. return desc;
  48441. }
  48442. END_JUCE_NAMESPACE
  48443. /*** End of inlined file: juce_KeyPress.cpp ***/
  48444. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  48445. BEGIN_JUCE_NAMESPACE
  48446. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
  48447. : commandManager (commandManager_)
  48448. {
  48449. // A manager is needed to get the descriptions of commands, and will be called when
  48450. // a command is invoked. So you can't leave this null..
  48451. jassert (commandManager_ != 0);
  48452. Desktop::getInstance().addFocusChangeListener (this);
  48453. }
  48454. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
  48455. : commandManager (other.commandManager)
  48456. {
  48457. Desktop::getInstance().addFocusChangeListener (this);
  48458. }
  48459. KeyPressMappingSet::~KeyPressMappingSet()
  48460. {
  48461. Desktop::getInstance().removeFocusChangeListener (this);
  48462. }
  48463. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const throw()
  48464. {
  48465. for (int i = 0; i < mappings.size(); ++i)
  48466. if (mappings.getUnchecked(i)->commandID == commandID)
  48467. return mappings.getUnchecked (i)->keypresses;
  48468. return Array <KeyPress> ();
  48469. }
  48470. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  48471. const KeyPress& newKeyPress,
  48472. int insertIndex) throw()
  48473. {
  48474. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  48475. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  48476. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  48477. && ! newKeyPress.getModifiers().isShiftDown()));
  48478. if (findCommandForKeyPress (newKeyPress) != commandID)
  48479. {
  48480. removeKeyPress (newKeyPress);
  48481. if (newKeyPress.isValid())
  48482. {
  48483. for (int i = mappings.size(); --i >= 0;)
  48484. {
  48485. if (mappings.getUnchecked(i)->commandID == commandID)
  48486. {
  48487. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  48488. sendChangeMessage (this);
  48489. return;
  48490. }
  48491. }
  48492. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48493. if (ci != 0)
  48494. {
  48495. CommandMapping* const cm = new CommandMapping();
  48496. cm->commandID = commandID;
  48497. cm->keypresses.add (newKeyPress);
  48498. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  48499. mappings.add (cm);
  48500. sendChangeMessage (this);
  48501. }
  48502. }
  48503. }
  48504. }
  48505. void KeyPressMappingSet::resetToDefaultMappings() throw()
  48506. {
  48507. mappings.clear();
  48508. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  48509. {
  48510. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  48511. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48512. {
  48513. addKeyPress (ci->commandID,
  48514. ci->defaultKeypresses.getReference (j));
  48515. }
  48516. }
  48517. sendChangeMessage (this);
  48518. }
  48519. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
  48520. {
  48521. clearAllKeyPresses (commandID);
  48522. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48523. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48524. {
  48525. addKeyPress (ci->commandID,
  48526. ci->defaultKeypresses.getReference (j));
  48527. }
  48528. }
  48529. void KeyPressMappingSet::clearAllKeyPresses() throw()
  48530. {
  48531. if (mappings.size() > 0)
  48532. {
  48533. sendChangeMessage (this);
  48534. mappings.clear();
  48535. }
  48536. }
  48537. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
  48538. {
  48539. for (int i = mappings.size(); --i >= 0;)
  48540. {
  48541. if (mappings.getUnchecked(i)->commandID == commandID)
  48542. {
  48543. mappings.remove (i);
  48544. sendChangeMessage (this);
  48545. }
  48546. }
  48547. }
  48548. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
  48549. {
  48550. if (keypress.isValid())
  48551. {
  48552. for (int i = mappings.size(); --i >= 0;)
  48553. {
  48554. CommandMapping* const cm = mappings.getUnchecked(i);
  48555. for (int j = cm->keypresses.size(); --j >= 0;)
  48556. {
  48557. if (keypress == cm->keypresses [j])
  48558. {
  48559. cm->keypresses.remove (j);
  48560. sendChangeMessage (this);
  48561. }
  48562. }
  48563. }
  48564. }
  48565. }
  48566. void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
  48567. const int keyPressIndex) throw()
  48568. {
  48569. for (int i = mappings.size(); --i >= 0;)
  48570. {
  48571. if (mappings.getUnchecked(i)->commandID == commandID)
  48572. {
  48573. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  48574. sendChangeMessage (this);
  48575. break;
  48576. }
  48577. }
  48578. }
  48579. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  48580. {
  48581. for (int i = 0; i < mappings.size(); ++i)
  48582. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  48583. return mappings.getUnchecked(i)->commandID;
  48584. return 0;
  48585. }
  48586. bool KeyPressMappingSet::containsMapping (const CommandID commandID,
  48587. const KeyPress& keyPress) const throw()
  48588. {
  48589. for (int i = mappings.size(); --i >= 0;)
  48590. if (mappings.getUnchecked(i)->commandID == commandID)
  48591. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  48592. return false;
  48593. }
  48594. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  48595. const KeyPress& key,
  48596. const bool isKeyDown,
  48597. const int millisecsSinceKeyPressed,
  48598. Component* const originatingComponent) const
  48599. {
  48600. ApplicationCommandTarget::InvocationInfo info (commandID);
  48601. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  48602. info.isKeyDown = isKeyDown;
  48603. info.keyPress = key;
  48604. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  48605. info.originatingComponent = originatingComponent;
  48606. commandManager->invoke (info, false);
  48607. }
  48608. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  48609. {
  48610. if (xmlVersion.hasTagName (T("KEYMAPPINGS")))
  48611. {
  48612. if (xmlVersion.getBoolAttribute (T("basedOnDefaults"), true))
  48613. {
  48614. // if the XML was created as a set of differences from the default mappings,
  48615. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  48616. resetToDefaultMappings();
  48617. }
  48618. else
  48619. {
  48620. // if the XML was created calling createXml (false), then we need to clear all
  48621. // the keys and treat the xml as describing the entire set of mappings.
  48622. clearAllKeyPresses();
  48623. }
  48624. forEachXmlChildElement (xmlVersion, map)
  48625. {
  48626. const CommandID commandId = map->getStringAttribute (T("commandId")).getHexValue32();
  48627. if (commandId != 0)
  48628. {
  48629. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute (T("key"))));
  48630. if (map->hasTagName (T("MAPPING")))
  48631. {
  48632. addKeyPress (commandId, key);
  48633. }
  48634. else if (map->hasTagName (T("UNMAPPING")))
  48635. {
  48636. if (containsMapping (commandId, key))
  48637. removeKeyPress (key);
  48638. }
  48639. }
  48640. }
  48641. return true;
  48642. }
  48643. return false;
  48644. }
  48645. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  48646. {
  48647. ScopedPointer <KeyPressMappingSet> defaultSet;
  48648. if (saveDifferencesFromDefaultSet)
  48649. {
  48650. defaultSet = new KeyPressMappingSet (commandManager);
  48651. defaultSet->resetToDefaultMappings();
  48652. }
  48653. XmlElement* const doc = new XmlElement (T("KEYMAPPINGS"));
  48654. doc->setAttribute (T("basedOnDefaults"), saveDifferencesFromDefaultSet);
  48655. int i;
  48656. for (i = 0; i < mappings.size(); ++i)
  48657. {
  48658. const CommandMapping* const cm = mappings.getUnchecked(i);
  48659. for (int j = 0; j < cm->keypresses.size(); ++j)
  48660. {
  48661. if (defaultSet == 0
  48662. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48663. {
  48664. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  48665. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48666. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48667. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48668. }
  48669. }
  48670. }
  48671. if (defaultSet != 0)
  48672. {
  48673. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48674. {
  48675. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48676. for (int j = 0; j < cm->keypresses.size(); ++j)
  48677. {
  48678. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48679. {
  48680. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  48681. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48682. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48683. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48684. }
  48685. }
  48686. }
  48687. }
  48688. return doc;
  48689. }
  48690. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48691. Component* originatingComponent)
  48692. {
  48693. bool used = false;
  48694. const CommandID commandID = findCommandForKeyPress (key);
  48695. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48696. if (ci != 0
  48697. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48698. {
  48699. ApplicationCommandInfo info (0);
  48700. if (commandManager->getTargetForCommand (commandID, info) != 0
  48701. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48702. {
  48703. invokeCommand (commandID, key, true, 0, originatingComponent);
  48704. used = true;
  48705. }
  48706. else
  48707. {
  48708. if (originatingComponent != 0)
  48709. originatingComponent->getLookAndFeel().playAlertSound();
  48710. }
  48711. }
  48712. return used;
  48713. }
  48714. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48715. {
  48716. bool used = false;
  48717. const uint32 now = Time::getMillisecondCounter();
  48718. for (int i = mappings.size(); --i >= 0;)
  48719. {
  48720. CommandMapping* const cm = mappings.getUnchecked(i);
  48721. if (cm->wantsKeyUpDownCallbacks)
  48722. {
  48723. for (int j = cm->keypresses.size(); --j >= 0;)
  48724. {
  48725. const KeyPress key (cm->keypresses.getReference (j));
  48726. const bool isDown = key.isCurrentlyDown();
  48727. int keyPressEntryIndex = 0;
  48728. bool wasDown = false;
  48729. for (int k = keysDown.size(); --k >= 0;)
  48730. {
  48731. if (key == keysDown.getUnchecked(k)->key)
  48732. {
  48733. keyPressEntryIndex = k;
  48734. wasDown = true;
  48735. used = true;
  48736. break;
  48737. }
  48738. }
  48739. if (isDown != wasDown)
  48740. {
  48741. int millisecs = 0;
  48742. if (isDown)
  48743. {
  48744. KeyPressTime* const k = new KeyPressTime();
  48745. k->key = key;
  48746. k->timeWhenPressed = now;
  48747. keysDown.add (k);
  48748. }
  48749. else
  48750. {
  48751. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48752. if (now > pressTime)
  48753. millisecs = now - pressTime;
  48754. keysDown.remove (keyPressEntryIndex);
  48755. }
  48756. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48757. used = true;
  48758. }
  48759. }
  48760. }
  48761. }
  48762. return used;
  48763. }
  48764. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48765. {
  48766. if (focusedComponent != 0)
  48767. focusedComponent->keyStateChanged (false);
  48768. }
  48769. END_JUCE_NAMESPACE
  48770. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48771. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48772. BEGIN_JUCE_NAMESPACE
  48773. ModifierKeys::ModifierKeys (const int flags_) throw()
  48774. : flags (flags_)
  48775. {
  48776. }
  48777. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48778. : flags (other.flags)
  48779. {
  48780. }
  48781. const ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48782. {
  48783. flags = other.flags;
  48784. return *this;
  48785. }
  48786. int ModifierKeys::currentModifierFlags = 0;
  48787. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48788. {
  48789. return ModifierKeys (currentModifierFlags);
  48790. }
  48791. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48792. {
  48793. int num = 0;
  48794. if (isLeftButtonDown()) ++num;
  48795. if (isRightButtonDown()) ++num;
  48796. if (isMiddleButtonDown()) ++num;
  48797. return num;
  48798. }
  48799. END_JUCE_NAMESPACE
  48800. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48801. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48802. BEGIN_JUCE_NAMESPACE
  48803. struct AnimationTask
  48804. {
  48805. AnimationTask (Component* const comp)
  48806. : component (comp),
  48807. watcher (comp)
  48808. {
  48809. }
  48810. Component* component;
  48811. ComponentDeletionWatcher watcher;
  48812. Rectangle<int> destination;
  48813. int msElapsed, msTotal;
  48814. double startSpeed, midSpeed, endSpeed, lastProgress;
  48815. double left, top, right, bottom;
  48816. bool useTimeslice (const int elapsed)
  48817. {
  48818. if (watcher.hasBeenDeleted())
  48819. return false;
  48820. msElapsed += elapsed;
  48821. double newProgress = msElapsed / (double) msTotal;
  48822. if (newProgress >= 0 && newProgress < 1.0)
  48823. {
  48824. newProgress = timeToDistance (newProgress);
  48825. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48826. jassert (newProgress >= lastProgress);
  48827. lastProgress = newProgress;
  48828. left += (destination.getX() - left) * delta;
  48829. top += (destination.getY() - top) * delta;
  48830. right += (destination.getRight() - right) * delta;
  48831. bottom += (destination.getBottom() - bottom) * delta;
  48832. if (delta < 1.0)
  48833. {
  48834. const Rectangle<int> newBounds (roundToInt (left),
  48835. roundToInt (top),
  48836. roundToInt (right - left),
  48837. roundToInt (bottom - top));
  48838. if (newBounds != destination)
  48839. {
  48840. component->setBounds (newBounds);
  48841. return true;
  48842. }
  48843. }
  48844. }
  48845. component->setBounds (destination);
  48846. return false;
  48847. }
  48848. void moveToFinalDestination()
  48849. {
  48850. if (! watcher.hasBeenDeleted())
  48851. component->setBounds (destination);
  48852. }
  48853. private:
  48854. inline double timeToDistance (const double time) const
  48855. {
  48856. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48857. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48858. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48859. }
  48860. };
  48861. ComponentAnimator::ComponentAnimator()
  48862. : lastTime (0)
  48863. {
  48864. }
  48865. ComponentAnimator::~ComponentAnimator()
  48866. {
  48867. cancelAllAnimations (false);
  48868. jassert (tasks.size() == 0);
  48869. }
  48870. void* ComponentAnimator::findTaskFor (Component* const component) const
  48871. {
  48872. for (int i = tasks.size(); --i >= 0;)
  48873. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component)
  48874. return tasks.getUnchecked(i);
  48875. return 0;
  48876. }
  48877. void ComponentAnimator::animateComponent (Component* const component,
  48878. const Rectangle<int>& finalPosition,
  48879. const int millisecondsToSpendMoving,
  48880. const double startSpeed,
  48881. const double endSpeed)
  48882. {
  48883. if (component != 0)
  48884. {
  48885. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48886. if (at == 0)
  48887. {
  48888. at = new AnimationTask (component);
  48889. tasks.add (at);
  48890. sendChangeMessage (this);
  48891. }
  48892. at->msElapsed = 0;
  48893. at->lastProgress = 0;
  48894. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48895. at->destination = finalPosition;
  48896. // the speeds must be 0 or greater!
  48897. jassert (startSpeed >= 0 && endSpeed >= 0)
  48898. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48899. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48900. at->midSpeed = invTotalDistance;
  48901. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48902. at->left = component->getX();
  48903. at->top = component->getY();
  48904. at->right = component->getRight();
  48905. at->bottom = component->getBottom();
  48906. if (! isTimerRunning())
  48907. {
  48908. lastTime = Time::getMillisecondCounter();
  48909. startTimer (1000 / 50);
  48910. }
  48911. }
  48912. }
  48913. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48914. {
  48915. for (int i = tasks.size(); --i >= 0;)
  48916. {
  48917. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48918. if (moveComponentsToTheirFinalPositions)
  48919. at->moveToFinalDestination();
  48920. delete at;
  48921. tasks.remove (i);
  48922. sendChangeMessage (this);
  48923. }
  48924. }
  48925. void ComponentAnimator::cancelAnimation (Component* const component,
  48926. const bool moveComponentToItsFinalPosition)
  48927. {
  48928. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48929. if (at != 0)
  48930. {
  48931. if (moveComponentToItsFinalPosition)
  48932. at->moveToFinalDestination();
  48933. tasks.removeValue (at);
  48934. delete at;
  48935. sendChangeMessage (this);
  48936. }
  48937. }
  48938. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48939. {
  48940. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48941. if (at != 0)
  48942. return at->destination;
  48943. else if (component != 0)
  48944. return component->getBounds();
  48945. return Rectangle<int>();
  48946. }
  48947. bool ComponentAnimator::isAnimating (Component* component) const
  48948. {
  48949. return findTaskFor (component) != 0;
  48950. }
  48951. void ComponentAnimator::timerCallback()
  48952. {
  48953. const uint32 timeNow = Time::getMillisecondCounter();
  48954. if (lastTime == 0 || lastTime == timeNow)
  48955. lastTime = timeNow;
  48956. const int elapsed = timeNow - lastTime;
  48957. for (int i = tasks.size(); --i >= 0;)
  48958. {
  48959. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48960. if (! at->useTimeslice (elapsed))
  48961. {
  48962. tasks.remove (i);
  48963. delete at;
  48964. sendChangeMessage (this);
  48965. }
  48966. }
  48967. lastTime = timeNow;
  48968. if (tasks.size() == 0)
  48969. stopTimer();
  48970. }
  48971. END_JUCE_NAMESPACE
  48972. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48973. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48974. BEGIN_JUCE_NAMESPACE
  48975. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48976. : minW (0),
  48977. maxW (0x3fffffff),
  48978. minH (0),
  48979. maxH (0x3fffffff),
  48980. minOffTop (0),
  48981. minOffLeft (0),
  48982. minOffBottom (0),
  48983. minOffRight (0),
  48984. aspectRatio (0.0)
  48985. {
  48986. }
  48987. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48988. {
  48989. }
  48990. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48991. {
  48992. minW = minimumWidth;
  48993. }
  48994. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48995. {
  48996. maxW = maximumWidth;
  48997. }
  48998. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48999. {
  49000. minH = minimumHeight;
  49001. }
  49002. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  49003. {
  49004. maxH = maximumHeight;
  49005. }
  49006. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  49007. {
  49008. jassert (maxW >= minimumWidth);
  49009. jassert (maxH >= minimumHeight);
  49010. jassert (minimumWidth > 0 && minimumHeight > 0);
  49011. minW = minimumWidth;
  49012. minH = minimumHeight;
  49013. if (minW > maxW)
  49014. maxW = minW;
  49015. if (minH > maxH)
  49016. maxH = minH;
  49017. }
  49018. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  49019. {
  49020. jassert (maximumWidth >= minW);
  49021. jassert (maximumHeight >= minH);
  49022. jassert (maximumWidth > 0 && maximumHeight > 0);
  49023. maxW = jmax (minW, maximumWidth);
  49024. maxH = jmax (minH, maximumHeight);
  49025. }
  49026. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  49027. const int minimumHeight,
  49028. const int maximumWidth,
  49029. const int maximumHeight) throw()
  49030. {
  49031. jassert (maximumWidth >= minimumWidth);
  49032. jassert (maximumHeight >= minimumHeight);
  49033. jassert (maximumWidth > 0 && maximumHeight > 0);
  49034. jassert (minimumWidth > 0 && minimumHeight > 0);
  49035. minW = jmax (0, minimumWidth);
  49036. minH = jmax (0, minimumHeight);
  49037. maxW = jmax (minW, maximumWidth);
  49038. maxH = jmax (minH, maximumHeight);
  49039. }
  49040. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  49041. const int minimumWhenOffTheLeft,
  49042. const int minimumWhenOffTheBottom,
  49043. const int minimumWhenOffTheRight) throw()
  49044. {
  49045. minOffTop = minimumWhenOffTheTop;
  49046. minOffLeft = minimumWhenOffTheLeft;
  49047. minOffBottom = minimumWhenOffTheBottom;
  49048. minOffRight = minimumWhenOffTheRight;
  49049. }
  49050. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  49051. {
  49052. aspectRatio = jmax (0.0, widthOverHeight);
  49053. }
  49054. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  49055. {
  49056. return aspectRatio;
  49057. }
  49058. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  49059. const Rectangle<int>& targetBounds,
  49060. const bool isStretchingTop,
  49061. const bool isStretchingLeft,
  49062. const bool isStretchingBottom,
  49063. const bool isStretchingRight)
  49064. {
  49065. jassert (component != 0);
  49066. Rectangle<int> limits, bounds (targetBounds);
  49067. BorderSize border;
  49068. Component* const parent = component->getParentComponent();
  49069. if (parent == 0)
  49070. {
  49071. ComponentPeer* peer = component->getPeer();
  49072. if (peer != 0)
  49073. border = peer->getFrameSize();
  49074. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentreX(),
  49075. bounds.getCentreY());
  49076. }
  49077. else
  49078. {
  49079. limits.setSize (parent->getWidth(), parent->getHeight());
  49080. }
  49081. border.addTo (bounds);
  49082. checkBounds (bounds,
  49083. border.addedTo (component->getBounds()), limits,
  49084. isStretchingTop, isStretchingLeft,
  49085. isStretchingBottom, isStretchingRight);
  49086. border.subtractFrom (bounds);
  49087. applyBoundsToComponent (component, bounds);
  49088. }
  49089. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  49090. {
  49091. setBoundsForComponent (component, component->getBounds(),
  49092. false, false, false, false);
  49093. }
  49094. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  49095. const Rectangle<int>& bounds)
  49096. {
  49097. component->setBounds (bounds);
  49098. }
  49099. void ComponentBoundsConstrainer::resizeStart()
  49100. {
  49101. }
  49102. void ComponentBoundsConstrainer::resizeEnd()
  49103. {
  49104. }
  49105. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  49106. const Rectangle<int>& old,
  49107. const Rectangle<int>& limits,
  49108. const bool isStretchingTop,
  49109. const bool isStretchingLeft,
  49110. const bool isStretchingBottom,
  49111. const bool isStretchingRight)
  49112. {
  49113. int x = bounds.getX();
  49114. int y = bounds.getY();
  49115. int w = bounds.getWidth();
  49116. int h = bounds.getHeight();
  49117. // constrain the size if it's being stretched..
  49118. if (isStretchingLeft)
  49119. {
  49120. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  49121. w = old.getRight() - x;
  49122. }
  49123. if (isStretchingRight)
  49124. {
  49125. w = jlimit (minW, maxW, w);
  49126. }
  49127. if (isStretchingTop)
  49128. {
  49129. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  49130. h = old.getBottom() - y;
  49131. }
  49132. if (isStretchingBottom)
  49133. {
  49134. h = jlimit (minH, maxH, h);
  49135. }
  49136. // constrain the aspect ratio if one has been specified..
  49137. if (aspectRatio > 0.0 && w > 0 && h > 0)
  49138. {
  49139. bool adjustWidth;
  49140. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49141. {
  49142. adjustWidth = true;
  49143. }
  49144. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49145. {
  49146. adjustWidth = false;
  49147. }
  49148. else
  49149. {
  49150. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  49151. const double newRatio = fabs (w / (double) h);
  49152. adjustWidth = (oldRatio > newRatio);
  49153. }
  49154. if (adjustWidth)
  49155. {
  49156. w = roundToInt (h * aspectRatio);
  49157. if (w > maxW || w < minW)
  49158. {
  49159. w = jlimit (minW, maxW, w);
  49160. h = roundToInt (w / aspectRatio);
  49161. }
  49162. }
  49163. else
  49164. {
  49165. h = roundToInt (w / aspectRatio);
  49166. if (h > maxH || h < minH)
  49167. {
  49168. h = jlimit (minH, maxH, h);
  49169. w = roundToInt (h * aspectRatio);
  49170. }
  49171. }
  49172. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49173. {
  49174. x = old.getX() + (old.getWidth() - w) / 2;
  49175. }
  49176. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49177. {
  49178. y = old.getY() + (old.getHeight() - h) / 2;
  49179. }
  49180. else
  49181. {
  49182. if (isStretchingLeft)
  49183. x = old.getRight() - w;
  49184. if (isStretchingTop)
  49185. y = old.getBottom() - h;
  49186. }
  49187. }
  49188. // ...and constrain the position if limits have been set for that.
  49189. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  49190. {
  49191. if (minOffTop > 0)
  49192. {
  49193. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  49194. if (y < limit)
  49195. {
  49196. if (isStretchingTop)
  49197. h -= (limit - y);
  49198. y = limit;
  49199. }
  49200. }
  49201. if (minOffLeft > 0)
  49202. {
  49203. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  49204. if (x < limit)
  49205. {
  49206. if (isStretchingLeft)
  49207. w -= (limit - x);
  49208. x = limit;
  49209. }
  49210. }
  49211. if (minOffBottom > 0)
  49212. {
  49213. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  49214. if (y > limit)
  49215. {
  49216. if (isStretchingBottom)
  49217. h += (limit - y);
  49218. else
  49219. y = limit;
  49220. }
  49221. }
  49222. if (minOffRight > 0)
  49223. {
  49224. const int limit = limits.getRight() - jmin (minOffRight, w);
  49225. if (x > limit)
  49226. {
  49227. if (isStretchingRight)
  49228. w += (limit - x);
  49229. else
  49230. x = limit;
  49231. }
  49232. }
  49233. }
  49234. jassert (w >= 0 && h >= 0);
  49235. bounds = Rectangle<int> (x, y, w, h);
  49236. }
  49237. END_JUCE_NAMESPACE
  49238. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  49239. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  49240. BEGIN_JUCE_NAMESPACE
  49241. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  49242. : component (component_),
  49243. lastPeer (0),
  49244. reentrant (false)
  49245. {
  49246. jassert (component != 0); // can't use this with a null pointer..
  49247. #ifdef JUCE_DEBUG
  49248. deletionWatcher = new ComponentDeletionWatcher (component_);
  49249. #endif
  49250. component->addComponentListener (this);
  49251. registerWithParentComps();
  49252. }
  49253. ComponentMovementWatcher::~ComponentMovementWatcher()
  49254. {
  49255. component->removeComponentListener (this);
  49256. unregister();
  49257. }
  49258. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  49259. {
  49260. #ifdef JUCE_DEBUG
  49261. // agh! don't delete the target component without deleting this object first!
  49262. jassert (! deletionWatcher->hasBeenDeleted());
  49263. #endif
  49264. if (! reentrant)
  49265. {
  49266. reentrant = true;
  49267. ComponentPeer* const peer = component->getPeer();
  49268. if (peer != lastPeer)
  49269. {
  49270. ComponentDeletionWatcher watcher (component);
  49271. componentPeerChanged();
  49272. if (watcher.hasBeenDeleted())
  49273. return;
  49274. lastPeer = peer;
  49275. }
  49276. unregister();
  49277. registerWithParentComps();
  49278. reentrant = false;
  49279. componentMovedOrResized (*component, true, true);
  49280. }
  49281. }
  49282. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  49283. {
  49284. #ifdef JUCE_DEBUG
  49285. // agh! don't delete the target component without deleting this object first!
  49286. jassert (! deletionWatcher->hasBeenDeleted());
  49287. #endif
  49288. if (wasMoved)
  49289. {
  49290. int x = 0, y = 0;
  49291. component->relativePositionToOtherComponent (component->getTopLevelComponent(), x, y);
  49292. wasMoved = (lastX != x || lastY != y);
  49293. lastX = x;
  49294. lastY = y;
  49295. }
  49296. wasResized = (lastWidth != component->getWidth() || lastHeight != component->getHeight());
  49297. lastWidth = component->getWidth();
  49298. lastHeight = component->getHeight();
  49299. if (wasMoved || wasResized)
  49300. componentMovedOrResized (wasMoved, wasResized);
  49301. }
  49302. void ComponentMovementWatcher::registerWithParentComps() throw()
  49303. {
  49304. Component* p = component->getParentComponent();
  49305. while (p != 0)
  49306. {
  49307. p->addComponentListener (this);
  49308. registeredParentComps.add (p);
  49309. p = p->getParentComponent();
  49310. }
  49311. }
  49312. void ComponentMovementWatcher::unregister() throw()
  49313. {
  49314. for (int i = registeredParentComps.size(); --i >= 0;)
  49315. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  49316. registeredParentComps.clear();
  49317. }
  49318. END_JUCE_NAMESPACE
  49319. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  49320. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  49321. BEGIN_JUCE_NAMESPACE
  49322. GroupComponent::GroupComponent (const String& componentName,
  49323. const String& labelText)
  49324. : Component (componentName),
  49325. text (labelText),
  49326. justification (Justification::left)
  49327. {
  49328. setInterceptsMouseClicks (false, true);
  49329. }
  49330. GroupComponent::~GroupComponent()
  49331. {
  49332. }
  49333. void GroupComponent::setText (const String& newText) throw()
  49334. {
  49335. if (text != newText)
  49336. {
  49337. text = newText;
  49338. repaint();
  49339. }
  49340. }
  49341. const String GroupComponent::getText() const throw()
  49342. {
  49343. return text;
  49344. }
  49345. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  49346. {
  49347. if (justification.getFlags() != newJustification.getFlags())
  49348. {
  49349. justification = newJustification;
  49350. repaint();
  49351. }
  49352. }
  49353. void GroupComponent::paint (Graphics& g)
  49354. {
  49355. getLookAndFeel()
  49356. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  49357. text, justification,
  49358. *this);
  49359. }
  49360. void GroupComponent::enablementChanged()
  49361. {
  49362. repaint();
  49363. }
  49364. void GroupComponent::colourChanged()
  49365. {
  49366. repaint();
  49367. }
  49368. END_JUCE_NAMESPACE
  49369. /*** End of inlined file: juce_GroupComponent.cpp ***/
  49370. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  49371. BEGIN_JUCE_NAMESPACE
  49372. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  49373. : DocumentWindow (String::empty, backgroundColour,
  49374. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  49375. {
  49376. }
  49377. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  49378. {
  49379. }
  49380. void MultiDocumentPanelWindow::maximiseButtonPressed()
  49381. {
  49382. MultiDocumentPanel* const owner = getOwner();
  49383. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49384. if (owner != 0)
  49385. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  49386. }
  49387. void MultiDocumentPanelWindow::closeButtonPressed()
  49388. {
  49389. MultiDocumentPanel* const owner = getOwner();
  49390. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49391. if (owner != 0)
  49392. owner->closeDocument (getContentComponent(), true);
  49393. }
  49394. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  49395. {
  49396. DocumentWindow::activeWindowStatusChanged();
  49397. updateOrder();
  49398. }
  49399. void MultiDocumentPanelWindow::broughtToFront()
  49400. {
  49401. DocumentWindow::broughtToFront();
  49402. updateOrder();
  49403. }
  49404. void MultiDocumentPanelWindow::updateOrder()
  49405. {
  49406. MultiDocumentPanel* const owner = getOwner();
  49407. if (owner != 0)
  49408. owner->updateOrder();
  49409. }
  49410. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  49411. {
  49412. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49413. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49414. }
  49415. class MDITabbedComponentInternal : public TabbedComponent
  49416. {
  49417. public:
  49418. MDITabbedComponentInternal()
  49419. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  49420. {
  49421. }
  49422. ~MDITabbedComponentInternal()
  49423. {
  49424. }
  49425. void currentTabChanged (const int, const String&)
  49426. {
  49427. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49428. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49429. if (owner != 0)
  49430. owner->updateOrder();
  49431. }
  49432. };
  49433. MultiDocumentPanel::MultiDocumentPanel()
  49434. : mode (MaximisedWindowsWithTabs),
  49435. tabComponent (0),
  49436. backgroundColour (Colours::lightblue),
  49437. maximumNumDocuments (0),
  49438. numDocsBeforeTabsUsed (0)
  49439. {
  49440. setOpaque (true);
  49441. }
  49442. MultiDocumentPanel::~MultiDocumentPanel()
  49443. {
  49444. closeAllDocuments (false);
  49445. }
  49446. static bool shouldDeleteComp (Component* const c)
  49447. {
  49448. return c->getProperties() ["mdiDocumentDelete_"];
  49449. }
  49450. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  49451. {
  49452. while (components.size() > 0)
  49453. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  49454. return false;
  49455. return true;
  49456. }
  49457. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  49458. {
  49459. return new MultiDocumentPanelWindow (backgroundColour);
  49460. }
  49461. void MultiDocumentPanel::addWindow (Component* component)
  49462. {
  49463. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  49464. dw->setResizable (true, false);
  49465. dw->setContentComponent (component, false, true);
  49466. dw->setName (component->getName());
  49467. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  49468. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  49469. int x = 4;
  49470. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  49471. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  49472. x += 16;
  49473. dw->setTopLeftPosition (x, x);
  49474. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  49475. if (pos.toString().isNotEmpty())
  49476. dw->restoreWindowStateFromString (pos.toString());
  49477. addAndMakeVisible (dw);
  49478. dw->toFront (true);
  49479. }
  49480. bool MultiDocumentPanel::addDocument (Component* const component,
  49481. const Colour& docColour,
  49482. const bool deleteWhenRemoved)
  49483. {
  49484. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  49485. // with a frame-within-a-frame! Just pass in the bare content component.
  49486. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  49487. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  49488. return false;
  49489. components.add (component);
  49490. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  49491. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  49492. component->addComponentListener (this);
  49493. if (mode == FloatingWindows)
  49494. {
  49495. if (isFullscreenWhenOneDocument())
  49496. {
  49497. if (components.size() == 1)
  49498. {
  49499. addAndMakeVisible (component);
  49500. }
  49501. else
  49502. {
  49503. if (components.size() == 2)
  49504. addWindow (components.getFirst());
  49505. addWindow (component);
  49506. }
  49507. }
  49508. else
  49509. {
  49510. addWindow (component);
  49511. }
  49512. }
  49513. else
  49514. {
  49515. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  49516. {
  49517. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  49518. Array <Component*> temp (components);
  49519. for (int i = 0; i < temp.size(); ++i)
  49520. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  49521. resized();
  49522. }
  49523. else
  49524. {
  49525. if (tabComponent != 0)
  49526. tabComponent->addTab (component->getName(), docColour, component, false);
  49527. else
  49528. addAndMakeVisible (component);
  49529. }
  49530. setActiveDocument (component);
  49531. }
  49532. resized();
  49533. activeDocumentChanged();
  49534. return true;
  49535. }
  49536. bool MultiDocumentPanel::closeDocument (Component* component,
  49537. const bool checkItsOkToCloseFirst)
  49538. {
  49539. if (components.contains (component))
  49540. {
  49541. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  49542. return false;
  49543. component->removeComponentListener (this);
  49544. const bool shouldDelete = shouldDeleteComp (component);
  49545. component->getProperties().remove ("mdiDocumentDelete_");
  49546. component->getProperties().remove ("mdiDocumentBkg_");
  49547. if (mode == FloatingWindows)
  49548. {
  49549. for (int i = getNumChildComponents(); --i >= 0;)
  49550. {
  49551. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49552. if (dw != 0 && dw->getContentComponent() == component)
  49553. {
  49554. dw->setContentComponent (0, false);
  49555. delete dw;
  49556. break;
  49557. }
  49558. }
  49559. if (shouldDelete)
  49560. delete component;
  49561. components.removeValue (component);
  49562. if (isFullscreenWhenOneDocument() && components.size() == 1)
  49563. {
  49564. for (int i = getNumChildComponents(); --i >= 0;)
  49565. {
  49566. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49567. if (dw != 0)
  49568. {
  49569. dw->setContentComponent (0, false);
  49570. delete dw;
  49571. }
  49572. }
  49573. addAndMakeVisible (components.getFirst());
  49574. }
  49575. }
  49576. else
  49577. {
  49578. jassert (components.indexOf (component) >= 0);
  49579. if (tabComponent != 0)
  49580. {
  49581. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49582. if (tabComponent->getTabContentComponent (i) == component)
  49583. tabComponent->removeTab (i);
  49584. }
  49585. else
  49586. {
  49587. removeChildComponent (component);
  49588. }
  49589. if (shouldDelete)
  49590. delete component;
  49591. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  49592. deleteAndZero (tabComponent);
  49593. components.removeValue (component);
  49594. if (components.size() > 0 && tabComponent == 0)
  49595. addAndMakeVisible (components.getFirst());
  49596. }
  49597. resized();
  49598. activeDocumentChanged();
  49599. }
  49600. else
  49601. {
  49602. jassertfalse
  49603. }
  49604. return true;
  49605. }
  49606. int MultiDocumentPanel::getNumDocuments() const throw()
  49607. {
  49608. return components.size();
  49609. }
  49610. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  49611. {
  49612. return components [index];
  49613. }
  49614. Component* MultiDocumentPanel::getActiveDocument() const throw()
  49615. {
  49616. if (mode == FloatingWindows)
  49617. {
  49618. for (int i = getNumChildComponents(); --i >= 0;)
  49619. {
  49620. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49621. if (dw != 0 && dw->isActiveWindow())
  49622. return dw->getContentComponent();
  49623. }
  49624. }
  49625. return components.getLast();
  49626. }
  49627. void MultiDocumentPanel::setActiveDocument (Component* component)
  49628. {
  49629. if (mode == FloatingWindows)
  49630. {
  49631. component = getContainerComp (component);
  49632. if (component != 0)
  49633. component->toFront (true);
  49634. }
  49635. else if (tabComponent != 0)
  49636. {
  49637. jassert (components.indexOf (component) >= 0);
  49638. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49639. {
  49640. if (tabComponent->getTabContentComponent (i) == component)
  49641. {
  49642. tabComponent->setCurrentTabIndex (i);
  49643. break;
  49644. }
  49645. }
  49646. }
  49647. else
  49648. {
  49649. component->grabKeyboardFocus();
  49650. }
  49651. }
  49652. void MultiDocumentPanel::activeDocumentChanged()
  49653. {
  49654. }
  49655. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  49656. {
  49657. maximumNumDocuments = newNumber;
  49658. }
  49659. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  49660. {
  49661. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  49662. }
  49663. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  49664. {
  49665. return numDocsBeforeTabsUsed != 0;
  49666. }
  49667. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  49668. {
  49669. if (mode != newLayoutMode)
  49670. {
  49671. mode = newLayoutMode;
  49672. if (mode == FloatingWindows)
  49673. {
  49674. deleteAndZero (tabComponent);
  49675. }
  49676. else
  49677. {
  49678. for (int i = getNumChildComponents(); --i >= 0;)
  49679. {
  49680. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49681. if (dw != 0)
  49682. {
  49683. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  49684. dw->setContentComponent (0, false);
  49685. delete dw;
  49686. }
  49687. }
  49688. }
  49689. resized();
  49690. const Array <Component*> tempComps (components);
  49691. components.clear();
  49692. for (int i = 0; i < tempComps.size(); ++i)
  49693. {
  49694. Component* const c = tempComps.getUnchecked(i);
  49695. addDocument (c,
  49696. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  49697. shouldDeleteComp (c));
  49698. }
  49699. }
  49700. }
  49701. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49702. {
  49703. if (backgroundColour != newBackgroundColour)
  49704. {
  49705. backgroundColour = newBackgroundColour;
  49706. setOpaque (newBackgroundColour.isOpaque());
  49707. repaint();
  49708. }
  49709. }
  49710. void MultiDocumentPanel::paint (Graphics& g)
  49711. {
  49712. g.fillAll (backgroundColour);
  49713. }
  49714. void MultiDocumentPanel::resized()
  49715. {
  49716. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49717. {
  49718. for (int i = getNumChildComponents(); --i >= 0;)
  49719. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49720. }
  49721. setWantsKeyboardFocus (components.size() == 0);
  49722. }
  49723. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49724. {
  49725. if (mode == FloatingWindows)
  49726. {
  49727. for (int i = 0; i < getNumChildComponents(); ++i)
  49728. {
  49729. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49730. if (dw != 0 && dw->getContentComponent() == c)
  49731. {
  49732. c = dw;
  49733. break;
  49734. }
  49735. }
  49736. }
  49737. return c;
  49738. }
  49739. void MultiDocumentPanel::componentNameChanged (Component&)
  49740. {
  49741. if (mode == FloatingWindows)
  49742. {
  49743. for (int i = 0; i < getNumChildComponents(); ++i)
  49744. {
  49745. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49746. if (dw != 0)
  49747. dw->setName (dw->getContentComponent()->getName());
  49748. }
  49749. }
  49750. else if (tabComponent != 0)
  49751. {
  49752. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49753. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49754. }
  49755. }
  49756. void MultiDocumentPanel::updateOrder()
  49757. {
  49758. const Array <Component*> oldList (components);
  49759. if (mode == FloatingWindows)
  49760. {
  49761. components.clear();
  49762. for (int i = 0; i < getNumChildComponents(); ++i)
  49763. {
  49764. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49765. if (dw != 0)
  49766. components.add (dw->getContentComponent());
  49767. }
  49768. }
  49769. else
  49770. {
  49771. if (tabComponent != 0)
  49772. {
  49773. Component* const current = tabComponent->getCurrentContentComponent();
  49774. if (current != 0)
  49775. {
  49776. components.removeValue (current);
  49777. components.add (current);
  49778. }
  49779. }
  49780. }
  49781. if (components != oldList)
  49782. activeDocumentChanged();
  49783. }
  49784. END_JUCE_NAMESPACE
  49785. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49786. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49787. BEGIN_JUCE_NAMESPACE
  49788. const int zoneL = 1;
  49789. const int zoneR = 2;
  49790. const int zoneT = 4;
  49791. const int zoneB = 8;
  49792. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49793. ComponentBoundsConstrainer* const constrainer_)
  49794. : component (componentToResize),
  49795. constrainer (constrainer_),
  49796. borderSize (5),
  49797. mouseZone (0)
  49798. {
  49799. }
  49800. ResizableBorderComponent::~ResizableBorderComponent()
  49801. {
  49802. }
  49803. void ResizableBorderComponent::paint (Graphics& g)
  49804. {
  49805. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49806. }
  49807. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49808. {
  49809. updateMouseZone (e);
  49810. }
  49811. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49812. {
  49813. updateMouseZone (e);
  49814. }
  49815. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49816. {
  49817. if (component->isValidComponent())
  49818. {
  49819. updateMouseZone (e);
  49820. originalX = component->getX();
  49821. originalY = component->getY();
  49822. originalW = component->getWidth();
  49823. originalH = component->getHeight();
  49824. if (constrainer != 0)
  49825. constrainer->resizeStart();
  49826. }
  49827. else
  49828. {
  49829. jassertfalse
  49830. }
  49831. }
  49832. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49833. {
  49834. if (! component->isValidComponent())
  49835. {
  49836. jassertfalse
  49837. return;
  49838. }
  49839. int x = originalX;
  49840. int y = originalY;
  49841. int w = originalW;
  49842. int h = originalH;
  49843. const int dx = e.getDistanceFromDragStartX();
  49844. const int dy = e.getDistanceFromDragStartY();
  49845. if ((mouseZone & zoneL) != 0)
  49846. {
  49847. x += dx;
  49848. w -= dx;
  49849. }
  49850. if ((mouseZone & zoneT) != 0)
  49851. {
  49852. y += dy;
  49853. h -= dy;
  49854. }
  49855. if ((mouseZone & zoneR) != 0)
  49856. w += dx;
  49857. if ((mouseZone & zoneB) != 0)
  49858. h += dy;
  49859. if (constrainer != 0)
  49860. constrainer->setBoundsForComponent (component,
  49861. Rectangle<int> (x, y, w, h),
  49862. (mouseZone & zoneT) != 0,
  49863. (mouseZone & zoneL) != 0,
  49864. (mouseZone & zoneB) != 0,
  49865. (mouseZone & zoneR) != 0);
  49866. else
  49867. component->setBounds (x, y, w, h);
  49868. }
  49869. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49870. {
  49871. if (constrainer != 0)
  49872. constrainer->resizeEnd();
  49873. }
  49874. bool ResizableBorderComponent::hitTest (int x, int y)
  49875. {
  49876. return x < borderSize.getLeft()
  49877. || x >= getWidth() - borderSize.getRight()
  49878. || y < borderSize.getTop()
  49879. || y >= getHeight() - borderSize.getBottom();
  49880. }
  49881. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize) throw()
  49882. {
  49883. if (borderSize != newBorderSize)
  49884. {
  49885. borderSize = newBorderSize;
  49886. repaint();
  49887. }
  49888. }
  49889. const BorderSize ResizableBorderComponent::getBorderThickness() const throw()
  49890. {
  49891. return borderSize;
  49892. }
  49893. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e) throw()
  49894. {
  49895. int newZone = 0;
  49896. if (ResizableBorderComponent::hitTest (e.x, e.y))
  49897. {
  49898. if (e.x < jmax (borderSize.getLeft(),
  49899. proportionOfWidth (0.1f),
  49900. jmin (10, proportionOfWidth (0.33f))))
  49901. newZone |= zoneL;
  49902. else if (e.x >= jmin (getWidth() - borderSize.getRight(),
  49903. proportionOfWidth (0.9f),
  49904. getWidth() - jmin (10, proportionOfWidth (0.33f))))
  49905. newZone |= zoneR;
  49906. if (e.y < jmax (borderSize.getTop(),
  49907. proportionOfHeight (0.1f),
  49908. jmin (10, proportionOfHeight (0.33f))))
  49909. newZone |= zoneT;
  49910. else if (e.y >= jmin (getHeight() - borderSize.getBottom(),
  49911. proportionOfHeight (0.9f),
  49912. getHeight() - jmin (10, proportionOfHeight (0.33f))))
  49913. newZone |= zoneB;
  49914. }
  49915. if (mouseZone != newZone)
  49916. {
  49917. mouseZone = newZone;
  49918. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49919. switch (newZone)
  49920. {
  49921. case (zoneL | zoneT):
  49922. mc = MouseCursor::TopLeftCornerResizeCursor;
  49923. break;
  49924. case zoneT:
  49925. mc = MouseCursor::TopEdgeResizeCursor;
  49926. break;
  49927. case (zoneR | zoneT):
  49928. mc = MouseCursor::TopRightCornerResizeCursor;
  49929. break;
  49930. case zoneL:
  49931. mc = MouseCursor::LeftEdgeResizeCursor;
  49932. break;
  49933. case zoneR:
  49934. mc = MouseCursor::RightEdgeResizeCursor;
  49935. break;
  49936. case (zoneL | zoneB):
  49937. mc = MouseCursor::BottomLeftCornerResizeCursor;
  49938. break;
  49939. case zoneB:
  49940. mc = MouseCursor::BottomEdgeResizeCursor;
  49941. break;
  49942. case (zoneR | zoneB):
  49943. mc = MouseCursor::BottomRightCornerResizeCursor;
  49944. break;
  49945. default:
  49946. break;
  49947. }
  49948. setMouseCursor (mc);
  49949. }
  49950. }
  49951. END_JUCE_NAMESPACE
  49952. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49953. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49954. BEGIN_JUCE_NAMESPACE
  49955. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49956. ComponentBoundsConstrainer* const constrainer_)
  49957. : component (componentToResize),
  49958. constrainer (constrainer_)
  49959. {
  49960. setRepaintsOnMouseActivity (true);
  49961. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49962. }
  49963. ResizableCornerComponent::~ResizableCornerComponent()
  49964. {
  49965. }
  49966. void ResizableCornerComponent::paint (Graphics& g)
  49967. {
  49968. getLookAndFeel()
  49969. .drawCornerResizer (g, getWidth(), getHeight(),
  49970. isMouseOverOrDragging(),
  49971. isMouseButtonDown());
  49972. }
  49973. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49974. {
  49975. if (component->isValidComponent())
  49976. {
  49977. originalX = component->getX();
  49978. originalY = component->getY();
  49979. originalW = component->getWidth();
  49980. originalH = component->getHeight();
  49981. if (constrainer != 0)
  49982. constrainer->resizeStart();
  49983. }
  49984. else
  49985. {
  49986. jassertfalse
  49987. }
  49988. }
  49989. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49990. {
  49991. if (! component->isValidComponent())
  49992. {
  49993. jassertfalse
  49994. return;
  49995. }
  49996. int x = originalX;
  49997. int y = originalY;
  49998. int w = originalW + e.getDistanceFromDragStartX();
  49999. int h = originalH + e.getDistanceFromDragStartY();
  50000. if (constrainer != 0)
  50001. constrainer->setBoundsForComponent (component, Rectangle<int> (x, y, w, h),
  50002. false, false, true, true);
  50003. else
  50004. component->setBounds (x, y, w, h);
  50005. }
  50006. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  50007. {
  50008. if (constrainer != 0)
  50009. constrainer->resizeStart();
  50010. }
  50011. bool ResizableCornerComponent::hitTest (int x, int y)
  50012. {
  50013. if (getWidth() <= 0)
  50014. return false;
  50015. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  50016. return y >= yAtX - getHeight() / 4;
  50017. }
  50018. END_JUCE_NAMESPACE
  50019. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  50020. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  50021. BEGIN_JUCE_NAMESPACE
  50022. class ScrollbarButton : public Button
  50023. {
  50024. public:
  50025. int direction;
  50026. ScrollbarButton (const int direction_,
  50027. ScrollBar& owner_) throw()
  50028. : Button (String::empty),
  50029. direction (direction_),
  50030. owner (owner_)
  50031. {
  50032. setWantsKeyboardFocus (false);
  50033. }
  50034. ~ScrollbarButton()
  50035. {
  50036. }
  50037. void paintButton (Graphics& g,
  50038. bool isMouseOver,
  50039. bool isMouseDown)
  50040. {
  50041. getLookAndFeel()
  50042. .drawScrollbarButton (g, owner,
  50043. getWidth(), getHeight(),
  50044. direction,
  50045. owner.isVertical(),
  50046. isMouseOver, isMouseDown);
  50047. }
  50048. void clicked()
  50049. {
  50050. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  50051. }
  50052. juce_UseDebuggingNewOperator
  50053. private:
  50054. ScrollBar& owner;
  50055. ScrollbarButton (const ScrollbarButton&);
  50056. const ScrollbarButton& operator= (const ScrollbarButton&);
  50057. };
  50058. ScrollBar::ScrollBar (const bool vertical_,
  50059. const bool buttonsAreVisible)
  50060. : minimum (0.0),
  50061. maximum (1.0),
  50062. rangeStart (0.0),
  50063. rangeSize (0.1),
  50064. singleStepSize (0.1),
  50065. thumbAreaStart (0),
  50066. thumbAreaSize (0),
  50067. thumbStart (0),
  50068. thumbSize (0),
  50069. initialDelayInMillisecs (100),
  50070. repeatDelayInMillisecs (50),
  50071. minimumDelayInMillisecs (10),
  50072. vertical (vertical_),
  50073. isDraggingThumb (false),
  50074. alwaysVisible (false),
  50075. upButton (0),
  50076. downButton (0)
  50077. {
  50078. setButtonVisibility (buttonsAreVisible);
  50079. setRepaintsOnMouseActivity (true);
  50080. setFocusContainer (true);
  50081. }
  50082. ScrollBar::~ScrollBar()
  50083. {
  50084. deleteAllChildren();
  50085. }
  50086. void ScrollBar::setRangeLimits (const double newMinimum,
  50087. const double newMaximum) throw()
  50088. {
  50089. minimum = newMinimum;
  50090. maximum = newMaximum;
  50091. jassert (maximum >= minimum); // these can't be the wrong way round!
  50092. setCurrentRangeStart (rangeStart);
  50093. updateThumbPosition();
  50094. }
  50095. void ScrollBar::setCurrentRange (double newStart,
  50096. double newSize) throw()
  50097. {
  50098. newSize = jlimit (0.0, maximum - minimum, newSize);
  50099. newStart = jlimit (minimum, maximum - newSize, newStart);
  50100. if (rangeStart != newStart
  50101. || rangeSize != newSize)
  50102. {
  50103. rangeStart = newStart;
  50104. rangeSize = newSize;
  50105. updateThumbPosition();
  50106. triggerAsyncUpdate();
  50107. }
  50108. }
  50109. void ScrollBar::setCurrentRangeStart (double newStart) throw()
  50110. {
  50111. setCurrentRange (newStart, rangeSize);
  50112. }
  50113. void ScrollBar::setSingleStepSize (const double newSingleStepSize) throw()
  50114. {
  50115. singleStepSize = newSingleStepSize;
  50116. }
  50117. void ScrollBar::moveScrollbarInSteps (const int howManySteps) throw()
  50118. {
  50119. setCurrentRangeStart (rangeStart + howManySteps * singleStepSize);
  50120. }
  50121. void ScrollBar::moveScrollbarInPages (const int howManyPages) throw()
  50122. {
  50123. setCurrentRangeStart (rangeStart + howManyPages * rangeSize);
  50124. }
  50125. void ScrollBar::scrollToTop() throw()
  50126. {
  50127. setCurrentRangeStart (minimum);
  50128. }
  50129. void ScrollBar::scrollToBottom() throw()
  50130. {
  50131. setCurrentRangeStart (maximum - rangeSize);
  50132. }
  50133. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  50134. const int repeatDelayInMillisecs_,
  50135. const int minimumDelayInMillisecs_) throw()
  50136. {
  50137. initialDelayInMillisecs = initialDelayInMillisecs_;
  50138. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  50139. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  50140. if (upButton != 0)
  50141. {
  50142. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50143. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50144. }
  50145. }
  50146. void ScrollBar::addListener (ScrollBarListener* const listener) throw()
  50147. {
  50148. jassert (listener != 0);
  50149. if (listener != 0)
  50150. listeners.add (listener);
  50151. }
  50152. void ScrollBar::removeListener (ScrollBarListener* const listener) throw()
  50153. {
  50154. listeners.removeValue (listener);
  50155. }
  50156. void ScrollBar::handleAsyncUpdate()
  50157. {
  50158. const double value = getCurrentRangeStart();
  50159. for (int i = listeners.size(); --i >= 0;)
  50160. {
  50161. ((ScrollBarListener*) listeners.getUnchecked (i))->scrollBarMoved (this, value);
  50162. i = jmin (i, listeners.size());
  50163. }
  50164. }
  50165. void ScrollBar::updateThumbPosition() throw()
  50166. {
  50167. int newThumbSize = roundToInt ((maximum > minimum) ? (rangeSize * thumbAreaSize) / (maximum - minimum)
  50168. : thumbAreaSize);
  50169. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50170. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  50171. if (newThumbSize > thumbAreaSize)
  50172. newThumbSize = thumbAreaSize;
  50173. int newThumbStart = thumbAreaStart;
  50174. if (maximum - minimum > rangeSize)
  50175. newThumbStart += roundToInt (((rangeStart - minimum) * (thumbAreaSize - newThumbSize))
  50176. / ((maximum - minimum) - rangeSize));
  50177. setVisible (alwaysVisible || (maximum - minimum > rangeSize && rangeSize > 0.0));
  50178. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  50179. {
  50180. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  50181. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  50182. if (vertical)
  50183. repaint (0, repaintStart, getWidth(), repaintSize);
  50184. else
  50185. repaint (repaintStart, 0, repaintSize, getHeight());
  50186. thumbStart = newThumbStart;
  50187. thumbSize = newThumbSize;
  50188. }
  50189. }
  50190. void ScrollBar::setOrientation (const bool shouldBeVertical) throw()
  50191. {
  50192. if (vertical != shouldBeVertical)
  50193. {
  50194. vertical = shouldBeVertical;
  50195. if (upButton != 0)
  50196. {
  50197. ((ScrollbarButton*) upButton)->direction = (vertical) ? 0 : 3;
  50198. ((ScrollbarButton*) downButton)->direction = (vertical) ? 2 : 1;
  50199. }
  50200. updateThumbPosition();
  50201. }
  50202. }
  50203. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  50204. {
  50205. deleteAndZero (upButton);
  50206. deleteAndZero (downButton);
  50207. if (buttonsAreVisible)
  50208. {
  50209. addAndMakeVisible (upButton = new ScrollbarButton ((vertical) ? 0 : 3, *this));
  50210. addAndMakeVisible (downButton = new ScrollbarButton ((vertical) ? 2 : 1, *this));
  50211. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50212. }
  50213. updateThumbPosition();
  50214. }
  50215. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  50216. {
  50217. alwaysVisible = ! shouldHideWhenFullRange;
  50218. updateThumbPosition();
  50219. }
  50220. void ScrollBar::paint (Graphics& g)
  50221. {
  50222. if (thumbAreaSize > 0)
  50223. {
  50224. LookAndFeel& lf = getLookAndFeel();
  50225. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  50226. ? thumbSize : 0;
  50227. if (vertical)
  50228. {
  50229. lf.drawScrollbar (g, *this,
  50230. 0, thumbAreaStart,
  50231. getWidth(), thumbAreaSize,
  50232. vertical,
  50233. thumbStart, thumb,
  50234. isMouseOver(), isMouseButtonDown());
  50235. }
  50236. else
  50237. {
  50238. lf.drawScrollbar (g, *this,
  50239. thumbAreaStart, 0,
  50240. thumbAreaSize, getHeight(),
  50241. vertical,
  50242. thumbStart, thumb,
  50243. isMouseOver(), isMouseButtonDown());
  50244. }
  50245. }
  50246. }
  50247. void ScrollBar::lookAndFeelChanged()
  50248. {
  50249. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  50250. }
  50251. void ScrollBar::resized()
  50252. {
  50253. const int length = ((vertical) ? getHeight() : getWidth());
  50254. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  50255. : 0;
  50256. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50257. {
  50258. thumbAreaStart = length >> 1;
  50259. thumbAreaSize = 0;
  50260. }
  50261. else
  50262. {
  50263. thumbAreaStart = buttonSize;
  50264. thumbAreaSize = length - (buttonSize << 1);
  50265. }
  50266. if (upButton != 0)
  50267. {
  50268. if (vertical)
  50269. {
  50270. upButton->setBounds (0, 0, getWidth(), buttonSize);
  50271. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  50272. }
  50273. else
  50274. {
  50275. upButton->setBounds (0, 0, buttonSize, getHeight());
  50276. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  50277. }
  50278. }
  50279. updateThumbPosition();
  50280. }
  50281. void ScrollBar::mouseDown (const MouseEvent& e)
  50282. {
  50283. isDraggingThumb = false;
  50284. lastMousePos = vertical ? e.y : e.x;
  50285. dragStartMousePos = lastMousePos;
  50286. dragStartRange = rangeStart;
  50287. if (dragStartMousePos < thumbStart)
  50288. {
  50289. moveScrollbarInPages (-1);
  50290. startTimer (400);
  50291. }
  50292. else if (dragStartMousePos >= thumbStart + thumbSize)
  50293. {
  50294. moveScrollbarInPages (1);
  50295. startTimer (400);
  50296. }
  50297. else
  50298. {
  50299. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50300. && (thumbAreaSize > thumbSize);
  50301. }
  50302. }
  50303. void ScrollBar::mouseDrag (const MouseEvent& e)
  50304. {
  50305. if (isDraggingThumb)
  50306. {
  50307. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  50308. setCurrentRangeStart (dragStartRange
  50309. + deltaPixels * ((maximum - minimum) - rangeSize)
  50310. / (thumbAreaSize - thumbSize));
  50311. }
  50312. else
  50313. {
  50314. lastMousePos = (vertical) ? e.y : e.x;
  50315. }
  50316. }
  50317. void ScrollBar::mouseUp (const MouseEvent&)
  50318. {
  50319. isDraggingThumb = false;
  50320. stopTimer();
  50321. repaint();
  50322. }
  50323. void ScrollBar::mouseWheelMove (const MouseEvent&,
  50324. float wheelIncrementX,
  50325. float wheelIncrementY)
  50326. {
  50327. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  50328. if (increment < 0)
  50329. increment = jmin (increment * 10.0f, -1.0f);
  50330. else if (increment > 0)
  50331. increment = jmax (increment * 10.0f, 1.0f);
  50332. setCurrentRangeStart (rangeStart - singleStepSize * increment);
  50333. }
  50334. void ScrollBar::timerCallback()
  50335. {
  50336. if (isMouseButtonDown())
  50337. {
  50338. startTimer (40);
  50339. if (lastMousePos < thumbStart)
  50340. setCurrentRangeStart (rangeStart - rangeSize);
  50341. else if (lastMousePos > thumbStart + thumbSize)
  50342. setCurrentRangeStart (rangeStart + rangeSize);
  50343. }
  50344. else
  50345. {
  50346. stopTimer();
  50347. }
  50348. }
  50349. bool ScrollBar::keyPressed (const KeyPress& key)
  50350. {
  50351. if (! isVisible())
  50352. return false;
  50353. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  50354. moveScrollbarInSteps (-1);
  50355. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  50356. moveScrollbarInSteps (1);
  50357. else if (key.isKeyCode (KeyPress::pageUpKey))
  50358. moveScrollbarInPages (-1);
  50359. else if (key.isKeyCode (KeyPress::pageDownKey))
  50360. moveScrollbarInPages (1);
  50361. else if (key.isKeyCode (KeyPress::homeKey))
  50362. scrollToTop();
  50363. else if (key.isKeyCode (KeyPress::endKey))
  50364. scrollToBottom();
  50365. else
  50366. return false;
  50367. return true;
  50368. }
  50369. END_JUCE_NAMESPACE
  50370. /*** End of inlined file: juce_ScrollBar.cpp ***/
  50371. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  50372. BEGIN_JUCE_NAMESPACE
  50373. StretchableLayoutManager::StretchableLayoutManager()
  50374. : totalSize (0)
  50375. {
  50376. }
  50377. StretchableLayoutManager::~StretchableLayoutManager()
  50378. {
  50379. }
  50380. void StretchableLayoutManager::clearAllItems()
  50381. {
  50382. items.clear();
  50383. totalSize = 0;
  50384. }
  50385. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  50386. const double minimumSize,
  50387. const double maximumSize,
  50388. const double preferredSize)
  50389. {
  50390. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  50391. if (layout == 0)
  50392. {
  50393. layout = new ItemLayoutProperties();
  50394. layout->itemIndex = itemIndex;
  50395. int i;
  50396. for (i = 0; i < items.size(); ++i)
  50397. if (items.getUnchecked (i)->itemIndex > itemIndex)
  50398. break;
  50399. items.insert (i, layout);
  50400. }
  50401. layout->minSize = minimumSize;
  50402. layout->maxSize = maximumSize;
  50403. layout->preferredSize = preferredSize;
  50404. layout->currentSize = 0;
  50405. }
  50406. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  50407. double& minimumSize,
  50408. double& maximumSize,
  50409. double& preferredSize) const
  50410. {
  50411. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50412. if (layout != 0)
  50413. {
  50414. minimumSize = layout->minSize;
  50415. maximumSize = layout->maxSize;
  50416. preferredSize = layout->preferredSize;
  50417. return true;
  50418. }
  50419. return false;
  50420. }
  50421. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  50422. {
  50423. totalSize = newTotalSize;
  50424. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  50425. }
  50426. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  50427. {
  50428. int pos = 0;
  50429. for (int i = 0; i < itemIndex; ++i)
  50430. {
  50431. const ItemLayoutProperties* const layout = getInfoFor (i);
  50432. if (layout != 0)
  50433. pos += layout->currentSize;
  50434. }
  50435. return pos;
  50436. }
  50437. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  50438. {
  50439. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50440. if (layout != 0)
  50441. return layout->currentSize;
  50442. return 0;
  50443. }
  50444. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  50445. {
  50446. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50447. if (layout != 0)
  50448. return -layout->currentSize / (double) totalSize;
  50449. return 0;
  50450. }
  50451. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  50452. int newPosition)
  50453. {
  50454. for (int i = items.size(); --i >= 0;)
  50455. {
  50456. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  50457. if (layout->itemIndex == itemIndex)
  50458. {
  50459. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  50460. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  50461. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  50462. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  50463. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  50464. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  50465. endPos += layout->currentSize;
  50466. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  50467. updatePrefSizesToMatchCurrentPositions();
  50468. break;
  50469. }
  50470. }
  50471. }
  50472. void StretchableLayoutManager::layOutComponents (Component** const components,
  50473. int numComponents,
  50474. int x, int y, int w, int h,
  50475. const bool vertically,
  50476. const bool resizeOtherDimension)
  50477. {
  50478. setTotalSize (vertically ? h : w);
  50479. int pos = vertically ? y : x;
  50480. for (int i = 0; i < numComponents; ++i)
  50481. {
  50482. const ItemLayoutProperties* const layout = getInfoFor (i);
  50483. if (layout != 0)
  50484. {
  50485. Component* const c = components[i];
  50486. if (c != 0)
  50487. {
  50488. if (i == numComponents - 1)
  50489. {
  50490. // if it's the last item, crop it to exactly fit the available space..
  50491. if (resizeOtherDimension)
  50492. {
  50493. if (vertically)
  50494. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  50495. else
  50496. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  50497. }
  50498. else
  50499. {
  50500. if (vertically)
  50501. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  50502. else
  50503. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  50504. }
  50505. }
  50506. else
  50507. {
  50508. if (resizeOtherDimension)
  50509. {
  50510. if (vertically)
  50511. c->setBounds (x, pos, w, layout->currentSize);
  50512. else
  50513. c->setBounds (pos, y, layout->currentSize, h);
  50514. }
  50515. else
  50516. {
  50517. if (vertically)
  50518. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  50519. else
  50520. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  50521. }
  50522. }
  50523. }
  50524. pos += layout->currentSize;
  50525. }
  50526. }
  50527. }
  50528. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  50529. {
  50530. for (int i = items.size(); --i >= 0;)
  50531. if (items.getUnchecked(i)->itemIndex == itemIndex)
  50532. return items.getUnchecked(i);
  50533. return 0;
  50534. }
  50535. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  50536. const int endIndex,
  50537. const int availableSpace,
  50538. int startPos)
  50539. {
  50540. // calculate the total sizes
  50541. int i;
  50542. double totalIdealSize = 0.0;
  50543. int totalMinimums = 0;
  50544. for (i = startIndex; i < endIndex; ++i)
  50545. {
  50546. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50547. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  50548. totalMinimums += layout->currentSize;
  50549. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  50550. }
  50551. if (totalIdealSize <= 0)
  50552. totalIdealSize = 1.0;
  50553. // now calc the best sizes..
  50554. int extraSpace = availableSpace - totalMinimums;
  50555. while (extraSpace > 0)
  50556. {
  50557. int numWantingMoreSpace = 0;
  50558. int numHavingTakenExtraSpace = 0;
  50559. // first figure out how many comps want a slice of the extra space..
  50560. for (i = startIndex; i < endIndex; ++i)
  50561. {
  50562. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50563. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50564. const int bestSize = jlimit (layout->currentSize,
  50565. jmax (layout->currentSize,
  50566. sizeToRealSize (layout->maxSize, totalSize)),
  50567. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50568. if (bestSize > layout->currentSize)
  50569. ++numWantingMoreSpace;
  50570. }
  50571. // ..share out the extra space..
  50572. for (i = startIndex; i < endIndex; ++i)
  50573. {
  50574. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50575. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50576. int bestSize = jlimit (layout->currentSize,
  50577. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  50578. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50579. const int extraWanted = bestSize - layout->currentSize;
  50580. if (extraWanted > 0)
  50581. {
  50582. const int extraAllowed = jmin (extraWanted,
  50583. extraSpace / jmax (1, numWantingMoreSpace));
  50584. if (extraAllowed > 0)
  50585. {
  50586. ++numHavingTakenExtraSpace;
  50587. --numWantingMoreSpace;
  50588. layout->currentSize += extraAllowed;
  50589. extraSpace -= extraAllowed;
  50590. }
  50591. }
  50592. }
  50593. if (numHavingTakenExtraSpace <= 0)
  50594. break;
  50595. }
  50596. // ..and calculate the end position
  50597. for (i = startIndex; i < endIndex; ++i)
  50598. {
  50599. ItemLayoutProperties* const layout = items.getUnchecked(i);
  50600. startPos += layout->currentSize;
  50601. }
  50602. return startPos;
  50603. }
  50604. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  50605. const int endIndex) const
  50606. {
  50607. int totalMinimums = 0;
  50608. for (int i = startIndex; i < endIndex; ++i)
  50609. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  50610. return totalMinimums;
  50611. }
  50612. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  50613. {
  50614. int totalMaximums = 0;
  50615. for (int i = startIndex; i < endIndex; ++i)
  50616. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  50617. return totalMaximums;
  50618. }
  50619. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  50620. {
  50621. for (int i = 0; i < items.size(); ++i)
  50622. {
  50623. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50624. layout->preferredSize
  50625. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  50626. : getItemCurrentAbsoluteSize (i);
  50627. }
  50628. }
  50629. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  50630. {
  50631. if (size < 0)
  50632. size *= -totalSpace;
  50633. return roundToInt (size);
  50634. }
  50635. END_JUCE_NAMESPACE
  50636. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  50637. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50638. BEGIN_JUCE_NAMESPACE
  50639. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  50640. const int itemIndex_,
  50641. const bool isVertical_)
  50642. : layout (layout_),
  50643. itemIndex (itemIndex_),
  50644. isVertical (isVertical_)
  50645. {
  50646. setRepaintsOnMouseActivity (true);
  50647. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  50648. : MouseCursor::UpDownResizeCursor));
  50649. }
  50650. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  50651. {
  50652. }
  50653. void StretchableLayoutResizerBar::paint (Graphics& g)
  50654. {
  50655. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  50656. getWidth(), getHeight(),
  50657. isVertical,
  50658. isMouseOver(),
  50659. isMouseButtonDown());
  50660. }
  50661. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  50662. {
  50663. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  50664. }
  50665. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  50666. {
  50667. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  50668. : e.getDistanceFromDragStartY());
  50669. layout->setItemPosition (itemIndex, desiredPos);
  50670. hasBeenMoved();
  50671. }
  50672. void StretchableLayoutResizerBar::hasBeenMoved()
  50673. {
  50674. if (getParentComponent() != 0)
  50675. getParentComponent()->resized();
  50676. }
  50677. END_JUCE_NAMESPACE
  50678. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50679. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  50680. BEGIN_JUCE_NAMESPACE
  50681. StretchableObjectResizer::StretchableObjectResizer()
  50682. {
  50683. }
  50684. StretchableObjectResizer::~StretchableObjectResizer()
  50685. {
  50686. }
  50687. void StretchableObjectResizer::addItem (const double size,
  50688. const double minSize, const double maxSize,
  50689. const int order)
  50690. {
  50691. // the order must be >= 0 but less than the maximum integer value.
  50692. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  50693. Item* const item = new Item();
  50694. item->size = size;
  50695. item->minSize = minSize;
  50696. item->maxSize = maxSize;
  50697. item->order = order;
  50698. items.add (item);
  50699. }
  50700. double StretchableObjectResizer::getItemSize (const int index) const throw()
  50701. {
  50702. const Item* const it = items [index];
  50703. return it != 0 ? it->size : 0;
  50704. }
  50705. void StretchableObjectResizer::resizeToFit (const double targetSize)
  50706. {
  50707. int order = 0;
  50708. for (;;)
  50709. {
  50710. double currentSize = 0;
  50711. double minSize = 0;
  50712. double maxSize = 0;
  50713. int nextHighestOrder = std::numeric_limits<int>::max();
  50714. for (int i = 0; i < items.size(); ++i)
  50715. {
  50716. const Item* const it = items.getUnchecked(i);
  50717. currentSize += it->size;
  50718. if (it->order <= order)
  50719. {
  50720. minSize += it->minSize;
  50721. maxSize += it->maxSize;
  50722. }
  50723. else
  50724. {
  50725. minSize += it->size;
  50726. maxSize += it->size;
  50727. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50728. }
  50729. }
  50730. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50731. if (thisIterationTarget >= currentSize)
  50732. {
  50733. const double availableExtraSpace = maxSize - currentSize;
  50734. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50735. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50736. for (int i = 0; i < items.size(); ++i)
  50737. {
  50738. Item* const it = items.getUnchecked(i);
  50739. if (it->order <= order)
  50740. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50741. }
  50742. }
  50743. else
  50744. {
  50745. const double amountOfSlack = currentSize - minSize;
  50746. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50747. const double scale = targetAmountOfSlack / amountOfSlack;
  50748. for (int i = 0; i < items.size(); ++i)
  50749. {
  50750. Item* const it = items.getUnchecked(i);
  50751. if (it->order <= order)
  50752. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50753. }
  50754. }
  50755. if (nextHighestOrder < std::numeric_limits<int>::max())
  50756. order = nextHighestOrder;
  50757. else
  50758. break;
  50759. }
  50760. }
  50761. END_JUCE_NAMESPACE
  50762. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50763. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50764. BEGIN_JUCE_NAMESPACE
  50765. TabBarButton::TabBarButton (const String& name,
  50766. TabbedButtonBar* const owner_,
  50767. const int index)
  50768. : Button (name),
  50769. owner (owner_),
  50770. tabIndex (index),
  50771. overlapPixels (0)
  50772. {
  50773. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50774. setComponentEffect (&shadow);
  50775. setWantsKeyboardFocus (false);
  50776. }
  50777. TabBarButton::~TabBarButton()
  50778. {
  50779. }
  50780. void TabBarButton::paintButton (Graphics& g,
  50781. bool isMouseOverButton,
  50782. bool isButtonDown)
  50783. {
  50784. int x, y, w, h;
  50785. getActiveArea (x, y, w, h);
  50786. g.setOrigin (x, y);
  50787. getLookAndFeel()
  50788. .drawTabButton (g, w, h,
  50789. owner->getTabBackgroundColour (tabIndex),
  50790. tabIndex, getButtonText(), *this,
  50791. owner->getOrientation(),
  50792. isMouseOverButton, isButtonDown,
  50793. getToggleState());
  50794. }
  50795. void TabBarButton::clicked (const ModifierKeys& mods)
  50796. {
  50797. if (mods.isPopupMenu())
  50798. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50799. else
  50800. owner->setCurrentTabIndex (tabIndex);
  50801. }
  50802. bool TabBarButton::hitTest (int mx, int my)
  50803. {
  50804. int x, y, w, h;
  50805. getActiveArea (x, y, w, h);
  50806. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50807. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50808. {
  50809. if (((unsigned int) mx) < (unsigned int) getWidth()
  50810. && my >= y + overlapPixels
  50811. && my < y + h - overlapPixels)
  50812. return true;
  50813. }
  50814. else
  50815. {
  50816. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50817. && ((unsigned int) my) < (unsigned int) getHeight())
  50818. return true;
  50819. }
  50820. Path p;
  50821. getLookAndFeel()
  50822. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50823. owner->getOrientation(),
  50824. false, false, getToggleState());
  50825. return p.contains ((float) (mx - x),
  50826. (float) (my - y));
  50827. }
  50828. int TabBarButton::getBestTabLength (const int depth)
  50829. {
  50830. return jlimit (depth * 2,
  50831. depth * 7,
  50832. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50833. }
  50834. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50835. {
  50836. x = 0;
  50837. y = 0;
  50838. int r = getWidth();
  50839. int b = getHeight();
  50840. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50841. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50842. r -= spaceAroundImage;
  50843. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50844. x += spaceAroundImage;
  50845. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50846. y += spaceAroundImage;
  50847. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50848. b -= spaceAroundImage;
  50849. w = r - x;
  50850. h = b - y;
  50851. }
  50852. class TabAreaBehindFrontButtonComponent : public Component
  50853. {
  50854. public:
  50855. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50856. : owner (owner_)
  50857. {
  50858. setInterceptsMouseClicks (false, false);
  50859. }
  50860. ~TabAreaBehindFrontButtonComponent()
  50861. {
  50862. }
  50863. void paint (Graphics& g)
  50864. {
  50865. getLookAndFeel()
  50866. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50867. *owner, owner->getOrientation());
  50868. }
  50869. void enablementChanged()
  50870. {
  50871. repaint();
  50872. }
  50873. private:
  50874. TabbedButtonBar* const owner;
  50875. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50876. const TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50877. };
  50878. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50879. : orientation (orientation_),
  50880. currentTabIndex (-1),
  50881. extraTabsButton (0)
  50882. {
  50883. setInterceptsMouseClicks (false, true);
  50884. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50885. setFocusContainer (true);
  50886. }
  50887. TabbedButtonBar::~TabbedButtonBar()
  50888. {
  50889. deleteAllChildren();
  50890. }
  50891. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50892. {
  50893. orientation = newOrientation;
  50894. for (int i = getNumChildComponents(); --i >= 0;)
  50895. getChildComponent (i)->resized();
  50896. resized();
  50897. }
  50898. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50899. {
  50900. return new TabBarButton (name, this, index);
  50901. }
  50902. void TabbedButtonBar::clearTabs()
  50903. {
  50904. tabs.clear();
  50905. tabColours.clear();
  50906. currentTabIndex = -1;
  50907. deleteAndZero (extraTabsButton);
  50908. removeChildComponent (behindFrontTab);
  50909. deleteAllChildren();
  50910. addChildComponent (behindFrontTab);
  50911. setCurrentTabIndex (-1);
  50912. }
  50913. void TabbedButtonBar::addTab (const String& tabName,
  50914. const Colour& tabBackgroundColour,
  50915. int insertIndex)
  50916. {
  50917. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50918. if (tabName.isNotEmpty())
  50919. {
  50920. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50921. insertIndex = tabs.size();
  50922. for (int i = tabs.size(); --i >= insertIndex;)
  50923. {
  50924. TabBarButton* const tb = getTabButton (i);
  50925. if (tb != 0)
  50926. tb->tabIndex++;
  50927. }
  50928. tabs.insert (insertIndex, tabName);
  50929. tabColours.insert (insertIndex, tabBackgroundColour);
  50930. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50931. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50932. addAndMakeVisible (tb, insertIndex);
  50933. resized();
  50934. if (currentTabIndex < 0)
  50935. setCurrentTabIndex (0);
  50936. }
  50937. }
  50938. void TabbedButtonBar::setTabName (const int tabIndex,
  50939. const String& newName)
  50940. {
  50941. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50942. && tabs[tabIndex] != newName)
  50943. {
  50944. tabs.set (tabIndex, newName);
  50945. TabBarButton* const tb = getTabButton (tabIndex);
  50946. if (tb != 0)
  50947. tb->setButtonText (newName);
  50948. resized();
  50949. }
  50950. }
  50951. void TabbedButtonBar::removeTab (const int tabIndex)
  50952. {
  50953. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50954. {
  50955. const int oldTabIndex = currentTabIndex;
  50956. if (currentTabIndex == tabIndex)
  50957. currentTabIndex = -1;
  50958. tabs.remove (tabIndex);
  50959. tabColours.remove (tabIndex);
  50960. delete getTabButton (tabIndex);
  50961. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50962. {
  50963. TabBarButton* const tb = getTabButton (i);
  50964. if (tb != 0)
  50965. tb->tabIndex--;
  50966. }
  50967. resized();
  50968. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50969. }
  50970. }
  50971. void TabbedButtonBar::moveTab (const int currentIndex,
  50972. const int newIndex)
  50973. {
  50974. tabs.move (currentIndex, newIndex);
  50975. tabColours.move (currentIndex, newIndex);
  50976. resized();
  50977. }
  50978. int TabbedButtonBar::getNumTabs() const
  50979. {
  50980. return tabs.size();
  50981. }
  50982. const StringArray TabbedButtonBar::getTabNames() const
  50983. {
  50984. return tabs;
  50985. }
  50986. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50987. {
  50988. if (currentTabIndex != newIndex)
  50989. {
  50990. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50991. newIndex = -1;
  50992. currentTabIndex = newIndex;
  50993. for (int i = 0; i < getNumChildComponents(); ++i)
  50994. {
  50995. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50996. if (tb != 0)
  50997. tb->setToggleState (tb->tabIndex == newIndex, false);
  50998. }
  50999. resized();
  51000. if (sendChangeMessage_)
  51001. sendChangeMessage (this);
  51002. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  51003. }
  51004. }
  51005. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  51006. {
  51007. for (int i = getNumChildComponents(); --i >= 0;)
  51008. {
  51009. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  51010. if (tb != 0 && tb->tabIndex == index)
  51011. return tb;
  51012. }
  51013. return 0;
  51014. }
  51015. void TabbedButtonBar::lookAndFeelChanged()
  51016. {
  51017. deleteAndZero (extraTabsButton);
  51018. resized();
  51019. }
  51020. void TabbedButtonBar::resized()
  51021. {
  51022. const double minimumScale = 0.7;
  51023. int depth = getWidth();
  51024. int length = getHeight();
  51025. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  51026. swapVariables (depth, length);
  51027. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  51028. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  51029. int i, totalLength = overlap;
  51030. int numVisibleButtons = tabs.size();
  51031. for (i = 0; i < getNumChildComponents(); ++i)
  51032. {
  51033. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  51034. if (tb != 0)
  51035. {
  51036. totalLength += tb->getBestTabLength (depth) - overlap;
  51037. tb->overlapPixels = overlap / 2;
  51038. }
  51039. }
  51040. double scale = 1.0;
  51041. if (totalLength > length)
  51042. scale = jmax (minimumScale, length / (double) totalLength);
  51043. const bool isTooBig = totalLength * scale > length;
  51044. int tabsButtonPos = 0;
  51045. if (isTooBig)
  51046. {
  51047. if (extraTabsButton == 0)
  51048. {
  51049. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  51050. extraTabsButton->addButtonListener (this);
  51051. extraTabsButton->setAlwaysOnTop (true);
  51052. extraTabsButton->setTriggeredOnMouseDown (true);
  51053. }
  51054. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  51055. extraTabsButton->setSize (buttonSize, buttonSize);
  51056. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  51057. {
  51058. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  51059. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  51060. }
  51061. else
  51062. {
  51063. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  51064. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  51065. }
  51066. totalLength = 0;
  51067. for (i = 0; i < tabs.size(); ++i)
  51068. {
  51069. TabBarButton* const tb = getTabButton (i);
  51070. if (tb != 0)
  51071. {
  51072. const int newLength = totalLength + tb->getBestTabLength (depth);
  51073. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  51074. {
  51075. totalLength += overlap;
  51076. break;
  51077. }
  51078. numVisibleButtons = i + 1;
  51079. totalLength = newLength - overlap;
  51080. }
  51081. }
  51082. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  51083. }
  51084. else
  51085. {
  51086. deleteAndZero (extraTabsButton);
  51087. }
  51088. int pos = 0;
  51089. TabBarButton* frontTab = 0;
  51090. for (i = 0; i < tabs.size(); ++i)
  51091. {
  51092. TabBarButton* const tb = getTabButton (i);
  51093. if (tb != 0)
  51094. {
  51095. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  51096. if (i < numVisibleButtons)
  51097. {
  51098. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  51099. tb->setBounds (pos, 0, bestLength, getHeight());
  51100. else
  51101. tb->setBounds (0, pos, getWidth(), bestLength);
  51102. tb->toBack();
  51103. if (tb->tabIndex == currentTabIndex)
  51104. frontTab = tb;
  51105. tb->setVisible (true);
  51106. }
  51107. else
  51108. {
  51109. tb->setVisible (false);
  51110. }
  51111. pos += bestLength - overlap;
  51112. }
  51113. }
  51114. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  51115. if (frontTab != 0)
  51116. {
  51117. frontTab->toFront (false);
  51118. behindFrontTab->toBehind (frontTab);
  51119. }
  51120. }
  51121. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  51122. {
  51123. return tabColours [tabIndex];
  51124. }
  51125. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51126. {
  51127. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  51128. && tabColours [tabIndex] != newColour)
  51129. {
  51130. tabColours.set (tabIndex, newColour);
  51131. repaint();
  51132. }
  51133. }
  51134. void TabbedButtonBar::buttonClicked (Button* button)
  51135. {
  51136. if (extraTabsButton == button)
  51137. {
  51138. PopupMenu m;
  51139. for (int i = 0; i < tabs.size(); ++i)
  51140. {
  51141. TabBarButton* const tb = getTabButton (i);
  51142. if (tb != 0 && ! tb->isVisible())
  51143. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  51144. }
  51145. const int res = m.showAt (extraTabsButton);
  51146. if (res != 0)
  51147. setCurrentTabIndex (res - 1);
  51148. }
  51149. }
  51150. void TabbedButtonBar::currentTabChanged (const int, const String&)
  51151. {
  51152. }
  51153. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  51154. {
  51155. }
  51156. END_JUCE_NAMESPACE
  51157. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  51158. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  51159. BEGIN_JUCE_NAMESPACE
  51160. class TabCompButtonBar : public TabbedButtonBar
  51161. {
  51162. public:
  51163. TabCompButtonBar (TabbedComponent* const owner_,
  51164. const TabbedButtonBar::Orientation orientation)
  51165. : TabbedButtonBar (orientation),
  51166. owner (owner_)
  51167. {
  51168. }
  51169. ~TabCompButtonBar()
  51170. {
  51171. }
  51172. void currentTabChanged (const int newCurrentTabIndex,
  51173. const String& newTabName)
  51174. {
  51175. owner->changeCallback (newCurrentTabIndex, newTabName);
  51176. }
  51177. void popupMenuClickOnTab (const int tabIndex,
  51178. const String& tabName)
  51179. {
  51180. owner->popupMenuClickOnTab (tabIndex, tabName);
  51181. }
  51182. const Colour getTabBackgroundColour (const int tabIndex)
  51183. {
  51184. return owner->tabs->getTabBackgroundColour (tabIndex);
  51185. }
  51186. TabBarButton* createTabButton (const String& tabName, const int tabIndex)
  51187. {
  51188. return owner->createTabButton (tabName, tabIndex);
  51189. }
  51190. juce_UseDebuggingNewOperator
  51191. private:
  51192. TabbedComponent* const owner;
  51193. TabCompButtonBar (const TabCompButtonBar&);
  51194. const TabCompButtonBar& operator= (const TabCompButtonBar&);
  51195. };
  51196. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  51197. : panelComponent (0),
  51198. tabDepth (30),
  51199. outlineThickness (1),
  51200. edgeIndent (0)
  51201. {
  51202. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  51203. }
  51204. TabbedComponent::~TabbedComponent()
  51205. {
  51206. clearTabs();
  51207. delete tabs;
  51208. }
  51209. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  51210. {
  51211. tabs->setOrientation (orientation);
  51212. resized();
  51213. }
  51214. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  51215. {
  51216. return tabs->getOrientation();
  51217. }
  51218. void TabbedComponent::setTabBarDepth (const int newDepth)
  51219. {
  51220. if (tabDepth != newDepth)
  51221. {
  51222. tabDepth = newDepth;
  51223. resized();
  51224. }
  51225. }
  51226. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  51227. {
  51228. return new TabBarButton (tabName, tabs, tabIndex);
  51229. }
  51230. void TabbedComponent::clearTabs()
  51231. {
  51232. if (panelComponent != 0)
  51233. {
  51234. panelComponent->setVisible (false);
  51235. removeChildComponent (panelComponent);
  51236. panelComponent = 0;
  51237. }
  51238. tabs->clearTabs();
  51239. for (int i = contentComponents.size(); --i >= 0;)
  51240. {
  51241. Component* const c = contentComponents.getUnchecked(i);
  51242. // be careful not to delete these components until they've been removed from the tab component
  51243. jassert (c == 0 || c->isValidComponent());
  51244. if (c != 0 && c->getProperties() ["deleteByTabComp_"])
  51245. delete c;
  51246. }
  51247. contentComponents.clear();
  51248. }
  51249. void TabbedComponent::addTab (const String& tabName,
  51250. const Colour& tabBackgroundColour,
  51251. Component* const contentComponent,
  51252. const bool deleteComponentWhenNotNeeded,
  51253. const int insertIndex)
  51254. {
  51255. contentComponents.insert (insertIndex, contentComponent);
  51256. if (contentComponent != 0)
  51257. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  51258. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  51259. }
  51260. void TabbedComponent::setTabName (const int tabIndex,
  51261. const String& newName)
  51262. {
  51263. tabs->setTabName (tabIndex, newName);
  51264. }
  51265. void TabbedComponent::removeTab (const int tabIndex)
  51266. {
  51267. Component* const c = contentComponents [tabIndex];
  51268. if (c != 0 && c->getProperties() ["deleteByTabComp_"])
  51269. {
  51270. if (c == panelComponent)
  51271. panelComponent = 0;
  51272. delete c;
  51273. }
  51274. contentComponents.remove (tabIndex);
  51275. tabs->removeTab (tabIndex);
  51276. }
  51277. int TabbedComponent::getNumTabs() const
  51278. {
  51279. return tabs->getNumTabs();
  51280. }
  51281. const StringArray TabbedComponent::getTabNames() const
  51282. {
  51283. return tabs->getTabNames();
  51284. }
  51285. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  51286. {
  51287. return contentComponents [tabIndex];
  51288. }
  51289. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  51290. {
  51291. return tabs->getTabBackgroundColour (tabIndex);
  51292. }
  51293. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51294. {
  51295. tabs->setTabBackgroundColour (tabIndex, newColour);
  51296. if (getCurrentTabIndex() == tabIndex)
  51297. repaint();
  51298. }
  51299. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  51300. {
  51301. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  51302. }
  51303. int TabbedComponent::getCurrentTabIndex() const
  51304. {
  51305. return tabs->getCurrentTabIndex();
  51306. }
  51307. const String& TabbedComponent::getCurrentTabName() const
  51308. {
  51309. return tabs->getCurrentTabName();
  51310. }
  51311. void TabbedComponent::setOutline (int thickness)
  51312. {
  51313. outlineThickness = thickness;
  51314. repaint();
  51315. }
  51316. void TabbedComponent::setIndent (const int indentThickness)
  51317. {
  51318. edgeIndent = indentThickness;
  51319. }
  51320. void TabbedComponent::paint (Graphics& g)
  51321. {
  51322. g.fillAll (findColour (backgroundColourId));
  51323. const TabbedButtonBar::Orientation o = getOrientation();
  51324. int x = 0;
  51325. int y = 0;
  51326. int r = getWidth();
  51327. int b = getHeight();
  51328. if (o == TabbedButtonBar::TabsAtTop)
  51329. y += tabDepth;
  51330. else if (o == TabbedButtonBar::TabsAtBottom)
  51331. b -= tabDepth;
  51332. else if (o == TabbedButtonBar::TabsAtLeft)
  51333. x += tabDepth;
  51334. else if (o == TabbedButtonBar::TabsAtRight)
  51335. r -= tabDepth;
  51336. g.reduceClipRegion (x, y, r - x, b - y);
  51337. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  51338. if (outlineThickness > 0)
  51339. {
  51340. if (o == TabbedButtonBar::TabsAtTop)
  51341. --y;
  51342. else if (o == TabbedButtonBar::TabsAtBottom)
  51343. ++b;
  51344. else if (o == TabbedButtonBar::TabsAtLeft)
  51345. --x;
  51346. else if (o == TabbedButtonBar::TabsAtRight)
  51347. ++r;
  51348. g.setColour (findColour (outlineColourId));
  51349. g.drawRect (x, y, r - x, b - y, outlineThickness);
  51350. }
  51351. }
  51352. void TabbedComponent::resized()
  51353. {
  51354. const TabbedButtonBar::Orientation o = getOrientation();
  51355. const int indent = edgeIndent + outlineThickness;
  51356. BorderSize indents (indent);
  51357. if (o == TabbedButtonBar::TabsAtTop)
  51358. {
  51359. tabs->setBounds (0, 0, getWidth(), tabDepth);
  51360. indents.setTop (tabDepth + edgeIndent);
  51361. }
  51362. else if (o == TabbedButtonBar::TabsAtBottom)
  51363. {
  51364. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  51365. indents.setBottom (tabDepth + edgeIndent);
  51366. }
  51367. else if (o == TabbedButtonBar::TabsAtLeft)
  51368. {
  51369. tabs->setBounds (0, 0, tabDepth, getHeight());
  51370. indents.setLeft (tabDepth + edgeIndent);
  51371. }
  51372. else if (o == TabbedButtonBar::TabsAtRight)
  51373. {
  51374. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  51375. indents.setRight (tabDepth + edgeIndent);
  51376. }
  51377. const Rectangle<int> bounds (indents.subtractedFrom (Rectangle<int> (0, 0, getWidth(), getHeight())));
  51378. for (int i = contentComponents.size(); --i >= 0;)
  51379. if (contentComponents.getUnchecked (i) != 0)
  51380. contentComponents.getUnchecked (i)->setBounds (bounds);
  51381. }
  51382. void TabbedComponent::lookAndFeelChanged()
  51383. {
  51384. for (int i = contentComponents.size(); --i >= 0;)
  51385. if (contentComponents.getUnchecked (i) != 0)
  51386. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  51387. }
  51388. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  51389. const String& newTabName)
  51390. {
  51391. if (panelComponent != 0)
  51392. {
  51393. panelComponent->setVisible (false);
  51394. removeChildComponent (panelComponent);
  51395. panelComponent = 0;
  51396. }
  51397. if (getCurrentTabIndex() >= 0)
  51398. {
  51399. panelComponent = contentComponents [getCurrentTabIndex()];
  51400. if (panelComponent != 0)
  51401. {
  51402. // do these ops as two stages instead of addAndMakeVisible() so that the
  51403. // component has always got a parent when it gets the visibilityChanged() callback
  51404. addChildComponent (panelComponent);
  51405. panelComponent->setVisible (true);
  51406. panelComponent->toFront (true);
  51407. }
  51408. repaint();
  51409. }
  51410. resized();
  51411. currentTabChanged (newCurrentTabIndex, newTabName);
  51412. }
  51413. void TabbedComponent::currentTabChanged (const int, const String&)
  51414. {
  51415. }
  51416. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  51417. {
  51418. }
  51419. END_JUCE_NAMESPACE
  51420. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  51421. /*** Start of inlined file: juce_Viewport.cpp ***/
  51422. BEGIN_JUCE_NAMESPACE
  51423. Viewport::Viewport (const String& componentName)
  51424. : Component (componentName),
  51425. contentComp (0),
  51426. lastVX (0),
  51427. lastVY (0),
  51428. lastVW (0),
  51429. lastVH (0),
  51430. scrollBarThickness (0),
  51431. singleStepX (16),
  51432. singleStepY (16),
  51433. showHScrollbar (true),
  51434. showVScrollbar (true)
  51435. {
  51436. // content holder is used to clip the contents so they don't overlap the scrollbars
  51437. addAndMakeVisible (contentHolder = new Component());
  51438. contentHolder->setInterceptsMouseClicks (false, true);
  51439. verticalScrollBar = new ScrollBar (true);
  51440. horizontalScrollBar = new ScrollBar (false);
  51441. addChildComponent (verticalScrollBar);
  51442. addChildComponent (horizontalScrollBar);
  51443. verticalScrollBar->addListener (this);
  51444. horizontalScrollBar->addListener (this);
  51445. setInterceptsMouseClicks (false, true);
  51446. setWantsKeyboardFocus (true);
  51447. }
  51448. Viewport::~Viewport()
  51449. {
  51450. contentHolder->deleteAllChildren();
  51451. deleteAllChildren();
  51452. }
  51453. void Viewport::visibleAreaChanged (int, int, int, int)
  51454. {
  51455. }
  51456. void Viewport::setViewedComponent (Component* const newViewedComponent)
  51457. {
  51458. if (contentComp != newViewedComponent)
  51459. {
  51460. if (contentComp->isValidComponent())
  51461. {
  51462. Component* const oldComp = contentComp;
  51463. contentComp = 0;
  51464. delete oldComp;
  51465. }
  51466. contentComp = newViewedComponent;
  51467. if (contentComp != 0)
  51468. {
  51469. contentComp->setTopLeftPosition (0, 0);
  51470. contentHolder->addAndMakeVisible (contentComp);
  51471. contentComp->addComponentListener (this);
  51472. }
  51473. updateVisibleRegion();
  51474. }
  51475. }
  51476. int Viewport::getMaximumVisibleWidth() const throw()
  51477. {
  51478. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51479. }
  51480. int Viewport::getMaximumVisibleHeight() const throw()
  51481. {
  51482. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51483. }
  51484. void Viewport::setViewPosition (const int xPixelsOffset,
  51485. const int yPixelsOffset)
  51486. {
  51487. if (contentComp != 0)
  51488. contentComp->setTopLeftPosition (-xPixelsOffset,
  51489. -yPixelsOffset);
  51490. }
  51491. void Viewport::setViewPositionProportionately (const double x,
  51492. const double y)
  51493. {
  51494. if (contentComp != 0)
  51495. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  51496. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  51497. }
  51498. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  51499. {
  51500. if (contentComp != 0)
  51501. {
  51502. int dx = 0, dy = 0;
  51503. if (mouseX < activeBorderThickness)
  51504. dx = activeBorderThickness - mouseX;
  51505. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  51506. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  51507. if (dx < 0)
  51508. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  51509. else
  51510. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  51511. if (mouseY < activeBorderThickness)
  51512. dy = activeBorderThickness - mouseY;
  51513. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  51514. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  51515. if (dy < 0)
  51516. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  51517. else
  51518. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  51519. if (dx != 0 || dy != 0)
  51520. {
  51521. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  51522. contentComp->getY() + dy);
  51523. return true;
  51524. }
  51525. }
  51526. return false;
  51527. }
  51528. void Viewport::componentMovedOrResized (Component&, bool, bool)
  51529. {
  51530. updateVisibleRegion();
  51531. }
  51532. void Viewport::resized()
  51533. {
  51534. updateVisibleRegion();
  51535. }
  51536. void Viewport::updateVisibleRegion()
  51537. {
  51538. if (contentComp != 0)
  51539. {
  51540. const int newVX = -contentComp->getX();
  51541. const int newVY = -contentComp->getY();
  51542. if (newVX == 0 && newVY == 0
  51543. && contentComp->getWidth() <= getWidth()
  51544. && contentComp->getHeight() <= getHeight())
  51545. {
  51546. horizontalScrollBar->setVisible (false);
  51547. verticalScrollBar->setVisible (false);
  51548. }
  51549. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  51550. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51551. horizontalScrollBar->setSingleStepSize (singleStepX);
  51552. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  51553. horizontalScrollBar->setVisible (false);
  51554. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  51555. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51556. verticalScrollBar->setSingleStepSize (singleStepY);
  51557. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  51558. verticalScrollBar->setVisible (false);
  51559. if (verticalScrollBar->isVisible())
  51560. {
  51561. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51562. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51563. verticalScrollBar
  51564. ->setBounds (getMaximumVisibleWidth(), 0,
  51565. getScrollBarThickness(), getMaximumVisibleHeight());
  51566. }
  51567. if (horizontalScrollBar->isVisible())
  51568. {
  51569. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51570. horizontalScrollBar
  51571. ->setBounds (0, getMaximumVisibleHeight(),
  51572. getMaximumVisibleWidth(), getScrollBarThickness());
  51573. }
  51574. contentHolder->setSize (getMaximumVisibleWidth(),
  51575. getMaximumVisibleHeight());
  51576. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  51577. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  51578. if (newVX != lastVX
  51579. || newVY != lastVY
  51580. || newVW != lastVW
  51581. || newVH != lastVH)
  51582. {
  51583. lastVX = newVX;
  51584. lastVY = newVY;
  51585. lastVW = newVW;
  51586. lastVH = newVH;
  51587. visibleAreaChanged (newVX, newVY, newVW, newVH);
  51588. }
  51589. horizontalScrollBar->handleUpdateNowIfNeeded();
  51590. verticalScrollBar->handleUpdateNowIfNeeded();
  51591. }
  51592. else
  51593. {
  51594. horizontalScrollBar->setVisible (false);
  51595. verticalScrollBar->setVisible (false);
  51596. }
  51597. }
  51598. void Viewport::setSingleStepSizes (const int stepX,
  51599. const int stepY)
  51600. {
  51601. singleStepX = stepX;
  51602. singleStepY = stepY;
  51603. updateVisibleRegion();
  51604. }
  51605. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  51606. const bool showHorizontalScrollbarIfNeeded)
  51607. {
  51608. showVScrollbar = showVerticalScrollbarIfNeeded;
  51609. showHScrollbar = showHorizontalScrollbarIfNeeded;
  51610. updateVisibleRegion();
  51611. }
  51612. void Viewport::setScrollBarThickness (const int thickness)
  51613. {
  51614. scrollBarThickness = thickness;
  51615. updateVisibleRegion();
  51616. }
  51617. int Viewport::getScrollBarThickness() const throw()
  51618. {
  51619. return (scrollBarThickness > 0) ? scrollBarThickness
  51620. : getLookAndFeel().getDefaultScrollbarWidth();
  51621. }
  51622. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  51623. {
  51624. verticalScrollBar->setButtonVisibility (buttonsVisible);
  51625. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  51626. }
  51627. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  51628. {
  51629. if (scrollBarThatHasMoved == horizontalScrollBar)
  51630. {
  51631. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  51632. }
  51633. else if (scrollBarThatHasMoved == verticalScrollBar)
  51634. {
  51635. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  51636. }
  51637. }
  51638. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51639. {
  51640. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  51641. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  51642. }
  51643. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51644. {
  51645. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  51646. {
  51647. const bool hasVertBar = verticalScrollBar->isVisible();
  51648. const bool hasHorzBar = horizontalScrollBar->isVisible();
  51649. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  51650. {
  51651. if (wheelIncrementX == 0 && ! hasVertBar)
  51652. wheelIncrementX = wheelIncrementY;
  51653. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  51654. wheelIncrementX, wheelIncrementY);
  51655. return true;
  51656. }
  51657. else if (hasVertBar && wheelIncrementY != 0)
  51658. {
  51659. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  51660. wheelIncrementX, wheelIncrementY);
  51661. return true;
  51662. }
  51663. }
  51664. return false;
  51665. }
  51666. bool Viewport::keyPressed (const KeyPress& key)
  51667. {
  51668. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  51669. || key.isKeyCode (KeyPress::downKey)
  51670. || key.isKeyCode (KeyPress::pageUpKey)
  51671. || key.isKeyCode (KeyPress::pageDownKey)
  51672. || key.isKeyCode (KeyPress::homeKey)
  51673. || key.isKeyCode (KeyPress::endKey);
  51674. if (verticalScrollBar->isVisible() && isUpDownKey)
  51675. return verticalScrollBar->keyPressed (key);
  51676. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  51677. || key.isKeyCode (KeyPress::rightKey);
  51678. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  51679. return horizontalScrollBar->keyPressed (key);
  51680. return false;
  51681. }
  51682. END_JUCE_NAMESPACE
  51683. /*** End of inlined file: juce_Viewport.cpp ***/
  51684. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  51685. BEGIN_JUCE_NAMESPACE
  51686. static const Colour createBaseColour (const Colour& buttonColour,
  51687. const bool hasKeyboardFocus,
  51688. const bool isMouseOverButton,
  51689. const bool isButtonDown) throw()
  51690. {
  51691. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  51692. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  51693. if (isButtonDown)
  51694. return baseColour.contrasting (0.2f);
  51695. else if (isMouseOverButton)
  51696. return baseColour.contrasting (0.1f);
  51697. return baseColour;
  51698. }
  51699. static String defaultSansName, defaultSerifName, defaultFixedName;
  51700. void clearUpDefaultFontNames() throw()
  51701. {
  51702. defaultSansName = String::empty;
  51703. defaultSerifName = String::empty;
  51704. defaultFixedName = String::empty;
  51705. }
  51706. LookAndFeel::LookAndFeel()
  51707. {
  51708. /* if this fails it means you're trying to create a LookAndFeel object before
  51709. the static Colours have been initialised. That ain't gonna work. It probably
  51710. means that you're using a static LookAndFeel object and that your compiler has
  51711. decided to intialise it before the Colours class.
  51712. */
  51713. jassert (Colours::white == Colour (0xffffffff));
  51714. // set up the standard set of colours..
  51715. const int textButtonColour = 0xffbbbbff;
  51716. const int textHighlightColour = 0x401111ee;
  51717. const int standardOutlineColour = 0xb2808080;
  51718. static const int standardColours[] =
  51719. {
  51720. TextButton::buttonColourId, textButtonColour,
  51721. TextButton::buttonOnColourId, 0xff4444ff,
  51722. TextButton::textColourOnId, 0xff000000,
  51723. TextButton::textColourOffId, 0xff000000,
  51724. ComboBox::buttonColourId, 0xffbbbbff,
  51725. ComboBox::outlineColourId, standardOutlineColour,
  51726. ToggleButton::textColourId, 0xff000000,
  51727. TextEditor::backgroundColourId, 0xffffffff,
  51728. TextEditor::textColourId, 0xff000000,
  51729. TextEditor::highlightColourId, textHighlightColour,
  51730. TextEditor::highlightedTextColourId, 0xff000000,
  51731. TextEditor::caretColourId, 0xff000000,
  51732. TextEditor::outlineColourId, 0x00000000,
  51733. TextEditor::focusedOutlineColourId, textButtonColour,
  51734. TextEditor::shadowColourId, 0x38000000,
  51735. Label::backgroundColourId, 0x00000000,
  51736. Label::textColourId, 0xff000000,
  51737. Label::outlineColourId, 0x00000000,
  51738. ScrollBar::backgroundColourId, 0x00000000,
  51739. ScrollBar::thumbColourId, 0xffffffff,
  51740. ScrollBar::trackColourId, 0xffffffff,
  51741. TreeView::linesColourId, 0x4c000000,
  51742. TreeView::backgroundColourId, 0x00000000,
  51743. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51744. PopupMenu::backgroundColourId, 0xffffffff,
  51745. PopupMenu::textColourId, 0xff000000,
  51746. PopupMenu::headerTextColourId, 0xff000000,
  51747. PopupMenu::highlightedTextColourId, 0xffffffff,
  51748. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51749. ComboBox::textColourId, 0xff000000,
  51750. ComboBox::backgroundColourId, 0xffffffff,
  51751. ComboBox::arrowColourId, 0x99000000,
  51752. ListBox::backgroundColourId, 0xffffffff,
  51753. ListBox::outlineColourId, standardOutlineColour,
  51754. ListBox::textColourId, 0xff000000,
  51755. Slider::backgroundColourId, 0x00000000,
  51756. Slider::thumbColourId, textButtonColour,
  51757. Slider::trackColourId, 0x7fffffff,
  51758. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51759. Slider::rotarySliderOutlineColourId, 0x66000000,
  51760. Slider::textBoxTextColourId, 0xff000000,
  51761. Slider::textBoxBackgroundColourId, 0xffffffff,
  51762. Slider::textBoxHighlightColourId, textHighlightColour,
  51763. Slider::textBoxOutlineColourId, standardOutlineColour,
  51764. ResizableWindow::backgroundColourId, 0xff777777,
  51765. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51766. AlertWindow::backgroundColourId, 0xffededed,
  51767. AlertWindow::textColourId, 0xff000000,
  51768. AlertWindow::outlineColourId, 0xff666666,
  51769. ProgressBar::backgroundColourId, 0xffeeeeee,
  51770. ProgressBar::foregroundColourId, 0xffaaaaee,
  51771. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51772. TooltipWindow::textColourId, 0xff000000,
  51773. TooltipWindow::outlineColourId, 0x4c000000,
  51774. TabbedComponent::backgroundColourId, 0x00000000,
  51775. TabbedComponent::outlineColourId, 0xff777777,
  51776. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51777. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51778. Toolbar::backgroundColourId, 0xfff6f8f9,
  51779. Toolbar::separatorColourId, 0x4c000000,
  51780. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51781. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51782. Toolbar::labelTextColourId, 0xff000000,
  51783. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51784. HyperlinkButton::textColourId, 0xcc1111ee,
  51785. GroupComponent::outlineColourId, 0x66000000,
  51786. GroupComponent::textColourId, 0xff000000,
  51787. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51788. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51789. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51790. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51791. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51792. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51793. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51794. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51795. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51796. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51797. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51798. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51799. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51800. CodeEditorComponent::caretColourId, 0xff000000,
  51801. CodeEditorComponent::highlightColourId, textHighlightColour,
  51802. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51803. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51804. ColourSelector::labelTextColourId, 0xff000000,
  51805. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51806. KeyMappingEditorComponent::textColourId, 0xff000000,
  51807. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51808. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51809. };
  51810. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51811. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51812. if (defaultSansName.isEmpty())
  51813. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51814. defaultSans = defaultSansName;
  51815. defaultSerif = defaultSerifName;
  51816. defaultFixed = defaultFixedName;
  51817. }
  51818. LookAndFeel::~LookAndFeel()
  51819. {
  51820. }
  51821. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51822. {
  51823. const int index = colourIds.indexOf (colourId);
  51824. if (index >= 0)
  51825. return colours [index];
  51826. jassertfalse
  51827. return Colours::black;
  51828. }
  51829. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51830. {
  51831. const int index = colourIds.indexOf (colourId);
  51832. if (index >= 0)
  51833. colours.set (index, colour);
  51834. colourIds.add (colourId);
  51835. colours.add (colour);
  51836. }
  51837. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51838. {
  51839. return colourIds.contains (colourId);
  51840. }
  51841. static LookAndFeel* defaultLF = 0;
  51842. static LookAndFeel* currentDefaultLF = 0;
  51843. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51844. {
  51845. // if this happens, your app hasn't initialised itself properly.. if you're
  51846. // trying to hack your own main() function, have a look at
  51847. // JUCEApplication::initialiseForGUI()
  51848. jassert (currentDefaultLF != 0);
  51849. return *currentDefaultLF;
  51850. }
  51851. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51852. {
  51853. if (newDefaultLookAndFeel == 0)
  51854. {
  51855. if (defaultLF == 0)
  51856. defaultLF = new LookAndFeel();
  51857. newDefaultLookAndFeel = defaultLF;
  51858. }
  51859. currentDefaultLF = newDefaultLookAndFeel;
  51860. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51861. {
  51862. Component* const c = Desktop::getInstance().getComponent (i);
  51863. if (c != 0)
  51864. c->sendLookAndFeelChange();
  51865. }
  51866. }
  51867. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51868. {
  51869. if (currentDefaultLF == defaultLF)
  51870. currentDefaultLF = 0;
  51871. deleteAndZero (defaultLF);
  51872. }
  51873. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51874. {
  51875. String faceName (font.getTypefaceName());
  51876. if (faceName == Font::getDefaultSansSerifFontName())
  51877. faceName = defaultSans;
  51878. else if (faceName == Font::getDefaultSerifFontName())
  51879. faceName = defaultSerif;
  51880. else if (faceName == Font::getDefaultMonospacedFontName())
  51881. faceName = defaultFixed;
  51882. Font f (font);
  51883. f.setTypefaceName (faceName);
  51884. return Typeface::createSystemTypefaceFor (f);
  51885. }
  51886. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51887. {
  51888. defaultSans = newName;
  51889. }
  51890. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51891. {
  51892. return component.getMouseCursor();
  51893. }
  51894. void LookAndFeel::drawButtonBackground (Graphics& g,
  51895. Button& button,
  51896. const Colour& backgroundColour,
  51897. bool isMouseOverButton,
  51898. bool isButtonDown)
  51899. {
  51900. const int width = button.getWidth();
  51901. const int height = button.getHeight();
  51902. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51903. const float halfThickness = outlineThickness * 0.5f;
  51904. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51905. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51906. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51907. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51908. const Colour baseColour (createBaseColour (backgroundColour,
  51909. button.hasKeyboardFocus (true),
  51910. isMouseOverButton, isButtonDown)
  51911. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51912. drawGlassLozenge (g,
  51913. indentL,
  51914. indentT,
  51915. width - indentL - indentR,
  51916. height - indentT - indentB,
  51917. baseColour, outlineThickness, -1.0f,
  51918. button.isConnectedOnLeft(),
  51919. button.isConnectedOnRight(),
  51920. button.isConnectedOnTop(),
  51921. button.isConnectedOnBottom());
  51922. }
  51923. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51924. {
  51925. return button.getFont();
  51926. }
  51927. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51928. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51929. {
  51930. Font font (getFontForTextButton (button));
  51931. g.setFont (font);
  51932. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51933. : TextButton::textColourOffId)
  51934. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51935. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51936. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51937. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51938. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51939. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51940. g.drawFittedText (button.getButtonText(),
  51941. leftIndent,
  51942. yIndent,
  51943. button.getWidth() - leftIndent - rightIndent,
  51944. button.getHeight() - yIndent * 2,
  51945. Justification::centred, 2);
  51946. }
  51947. void LookAndFeel::drawTickBox (Graphics& g,
  51948. Component& component,
  51949. float x, float y, float w, float h,
  51950. const bool ticked,
  51951. const bool isEnabled,
  51952. const bool isMouseOverButton,
  51953. const bool isButtonDown)
  51954. {
  51955. const float boxSize = w * 0.7f;
  51956. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51957. createBaseColour (component.findColour (TextButton::buttonColourId)
  51958. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51959. true,
  51960. isMouseOverButton,
  51961. isButtonDown),
  51962. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51963. if (ticked)
  51964. {
  51965. Path tick;
  51966. tick.startNewSubPath (1.5f, 3.0f);
  51967. tick.lineTo (3.0f, 6.0f);
  51968. tick.lineTo (6.0f, 0.0f);
  51969. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51970. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51971. .translated (x, y));
  51972. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51973. }
  51974. }
  51975. void LookAndFeel::drawToggleButton (Graphics& g,
  51976. ToggleButton& button,
  51977. bool isMouseOverButton,
  51978. bool isButtonDown)
  51979. {
  51980. if (button.hasKeyboardFocus (true))
  51981. {
  51982. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51983. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51984. }
  51985. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51986. const float tickWidth = fontSize * 1.1f;
  51987. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51988. tickWidth, tickWidth,
  51989. button.getToggleState(),
  51990. button.isEnabled(),
  51991. isMouseOverButton,
  51992. isButtonDown);
  51993. g.setColour (button.findColour (ToggleButton::textColourId));
  51994. g.setFont (fontSize);
  51995. if (! button.isEnabled())
  51996. g.setOpacity (0.5f);
  51997. const int textX = (int) tickWidth + 5;
  51998. g.drawFittedText (button.getButtonText(),
  51999. textX, 0,
  52000. button.getWidth() - textX - 2, button.getHeight(),
  52001. Justification::centredLeft, 10);
  52002. }
  52003. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  52004. {
  52005. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  52006. const int tickWidth = jmin (24, button.getHeight());
  52007. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  52008. button.getHeight());
  52009. }
  52010. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  52011. const String& message,
  52012. const String& button1,
  52013. const String& button2,
  52014. const String& button3,
  52015. AlertWindow::AlertIconType iconType,
  52016. int numButtons,
  52017. Component* associatedComponent)
  52018. {
  52019. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  52020. if (numButtons == 1)
  52021. {
  52022. aw->addButton (button1, 0,
  52023. KeyPress (KeyPress::escapeKey, 0, 0),
  52024. KeyPress (KeyPress::returnKey, 0, 0));
  52025. }
  52026. else
  52027. {
  52028. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  52029. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  52030. if (button1ShortCut == button2ShortCut)
  52031. button2ShortCut = KeyPress();
  52032. if (numButtons == 2)
  52033. {
  52034. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  52035. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  52036. }
  52037. else if (numButtons == 3)
  52038. {
  52039. aw->addButton (button1, 1, button1ShortCut);
  52040. aw->addButton (button2, 2, button2ShortCut);
  52041. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  52042. }
  52043. }
  52044. return aw;
  52045. }
  52046. void LookAndFeel::drawAlertBox (Graphics& g,
  52047. AlertWindow& alert,
  52048. const Rectangle<int>& textArea,
  52049. TextLayout& textLayout)
  52050. {
  52051. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  52052. int iconSpaceUsed = 0;
  52053. Justification alignment (Justification::horizontallyCentred);
  52054. const int iconWidth = 80;
  52055. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  52056. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  52057. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  52058. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  52059. iconSize, iconSize);
  52060. if (alert.getAlertType() != AlertWindow::NoIcon)
  52061. {
  52062. Path icon;
  52063. uint32 colour;
  52064. char character;
  52065. if (alert.getAlertType() == AlertWindow::WarningIcon)
  52066. {
  52067. colour = 0x55ff5555;
  52068. character = '!';
  52069. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  52070. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  52071. (float) iconRect.getX(), (float) iconRect.getBottom());
  52072. icon = icon.createPathWithRoundedCorners (5.0f);
  52073. }
  52074. else
  52075. {
  52076. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  52077. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  52078. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  52079. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  52080. }
  52081. GlyphArrangement ga;
  52082. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  52083. String::charToString (character),
  52084. (float) iconRect.getX(), (float) iconRect.getY(),
  52085. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  52086. Justification::centred, false);
  52087. ga.createPath (icon);
  52088. icon.setUsingNonZeroWinding (false);
  52089. g.setColour (Colour (colour));
  52090. g.fillPath (icon);
  52091. iconSpaceUsed = iconWidth;
  52092. alignment = Justification::left;
  52093. }
  52094. g.setColour (alert.findColour (AlertWindow::textColourId));
  52095. textLayout.drawWithin (g,
  52096. textArea.getX() + iconSpaceUsed, textArea.getY(),
  52097. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  52098. alignment.getFlags() | Justification::top);
  52099. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  52100. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  52101. }
  52102. int LookAndFeel::getAlertBoxWindowFlags()
  52103. {
  52104. return ComponentPeer::windowAppearsOnTaskbar
  52105. | ComponentPeer::windowHasDropShadow;
  52106. }
  52107. int LookAndFeel::getAlertWindowButtonHeight()
  52108. {
  52109. return 28;
  52110. }
  52111. const Font LookAndFeel::getAlertWindowFont()
  52112. {
  52113. return Font (12.0f);
  52114. }
  52115. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  52116. int width, int height,
  52117. double progress, const String& textToShow)
  52118. {
  52119. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  52120. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  52121. g.fillAll (background);
  52122. if (progress >= 0.0f && progress < 1.0f)
  52123. {
  52124. drawGlassLozenge (g, 1.0f, 1.0f,
  52125. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  52126. (float) (height - 2),
  52127. foreground,
  52128. 0.5f, 0.0f,
  52129. true, true, true, true);
  52130. }
  52131. else
  52132. {
  52133. // spinning bar..
  52134. g.setColour (foreground);
  52135. const int stripeWidth = height * 2;
  52136. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  52137. Path p;
  52138. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  52139. p.addQuadrilateral (x, 0.0f,
  52140. x + stripeWidth * 0.5f, 0.0f,
  52141. x, (float) height,
  52142. x - stripeWidth * 0.5f, (float) height);
  52143. Image im (Image::ARGB, width, height, true);
  52144. {
  52145. Graphics g2 (im);
  52146. drawGlassLozenge (g2, 1.0f, 1.0f,
  52147. (float) (width - 2),
  52148. (float) (height - 2),
  52149. foreground,
  52150. 0.5f, 0.0f,
  52151. true, true, true, true);
  52152. }
  52153. g.setTiledImageFill (im, 0, 0, 0.85f);
  52154. g.fillPath (p);
  52155. }
  52156. if (textToShow.isNotEmpty())
  52157. {
  52158. g.setColour (Colour::contrasting (background, foreground));
  52159. g.setFont (height * 0.6f);
  52160. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  52161. }
  52162. }
  52163. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  52164. {
  52165. const float radius = jmin (w, h) * 0.4f;
  52166. const float thickness = radius * 0.15f;
  52167. Path p;
  52168. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  52169. radius * 0.6f, thickness,
  52170. thickness * 0.5f);
  52171. const float cx = x + w * 0.5f;
  52172. const float cy = y + h * 0.5f;
  52173. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  52174. for (int i = 0; i < 12; ++i)
  52175. {
  52176. const int n = (i + 12 - animationIndex) % 12;
  52177. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  52178. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  52179. .translated (cx, cy));
  52180. }
  52181. }
  52182. void LookAndFeel::drawScrollbarButton (Graphics& g,
  52183. ScrollBar& scrollbar,
  52184. int width, int height,
  52185. int buttonDirection,
  52186. bool /*isScrollbarVertical*/,
  52187. bool /*isMouseOverButton*/,
  52188. bool isButtonDown)
  52189. {
  52190. Path p;
  52191. if (buttonDirection == 0)
  52192. p.addTriangle (width * 0.5f, height * 0.2f,
  52193. width * 0.1f, height * 0.7f,
  52194. width * 0.9f, height * 0.7f);
  52195. else if (buttonDirection == 1)
  52196. p.addTriangle (width * 0.8f, height * 0.5f,
  52197. width * 0.3f, height * 0.1f,
  52198. width * 0.3f, height * 0.9f);
  52199. else if (buttonDirection == 2)
  52200. p.addTriangle (width * 0.5f, height * 0.8f,
  52201. width * 0.1f, height * 0.3f,
  52202. width * 0.9f, height * 0.3f);
  52203. else if (buttonDirection == 3)
  52204. p.addTriangle (width * 0.2f, height * 0.5f,
  52205. width * 0.7f, height * 0.1f,
  52206. width * 0.7f, height * 0.9f);
  52207. if (isButtonDown)
  52208. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  52209. else
  52210. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52211. g.fillPath (p);
  52212. g.setColour (Colour (0x80000000));
  52213. g.strokePath (p, PathStrokeType (0.5f));
  52214. }
  52215. void LookAndFeel::drawScrollbar (Graphics& g,
  52216. ScrollBar& scrollbar,
  52217. int x, int y,
  52218. int width, int height,
  52219. bool isScrollbarVertical,
  52220. int thumbStartPosition,
  52221. int thumbSize,
  52222. bool /*isMouseOver*/,
  52223. bool /*isMouseDown*/)
  52224. {
  52225. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  52226. Path slotPath, thumbPath;
  52227. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  52228. const float slotIndentx2 = slotIndent * 2.0f;
  52229. const float thumbIndent = slotIndent + 1.0f;
  52230. const float thumbIndentx2 = thumbIndent * 2.0f;
  52231. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  52232. if (isScrollbarVertical)
  52233. {
  52234. slotPath.addRoundedRectangle (x + slotIndent,
  52235. y + slotIndent,
  52236. width - slotIndentx2,
  52237. height - slotIndentx2,
  52238. (width - slotIndentx2) * 0.5f);
  52239. if (thumbSize > 0)
  52240. thumbPath.addRoundedRectangle (x + thumbIndent,
  52241. thumbStartPosition + thumbIndent,
  52242. width - thumbIndentx2,
  52243. thumbSize - thumbIndentx2,
  52244. (width - thumbIndentx2) * 0.5f);
  52245. gx1 = (float) x;
  52246. gx2 = x + width * 0.7f;
  52247. }
  52248. else
  52249. {
  52250. slotPath.addRoundedRectangle (x + slotIndent,
  52251. y + slotIndent,
  52252. width - slotIndentx2,
  52253. height - slotIndentx2,
  52254. (height - slotIndentx2) * 0.5f);
  52255. if (thumbSize > 0)
  52256. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  52257. y + thumbIndent,
  52258. thumbSize - thumbIndentx2,
  52259. height - thumbIndentx2,
  52260. (height - thumbIndentx2) * 0.5f);
  52261. gy1 = (float) y;
  52262. gy2 = y + height * 0.7f;
  52263. }
  52264. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52265. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  52266. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  52267. g.fillPath (slotPath);
  52268. if (isScrollbarVertical)
  52269. {
  52270. gx1 = x + width * 0.6f;
  52271. gx2 = (float) x + width;
  52272. }
  52273. else
  52274. {
  52275. gy1 = y + height * 0.6f;
  52276. gy2 = (float) y + height;
  52277. }
  52278. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  52279. Colour (0x19000000), gx2, gy2, false));
  52280. g.fillPath (slotPath);
  52281. g.setColour (thumbColour);
  52282. g.fillPath (thumbPath);
  52283. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  52284. Colours::transparentBlack, gx2, gy2, false));
  52285. g.saveState();
  52286. if (isScrollbarVertical)
  52287. g.reduceClipRegion (x + width / 2, y, width, height);
  52288. else
  52289. g.reduceClipRegion (x, y + height / 2, width, height);
  52290. g.fillPath (thumbPath);
  52291. g.restoreState();
  52292. g.setColour (Colour (0x4c000000));
  52293. g.strokePath (thumbPath, PathStrokeType (0.4f));
  52294. }
  52295. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  52296. {
  52297. return 0;
  52298. }
  52299. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  52300. {
  52301. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  52302. }
  52303. int LookAndFeel::getDefaultScrollbarWidth()
  52304. {
  52305. return 18;
  52306. }
  52307. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  52308. {
  52309. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  52310. : scrollbar.getHeight());
  52311. }
  52312. const Path LookAndFeel::getTickShape (const float height)
  52313. {
  52314. static const unsigned char tickShapeData[] =
  52315. {
  52316. 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,
  52317. 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,
  52318. 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,
  52319. 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,
  52320. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  52321. };
  52322. Path p;
  52323. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  52324. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52325. return p;
  52326. }
  52327. const Path LookAndFeel::getCrossShape (const float height)
  52328. {
  52329. static const unsigned char crossShapeData[] =
  52330. {
  52331. 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,
  52332. 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,
  52333. 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,
  52334. 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,
  52335. 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,
  52336. 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,
  52337. 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
  52338. };
  52339. Path p;
  52340. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  52341. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52342. return p;
  52343. }
  52344. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  52345. {
  52346. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  52347. x += (w - boxSize) >> 1;
  52348. y += (h - boxSize) >> 1;
  52349. w = boxSize;
  52350. h = boxSize;
  52351. g.setColour (Colour (0xe5ffffff));
  52352. g.fillRect (x, y, w, h);
  52353. g.setColour (Colour (0x80000000));
  52354. g.drawRect (x, y, w, h);
  52355. const float size = boxSize / 2 + 1.0f;
  52356. const float centre = (float) (boxSize / 2);
  52357. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  52358. if (isPlus)
  52359. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  52360. }
  52361. void LookAndFeel::drawBubble (Graphics& g,
  52362. float tipX, float tipY,
  52363. float boxX, float boxY,
  52364. float boxW, float boxH)
  52365. {
  52366. int side = 0;
  52367. if (tipX < boxX)
  52368. side = 1;
  52369. else if (tipX > boxX + boxW)
  52370. side = 3;
  52371. else if (tipY > boxY + boxH)
  52372. side = 2;
  52373. const float indent = 2.0f;
  52374. Path p;
  52375. p.addBubble (boxX + indent,
  52376. boxY + indent,
  52377. boxW - indent * 2.0f,
  52378. boxH - indent * 2.0f,
  52379. 5.0f,
  52380. tipX, tipY,
  52381. side,
  52382. 0.5f,
  52383. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  52384. //xxx need to take comp as param for colour
  52385. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  52386. g.fillPath (p);
  52387. //xxx as above
  52388. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  52389. g.strokePath (p, PathStrokeType (1.33f));
  52390. }
  52391. const Font LookAndFeel::getPopupMenuFont()
  52392. {
  52393. return Font (17.0f);
  52394. }
  52395. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  52396. const bool isSeparator,
  52397. int standardMenuItemHeight,
  52398. int& idealWidth,
  52399. int& idealHeight)
  52400. {
  52401. if (isSeparator)
  52402. {
  52403. idealWidth = 50;
  52404. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  52405. }
  52406. else
  52407. {
  52408. Font font (getPopupMenuFont());
  52409. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  52410. font.setHeight (standardMenuItemHeight / 1.3f);
  52411. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  52412. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  52413. }
  52414. }
  52415. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  52416. {
  52417. const Colour background (findColour (PopupMenu::backgroundColourId));
  52418. g.fillAll (background);
  52419. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  52420. for (int i = 0; i < height; i += 3)
  52421. g.fillRect (0, i, width, 1);
  52422. #if ! JUCE_MAC
  52423. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  52424. g.drawRect (0, 0, width, height);
  52425. #endif
  52426. }
  52427. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  52428. int width, int height,
  52429. bool isScrollUpArrow)
  52430. {
  52431. const Colour background (findColour (PopupMenu::backgroundColourId));
  52432. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  52433. background.withAlpha (0.0f),
  52434. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  52435. false));
  52436. g.fillRect (1, 1, width - 2, height - 2);
  52437. const float hw = width * 0.5f;
  52438. const float arrowW = height * 0.3f;
  52439. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  52440. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  52441. Path p;
  52442. p.addTriangle (hw - arrowW, y1,
  52443. hw + arrowW, y1,
  52444. hw, y2);
  52445. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  52446. g.fillPath (p);
  52447. }
  52448. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  52449. int width, int height,
  52450. const bool isSeparator,
  52451. const bool isActive,
  52452. const bool isHighlighted,
  52453. const bool isTicked,
  52454. const bool hasSubMenu,
  52455. const String& text,
  52456. const String& shortcutKeyText,
  52457. Image* image,
  52458. const Colour* const textColourToUse)
  52459. {
  52460. const float halfH = height * 0.5f;
  52461. if (isSeparator)
  52462. {
  52463. const float separatorIndent = 5.5f;
  52464. g.setColour (Colour (0x33000000));
  52465. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  52466. g.setColour (Colour (0x66ffffff));
  52467. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  52468. }
  52469. else
  52470. {
  52471. Colour textColour (findColour (PopupMenu::textColourId));
  52472. if (textColourToUse != 0)
  52473. textColour = *textColourToUse;
  52474. if (isHighlighted)
  52475. {
  52476. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  52477. g.fillRect (1, 1, width - 2, height - 2);
  52478. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  52479. }
  52480. else
  52481. {
  52482. g.setColour (textColour);
  52483. }
  52484. if (! isActive)
  52485. g.setOpacity (0.3f);
  52486. Font font (getPopupMenuFont());
  52487. if (font.getHeight() > height / 1.3f)
  52488. font.setHeight (height / 1.3f);
  52489. g.setFont (font);
  52490. const int leftBorder = (height * 5) / 4;
  52491. const int rightBorder = 4;
  52492. if (image != 0)
  52493. {
  52494. g.drawImageWithin (image,
  52495. 2, 1, leftBorder - 4, height - 2,
  52496. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  52497. }
  52498. else if (isTicked)
  52499. {
  52500. const Path tick (getTickShape (1.0f));
  52501. const float th = font.getAscent();
  52502. const float ty = halfH - th * 0.5f;
  52503. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  52504. th, true));
  52505. }
  52506. g.drawFittedText (text,
  52507. leftBorder, 0,
  52508. width - (leftBorder + rightBorder), height,
  52509. Justification::centredLeft, 1);
  52510. if (shortcutKeyText.isNotEmpty())
  52511. {
  52512. Font f2 (font);
  52513. f2.setHeight (f2.getHeight() * 0.75f);
  52514. f2.setHorizontalScale (0.95f);
  52515. g.setFont (f2);
  52516. g.drawText (shortcutKeyText,
  52517. leftBorder,
  52518. 0,
  52519. width - (leftBorder + rightBorder + 4),
  52520. height,
  52521. Justification::centredRight,
  52522. true);
  52523. }
  52524. if (hasSubMenu)
  52525. {
  52526. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  52527. const float x = width - height * 0.6f;
  52528. Path p;
  52529. p.addTriangle (x, halfH - arrowH * 0.5f,
  52530. x, halfH + arrowH * 0.5f,
  52531. x + arrowH * 0.6f, halfH);
  52532. g.fillPath (p);
  52533. }
  52534. }
  52535. }
  52536. int LookAndFeel::getMenuWindowFlags()
  52537. {
  52538. return ComponentPeer::windowHasDropShadow;
  52539. }
  52540. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  52541. bool, MenuBarComponent& menuBar)
  52542. {
  52543. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  52544. if (menuBar.isEnabled())
  52545. {
  52546. drawShinyButtonShape (g,
  52547. -4.0f, 0.0f,
  52548. width + 8.0f, (float) height,
  52549. 0.0f,
  52550. baseColour,
  52551. 0.4f,
  52552. true, true, true, true);
  52553. }
  52554. else
  52555. {
  52556. g.fillAll (baseColour);
  52557. }
  52558. }
  52559. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  52560. {
  52561. return Font (menuBar.getHeight() * 0.7f);
  52562. }
  52563. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  52564. {
  52565. return getMenuBarFont (menuBar, itemIndex, itemText)
  52566. .getStringWidth (itemText) + menuBar.getHeight();
  52567. }
  52568. void LookAndFeel::drawMenuBarItem (Graphics& g,
  52569. int width, int height,
  52570. int itemIndex,
  52571. const String& itemText,
  52572. bool isMouseOverItem,
  52573. bool isMenuOpen,
  52574. bool /*isMouseOverBar*/,
  52575. MenuBarComponent& menuBar)
  52576. {
  52577. if (! menuBar.isEnabled())
  52578. {
  52579. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  52580. .withMultipliedAlpha (0.5f));
  52581. }
  52582. else if (isMenuOpen || isMouseOverItem)
  52583. {
  52584. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  52585. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  52586. }
  52587. else
  52588. {
  52589. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  52590. }
  52591. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  52592. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  52593. }
  52594. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  52595. TextEditor& textEditor)
  52596. {
  52597. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  52598. }
  52599. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  52600. {
  52601. if (textEditor.isEnabled())
  52602. {
  52603. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  52604. {
  52605. const int border = 2;
  52606. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  52607. g.drawRect (0, 0, width, height, border);
  52608. g.setOpacity (1.0f);
  52609. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  52610. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  52611. }
  52612. else
  52613. {
  52614. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  52615. g.drawRect (0, 0, width, height);
  52616. g.setOpacity (1.0f);
  52617. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  52618. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  52619. }
  52620. }
  52621. }
  52622. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  52623. const bool isButtonDown,
  52624. int buttonX, int buttonY,
  52625. int buttonW, int buttonH,
  52626. ComboBox& box)
  52627. {
  52628. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  52629. if (box.isEnabled() && box.hasKeyboardFocus (false))
  52630. {
  52631. g.setColour (box.findColour (TextButton::buttonColourId));
  52632. g.drawRect (0, 0, width, height, 2);
  52633. }
  52634. else
  52635. {
  52636. g.setColour (box.findColour (ComboBox::outlineColourId));
  52637. g.drawRect (0, 0, width, height);
  52638. }
  52639. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  52640. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  52641. box.hasKeyboardFocus (true),
  52642. false, isButtonDown)
  52643. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  52644. drawGlassLozenge (g,
  52645. buttonX + outlineThickness, buttonY + outlineThickness,
  52646. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  52647. baseColour, outlineThickness, -1.0f,
  52648. true, true, true, true);
  52649. if (box.isEnabled())
  52650. {
  52651. const float arrowX = 0.3f;
  52652. const float arrowH = 0.2f;
  52653. Path p;
  52654. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  52655. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  52656. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  52657. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  52658. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  52659. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  52660. g.setColour (box.findColour (ComboBox::arrowColourId));
  52661. g.fillPath (p);
  52662. }
  52663. }
  52664. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  52665. {
  52666. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  52667. }
  52668. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  52669. {
  52670. return new Label (String::empty, String::empty);
  52671. }
  52672. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  52673. {
  52674. label.setBounds (1, 1,
  52675. box.getWidth() + 3 - box.getHeight(),
  52676. box.getHeight() - 2);
  52677. label.setFont (getComboBoxFont (box));
  52678. }
  52679. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  52680. {
  52681. g.fillAll (label.findColour (Label::backgroundColourId));
  52682. if (! label.isBeingEdited())
  52683. {
  52684. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  52685. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  52686. g.setFont (label.getFont());
  52687. g.drawFittedText (label.getText(),
  52688. label.getHorizontalBorderSize(),
  52689. label.getVerticalBorderSize(),
  52690. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  52691. label.getHeight() - 2 * label.getVerticalBorderSize(),
  52692. label.getJustificationType(),
  52693. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  52694. label.getMinimumHorizontalScale());
  52695. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  52696. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52697. }
  52698. else if (label.isEnabled())
  52699. {
  52700. g.setColour (label.findColour (Label::outlineColourId));
  52701. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52702. }
  52703. }
  52704. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  52705. int x, int y,
  52706. int width, int height,
  52707. float /*sliderPos*/,
  52708. float /*minSliderPos*/,
  52709. float /*maxSliderPos*/,
  52710. const Slider::SliderStyle /*style*/,
  52711. Slider& slider)
  52712. {
  52713. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52714. const Colour trackColour (slider.findColour (Slider::trackColourId));
  52715. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  52716. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  52717. Path indent;
  52718. if (slider.isHorizontal())
  52719. {
  52720. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  52721. const float ih = sliderRadius;
  52722. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  52723. gradCol2, 0.0f, iy + ih, false));
  52724. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52725. width + sliderRadius, ih,
  52726. 5.0f);
  52727. g.fillPath (indent);
  52728. }
  52729. else
  52730. {
  52731. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52732. const float iw = sliderRadius;
  52733. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52734. gradCol2, ix + iw, 0.0f, false));
  52735. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52736. iw, height + sliderRadius,
  52737. 5.0f);
  52738. g.fillPath (indent);
  52739. }
  52740. g.setColour (Colour (0x4c000000));
  52741. g.strokePath (indent, PathStrokeType (0.5f));
  52742. }
  52743. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52744. int x, int y,
  52745. int width, int height,
  52746. float sliderPos,
  52747. float minSliderPos,
  52748. float maxSliderPos,
  52749. const Slider::SliderStyle style,
  52750. Slider& slider)
  52751. {
  52752. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52753. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52754. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52755. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52756. slider.isMouseButtonDown() && slider.isEnabled()));
  52757. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52758. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52759. {
  52760. float kx, ky;
  52761. if (style == Slider::LinearVertical)
  52762. {
  52763. kx = x + width * 0.5f;
  52764. ky = sliderPos;
  52765. }
  52766. else
  52767. {
  52768. kx = sliderPos;
  52769. ky = y + height * 0.5f;
  52770. }
  52771. drawGlassSphere (g,
  52772. kx - sliderRadius,
  52773. ky - sliderRadius,
  52774. sliderRadius * 2.0f,
  52775. knobColour, outlineThickness);
  52776. }
  52777. else
  52778. {
  52779. if (style == Slider::ThreeValueVertical)
  52780. {
  52781. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52782. sliderPos - sliderRadius,
  52783. sliderRadius * 2.0f,
  52784. knobColour, outlineThickness);
  52785. }
  52786. else if (style == Slider::ThreeValueHorizontal)
  52787. {
  52788. drawGlassSphere (g,sliderPos - sliderRadius,
  52789. y + height * 0.5f - sliderRadius,
  52790. sliderRadius * 2.0f,
  52791. knobColour, outlineThickness);
  52792. }
  52793. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52794. {
  52795. const float sr = jmin (sliderRadius, width * 0.4f);
  52796. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52797. minSliderPos - sliderRadius,
  52798. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52799. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52800. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52801. }
  52802. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52803. {
  52804. const float sr = jmin (sliderRadius, height * 0.4f);
  52805. drawGlassPointer (g, minSliderPos - sr,
  52806. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52807. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52808. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52809. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52810. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52811. }
  52812. }
  52813. }
  52814. void LookAndFeel::drawLinearSlider (Graphics& g,
  52815. int x, int y,
  52816. int width, int height,
  52817. float sliderPos,
  52818. float minSliderPos,
  52819. float maxSliderPos,
  52820. const Slider::SliderStyle style,
  52821. Slider& slider)
  52822. {
  52823. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52824. if (style == Slider::LinearBar)
  52825. {
  52826. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52827. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52828. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52829. false,
  52830. isMouseOver,
  52831. isMouseOver || slider.isMouseButtonDown()));
  52832. drawShinyButtonShape (g,
  52833. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52834. baseColour,
  52835. slider.isEnabled() ? 0.9f : 0.3f,
  52836. true, true, true, true);
  52837. }
  52838. else
  52839. {
  52840. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52841. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52842. }
  52843. }
  52844. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52845. {
  52846. return jmin (7,
  52847. slider.getHeight() / 2,
  52848. slider.getWidth() / 2) + 2;
  52849. }
  52850. void LookAndFeel::drawRotarySlider (Graphics& g,
  52851. int x, int y,
  52852. int width, int height,
  52853. float sliderPos,
  52854. const float rotaryStartAngle,
  52855. const float rotaryEndAngle,
  52856. Slider& slider)
  52857. {
  52858. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52859. const float centreX = x + width * 0.5f;
  52860. const float centreY = y + height * 0.5f;
  52861. const float rx = centreX - radius;
  52862. const float ry = centreY - radius;
  52863. const float rw = radius * 2.0f;
  52864. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52865. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52866. if (radius > 12.0f)
  52867. {
  52868. if (slider.isEnabled())
  52869. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52870. else
  52871. g.setColour (Colour (0x80808080));
  52872. const float thickness = 0.7f;
  52873. {
  52874. Path filledArc;
  52875. filledArc.addPieSegment (rx, ry, rw, rw,
  52876. rotaryStartAngle,
  52877. angle,
  52878. thickness);
  52879. g.fillPath (filledArc);
  52880. }
  52881. if (thickness > 0)
  52882. {
  52883. const float innerRadius = radius * 0.2f;
  52884. Path p;
  52885. p.addTriangle (-innerRadius, 0.0f,
  52886. 0.0f, -radius * thickness * 1.1f,
  52887. innerRadius, 0.0f);
  52888. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52889. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52890. }
  52891. if (slider.isEnabled())
  52892. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52893. else
  52894. g.setColour (Colour (0x80808080));
  52895. Path outlineArc;
  52896. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52897. outlineArc.closeSubPath();
  52898. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52899. }
  52900. else
  52901. {
  52902. if (slider.isEnabled())
  52903. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52904. else
  52905. g.setColour (Colour (0x80808080));
  52906. Path p;
  52907. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52908. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52909. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52910. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52911. }
  52912. }
  52913. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52914. {
  52915. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52916. }
  52917. class SliderLabelComp : public Label
  52918. {
  52919. public:
  52920. SliderLabelComp() : Label (String::empty, String::empty) {}
  52921. ~SliderLabelComp() {}
  52922. void mouseWheelMove (const MouseEvent&, float, float) {}
  52923. };
  52924. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52925. {
  52926. Label* const l = new SliderLabelComp();
  52927. l->setJustificationType (Justification::centred);
  52928. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52929. l->setColour (Label::backgroundColourId,
  52930. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52931. : slider.findColour (Slider::textBoxBackgroundColourId));
  52932. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52933. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52934. l->setColour (TextEditor::backgroundColourId,
  52935. slider.findColour (Slider::textBoxBackgroundColourId)
  52936. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52937. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52938. return l;
  52939. }
  52940. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52941. {
  52942. return 0;
  52943. }
  52944. static const TextLayout layoutTooltipText (const String& text) throw()
  52945. {
  52946. const float tooltipFontSize = 12.0f;
  52947. const int maxToolTipWidth = 400;
  52948. const Font f (tooltipFontSize, Font::bold);
  52949. TextLayout tl (text, f);
  52950. tl.layout (maxToolTipWidth, Justification::left, true);
  52951. return tl;
  52952. }
  52953. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52954. {
  52955. const TextLayout tl (layoutTooltipText (tipText));
  52956. width = tl.getWidth() + 14;
  52957. height = tl.getHeight() + 6;
  52958. }
  52959. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52960. {
  52961. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52962. const Colour textCol (findColour (TooltipWindow::textColourId));
  52963. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52964. g.setColour (findColour (TooltipWindow::outlineColourId));
  52965. g.drawRect (0, 0, width, height, 1);
  52966. #endif
  52967. const TextLayout tl (layoutTooltipText (text));
  52968. g.setColour (findColour (TooltipWindow::textColourId));
  52969. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52970. }
  52971. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52972. {
  52973. return new TextButton (text, TRANS("click to browse for a different file"));
  52974. }
  52975. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52976. ComboBox* filenameBox,
  52977. Button* browseButton)
  52978. {
  52979. browseButton->setSize (80, filenameComp.getHeight());
  52980. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52981. if (tb != 0)
  52982. tb->changeWidthToFitText();
  52983. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52984. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52985. }
  52986. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52987. int imageX, int imageY, int imageW, int imageH,
  52988. const Colour& overlayColour,
  52989. float imageOpacity,
  52990. ImageButton& button)
  52991. {
  52992. if (! button.isEnabled())
  52993. imageOpacity *= 0.3f;
  52994. if (! overlayColour.isOpaque())
  52995. {
  52996. g.setOpacity (imageOpacity);
  52997. g.drawImage (image, imageX, imageY, imageW, imageH,
  52998. 0, 0, image->getWidth(), image->getHeight(), false);
  52999. }
  53000. if (! overlayColour.isTransparent())
  53001. {
  53002. g.setColour (overlayColour);
  53003. g.drawImage (image, imageX, imageY, imageW, imageH,
  53004. 0, 0, image->getWidth(), image->getHeight(), true);
  53005. }
  53006. }
  53007. void LookAndFeel::drawCornerResizer (Graphics& g,
  53008. int w, int h,
  53009. bool /*isMouseOver*/,
  53010. bool /*isMouseDragging*/)
  53011. {
  53012. const float lineThickness = jmin (w, h) * 0.075f;
  53013. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  53014. {
  53015. g.setColour (Colours::lightgrey);
  53016. g.drawLine (w * i,
  53017. h + 1.0f,
  53018. w + 1.0f,
  53019. h * i,
  53020. lineThickness);
  53021. g.setColour (Colours::darkgrey);
  53022. g.drawLine (w * i + lineThickness,
  53023. h + 1.0f,
  53024. w + 1.0f,
  53025. h * i + lineThickness,
  53026. lineThickness);
  53027. }
  53028. }
  53029. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  53030. const BorderSize& /*borders*/)
  53031. {
  53032. }
  53033. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  53034. const BorderSize& /*border*/, ResizableWindow& window)
  53035. {
  53036. g.fillAll (window.getBackgroundColour());
  53037. }
  53038. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  53039. const BorderSize& border, ResizableWindow&)
  53040. {
  53041. g.setColour (Colour (0x80000000));
  53042. g.drawRect (0, 0, w, h);
  53043. g.setColour (Colour (0x19000000));
  53044. g.drawRect (border.getLeft() - 1,
  53045. border.getTop() - 1,
  53046. w + 2 - border.getLeftAndRight(),
  53047. h + 2 - border.getTopAndBottom());
  53048. }
  53049. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  53050. Graphics& g, int w, int h,
  53051. int titleSpaceX, int titleSpaceW,
  53052. const Image* icon,
  53053. bool drawTitleTextOnLeft)
  53054. {
  53055. const bool isActive = window.isActiveWindow();
  53056. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  53057. 0.0f, 0.0f,
  53058. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  53059. 0.0f, (float) h, false));
  53060. g.fillAll();
  53061. Font font (h * 0.65f, Font::bold);
  53062. g.setFont (font);
  53063. int textW = font.getStringWidth (window.getName());
  53064. int iconW = 0;
  53065. int iconH = 0;
  53066. if (icon != 0)
  53067. {
  53068. iconH = (int) font.getHeight();
  53069. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  53070. }
  53071. textW = jmin (titleSpaceW, textW + iconW);
  53072. int textX = drawTitleTextOnLeft ? titleSpaceX
  53073. : jmax (titleSpaceX, (w - textW) / 2);
  53074. if (textX + textW > titleSpaceX + titleSpaceW)
  53075. textX = titleSpaceX + titleSpaceW - textW;
  53076. if (icon != 0)
  53077. {
  53078. g.setOpacity (isActive ? 1.0f : 0.6f);
  53079. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  53080. RectanglePlacement::centred, false);
  53081. textX += iconW;
  53082. textW -= iconW;
  53083. }
  53084. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  53085. g.setColour (findColour (DocumentWindow::textColourId));
  53086. else
  53087. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  53088. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  53089. }
  53090. class GlassWindowButton : public Button
  53091. {
  53092. public:
  53093. GlassWindowButton (const String& name, const Colour& col,
  53094. const Path& normalShape_,
  53095. const Path& toggledShape_) throw()
  53096. : Button (name),
  53097. colour (col),
  53098. normalShape (normalShape_),
  53099. toggledShape (toggledShape_)
  53100. {
  53101. }
  53102. ~GlassWindowButton()
  53103. {
  53104. }
  53105. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  53106. {
  53107. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  53108. if (! isEnabled())
  53109. alpha *= 0.5f;
  53110. float x = 0, y = 0, diam;
  53111. if (getWidth() < getHeight())
  53112. {
  53113. diam = (float) getWidth();
  53114. y = (getHeight() - getWidth()) * 0.5f;
  53115. }
  53116. else
  53117. {
  53118. diam = (float) getHeight();
  53119. y = (getWidth() - getHeight()) * 0.5f;
  53120. }
  53121. x += diam * 0.05f;
  53122. y += diam * 0.05f;
  53123. diam *= 0.9f;
  53124. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  53125. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  53126. g.fillEllipse (x, y, diam, diam);
  53127. x += 2.0f;
  53128. y += 2.0f;
  53129. diam -= 4.0f;
  53130. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  53131. Path& p = getToggleState() ? toggledShape : normalShape;
  53132. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  53133. diam * 0.4f, diam * 0.4f, true));
  53134. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  53135. g.fillPath (p, t);
  53136. }
  53137. juce_UseDebuggingNewOperator
  53138. private:
  53139. Colour colour;
  53140. Path normalShape, toggledShape;
  53141. GlassWindowButton (const GlassWindowButton&);
  53142. const GlassWindowButton& operator= (const GlassWindowButton&);
  53143. };
  53144. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  53145. {
  53146. Path shape;
  53147. const float crossThickness = 0.25f;
  53148. if (buttonType == DocumentWindow::closeButton)
  53149. {
  53150. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  53151. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  53152. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  53153. }
  53154. else if (buttonType == DocumentWindow::minimiseButton)
  53155. {
  53156. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  53157. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  53158. }
  53159. else if (buttonType == DocumentWindow::maximiseButton)
  53160. {
  53161. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  53162. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  53163. Path fullscreenShape;
  53164. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  53165. fullscreenShape.lineTo (0.0f, 100.0f);
  53166. fullscreenShape.lineTo (0.0f, 0.0f);
  53167. fullscreenShape.lineTo (100.0f, 0.0f);
  53168. fullscreenShape.lineTo (100.0f, 45.0f);
  53169. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  53170. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  53171. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  53172. }
  53173. jassertfalse
  53174. return 0;
  53175. }
  53176. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53177. int titleBarX,
  53178. int titleBarY,
  53179. int titleBarW,
  53180. int titleBarH,
  53181. Button* minimiseButton,
  53182. Button* maximiseButton,
  53183. Button* closeButton,
  53184. bool positionTitleBarButtonsOnLeft)
  53185. {
  53186. const int buttonW = titleBarH - titleBarH / 8;
  53187. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53188. : titleBarX + titleBarW - buttonW - buttonW / 4;
  53189. if (closeButton != 0)
  53190. {
  53191. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53192. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  53193. }
  53194. if (positionTitleBarButtonsOnLeft)
  53195. swapVariables (minimiseButton, maximiseButton);
  53196. if (maximiseButton != 0)
  53197. {
  53198. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53199. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53200. }
  53201. if (minimiseButton != 0)
  53202. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53203. }
  53204. int LookAndFeel::getDefaultMenuBarHeight()
  53205. {
  53206. return 24;
  53207. }
  53208. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  53209. {
  53210. return new DropShadower (0.4f, 1, 5, 10);
  53211. }
  53212. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  53213. int w, int h,
  53214. bool /*isVerticalBar*/,
  53215. bool isMouseOver,
  53216. bool isMouseDragging)
  53217. {
  53218. float alpha = 0.5f;
  53219. if (isMouseOver || isMouseDragging)
  53220. {
  53221. g.fillAll (Colour (0x190000ff));
  53222. alpha = 1.0f;
  53223. }
  53224. const float cx = w * 0.5f;
  53225. const float cy = h * 0.5f;
  53226. const float cr = jmin (w, h) * 0.4f;
  53227. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  53228. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  53229. true));
  53230. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  53231. }
  53232. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  53233. const String& text,
  53234. const Justification& position,
  53235. GroupComponent& group)
  53236. {
  53237. const float textH = 15.0f;
  53238. const float indent = 3.0f;
  53239. const float textEdgeGap = 4.0f;
  53240. float cs = 5.0f;
  53241. Font f (textH);
  53242. Path p;
  53243. float x = indent;
  53244. float y = f.getAscent() - 3.0f;
  53245. float w = jmax (0.0f, width - x * 2.0f);
  53246. float h = jmax (0.0f, height - y - indent);
  53247. cs = jmin (cs, w * 0.5f, h * 0.5f);
  53248. const float cs2 = 2.0f * cs;
  53249. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  53250. float textX = cs + textEdgeGap;
  53251. if (position.testFlags (Justification::horizontallyCentred))
  53252. textX = cs + (w - cs2 - textW) * 0.5f;
  53253. else if (position.testFlags (Justification::right))
  53254. textX = w - cs - textW - textEdgeGap;
  53255. p.startNewSubPath (x + textX + textW, y);
  53256. p.lineTo (x + w - cs, y);
  53257. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  53258. p.lineTo (x + w, y + h - cs);
  53259. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53260. p.lineTo (x + cs, y + h);
  53261. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53262. p.lineTo (x, y + cs);
  53263. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53264. p.lineTo (x + textX, y);
  53265. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  53266. g.setColour (group.findColour (GroupComponent::outlineColourId)
  53267. .withMultipliedAlpha (alpha));
  53268. g.strokePath (p, PathStrokeType (2.0f));
  53269. g.setColour (group.findColour (GroupComponent::textColourId)
  53270. .withMultipliedAlpha (alpha));
  53271. g.setFont (f);
  53272. g.drawText (text,
  53273. roundToInt (x + textX), 0,
  53274. roundToInt (textW),
  53275. roundToInt (textH),
  53276. Justification::centred, true);
  53277. }
  53278. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  53279. {
  53280. return 1 + tabDepth / 3;
  53281. }
  53282. int LookAndFeel::getTabButtonSpaceAroundImage()
  53283. {
  53284. return 4;
  53285. }
  53286. void LookAndFeel::createTabButtonShape (Path& p,
  53287. int width, int height,
  53288. int /*tabIndex*/,
  53289. const String& /*text*/,
  53290. Button& /*button*/,
  53291. TabbedButtonBar::Orientation orientation,
  53292. const bool /*isMouseOver*/,
  53293. const bool /*isMouseDown*/,
  53294. const bool /*isFrontTab*/)
  53295. {
  53296. const float w = (float) width;
  53297. const float h = (float) height;
  53298. float length = w;
  53299. float depth = h;
  53300. if (orientation == TabbedButtonBar::TabsAtLeft
  53301. || orientation == TabbedButtonBar::TabsAtRight)
  53302. {
  53303. swapVariables (length, depth);
  53304. }
  53305. const float indent = (float) getTabButtonOverlap ((int) depth);
  53306. const float overhang = 4.0f;
  53307. if (orientation == TabbedButtonBar::TabsAtLeft)
  53308. {
  53309. p.startNewSubPath (w, 0.0f);
  53310. p.lineTo (0.0f, indent);
  53311. p.lineTo (0.0f, h - indent);
  53312. p.lineTo (w, h);
  53313. p.lineTo (w + overhang, h + overhang);
  53314. p.lineTo (w + overhang, -overhang);
  53315. }
  53316. else if (orientation == TabbedButtonBar::TabsAtRight)
  53317. {
  53318. p.startNewSubPath (0.0f, 0.0f);
  53319. p.lineTo (w, indent);
  53320. p.lineTo (w, h - indent);
  53321. p.lineTo (0.0f, h);
  53322. p.lineTo (-overhang, h + overhang);
  53323. p.lineTo (-overhang, -overhang);
  53324. }
  53325. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53326. {
  53327. p.startNewSubPath (0.0f, 0.0f);
  53328. p.lineTo (indent, h);
  53329. p.lineTo (w - indent, h);
  53330. p.lineTo (w, 0.0f);
  53331. p.lineTo (w + overhang, -overhang);
  53332. p.lineTo (-overhang, -overhang);
  53333. }
  53334. else
  53335. {
  53336. p.startNewSubPath (0.0f, h);
  53337. p.lineTo (indent, 0.0f);
  53338. p.lineTo (w - indent, 0.0f);
  53339. p.lineTo (w, h);
  53340. p.lineTo (w + overhang, h + overhang);
  53341. p.lineTo (-overhang, h + overhang);
  53342. }
  53343. p.closeSubPath();
  53344. p = p.createPathWithRoundedCorners (3.0f);
  53345. }
  53346. void LookAndFeel::fillTabButtonShape (Graphics& g,
  53347. const Path& path,
  53348. const Colour& preferredColour,
  53349. int /*tabIndex*/,
  53350. const String& /*text*/,
  53351. Button& button,
  53352. TabbedButtonBar::Orientation /*orientation*/,
  53353. const bool /*isMouseOver*/,
  53354. const bool /*isMouseDown*/,
  53355. const bool isFrontTab)
  53356. {
  53357. g.setColour (isFrontTab ? preferredColour
  53358. : preferredColour.withMultipliedAlpha (0.9f));
  53359. g.fillPath (path);
  53360. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  53361. : TabbedButtonBar::tabOutlineColourId, false)
  53362. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  53363. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  53364. }
  53365. void LookAndFeel::drawTabButtonText (Graphics& g,
  53366. int x, int y, int w, int h,
  53367. const Colour& preferredBackgroundColour,
  53368. int /*tabIndex*/,
  53369. const String& text,
  53370. Button& button,
  53371. TabbedButtonBar::Orientation orientation,
  53372. const bool isMouseOver,
  53373. const bool isMouseDown,
  53374. const bool isFrontTab)
  53375. {
  53376. int length = w;
  53377. int depth = h;
  53378. if (orientation == TabbedButtonBar::TabsAtLeft
  53379. || orientation == TabbedButtonBar::TabsAtRight)
  53380. {
  53381. swapVariables (length, depth);
  53382. }
  53383. Font font (depth * 0.6f);
  53384. font.setUnderline (button.hasKeyboardFocus (false));
  53385. GlyphArrangement textLayout;
  53386. textLayout.addFittedText (font, text.trim(),
  53387. 0.0f, 0.0f, (float) length, (float) depth,
  53388. Justification::centred,
  53389. jmax (1, depth / 12));
  53390. AffineTransform transform;
  53391. if (orientation == TabbedButtonBar::TabsAtLeft)
  53392. {
  53393. transform = transform.rotated (float_Pi * -0.5f)
  53394. .translated ((float) x, (float) (y + h));
  53395. }
  53396. else if (orientation == TabbedButtonBar::TabsAtRight)
  53397. {
  53398. transform = transform.rotated (float_Pi * 0.5f)
  53399. .translated ((float) (x + w), (float) y);
  53400. }
  53401. else
  53402. {
  53403. transform = transform.translated ((float) x, (float) y);
  53404. }
  53405. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  53406. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  53407. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  53408. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  53409. else
  53410. g.setColour (preferredBackgroundColour.contrasting());
  53411. if (! (isMouseOver || isMouseDown))
  53412. g.setOpacity (0.8f);
  53413. if (! button.isEnabled())
  53414. g.setOpacity (0.3f);
  53415. textLayout.draw (g, transform);
  53416. }
  53417. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  53418. const String& text,
  53419. int tabDepth,
  53420. Button&)
  53421. {
  53422. Font f (tabDepth * 0.6f);
  53423. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  53424. }
  53425. void LookAndFeel::drawTabButton (Graphics& g,
  53426. int w, int h,
  53427. const Colour& preferredColour,
  53428. int tabIndex,
  53429. const String& text,
  53430. Button& button,
  53431. TabbedButtonBar::Orientation orientation,
  53432. const bool isMouseOver,
  53433. const bool isMouseDown,
  53434. const bool isFrontTab)
  53435. {
  53436. int length = w;
  53437. int depth = h;
  53438. if (orientation == TabbedButtonBar::TabsAtLeft
  53439. || orientation == TabbedButtonBar::TabsAtRight)
  53440. {
  53441. swapVariables (length, depth);
  53442. }
  53443. Path tabShape;
  53444. createTabButtonShape (tabShape, w, h,
  53445. tabIndex, text, button, orientation,
  53446. isMouseOver, isMouseDown, isFrontTab);
  53447. fillTabButtonShape (g, tabShape, preferredColour,
  53448. tabIndex, text, button, orientation,
  53449. isMouseOver, isMouseDown, isFrontTab);
  53450. const int indent = getTabButtonOverlap (depth);
  53451. int x = 0, y = 0;
  53452. if (orientation == TabbedButtonBar::TabsAtLeft
  53453. || orientation == TabbedButtonBar::TabsAtRight)
  53454. {
  53455. y += indent;
  53456. h -= indent * 2;
  53457. }
  53458. else
  53459. {
  53460. x += indent;
  53461. w -= indent * 2;
  53462. }
  53463. drawTabButtonText (g, x, y, w, h, preferredColour,
  53464. tabIndex, text, button, orientation,
  53465. isMouseOver, isMouseDown, isFrontTab);
  53466. }
  53467. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  53468. int w, int h,
  53469. TabbedButtonBar& tabBar,
  53470. TabbedButtonBar::Orientation orientation)
  53471. {
  53472. const float shadowSize = 0.2f;
  53473. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  53474. Rectangle<int> shadowRect;
  53475. if (orientation == TabbedButtonBar::TabsAtLeft)
  53476. {
  53477. x1 = (float) w;
  53478. x2 = w * (1.0f - shadowSize);
  53479. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  53480. }
  53481. else if (orientation == TabbedButtonBar::TabsAtRight)
  53482. {
  53483. x2 = w * shadowSize;
  53484. shadowRect.setBounds (0, 0, (int) x2, h);
  53485. }
  53486. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53487. {
  53488. y2 = h * shadowSize;
  53489. shadowRect.setBounds (0, 0, w, (int) y2);
  53490. }
  53491. else
  53492. {
  53493. y1 = (float) h;
  53494. y2 = h * (1.0f - shadowSize);
  53495. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  53496. }
  53497. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  53498. Colours::transparentBlack, x2, y2, false));
  53499. shadowRect.expand (2, 2);
  53500. g.fillRect (shadowRect);
  53501. g.setColour (Colour (0x80000000));
  53502. if (orientation == TabbedButtonBar::TabsAtLeft)
  53503. {
  53504. g.fillRect (w - 1, 0, 1, h);
  53505. }
  53506. else if (orientation == TabbedButtonBar::TabsAtRight)
  53507. {
  53508. g.fillRect (0, 0, 1, h);
  53509. }
  53510. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53511. {
  53512. g.fillRect (0, 0, w, 1);
  53513. }
  53514. else
  53515. {
  53516. g.fillRect (0, h - 1, w, 1);
  53517. }
  53518. }
  53519. Button* LookAndFeel::createTabBarExtrasButton()
  53520. {
  53521. const float thickness = 7.0f;
  53522. const float indent = 22.0f;
  53523. Path p;
  53524. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  53525. DrawablePath ellipse;
  53526. ellipse.setPath (p);
  53527. ellipse.setFill (Colour (0x99ffffff));
  53528. p.clear();
  53529. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53530. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53531. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53532. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53533. p.setUsingNonZeroWinding (false);
  53534. DrawablePath dp;
  53535. dp.setPath (p);
  53536. dp.setFill (Colour (0x59000000));
  53537. DrawableComposite normalImage;
  53538. normalImage.insertDrawable (ellipse);
  53539. normalImage.insertDrawable (dp);
  53540. dp.setFill (Colour (0xcc000000));
  53541. DrawableComposite overImage;
  53542. overImage.insertDrawable (ellipse);
  53543. overImage.insertDrawable (dp);
  53544. DrawableButton* db = new DrawableButton (T("tabs"), DrawableButton::ImageFitted);
  53545. db->setImages (&normalImage, &overImage, 0);
  53546. return db;
  53547. }
  53548. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  53549. {
  53550. g.fillAll (Colours::white);
  53551. const int w = header.getWidth();
  53552. const int h = header.getHeight();
  53553. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  53554. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  53555. false));
  53556. g.fillRect (0, h / 2, w, h);
  53557. g.setColour (Colour (0x33000000));
  53558. g.fillRect (0, h - 1, w, 1);
  53559. for (int i = header.getNumColumns (true); --i >= 0;)
  53560. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  53561. }
  53562. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  53563. int width, int height,
  53564. bool isMouseOver, bool isMouseDown,
  53565. int columnFlags)
  53566. {
  53567. if (isMouseDown)
  53568. g.fillAll (Colour (0x8899aadd));
  53569. else if (isMouseOver)
  53570. g.fillAll (Colour (0x5599aadd));
  53571. int rightOfText = width - 4;
  53572. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  53573. {
  53574. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  53575. const float bottom = height - top;
  53576. const float w = height * 0.5f;
  53577. const float x = rightOfText - (w * 1.25f);
  53578. rightOfText = (int) x;
  53579. Path sortArrow;
  53580. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  53581. g.setColour (Colour (0x99000000));
  53582. g.fillPath (sortArrow);
  53583. }
  53584. g.setColour (Colours::black);
  53585. g.setFont (height * 0.5f, Font::bold);
  53586. const int textX = 4;
  53587. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  53588. }
  53589. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  53590. {
  53591. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  53592. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  53593. background.darker (0.1f),
  53594. toolbar.isVertical() ? w - 1.0f : 0.0f,
  53595. toolbar.isVertical() ? 0.0f : h - 1.0f,
  53596. false));
  53597. g.fillAll();
  53598. }
  53599. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  53600. {
  53601. return createTabBarExtrasButton();
  53602. }
  53603. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  53604. bool isMouseOver, bool isMouseDown,
  53605. ToolbarItemComponent& component)
  53606. {
  53607. if (isMouseDown)
  53608. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  53609. else if (isMouseOver)
  53610. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  53611. }
  53612. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  53613. const String& text, ToolbarItemComponent& component)
  53614. {
  53615. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  53616. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  53617. const float fontHeight = jmin (14.0f, height * 0.85f);
  53618. g.setFont (fontHeight);
  53619. g.drawFittedText (text,
  53620. x, y, width, height,
  53621. Justification::centred,
  53622. jmax (1, height / (int) fontHeight));
  53623. }
  53624. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  53625. bool isOpen, int width, int height)
  53626. {
  53627. const int buttonSize = (height * 3) / 4;
  53628. const int buttonIndent = (height - buttonSize) / 2;
  53629. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  53630. const int textX = buttonIndent * 2 + buttonSize + 2;
  53631. g.setColour (Colours::black);
  53632. g.setFont (height * 0.7f, Font::bold);
  53633. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  53634. }
  53635. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  53636. PropertyComponent&)
  53637. {
  53638. g.setColour (Colour (0x66ffffff));
  53639. g.fillRect (0, 0, width, height - 1);
  53640. }
  53641. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  53642. PropertyComponent& component)
  53643. {
  53644. g.setColour (Colours::black);
  53645. if (! component.isEnabled())
  53646. g.setOpacity (0.6f);
  53647. g.setFont (jmin (height, 24) * 0.65f);
  53648. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  53649. g.drawFittedText (component.getName(),
  53650. 3, r.getY(), r.getX() - 5, r.getHeight(),
  53651. Justification::centredLeft, 2);
  53652. }
  53653. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  53654. {
  53655. return Rectangle<int> (component.getWidth() / 3, 1,
  53656. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  53657. }
  53658. void LookAndFeel::createFileChooserHeaderText (const String& title,
  53659. const String& instructions,
  53660. GlyphArrangement& text,
  53661. int width)
  53662. {
  53663. text.clear();
  53664. text.addJustifiedText (Font (17.0f, Font::bold), title,
  53665. 8.0f, 22.0f, width - 16.0f,
  53666. Justification::centred);
  53667. text.addJustifiedText (Font (14.0f), instructions,
  53668. 8.0f, 24.0f + 16.0f, width - 16.0f,
  53669. Justification::centred);
  53670. }
  53671. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  53672. const String& filename, Image* icon,
  53673. const String& fileSizeDescription,
  53674. const String& fileTimeDescription,
  53675. const bool isDirectory,
  53676. const bool isItemSelected,
  53677. const int /*itemIndex*/)
  53678. {
  53679. if (isItemSelected)
  53680. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  53681. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  53682. g.setFont (height * 0.7f);
  53683. Image* im = icon;
  53684. Image* toRelease = 0;
  53685. if (im == 0)
  53686. {
  53687. toRelease = im = (isDirectory ? getDefaultFolderImage()
  53688. : getDefaultDocumentFileImage());
  53689. }
  53690. const int x = 32;
  53691. if (im != 0)
  53692. {
  53693. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  53694. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  53695. false);
  53696. ImageCache::release (toRelease);
  53697. }
  53698. if (width > 450 && ! isDirectory)
  53699. {
  53700. const int sizeX = roundToInt (width * 0.7f);
  53701. const int dateX = roundToInt (width * 0.8f);
  53702. g.drawFittedText (filename,
  53703. x, 0, sizeX - x, height,
  53704. Justification::centredLeft, 1);
  53705. g.setFont (height * 0.5f);
  53706. g.setColour (Colours::darkgrey);
  53707. if (! isDirectory)
  53708. {
  53709. g.drawFittedText (fileSizeDescription,
  53710. sizeX, 0, dateX - sizeX - 8, height,
  53711. Justification::centredRight, 1);
  53712. g.drawFittedText (fileTimeDescription,
  53713. dateX, 0, width - 8 - dateX, height,
  53714. Justification::centredRight, 1);
  53715. }
  53716. }
  53717. else
  53718. {
  53719. g.drawFittedText (filename,
  53720. x, 0, width - x, height,
  53721. Justification::centredLeft, 1);
  53722. }
  53723. }
  53724. Button* LookAndFeel::createFileBrowserGoUpButton()
  53725. {
  53726. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53727. Path arrowPath;
  53728. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53729. DrawablePath arrowImage;
  53730. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53731. arrowImage.setPath (arrowPath);
  53732. goUpButton->setImages (&arrowImage);
  53733. return goUpButton;
  53734. }
  53735. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53736. DirectoryContentsDisplayComponent* fileListComponent,
  53737. FilePreviewComponent* previewComp,
  53738. ComboBox* currentPathBox,
  53739. TextEditor* filenameBox,
  53740. Button* goUpButton)
  53741. {
  53742. const int x = 8;
  53743. int w = browserComp.getWidth() - x - x;
  53744. if (previewComp != 0)
  53745. {
  53746. const int previewWidth = w / 3;
  53747. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53748. w -= previewWidth + 4;
  53749. }
  53750. int y = 4;
  53751. const int controlsHeight = 22;
  53752. const int bottomSectionHeight = controlsHeight + 8;
  53753. const int upButtonWidth = 50;
  53754. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53755. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53756. y += controlsHeight + 4;
  53757. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53758. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53759. y = listAsComp->getBottom() + 4;
  53760. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53761. }
  53762. Image* LookAndFeel::getDefaultFolderImage()
  53763. {
  53764. 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,
  53765. 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,
  53766. 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,
  53767. 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,
  53768. 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,
  53769. 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,
  53770. 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,
  53771. 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,
  53772. 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,
  53773. 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,
  53774. 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,
  53775. 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,
  53776. 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,
  53777. 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,
  53778. 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,
  53779. 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,
  53780. 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,
  53781. 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,
  53782. 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,
  53783. 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,
  53784. 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,
  53785. 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,
  53786. 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,
  53787. 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,
  53788. 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,
  53789. 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,
  53790. 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,
  53791. 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,
  53792. 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,
  53793. 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,
  53794. 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,
  53795. 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,
  53796. 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,
  53797. 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,
  53798. 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,
  53799. 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,
  53800. 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,
  53801. 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,
  53802. 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,
  53803. 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,
  53804. 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,
  53805. 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,
  53806. 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,
  53807. 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};
  53808. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53809. }
  53810. Image* LookAndFeel::getDefaultDocumentFileImage()
  53811. {
  53812. 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,
  53813. 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,
  53814. 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,
  53815. 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,
  53816. 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,
  53817. 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,
  53818. 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,
  53819. 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,
  53820. 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,
  53821. 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,
  53822. 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,
  53823. 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,
  53824. 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,
  53825. 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,
  53826. 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,
  53827. 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,
  53828. 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,
  53829. 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,
  53830. 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,
  53831. 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,
  53832. 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,
  53833. 174,66,96,130,0,0};
  53834. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53835. }
  53836. void LookAndFeel::playAlertSound()
  53837. {
  53838. PlatformUtilities::beep();
  53839. }
  53840. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53841. {
  53842. g.setColour (Colours::white.withAlpha (0.7f));
  53843. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53844. g.setColour (Colours::black.withAlpha (0.2f));
  53845. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53846. const int totalBlocks = 7;
  53847. const int numBlocks = roundToInt (totalBlocks * level);
  53848. const float w = (width - 6.0f) / (float) totalBlocks;
  53849. for (int i = 0; i < totalBlocks; ++i)
  53850. {
  53851. if (i >= numBlocks)
  53852. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53853. else
  53854. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53855. : Colours::red);
  53856. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53857. }
  53858. }
  53859. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53860. {
  53861. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53862. if (keyDescription.isNotEmpty())
  53863. {
  53864. if (button.isEnabled())
  53865. {
  53866. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53867. g.fillAll (textColour.withAlpha (alpha));
  53868. g.setOpacity (0.3f);
  53869. g.drawBevel (0, 0, width, height, 2);
  53870. }
  53871. g.setColour (textColour);
  53872. g.setFont (height * 0.6f);
  53873. g.drawFittedText (keyDescription,
  53874. 3, 0, width - 6, height,
  53875. Justification::centred, 1);
  53876. }
  53877. else
  53878. {
  53879. const float thickness = 7.0f;
  53880. const float indent = 22.0f;
  53881. Path p;
  53882. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53883. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53884. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53885. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53886. p.setUsingNonZeroWinding (false);
  53887. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53888. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53889. }
  53890. if (button.hasKeyboardFocus (false))
  53891. {
  53892. g.setColour (textColour.withAlpha (0.4f));
  53893. g.drawRect (0, 0, width, height);
  53894. }
  53895. }
  53896. static void createRoundedPath (Path& p,
  53897. const float x, const float y,
  53898. const float w, const float h,
  53899. const float cs,
  53900. const bool curveTopLeft, const bool curveTopRight,
  53901. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53902. {
  53903. const float cs2 = 2.0f * cs;
  53904. if (curveTopLeft)
  53905. {
  53906. p.startNewSubPath (x, y + cs);
  53907. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53908. }
  53909. else
  53910. {
  53911. p.startNewSubPath (x, y);
  53912. }
  53913. if (curveTopRight)
  53914. {
  53915. p.lineTo (x + w - cs, y);
  53916. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53917. }
  53918. else
  53919. {
  53920. p.lineTo (x + w, y);
  53921. }
  53922. if (curveBottomRight)
  53923. {
  53924. p.lineTo (x + w, y + h - cs);
  53925. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53926. }
  53927. else
  53928. {
  53929. p.lineTo (x + w, y + h);
  53930. }
  53931. if (curveBottomLeft)
  53932. {
  53933. p.lineTo (x + cs, y + h);
  53934. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53935. }
  53936. else
  53937. {
  53938. p.lineTo (x, y + h);
  53939. }
  53940. p.closeSubPath();
  53941. }
  53942. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53943. float x, float y, float w, float h,
  53944. float maxCornerSize,
  53945. const Colour& baseColour,
  53946. const float strokeWidth,
  53947. const bool flatOnLeft,
  53948. const bool flatOnRight,
  53949. const bool flatOnTop,
  53950. const bool flatOnBottom) throw()
  53951. {
  53952. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53953. return;
  53954. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53955. Path outline;
  53956. createRoundedPath (outline, x, y, w, h, cs,
  53957. ! (flatOnLeft || flatOnTop),
  53958. ! (flatOnRight || flatOnTop),
  53959. ! (flatOnLeft || flatOnBottom),
  53960. ! (flatOnRight || flatOnBottom));
  53961. ColourGradient cg (baseColour, 0.0f, y,
  53962. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53963. false);
  53964. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53965. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53966. g.setGradientFill (cg);
  53967. g.fillPath (outline);
  53968. g.setColour (Colour (0x80000000));
  53969. g.strokePath (outline, PathStrokeType (strokeWidth));
  53970. }
  53971. void LookAndFeel::drawGlassSphere (Graphics& g,
  53972. const float x, const float y,
  53973. const float diameter,
  53974. const Colour& colour,
  53975. const float outlineThickness) throw()
  53976. {
  53977. if (diameter <= outlineThickness)
  53978. return;
  53979. Path p;
  53980. p.addEllipse (x, y, diameter, diameter);
  53981. {
  53982. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53983. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53984. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53985. g.setGradientFill (cg);
  53986. g.fillPath (p);
  53987. }
  53988. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53989. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53990. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53991. ColourGradient cg (Colours::transparentBlack,
  53992. x + diameter * 0.5f, y + diameter * 0.5f,
  53993. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53994. x, y + diameter * 0.5f, true);
  53995. cg.addColour (0.7, Colours::transparentBlack);
  53996. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53997. g.setGradientFill (cg);
  53998. g.fillPath (p);
  53999. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  54000. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  54001. }
  54002. void LookAndFeel::drawGlassPointer (Graphics& g,
  54003. const float x, const float y,
  54004. const float diameter,
  54005. const Colour& colour, const float outlineThickness,
  54006. const int direction) throw()
  54007. {
  54008. if (diameter <= outlineThickness)
  54009. return;
  54010. Path p;
  54011. p.startNewSubPath (x + diameter * 0.5f, y);
  54012. p.lineTo (x + diameter, y + diameter * 0.6f);
  54013. p.lineTo (x + diameter, y + diameter);
  54014. p.lineTo (x, y + diameter);
  54015. p.lineTo (x, y + diameter * 0.6f);
  54016. p.closeSubPath();
  54017. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  54018. {
  54019. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  54020. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  54021. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  54022. g.setGradientFill (cg);
  54023. g.fillPath (p);
  54024. }
  54025. ColourGradient cg (Colours::transparentBlack,
  54026. x + diameter * 0.5f, y + diameter * 0.5f,
  54027. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  54028. x - diameter * 0.2f, y + diameter * 0.5f, true);
  54029. cg.addColour (0.5, Colours::transparentBlack);
  54030. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  54031. g.setGradientFill (cg);
  54032. g.fillPath (p);
  54033. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  54034. g.strokePath (p, PathStrokeType (outlineThickness));
  54035. }
  54036. void LookAndFeel::drawGlassLozenge (Graphics& g,
  54037. const float x, const float y,
  54038. const float width, const float height,
  54039. const Colour& colour,
  54040. const float outlineThickness,
  54041. const float cornerSize,
  54042. const bool flatOnLeft,
  54043. const bool flatOnRight,
  54044. const bool flatOnTop,
  54045. const bool flatOnBottom) throw()
  54046. {
  54047. if (width <= outlineThickness || height <= outlineThickness)
  54048. return;
  54049. const int intX = (int) x;
  54050. const int intY = (int) y;
  54051. const int intW = (int) width;
  54052. const int intH = (int) height;
  54053. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  54054. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  54055. const int intEdge = (int) edgeBlurRadius;
  54056. Path outline;
  54057. createRoundedPath (outline, x, y, width, height, cs,
  54058. ! (flatOnLeft || flatOnTop),
  54059. ! (flatOnRight || flatOnTop),
  54060. ! (flatOnLeft || flatOnBottom),
  54061. ! (flatOnRight || flatOnBottom));
  54062. {
  54063. ColourGradient cg (colour.darker (0.2f), 0, y,
  54064. colour.darker (0.2f), 0, y + height, false);
  54065. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  54066. cg.addColour (0.4, colour);
  54067. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  54068. g.setGradientFill (cg);
  54069. g.fillPath (outline);
  54070. }
  54071. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  54072. colour.darker (0.2f), x, y + height * 0.5f, true);
  54073. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  54074. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  54075. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  54076. {
  54077. g.saveState();
  54078. g.setGradientFill (cg);
  54079. g.reduceClipRegion (intX, intY, intEdge, intH);
  54080. g.fillPath (outline);
  54081. g.restoreState();
  54082. }
  54083. if (! (flatOnRight || flatOnTop || flatOnBottom))
  54084. {
  54085. cg.x1 = x + width - edgeBlurRadius;
  54086. cg.x2 = x + width;
  54087. g.saveState();
  54088. g.setGradientFill (cg);
  54089. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  54090. g.fillPath (outline);
  54091. g.restoreState();
  54092. }
  54093. {
  54094. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  54095. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  54096. Path highlight;
  54097. createRoundedPath (highlight,
  54098. x + leftIndent,
  54099. y + cs * 0.1f,
  54100. width - (leftIndent + rightIndent),
  54101. height * 0.4f, cs * 0.4f,
  54102. ! (flatOnLeft || flatOnTop),
  54103. ! (flatOnRight || flatOnTop),
  54104. ! (flatOnLeft || flatOnBottom),
  54105. ! (flatOnRight || flatOnBottom));
  54106. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  54107. Colours::transparentWhite, 0, y + height * 0.4f, false));
  54108. g.fillPath (highlight);
  54109. }
  54110. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  54111. g.strokePath (outline, PathStrokeType (outlineThickness));
  54112. }
  54113. END_JUCE_NAMESPACE
  54114. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  54115. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  54116. BEGIN_JUCE_NAMESPACE
  54117. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  54118. {
  54119. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  54120. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  54121. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  54122. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  54123. setColour (Slider::thumbColourId, Colours::white);
  54124. setColour (Slider::trackColourId, Colour (0x7f000000));
  54125. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  54126. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  54127. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  54128. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  54129. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  54130. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  54131. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  54132. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  54133. }
  54134. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  54135. {
  54136. }
  54137. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  54138. Button& button,
  54139. const Colour& backgroundColour,
  54140. bool isMouseOverButton,
  54141. bool isButtonDown)
  54142. {
  54143. const int width = button.getWidth();
  54144. const int height = button.getHeight();
  54145. const float indent = 2.0f;
  54146. const int cornerSize = jmin (roundToInt (width * 0.4f),
  54147. roundToInt (height * 0.4f));
  54148. Path p;
  54149. p.addRoundedRectangle (indent, indent,
  54150. width - indent * 2.0f,
  54151. height - indent * 2.0f,
  54152. (float) cornerSize);
  54153. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  54154. if (isMouseOverButton)
  54155. {
  54156. if (isButtonDown)
  54157. bc = bc.brighter();
  54158. else if (bc.getBrightness() > 0.5f)
  54159. bc = bc.darker (0.1f);
  54160. else
  54161. bc = bc.brighter (0.1f);
  54162. }
  54163. g.setColour (bc);
  54164. g.fillPath (p);
  54165. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  54166. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  54167. }
  54168. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  54169. Component& /*component*/,
  54170. float x, float y, float w, float h,
  54171. const bool ticked,
  54172. const bool isEnabled,
  54173. const bool /*isMouseOverButton*/,
  54174. const bool isButtonDown)
  54175. {
  54176. Path box;
  54177. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  54178. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  54179. : Colours::lightgrey.withAlpha (0.1f));
  54180. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  54181. g.fillPath (box, trans);
  54182. g.setColour (Colours::black.withAlpha (0.6f));
  54183. g.strokePath (box, PathStrokeType (0.9f), trans);
  54184. if (ticked)
  54185. {
  54186. Path tick;
  54187. tick.startNewSubPath (1.5f, 3.0f);
  54188. tick.lineTo (3.0f, 6.0f);
  54189. tick.lineTo (6.0f, 0.0f);
  54190. g.setColour (isEnabled ? Colours::black : Colours::grey);
  54191. g.strokePath (tick, PathStrokeType (2.5f), trans);
  54192. }
  54193. }
  54194. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  54195. ToggleButton& button,
  54196. bool isMouseOverButton,
  54197. bool isButtonDown)
  54198. {
  54199. if (button.hasKeyboardFocus (true))
  54200. {
  54201. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  54202. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  54203. }
  54204. const int tickWidth = jmin (20, button.getHeight() - 4);
  54205. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  54206. (float) tickWidth, (float) tickWidth,
  54207. button.getToggleState(),
  54208. button.isEnabled(),
  54209. isMouseOverButton,
  54210. isButtonDown);
  54211. g.setColour (button.findColour (ToggleButton::textColourId));
  54212. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  54213. if (! button.isEnabled())
  54214. g.setOpacity (0.5f);
  54215. const int textX = tickWidth + 5;
  54216. g.drawFittedText (button.getButtonText(),
  54217. textX, 4,
  54218. button.getWidth() - textX - 2, button.getHeight() - 8,
  54219. Justification::centredLeft, 10);
  54220. }
  54221. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  54222. int width, int height,
  54223. double progress, const String& textToShow)
  54224. {
  54225. if (progress < 0 || progress >= 1.0)
  54226. {
  54227. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  54228. }
  54229. else
  54230. {
  54231. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  54232. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  54233. g.fillAll (background);
  54234. g.setColour (foreground);
  54235. g.fillRect (1, 1,
  54236. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  54237. height - 2);
  54238. if (textToShow.isNotEmpty())
  54239. {
  54240. g.setColour (Colour::contrasting (background, foreground));
  54241. g.setFont (height * 0.6f);
  54242. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  54243. }
  54244. }
  54245. }
  54246. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  54247. ScrollBar& bar,
  54248. int width, int height,
  54249. int buttonDirection,
  54250. bool isScrollbarVertical,
  54251. bool isMouseOverButton,
  54252. bool isButtonDown)
  54253. {
  54254. if (isScrollbarVertical)
  54255. width -= 2;
  54256. else
  54257. height -= 2;
  54258. Path p;
  54259. if (buttonDirection == 0)
  54260. p.addTriangle (width * 0.5f, height * 0.2f,
  54261. width * 0.1f, height * 0.7f,
  54262. width * 0.9f, height * 0.7f);
  54263. else if (buttonDirection == 1)
  54264. p.addTriangle (width * 0.8f, height * 0.5f,
  54265. width * 0.3f, height * 0.1f,
  54266. width * 0.3f, height * 0.9f);
  54267. else if (buttonDirection == 2)
  54268. p.addTriangle (width * 0.5f, height * 0.8f,
  54269. width * 0.1f, height * 0.3f,
  54270. width * 0.9f, height * 0.3f);
  54271. else if (buttonDirection == 3)
  54272. p.addTriangle (width * 0.2f, height * 0.5f,
  54273. width * 0.7f, height * 0.1f,
  54274. width * 0.7f, height * 0.9f);
  54275. if (isButtonDown)
  54276. g.setColour (Colours::white);
  54277. else if (isMouseOverButton)
  54278. g.setColour (Colours::white.withAlpha (0.7f));
  54279. else
  54280. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  54281. g.fillPath (p);
  54282. g.setColour (Colours::black.withAlpha (0.5f));
  54283. g.strokePath (p, PathStrokeType (0.5f));
  54284. }
  54285. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  54286. ScrollBar& bar,
  54287. int x, int y,
  54288. int width, int height,
  54289. bool isScrollbarVertical,
  54290. int thumbStartPosition,
  54291. int thumbSize,
  54292. bool isMouseOver,
  54293. bool isMouseDown)
  54294. {
  54295. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  54296. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54297. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  54298. if (thumbSize > 0.0f)
  54299. {
  54300. Rectangle<int> thumb;
  54301. if (isScrollbarVertical)
  54302. {
  54303. width -= 2;
  54304. g.fillRect (x + roundToInt (width * 0.35f), y,
  54305. roundToInt (width * 0.3f), height);
  54306. thumb.setBounds (x + 1, thumbStartPosition,
  54307. width - 2, thumbSize);
  54308. }
  54309. else
  54310. {
  54311. height -= 2;
  54312. g.fillRect (x, y + roundToInt (height * 0.35f),
  54313. width, roundToInt (height * 0.3f));
  54314. thumb.setBounds (thumbStartPosition, y + 1,
  54315. thumbSize, height - 2);
  54316. }
  54317. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54318. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  54319. g.fillRect (thumb);
  54320. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  54321. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  54322. if (thumbSize > 16)
  54323. {
  54324. for (int i = 3; --i >= 0;)
  54325. {
  54326. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  54327. g.setColour (Colours::black.withAlpha (0.15f));
  54328. if (isScrollbarVertical)
  54329. {
  54330. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  54331. g.setColour (Colours::white.withAlpha (0.15f));
  54332. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  54333. }
  54334. else
  54335. {
  54336. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  54337. g.setColour (Colours::white.withAlpha (0.15f));
  54338. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  54339. }
  54340. }
  54341. }
  54342. }
  54343. }
  54344. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  54345. {
  54346. return &scrollbarShadow;
  54347. }
  54348. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  54349. {
  54350. g.fillAll (findColour (PopupMenu::backgroundColourId));
  54351. g.setColour (Colours::black.withAlpha (0.6f));
  54352. g.drawRect (0, 0, width, height);
  54353. }
  54354. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  54355. bool, MenuBarComponent& menuBar)
  54356. {
  54357. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  54358. }
  54359. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  54360. {
  54361. if (textEditor.isEnabled())
  54362. {
  54363. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  54364. g.drawRect (0, 0, width, height);
  54365. }
  54366. }
  54367. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  54368. const bool isButtonDown,
  54369. int buttonX, int buttonY,
  54370. int buttonW, int buttonH,
  54371. ComboBox& box)
  54372. {
  54373. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  54374. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  54375. : ComboBox::backgroundColourId));
  54376. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  54377. g.setColour (box.findColour (ComboBox::outlineColourId));
  54378. g.drawRect (0, 0, width, height);
  54379. const float arrowX = 0.2f;
  54380. const float arrowH = 0.3f;
  54381. if (box.isEnabled())
  54382. {
  54383. Path p;
  54384. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  54385. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  54386. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  54387. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  54388. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  54389. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  54390. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  54391. : ComboBox::buttonColourId));
  54392. g.fillPath (p);
  54393. }
  54394. }
  54395. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  54396. {
  54397. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  54398. f.setHorizontalScale (0.9f);
  54399. return f;
  54400. }
  54401. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  54402. {
  54403. Path p;
  54404. p.addTriangle (x1, y1, x2, y2, x3, y3);
  54405. g.setColour (fill);
  54406. g.fillPath (p);
  54407. g.setColour (outline);
  54408. g.strokePath (p, PathStrokeType (0.3f));
  54409. }
  54410. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  54411. int x, int y,
  54412. int w, int h,
  54413. float sliderPos,
  54414. float minSliderPos,
  54415. float maxSliderPos,
  54416. const Slider::SliderStyle style,
  54417. Slider& slider)
  54418. {
  54419. g.fillAll (slider.findColour (Slider::backgroundColourId));
  54420. if (style == Slider::LinearBar)
  54421. {
  54422. g.setColour (slider.findColour (Slider::thumbColourId));
  54423. g.fillRect (x, y, (int) sliderPos - x, h);
  54424. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  54425. g.drawRect (x, y, (int) sliderPos - x, h);
  54426. }
  54427. else
  54428. {
  54429. g.setColour (slider.findColour (Slider::trackColourId)
  54430. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  54431. if (slider.isHorizontal())
  54432. {
  54433. g.fillRect (x, y + roundToInt (h * 0.6f),
  54434. w, roundToInt (h * 0.2f));
  54435. }
  54436. else
  54437. {
  54438. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  54439. jmin (4, roundToInt (w * 0.2f)), h);
  54440. }
  54441. float alpha = 0.35f;
  54442. if (slider.isEnabled())
  54443. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  54444. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  54445. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  54446. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  54447. {
  54448. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  54449. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  54450. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  54451. fill, outline);
  54452. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  54453. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  54454. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  54455. fill, outline);
  54456. }
  54457. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  54458. {
  54459. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54460. minSliderPos - 7.0f, y + h * 0.9f ,
  54461. minSliderPos, y + h * 0.9f,
  54462. fill, outline);
  54463. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54464. maxSliderPos, y + h * 0.9f,
  54465. maxSliderPos + 7.0f, y + h * 0.9f,
  54466. fill, outline);
  54467. }
  54468. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  54469. {
  54470. drawTriangle (g, sliderPos, y + h * 0.9f,
  54471. sliderPos - 7.0f, y + h * 0.2f,
  54472. sliderPos + 7.0f, y + h * 0.2f,
  54473. fill, outline);
  54474. }
  54475. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  54476. {
  54477. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  54478. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  54479. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  54480. fill, outline);
  54481. }
  54482. }
  54483. }
  54484. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  54485. {
  54486. if (isIncrement)
  54487. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  54488. else
  54489. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  54490. }
  54491. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  54492. {
  54493. return &scrollbarShadow;
  54494. }
  54495. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  54496. {
  54497. return 8;
  54498. }
  54499. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  54500. int w, int h,
  54501. bool isMouseOver,
  54502. bool isMouseDragging)
  54503. {
  54504. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  54505. : Colours::darkgrey);
  54506. const float lineThickness = jmin (w, h) * 0.1f;
  54507. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  54508. {
  54509. g.drawLine (w * i,
  54510. h + 1.0f,
  54511. w + 1.0f,
  54512. h * i,
  54513. lineThickness);
  54514. }
  54515. }
  54516. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  54517. {
  54518. Path shape;
  54519. if (buttonType == DocumentWindow::closeButton)
  54520. {
  54521. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  54522. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  54523. ShapeButton* const b = new ShapeButton ("close",
  54524. Colour (0x7fff3333),
  54525. Colour (0xd7ff3333),
  54526. Colour (0xf7ff3333));
  54527. b->setShape (shape, true, true, true);
  54528. return b;
  54529. }
  54530. else if (buttonType == DocumentWindow::minimiseButton)
  54531. {
  54532. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54533. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  54534. DrawablePath dp;
  54535. dp.setPath (shape);
  54536. dp.setFill (Colours::black.withAlpha (0.3f));
  54537. b->setImages (&dp);
  54538. return b;
  54539. }
  54540. else if (buttonType == DocumentWindow::maximiseButton)
  54541. {
  54542. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  54543. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54544. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  54545. DrawablePath dp;
  54546. dp.setPath (shape);
  54547. dp.setFill (Colours::black.withAlpha (0.3f));
  54548. b->setImages (&dp);
  54549. return b;
  54550. }
  54551. jassertfalse
  54552. return 0;
  54553. }
  54554. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  54555. int titleBarX,
  54556. int titleBarY,
  54557. int titleBarW,
  54558. int titleBarH,
  54559. Button* minimiseButton,
  54560. Button* maximiseButton,
  54561. Button* closeButton,
  54562. bool positionTitleBarButtonsOnLeft)
  54563. {
  54564. titleBarY += titleBarH / 8;
  54565. titleBarH -= titleBarH / 4;
  54566. const int buttonW = titleBarH;
  54567. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  54568. : titleBarX + titleBarW - buttonW - 4;
  54569. if (closeButton != 0)
  54570. {
  54571. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  54572. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  54573. : -(buttonW + buttonW / 5);
  54574. }
  54575. if (positionTitleBarButtonsOnLeft)
  54576. swapVariables (minimiseButton, maximiseButton);
  54577. if (maximiseButton != 0)
  54578. {
  54579. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54580. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  54581. }
  54582. if (minimiseButton != 0)
  54583. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54584. }
  54585. END_JUCE_NAMESPACE
  54586. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  54587. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  54588. BEGIN_JUCE_NAMESPACE
  54589. class DummyMenuComponent : public Component
  54590. {
  54591. DummyMenuComponent (const DummyMenuComponent&);
  54592. const DummyMenuComponent& operator= (const DummyMenuComponent&);
  54593. public:
  54594. DummyMenuComponent() {}
  54595. ~DummyMenuComponent() {}
  54596. void inputAttemptWhenModal()
  54597. {
  54598. exitModalState (0);
  54599. }
  54600. };
  54601. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  54602. : model (0),
  54603. itemUnderMouse (-1),
  54604. currentPopupIndex (-1),
  54605. indexToShowAgain (-1),
  54606. lastMouseX (0),
  54607. lastMouseY (0),
  54608. inModalState (false)
  54609. {
  54610. setRepaintsOnMouseActivity (true);
  54611. setWantsKeyboardFocus (false);
  54612. setMouseClickGrabsKeyboardFocus (false);
  54613. setModel (model_);
  54614. }
  54615. MenuBarComponent::~MenuBarComponent()
  54616. {
  54617. setModel (0);
  54618. Desktop::getInstance().removeGlobalMouseListener (this);
  54619. currentPopup = 0;
  54620. }
  54621. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  54622. {
  54623. if (model != newModel)
  54624. {
  54625. if (model != 0)
  54626. model->removeListener (this);
  54627. model = newModel;
  54628. if (model != 0)
  54629. model->addListener (this);
  54630. repaint();
  54631. menuBarItemsChanged (0);
  54632. }
  54633. }
  54634. void MenuBarComponent::paint (Graphics& g)
  54635. {
  54636. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  54637. getLookAndFeel().drawMenuBarBackground (g,
  54638. getWidth(),
  54639. getHeight(),
  54640. isMouseOverBar,
  54641. *this);
  54642. if (model != 0)
  54643. {
  54644. for (int i = 0; i < menuNames.size(); ++i)
  54645. {
  54646. g.saveState();
  54647. g.setOrigin (xPositions [i], 0);
  54648. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  54649. getLookAndFeel().drawMenuBarItem (g,
  54650. xPositions[i + 1] - xPositions[i],
  54651. getHeight(),
  54652. i,
  54653. menuNames[i],
  54654. i == itemUnderMouse,
  54655. i == currentPopupIndex,
  54656. isMouseOverBar,
  54657. *this);
  54658. g.restoreState();
  54659. }
  54660. }
  54661. }
  54662. void MenuBarComponent::resized()
  54663. {
  54664. xPositions.clear();
  54665. int x = 2;
  54666. xPositions.add (x);
  54667. for (int i = 0; i < menuNames.size(); ++i)
  54668. {
  54669. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  54670. xPositions.add (x);
  54671. }
  54672. }
  54673. int MenuBarComponent::getItemAt (const int x, const int y)
  54674. {
  54675. for (int i = 0; i < xPositions.size(); ++i)
  54676. if (x >= xPositions[i] && x < xPositions[i + 1])
  54677. return reallyContains (x, y, true) ? i : -1;
  54678. return -1;
  54679. }
  54680. void MenuBarComponent::repaintMenuItem (int index)
  54681. {
  54682. if (((unsigned int) index) < (unsigned int) xPositions.size())
  54683. {
  54684. const int x1 = xPositions [index];
  54685. const int x2 = xPositions [index + 1];
  54686. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  54687. }
  54688. }
  54689. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  54690. {
  54691. const int newItem = getItemAt (x, y);
  54692. if (itemUnderMouse != newItem)
  54693. {
  54694. repaintMenuItem (itemUnderMouse);
  54695. itemUnderMouse = newItem;
  54696. repaintMenuItem (itemUnderMouse);
  54697. }
  54698. }
  54699. void MenuBarComponent::hideCurrentMenu()
  54700. {
  54701. currentPopup = 0;
  54702. repaint();
  54703. }
  54704. void MenuBarComponent::showMenu (int index)
  54705. {
  54706. if (index != currentPopupIndex)
  54707. {
  54708. if (inModalState)
  54709. {
  54710. hideCurrentMenu();
  54711. indexToShowAgain = index;
  54712. return;
  54713. }
  54714. indexToShowAgain = -1;
  54715. currentPopupIndex = -1;
  54716. itemUnderMouse = index;
  54717. currentPopup = 0;
  54718. menuBarItemsChanged (0);
  54719. Component* const prevFocused = getCurrentlyFocusedComponent();
  54720. ScopedPointer <ComponentDeletionWatcher> prevCompDeletionChecker;
  54721. if (prevFocused != 0)
  54722. prevCompDeletionChecker = new ComponentDeletionWatcher (prevFocused);
  54723. ComponentDeletionWatcher deletionChecker (this);
  54724. enterModalState (false);
  54725. inModalState = true;
  54726. int result = 0;
  54727. ApplicationCommandManager* managerOfChosenCommand = 0;
  54728. Desktop::getInstance().addGlobalMouseListener (this);
  54729. for (;;)
  54730. {
  54731. const int x = getScreenX() + xPositions [itemUnderMouse];
  54732. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54733. currentPopupIndex = itemUnderMouse;
  54734. indexToShowAgain = -1;
  54735. repaint();
  54736. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54737. {
  54738. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54739. menuNames [itemUnderMouse]));
  54740. if (m.lookAndFeel == 0)
  54741. m.setLookAndFeel (&getLookAndFeel());
  54742. currentPopup = m.createMenuComponent (x, getScreenY(),
  54743. w, getHeight(),
  54744. 0, w, 0, 0,
  54745. true, this,
  54746. &managerOfChosenCommand,
  54747. this);
  54748. }
  54749. if (currentPopup == 0)
  54750. {
  54751. currentPopup = new DummyMenuComponent();
  54752. addAndMakeVisible (currentPopup);
  54753. }
  54754. currentPopup->enterModalState (false);
  54755. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54756. // be stuck behind other comps that are already modal..
  54757. result = currentPopup->runModalLoop();
  54758. if (deletionChecker.hasBeenDeleted())
  54759. return;
  54760. const int lastPopupIndex = currentPopupIndex;
  54761. currentPopup = 0;
  54762. currentPopupIndex = -1;
  54763. if (result != 0)
  54764. {
  54765. topLevelIndexClicked = lastPopupIndex;
  54766. break;
  54767. }
  54768. else if (indexToShowAgain >= 0)
  54769. {
  54770. menuBarItemsChanged (0);
  54771. repaint();
  54772. itemUnderMouse = indexToShowAgain;
  54773. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54774. break;
  54775. }
  54776. else
  54777. {
  54778. break;
  54779. }
  54780. }
  54781. Desktop::getInstance().removeGlobalMouseListener (this);
  54782. inModalState = false;
  54783. exitModalState (0);
  54784. if (prevCompDeletionChecker != 0 && ! prevCompDeletionChecker->hasBeenDeleted())
  54785. prevFocused->grabKeyboardFocus();
  54786. int mx, my;
  54787. getMouseXYRelative (mx, my);
  54788. updateItemUnderMouse (mx, my);
  54789. repaint();
  54790. if (result != 0)
  54791. {
  54792. if (managerOfChosenCommand != 0)
  54793. {
  54794. ApplicationCommandTarget::InvocationInfo info (result);
  54795. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54796. managerOfChosenCommand->invoke (info, true);
  54797. }
  54798. postCommandMessage (result);
  54799. }
  54800. }
  54801. }
  54802. void MenuBarComponent::handleCommandMessage (int commandId)
  54803. {
  54804. if (model != 0)
  54805. model->menuItemSelected (commandId, topLevelIndexClicked);
  54806. }
  54807. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54808. {
  54809. if (e.eventComponent == this)
  54810. updateItemUnderMouse (e.x, e.y);
  54811. }
  54812. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54813. {
  54814. if (e.eventComponent == this)
  54815. updateItemUnderMouse (e.x, e.y);
  54816. }
  54817. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54818. {
  54819. const MouseEvent e2 (e.getEventRelativeTo (this));
  54820. if (currentPopupIndex < 0)
  54821. {
  54822. updateItemUnderMouse (e2.x, e2.y);
  54823. currentPopupIndex = -2;
  54824. showMenu (itemUnderMouse);
  54825. }
  54826. }
  54827. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54828. {
  54829. const MouseEvent e2 (e.getEventRelativeTo (this));
  54830. const int item = getItemAt (e2.x, e2.y);
  54831. if (item >= 0)
  54832. showMenu (item);
  54833. }
  54834. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54835. {
  54836. const MouseEvent e2 (e.getEventRelativeTo (this));
  54837. updateItemUnderMouse (e2.x, e2.y);
  54838. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54839. hideCurrentMenu();
  54840. }
  54841. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54842. {
  54843. const MouseEvent e2 (e.getEventRelativeTo (this));
  54844. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54845. {
  54846. if (currentPopupIndex >= 0)
  54847. {
  54848. const int item = getItemAt (e2.x, e2.y);
  54849. if (item >= 0)
  54850. showMenu (item);
  54851. }
  54852. else
  54853. {
  54854. updateItemUnderMouse (e2.x, e2.y);
  54855. }
  54856. lastMouseX = e2.x;
  54857. lastMouseY = e2.y;
  54858. }
  54859. }
  54860. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54861. {
  54862. bool used = false;
  54863. const int numMenus = menuNames.size();
  54864. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54865. if (key.isKeyCode (KeyPress::leftKey))
  54866. {
  54867. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54868. used = true;
  54869. }
  54870. else if (key.isKeyCode (KeyPress::rightKey))
  54871. {
  54872. showMenu ((currentIndex + 1) % numMenus);
  54873. used = true;
  54874. }
  54875. return used;
  54876. }
  54877. void MenuBarComponent::inputAttemptWhenModal()
  54878. {
  54879. hideCurrentMenu();
  54880. }
  54881. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54882. {
  54883. StringArray newNames;
  54884. if (model != 0)
  54885. newNames = model->getMenuBarNames();
  54886. if (newNames != menuNames)
  54887. {
  54888. menuNames = newNames;
  54889. repaint();
  54890. resized();
  54891. }
  54892. }
  54893. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54894. const ApplicationCommandTarget::InvocationInfo& info)
  54895. {
  54896. if (model == 0
  54897. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54898. return;
  54899. for (int i = 0; i < menuNames.size(); ++i)
  54900. {
  54901. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54902. if (menu.containsCommandItem (info.commandID))
  54903. {
  54904. itemUnderMouse = i;
  54905. repaintMenuItem (i);
  54906. startTimer (200);
  54907. break;
  54908. }
  54909. }
  54910. }
  54911. void MenuBarComponent::timerCallback()
  54912. {
  54913. stopTimer();
  54914. int mx, my;
  54915. getMouseXYRelative (mx, my);
  54916. updateItemUnderMouse (mx, my);
  54917. }
  54918. END_JUCE_NAMESPACE
  54919. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54920. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54921. BEGIN_JUCE_NAMESPACE
  54922. MenuBarModel::MenuBarModel() throw()
  54923. : manager (0)
  54924. {
  54925. }
  54926. MenuBarModel::~MenuBarModel()
  54927. {
  54928. setApplicationCommandManagerToWatch (0);
  54929. }
  54930. void MenuBarModel::menuItemsChanged()
  54931. {
  54932. triggerAsyncUpdate();
  54933. }
  54934. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54935. {
  54936. if (manager != newManager)
  54937. {
  54938. if (manager != 0)
  54939. manager->removeListener (this);
  54940. manager = newManager;
  54941. if (manager != 0)
  54942. manager->addListener (this);
  54943. }
  54944. }
  54945. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54946. {
  54947. jassert (newListener != 0);
  54948. jassert (! listeners.contains (newListener)); // trying to add a listener to the list twice!
  54949. if (newListener != 0)
  54950. listeners.add (newListener);
  54951. }
  54952. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54953. {
  54954. // Trying to remove a listener that isn't on the list!
  54955. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54956. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54957. jassert (listeners.contains (listenerToRemove));
  54958. listeners.removeValue (listenerToRemove);
  54959. }
  54960. void MenuBarModel::handleAsyncUpdate()
  54961. {
  54962. for (int i = listeners.size(); --i >= 0;)
  54963. {
  54964. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuBarItemsChanged (this);
  54965. i = jmin (i, listeners.size());
  54966. }
  54967. }
  54968. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54969. {
  54970. for (int i = listeners.size(); --i >= 0;)
  54971. {
  54972. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuCommandInvoked (this, info);
  54973. i = jmin (i, listeners.size());
  54974. }
  54975. }
  54976. void MenuBarModel::applicationCommandListChanged()
  54977. {
  54978. menuItemsChanged();
  54979. }
  54980. END_JUCE_NAMESPACE
  54981. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54982. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54983. BEGIN_JUCE_NAMESPACE
  54984. class PopupMenu::Item
  54985. {
  54986. public:
  54987. Item()
  54988. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54989. usesColour (false), customComp (0), commandManager (0)
  54990. {
  54991. }
  54992. Item (const int itemId_,
  54993. const String& text_,
  54994. const bool active_,
  54995. const bool isTicked_,
  54996. const Image* im,
  54997. const Colour& textColour_,
  54998. const bool usesColour_,
  54999. PopupMenuCustomComponent* const customComp_,
  55000. const PopupMenu* const subMenu_,
  55001. ApplicationCommandManager* const commandManager_)
  55002. : itemId (itemId_), text (text_), textColour (textColour_),
  55003. active (active_), isSeparator (false), isTicked (isTicked_),
  55004. usesColour (usesColour_), customComp (customComp_),
  55005. commandManager (commandManager_)
  55006. {
  55007. if (subMenu_ != 0)
  55008. subMenu = new PopupMenu (*subMenu_);
  55009. if (im != 0)
  55010. image = im->createCopy();
  55011. if (commandManager_ != 0 && itemId_ != 0)
  55012. {
  55013. String shortcutKey;
  55014. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  55015. ->getKeyPressesAssignedToCommand (itemId_));
  55016. for (int i = 0; i < keyPresses.size(); ++i)
  55017. {
  55018. const String key (keyPresses.getReference(i).getTextDescription());
  55019. if (shortcutKey.isNotEmpty())
  55020. shortcutKey << ", ";
  55021. if (key.length() == 1)
  55022. shortcutKey << "shortcut: '" << key << '\'';
  55023. else
  55024. shortcutKey << key;
  55025. }
  55026. shortcutKey = shortcutKey.trim();
  55027. if (shortcutKey.isNotEmpty())
  55028. text << "<end>" << shortcutKey;
  55029. }
  55030. }
  55031. Item (const Item& other)
  55032. : itemId (other.itemId),
  55033. text (other.text),
  55034. textColour (other.textColour),
  55035. active (other.active),
  55036. isSeparator (other.isSeparator),
  55037. isTicked (other.isTicked),
  55038. usesColour (other.usesColour),
  55039. customComp (other.customComp),
  55040. commandManager (other.commandManager)
  55041. {
  55042. if (other.subMenu != 0)
  55043. subMenu = new PopupMenu (*(other.subMenu));
  55044. if (other.image != 0)
  55045. image = other.image->createCopy();
  55046. }
  55047. ~Item()
  55048. {
  55049. customComp = 0;
  55050. }
  55051. bool canBeTriggered() const throw()
  55052. {
  55053. return active && ! (isSeparator || (subMenu != 0));
  55054. }
  55055. bool hasActiveSubMenu() const throw()
  55056. {
  55057. return active && (subMenu != 0);
  55058. }
  55059. const int itemId;
  55060. String text;
  55061. const Colour textColour;
  55062. const bool active, isSeparator, isTicked, usesColour;
  55063. ScopedPointer <Image> image;
  55064. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  55065. ScopedPointer <PopupMenu> subMenu;
  55066. ApplicationCommandManager* const commandManager;
  55067. juce_UseDebuggingNewOperator
  55068. private:
  55069. Item& operator= (const Item&);
  55070. };
  55071. class PopupMenu::ItemComponent : public Component
  55072. {
  55073. public:
  55074. ItemComponent (const PopupMenu::Item& itemInfo_)
  55075. : itemInfo (itemInfo_),
  55076. isHighlighted (false)
  55077. {
  55078. if (itemInfo.customComp != 0)
  55079. addAndMakeVisible (itemInfo.customComp);
  55080. }
  55081. ~ItemComponent()
  55082. {
  55083. if (itemInfo.customComp != 0)
  55084. removeChildComponent (itemInfo.customComp);
  55085. }
  55086. void getIdealSize (int& idealWidth,
  55087. int& idealHeight,
  55088. const int standardItemHeight)
  55089. {
  55090. if (itemInfo.customComp != 0)
  55091. {
  55092. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  55093. }
  55094. else
  55095. {
  55096. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  55097. itemInfo.isSeparator,
  55098. standardItemHeight,
  55099. idealWidth,
  55100. idealHeight);
  55101. }
  55102. }
  55103. void paint (Graphics& g)
  55104. {
  55105. if (itemInfo.customComp == 0)
  55106. {
  55107. String mainText (itemInfo.text);
  55108. String endText;
  55109. const int endIndex = mainText.indexOf (T("<end>"));
  55110. if (endIndex >= 0)
  55111. {
  55112. endText = mainText.substring (endIndex + 5).trim();
  55113. mainText = mainText.substring (0, endIndex);
  55114. }
  55115. getLookAndFeel()
  55116. .drawPopupMenuItem (g, getWidth(), getHeight(),
  55117. itemInfo.isSeparator,
  55118. itemInfo.active,
  55119. isHighlighted,
  55120. itemInfo.isTicked,
  55121. itemInfo.subMenu != 0,
  55122. mainText, endText,
  55123. itemInfo.image,
  55124. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  55125. }
  55126. }
  55127. void resized()
  55128. {
  55129. if (getNumChildComponents() > 0)
  55130. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  55131. }
  55132. void setHighlighted (bool shouldBeHighlighted)
  55133. {
  55134. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  55135. if (isHighlighted != shouldBeHighlighted)
  55136. {
  55137. isHighlighted = shouldBeHighlighted;
  55138. if (itemInfo.customComp != 0)
  55139. {
  55140. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  55141. itemInfo.customComp->repaint();
  55142. }
  55143. repaint();
  55144. }
  55145. }
  55146. PopupMenu::Item itemInfo;
  55147. juce_UseDebuggingNewOperator
  55148. private:
  55149. bool isHighlighted;
  55150. ItemComponent (const ItemComponent&);
  55151. ItemComponent& operator= (const ItemComponent&);
  55152. };
  55153. namespace PopupMenuSettings
  55154. {
  55155. static const int scrollZone = 24;
  55156. static const int borderSize = 2;
  55157. static const int timerInterval = 50;
  55158. static const int dismissCommandId = 0x6287345f;
  55159. }
  55160. class PopupMenu::Window : public Component,
  55161. private Timer
  55162. {
  55163. public:
  55164. Window()
  55165. : Component (T("menu")),
  55166. owner (0),
  55167. currentChild (0),
  55168. activeSubMenu (0),
  55169. menuBarComponent (0),
  55170. managerOfChosenCommand (0),
  55171. componentAttachedTo (0),
  55172. lastMouseX (0),
  55173. lastMouseY (0),
  55174. minimumWidth (0),
  55175. maximumNumColumns (7),
  55176. standardItemHeight (0),
  55177. isOver (false),
  55178. hasBeenOver (false),
  55179. isDown (false),
  55180. needsToScroll (false),
  55181. hideOnExit (false),
  55182. disableMouseMoves (false),
  55183. hasAnyJuceCompHadFocus (false),
  55184. numColumns (0),
  55185. contentHeight (0),
  55186. childYOffset (0),
  55187. timeEnteredCurrentChildComp (0),
  55188. scrollAcceleration (1.0)
  55189. {
  55190. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  55191. setWantsKeyboardFocus (true);
  55192. setMouseClickGrabsKeyboardFocus (false);
  55193. setOpaque (true);
  55194. setAlwaysOnTop (true);
  55195. Desktop::getInstance().addGlobalMouseListener (this);
  55196. getActiveWindows().add (this);
  55197. }
  55198. ~Window()
  55199. {
  55200. getActiveWindows().removeValue (this);
  55201. Desktop::getInstance().removeGlobalMouseListener (this);
  55202. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55203. activeSubMenu = 0;
  55204. deleteAllChildren();
  55205. attachedCompWatcher = 0;
  55206. }
  55207. static Window* create (const PopupMenu& menu,
  55208. const bool dismissOnMouseUp,
  55209. Window* const owner_,
  55210. const int minX, const int maxX,
  55211. const int minY, const int maxY,
  55212. const int minimumWidth,
  55213. const int maximumNumColumns,
  55214. const int standardItemHeight,
  55215. const bool alignToRectangle,
  55216. const int itemIdThatMustBeVisible,
  55217. Component* const menuBarComponent,
  55218. ApplicationCommandManager** managerOfChosenCommand,
  55219. Component* const componentAttachedTo)
  55220. {
  55221. if (menu.items.size() > 0)
  55222. {
  55223. int totalItems = 0;
  55224. ScopedPointer <Window> mw (new Window());
  55225. mw->setLookAndFeel (menu.lookAndFeel);
  55226. mw->setWantsKeyboardFocus (false);
  55227. mw->minimumWidth = minimumWidth;
  55228. mw->maximumNumColumns = maximumNumColumns;
  55229. mw->standardItemHeight = standardItemHeight;
  55230. mw->dismissOnMouseUp = dismissOnMouseUp;
  55231. for (int i = 0; i < menu.items.size(); ++i)
  55232. {
  55233. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  55234. mw->addItem (*item);
  55235. ++totalItems;
  55236. }
  55237. if (totalItems > 0)
  55238. {
  55239. mw->owner = owner_;
  55240. mw->menuBarComponent = menuBarComponent;
  55241. mw->managerOfChosenCommand = managerOfChosenCommand;
  55242. mw->componentAttachedTo = componentAttachedTo;
  55243. mw->attachedCompWatcher = componentAttachedTo != 0 ? new ComponentDeletionWatcher (componentAttachedTo) : 0;
  55244. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  55245. mw->setTopLeftPosition (mw->windowPos.getX(),
  55246. mw->windowPos.getY());
  55247. mw->updateYPositions();
  55248. if (itemIdThatMustBeVisible != 0)
  55249. {
  55250. const int y = minY - mw->windowPos.getY();
  55251. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  55252. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  55253. }
  55254. mw->resizeToBestWindowPos();
  55255. mw->addToDesktop (ComponentPeer::windowIsTemporary
  55256. | mw->getLookAndFeel().getMenuWindowFlags());
  55257. return mw.release();
  55258. }
  55259. }
  55260. return 0;
  55261. }
  55262. void paint (Graphics& g)
  55263. {
  55264. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  55265. }
  55266. void paintOverChildren (Graphics& g)
  55267. {
  55268. if (isScrolling())
  55269. {
  55270. LookAndFeel& lf = getLookAndFeel();
  55271. if (isScrollZoneActive (false))
  55272. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  55273. if (isScrollZoneActive (true))
  55274. {
  55275. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  55276. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  55277. }
  55278. }
  55279. }
  55280. bool isScrollZoneActive (bool bottomOne) const
  55281. {
  55282. return isScrolling()
  55283. && (bottomOne
  55284. ? childYOffset < contentHeight - windowPos.getHeight()
  55285. : childYOffset > 0);
  55286. }
  55287. void addItem (const PopupMenu::Item& item)
  55288. {
  55289. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  55290. addAndMakeVisible (mic);
  55291. int itemW = 80;
  55292. int itemH = 16;
  55293. mic->getIdealSize (itemW, itemH, standardItemHeight);
  55294. mic->setSize (itemW, jlimit (2, 600, itemH));
  55295. mic->addMouseListener (this, false);
  55296. }
  55297. // hide this and all sub-comps
  55298. void hide (const PopupMenu::Item* const item)
  55299. {
  55300. if (isVisible())
  55301. {
  55302. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55303. activeSubMenu = 0;
  55304. currentChild = 0;
  55305. exitModalState (item != 0 ? item->itemId : 0);
  55306. setVisible (false);
  55307. if (item != 0
  55308. && item->commandManager != 0
  55309. && item->itemId != 0)
  55310. {
  55311. *managerOfChosenCommand = item->commandManager;
  55312. }
  55313. }
  55314. }
  55315. void dismissMenu (const PopupMenu::Item* const item)
  55316. {
  55317. if (owner != 0)
  55318. {
  55319. owner->dismissMenu (item);
  55320. }
  55321. else
  55322. {
  55323. if (item != 0)
  55324. {
  55325. // need a copy of this on the stack as the one passed in will get deleted during this call
  55326. const PopupMenu::Item mi (*item);
  55327. hide (&mi);
  55328. }
  55329. else
  55330. {
  55331. hide (0);
  55332. }
  55333. }
  55334. }
  55335. void mouseMove (const MouseEvent&)
  55336. {
  55337. timerCallback();
  55338. }
  55339. void mouseDown (const MouseEvent&)
  55340. {
  55341. timerCallback();
  55342. }
  55343. void mouseDrag (const MouseEvent&)
  55344. {
  55345. timerCallback();
  55346. }
  55347. void mouseUp (const MouseEvent&)
  55348. {
  55349. timerCallback();
  55350. }
  55351. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  55352. {
  55353. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  55354. lastMouseX = -1;
  55355. }
  55356. bool keyPressed (const KeyPress& key)
  55357. {
  55358. if (key.isKeyCode (KeyPress::downKey))
  55359. {
  55360. selectNextItem (1);
  55361. }
  55362. else if (key.isKeyCode (KeyPress::upKey))
  55363. {
  55364. selectNextItem (-1);
  55365. }
  55366. else if (key.isKeyCode (KeyPress::leftKey))
  55367. {
  55368. Window* parentWindow = owner;
  55369. if (parentWindow != 0)
  55370. {
  55371. PopupMenu::ItemComponent* currentChildOfParent
  55372. = (parentWindow != 0) ? parentWindow->currentChild : 0;
  55373. hide (0);
  55374. if (parentWindow->isValidComponent())
  55375. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  55376. disableTimerUntilMouseMoves();
  55377. }
  55378. else if (menuBarComponent != 0)
  55379. {
  55380. menuBarComponent->keyPressed (key);
  55381. }
  55382. }
  55383. else if (key.isKeyCode (KeyPress::rightKey))
  55384. {
  55385. disableTimerUntilMouseMoves();
  55386. if (showSubMenuFor (currentChild))
  55387. {
  55388. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55389. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  55390. activeSubMenu->selectNextItem (1);
  55391. }
  55392. else if (menuBarComponent != 0)
  55393. {
  55394. menuBarComponent->keyPressed (key);
  55395. }
  55396. }
  55397. else if (key.isKeyCode (KeyPress::returnKey))
  55398. {
  55399. triggerCurrentlyHighlightedItem();
  55400. }
  55401. else if (key.isKeyCode (KeyPress::escapeKey))
  55402. {
  55403. dismissMenu (0);
  55404. }
  55405. else
  55406. {
  55407. return false;
  55408. }
  55409. return true;
  55410. }
  55411. void inputAttemptWhenModal()
  55412. {
  55413. timerCallback();
  55414. if (! isOverAnyMenu())
  55415. {
  55416. if (componentAttachedTo != 0 && ! attachedCompWatcher->hasBeenDeleted())
  55417. {
  55418. // we want to dismiss the menu, but if we do it synchronously, then
  55419. // the mouse-click will be allowed to pass through. That's good, except
  55420. // when the user clicks on the button that orginally popped the menu up,
  55421. // as they'll expect the menu to go away, and in fact it'll just
  55422. // come back. So only dismiss synchronously if they're not on the original
  55423. // comp that we're attached to.
  55424. int mx, my;
  55425. componentAttachedTo->getMouseXYRelative (mx, my);
  55426. if (componentAttachedTo->reallyContains (mx, my, true))
  55427. {
  55428. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  55429. return;
  55430. }
  55431. }
  55432. dismissMenu (0);
  55433. }
  55434. }
  55435. void handleCommandMessage (int commandId)
  55436. {
  55437. Component::handleCommandMessage (commandId);
  55438. if (commandId == PopupMenuSettings::dismissCommandId)
  55439. dismissMenu (0);
  55440. }
  55441. void timerCallback()
  55442. {
  55443. if (! isVisible())
  55444. return;
  55445. if (attachedCompWatcher != 0 && attachedCompWatcher->hasBeenDeleted())
  55446. {
  55447. dismissMenu (0);
  55448. return;
  55449. }
  55450. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  55451. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  55452. return;
  55453. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  55454. // move rather than a real timer callback
  55455. int mx, my;
  55456. Desktop::getMousePosition (mx, my);
  55457. int x = mx, y = my;
  55458. globalPositionToRelative (x, y);
  55459. const uint32 now = Time::getMillisecondCounter();
  55460. if (now > timeEnteredCurrentChildComp + 100
  55461. && reallyContains (x, y, true)
  55462. && currentChild->isValidComponent()
  55463. && (! disableMouseMoves)
  55464. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  55465. {
  55466. showSubMenuFor (currentChild);
  55467. }
  55468. if (mx != lastMouseX || my != lastMouseY || now > lastMouseMoveTime + 350)
  55469. {
  55470. highlightItemUnderMouse (mx, my, x, y);
  55471. }
  55472. bool overScrollArea = false;
  55473. if (isScrolling()
  55474. && (isOver || (isDown && ((unsigned int) x) < (unsigned int) getWidth()))
  55475. && ((isScrollZoneActive (false) && y < PopupMenuSettings::scrollZone)
  55476. || (isScrollZoneActive (true) && y > getHeight() - PopupMenuSettings::scrollZone)))
  55477. {
  55478. if (now > lastScroll + 20)
  55479. {
  55480. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  55481. int amount = 0;
  55482. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  55483. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  55484. alterChildYPos (y < PopupMenuSettings::scrollZone ? -amount : amount);
  55485. lastScroll = now;
  55486. }
  55487. overScrollArea = true;
  55488. lastMouseX = -1; // trigger a mouse-move
  55489. }
  55490. else
  55491. {
  55492. scrollAcceleration = 1.0;
  55493. }
  55494. const bool wasDown = isDown;
  55495. bool isOverAny = isOverAnyMenu();
  55496. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  55497. {
  55498. activeSubMenu->updateMouseOverStatus (mx, my);
  55499. isOverAny = isOverAnyMenu();
  55500. }
  55501. if (hideOnExit && hasBeenOver && ! isOverAny)
  55502. {
  55503. hide (0);
  55504. }
  55505. else
  55506. {
  55507. isDown = hasBeenOver
  55508. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  55509. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  55510. bool anyFocused = Process::isForegroundProcess();
  55511. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  55512. {
  55513. // because no component at all may have focus, our test here will
  55514. // only be triggered when something has focus and then loses it.
  55515. anyFocused = ! hasAnyJuceCompHadFocus;
  55516. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  55517. {
  55518. if (ComponentPeer::getPeer (i)->isFocused())
  55519. {
  55520. anyFocused = true;
  55521. hasAnyJuceCompHadFocus = true;
  55522. break;
  55523. }
  55524. }
  55525. }
  55526. if (! anyFocused)
  55527. {
  55528. if (now > lastFocused + 10)
  55529. {
  55530. wasHiddenBecauseOfAppChange() = true;
  55531. dismissMenu (0);
  55532. return; // may have been deleted by the previous call..
  55533. }
  55534. }
  55535. else if (wasDown && now > menuCreationTime + 250
  55536. && ! (isDown || overScrollArea))
  55537. {
  55538. isOver = reallyContains (x, y, true);
  55539. if (isOver)
  55540. {
  55541. triggerCurrentlyHighlightedItem();
  55542. }
  55543. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  55544. {
  55545. dismissMenu (0);
  55546. }
  55547. return; // may have been deleted by the previous calls..
  55548. }
  55549. else
  55550. {
  55551. lastFocused = now;
  55552. }
  55553. }
  55554. }
  55555. static Array<Window*>& getActiveWindows()
  55556. {
  55557. static Array<Window*> activeMenuWindows;
  55558. return activeMenuWindows;
  55559. }
  55560. static bool& wasHiddenBecauseOfAppChange() throw()
  55561. {
  55562. static bool b = false;
  55563. return b;
  55564. }
  55565. juce_UseDebuggingNewOperator
  55566. private:
  55567. Window* owner;
  55568. PopupMenu::ItemComponent* currentChild;
  55569. ScopedPointer <Window> activeSubMenu;
  55570. Component* menuBarComponent;
  55571. ApplicationCommandManager** managerOfChosenCommand;
  55572. Component* componentAttachedTo;
  55573. ScopedPointer <ComponentDeletionWatcher> attachedCompWatcher;
  55574. Rectangle<int> windowPos;
  55575. int lastMouseX, lastMouseY;
  55576. int minimumWidth, maximumNumColumns, standardItemHeight;
  55577. bool isOver, hasBeenOver, isDown, needsToScroll;
  55578. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  55579. int numColumns, contentHeight, childYOffset;
  55580. Array <int> columnWidths;
  55581. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  55582. double scrollAcceleration;
  55583. bool overlaps (const Rectangle<int>& r) const
  55584. {
  55585. return r.intersects (getBounds())
  55586. || (owner != 0 && owner->overlaps (r));
  55587. }
  55588. bool isOverAnyMenu() const
  55589. {
  55590. return (owner != 0) ? owner->isOverAnyMenu()
  55591. : isOverChildren();
  55592. }
  55593. bool isOverChildren() const
  55594. {
  55595. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55596. return isVisible()
  55597. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  55598. }
  55599. void updateMouseOverStatus (const int mx, const int my)
  55600. {
  55601. int rx = mx, ry = my;
  55602. globalPositionToRelative (rx, ry);
  55603. isOver = reallyContains (rx, ry, true);
  55604. if (activeSubMenu != 0)
  55605. activeSubMenu->updateMouseOverStatus (mx, my);
  55606. }
  55607. bool treeContains (const Window* const window) const throw()
  55608. {
  55609. const Window* mw = this;
  55610. while (mw->owner != 0)
  55611. mw = mw->owner;
  55612. while (mw != 0)
  55613. {
  55614. if (mw == window)
  55615. return true;
  55616. mw = mw->activeSubMenu;
  55617. }
  55618. return false;
  55619. }
  55620. void calculateWindowPos (const int minX, const int maxX,
  55621. const int minY, const int maxY,
  55622. const bool alignToRectangle)
  55623. {
  55624. const Rectangle<int> mon (Desktop::getInstance()
  55625. .getMonitorAreaContaining ((minX + maxX) / 2,
  55626. (minY + maxY) / 2,
  55627. #if JUCE_MAC
  55628. true));
  55629. #else
  55630. false)); // on windows, don't stop the menu overlapping the taskbar
  55631. #endif
  55632. int x, y, widthToUse, heightToUse;
  55633. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  55634. if (alignToRectangle)
  55635. {
  55636. x = minX;
  55637. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  55638. const int spaceOver = minY - mon.getY();
  55639. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  55640. y = maxY;
  55641. else
  55642. y = minY - heightToUse;
  55643. }
  55644. else
  55645. {
  55646. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  55647. if (owner != 0)
  55648. {
  55649. if (owner->owner != 0)
  55650. {
  55651. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  55652. > owner->owner->getX() + owner->owner->getWidth() / 2);
  55653. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  55654. tendTowardsRight = true;
  55655. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  55656. tendTowardsRight = false;
  55657. }
  55658. else if (maxX + widthToUse < mon.getRight() - 32)
  55659. {
  55660. tendTowardsRight = true;
  55661. }
  55662. }
  55663. const int biggestSpace = jmax (mon.getRight() - maxX,
  55664. minX - mon.getX()) - 32;
  55665. if (biggestSpace < widthToUse)
  55666. {
  55667. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  55668. if (numColumns > 1)
  55669. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  55670. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  55671. }
  55672. if (tendTowardsRight)
  55673. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  55674. else
  55675. x = jmax (mon.getX() + 4, minX - widthToUse);
  55676. y = minY;
  55677. if ((minY + maxY) / 2 > mon.getCentreY())
  55678. y = jmax (mon.getY(), maxY - heightToUse);
  55679. }
  55680. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  55681. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  55682. windowPos.setBounds (x, y, widthToUse, heightToUse);
  55683. // sets this flag if it's big enough to obscure any of its parent menus
  55684. hideOnExit = (owner != 0)
  55685. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  55686. }
  55687. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  55688. {
  55689. numColumns = 0;
  55690. contentHeight = 0;
  55691. const int maxMenuH = getParentHeight() - 24;
  55692. int totalW;
  55693. do
  55694. {
  55695. ++numColumns;
  55696. totalW = workOutBestSize (maxMenuW);
  55697. if (totalW > maxMenuW)
  55698. {
  55699. numColumns = jmax (1, numColumns - 1);
  55700. totalW = workOutBestSize (maxMenuW); // to update col widths
  55701. break;
  55702. }
  55703. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  55704. {
  55705. break;
  55706. }
  55707. } while (numColumns < maximumNumColumns);
  55708. const int actualH = jmin (contentHeight, maxMenuH);
  55709. needsToScroll = contentHeight > actualH;
  55710. width = updateYPositions();
  55711. height = actualH + PopupMenuSettings::borderSize * 2;
  55712. }
  55713. int workOutBestSize (const int maxMenuW)
  55714. {
  55715. int totalW = 0;
  55716. contentHeight = 0;
  55717. int childNum = 0;
  55718. for (int col = 0; col < numColumns; ++col)
  55719. {
  55720. int i, colW = 50, colH = 0;
  55721. const int numChildren = jmin (getNumChildComponents() - childNum,
  55722. (getNumChildComponents() + numColumns - 1) / numColumns);
  55723. for (i = numChildren; --i >= 0;)
  55724. {
  55725. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  55726. colH += getChildComponent (childNum + i)->getHeight();
  55727. }
  55728. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  55729. columnWidths.set (col, colW);
  55730. totalW += colW;
  55731. contentHeight = jmax (contentHeight, colH);
  55732. childNum += numChildren;
  55733. }
  55734. if (totalW < minimumWidth)
  55735. {
  55736. totalW = minimumWidth;
  55737. for (int col = 0; col < numColumns; ++col)
  55738. columnWidths.set (0, totalW / numColumns);
  55739. }
  55740. return totalW;
  55741. }
  55742. void ensureItemIsVisible (const int itemId, int wantedY)
  55743. {
  55744. jassert (itemId != 0)
  55745. for (int i = getNumChildComponents(); --i >= 0;)
  55746. {
  55747. PopupMenu::ItemComponent* const m = (PopupMenu::ItemComponent*) getChildComponent (i);
  55748. if (m != 0
  55749. && m->itemInfo.itemId == itemId
  55750. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  55751. {
  55752. const int currentY = m->getY();
  55753. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55754. {
  55755. if (wantedY < 0)
  55756. wantedY = jlimit (PopupMenuSettings::scrollZone,
  55757. jmax (PopupMenuSettings::scrollZone,
  55758. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  55759. currentY);
  55760. const Rectangle<int> mon (Desktop::getInstance()
  55761. .getMonitorAreaContaining (windowPos.getX(),
  55762. windowPos.getY(),
  55763. true));
  55764. int deltaY = wantedY - currentY;
  55765. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  55766. jmin (windowPos.getHeight(), mon.getHeight()));
  55767. const int newY = jlimit (mon.getY(),
  55768. mon.getBottom() - windowPos.getHeight(),
  55769. windowPos.getY() + deltaY);
  55770. deltaY -= newY - windowPos.getY();
  55771. childYOffset -= deltaY;
  55772. windowPos.setPosition (windowPos.getX(), newY);
  55773. updateYPositions();
  55774. }
  55775. break;
  55776. }
  55777. }
  55778. }
  55779. void resizeToBestWindowPos()
  55780. {
  55781. Rectangle<int> r (windowPos);
  55782. if (childYOffset < 0)
  55783. {
  55784. r.setBounds (r.getX(), r.getY() - childYOffset,
  55785. r.getWidth(), r.getHeight() + childYOffset);
  55786. }
  55787. else if (childYOffset > 0)
  55788. {
  55789. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55790. if (spaceAtBottom > 0)
  55791. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55792. }
  55793. setBounds (r);
  55794. updateYPositions();
  55795. }
  55796. void alterChildYPos (const int delta)
  55797. {
  55798. if (isScrolling())
  55799. {
  55800. childYOffset += delta;
  55801. if (delta < 0)
  55802. {
  55803. childYOffset = jmax (childYOffset, 0);
  55804. }
  55805. else if (delta > 0)
  55806. {
  55807. childYOffset = jmin (childYOffset,
  55808. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55809. }
  55810. updateYPositions();
  55811. }
  55812. else
  55813. {
  55814. childYOffset = 0;
  55815. }
  55816. resizeToBestWindowPos();
  55817. repaint();
  55818. }
  55819. int updateYPositions()
  55820. {
  55821. int x = 0;
  55822. int childNum = 0;
  55823. for (int col = 0; col < numColumns; ++col)
  55824. {
  55825. const int numChildren = jmin (getNumChildComponents() - childNum,
  55826. (getNumChildComponents() + numColumns - 1) / numColumns);
  55827. const int colW = columnWidths [col];
  55828. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55829. for (int i = 0; i < numChildren; ++i)
  55830. {
  55831. Component* const c = getChildComponent (childNum + i);
  55832. c->setBounds (x, y, colW, c->getHeight());
  55833. y += c->getHeight();
  55834. }
  55835. x += colW;
  55836. childNum += numChildren;
  55837. }
  55838. return x;
  55839. }
  55840. bool isScrolling() const throw()
  55841. {
  55842. return childYOffset != 0 || needsToScroll;
  55843. }
  55844. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55845. {
  55846. if (currentChild->isValidComponent())
  55847. currentChild->setHighlighted (false);
  55848. currentChild = child;
  55849. if (currentChild != 0)
  55850. {
  55851. currentChild->setHighlighted (true);
  55852. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55853. }
  55854. }
  55855. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55856. {
  55857. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55858. activeSubMenu = 0;
  55859. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55860. {
  55861. int left = 0, top = 0;
  55862. childComp->relativePositionToGlobal (left, top);
  55863. int right = childComp->getWidth(), bottom = childComp->getHeight();
  55864. childComp->relativePositionToGlobal (right, bottom);
  55865. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55866. dismissOnMouseUp,
  55867. this,
  55868. left, right, top, bottom,
  55869. 0, maximumNumColumns,
  55870. standardItemHeight,
  55871. false, 0, menuBarComponent,
  55872. managerOfChosenCommand,
  55873. componentAttachedTo);
  55874. if (activeSubMenu != 0)
  55875. {
  55876. activeSubMenu->setVisible (true);
  55877. activeSubMenu->enterModalState (false);
  55878. activeSubMenu->toFront (false);
  55879. return true;
  55880. }
  55881. }
  55882. return false;
  55883. }
  55884. void highlightItemUnderMouse (const int mx, const int my, const int x, const int y)
  55885. {
  55886. isOver = reallyContains (x, y, true);
  55887. if (isOver)
  55888. hasBeenOver = true;
  55889. if (abs (lastMouseX - mx) > 2 || abs (lastMouseY - my) > 2)
  55890. {
  55891. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55892. if (disableMouseMoves && isOver)
  55893. disableMouseMoves = false;
  55894. }
  55895. if (disableMouseMoves)
  55896. return;
  55897. bool isMovingTowardsMenu = false;
  55898. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55899. if (isOver && (activeSubMenu != 0) && (mx != lastMouseX || my != lastMouseY))
  55900. {
  55901. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55902. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55903. // extends from the last mouse pos to the submenu's rectangle..
  55904. float subX = (float) activeSubMenu->getScreenX();
  55905. if (activeSubMenu->getX() > getX())
  55906. {
  55907. lastMouseX -= 2; // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55908. }
  55909. else
  55910. {
  55911. lastMouseX += 2;
  55912. subX += activeSubMenu->getWidth();
  55913. }
  55914. Path areaTowardsSubMenu;
  55915. areaTowardsSubMenu.addTriangle ((float) lastMouseX,
  55916. (float) lastMouseY,
  55917. subX,
  55918. (float) activeSubMenu->getScreenY(),
  55919. subX,
  55920. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55921. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) mx, (float) my);
  55922. }
  55923. lastMouseX = mx;
  55924. lastMouseY = my;
  55925. if (! isMovingTowardsMenu)
  55926. {
  55927. Component* c = getComponentAt (x, y);
  55928. if (c == this)
  55929. c = 0;
  55930. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55931. if (mic == 0 && c != 0)
  55932. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55933. if (mic != currentChild
  55934. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55935. {
  55936. if (isOver && (c != 0) && (activeSubMenu != 0))
  55937. {
  55938. activeSubMenu->hide (0);
  55939. }
  55940. if (! isOver)
  55941. mic = 0;
  55942. setCurrentlyHighlightedChild (mic);
  55943. }
  55944. }
  55945. }
  55946. void triggerCurrentlyHighlightedItem()
  55947. {
  55948. if (currentChild->isValidComponent()
  55949. && currentChild->itemInfo.canBeTriggered()
  55950. && (currentChild->itemInfo.customComp == 0
  55951. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55952. {
  55953. dismissMenu (&currentChild->itemInfo);
  55954. }
  55955. }
  55956. void selectNextItem (const int delta)
  55957. {
  55958. disableTimerUntilMouseMoves();
  55959. PopupMenu::ItemComponent* mic = 0;
  55960. bool wasLastOne = (currentChild == 0);
  55961. const int numItems = getNumChildComponents();
  55962. for (int i = 0; i < numItems + 1; ++i)
  55963. {
  55964. int index = (delta > 0) ? i : (numItems - 1 - i);
  55965. index = (index + numItems) % numItems;
  55966. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55967. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55968. && wasLastOne)
  55969. break;
  55970. if (mic == currentChild)
  55971. wasLastOne = true;
  55972. }
  55973. setCurrentlyHighlightedChild (mic);
  55974. }
  55975. void disableTimerUntilMouseMoves()
  55976. {
  55977. disableMouseMoves = true;
  55978. if (owner != 0)
  55979. owner->disableTimerUntilMouseMoves();
  55980. }
  55981. Window (const Window&);
  55982. Window& operator= (const Window&);
  55983. };
  55984. PopupMenu::PopupMenu()
  55985. : lookAndFeel (0),
  55986. separatorPending (false)
  55987. {
  55988. }
  55989. PopupMenu::PopupMenu (const PopupMenu& other)
  55990. : lookAndFeel (other.lookAndFeel),
  55991. separatorPending (false)
  55992. {
  55993. items.ensureStorageAllocated (other.items.size());
  55994. for (int i = 0; i < other.items.size(); ++i)
  55995. items.add (new Item (*other.items.getUnchecked(i)));
  55996. }
  55997. const PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55998. {
  55999. if (this != &other)
  56000. {
  56001. lookAndFeel = other.lookAndFeel;
  56002. clear();
  56003. items.ensureStorageAllocated (other.items.size());
  56004. for (int i = 0; i < other.items.size(); ++i)
  56005. items.add (new Item (*other.items.getUnchecked(i)));
  56006. }
  56007. return *this;
  56008. }
  56009. PopupMenu::~PopupMenu()
  56010. {
  56011. clear();
  56012. }
  56013. void PopupMenu::clear()
  56014. {
  56015. items.clear();
  56016. separatorPending = false;
  56017. }
  56018. void PopupMenu::addSeparatorIfPending()
  56019. {
  56020. if (separatorPending)
  56021. {
  56022. separatorPending = false;
  56023. if (items.size() > 0)
  56024. items.add (new Item());
  56025. }
  56026. }
  56027. void PopupMenu::addItem (const int itemResultId,
  56028. const String& itemText,
  56029. const bool isActive,
  56030. const bool isTicked,
  56031. const Image* const iconToUse)
  56032. {
  56033. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  56034. // didn't pick anything, so you shouldn't use it as the id
  56035. // for an item..
  56036. addSeparatorIfPending();
  56037. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  56038. iconToUse, Colours::black, false, 0, 0, 0));
  56039. }
  56040. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  56041. const int commandID,
  56042. const String& displayName)
  56043. {
  56044. jassert (commandManager != 0 && commandID != 0);
  56045. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  56046. if (registeredInfo != 0)
  56047. {
  56048. ApplicationCommandInfo info (*registeredInfo);
  56049. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  56050. addSeparatorIfPending();
  56051. items.add (new Item (commandID,
  56052. displayName.isNotEmpty() ? displayName
  56053. : info.shortName,
  56054. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  56055. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  56056. 0,
  56057. Colours::black,
  56058. false,
  56059. 0, 0,
  56060. commandManager));
  56061. }
  56062. }
  56063. void PopupMenu::addColouredItem (const int itemResultId,
  56064. const String& itemText,
  56065. const Colour& itemTextColour,
  56066. const bool isActive,
  56067. const bool isTicked,
  56068. const Image* const iconToUse)
  56069. {
  56070. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  56071. // didn't pick anything, so you shouldn't use it as the id
  56072. // for an item..
  56073. addSeparatorIfPending();
  56074. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  56075. iconToUse, itemTextColour, true, 0, 0, 0));
  56076. }
  56077. void PopupMenu::addCustomItem (const int itemResultId,
  56078. PopupMenuCustomComponent* const customComponent)
  56079. {
  56080. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  56081. // didn't pick anything, so you shouldn't use it as the id
  56082. // for an item..
  56083. addSeparatorIfPending();
  56084. items.add (new Item (itemResultId, String::empty, true, false, 0,
  56085. Colours::black, false, customComponent, 0, 0));
  56086. }
  56087. class NormalComponentWrapper : public PopupMenuCustomComponent
  56088. {
  56089. public:
  56090. NormalComponentWrapper (Component* const comp,
  56091. const int w, const int h,
  56092. const bool triggerMenuItemAutomaticallyWhenClicked)
  56093. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  56094. width (w),
  56095. height (h)
  56096. {
  56097. addAndMakeVisible (comp);
  56098. }
  56099. ~NormalComponentWrapper() {}
  56100. void getIdealSize (int& idealWidth, int& idealHeight)
  56101. {
  56102. idealWidth = width;
  56103. idealHeight = height;
  56104. }
  56105. void resized()
  56106. {
  56107. if (getChildComponent(0) != 0)
  56108. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  56109. }
  56110. juce_UseDebuggingNewOperator
  56111. private:
  56112. const int width, height;
  56113. NormalComponentWrapper (const NormalComponentWrapper&);
  56114. const NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  56115. };
  56116. void PopupMenu::addCustomItem (const int itemResultId,
  56117. Component* customComponent,
  56118. int idealWidth, int idealHeight,
  56119. const bool triggerMenuItemAutomaticallyWhenClicked)
  56120. {
  56121. addCustomItem (itemResultId,
  56122. new NormalComponentWrapper (customComponent,
  56123. idealWidth, idealHeight,
  56124. triggerMenuItemAutomaticallyWhenClicked));
  56125. }
  56126. void PopupMenu::addSubMenu (const String& subMenuName,
  56127. const PopupMenu& subMenu,
  56128. const bool isActive,
  56129. Image* const iconToUse,
  56130. const bool isTicked)
  56131. {
  56132. addSeparatorIfPending();
  56133. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  56134. iconToUse, Colours::black, false, 0, &subMenu, 0));
  56135. }
  56136. void PopupMenu::addSeparator()
  56137. {
  56138. separatorPending = true;
  56139. }
  56140. class HeaderItemComponent : public PopupMenuCustomComponent
  56141. {
  56142. public:
  56143. HeaderItemComponent (const String& name)
  56144. : PopupMenuCustomComponent (false)
  56145. {
  56146. setName (name);
  56147. }
  56148. ~HeaderItemComponent()
  56149. {
  56150. }
  56151. void paint (Graphics& g)
  56152. {
  56153. Font f (getLookAndFeel().getPopupMenuFont());
  56154. f.setBold (true);
  56155. g.setFont (f);
  56156. g.setColour (findColour (PopupMenu::headerTextColourId));
  56157. g.drawFittedText (getName(),
  56158. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  56159. Justification::bottomLeft, 1);
  56160. }
  56161. void getIdealSize (int& idealWidth,
  56162. int& idealHeight)
  56163. {
  56164. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  56165. idealHeight += idealHeight / 2;
  56166. idealWidth += idealWidth / 4;
  56167. }
  56168. juce_UseDebuggingNewOperator
  56169. };
  56170. void PopupMenu::addSectionHeader (const String& title)
  56171. {
  56172. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  56173. }
  56174. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  56175. const int itemIdThatMustBeVisible,
  56176. const int minimumWidth,
  56177. const int maximumNumColumns,
  56178. const int standardItemHeight,
  56179. const bool alignToRectangle,
  56180. Component* menuBarComponent,
  56181. ApplicationCommandManager** managerOfChosenCommand,
  56182. Component* const componentAttachedTo)
  56183. {
  56184. Window* const pw
  56185. = Window::create (*this,
  56186. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  56187. 0,
  56188. x, x + w,
  56189. y, y + h,
  56190. minimumWidth,
  56191. maximumNumColumns,
  56192. standardItemHeight,
  56193. alignToRectangle,
  56194. itemIdThatMustBeVisible,
  56195. menuBarComponent,
  56196. managerOfChosenCommand,
  56197. componentAttachedTo);
  56198. if (pw != 0)
  56199. pw->setVisible (true);
  56200. return pw;
  56201. }
  56202. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  56203. const int itemIdThatMustBeVisible,
  56204. const int minimumWidth,
  56205. const int maximumNumColumns,
  56206. const int standardItemHeight,
  56207. const bool alignToRectangle,
  56208. Component* const componentAttachedTo)
  56209. {
  56210. Component* const prevFocused = Component::getCurrentlyFocusedComponent();
  56211. ScopedPointer <ComponentDeletionWatcher> deletionChecker[2];
  56212. if (prevFocused != 0)
  56213. deletionChecker[0] = new ComponentDeletionWatcher (prevFocused);
  56214. Component* const prevTopLevel = (prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0;
  56215. if (prevTopLevel != 0)
  56216. deletionChecker[1] = new ComponentDeletionWatcher (prevTopLevel);
  56217. Window::wasHiddenBecauseOfAppChange() = false;
  56218. int result = 0;
  56219. ApplicationCommandManager* managerOfChosenCommand = 0;
  56220. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  56221. itemIdThatMustBeVisible,
  56222. minimumWidth,
  56223. maximumNumColumns > 0 ? maximumNumColumns : 7,
  56224. standardItemHeight,
  56225. alignToRectangle, 0,
  56226. &managerOfChosenCommand,
  56227. componentAttachedTo));
  56228. if (popupComp != 0)
  56229. {
  56230. popupComp->enterModalState (false);
  56231. popupComp->toFront (false); // need to do this after making it modal, or it could
  56232. // be stuck behind other comps that are already modal..
  56233. result = popupComp->runModalLoop();
  56234. popupComp = 0;
  56235. if (! Window::wasHiddenBecauseOfAppChange())
  56236. {
  56237. if (deletionChecker[1] != 0 && ! deletionChecker[1]->hasBeenDeleted())
  56238. prevTopLevel->toFront (true);
  56239. if (deletionChecker[0] != 0 && ! deletionChecker[0]->hasBeenDeleted())
  56240. prevFocused->grabKeyboardFocus();
  56241. }
  56242. }
  56243. if (managerOfChosenCommand != 0 && result != 0)
  56244. {
  56245. ApplicationCommandTarget::InvocationInfo info (result);
  56246. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  56247. managerOfChosenCommand->invoke (info, true);
  56248. }
  56249. return result;
  56250. }
  56251. int PopupMenu::show (const int itemIdThatMustBeVisible,
  56252. const int minimumWidth,
  56253. const int maximumNumColumns,
  56254. const int standardItemHeight)
  56255. {
  56256. int x, y;
  56257. Desktop::getMousePosition (x, y);
  56258. return showAt (x, y,
  56259. itemIdThatMustBeVisible,
  56260. minimumWidth,
  56261. maximumNumColumns,
  56262. standardItemHeight);
  56263. }
  56264. int PopupMenu::showAt (const int screenX,
  56265. const int screenY,
  56266. const int itemIdThatMustBeVisible,
  56267. const int minimumWidth,
  56268. const int maximumNumColumns,
  56269. const int standardItemHeight)
  56270. {
  56271. return showMenu (screenX, screenY, 1, 1,
  56272. itemIdThatMustBeVisible,
  56273. minimumWidth, maximumNumColumns,
  56274. standardItemHeight,
  56275. false, 0);
  56276. }
  56277. int PopupMenu::showAt (Component* componentToAttachTo,
  56278. const int itemIdThatMustBeVisible,
  56279. const int minimumWidth,
  56280. const int maximumNumColumns,
  56281. const int standardItemHeight)
  56282. {
  56283. if (componentToAttachTo != 0)
  56284. {
  56285. return showMenu (componentToAttachTo->getScreenX(),
  56286. componentToAttachTo->getScreenY(),
  56287. componentToAttachTo->getWidth(),
  56288. componentToAttachTo->getHeight(),
  56289. itemIdThatMustBeVisible,
  56290. minimumWidth,
  56291. maximumNumColumns,
  56292. standardItemHeight,
  56293. true, componentToAttachTo);
  56294. }
  56295. else
  56296. {
  56297. return show (itemIdThatMustBeVisible,
  56298. minimumWidth,
  56299. maximumNumColumns,
  56300. standardItemHeight);
  56301. }
  56302. }
  56303. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  56304. {
  56305. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  56306. {
  56307. Window* const pmw = Window::getActiveWindows()[i];
  56308. if (pmw != 0)
  56309. pmw->dismissMenu (0);
  56310. }
  56311. }
  56312. int PopupMenu::getNumItems() const throw()
  56313. {
  56314. int num = 0;
  56315. for (int i = items.size(); --i >= 0;)
  56316. if (! (items.getUnchecked(i))->isSeparator)
  56317. ++num;
  56318. return num;
  56319. }
  56320. bool PopupMenu::containsCommandItem (const int commandID) const
  56321. {
  56322. for (int i = items.size(); --i >= 0;)
  56323. {
  56324. const Item* mi = items.getUnchecked (i);
  56325. if ((mi->itemId == commandID && mi->commandManager != 0)
  56326. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  56327. {
  56328. return true;
  56329. }
  56330. }
  56331. return false;
  56332. }
  56333. bool PopupMenu::containsAnyActiveItems() const throw()
  56334. {
  56335. for (int i = items.size(); --i >= 0;)
  56336. {
  56337. const Item* const mi = items.getUnchecked (i);
  56338. if (mi->subMenu != 0)
  56339. {
  56340. if (mi->subMenu->containsAnyActiveItems())
  56341. return true;
  56342. }
  56343. else if (mi->active)
  56344. {
  56345. return true;
  56346. }
  56347. }
  56348. return false;
  56349. }
  56350. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  56351. {
  56352. lookAndFeel = newLookAndFeel;
  56353. }
  56354. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  56355. : isHighlighted (false),
  56356. isTriggeredAutomatically (isTriggeredAutomatically_)
  56357. {
  56358. }
  56359. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  56360. {
  56361. }
  56362. void PopupMenuCustomComponent::triggerMenuItem()
  56363. {
  56364. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  56365. if (mic != 0)
  56366. {
  56367. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  56368. if (pmw != 0)
  56369. {
  56370. pmw->dismissMenu (&mic->itemInfo);
  56371. }
  56372. else
  56373. {
  56374. // something must have gone wrong with the component hierarchy if this happens..
  56375. jassertfalse
  56376. }
  56377. }
  56378. else
  56379. {
  56380. // why isn't this component inside a menu? Not much point triggering the item if
  56381. // there's no menu.
  56382. jassertfalse
  56383. }
  56384. }
  56385. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  56386. : subMenu (0),
  56387. itemId (0),
  56388. isSeparator (false),
  56389. isTicked (false),
  56390. isEnabled (false),
  56391. isCustomComponent (false),
  56392. isSectionHeader (false),
  56393. customColour (0),
  56394. customImage (0),
  56395. menu (menu_),
  56396. index (0)
  56397. {
  56398. }
  56399. PopupMenu::MenuItemIterator::~MenuItemIterator()
  56400. {
  56401. }
  56402. bool PopupMenu::MenuItemIterator::next()
  56403. {
  56404. if (index >= menu.items.size())
  56405. return false;
  56406. const Item* const item = menu.items.getUnchecked (index);
  56407. ++index;
  56408. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  56409. subMenu = item->subMenu;
  56410. itemId = item->itemId;
  56411. isSeparator = item->isSeparator;
  56412. isTicked = item->isTicked;
  56413. isEnabled = item->active;
  56414. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  56415. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  56416. customColour = item->usesColour ? &(item->textColour) : 0;
  56417. customImage = item->image;
  56418. commandManager = item->commandManager;
  56419. return true;
  56420. }
  56421. END_JUCE_NAMESPACE
  56422. /*** End of inlined file: juce_PopupMenu.cpp ***/
  56423. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  56424. BEGIN_JUCE_NAMESPACE
  56425. ComponentDragger::ComponentDragger()
  56426. : constrainer (0),
  56427. originalX (0),
  56428. originalY (0)
  56429. {
  56430. }
  56431. ComponentDragger::~ComponentDragger()
  56432. {
  56433. }
  56434. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  56435. ComponentBoundsConstrainer* const constrainer_)
  56436. {
  56437. jassert (componentToDrag->isValidComponent());
  56438. if (componentToDrag->isValidComponent())
  56439. {
  56440. constrainer = constrainer_;
  56441. originalX = 0;
  56442. originalY = 0;
  56443. componentToDrag->relativePositionToGlobal (originalX, originalY);
  56444. }
  56445. }
  56446. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  56447. {
  56448. jassert (componentToDrag->isValidComponent());
  56449. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  56450. if (componentToDrag->isValidComponent())
  56451. {
  56452. int x = originalX;
  56453. int y = originalY;
  56454. int w = componentToDrag->getWidth();
  56455. int h = componentToDrag->getHeight();
  56456. const Component* const parentComp = componentToDrag->getParentComponent();
  56457. if (parentComp != 0)
  56458. parentComp->globalPositionToRelative (x, y);
  56459. x += e.getDistanceFromDragStartX();
  56460. y += e.getDistanceFromDragStartY();
  56461. if (constrainer != 0)
  56462. constrainer->setBoundsForComponent (componentToDrag, Rectangle<int> (x, y, w, h),
  56463. false, false, false, false);
  56464. else
  56465. componentToDrag->setBounds (x, y, w, h);
  56466. }
  56467. }
  56468. END_JUCE_NAMESPACE
  56469. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  56470. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  56471. BEGIN_JUCE_NAMESPACE
  56472. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  56473. bool juce_performDragDropText (const String& text, bool& shouldStop);
  56474. class DragImageComponent : public Component,
  56475. public Timer
  56476. {
  56477. private:
  56478. ScopedPointer <Image> image;
  56479. Component* const source;
  56480. DragAndDropContainer* const owner;
  56481. ScopedPointer <ComponentDeletionWatcher> sourceWatcher, mouseDragSourceWatcher, currentlyOverWatcher;
  56482. Component* mouseDragSource;
  56483. DragAndDropTarget* currentlyOver;
  56484. String dragDesc;
  56485. const int imageX, imageY;
  56486. bool hasCheckedForExternalDrag, drawImage;
  56487. DragImageComponent (const DragImageComponent&);
  56488. const DragImageComponent& operator= (const DragImageComponent&);
  56489. public:
  56490. DragImageComponent (Image* const im,
  56491. const String& desc,
  56492. Component* const s,
  56493. DragAndDropContainer* const o,
  56494. const int imageX_, const int imageY_)
  56495. : image (im),
  56496. source (s),
  56497. owner (o),
  56498. currentlyOver (0),
  56499. dragDesc (desc),
  56500. imageX (imageX_),
  56501. imageY (imageY_),
  56502. hasCheckedForExternalDrag (false),
  56503. drawImage (true)
  56504. {
  56505. setSize (im->getWidth(), im->getHeight());
  56506. sourceWatcher = new ComponentDeletionWatcher (source);
  56507. mouseDragSource = Component::getComponentUnderMouse();
  56508. if (mouseDragSource == 0)
  56509. mouseDragSource = source;
  56510. mouseDragSourceWatcher = new ComponentDeletionWatcher (mouseDragSource);
  56511. mouseDragSource->addMouseListener (this, false);
  56512. startTimer (200);
  56513. setInterceptsMouseClicks (false, false);
  56514. setAlwaysOnTop (true);
  56515. }
  56516. ~DragImageComponent()
  56517. {
  56518. if ((DragImageComponent*) owner->dragImageComponent == this)
  56519. owner->dragImageComponent.release();
  56520. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56521. {
  56522. mouseDragSource->removeMouseListener (this);
  56523. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56524. if (currentlyOver->isInterestedInDragSource (dragDesc, source))
  56525. currentlyOver->itemDragExit (dragDesc, source);
  56526. }
  56527. }
  56528. void paint (Graphics& g)
  56529. {
  56530. if (isOpaque())
  56531. g.fillAll (Colours::white);
  56532. if (drawImage)
  56533. {
  56534. g.setOpacity (1.0f);
  56535. g.drawImageAt (image, 0, 0);
  56536. }
  56537. }
  56538. DragAndDropTarget* findTarget (const int screenX, const int screenY,
  56539. int& relX, int& relY) const
  56540. {
  56541. Component* hit = getParentComponent();
  56542. if (hit == 0)
  56543. {
  56544. hit = Desktop::getInstance().findComponentAt (screenX, screenY);
  56545. }
  56546. else
  56547. {
  56548. int rx = screenX, ry = screenY;
  56549. hit->globalPositionToRelative (rx, ry);
  56550. hit = hit->getComponentAt (rx, ry);
  56551. }
  56552. // (note: use a local copy of the dragDesc member in case the callback runs
  56553. // a modal loop and deletes this object before the method completes)
  56554. const String dragDescLocal (dragDesc);
  56555. while (hit != 0)
  56556. {
  56557. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  56558. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  56559. {
  56560. relX = screenX;
  56561. relY = screenY;
  56562. hit->globalPositionToRelative (relX, relY);
  56563. return ddt;
  56564. }
  56565. hit = hit->getParentComponent();
  56566. }
  56567. return 0;
  56568. }
  56569. void mouseUp (const MouseEvent& e)
  56570. {
  56571. if (e.originalComponent != this)
  56572. {
  56573. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56574. mouseDragSource->removeMouseListener (this);
  56575. bool dropAccepted = false;
  56576. DragAndDropTarget* ddt = 0;
  56577. int relX = 0, relY = 0;
  56578. if (isVisible())
  56579. {
  56580. setVisible (false);
  56581. ddt = findTarget (e.getScreenX(),
  56582. e.getScreenY(),
  56583. relX, relY);
  56584. // fade this component and remove it - it'll be deleted later by the timer callback
  56585. dropAccepted = ddt != 0;
  56586. setVisible (true);
  56587. if (dropAccepted || sourceWatcher->hasBeenDeleted())
  56588. {
  56589. fadeOutComponent (120);
  56590. }
  56591. else
  56592. {
  56593. int targetX = source->getWidth() / 2;
  56594. int targetY = source->getHeight() / 2;
  56595. source->relativePositionToGlobal (targetX, targetY);
  56596. int ourCentreX = getWidth() / 2;
  56597. int ourCentreY = getHeight() / 2;
  56598. relativePositionToGlobal (ourCentreX, ourCentreY);
  56599. fadeOutComponent (120,
  56600. targetX - ourCentreX,
  56601. targetY - ourCentreY);
  56602. }
  56603. }
  56604. if (getParentComponent() != 0)
  56605. getParentComponent()->removeChildComponent (this);
  56606. if (dropAccepted && ddt != 0)
  56607. {
  56608. // (note: use a local copy of the dragDesc member in case the callback runs
  56609. // a modal loop and deletes this object before the method completes)
  56610. const String dragDescLocal (dragDesc);
  56611. currentlyOverWatcher = 0;
  56612. currentlyOver = 0;
  56613. ddt->itemDropped (dragDescLocal, source, relX, relY);
  56614. }
  56615. // careful - this object could now be deleted..
  56616. }
  56617. }
  56618. void updateLocation (const bool canDoExternalDrag, int x, int y)
  56619. {
  56620. // (note: use a local copy of the dragDesc member in case the callback runs
  56621. // a modal loop and deletes this object before it returns)
  56622. const String dragDescLocal (dragDesc);
  56623. int newX = x + imageX;
  56624. int newY = y + imageY;
  56625. if (getParentComponent() != 0)
  56626. getParentComponent()->globalPositionToRelative (newX, newY);
  56627. //if (newX != getX() || newY != getY())
  56628. {
  56629. setTopLeftPosition (newX, newY);
  56630. int relX = 0, relY = 0;
  56631. DragAndDropTarget* const ddt = findTarget (x, y, relX, relY);
  56632. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  56633. if (ddt != currentlyOver)
  56634. {
  56635. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56636. {
  56637. Component* const over = dynamic_cast <Component*> (currentlyOver);
  56638. if (over != 0
  56639. && over->isValidComponent()
  56640. && ! (sourceWatcher->hasBeenDeleted())
  56641. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56642. {
  56643. currentlyOver->itemDragExit (dragDescLocal, source);
  56644. }
  56645. }
  56646. currentlyOver = ddt;
  56647. currentlyOverWatcher = 0;
  56648. if (ddt != 0)
  56649. {
  56650. currentlyOverWatcher = new ComponentDeletionWatcher (dynamic_cast <Component*> (ddt));
  56651. if (currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56652. currentlyOver->itemDragEnter (dragDescLocal, source, relX, relY);
  56653. }
  56654. }
  56655. else if (currentlyOverWatcher != 0 && currentlyOverWatcher->hasBeenDeleted())
  56656. {
  56657. currentlyOver = 0;
  56658. currentlyOverWatcher = 0;
  56659. }
  56660. if (currentlyOver != 0
  56661. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56662. currentlyOver->itemDragMove (dragDescLocal, source, relX, relY);
  56663. if (currentlyOver == 0
  56664. && canDoExternalDrag
  56665. && ! hasCheckedForExternalDrag)
  56666. {
  56667. if (Desktop::getInstance().findComponentAt (x, y) == 0)
  56668. {
  56669. hasCheckedForExternalDrag = true;
  56670. StringArray files;
  56671. bool canMoveFiles = false;
  56672. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  56673. && files.size() > 0)
  56674. {
  56675. ComponentDeletionWatcher cdw (this);
  56676. setVisible (false);
  56677. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  56678. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  56679. if (! cdw.hasBeenDeleted())
  56680. delete this;
  56681. return;
  56682. }
  56683. }
  56684. }
  56685. }
  56686. }
  56687. void mouseDrag (const MouseEvent& e)
  56688. {
  56689. if (e.originalComponent != this)
  56690. updateLocation (true, e.getScreenX(), e.getScreenY());
  56691. }
  56692. void timerCallback()
  56693. {
  56694. if (sourceWatcher->hasBeenDeleted())
  56695. {
  56696. delete this;
  56697. }
  56698. else if (! isMouseButtonDownAnywhere())
  56699. {
  56700. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56701. mouseDragSource->removeMouseListener (this);
  56702. delete this;
  56703. }
  56704. }
  56705. };
  56706. DragAndDropContainer::DragAndDropContainer()
  56707. {
  56708. }
  56709. DragAndDropContainer::~DragAndDropContainer()
  56710. {
  56711. dragImageComponent = 0;
  56712. }
  56713. void DragAndDropContainer::startDragging (const String& sourceDescription,
  56714. Component* sourceComponent,
  56715. Image* dragImage_,
  56716. const bool allowDraggingToExternalWindows,
  56717. const Point<int>* imageOffsetFromMouse)
  56718. {
  56719. ScopedPointer <Image> dragImage (dragImage_);
  56720. if (dragImageComponent == 0)
  56721. {
  56722. Component* const thisComp = dynamic_cast <Component*> (this);
  56723. if (thisComp != 0)
  56724. {
  56725. int mx, my;
  56726. Desktop::getLastMouseDownPosition (mx, my);
  56727. int imageX = 0, imageY = 0;
  56728. if (dragImage == 0)
  56729. {
  56730. dragImage = sourceComponent->createComponentSnapshot (Rectangle<int> (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
  56731. if (dragImage->getFormat() != Image::ARGB)
  56732. {
  56733. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  56734. Graphics g2 (*newIm);
  56735. g2.drawImageAt (dragImage, 0, 0);
  56736. dragImage = newIm;
  56737. }
  56738. dragImage->multiplyAllAlphas (0.6f);
  56739. const int lo = 150;
  56740. const int hi = 400;
  56741. int rx = mx, ry = my;
  56742. sourceComponent->globalPositionToRelative (rx, ry);
  56743. const int cx = jlimit (0, dragImage->getWidth(), rx);
  56744. const int cy = jlimit (0, dragImage->getHeight(), ry);
  56745. for (int y = dragImage->getHeight(); --y >= 0;)
  56746. {
  56747. const double dy = (y - cy) * (y - cy);
  56748. for (int x = dragImage->getWidth(); --x >= 0;)
  56749. {
  56750. const int dx = x - cx;
  56751. const int distance = roundToInt (sqrt (dx * dx + dy));
  56752. if (distance > lo)
  56753. {
  56754. const float alpha = (distance > hi) ? 0
  56755. : (hi - distance) / (float) (hi - lo)
  56756. + Random::getSystemRandom().nextFloat() * 0.008f;
  56757. dragImage->multiplyAlphaAt (x, y, alpha);
  56758. }
  56759. }
  56760. }
  56761. imageX = -cx;
  56762. imageY = -cy;
  56763. }
  56764. else
  56765. {
  56766. if (imageOffsetFromMouse == 0)
  56767. {
  56768. imageX = dragImage->getWidth() / -2;
  56769. imageY = dragImage->getHeight() / -2;
  56770. }
  56771. else
  56772. {
  56773. imageX = imageOffsetFromMouse->getX();
  56774. imageY = imageOffsetFromMouse->getY();
  56775. }
  56776. }
  56777. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  56778. this, imageX, imageY);
  56779. currentDragDesc = sourceDescription;
  56780. if (allowDraggingToExternalWindows)
  56781. {
  56782. if (! Desktop::canUseSemiTransparentWindows())
  56783. dragImageComponent->setOpaque (true);
  56784. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  56785. | ComponentPeer::windowIsTemporary
  56786. | ComponentPeer::windowIgnoresKeyPresses);
  56787. }
  56788. else
  56789. thisComp->addChildComponent (dragImageComponent);
  56790. ((DragImageComponent*) dragImageComponent)->updateLocation (false, mx, my);
  56791. dragImageComponent->setVisible (true);
  56792. }
  56793. else
  56794. {
  56795. // this class must only be implemented by an object that
  56796. // is also a Component.
  56797. jassertfalse
  56798. }
  56799. }
  56800. }
  56801. bool DragAndDropContainer::isDragAndDropActive() const
  56802. {
  56803. return dragImageComponent != 0;
  56804. }
  56805. const String DragAndDropContainer::getCurrentDragDescription() const
  56806. {
  56807. return (dragImageComponent != 0) ? currentDragDesc
  56808. : String::empty;
  56809. }
  56810. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56811. {
  56812. if (c == 0)
  56813. return 0;
  56814. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56815. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56816. }
  56817. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56818. {
  56819. return false;
  56820. }
  56821. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56822. {
  56823. }
  56824. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56825. {
  56826. }
  56827. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56828. {
  56829. }
  56830. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56831. {
  56832. return true;
  56833. }
  56834. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56835. {
  56836. }
  56837. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56838. {
  56839. }
  56840. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56841. {
  56842. }
  56843. END_JUCE_NAMESPACE
  56844. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56845. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56846. BEGIN_JUCE_NAMESPACE
  56847. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56848. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56849. // isStandard set depending on which interface was used to create the cursor
  56850. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56851. static CriticalSection activeCursorListLock;
  56852. static VoidArray activeCursors;
  56853. class SharedMouseCursorInternal : public ReferenceCountedObject
  56854. {
  56855. public:
  56856. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56857. : standardType (type),
  56858. isStandard (true)
  56859. {
  56860. handle = juce_createStandardMouseCursor (standardType);
  56861. activeCursors.add (this);
  56862. }
  56863. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56864. : standardType (MouseCursor::NormalCursor),
  56865. isStandard (false)
  56866. {
  56867. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56868. }
  56869. ~SharedMouseCursorInternal() throw()
  56870. {
  56871. juce_deleteMouseCursor (handle, isStandard);
  56872. activeCursors.removeValue (this);
  56873. }
  56874. void* getHandle() const throw()
  56875. {
  56876. return handle;
  56877. }
  56878. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56879. {
  56880. for (int i = activeCursors.size(); --i >= 0;)
  56881. {
  56882. SharedMouseCursorInternal* const r = (SharedMouseCursorInternal*) activeCursors.getUnchecked(i);
  56883. if (r->standardType == type)
  56884. return r;
  56885. }
  56886. return new SharedMouseCursorInternal (type);
  56887. }
  56888. juce_UseDebuggingNewOperator
  56889. private:
  56890. void* handle;
  56891. const MouseCursor::StandardCursorType standardType;
  56892. const bool isStandard;
  56893. const SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56894. };
  56895. MouseCursor::MouseCursor() throw()
  56896. {
  56897. const ScopedLock sl (activeCursorListLock);
  56898. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56899. }
  56900. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56901. {
  56902. const ScopedLock sl (activeCursorListLock);
  56903. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56904. }
  56905. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56906. {
  56907. const ScopedLock sl (activeCursorListLock);
  56908. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56909. }
  56910. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56911. : cursorHandle (other.cursorHandle)
  56912. {
  56913. }
  56914. MouseCursor::~MouseCursor() throw()
  56915. {
  56916. }
  56917. const MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56918. {
  56919. cursorHandle = other.cursorHandle;
  56920. return *this;
  56921. }
  56922. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56923. {
  56924. return cursorHandle == other.cursorHandle;
  56925. }
  56926. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56927. {
  56928. return cursorHandle != other.cursorHandle;
  56929. }
  56930. void* MouseCursor::getHandle() const throw()
  56931. {
  56932. return cursorHandle->getHandle();
  56933. }
  56934. void MouseCursor::showWaitCursor() throw()
  56935. {
  56936. const MouseCursor mc (MouseCursor::WaitCursor);
  56937. mc.showInAllWindows();
  56938. }
  56939. void MouseCursor::hideWaitCursor() throw()
  56940. {
  56941. Component* const c = Component::getComponentUnderMouse();
  56942. MouseCursor mc (c->isValidComponent() ? c->getLookAndFeel().getMouseCursorFor (*c)
  56943. : MouseCursor::NormalCursor);
  56944. mc.showInAllWindows();
  56945. }
  56946. END_JUCE_NAMESPACE
  56947. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56948. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56949. BEGIN_JUCE_NAMESPACE
  56950. MouseEvent::MouseEvent (const int x_,
  56951. const int y_,
  56952. const ModifierKeys& mods_,
  56953. Component* const originator,
  56954. const Time& eventTime_,
  56955. const int mouseDownX_,
  56956. const int mouseDownY_,
  56957. const Time& mouseDownTime_,
  56958. const int numberOfClicks_,
  56959. const bool mouseWasDragged) throw()
  56960. : x (x_),
  56961. y (y_),
  56962. mods (mods_),
  56963. eventComponent (originator),
  56964. originalComponent (originator),
  56965. eventTime (eventTime_),
  56966. mouseDownX (mouseDownX_),
  56967. mouseDownY (mouseDownY_),
  56968. mouseDownTime (mouseDownTime_),
  56969. numberOfClicks (numberOfClicks_),
  56970. wasMovedSinceMouseDown (mouseWasDragged)
  56971. {
  56972. }
  56973. MouseEvent::~MouseEvent() throw()
  56974. {
  56975. }
  56976. bool MouseEvent::mouseWasClicked() const throw()
  56977. {
  56978. return ! wasMovedSinceMouseDown;
  56979. }
  56980. int MouseEvent::getMouseDownX() const throw()
  56981. {
  56982. return mouseDownX;
  56983. }
  56984. int MouseEvent::getMouseDownY() const throw()
  56985. {
  56986. return mouseDownY;
  56987. }
  56988. int MouseEvent::getDistanceFromDragStartX() const throw()
  56989. {
  56990. return x - mouseDownX;
  56991. }
  56992. int MouseEvent::getDistanceFromDragStartY() const throw()
  56993. {
  56994. return y - mouseDownY;
  56995. }
  56996. int MouseEvent::getDistanceFromDragStart() const throw()
  56997. {
  56998. return roundToInt (juce_hypot (getDistanceFromDragStartX(),
  56999. getDistanceFromDragStartY()));
  57000. }
  57001. int MouseEvent::getLengthOfMousePress() const throw()
  57002. {
  57003. if (mouseDownTime.toMilliseconds() > 0)
  57004. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  57005. return 0;
  57006. }
  57007. int MouseEvent::getScreenX() const throw()
  57008. {
  57009. int sx = x, sy = y;
  57010. eventComponent->relativePositionToGlobal (sx, sy);
  57011. return sx;
  57012. }
  57013. int MouseEvent::getScreenY() const throw()
  57014. {
  57015. int sx = x, sy = y;
  57016. eventComponent->relativePositionToGlobal (sx, sy);
  57017. return sy;
  57018. }
  57019. int MouseEvent::getMouseDownScreenX() const throw()
  57020. {
  57021. int sx = mouseDownX, sy = mouseDownY;
  57022. eventComponent->relativePositionToGlobal (sx, sy);
  57023. return sx;
  57024. }
  57025. int MouseEvent::getMouseDownScreenY() const throw()
  57026. {
  57027. int sx = mouseDownX, sy = mouseDownY;
  57028. eventComponent->relativePositionToGlobal (sx, sy);
  57029. return sy;
  57030. }
  57031. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  57032. {
  57033. if (otherComponent == 0)
  57034. {
  57035. jassertfalse
  57036. return *this;
  57037. }
  57038. MouseEvent me (*this);
  57039. eventComponent->relativePositionToOtherComponent (otherComponent, me.x, me.y);
  57040. eventComponent->relativePositionToOtherComponent (otherComponent, me.mouseDownX, me.mouseDownY);
  57041. me.eventComponent = otherComponent;
  57042. return me;
  57043. }
  57044. static int doubleClickTimeOutMs = 400;
  57045. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  57046. {
  57047. doubleClickTimeOutMs = newTime;
  57048. }
  57049. int MouseEvent::getDoubleClickTimeout() throw()
  57050. {
  57051. return doubleClickTimeOutMs;
  57052. }
  57053. END_JUCE_NAMESPACE
  57054. /*** End of inlined file: juce_MouseEvent.cpp ***/
  57055. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  57056. BEGIN_JUCE_NAMESPACE
  57057. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  57058. : source (0),
  57059. hoverTimeMillisecs (hoverTimeMillisecs_),
  57060. hasJustHovered (false)
  57061. {
  57062. internalTimer.owner = this;
  57063. }
  57064. MouseHoverDetector::~MouseHoverDetector()
  57065. {
  57066. setHoverComponent (0);
  57067. }
  57068. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  57069. {
  57070. hoverTimeMillisecs = newTimeInMillisecs;
  57071. }
  57072. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  57073. {
  57074. if (source != newSourceComponent)
  57075. {
  57076. internalTimer.stopTimer();
  57077. hasJustHovered = false;
  57078. if (source != 0)
  57079. {
  57080. // ! you need to delete the hover detector before deleting its component
  57081. jassert (source->isValidComponent());
  57082. source->removeMouseListener (&internalTimer);
  57083. }
  57084. source = newSourceComponent;
  57085. if (newSourceComponent != 0)
  57086. newSourceComponent->addMouseListener (&internalTimer, false);
  57087. }
  57088. }
  57089. void MouseHoverDetector::hoverTimerCallback()
  57090. {
  57091. internalTimer.stopTimer();
  57092. if (source != 0)
  57093. {
  57094. int mx, my;
  57095. source->getMouseXYRelative (mx, my);
  57096. if (source->reallyContains (mx, my, false))
  57097. {
  57098. hasJustHovered = true;
  57099. mouseHovered (mx, my);
  57100. }
  57101. }
  57102. }
  57103. void MouseHoverDetector::checkJustHoveredCallback()
  57104. {
  57105. if (hasJustHovered)
  57106. {
  57107. hasJustHovered = false;
  57108. mouseMovedAfterHover();
  57109. }
  57110. }
  57111. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  57112. {
  57113. owner->hoverTimerCallback();
  57114. }
  57115. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  57116. {
  57117. stopTimer();
  57118. owner->checkJustHoveredCallback();
  57119. }
  57120. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  57121. {
  57122. stopTimer();
  57123. owner->checkJustHoveredCallback();
  57124. }
  57125. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  57126. {
  57127. stopTimer();
  57128. owner->checkJustHoveredCallback();
  57129. }
  57130. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  57131. {
  57132. stopTimer();
  57133. owner->checkJustHoveredCallback();
  57134. }
  57135. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  57136. {
  57137. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  57138. {
  57139. lastX = e.x;
  57140. lastY = e.y;
  57141. if (owner->source != 0)
  57142. startTimer (owner->hoverTimeMillisecs);
  57143. owner->checkJustHoveredCallback();
  57144. }
  57145. }
  57146. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  57147. {
  57148. stopTimer();
  57149. owner->checkJustHoveredCallback();
  57150. }
  57151. END_JUCE_NAMESPACE
  57152. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  57153. /*** Start of inlined file: juce_MouseListener.cpp ***/
  57154. BEGIN_JUCE_NAMESPACE
  57155. void MouseListener::mouseEnter (const MouseEvent&)
  57156. {
  57157. }
  57158. void MouseListener::mouseExit (const MouseEvent&)
  57159. {
  57160. }
  57161. void MouseListener::mouseDown (const MouseEvent&)
  57162. {
  57163. }
  57164. void MouseListener::mouseUp (const MouseEvent&)
  57165. {
  57166. }
  57167. void MouseListener::mouseDrag (const MouseEvent&)
  57168. {
  57169. }
  57170. void MouseListener::mouseMove (const MouseEvent&)
  57171. {
  57172. }
  57173. void MouseListener::mouseDoubleClick (const MouseEvent&)
  57174. {
  57175. }
  57176. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  57177. {
  57178. }
  57179. END_JUCE_NAMESPACE
  57180. /*** End of inlined file: juce_MouseListener.cpp ***/
  57181. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  57182. BEGIN_JUCE_NAMESPACE
  57183. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  57184. const String& buttonTextWhenTrue,
  57185. const String& buttonTextWhenFalse)
  57186. : PropertyComponent (name),
  57187. onText (buttonTextWhenTrue),
  57188. offText (buttonTextWhenFalse)
  57189. {
  57190. createButton();
  57191. button->addButtonListener (this);
  57192. }
  57193. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  57194. const String& name,
  57195. const String& buttonText)
  57196. : PropertyComponent (name),
  57197. onText (buttonText),
  57198. offText (buttonText)
  57199. {
  57200. createButton();
  57201. button->setButtonText (buttonText);
  57202. button->getToggleStateValue().referTo (valueToControl);
  57203. button->setClickingTogglesState (true);
  57204. }
  57205. BooleanPropertyComponent::~BooleanPropertyComponent()
  57206. {
  57207. deleteAllChildren();
  57208. }
  57209. void BooleanPropertyComponent::createButton()
  57210. {
  57211. addAndMakeVisible (button = new ToggleButton (String::empty));
  57212. button->setClickingTogglesState (false);
  57213. }
  57214. void BooleanPropertyComponent::setState (const bool newState)
  57215. {
  57216. button->setToggleState (newState, true);
  57217. }
  57218. bool BooleanPropertyComponent::getState() const
  57219. {
  57220. return button->getToggleState();
  57221. }
  57222. void BooleanPropertyComponent::paint (Graphics& g)
  57223. {
  57224. PropertyComponent::paint (g);
  57225. const Rectangle<int> r (button->getBounds());
  57226. g.setColour (Colours::white);
  57227. g.fillRect (r);
  57228. g.setColour (findColour (ComboBox::outlineColourId));
  57229. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  57230. }
  57231. void BooleanPropertyComponent::refresh()
  57232. {
  57233. button->setToggleState (getState(), false);
  57234. button->setButtonText (button->getToggleState() ? onText : offText);
  57235. }
  57236. void BooleanPropertyComponent::buttonClicked (Button*)
  57237. {
  57238. setState (! getState());
  57239. }
  57240. END_JUCE_NAMESPACE
  57241. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  57242. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57243. BEGIN_JUCE_NAMESPACE
  57244. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  57245. const bool triggerOnMouseDown)
  57246. : PropertyComponent (name)
  57247. {
  57248. addAndMakeVisible (button = new TextButton (String::empty));
  57249. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  57250. button->addButtonListener (this);
  57251. }
  57252. ButtonPropertyComponent::~ButtonPropertyComponent()
  57253. {
  57254. deleteAllChildren();
  57255. }
  57256. void ButtonPropertyComponent::refresh()
  57257. {
  57258. button->setButtonText (getButtonText());
  57259. }
  57260. void ButtonPropertyComponent::buttonClicked (Button*)
  57261. {
  57262. buttonClicked();
  57263. }
  57264. END_JUCE_NAMESPACE
  57265. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57266. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57267. BEGIN_JUCE_NAMESPACE
  57268. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  57269. : PropertyComponent (name),
  57270. comboBox (0)
  57271. {
  57272. }
  57273. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  57274. const String& name,
  57275. const StringArray& choices_,
  57276. const Array <int>* choiceIDs)
  57277. : PropertyComponent (name),
  57278. choices (choices_),
  57279. comboBox (0)
  57280. {
  57281. createComboBox (choiceIDs);
  57282. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  57283. }
  57284. ChoicePropertyComponent::~ChoicePropertyComponent()
  57285. {
  57286. deleteAllChildren();
  57287. }
  57288. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  57289. {
  57290. // The array of IDs must contain the same number of values as the choices list!
  57291. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  57292. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  57293. for (int i = 0; i < choices.size(); ++i)
  57294. {
  57295. if (choices[i].isNotEmpty())
  57296. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  57297. : ((*choiceIDs)[i]));
  57298. else
  57299. comboBox->addSeparator();
  57300. }
  57301. comboBox->setEditableText (false);
  57302. }
  57303. void ChoicePropertyComponent::setIndex (const int newIndex)
  57304. {
  57305. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  57306. }
  57307. int ChoicePropertyComponent::getIndex() const
  57308. {
  57309. return comboBox->getSelectedItemIndex();
  57310. }
  57311. const StringArray& ChoicePropertyComponent::getChoices() const
  57312. {
  57313. return choices;
  57314. }
  57315. void ChoicePropertyComponent::refresh()
  57316. {
  57317. if (comboBox == 0)
  57318. {
  57319. createComboBox (0);
  57320. comboBox->addListener (this);
  57321. }
  57322. comboBox->setSelectedId (getIndex() + 1, true);
  57323. }
  57324. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  57325. {
  57326. const int newIndex = comboBox->getSelectedId() - 1;
  57327. if (newIndex != getIndex())
  57328. setIndex (newIndex);
  57329. }
  57330. END_JUCE_NAMESPACE
  57331. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57332. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  57333. BEGIN_JUCE_NAMESPACE
  57334. PropertyComponent::PropertyComponent (const String& name,
  57335. const int preferredHeight_)
  57336. : Component (name),
  57337. preferredHeight (preferredHeight_)
  57338. {
  57339. jassert (name.isNotEmpty());
  57340. }
  57341. PropertyComponent::~PropertyComponent()
  57342. {
  57343. }
  57344. void PropertyComponent::paint (Graphics& g)
  57345. {
  57346. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  57347. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  57348. }
  57349. void PropertyComponent::resized()
  57350. {
  57351. if (getNumChildComponents() > 0)
  57352. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  57353. }
  57354. void PropertyComponent::enablementChanged()
  57355. {
  57356. repaint();
  57357. }
  57358. END_JUCE_NAMESPACE
  57359. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  57360. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  57361. BEGIN_JUCE_NAMESPACE
  57362. class PropertyHolderComponent : public Component
  57363. {
  57364. public:
  57365. PropertyHolderComponent()
  57366. {
  57367. }
  57368. ~PropertyHolderComponent()
  57369. {
  57370. deleteAllChildren();
  57371. }
  57372. void paint (Graphics&)
  57373. {
  57374. }
  57375. void updateLayout (const int width);
  57376. void refreshAll() const;
  57377. };
  57378. class PropertySectionComponent : public Component
  57379. {
  57380. public:
  57381. PropertySectionComponent (const String& sectionTitle,
  57382. const Array <PropertyComponent*>& newProperties,
  57383. const bool open)
  57384. : Component (sectionTitle),
  57385. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  57386. isOpen_ (open)
  57387. {
  57388. for (int i = newProperties.size(); --i >= 0;)
  57389. {
  57390. addAndMakeVisible (newProperties.getUnchecked(i));
  57391. newProperties.getUnchecked(i)->refresh();
  57392. }
  57393. }
  57394. ~PropertySectionComponent()
  57395. {
  57396. deleteAllChildren();
  57397. }
  57398. void paint (Graphics& g)
  57399. {
  57400. if (titleHeight > 0)
  57401. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57402. }
  57403. void resized()
  57404. {
  57405. int y = titleHeight;
  57406. for (int i = getNumChildComponents(); --i >= 0;)
  57407. {
  57408. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57409. if (pec != 0)
  57410. {
  57411. const int prefH = pec->getPreferredHeight();
  57412. pec->setBounds (1, y, getWidth() - 2, prefH);
  57413. y += prefH;
  57414. }
  57415. }
  57416. }
  57417. int getPreferredHeight() const
  57418. {
  57419. int y = titleHeight;
  57420. if (isOpen())
  57421. {
  57422. for (int i = 0; i < getNumChildComponents(); ++i)
  57423. {
  57424. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57425. if (pec != 0)
  57426. y += pec->getPreferredHeight();
  57427. }
  57428. }
  57429. return y;
  57430. }
  57431. void setOpen (const bool open)
  57432. {
  57433. if (isOpen_ != open)
  57434. {
  57435. isOpen_ = open;
  57436. for (int i = 0; i < getNumChildComponents(); ++i)
  57437. {
  57438. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57439. if (pec != 0)
  57440. pec->setVisible (open);
  57441. }
  57442. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57443. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57444. if (pp != 0)
  57445. pp->resized();
  57446. }
  57447. }
  57448. bool isOpen() const
  57449. {
  57450. return isOpen_;
  57451. }
  57452. void refreshAll() const
  57453. {
  57454. for (int i = 0; i < getNumChildComponents(); ++i)
  57455. {
  57456. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57457. if (pec != 0)
  57458. pec->refresh();
  57459. }
  57460. }
  57461. void mouseDown (const MouseEvent&)
  57462. {
  57463. }
  57464. void mouseUp (const MouseEvent& e)
  57465. {
  57466. if (e.getMouseDownX() < titleHeight
  57467. && e.x < titleHeight
  57468. && e.y < titleHeight
  57469. && e.getNumberOfClicks() != 2)
  57470. {
  57471. setOpen (! isOpen());
  57472. }
  57473. }
  57474. void mouseDoubleClick (const MouseEvent& e)
  57475. {
  57476. if (e.y < titleHeight)
  57477. setOpen (! isOpen());
  57478. }
  57479. private:
  57480. int titleHeight;
  57481. bool isOpen_;
  57482. };
  57483. void PropertyHolderComponent::updateLayout (const int width)
  57484. {
  57485. int y = 0;
  57486. for (int i = getNumChildComponents(); --i >= 0;)
  57487. {
  57488. PropertySectionComponent* const section
  57489. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57490. if (section != 0)
  57491. {
  57492. const int prefH = section->getPreferredHeight();
  57493. section->setBounds (0, y, width, prefH);
  57494. y += prefH;
  57495. }
  57496. }
  57497. setSize (width, y);
  57498. repaint();
  57499. }
  57500. void PropertyHolderComponent::refreshAll() const
  57501. {
  57502. for (int i = getNumChildComponents(); --i >= 0;)
  57503. {
  57504. PropertySectionComponent* const section
  57505. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57506. if (section != 0)
  57507. section->refreshAll();
  57508. }
  57509. }
  57510. PropertyPanel::PropertyPanel()
  57511. {
  57512. messageWhenEmpty = TRANS("(nothing selected)");
  57513. addAndMakeVisible (viewport = new Viewport());
  57514. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57515. viewport->setFocusContainer (true);
  57516. }
  57517. PropertyPanel::~PropertyPanel()
  57518. {
  57519. clear();
  57520. deleteAllChildren();
  57521. }
  57522. void PropertyPanel::paint (Graphics& g)
  57523. {
  57524. if (propertyHolderComponent->getNumChildComponents() == 0)
  57525. {
  57526. g.setColour (Colours::black.withAlpha (0.5f));
  57527. g.setFont (14.0f);
  57528. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57529. Justification::centred, true);
  57530. }
  57531. }
  57532. void PropertyPanel::resized()
  57533. {
  57534. viewport->setBounds (0, 0, getWidth(), getHeight());
  57535. updatePropHolderLayout();
  57536. }
  57537. void PropertyPanel::clear()
  57538. {
  57539. if (propertyHolderComponent->getNumChildComponents() > 0)
  57540. {
  57541. propertyHolderComponent->deleteAllChildren();
  57542. repaint();
  57543. }
  57544. }
  57545. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57546. {
  57547. if (propertyHolderComponent->getNumChildComponents() == 0)
  57548. repaint();
  57549. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57550. newProperties,
  57551. true), 0);
  57552. updatePropHolderLayout();
  57553. }
  57554. void PropertyPanel::addSection (const String& sectionTitle,
  57555. const Array <PropertyComponent*>& newProperties,
  57556. const bool shouldBeOpen)
  57557. {
  57558. jassert (sectionTitle.isNotEmpty());
  57559. if (propertyHolderComponent->getNumChildComponents() == 0)
  57560. repaint();
  57561. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57562. newProperties,
  57563. shouldBeOpen), 0);
  57564. updatePropHolderLayout();
  57565. }
  57566. void PropertyPanel::updatePropHolderLayout() const
  57567. {
  57568. const int maxWidth = viewport->getMaximumVisibleWidth();
  57569. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (maxWidth);
  57570. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57571. if (maxWidth != newMaxWidth)
  57572. {
  57573. // need to do this twice because of scrollbars changing the size, etc.
  57574. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (newMaxWidth);
  57575. }
  57576. }
  57577. void PropertyPanel::refreshAll() const
  57578. {
  57579. ((PropertyHolderComponent*) propertyHolderComponent)->refreshAll();
  57580. }
  57581. const StringArray PropertyPanel::getSectionNames() const
  57582. {
  57583. StringArray s;
  57584. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57585. {
  57586. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57587. if (section != 0 && section->getName().isNotEmpty())
  57588. s.add (section->getName());
  57589. }
  57590. return s;
  57591. }
  57592. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57593. {
  57594. int index = 0;
  57595. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57596. {
  57597. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57598. if (section != 0 && section->getName().isNotEmpty())
  57599. {
  57600. if (index == sectionIndex)
  57601. return section->isOpen();
  57602. ++index;
  57603. }
  57604. }
  57605. return false;
  57606. }
  57607. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57608. {
  57609. int index = 0;
  57610. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57611. {
  57612. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57613. if (section != 0 && section->getName().isNotEmpty())
  57614. {
  57615. if (index == sectionIndex)
  57616. {
  57617. section->setOpen (shouldBeOpen);
  57618. break;
  57619. }
  57620. ++index;
  57621. }
  57622. }
  57623. }
  57624. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57625. {
  57626. int index = 0;
  57627. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57628. {
  57629. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57630. if (section != 0 && section->getName().isNotEmpty())
  57631. {
  57632. if (index == sectionIndex)
  57633. {
  57634. section->setEnabled (shouldBeEnabled);
  57635. break;
  57636. }
  57637. ++index;
  57638. }
  57639. }
  57640. }
  57641. XmlElement* PropertyPanel::getOpennessState() const
  57642. {
  57643. XmlElement* const xml = new XmlElement (T("PROPERTYPANELSTATE"));
  57644. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57645. const StringArray sections (getSectionNames());
  57646. for (int i = 0; i < sections.size(); ++i)
  57647. {
  57648. if (sections[i].isNotEmpty())
  57649. {
  57650. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57651. e->setAttribute ("name", sections[i]);
  57652. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57653. }
  57654. }
  57655. return xml;
  57656. }
  57657. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57658. {
  57659. if (xml.hasTagName (T("PROPERTYPANELSTATE")))
  57660. {
  57661. const StringArray sections (getSectionNames());
  57662. forEachXmlChildElementWithTagName (xml, e, T("SECTION"))
  57663. {
  57664. setSectionOpen (sections.indexOf (e->getStringAttribute (T("name"))),
  57665. e->getBoolAttribute (T("open")));
  57666. }
  57667. viewport->setViewPosition (viewport->getViewPositionX(),
  57668. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57669. }
  57670. }
  57671. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57672. {
  57673. if (messageWhenEmpty != newMessage)
  57674. {
  57675. messageWhenEmpty = newMessage;
  57676. repaint();
  57677. }
  57678. }
  57679. const String& PropertyPanel::getMessageWhenEmpty() const
  57680. {
  57681. return messageWhenEmpty;
  57682. }
  57683. END_JUCE_NAMESPACE
  57684. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57685. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57686. BEGIN_JUCE_NAMESPACE
  57687. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57688. const double rangeMin,
  57689. const double rangeMax,
  57690. const double interval,
  57691. const double skewFactor)
  57692. : PropertyComponent (name)
  57693. {
  57694. addAndMakeVisible (slider = new Slider (name));
  57695. slider->setRange (rangeMin, rangeMax, interval);
  57696. slider->setSkewFactor (skewFactor);
  57697. slider->setSliderStyle (Slider::LinearBar);
  57698. slider->addListener (this);
  57699. }
  57700. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57701. const String& name,
  57702. const double rangeMin,
  57703. const double rangeMax,
  57704. const double interval,
  57705. const double skewFactor)
  57706. : PropertyComponent (name)
  57707. {
  57708. addAndMakeVisible (slider = new Slider (name));
  57709. slider->setRange (rangeMin, rangeMax, interval);
  57710. slider->setSkewFactor (skewFactor);
  57711. slider->setSliderStyle (Slider::LinearBar);
  57712. slider->getValueObject().referTo (valueToControl);
  57713. }
  57714. SliderPropertyComponent::~SliderPropertyComponent()
  57715. {
  57716. deleteAllChildren();
  57717. }
  57718. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57719. {
  57720. }
  57721. const double SliderPropertyComponent::getValue() const
  57722. {
  57723. return slider->getValue();
  57724. }
  57725. void SliderPropertyComponent::refresh()
  57726. {
  57727. slider->setValue (getValue(), false);
  57728. }
  57729. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57730. {
  57731. if (getValue() != slider->getValue())
  57732. setValue (slider->getValue());
  57733. }
  57734. END_JUCE_NAMESPACE
  57735. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57736. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57737. BEGIN_JUCE_NAMESPACE
  57738. class TextPropLabel : public Label
  57739. {
  57740. TextPropertyComponent& owner;
  57741. int maxChars;
  57742. bool isMultiline;
  57743. public:
  57744. TextPropLabel (TextPropertyComponent& owner_,
  57745. const int maxChars_, const bool isMultiline_)
  57746. : Label (String::empty, String::empty),
  57747. owner (owner_),
  57748. maxChars (maxChars_),
  57749. isMultiline (isMultiline_)
  57750. {
  57751. setEditable (true, true, false);
  57752. setColour (backgroundColourId, Colours::white);
  57753. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57754. }
  57755. ~TextPropLabel()
  57756. {
  57757. }
  57758. TextEditor* createEditorComponent()
  57759. {
  57760. TextEditor* const textEditor = Label::createEditorComponent();
  57761. textEditor->setInputRestrictions (maxChars);
  57762. if (isMultiline)
  57763. {
  57764. textEditor->setMultiLine (true, true);
  57765. textEditor->setReturnKeyStartsNewLine (true);
  57766. }
  57767. return textEditor;
  57768. }
  57769. void textWasEdited()
  57770. {
  57771. owner.textWasEdited();
  57772. }
  57773. };
  57774. TextPropertyComponent::TextPropertyComponent (const String& name,
  57775. const int maxNumChars,
  57776. const bool isMultiLine)
  57777. : PropertyComponent (name)
  57778. {
  57779. createEditor (maxNumChars, isMultiLine);
  57780. }
  57781. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57782. const String& name,
  57783. const int maxNumChars,
  57784. const bool isMultiLine)
  57785. : PropertyComponent (name)
  57786. {
  57787. createEditor (maxNumChars, isMultiLine);
  57788. textEditor->getTextValue().referTo (valueToControl);
  57789. }
  57790. TextPropertyComponent::~TextPropertyComponent()
  57791. {
  57792. deleteAllChildren();
  57793. }
  57794. void TextPropertyComponent::setText (const String& newText)
  57795. {
  57796. textEditor->setText (newText, true);
  57797. }
  57798. const String TextPropertyComponent::getText() const
  57799. {
  57800. return textEditor->getText();
  57801. }
  57802. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57803. {
  57804. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57805. if (isMultiLine)
  57806. {
  57807. textEditor->setJustificationType (Justification::topLeft);
  57808. preferredHeight = 120;
  57809. }
  57810. }
  57811. void TextPropertyComponent::refresh()
  57812. {
  57813. textEditor->setText (getText(), false);
  57814. }
  57815. void TextPropertyComponent::textWasEdited()
  57816. {
  57817. const String newText (textEditor->getText());
  57818. if (getText() != newText)
  57819. setText (newText);
  57820. }
  57821. END_JUCE_NAMESPACE
  57822. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57823. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57824. BEGIN_JUCE_NAMESPACE
  57825. class SimpleDeviceManagerInputLevelMeter : public Component,
  57826. public Timer
  57827. {
  57828. public:
  57829. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57830. : manager (manager_),
  57831. level (0)
  57832. {
  57833. startTimer (50);
  57834. manager->enableInputLevelMeasurement (true);
  57835. }
  57836. ~SimpleDeviceManagerInputLevelMeter()
  57837. {
  57838. manager->enableInputLevelMeasurement (false);
  57839. }
  57840. void timerCallback()
  57841. {
  57842. const float newLevel = (float) manager->getCurrentInputLevel();
  57843. if (fabsf (level - newLevel) > 0.005f)
  57844. {
  57845. level = newLevel;
  57846. repaint();
  57847. }
  57848. }
  57849. void paint (Graphics& g)
  57850. {
  57851. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57852. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57853. }
  57854. private:
  57855. AudioDeviceManager* const manager;
  57856. float level;
  57857. };
  57858. class MidiInputSelectorComponentListBox : public ListBox,
  57859. public ListBoxModel
  57860. {
  57861. public:
  57862. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57863. const String& noItemsMessage_,
  57864. const int minNumber_,
  57865. const int maxNumber_)
  57866. : ListBox (String::empty, 0),
  57867. deviceManager (deviceManager_),
  57868. noItemsMessage (noItemsMessage_),
  57869. minNumber (minNumber_),
  57870. maxNumber (maxNumber_)
  57871. {
  57872. items = MidiInput::getDevices();
  57873. setModel (this);
  57874. setOutlineThickness (1);
  57875. }
  57876. ~MidiInputSelectorComponentListBox()
  57877. {
  57878. }
  57879. int getNumRows()
  57880. {
  57881. return items.size();
  57882. }
  57883. void paintListBoxItem (int row,
  57884. Graphics& g,
  57885. int width, int height,
  57886. bool rowIsSelected)
  57887. {
  57888. if (((unsigned int) row) < (unsigned int) items.size())
  57889. {
  57890. if (rowIsSelected)
  57891. g.fillAll (findColour (TextEditor::highlightColourId)
  57892. .withMultipliedAlpha (0.3f));
  57893. const String item (items [row]);
  57894. bool enabled = deviceManager.isMidiInputEnabled (item);
  57895. const int x = getTickX();
  57896. const float tickW = height * 0.75f;
  57897. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57898. enabled, true, true, false);
  57899. g.setFont (height * 0.6f);
  57900. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57901. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57902. }
  57903. }
  57904. void listBoxItemClicked (int row, const MouseEvent& e)
  57905. {
  57906. selectRow (row);
  57907. if (e.x < getTickX())
  57908. flipEnablement (row);
  57909. }
  57910. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57911. {
  57912. flipEnablement (row);
  57913. }
  57914. void returnKeyPressed (int row)
  57915. {
  57916. flipEnablement (row);
  57917. }
  57918. void paint (Graphics& g)
  57919. {
  57920. ListBox::paint (g);
  57921. if (items.size() == 0)
  57922. {
  57923. g.setColour (Colours::grey);
  57924. g.setFont (13.0f);
  57925. g.drawText (noItemsMessage,
  57926. 0, 0, getWidth(), getHeight() / 2,
  57927. Justification::centred, true);
  57928. }
  57929. }
  57930. int getBestHeight (const int preferredHeight)
  57931. {
  57932. const int extra = getOutlineThickness() * 2;
  57933. return jmax (getRowHeight() * 2 + extra,
  57934. jmin (getRowHeight() * getNumRows() + extra,
  57935. preferredHeight));
  57936. }
  57937. juce_UseDebuggingNewOperator
  57938. private:
  57939. AudioDeviceManager& deviceManager;
  57940. const String noItemsMessage;
  57941. StringArray items;
  57942. int minNumber, maxNumber;
  57943. void flipEnablement (const int row)
  57944. {
  57945. if (((unsigned int) row) < (unsigned int) items.size())
  57946. {
  57947. const String item (items [row]);
  57948. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57949. }
  57950. }
  57951. int getTickX() const
  57952. {
  57953. return getRowHeight() + 5;
  57954. }
  57955. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57956. const MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57957. };
  57958. class AudioDeviceSettingsPanel : public Component,
  57959. public ComboBoxListener,
  57960. public ChangeListener,
  57961. public ButtonListener
  57962. {
  57963. public:
  57964. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57965. AudioIODeviceType::DeviceSetupDetails& setup_,
  57966. const bool hideAdvancedOptionsWithButton)
  57967. : type (type_),
  57968. setup (setup_)
  57969. {
  57970. sampleRateDropDown = 0;
  57971. sampleRateLabel = 0;
  57972. bufferSizeDropDown = 0;
  57973. bufferSizeLabel = 0;
  57974. outputDeviceDropDown = 0;
  57975. outputDeviceLabel = 0;
  57976. inputDeviceDropDown = 0;
  57977. inputDeviceLabel = 0;
  57978. testButton = 0;
  57979. inputLevelMeter = 0;
  57980. showUIButton = 0;
  57981. inputChanList = 0;
  57982. outputChanList = 0;
  57983. inputChanLabel = 0;
  57984. outputChanLabel = 0;
  57985. showAdvancedSettingsButton = 0;
  57986. if (hideAdvancedOptionsWithButton)
  57987. {
  57988. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57989. showAdvancedSettingsButton->addButtonListener (this);
  57990. }
  57991. type->scanForDevices();
  57992. setup.manager->addChangeListener (this);
  57993. changeListenerCallback (0);
  57994. }
  57995. ~AudioDeviceSettingsPanel()
  57996. {
  57997. setup.manager->removeChangeListener (this);
  57998. deleteAndZero (outputDeviceLabel);
  57999. deleteAndZero (inputDeviceLabel);
  58000. deleteAndZero (sampleRateLabel);
  58001. deleteAndZero (bufferSizeLabel);
  58002. deleteAndZero (showUIButton);
  58003. deleteAndZero (inputChanLabel);
  58004. deleteAndZero (outputChanLabel);
  58005. deleteAndZero (showAdvancedSettingsButton);
  58006. deleteAllChildren();
  58007. }
  58008. void resized()
  58009. {
  58010. const int lx = proportionOfWidth (0.35f);
  58011. const int w = proportionOfWidth (0.4f);
  58012. const int h = 24;
  58013. const int space = 6;
  58014. const int dh = h + space;
  58015. int y = 0;
  58016. if (outputDeviceDropDown != 0)
  58017. {
  58018. outputDeviceDropDown->setBounds (lx, y, w, h);
  58019. if (testButton != 0)
  58020. testButton->setBounds (proportionOfWidth (0.77f),
  58021. outputDeviceDropDown->getY(),
  58022. proportionOfWidth (0.18f),
  58023. h);
  58024. y += dh;
  58025. }
  58026. if (inputDeviceDropDown != 0)
  58027. {
  58028. inputDeviceDropDown->setBounds (lx, y, w, h);
  58029. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  58030. inputDeviceDropDown->getY(),
  58031. proportionOfWidth (0.18f),
  58032. h);
  58033. y += dh;
  58034. }
  58035. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  58036. if (outputChanList != 0)
  58037. {
  58038. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  58039. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  58040. y += bh + space;
  58041. }
  58042. if (inputChanList != 0)
  58043. {
  58044. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  58045. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  58046. y += bh + space;
  58047. }
  58048. y += space * 2;
  58049. if (showAdvancedSettingsButton != 0)
  58050. {
  58051. showAdvancedSettingsButton->changeWidthToFitText (h);
  58052. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  58053. }
  58054. if (sampleRateDropDown != 0)
  58055. {
  58056. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  58057. || ! showAdvancedSettingsButton->isVisible());
  58058. sampleRateDropDown->setBounds (lx, y, w, h);
  58059. y += dh;
  58060. }
  58061. if (bufferSizeDropDown != 0)
  58062. {
  58063. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  58064. || ! showAdvancedSettingsButton->isVisible());
  58065. bufferSizeDropDown->setBounds (lx, y, w, h);
  58066. y += dh;
  58067. }
  58068. if (showUIButton != 0)
  58069. {
  58070. showUIButton->setVisible (showAdvancedSettingsButton == 0
  58071. || ! showAdvancedSettingsButton->isVisible());
  58072. showUIButton->changeWidthToFitText (h);
  58073. showUIButton->setTopLeftPosition (lx, y);
  58074. }
  58075. }
  58076. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58077. {
  58078. if (comboBoxThatHasChanged == 0)
  58079. return;
  58080. AudioDeviceManager::AudioDeviceSetup config;
  58081. setup.manager->getAudioDeviceSetup (config);
  58082. String error;
  58083. if (comboBoxThatHasChanged == outputDeviceDropDown
  58084. || comboBoxThatHasChanged == inputDeviceDropDown)
  58085. {
  58086. if (outputDeviceDropDown != 0)
  58087. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  58088. : outputDeviceDropDown->getText();
  58089. if (inputDeviceDropDown != 0)
  58090. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  58091. : inputDeviceDropDown->getText();
  58092. if (! type->hasSeparateInputsAndOutputs())
  58093. config.inputDeviceName = config.outputDeviceName;
  58094. if (comboBoxThatHasChanged == inputDeviceDropDown)
  58095. config.useDefaultInputChannels = true;
  58096. else
  58097. config.useDefaultOutputChannels = true;
  58098. error = setup.manager->setAudioDeviceSetup (config, true);
  58099. showCorrectDeviceName (inputDeviceDropDown, true);
  58100. showCorrectDeviceName (outputDeviceDropDown, false);
  58101. updateControlPanelButton();
  58102. resized();
  58103. }
  58104. else if (comboBoxThatHasChanged == sampleRateDropDown)
  58105. {
  58106. if (sampleRateDropDown->getSelectedId() > 0)
  58107. {
  58108. config.sampleRate = sampleRateDropDown->getSelectedId();
  58109. error = setup.manager->setAudioDeviceSetup (config, true);
  58110. }
  58111. }
  58112. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  58113. {
  58114. if (bufferSizeDropDown->getSelectedId() > 0)
  58115. {
  58116. config.bufferSize = bufferSizeDropDown->getSelectedId();
  58117. error = setup.manager->setAudioDeviceSetup (config, true);
  58118. }
  58119. }
  58120. if (error.isNotEmpty())
  58121. {
  58122. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  58123. T("Error when trying to open audio device!"),
  58124. error);
  58125. }
  58126. }
  58127. void buttonClicked (Button* button)
  58128. {
  58129. if (button == showAdvancedSettingsButton)
  58130. {
  58131. showAdvancedSettingsButton->setVisible (false);
  58132. resized();
  58133. }
  58134. else if (button == showUIButton)
  58135. {
  58136. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  58137. if (device != 0 && device->showControlPanel())
  58138. {
  58139. setup.manager->closeAudioDevice();
  58140. setup.manager->restartLastAudioDevice();
  58141. getTopLevelComponent()->toFront (true);
  58142. }
  58143. }
  58144. else if (button == testButton && testButton != 0)
  58145. {
  58146. setup.manager->playTestSound();
  58147. }
  58148. }
  58149. void updateControlPanelButton()
  58150. {
  58151. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58152. deleteAndZero (showUIButton);
  58153. if (currentDevice != 0 && currentDevice->hasControlPanel())
  58154. {
  58155. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  58156. TRANS ("opens the device's own control panel")));
  58157. showUIButton->addButtonListener (this);
  58158. }
  58159. resized();
  58160. }
  58161. void changeListenerCallback (void*)
  58162. {
  58163. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58164. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  58165. {
  58166. if (outputDeviceDropDown == 0)
  58167. {
  58168. outputDeviceDropDown = new ComboBox (String::empty);
  58169. outputDeviceDropDown->addListener (this);
  58170. addAndMakeVisible (outputDeviceDropDown);
  58171. outputDeviceLabel = new Label (String::empty,
  58172. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  58173. : TRANS ("device:"));
  58174. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  58175. if (setup.maxNumOutputChannels > 0)
  58176. {
  58177. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  58178. testButton->addButtonListener (this);
  58179. }
  58180. }
  58181. addNamesToDeviceBox (*outputDeviceDropDown, false);
  58182. }
  58183. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  58184. {
  58185. if (inputDeviceDropDown == 0)
  58186. {
  58187. inputDeviceDropDown = new ComboBox (String::empty);
  58188. inputDeviceDropDown->addListener (this);
  58189. addAndMakeVisible (inputDeviceDropDown);
  58190. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  58191. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  58192. addAndMakeVisible (inputLevelMeter
  58193. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  58194. }
  58195. addNamesToDeviceBox (*inputDeviceDropDown, true);
  58196. }
  58197. updateControlPanelButton();
  58198. showCorrectDeviceName (inputDeviceDropDown, true);
  58199. showCorrectDeviceName (outputDeviceDropDown, false);
  58200. if (currentDevice != 0)
  58201. {
  58202. if (setup.maxNumOutputChannels > 0
  58203. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  58204. {
  58205. if (outputChanList == 0)
  58206. {
  58207. addAndMakeVisible (outputChanList
  58208. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  58209. TRANS ("(no audio output channels found)")));
  58210. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  58211. outputChanLabel->attachToComponent (outputChanList, true);
  58212. }
  58213. outputChanList->refresh();
  58214. }
  58215. else
  58216. {
  58217. deleteAndZero (outputChanLabel);
  58218. deleteAndZero (outputChanList);
  58219. }
  58220. if (setup.maxNumInputChannels > 0
  58221. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  58222. {
  58223. if (inputChanList == 0)
  58224. {
  58225. addAndMakeVisible (inputChanList
  58226. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  58227. TRANS ("(no audio input channels found)")));
  58228. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  58229. inputChanLabel->attachToComponent (inputChanList, true);
  58230. }
  58231. inputChanList->refresh();
  58232. }
  58233. else
  58234. {
  58235. deleteAndZero (inputChanLabel);
  58236. deleteAndZero (inputChanList);
  58237. }
  58238. // sample rate..
  58239. {
  58240. if (sampleRateDropDown == 0)
  58241. {
  58242. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  58243. sampleRateDropDown->addListener (this);
  58244. delete sampleRateLabel;
  58245. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  58246. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  58247. }
  58248. else
  58249. {
  58250. sampleRateDropDown->clear();
  58251. sampleRateDropDown->removeListener (this);
  58252. }
  58253. const int numRates = currentDevice->getNumSampleRates();
  58254. for (int i = 0; i < numRates; ++i)
  58255. {
  58256. const int rate = roundToInt (currentDevice->getSampleRate (i));
  58257. sampleRateDropDown->addItem (String (rate) + T(" Hz"), rate);
  58258. }
  58259. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  58260. sampleRateDropDown->addListener (this);
  58261. }
  58262. // buffer size
  58263. {
  58264. if (bufferSizeDropDown == 0)
  58265. {
  58266. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  58267. bufferSizeDropDown->addListener (this);
  58268. delete bufferSizeLabel;
  58269. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  58270. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  58271. }
  58272. else
  58273. {
  58274. bufferSizeDropDown->clear();
  58275. }
  58276. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  58277. double currentRate = currentDevice->getCurrentSampleRate();
  58278. if (currentRate == 0)
  58279. currentRate = 48000.0;
  58280. for (int i = 0; i < numBufferSizes; ++i)
  58281. {
  58282. const int bs = currentDevice->getBufferSizeSamples (i);
  58283. bufferSizeDropDown->addItem (String (bs)
  58284. + T(" samples (")
  58285. + String (bs * 1000.0 / currentRate, 1)
  58286. + T(" ms)"),
  58287. bs);
  58288. }
  58289. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  58290. }
  58291. }
  58292. else
  58293. {
  58294. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  58295. deleteAndZero (sampleRateLabel);
  58296. deleteAndZero (bufferSizeLabel);
  58297. deleteAndZero (sampleRateDropDown);
  58298. deleteAndZero (bufferSizeDropDown);
  58299. if (outputDeviceDropDown != 0)
  58300. outputDeviceDropDown->setSelectedId (-1, true);
  58301. if (inputDeviceDropDown != 0)
  58302. inputDeviceDropDown->setSelectedId (-1, true);
  58303. }
  58304. resized();
  58305. setSize (getWidth(), getLowestY() + 4);
  58306. }
  58307. private:
  58308. AudioIODeviceType* const type;
  58309. const AudioIODeviceType::DeviceSetupDetails setup;
  58310. ComboBox* outputDeviceDropDown;
  58311. ComboBox* inputDeviceDropDown;
  58312. ComboBox* sampleRateDropDown;
  58313. ComboBox* bufferSizeDropDown;
  58314. Label* outputDeviceLabel;
  58315. Label* inputDeviceLabel;
  58316. Label* sampleRateLabel;
  58317. Label* bufferSizeLabel;
  58318. Label* inputChanLabel;
  58319. Label* outputChanLabel;
  58320. TextButton* testButton;
  58321. Component* inputLevelMeter;
  58322. TextButton* showUIButton;
  58323. TextButton* showAdvancedSettingsButton;
  58324. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  58325. {
  58326. if (box != 0)
  58327. {
  58328. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  58329. const int index = type->getIndexOfDevice (currentDevice, isInput);
  58330. box->setSelectedId (index + 1, true);
  58331. if (testButton != 0 && ! isInput)
  58332. testButton->setEnabled (index >= 0);
  58333. }
  58334. }
  58335. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  58336. {
  58337. const StringArray devs (type->getDeviceNames (isInputs));
  58338. combo.clear (true);
  58339. for (int i = 0; i < devs.size(); ++i)
  58340. combo.addItem (devs[i], i + 1);
  58341. combo.addItem (TRANS("<< none >>"), -1);
  58342. combo.setSelectedId (-1, true);
  58343. }
  58344. int getLowestY() const
  58345. {
  58346. int y = 0;
  58347. for (int i = getNumChildComponents(); --i >= 0;)
  58348. y = jmax (y, getChildComponent (i)->getBottom());
  58349. return y;
  58350. }
  58351. public:
  58352. class ChannelSelectorListBox : public ListBox,
  58353. public ListBoxModel
  58354. {
  58355. public:
  58356. enum BoxType
  58357. {
  58358. audioInputType,
  58359. audioOutputType
  58360. };
  58361. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  58362. const BoxType type_,
  58363. const String& noItemsMessage_)
  58364. : ListBox (String::empty, 0),
  58365. setup (setup_),
  58366. type (type_),
  58367. noItemsMessage (noItemsMessage_)
  58368. {
  58369. refresh();
  58370. setModel (this);
  58371. setOutlineThickness (1);
  58372. }
  58373. ~ChannelSelectorListBox()
  58374. {
  58375. }
  58376. void refresh()
  58377. {
  58378. items.clear();
  58379. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58380. if (currentDevice != 0)
  58381. {
  58382. if (type == audioInputType)
  58383. items = currentDevice->getInputChannelNames();
  58384. else if (type == audioOutputType)
  58385. items = currentDevice->getOutputChannelNames();
  58386. if (setup.useStereoPairs)
  58387. {
  58388. StringArray pairs;
  58389. for (int i = 0; i < items.size(); i += 2)
  58390. {
  58391. String name (items[i]);
  58392. String name2 (items[i + 1]);
  58393. String commonBit;
  58394. for (int j = 0; j < name.length(); ++j)
  58395. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58396. commonBit = name.substring (0, j);
  58397. pairs.add (name.trim()
  58398. + " + "
  58399. + name2.substring (commonBit.length()).trim());
  58400. }
  58401. items = pairs;
  58402. }
  58403. }
  58404. updateContent();
  58405. repaint();
  58406. }
  58407. int getNumRows()
  58408. {
  58409. return items.size();
  58410. }
  58411. void paintListBoxItem (int row,
  58412. Graphics& g,
  58413. int width, int height,
  58414. bool rowIsSelected)
  58415. {
  58416. if (((unsigned int) row) < (unsigned int) items.size())
  58417. {
  58418. if (rowIsSelected)
  58419. g.fillAll (findColour (TextEditor::highlightColourId)
  58420. .withMultipliedAlpha (0.3f));
  58421. const String item (items [row]);
  58422. bool enabled = false;
  58423. AudioDeviceManager::AudioDeviceSetup config;
  58424. setup.manager->getAudioDeviceSetup (config);
  58425. if (setup.useStereoPairs)
  58426. {
  58427. if (type == audioInputType)
  58428. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58429. else if (type == audioOutputType)
  58430. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58431. }
  58432. else
  58433. {
  58434. if (type == audioInputType)
  58435. enabled = config.inputChannels [row];
  58436. else if (type == audioOutputType)
  58437. enabled = config.outputChannels [row];
  58438. }
  58439. const int x = getTickX();
  58440. const float tickW = height * 0.75f;
  58441. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58442. enabled, true, true, false);
  58443. g.setFont (height * 0.6f);
  58444. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58445. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58446. }
  58447. }
  58448. void listBoxItemClicked (int row, const MouseEvent& e)
  58449. {
  58450. selectRow (row);
  58451. if (e.x < getTickX())
  58452. flipEnablement (row);
  58453. }
  58454. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58455. {
  58456. flipEnablement (row);
  58457. }
  58458. void returnKeyPressed (int row)
  58459. {
  58460. flipEnablement (row);
  58461. }
  58462. void paint (Graphics& g)
  58463. {
  58464. ListBox::paint (g);
  58465. if (items.size() == 0)
  58466. {
  58467. g.setColour (Colours::grey);
  58468. g.setFont (13.0f);
  58469. g.drawText (noItemsMessage,
  58470. 0, 0, getWidth(), getHeight() / 2,
  58471. Justification::centred, true);
  58472. }
  58473. }
  58474. int getBestHeight (int maxHeight)
  58475. {
  58476. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58477. getNumRows())
  58478. + getOutlineThickness() * 2;
  58479. }
  58480. juce_UseDebuggingNewOperator
  58481. private:
  58482. const AudioIODeviceType::DeviceSetupDetails setup;
  58483. const BoxType type;
  58484. const String noItemsMessage;
  58485. StringArray items;
  58486. void flipEnablement (const int row)
  58487. {
  58488. jassert (type == audioInputType || type == audioOutputType);
  58489. if (((unsigned int) row) < (unsigned int) items.size())
  58490. {
  58491. AudioDeviceManager::AudioDeviceSetup config;
  58492. setup.manager->getAudioDeviceSetup (config);
  58493. if (setup.useStereoPairs)
  58494. {
  58495. BitArray bits;
  58496. BitArray& original = (type == audioInputType ? config.inputChannels
  58497. : config.outputChannels);
  58498. int i;
  58499. for (i = 0; i < 256; i += 2)
  58500. bits.setBit (i / 2, original [i] || original [i + 1]);
  58501. if (type == audioInputType)
  58502. {
  58503. config.useDefaultInputChannels = false;
  58504. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58505. }
  58506. else
  58507. {
  58508. config.useDefaultOutputChannels = false;
  58509. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58510. }
  58511. for (i = 0; i < 256; ++i)
  58512. original.setBit (i, bits [i / 2]);
  58513. }
  58514. else
  58515. {
  58516. if (type == audioInputType)
  58517. {
  58518. config.useDefaultInputChannels = false;
  58519. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58520. }
  58521. else
  58522. {
  58523. config.useDefaultOutputChannels = false;
  58524. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58525. }
  58526. }
  58527. String error (setup.manager->setAudioDeviceSetup (config, true));
  58528. if (! error.isEmpty())
  58529. {
  58530. //xxx
  58531. }
  58532. }
  58533. }
  58534. static void flipBit (BitArray& chans, int index, int minNumber, int maxNumber)
  58535. {
  58536. const int numActive = chans.countNumberOfSetBits();
  58537. if (chans [index])
  58538. {
  58539. if (numActive > minNumber)
  58540. chans.setBit (index, false);
  58541. }
  58542. else
  58543. {
  58544. if (numActive >= maxNumber)
  58545. {
  58546. const int firstActiveChan = chans.findNextSetBit();
  58547. chans.setBit (index > firstActiveChan
  58548. ? firstActiveChan : chans.getHighestBit(),
  58549. false);
  58550. }
  58551. chans.setBit (index, true);
  58552. }
  58553. }
  58554. int getTickX() const
  58555. {
  58556. return getRowHeight() + 5;
  58557. }
  58558. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58559. const ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58560. };
  58561. private:
  58562. ChannelSelectorListBox* inputChanList;
  58563. ChannelSelectorListBox* outputChanList;
  58564. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58565. const AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58566. };
  58567. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58568. const int minInputChannels_,
  58569. const int maxInputChannels_,
  58570. const int minOutputChannels_,
  58571. const int maxOutputChannels_,
  58572. const bool showMidiInputOptions,
  58573. const bool showMidiOutputSelector,
  58574. const bool showChannelsAsStereoPairs_,
  58575. const bool hideAdvancedOptionsWithButton_)
  58576. : deviceManager (deviceManager_),
  58577. deviceTypeDropDown (0),
  58578. deviceTypeDropDownLabel (0),
  58579. audioDeviceSettingsComp (0),
  58580. minOutputChannels (minOutputChannels_),
  58581. maxOutputChannels (maxOutputChannels_),
  58582. minInputChannels (minInputChannels_),
  58583. maxInputChannels (maxInputChannels_),
  58584. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58585. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58586. {
  58587. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58588. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58589. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58590. {
  58591. deviceTypeDropDown = new ComboBox (String::empty);
  58592. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58593. {
  58594. deviceTypeDropDown
  58595. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58596. i + 1);
  58597. }
  58598. addAndMakeVisible (deviceTypeDropDown);
  58599. deviceTypeDropDown->addListener (this);
  58600. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58601. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58602. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58603. }
  58604. if (showMidiInputOptions)
  58605. {
  58606. addAndMakeVisible (midiInputsList
  58607. = new MidiInputSelectorComponentListBox (deviceManager,
  58608. TRANS("(no midi inputs available)"),
  58609. 0, 0));
  58610. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58611. midiInputsLabel->setJustificationType (Justification::topRight);
  58612. midiInputsLabel->attachToComponent (midiInputsList, true);
  58613. }
  58614. else
  58615. {
  58616. midiInputsList = 0;
  58617. midiInputsLabel = 0;
  58618. }
  58619. if (showMidiOutputSelector)
  58620. {
  58621. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58622. midiOutputSelector->addListener (this);
  58623. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58624. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58625. }
  58626. else
  58627. {
  58628. midiOutputSelector = 0;
  58629. midiOutputLabel = 0;
  58630. }
  58631. deviceManager_.addChangeListener (this);
  58632. changeListenerCallback (0);
  58633. }
  58634. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58635. {
  58636. deviceManager.removeChangeListener (this);
  58637. deleteAllChildren();
  58638. }
  58639. void AudioDeviceSelectorComponent::resized()
  58640. {
  58641. const int lx = proportionOfWidth (0.35f);
  58642. const int w = proportionOfWidth (0.4f);
  58643. const int h = 24;
  58644. const int space = 6;
  58645. const int dh = h + space;
  58646. int y = 15;
  58647. if (deviceTypeDropDown != 0)
  58648. {
  58649. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58650. y += dh + space * 2;
  58651. }
  58652. if (audioDeviceSettingsComp != 0)
  58653. {
  58654. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58655. y += audioDeviceSettingsComp->getHeight() + space;
  58656. }
  58657. if (midiInputsList != 0)
  58658. {
  58659. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58660. midiInputsList->setBounds (lx, y, w, bh);
  58661. y += bh + space;
  58662. }
  58663. if (midiOutputSelector != 0)
  58664. midiOutputSelector->setBounds (lx, y, w, h);
  58665. }
  58666. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58667. {
  58668. if (child == audioDeviceSettingsComp)
  58669. resized();
  58670. }
  58671. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58672. {
  58673. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58674. if (device != 0 && device->hasControlPanel())
  58675. {
  58676. if (device->showControlPanel())
  58677. deviceManager.restartLastAudioDevice();
  58678. getTopLevelComponent()->toFront (true);
  58679. }
  58680. }
  58681. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58682. {
  58683. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58684. {
  58685. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58686. if (type != 0)
  58687. {
  58688. deleteAndZero (audioDeviceSettingsComp);
  58689. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58690. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58691. }
  58692. }
  58693. else if (comboBoxThatHasChanged == midiOutputSelector)
  58694. {
  58695. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58696. }
  58697. }
  58698. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58699. {
  58700. if (deviceTypeDropDown != 0)
  58701. {
  58702. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58703. }
  58704. if (audioDeviceSettingsComp == 0
  58705. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58706. {
  58707. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58708. deleteAndZero (audioDeviceSettingsComp);
  58709. AudioIODeviceType* const type
  58710. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58711. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58712. if (type != 0)
  58713. {
  58714. AudioIODeviceType::DeviceSetupDetails details;
  58715. details.manager = &deviceManager;
  58716. details.minNumInputChannels = minInputChannels;
  58717. details.maxNumInputChannels = maxInputChannels;
  58718. details.minNumOutputChannels = minOutputChannels;
  58719. details.maxNumOutputChannels = maxOutputChannels;
  58720. details.useStereoPairs = showChannelsAsStereoPairs;
  58721. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58722. if (audioDeviceSettingsComp != 0)
  58723. {
  58724. addAndMakeVisible (audioDeviceSettingsComp);
  58725. audioDeviceSettingsComp->resized();
  58726. }
  58727. }
  58728. }
  58729. if (midiInputsList != 0)
  58730. {
  58731. midiInputsList->updateContent();
  58732. midiInputsList->repaint();
  58733. }
  58734. if (midiOutputSelector != 0)
  58735. {
  58736. midiOutputSelector->clear();
  58737. const StringArray midiOuts (MidiOutput::getDevices());
  58738. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58739. midiOutputSelector->addSeparator();
  58740. for (int i = 0; i < midiOuts.size(); ++i)
  58741. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58742. int current = -1;
  58743. if (deviceManager.getDefaultMidiOutput() != 0)
  58744. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58745. midiOutputSelector->setSelectedId (current, true);
  58746. }
  58747. resized();
  58748. }
  58749. END_JUCE_NAMESPACE
  58750. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58751. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58752. BEGIN_JUCE_NAMESPACE
  58753. BubbleComponent::BubbleComponent()
  58754. : side (0),
  58755. allowablePlacements (above | below | left | right),
  58756. arrowTipX (0.0f),
  58757. arrowTipY (0.0f)
  58758. {
  58759. setInterceptsMouseClicks (false, false);
  58760. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58761. setComponentEffect (&shadow);
  58762. }
  58763. BubbleComponent::~BubbleComponent()
  58764. {
  58765. }
  58766. void BubbleComponent::paint (Graphics& g)
  58767. {
  58768. int x = content.getX();
  58769. int y = content.getY();
  58770. int w = content.getWidth();
  58771. int h = content.getHeight();
  58772. int cw, ch;
  58773. getContentSize (cw, ch);
  58774. if (side == 3)
  58775. x += w - cw;
  58776. else if (side != 1)
  58777. x += (w - cw) / 2;
  58778. w = cw;
  58779. if (side == 2)
  58780. y += h - ch;
  58781. else if (side != 0)
  58782. y += (h - ch) / 2;
  58783. h = ch;
  58784. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58785. (float) x, (float) y,
  58786. (float) w, (float) h);
  58787. const int cx = x + (w - cw) / 2;
  58788. const int cy = y + (h - ch) / 2;
  58789. const int indent = 3;
  58790. g.setOrigin (cx + indent, cy + indent);
  58791. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58792. paintContent (g, cw - indent * 2, ch - indent * 2);
  58793. }
  58794. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58795. {
  58796. allowablePlacements = newPlacement;
  58797. }
  58798. void BubbleComponent::setPosition (Component* componentToPointTo)
  58799. {
  58800. jassert (componentToPointTo->isValidComponent());
  58801. int tx = 0;
  58802. int ty = 0;
  58803. if (getParentComponent() != 0)
  58804. componentToPointTo->relativePositionToOtherComponent (getParentComponent(), tx, ty);
  58805. else
  58806. componentToPointTo->relativePositionToGlobal (tx, ty);
  58807. setPosition (Rectangle<int> (tx, ty, componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58808. }
  58809. void BubbleComponent::setPosition (const int arrowTipX_,
  58810. const int arrowTipY_)
  58811. {
  58812. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58813. }
  58814. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58815. {
  58816. Rectangle<int> availableSpace;
  58817. if (getParentComponent() != 0)
  58818. {
  58819. availableSpace.setSize (getParentComponent()->getWidth(),
  58820. getParentComponent()->getHeight());
  58821. }
  58822. else
  58823. {
  58824. availableSpace = getParentMonitorArea();
  58825. }
  58826. int x = 0;
  58827. int y = 0;
  58828. int w = 150;
  58829. int h = 30;
  58830. getContentSize (w, h);
  58831. w += 30;
  58832. h += 30;
  58833. const float edgeIndent = 2.0f;
  58834. const int arrowLength = jmin (10, h / 3, w / 3);
  58835. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58836. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58837. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58838. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58839. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58840. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58841. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58842. {
  58843. spaceLeft = spaceRight = 0;
  58844. }
  58845. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58846. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58847. {
  58848. spaceAbove = spaceBelow = 0;
  58849. }
  58850. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58851. {
  58852. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58853. arrowTipX = w * 0.5f;
  58854. content.setSize (w, h - arrowLength);
  58855. if (spaceAbove >= spaceBelow)
  58856. {
  58857. // above
  58858. y = rectangleToPointTo.getY() - h;
  58859. content.setPosition (0, 0);
  58860. arrowTipY = h - edgeIndent;
  58861. side = 2;
  58862. }
  58863. else
  58864. {
  58865. // below
  58866. y = rectangleToPointTo.getBottom();
  58867. content.setPosition (0, arrowLength);
  58868. arrowTipY = edgeIndent;
  58869. side = 0;
  58870. }
  58871. }
  58872. else
  58873. {
  58874. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58875. arrowTipY = h * 0.5f;
  58876. content.setSize (w - arrowLength, h);
  58877. if (spaceLeft > spaceRight)
  58878. {
  58879. // on the left
  58880. x = rectangleToPointTo.getX() - w;
  58881. content.setPosition (0, 0);
  58882. arrowTipX = w - edgeIndent;
  58883. side = 3;
  58884. }
  58885. else
  58886. {
  58887. // on the right
  58888. x = rectangleToPointTo.getRight();
  58889. content.setPosition (arrowLength, 0);
  58890. arrowTipX = edgeIndent;
  58891. side = 1;
  58892. }
  58893. }
  58894. setBounds (x, y, w, h);
  58895. }
  58896. END_JUCE_NAMESPACE
  58897. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58898. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58899. BEGIN_JUCE_NAMESPACE
  58900. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58901. : fadeOutLength (fadeOutLengthMs),
  58902. deleteAfterUse (false)
  58903. {
  58904. }
  58905. BubbleMessageComponent::~BubbleMessageComponent()
  58906. {
  58907. fadeOutComponent (fadeOutLength);
  58908. }
  58909. void BubbleMessageComponent::showAt (int x, int y,
  58910. const String& text,
  58911. const int numMillisecondsBeforeRemoving,
  58912. const bool removeWhenMouseClicked,
  58913. const bool deleteSelfAfterUse)
  58914. {
  58915. textLayout.clear();
  58916. textLayout.setText (text, Font (14.0f));
  58917. textLayout.layout (256, Justification::centredLeft, true);
  58918. setPosition (x, y);
  58919. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58920. }
  58921. void BubbleMessageComponent::showAt (Component* const component,
  58922. const String& text,
  58923. const int numMillisecondsBeforeRemoving,
  58924. const bool removeWhenMouseClicked,
  58925. const bool deleteSelfAfterUse)
  58926. {
  58927. textLayout.clear();
  58928. textLayout.setText (text, Font (14.0f));
  58929. textLayout.layout (256, Justification::centredLeft, true);
  58930. setPosition (component);
  58931. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58932. }
  58933. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58934. const bool removeWhenMouseClicked,
  58935. const bool deleteSelfAfterUse)
  58936. {
  58937. setVisible (true);
  58938. deleteAfterUse = deleteSelfAfterUse;
  58939. if (numMillisecondsBeforeRemoving > 0)
  58940. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58941. else
  58942. expiryTime = 0;
  58943. startTimer (77);
  58944. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58945. if (! (removeWhenMouseClicked && isShowing()))
  58946. mouseClickCounter += 0xfffff;
  58947. repaint();
  58948. }
  58949. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58950. {
  58951. w = textLayout.getWidth() + 16;
  58952. h = textLayout.getHeight() + 16;
  58953. }
  58954. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58955. {
  58956. g.setColour (findColour (TooltipWindow::textColourId));
  58957. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58958. }
  58959. void BubbleMessageComponent::timerCallback()
  58960. {
  58961. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58962. {
  58963. stopTimer();
  58964. setVisible (false);
  58965. if (deleteAfterUse)
  58966. delete this;
  58967. }
  58968. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58969. {
  58970. stopTimer();
  58971. fadeOutComponent (fadeOutLength);
  58972. if (deleteAfterUse)
  58973. delete this;
  58974. }
  58975. }
  58976. END_JUCE_NAMESPACE
  58977. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58978. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58979. BEGIN_JUCE_NAMESPACE
  58980. static const int swatchesPerRow = 8;
  58981. static const int swatchHeight = 22;
  58982. class ColourComponentSlider : public Slider
  58983. {
  58984. public:
  58985. ColourComponentSlider (const String& name)
  58986. : Slider (name)
  58987. {
  58988. setRange (0.0, 255.0, 1.0);
  58989. }
  58990. ~ColourComponentSlider()
  58991. {
  58992. }
  58993. const String getTextFromValue (double value)
  58994. {
  58995. return String::formatted (T("%02X"), (int) value);
  58996. }
  58997. double getValueFromText (const String& text)
  58998. {
  58999. return (double) text.getHexValue32();
  59000. }
  59001. private:
  59002. ColourComponentSlider (const ColourComponentSlider&);
  59003. const ColourComponentSlider& operator= (const ColourComponentSlider&);
  59004. };
  59005. class ColourSpaceMarker : public Component
  59006. {
  59007. public:
  59008. ColourSpaceMarker()
  59009. {
  59010. setInterceptsMouseClicks (false, false);
  59011. }
  59012. ~ColourSpaceMarker()
  59013. {
  59014. }
  59015. void paint (Graphics& g)
  59016. {
  59017. g.setColour (Colour::greyLevel (0.1f));
  59018. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  59019. g.setColour (Colour::greyLevel (0.9f));
  59020. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  59021. }
  59022. private:
  59023. ColourSpaceMarker (const ColourSpaceMarker&);
  59024. const ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  59025. };
  59026. class ColourSpaceView : public Component
  59027. {
  59028. ColourSelector* const owner;
  59029. float& h;
  59030. float& s;
  59031. float& v;
  59032. float lastHue;
  59033. ColourSpaceMarker* marker;
  59034. const int edge;
  59035. public:
  59036. ColourSpaceView (ColourSelector* owner_,
  59037. float& h_, float& s_, float& v_,
  59038. const int edgeSize)
  59039. : owner (owner_),
  59040. h (h_), s (s_), v (v_),
  59041. lastHue (0.0f),
  59042. edge (edgeSize)
  59043. {
  59044. addAndMakeVisible (marker = new ColourSpaceMarker());
  59045. setMouseCursor (MouseCursor::CrosshairCursor);
  59046. }
  59047. ~ColourSpaceView()
  59048. {
  59049. deleteAllChildren();
  59050. }
  59051. void paint (Graphics& g)
  59052. {
  59053. if (colours == 0)
  59054. {
  59055. const int width = getWidth() / 2;
  59056. const int height = getHeight() / 2;
  59057. colours = new Image (Image::RGB, width, height, false);
  59058. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  59059. for (int y = 0; y < height; ++y)
  59060. {
  59061. const float v = 1.0f - y / (float) height;
  59062. for (int x = 0; x < width; ++x)
  59063. {
  59064. const float s = x / (float) width;
  59065. const Colour col (h, s, v, 1.0f);
  59066. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  59067. pix->set (col.getPixelARGB());
  59068. }
  59069. }
  59070. }
  59071. g.setOpacity (1.0f);
  59072. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  59073. 0, 0, colours->getWidth(), colours->getHeight());
  59074. }
  59075. void mouseDown (const MouseEvent& e)
  59076. {
  59077. mouseDrag (e);
  59078. }
  59079. void mouseDrag (const MouseEvent& e)
  59080. {
  59081. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  59082. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  59083. owner->setSV (s, v);
  59084. }
  59085. void updateIfNeeded()
  59086. {
  59087. if (lastHue != h)
  59088. {
  59089. lastHue = h;
  59090. colours = 0;
  59091. repaint();
  59092. }
  59093. updateMarker();
  59094. }
  59095. void resized()
  59096. {
  59097. colours = 0;
  59098. updateMarker();
  59099. }
  59100. private:
  59101. ScopedPointer <Image> colours;
  59102. void updateMarker() const throw()
  59103. {
  59104. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  59105. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  59106. edge * 2, edge * 2);
  59107. }
  59108. ColourSpaceView (const ColourSpaceView&);
  59109. const ColourSpaceView& operator= (const ColourSpaceView&);
  59110. };
  59111. class HueSelectorMarker : public Component
  59112. {
  59113. public:
  59114. HueSelectorMarker()
  59115. {
  59116. setInterceptsMouseClicks (false, false);
  59117. }
  59118. ~HueSelectorMarker()
  59119. {
  59120. }
  59121. void paint (Graphics& g)
  59122. {
  59123. Path p;
  59124. p.addTriangle (1.0f, 1.0f,
  59125. getWidth() * 0.3f, getHeight() * 0.5f,
  59126. 1.0f, getHeight() - 1.0f);
  59127. p.addTriangle (getWidth() - 1.0f, 1.0f,
  59128. getWidth() * 0.7f, getHeight() * 0.5f,
  59129. getWidth() - 1.0f, getHeight() - 1.0f);
  59130. g.setColour (Colours::white.withAlpha (0.75f));
  59131. g.fillPath (p);
  59132. g.setColour (Colours::black.withAlpha (0.75f));
  59133. g.strokePath (p, PathStrokeType (1.2f));
  59134. }
  59135. private:
  59136. HueSelectorMarker (const HueSelectorMarker&);
  59137. const HueSelectorMarker& operator= (const HueSelectorMarker&);
  59138. };
  59139. class HueSelectorComp : public Component
  59140. {
  59141. public:
  59142. HueSelectorComp (ColourSelector* owner_,
  59143. float& h_, float& s_, float& v_,
  59144. const int edgeSize)
  59145. : owner (owner_),
  59146. h (h_), s (s_), v (v_),
  59147. lastHue (0.0f),
  59148. edge (edgeSize)
  59149. {
  59150. addAndMakeVisible (marker = new HueSelectorMarker());
  59151. }
  59152. ~HueSelectorComp()
  59153. {
  59154. deleteAllChildren();
  59155. }
  59156. void paint (Graphics& g)
  59157. {
  59158. const float yScale = 1.0f / (getHeight() - edge * 2);
  59159. const Rectangle<int> clip (g.getClipBounds());
  59160. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  59161. {
  59162. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  59163. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  59164. }
  59165. }
  59166. void resized()
  59167. {
  59168. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  59169. getWidth(), edge * 2);
  59170. }
  59171. void mouseDown (const MouseEvent& e)
  59172. {
  59173. mouseDrag (e);
  59174. }
  59175. void mouseDrag (const MouseEvent& e)
  59176. {
  59177. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  59178. owner->setHue (hue);
  59179. }
  59180. void updateIfNeeded()
  59181. {
  59182. resized();
  59183. }
  59184. private:
  59185. ColourSelector* const owner;
  59186. float& h;
  59187. float& s;
  59188. float& v;
  59189. float lastHue;
  59190. HueSelectorMarker* marker;
  59191. const int edge;
  59192. HueSelectorComp (const HueSelectorComp&);
  59193. const HueSelectorComp& operator= (const HueSelectorComp&);
  59194. };
  59195. class ColourSelector::SwatchComponent : public Component
  59196. {
  59197. public:
  59198. SwatchComponent (ColourSelector* owner_, int index_)
  59199. : owner (owner_),
  59200. index (index_)
  59201. {
  59202. }
  59203. ~SwatchComponent()
  59204. {
  59205. }
  59206. void paint (Graphics& g)
  59207. {
  59208. const Colour colour (owner->getSwatchColour (index));
  59209. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  59210. 6, 6,
  59211. Colour (0xffdddddd).overlaidWith (colour),
  59212. Colour (0xffffffff).overlaidWith (colour));
  59213. }
  59214. void mouseDown (const MouseEvent&)
  59215. {
  59216. PopupMenu m;
  59217. m.addItem (1, TRANS("Use this swatch as the current colour"));
  59218. m.addSeparator();
  59219. m.addItem (2, TRANS("Set this swatch to the current colour"));
  59220. const int r = m.showAt (this);
  59221. if (r == 1)
  59222. {
  59223. owner->setCurrentColour (owner->getSwatchColour (index));
  59224. }
  59225. else if (r == 2)
  59226. {
  59227. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  59228. {
  59229. owner->setSwatchColour (index, owner->getCurrentColour());
  59230. repaint();
  59231. }
  59232. }
  59233. }
  59234. private:
  59235. ColourSelector* const owner;
  59236. const int index;
  59237. SwatchComponent (const SwatchComponent&);
  59238. const SwatchComponent& operator= (const SwatchComponent&);
  59239. };
  59240. ColourSelector::ColourSelector (const int flags_,
  59241. const int edgeGap_,
  59242. const int gapAroundColourSpaceComponent)
  59243. : colour (Colours::white),
  59244. flags (flags_),
  59245. topSpace (0),
  59246. edgeGap (edgeGap_)
  59247. {
  59248. // not much point having a selector with no components in it!
  59249. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  59250. updateHSV();
  59251. if ((flags & showSliders) != 0)
  59252. {
  59253. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  59254. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  59255. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  59256. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  59257. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  59258. for (int i = 4; --i >= 0;)
  59259. sliders[i]->addListener (this);
  59260. }
  59261. else
  59262. {
  59263. zeromem (sliders, sizeof (sliders));
  59264. }
  59265. if ((flags & showColourspace) != 0)
  59266. {
  59267. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  59268. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  59269. }
  59270. else
  59271. {
  59272. colourSpace = 0;
  59273. hueSelector = 0;
  59274. }
  59275. update();
  59276. }
  59277. ColourSelector::~ColourSelector()
  59278. {
  59279. dispatchPendingMessages();
  59280. swatchComponents.clear();
  59281. deleteAllChildren();
  59282. }
  59283. const Colour ColourSelector::getCurrentColour() const
  59284. {
  59285. return ((flags & showAlphaChannel) != 0) ? colour
  59286. : colour.withAlpha ((uint8) 0xff);
  59287. }
  59288. void ColourSelector::setCurrentColour (const Colour& c)
  59289. {
  59290. if (c != colour)
  59291. {
  59292. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  59293. updateHSV();
  59294. update();
  59295. }
  59296. }
  59297. void ColourSelector::setHue (float newH)
  59298. {
  59299. newH = jlimit (0.0f, 1.0f, newH);
  59300. if (h != newH)
  59301. {
  59302. h = newH;
  59303. colour = Colour (h, s, v, colour.getFloatAlpha());
  59304. update();
  59305. }
  59306. }
  59307. void ColourSelector::setSV (float newS, float newV)
  59308. {
  59309. newS = jlimit (0.0f, 1.0f, newS);
  59310. newV = jlimit (0.0f, 1.0f, newV);
  59311. if (s != newS || v != newV)
  59312. {
  59313. s = newS;
  59314. v = newV;
  59315. colour = Colour (h, s, v, colour.getFloatAlpha());
  59316. update();
  59317. }
  59318. }
  59319. void ColourSelector::updateHSV()
  59320. {
  59321. colour.getHSB (h, s, v);
  59322. }
  59323. void ColourSelector::update()
  59324. {
  59325. if (sliders[0] != 0)
  59326. {
  59327. sliders[0]->setValue ((int) colour.getRed());
  59328. sliders[1]->setValue ((int) colour.getGreen());
  59329. sliders[2]->setValue ((int) colour.getBlue());
  59330. sliders[3]->setValue ((int) colour.getAlpha());
  59331. }
  59332. if (colourSpace != 0)
  59333. {
  59334. ((ColourSpaceView*) colourSpace)->updateIfNeeded();
  59335. ((HueSelectorComp*) hueSelector)->updateIfNeeded();
  59336. }
  59337. if ((flags & showColourAtTop) != 0)
  59338. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  59339. sendChangeMessage (this);
  59340. }
  59341. void ColourSelector::paint (Graphics& g)
  59342. {
  59343. g.fillAll (findColour (backgroundColourId));
  59344. if ((flags & showColourAtTop) != 0)
  59345. {
  59346. const Colour colour (getCurrentColour());
  59347. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  59348. 10, 10,
  59349. Colour (0xffdddddd).overlaidWith (colour),
  59350. Colour (0xffffffff).overlaidWith (colour));
  59351. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  59352. g.setFont (14.0f, true);
  59353. g.drawText (((flags & showAlphaChannel) != 0)
  59354. ? String::formatted (T("#%02X%02X%02X%02X"),
  59355. (int) colour.getAlpha(),
  59356. (int) colour.getRed(),
  59357. (int) colour.getGreen(),
  59358. (int) colour.getBlue())
  59359. : String::formatted (T("#%02X%02X%02X"),
  59360. (int) colour.getRed(),
  59361. (int) colour.getGreen(),
  59362. (int) colour.getBlue()),
  59363. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  59364. Justification::centred, false);
  59365. }
  59366. if ((flags & showSliders) != 0)
  59367. {
  59368. g.setColour (findColour (labelTextColourId));
  59369. g.setFont (11.0f);
  59370. for (int i = 4; --i >= 0;)
  59371. {
  59372. if (sliders[i]->isVisible())
  59373. g.drawText (sliders[i]->getName() + T(":"),
  59374. 0, sliders[i]->getY(),
  59375. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  59376. Justification::centredRight, false);
  59377. }
  59378. }
  59379. }
  59380. void ColourSelector::resized()
  59381. {
  59382. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  59383. const int numSwatches = getNumSwatches();
  59384. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  59385. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  59386. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  59387. int y = topSpace;
  59388. if ((flags & showColourspace) != 0)
  59389. {
  59390. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  59391. colourSpace->setBounds (edgeGap, y,
  59392. getWidth() - hueWidth - edgeGap - 4,
  59393. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  59394. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  59395. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  59396. colourSpace->getHeight());
  59397. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  59398. }
  59399. if ((flags & showSliders) != 0)
  59400. {
  59401. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  59402. for (int i = 0; i < numSliders; ++i)
  59403. {
  59404. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59405. proportionOfWidth (0.72f), sliderHeight - 2);
  59406. y += sliderHeight;
  59407. }
  59408. }
  59409. if (numSwatches > 0)
  59410. {
  59411. const int startX = 8;
  59412. const int xGap = 4;
  59413. const int yGap = 4;
  59414. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59415. y += edgeGap;
  59416. if (swatchComponents.size() != numSwatches)
  59417. {
  59418. swatchComponents.clear();
  59419. for (int i = 0; i < numSwatches; ++i)
  59420. {
  59421. SwatchComponent* const sc = new SwatchComponent (this, i);
  59422. swatchComponents.add (sc);
  59423. addAndMakeVisible (sc);
  59424. }
  59425. }
  59426. int x = startX;
  59427. for (int i = 0; i < swatchComponents.size(); ++i)
  59428. {
  59429. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59430. sc->setBounds (x + xGap / 2,
  59431. y + yGap / 2,
  59432. swatchWidth - xGap,
  59433. swatchHeight - yGap);
  59434. if (((i + 1) % swatchesPerRow) == 0)
  59435. {
  59436. x = startX;
  59437. y += swatchHeight;
  59438. }
  59439. else
  59440. {
  59441. x += swatchWidth;
  59442. }
  59443. }
  59444. }
  59445. }
  59446. void ColourSelector::sliderValueChanged (Slider*)
  59447. {
  59448. if (sliders[0] != 0)
  59449. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59450. (uint8) sliders[1]->getValue(),
  59451. (uint8) sliders[2]->getValue(),
  59452. (uint8) sliders[3]->getValue()));
  59453. }
  59454. int ColourSelector::getNumSwatches() const
  59455. {
  59456. return 0;
  59457. }
  59458. const Colour ColourSelector::getSwatchColour (const int) const
  59459. {
  59460. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59461. return Colours::black;
  59462. }
  59463. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59464. {
  59465. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59466. }
  59467. END_JUCE_NAMESPACE
  59468. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59469. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59470. BEGIN_JUCE_NAMESPACE
  59471. class ShadowWindow : public Component
  59472. {
  59473. Component* owner;
  59474. Image** shadowImageSections;
  59475. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59476. public:
  59477. ShadowWindow (Component* const owner_,
  59478. const int type_,
  59479. Image** const shadowImageSections_)
  59480. : owner (owner_),
  59481. shadowImageSections (shadowImageSections_),
  59482. type (type_)
  59483. {
  59484. setInterceptsMouseClicks (false, false);
  59485. if (owner_->isOnDesktop())
  59486. {
  59487. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59488. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59489. | ComponentPeer::windowIsTemporary
  59490. | ComponentPeer::windowIgnoresKeyPresses);
  59491. }
  59492. else if (owner_->getParentComponent() != 0)
  59493. {
  59494. owner_->getParentComponent()->addChildComponent (this);
  59495. }
  59496. }
  59497. ~ShadowWindow()
  59498. {
  59499. }
  59500. void paint (Graphics& g)
  59501. {
  59502. Image* const topLeft = shadowImageSections [type * 3];
  59503. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59504. Image* const filler = shadowImageSections [type * 3 + 2];
  59505. g.setOpacity (1.0f);
  59506. if (type < 2)
  59507. {
  59508. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59509. g.drawImage (topLeft,
  59510. 0, 0, topLeft->getWidth(), imH,
  59511. 0, 0, topLeft->getWidth(), imH);
  59512. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59513. g.drawImage (bottomRight,
  59514. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59515. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59516. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59517. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59518. }
  59519. else
  59520. {
  59521. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59522. g.drawImage (topLeft,
  59523. 0, 0, imW, topLeft->getHeight(),
  59524. 0, 0, imW, topLeft->getHeight());
  59525. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59526. g.drawImage (bottomRight,
  59527. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59528. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59529. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59530. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59531. }
  59532. }
  59533. void resized()
  59534. {
  59535. repaint(); // (needed for correct repainting)
  59536. }
  59537. private:
  59538. ShadowWindow (const ShadowWindow&);
  59539. const ShadowWindow& operator= (const ShadowWindow&);
  59540. };
  59541. DropShadower::DropShadower (const float alpha_,
  59542. const int xOffset_,
  59543. const int yOffset_,
  59544. const float blurRadius_)
  59545. : owner (0),
  59546. numShadows (0),
  59547. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59548. xOffset (xOffset_),
  59549. yOffset (yOffset_),
  59550. alpha (alpha_),
  59551. blurRadius (blurRadius_),
  59552. inDestructor (false),
  59553. reentrant (false)
  59554. {
  59555. }
  59556. DropShadower::~DropShadower()
  59557. {
  59558. if (owner != 0)
  59559. owner->removeComponentListener (this);
  59560. inDestructor = true;
  59561. deleteShadowWindows();
  59562. }
  59563. void DropShadower::deleteShadowWindows()
  59564. {
  59565. if (numShadows > 0)
  59566. {
  59567. int i;
  59568. for (i = numShadows; --i >= 0;)
  59569. delete shadowWindows[i];
  59570. for (i = 12; --i >= 0;)
  59571. delete shadowImageSections[i];
  59572. numShadows = 0;
  59573. }
  59574. }
  59575. void DropShadower::setOwner (Component* componentToFollow)
  59576. {
  59577. if (componentToFollow != owner)
  59578. {
  59579. if (owner != 0)
  59580. owner->removeComponentListener (this);
  59581. // (the component can't be null)
  59582. jassert (componentToFollow != 0);
  59583. owner = componentToFollow;
  59584. jassert (owner != 0);
  59585. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59586. owner->addComponentListener (this);
  59587. updateShadows();
  59588. }
  59589. }
  59590. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59591. {
  59592. updateShadows();
  59593. }
  59594. void DropShadower::componentBroughtToFront (Component&)
  59595. {
  59596. bringShadowWindowsToFront();
  59597. }
  59598. void DropShadower::componentChildrenChanged (Component&)
  59599. {
  59600. }
  59601. void DropShadower::componentParentHierarchyChanged (Component&)
  59602. {
  59603. deleteShadowWindows();
  59604. updateShadows();
  59605. }
  59606. void DropShadower::componentVisibilityChanged (Component&)
  59607. {
  59608. updateShadows();
  59609. }
  59610. void DropShadower::updateShadows()
  59611. {
  59612. if (reentrant || inDestructor || (owner == 0))
  59613. return;
  59614. reentrant = true;
  59615. ComponentPeer* const nw = owner->getPeer();
  59616. const bool isOwnerVisible = owner->isVisible()
  59617. && (nw == 0 || ! nw->isMinimised());
  59618. const bool createShadowWindows = numShadows == 0
  59619. && owner->getWidth() > 0
  59620. && owner->getHeight() > 0
  59621. && isOwnerVisible
  59622. && (Desktop::canUseSemiTransparentWindows()
  59623. || owner->getParentComponent() != 0);
  59624. if (createShadowWindows)
  59625. {
  59626. // keep a cached version of the image to save doing the gaussian too often
  59627. String imageId;
  59628. imageId << shadowEdge << T(',')
  59629. << xOffset << T(',')
  59630. << yOffset << T(',')
  59631. << alpha;
  59632. const int hash = imageId.hashCode();
  59633. Image* bigIm = ImageCache::getFromHashCode (hash);
  59634. if (bigIm == 0)
  59635. {
  59636. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59637. Graphics bigG (*bigIm);
  59638. bigG.setColour (Colours::black.withAlpha (alpha));
  59639. bigG.fillRect (shadowEdge + xOffset,
  59640. shadowEdge + yOffset,
  59641. bigIm->getWidth() - (shadowEdge * 2),
  59642. bigIm->getHeight() - (shadowEdge * 2));
  59643. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59644. blurKernel.createGaussianBlur (blurRadius);
  59645. blurKernel.applyToImage (*bigIm, 0,
  59646. xOffset,
  59647. yOffset,
  59648. bigIm->getWidth(),
  59649. bigIm->getHeight());
  59650. ImageCache::addImageToCache (bigIm, hash);
  59651. }
  59652. const int iw = bigIm->getWidth();
  59653. const int ih = bigIm->getHeight();
  59654. const int shadowEdge2 = shadowEdge * 2;
  59655. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59656. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59657. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59658. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59659. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59660. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59661. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59662. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59663. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59664. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59665. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59666. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59667. ImageCache::release (bigIm);
  59668. for (int i = 0; i < 4; ++i)
  59669. {
  59670. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59671. ++numShadows;
  59672. }
  59673. }
  59674. if (numShadows > 0)
  59675. {
  59676. for (int i = numShadows; --i >= 0;)
  59677. {
  59678. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59679. shadowWindows[i]->setVisible (isOwnerVisible);
  59680. }
  59681. const int x = owner->getX();
  59682. const int y = owner->getY() - shadowEdge;
  59683. const int w = owner->getWidth();
  59684. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59685. shadowWindows[0]->setBounds (x - shadowEdge,
  59686. y,
  59687. shadowEdge,
  59688. h);
  59689. shadowWindows[1]->setBounds (x + w,
  59690. y,
  59691. shadowEdge,
  59692. h);
  59693. shadowWindows[2]->setBounds (x,
  59694. y,
  59695. w,
  59696. shadowEdge);
  59697. shadowWindows[3]->setBounds (x,
  59698. owner->getBottom(),
  59699. w,
  59700. shadowEdge);
  59701. }
  59702. reentrant = false;
  59703. if (createShadowWindows)
  59704. bringShadowWindowsToFront();
  59705. }
  59706. void DropShadower::setShadowImage (Image* const src,
  59707. const int num,
  59708. const int w,
  59709. const int h,
  59710. const int sx,
  59711. const int sy)
  59712. {
  59713. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59714. Graphics g (*shadowImageSections[num]);
  59715. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59716. }
  59717. void DropShadower::bringShadowWindowsToFront()
  59718. {
  59719. if (! (inDestructor || reentrant))
  59720. {
  59721. updateShadows();
  59722. reentrant = true;
  59723. for (int i = numShadows; --i >= 0;)
  59724. shadowWindows[i]->toBehind (owner);
  59725. reentrant = false;
  59726. }
  59727. }
  59728. END_JUCE_NAMESPACE
  59729. /*** End of inlined file: juce_DropShadower.cpp ***/
  59730. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59731. BEGIN_JUCE_NAMESPACE
  59732. class MagnifyingPeer : public ComponentPeer
  59733. {
  59734. public:
  59735. MagnifyingPeer (Component* const component_,
  59736. MagnifierComponent* const magnifierComp_)
  59737. : ComponentPeer (component_, 0),
  59738. magnifierComp (magnifierComp_)
  59739. {
  59740. }
  59741. ~MagnifyingPeer()
  59742. {
  59743. }
  59744. void* getNativeHandle() const { return 0; }
  59745. void setVisible (bool) {}
  59746. void setTitle (const String&) {}
  59747. void setPosition (int, int) {}
  59748. void setSize (int, int) {}
  59749. void setBounds (int, int, int, int, const bool) {}
  59750. void setMinimised (bool) {}
  59751. bool isMinimised() const { return false; }
  59752. void setFullScreen (bool) {}
  59753. bool isFullScreen() const { return false; }
  59754. const BorderSize getFrameSize() const { return BorderSize (0); }
  59755. bool setAlwaysOnTop (bool) { return true; }
  59756. void toFront (bool) {}
  59757. void toBehind (ComponentPeer*) {}
  59758. void setIcon (const Image&) {}
  59759. bool isFocused() const
  59760. {
  59761. return magnifierComp->hasKeyboardFocus (true);
  59762. }
  59763. void grabFocus()
  59764. {
  59765. ComponentPeer* peer = magnifierComp->getPeer();
  59766. if (peer != 0)
  59767. peer->grabFocus();
  59768. }
  59769. void textInputRequired (int x, int y)
  59770. {
  59771. ComponentPeer* peer = magnifierComp->getPeer();
  59772. if (peer != 0)
  59773. peer->textInputRequired (x, y);
  59774. }
  59775. void getBounds (int& x, int& y, int& w, int& h) const
  59776. {
  59777. x = magnifierComp->getScreenX();
  59778. y = magnifierComp->getScreenY();
  59779. w = component->getWidth();
  59780. h = component->getHeight();
  59781. }
  59782. int getScreenX() const { return magnifierComp->getScreenX(); }
  59783. int getScreenY() const { return magnifierComp->getScreenY(); }
  59784. void relativePositionToGlobal (int& x, int& y)
  59785. {
  59786. const double zoom = magnifierComp->getScaleFactor();
  59787. x = roundToInt (x * zoom);
  59788. y = roundToInt (y * zoom);
  59789. magnifierComp->relativePositionToGlobal (x, y);
  59790. }
  59791. void globalPositionToRelative (int& x, int& y)
  59792. {
  59793. magnifierComp->globalPositionToRelative (x, y);
  59794. const double zoom = magnifierComp->getScaleFactor();
  59795. x = roundToInt (x / zoom);
  59796. y = roundToInt (y / zoom);
  59797. }
  59798. bool contains (int x, int y, bool) const
  59799. {
  59800. return ((unsigned int) x) < (unsigned int) magnifierComp->getWidth()
  59801. && ((unsigned int) y) < (unsigned int) magnifierComp->getHeight();
  59802. }
  59803. void repaint (int x, int y, int w, int h)
  59804. {
  59805. const double zoom = magnifierComp->getScaleFactor();
  59806. magnifierComp->repaint ((int) (x * zoom),
  59807. (int) (y * zoom),
  59808. roundToInt (w * zoom) + 1,
  59809. roundToInt (h * zoom) + 1);
  59810. }
  59811. void performAnyPendingRepaintsNow()
  59812. {
  59813. }
  59814. juce_UseDebuggingNewOperator
  59815. private:
  59816. MagnifierComponent* const magnifierComp;
  59817. MagnifyingPeer (const MagnifyingPeer&);
  59818. const MagnifyingPeer& operator= (const MagnifyingPeer&);
  59819. };
  59820. class PeerHolderComp : public Component
  59821. {
  59822. public:
  59823. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59824. : magnifierComp (magnifierComp_)
  59825. {
  59826. setVisible (true);
  59827. }
  59828. ~PeerHolderComp()
  59829. {
  59830. }
  59831. ComponentPeer* createNewPeer (int, void*)
  59832. {
  59833. return new MagnifyingPeer (this, magnifierComp);
  59834. }
  59835. void childBoundsChanged (Component* c)
  59836. {
  59837. if (c != 0)
  59838. {
  59839. setSize (c->getWidth(), c->getHeight());
  59840. magnifierComp->childBoundsChanged (this);
  59841. }
  59842. }
  59843. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59844. {
  59845. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59846. Component* const p = magnifierComp->getParentComponent();
  59847. if (p != 0)
  59848. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59849. }
  59850. private:
  59851. MagnifierComponent* const magnifierComp;
  59852. PeerHolderComp (const PeerHolderComp&);
  59853. const PeerHolderComp& operator= (const PeerHolderComp&);
  59854. };
  59855. MagnifierComponent::MagnifierComponent (Component* const content_,
  59856. const bool deleteContentCompWhenNoLongerNeeded)
  59857. : content (content_),
  59858. scaleFactor (0.0),
  59859. peer (0),
  59860. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59861. quality (Graphics::lowResamplingQuality)
  59862. {
  59863. holderComp = new PeerHolderComp (this);
  59864. setScaleFactor (1.0);
  59865. }
  59866. MagnifierComponent::~MagnifierComponent()
  59867. {
  59868. delete holderComp;
  59869. if (deleteContent)
  59870. delete content;
  59871. }
  59872. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59873. {
  59874. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59875. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59876. if (scaleFactor != newScaleFactor)
  59877. {
  59878. scaleFactor = newScaleFactor;
  59879. if (scaleFactor == 1.0)
  59880. {
  59881. holderComp->removeFromDesktop();
  59882. peer = 0;
  59883. addChildComponent (content);
  59884. childBoundsChanged (content);
  59885. }
  59886. else
  59887. {
  59888. holderComp->addAndMakeVisible (content);
  59889. holderComp->childBoundsChanged (content);
  59890. childBoundsChanged (holderComp);
  59891. holderComp->addToDesktop (0);
  59892. peer = holderComp->getPeer();
  59893. }
  59894. repaint();
  59895. }
  59896. }
  59897. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59898. {
  59899. quality = newQuality;
  59900. }
  59901. void MagnifierComponent::paint (Graphics& g)
  59902. {
  59903. const int w = holderComp->getWidth();
  59904. const int h = holderComp->getHeight();
  59905. if (w == 0 || h == 0)
  59906. return;
  59907. const Rectangle<int> r (g.getClipBounds());
  59908. const int srcX = (int) (r.getX() / scaleFactor);
  59909. const int srcY = (int) (r.getY() / scaleFactor);
  59910. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59911. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59912. if (scaleFactor >= 1.0)
  59913. {
  59914. ++srcW;
  59915. ++srcH;
  59916. }
  59917. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59918. temp.clear (srcX, srcY, srcW, srcH);
  59919. {
  59920. Graphics g2 (temp);
  59921. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59922. holderComp->paintEntireComponent (g2);
  59923. }
  59924. g.setImageResamplingQuality (quality);
  59925. g.drawImageTransformed (&temp, temp.getBounds(),
  59926. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59927. false);
  59928. }
  59929. void MagnifierComponent::childBoundsChanged (Component* c)
  59930. {
  59931. if (c != 0)
  59932. setSize (roundToInt (c->getWidth() * scaleFactor),
  59933. roundToInt (c->getHeight() * scaleFactor));
  59934. }
  59935. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59936. {
  59937. if (peer != 0)
  59938. peer->handleMouseDown (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59939. }
  59940. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59941. {
  59942. if (peer != 0)
  59943. peer->handleMouseUp (e.mods.getRawFlags(), scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59944. }
  59945. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59946. {
  59947. if (peer != 0)
  59948. peer->handleMouseDrag (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59949. }
  59950. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59951. {
  59952. if (peer != 0)
  59953. peer->handleMouseMove (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59954. }
  59955. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59956. {
  59957. if (peer != 0)
  59958. peer->handleMouseEnter (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59959. }
  59960. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59961. {
  59962. if (peer != 0)
  59963. peer->handleMouseExit (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59964. }
  59965. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59966. {
  59967. if (peer != 0)
  59968. peer->handleMouseWheel (roundToInt (ix * 256.0f),
  59969. roundToInt (iy * 256.0f),
  59970. e.eventTime.toMilliseconds());
  59971. else
  59972. Component::mouseWheelMove (e, ix, iy);
  59973. }
  59974. int MagnifierComponent::scaleInt (const int n) const
  59975. {
  59976. return roundToInt (n / scaleFactor);
  59977. }
  59978. END_JUCE_NAMESPACE
  59979. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59980. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59981. BEGIN_JUCE_NAMESPACE
  59982. class MidiKeyboardUpDownButton : public Button
  59983. {
  59984. public:
  59985. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59986. const int delta_)
  59987. : Button (String::empty),
  59988. owner (owner_),
  59989. delta (delta_)
  59990. {
  59991. setOpaque (true);
  59992. }
  59993. ~MidiKeyboardUpDownButton()
  59994. {
  59995. }
  59996. void clicked()
  59997. {
  59998. int note = owner->getLowestVisibleKey();
  59999. if (delta < 0)
  60000. note = (note - 1) / 12;
  60001. else
  60002. note = note / 12 + 1;
  60003. owner->setLowestVisibleKey (note * 12);
  60004. }
  60005. void paintButton (Graphics& g,
  60006. bool isMouseOverButton,
  60007. bool isButtonDown)
  60008. {
  60009. owner->drawUpDownButton (g, getWidth(), getHeight(),
  60010. isMouseOverButton, isButtonDown,
  60011. delta > 0);
  60012. }
  60013. private:
  60014. MidiKeyboardComponent* const owner;
  60015. const int delta;
  60016. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  60017. const MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  60018. };
  60019. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  60020. const Orientation orientation_)
  60021. : state (state_),
  60022. xOffset (0),
  60023. blackNoteLength (1),
  60024. keyWidth (16.0f),
  60025. orientation (orientation_),
  60026. midiChannel (1),
  60027. midiInChannelMask (0xffff),
  60028. velocity (1.0f),
  60029. noteUnderMouse (-1),
  60030. mouseDownNote (-1),
  60031. rangeStart (0),
  60032. rangeEnd (127),
  60033. firstKey (12 * 4),
  60034. canScroll (true),
  60035. mouseDragging (false),
  60036. useMousePositionForVelocity (true),
  60037. keyMappingOctave (6),
  60038. octaveNumForMiddleC (3)
  60039. {
  60040. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  60041. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  60042. // initialise with a default set of querty key-mappings..
  60043. const char* const keymap = "awsedftgyhujkolp;";
  60044. for (int i = String (keymap).length(); --i >= 0;)
  60045. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  60046. setOpaque (true);
  60047. setWantsKeyboardFocus (true);
  60048. state.addListener (this);
  60049. }
  60050. MidiKeyboardComponent::~MidiKeyboardComponent()
  60051. {
  60052. state.removeListener (this);
  60053. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  60054. deleteAllChildren();
  60055. }
  60056. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  60057. {
  60058. keyWidth = widthInPixels;
  60059. resized();
  60060. }
  60061. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  60062. {
  60063. if (orientation != newOrientation)
  60064. {
  60065. orientation = newOrientation;
  60066. resized();
  60067. }
  60068. }
  60069. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  60070. const int highestNote)
  60071. {
  60072. jassert (lowestNote >= 0 && lowestNote <= 127);
  60073. jassert (highestNote >= 0 && highestNote <= 127);
  60074. jassert (lowestNote <= highestNote);
  60075. if (rangeStart != lowestNote || rangeEnd != highestNote)
  60076. {
  60077. rangeStart = jlimit (0, 127, lowestNote);
  60078. rangeEnd = jlimit (0, 127, highestNote);
  60079. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  60080. resized();
  60081. }
  60082. }
  60083. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  60084. {
  60085. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  60086. if (noteNumber != firstKey)
  60087. {
  60088. firstKey = noteNumber;
  60089. sendChangeMessage (this);
  60090. resized();
  60091. }
  60092. }
  60093. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  60094. {
  60095. if (canScroll != canScroll_)
  60096. {
  60097. canScroll = canScroll_;
  60098. resized();
  60099. }
  60100. }
  60101. void MidiKeyboardComponent::colourChanged()
  60102. {
  60103. repaint();
  60104. }
  60105. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  60106. {
  60107. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  60108. if (midiChannel != midiChannelNumber)
  60109. {
  60110. resetAnyKeysInUse();
  60111. midiChannel = jlimit (1, 16, midiChannelNumber);
  60112. }
  60113. }
  60114. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  60115. {
  60116. midiInChannelMask = midiChannelMask;
  60117. triggerAsyncUpdate();
  60118. }
  60119. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  60120. {
  60121. velocity = jlimit (0.0f, 1.0f, velocity_);
  60122. useMousePositionForVelocity = useMousePositionForVelocity_;
  60123. }
  60124. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  60125. {
  60126. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  60127. static const float blackNoteWidth = 0.7f;
  60128. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  60129. 1.0f, 2 - blackNoteWidth * 0.4f,
  60130. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  60131. 4.0f, 5 - blackNoteWidth * 0.5f,
  60132. 5.0f, 6 - blackNoteWidth * 0.3f,
  60133. 6.0f };
  60134. static const float widths[] = { 1.0f, blackNoteWidth,
  60135. 1.0f, blackNoteWidth,
  60136. 1.0f, 1.0f, blackNoteWidth,
  60137. 1.0f, blackNoteWidth,
  60138. 1.0f, blackNoteWidth,
  60139. 1.0f };
  60140. const int octave = midiNoteNumber / 12;
  60141. const int note = midiNoteNumber % 12;
  60142. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  60143. w = roundToInt (widths [note] * keyWidth);
  60144. }
  60145. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  60146. {
  60147. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  60148. int rx, rw;
  60149. getKeyPosition (rangeStart, keyWidth, rx, rw);
  60150. x -= xOffset + rx;
  60151. }
  60152. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  60153. {
  60154. int x, y;
  60155. getKeyPos (midiNoteNumber, x, y);
  60156. return x;
  60157. }
  60158. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  60159. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  60160. int MidiKeyboardComponent::xyToNote (int x, int y, float& mousePositionVelocity)
  60161. {
  60162. if (! reallyContains (x, y, false))
  60163. return -1;
  60164. if (orientation != horizontalKeyboard)
  60165. {
  60166. swapVariables (x, y);
  60167. if (orientation == verticalKeyboardFacingLeft)
  60168. y = getWidth() - y;
  60169. else
  60170. x = getHeight() - x;
  60171. }
  60172. return remappedXYToNote (x + xOffset, y, mousePositionVelocity);
  60173. }
  60174. int MidiKeyboardComponent::remappedXYToNote (int x, int y, float& mousePositionVelocity) const
  60175. {
  60176. if (y < blackNoteLength)
  60177. {
  60178. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60179. {
  60180. for (int i = 0; i < 5; ++i)
  60181. {
  60182. const int note = octaveStart + blackNotes [i];
  60183. if (note >= rangeStart && note <= rangeEnd)
  60184. {
  60185. int kx, kw;
  60186. getKeyPos (note, kx, kw);
  60187. kx += xOffset;
  60188. if (x >= kx && x < kx + kw)
  60189. {
  60190. mousePositionVelocity = y / (float) blackNoteLength;
  60191. return note;
  60192. }
  60193. }
  60194. }
  60195. }
  60196. }
  60197. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60198. {
  60199. for (int i = 0; i < 7; ++i)
  60200. {
  60201. const int note = octaveStart + whiteNotes [i];
  60202. if (note >= rangeStart && note <= rangeEnd)
  60203. {
  60204. int kx, kw;
  60205. getKeyPos (note, kx, kw);
  60206. kx += xOffset;
  60207. if (x >= kx && x < kx + kw)
  60208. {
  60209. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  60210. mousePositionVelocity = y / (float) whiteNoteLength;
  60211. return note;
  60212. }
  60213. }
  60214. }
  60215. }
  60216. mousePositionVelocity = 0;
  60217. return -1;
  60218. }
  60219. void MidiKeyboardComponent::repaintNote (const int noteNum)
  60220. {
  60221. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60222. {
  60223. int x, w;
  60224. getKeyPos (noteNum, x, w);
  60225. if (orientation == horizontalKeyboard)
  60226. repaint (x, 0, w, getHeight());
  60227. else if (orientation == verticalKeyboardFacingLeft)
  60228. repaint (0, x, getWidth(), w);
  60229. else if (orientation == verticalKeyboardFacingRight)
  60230. repaint (0, getHeight() - x - w, getWidth(), w);
  60231. }
  60232. }
  60233. void MidiKeyboardComponent::paint (Graphics& g)
  60234. {
  60235. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  60236. const Colour lineColour (findColour (keySeparatorLineColourId));
  60237. const Colour textColour (findColour (textLabelColourId));
  60238. int x, w, octave;
  60239. for (octave = 0; octave < 128; octave += 12)
  60240. {
  60241. for (int white = 0; white < 7; ++white)
  60242. {
  60243. const int noteNum = octave + whiteNotes [white];
  60244. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60245. {
  60246. getKeyPos (noteNum, x, w);
  60247. if (orientation == horizontalKeyboard)
  60248. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  60249. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60250. noteUnderMouse == noteNum,
  60251. lineColour, textColour);
  60252. else if (orientation == verticalKeyboardFacingLeft)
  60253. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  60254. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60255. noteUnderMouse == noteNum,
  60256. lineColour, textColour);
  60257. else if (orientation == verticalKeyboardFacingRight)
  60258. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  60259. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60260. noteUnderMouse == noteNum,
  60261. lineColour, textColour);
  60262. }
  60263. }
  60264. }
  60265. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  60266. if (orientation == verticalKeyboardFacingLeft)
  60267. {
  60268. x1 = getWidth() - 1.0f;
  60269. x2 = getWidth() - 5.0f;
  60270. }
  60271. else if (orientation == verticalKeyboardFacingRight)
  60272. x2 = 5.0f;
  60273. else
  60274. y2 = 5.0f;
  60275. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  60276. Colours::transparentBlack, x2, y2, false));
  60277. getKeyPos (rangeEnd, x, w);
  60278. x += w;
  60279. if (orientation == verticalKeyboardFacingLeft)
  60280. g.fillRect (getWidth() - 5, 0, 5, x);
  60281. else if (orientation == verticalKeyboardFacingRight)
  60282. g.fillRect (0, 0, 5, x);
  60283. else
  60284. g.fillRect (0, 0, x, 5);
  60285. g.setColour (lineColour);
  60286. if (orientation == verticalKeyboardFacingLeft)
  60287. g.fillRect (0, 0, 1, x);
  60288. else if (orientation == verticalKeyboardFacingRight)
  60289. g.fillRect (getWidth() - 1, 0, 1, x);
  60290. else
  60291. g.fillRect (0, getHeight() - 1, x, 1);
  60292. const Colour blackNoteColour (findColour (blackNoteColourId));
  60293. for (octave = 0; octave < 128; octave += 12)
  60294. {
  60295. for (int black = 0; black < 5; ++black)
  60296. {
  60297. const int noteNum = octave + blackNotes [black];
  60298. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60299. {
  60300. getKeyPos (noteNum, x, w);
  60301. if (orientation == horizontalKeyboard)
  60302. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  60303. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60304. noteUnderMouse == noteNum,
  60305. blackNoteColour);
  60306. else if (orientation == verticalKeyboardFacingLeft)
  60307. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  60308. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60309. noteUnderMouse == noteNum,
  60310. blackNoteColour);
  60311. else if (orientation == verticalKeyboardFacingRight)
  60312. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  60313. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60314. noteUnderMouse == noteNum,
  60315. blackNoteColour);
  60316. }
  60317. }
  60318. }
  60319. }
  60320. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  60321. Graphics& g, int x, int y, int w, int h,
  60322. bool isDown, bool isOver,
  60323. const Colour& lineColour,
  60324. const Colour& textColour)
  60325. {
  60326. Colour c (Colours::transparentWhite);
  60327. if (isDown)
  60328. c = findColour (keyDownOverlayColourId);
  60329. if (isOver)
  60330. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60331. g.setColour (c);
  60332. g.fillRect (x, y, w, h);
  60333. const String text (getWhiteNoteText (midiNoteNumber));
  60334. if (! text.isEmpty())
  60335. {
  60336. g.setColour (textColour);
  60337. Font f (jmin (12.0f, keyWidth * 0.9f));
  60338. f.setHorizontalScale (0.8f);
  60339. g.setFont (f);
  60340. Justification justification (Justification::centredBottom);
  60341. if (orientation == verticalKeyboardFacingLeft)
  60342. justification = Justification::centredLeft;
  60343. else if (orientation == verticalKeyboardFacingRight)
  60344. justification = Justification::centredRight;
  60345. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  60346. }
  60347. g.setColour (lineColour);
  60348. if (orientation == horizontalKeyboard)
  60349. g.fillRect (x, y, 1, h);
  60350. else if (orientation == verticalKeyboardFacingLeft)
  60351. g.fillRect (x, y, w, 1);
  60352. else if (orientation == verticalKeyboardFacingRight)
  60353. g.fillRect (x, y + h - 1, w, 1);
  60354. if (midiNoteNumber == rangeEnd)
  60355. {
  60356. if (orientation == horizontalKeyboard)
  60357. g.fillRect (x + w, y, 1, h);
  60358. else if (orientation == verticalKeyboardFacingLeft)
  60359. g.fillRect (x, y + h, w, 1);
  60360. else if (orientation == verticalKeyboardFacingRight)
  60361. g.fillRect (x, y - 1, w, 1);
  60362. }
  60363. }
  60364. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  60365. Graphics& g, int x, int y, int w, int h,
  60366. bool isDown, bool isOver,
  60367. const Colour& noteFillColour)
  60368. {
  60369. Colour c (noteFillColour);
  60370. if (isDown)
  60371. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  60372. if (isOver)
  60373. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60374. g.setColour (c);
  60375. g.fillRect (x, y, w, h);
  60376. if (isDown)
  60377. {
  60378. g.setColour (noteFillColour);
  60379. g.drawRect (x, y, w, h);
  60380. }
  60381. else
  60382. {
  60383. const int xIndent = jmax (1, jmin (w, h) / 8);
  60384. g.setColour (c.brighter());
  60385. if (orientation == horizontalKeyboard)
  60386. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  60387. else if (orientation == verticalKeyboardFacingLeft)
  60388. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  60389. else if (orientation == verticalKeyboardFacingRight)
  60390. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  60391. }
  60392. }
  60393. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  60394. {
  60395. octaveNumForMiddleC = octaveNumForMiddleC_;
  60396. repaint();
  60397. }
  60398. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  60399. {
  60400. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  60401. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  60402. return String::empty;
  60403. }
  60404. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  60405. const bool isMouseOver,
  60406. const bool isButtonDown,
  60407. const bool movesOctavesUp)
  60408. {
  60409. g.fillAll (findColour (upDownButtonBackgroundColourId));
  60410. float angle;
  60411. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60412. angle = movesOctavesUp ? 0.0f : 0.5f;
  60413. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60414. angle = movesOctavesUp ? 0.25f : 0.75f;
  60415. else
  60416. angle = movesOctavesUp ? 0.75f : 0.25f;
  60417. Path path;
  60418. path.lineTo (0.0f, 1.0f);
  60419. path.lineTo (1.0f, 0.5f);
  60420. path.closeSubPath();
  60421. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60422. g.setColour (findColour (upDownButtonArrowColourId)
  60423. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60424. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60425. w - 2.0f,
  60426. h - 2.0f,
  60427. true));
  60428. }
  60429. void MidiKeyboardComponent::resized()
  60430. {
  60431. int w = getWidth();
  60432. int h = getHeight();
  60433. if (w > 0 && h > 0)
  60434. {
  60435. if (orientation != horizontalKeyboard)
  60436. swapVariables (w, h);
  60437. blackNoteLength = roundToInt (h * 0.7f);
  60438. int kx2, kw2;
  60439. getKeyPos (rangeEnd, kx2, kw2);
  60440. kx2 += kw2;
  60441. if (firstKey != rangeStart)
  60442. {
  60443. int kx1, kw1;
  60444. getKeyPos (rangeStart, kx1, kw1);
  60445. if (kx2 - kx1 <= w)
  60446. {
  60447. firstKey = rangeStart;
  60448. sendChangeMessage (this);
  60449. repaint();
  60450. }
  60451. }
  60452. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60453. scrollDown->setVisible (showScrollButtons);
  60454. scrollUp->setVisible (showScrollButtons);
  60455. xOffset = 0;
  60456. if (showScrollButtons)
  60457. {
  60458. const int scrollButtonW = jmin (12, w / 2);
  60459. if (orientation == horizontalKeyboard)
  60460. {
  60461. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60462. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60463. }
  60464. else if (orientation == verticalKeyboardFacingLeft)
  60465. {
  60466. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60467. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60468. }
  60469. else if (orientation == verticalKeyboardFacingRight)
  60470. {
  60471. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60472. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60473. }
  60474. int endOfLastKey, kw;
  60475. getKeyPos (rangeEnd, endOfLastKey, kw);
  60476. endOfLastKey += kw;
  60477. float mousePositionVelocity;
  60478. const int spaceAvailable = w - scrollButtonW * 2;
  60479. const int lastStartKey = remappedXYToNote (endOfLastKey - spaceAvailable, 0, mousePositionVelocity) + 1;
  60480. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60481. {
  60482. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60483. sendChangeMessage (this);
  60484. }
  60485. int newOffset = 0;
  60486. getKeyPos (firstKey, newOffset, kw);
  60487. xOffset = newOffset - scrollButtonW;
  60488. }
  60489. else
  60490. {
  60491. firstKey = rangeStart;
  60492. }
  60493. timerCallback();
  60494. repaint();
  60495. }
  60496. }
  60497. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60498. {
  60499. triggerAsyncUpdate();
  60500. }
  60501. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60502. {
  60503. triggerAsyncUpdate();
  60504. }
  60505. void MidiKeyboardComponent::handleAsyncUpdate()
  60506. {
  60507. for (int i = rangeStart; i <= rangeEnd; ++i)
  60508. {
  60509. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60510. {
  60511. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60512. repaintNote (i);
  60513. }
  60514. }
  60515. }
  60516. void MidiKeyboardComponent::resetAnyKeysInUse()
  60517. {
  60518. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60519. {
  60520. state.allNotesOff (midiChannel);
  60521. keysPressed.clear();
  60522. mouseDownNote = -1;
  60523. }
  60524. }
  60525. void MidiKeyboardComponent::updateNoteUnderMouse (int x, int y)
  60526. {
  60527. float mousePositionVelocity = 0.0f;
  60528. const int newNote = (mouseDragging || isMouseOver())
  60529. ? xyToNote (x, y, mousePositionVelocity) : -1;
  60530. if (noteUnderMouse != newNote)
  60531. {
  60532. if (mouseDownNote >= 0)
  60533. {
  60534. state.noteOff (midiChannel, mouseDownNote);
  60535. mouseDownNote = -1;
  60536. }
  60537. if (mouseDragging && newNote >= 0)
  60538. {
  60539. if (! useMousePositionForVelocity)
  60540. mousePositionVelocity = 1.0f;
  60541. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60542. mouseDownNote = newNote;
  60543. }
  60544. repaintNote (noteUnderMouse);
  60545. noteUnderMouse = newNote;
  60546. repaintNote (noteUnderMouse);
  60547. }
  60548. else if (mouseDownNote >= 0 && ! mouseDragging)
  60549. {
  60550. state.noteOff (midiChannel, mouseDownNote);
  60551. mouseDownNote = -1;
  60552. }
  60553. }
  60554. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60555. {
  60556. updateNoteUnderMouse (e.x, e.y);
  60557. stopTimer();
  60558. }
  60559. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60560. {
  60561. float mousePositionVelocity;
  60562. const int newNote = xyToNote (e.x, e.y, mousePositionVelocity);
  60563. if (newNote >= 0)
  60564. mouseDraggedToKey (newNote, e);
  60565. updateNoteUnderMouse (e.x, e.y);
  60566. }
  60567. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60568. {
  60569. return true;
  60570. }
  60571. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60572. {
  60573. }
  60574. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60575. {
  60576. float mousePositionVelocity;
  60577. const int newNote = xyToNote (e.x, e.y, mousePositionVelocity);
  60578. mouseDragging = false;
  60579. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60580. {
  60581. repaintNote (noteUnderMouse);
  60582. noteUnderMouse = -1;
  60583. mouseDragging = true;
  60584. updateNoteUnderMouse (e.x, e.y);
  60585. startTimer (500);
  60586. }
  60587. }
  60588. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60589. {
  60590. mouseDragging = false;
  60591. updateNoteUnderMouse (e.x, e.y);
  60592. stopTimer();
  60593. }
  60594. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60595. {
  60596. updateNoteUnderMouse (e.x, e.y);
  60597. }
  60598. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60599. {
  60600. updateNoteUnderMouse (e.x, e.y);
  60601. }
  60602. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60603. {
  60604. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60605. }
  60606. void MidiKeyboardComponent::timerCallback()
  60607. {
  60608. int mx, my;
  60609. getMouseXYRelative (mx, my);
  60610. updateNoteUnderMouse (mx, my);
  60611. }
  60612. void MidiKeyboardComponent::clearKeyMappings()
  60613. {
  60614. resetAnyKeysInUse();
  60615. keyPressNotes.clear();
  60616. keyPresses.clear();
  60617. }
  60618. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60619. const int midiNoteOffsetFromC)
  60620. {
  60621. removeKeyPressForNote (midiNoteOffsetFromC);
  60622. keyPressNotes.add (midiNoteOffsetFromC);
  60623. keyPresses.add (key);
  60624. }
  60625. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60626. {
  60627. for (int i = keyPressNotes.size(); --i >= 0;)
  60628. {
  60629. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60630. {
  60631. keyPressNotes.remove (i);
  60632. keyPresses.remove (i);
  60633. }
  60634. }
  60635. }
  60636. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60637. {
  60638. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60639. keyMappingOctave = newOctaveNumber;
  60640. }
  60641. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60642. {
  60643. bool keyPressUsed = false;
  60644. for (int i = keyPresses.size(); --i >= 0;)
  60645. {
  60646. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60647. if (keyPresses.getReference(i).isCurrentlyDown())
  60648. {
  60649. if (! keysPressed [note])
  60650. {
  60651. keysPressed.setBit (note);
  60652. state.noteOn (midiChannel, note, velocity);
  60653. keyPressUsed = true;
  60654. }
  60655. }
  60656. else
  60657. {
  60658. if (keysPressed [note])
  60659. {
  60660. keysPressed.clearBit (note);
  60661. state.noteOff (midiChannel, note);
  60662. keyPressUsed = true;
  60663. }
  60664. }
  60665. }
  60666. return keyPressUsed;
  60667. }
  60668. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60669. {
  60670. resetAnyKeysInUse();
  60671. }
  60672. END_JUCE_NAMESPACE
  60673. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60674. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60675. #if JUCE_OPENGL
  60676. BEGIN_JUCE_NAMESPACE
  60677. extern void juce_glViewport (const int w, const int h);
  60678. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60679. const int alphaBits_,
  60680. const int depthBufferBits_,
  60681. const int stencilBufferBits_) throw()
  60682. : redBits (bitsPerRGBComponent),
  60683. greenBits (bitsPerRGBComponent),
  60684. blueBits (bitsPerRGBComponent),
  60685. alphaBits (alphaBits_),
  60686. depthBufferBits (depthBufferBits_),
  60687. stencilBufferBits (stencilBufferBits_),
  60688. accumulationBufferRedBits (0),
  60689. accumulationBufferGreenBits (0),
  60690. accumulationBufferBlueBits (0),
  60691. accumulationBufferAlphaBits (0),
  60692. fullSceneAntiAliasingNumSamples (0)
  60693. {
  60694. }
  60695. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const throw()
  60696. {
  60697. return memcmp (this, &other, sizeof (other)) == 0;
  60698. }
  60699. static VoidArray knownContexts;
  60700. OpenGLContext::OpenGLContext() throw()
  60701. {
  60702. knownContexts.add (this);
  60703. }
  60704. OpenGLContext::~OpenGLContext()
  60705. {
  60706. knownContexts.removeValue (this);
  60707. }
  60708. OpenGLContext* OpenGLContext::getCurrentContext()
  60709. {
  60710. for (int i = knownContexts.size(); --i >= 0;)
  60711. {
  60712. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60713. if (oglc->isActive())
  60714. return oglc;
  60715. }
  60716. return 0;
  60717. }
  60718. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60719. {
  60720. public:
  60721. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60722. : ComponentMovementWatcher (owner_),
  60723. owner (owner_),
  60724. wasShowing (false)
  60725. {
  60726. }
  60727. ~OpenGLComponentWatcher() {}
  60728. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60729. {
  60730. owner->updateContextPosition();
  60731. }
  60732. void componentPeerChanged()
  60733. {
  60734. const ScopedLock sl (owner->getContextLock());
  60735. owner->deleteContext();
  60736. }
  60737. void componentVisibilityChanged (Component&)
  60738. {
  60739. const bool isShowingNow = owner->isShowing();
  60740. if (wasShowing != isShowingNow)
  60741. {
  60742. wasShowing = isShowingNow;
  60743. owner->updateContextPosition();
  60744. }
  60745. }
  60746. juce_UseDebuggingNewOperator
  60747. private:
  60748. OpenGLComponent* const owner;
  60749. bool wasShowing;
  60750. };
  60751. OpenGLComponent::OpenGLComponent()
  60752. : context (0),
  60753. contextToShareListsWith (0),
  60754. needToUpdateViewport (true)
  60755. {
  60756. setOpaque (true);
  60757. componentWatcher = new OpenGLComponentWatcher (this);
  60758. }
  60759. OpenGLComponent::~OpenGLComponent()
  60760. {
  60761. deleteContext();
  60762. componentWatcher = 0;
  60763. }
  60764. void OpenGLComponent::deleteContext()
  60765. {
  60766. const ScopedLock sl (contextLock);
  60767. deleteAndZero (context);
  60768. }
  60769. void OpenGLComponent::updateContextPosition()
  60770. {
  60771. needToUpdateViewport = true;
  60772. if (getWidth() > 0 && getHeight() > 0)
  60773. {
  60774. Component* const topComp = getTopLevelComponent();
  60775. if (topComp->getPeer() != 0)
  60776. {
  60777. const ScopedLock sl (contextLock);
  60778. if (context != 0)
  60779. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60780. getScreenY() - topComp->getScreenY(),
  60781. getWidth(),
  60782. getHeight(),
  60783. topComp->getHeight());
  60784. }
  60785. }
  60786. }
  60787. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60788. {
  60789. OpenGLPixelFormat pf;
  60790. const ScopedLock sl (contextLock);
  60791. if (context != 0)
  60792. pf = context->getPixelFormat();
  60793. return pf;
  60794. }
  60795. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60796. {
  60797. if (! (preferredPixelFormat == formatToUse))
  60798. {
  60799. const ScopedLock sl (contextLock);
  60800. deleteContext();
  60801. preferredPixelFormat = formatToUse;
  60802. }
  60803. }
  60804. void OpenGLComponent::shareWith (OpenGLContext* c)
  60805. {
  60806. if (contextToShareListsWith != c)
  60807. {
  60808. const ScopedLock sl (contextLock);
  60809. deleteContext();
  60810. contextToShareListsWith = c;
  60811. }
  60812. }
  60813. bool OpenGLComponent::makeCurrentContextActive()
  60814. {
  60815. if (context == 0)
  60816. {
  60817. const ScopedLock sl (contextLock);
  60818. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60819. {
  60820. context = OpenGLContext::createContextForWindow (this,
  60821. preferredPixelFormat,
  60822. contextToShareListsWith);
  60823. if (context != 0)
  60824. {
  60825. updateContextPosition();
  60826. if (context->makeActive())
  60827. newOpenGLContextCreated();
  60828. }
  60829. }
  60830. }
  60831. return context != 0 && context->makeActive();
  60832. }
  60833. void OpenGLComponent::makeCurrentContextInactive()
  60834. {
  60835. if (context != 0)
  60836. context->makeInactive();
  60837. }
  60838. bool OpenGLComponent::isActiveContext() const throw()
  60839. {
  60840. return context != 0 && context->isActive();
  60841. }
  60842. void OpenGLComponent::swapBuffers()
  60843. {
  60844. if (context != 0)
  60845. context->swapBuffers();
  60846. }
  60847. void OpenGLComponent::paint (Graphics&)
  60848. {
  60849. if (renderAndSwapBuffers())
  60850. {
  60851. ComponentPeer* const peer = getPeer();
  60852. if (peer != 0)
  60853. {
  60854. peer->addMaskedRegion (getScreenX() - peer->getScreenX(),
  60855. getScreenY() - peer->getScreenY(),
  60856. getWidth(), getHeight());
  60857. }
  60858. }
  60859. }
  60860. bool OpenGLComponent::renderAndSwapBuffers()
  60861. {
  60862. const ScopedLock sl (contextLock);
  60863. if (! makeCurrentContextActive())
  60864. return false;
  60865. if (needToUpdateViewport)
  60866. {
  60867. needToUpdateViewport = false;
  60868. juce_glViewport (getWidth(), getHeight());
  60869. }
  60870. renderOpenGL();
  60871. swapBuffers();
  60872. return true;
  60873. }
  60874. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60875. {
  60876. Component::internalRepaint (x, y, w, h);
  60877. if (context != 0)
  60878. context->repaint();
  60879. }
  60880. END_JUCE_NAMESPACE
  60881. #endif
  60882. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60883. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60884. BEGIN_JUCE_NAMESPACE
  60885. PreferencesPanel::PreferencesPanel()
  60886. : buttonSize (70)
  60887. {
  60888. }
  60889. PreferencesPanel::~PreferencesPanel()
  60890. {
  60891. currentPage = 0;
  60892. deleteAllChildren();
  60893. }
  60894. void PreferencesPanel::addSettingsPage (const String& title,
  60895. const Drawable* icon,
  60896. const Drawable* overIcon,
  60897. const Drawable* downIcon)
  60898. {
  60899. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60900. button->setImages (icon, overIcon, downIcon);
  60901. button->setRadioGroupId (1);
  60902. button->addButtonListener (this);
  60903. button->setClickingTogglesState (true);
  60904. button->setWantsKeyboardFocus (false);
  60905. addAndMakeVisible (button);
  60906. resized();
  60907. if (currentPage == 0)
  60908. setCurrentPage (title);
  60909. }
  60910. void PreferencesPanel::addSettingsPage (const String& title,
  60911. const char* imageData,
  60912. const int imageDataSize)
  60913. {
  60914. DrawableImage icon, iconOver, iconDown;
  60915. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60916. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60917. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60918. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60919. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60920. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60921. }
  60922. class PrefsDialogWindow : public DialogWindow
  60923. {
  60924. public:
  60925. PrefsDialogWindow (const String& dialogtitle,
  60926. const Colour& backgroundColour)
  60927. : DialogWindow (dialogtitle, backgroundColour, true)
  60928. {
  60929. }
  60930. ~PrefsDialogWindow()
  60931. {
  60932. }
  60933. void closeButtonPressed()
  60934. {
  60935. exitModalState (0);
  60936. }
  60937. private:
  60938. PrefsDialogWindow (const PrefsDialogWindow&);
  60939. const PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60940. };
  60941. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60942. int dialogWidth,
  60943. int dialogHeight,
  60944. const Colour& backgroundColour)
  60945. {
  60946. setSize (dialogWidth, dialogHeight);
  60947. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60948. dw.setContentComponent (this, true, true);
  60949. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60950. dw.runModalLoop();
  60951. dw.setContentComponent (0, false, false);
  60952. }
  60953. void PreferencesPanel::resized()
  60954. {
  60955. int x = 0;
  60956. for (int i = 0; i < getNumChildComponents(); ++i)
  60957. {
  60958. Component* c = getChildComponent (i);
  60959. if (dynamic_cast <DrawableButton*> (c) == 0)
  60960. {
  60961. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60962. }
  60963. else
  60964. {
  60965. c->setBounds (x, 0, buttonSize, buttonSize);
  60966. x += buttonSize;
  60967. }
  60968. }
  60969. }
  60970. void PreferencesPanel::paint (Graphics& g)
  60971. {
  60972. g.setColour (Colours::grey);
  60973. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60974. }
  60975. void PreferencesPanel::setCurrentPage (const String& pageName)
  60976. {
  60977. if (currentPageName != pageName)
  60978. {
  60979. currentPageName = pageName;
  60980. currentPage = 0;
  60981. currentPage = createComponentForPage (pageName);
  60982. if (currentPage != 0)
  60983. {
  60984. addAndMakeVisible (currentPage);
  60985. currentPage->toBack();
  60986. resized();
  60987. }
  60988. for (int i = 0; i < getNumChildComponents(); ++i)
  60989. {
  60990. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60991. if (db != 0 && db->getName() == pageName)
  60992. {
  60993. db->setToggleState (true, false);
  60994. break;
  60995. }
  60996. }
  60997. }
  60998. }
  60999. void PreferencesPanel::buttonClicked (Button*)
  61000. {
  61001. for (int i = 0; i < getNumChildComponents(); ++i)
  61002. {
  61003. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  61004. if (db != 0 && db->getToggleState())
  61005. {
  61006. setCurrentPage (db->getName());
  61007. break;
  61008. }
  61009. }
  61010. }
  61011. END_JUCE_NAMESPACE
  61012. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  61013. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  61014. #if JUCE_WINDOWS || JUCE_LINUX
  61015. BEGIN_JUCE_NAMESPACE
  61016. SystemTrayIconComponent::SystemTrayIconComponent()
  61017. {
  61018. addToDesktop (0);
  61019. }
  61020. SystemTrayIconComponent::~SystemTrayIconComponent()
  61021. {
  61022. }
  61023. END_JUCE_NAMESPACE
  61024. #endif
  61025. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  61026. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  61027. BEGIN_JUCE_NAMESPACE
  61028. static const int titleH = 24;
  61029. static const int iconWidth = 80;
  61030. class AlertWindowTextEditor : public TextEditor
  61031. {
  61032. public:
  61033. static const tchar passwordChar;
  61034. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  61035. : TextEditor (name, isPasswordBox ? passwordChar : 0)
  61036. {
  61037. setSelectAllWhenFocused (true);
  61038. }
  61039. ~AlertWindowTextEditor()
  61040. {
  61041. }
  61042. void returnPressed()
  61043. {
  61044. // pass these up the component hierarchy to be trigger the buttons
  61045. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, T('\n')));
  61046. }
  61047. void escapePressed()
  61048. {
  61049. // pass these up the component hierarchy to be trigger the buttons
  61050. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  61051. }
  61052. private:
  61053. AlertWindowTextEditor (const AlertWindowTextEditor&);
  61054. const AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  61055. };
  61056. #if JUCE_LINUX
  61057. const tchar AlertWindowTextEditor::passwordChar = 0x2022;
  61058. #else
  61059. const tchar AlertWindowTextEditor::passwordChar = 0x25cf;
  61060. #endif
  61061. AlertWindow::AlertWindow (const String& title,
  61062. const String& message,
  61063. AlertIconType iconType,
  61064. Component* associatedComponent_)
  61065. : TopLevelWindow (title, true),
  61066. alertIconType (iconType),
  61067. associatedComponent (associatedComponent_)
  61068. {
  61069. if (message.isEmpty())
  61070. text = T(" "); // to force an update if the message is empty
  61071. setMessage (message);
  61072. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  61073. {
  61074. Component* const c = Desktop::getInstance().getComponent (i);
  61075. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  61076. {
  61077. setAlwaysOnTop (true);
  61078. break;
  61079. }
  61080. }
  61081. if (JUCEApplication::getInstance() == 0)
  61082. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  61083. lookAndFeelChanged();
  61084. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  61085. }
  61086. AlertWindow::~AlertWindow()
  61087. {
  61088. for (int i = customComps.size(); --i >= 0;)
  61089. removeChildComponent ((Component*) customComps[i]);
  61090. deleteAllChildren();
  61091. }
  61092. void AlertWindow::userTriedToCloseWindow()
  61093. {
  61094. exitModalState (0);
  61095. }
  61096. void AlertWindow::setMessage (const String& message)
  61097. {
  61098. const String newMessage (message.substring (0, 2048));
  61099. if (text != newMessage)
  61100. {
  61101. text = newMessage;
  61102. font.setHeight (15.0f);
  61103. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  61104. textLayout.setText (getName() + T("\n\n"), titleFont);
  61105. textLayout.appendText (text, font);
  61106. updateLayout (true);
  61107. repaint();
  61108. }
  61109. }
  61110. void AlertWindow::buttonClicked (Button* button)
  61111. {
  61112. for (int i = 0; i < buttons.size(); i++)
  61113. {
  61114. TextButton* const c = (TextButton*) buttons[i];
  61115. if (button->getName() == c->getName())
  61116. {
  61117. if (c->getParentComponent() != 0)
  61118. c->getParentComponent()->exitModalState (c->getCommandID());
  61119. break;
  61120. }
  61121. }
  61122. }
  61123. void AlertWindow::addButton (const String& name,
  61124. const int returnValue,
  61125. const KeyPress& shortcutKey1,
  61126. const KeyPress& shortcutKey2)
  61127. {
  61128. TextButton* const b = new TextButton (name, String::empty);
  61129. b->setWantsKeyboardFocus (true);
  61130. b->setMouseClickGrabsKeyboardFocus (false);
  61131. b->setCommandToTrigger (0, returnValue, false);
  61132. b->addShortcut (shortcutKey1);
  61133. b->addShortcut (shortcutKey2);
  61134. b->addButtonListener (this);
  61135. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  61136. addAndMakeVisible (b, 0);
  61137. buttons.add (b);
  61138. updateLayout (false);
  61139. }
  61140. int AlertWindow::getNumButtons() const
  61141. {
  61142. return buttons.size();
  61143. }
  61144. void AlertWindow::addTextEditor (const String& name,
  61145. const String& initialContents,
  61146. const String& onScreenLabel,
  61147. const bool isPasswordBox)
  61148. {
  61149. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  61150. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  61151. tc->setFont (font);
  61152. tc->setText (initialContents);
  61153. tc->setCaretPosition (initialContents.length());
  61154. addAndMakeVisible (tc);
  61155. textBoxes.add (tc);
  61156. allComps.add (tc);
  61157. textboxNames.add (onScreenLabel);
  61158. updateLayout (false);
  61159. }
  61160. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  61161. {
  61162. for (int i = textBoxes.size(); --i >= 0;)
  61163. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  61164. return ((TextEditor*)textBoxes[i])->getText();
  61165. return String::empty;
  61166. }
  61167. void AlertWindow::addComboBox (const String& name,
  61168. const StringArray& items,
  61169. const String& onScreenLabel)
  61170. {
  61171. ComboBox* const cb = new ComboBox (name);
  61172. for (int i = 0; i < items.size(); ++i)
  61173. cb->addItem (items[i], i + 1);
  61174. addAndMakeVisible (cb);
  61175. cb->setSelectedItemIndex (0);
  61176. comboBoxes.add (cb);
  61177. allComps.add (cb);
  61178. comboBoxNames.add (onScreenLabel);
  61179. updateLayout (false);
  61180. }
  61181. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  61182. {
  61183. for (int i = comboBoxes.size(); --i >= 0;)
  61184. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  61185. return (ComboBox*) comboBoxes[i];
  61186. return 0;
  61187. }
  61188. class AlertTextComp : public TextEditor
  61189. {
  61190. AlertTextComp (const AlertTextComp&);
  61191. const AlertTextComp& operator= (const AlertTextComp&);
  61192. int bestWidth;
  61193. public:
  61194. AlertTextComp (const String& message,
  61195. const Font& font)
  61196. {
  61197. setReadOnly (true);
  61198. setMultiLine (true, true);
  61199. setCaretVisible (false);
  61200. setScrollbarsShown (true);
  61201. lookAndFeelChanged();
  61202. setWantsKeyboardFocus (false);
  61203. setFont (font);
  61204. setText (message, false);
  61205. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  61206. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  61207. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  61208. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  61209. }
  61210. ~AlertTextComp()
  61211. {
  61212. }
  61213. int getPreferredWidth() const throw() { return bestWidth; }
  61214. void updateLayout (const int width)
  61215. {
  61216. TextLayout text;
  61217. text.appendText (getText(), getFont());
  61218. text.layout (width - 8, Justification::topLeft, true);
  61219. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  61220. }
  61221. };
  61222. void AlertWindow::addTextBlock (const String& text)
  61223. {
  61224. AlertTextComp* const c = new AlertTextComp (text, font);
  61225. textBlocks.add (c);
  61226. allComps.add (c);
  61227. addAndMakeVisible (c);
  61228. updateLayout (false);
  61229. }
  61230. void AlertWindow::addProgressBarComponent (double& progressValue)
  61231. {
  61232. ProgressBar* const pb = new ProgressBar (progressValue);
  61233. progressBars.add (pb);
  61234. allComps.add (pb);
  61235. addAndMakeVisible (pb);
  61236. updateLayout (false);
  61237. }
  61238. void AlertWindow::addCustomComponent (Component* const component)
  61239. {
  61240. customComps.add (component);
  61241. allComps.add (component);
  61242. addAndMakeVisible (component);
  61243. updateLayout (false);
  61244. }
  61245. int AlertWindow::getNumCustomComponents() const
  61246. {
  61247. return customComps.size();
  61248. }
  61249. Component* AlertWindow::getCustomComponent (const int index) const
  61250. {
  61251. return (Component*) customComps [index];
  61252. }
  61253. Component* AlertWindow::removeCustomComponent (const int index)
  61254. {
  61255. Component* const c = getCustomComponent (index);
  61256. if (c != 0)
  61257. {
  61258. customComps.removeValue (c);
  61259. allComps.removeValue (c);
  61260. removeChildComponent (c);
  61261. updateLayout (false);
  61262. }
  61263. return c;
  61264. }
  61265. void AlertWindow::paint (Graphics& g)
  61266. {
  61267. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  61268. g.setColour (findColour (textColourId));
  61269. g.setFont (getLookAndFeel().getAlertWindowFont());
  61270. int i;
  61271. for (i = textBoxes.size(); --i >= 0;)
  61272. {
  61273. const TextEditor* const te = (TextEditor*) textBoxes[i];
  61274. g.drawFittedText (textboxNames[i],
  61275. te->getX(), te->getY() - 14,
  61276. te->getWidth(), 14,
  61277. Justification::centredLeft, 1);
  61278. }
  61279. for (i = comboBoxNames.size(); --i >= 0;)
  61280. {
  61281. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  61282. g.drawFittedText (comboBoxNames[i],
  61283. cb->getX(), cb->getY() - 14,
  61284. cb->getWidth(), 14,
  61285. Justification::centredLeft, 1);
  61286. }
  61287. for (i = customComps.size(); --i >= 0;)
  61288. {
  61289. const Component* const c = (Component*) customComps[i];
  61290. g.drawFittedText (c->getName(),
  61291. c->getX(), c->getY() - 14,
  61292. c->getWidth(), 14,
  61293. Justification::centredLeft, 1);
  61294. }
  61295. }
  61296. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  61297. {
  61298. const int wid = jmax (font.getStringWidth (text),
  61299. font.getStringWidth (getName()));
  61300. const int sw = (int) sqrt (font.getHeight() * wid);
  61301. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  61302. const int edgeGap = 10;
  61303. const int labelHeight = 18;
  61304. int iconSpace;
  61305. if (alertIconType == NoIcon)
  61306. {
  61307. textLayout.layout (w, Justification::horizontallyCentred, true);
  61308. iconSpace = 0;
  61309. }
  61310. else
  61311. {
  61312. textLayout.layout (w, Justification::left, true);
  61313. iconSpace = iconWidth;
  61314. }
  61315. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  61316. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61317. const int textLayoutH = textLayout.getHeight();
  61318. const int textBottom = 16 + titleH + textLayoutH;
  61319. int h = textBottom;
  61320. int buttonW = 40;
  61321. int i;
  61322. for (i = 0; i < buttons.size(); ++i)
  61323. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  61324. w = jmax (buttonW, w);
  61325. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  61326. if (buttons.size() > 0)
  61327. h += 20 + ((TextButton*) buttons[0])->getHeight();
  61328. for (i = customComps.size(); --i >= 0;)
  61329. {
  61330. Component* c = (Component*) customComps[i];
  61331. w = jmax (w, (c->getWidth() * 100) / 80);
  61332. h += 10 + c->getHeight();
  61333. if (c->getName().isNotEmpty())
  61334. h += labelHeight;
  61335. }
  61336. for (i = textBlocks.size(); --i >= 0;)
  61337. {
  61338. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61339. w = jmax (w, ac->getPreferredWidth());
  61340. }
  61341. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61342. for (i = textBlocks.size(); --i >= 0;)
  61343. {
  61344. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61345. ac->updateLayout ((int) (w * 0.8f));
  61346. h += ac->getHeight() + 10;
  61347. }
  61348. h = jmin (getParentHeight() - 50, h);
  61349. if (onlyIncreaseSize)
  61350. {
  61351. w = jmax (w, getWidth());
  61352. h = jmax (h, getHeight());
  61353. }
  61354. if (! isVisible())
  61355. {
  61356. centreAroundComponent (associatedComponent, w, h);
  61357. }
  61358. else
  61359. {
  61360. const int cx = getX() + getWidth() / 2;
  61361. const int cy = getY() + getHeight() / 2;
  61362. setBounds (cx - w / 2,
  61363. cy - h / 2,
  61364. w, h);
  61365. }
  61366. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  61367. const int spacer = 16;
  61368. int totalWidth = -spacer;
  61369. for (i = buttons.size(); --i >= 0;)
  61370. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  61371. int x = (w - totalWidth) / 2;
  61372. int y = (int) (getHeight() * 0.95f);
  61373. for (i = 0; i < buttons.size(); ++i)
  61374. {
  61375. TextButton* const c = (TextButton*) buttons[i];
  61376. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61377. c->setTopLeftPosition (x, ny);
  61378. if (ny < y)
  61379. y = ny;
  61380. x += c->getWidth() + spacer;
  61381. c->toFront (false);
  61382. }
  61383. y = textBottom;
  61384. for (i = 0; i < allComps.size(); ++i)
  61385. {
  61386. Component* const c = (Component*) allComps[i];
  61387. int h = 22;
  61388. const int comboIndex = comboBoxes.indexOf (c);
  61389. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61390. y += labelHeight;
  61391. const int tbIndex = textBoxes.indexOf (c);
  61392. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61393. y += labelHeight;
  61394. if (customComps.contains (c))
  61395. {
  61396. if (c->getName().isNotEmpty())
  61397. y += labelHeight;
  61398. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61399. h = c->getHeight();
  61400. }
  61401. else if (textBlocks.contains (c))
  61402. {
  61403. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61404. h = c->getHeight();
  61405. }
  61406. else
  61407. {
  61408. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61409. }
  61410. y += h + 10;
  61411. }
  61412. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61413. }
  61414. bool AlertWindow::containsAnyExtraComponents() const
  61415. {
  61416. return textBoxes.size()
  61417. + comboBoxes.size()
  61418. + progressBars.size()
  61419. + customComps.size() > 0;
  61420. }
  61421. void AlertWindow::mouseDown (const MouseEvent&)
  61422. {
  61423. dragger.startDraggingComponent (this, &constrainer);
  61424. }
  61425. void AlertWindow::mouseDrag (const MouseEvent& e)
  61426. {
  61427. dragger.dragComponent (this, e);
  61428. }
  61429. bool AlertWindow::keyPressed (const KeyPress& key)
  61430. {
  61431. for (int i = buttons.size(); --i >= 0;)
  61432. {
  61433. TextButton* const b = (TextButton*) buttons[i];
  61434. if (b->isRegisteredForShortcut (key))
  61435. {
  61436. b->triggerClick();
  61437. return true;
  61438. }
  61439. }
  61440. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61441. {
  61442. exitModalState (0);
  61443. return true;
  61444. }
  61445. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61446. {
  61447. ((TextButton*) buttons.getFirst())->triggerClick();
  61448. return true;
  61449. }
  61450. return false;
  61451. }
  61452. void AlertWindow::lookAndFeelChanged()
  61453. {
  61454. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61455. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61456. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61457. }
  61458. int AlertWindow::getDesktopWindowStyleFlags() const
  61459. {
  61460. return getLookAndFeel().getAlertBoxWindowFlags();
  61461. }
  61462. struct AlertWindowInfo
  61463. {
  61464. String title, message, button1, button2, button3;
  61465. AlertWindow::AlertIconType iconType;
  61466. int numButtons;
  61467. Component* associatedComponent;
  61468. int run() const
  61469. {
  61470. return (int) (pointer_sized_int)
  61471. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61472. }
  61473. private:
  61474. int show() const
  61475. {
  61476. jassert (associatedComponent == 0 || associatedComponent->isValidComponent()); // has your comp been deleted?
  61477. LookAndFeel& lf = associatedComponent->isValidComponent() ? associatedComponent->getLookAndFeel()
  61478. : LookAndFeel::getDefaultLookAndFeel();
  61479. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61480. iconType, numButtons, associatedComponent));
  61481. jassert (alertBox != 0); // you have to return one of these!
  61482. return alertBox->runModalLoop();
  61483. }
  61484. static void* showCallback (void* userData)
  61485. {
  61486. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61487. }
  61488. };
  61489. void AlertWindow::showMessageBox (AlertIconType iconType,
  61490. const String& title,
  61491. const String& message,
  61492. const String& buttonText,
  61493. Component* associatedComponent)
  61494. {
  61495. AlertWindowInfo info;
  61496. info.title = title;
  61497. info.message = message;
  61498. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61499. info.iconType = iconType;
  61500. info.numButtons = 1;
  61501. info.associatedComponent = associatedComponent;
  61502. info.run();
  61503. }
  61504. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61505. const String& title,
  61506. const String& message,
  61507. const String& button1Text,
  61508. const String& button2Text,
  61509. Component* associatedComponent)
  61510. {
  61511. AlertWindowInfo info;
  61512. info.title = title;
  61513. info.message = message;
  61514. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61515. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61516. info.iconType = iconType;
  61517. info.numButtons = 2;
  61518. info.associatedComponent = associatedComponent;
  61519. return info.run() != 0;
  61520. }
  61521. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61522. const String& title,
  61523. const String& message,
  61524. const String& button1Text,
  61525. const String& button2Text,
  61526. const String& button3Text,
  61527. Component* associatedComponent)
  61528. {
  61529. AlertWindowInfo info;
  61530. info.title = title;
  61531. info.message = message;
  61532. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61533. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61534. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61535. info.iconType = iconType;
  61536. info.numButtons = 3;
  61537. info.associatedComponent = associatedComponent;
  61538. return info.run();
  61539. }
  61540. END_JUCE_NAMESPACE
  61541. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61542. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61543. BEGIN_JUCE_NAMESPACE
  61544. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61545. static const int fakeMouseMoveMessage = 0x7fff00ff;
  61546. static VoidArray heavyweightPeers;
  61547. ComponentPeer::ComponentPeer (Component* const component_,
  61548. const int styleFlags_) throw()
  61549. : component (component_),
  61550. styleFlags (styleFlags_),
  61551. lastPaintTime (0),
  61552. constrainer (0),
  61553. lastFocusedComponent (0),
  61554. lastDragAndDropCompUnderMouse (0),
  61555. fakeMouseMessageSent (false),
  61556. isWindowMinimised (false)
  61557. {
  61558. heavyweightPeers.add (this);
  61559. }
  61560. ComponentPeer::~ComponentPeer()
  61561. {
  61562. heavyweightPeers.removeValue (this);
  61563. Desktop::getInstance().triggerFocusCallback();
  61564. }
  61565. int ComponentPeer::getNumPeers() throw()
  61566. {
  61567. return heavyweightPeers.size();
  61568. }
  61569. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61570. {
  61571. return (ComponentPeer*) heavyweightPeers [index];
  61572. }
  61573. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61574. {
  61575. for (int i = heavyweightPeers.size(); --i >= 0;)
  61576. {
  61577. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61578. if (peer->getComponent() == component)
  61579. return peer;
  61580. }
  61581. return 0;
  61582. }
  61583. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61584. {
  61585. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61586. }
  61587. void ComponentPeer::updateCurrentModifiers() throw()
  61588. {
  61589. ModifierKeys::updateCurrentModifiers();
  61590. }
  61591. void ComponentPeer::handleMouseEnter (int x, int y, const int64 time)
  61592. {
  61593. jassert (component->isValidComponent());
  61594. updateCurrentModifiers();
  61595. Component* c = component->getComponentAt (x, y);
  61596. const ComponentDeletionWatcher deletionChecker (component);
  61597. if (c != Component::componentUnderMouse && Component::componentUnderMouse != 0)
  61598. {
  61599. jassert (Component::componentUnderMouse->isValidComponent());
  61600. const int oldX = x;
  61601. const int oldY = y;
  61602. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61603. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61604. Component::componentUnderMouse = 0;
  61605. if (deletionChecker.hasBeenDeleted())
  61606. return;
  61607. c = component->getComponentAt (oldX, oldY);
  61608. }
  61609. Component::componentUnderMouse = c;
  61610. if (Component::componentUnderMouse != 0)
  61611. {
  61612. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61613. Component::componentUnderMouse->internalMouseEnter (x, y, time);
  61614. }
  61615. }
  61616. void ComponentPeer::handleMouseMove (int x, int y, const int64 time)
  61617. {
  61618. jassert (component->isValidComponent());
  61619. updateCurrentModifiers();
  61620. fakeMouseMessageSent = false;
  61621. const ComponentDeletionWatcher deletionChecker (component);
  61622. Component* c = component->getComponentAt (x, y);
  61623. if (c != Component::componentUnderMouse)
  61624. {
  61625. const int oldX = x;
  61626. const int oldY = y;
  61627. if (Component::componentUnderMouse != 0)
  61628. {
  61629. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61630. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61631. x = oldX;
  61632. y = oldY;
  61633. Component::componentUnderMouse = 0;
  61634. if (deletionChecker.hasBeenDeleted())
  61635. return; // if this window has just been deleted..
  61636. c = component->getComponentAt (x, y);
  61637. }
  61638. Component::componentUnderMouse = c;
  61639. if (c != 0)
  61640. {
  61641. component->relativePositionToOtherComponent (c, x, y);
  61642. c->internalMouseEnter (x, y, time);
  61643. x = oldX;
  61644. y = oldY;
  61645. if (deletionChecker.hasBeenDeleted())
  61646. return; // if this window has just been deleted..
  61647. }
  61648. }
  61649. if (Component::componentUnderMouse != 0)
  61650. {
  61651. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61652. Component::componentUnderMouse->internalMouseMove (x, y, time);
  61653. }
  61654. }
  61655. void ComponentPeer::handleMouseDown (int x, int y, const int64 time)
  61656. {
  61657. Desktop::getInstance().incrementMouseClickCounter();
  61658. updateCurrentModifiers();
  61659. if (ModifierKeys::getCurrentModifiers().getNumMouseButtonsDown() == 1)
  61660. {
  61661. Component::componentUnderMouse = component->getComponentAt (x, y);
  61662. if (Component::componentUnderMouse != 0)
  61663. {
  61664. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61665. Component::componentUnderMouse->internalMouseDown (x, y, time);
  61666. }
  61667. }
  61668. }
  61669. void ComponentPeer::handleMouseDrag (int x, int y, const int64 time)
  61670. {
  61671. updateCurrentModifiers();
  61672. if (Component::componentUnderMouse != 0)
  61673. {
  61674. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61675. Component::componentUnderMouse->internalMouseDrag (x, y, time);
  61676. }
  61677. }
  61678. void ComponentPeer::handleMouseUp (const int oldModifiers, int x, int y, const int64 time)
  61679. {
  61680. updateCurrentModifiers();
  61681. if (ModifierKeys (oldModifiers).getNumMouseButtonsDown() == 1)
  61682. {
  61683. const ComponentDeletionWatcher deletionChecker (component);
  61684. Component* c = component->getComponentAt (x, y);
  61685. if (c != Component::componentUnderMouse)
  61686. {
  61687. const int oldX = x;
  61688. const int oldY = y;
  61689. if (Component::componentUnderMouse != 0)
  61690. {
  61691. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61692. Component::componentUnderMouse->internalMouseUp (oldModifiers, x, y, time);
  61693. x = oldX;
  61694. y = oldY;
  61695. if (Component::componentUnderMouse != 0)
  61696. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61697. if (deletionChecker.hasBeenDeleted())
  61698. return;
  61699. c = component->getComponentAt (oldX, oldY);
  61700. }
  61701. Component::componentUnderMouse = c;
  61702. if (Component::componentUnderMouse != 0)
  61703. {
  61704. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61705. Component::componentUnderMouse->internalMouseEnter (x, y, time);
  61706. }
  61707. }
  61708. else
  61709. {
  61710. if (Component::componentUnderMouse != 0)
  61711. {
  61712. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61713. Component::componentUnderMouse->internalMouseUp (oldModifiers, x, y, time);
  61714. }
  61715. }
  61716. }
  61717. }
  61718. void ComponentPeer::handleMouseExit (int x, int y, const int64 time)
  61719. {
  61720. jassert (component->isValidComponent());
  61721. updateCurrentModifiers();
  61722. if (Component::componentUnderMouse != 0)
  61723. {
  61724. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61725. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61726. Component::componentUnderMouse = 0;
  61727. }
  61728. }
  61729. void ComponentPeer::handleMouseWheel (const int amountX, const int amountY, const int64 time)
  61730. {
  61731. updateCurrentModifiers();
  61732. if (Component::componentUnderMouse != 0)
  61733. Component::componentUnderMouse->internalMouseWheel (amountX, amountY, time);
  61734. }
  61735. void ComponentPeer::sendFakeMouseMove() throw()
  61736. {
  61737. if ((! fakeMouseMessageSent)
  61738. && component->flags.hasHeavyweightPeerFlag
  61739. && ! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  61740. {
  61741. if (! isMinimised())
  61742. {
  61743. int realX, realY, realW, realH;
  61744. getBounds (realX, realY, realW, realH);
  61745. component->bounds_.setBounds (realX, realY, realW, realH);
  61746. }
  61747. int x, y;
  61748. component->getMouseXYRelative (x, y);
  61749. if (((unsigned int) x) < (unsigned int) component->getWidth()
  61750. && ((unsigned int) y) < (unsigned int) component->getHeight()
  61751. && contains (x, y, false))
  61752. {
  61753. postMessage (new Message (fakeMouseMoveMessage, x, y, 0));
  61754. }
  61755. fakeMouseMessageSent = true;
  61756. }
  61757. }
  61758. void ComponentPeer::handleMessage (const Message& message)
  61759. {
  61760. if (message.intParameter1 == fakeMouseMoveMessage)
  61761. {
  61762. if (! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  61763. handleMouseMove (message.intParameter2,
  61764. message.intParameter3,
  61765. Time::currentTimeMillis());
  61766. }
  61767. }
  61768. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61769. {
  61770. Graphics g (&contextToPaintTo);
  61771. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61772. g.saveState();
  61773. #endif
  61774. JUCE_TRY
  61775. {
  61776. component->paintEntireComponent (g);
  61777. }
  61778. JUCE_CATCH_EXCEPTION
  61779. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61780. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61781. // clearly when things are being repainted.
  61782. {
  61783. g.restoreState();
  61784. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61785. (uint8) Random::getSystemRandom().nextInt (255),
  61786. (uint8) Random::getSystemRandom().nextInt (255),
  61787. (uint8) 0x50));
  61788. }
  61789. #endif
  61790. }
  61791. bool ComponentPeer::handleKeyPress (const int keyCode,
  61792. const juce_wchar textCharacter)
  61793. {
  61794. updateCurrentModifiers();
  61795. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61796. ? Component::currentlyFocusedComponent
  61797. : component;
  61798. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61799. {
  61800. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61801. if (currentModalComp != 0)
  61802. target = currentModalComp;
  61803. }
  61804. const KeyPress keyInfo (keyCode,
  61805. ModifierKeys::getCurrentModifiers().getRawFlags()
  61806. & ModifierKeys::allKeyboardModifiers,
  61807. textCharacter);
  61808. bool keyWasUsed = false;
  61809. while (target != 0)
  61810. {
  61811. const ComponentDeletionWatcher deletionChecker (target);
  61812. if (target->keyListeners_ != 0)
  61813. {
  61814. for (int i = target->keyListeners_->size(); --i >= 0;)
  61815. {
  61816. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61817. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61818. return keyWasUsed;
  61819. i = jmin (i, target->keyListeners_->size());
  61820. }
  61821. }
  61822. keyWasUsed = target->keyPressed (keyInfo);
  61823. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61824. break;
  61825. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61826. {
  61827. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61828. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61829. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61830. break;
  61831. }
  61832. target = target->parentComponent_;
  61833. }
  61834. return keyWasUsed;
  61835. }
  61836. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61837. {
  61838. updateCurrentModifiers();
  61839. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61840. ? Component::currentlyFocusedComponent
  61841. : component;
  61842. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61843. {
  61844. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61845. if (currentModalComp != 0)
  61846. target = currentModalComp;
  61847. }
  61848. bool keyWasUsed = false;
  61849. while (target != 0)
  61850. {
  61851. const ComponentDeletionWatcher deletionChecker (target);
  61852. keyWasUsed = target->keyStateChanged (isKeyDown);
  61853. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61854. break;
  61855. if (target->keyListeners_ != 0)
  61856. {
  61857. for (int i = target->keyListeners_->size(); --i >= 0;)
  61858. {
  61859. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61860. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61861. return keyWasUsed;
  61862. i = jmin (i, target->keyListeners_->size());
  61863. }
  61864. }
  61865. target = target->parentComponent_;
  61866. }
  61867. return keyWasUsed;
  61868. }
  61869. void ComponentPeer::handleModifierKeysChange()
  61870. {
  61871. updateCurrentModifiers();
  61872. Component* target = Component::getComponentUnderMouse();
  61873. if (target == 0)
  61874. target = Component::getCurrentlyFocusedComponent();
  61875. if (target == 0)
  61876. target = component;
  61877. if (target->isValidComponent())
  61878. target->internalModifierKeysChanged();
  61879. }
  61880. void ComponentPeer::handleBroughtToFront()
  61881. {
  61882. updateCurrentModifiers();
  61883. if (component != 0)
  61884. component->internalBroughtToFront();
  61885. }
  61886. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61887. {
  61888. constrainer = newConstrainer;
  61889. }
  61890. void ComponentPeer::handleMovedOrResized()
  61891. {
  61892. jassert (component->isValidComponent());
  61893. updateCurrentModifiers();
  61894. const bool nowMinimised = isMinimised();
  61895. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61896. {
  61897. const ComponentDeletionWatcher deletionChecker (component);
  61898. int realX, realY, realW, realH;
  61899. getBounds (realX, realY, realW, realH);
  61900. const bool wasMoved = (component->getX() != realX || component->getY() != realY);
  61901. const bool wasResized = (component->getWidth() != realW || component->getHeight() != realH);
  61902. if (wasMoved || wasResized)
  61903. {
  61904. component->bounds_.setBounds (realX, realY, realW, realH);
  61905. if (wasResized)
  61906. component->repaint();
  61907. component->sendMovedResizedMessages (wasMoved, wasResized);
  61908. if (deletionChecker.hasBeenDeleted())
  61909. return;
  61910. }
  61911. }
  61912. if (isWindowMinimised != nowMinimised)
  61913. {
  61914. isWindowMinimised = nowMinimised;
  61915. component->minimisationStateChanged (nowMinimised);
  61916. component->sendVisibilityChangeMessage();
  61917. }
  61918. if (! isFullScreen())
  61919. lastNonFullscreenBounds = component->getBounds();
  61920. }
  61921. void ComponentPeer::handleFocusGain()
  61922. {
  61923. updateCurrentModifiers();
  61924. if (component->isParentOf (lastFocusedComponent))
  61925. {
  61926. Component::currentlyFocusedComponent = lastFocusedComponent;
  61927. Desktop::getInstance().triggerFocusCallback();
  61928. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61929. }
  61930. else
  61931. {
  61932. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61933. component->grabKeyboardFocus();
  61934. else
  61935. Component::bringModalComponentToFront();
  61936. }
  61937. }
  61938. void ComponentPeer::handleFocusLoss()
  61939. {
  61940. updateCurrentModifiers();
  61941. if (component->hasKeyboardFocus (true))
  61942. {
  61943. lastFocusedComponent = Component::currentlyFocusedComponent;
  61944. if (lastFocusedComponent != 0)
  61945. {
  61946. Component::currentlyFocusedComponent = 0;
  61947. Desktop::getInstance().triggerFocusCallback();
  61948. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61949. }
  61950. }
  61951. }
  61952. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61953. {
  61954. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61955. ? lastFocusedComponent
  61956. : component;
  61957. }
  61958. void ComponentPeer::handleScreenSizeChange()
  61959. {
  61960. updateCurrentModifiers();
  61961. component->parentSizeChanged();
  61962. handleMovedOrResized();
  61963. }
  61964. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61965. {
  61966. lastNonFullscreenBounds = newBounds;
  61967. }
  61968. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61969. {
  61970. return lastNonFullscreenBounds;
  61971. }
  61972. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61973. const StringArray& files,
  61974. FileDragAndDropTarget* const lastOne)
  61975. {
  61976. while (c != 0)
  61977. {
  61978. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61979. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61980. return t;
  61981. c = c->getParentComponent();
  61982. }
  61983. return 0;
  61984. }
  61985. void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y)
  61986. {
  61987. updateCurrentModifiers();
  61988. FileDragAndDropTarget* lastTarget = 0;
  61989. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  61990. lastTarget = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  61991. FileDragAndDropTarget* newTarget = 0;
  61992. Component* const compUnderMouse = component->getComponentAt (x, y);
  61993. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61994. {
  61995. lastDragAndDropCompUnderMouse = compUnderMouse;
  61996. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61997. if (newTarget != lastTarget)
  61998. {
  61999. if (lastTarget != 0)
  62000. lastTarget->fileDragExit (files);
  62001. dragAndDropTargetComponent = 0;
  62002. if (newTarget != 0)
  62003. {
  62004. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  62005. int mx = x, my = y;
  62006. component->relativePositionToOtherComponent (targetComp, mx, my);
  62007. dragAndDropTargetComponent = new ComponentDeletionWatcher (dynamic_cast <Component*> (newTarget));
  62008. newTarget->fileDragEnter (files, mx, my);
  62009. }
  62010. }
  62011. }
  62012. else
  62013. {
  62014. newTarget = lastTarget;
  62015. }
  62016. if (newTarget != 0)
  62017. {
  62018. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  62019. component->relativePositionToOtherComponent (targetComp, x, y);
  62020. newTarget->fileDragMove (files, x, y);
  62021. }
  62022. }
  62023. void ComponentPeer::handleFileDragExit (const StringArray& files)
  62024. {
  62025. handleFileDragMove (files, -1, -1);
  62026. jassert (dragAndDropTargetComponent == 0);
  62027. lastDragAndDropCompUnderMouse = 0;
  62028. }
  62029. void ComponentPeer::handleFileDragDrop (const StringArray& files, int x, int y)
  62030. {
  62031. handleFileDragMove (files, x, y);
  62032. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  62033. {
  62034. FileDragAndDropTarget* const target = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  62035. dragAndDropTargetComponent = 0;
  62036. lastDragAndDropCompUnderMouse = 0;
  62037. if (target != 0)
  62038. {
  62039. Component* const targetComp = dynamic_cast <Component*> (target);
  62040. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  62041. {
  62042. targetComp->internalModalInputAttempt();
  62043. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  62044. return;
  62045. }
  62046. component->relativePositionToOtherComponent (targetComp, x, y);
  62047. target->filesDropped (files, x, y);
  62048. }
  62049. }
  62050. }
  62051. void ComponentPeer::handleUserClosingWindow()
  62052. {
  62053. updateCurrentModifiers();
  62054. component->userTriedToCloseWindow();
  62055. }
  62056. void ComponentPeer::bringModalComponentToFront()
  62057. {
  62058. Component::bringModalComponentToFront();
  62059. }
  62060. void ComponentPeer::clearMaskedRegion() throw()
  62061. {
  62062. maskedRegion.clear();
  62063. }
  62064. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  62065. {
  62066. maskedRegion.add (x, y, w, h);
  62067. }
  62068. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  62069. {
  62070. StringArray s;
  62071. s.add ("Software Renderer");
  62072. return s;
  62073. }
  62074. int ComponentPeer::getCurrentRenderingEngine() throw()
  62075. {
  62076. return 0;
  62077. }
  62078. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  62079. {
  62080. }
  62081. END_JUCE_NAMESPACE
  62082. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  62083. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  62084. BEGIN_JUCE_NAMESPACE
  62085. DialogWindow::DialogWindow (const String& name,
  62086. const Colour& backgroundColour_,
  62087. const bool escapeKeyTriggersCloseButton_,
  62088. const bool addToDesktop_)
  62089. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  62090. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  62091. {
  62092. }
  62093. DialogWindow::~DialogWindow()
  62094. {
  62095. }
  62096. void DialogWindow::resized()
  62097. {
  62098. DocumentWindow::resized();
  62099. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  62100. if (escapeKeyTriggersCloseButton
  62101. && getCloseButton() != 0
  62102. && ! getCloseButton()->isRegisteredForShortcut (esc))
  62103. {
  62104. getCloseButton()->addShortcut (esc);
  62105. }
  62106. }
  62107. class TempDialogWindow : public DialogWindow
  62108. {
  62109. public:
  62110. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  62111. : DialogWindow (title, colour, escapeCloses, true)
  62112. {
  62113. }
  62114. ~TempDialogWindow()
  62115. {
  62116. }
  62117. void closeButtonPressed()
  62118. {
  62119. setVisible (false);
  62120. }
  62121. private:
  62122. TempDialogWindow (const TempDialogWindow&);
  62123. const TempDialogWindow& operator= (const TempDialogWindow&);
  62124. };
  62125. int DialogWindow::showModalDialog (const String& dialogTitle,
  62126. Component* contentComponent,
  62127. Component* componentToCentreAround,
  62128. const Colour& colour,
  62129. const bool escapeKeyTriggersCloseButton,
  62130. const bool shouldBeResizable,
  62131. const bool useBottomRightCornerResizer)
  62132. {
  62133. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  62134. dw.setContentComponent (contentComponent, true, true);
  62135. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  62136. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62137. const int result = dw.runModalLoop();
  62138. dw.setContentComponent (0, false);
  62139. return result;
  62140. }
  62141. END_JUCE_NAMESPACE
  62142. /*** End of inlined file: juce_DialogWindow.cpp ***/
  62143. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  62144. BEGIN_JUCE_NAMESPACE
  62145. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  62146. {
  62147. public:
  62148. ButtonListenerProxy (DocumentWindow& owner_)
  62149. : owner (owner_)
  62150. {
  62151. }
  62152. void buttonClicked (Button* button)
  62153. {
  62154. if (button == owner.getMinimiseButton())
  62155. owner.minimiseButtonPressed();
  62156. else if (button == owner.getMaximiseButton())
  62157. owner.maximiseButtonPressed();
  62158. else if (button == owner.getCloseButton())
  62159. owner.closeButtonPressed();
  62160. }
  62161. juce_UseDebuggingNewOperator
  62162. private:
  62163. DocumentWindow& owner;
  62164. ButtonListenerProxy (const ButtonListenerProxy&);
  62165. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  62166. };
  62167. DocumentWindow::DocumentWindow (const String& title,
  62168. const Colour& backgroundColour,
  62169. const int requiredButtons_,
  62170. const bool addToDesktop_)
  62171. : ResizableWindow (title, backgroundColour, addToDesktop_),
  62172. titleBarHeight (26),
  62173. menuBarHeight (24),
  62174. requiredButtons (requiredButtons_),
  62175. #if JUCE_MAC
  62176. positionTitleBarButtonsOnLeft (true),
  62177. #else
  62178. positionTitleBarButtonsOnLeft (false),
  62179. #endif
  62180. drawTitleTextCentred (true),
  62181. menuBarModel (0)
  62182. {
  62183. setResizeLimits (128, 128, 32768, 32768);
  62184. lookAndFeelChanged();
  62185. }
  62186. DocumentWindow::~DocumentWindow()
  62187. {
  62188. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62189. titleBarButtons[i] = 0;
  62190. menuBar = 0;
  62191. }
  62192. void DocumentWindow::repaintTitleBar()
  62193. {
  62194. const Rectangle<int> titleBarArea (getTitleBarArea());
  62195. repaint (titleBarArea.getX(), titleBarArea.getY(),
  62196. titleBarArea.getWidth(), titleBarArea.getHeight());
  62197. }
  62198. void DocumentWindow::setName (const String& newName)
  62199. {
  62200. if (newName != getName())
  62201. {
  62202. Component::setName (newName);
  62203. repaintTitleBar();
  62204. }
  62205. }
  62206. void DocumentWindow::setIcon (const Image* imageToUse)
  62207. {
  62208. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  62209. repaintTitleBar();
  62210. }
  62211. void DocumentWindow::setTitleBarHeight (const int newHeight)
  62212. {
  62213. titleBarHeight = newHeight;
  62214. resized();
  62215. repaintTitleBar();
  62216. }
  62217. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  62218. const bool positionTitleBarButtonsOnLeft_)
  62219. {
  62220. requiredButtons = requiredButtons_;
  62221. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  62222. lookAndFeelChanged();
  62223. }
  62224. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  62225. {
  62226. drawTitleTextCentred = textShouldBeCentred;
  62227. repaintTitleBar();
  62228. }
  62229. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  62230. const int menuBarHeight_)
  62231. {
  62232. if (menuBarModel != menuBarModel_)
  62233. {
  62234. menuBar = 0;
  62235. menuBarModel = menuBarModel_;
  62236. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  62237. : getLookAndFeel().getDefaultMenuBarHeight();
  62238. if (menuBarModel != 0)
  62239. {
  62240. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62241. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  62242. menuBar->setEnabled (isActiveWindow());
  62243. }
  62244. resized();
  62245. }
  62246. }
  62247. void DocumentWindow::closeButtonPressed()
  62248. {
  62249. /* If you've got a close button, you have to override this method to get
  62250. rid of your window!
  62251. If the window is just a pop-up, you should override this method and make
  62252. it delete the window in whatever way is appropriate for your app. E.g. you
  62253. might just want to call "delete this".
  62254. If your app is centred around this window such that the whole app should quit when
  62255. the window is closed, then you will probably want to use this method as an opportunity
  62256. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  62257. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  62258. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  62259. or closing it via the taskbar icon on Windows).
  62260. */
  62261. jassertfalse
  62262. }
  62263. void DocumentWindow::minimiseButtonPressed()
  62264. {
  62265. setMinimised (true);
  62266. }
  62267. void DocumentWindow::maximiseButtonPressed()
  62268. {
  62269. setFullScreen (! isFullScreen());
  62270. }
  62271. void DocumentWindow::paint (Graphics& g)
  62272. {
  62273. ResizableWindow::paint (g);
  62274. if (resizableBorder == 0)
  62275. {
  62276. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  62277. const BorderSize border (getBorderThickness());
  62278. g.fillRect (0, 0, getWidth(), border.getTop());
  62279. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  62280. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  62281. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  62282. }
  62283. const Rectangle<int> titleBarArea (getTitleBarArea());
  62284. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  62285. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  62286. int titleSpaceX1 = 6;
  62287. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  62288. for (int i = 0; i < 3; ++i)
  62289. {
  62290. if (titleBarButtons[i] != 0)
  62291. {
  62292. if (positionTitleBarButtonsOnLeft)
  62293. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  62294. else
  62295. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  62296. }
  62297. }
  62298. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  62299. titleBarArea.getWidth(),
  62300. titleBarArea.getHeight(),
  62301. titleSpaceX1,
  62302. jmax (1, titleSpaceX2 - titleSpaceX1),
  62303. titleBarIcon,
  62304. ! drawTitleTextCentred);
  62305. }
  62306. void DocumentWindow::resized()
  62307. {
  62308. ResizableWindow::resized();
  62309. if (titleBarButtons[1] != 0)
  62310. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  62311. const Rectangle<int> titleBarArea (getTitleBarArea());
  62312. getLookAndFeel()
  62313. .positionDocumentWindowButtons (*this,
  62314. titleBarArea.getX(), titleBarArea.getY(),
  62315. titleBarArea.getWidth(), titleBarArea.getHeight(),
  62316. titleBarButtons[0],
  62317. titleBarButtons[1],
  62318. titleBarButtons[2],
  62319. positionTitleBarButtonsOnLeft);
  62320. if (menuBar != 0)
  62321. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  62322. titleBarArea.getWidth(), menuBarHeight);
  62323. }
  62324. const BorderSize DocumentWindow::getBorderThickness()
  62325. {
  62326. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  62327. ? 0 : (resizableBorder != 0 ? 4 : 1));
  62328. }
  62329. const BorderSize DocumentWindow::getContentComponentBorder()
  62330. {
  62331. BorderSize border (getBorderThickness());
  62332. border.setTop (border.getTop()
  62333. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  62334. + (menuBar != 0 ? menuBarHeight : 0));
  62335. return border;
  62336. }
  62337. int DocumentWindow::getTitleBarHeight() const
  62338. {
  62339. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  62340. }
  62341. const Rectangle<int> DocumentWindow::getTitleBarArea()
  62342. {
  62343. const BorderSize border (getBorderThickness());
  62344. return Rectangle<int> (border.getLeft(), border.getTop(),
  62345. getWidth() - border.getLeftAndRight(),
  62346. getTitleBarHeight());
  62347. }
  62348. Button* DocumentWindow::getCloseButton() const throw()
  62349. {
  62350. return titleBarButtons[2];
  62351. }
  62352. Button* DocumentWindow::getMinimiseButton() const throw()
  62353. {
  62354. return titleBarButtons[0];
  62355. }
  62356. Button* DocumentWindow::getMaximiseButton() const throw()
  62357. {
  62358. return titleBarButtons[1];
  62359. }
  62360. int DocumentWindow::getDesktopWindowStyleFlags() const
  62361. {
  62362. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  62363. if ((requiredButtons & minimiseButton) != 0)
  62364. flags |= ComponentPeer::windowHasMinimiseButton;
  62365. if ((requiredButtons & maximiseButton) != 0)
  62366. flags |= ComponentPeer::windowHasMaximiseButton;
  62367. if ((requiredButtons & closeButton) != 0)
  62368. flags |= ComponentPeer::windowHasCloseButton;
  62369. return flags;
  62370. }
  62371. void DocumentWindow::lookAndFeelChanged()
  62372. {
  62373. int i;
  62374. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  62375. titleBarButtons[i] = 0;
  62376. if (! isUsingNativeTitleBar())
  62377. {
  62378. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  62379. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  62380. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  62381. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  62382. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  62383. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  62384. for (i = 0; i < 3; ++i)
  62385. {
  62386. if (titleBarButtons[i] != 0)
  62387. {
  62388. if (buttonListener == 0)
  62389. buttonListener = new ButtonListenerProxy (*this);
  62390. titleBarButtons[i]->addButtonListener (buttonListener);
  62391. titleBarButtons[i]->setWantsKeyboardFocus (false);
  62392. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62393. Component::addAndMakeVisible (titleBarButtons[i]);
  62394. }
  62395. }
  62396. if (getCloseButton() != 0)
  62397. {
  62398. #if JUCE_MAC
  62399. getCloseButton()->addShortcut (KeyPress (T('w'), ModifierKeys::commandModifier, 0));
  62400. #else
  62401. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  62402. #endif
  62403. }
  62404. }
  62405. activeWindowStatusChanged();
  62406. ResizableWindow::lookAndFeelChanged();
  62407. }
  62408. void DocumentWindow::parentHierarchyChanged()
  62409. {
  62410. lookAndFeelChanged();
  62411. }
  62412. void DocumentWindow::activeWindowStatusChanged()
  62413. {
  62414. ResizableWindow::activeWindowStatusChanged();
  62415. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62416. if (titleBarButtons[i] != 0)
  62417. titleBarButtons[i]->setEnabled (isActiveWindow());
  62418. if (menuBar != 0)
  62419. menuBar->setEnabled (isActiveWindow());
  62420. }
  62421. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  62422. {
  62423. if (getTitleBarArea().contains (e.x, e.y)
  62424. && getMaximiseButton() != 0)
  62425. {
  62426. getMaximiseButton()->triggerClick();
  62427. }
  62428. }
  62429. void DocumentWindow::userTriedToCloseWindow()
  62430. {
  62431. closeButtonPressed();
  62432. }
  62433. END_JUCE_NAMESPACE
  62434. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  62435. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  62436. BEGIN_JUCE_NAMESPACE
  62437. ResizableWindow::ResizableWindow (const String& name,
  62438. const bool addToDesktop_)
  62439. : TopLevelWindow (name, addToDesktop_),
  62440. resizeToFitContent (false),
  62441. fullscreen (false),
  62442. lastNonFullScreenPos (50, 50, 256, 256),
  62443. constrainer (0)
  62444. #ifdef JUCE_DEBUG
  62445. , hasBeenResized (false)
  62446. #endif
  62447. {
  62448. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62449. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  62450. if (addToDesktop_)
  62451. Component::addToDesktop (getDesktopWindowStyleFlags());
  62452. }
  62453. ResizableWindow::ResizableWindow (const String& name,
  62454. const Colour& backgroundColour_,
  62455. const bool addToDesktop_)
  62456. : TopLevelWindow (name, addToDesktop_),
  62457. resizeToFitContent (false),
  62458. fullscreen (false),
  62459. lastNonFullScreenPos (50, 50, 256, 256),
  62460. constrainer (0)
  62461. #ifdef JUCE_DEBUG
  62462. , hasBeenResized (false)
  62463. #endif
  62464. {
  62465. setBackgroundColour (backgroundColour_);
  62466. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62467. if (addToDesktop_)
  62468. Component::addToDesktop (getDesktopWindowStyleFlags());
  62469. }
  62470. ResizableWindow::~ResizableWindow()
  62471. {
  62472. resizableCorner = 0;
  62473. resizableBorder = 0;
  62474. contentComponent = 0;
  62475. // have you been adding your own components directly to this window..? tut tut tut.
  62476. // Read the instructions for using a ResizableWindow!
  62477. jassert (getNumChildComponents() == 0);
  62478. }
  62479. int ResizableWindow::getDesktopWindowStyleFlags() const
  62480. {
  62481. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  62482. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  62483. flags |= ComponentPeer::windowIsResizable;
  62484. return flags;
  62485. }
  62486. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  62487. const bool deleteOldOne,
  62488. const bool resizeToFit)
  62489. {
  62490. resizeToFitContent = resizeToFit;
  62491. if (newContentComponent != (Component*) contentComponent)
  62492. {
  62493. if (! deleteOldOne)
  62494. removeChildComponent (contentComponent.release());
  62495. contentComponent = newContentComponent;
  62496. Component::addAndMakeVisible (contentComponent);
  62497. }
  62498. if (resizeToFit)
  62499. childBoundsChanged (contentComponent);
  62500. resized(); // must always be called to position the new content comp
  62501. }
  62502. void ResizableWindow::setContentComponentSize (int width, int height)
  62503. {
  62504. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  62505. const BorderSize border (getContentComponentBorder());
  62506. setSize (width + border.getLeftAndRight(),
  62507. height + border.getTopAndBottom());
  62508. }
  62509. const BorderSize ResizableWindow::getBorderThickness()
  62510. {
  62511. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  62512. }
  62513. const BorderSize ResizableWindow::getContentComponentBorder()
  62514. {
  62515. return getBorderThickness();
  62516. }
  62517. void ResizableWindow::moved()
  62518. {
  62519. updateLastPos();
  62520. }
  62521. void ResizableWindow::visibilityChanged()
  62522. {
  62523. TopLevelWindow::visibilityChanged();
  62524. updateLastPos();
  62525. }
  62526. void ResizableWindow::resized()
  62527. {
  62528. if (resizableBorder != 0)
  62529. {
  62530. resizableBorder->setVisible (! isFullScreen());
  62531. resizableBorder->setBorderThickness (getBorderThickness());
  62532. resizableBorder->setSize (getWidth(), getHeight());
  62533. resizableBorder->toBack();
  62534. }
  62535. if (resizableCorner != 0)
  62536. {
  62537. resizableCorner->setVisible (! isFullScreen());
  62538. const int resizerSize = 18;
  62539. resizableCorner->setBounds (getWidth() - resizerSize,
  62540. getHeight() - resizerSize,
  62541. resizerSize, resizerSize);
  62542. }
  62543. if (contentComponent != 0)
  62544. contentComponent->setBoundsInset (getContentComponentBorder());
  62545. updateLastPos();
  62546. #ifdef JUCE_DEBUG
  62547. hasBeenResized = true;
  62548. #endif
  62549. }
  62550. void ResizableWindow::childBoundsChanged (Component* child)
  62551. {
  62552. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62553. {
  62554. // not going to look very good if this component has a zero size..
  62555. jassert (child->getWidth() > 0);
  62556. jassert (child->getHeight() > 0);
  62557. const BorderSize borders (getContentComponentBorder());
  62558. setSize (child->getWidth() + borders.getLeftAndRight(),
  62559. child->getHeight() + borders.getTopAndBottom());
  62560. }
  62561. }
  62562. void ResizableWindow::activeWindowStatusChanged()
  62563. {
  62564. const BorderSize borders (getContentComponentBorder());
  62565. repaint (0, 0, getWidth(), borders.getTop());
  62566. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62567. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62568. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62569. }
  62570. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62571. const bool useBottomRightCornerResizer)
  62572. {
  62573. if (shouldBeResizable)
  62574. {
  62575. if (useBottomRightCornerResizer)
  62576. {
  62577. resizableBorder = 0;
  62578. if (resizableCorner == 0)
  62579. {
  62580. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62581. resizableCorner->setAlwaysOnTop (true);
  62582. }
  62583. }
  62584. else
  62585. {
  62586. resizableCorner = 0;
  62587. if (resizableBorder == 0)
  62588. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62589. }
  62590. }
  62591. else
  62592. {
  62593. resizableCorner = 0;
  62594. resizableBorder = 0;
  62595. }
  62596. if (isUsingNativeTitleBar())
  62597. recreateDesktopWindow();
  62598. childBoundsChanged (contentComponent);
  62599. resized();
  62600. }
  62601. bool ResizableWindow::isResizable() const throw()
  62602. {
  62603. return resizableCorner != 0
  62604. || resizableBorder != 0;
  62605. }
  62606. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62607. const int newMinimumHeight,
  62608. const int newMaximumWidth,
  62609. const int newMaximumHeight) throw()
  62610. {
  62611. // if you've set up a custom constrainer then these settings won't have any effect..
  62612. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62613. if (constrainer == 0)
  62614. setConstrainer (&defaultConstrainer);
  62615. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62616. newMaximumWidth, newMaximumHeight);
  62617. setBoundsConstrained (getBounds());
  62618. }
  62619. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62620. {
  62621. if (constrainer != newConstrainer)
  62622. {
  62623. constrainer = newConstrainer;
  62624. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62625. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62626. resizableCorner = 0;
  62627. resizableBorder = 0;
  62628. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62629. ComponentPeer* const peer = getPeer();
  62630. if (peer != 0)
  62631. peer->setConstrainer (newConstrainer);
  62632. }
  62633. }
  62634. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62635. {
  62636. if (constrainer != 0)
  62637. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62638. else
  62639. setBounds (bounds);
  62640. }
  62641. void ResizableWindow::paint (Graphics& g)
  62642. {
  62643. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62644. getBorderThickness(), *this);
  62645. if (! isFullScreen())
  62646. {
  62647. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62648. getBorderThickness(), *this);
  62649. }
  62650. #ifdef JUCE_DEBUG
  62651. /* If this fails, then you've probably written a subclass with a resized()
  62652. callback but forgotten to make it call its parent class's resized() method.
  62653. It's important when you override methods like resized(), moved(),
  62654. etc., that you make sure the base class methods also get called.
  62655. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62656. because your content should all be inside the content component - and it's the
  62657. content component's resized() method that you should be using to do your
  62658. layout.
  62659. */
  62660. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62661. #endif
  62662. }
  62663. void ResizableWindow::lookAndFeelChanged()
  62664. {
  62665. resized();
  62666. if (isOnDesktop())
  62667. {
  62668. Component::addToDesktop (getDesktopWindowStyleFlags());
  62669. ComponentPeer* const peer = getPeer();
  62670. if (peer != 0)
  62671. peer->setConstrainer (constrainer);
  62672. }
  62673. }
  62674. const Colour ResizableWindow::getBackgroundColour() const throw()
  62675. {
  62676. return findColour (backgroundColourId, false);
  62677. }
  62678. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62679. {
  62680. Colour backgroundColour (newColour);
  62681. if (! Desktop::canUseSemiTransparentWindows())
  62682. backgroundColour = newColour.withAlpha (1.0f);
  62683. setColour (backgroundColourId, backgroundColour);
  62684. setOpaque (backgroundColour.isOpaque());
  62685. repaint();
  62686. }
  62687. bool ResizableWindow::isFullScreen() const
  62688. {
  62689. if (isOnDesktop())
  62690. {
  62691. ComponentPeer* const peer = getPeer();
  62692. return peer != 0 && peer->isFullScreen();
  62693. }
  62694. return fullscreen;
  62695. }
  62696. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62697. {
  62698. if (shouldBeFullScreen != isFullScreen())
  62699. {
  62700. updateLastPos();
  62701. fullscreen = shouldBeFullScreen;
  62702. if (isOnDesktop())
  62703. {
  62704. ComponentPeer* const peer = getPeer();
  62705. if (peer != 0)
  62706. {
  62707. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62708. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62709. peer->setFullScreen (shouldBeFullScreen);
  62710. if (! shouldBeFullScreen)
  62711. setBounds (lastPos);
  62712. }
  62713. else
  62714. {
  62715. jassertfalse
  62716. }
  62717. }
  62718. else
  62719. {
  62720. if (shouldBeFullScreen)
  62721. setBounds (0, 0, getParentWidth(), getParentHeight());
  62722. else
  62723. setBounds (lastNonFullScreenPos);
  62724. }
  62725. resized();
  62726. }
  62727. }
  62728. bool ResizableWindow::isMinimised() const
  62729. {
  62730. ComponentPeer* const peer = getPeer();
  62731. return (peer != 0) && peer->isMinimised();
  62732. }
  62733. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62734. {
  62735. if (shouldMinimise != isMinimised())
  62736. {
  62737. ComponentPeer* const peer = getPeer();
  62738. if (peer != 0)
  62739. {
  62740. updateLastPos();
  62741. peer->setMinimised (shouldMinimise);
  62742. }
  62743. else
  62744. {
  62745. jassertfalse
  62746. }
  62747. }
  62748. }
  62749. void ResizableWindow::updateLastPos()
  62750. {
  62751. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62752. {
  62753. lastNonFullScreenPos = getBounds();
  62754. }
  62755. }
  62756. void ResizableWindow::parentSizeChanged()
  62757. {
  62758. if (isFullScreen() && getParentComponent() != 0)
  62759. {
  62760. setBounds (0, 0, getParentWidth(), getParentHeight());
  62761. }
  62762. }
  62763. const String ResizableWindow::getWindowStateAsString()
  62764. {
  62765. updateLastPos();
  62766. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62767. }
  62768. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62769. {
  62770. StringArray tokens;
  62771. tokens.addTokens (s, false);
  62772. tokens.removeEmptyStrings();
  62773. tokens.trim();
  62774. const bool fs = tokens[0].startsWithIgnoreCase (T("fs"));
  62775. const int firstCoord = fs ? 1 : 0;
  62776. if (tokens.size() != firstCoord + 4)
  62777. return false;
  62778. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62779. tokens[firstCoord + 1].getIntValue(),
  62780. tokens[firstCoord + 2].getIntValue(),
  62781. tokens[firstCoord + 3].getIntValue());
  62782. if (newPos.isEmpty())
  62783. return false;
  62784. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentreX(),
  62785. newPos.getCentreY()));
  62786. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62787. if (peer != 0)
  62788. peer->getFrameSize().addTo (newPos);
  62789. if (! screen.contains (newPos))
  62790. {
  62791. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62792. jmin (newPos.getHeight(), screen.getHeight()));
  62793. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62794. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62795. }
  62796. if (peer != 0)
  62797. {
  62798. peer->getFrameSize().subtractFrom (newPos);
  62799. peer->setNonFullScreenBounds (newPos);
  62800. }
  62801. lastNonFullScreenPos = newPos;
  62802. setFullScreen (fs);
  62803. if (! fs)
  62804. setBoundsConstrained (newPos);
  62805. return true;
  62806. }
  62807. void ResizableWindow::mouseDown (const MouseEvent&)
  62808. {
  62809. if (! isFullScreen())
  62810. dragger.startDraggingComponent (this, constrainer);
  62811. }
  62812. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62813. {
  62814. if (! isFullScreen())
  62815. dragger.dragComponent (this, e);
  62816. }
  62817. #ifdef JUCE_DEBUG
  62818. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62819. {
  62820. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62821. manages its child components automatically, and if you add your own it'll cause
  62822. trouble. Instead, use setContentComponent() to give it a component which
  62823. will be automatically resized and kept in the right place - then you can add
  62824. subcomponents to the content comp. See the notes for the ResizableWindow class
  62825. for more info.
  62826. If you really know what you're doing and want to avoid this assertion, just call
  62827. Component::addChildComponent directly.
  62828. */
  62829. jassertfalse
  62830. Component::addChildComponent (child, zOrder);
  62831. }
  62832. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62833. {
  62834. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62835. manages its child components automatically, and if you add your own it'll cause
  62836. trouble. Instead, use setContentComponent() to give it a component which
  62837. will be automatically resized and kept in the right place - then you can add
  62838. subcomponents to the content comp. See the notes for the ResizableWindow class
  62839. for more info.
  62840. If you really know what you're doing and want to avoid this assertion, just call
  62841. Component::addAndMakeVisible directly.
  62842. */
  62843. jassertfalse
  62844. Component::addAndMakeVisible (child, zOrder);
  62845. }
  62846. #endif
  62847. END_JUCE_NAMESPACE
  62848. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62849. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62850. BEGIN_JUCE_NAMESPACE
  62851. SplashScreen::SplashScreen()
  62852. : backgroundImage (0)
  62853. {
  62854. setOpaque (true);
  62855. }
  62856. SplashScreen::~SplashScreen()
  62857. {
  62858. ImageCache::releaseOrDelete (backgroundImage);
  62859. }
  62860. void SplashScreen::show (const String& title,
  62861. Image* const backgroundImage_,
  62862. const int minimumTimeToDisplayFor,
  62863. const bool useDropShadow,
  62864. const bool removeOnMouseClick)
  62865. {
  62866. backgroundImage = backgroundImage_;
  62867. jassert (backgroundImage_ != 0);
  62868. if (backgroundImage_ != 0)
  62869. {
  62870. setOpaque (! backgroundImage_->hasAlphaChannel());
  62871. show (title,
  62872. backgroundImage_->getWidth(),
  62873. backgroundImage_->getHeight(),
  62874. minimumTimeToDisplayFor,
  62875. useDropShadow,
  62876. removeOnMouseClick);
  62877. }
  62878. }
  62879. void SplashScreen::show (const String& title,
  62880. const int width,
  62881. const int height,
  62882. const int minimumTimeToDisplayFor,
  62883. const bool useDropShadow,
  62884. const bool removeOnMouseClick)
  62885. {
  62886. setName (title);
  62887. setAlwaysOnTop (true);
  62888. setVisible (true);
  62889. centreWithSize (width, height);
  62890. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62891. toFront (false);
  62892. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62893. repaint();
  62894. originalClickCounter = removeOnMouseClick
  62895. ? Desktop::getMouseButtonClickCounter()
  62896. : std::numeric_limits<int>::max();
  62897. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62898. startTimer (50);
  62899. }
  62900. void SplashScreen::paint (Graphics& g)
  62901. {
  62902. if (backgroundImage != 0)
  62903. {
  62904. g.setOpacity (1.0f);
  62905. g.drawImage (backgroundImage,
  62906. 0, 0, getWidth(), getHeight(),
  62907. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62908. }
  62909. }
  62910. void SplashScreen::timerCallback()
  62911. {
  62912. if (Time::getCurrentTime() > earliestTimeToDelete
  62913. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62914. {
  62915. delete this;
  62916. }
  62917. }
  62918. END_JUCE_NAMESPACE
  62919. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62920. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62921. BEGIN_JUCE_NAMESPACE
  62922. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62923. const bool hasProgressBar,
  62924. const bool hasCancelButton,
  62925. const int timeOutMsWhenCancelling_,
  62926. const String& cancelButtonText)
  62927. : Thread ("Juce Progress Window"),
  62928. progress (0.0),
  62929. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62930. {
  62931. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62932. .createAlertWindow (title, String::empty, cancelButtonText,
  62933. String::empty, String::empty,
  62934. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62935. if (hasProgressBar)
  62936. alertWindow->addProgressBarComponent (progress);
  62937. }
  62938. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62939. {
  62940. stopThread (timeOutMsWhenCancelling);
  62941. }
  62942. bool ThreadWithProgressWindow::runThread (const int priority)
  62943. {
  62944. startThread (priority);
  62945. startTimer (100);
  62946. {
  62947. const ScopedLock sl (messageLock);
  62948. alertWindow->setMessage (message);
  62949. }
  62950. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62951. stopThread (timeOutMsWhenCancelling);
  62952. alertWindow->setVisible (false);
  62953. return finishedNaturally;
  62954. }
  62955. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62956. {
  62957. progress = newProgress;
  62958. }
  62959. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62960. {
  62961. const ScopedLock sl (messageLock);
  62962. message = newStatusMessage;
  62963. }
  62964. void ThreadWithProgressWindow::timerCallback()
  62965. {
  62966. if (! isThreadRunning())
  62967. {
  62968. // thread has finished normally..
  62969. alertWindow->exitModalState (1);
  62970. alertWindow->setVisible (false);
  62971. }
  62972. else
  62973. {
  62974. const ScopedLock sl (messageLock);
  62975. alertWindow->setMessage (message);
  62976. }
  62977. }
  62978. END_JUCE_NAMESPACE
  62979. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62980. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62981. BEGIN_JUCE_NAMESPACE
  62982. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62983. const int millisecondsBeforeTipAppears_)
  62984. : Component ("tooltip"),
  62985. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62986. mouseX (0),
  62987. mouseY (0),
  62988. lastHideTime (0),
  62989. lastComponentUnderMouse (0),
  62990. changedCompsSinceShown (true)
  62991. {
  62992. startTimer (123);
  62993. setAlwaysOnTop (true);
  62994. setOpaque (true);
  62995. if (parentComponent != 0)
  62996. parentComponent->addChildComponent (this);
  62997. }
  62998. TooltipWindow::~TooltipWindow()
  62999. {
  63000. hide();
  63001. }
  63002. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  63003. {
  63004. millisecondsBeforeTipAppears = newTimeMs;
  63005. }
  63006. void TooltipWindow::paint (Graphics& g)
  63007. {
  63008. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  63009. }
  63010. void TooltipWindow::mouseEnter (const MouseEvent&)
  63011. {
  63012. hide();
  63013. }
  63014. void TooltipWindow::showFor (const String& tip)
  63015. {
  63016. jassert (tip.isNotEmpty());
  63017. tipShowing = tip;
  63018. int mx, my;
  63019. Desktop::getMousePosition (mx, my);
  63020. if (getParentComponent() != 0)
  63021. getParentComponent()->globalPositionToRelative (mx, my);
  63022. int x, y, w, h;
  63023. getLookAndFeel().getTooltipSize (tip, w, h);
  63024. if (mx > getParentWidth() / 2)
  63025. x = mx - (w + 12);
  63026. else
  63027. x = mx + 24;
  63028. if (my > getParentHeight() / 2)
  63029. y = my - (h + 6);
  63030. else
  63031. y = my + 6;
  63032. setBounds (x, y, w, h);
  63033. setVisible (true);
  63034. if (getParentComponent() == 0)
  63035. {
  63036. addToDesktop (ComponentPeer::windowHasDropShadow
  63037. | ComponentPeer::windowIsTemporary
  63038. | ComponentPeer::windowIgnoresKeyPresses);
  63039. }
  63040. toFront (false);
  63041. }
  63042. const String TooltipWindow::getTipFor (Component* const c)
  63043. {
  63044. if (c->isValidComponent()
  63045. && Process::isForegroundProcess()
  63046. && ! Component::isMouseButtonDownAnywhere())
  63047. {
  63048. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  63049. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  63050. return ttc->getTooltip();
  63051. }
  63052. return String::empty;
  63053. }
  63054. void TooltipWindow::hide()
  63055. {
  63056. tipShowing = String::empty;
  63057. removeFromDesktop();
  63058. setVisible (false);
  63059. }
  63060. void TooltipWindow::timerCallback()
  63061. {
  63062. const unsigned int now = Time::getApproximateMillisecondCounter();
  63063. Component* const newComp = Component::getComponentUnderMouse();
  63064. const String newTip (getTipFor (newComp));
  63065. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  63066. lastComponentUnderMouse = newComp;
  63067. lastTipUnderMouse = newTip;
  63068. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  63069. const bool mouseWasClicked = clickCount > mouseClicks;
  63070. mouseClicks = clickCount;
  63071. int mx, my;
  63072. Desktop::getMousePosition (mx, my);
  63073. const bool mouseMovedQuickly = (abs (mx - mouseX) + abs (my - mouseY) > 12);
  63074. mouseX = mx;
  63075. mouseY = my;
  63076. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  63077. lastCompChangeTime = now;
  63078. if (isVisible() || now < lastHideTime + 500)
  63079. {
  63080. // if a tip is currently visible (or has just disappeared), update to a new one
  63081. // immediately if needed..
  63082. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  63083. {
  63084. if (isVisible())
  63085. {
  63086. lastHideTime = now;
  63087. hide();
  63088. }
  63089. }
  63090. else if (tipChanged)
  63091. {
  63092. showFor (newTip);
  63093. }
  63094. }
  63095. else
  63096. {
  63097. // if there isn't currently a tip, but one is needed, only let it
  63098. // appear after a timeout..
  63099. if (newTip.isNotEmpty()
  63100. && newTip != tipShowing
  63101. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  63102. {
  63103. showFor (newTip);
  63104. }
  63105. }
  63106. }
  63107. END_JUCE_NAMESPACE
  63108. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  63109. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  63110. BEGIN_JUCE_NAMESPACE
  63111. class TopLevelWindowManager : public Timer,
  63112. public DeletedAtShutdown
  63113. {
  63114. public:
  63115. TopLevelWindowManager()
  63116. : currentActive (0)
  63117. {
  63118. }
  63119. ~TopLevelWindowManager()
  63120. {
  63121. clearSingletonInstance();
  63122. }
  63123. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  63124. void timerCallback()
  63125. {
  63126. startTimer (jmin (1731, getTimerInterval() * 2));
  63127. TopLevelWindow* active = 0;
  63128. if (Process::isForegroundProcess())
  63129. {
  63130. active = currentActive;
  63131. Component* const c = Component::getCurrentlyFocusedComponent();
  63132. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  63133. if (tlw == 0 && c != 0)
  63134. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  63135. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  63136. if (tlw != 0)
  63137. active = tlw;
  63138. }
  63139. if (active != currentActive)
  63140. {
  63141. currentActive = active;
  63142. for (int i = windows.size(); --i >= 0;)
  63143. {
  63144. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  63145. tlw->setWindowActive (isWindowActive (tlw));
  63146. i = jmin (i, windows.size() - 1);
  63147. }
  63148. Desktop::getInstance().triggerFocusCallback();
  63149. }
  63150. }
  63151. bool addWindow (TopLevelWindow* const w) throw()
  63152. {
  63153. windows.add (w);
  63154. startTimer (10);
  63155. return isWindowActive (w);
  63156. }
  63157. void removeWindow (TopLevelWindow* const w) throw()
  63158. {
  63159. startTimer (10);
  63160. if (currentActive == w)
  63161. currentActive = 0;
  63162. windows.removeValue (w);
  63163. if (windows.size() == 0)
  63164. deleteInstance();
  63165. }
  63166. VoidArray windows;
  63167. private:
  63168. TopLevelWindow* currentActive;
  63169. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  63170. {
  63171. return (tlw == currentActive
  63172. || tlw->isParentOf (currentActive)
  63173. || tlw->hasKeyboardFocus (true))
  63174. && tlw->isShowing();
  63175. }
  63176. TopLevelWindowManager (const TopLevelWindowManager&);
  63177. const TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  63178. };
  63179. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  63180. void juce_CheckCurrentlyFocusedTopLevelWindow()
  63181. {
  63182. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  63183. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  63184. }
  63185. TopLevelWindow::TopLevelWindow (const String& name,
  63186. const bool addToDesktop_)
  63187. : Component (name),
  63188. useDropShadow (true),
  63189. useNativeTitleBar (false),
  63190. windowIsActive_ (false)
  63191. {
  63192. setOpaque (true);
  63193. if (addToDesktop_)
  63194. Component::addToDesktop (getDesktopWindowStyleFlags());
  63195. else
  63196. setDropShadowEnabled (true);
  63197. setWantsKeyboardFocus (true);
  63198. setBroughtToFrontOnMouseClick (true);
  63199. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  63200. }
  63201. TopLevelWindow::~TopLevelWindow()
  63202. {
  63203. shadower = 0;
  63204. TopLevelWindowManager::getInstance()->removeWindow (this);
  63205. }
  63206. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  63207. {
  63208. if (hasKeyboardFocus (true))
  63209. TopLevelWindowManager::getInstance()->timerCallback();
  63210. else
  63211. TopLevelWindowManager::getInstance()->startTimer (10);
  63212. }
  63213. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  63214. {
  63215. if (windowIsActive_ != isNowActive)
  63216. {
  63217. windowIsActive_ = isNowActive;
  63218. activeWindowStatusChanged();
  63219. }
  63220. }
  63221. void TopLevelWindow::activeWindowStatusChanged()
  63222. {
  63223. }
  63224. void TopLevelWindow::parentHierarchyChanged()
  63225. {
  63226. setDropShadowEnabled (useDropShadow);
  63227. }
  63228. void TopLevelWindow::visibilityChanged()
  63229. {
  63230. if (isShowing())
  63231. toFront (true);
  63232. }
  63233. int TopLevelWindow::getDesktopWindowStyleFlags() const
  63234. {
  63235. int flags = ComponentPeer::windowAppearsOnTaskbar;
  63236. if (useDropShadow)
  63237. flags |= ComponentPeer::windowHasDropShadow;
  63238. if (useNativeTitleBar)
  63239. flags |= ComponentPeer::windowHasTitleBar;
  63240. return flags;
  63241. }
  63242. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  63243. {
  63244. useDropShadow = useShadow;
  63245. if (isOnDesktop())
  63246. {
  63247. shadower = 0;
  63248. Component::addToDesktop (getDesktopWindowStyleFlags());
  63249. }
  63250. else
  63251. {
  63252. if (useShadow && isOpaque())
  63253. {
  63254. if (shadower == 0)
  63255. {
  63256. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  63257. if (shadower != 0)
  63258. shadower->setOwner (this);
  63259. }
  63260. }
  63261. else
  63262. {
  63263. shadower = 0;
  63264. }
  63265. }
  63266. }
  63267. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  63268. {
  63269. if (useNativeTitleBar != useNativeTitleBar_)
  63270. {
  63271. useNativeTitleBar = useNativeTitleBar_;
  63272. recreateDesktopWindow();
  63273. sendLookAndFeelChange();
  63274. }
  63275. }
  63276. void TopLevelWindow::recreateDesktopWindow()
  63277. {
  63278. if (isOnDesktop())
  63279. {
  63280. Component::addToDesktop (getDesktopWindowStyleFlags());
  63281. toFront (true);
  63282. }
  63283. }
  63284. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  63285. {
  63286. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  63287. because this class needs to make sure its layout corresponds with settings like whether
  63288. it's got a native title bar or not.
  63289. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  63290. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  63291. method, then add or remove whatever flags are necessary from this value before returning it.
  63292. */
  63293. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  63294. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  63295. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  63296. if (windowStyleFlags != getDesktopWindowStyleFlags())
  63297. sendLookAndFeelChange();
  63298. }
  63299. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  63300. {
  63301. if (c == 0)
  63302. c = TopLevelWindow::getActiveTopLevelWindow();
  63303. if (c == 0)
  63304. {
  63305. centreWithSize (width, height);
  63306. }
  63307. else
  63308. {
  63309. int x = (c->getWidth() - width) / 2;
  63310. int y = (c->getHeight() - height) / 2;
  63311. c->relativePositionToGlobal (x, y);
  63312. Rectangle<int> parentArea (c->getParentMonitorArea());
  63313. if (getParentComponent() != 0)
  63314. {
  63315. getParentComponent()->globalPositionToRelative (x, y);
  63316. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  63317. }
  63318. parentArea.reduce (12, 12);
  63319. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), x),
  63320. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), y),
  63321. width, height);
  63322. }
  63323. }
  63324. int TopLevelWindow::getNumTopLevelWindows() throw()
  63325. {
  63326. return TopLevelWindowManager::getInstance()->windows.size();
  63327. }
  63328. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  63329. {
  63330. return (TopLevelWindow*) TopLevelWindowManager::getInstance()->windows [index];
  63331. }
  63332. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  63333. {
  63334. TopLevelWindow* best = 0;
  63335. int bestNumTWLParents = -1;
  63336. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  63337. {
  63338. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  63339. if (tlw->isActiveWindow())
  63340. {
  63341. int numTWLParents = 0;
  63342. const Component* c = tlw->getParentComponent();
  63343. while (c != 0)
  63344. {
  63345. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  63346. ++numTWLParents;
  63347. c = c->getParentComponent();
  63348. }
  63349. if (bestNumTWLParents < numTWLParents)
  63350. {
  63351. best = tlw;
  63352. bestNumTWLParents = numTWLParents;
  63353. }
  63354. }
  63355. }
  63356. return best;
  63357. }
  63358. END_JUCE_NAMESPACE
  63359. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  63360. /*** Start of inlined file: juce_Colour.cpp ***/
  63361. BEGIN_JUCE_NAMESPACE
  63362. static uint8 floatAlphaToInt (const float alpha)
  63363. {
  63364. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  63365. }
  63366. static const float oneOver255 = 1.0f / 255.0f;
  63367. Colour::Colour() throw()
  63368. : argb (0)
  63369. {
  63370. }
  63371. Colour::Colour (const Colour& other) throw()
  63372. : argb (other.argb)
  63373. {
  63374. }
  63375. const Colour& Colour::operator= (const Colour& other) throw()
  63376. {
  63377. argb = other.argb;
  63378. return *this;
  63379. }
  63380. bool Colour::operator== (const Colour& other) const throw()
  63381. {
  63382. return argb.getARGB() == other.argb.getARGB();
  63383. }
  63384. bool Colour::operator!= (const Colour& other) const throw()
  63385. {
  63386. return argb.getARGB() != other.argb.getARGB();
  63387. }
  63388. Colour::Colour (const uint32 argb_) throw()
  63389. : argb (argb_)
  63390. {
  63391. }
  63392. Colour::Colour (const uint8 red,
  63393. const uint8 green,
  63394. const uint8 blue) throw()
  63395. {
  63396. argb.setARGB (0xff, red, green, blue);
  63397. }
  63398. const Colour Colour::fromRGB (const uint8 red,
  63399. const uint8 green,
  63400. const uint8 blue) throw()
  63401. {
  63402. return Colour (red, green, blue);
  63403. }
  63404. Colour::Colour (const uint8 red,
  63405. const uint8 green,
  63406. const uint8 blue,
  63407. const uint8 alpha) throw()
  63408. {
  63409. argb.setARGB (alpha, red, green, blue);
  63410. }
  63411. const Colour Colour::fromRGBA (const uint8 red,
  63412. const uint8 green,
  63413. const uint8 blue,
  63414. const uint8 alpha) throw()
  63415. {
  63416. return Colour (red, green, blue, alpha);
  63417. }
  63418. Colour::Colour (const uint8 red,
  63419. const uint8 green,
  63420. const uint8 blue,
  63421. const float alpha) throw()
  63422. {
  63423. argb.setARGB (floatAlphaToInt (alpha), red, green, blue);
  63424. }
  63425. const Colour Colour::fromRGBAFloat (const uint8 red,
  63426. const uint8 green,
  63427. const uint8 blue,
  63428. const float alpha) throw()
  63429. {
  63430. return Colour (red, green, blue, alpha);
  63431. }
  63432. static void convertHSBtoRGB (float h, float s, float v,
  63433. uint8& r, uint8& g, uint8& b) throw()
  63434. {
  63435. v = jlimit (0.0f, 1.0f, v);
  63436. v *= 255.0f;
  63437. const uint8 intV = (uint8) roundToInt (v);
  63438. if (s <= 0)
  63439. {
  63440. r = intV;
  63441. g = intV;
  63442. b = intV;
  63443. }
  63444. else
  63445. {
  63446. s = jmin (1.0f, s);
  63447. h = jlimit (0.0f, 1.0f, h);
  63448. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  63449. const float f = h - floorf (h);
  63450. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  63451. const float y = v * (1.0f - s * f);
  63452. const float z = v * (1.0f - (s * (1.0f - f)));
  63453. if (h < 1.0f)
  63454. {
  63455. r = intV;
  63456. g = (uint8) roundToInt (z);
  63457. b = x;
  63458. }
  63459. else if (h < 2.0f)
  63460. {
  63461. r = (uint8) roundToInt (y);
  63462. g = intV;
  63463. b = x;
  63464. }
  63465. else if (h < 3.0f)
  63466. {
  63467. r = x;
  63468. g = intV;
  63469. b = (uint8) roundToInt (z);
  63470. }
  63471. else if (h < 4.0f)
  63472. {
  63473. r = x;
  63474. g = (uint8) roundToInt (y);
  63475. b = intV;
  63476. }
  63477. else if (h < 5.0f)
  63478. {
  63479. r = (uint8) roundToInt (z);
  63480. g = x;
  63481. b = intV;
  63482. }
  63483. else if (h < 6.0f)
  63484. {
  63485. r = intV;
  63486. g = x;
  63487. b = (uint8) roundToInt (y);
  63488. }
  63489. else
  63490. {
  63491. r = 0;
  63492. g = 0;
  63493. b = 0;
  63494. }
  63495. }
  63496. }
  63497. Colour::Colour (const float hue,
  63498. const float saturation,
  63499. const float brightness,
  63500. const float alpha) throw()
  63501. {
  63502. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63503. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63504. argb.setARGB (floatAlphaToInt (alpha), r, g, b);
  63505. }
  63506. const Colour Colour::fromHSV (const float hue,
  63507. const float saturation,
  63508. const float brightness,
  63509. const float alpha) throw()
  63510. {
  63511. return Colour (hue, saturation, brightness, alpha);
  63512. }
  63513. Colour::Colour (const float hue,
  63514. const float saturation,
  63515. const float brightness,
  63516. const uint8 alpha) throw()
  63517. {
  63518. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63519. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63520. argb.setARGB (alpha, r, g, b);
  63521. }
  63522. Colour::~Colour() throw()
  63523. {
  63524. }
  63525. const PixelARGB Colour::getPixelARGB() const throw()
  63526. {
  63527. PixelARGB p (argb);
  63528. p.premultiply();
  63529. return p;
  63530. }
  63531. uint32 Colour::getARGB() const throw()
  63532. {
  63533. return argb.getARGB();
  63534. }
  63535. bool Colour::isTransparent() const throw()
  63536. {
  63537. return getAlpha() == 0;
  63538. }
  63539. bool Colour::isOpaque() const throw()
  63540. {
  63541. return getAlpha() == 0xff;
  63542. }
  63543. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63544. {
  63545. PixelARGB newCol (argb);
  63546. newCol.setAlpha (newAlpha);
  63547. return Colour (newCol.getARGB());
  63548. }
  63549. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63550. {
  63551. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63552. PixelARGB newCol (argb);
  63553. newCol.setAlpha (floatAlphaToInt (newAlpha));
  63554. return Colour (newCol.getARGB());
  63555. }
  63556. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63557. {
  63558. jassert (alphaMultiplier >= 0);
  63559. PixelARGB newCol (argb);
  63560. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63561. return Colour (newCol.getARGB());
  63562. }
  63563. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63564. {
  63565. const int destAlpha = getAlpha();
  63566. if (destAlpha > 0)
  63567. {
  63568. const int invA = 0xff - (int) src.getAlpha();
  63569. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63570. if (resA > 0)
  63571. {
  63572. const int da = (invA * destAlpha) / resA;
  63573. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63574. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63575. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63576. (uint8) resA);
  63577. }
  63578. return *this;
  63579. }
  63580. else
  63581. {
  63582. return src;
  63583. }
  63584. }
  63585. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63586. {
  63587. if (proportionOfOther <= 0)
  63588. return *this;
  63589. if (proportionOfOther >= 1.0f)
  63590. return other;
  63591. PixelARGB c1 (getPixelARGB());
  63592. const PixelARGB c2 (other.getPixelARGB());
  63593. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63594. c1.unpremultiply();
  63595. return Colour (c1.getARGB());
  63596. }
  63597. float Colour::getFloatRed() const throw()
  63598. {
  63599. return getRed() * oneOver255;
  63600. }
  63601. float Colour::getFloatGreen() const throw()
  63602. {
  63603. return getGreen() * oneOver255;
  63604. }
  63605. float Colour::getFloatBlue() const throw()
  63606. {
  63607. return getBlue() * oneOver255;
  63608. }
  63609. float Colour::getFloatAlpha() const throw()
  63610. {
  63611. return getAlpha() * oneOver255;
  63612. }
  63613. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63614. {
  63615. const int r = getRed();
  63616. const int g = getGreen();
  63617. const int b = getBlue();
  63618. const int hi = jmax (r, g, b);
  63619. const int lo = jmin (r, g, b);
  63620. if (hi != 0)
  63621. {
  63622. s = (hi - lo) / (float) hi;
  63623. if (s != 0)
  63624. {
  63625. const float invDiff = 1.0f / (hi - lo);
  63626. const float red = (hi - r) * invDiff;
  63627. const float green = (hi - g) * invDiff;
  63628. const float blue = (hi - b) * invDiff;
  63629. if (r == hi)
  63630. h = blue - green;
  63631. else if (g == hi)
  63632. h = 2.0f + red - blue;
  63633. else
  63634. h = 4.0f + green - red;
  63635. h *= 1.0f / 6.0f;
  63636. if (h < 0)
  63637. ++h;
  63638. }
  63639. else
  63640. {
  63641. h = 0;
  63642. }
  63643. }
  63644. else
  63645. {
  63646. s = 0;
  63647. h = 0;
  63648. }
  63649. v = hi * oneOver255;
  63650. }
  63651. float Colour::getHue() const throw()
  63652. {
  63653. float h, s, b;
  63654. getHSB (h, s, b);
  63655. return h;
  63656. }
  63657. const Colour Colour::withHue (const float hue) const throw()
  63658. {
  63659. float h, s, b;
  63660. getHSB (h, s, b);
  63661. return Colour (hue, s, b, getAlpha());
  63662. }
  63663. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63664. {
  63665. float h, s, b;
  63666. getHSB (h, s, b);
  63667. h += amountToRotate;
  63668. h -= floorf (h);
  63669. return Colour (h, s, b, getAlpha());
  63670. }
  63671. float Colour::getSaturation() const throw()
  63672. {
  63673. float h, s, b;
  63674. getHSB (h, s, b);
  63675. return s;
  63676. }
  63677. const Colour Colour::withSaturation (const float saturation) const throw()
  63678. {
  63679. float h, s, b;
  63680. getHSB (h, s, b);
  63681. return Colour (h, saturation, b, getAlpha());
  63682. }
  63683. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63684. {
  63685. float h, s, b;
  63686. getHSB (h, s, b);
  63687. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63688. }
  63689. float Colour::getBrightness() const throw()
  63690. {
  63691. float h, s, b;
  63692. getHSB (h, s, b);
  63693. return b;
  63694. }
  63695. const Colour Colour::withBrightness (const float brightness) const throw()
  63696. {
  63697. float h, s, b;
  63698. getHSB (h, s, b);
  63699. return Colour (h, s, brightness, getAlpha());
  63700. }
  63701. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63702. {
  63703. float h, s, b;
  63704. getHSB (h, s, b);
  63705. b *= amount;
  63706. if (b > 1.0f)
  63707. b = 1.0f;
  63708. return Colour (h, s, b, getAlpha());
  63709. }
  63710. const Colour Colour::brighter (float amount) const throw()
  63711. {
  63712. amount = 1.0f / (1.0f + amount);
  63713. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63714. (uint8) (255 - (amount * (255 - getGreen()))),
  63715. (uint8) (255 - (amount * (255 - getBlue()))),
  63716. getAlpha());
  63717. }
  63718. const Colour Colour::darker (float amount) const throw()
  63719. {
  63720. amount = 1.0f / (1.0f + amount);
  63721. return Colour ((uint8) (amount * getRed()),
  63722. (uint8) (amount * getGreen()),
  63723. (uint8) (amount * getBlue()),
  63724. getAlpha());
  63725. }
  63726. const Colour Colour::greyLevel (const float brightness) throw()
  63727. {
  63728. const uint8 level
  63729. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63730. return Colour (level, level, level);
  63731. }
  63732. const Colour Colour::contrasting (const float amount) const throw()
  63733. {
  63734. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63735. ? Colours::black
  63736. : Colours::white).withAlpha (amount));
  63737. }
  63738. const Colour Colour::contrasting (const Colour& colour1,
  63739. const Colour& colour2) throw()
  63740. {
  63741. const float b1 = colour1.getBrightness();
  63742. const float b2 = colour2.getBrightness();
  63743. float best = 0.0f;
  63744. float bestDist = 0.0f;
  63745. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63746. {
  63747. const float d1 = fabsf (i - b1);
  63748. const float d2 = fabsf (i - b2);
  63749. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63750. if (dist > bestDist)
  63751. {
  63752. best = i;
  63753. bestDist = dist;
  63754. }
  63755. }
  63756. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63757. .withBrightness (best);
  63758. }
  63759. const String Colour::toString() const throw()
  63760. {
  63761. return String::toHexString ((int) argb.getARGB());
  63762. }
  63763. const Colour Colour::fromString (const String& encodedColourString)
  63764. {
  63765. return Colour ((uint32) encodedColourString.getHexValue32());
  63766. }
  63767. END_JUCE_NAMESPACE
  63768. /*** End of inlined file: juce_Colour.cpp ***/
  63769. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63770. BEGIN_JUCE_NAMESPACE
  63771. ColourGradient::ColourGradient() throw()
  63772. {
  63773. #ifdef JUCE_DEBUG
  63774. x1 = 987654.0f;
  63775. #endif
  63776. }
  63777. ColourGradient::ColourGradient (const Colour& colour1,
  63778. const float x1_,
  63779. const float y1_,
  63780. const Colour& colour2,
  63781. const float x2_,
  63782. const float y2_,
  63783. const bool isRadial_) throw()
  63784. : x1 (x1_),
  63785. y1 (y1_),
  63786. x2 (x2_),
  63787. y2 (y2_),
  63788. isRadial (isRadial_)
  63789. {
  63790. colours.add (0);
  63791. colours.add (colour1.getARGB());
  63792. colours.add (1 << 16);
  63793. colours.add (colour2.getARGB());
  63794. }
  63795. ColourGradient::~ColourGradient() throw()
  63796. {
  63797. }
  63798. void ColourGradient::clearColours() throw()
  63799. {
  63800. colours.clear();
  63801. }
  63802. void ColourGradient::addColour (const double proportionAlongGradient,
  63803. const Colour& colour) throw()
  63804. {
  63805. // must be within the two end-points
  63806. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63807. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63808. int i;
  63809. for (i = 0; i < colours.size(); i += 2)
  63810. if (colours.getUnchecked(i) > pos)
  63811. break;
  63812. colours.insert (i, pos);
  63813. colours.insert (i + 1, colour.getARGB());
  63814. }
  63815. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63816. {
  63817. for (int i = 1; i < colours.size(); i += 2)
  63818. {
  63819. const Colour c (colours.getUnchecked(i));
  63820. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63821. }
  63822. }
  63823. int ColourGradient::getNumColours() const throw()
  63824. {
  63825. return colours.size() >> 1;
  63826. }
  63827. double ColourGradient::getColourPosition (const int index) const throw()
  63828. {
  63829. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63830. }
  63831. const Colour ColourGradient::getColour (const int index) const throw()
  63832. {
  63833. return Colour (colours [(index << 1) + 1]);
  63834. }
  63835. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63836. {
  63837. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63838. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63839. if (integerPos <= 0 || colours.size() <= 2)
  63840. return getColour (0);
  63841. int i = colours.size() - 2;
  63842. while (integerPos < (int) colours.getUnchecked(i))
  63843. i -= 2;
  63844. if (i >= colours.size() - 2)
  63845. return Colour (colours.getUnchecked(i));
  63846. const int pos1 = colours.getUnchecked (i);
  63847. const Colour col1 (colours.getUnchecked (i + 1));
  63848. const int pos2 = colours.getUnchecked (i + 2);
  63849. const Colour col2 (colours.getUnchecked (i + 3));
  63850. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63851. }
  63852. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63853. {
  63854. #ifdef JUCE_DEBUG
  63855. // trying to use the object without setting its co-ordinates? Have a careful read of
  63856. // the comments for the constructors.
  63857. jassert (x1 != 987654.0f);
  63858. #endif
  63859. const int numColours = colours.size() >> 1;
  63860. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63861. transform.transformPoint (tx1, ty1);
  63862. transform.transformPoint (tx2, ty2);
  63863. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63864. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63865. lookupTable.malloc (numEntries);
  63866. if (numColours >= 2)
  63867. {
  63868. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63869. PixelARGB pix1 (colours.getUnchecked (1));
  63870. pix1.premultiply();
  63871. int index = 0;
  63872. for (int j = 2; j < colours.size(); j += 2)
  63873. {
  63874. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63875. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63876. pix2.premultiply();
  63877. for (int i = 0; i < numToDo; ++i)
  63878. {
  63879. jassert (index >= 0 && index < numEntries);
  63880. lookupTable[index] = pix1;
  63881. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63882. ++index;
  63883. }
  63884. pix1 = pix2;
  63885. }
  63886. while (index < numEntries)
  63887. lookupTable [index++] = pix1;
  63888. }
  63889. else
  63890. {
  63891. jassertfalse // no colours specified!
  63892. }
  63893. return numEntries;
  63894. }
  63895. bool ColourGradient::isOpaque() const throw()
  63896. {
  63897. for (int i = 1; i < colours.size(); i += 2)
  63898. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63899. return false;
  63900. return true;
  63901. }
  63902. bool ColourGradient::isInvisible() const throw()
  63903. {
  63904. for (int i = 1; i < colours.size(); i += 2)
  63905. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63906. return false;
  63907. return true;
  63908. }
  63909. END_JUCE_NAMESPACE
  63910. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63911. /*** Start of inlined file: juce_Colours.cpp ***/
  63912. BEGIN_JUCE_NAMESPACE
  63913. const Colour Colours::transparentBlack (0);
  63914. const Colour Colours::transparentWhite (0x00ffffff);
  63915. const Colour Colours::aliceblue (0xfff0f8ff);
  63916. const Colour Colours::antiquewhite (0xfffaebd7);
  63917. const Colour Colours::aqua (0xff00ffff);
  63918. const Colour Colours::aquamarine (0xff7fffd4);
  63919. const Colour Colours::azure (0xfff0ffff);
  63920. const Colour Colours::beige (0xfff5f5dc);
  63921. const Colour Colours::bisque (0xffffe4c4);
  63922. const Colour Colours::black (0xff000000);
  63923. const Colour Colours::blanchedalmond (0xffffebcd);
  63924. const Colour Colours::blue (0xff0000ff);
  63925. const Colour Colours::blueviolet (0xff8a2be2);
  63926. const Colour Colours::brown (0xffa52a2a);
  63927. const Colour Colours::burlywood (0xffdeb887);
  63928. const Colour Colours::cadetblue (0xff5f9ea0);
  63929. const Colour Colours::chartreuse (0xff7fff00);
  63930. const Colour Colours::chocolate (0xffd2691e);
  63931. const Colour Colours::coral (0xffff7f50);
  63932. const Colour Colours::cornflowerblue (0xff6495ed);
  63933. const Colour Colours::cornsilk (0xfffff8dc);
  63934. const Colour Colours::crimson (0xffdc143c);
  63935. const Colour Colours::cyan (0xff00ffff);
  63936. const Colour Colours::darkblue (0xff00008b);
  63937. const Colour Colours::darkcyan (0xff008b8b);
  63938. const Colour Colours::darkgoldenrod (0xffb8860b);
  63939. const Colour Colours::darkgrey (0xff555555);
  63940. const Colour Colours::darkgreen (0xff006400);
  63941. const Colour Colours::darkkhaki (0xffbdb76b);
  63942. const Colour Colours::darkmagenta (0xff8b008b);
  63943. const Colour Colours::darkolivegreen (0xff556b2f);
  63944. const Colour Colours::darkorange (0xffff8c00);
  63945. const Colour Colours::darkorchid (0xff9932cc);
  63946. const Colour Colours::darkred (0xff8b0000);
  63947. const Colour Colours::darksalmon (0xffe9967a);
  63948. const Colour Colours::darkseagreen (0xff8fbc8f);
  63949. const Colour Colours::darkslateblue (0xff483d8b);
  63950. const Colour Colours::darkslategrey (0xff2f4f4f);
  63951. const Colour Colours::darkturquoise (0xff00ced1);
  63952. const Colour Colours::darkviolet (0xff9400d3);
  63953. const Colour Colours::deeppink (0xffff1493);
  63954. const Colour Colours::deepskyblue (0xff00bfff);
  63955. const Colour Colours::dimgrey (0xff696969);
  63956. const Colour Colours::dodgerblue (0xff1e90ff);
  63957. const Colour Colours::firebrick (0xffb22222);
  63958. const Colour Colours::floralwhite (0xfffffaf0);
  63959. const Colour Colours::forestgreen (0xff228b22);
  63960. const Colour Colours::fuchsia (0xffff00ff);
  63961. const Colour Colours::gainsboro (0xffdcdcdc);
  63962. const Colour Colours::gold (0xffffd700);
  63963. const Colour Colours::goldenrod (0xffdaa520);
  63964. const Colour Colours::grey (0xff808080);
  63965. const Colour Colours::green (0xff008000);
  63966. const Colour Colours::greenyellow (0xffadff2f);
  63967. const Colour Colours::honeydew (0xfff0fff0);
  63968. const Colour Colours::hotpink (0xffff69b4);
  63969. const Colour Colours::indianred (0xffcd5c5c);
  63970. const Colour Colours::indigo (0xff4b0082);
  63971. const Colour Colours::ivory (0xfffffff0);
  63972. const Colour Colours::khaki (0xfff0e68c);
  63973. const Colour Colours::lavender (0xffe6e6fa);
  63974. const Colour Colours::lavenderblush (0xfffff0f5);
  63975. const Colour Colours::lemonchiffon (0xfffffacd);
  63976. const Colour Colours::lightblue (0xffadd8e6);
  63977. const Colour Colours::lightcoral (0xfff08080);
  63978. const Colour Colours::lightcyan (0xffe0ffff);
  63979. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63980. const Colour Colours::lightgreen (0xff90ee90);
  63981. const Colour Colours::lightgrey (0xffd3d3d3);
  63982. const Colour Colours::lightpink (0xffffb6c1);
  63983. const Colour Colours::lightsalmon (0xffffa07a);
  63984. const Colour Colours::lightseagreen (0xff20b2aa);
  63985. const Colour Colours::lightskyblue (0xff87cefa);
  63986. const Colour Colours::lightslategrey (0xff778899);
  63987. const Colour Colours::lightsteelblue (0xffb0c4de);
  63988. const Colour Colours::lightyellow (0xffffffe0);
  63989. const Colour Colours::lime (0xff00ff00);
  63990. const Colour Colours::limegreen (0xff32cd32);
  63991. const Colour Colours::linen (0xfffaf0e6);
  63992. const Colour Colours::magenta (0xffff00ff);
  63993. const Colour Colours::maroon (0xff800000);
  63994. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63995. const Colour Colours::mediumblue (0xff0000cd);
  63996. const Colour Colours::mediumorchid (0xffba55d3);
  63997. const Colour Colours::mediumpurple (0xff9370db);
  63998. const Colour Colours::mediumseagreen (0xff3cb371);
  63999. const Colour Colours::mediumslateblue (0xff7b68ee);
  64000. const Colour Colours::mediumspringgreen (0xff00fa9a);
  64001. const Colour Colours::mediumturquoise (0xff48d1cc);
  64002. const Colour Colours::mediumvioletred (0xffc71585);
  64003. const Colour Colours::midnightblue (0xff191970);
  64004. const Colour Colours::mintcream (0xfff5fffa);
  64005. const Colour Colours::mistyrose (0xffffe4e1);
  64006. const Colour Colours::navajowhite (0xffffdead);
  64007. const Colour Colours::navy (0xff000080);
  64008. const Colour Colours::oldlace (0xfffdf5e6);
  64009. const Colour Colours::olive (0xff808000);
  64010. const Colour Colours::olivedrab (0xff6b8e23);
  64011. const Colour Colours::orange (0xffffa500);
  64012. const Colour Colours::orangered (0xffff4500);
  64013. const Colour Colours::orchid (0xffda70d6);
  64014. const Colour Colours::palegoldenrod (0xffeee8aa);
  64015. const Colour Colours::palegreen (0xff98fb98);
  64016. const Colour Colours::paleturquoise (0xffafeeee);
  64017. const Colour Colours::palevioletred (0xffdb7093);
  64018. const Colour Colours::papayawhip (0xffffefd5);
  64019. const Colour Colours::peachpuff (0xffffdab9);
  64020. const Colour Colours::peru (0xffcd853f);
  64021. const Colour Colours::pink (0xffffc0cb);
  64022. const Colour Colours::plum (0xffdda0dd);
  64023. const Colour Colours::powderblue (0xffb0e0e6);
  64024. const Colour Colours::purple (0xff800080);
  64025. const Colour Colours::red (0xffff0000);
  64026. const Colour Colours::rosybrown (0xffbc8f8f);
  64027. const Colour Colours::royalblue (0xff4169e1);
  64028. const Colour Colours::saddlebrown (0xff8b4513);
  64029. const Colour Colours::salmon (0xfffa8072);
  64030. const Colour Colours::sandybrown (0xfff4a460);
  64031. const Colour Colours::seagreen (0xff2e8b57);
  64032. const Colour Colours::seashell (0xfffff5ee);
  64033. const Colour Colours::sienna (0xffa0522d);
  64034. const Colour Colours::silver (0xffc0c0c0);
  64035. const Colour Colours::skyblue (0xff87ceeb);
  64036. const Colour Colours::slateblue (0xff6a5acd);
  64037. const Colour Colours::slategrey (0xff708090);
  64038. const Colour Colours::snow (0xfffffafa);
  64039. const Colour Colours::springgreen (0xff00ff7f);
  64040. const Colour Colours::steelblue (0xff4682b4);
  64041. const Colour Colours::tan (0xffd2b48c);
  64042. const Colour Colours::teal (0xff008080);
  64043. const Colour Colours::thistle (0xffd8bfd8);
  64044. const Colour Colours::tomato (0xffff6347);
  64045. const Colour Colours::turquoise (0xff40e0d0);
  64046. const Colour Colours::violet (0xffee82ee);
  64047. const Colour Colours::wheat (0xfff5deb3);
  64048. const Colour Colours::white (0xffffffff);
  64049. const Colour Colours::whitesmoke (0xfff5f5f5);
  64050. const Colour Colours::yellow (0xffffff00);
  64051. const Colour Colours::yellowgreen (0xff9acd32);
  64052. const Colour Colours::findColourForName (const String& colourName,
  64053. const Colour& defaultColour)
  64054. {
  64055. static const int presets[] =
  64056. {
  64057. // (first value is the string's hashcode, second is ARGB)
  64058. 0x05978fff, 0xff000000, /* black */
  64059. 0x06bdcc29, 0xffffffff, /* white */
  64060. 0x002e305a, 0xff0000ff, /* blue */
  64061. 0x00308adf, 0xff808080, /* grey */
  64062. 0x05e0cf03, 0xff008000, /* green */
  64063. 0x0001b891, 0xffff0000, /* red */
  64064. 0xd43c6474, 0xffffff00, /* yellow */
  64065. 0x620886da, 0xfff0f8ff, /* aliceblue */
  64066. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  64067. 0x002dcebc, 0xff00ffff, /* aqua */
  64068. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  64069. 0x0590228f, 0xfff0ffff, /* azure */
  64070. 0x05947fe4, 0xfff5f5dc, /* beige */
  64071. 0xad388e35, 0xffffe4c4, /* bisque */
  64072. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  64073. 0x39129959, 0xff8a2be2, /* blueviolet */
  64074. 0x059a8136, 0xffa52a2a, /* brown */
  64075. 0x89cea8f9, 0xffdeb887, /* burlywood */
  64076. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  64077. 0x6b748956, 0xff7fff00, /* chartreuse */
  64078. 0x2903623c, 0xffd2691e, /* chocolate */
  64079. 0x05a74431, 0xffff7f50, /* coral */
  64080. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  64081. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  64082. 0x3d8c4edf, 0xffdc143c, /* crimson */
  64083. 0x002ed323, 0xff00ffff, /* cyan */
  64084. 0x67cc74d0, 0xff00008b, /* darkblue */
  64085. 0x67cd1799, 0xff008b8b, /* darkcyan */
  64086. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  64087. 0x67cecf55, 0xff555555, /* darkgrey */
  64088. 0x920b194d, 0xff006400, /* darkgreen */
  64089. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  64090. 0x5c293873, 0xff8b008b, /* darkmagenta */
  64091. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  64092. 0xbcfd2524, 0xffff8c00, /* darkorange */
  64093. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  64094. 0x55ee0d5b, 0xff8b0000, /* darkred */
  64095. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  64096. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  64097. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  64098. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  64099. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  64100. 0xc8769375, 0xff9400d3, /* darkviolet */
  64101. 0x25832862, 0xffff1493, /* deeppink */
  64102. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  64103. 0x634c8b67, 0xff696969, /* dimgrey */
  64104. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  64105. 0xef19e3cb, 0xffb22222, /* firebrick */
  64106. 0xb852b195, 0xfffffaf0, /* floralwhite */
  64107. 0xd086fd06, 0xff228b22, /* forestgreen */
  64108. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  64109. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  64110. 0x00308060, 0xffffd700, /* gold */
  64111. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  64112. 0xbab8a537, 0xffadff2f, /* greenyellow */
  64113. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  64114. 0x41892743, 0xffff69b4, /* hotpink */
  64115. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  64116. 0xb969fed2, 0xff4b0082, /* indigo */
  64117. 0x05fef6a9, 0xfffffff0, /* ivory */
  64118. 0x06149302, 0xfff0e68c, /* khaki */
  64119. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  64120. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  64121. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  64122. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  64123. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  64124. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  64125. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  64126. 0xf40157ad, 0xff90ee90, /* lightgreen */
  64127. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  64128. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  64129. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  64130. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  64131. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  64132. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  64133. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  64134. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  64135. 0x0032afd5, 0xff00ff00, /* lime */
  64136. 0x607bbc4e, 0xff32cd32, /* limegreen */
  64137. 0x06234efa, 0xfffaf0e6, /* linen */
  64138. 0x316858a9, 0xffff00ff, /* magenta */
  64139. 0xbf8ca470, 0xff800000, /* maroon */
  64140. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  64141. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  64142. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  64143. 0x07556b71, 0xff9370db, /* mediumpurple */
  64144. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  64145. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  64146. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  64147. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  64148. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  64149. 0x168eb32a, 0xff191970, /* midnightblue */
  64150. 0x4306b960, 0xfff5fffa, /* mintcream */
  64151. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  64152. 0xe97218a6, 0xffffdead, /* navajowhite */
  64153. 0x00337bb6, 0xff000080, /* navy */
  64154. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  64155. 0x064ee1db, 0xff808000, /* olive */
  64156. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  64157. 0xc3de262e, 0xffffa500, /* orange */
  64158. 0x58bebba3, 0xffff4500, /* orangered */
  64159. 0xc3def8a3, 0xffda70d6, /* orchid */
  64160. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  64161. 0x3d9dd619, 0xff98fb98, /* palegreen */
  64162. 0x74022737, 0xffafeeee, /* paleturquoise */
  64163. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  64164. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  64165. 0x93e1b776, 0xffffdab9, /* peachpuff */
  64166. 0x003472f8, 0xffcd853f, /* peru */
  64167. 0x00348176, 0xffffc0cb, /* pink */
  64168. 0x00348d94, 0xffdda0dd, /* plum */
  64169. 0xd036be93, 0xffb0e0e6, /* powderblue */
  64170. 0xc5c507bc, 0xff800080, /* purple */
  64171. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  64172. 0xbd9413e1, 0xff4169e1, /* royalblue */
  64173. 0xf456044f, 0xff8b4513, /* saddlebrown */
  64174. 0xc9c6f66e, 0xfffa8072, /* salmon */
  64175. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  64176. 0x34636c14, 0xff2e8b57, /* seagreen */
  64177. 0x3507fb41, 0xfffff5ee, /* seashell */
  64178. 0xca348772, 0xffa0522d, /* sienna */
  64179. 0xca37d30d, 0xffc0c0c0, /* silver */
  64180. 0x80da74fb, 0xff87ceeb, /* skyblue */
  64181. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  64182. 0x44ab37f8, 0xff708090, /* slategrey */
  64183. 0x0035f183, 0xfffffafa, /* snow */
  64184. 0xd5440d16, 0xff00ff7f, /* springgreen */
  64185. 0x3e1524a5, 0xff4682b4, /* steelblue */
  64186. 0x0001bfa1, 0xffd2b48c, /* tan */
  64187. 0x0036425c, 0xff008080, /* teal */
  64188. 0xafc8858f, 0xffd8bfd8, /* thistle */
  64189. 0xcc41600a, 0xffff6347, /* tomato */
  64190. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  64191. 0xcf57947f, 0xffee82ee, /* violet */
  64192. 0x06bdbae7, 0xfff5deb3, /* wheat */
  64193. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  64194. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  64195. };
  64196. const int hash = colourName.trim().toLowerCase().hashCode();
  64197. for (int i = 0; i < numElementsInArray (presets); i += 2)
  64198. if (presets [i] == hash)
  64199. return Colour (presets [i + 1]);
  64200. return defaultColour;
  64201. }
  64202. END_JUCE_NAMESPACE
  64203. /*** End of inlined file: juce_Colours.cpp ***/
  64204. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  64205. BEGIN_JUCE_NAMESPACE
  64206. const int juce_edgeTableDefaultEdgesPerLine = 32;
  64207. static void copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  64208. {
  64209. while (--numLines >= 0)
  64210. {
  64211. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  64212. src += srcLineStride;
  64213. dest += destLineStride;
  64214. }
  64215. }
  64216. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  64217. const Path& path, const AffineTransform& transform) throw()
  64218. : bounds (bounds_),
  64219. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64220. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64221. needToCheckEmptinesss (true)
  64222. {
  64223. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  64224. int* t = table;
  64225. for (int i = bounds.getHeight(); --i >= 0;)
  64226. {
  64227. *t = 0;
  64228. t += lineStrideElements;
  64229. }
  64230. const int topLimit = bounds.getY() << 8;
  64231. const int heightLimit = bounds.getHeight() << 8;
  64232. const int leftLimit = bounds.getX() << 8;
  64233. const int rightLimit = bounds.getRight() << 8;
  64234. PathFlatteningIterator iter (path, transform);
  64235. while (iter.next())
  64236. {
  64237. int y1 = roundToInt (iter.y1 * 256.0f);
  64238. int y2 = roundToInt (iter.y2 * 256.0f);
  64239. if (y1 != y2)
  64240. {
  64241. y1 -= topLimit;
  64242. y2 -= topLimit;
  64243. const int startY = y1;
  64244. int direction = -1;
  64245. if (y1 > y2)
  64246. {
  64247. swapVariables (y1, y2);
  64248. direction = 1;
  64249. }
  64250. if (y1 < 0)
  64251. y1 = 0;
  64252. if (y2 > heightLimit)
  64253. y2 = heightLimit;
  64254. if (y1 < y2)
  64255. {
  64256. const double startX = 256.0f * iter.x1;
  64257. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  64258. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  64259. do
  64260. {
  64261. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  64262. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  64263. if (x < leftLimit)
  64264. x = leftLimit;
  64265. else if (x >= rightLimit)
  64266. x = rightLimit - 1;
  64267. addEdgePoint (x, y1 >> 8, direction * step);
  64268. y1 += step;
  64269. }
  64270. while (y1 < y2);
  64271. }
  64272. }
  64273. }
  64274. sanitiseLevels (path.isUsingNonZeroWinding());
  64275. }
  64276. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd) throw()
  64277. : bounds (rectangleToAdd),
  64278. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64279. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64280. needToCheckEmptinesss (true)
  64281. {
  64282. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64283. table[0] = 0;
  64284. const int x1 = rectangleToAdd.getX() << 8;
  64285. const int x2 = rectangleToAdd.getRight() << 8;
  64286. int* t = table;
  64287. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  64288. {
  64289. t[0] = 2;
  64290. t[1] = x1;
  64291. t[2] = 255;
  64292. t[3] = x2;
  64293. t[4] = 0;
  64294. t += lineStrideElements;
  64295. }
  64296. }
  64297. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd) throw()
  64298. : bounds (rectanglesToAdd.getBounds()),
  64299. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64300. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64301. needToCheckEmptinesss (true)
  64302. {
  64303. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64304. int* t = table;
  64305. for (int i = bounds.getHeight(); --i >= 0;)
  64306. {
  64307. *t = 0;
  64308. t += lineStrideElements;
  64309. }
  64310. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  64311. {
  64312. const Rectangle<int>* const r = iter.getRectangle();
  64313. const int x1 = r->getX() << 8;
  64314. const int x2 = r->getRight() << 8;
  64315. int y = r->getY() - bounds.getY();
  64316. for (int j = r->getHeight(); --j >= 0;)
  64317. {
  64318. addEdgePoint (x1, y, 255);
  64319. addEdgePoint (x2, y, -255);
  64320. ++y;
  64321. }
  64322. }
  64323. sanitiseLevels (true);
  64324. }
  64325. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h) throw()
  64326. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  64327. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64328. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64329. needToCheckEmptinesss (true)
  64330. {
  64331. jassert (w > 0 && h > 0);
  64332. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64333. table[0] = 0;
  64334. const int x1 = roundToInt (x * 256.0f);
  64335. const int x2 = roundToInt ((x + w) * 256.0f);
  64336. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  64337. jassert (y1 < 256);
  64338. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  64339. if (x2 <= x1 || y2 <= y1)
  64340. {
  64341. bounds.setHeight (0);
  64342. return;
  64343. }
  64344. int lineY = 0;
  64345. int* t = table;
  64346. if ((y1 >> 8) == (y2 >> 8))
  64347. {
  64348. t[0] = 2;
  64349. t[1] = x1;
  64350. t[2] = y2 - y1;
  64351. t[3] = x2;
  64352. t[4] = 0;
  64353. ++lineY;
  64354. t += lineStrideElements;
  64355. }
  64356. else
  64357. {
  64358. t[0] = 2;
  64359. t[1] = x1;
  64360. t[2] = 255 - (y1 & 255);
  64361. t[3] = x2;
  64362. t[4] = 0;
  64363. ++lineY;
  64364. t += lineStrideElements;
  64365. while (lineY < (y2 >> 8))
  64366. {
  64367. t[0] = 2;
  64368. t[1] = x1;
  64369. t[2] = 255;
  64370. t[3] = x2;
  64371. t[4] = 0;
  64372. ++lineY;
  64373. t += lineStrideElements;
  64374. }
  64375. jassert (lineY < bounds.getHeight());
  64376. t[0] = 2;
  64377. t[1] = x1;
  64378. t[2] = y2 & 255;
  64379. t[3] = x2;
  64380. t[4] = 0;
  64381. ++lineY;
  64382. t += lineStrideElements;
  64383. }
  64384. while (lineY < bounds.getHeight())
  64385. {
  64386. t[0] = 0;
  64387. t += lineStrideElements;
  64388. ++lineY;
  64389. }
  64390. }
  64391. EdgeTable::EdgeTable (const EdgeTable& other) throw()
  64392. : table (0)
  64393. {
  64394. operator= (other);
  64395. }
  64396. const EdgeTable& EdgeTable::operator= (const EdgeTable& other) throw()
  64397. {
  64398. bounds = other.bounds;
  64399. maxEdgesPerLine = other.maxEdgesPerLine;
  64400. lineStrideElements = other.lineStrideElements;
  64401. needToCheckEmptinesss = other.needToCheckEmptinesss;
  64402. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64403. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  64404. return *this;
  64405. }
  64406. EdgeTable::~EdgeTable() throw()
  64407. {
  64408. }
  64409. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  64410. {
  64411. // Convert the table from relative windings to absolute levels..
  64412. int* lineStart = table;
  64413. for (int i = bounds.getHeight(); --i >= 0;)
  64414. {
  64415. int* line = lineStart;
  64416. lineStart += lineStrideElements;
  64417. int num = *line;
  64418. if (num == 0)
  64419. continue;
  64420. int level = 0;
  64421. if (useNonZeroWinding)
  64422. {
  64423. while (--num > 0)
  64424. {
  64425. line += 2;
  64426. level += *line;
  64427. int corrected = abs (level);
  64428. if (corrected >> 8)
  64429. corrected = 255;
  64430. *line = corrected;
  64431. }
  64432. }
  64433. else
  64434. {
  64435. while (--num > 0)
  64436. {
  64437. line += 2;
  64438. level += *line;
  64439. int corrected = abs (level);
  64440. if (corrected >> 8)
  64441. {
  64442. corrected &= 511;
  64443. if (corrected >> 8)
  64444. corrected = 511 - corrected;
  64445. }
  64446. *line = corrected;
  64447. }
  64448. }
  64449. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  64450. }
  64451. }
  64452. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  64453. {
  64454. if (newNumEdgesPerLine != maxEdgesPerLine)
  64455. {
  64456. maxEdgesPerLine = newNumEdgesPerLine;
  64457. jassert (bounds.getHeight() > 0);
  64458. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  64459. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  64460. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  64461. table.swapWith (newTable);
  64462. lineStrideElements = newLineStrideElements;
  64463. }
  64464. }
  64465. void EdgeTable::optimiseTable() throw()
  64466. {
  64467. int maxLineElements = 0;
  64468. for (int i = bounds.getHeight(); --i >= 0;)
  64469. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  64470. remapTableForNumEdges (maxLineElements);
  64471. }
  64472. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  64473. {
  64474. jassert (y >= 0 && y < bounds.getHeight());
  64475. int* line = table + lineStrideElements * y;
  64476. const int numPoints = line[0];
  64477. int n = numPoints << 1;
  64478. if (n > 0)
  64479. {
  64480. while (n > 0)
  64481. {
  64482. const int cx = line [n - 1];
  64483. if (cx <= x)
  64484. {
  64485. if (cx == x)
  64486. {
  64487. line [n] += winding;
  64488. return;
  64489. }
  64490. break;
  64491. }
  64492. n -= 2;
  64493. }
  64494. if (numPoints >= maxEdgesPerLine)
  64495. {
  64496. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64497. jassert (numPoints < maxEdgesPerLine);
  64498. line = table + lineStrideElements * y;
  64499. }
  64500. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  64501. }
  64502. line [n + 1] = x;
  64503. line [n + 2] = winding;
  64504. line[0]++;
  64505. }
  64506. void EdgeTable::translate (float dx, int dy) throw()
  64507. {
  64508. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  64509. int* lineStart = table;
  64510. const int intDx = (int) (dx * 256.0f);
  64511. for (int i = bounds.getHeight(); --i >= 0;)
  64512. {
  64513. int* line = lineStart;
  64514. lineStart += lineStrideElements;
  64515. int num = *line++;
  64516. while (--num >= 0)
  64517. {
  64518. *line += intDx;
  64519. line += 2;
  64520. }
  64521. }
  64522. }
  64523. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  64524. {
  64525. jassert (y >= 0 && y < bounds.getHeight());
  64526. int* dest = table + lineStrideElements * y;
  64527. if (dest[0] == 0)
  64528. return;
  64529. int otherNumPoints = *otherLine;
  64530. if (otherNumPoints == 0)
  64531. {
  64532. *dest = 0;
  64533. return;
  64534. }
  64535. const int right = bounds.getRight() << 8;
  64536. // optimise for the common case where our line lies entirely within a
  64537. // single pair of points, as happens when clipping to a simple rect.
  64538. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64539. {
  64540. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64541. return;
  64542. }
  64543. ++otherLine;
  64544. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64545. int* temp = (int*) alloca (lineSizeBytes);
  64546. memcpy (temp, dest, lineSizeBytes);
  64547. const int* src1 = temp;
  64548. int srcNum1 = *src1++;
  64549. int x1 = *src1++;
  64550. const int* src2 = otherLine;
  64551. int srcNum2 = otherNumPoints;
  64552. int x2 = *src2++;
  64553. int destIndex = 0, destTotal = 0;
  64554. int level1 = 0, level2 = 0;
  64555. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  64556. while (srcNum1 > 0 && srcNum2 > 0)
  64557. {
  64558. int nextX;
  64559. if (x1 < x2)
  64560. {
  64561. nextX = x1;
  64562. level1 = *src1++;
  64563. x1 = *src1++;
  64564. --srcNum1;
  64565. }
  64566. else if (x1 == x2)
  64567. {
  64568. nextX = x1;
  64569. level1 = *src1++;
  64570. level2 = *src2++;
  64571. x1 = *src1++;
  64572. x2 = *src2++;
  64573. --srcNum1;
  64574. --srcNum2;
  64575. }
  64576. else
  64577. {
  64578. nextX = x2;
  64579. level2 = *src2++;
  64580. x2 = *src2++;
  64581. --srcNum2;
  64582. }
  64583. if (nextX > lastX)
  64584. {
  64585. if (nextX >= right)
  64586. break;
  64587. lastX = nextX;
  64588. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64589. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64590. if (nextLevel != lastLevel)
  64591. {
  64592. if (destTotal >= maxEdgesPerLine)
  64593. {
  64594. dest[0] = destTotal;
  64595. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64596. dest = table + lineStrideElements * y;
  64597. }
  64598. ++destTotal;
  64599. lastLevel = nextLevel;
  64600. dest[++destIndex] = nextX;
  64601. dest[++destIndex] = nextLevel;
  64602. }
  64603. }
  64604. }
  64605. if (lastLevel > 0)
  64606. {
  64607. if (destTotal >= maxEdgesPerLine)
  64608. {
  64609. dest[0] = destTotal;
  64610. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64611. dest = table + lineStrideElements * y;
  64612. }
  64613. ++destTotal;
  64614. dest[++destIndex] = right;
  64615. dest[++destIndex] = 0;
  64616. }
  64617. dest[0] = destTotal;
  64618. #if JUCE_DEBUG
  64619. int last = std::numeric_limits<int>::min();
  64620. for (int i = 0; i < dest[0]; ++i)
  64621. {
  64622. jassert (dest[i * 2 + 1] > last);
  64623. last = dest[i * 2 + 1];
  64624. }
  64625. jassert (dest [dest[0] * 2] == 0);
  64626. #endif
  64627. }
  64628. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64629. {
  64630. int* lastItem = dest + (dest[0] * 2 - 1);
  64631. if (x2 < lastItem[0])
  64632. {
  64633. if (x2 <= dest[1])
  64634. {
  64635. dest[0] = 0;
  64636. return;
  64637. }
  64638. while (x2 < lastItem[-2])
  64639. {
  64640. --(dest[0]);
  64641. lastItem -= 2;
  64642. }
  64643. lastItem[0] = x2;
  64644. lastItem[1] = 0;
  64645. }
  64646. if (x1 > dest[1])
  64647. {
  64648. while (lastItem[0] > x1)
  64649. lastItem -= 2;
  64650. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64651. if (itemsRemoved > 0)
  64652. {
  64653. dest[0] -= itemsRemoved;
  64654. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64655. }
  64656. dest[1] = x1;
  64657. }
  64658. }
  64659. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64660. {
  64661. const Rectangle<int> clipped (r.getIntersection (bounds));
  64662. if (clipped.isEmpty())
  64663. {
  64664. needToCheckEmptinesss = false;
  64665. bounds.setHeight (0);
  64666. }
  64667. else
  64668. {
  64669. const int top = clipped.getY() - bounds.getY();
  64670. const int bottom = clipped.getBottom() - bounds.getY();
  64671. if (bottom < bounds.getHeight())
  64672. bounds.setHeight (bottom);
  64673. if (clipped.getRight() < bounds.getRight())
  64674. bounds.setRight (clipped.getRight());
  64675. for (int i = top; --i >= 0;)
  64676. table [lineStrideElements * i] = 0;
  64677. if (clipped.getX() > bounds.getX())
  64678. {
  64679. const int x1 = clipped.getX() << 8;
  64680. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64681. int* line = table + lineStrideElements * top;
  64682. for (int i = bottom - top; --i >= 0;)
  64683. {
  64684. if (line[0] != 0)
  64685. clipEdgeTableLineToRange (line, x1, x2);
  64686. line += lineStrideElements;
  64687. }
  64688. }
  64689. needToCheckEmptinesss = true;
  64690. }
  64691. }
  64692. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64693. {
  64694. const Rectangle<int> clipped (r.getIntersection (bounds));
  64695. if (! clipped.isEmpty())
  64696. {
  64697. const int top = clipped.getY() - bounds.getY();
  64698. const int bottom = clipped.getBottom() - bounds.getY();
  64699. //XXX optimise here by shortening the table if it fills top or bottom
  64700. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64701. clipped.getX() << 8, 0,
  64702. clipped.getRight() << 8, 255,
  64703. std::numeric_limits<int>::max(), 0 };
  64704. for (int i = top; i < bottom; ++i)
  64705. intersectWithEdgeTableLine (i, rectLine);
  64706. needToCheckEmptinesss = true;
  64707. }
  64708. }
  64709. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64710. {
  64711. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64712. if (clipped.isEmpty())
  64713. {
  64714. needToCheckEmptinesss = false;
  64715. bounds.setHeight (0);
  64716. }
  64717. else
  64718. {
  64719. const int top = clipped.getY() - bounds.getY();
  64720. const int bottom = clipped.getBottom() - bounds.getY();
  64721. if (bottom < bounds.getHeight())
  64722. bounds.setHeight (bottom);
  64723. if (clipped.getRight() < bounds.getRight())
  64724. bounds.setRight (clipped.getRight());
  64725. int i = 0;
  64726. for (i = top; --i >= 0;)
  64727. table [lineStrideElements * i] = 0;
  64728. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64729. for (i = top; i < bottom; ++i)
  64730. {
  64731. intersectWithEdgeTableLine (i, otherLine);
  64732. otherLine += other.lineStrideElements;
  64733. }
  64734. needToCheckEmptinesss = true;
  64735. }
  64736. }
  64737. void EdgeTable::clipLineToMask (int x, int y, uint8* mask, int maskStride, int numPixels) throw()
  64738. {
  64739. y -= bounds.getY();
  64740. if (y < 0 || y >= bounds.getHeight())
  64741. return;
  64742. needToCheckEmptinesss = true;
  64743. if (numPixels <= 0)
  64744. {
  64745. table [lineStrideElements * y] = 0;
  64746. return;
  64747. }
  64748. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64749. int destIndex = 0, lastLevel = 0;
  64750. while (--numPixels >= 0)
  64751. {
  64752. const int alpha = *mask;
  64753. mask += maskStride;
  64754. if (alpha != lastLevel)
  64755. {
  64756. tempLine[++destIndex] = (x << 8);
  64757. tempLine[++destIndex] = alpha;
  64758. lastLevel = alpha;
  64759. }
  64760. ++x;
  64761. }
  64762. if (lastLevel > 0)
  64763. {
  64764. tempLine[++destIndex] = (x << 8);
  64765. tempLine[++destIndex] = 0;
  64766. }
  64767. tempLine[0] = destIndex >> 1;
  64768. intersectWithEdgeTableLine (y, tempLine);
  64769. }
  64770. bool EdgeTable::isEmpty() throw()
  64771. {
  64772. if (needToCheckEmptinesss)
  64773. {
  64774. needToCheckEmptinesss = false;
  64775. int* t = table;
  64776. for (int i = bounds.getHeight(); --i >= 0;)
  64777. {
  64778. if (t[0] > 1)
  64779. return false;
  64780. t += lineStrideElements;
  64781. }
  64782. bounds.setHeight (0);
  64783. }
  64784. return bounds.getHeight() == 0;
  64785. }
  64786. END_JUCE_NAMESPACE
  64787. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64788. /*** Start of inlined file: juce_FillType.cpp ***/
  64789. BEGIN_JUCE_NAMESPACE
  64790. FillType::FillType() throw()
  64791. : colour (0xff000000), image (0)
  64792. {
  64793. }
  64794. FillType::FillType (const Colour& colour_) throw()
  64795. : colour (colour_), image (0)
  64796. {
  64797. }
  64798. FillType::FillType (const ColourGradient& gradient_) throw()
  64799. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64800. {
  64801. }
  64802. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64803. : colour (0xff000000), image (&image_), transform (transform_)
  64804. {
  64805. }
  64806. FillType::FillType (const FillType& other) throw()
  64807. : colour (other.colour),
  64808. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64809. image (other.image), transform (other.transform)
  64810. {
  64811. }
  64812. const FillType& FillType::operator= (const FillType& other) throw()
  64813. {
  64814. if (this != &other)
  64815. {
  64816. colour = other.colour;
  64817. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64818. image = other.image;
  64819. transform = other.transform;
  64820. }
  64821. return *this;
  64822. }
  64823. FillType::~FillType() throw()
  64824. {
  64825. }
  64826. void FillType::setColour (const Colour& newColour) throw()
  64827. {
  64828. gradient = 0;
  64829. image = 0;
  64830. colour = newColour;
  64831. }
  64832. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64833. {
  64834. if (gradient != 0)
  64835. {
  64836. *gradient = newGradient;
  64837. }
  64838. else
  64839. {
  64840. image = 0;
  64841. gradient = new ColourGradient (newGradient);
  64842. colour = Colours::black;
  64843. }
  64844. }
  64845. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64846. {
  64847. gradient = 0;
  64848. image = &image_;
  64849. transform = transform_;
  64850. colour = Colours::black;
  64851. }
  64852. void FillType::setOpacity (const float newOpacity) throw()
  64853. {
  64854. colour = colour.withAlpha (newOpacity);
  64855. }
  64856. END_JUCE_NAMESPACE
  64857. /*** End of inlined file: juce_FillType.cpp ***/
  64858. /*** Start of inlined file: juce_Graphics.cpp ***/
  64859. BEGIN_JUCE_NAMESPACE
  64860. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64861. template <typename Type>
  64862. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64863. {
  64864. const int maxVal = 0x3fffffff;
  64865. return (int) x >= -maxVal && (int) x <= maxVal
  64866. && (int) y >= -maxVal && (int) y <= maxVal
  64867. && (int) w >= -maxVal && (int) w <= maxVal
  64868. && (int) h >= -maxVal && (int) h <= maxVal;
  64869. }
  64870. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64871. {
  64872. }
  64873. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64874. {
  64875. }
  64876. Graphics::Graphics (Image& imageToDrawOnto) throw()
  64877. : context (imageToDrawOnto.createLowLevelContext()),
  64878. contextToDelete (context),
  64879. saveStatePending (false)
  64880. {
  64881. resetToDefaultState();
  64882. }
  64883. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64884. : context (internalContext),
  64885. saveStatePending (false)
  64886. {
  64887. resetToDefaultState();
  64888. }
  64889. Graphics::~Graphics() throw()
  64890. {
  64891. }
  64892. void Graphics::resetToDefaultState() throw()
  64893. {
  64894. saveStateIfPending();
  64895. context->setFill (FillType());
  64896. context->setFont (Font());
  64897. context->setInterpolationQuality (defaultQuality);
  64898. }
  64899. bool Graphics::isVectorDevice() const throw()
  64900. {
  64901. return context->isVectorDevice();
  64902. }
  64903. bool Graphics::reduceClipRegion (const int x, const int y,
  64904. const int w, const int h) throw()
  64905. {
  64906. saveStateIfPending();
  64907. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64908. }
  64909. bool Graphics::reduceClipRegion (const RectangleList& clipRegion) throw()
  64910. {
  64911. saveStateIfPending();
  64912. return context->clipToRectangleList (clipRegion);
  64913. }
  64914. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform) throw()
  64915. {
  64916. saveStateIfPending();
  64917. context->clipToPath (path, transform);
  64918. return ! context->isClipEmpty();
  64919. }
  64920. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform) throw()
  64921. {
  64922. saveStateIfPending();
  64923. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64924. return ! context->isClipEmpty();
  64925. }
  64926. void Graphics::excludeClipRegion (const int x, const int y,
  64927. const int w, const int h) throw()
  64928. {
  64929. saveStateIfPending();
  64930. context->excludeClipRectangle (Rectangle<int> (x, y, w, h));
  64931. }
  64932. bool Graphics::isClipEmpty() const throw()
  64933. {
  64934. return context->isClipEmpty();
  64935. }
  64936. const Rectangle<int> Graphics::getClipBounds() const throw()
  64937. {
  64938. return context->getClipBounds();
  64939. }
  64940. void Graphics::saveState() throw()
  64941. {
  64942. saveStateIfPending();
  64943. saveStatePending = true;
  64944. }
  64945. void Graphics::restoreState() throw()
  64946. {
  64947. if (saveStatePending)
  64948. saveStatePending = false;
  64949. else
  64950. context->restoreState();
  64951. }
  64952. void Graphics::saveStateIfPending() throw()
  64953. {
  64954. if (saveStatePending)
  64955. {
  64956. saveStatePending = false;
  64957. context->saveState();
  64958. }
  64959. }
  64960. void Graphics::setOrigin (const int newOriginX,
  64961. const int newOriginY) throw()
  64962. {
  64963. saveStateIfPending();
  64964. context->setOrigin (newOriginX, newOriginY);
  64965. }
  64966. bool Graphics::clipRegionIntersects (const int x, const int y,
  64967. const int w, const int h) const throw()
  64968. {
  64969. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64970. }
  64971. void Graphics::setColour (const Colour& newColour) throw()
  64972. {
  64973. saveStateIfPending();
  64974. context->setFill (FillType (newColour));
  64975. }
  64976. void Graphics::setOpacity (const float newOpacity) throw()
  64977. {
  64978. saveStateIfPending();
  64979. context->setOpacity (newOpacity);
  64980. }
  64981. void Graphics::setGradientFill (const ColourGradient& gradient) throw()
  64982. {
  64983. saveStateIfPending();
  64984. context->setFill (FillType (gradient));
  64985. }
  64986. void Graphics::setTiledImageFill (const Image& imageToUse,
  64987. const int anchorX,
  64988. const int anchorY,
  64989. const float opacity) throw()
  64990. {
  64991. saveStateIfPending();
  64992. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64993. context->setOpacity (opacity);
  64994. }
  64995. void Graphics::setFillType (const FillType& newFill) throw()
  64996. {
  64997. saveStateIfPending();
  64998. context->setFill (newFill);
  64999. }
  65000. void Graphics::setFont (const Font& newFont) throw()
  65001. {
  65002. saveStateIfPending();
  65003. context->setFont (newFont);
  65004. }
  65005. void Graphics::setFont (const float newFontHeight,
  65006. const int newFontStyleFlags) throw()
  65007. {
  65008. saveStateIfPending();
  65009. Font f (context->getFont());
  65010. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  65011. context->setFont (f);
  65012. }
  65013. void Graphics::drawSingleLineText (const String& text,
  65014. const int startX,
  65015. const int baselineY) const throw()
  65016. {
  65017. if (text.isNotEmpty()
  65018. && startX < context->getClipBounds().getRight())
  65019. {
  65020. GlyphArrangement arr;
  65021. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  65022. arr.draw (*this);
  65023. }
  65024. }
  65025. void Graphics::drawTextAsPath (const String& text,
  65026. const AffineTransform& transform) const throw()
  65027. {
  65028. if (text.isNotEmpty())
  65029. {
  65030. GlyphArrangement arr;
  65031. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  65032. arr.draw (*this, transform);
  65033. }
  65034. }
  65035. void Graphics::drawMultiLineText (const String& text,
  65036. const int startX,
  65037. const int baselineY,
  65038. const int maximumLineWidth) const throw()
  65039. {
  65040. if (text.isNotEmpty()
  65041. && startX < context->getClipBounds().getRight())
  65042. {
  65043. GlyphArrangement arr;
  65044. arr.addJustifiedText (context->getFont(), text,
  65045. (float) startX, (float) baselineY, (float) maximumLineWidth,
  65046. Justification::left);
  65047. arr.draw (*this);
  65048. }
  65049. }
  65050. void Graphics::drawText (const String& text,
  65051. const int x,
  65052. const int y,
  65053. const int width,
  65054. const int height,
  65055. const Justification& justificationType,
  65056. const bool useEllipsesIfTooBig) const throw()
  65057. {
  65058. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  65059. {
  65060. GlyphArrangement arr;
  65061. arr.addCurtailedLineOfText (context->getFont(), text,
  65062. 0.0f, 0.0f, (float)width,
  65063. useEllipsesIfTooBig);
  65064. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  65065. (float) x, (float) y,
  65066. (float) width, (float) height,
  65067. justificationType);
  65068. arr.draw (*this);
  65069. }
  65070. }
  65071. void Graphics::drawFittedText (const String& text,
  65072. const int x,
  65073. const int y,
  65074. const int width,
  65075. const int height,
  65076. const Justification& justification,
  65077. const int maximumNumberOfLines,
  65078. const float minimumHorizontalScale) const throw()
  65079. {
  65080. if (text.isNotEmpty()
  65081. && width > 0 && height > 0
  65082. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  65083. {
  65084. GlyphArrangement arr;
  65085. arr.addFittedText (context->getFont(), text,
  65086. (float) x, (float) y,
  65087. (float) width, (float) height,
  65088. justification,
  65089. maximumNumberOfLines,
  65090. minimumHorizontalScale);
  65091. arr.draw (*this);
  65092. }
  65093. }
  65094. void Graphics::fillRect (int x,
  65095. int y,
  65096. int width,
  65097. int height) const throw()
  65098. {
  65099. // passing in a silly number can cause maths problems in rendering!
  65100. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65101. context->fillRect (Rectangle<int> (x, y, width, height), false);
  65102. }
  65103. void Graphics::fillRect (const Rectangle<int>& r) const throw()
  65104. {
  65105. context->fillRect (r, false);
  65106. }
  65107. void Graphics::fillRect (const float x,
  65108. const float y,
  65109. const float width,
  65110. const float height) const throw()
  65111. {
  65112. // passing in a silly number can cause maths problems in rendering!
  65113. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65114. Path p;
  65115. p.addRectangle (x, y, width, height);
  65116. fillPath (p);
  65117. }
  65118. void Graphics::setPixel (int x, int y) const throw()
  65119. {
  65120. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  65121. }
  65122. void Graphics::fillAll() const throw()
  65123. {
  65124. fillRect (context->getClipBounds());
  65125. }
  65126. void Graphics::fillAll (const Colour& colourToUse) const throw()
  65127. {
  65128. if (! colourToUse.isTransparent())
  65129. {
  65130. const Rectangle<int> clip (context->getClipBounds());
  65131. context->saveState();
  65132. context->setFill (FillType (colourToUse));
  65133. context->fillRect (clip, false);
  65134. context->restoreState();
  65135. }
  65136. }
  65137. void Graphics::fillPath (const Path& path,
  65138. const AffineTransform& transform) const throw()
  65139. {
  65140. if ((! context->isClipEmpty()) && ! path.isEmpty())
  65141. context->fillPath (path, transform);
  65142. }
  65143. void Graphics::strokePath (const Path& path,
  65144. const PathStrokeType& strokeType,
  65145. const AffineTransform& transform) const throw()
  65146. {
  65147. Path stroke;
  65148. strokeType.createStrokedPath (stroke, path, transform);
  65149. fillPath (stroke);
  65150. }
  65151. void Graphics::drawRect (const int x,
  65152. const int y,
  65153. const int width,
  65154. const int height,
  65155. const int lineThickness) const throw()
  65156. {
  65157. // passing in a silly number can cause maths problems in rendering!
  65158. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65159. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  65160. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65161. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65162. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  65163. }
  65164. void Graphics::drawRect (const float x,
  65165. const float y,
  65166. const float width,
  65167. const float height,
  65168. const float lineThickness) const throw()
  65169. {
  65170. // passing in a silly number can cause maths problems in rendering!
  65171. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65172. Path p;
  65173. p.addRectangle (x, y, width, lineThickness);
  65174. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65175. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65176. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  65177. fillPath (p);
  65178. }
  65179. void Graphics::drawRect (const Rectangle<int>& r,
  65180. const int lineThickness) const throw()
  65181. {
  65182. drawRect (r.getX(), r.getY(),
  65183. r.getWidth(), r.getHeight(),
  65184. lineThickness);
  65185. }
  65186. void Graphics::drawBevel (const int x,
  65187. const int y,
  65188. const int width,
  65189. const int height,
  65190. const int bevelThickness,
  65191. const Colour& topLeftColour,
  65192. const Colour& bottomRightColour,
  65193. const bool useGradient,
  65194. const bool sharpEdgeOnOutside) const throw()
  65195. {
  65196. // passing in a silly number can cause maths problems in rendering!
  65197. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65198. if (clipRegionIntersects (x, y, width, height))
  65199. {
  65200. context->saveState();
  65201. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  65202. const float ramp = oldOpacity / bevelThickness;
  65203. for (int i = bevelThickness; --i >= 0;)
  65204. {
  65205. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  65206. : oldOpacity;
  65207. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op)));
  65208. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  65209. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op * 0.75f)));
  65210. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  65211. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op)));
  65212. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  65213. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op * 0.75f)));
  65214. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  65215. }
  65216. context->restoreState();
  65217. }
  65218. }
  65219. void Graphics::fillEllipse (const float x,
  65220. const float y,
  65221. const float width,
  65222. const float height) const throw()
  65223. {
  65224. // passing in a silly number can cause maths problems in rendering!
  65225. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65226. Path p;
  65227. p.addEllipse (x, y, width, height);
  65228. fillPath (p);
  65229. }
  65230. void Graphics::drawEllipse (const float x,
  65231. const float y,
  65232. const float width,
  65233. const float height,
  65234. const float lineThickness) const throw()
  65235. {
  65236. // passing in a silly number can cause maths problems in rendering!
  65237. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65238. Path p;
  65239. p.addEllipse (x, y, width, height);
  65240. strokePath (p, PathStrokeType (lineThickness));
  65241. }
  65242. void Graphics::fillRoundedRectangle (const float x,
  65243. const float y,
  65244. const float width,
  65245. const float height,
  65246. const float cornerSize) const throw()
  65247. {
  65248. // passing in a silly number can cause maths problems in rendering!
  65249. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65250. Path p;
  65251. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65252. fillPath (p);
  65253. }
  65254. void Graphics::fillRoundedRectangle (const Rectangle<int>& r,
  65255. const float cornerSize) const throw()
  65256. {
  65257. fillRoundedRectangle ((float) r.getX(),
  65258. (float) r.getY(),
  65259. (float) r.getWidth(),
  65260. (float) r.getHeight(),
  65261. cornerSize);
  65262. }
  65263. void Graphics::drawRoundedRectangle (const float x,
  65264. const float y,
  65265. const float width,
  65266. const float height,
  65267. const float cornerSize,
  65268. const float lineThickness) const throw()
  65269. {
  65270. // passing in a silly number can cause maths problems in rendering!
  65271. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65272. Path p;
  65273. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65274. strokePath (p, PathStrokeType (lineThickness));
  65275. }
  65276. void Graphics::drawRoundedRectangle (const Rectangle<int>& r,
  65277. const float cornerSize,
  65278. const float lineThickness) const throw()
  65279. {
  65280. drawRoundedRectangle ((float) r.getX(),
  65281. (float) r.getY(),
  65282. (float) r.getWidth(),
  65283. (float) r.getHeight(),
  65284. cornerSize, lineThickness);
  65285. }
  65286. void Graphics::drawArrow (const float startX,
  65287. const float startY,
  65288. const float endX,
  65289. const float endY,
  65290. const float lineThickness,
  65291. const float arrowheadWidth,
  65292. const float arrowheadLength) const throw()
  65293. {
  65294. Path p;
  65295. p.addArrow (startX, startY, endX, endY,
  65296. lineThickness, arrowheadWidth, arrowheadLength);
  65297. fillPath (p);
  65298. }
  65299. void Graphics::fillCheckerBoard (int x, int y,
  65300. int width, int height,
  65301. const int checkWidth,
  65302. const int checkHeight,
  65303. const Colour& colour1,
  65304. const Colour& colour2) const throw()
  65305. {
  65306. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  65307. if (checkWidth > 0 && checkHeight > 0)
  65308. {
  65309. context->saveState();
  65310. if (colour1 == colour2)
  65311. {
  65312. context->setFill (FillType (colour1));
  65313. context->fillRect (Rectangle<int> (x, y, width, height), false);
  65314. }
  65315. else
  65316. {
  65317. const Rectangle<int> clip (context->getClipBounds());
  65318. const int right = jmin (x + width, clip.getRight());
  65319. const int bottom = jmin (y + height, clip.getBottom());
  65320. int cy = 0;
  65321. while (y < bottom)
  65322. {
  65323. int cx = cy;
  65324. for (int xx = x; xx < right; xx += checkWidth)
  65325. {
  65326. context->setFill (FillType (((cx++ & 1) == 0) ? colour1 : colour2));
  65327. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  65328. false);
  65329. }
  65330. ++cy;
  65331. y += checkHeight;
  65332. }
  65333. }
  65334. context->restoreState();
  65335. }
  65336. }
  65337. void Graphics::drawVerticalLine (const int x, float top, float bottom) const throw()
  65338. {
  65339. context->drawVerticalLine (x, top, bottom);
  65340. }
  65341. void Graphics::drawHorizontalLine (const int y, float left, float right) const throw()
  65342. {
  65343. context->drawHorizontalLine (y, left, right);
  65344. }
  65345. void Graphics::drawLine (float x1, float y1, float x2, float y2) const throw()
  65346. {
  65347. context->drawLine (x1, y1, x2, y2);
  65348. }
  65349. void Graphics::drawLine (const float startX,
  65350. const float startY,
  65351. const float endX,
  65352. const float endY,
  65353. const float lineThickness) const throw()
  65354. {
  65355. Path p;
  65356. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  65357. fillPath (p);
  65358. }
  65359. void Graphics::drawLine (const Line& line) const throw()
  65360. {
  65361. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  65362. }
  65363. void Graphics::drawLine (const Line& line,
  65364. const float lineThickness) const throw()
  65365. {
  65366. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  65367. }
  65368. void Graphics::drawDashedLine (const float startX,
  65369. const float startY,
  65370. const float endX,
  65371. const float endY,
  65372. const float* const dashLengths,
  65373. const int numDashLengths,
  65374. const float lineThickness) const throw()
  65375. {
  65376. const double dx = endX - startX;
  65377. const double dy = endY - startY;
  65378. const double totalLen = juce_hypot (dx, dy);
  65379. if (totalLen >= 0.5)
  65380. {
  65381. const double onePixAlpha = 1.0 / totalLen;
  65382. double alpha = 0.0;
  65383. float x = startX;
  65384. float y = startY;
  65385. int n = 0;
  65386. while (alpha < 1.0f)
  65387. {
  65388. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  65389. n = n % numDashLengths;
  65390. const float oldX = x;
  65391. const float oldY = y;
  65392. x = (float) (startX + dx * alpha);
  65393. y = (float) (startY + dy * alpha);
  65394. if ((n & 1) != 0)
  65395. {
  65396. if (lineThickness != 1.0f)
  65397. drawLine (oldX, oldY, x, y, lineThickness);
  65398. else
  65399. drawLine (oldX, oldY, x, y);
  65400. }
  65401. }
  65402. }
  65403. }
  65404. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality) throw()
  65405. {
  65406. saveStateIfPending();
  65407. context->setInterpolationQuality (newQuality);
  65408. }
  65409. void Graphics::drawImageAt (const Image* const imageToDraw,
  65410. const int topLeftX,
  65411. const int topLeftY,
  65412. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65413. {
  65414. if (imageToDraw != 0)
  65415. {
  65416. const int imageW = imageToDraw->getWidth();
  65417. const int imageH = imageToDraw->getHeight();
  65418. drawImage (imageToDraw,
  65419. topLeftX, topLeftY, imageW, imageH,
  65420. 0, 0, imageW, imageH,
  65421. fillAlphaChannelWithCurrentBrush);
  65422. }
  65423. }
  65424. void Graphics::drawImageWithin (const Image* const imageToDraw,
  65425. const int destX,
  65426. const int destY,
  65427. const int destW,
  65428. const int destH,
  65429. const RectanglePlacement& placementWithinTarget,
  65430. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65431. {
  65432. // passing in a silly number can cause maths problems in rendering!
  65433. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  65434. if (imageToDraw != 0)
  65435. {
  65436. const int imageW = imageToDraw->getWidth();
  65437. const int imageH = imageToDraw->getHeight();
  65438. if (imageW > 0 && imageH > 0)
  65439. {
  65440. double newX = 0.0, newY = 0.0;
  65441. double newW = imageW;
  65442. double newH = imageH;
  65443. placementWithinTarget.applyTo (newX, newY, newW, newH,
  65444. destX, destY, destW, destH);
  65445. if (newW > 0 && newH > 0)
  65446. {
  65447. drawImage (imageToDraw,
  65448. roundToInt (newX), roundToInt (newY),
  65449. roundToInt (newW), roundToInt (newH),
  65450. 0, 0, imageW, imageH,
  65451. fillAlphaChannelWithCurrentBrush);
  65452. }
  65453. }
  65454. }
  65455. }
  65456. void Graphics::drawImage (const Image* const imageToDraw,
  65457. int dx, int dy, int dw, int dh,
  65458. int sx, int sy, int sw, int sh,
  65459. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65460. {
  65461. // passing in a silly number can cause maths problems in rendering!
  65462. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  65463. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  65464. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  65465. {
  65466. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  65467. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  65468. .translated ((float) dx, (float) dy),
  65469. fillAlphaChannelWithCurrentBrush);
  65470. }
  65471. }
  65472. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  65473. const Rectangle<int>& imageSubRegion,
  65474. const AffineTransform& transform,
  65475. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65476. {
  65477. if (imageToDraw != 0 && ! context->isClipEmpty())
  65478. {
  65479. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  65480. if (fillAlphaChannelWithCurrentBrush)
  65481. {
  65482. context->saveState();
  65483. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  65484. fillAll();
  65485. context->restoreState();
  65486. }
  65487. else
  65488. {
  65489. context->drawImage (*imageToDraw, srcClip, transform, false);
  65490. }
  65491. }
  65492. }
  65493. END_JUCE_NAMESPACE
  65494. /*** End of inlined file: juce_Graphics.cpp ***/
  65495. /*** Start of inlined file: juce_Justification.cpp ***/
  65496. BEGIN_JUCE_NAMESPACE
  65497. Justification::Justification (const Justification& other) throw()
  65498. : flags (other.flags)
  65499. {
  65500. }
  65501. const Justification& Justification::operator= (const Justification& other) throw()
  65502. {
  65503. flags = other.flags;
  65504. return *this;
  65505. }
  65506. int Justification::getOnlyVerticalFlags() const throw()
  65507. {
  65508. return flags & (top | bottom | verticallyCentred);
  65509. }
  65510. int Justification::getOnlyHorizontalFlags() const throw()
  65511. {
  65512. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  65513. }
  65514. void Justification::applyToRectangle (int& x, int& y,
  65515. const int w, const int h,
  65516. const int spaceX, const int spaceY,
  65517. const int spaceW, const int spaceH) const throw()
  65518. {
  65519. if ((flags & horizontallyCentred) != 0)
  65520. {
  65521. x = spaceX + ((spaceW - w) >> 1);
  65522. }
  65523. else if ((flags & right) != 0)
  65524. {
  65525. x = spaceX + spaceW - w;
  65526. }
  65527. else
  65528. {
  65529. x = spaceX;
  65530. }
  65531. if ((flags & verticallyCentred) != 0)
  65532. {
  65533. y = spaceY + ((spaceH - h) >> 1);
  65534. }
  65535. else if ((flags & bottom) != 0)
  65536. {
  65537. y = spaceY + spaceH - h;
  65538. }
  65539. else
  65540. {
  65541. y = spaceY;
  65542. }
  65543. }
  65544. END_JUCE_NAMESPACE
  65545. /*** End of inlined file: juce_Justification.cpp ***/
  65546. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65547. BEGIN_JUCE_NAMESPACE
  65548. // this will throw an assertion if you try to draw something that's not
  65549. // possible in postscript
  65550. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65551. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65552. #define notPossibleInPostscriptAssert jassertfalse
  65553. #else
  65554. #define notPossibleInPostscriptAssert
  65555. #endif
  65556. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65557. const String& documentTitle,
  65558. const int totalWidth_,
  65559. const int totalHeight_)
  65560. : out (resultingPostScript),
  65561. totalWidth (totalWidth_),
  65562. totalHeight (totalHeight_),
  65563. needToClip (true)
  65564. {
  65565. stateStack.add (new SavedState());
  65566. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  65567. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65568. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65569. "\n%%BoundingBox: 0 0 600 824"
  65570. "\n%%Pages: 0"
  65571. "\n%%Creator: Raw Material Software JUCE"
  65572. "\n%%Title: " << documentTitle <<
  65573. "\n%%CreationDate: none"
  65574. "\n%%LanguageLevel: 2"
  65575. "\n%%EndComments"
  65576. "\n%%BeginProlog"
  65577. "\n%%BeginResource: JRes"
  65578. "\n/bd {bind def} bind def"
  65579. "\n/c {setrgbcolor} bd"
  65580. "\n/m {moveto} bd"
  65581. "\n/l {lineto} bd"
  65582. "\n/rl {rlineto} bd"
  65583. "\n/ct {curveto} bd"
  65584. "\n/cp {closepath} bd"
  65585. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65586. "\n/doclip {initclip newpath} bd"
  65587. "\n/endclip {clip newpath} bd"
  65588. "\n%%EndResource"
  65589. "\n%%EndProlog"
  65590. "\n%%BeginSetup"
  65591. "\n%%EndSetup"
  65592. "\n%%Page: 1 1"
  65593. "\n%%BeginPageSetup"
  65594. "\n%%EndPageSetup\n\n"
  65595. << "40 800 translate\n"
  65596. << scale << ' ' << scale << " scale\n\n";
  65597. }
  65598. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65599. {
  65600. }
  65601. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65602. {
  65603. return true;
  65604. }
  65605. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65606. {
  65607. if (x != 0 || y != 0)
  65608. {
  65609. stateStack.getLast()->xOffset += x;
  65610. stateStack.getLast()->yOffset += y;
  65611. needToClip = true;
  65612. }
  65613. }
  65614. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  65615. {
  65616. needToClip = true;
  65617. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65618. }
  65619. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65620. {
  65621. needToClip = true;
  65622. return stateStack.getLast()->clip.clipTo (clipRegion);
  65623. }
  65624. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  65625. {
  65626. needToClip = true;
  65627. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65628. }
  65629. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65630. {
  65631. writeClip();
  65632. Path p (path);
  65633. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65634. writePath (p);
  65635. out << "clip\n";
  65636. }
  65637. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65638. {
  65639. needToClip = true;
  65640. jassertfalse // xxx
  65641. }
  65642. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65643. {
  65644. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65645. }
  65646. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65647. {
  65648. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65649. -stateStack.getLast()->yOffset);
  65650. }
  65651. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65652. {
  65653. return stateStack.getLast()->clip.isEmpty();
  65654. }
  65655. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65656. : xOffset (0),
  65657. yOffset (0)
  65658. {
  65659. }
  65660. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65661. {
  65662. }
  65663. void LowLevelGraphicsPostScriptRenderer::saveState()
  65664. {
  65665. stateStack.add (new SavedState (*stateStack.getLast()));
  65666. }
  65667. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65668. {
  65669. jassert (stateStack.size() > 0);
  65670. if (stateStack.size() > 0)
  65671. stateStack.removeLast();
  65672. }
  65673. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65674. {
  65675. if (needToClip)
  65676. {
  65677. needToClip = false;
  65678. out << "doclip ";
  65679. int itemsOnLine = 0;
  65680. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65681. {
  65682. if (++itemsOnLine == 6)
  65683. {
  65684. itemsOnLine = 0;
  65685. out << '\n';
  65686. }
  65687. const Rectangle<int>& r = *i.getRectangle();
  65688. out << r.getX() << ' ' << -r.getY() << ' '
  65689. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65690. }
  65691. out << "endclip\n";
  65692. }
  65693. }
  65694. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65695. {
  65696. Colour c (Colours::white.overlaidWith (colour));
  65697. if (lastColour != c)
  65698. {
  65699. lastColour = c;
  65700. out << String (c.getFloatRed(), 3) << ' '
  65701. << String (c.getFloatGreen(), 3) << ' '
  65702. << String (c.getFloatBlue(), 3) << " c\n";
  65703. }
  65704. }
  65705. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65706. {
  65707. out << String (x, 2) << ' '
  65708. << String (-y, 2) << ' ';
  65709. }
  65710. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65711. {
  65712. out << "newpath ";
  65713. float lastX = 0.0f;
  65714. float lastY = 0.0f;
  65715. int itemsOnLine = 0;
  65716. Path::Iterator i (path);
  65717. while (i.next())
  65718. {
  65719. if (++itemsOnLine == 4)
  65720. {
  65721. itemsOnLine = 0;
  65722. out << '\n';
  65723. }
  65724. switch (i.elementType)
  65725. {
  65726. case Path::Iterator::startNewSubPath:
  65727. writeXY (i.x1, i.y1);
  65728. lastX = i.x1;
  65729. lastY = i.y1;
  65730. out << "m ";
  65731. break;
  65732. case Path::Iterator::lineTo:
  65733. writeXY (i.x1, i.y1);
  65734. lastX = i.x1;
  65735. lastY = i.y1;
  65736. out << "l ";
  65737. break;
  65738. case Path::Iterator::quadraticTo:
  65739. {
  65740. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65741. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65742. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65743. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65744. writeXY (cp1x, cp1y);
  65745. writeXY (cp2x, cp2y);
  65746. writeXY (i.x2, i.y2);
  65747. out << "ct ";
  65748. lastX = i.x2;
  65749. lastY = i.y2;
  65750. }
  65751. break;
  65752. case Path::Iterator::cubicTo:
  65753. writeXY (i.x1, i.y1);
  65754. writeXY (i.x2, i.y2);
  65755. writeXY (i.x3, i.y3);
  65756. out << "ct ";
  65757. lastX = i.x3;
  65758. lastY = i.y3;
  65759. break;
  65760. case Path::Iterator::closePath:
  65761. out << "cp ";
  65762. break;
  65763. default:
  65764. jassertfalse
  65765. break;
  65766. }
  65767. }
  65768. out << '\n';
  65769. }
  65770. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65771. {
  65772. out << "[ "
  65773. << trans.mat00 << ' '
  65774. << trans.mat10 << ' '
  65775. << trans.mat01 << ' '
  65776. << trans.mat11 << ' '
  65777. << trans.mat02 << ' '
  65778. << trans.mat12 << " ] concat ";
  65779. }
  65780. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65781. {
  65782. stateStack.getLast()->fillType = fillType;
  65783. }
  65784. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65785. {
  65786. }
  65787. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65788. {
  65789. }
  65790. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65791. {
  65792. if (stateStack.getLast()->fillType.isColour())
  65793. {
  65794. writeClip();
  65795. writeColour (stateStack.getLast()->fillType.colour);
  65796. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65797. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65798. }
  65799. else
  65800. {
  65801. Path p;
  65802. p.addRectangle (r);
  65803. fillPath (p, AffineTransform::identity);
  65804. }
  65805. }
  65806. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65807. {
  65808. if (stateStack.getLast()->fillType.isColour())
  65809. {
  65810. writeClip();
  65811. Path p (path);
  65812. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65813. (float) stateStack.getLast()->yOffset));
  65814. writePath (p);
  65815. writeColour (stateStack.getLast()->fillType.colour);
  65816. out << "fill\n";
  65817. }
  65818. else if (stateStack.getLast()->fillType.isGradient())
  65819. {
  65820. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65821. // postscript can't do semi-transparent ones.
  65822. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65823. writeClip();
  65824. out << "gsave ";
  65825. {
  65826. Path p (path);
  65827. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65828. writePath (p);
  65829. out << "clip\n";
  65830. }
  65831. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65832. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65833. // time-being, this just fills it with the average colour..
  65834. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65835. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65836. out << "grestore\n";
  65837. }
  65838. }
  65839. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65840. const int sx, const int sy,
  65841. const int maxW, const int maxH) const
  65842. {
  65843. out << "{<\n";
  65844. const int w = jmin (maxW, im.getWidth());
  65845. const int h = jmin (maxH, im.getHeight());
  65846. int charsOnLine = 0;
  65847. const Image::BitmapData srcData (im, 0, 0, w, h);
  65848. Colour pixel;
  65849. for (int y = h; --y >= 0;)
  65850. {
  65851. for (int x = 0; x < w; ++x)
  65852. {
  65853. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65854. if (x >= sx && y >= sy)
  65855. {
  65856. if (im.isARGB())
  65857. {
  65858. PixelARGB p (*(const PixelARGB*) pixelData);
  65859. p.unpremultiply();
  65860. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65861. }
  65862. else if (im.isRGB())
  65863. {
  65864. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65865. }
  65866. else
  65867. {
  65868. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65869. }
  65870. }
  65871. else
  65872. {
  65873. pixel = Colours::transparentWhite;
  65874. }
  65875. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65876. out << String::toHexString (pixelValues, 3, 0);
  65877. charsOnLine += 3;
  65878. if (charsOnLine > 100)
  65879. {
  65880. out << '\n';
  65881. charsOnLine = 0;
  65882. }
  65883. }
  65884. }
  65885. out << "\n>}\n";
  65886. }
  65887. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65888. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65889. {
  65890. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65891. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65892. writeClip();
  65893. out << "gsave ";
  65894. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65895. .scaled (1.0f, -1.0f));
  65896. RectangleList imageClip;
  65897. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65898. imageClip.clipTo (srcClip);
  65899. out << "newpath ";
  65900. int itemsOnLine = 0;
  65901. for (RectangleList::Iterator i (imageClip); i.next();)
  65902. {
  65903. if (++itemsOnLine == 6)
  65904. {
  65905. out << '\n';
  65906. itemsOnLine = 0;
  65907. }
  65908. const Rectangle<int>& r = *i.getRectangle();
  65909. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65910. }
  65911. out << " clip newpath\n";
  65912. out << w << ' ' << h << " scale\n";
  65913. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65914. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65915. out << "false 3 colorimage grestore\n";
  65916. needToClip = true;
  65917. }
  65918. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65919. {
  65920. Path p;
  65921. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65922. fillPath (p, AffineTransform::identity);
  65923. }
  65924. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65925. {
  65926. drawLine (x, top, x, bottom);
  65927. }
  65928. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65929. {
  65930. drawLine (left, y, right, y);
  65931. }
  65932. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65933. {
  65934. stateStack.getLast()->font = newFont;
  65935. }
  65936. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65937. {
  65938. return stateStack.getLast()->font;
  65939. }
  65940. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65941. {
  65942. Path p;
  65943. Font& font = stateStack.getLast()->font;
  65944. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65945. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65946. }
  65947. END_JUCE_NAMESPACE
  65948. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65949. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65950. BEGIN_JUCE_NAMESPACE
  65951. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65952. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65953. #endif
  65954. #if JUCE_MSVC && JUCE_DEBUG
  65955. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65956. #endif
  65957. #if JUCE_MSVC
  65958. #pragma warning (push)
  65959. #pragma warning (disable: 4127) // "expression is constant" warning
  65960. #endif
  65961. template <class PixelType, bool replaceExisting = false>
  65962. class SolidColourEdgeTableRenderer
  65963. {
  65964. public:
  65965. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65966. : data (data_),
  65967. sourceColour (colour)
  65968. {
  65969. if (sizeof (PixelType) == 3)
  65970. {
  65971. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65972. && sourceColour.getGreen() == sourceColour.getBlue();
  65973. filler[0].set (sourceColour);
  65974. filler[1].set (sourceColour);
  65975. filler[2].set (sourceColour);
  65976. filler[3].set (sourceColour);
  65977. }
  65978. }
  65979. forcedinline void setEdgeTableYPos (const int y) throw()
  65980. {
  65981. linePixels = (PixelType*) data.getLinePointer (y);
  65982. }
  65983. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65984. {
  65985. if (replaceExisting)
  65986. linePixels[x].set (sourceColour);
  65987. else
  65988. linePixels[x].blend (sourceColour, alphaLevel);
  65989. }
  65990. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65991. {
  65992. PixelARGB p (sourceColour);
  65993. p.multiplyAlpha (alphaLevel);
  65994. PixelType* dest = linePixels + x;
  65995. if (replaceExisting || p.getAlpha() >= 0xff)
  65996. replaceLine (dest, p, width);
  65997. else
  65998. blendLine (dest, p, width);
  65999. }
  66000. private:
  66001. const Image::BitmapData& data;
  66002. PixelType* linePixels;
  66003. PixelARGB sourceColour;
  66004. PixelRGB filler [4];
  66005. bool areRGBComponentsEqual;
  66006. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const
  66007. {
  66008. do
  66009. {
  66010. dest->blend (colour);
  66011. ++dest;
  66012. } while (--width > 0);
  66013. }
  66014. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  66015. {
  66016. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  66017. {
  66018. memset (dest, colour.getRed(), width * 3);
  66019. }
  66020. else
  66021. {
  66022. if (width >> 5)
  66023. {
  66024. const int* const intFiller = (const int*) filler;
  66025. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  66026. {
  66027. dest->set (colour);
  66028. ++dest;
  66029. --width;
  66030. }
  66031. while (width > 4)
  66032. {
  66033. ((int*) dest) [0] = intFiller[0];
  66034. ((int*) dest) [1] = intFiller[1];
  66035. ((int*) dest) [2] = intFiller[2];
  66036. dest = (PixelRGB*) (((uint8*) dest) + 12);
  66037. width -= 4;
  66038. }
  66039. }
  66040. while (--width >= 0)
  66041. {
  66042. dest->set (colour);
  66043. ++dest;
  66044. }
  66045. }
  66046. }
  66047. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  66048. {
  66049. memset (dest, colour.getAlpha(), width);
  66050. }
  66051. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  66052. {
  66053. do
  66054. {
  66055. dest->set (colour);
  66056. ++dest;
  66057. } while (--width > 0);
  66058. }
  66059. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  66060. const SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  66061. };
  66062. class LinearGradientPixelGenerator
  66063. {
  66064. public:
  66065. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  66066. : lookupTable (lookupTable_), numEntries (numEntries_)
  66067. {
  66068. jassert (numEntries_ >= 0);
  66069. float x1 = gradient.x1;
  66070. float y1 = gradient.y1;
  66071. float x2 = gradient.x2;
  66072. float y2 = gradient.y2;
  66073. if (! transform.isIdentity())
  66074. {
  66075. const Line l (x2, y2, x1, y1);
  66076. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  66077. float x3 = p3.getX();
  66078. float y3 = p3.getY();
  66079. transform.transformPoint (x1, y1);
  66080. transform.transformPoint (x2, y2);
  66081. transform.transformPoint (x3, y3);
  66082. const Line l2 (x2, y2, x3, y3);
  66083. const float prop = l2.findNearestPointTo (x1, y1);
  66084. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  66085. x2 = newP2.getX();
  66086. y2 = newP2.getY();
  66087. }
  66088. vertical = fabs (x1 - x2) < 0.001f;
  66089. horizontal = fabs (y1 - y2) < 0.001f;
  66090. if (vertical)
  66091. {
  66092. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  66093. start = roundToInt (y1 * scale);
  66094. }
  66095. else if (horizontal)
  66096. {
  66097. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  66098. start = roundToInt (x1 * scale);
  66099. }
  66100. else
  66101. {
  66102. grad = (y2 - y1) / (double) (x1 - x2);
  66103. yTerm = y1 - x1 / grad;
  66104. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  66105. grad *= scale;
  66106. }
  66107. }
  66108. forcedinline void setY (const int y) throw()
  66109. {
  66110. if (vertical)
  66111. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  66112. else if (! horizontal)
  66113. start = roundToInt ((y - yTerm) * grad);
  66114. }
  66115. forcedinline const PixelARGB getPixel (const int x) const throw()
  66116. {
  66117. return vertical ? linePix
  66118. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  66119. }
  66120. private:
  66121. const PixelARGB* const lookupTable;
  66122. const int numEntries;
  66123. PixelARGB linePix;
  66124. int start, scale;
  66125. double grad, yTerm;
  66126. bool vertical, horizontal;
  66127. enum { numScaleBits = 12 };
  66128. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  66129. const LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  66130. };
  66131. class RadialGradientPixelGenerator
  66132. {
  66133. public:
  66134. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  66135. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66136. : lookupTable (lookupTable_),
  66137. numEntries (numEntries_),
  66138. gx1 (gradient.x1),
  66139. gy1 (gradient.y1)
  66140. {
  66141. jassert (numEntries_ >= 0);
  66142. const float gdx = gradient.x1 - gradient.x2;
  66143. const float gdy = gradient.y1 - gradient.y2;
  66144. maxDist = gdx * gdx + gdy * gdy;
  66145. invScale = numEntries / sqrt (maxDist);
  66146. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  66147. }
  66148. forcedinline void setY (const int y) throw()
  66149. {
  66150. dy = y - gy1;
  66151. dy *= dy;
  66152. }
  66153. forcedinline const PixelARGB getPixel (const int px) const throw()
  66154. {
  66155. double x = px - gx1;
  66156. x *= x;
  66157. x += dy;
  66158. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  66159. }
  66160. protected:
  66161. const PixelARGB* const lookupTable;
  66162. const int numEntries;
  66163. const double gx1, gy1;
  66164. double maxDist, invScale, dy;
  66165. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  66166. const RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  66167. };
  66168. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  66169. {
  66170. public:
  66171. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  66172. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66173. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  66174. inverseTransform (transform.inverted())
  66175. {
  66176. tM10 = inverseTransform.mat10;
  66177. tM00 = inverseTransform.mat00;
  66178. }
  66179. forcedinline void setY (const int y) throw()
  66180. {
  66181. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  66182. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  66183. }
  66184. forcedinline const PixelARGB getPixel (const int px) const throw()
  66185. {
  66186. double x = px;
  66187. const double y = tM10 * x + lineYM11;
  66188. x = tM00 * x + lineYM01;
  66189. x *= x;
  66190. x += y * y;
  66191. if (x >= maxDist)
  66192. return lookupTable [numEntries];
  66193. else
  66194. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  66195. }
  66196. private:
  66197. double tM10, tM00, lineYM01, lineYM11;
  66198. const AffineTransform inverseTransform;
  66199. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  66200. const TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  66201. };
  66202. template <class PixelType, class GradientType>
  66203. class GradientEdgeTableRenderer : public GradientType
  66204. {
  66205. public:
  66206. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  66207. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66208. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  66209. destData (destData_)
  66210. {
  66211. }
  66212. forcedinline void setEdgeTableYPos (const int y) throw()
  66213. {
  66214. linePixels = (PixelType*) destData.getLinePointer (y);
  66215. GradientType::setY (y);
  66216. }
  66217. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  66218. {
  66219. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  66220. }
  66221. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  66222. {
  66223. PixelType* dest = linePixels + x;
  66224. if (alphaLevel < 0xff)
  66225. {
  66226. do
  66227. {
  66228. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  66229. } while (--width > 0);
  66230. }
  66231. else
  66232. {
  66233. do
  66234. {
  66235. (dest++)->blend (GradientType::getPixel (x++));
  66236. } while (--width > 0);
  66237. }
  66238. }
  66239. private:
  66240. const Image::BitmapData& destData;
  66241. PixelType* linePixels;
  66242. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  66243. const GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  66244. };
  66245. static forcedinline int safeModulo (int n, const int divisor) throw()
  66246. {
  66247. jassert (divisor > 0);
  66248. n %= divisor;
  66249. return (n < 0) ? (n + divisor) : n;
  66250. }
  66251. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66252. class ImageFillEdgeTableRenderer
  66253. {
  66254. public:
  66255. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66256. const Image::BitmapData& srcData_,
  66257. const int extraAlpha_,
  66258. const int x, const int y) throw()
  66259. : destData (destData_),
  66260. srcData (srcData_),
  66261. extraAlpha (extraAlpha_ + 1),
  66262. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  66263. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  66264. {
  66265. }
  66266. forcedinline void setEdgeTableYPos (int y) throw()
  66267. {
  66268. linePixels = (DestPixelType*) destData.getLinePointer (y);
  66269. y -= yOffset;
  66270. if (repeatPattern)
  66271. {
  66272. jassert (y >= 0);
  66273. y %= srcData.height;
  66274. }
  66275. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  66276. }
  66277. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  66278. {
  66279. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66280. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  66281. }
  66282. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  66283. {
  66284. DestPixelType* dest = linePixels + x;
  66285. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66286. x -= xOffset;
  66287. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  66288. if (alphaLevel < 0xfe)
  66289. {
  66290. do
  66291. {
  66292. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  66293. } while (--width > 0);
  66294. }
  66295. else
  66296. {
  66297. if (repeatPattern)
  66298. {
  66299. do
  66300. {
  66301. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  66302. } while (--width > 0);
  66303. }
  66304. else
  66305. {
  66306. copyRow (dest, sourceLineStart + x, width);
  66307. }
  66308. }
  66309. }
  66310. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  66311. {
  66312. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  66313. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  66314. uint8* mask = (uint8*) (s + x - xOffset);
  66315. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66316. mask += PixelARGB::indexA;
  66317. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  66318. }
  66319. private:
  66320. const Image::BitmapData& destData;
  66321. const Image::BitmapData& srcData;
  66322. const int extraAlpha, xOffset, yOffset;
  66323. DestPixelType* linePixels;
  66324. SrcPixelType* sourceLineStart;
  66325. template <class PixelType1, class PixelType2>
  66326. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  66327. {
  66328. do
  66329. {
  66330. dest++ ->blend (*src++);
  66331. } while (--width > 0);
  66332. }
  66333. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  66334. {
  66335. memcpy (dest, src, width * sizeof (PixelRGB));
  66336. }
  66337. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  66338. const ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  66339. };
  66340. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66341. class TransformedImageFillEdgeTableRenderer
  66342. {
  66343. public:
  66344. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66345. const Image::BitmapData& srcData_,
  66346. const AffineTransform& transform,
  66347. const int extraAlpha_,
  66348. const bool betterQuality_) throw()
  66349. : interpolator (transform),
  66350. destData (destData_),
  66351. srcData (srcData_),
  66352. extraAlpha (extraAlpha_ + 1),
  66353. betterQuality (betterQuality_),
  66354. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  66355. pixelOffsetInt (betterQuality_ ? -128 : 0),
  66356. maxX (srcData_.width - 1),
  66357. maxY (srcData_.height - 1),
  66358. scratchSize (2048)
  66359. {
  66360. scratchBuffer.malloc (scratchSize);
  66361. }
  66362. ~TransformedImageFillEdgeTableRenderer() throw()
  66363. {
  66364. }
  66365. forcedinline void setEdgeTableYPos (const int newY) throw()
  66366. {
  66367. y = newY;
  66368. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  66369. }
  66370. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  66371. {
  66372. alphaLevel *= extraAlpha;
  66373. alphaLevel >>= 8;
  66374. SrcPixelType p;
  66375. generate (&p, x, 1);
  66376. linePixels[x].blend (p, alphaLevel);
  66377. }
  66378. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  66379. {
  66380. if (width > scratchSize)
  66381. {
  66382. scratchSize = width;
  66383. scratchBuffer.malloc (scratchSize);
  66384. }
  66385. SrcPixelType* span = scratchBuffer;
  66386. generate (span, x, width);
  66387. DestPixelType* dest = linePixels + x;
  66388. alphaLevel *= extraAlpha;
  66389. alphaLevel >>= 8;
  66390. if (alphaLevel < 0xfe)
  66391. {
  66392. do
  66393. {
  66394. dest++ ->blend (*span++, alphaLevel);
  66395. } while (--width > 0);
  66396. }
  66397. else
  66398. {
  66399. do
  66400. {
  66401. dest++ ->blend (*span++);
  66402. } while (--width > 0);
  66403. }
  66404. }
  66405. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  66406. {
  66407. if (width > scratchSize)
  66408. {
  66409. scratchSize = width;
  66410. scratchBuffer.malloc (scratchSize);
  66411. }
  66412. uint8* mask = (uint8*) scratchBuffer;
  66413. y = y_;
  66414. generate ((SrcPixelType*) mask, x, width);
  66415. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66416. mask += PixelARGB::indexA;
  66417. et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width);
  66418. }
  66419. private:
  66420. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  66421. {
  66422. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66423. do
  66424. {
  66425. int hiResX, hiResY;
  66426. this->interpolator.next (hiResX, hiResY);
  66427. hiResX += pixelOffsetInt;
  66428. hiResY += pixelOffsetInt;
  66429. int loResX = hiResX >> 8;
  66430. int loResY = hiResY >> 8;
  66431. if (repeatPattern)
  66432. {
  66433. loResX = safeModulo (loResX, srcData.width);
  66434. loResY = safeModulo (loResY, srcData.height);
  66435. }
  66436. if (betterQuality
  66437. && ((unsigned int) loResX) < (unsigned int) maxX
  66438. && ((unsigned int) loResY) < (unsigned int) maxY)
  66439. {
  66440. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  66441. hiResX &= 255;
  66442. hiResY &= 255;
  66443. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66444. uint32 weight = (256 - hiResX) * (256 - hiResY);
  66445. c[0] += weight * src[0];
  66446. c[1] += weight * src[1];
  66447. c[2] += weight * src[2];
  66448. c[3] += weight * src[3];
  66449. weight = hiResX * (256 - hiResY);
  66450. c[0] += weight * src[4];
  66451. c[1] += weight * src[5];
  66452. c[2] += weight * src[6];
  66453. c[3] += weight * src[7];
  66454. src += this->srcData.lineStride;
  66455. weight = (256 - hiResX) * hiResY;
  66456. c[0] += weight * src[0];
  66457. c[1] += weight * src[1];
  66458. c[2] += weight * src[2];
  66459. c[3] += weight * src[3];
  66460. weight = hiResX * hiResY;
  66461. c[0] += weight * src[4];
  66462. c[1] += weight * src[5];
  66463. c[2] += weight * src[6];
  66464. c[3] += weight * src[7];
  66465. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  66466. (uint8) (c[PixelARGB::indexR] >> 16),
  66467. (uint8) (c[PixelARGB::indexG] >> 16),
  66468. (uint8) (c[PixelARGB::indexB] >> 16));
  66469. }
  66470. else
  66471. {
  66472. if (! repeatPattern)
  66473. {
  66474. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66475. if (loResX < 0) loResX = 0;
  66476. if (loResY < 0) loResY = 0;
  66477. if (loResX > maxX) loResX = maxX;
  66478. if (loResY > maxY) loResY = maxY;
  66479. }
  66480. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  66481. }
  66482. ++dest;
  66483. } while (--numPixels > 0);
  66484. }
  66485. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  66486. {
  66487. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66488. do
  66489. {
  66490. int hiResX, hiResY;
  66491. this->interpolator.next (hiResX, hiResY);
  66492. hiResX += pixelOffsetInt;
  66493. hiResY += pixelOffsetInt;
  66494. int loResX = hiResX >> 8;
  66495. int loResY = hiResY >> 8;
  66496. if (repeatPattern)
  66497. {
  66498. loResX = safeModulo (loResX, srcData.width);
  66499. loResY = safeModulo (loResY, srcData.height);
  66500. }
  66501. if (betterQuality
  66502. && ((unsigned int) loResX) < (unsigned int) maxX
  66503. && ((unsigned int) loResY) < (unsigned int) maxY)
  66504. {
  66505. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  66506. hiResX &= 255;
  66507. hiResY &= 255;
  66508. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66509. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  66510. c[0] += weight * src[0];
  66511. c[1] += weight * src[1];
  66512. c[2] += weight * src[2];
  66513. weight = hiResX * (256 - hiResY);
  66514. c[0] += weight * src[3];
  66515. c[1] += weight * src[4];
  66516. c[2] += weight * src[5];
  66517. src += this->srcData.lineStride;
  66518. weight = (256 - hiResX) * hiResY;
  66519. c[0] += weight * src[0];
  66520. c[1] += weight * src[1];
  66521. c[2] += weight * src[2];
  66522. weight = hiResX * hiResY;
  66523. c[0] += weight * src[3];
  66524. c[1] += weight * src[4];
  66525. c[2] += weight * src[5];
  66526. dest->setARGB ((uint8) 255,
  66527. (uint8) (c[PixelRGB::indexR] >> 16),
  66528. (uint8) (c[PixelRGB::indexG] >> 16),
  66529. (uint8) (c[PixelRGB::indexB] >> 16));
  66530. }
  66531. else
  66532. {
  66533. if (! repeatPattern)
  66534. {
  66535. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66536. if (loResX < 0) loResX = 0;
  66537. if (loResY < 0) loResY = 0;
  66538. if (loResX > maxX) loResX = maxX;
  66539. if (loResY > maxY) loResY = maxY;
  66540. }
  66541. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66542. }
  66543. ++dest;
  66544. } while (--numPixels > 0);
  66545. }
  66546. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66547. {
  66548. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66549. do
  66550. {
  66551. int hiResX, hiResY;
  66552. this->interpolator.next (hiResX, hiResY);
  66553. hiResX += pixelOffsetInt;
  66554. hiResY += pixelOffsetInt;
  66555. int loResX = hiResX >> 8;
  66556. int loResY = hiResY >> 8;
  66557. if (repeatPattern)
  66558. {
  66559. loResX = safeModulo (loResX, srcData.width);
  66560. loResY = safeModulo (loResY, srcData.height);
  66561. }
  66562. if (betterQuality
  66563. && ((unsigned int) loResX) < (unsigned int) maxX
  66564. && ((unsigned int) loResY) < (unsigned int) maxY)
  66565. {
  66566. hiResX &= 255;
  66567. hiResY &= 255;
  66568. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66569. uint32 c = 256 * 128;
  66570. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66571. c += src[1] * (hiResX * (256 - hiResY));
  66572. src += this->srcData.lineStride;
  66573. c += src[0] * ((256 - hiResX) * hiResY);
  66574. c += src[1] * (hiResX * hiResY);
  66575. *((uint8*) dest) = (uint8) c;
  66576. }
  66577. else
  66578. {
  66579. if (! repeatPattern)
  66580. {
  66581. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66582. if (loResX < 0) loResX = 0;
  66583. if (loResY < 0) loResY = 0;
  66584. if (loResX > maxX) loResX = maxX;
  66585. if (loResY > maxY) loResY = maxY;
  66586. }
  66587. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66588. }
  66589. ++dest;
  66590. } while (--numPixels > 0);
  66591. }
  66592. class TransformedImageSpanInterpolator
  66593. {
  66594. public:
  66595. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66596. : inverseTransform (transform.inverted())
  66597. {}
  66598. void setStartOfLine (float x, float y, const int numPixels) throw()
  66599. {
  66600. float x1 = x, y1 = y;
  66601. inverseTransform.transformPoint (x1, y1);
  66602. x += numPixels;
  66603. inverseTransform.transformPoint (x, y);
  66604. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66605. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66606. }
  66607. void next (int& x, int& y) throw()
  66608. {
  66609. x = xBresenham.n;
  66610. xBresenham.stepToNext();
  66611. y = yBresenham.n;
  66612. yBresenham.stepToNext();
  66613. }
  66614. private:
  66615. class BresenhamInterpolator
  66616. {
  66617. public:
  66618. BresenhamInterpolator() throw() {}
  66619. void set (const int n1, const int n2, const int numSteps_) throw()
  66620. {
  66621. numSteps = jmax (1, numSteps_);
  66622. step = (n2 - n1) / numSteps;
  66623. remainder = modulo = (n2 - n1) % numSteps;
  66624. n = n1;
  66625. if (modulo <= 0)
  66626. {
  66627. modulo += numSteps;
  66628. remainder += numSteps;
  66629. --step;
  66630. }
  66631. modulo -= numSteps;
  66632. }
  66633. forcedinline void stepToNext() throw()
  66634. {
  66635. modulo += remainder;
  66636. n += step;
  66637. if (modulo > 0)
  66638. {
  66639. modulo -= numSteps;
  66640. ++n;
  66641. }
  66642. }
  66643. int n;
  66644. private:
  66645. int numSteps, step, modulo, remainder;
  66646. };
  66647. const AffineTransform inverseTransform;
  66648. BresenhamInterpolator xBresenham, yBresenham;
  66649. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66650. const TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66651. };
  66652. TransformedImageSpanInterpolator interpolator;
  66653. const Image::BitmapData& destData;
  66654. const Image::BitmapData& srcData;
  66655. const int extraAlpha;
  66656. const bool betterQuality;
  66657. const float pixelOffset;
  66658. const int pixelOffsetInt, maxX, maxY;
  66659. int y;
  66660. DestPixelType* linePixels;
  66661. HeapBlock <SrcPixelType> scratchBuffer;
  66662. int scratchSize;
  66663. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66664. const TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66665. };
  66666. class LLGCSavedState
  66667. {
  66668. public:
  66669. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66670. const Font& font_, const FillType& fillType_,
  66671. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66672. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66673. xOffset (xOffset_), yOffset (yOffset_),
  66674. font (font_), fillType (fillType_),
  66675. interpolationQuality (interpolationQuality_)
  66676. {
  66677. }
  66678. LLGCSavedState (const LLGCSavedState& other) throw()
  66679. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66680. yOffset (other.yOffset), font (other.font),
  66681. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66682. {
  66683. }
  66684. ~LLGCSavedState() throw()
  66685. {
  66686. }
  66687. bool clipToRectangle (const Rectangle<int>& r) throw()
  66688. {
  66689. dupeEdgeTableIfMultiplyReferenced();
  66690. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66691. return ! edgeTable->edgeTable.isEmpty();
  66692. }
  66693. bool clipToRectangleList (const RectangleList& r) throw()
  66694. {
  66695. dupeEdgeTableIfMultiplyReferenced();
  66696. RectangleList offsetList (r);
  66697. offsetList.offsetAll (xOffset, yOffset);
  66698. EdgeTable e2 (offsetList);
  66699. edgeTable->edgeTable.clipToEdgeTable (e2);
  66700. return ! edgeTable->edgeTable.isEmpty();
  66701. }
  66702. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66703. {
  66704. dupeEdgeTableIfMultiplyReferenced();
  66705. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66706. return ! edgeTable->edgeTable.isEmpty();
  66707. }
  66708. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66709. {
  66710. dupeEdgeTableIfMultiplyReferenced();
  66711. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66712. edgeTable->edgeTable.clipToEdgeTable (et);
  66713. }
  66714. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66715. {
  66716. et.clipToEdgeTable (edgeTable->edgeTable);
  66717. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66718. if (fillType.isGradient())
  66719. {
  66720. jassert (! replaceContents); // that option is just for solid colours
  66721. ColourGradient g2 (*(fillType.gradient));
  66722. g2.multiplyOpacity (fillType.getOpacity());
  66723. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66724. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66725. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66726. const bool isIdentity = transform.isOnlyTranslation();
  66727. if (isIdentity)
  66728. {
  66729. // If our translation doesn't involve any distortion, we can speed it up..
  66730. transform.transformPoint (g2.x1, g2.y1);
  66731. transform.transformPoint (g2.x2, g2.y2);
  66732. transform = AffineTransform::identity;
  66733. }
  66734. HeapBlock <PixelARGB> lookupTable;
  66735. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66736. jassert (numLookupEntries > 0);
  66737. switch (image.getFormat())
  66738. {
  66739. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66740. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66741. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66742. }
  66743. }
  66744. else if (fillType.isTiledImage())
  66745. {
  66746. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66747. }
  66748. else
  66749. {
  66750. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66751. switch (image.getFormat())
  66752. {
  66753. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66754. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66755. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66756. }
  66757. }
  66758. }
  66759. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66760. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66761. {
  66762. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66763. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66764. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66765. const int alpha = fillType.colour.getAlpha();
  66766. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66767. if (transform.isOnlyTranslation())
  66768. {
  66769. // If our translation doesn't involve any distortion, just use a simple blit..
  66770. int tx = (int) (transform.getTranslationX() * 256.0f);
  66771. int ty = (int) (transform.getTranslationY() * 256.0f);
  66772. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66773. {
  66774. tx = ((tx + 128) >> 8);
  66775. ty = ((ty + 128) >> 8);
  66776. if (tiledFillClipRegion != 0)
  66777. {
  66778. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66779. }
  66780. else
  66781. {
  66782. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66783. et.clipToEdgeTable (edgeTable->edgeTable);
  66784. if (! et.isEmpty())
  66785. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66786. }
  66787. return;
  66788. }
  66789. }
  66790. if (transform.isSingularity())
  66791. return;
  66792. if (tiledFillClipRegion != 0)
  66793. {
  66794. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66795. }
  66796. else
  66797. {
  66798. Path p;
  66799. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66800. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66801. et.clipToEdgeTable (edgeTable->edgeTable);
  66802. if (! et.isEmpty())
  66803. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66804. }
  66805. }
  66806. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66807. {
  66808. if (! image.hasAlphaChannel())
  66809. {
  66810. Path p;
  66811. p.addRectangle (srcClip);
  66812. clipToPath (p, t);
  66813. return;
  66814. }
  66815. dupeEdgeTableIfMultiplyReferenced();
  66816. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66817. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66818. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66819. EdgeTable& et = edgeTable->edgeTable;
  66820. if (transform.isOnlyTranslation())
  66821. {
  66822. // If our translation doesn't involve any distortion, just use a simple blit..
  66823. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66824. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66825. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66826. {
  66827. const int imageX = ((tx + 128) >> 8);
  66828. const int imageY = ((ty + 128) >> 8);
  66829. if (image.getFormat() == Image::ARGB)
  66830. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66831. else
  66832. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66833. return;
  66834. }
  66835. }
  66836. if (transform.isSingularity())
  66837. {
  66838. et.clipToRectangle (Rectangle<int>());
  66839. return;
  66840. }
  66841. {
  66842. Path p;
  66843. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66844. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66845. et.clipToEdgeTable (et2);
  66846. }
  66847. if (! et.isEmpty())
  66848. {
  66849. if (image.getFormat() == Image::ARGB)
  66850. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66851. else
  66852. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66853. }
  66854. }
  66855. template <class SrcPixelType>
  66856. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66857. {
  66858. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66859. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66860. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66861. et.getMaximumBounds().getWidth());
  66862. }
  66863. template <class SrcPixelType>
  66864. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66865. {
  66866. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66867. et.clipToRectangle (r);
  66868. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66869. for (int y = 0; y < r.getHeight(); ++y)
  66870. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66871. }
  66872. class EdgeTableHolder : public ReferenceCountedObject
  66873. {
  66874. public:
  66875. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66876. EdgeTable edgeTable;
  66877. };
  66878. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66879. int xOffset, yOffset;
  66880. Font font;
  66881. FillType fillType;
  66882. Graphics::ResamplingQuality interpolationQuality;
  66883. private:
  66884. const LLGCSavedState& operator= (const LLGCSavedState&);
  66885. void dupeEdgeTableIfMultiplyReferenced() throw()
  66886. {
  66887. if (edgeTable->getReferenceCount() > 1)
  66888. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66889. }
  66890. template <class DestPixelType>
  66891. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66892. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66893. {
  66894. jassert (destData.pixelStride == sizeof (DestPixelType));
  66895. if (g.isRadial)
  66896. {
  66897. if (isIdentity)
  66898. {
  66899. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66900. et.iterate (renderer);
  66901. }
  66902. else
  66903. {
  66904. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66905. et.iterate (renderer);
  66906. }
  66907. }
  66908. else
  66909. {
  66910. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66911. et.iterate (renderer);
  66912. }
  66913. }
  66914. template <class DestPixelType>
  66915. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66916. {
  66917. jassert (destData.pixelStride == sizeof (DestPixelType));
  66918. if (replaceContents)
  66919. {
  66920. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66921. et.iterate (r);
  66922. }
  66923. else
  66924. {
  66925. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66926. et.iterate (r);
  66927. }
  66928. }
  66929. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66930. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66931. {
  66932. switch (destImage.getFormat())
  66933. {
  66934. case Image::ARGB:
  66935. switch (srcImage.getFormat())
  66936. {
  66937. case Image::ARGB:
  66938. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66939. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66940. break;
  66941. case Image::RGB:
  66942. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66943. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66944. break;
  66945. default:
  66946. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66947. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66948. break;
  66949. }
  66950. break;
  66951. case Image::RGB:
  66952. switch (srcImage.getFormat())
  66953. {
  66954. case Image::ARGB:
  66955. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66956. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66957. break;
  66958. case Image::RGB:
  66959. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66960. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66961. break;
  66962. default:
  66963. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66964. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66965. break;
  66966. }
  66967. break;
  66968. default:
  66969. switch (srcImage.getFormat())
  66970. {
  66971. case Image::ARGB:
  66972. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66973. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66974. break;
  66975. case Image::RGB:
  66976. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66977. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66978. break;
  66979. default:
  66980. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66981. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66982. break;
  66983. }
  66984. break;
  66985. }
  66986. }
  66987. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66988. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66989. {
  66990. switch (destImage.getFormat())
  66991. {
  66992. case Image::ARGB:
  66993. switch (srcImage.getFormat())
  66994. {
  66995. case Image::ARGB:
  66996. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66997. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66998. break;
  66999. case Image::RGB:
  67000. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67001. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67002. break;
  67003. default:
  67004. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67005. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67006. break;
  67007. }
  67008. break;
  67009. case Image::RGB:
  67010. switch (srcImage.getFormat())
  67011. {
  67012. case Image::ARGB:
  67013. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67014. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67015. break;
  67016. case Image::RGB:
  67017. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67018. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67019. break;
  67020. default:
  67021. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67022. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67023. break;
  67024. }
  67025. break;
  67026. default:
  67027. switch (srcImage.getFormat())
  67028. {
  67029. case Image::ARGB:
  67030. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67031. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67032. break;
  67033. case Image::RGB:
  67034. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67035. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67036. break;
  67037. default:
  67038. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67039. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67040. break;
  67041. }
  67042. break;
  67043. }
  67044. }
  67045. };
  67046. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  67047. : image (image_)
  67048. {
  67049. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  67050. FillType(), Graphics::mediumResamplingQuality);
  67051. }
  67052. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  67053. {
  67054. }
  67055. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  67056. {
  67057. return false;
  67058. }
  67059. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  67060. {
  67061. currentState->xOffset += x;
  67062. currentState->yOffset += y;
  67063. }
  67064. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  67065. {
  67066. return currentState->clipToRectangle (r);
  67067. }
  67068. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  67069. {
  67070. return currentState->clipToRectangleList (clipRegion);
  67071. }
  67072. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  67073. {
  67074. currentState->excludeClipRectangle (r);
  67075. }
  67076. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  67077. {
  67078. currentState->clipToPath (path, transform);
  67079. }
  67080. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  67081. {
  67082. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  67083. }
  67084. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  67085. {
  67086. return currentState->edgeTable->edgeTable.getMaximumBounds()
  67087. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  67088. }
  67089. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  67090. {
  67091. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  67092. }
  67093. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  67094. {
  67095. return currentState->edgeTable->edgeTable.isEmpty();
  67096. }
  67097. void LowLevelGraphicsSoftwareRenderer::saveState()
  67098. {
  67099. stateStack.add (new LLGCSavedState (*currentState));
  67100. }
  67101. void LowLevelGraphicsSoftwareRenderer::restoreState()
  67102. {
  67103. LLGCSavedState* const top = stateStack.getLast();
  67104. if (top != 0)
  67105. {
  67106. currentState = top;
  67107. stateStack.removeLast (1, false);
  67108. }
  67109. else
  67110. {
  67111. jassertfalse // trying to pop with an empty stack!
  67112. }
  67113. }
  67114. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  67115. {
  67116. currentState->fillType = fillType;
  67117. }
  67118. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  67119. {
  67120. currentState->fillType.setOpacity (newOpacity);
  67121. }
  67122. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  67123. {
  67124. currentState->interpolationQuality = quality;
  67125. }
  67126. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  67127. {
  67128. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  67129. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  67130. if (! clipped.isEmpty())
  67131. {
  67132. EdgeTable et (clipped);
  67133. currentState->fillEdgeTable (image, et, replaceExistingContents);
  67134. }
  67135. }
  67136. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  67137. {
  67138. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  67139. path, transform.translated ((float) currentState->xOffset,
  67140. (float) currentState->yOffset));
  67141. currentState->fillEdgeTable (image, et);
  67142. }
  67143. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  67144. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  67145. {
  67146. jassert (sourceImage.getBounds().contains (srcClip));
  67147. currentState->renderImage (image, sourceImage, srcClip, transform,
  67148. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  67149. }
  67150. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  67151. {
  67152. Path p;
  67153. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  67154. fillPath (p, AffineTransform::identity);
  67155. }
  67156. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  67157. {
  67158. if (bottom > top)
  67159. {
  67160. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  67161. currentState->fillEdgeTable (image, et);
  67162. }
  67163. }
  67164. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  67165. {
  67166. if (right > left)
  67167. {
  67168. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  67169. (float) (right - left), 1.0f);
  67170. currentState->fillEdgeTable (image, et);
  67171. }
  67172. }
  67173. class GlyphCache : private DeletedAtShutdown
  67174. {
  67175. public:
  67176. GlyphCache() throw()
  67177. : accessCounter (0), hits (0), misses (0)
  67178. {
  67179. for (int i = 120; --i >= 0;)
  67180. glyphs.add (new CachedGlyph());
  67181. }
  67182. ~GlyphCache() throw()
  67183. {
  67184. clearSingletonInstance();
  67185. }
  67186. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  67187. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  67188. {
  67189. ++accessCounter;
  67190. int oldestCounter = std::numeric_limits<int>::max();
  67191. CachedGlyph* oldest = 0;
  67192. for (int i = glyphs.size(); --i >= 0;)
  67193. {
  67194. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  67195. if (glyph->glyph == glyphNumber && glyph->font == font)
  67196. {
  67197. ++hits;
  67198. glyph->lastAccessCount = accessCounter;
  67199. glyph->draw (state, image, x, y);
  67200. return;
  67201. }
  67202. if (glyph->lastAccessCount <= oldestCounter)
  67203. {
  67204. oldestCounter = glyph->lastAccessCount;
  67205. oldest = glyph;
  67206. }
  67207. }
  67208. if (hits + ++misses > (glyphs.size() << 4))
  67209. {
  67210. if (misses * 2 > hits)
  67211. {
  67212. for (int i = 32; --i >= 0;)
  67213. glyphs.add (new CachedGlyph());
  67214. }
  67215. hits = misses = 0;
  67216. oldest = glyphs.getLast();
  67217. }
  67218. jassert (oldest != 0);
  67219. oldest->lastAccessCount = accessCounter;
  67220. oldest->generate (font, glyphNumber);
  67221. oldest->draw (state, image, x, y);
  67222. }
  67223. class CachedGlyph
  67224. {
  67225. public:
  67226. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  67227. ~CachedGlyph() {}
  67228. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  67229. {
  67230. if (edgeTable != 0)
  67231. {
  67232. EdgeTable et (*edgeTable);
  67233. et.translate (x, roundToInt (y));
  67234. state.fillEdgeTable (image, et, false);
  67235. }
  67236. }
  67237. void generate (const Font& newFont, const int glyphNumber) throw()
  67238. {
  67239. font = newFont;
  67240. glyph = glyphNumber;
  67241. edgeTable = 0;
  67242. Path glyphPath;
  67243. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  67244. if (! glyphPath.isEmpty())
  67245. {
  67246. const float fontHeight = font.getHeight();
  67247. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  67248. .translated (0.0f, -0.5f));
  67249. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  67250. glyphPath, transform);
  67251. }
  67252. }
  67253. int glyph, lastAccessCount;
  67254. Font font;
  67255. juce_UseDebuggingNewOperator
  67256. private:
  67257. ScopedPointer <EdgeTable> edgeTable;
  67258. CachedGlyph (const CachedGlyph&);
  67259. const CachedGlyph& operator= (const CachedGlyph&);
  67260. };
  67261. juce_UseDebuggingNewOperator
  67262. private:
  67263. OwnedArray <CachedGlyph> glyphs;
  67264. int accessCounter, hits, misses;
  67265. GlyphCache (const GlyphCache&);
  67266. const GlyphCache& operator= (const GlyphCache&);
  67267. };
  67268. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  67269. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  67270. {
  67271. currentState->font = newFont;
  67272. }
  67273. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  67274. {
  67275. return currentState->font;
  67276. }
  67277. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  67278. {
  67279. Font& f = currentState->font;
  67280. if (transform.isOnlyTranslation())
  67281. {
  67282. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  67283. transform.getTranslationX() + (float) currentState->xOffset,
  67284. transform.getTranslationY() + (float) currentState->yOffset);
  67285. }
  67286. else
  67287. {
  67288. Path p;
  67289. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  67290. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  67291. }
  67292. }
  67293. #if JUCE_MSVC
  67294. #pragma warning (pop)
  67295. #endif
  67296. END_JUCE_NAMESPACE
  67297. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  67298. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  67299. BEGIN_JUCE_NAMESPACE
  67300. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  67301. : flags (other.flags)
  67302. {
  67303. }
  67304. const RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  67305. {
  67306. flags = other.flags;
  67307. return *this;
  67308. }
  67309. void RectanglePlacement::applyTo (double& x, double& y,
  67310. double& w, double& h,
  67311. const double dx, const double dy,
  67312. const double dw, const double dh) const throw()
  67313. {
  67314. if (w == 0 || h == 0)
  67315. return;
  67316. if ((flags & stretchToFit) != 0)
  67317. {
  67318. x = dx;
  67319. y = dy;
  67320. w = dw;
  67321. h = dh;
  67322. }
  67323. else
  67324. {
  67325. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  67326. : jmin (dw / w, dh / h);
  67327. if ((flags & onlyReduceInSize) != 0)
  67328. scale = jmin (scale, 1.0);
  67329. if ((flags & onlyIncreaseInSize) != 0)
  67330. scale = jmax (scale, 1.0);
  67331. w *= scale;
  67332. h *= scale;
  67333. if ((flags & xLeft) != 0)
  67334. x = dx;
  67335. else if ((flags & xRight) != 0)
  67336. x = dx + dw - w;
  67337. else
  67338. x = dx + (dw - w) * 0.5;
  67339. if ((flags & yTop) != 0)
  67340. y = dy;
  67341. else if ((flags & yBottom) != 0)
  67342. y = dy + dh - h;
  67343. else
  67344. y = dy + (dh - h) * 0.5;
  67345. }
  67346. }
  67347. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  67348. float w, float h,
  67349. const float dx, const float dy,
  67350. const float dw, const float dh) const throw()
  67351. {
  67352. if (w == 0 || h == 0)
  67353. return AffineTransform::identity;
  67354. const float scaleX = dw / w;
  67355. const float scaleY = dh / h;
  67356. if ((flags & stretchToFit) != 0)
  67357. return AffineTransform::translation (-x, -y)
  67358. .scaled (scaleX, scaleY)
  67359. .translated (dx, dy);
  67360. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  67361. : jmin (scaleX, scaleY);
  67362. if ((flags & onlyReduceInSize) != 0)
  67363. scale = jmin (scale, 1.0f);
  67364. if ((flags & onlyIncreaseInSize) != 0)
  67365. scale = jmax (scale, 1.0f);
  67366. w *= scale;
  67367. h *= scale;
  67368. float newX = dx;
  67369. if ((flags & xRight) != 0)
  67370. newX += dw - w; // right
  67371. else if ((flags & xLeft) == 0)
  67372. newX += (dw - w) / 2.0f; // centre
  67373. float newY = dy;
  67374. if ((flags & yBottom) != 0)
  67375. newY += dh - h; // bottom
  67376. else if ((flags & yTop) == 0)
  67377. newY += (dh - h) / 2.0f; // centre
  67378. return AffineTransform::translation (-x, -y)
  67379. .scaled (scale, scale)
  67380. .translated (newX, newY);
  67381. }
  67382. END_JUCE_NAMESPACE
  67383. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  67384. /*** Start of inlined file: juce_Drawable.cpp ***/
  67385. BEGIN_JUCE_NAMESPACE
  67386. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  67387. const AffineTransform& transform_,
  67388. const float opacity_) throw()
  67389. : g (g_),
  67390. transform (transform_),
  67391. opacity (opacity_)
  67392. {
  67393. }
  67394. Drawable::Drawable()
  67395. {
  67396. }
  67397. Drawable::~Drawable()
  67398. {
  67399. }
  67400. void Drawable::draw (Graphics& g, const float opacity,
  67401. const AffineTransform& transform) const
  67402. {
  67403. render (RenderingContext (g, transform, opacity));
  67404. }
  67405. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  67406. {
  67407. draw (g, opacity, AffineTransform::translation (x, y));
  67408. }
  67409. void Drawable::drawWithin (Graphics& g,
  67410. const int destX,
  67411. const int destY,
  67412. const int destW,
  67413. const int destH,
  67414. const RectanglePlacement& placement,
  67415. const float opacity) const
  67416. {
  67417. if (destW > 0 && destH > 0)
  67418. {
  67419. Rectangle<float> bounds (getBounds());
  67420. draw (g, opacity,
  67421. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  67422. (float) destX, (float) destY,
  67423. (float) destW, (float) destH));
  67424. }
  67425. }
  67426. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  67427. {
  67428. Drawable* result = 0;
  67429. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  67430. if (image != 0)
  67431. {
  67432. DrawableImage* const di = new DrawableImage();
  67433. di->setImage (image, true);
  67434. result = di;
  67435. }
  67436. else
  67437. {
  67438. const String asString (String::createStringFromData (data, (int) numBytes));
  67439. XmlDocument doc (asString);
  67440. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  67441. if (outer != 0 && outer->hasTagName (T("svg")))
  67442. {
  67443. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  67444. if (svg != 0)
  67445. result = Drawable::createFromSVG (*svg);
  67446. }
  67447. }
  67448. return result;
  67449. }
  67450. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  67451. {
  67452. MemoryBlock mb;
  67453. dataSource.readIntoMemoryBlock (mb);
  67454. return createFromImageData (mb.getData(), mb.getSize());
  67455. }
  67456. Drawable* Drawable::createFromImageFile (const File& file)
  67457. {
  67458. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  67459. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  67460. }
  67461. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  67462. {
  67463. Drawable* d = DrawablePath::createFromValueTree (tree);
  67464. if (d == 0)
  67465. {
  67466. d = DrawableComposite::createFromValueTree (tree);
  67467. if (d == 0)
  67468. {
  67469. d = DrawableImage::createFromValueTree (tree);
  67470. if (d == 0)
  67471. d = DrawableText::createFromValueTree (tree);
  67472. }
  67473. }
  67474. return d;
  67475. }
  67476. END_JUCE_NAMESPACE
  67477. /*** End of inlined file: juce_Drawable.cpp ***/
  67478. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  67479. BEGIN_JUCE_NAMESPACE
  67480. DrawableComposite::DrawableComposite()
  67481. {
  67482. }
  67483. DrawableComposite::~DrawableComposite()
  67484. {
  67485. }
  67486. void DrawableComposite::insertDrawable (Drawable* drawable,
  67487. const AffineTransform& transform,
  67488. const int index)
  67489. {
  67490. if (drawable != 0)
  67491. {
  67492. if (! drawables.contains (drawable))
  67493. {
  67494. drawables.insert (index, drawable);
  67495. if (transform.isIdentity())
  67496. transforms.insert (index, 0);
  67497. else
  67498. transforms.insert (index, new AffineTransform (transform));
  67499. }
  67500. else
  67501. {
  67502. jassertfalse // trying to add a drawable that's already in here!
  67503. }
  67504. }
  67505. }
  67506. void DrawableComposite::insertDrawable (const Drawable& drawable,
  67507. const AffineTransform& transform,
  67508. const int index)
  67509. {
  67510. insertDrawable (drawable.createCopy(), transform, index);
  67511. }
  67512. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  67513. {
  67514. drawables.remove (index, deleteDrawable);
  67515. transforms.remove (index);
  67516. }
  67517. void DrawableComposite::bringToFront (const int index)
  67518. {
  67519. if (index >= 0 && index < drawables.size() - 1)
  67520. {
  67521. drawables.move (index, -1);
  67522. transforms.move (index, -1);
  67523. }
  67524. }
  67525. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  67526. {
  67527. if (drawables.size() > 0 && context.opacity > 0)
  67528. {
  67529. if (context.opacity >= 1.0f || drawables.size() == 1)
  67530. {
  67531. Drawable::RenderingContext contextCopy (context);
  67532. for (int i = 0; i < drawables.size(); ++i)
  67533. {
  67534. const AffineTransform* const t = transforms.getUnchecked(i);
  67535. contextCopy.transform = (t == 0) ? context.transform
  67536. : t->followedBy (context.transform);
  67537. drawables.getUnchecked(i)->render (contextCopy);
  67538. }
  67539. }
  67540. else
  67541. {
  67542. // To correctly render a whole composite layer with an overall transparency,
  67543. // we need to render everything opaquely into a temp buffer, then blend that
  67544. // with the target opacity...
  67545. const Rectangle<int> clipBounds (context.g.getClipBounds());
  67546. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67547. {
  67548. Graphics tempG (tempImage);
  67549. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67550. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67551. render (tempContext);
  67552. }
  67553. context.g.setOpacity (context.opacity);
  67554. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67555. }
  67556. }
  67557. }
  67558. const Rectangle<float> DrawableComposite::getBounds() const
  67559. {
  67560. Rectangle<float> bounds;
  67561. for (int i = 0; i < drawables.size(); ++i)
  67562. {
  67563. const Drawable* const d = drawables.getUnchecked(i);
  67564. const AffineTransform* const t = transforms.getUnchecked(i);
  67565. bounds = bounds.getUnion (t == 0 ? d->getBounds()
  67566. : d->getBounds().transformed (*t));
  67567. }
  67568. return bounds;
  67569. }
  67570. bool DrawableComposite::hitTest (float x, float y) const
  67571. {
  67572. for (int i = 0; i < drawables.size(); ++i)
  67573. {
  67574. float tx = x;
  67575. float ty = y;
  67576. const AffineTransform* const t = transforms.getUnchecked(i);
  67577. if (t != 0)
  67578. t->inverted().transformPoint (tx, ty);
  67579. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67580. return true;
  67581. }
  67582. return false;
  67583. }
  67584. Drawable* DrawableComposite::createCopy() const
  67585. {
  67586. DrawableComposite* const dc = new DrawableComposite();
  67587. for (int i = 0; i < drawables.size(); ++i)
  67588. {
  67589. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67590. const AffineTransform* const t = transforms.getUnchecked(i);
  67591. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67592. }
  67593. return dc;
  67594. }
  67595. ValueTree DrawableComposite::createValueTree() const throw()
  67596. {
  67597. ValueTree v (T("Group"));
  67598. if (getName().isNotEmpty())
  67599. v.setProperty ("id", getName(), 0);
  67600. for (int i = 0; i < drawables.size(); ++i)
  67601. {
  67602. Drawable* const d = drawables.getUnchecked(i);
  67603. ValueTree child (d->createValueTree());
  67604. AffineTransform* transform = transforms.getUnchecked(i);
  67605. if (transform != 0)
  67606. {
  67607. String t;
  67608. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67609. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67610. child.setProperty ("transform", t, 0);
  67611. }
  67612. v.addChild (child, -1, 0);
  67613. }
  67614. return v;
  67615. }
  67616. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67617. {
  67618. if (! tree.hasType ("Group"))
  67619. return 0;
  67620. DrawableComposite* dc = new DrawableComposite();
  67621. dc->setName (tree ["id"]);
  67622. for (int i = 0; i < tree.getNumChildren(); ++i)
  67623. {
  67624. ValueTree childTree (tree.getChild (i));
  67625. Drawable* d = Drawable::createFromValueTree (childTree);
  67626. if (d != 0)
  67627. {
  67628. AffineTransform transform;
  67629. const String transformAtt (childTree ["transform"].toString());
  67630. if (transformAtt.isNotEmpty())
  67631. {
  67632. StringArray tokens;
  67633. tokens.addTokens (transformAtt.trim(), false);
  67634. tokens.removeEmptyStrings (true);
  67635. if (tokens.size() == 6)
  67636. {
  67637. float f[6];
  67638. for (int j = 0; j < 6; ++j)
  67639. f[j] = (float) tokens[j].getDoubleValue();
  67640. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67641. }
  67642. }
  67643. dc->insertDrawable (d, transform);
  67644. }
  67645. }
  67646. return dc;
  67647. }
  67648. END_JUCE_NAMESPACE
  67649. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67650. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67651. BEGIN_JUCE_NAMESPACE
  67652. DrawableImage::DrawableImage()
  67653. : image (0),
  67654. canDeleteImage (false),
  67655. opacity (1.0f),
  67656. overlayColour (0x00000000)
  67657. {
  67658. }
  67659. DrawableImage::~DrawableImage()
  67660. {
  67661. clearImage();
  67662. }
  67663. void DrawableImage::clearImage()
  67664. {
  67665. if (canDeleteImage && image != 0)
  67666. ImageCache::releaseOrDelete (image);
  67667. image = 0;
  67668. }
  67669. void DrawableImage::setImage (const Image& imageToCopy)
  67670. {
  67671. clearImage();
  67672. image = new Image (imageToCopy);
  67673. canDeleteImage = true;
  67674. }
  67675. void DrawableImage::setImage (Image* imageToUse,
  67676. const bool releaseWhenNotNeeded)
  67677. {
  67678. clearImage();
  67679. image = imageToUse;
  67680. canDeleteImage = releaseWhenNotNeeded;
  67681. }
  67682. void DrawableImage::setOpacity (const float newOpacity)
  67683. {
  67684. opacity = newOpacity;
  67685. }
  67686. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67687. {
  67688. overlayColour = newOverlayColour;
  67689. }
  67690. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67691. {
  67692. if (image != 0)
  67693. {
  67694. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67695. {
  67696. context.g.setOpacity (context.opacity * opacity);
  67697. context.g.drawImageTransformed (image, image->getBounds(),
  67698. context.transform, false);
  67699. }
  67700. if (! overlayColour.isTransparent())
  67701. {
  67702. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67703. context.g.drawImageTransformed (image, image->getBounds(),
  67704. context.transform, true);
  67705. }
  67706. }
  67707. }
  67708. const Rectangle<float> DrawableImage::getBounds() const
  67709. {
  67710. if (image == 0)
  67711. return Rectangle<float>();
  67712. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67713. }
  67714. bool DrawableImage::hitTest (float x, float y) const
  67715. {
  67716. return image != 0
  67717. && x >= 0.0f
  67718. && y >= 0.0f
  67719. && x < image->getWidth()
  67720. && y < image->getHeight()
  67721. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67722. }
  67723. Drawable* DrawableImage::createCopy() const
  67724. {
  67725. DrawableImage* const di = new DrawableImage();
  67726. di->opacity = opacity;
  67727. di->overlayColour = overlayColour;
  67728. if (image != 0)
  67729. {
  67730. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67731. {
  67732. di->setImage (*image);
  67733. }
  67734. else
  67735. {
  67736. ImageCache::incReferenceCount (image);
  67737. di->setImage (image, true);
  67738. }
  67739. }
  67740. return di;
  67741. }
  67742. ValueTree DrawableImage::createValueTree() const throw()
  67743. {
  67744. ValueTree v (T("Image"));
  67745. if (getName().isNotEmpty())
  67746. v.setProperty ("id", getName(), 0);
  67747. if (opacity < 1.0f)
  67748. v.setProperty ("opacity", (double) opacity, 0);
  67749. if (! overlayColour.isTransparent())
  67750. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67751. if (image != 0)
  67752. {
  67753. MemoryOutputStream imageData;
  67754. PNGImageFormat pngFormat;
  67755. if (pngFormat.writeImageToStream (*image, imageData))
  67756. {
  67757. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67758. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67759. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67760. v.setProperty ("data", base64, 0);
  67761. }
  67762. }
  67763. return v;
  67764. }
  67765. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67766. {
  67767. if (! tree.hasType ("Image"))
  67768. return 0;
  67769. DrawableImage* di = new DrawableImage();
  67770. di->setName (tree ["id"]);
  67771. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67772. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67773. MemoryBlock imageData;
  67774. if (imageData.fromBase64Encoding (tree ["data"]))
  67775. {
  67776. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67777. if (im == 0)
  67778. return false;
  67779. di->setImage (im, true);
  67780. }
  67781. return di;
  67782. }
  67783. END_JUCE_NAMESPACE
  67784. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67785. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67786. BEGIN_JUCE_NAMESPACE
  67787. DrawablePath::DrawablePath()
  67788. : mainFill (FillType (Colours::black)),
  67789. strokeFill (FillType (Colours::transparentBlack)),
  67790. strokeType (0.0f)
  67791. {
  67792. }
  67793. DrawablePath::~DrawablePath()
  67794. {
  67795. }
  67796. void DrawablePath::setPath (const Path& newPath) throw()
  67797. {
  67798. path = newPath;
  67799. updateOutline();
  67800. }
  67801. void DrawablePath::setFill (const FillType& newFill) throw()
  67802. {
  67803. mainFill = newFill;
  67804. }
  67805. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67806. {
  67807. strokeFill = newFill;
  67808. }
  67809. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67810. {
  67811. strokeType = newStrokeType;
  67812. updateOutline();
  67813. }
  67814. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67815. {
  67816. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67817. }
  67818. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67819. {
  67820. {
  67821. FillType f (mainFill);
  67822. if (f.isGradient())
  67823. f.gradient->multiplyOpacity (context.opacity);
  67824. f.transform = f.transform.followedBy (context.transform);
  67825. context.g.setFillType (f);
  67826. context.g.fillPath (path, context.transform);
  67827. }
  67828. if (strokeType.getStrokeThickness() > 0.0f)
  67829. {
  67830. FillType f (strokeFill);
  67831. if (f.isGradient())
  67832. f.gradient->multiplyOpacity (context.opacity);
  67833. f.transform = f.transform.followedBy (context.transform);
  67834. context.g.setFillType (f);
  67835. context.g.fillPath (stroke, context.transform);
  67836. }
  67837. }
  67838. void DrawablePath::updateOutline()
  67839. {
  67840. stroke.clear();
  67841. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67842. }
  67843. const Rectangle<float> DrawablePath::getBounds() const
  67844. {
  67845. if (strokeType.getStrokeThickness() > 0.0f)
  67846. return stroke.getBounds();
  67847. else
  67848. return path.getBounds();
  67849. }
  67850. bool DrawablePath::hitTest (float x, float y) const
  67851. {
  67852. return path.contains (x, y)
  67853. || stroke.contains (x, y);
  67854. }
  67855. Drawable* DrawablePath::createCopy() const
  67856. {
  67857. DrawablePath* const dp = new DrawablePath();
  67858. dp->path = path;
  67859. dp->stroke = stroke;
  67860. dp->mainFill = mainFill;
  67861. dp->strokeFill = strokeFill;
  67862. dp->strokeType = strokeType;
  67863. return dp;
  67864. }
  67865. static const FillType readFillTypeFromTree (const ValueTree& v)
  67866. {
  67867. const String type (v["type"].toString());
  67868. if (type.equalsIgnoreCase (T("solid")))
  67869. {
  67870. const String colour (v ["colour"].toString());
  67871. return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000
  67872. : (uint32) colour.getHexValue32()));
  67873. }
  67874. else if (type.equalsIgnoreCase ("gradient"))
  67875. {
  67876. ColourGradient g;
  67877. g.x1 = v["x1"];
  67878. g.y1 = v["y1"];
  67879. g.x2 = v["x2"];
  67880. g.y2 = v["y2"];
  67881. g.isRadial = v["radial"];
  67882. StringArray colours;
  67883. colours.addTokens (v["colours"].toString(), false);
  67884. for (int i = 0; i < colours.size() / 2; ++i)
  67885. g.addColour (colours[i * 2].getDoubleValue(),
  67886. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67887. return FillType (g);
  67888. }
  67889. jassertfalse
  67890. return FillType();
  67891. }
  67892. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67893. {
  67894. ValueTree v (tagName);
  67895. if (fillType.isColour())
  67896. {
  67897. v.setProperty ("type", T("solid"), 0);
  67898. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67899. }
  67900. else if (fillType.isGradient())
  67901. {
  67902. v.setProperty ("type", T("gradient"), 0);
  67903. v.setProperty ("x1", fillType.gradient->x1, 0);
  67904. v.setProperty ("y1", fillType.gradient->y1, 0);
  67905. v.setProperty ("x2", fillType.gradient->x2, 0);
  67906. v.setProperty ("y2", fillType.gradient->y2, 0);
  67907. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67908. String s;
  67909. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67910. s << " " << fillType.gradient->getColourPosition (i)
  67911. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67912. v.setProperty ("colours", s.trimStart(), 0);
  67913. }
  67914. else
  67915. {
  67916. jassertfalse //xxx
  67917. }
  67918. return v;
  67919. }
  67920. ValueTree DrawablePath::createValueTree() const throw()
  67921. {
  67922. ValueTree v (T("Path"));
  67923. v.addChild (createTreeForFillType (T("fill"), mainFill), -1, 0);
  67924. v.addChild (createTreeForFillType (T("stroke"), strokeFill), -1, 0);
  67925. if (getName().isNotEmpty())
  67926. v.setProperty ("id", getName(), 0);
  67927. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67928. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67929. ? T("miter") : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel")), 0);
  67930. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67931. ? T("butt") : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round")), 0);
  67932. v.setProperty ("path", path.toString(), 0);
  67933. return v;
  67934. }
  67935. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67936. {
  67937. if (! tree.hasType ("Path"))
  67938. return 0;
  67939. DrawablePath* p = new DrawablePath();
  67940. p->setName (tree ["id"]);
  67941. p->mainFill = readFillTypeFromTree (tree.getChildWithName (T("fill")));
  67942. p->strokeFill = readFillTypeFromTree (tree.getChildWithName (T("stroke")));
  67943. const String jointStyle (tree ["jointStyle"].toString());
  67944. const String endStyle (tree ["capStyle"].toString());
  67945. p->strokeType
  67946. = PathStrokeType (tree ["strokeWidth"],
  67947. jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved
  67948. : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled
  67949. : PathStrokeType::mitered),
  67950. endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square
  67951. : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded
  67952. : PathStrokeType::butt));
  67953. p->path.clear();
  67954. p->path.restoreFromString (tree ["path"]);
  67955. p->updateOutline();
  67956. return p;
  67957. }
  67958. END_JUCE_NAMESPACE
  67959. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67960. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67961. BEGIN_JUCE_NAMESPACE
  67962. DrawableText::DrawableText()
  67963. : colour (Colours::white)
  67964. {
  67965. }
  67966. DrawableText::~DrawableText()
  67967. {
  67968. }
  67969. void DrawableText::setText (const GlyphArrangement& newText)
  67970. {
  67971. text = newText;
  67972. }
  67973. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67974. {
  67975. text.clear();
  67976. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67977. }
  67978. void DrawableText::setColour (const Colour& newColour)
  67979. {
  67980. colour = newColour;
  67981. }
  67982. void DrawableText::render (const Drawable::RenderingContext& context) const
  67983. {
  67984. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67985. text.draw (context.g, context.transform);
  67986. }
  67987. const Rectangle<float> DrawableText::getBounds() const
  67988. {
  67989. float x, y, w, h;
  67990. text.getBoundingBox (0, -1, x, y, w, h, false); // (really returns top, left, bottom, right)
  67991. w -= x;
  67992. h -= y;
  67993. return Rectangle<float> (x, y, w, h);
  67994. }
  67995. bool DrawableText::hitTest (float x, float y) const
  67996. {
  67997. return text.findGlyphIndexAt (x, y) >= 0;
  67998. }
  67999. Drawable* DrawableText::createCopy() const
  68000. {
  68001. DrawableText* const dt = new DrawableText();
  68002. dt->text = text;
  68003. dt->colour = colour;
  68004. return dt;
  68005. }
  68006. ValueTree DrawableText::createValueTree() const throw()
  68007. {
  68008. ValueTree v (T("Text"));
  68009. if (getName().isNotEmpty())
  68010. v.setProperty ("id", getName(), 0);
  68011. jassertfalse // xxx not finished!
  68012. return v;
  68013. }
  68014. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  68015. {
  68016. if (! tree.hasType ("Text"))
  68017. return 0;
  68018. DrawableText* dt = new DrawableText();
  68019. dt->setName (tree ["id"]);
  68020. jassertfalse // xxx not finished!
  68021. return dt;
  68022. }
  68023. END_JUCE_NAMESPACE
  68024. /*** End of inlined file: juce_DrawableText.cpp ***/
  68025. /*** Start of inlined file: juce_SVGParser.cpp ***/
  68026. BEGIN_JUCE_NAMESPACE
  68027. class SVGState
  68028. {
  68029. public:
  68030. SVGState (const XmlElement* const topLevel)
  68031. : topLevelXml (topLevel),
  68032. elementX (0), elementY (0),
  68033. width (512), height (512),
  68034. viewBoxW (0), viewBoxH (0)
  68035. {
  68036. }
  68037. ~SVGState()
  68038. {
  68039. }
  68040. Drawable* parseSVGElement (const XmlElement& xml)
  68041. {
  68042. if (! xml.hasTagName (T("svg")))
  68043. return 0;
  68044. DrawableComposite* const drawable = new DrawableComposite();
  68045. drawable->setName (xml.getStringAttribute (T("id")));
  68046. SVGState newState (*this);
  68047. if (xml.hasAttribute (T("transform")))
  68048. newState.addTransform (xml);
  68049. newState.elementX = getCoordLength (xml.getStringAttribute (T("x"), String (newState.elementX)), viewBoxW);
  68050. newState.elementY = getCoordLength (xml.getStringAttribute (T("y"), String (newState.elementY)), viewBoxH);
  68051. newState.width = getCoordLength (xml.getStringAttribute (T("width"), String (newState.width)), viewBoxW);
  68052. newState.height = getCoordLength (xml.getStringAttribute (T("height"), String (newState.height)), viewBoxH);
  68053. if (xml.hasAttribute (T("viewBox")))
  68054. {
  68055. const String viewParams (xml.getStringAttribute (T("viewBox")));
  68056. int i = 0;
  68057. float vx, vy, vw, vh;
  68058. if (parseCoords (viewParams, vx, vy, i, true)
  68059. && parseCoords (viewParams, vw, vh, i, true)
  68060. && vw > 0
  68061. && vh > 0)
  68062. {
  68063. newState.viewBoxW = vw;
  68064. newState.viewBoxH = vh;
  68065. int placementFlags = 0;
  68066. const String aspect (xml.getStringAttribute (T("preserveAspectRatio")));
  68067. if (aspect.containsIgnoreCase (T("none")))
  68068. {
  68069. placementFlags = RectanglePlacement::stretchToFit;
  68070. }
  68071. else
  68072. {
  68073. if (aspect.containsIgnoreCase (T("slice")))
  68074. placementFlags |= RectanglePlacement::fillDestination;
  68075. if (aspect.containsIgnoreCase (T("xMin")))
  68076. placementFlags |= RectanglePlacement::xLeft;
  68077. else if (aspect.containsIgnoreCase (T("xMax")))
  68078. placementFlags |= RectanglePlacement::xRight;
  68079. else
  68080. placementFlags |= RectanglePlacement::xMid;
  68081. if (aspect.containsIgnoreCase (T("yMin")))
  68082. placementFlags |= RectanglePlacement::yTop;
  68083. else if (aspect.containsIgnoreCase (T("yMax")))
  68084. placementFlags |= RectanglePlacement::yBottom;
  68085. else
  68086. placementFlags |= RectanglePlacement::yMid;
  68087. }
  68088. const RectanglePlacement placement (placementFlags);
  68089. newState.transform
  68090. = placement.getTransformToFit (vx, vy, vw, vh,
  68091. 0.0f, 0.0f, newState.width, newState.height)
  68092. .followedBy (newState.transform);
  68093. }
  68094. }
  68095. else
  68096. {
  68097. if (viewBoxW == 0)
  68098. newState.viewBoxW = newState.width;
  68099. if (viewBoxH == 0)
  68100. newState.viewBoxH = newState.height;
  68101. }
  68102. newState.parseSubElements (xml, drawable);
  68103. return drawable;
  68104. }
  68105. private:
  68106. const XmlElement* const topLevelXml;
  68107. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  68108. AffineTransform transform;
  68109. String cssStyleText;
  68110. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  68111. {
  68112. forEachXmlChildElement (xml, e)
  68113. {
  68114. Drawable* d = 0;
  68115. if (e->hasTagName (T("g")))
  68116. d = parseGroupElement (*e);
  68117. else if (e->hasTagName (T("svg")))
  68118. d = parseSVGElement (*e);
  68119. else if (e->hasTagName (T("path")))
  68120. d = parsePath (*e);
  68121. else if (e->hasTagName (T("rect")))
  68122. d = parseRect (*e);
  68123. else if (e->hasTagName (T("circle")))
  68124. d = parseCircle (*e);
  68125. else if (e->hasTagName (T("ellipse")))
  68126. d = parseEllipse (*e);
  68127. else if (e->hasTagName (T("line")))
  68128. d = parseLine (*e);
  68129. else if (e->hasTagName (T("polyline")))
  68130. d = parsePolygon (*e, true);
  68131. else if (e->hasTagName (T("polygon")))
  68132. d = parsePolygon (*e, false);
  68133. else if (e->hasTagName (T("text")))
  68134. d = parseText (*e);
  68135. else if (e->hasTagName (T("switch")))
  68136. d = parseSwitch (*e);
  68137. else if (e->hasTagName (T("style")))
  68138. parseCSSStyle (*e);
  68139. parentDrawable->insertDrawable (d);
  68140. }
  68141. }
  68142. DrawableComposite* parseSwitch (const XmlElement& xml)
  68143. {
  68144. const XmlElement* const group = xml.getChildByName (T("g"));
  68145. if (group != 0)
  68146. return parseGroupElement (*group);
  68147. return 0;
  68148. }
  68149. DrawableComposite* parseGroupElement (const XmlElement& xml)
  68150. {
  68151. DrawableComposite* const drawable = new DrawableComposite();
  68152. drawable->setName (xml.getStringAttribute (T("id")));
  68153. if (xml.hasAttribute (T("transform")))
  68154. {
  68155. SVGState newState (*this);
  68156. newState.addTransform (xml);
  68157. newState.parseSubElements (xml, drawable);
  68158. }
  68159. else
  68160. {
  68161. parseSubElements (xml, drawable);
  68162. }
  68163. return drawable;
  68164. }
  68165. Drawable* parsePath (const XmlElement& xml) const
  68166. {
  68167. const String d (xml.getStringAttribute (T("d")).trimStart());
  68168. Path path;
  68169. if (getStyleAttribute (&xml, T("fill-rule")).trim().equalsIgnoreCase (T("evenodd")))
  68170. path.setUsingNonZeroWinding (false);
  68171. int index = 0;
  68172. float lastX = 0, lastY = 0;
  68173. float lastX2 = 0, lastY2 = 0;
  68174. tchar lastCommandChar = 0;
  68175. bool carryOn = true;
  68176. const String validCommandChars (T("MmLlHhVvCcSsQqTtAaZz"));
  68177. for (;;)
  68178. {
  68179. float x, y, x2, y2, x3, y3;
  68180. const bool isRelative = (d[index] >= 'a' && d[index] <= 'z');
  68181. if (validCommandChars.containsChar (d[index]))
  68182. lastCommandChar = d [index++];
  68183. switch (lastCommandChar)
  68184. {
  68185. case T('M'):
  68186. case T('m'):
  68187. case T('L'):
  68188. case T('l'):
  68189. if (parseCoords (d, x, y, index, false))
  68190. {
  68191. if (isRelative)
  68192. {
  68193. x += lastX;
  68194. y += lastY;
  68195. }
  68196. if (lastCommandChar == T('M') || lastCommandChar == T('m'))
  68197. path.startNewSubPath (x, y);
  68198. else
  68199. path.lineTo (x, y);
  68200. lastX2 = lastX;
  68201. lastY2 = lastY;
  68202. lastX = x;
  68203. lastY = y;
  68204. }
  68205. else
  68206. {
  68207. ++index;
  68208. }
  68209. break;
  68210. case T('H'):
  68211. case T('h'):
  68212. if (parseCoord (d, x, index, false, true))
  68213. {
  68214. if (isRelative)
  68215. x += lastX;
  68216. path.lineTo (x, lastY);
  68217. lastX2 = lastX;
  68218. lastX = x;
  68219. }
  68220. else
  68221. {
  68222. ++index;
  68223. }
  68224. break;
  68225. case T('V'):
  68226. case T('v'):
  68227. if (parseCoord (d, y, index, false, false))
  68228. {
  68229. if (isRelative)
  68230. y += lastY;
  68231. path.lineTo (lastX, y);
  68232. lastY2 = lastY;
  68233. lastY = y;
  68234. }
  68235. else
  68236. {
  68237. ++index;
  68238. }
  68239. break;
  68240. case T('C'):
  68241. case T('c'):
  68242. if (parseCoords (d, x, y, index, false)
  68243. && parseCoords (d, x2, y2, index, false)
  68244. && parseCoords (d, x3, y3, index, false))
  68245. {
  68246. if (isRelative)
  68247. {
  68248. x += lastX;
  68249. y += lastY;
  68250. x2 += lastX;
  68251. y2 += lastY;
  68252. x3 += lastX;
  68253. y3 += lastY;
  68254. }
  68255. path.cubicTo (x, y, x2, y2, x3, y3);
  68256. lastX2 = x2;
  68257. lastY2 = y2;
  68258. lastX = x3;
  68259. lastY = y3;
  68260. }
  68261. else
  68262. {
  68263. ++index;
  68264. }
  68265. break;
  68266. case T('S'):
  68267. case T('s'):
  68268. if (parseCoords (d, x, y, index, false)
  68269. && parseCoords (d, x3, y3, index, false))
  68270. {
  68271. if (isRelative)
  68272. {
  68273. x += lastX;
  68274. y += lastY;
  68275. x3 += lastX;
  68276. y3 += lastY;
  68277. }
  68278. x2 = lastX + (lastX - lastX2);
  68279. y2 = lastY + (lastY - lastY2);
  68280. path.cubicTo (x2, y2, x, y, x3, y3);
  68281. lastX2 = x;
  68282. lastY2 = y;
  68283. lastX = x3;
  68284. lastY = y3;
  68285. }
  68286. else
  68287. {
  68288. ++index;
  68289. }
  68290. break;
  68291. case T('Q'):
  68292. case T('q'):
  68293. if (parseCoords (d, x, y, index, false)
  68294. && parseCoords (d, x2, y2, index, false))
  68295. {
  68296. if (isRelative)
  68297. {
  68298. x += lastX;
  68299. y += lastY;
  68300. x2 += lastX;
  68301. y2 += lastY;
  68302. }
  68303. path.quadraticTo (x, y, x2, y2);
  68304. lastX2 = x;
  68305. lastY2 = y;
  68306. lastX = x2;
  68307. lastY = y2;
  68308. }
  68309. else
  68310. {
  68311. ++index;
  68312. }
  68313. break;
  68314. case T('T'):
  68315. case T('t'):
  68316. if (parseCoords (d, x, y, index, false))
  68317. {
  68318. if (isRelative)
  68319. {
  68320. x += lastX;
  68321. y += lastY;
  68322. }
  68323. x2 = lastX + (lastX - lastX2);
  68324. y2 = lastY + (lastY - lastY2);
  68325. path.quadraticTo (x2, y2, x, y);
  68326. lastX2 = x2;
  68327. lastY2 = y2;
  68328. lastX = x;
  68329. lastY = y;
  68330. }
  68331. else
  68332. {
  68333. ++index;
  68334. }
  68335. break;
  68336. case T('A'):
  68337. case T('a'):
  68338. if (parseCoords (d, x, y, index, false))
  68339. {
  68340. String num;
  68341. if (parseNextNumber (d, num, index, false))
  68342. {
  68343. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  68344. if (parseNextNumber (d, num, index, false))
  68345. {
  68346. const bool largeArc = num.getIntValue() != 0;
  68347. if (parseNextNumber (d, num, index, false))
  68348. {
  68349. const bool sweep = num.getIntValue() != 0;
  68350. if (parseCoords (d, x2, y2, index, false))
  68351. {
  68352. if (isRelative)
  68353. {
  68354. x2 += lastX;
  68355. y2 += lastY;
  68356. }
  68357. if (lastX != x2 || lastY != y2)
  68358. {
  68359. double centreX, centreY, startAngle, deltaAngle;
  68360. double rx = x, ry = y;
  68361. endpointToCentreParameters (lastX, lastY, x2, y2,
  68362. angle, largeArc, sweep,
  68363. rx, ry, centreX, centreY,
  68364. startAngle, deltaAngle);
  68365. path.addCentredArc ((float) centreX, (float) centreY,
  68366. (float) rx, (float) ry,
  68367. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  68368. false);
  68369. path.lineTo (x2, y2);
  68370. }
  68371. lastX2 = lastX;
  68372. lastY2 = lastY;
  68373. lastX = x2;
  68374. lastY = y2;
  68375. }
  68376. }
  68377. }
  68378. }
  68379. }
  68380. else
  68381. {
  68382. ++index;
  68383. }
  68384. break;
  68385. case T('Z'):
  68386. case T('z'):
  68387. path.closeSubPath();
  68388. while (CharacterFunctions::isWhitespace (d [index]))
  68389. ++index;
  68390. break;
  68391. default:
  68392. carryOn = false;
  68393. break;
  68394. }
  68395. if (! carryOn)
  68396. break;
  68397. }
  68398. return parseShape (xml, path);
  68399. }
  68400. Drawable* parseRect (const XmlElement& xml) const
  68401. {
  68402. Path rect;
  68403. const bool hasRX = xml.hasAttribute (T("rx"));
  68404. const bool hasRY = xml.hasAttribute (T("ry"));
  68405. if (hasRX || hasRY)
  68406. {
  68407. float rx = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68408. float ry = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68409. if (! hasRX)
  68410. rx = ry;
  68411. else if (! hasRY)
  68412. ry = rx;
  68413. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68414. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68415. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68416. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH),
  68417. rx, ry);
  68418. }
  68419. else
  68420. {
  68421. rect.addRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68422. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68423. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68424. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH));
  68425. }
  68426. return parseShape (xml, rect);
  68427. }
  68428. Drawable* parseCircle (const XmlElement& xml) const
  68429. {
  68430. Path circle;
  68431. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68432. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68433. const float radius = getCoordLength (xml.getStringAttribute (T("r")), viewBoxW);
  68434. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  68435. return parseShape (xml, circle);
  68436. }
  68437. Drawable* parseEllipse (const XmlElement& xml) const
  68438. {
  68439. Path ellipse;
  68440. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68441. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68442. const float radiusX = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68443. const float radiusY = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68444. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  68445. return parseShape (xml, ellipse);
  68446. }
  68447. Drawable* parseLine (const XmlElement& xml) const
  68448. {
  68449. Path line;
  68450. const float x1 = getCoordLength (xml.getStringAttribute (T("x1")), viewBoxW);
  68451. const float y1 = getCoordLength (xml.getStringAttribute (T("y1")), viewBoxH);
  68452. const float x2 = getCoordLength (xml.getStringAttribute (T("x2")), viewBoxW);
  68453. const float y2 = getCoordLength (xml.getStringAttribute (T("y2")), viewBoxH);
  68454. line.startNewSubPath (x1, y1);
  68455. line.lineTo (x2, y2);
  68456. return parseShape (xml, line);
  68457. }
  68458. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  68459. {
  68460. const String points (xml.getStringAttribute (T("points")));
  68461. Path path;
  68462. int index = 0;
  68463. float x, y;
  68464. if (parseCoords (points, x, y, index, true))
  68465. {
  68466. float firstX = x;
  68467. float firstY = y;
  68468. float lastX = 0, lastY = 0;
  68469. path.startNewSubPath (x, y);
  68470. while (parseCoords (points, x, y, index, true))
  68471. {
  68472. lastX = x;
  68473. lastY = y;
  68474. path.lineTo (x, y);
  68475. }
  68476. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  68477. path.closeSubPath();
  68478. }
  68479. return parseShape (xml, path);
  68480. }
  68481. Drawable* parseShape (const XmlElement& xml, Path& path,
  68482. const bool shouldParseTransform = true) const
  68483. {
  68484. if (shouldParseTransform && xml.hasAttribute (T("transform")))
  68485. {
  68486. SVGState newState (*this);
  68487. newState.addTransform (xml);
  68488. return newState.parseShape (xml, path, false);
  68489. }
  68490. DrawablePath* dp = new DrawablePath();
  68491. dp->setName (xml.getStringAttribute (T("id")));
  68492. dp->setFill (FillType (Colours::transparentBlack));
  68493. path.applyTransform (transform);
  68494. dp->setPath (path);
  68495. Path::Iterator iter (path);
  68496. bool containsClosedSubPath = false;
  68497. while (iter.next())
  68498. {
  68499. if (iter.elementType == Path::Iterator::closePath)
  68500. {
  68501. containsClosedSubPath = true;
  68502. break;
  68503. }
  68504. }
  68505. dp->setFill (getPathFillType (path,
  68506. getStyleAttribute (&xml, T("fill")),
  68507. getStyleAttribute (&xml, T("fill-opacity")),
  68508. getStyleAttribute (&xml, T("opacity")),
  68509. containsClosedSubPath ? Colours::black
  68510. : Colours::transparentBlack));
  68511. const String strokeType (getStyleAttribute (&xml, T("stroke")));
  68512. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase (T("none")))
  68513. {
  68514. dp->setStrokeFill (getPathFillType (path, strokeType,
  68515. getStyleAttribute (&xml, T("stroke-opacity")),
  68516. getStyleAttribute (&xml, T("opacity")),
  68517. Colours::transparentBlack));
  68518. dp->setStrokeType (getStrokeFor (&xml));
  68519. }
  68520. return dp;
  68521. }
  68522. const XmlElement* findLinkedElement (const XmlElement* e) const
  68523. {
  68524. const String id (e->getStringAttribute (T("xlink:href")));
  68525. if (! id.startsWithChar (T('#')))
  68526. return 0;
  68527. return findElementForId (topLevelXml, id.substring (1));
  68528. }
  68529. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  68530. {
  68531. if (fillXml == 0)
  68532. return;
  68533. forEachXmlChildElementWithTagName (*fillXml, e, T("stop"))
  68534. {
  68535. int index = 0;
  68536. Colour col (parseColour (getStyleAttribute (e, T("stop-color")), index, Colours::black));
  68537. const String opacity (getStyleAttribute (e, T("stop-opacity"), T("1")));
  68538. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68539. double offset = e->getDoubleAttribute (T("offset"));
  68540. if (e->getStringAttribute (T("offset")).containsChar (T('%')))
  68541. offset *= 0.01;
  68542. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68543. }
  68544. }
  68545. const FillType getPathFillType (const Path& path,
  68546. const String& fill,
  68547. const String& fillOpacity,
  68548. const String& overallOpacity,
  68549. const Colour& defaultColour) const
  68550. {
  68551. float opacity = 1.0f;
  68552. if (overallOpacity.isNotEmpty())
  68553. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68554. if (fillOpacity.isNotEmpty())
  68555. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68556. if (fill.startsWithIgnoreCase (T("url")))
  68557. {
  68558. const String id (fill.fromFirstOccurrenceOf (T("#"), false, false)
  68559. .upToLastOccurrenceOf (T(")"), false, false).trim());
  68560. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68561. if (fillXml != 0
  68562. && (fillXml->hasTagName (T("linearGradient"))
  68563. || fillXml->hasTagName (T("radialGradient"))))
  68564. {
  68565. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68566. ColourGradient gradient;
  68567. addGradientStopsIn (gradient, inheritedFrom);
  68568. addGradientStopsIn (gradient, fillXml);
  68569. if (gradient.getNumColours() > 0)
  68570. {
  68571. gradient.addColour (0.0, gradient.getColour (0));
  68572. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68573. }
  68574. else
  68575. {
  68576. gradient.addColour (0.0, Colours::black);
  68577. gradient.addColour (1.0, Colours::black);
  68578. }
  68579. if (overallOpacity.isNotEmpty())
  68580. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68581. jassert (gradient.getNumColours() > 0);
  68582. gradient.isRadial = fillXml->hasTagName (T("radialGradient"));
  68583. float width = viewBoxW;
  68584. float height = viewBoxH;
  68585. float dx = 0.0f;
  68586. float dy = 0.0f;
  68587. const bool userSpace = fillXml->getStringAttribute (T("gradientUnits")).equalsIgnoreCase (T("userSpaceOnUse"));
  68588. if (! userSpace)
  68589. {
  68590. const Rectangle<float> bounds (path.getBounds());
  68591. dx = bounds.getX();
  68592. dy = bounds.getY();
  68593. width = bounds.getWidth();
  68594. height = bounds.getHeight();
  68595. }
  68596. if (gradient.isRadial)
  68597. {
  68598. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("cx"), T("50%")), width);
  68599. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("cy"), T("50%")), height);
  68600. const float radius = getCoordLength (fillXml->getStringAttribute (T("r"), T("50%")), width);
  68601. gradient.x2 = gradient.x1 + radius;
  68602. gradient.y2 = gradient.y1;
  68603. //xxx (the fx, fy focal point isn't handled properly here..)
  68604. }
  68605. else
  68606. {
  68607. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("x1"), T("0%")), width);
  68608. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("y1"), T("0%")), height);
  68609. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute (T("x2"), T("100%")), width);
  68610. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute (T("y2"), T("0%")), height);
  68611. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68612. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68613. }
  68614. FillType type (gradient);
  68615. type.transform = parseTransform (fillXml->getStringAttribute (T("gradientTransform")))
  68616. .followedBy (transform);
  68617. return type;
  68618. }
  68619. }
  68620. if (fill.equalsIgnoreCase (T("none")))
  68621. return Colours::transparentBlack;
  68622. int i = 0;
  68623. const Colour colour (parseColour (fill, i, defaultColour));
  68624. return colour.withMultipliedAlpha (opacity);
  68625. }
  68626. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68627. {
  68628. const String width (getStyleAttribute (xml, T("stroke-width")));
  68629. const String cap (getStyleAttribute (xml, T("stroke-linecap")));
  68630. const String join (getStyleAttribute (xml, T("stroke-linejoin")));
  68631. //const String mitreLimit (getStyleAttribute (xml, T("stroke-miterlimit")));
  68632. //const String dashArray (getStyleAttribute (xml, T("stroke-dasharray")));
  68633. //const String dashOffset (getStyleAttribute (xml, T("stroke-dashoffset")));
  68634. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68635. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68636. if (join.equalsIgnoreCase (T("round")))
  68637. joinStyle = PathStrokeType::curved;
  68638. else if (join.equalsIgnoreCase (T("bevel")))
  68639. joinStyle = PathStrokeType::beveled;
  68640. if (cap.equalsIgnoreCase (T("round")))
  68641. capStyle = PathStrokeType::rounded;
  68642. else if (cap.equalsIgnoreCase (T("square")))
  68643. capStyle = PathStrokeType::square;
  68644. float ox = 0.0f, oy = 0.0f;
  68645. transform.transformPoint (ox, oy);
  68646. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68647. transform.transformPoint (x, y);
  68648. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68649. joinStyle, capStyle);
  68650. }
  68651. Drawable* parseText (const XmlElement& xml)
  68652. {
  68653. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68654. getCoordList (xCoords, getInheritedAttribute (&xml, T("x")), true, true);
  68655. getCoordList (yCoords, getInheritedAttribute (&xml, T("y")), true, false);
  68656. getCoordList (dxCoords, getInheritedAttribute (&xml, T("dx")), true, true);
  68657. getCoordList (dyCoords, getInheritedAttribute (&xml, T("dy")), true, false);
  68658. //xxx not done text yet!
  68659. forEachXmlChildElement (xml, e)
  68660. {
  68661. if (e->isTextElement())
  68662. {
  68663. const String text (e->getText());
  68664. Path path;
  68665. Drawable* s = parseShape (*e, path);
  68666. delete s;
  68667. }
  68668. else if (e->hasTagName (T("tspan")))
  68669. {
  68670. Drawable* s = parseText (*e);
  68671. delete s;
  68672. }
  68673. }
  68674. return 0;
  68675. }
  68676. void addTransform (const XmlElement& xml)
  68677. {
  68678. transform = parseTransform (xml.getStringAttribute (T("transform")))
  68679. .followedBy (transform);
  68680. }
  68681. bool parseCoord (const String& s, float& value, int& index,
  68682. const bool allowUnits, const bool isX) const
  68683. {
  68684. String number;
  68685. if (! parseNextNumber (s, number, index, allowUnits))
  68686. {
  68687. value = 0;
  68688. return false;
  68689. }
  68690. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68691. return true;
  68692. }
  68693. bool parseCoords (const String& s, float& x, float& y,
  68694. int& index, const bool allowUnits) const
  68695. {
  68696. return parseCoord (s, x, index, allowUnits, true)
  68697. && parseCoord (s, y, index, allowUnits, false);
  68698. }
  68699. float getCoordLength (const String& s, const float sizeForProportions) const
  68700. {
  68701. float n = s.getFloatValue();
  68702. const int len = s.length();
  68703. if (len > 2)
  68704. {
  68705. const float dpi = 96.0f;
  68706. const tchar n1 = s [len - 2];
  68707. const tchar n2 = s [len - 1];
  68708. if (n1 == T('i') && n2 == T('n'))
  68709. n *= dpi;
  68710. else if (n1 == T('m') && n2 == T('m'))
  68711. n *= dpi / 25.4f;
  68712. else if (n1 == T('c') && n2 == T('m'))
  68713. n *= dpi / 2.54f;
  68714. else if (n1 == T('p') && n2 == T('c'))
  68715. n *= 15.0f;
  68716. else if (n2 == T('%'))
  68717. n *= 0.01f * sizeForProportions;
  68718. }
  68719. return n;
  68720. }
  68721. void getCoordList (Array <float>& coords, const String& list,
  68722. const bool allowUnits, const bool isX) const
  68723. {
  68724. int index = 0;
  68725. float value;
  68726. while (parseCoord (list, value, index, allowUnits, isX))
  68727. coords.add (value);
  68728. }
  68729. void parseCSSStyle (const XmlElement& xml)
  68730. {
  68731. cssStyleText = xml.getAllSubText() + T("\n") + cssStyleText;
  68732. }
  68733. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68734. const String& defaultValue = String::empty) const
  68735. {
  68736. if (xml->hasAttribute (attributeName))
  68737. return xml->getStringAttribute (attributeName, defaultValue);
  68738. const String styleAtt (xml->getStringAttribute (T("style")));
  68739. if (styleAtt.isNotEmpty())
  68740. {
  68741. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68742. if (value.isNotEmpty())
  68743. return value;
  68744. }
  68745. else if (xml->hasAttribute (T("class")))
  68746. {
  68747. const String className (T(".") + xml->getStringAttribute (T("class")));
  68748. int index = cssStyleText.indexOfIgnoreCase (className + T(" "));
  68749. if (index < 0)
  68750. index = cssStyleText.indexOfIgnoreCase (className + T("{"));
  68751. if (index >= 0)
  68752. {
  68753. const int openBracket = cssStyleText.indexOfChar (index, T('{'));
  68754. if (openBracket > index)
  68755. {
  68756. const int closeBracket = cssStyleText.indexOfChar (openBracket, T('}'));
  68757. if (closeBracket > openBracket)
  68758. {
  68759. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68760. if (value.isNotEmpty())
  68761. return value;
  68762. }
  68763. }
  68764. }
  68765. }
  68766. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68767. if (xml != 0)
  68768. return getStyleAttribute (xml, attributeName, defaultValue);
  68769. return defaultValue;
  68770. }
  68771. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68772. {
  68773. if (xml->hasAttribute (attributeName))
  68774. return xml->getStringAttribute (attributeName);
  68775. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68776. if (xml != 0)
  68777. return getInheritedAttribute (xml, attributeName);
  68778. return String::empty;
  68779. }
  68780. static bool isIdentifierChar (const tchar c)
  68781. {
  68782. return CharacterFunctions::isLetter (c) || c == T('-');
  68783. }
  68784. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68785. {
  68786. int i = 0;
  68787. for (;;)
  68788. {
  68789. i = list.indexOf (i, attributeName);
  68790. if (i < 0)
  68791. break;
  68792. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68793. && ! isIdentifierChar (list [i + attributeName.length()]))
  68794. {
  68795. i = list.indexOfChar (i, T(':'));
  68796. if (i < 0)
  68797. break;
  68798. int end = list.indexOfChar (i, T(';'));
  68799. if (end < 0)
  68800. end = 0x7ffff;
  68801. return list.substring (i + 1, end).trim();
  68802. }
  68803. ++i;
  68804. }
  68805. return defaultValue;
  68806. }
  68807. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68808. {
  68809. const tchar* const s = (const tchar*) source;
  68810. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68811. ++index;
  68812. int start = index;
  68813. if (CharacterFunctions::isDigit (s[index]) || s[index] == T('.') || s[index] == T('-'))
  68814. ++index;
  68815. while (CharacterFunctions::isDigit (s[index]) || s[index] == T('.'))
  68816. ++index;
  68817. if ((s[index] == T('e') || s[index] == T('E'))
  68818. && (CharacterFunctions::isDigit (s[index + 1])
  68819. || s[index + 1] == T('-')
  68820. || s[index + 1] == T('+')))
  68821. {
  68822. index += 2;
  68823. while (CharacterFunctions::isDigit (s[index]))
  68824. ++index;
  68825. }
  68826. if (allowUnits)
  68827. {
  68828. while (CharacterFunctions::isLetter (s[index]))
  68829. ++index;
  68830. }
  68831. if (index == start)
  68832. return false;
  68833. value = String (s + start, index - start);
  68834. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68835. ++index;
  68836. return true;
  68837. }
  68838. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68839. {
  68840. if (s [index] == T('#'))
  68841. {
  68842. uint32 hex [6];
  68843. zeromem (hex, sizeof (hex));
  68844. int numChars = 0;
  68845. for (int i = 6; --i >= 0;)
  68846. {
  68847. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68848. if (hexValue >= 0)
  68849. hex [numChars++] = hexValue;
  68850. else
  68851. break;
  68852. }
  68853. if (numChars <= 3)
  68854. return Colour ((uint8) (hex [0] * 0x11),
  68855. (uint8) (hex [1] * 0x11),
  68856. (uint8) (hex [2] * 0x11));
  68857. else
  68858. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68859. (uint8) ((hex [2] << 4) + hex [3]),
  68860. (uint8) ((hex [4] << 4) + hex [5]));
  68861. }
  68862. else if (s [index] == T('r')
  68863. && s [index + 1] == T('g')
  68864. && s [index + 2] == T('b'))
  68865. {
  68866. const int openBracket = s.indexOfChar (index, T('('));
  68867. const int closeBracket = s.indexOfChar (openBracket, T(')'));
  68868. if (openBracket >= 3 && closeBracket > openBracket)
  68869. {
  68870. index = closeBracket;
  68871. StringArray tokens;
  68872. tokens.addTokens (s.substring (openBracket + 1, closeBracket), T(","), T(""));
  68873. tokens.trim();
  68874. tokens.removeEmptyStrings();
  68875. if (tokens[0].containsChar (T('%')))
  68876. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68877. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68878. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68879. else
  68880. return Colour ((uint8) tokens[0].getIntValue(),
  68881. (uint8) tokens[1].getIntValue(),
  68882. (uint8) tokens[2].getIntValue());
  68883. }
  68884. }
  68885. return Colours::findColourForName (s, defaultColour);
  68886. }
  68887. static const AffineTransform parseTransform (String t)
  68888. {
  68889. AffineTransform result;
  68890. while (t.isNotEmpty())
  68891. {
  68892. StringArray tokens;
  68893. tokens.addTokens (t.fromFirstOccurrenceOf (T("("), false, false)
  68894. .upToFirstOccurrenceOf (T(")"), false, false),
  68895. T(", "), 0);
  68896. tokens.removeEmptyStrings (true);
  68897. float numbers [6];
  68898. for (int i = 0; i < 6; ++i)
  68899. numbers[i] = tokens[i].getFloatValue();
  68900. AffineTransform trans;
  68901. if (t.startsWithIgnoreCase (T("matrix")))
  68902. {
  68903. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68904. numbers[1], numbers[3], numbers[5]);
  68905. }
  68906. else if (t.startsWithIgnoreCase (T("translate")))
  68907. {
  68908. trans = trans.translated (numbers[0], numbers[1]);
  68909. }
  68910. else if (t.startsWithIgnoreCase (T("scale")))
  68911. {
  68912. if (tokens.size() == 1)
  68913. trans = trans.scaled (numbers[0], numbers[0]);
  68914. else
  68915. trans = trans.scaled (numbers[0], numbers[1]);
  68916. }
  68917. else if (t.startsWithIgnoreCase (T("rotate")))
  68918. {
  68919. if (tokens.size() != 3)
  68920. trans = trans.rotated (numbers[0] / (180.0f / float_Pi));
  68921. else
  68922. trans = trans.rotated (numbers[0] / (180.0f / float_Pi),
  68923. numbers[1], numbers[2]);
  68924. }
  68925. else if (t.startsWithIgnoreCase (T("skewX")))
  68926. {
  68927. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68928. 0.0f, 1.0f, 0.0f);
  68929. }
  68930. else if (t.startsWithIgnoreCase (T("skewY")))
  68931. {
  68932. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68933. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68934. }
  68935. result = trans.followedBy (result);
  68936. t = t.fromFirstOccurrenceOf (T(")"), false, false).trimStart();
  68937. }
  68938. return result;
  68939. }
  68940. static void endpointToCentreParameters (const double x1, const double y1,
  68941. const double x2, const double y2,
  68942. const double angle,
  68943. const bool largeArc, const bool sweep,
  68944. double& rx, double& ry,
  68945. double& centreX, double& centreY,
  68946. double& startAngle, double& deltaAngle)
  68947. {
  68948. const double midX = (x1 - x2) * 0.5;
  68949. const double midY = (y1 - y2) * 0.5;
  68950. const double cosAngle = cos (angle);
  68951. const double sinAngle = sin (angle);
  68952. const double xp = cosAngle * midX + sinAngle * midY;
  68953. const double yp = cosAngle * midY - sinAngle * midX;
  68954. const double xp2 = xp * xp;
  68955. const double yp2 = yp * yp;
  68956. double rx2 = rx * rx;
  68957. double ry2 = ry * ry;
  68958. const double s = (xp2 / rx2) + (yp2 / ry2);
  68959. double c;
  68960. if (s <= 1.0)
  68961. {
  68962. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68963. / (( rx2 * yp2) + (ry2 * xp2))));
  68964. if (largeArc == sweep)
  68965. c = -c;
  68966. }
  68967. else
  68968. {
  68969. const double s2 = sqrt (s);
  68970. rx *= s2;
  68971. ry *= s2;
  68972. rx2 = rx * rx;
  68973. ry2 = ry * ry;
  68974. c = 0;
  68975. }
  68976. const double cpx = ((rx * yp) / ry) * c;
  68977. const double cpy = ((-ry * xp) / rx) * c;
  68978. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68979. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68980. const double ux = (xp - cpx) / rx;
  68981. const double uy = (yp - cpy) / ry;
  68982. const double vx = (-xp - cpx) / rx;
  68983. const double vy = (-yp - cpy) / ry;
  68984. const double length = juce_hypot (ux, uy);
  68985. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68986. if (uy < 0)
  68987. startAngle = -startAngle;
  68988. startAngle += double_Pi * 0.5;
  68989. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68990. / (length * juce_hypot (vx, vy))));
  68991. if ((ux * vy) - (uy * vx) < 0)
  68992. deltaAngle = -deltaAngle;
  68993. if (sweep)
  68994. {
  68995. if (deltaAngle < 0)
  68996. deltaAngle += double_Pi * 2.0;
  68997. }
  68998. else
  68999. {
  69000. if (deltaAngle > 0)
  69001. deltaAngle -= double_Pi * 2.0;
  69002. }
  69003. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  69004. }
  69005. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  69006. {
  69007. forEachXmlChildElement (*parent, e)
  69008. {
  69009. if (e->compareAttribute (T("id"), id))
  69010. return e;
  69011. const XmlElement* const found = findElementForId (e, id);
  69012. if (found != 0)
  69013. return found;
  69014. }
  69015. return 0;
  69016. }
  69017. const SVGState& operator= (const SVGState&);
  69018. };
  69019. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  69020. {
  69021. SVGState state (&svgDocument);
  69022. return state.parseSVGElement (svgDocument);
  69023. }
  69024. END_JUCE_NAMESPACE
  69025. /*** End of inlined file: juce_SVGParser.cpp ***/
  69026. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  69027. BEGIN_JUCE_NAMESPACE
  69028. #if JUCE_MSVC
  69029. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  69030. #endif
  69031. DropShadowEffect::DropShadowEffect()
  69032. : offsetX (0),
  69033. offsetY (0),
  69034. radius (4),
  69035. opacity (0.6f)
  69036. {
  69037. }
  69038. DropShadowEffect::~DropShadowEffect()
  69039. {
  69040. }
  69041. void DropShadowEffect::setShadowProperties (const float newRadius,
  69042. const float newOpacity,
  69043. const int newShadowOffsetX,
  69044. const int newShadowOffsetY)
  69045. {
  69046. radius = jmax (1.1f, newRadius);
  69047. offsetX = newShadowOffsetX;
  69048. offsetY = newShadowOffsetY;
  69049. opacity = newOpacity;
  69050. }
  69051. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  69052. {
  69053. const int w = image.getWidth();
  69054. const int h = image.getHeight();
  69055. Image shadowImage (Image::SingleChannel, w, h, false);
  69056. const Image::BitmapData srcData (image, 0, 0, w, h);
  69057. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  69058. const int filter = roundToInt (63.0f / radius);
  69059. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  69060. for (int x = w; --x >= 0;)
  69061. {
  69062. int shadowAlpha = 0;
  69063. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  69064. uint8* shadowPix = destData.data + x;
  69065. for (int y = h; --y >= 0;)
  69066. {
  69067. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  69068. *shadowPix = (uint8) shadowAlpha;
  69069. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  69070. shadowPix += destData.lineStride;
  69071. }
  69072. }
  69073. for (int y = h; --y >= 0;)
  69074. {
  69075. int shadowAlpha = 0;
  69076. uint8* shadowPix = destData.getLinePointer (y);
  69077. for (int x = w; --x >= 0;)
  69078. {
  69079. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  69080. *shadowPix++ = (uint8) shadowAlpha;
  69081. }
  69082. }
  69083. g.setColour (Colours::black.withAlpha (opacity));
  69084. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  69085. g.setOpacity (1.0f);
  69086. g.drawImageAt (&image, 0, 0);
  69087. }
  69088. END_JUCE_NAMESPACE
  69089. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  69090. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  69091. BEGIN_JUCE_NAMESPACE
  69092. GlowEffect::GlowEffect()
  69093. : radius (2.0f),
  69094. colour (Colours::white)
  69095. {
  69096. }
  69097. GlowEffect::~GlowEffect()
  69098. {
  69099. }
  69100. void GlowEffect::setGlowProperties (const float newRadius,
  69101. const Colour& newColour)
  69102. {
  69103. radius = newRadius;
  69104. colour = newColour;
  69105. }
  69106. void GlowEffect::applyEffect (Image& image, Graphics& g)
  69107. {
  69108. const int w = image.getWidth();
  69109. const int h = image.getHeight();
  69110. Image temp (image.getFormat(), w, h, true);
  69111. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  69112. blurKernel.createGaussianBlur (radius);
  69113. blurKernel.rescaleAllValues (radius);
  69114. blurKernel.applyToImage (temp, &image, 0, 0, w, h);
  69115. g.setColour (colour);
  69116. g.drawImageAt (&temp, 0, 0, true);
  69117. g.setOpacity (1.0f);
  69118. g.drawImageAt (&image, 0, 0, false);
  69119. }
  69120. END_JUCE_NAMESPACE
  69121. /*** End of inlined file: juce_GlowEffect.cpp ***/
  69122. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  69123. BEGIN_JUCE_NAMESPACE
  69124. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  69125. : opacity (opacity_)
  69126. {
  69127. }
  69128. ReduceOpacityEffect::~ReduceOpacityEffect()
  69129. {
  69130. }
  69131. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  69132. {
  69133. opacity = jlimit (0.0f, 1.0f, newOpacity);
  69134. }
  69135. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  69136. {
  69137. g.setOpacity (opacity);
  69138. g.drawImageAt (&image, 0, 0);
  69139. }
  69140. END_JUCE_NAMESPACE
  69141. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  69142. /*** Start of inlined file: juce_Font.cpp ***/
  69143. BEGIN_JUCE_NAMESPACE
  69144. static const float minFontHeight = 0.1f;
  69145. static const float maxFontHeight = 10000.0f;
  69146. static const float defaultFontHeight = 14.0f;
  69147. static const tchar* const juce_defaultFontNameSans = T("<Sans-Serif>");
  69148. static const tchar* const juce_defaultFontNameSerif = T("<Serif>");
  69149. static const tchar* const juce_defaultFontNameMono = T("<Monospaced>");
  69150. void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp
  69151. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  69152. const float kerning_, const float ascent_, const int styleFlags_,
  69153. Typeface* const typeface_) throw()
  69154. : typefaceName (typefaceName_),
  69155. height (height_),
  69156. horizontalScale (horizontalScale_),
  69157. kerning (kerning_),
  69158. ascent (ascent_),
  69159. styleFlags (styleFlags_),
  69160. typeface (typeface_)
  69161. {
  69162. }
  69163. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  69164. : typefaceName (other.typefaceName),
  69165. height (other.height),
  69166. horizontalScale (other.horizontalScale),
  69167. kerning (other.kerning),
  69168. ascent (other.ascent),
  69169. styleFlags (other.styleFlags),
  69170. typeface (other.typeface)
  69171. {
  69172. }
  69173. Font::Font() throw()
  69174. : font (new SharedFontInternal (juce_defaultFontNameSans, defaultFontHeight,
  69175. 1.0f, 0, 0, Font::plain, 0))
  69176. {
  69177. }
  69178. Font::Font (const float fontHeight, const int styleFlags_) throw()
  69179. : font (new SharedFontInternal (juce_defaultFontNameSans, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69180. 1.0f, 0, 0, styleFlags_, 0))
  69181. {
  69182. }
  69183. Font::Font (const String& typefaceName_,
  69184. const float fontHeight,
  69185. const int styleFlags_) throw()
  69186. : font (new SharedFontInternal (typefaceName_, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69187. 1.0f, 0, 0, styleFlags_, 0))
  69188. {
  69189. }
  69190. Font::Font (const Font& other) throw()
  69191. : font (other.font)
  69192. {
  69193. }
  69194. const Font& Font::operator= (const Font& other) throw()
  69195. {
  69196. font = other.font;
  69197. return *this;
  69198. }
  69199. Font::~Font() throw()
  69200. {
  69201. }
  69202. Font::Font (const Typeface::Ptr& typeface) throw()
  69203. : font (new SharedFontInternal (typeface->getName(), defaultFontHeight,
  69204. 1.0f, 0, 0, Font::plain, typeface))
  69205. {
  69206. }
  69207. bool Font::operator== (const Font& other) const throw()
  69208. {
  69209. return font == other.font
  69210. || (font->height == other.font->height
  69211. && font->styleFlags == other.font->styleFlags
  69212. && font->horizontalScale == other.font->horizontalScale
  69213. && font->kerning == other.font->kerning
  69214. && font->typefaceName == other.font->typefaceName);
  69215. }
  69216. bool Font::operator!= (const Font& other) const throw()
  69217. {
  69218. return ! operator== (other);
  69219. }
  69220. void Font::dupeInternalIfShared() throw()
  69221. {
  69222. if (font->getReferenceCount() > 1)
  69223. font = new SharedFontInternal (*font);
  69224. }
  69225. const String Font::getDefaultSansSerifFontName() throw()
  69226. {
  69227. return juce_defaultFontNameSans;
  69228. }
  69229. const String Font::getDefaultSerifFontName() throw()
  69230. {
  69231. return juce_defaultFontNameSerif;
  69232. }
  69233. const String Font::getDefaultMonospacedFontName() throw()
  69234. {
  69235. return juce_defaultFontNameMono;
  69236. }
  69237. void Font::setTypefaceName (const String& faceName) throw()
  69238. {
  69239. if (faceName != font->typefaceName)
  69240. {
  69241. dupeInternalIfShared();
  69242. font->typefaceName = faceName;
  69243. font->typeface = 0;
  69244. font->ascent = 0;
  69245. }
  69246. }
  69247. static String fallbackFont;
  69248. const String Font::getFallbackFontName() throw()
  69249. {
  69250. return fallbackFont;
  69251. }
  69252. void Font::setFallbackFontName (const String& name) throw()
  69253. {
  69254. fallbackFont = name;
  69255. }
  69256. void Font::setHeight (float newHeight) throw()
  69257. {
  69258. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69259. if (font->height != newHeight)
  69260. {
  69261. dupeInternalIfShared();
  69262. font->height = newHeight;
  69263. }
  69264. }
  69265. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  69266. {
  69267. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69268. if (font->height != newHeight)
  69269. {
  69270. dupeInternalIfShared();
  69271. font->horizontalScale *= (font->height / newHeight);
  69272. font->height = newHeight;
  69273. }
  69274. }
  69275. void Font::setStyleFlags (const int newFlags) throw()
  69276. {
  69277. if (font->styleFlags != newFlags)
  69278. {
  69279. dupeInternalIfShared();
  69280. font->styleFlags = newFlags;
  69281. font->typeface = 0;
  69282. font->ascent = 0;
  69283. }
  69284. }
  69285. void Font::setSizeAndStyle (float newHeight,
  69286. const int newStyleFlags,
  69287. const float newHorizontalScale,
  69288. const float newKerningAmount) throw()
  69289. {
  69290. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69291. if (font->height != newHeight
  69292. || font->horizontalScale != newHorizontalScale
  69293. || font->kerning != newKerningAmount)
  69294. {
  69295. dupeInternalIfShared();
  69296. font->height = newHeight;
  69297. font->horizontalScale = newHorizontalScale;
  69298. font->kerning = newKerningAmount;
  69299. }
  69300. setStyleFlags (newStyleFlags);
  69301. }
  69302. void Font::setHorizontalScale (const float scaleFactor) throw()
  69303. {
  69304. dupeInternalIfShared();
  69305. font->horizontalScale = scaleFactor;
  69306. }
  69307. void Font::setExtraKerningFactor (const float extraKerning) throw()
  69308. {
  69309. dupeInternalIfShared();
  69310. font->kerning = extraKerning;
  69311. }
  69312. void Font::setBold (const bool shouldBeBold) throw()
  69313. {
  69314. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  69315. : (font->styleFlags & ~bold));
  69316. }
  69317. bool Font::isBold() const throw()
  69318. {
  69319. return (font->styleFlags & bold) != 0;
  69320. }
  69321. void Font::setItalic (const bool shouldBeItalic) throw()
  69322. {
  69323. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  69324. : (font->styleFlags & ~italic));
  69325. }
  69326. bool Font::isItalic() const throw()
  69327. {
  69328. return (font->styleFlags & italic) != 0;
  69329. }
  69330. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  69331. {
  69332. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  69333. : (font->styleFlags & ~underlined));
  69334. }
  69335. bool Font::isUnderlined() const throw()
  69336. {
  69337. return (font->styleFlags & underlined) != 0;
  69338. }
  69339. float Font::getAscent() const throw()
  69340. {
  69341. if (font->ascent == 0)
  69342. font->ascent = getTypeface()->getAscent();
  69343. return font->height * font->ascent;
  69344. }
  69345. float Font::getDescent() const throw()
  69346. {
  69347. return font->height - getAscent();
  69348. }
  69349. int Font::getStringWidth (const String& text) const throw()
  69350. {
  69351. return roundToInt (getStringWidthFloat (text));
  69352. }
  69353. float Font::getStringWidthFloat (const String& text) const throw()
  69354. {
  69355. float w = getTypeface()->getStringWidth (text);
  69356. if (font->kerning != 0)
  69357. w += font->kerning * text.length();
  69358. return w * font->height * font->horizontalScale;
  69359. }
  69360. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  69361. {
  69362. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  69363. const float scale = font->height * font->horizontalScale;
  69364. const int num = xOffsets.size();
  69365. if (num > 0)
  69366. {
  69367. float* const x = &(xOffsets.getReference(0));
  69368. if (font->kerning != 0)
  69369. {
  69370. for (int i = 0; i < num; ++i)
  69371. x[i] = (x[i] + i * font->kerning) * scale;
  69372. }
  69373. else
  69374. {
  69375. for (int i = 0; i < num; ++i)
  69376. x[i] *= scale;
  69377. }
  69378. }
  69379. }
  69380. void Font::findFonts (Array<Font>& destArray) throw()
  69381. {
  69382. const StringArray names (findAllTypefaceNames());
  69383. for (int i = 0; i < names.size(); ++i)
  69384. destArray.add (Font (names[i], defaultFontHeight, Font::plain));
  69385. }
  69386. class TypefaceCache : public DeletedAtShutdown
  69387. {
  69388. public:
  69389. TypefaceCache (int numToCache = 10) throw()
  69390. : counter (1)
  69391. {
  69392. while (--numToCache >= 0)
  69393. faces.add (new CachedFace());
  69394. }
  69395. ~TypefaceCache()
  69396. {
  69397. clearUpDefaultFontNames();
  69398. clearSingletonInstance();
  69399. }
  69400. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  69401. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  69402. {
  69403. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  69404. const String faceName (font.getTypefaceName());
  69405. int i;
  69406. for (i = faces.size(); --i >= 0;)
  69407. {
  69408. CachedFace* const face = faces.getUnchecked(i);
  69409. if (face->flags == flags
  69410. && face->typefaceName == faceName)
  69411. {
  69412. face->lastUsageCount = ++counter;
  69413. return face->typeFace;
  69414. }
  69415. }
  69416. int replaceIndex = 0;
  69417. int bestLastUsageCount = std::numeric_limits<int>::max();
  69418. for (i = faces.size(); --i >= 0;)
  69419. {
  69420. const int lu = faces.getUnchecked(i)->lastUsageCount;
  69421. if (bestLastUsageCount > lu)
  69422. {
  69423. bestLastUsageCount = lu;
  69424. replaceIndex = i;
  69425. }
  69426. }
  69427. CachedFace* const face = faces.getUnchecked (replaceIndex);
  69428. face->typefaceName = faceName;
  69429. face->flags = flags;
  69430. face->lastUsageCount = ++counter;
  69431. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  69432. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  69433. return face->typeFace;
  69434. }
  69435. juce_UseDebuggingNewOperator
  69436. private:
  69437. struct CachedFace
  69438. {
  69439. CachedFace() throw()
  69440. : lastUsageCount (0), flags (-1)
  69441. {
  69442. }
  69443. String typefaceName;
  69444. int lastUsageCount;
  69445. int flags;
  69446. Typeface::Ptr typeFace;
  69447. };
  69448. int counter;
  69449. OwnedArray <CachedFace> faces;
  69450. TypefaceCache (const TypefaceCache&);
  69451. const TypefaceCache& operator= (const TypefaceCache&);
  69452. };
  69453. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  69454. Typeface* Font::getTypeface() const throw()
  69455. {
  69456. if (font->typeface == 0)
  69457. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  69458. return font->typeface;
  69459. }
  69460. END_JUCE_NAMESPACE
  69461. /*** End of inlined file: juce_Font.cpp ***/
  69462. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  69463. BEGIN_JUCE_NAMESPACE
  69464. PositionedGlyph::PositionedGlyph()
  69465. {
  69466. }
  69467. void PositionedGlyph::draw (const Graphics& g) const
  69468. {
  69469. if (! isWhitespace())
  69470. {
  69471. g.getInternalContext()->setFont (font);
  69472. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  69473. }
  69474. }
  69475. void PositionedGlyph::draw (const Graphics& g,
  69476. const AffineTransform& transform) const
  69477. {
  69478. if (! isWhitespace())
  69479. {
  69480. g.getInternalContext()->setFont (font);
  69481. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  69482. .followedBy (transform));
  69483. }
  69484. }
  69485. void PositionedGlyph::createPath (Path& path) const
  69486. {
  69487. if (! isWhitespace())
  69488. {
  69489. Typeface* const t = font.getTypeface();
  69490. if (t != 0)
  69491. {
  69492. Path p;
  69493. t->getOutlineForGlyph (glyph, p);
  69494. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  69495. .translated (x, y));
  69496. }
  69497. }
  69498. }
  69499. bool PositionedGlyph::hitTest (float px, float py) const
  69500. {
  69501. if (px >= getLeft() && px < getRight()
  69502. && py >= getTop() && py < getBottom()
  69503. && ! isWhitespace())
  69504. {
  69505. Typeface* const t = font.getTypeface();
  69506. if (t != 0)
  69507. {
  69508. Path p;
  69509. t->getOutlineForGlyph (glyph, p);
  69510. AffineTransform::translation (-x, -y)
  69511. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  69512. .transformPoint (px, py);
  69513. return p.contains (px, py);
  69514. }
  69515. }
  69516. return false;
  69517. }
  69518. void PositionedGlyph::moveBy (const float deltaX,
  69519. const float deltaY)
  69520. {
  69521. x += deltaX;
  69522. y += deltaY;
  69523. }
  69524. GlyphArrangement::GlyphArrangement()
  69525. {
  69526. glyphs.ensureStorageAllocated (128);
  69527. }
  69528. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69529. {
  69530. addGlyphArrangement (other);
  69531. }
  69532. const GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69533. {
  69534. if (this != &other)
  69535. {
  69536. clear();
  69537. addGlyphArrangement (other);
  69538. }
  69539. return *this;
  69540. }
  69541. GlyphArrangement::~GlyphArrangement()
  69542. {
  69543. }
  69544. void GlyphArrangement::clear()
  69545. {
  69546. glyphs.clear();
  69547. }
  69548. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69549. {
  69550. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69551. return *glyphs [index];
  69552. }
  69553. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69554. {
  69555. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69556. for (int i = 0; i < other.glyphs.size(); ++i)
  69557. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69558. }
  69559. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69560. {
  69561. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69562. }
  69563. void GlyphArrangement::addLineOfText (const Font& font,
  69564. const String& text,
  69565. const float xOffset,
  69566. const float yOffset)
  69567. {
  69568. addCurtailedLineOfText (font, text,
  69569. xOffset, yOffset,
  69570. 1.0e10f, false);
  69571. }
  69572. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69573. const String& text,
  69574. float xOffset,
  69575. const float yOffset,
  69576. const float maxWidthPixels,
  69577. const bool useEllipsis)
  69578. {
  69579. int textLen = text.length();
  69580. if (textLen > 0)
  69581. {
  69582. Array <int> newGlyphs;
  69583. Array <float> xOffsets;
  69584. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69585. const juce_wchar* const unicodeText = (const juce_wchar*) text;
  69586. textLen = jmin (textLen, newGlyphs.size());
  69587. for (int i = 0; i < textLen; ++i)
  69588. {
  69589. const float thisX = xOffsets.getUnchecked (i);
  69590. const float nextX = xOffsets.getUnchecked (i + 1);
  69591. if (nextX > maxWidthPixels + 1.0f)
  69592. {
  69593. // curtail the string if it's too wide..
  69594. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69595. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69596. break;
  69597. }
  69598. else
  69599. {
  69600. PositionedGlyph* const pg = new PositionedGlyph();
  69601. pg->x = xOffset + thisX;
  69602. pg->y = yOffset;
  69603. pg->w = nextX - thisX;
  69604. pg->font = font;
  69605. pg->glyph = newGlyphs.getUnchecked(i);
  69606. pg->character = unicodeText[i];
  69607. glyphs.add (pg);
  69608. }
  69609. }
  69610. }
  69611. }
  69612. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69613. const int startIndex, int endIndex)
  69614. {
  69615. int numDeleted = 0;
  69616. if (glyphs.size() > 0)
  69617. {
  69618. Array<int> dotGlyphs;
  69619. Array<float> dotXs;
  69620. font.getGlyphPositions (T(".."), dotGlyphs, dotXs);
  69621. const float dx = dotXs[1];
  69622. float xOffset = 0.0f, yOffset = 0.0f;
  69623. while (endIndex > startIndex)
  69624. {
  69625. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69626. xOffset = pg->x;
  69627. yOffset = pg->y;
  69628. glyphs.remove (endIndex);
  69629. ++numDeleted;
  69630. if (xOffset + dx * 3 <= maxXPos)
  69631. break;
  69632. }
  69633. for (int i = 3; --i >= 0;)
  69634. {
  69635. PositionedGlyph* const pg = new PositionedGlyph();
  69636. pg->x = xOffset;
  69637. pg->y = yOffset;
  69638. pg->w = dx;
  69639. pg->font = font;
  69640. pg->character = '.';
  69641. pg->glyph = dotGlyphs.getFirst();
  69642. glyphs.insert (endIndex++, pg);
  69643. --numDeleted;
  69644. xOffset += dx;
  69645. if (xOffset > maxXPos)
  69646. break;
  69647. }
  69648. }
  69649. return numDeleted;
  69650. }
  69651. void GlyphArrangement::addJustifiedText (const Font& font,
  69652. const String& text,
  69653. float x, float y,
  69654. const float maxLineWidth,
  69655. const Justification& horizontalLayout)
  69656. {
  69657. int lineStartIndex = glyphs.size();
  69658. addLineOfText (font, text, x, y);
  69659. const float originalY = y;
  69660. while (lineStartIndex < glyphs.size())
  69661. {
  69662. int i = lineStartIndex;
  69663. if (glyphs.getUnchecked(i)->getCharacter() != T('\n')
  69664. && glyphs.getUnchecked(i)->getCharacter() != T('\r'))
  69665. ++i;
  69666. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69667. int lastWordBreakIndex = -1;
  69668. while (i < glyphs.size())
  69669. {
  69670. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69671. const juce_wchar c = pg->getCharacter();
  69672. if (c == T('\r') || c == T('\n'))
  69673. {
  69674. ++i;
  69675. if (c == T('\r') && i < glyphs.size()
  69676. && glyphs.getUnchecked(i)->getCharacter() == T('\n'))
  69677. ++i;
  69678. break;
  69679. }
  69680. else if (pg->isWhitespace())
  69681. {
  69682. lastWordBreakIndex = i + 1;
  69683. }
  69684. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69685. {
  69686. if (lastWordBreakIndex >= 0)
  69687. i = lastWordBreakIndex;
  69688. break;
  69689. }
  69690. ++i;
  69691. }
  69692. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69693. float currentLineEndX = currentLineStartX;
  69694. for (int j = i; --j >= lineStartIndex;)
  69695. {
  69696. if (! glyphs.getUnchecked (j)->isWhitespace())
  69697. {
  69698. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69699. break;
  69700. }
  69701. }
  69702. float deltaX = 0.0f;
  69703. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69704. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69705. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69706. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69707. else if (horizontalLayout.testFlags (Justification::right))
  69708. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69709. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69710. x + deltaX - currentLineStartX, y - originalY);
  69711. lineStartIndex = i;
  69712. y += font.getHeight();
  69713. }
  69714. }
  69715. void GlyphArrangement::addFittedText (const Font& f,
  69716. const String& text,
  69717. const float x, const float y,
  69718. const float width, const float height,
  69719. const Justification& layout,
  69720. int maximumLines,
  69721. const float minimumHorizontalScale)
  69722. {
  69723. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69724. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69725. if (text.containsAnyOf (T("\r\n")))
  69726. {
  69727. GlyphArrangement ga;
  69728. ga.addJustifiedText (f, text, x, y, width, layout);
  69729. float l, t, r, b;
  69730. ga.getBoundingBox (0, -1, l, t, r, b, false);
  69731. float dy = y - t;
  69732. if (layout.testFlags (Justification::verticallyCentred))
  69733. dy += (height - (b - t)) * 0.5f;
  69734. else if (layout.testFlags (Justification::bottom))
  69735. dy += height - (b - t);
  69736. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69737. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69738. for (int i = 0; i < ga.glyphs.size(); ++i)
  69739. glyphs.add (ga.glyphs.getUnchecked (i));
  69740. ga.glyphs.clear (false);
  69741. return;
  69742. }
  69743. int startIndex = glyphs.size();
  69744. addLineOfText (f, text.trim(), x, y);
  69745. if (glyphs.size() > startIndex)
  69746. {
  69747. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69748. - glyphs.getUnchecked (startIndex)->getLeft();
  69749. if (lineWidth <= 0)
  69750. return;
  69751. if (lineWidth * minimumHorizontalScale < width)
  69752. {
  69753. if (lineWidth > width)
  69754. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69755. width / lineWidth);
  69756. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69757. x, y, width, height, layout);
  69758. }
  69759. else if (maximumLines <= 1)
  69760. {
  69761. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69762. x, y, width, height, f, layout, minimumHorizontalScale);
  69763. }
  69764. else
  69765. {
  69766. Font font (f);
  69767. String txt (text.trim());
  69768. const int length = txt.length();
  69769. const int originalStartIndex = startIndex;
  69770. int numLines = 1;
  69771. if (length <= 12 && ! txt.containsAnyOf (T(" -\t\r\n")))
  69772. maximumLines = 1;
  69773. maximumLines = jmin (maximumLines, length);
  69774. while (numLines < maximumLines)
  69775. {
  69776. ++numLines;
  69777. const float newFontHeight = height / (float) numLines;
  69778. if (newFontHeight < font.getHeight())
  69779. {
  69780. font.setHeight (jmax (8.0f, newFontHeight));
  69781. removeRangeOfGlyphs (startIndex, -1);
  69782. addLineOfText (font, txt, x, y);
  69783. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69784. - glyphs.getUnchecked (startIndex)->getLeft();
  69785. }
  69786. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69787. break;
  69788. }
  69789. if (numLines < 1)
  69790. numLines = 1;
  69791. float lineY = y;
  69792. float widthPerLine = lineWidth / numLines;
  69793. int lastLineStartIndex = 0;
  69794. for (int line = 0; line < numLines; ++line)
  69795. {
  69796. int i = startIndex;
  69797. lastLineStartIndex = i;
  69798. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69799. if (line == numLines - 1)
  69800. {
  69801. widthPerLine = width;
  69802. i = glyphs.size();
  69803. }
  69804. else
  69805. {
  69806. while (i < glyphs.size())
  69807. {
  69808. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69809. if (lineWidth > widthPerLine)
  69810. {
  69811. // got to a point where the line's too long, so skip forward to find a
  69812. // good place to break it..
  69813. const int searchStartIndex = i;
  69814. while (i < glyphs.size())
  69815. {
  69816. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69817. {
  69818. if (glyphs.getUnchecked (i)->isWhitespace()
  69819. || glyphs.getUnchecked (i)->getCharacter() == T('-'))
  69820. {
  69821. ++i;
  69822. break;
  69823. }
  69824. }
  69825. else
  69826. {
  69827. // can't find a suitable break, so try looking backwards..
  69828. i = searchStartIndex;
  69829. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69830. {
  69831. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69832. || glyphs.getUnchecked (i - back)->getCharacter() == T('-'))
  69833. {
  69834. i -= back - 1;
  69835. break;
  69836. }
  69837. }
  69838. break;
  69839. }
  69840. ++i;
  69841. }
  69842. break;
  69843. }
  69844. ++i;
  69845. }
  69846. int wsStart = i;
  69847. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69848. --wsStart;
  69849. int wsEnd = i;
  69850. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69851. ++wsEnd;
  69852. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69853. i = jmax (wsStart, startIndex + 1);
  69854. }
  69855. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69856. x, lineY, width, font.getHeight(), font,
  69857. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69858. minimumHorizontalScale);
  69859. startIndex = i;
  69860. lineY += font.getHeight();
  69861. if (startIndex >= glyphs.size())
  69862. break;
  69863. }
  69864. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69865. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69866. }
  69867. }
  69868. }
  69869. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69870. const float dx, const float dy)
  69871. {
  69872. jassert (startIndex >= 0);
  69873. if (dx != 0.0f || dy != 0.0f)
  69874. {
  69875. if (num < 0 || startIndex + num > glyphs.size())
  69876. num = glyphs.size() - startIndex;
  69877. while (--num >= 0)
  69878. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69879. }
  69880. }
  69881. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69882. const Justification& justification, float minimumHorizontalScale)
  69883. {
  69884. int numDeleted = 0;
  69885. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69886. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69887. if (lineWidth > w)
  69888. {
  69889. if (minimumHorizontalScale < 1.0f)
  69890. {
  69891. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69892. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69893. }
  69894. if (lineWidth > w)
  69895. {
  69896. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69897. numGlyphs -= numDeleted;
  69898. }
  69899. }
  69900. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69901. return numDeleted;
  69902. }
  69903. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69904. const float horizontalScaleFactor)
  69905. {
  69906. jassert (startIndex >= 0);
  69907. if (num < 0 || startIndex + num > glyphs.size())
  69908. num = glyphs.size() - startIndex;
  69909. if (num > 0)
  69910. {
  69911. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69912. while (--num >= 0)
  69913. {
  69914. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69915. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69916. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69917. pg->w *= horizontalScaleFactor;
  69918. }
  69919. }
  69920. }
  69921. void GlyphArrangement::getBoundingBox (int startIndex, int num,
  69922. float& left,
  69923. float& top,
  69924. float& right,
  69925. float& bottom,
  69926. const bool includeWhitespace) const
  69927. {
  69928. jassert (startIndex >= 0);
  69929. if (num < 0 || startIndex + num > glyphs.size())
  69930. num = glyphs.size() - startIndex;
  69931. left = 0.0f;
  69932. top = 0.0f;
  69933. right = 0.0f;
  69934. bottom = 0.0f;
  69935. bool isFirst = true;
  69936. while (--num >= 0)
  69937. {
  69938. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69939. if (includeWhitespace || ! pg->isWhitespace())
  69940. {
  69941. if (isFirst)
  69942. {
  69943. isFirst = false;
  69944. left = pg->getLeft();
  69945. top = pg->getTop();
  69946. right = pg->getRight();
  69947. bottom = pg->getBottom();
  69948. }
  69949. else
  69950. {
  69951. left = jmin (left, pg->getLeft());
  69952. top = jmin (top, pg->getTop());
  69953. right = jmax (right, pg->getRight());
  69954. bottom = jmax (bottom, pg->getBottom());
  69955. }
  69956. }
  69957. }
  69958. }
  69959. void GlyphArrangement::justifyGlyphs (const int startIndex,
  69960. const int num,
  69961. const float x, const float y,
  69962. const float width, const float height,
  69963. const Justification& justification)
  69964. {
  69965. jassert (num >= 0 && startIndex >= 0);
  69966. if (glyphs.size() > 0 && num > 0)
  69967. {
  69968. float left, top, right, bottom;
  69969. getBoundingBox (startIndex, num, left, top, right, bottom,
  69970. ! justification.testFlags (Justification::horizontallyJustified
  69971. | Justification::horizontallyCentred));
  69972. float deltaX = 0.0f;
  69973. if (justification.testFlags (Justification::horizontallyJustified))
  69974. deltaX = x - left;
  69975. else if (justification.testFlags (Justification::horizontallyCentred))
  69976. deltaX = x + (width - (right - left)) * 0.5f - left;
  69977. else if (justification.testFlags (Justification::right))
  69978. deltaX = (x + width) - right;
  69979. else
  69980. deltaX = x - left;
  69981. float deltaY = 0.0f;
  69982. if (justification.testFlags (Justification::top))
  69983. deltaY = y - top;
  69984. else if (justification.testFlags (Justification::bottom))
  69985. deltaY = (y + height) - bottom;
  69986. else
  69987. deltaY = y + (height - (bottom - top)) * 0.5f - top;
  69988. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69989. if (justification.testFlags (Justification::horizontallyJustified))
  69990. {
  69991. int lineStart = 0;
  69992. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69993. int i;
  69994. for (i = 0; i < num; ++i)
  69995. {
  69996. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69997. if (glyphY != baseY)
  69998. {
  69999. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  70000. lineStart = i;
  70001. baseY = glyphY;
  70002. }
  70003. }
  70004. if (i > lineStart)
  70005. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  70006. }
  70007. }
  70008. }
  70009. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  70010. {
  70011. if (start + num < glyphs.size()
  70012. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\r')
  70013. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\n'))
  70014. {
  70015. int numSpaces = 0;
  70016. int spacesAtEnd = 0;
  70017. for (int i = 0; i < num; ++i)
  70018. {
  70019. if (glyphs.getUnchecked (start + i)->isWhitespace())
  70020. {
  70021. ++spacesAtEnd;
  70022. ++numSpaces;
  70023. }
  70024. else
  70025. {
  70026. spacesAtEnd = 0;
  70027. }
  70028. }
  70029. numSpaces -= spacesAtEnd;
  70030. if (numSpaces > 0)
  70031. {
  70032. const float startX = glyphs.getUnchecked (start)->getLeft();
  70033. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  70034. const float extraPaddingBetweenWords
  70035. = (targetWidth - (endX - startX)) / (float) numSpaces;
  70036. float deltaX = 0.0f;
  70037. for (int i = 0; i < num; ++i)
  70038. {
  70039. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  70040. if (glyphs.getUnchecked (start + i)->isWhitespace())
  70041. deltaX += extraPaddingBetweenWords;
  70042. }
  70043. }
  70044. }
  70045. }
  70046. void GlyphArrangement::draw (const Graphics& g) const
  70047. {
  70048. for (int i = 0; i < glyphs.size(); ++i)
  70049. {
  70050. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  70051. if (pg->font.isUnderlined())
  70052. {
  70053. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  70054. float nextX = pg->x + pg->w;
  70055. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  70056. nextX = glyphs.getUnchecked (i + 1)->x;
  70057. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  70058. nextX - pg->x, lineThickness);
  70059. }
  70060. pg->draw (g);
  70061. }
  70062. }
  70063. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  70064. {
  70065. for (int i = 0; i < glyphs.size(); ++i)
  70066. {
  70067. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  70068. if (pg->font.isUnderlined())
  70069. {
  70070. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  70071. float nextX = pg->x + pg->w;
  70072. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  70073. nextX = glyphs.getUnchecked (i + 1)->x;
  70074. Path p;
  70075. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  70076. nextX, pg->y + lineThickness * 2.0f,
  70077. lineThickness);
  70078. g.fillPath (p, transform);
  70079. }
  70080. pg->draw (g, transform);
  70081. }
  70082. }
  70083. void GlyphArrangement::createPath (Path& path) const
  70084. {
  70085. for (int i = 0; i < glyphs.size(); ++i)
  70086. glyphs.getUnchecked (i)->createPath (path);
  70087. }
  70088. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  70089. {
  70090. for (int i = 0; i < glyphs.size(); ++i)
  70091. if (glyphs.getUnchecked (i)->hitTest (x, y))
  70092. return i;
  70093. return -1;
  70094. }
  70095. END_JUCE_NAMESPACE
  70096. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  70097. /*** Start of inlined file: juce_TextLayout.cpp ***/
  70098. BEGIN_JUCE_NAMESPACE
  70099. class TextLayout::Token
  70100. {
  70101. public:
  70102. String text;
  70103. Font font;
  70104. int x, y, w, h;
  70105. int line, lineHeight;
  70106. bool isWhitespace, isNewLine;
  70107. Token (const String& t,
  70108. const Font& f,
  70109. const bool isWhitespace_) throw()
  70110. : text (t),
  70111. font (f),
  70112. x(0),
  70113. y(0),
  70114. isWhitespace (isWhitespace_)
  70115. {
  70116. w = font.getStringWidth (t);
  70117. h = roundToInt (f.getHeight());
  70118. isNewLine = t.containsAnyOf (T("\r\n"));
  70119. }
  70120. Token (const Token& other) throw()
  70121. : text (other.text),
  70122. font (other.font),
  70123. x (other.x),
  70124. y (other.y),
  70125. w (other.w),
  70126. h (other.h),
  70127. line (other.line),
  70128. lineHeight (other.lineHeight),
  70129. isWhitespace (other.isWhitespace),
  70130. isNewLine (other.isNewLine)
  70131. {
  70132. }
  70133. ~Token() throw()
  70134. {
  70135. }
  70136. void draw (Graphics& g,
  70137. const int xOffset,
  70138. const int yOffset) throw()
  70139. {
  70140. if (! isWhitespace)
  70141. {
  70142. g.setFont (font);
  70143. g.drawSingleLineText (text.trimEnd(),
  70144. xOffset + x,
  70145. yOffset + y + (lineHeight - h)
  70146. + roundToInt (font.getAscent()));
  70147. }
  70148. }
  70149. juce_UseDebuggingNewOperator
  70150. };
  70151. TextLayout::TextLayout() throw()
  70152. : totalLines (0)
  70153. {
  70154. tokens.ensureStorageAllocated (64);
  70155. }
  70156. TextLayout::TextLayout (const String& text,
  70157. const Font& font) throw()
  70158. : totalLines (0)
  70159. {
  70160. tokens.ensureStorageAllocated (64);
  70161. appendText (text, font);
  70162. }
  70163. TextLayout::TextLayout (const TextLayout& other) throw()
  70164. : totalLines (0)
  70165. {
  70166. *this = other;
  70167. }
  70168. const TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  70169. {
  70170. if (this != &other)
  70171. {
  70172. clear();
  70173. totalLines = other.totalLines;
  70174. for (int i = 0; i < other.tokens.size(); ++i)
  70175. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  70176. }
  70177. return *this;
  70178. }
  70179. TextLayout::~TextLayout() throw()
  70180. {
  70181. clear();
  70182. }
  70183. void TextLayout::clear() throw()
  70184. {
  70185. tokens.clear();
  70186. totalLines = 0;
  70187. }
  70188. void TextLayout::appendText (const String& text,
  70189. const Font& font) throw()
  70190. {
  70191. const tchar* t = text;
  70192. String currentString;
  70193. int lastCharType = 0;
  70194. for (;;)
  70195. {
  70196. const tchar c = *t++;
  70197. if (c == 0)
  70198. break;
  70199. int charType;
  70200. if (c == T('\r') || c == T('\n'))
  70201. {
  70202. charType = 0;
  70203. }
  70204. else if (CharacterFunctions::isWhitespace (c))
  70205. {
  70206. charType = 2;
  70207. }
  70208. else
  70209. {
  70210. charType = 1;
  70211. }
  70212. if (charType == 0 || charType != lastCharType)
  70213. {
  70214. if (currentString.isNotEmpty())
  70215. {
  70216. tokens.add (new Token (currentString, font,
  70217. lastCharType == 2 || lastCharType == 0));
  70218. }
  70219. currentString = String::charToString (c);
  70220. if (c == T('\r') && *t == T('\n'))
  70221. currentString += *t++;
  70222. }
  70223. else
  70224. {
  70225. currentString += c;
  70226. }
  70227. lastCharType = charType;
  70228. }
  70229. if (currentString.isNotEmpty())
  70230. tokens.add (new Token (currentString, font, lastCharType == 2));
  70231. }
  70232. void TextLayout::setText (const String& text, const Font& font) throw()
  70233. {
  70234. clear();
  70235. appendText (text, font);
  70236. }
  70237. void TextLayout::layout (int maxWidth,
  70238. const Justification& justification,
  70239. const bool attemptToBalanceLineLengths) throw()
  70240. {
  70241. if (attemptToBalanceLineLengths)
  70242. {
  70243. const int originalW = maxWidth;
  70244. int bestWidth = maxWidth;
  70245. float bestLineProportion = 0.0f;
  70246. while (maxWidth > originalW / 2)
  70247. {
  70248. layout (maxWidth, justification, false);
  70249. if (getNumLines() <= 1)
  70250. return;
  70251. const int lastLineW = getLineWidth (getNumLines() - 1);
  70252. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  70253. const float prop = lastLineW / (float) lastButOneLineW;
  70254. if (prop > 0.9f)
  70255. return;
  70256. if (prop > bestLineProportion)
  70257. {
  70258. bestLineProportion = prop;
  70259. bestWidth = maxWidth;
  70260. }
  70261. maxWidth -= 10;
  70262. }
  70263. layout (bestWidth, justification, false);
  70264. }
  70265. else
  70266. {
  70267. int x = 0;
  70268. int y = 0;
  70269. int h = 0;
  70270. totalLines = 0;
  70271. int i;
  70272. for (i = 0; i < tokens.size(); ++i)
  70273. {
  70274. Token* const t = tokens.getUnchecked(i);
  70275. t->x = x;
  70276. t->y = y;
  70277. t->line = totalLines;
  70278. x += t->w;
  70279. h = jmax (h, t->h);
  70280. const Token* nextTok = tokens [i + 1];
  70281. if (nextTok == 0)
  70282. break;
  70283. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  70284. {
  70285. // finished a line, so go back and update the heights of the things on it
  70286. for (int j = i; j >= 0; --j)
  70287. {
  70288. Token* const tok = tokens.getUnchecked(j);
  70289. if (tok->line == totalLines)
  70290. tok->lineHeight = h;
  70291. else
  70292. break;
  70293. }
  70294. x = 0;
  70295. y += h;
  70296. h = 0;
  70297. ++totalLines;
  70298. }
  70299. }
  70300. // finished a line, so go back and update the heights of the things on it
  70301. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  70302. {
  70303. Token* const t = tokens.getUnchecked(j);
  70304. if (t->line == totalLines)
  70305. t->lineHeight = h;
  70306. else
  70307. break;
  70308. }
  70309. ++totalLines;
  70310. if (! justification.testFlags (Justification::left))
  70311. {
  70312. int totalW = getWidth();
  70313. for (i = totalLines; --i >= 0;)
  70314. {
  70315. const int lineW = getLineWidth (i);
  70316. int dx = 0;
  70317. if (justification.testFlags (Justification::horizontallyCentred))
  70318. dx = (totalW - lineW) / 2;
  70319. else if (justification.testFlags (Justification::right))
  70320. dx = totalW - lineW;
  70321. for (int j = tokens.size(); --j >= 0;)
  70322. {
  70323. Token* const t = tokens.getUnchecked(j);
  70324. if (t->line == i)
  70325. t->x += dx;
  70326. }
  70327. }
  70328. }
  70329. }
  70330. }
  70331. int TextLayout::getLineWidth (const int lineNumber) const throw()
  70332. {
  70333. int maxW = 0;
  70334. for (int i = tokens.size(); --i >= 0;)
  70335. {
  70336. const Token* const t = tokens.getUnchecked(i);
  70337. if (t->line == lineNumber && ! t->isWhitespace)
  70338. maxW = jmax (maxW, t->x + t->w);
  70339. }
  70340. return maxW;
  70341. }
  70342. int TextLayout::getWidth() const throw()
  70343. {
  70344. int maxW = 0;
  70345. for (int i = tokens.size(); --i >= 0;)
  70346. {
  70347. const Token* const t = tokens.getUnchecked(i);
  70348. if (! t->isWhitespace)
  70349. maxW = jmax (maxW, t->x + t->w);
  70350. }
  70351. return maxW;
  70352. }
  70353. int TextLayout::getHeight() const throw()
  70354. {
  70355. int maxH = 0;
  70356. for (int i = tokens.size(); --i >= 0;)
  70357. {
  70358. const Token* const t = tokens.getUnchecked(i);
  70359. if (! t->isWhitespace)
  70360. maxH = jmax (maxH, t->y + t->h);
  70361. }
  70362. return maxH;
  70363. }
  70364. void TextLayout::draw (Graphics& g,
  70365. const int xOffset,
  70366. const int yOffset) const throw()
  70367. {
  70368. for (int i = tokens.size(); --i >= 0;)
  70369. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  70370. }
  70371. void TextLayout::drawWithin (Graphics& g,
  70372. int x, int y, int w, int h,
  70373. const Justification& justification) const throw()
  70374. {
  70375. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  70376. x, y, w, h);
  70377. draw (g, x, y);
  70378. }
  70379. END_JUCE_NAMESPACE
  70380. /*** End of inlined file: juce_TextLayout.cpp ***/
  70381. /*** Start of inlined file: juce_Typeface.cpp ***/
  70382. BEGIN_JUCE_NAMESPACE
  70383. Typeface::Typeface (const String& name_) throw()
  70384. : name (name_)
  70385. {
  70386. }
  70387. Typeface::~Typeface()
  70388. {
  70389. }
  70390. class CustomTypeface::GlyphInfo
  70391. {
  70392. public:
  70393. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  70394. : character (character_), path (path_), width (width_)
  70395. {
  70396. }
  70397. ~GlyphInfo() throw()
  70398. {
  70399. }
  70400. struct KerningPair
  70401. {
  70402. juce_wchar character2;
  70403. float kerningAmount;
  70404. };
  70405. void addKerningPair (const juce_wchar subsequentCharacter,
  70406. const float extraKerningAmount) throw()
  70407. {
  70408. KerningPair kp;
  70409. kp.character2 = subsequentCharacter;
  70410. kp.kerningAmount = extraKerningAmount;
  70411. kerningPairs.add (kp);
  70412. }
  70413. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  70414. {
  70415. if (subsequentCharacter != 0)
  70416. {
  70417. for (int i = kerningPairs.size(); --i >= 0;)
  70418. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  70419. return width + kerningPairs.getReference(i).kerningAmount;
  70420. }
  70421. return width;
  70422. }
  70423. const juce_wchar character;
  70424. const Path path;
  70425. float width;
  70426. Array <KerningPair> kerningPairs;
  70427. juce_UseDebuggingNewOperator
  70428. private:
  70429. GlyphInfo (const GlyphInfo&);
  70430. const GlyphInfo& operator= (const GlyphInfo&);
  70431. };
  70432. CustomTypeface::CustomTypeface()
  70433. : Typeface (String::empty)
  70434. {
  70435. clear();
  70436. }
  70437. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  70438. : Typeface (String::empty)
  70439. {
  70440. clear();
  70441. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  70442. BufferedInputStream in (&gzin, 32768, false);
  70443. name = in.readString();
  70444. isBold = in.readBool();
  70445. isItalic = in.readBool();
  70446. ascent = in.readFloat();
  70447. defaultCharacter = (juce_wchar) in.readShort();
  70448. int i, numChars = in.readInt();
  70449. for (i = 0; i < numChars; ++i)
  70450. {
  70451. const juce_wchar c = (juce_wchar) in.readShort();
  70452. const float width = in.readFloat();
  70453. Path p;
  70454. p.loadPathFromStream (in);
  70455. addGlyph (c, p, width);
  70456. }
  70457. const int numKerningPairs = in.readInt();
  70458. for (i = 0; i < numKerningPairs; ++i)
  70459. {
  70460. const juce_wchar char1 = (juce_wchar) in.readShort();
  70461. const juce_wchar char2 = (juce_wchar) in.readShort();
  70462. addKerningPair (char1, char2, in.readFloat());
  70463. }
  70464. }
  70465. CustomTypeface::~CustomTypeface()
  70466. {
  70467. }
  70468. void CustomTypeface::clear()
  70469. {
  70470. defaultCharacter = 0;
  70471. ascent = 1.0f;
  70472. isBold = isItalic = false;
  70473. zeromem (lookupTable, sizeof (lookupTable));
  70474. glyphs.clear();
  70475. }
  70476. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  70477. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  70478. {
  70479. name = name_;
  70480. defaultCharacter = defaultCharacter_;
  70481. ascent = ascent_;
  70482. isBold = isBold_;
  70483. isItalic = isItalic_;
  70484. }
  70485. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  70486. {
  70487. // Check that you're not trying to add the same character twice..
  70488. jassert (findGlyph (character, false) == 0);
  70489. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  70490. lookupTable [character] = (short) glyphs.size();
  70491. glyphs.add (new GlyphInfo (character, path, width));
  70492. }
  70493. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  70494. {
  70495. if (extraAmount != 0)
  70496. {
  70497. GlyphInfo* const g = findGlyph (char1, true);
  70498. jassert (g != 0); // can only add kerning pairs for characters that exist!
  70499. if (g != 0)
  70500. g->addKerningPair (char2, extraAmount);
  70501. }
  70502. }
  70503. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  70504. {
  70505. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  70506. return glyphs [(int) lookupTable [(int) character]];
  70507. for (int i = 0; i < glyphs.size(); ++i)
  70508. {
  70509. GlyphInfo* const g = glyphs.getUnchecked(i);
  70510. if (g->character == character)
  70511. return g;
  70512. }
  70513. if (loadIfNeeded && loadGlyphIfPossible (character))
  70514. return findGlyph (character, false);
  70515. return 0;
  70516. }
  70517. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  70518. {
  70519. GlyphInfo* glyph = findGlyph (character, true);
  70520. if (glyph == 0)
  70521. {
  70522. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  70523. glyph = findGlyph (L' ', true);
  70524. if (glyph == 0)
  70525. {
  70526. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  70527. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  70528. if (fallbackTypeface != 0 && fallbackTypeface != this)
  70529. {
  70530. //xxx
  70531. }
  70532. if (glyph == 0)
  70533. glyph = findGlyph (defaultCharacter, true);
  70534. }
  70535. }
  70536. return glyph;
  70537. }
  70538. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  70539. {
  70540. return false;
  70541. }
  70542. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  70543. {
  70544. for (int i = 0; i < numCharacters; ++i)
  70545. {
  70546. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  70547. Array <int> glyphIndexes;
  70548. Array <float> offsets;
  70549. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70550. const int glyphIndex = glyphIndexes.getFirst();
  70551. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70552. {
  70553. const float glyphWidth = offsets[1];
  70554. Path p;
  70555. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70556. addGlyph (c, p, glyphWidth);
  70557. for (int j = glyphs.size() - 1; --j >= 0;)
  70558. {
  70559. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70560. glyphIndexes.clearQuick();
  70561. offsets.clearQuick();
  70562. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70563. if (offsets.size() > 1)
  70564. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70565. }
  70566. }
  70567. }
  70568. }
  70569. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70570. {
  70571. GZIPCompressorOutputStream out (&outputStream);
  70572. out.writeString (name);
  70573. out.writeBool (isBold);
  70574. out.writeBool (isItalic);
  70575. out.writeFloat (ascent);
  70576. out.writeShort ((short) (unsigned short) defaultCharacter);
  70577. out.writeInt (glyphs.size());
  70578. int i, numKerningPairs = 0;
  70579. for (i = 0; i < glyphs.size(); ++i)
  70580. {
  70581. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70582. out.writeShort ((short) (unsigned short) g->character);
  70583. out.writeFloat (g->width);
  70584. g->path.writePathToStream (out);
  70585. numKerningPairs += g->kerningPairs.size();
  70586. }
  70587. out.writeInt (numKerningPairs);
  70588. for (i = 0; i < glyphs.size(); ++i)
  70589. {
  70590. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70591. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70592. {
  70593. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70594. out.writeShort ((short) (unsigned short) g->character);
  70595. out.writeShort ((short) (unsigned short) p.character2);
  70596. out.writeFloat (p.kerningAmount);
  70597. }
  70598. }
  70599. return true;
  70600. }
  70601. float CustomTypeface::getAscent() const
  70602. {
  70603. return ascent;
  70604. }
  70605. float CustomTypeface::getDescent() const
  70606. {
  70607. return 1.0f - ascent;
  70608. }
  70609. float CustomTypeface::getStringWidth (const String& text)
  70610. {
  70611. float x = 0;
  70612. const juce_wchar* t = (const juce_wchar*) text;
  70613. while (*t != 0)
  70614. {
  70615. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70616. if (glyph != 0)
  70617. x += glyph->getHorizontalSpacing (*t);
  70618. }
  70619. return x;
  70620. }
  70621. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70622. {
  70623. xOffsets.add (0);
  70624. float x = 0;
  70625. const juce_wchar* t = (const juce_wchar*) text;
  70626. while (*t != 0)
  70627. {
  70628. const juce_wchar c = *t++;
  70629. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70630. if (glyph != 0)
  70631. {
  70632. x += glyph->getHorizontalSpacing (*t);
  70633. resultGlyphs.add ((int) glyph->character);
  70634. xOffsets.add (x);
  70635. }
  70636. }
  70637. }
  70638. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70639. {
  70640. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70641. if (glyph != 0)
  70642. {
  70643. path = glyph->path;
  70644. return true;
  70645. }
  70646. return false;
  70647. }
  70648. END_JUCE_NAMESPACE
  70649. /*** End of inlined file: juce_Typeface.cpp ***/
  70650. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70651. BEGIN_JUCE_NAMESPACE
  70652. AffineTransform::AffineTransform() throw()
  70653. : mat00 (1.0f),
  70654. mat01 (0),
  70655. mat02 (0),
  70656. mat10 (0),
  70657. mat11 (1.0f),
  70658. mat12 (0)
  70659. {
  70660. }
  70661. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70662. : mat00 (other.mat00),
  70663. mat01 (other.mat01),
  70664. mat02 (other.mat02),
  70665. mat10 (other.mat10),
  70666. mat11 (other.mat11),
  70667. mat12 (other.mat12)
  70668. {
  70669. }
  70670. AffineTransform::AffineTransform (const float mat00_,
  70671. const float mat01_,
  70672. const float mat02_,
  70673. const float mat10_,
  70674. const float mat11_,
  70675. const float mat12_) throw()
  70676. : mat00 (mat00_),
  70677. mat01 (mat01_),
  70678. mat02 (mat02_),
  70679. mat10 (mat10_),
  70680. mat11 (mat11_),
  70681. mat12 (mat12_)
  70682. {
  70683. }
  70684. const AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70685. {
  70686. mat00 = other.mat00;
  70687. mat01 = other.mat01;
  70688. mat02 = other.mat02;
  70689. mat10 = other.mat10;
  70690. mat11 = other.mat11;
  70691. mat12 = other.mat12;
  70692. return *this;
  70693. }
  70694. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70695. {
  70696. return mat00 == other.mat00
  70697. && mat01 == other.mat01
  70698. && mat02 == other.mat02
  70699. && mat10 == other.mat10
  70700. && mat11 == other.mat11
  70701. && mat12 == other.mat12;
  70702. }
  70703. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70704. {
  70705. return ! operator== (other);
  70706. }
  70707. bool AffineTransform::isIdentity() const throw()
  70708. {
  70709. return (mat01 == 0)
  70710. && (mat02 == 0)
  70711. && (mat10 == 0)
  70712. && (mat12 == 0)
  70713. && (mat00 == 1.0f)
  70714. && (mat11 == 1.0f);
  70715. }
  70716. const AffineTransform AffineTransform::identity;
  70717. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70718. {
  70719. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70720. other.mat00 * mat01 + other.mat01 * mat11,
  70721. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70722. other.mat10 * mat00 + other.mat11 * mat10,
  70723. other.mat10 * mat01 + other.mat11 * mat11,
  70724. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70725. }
  70726. const AffineTransform AffineTransform::followedBy (const float omat00,
  70727. const float omat01,
  70728. const float omat02,
  70729. const float omat10,
  70730. const float omat11,
  70731. const float omat12) const throw()
  70732. {
  70733. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70734. omat00 * mat01 + omat01 * mat11,
  70735. omat00 * mat02 + omat01 * mat12 + omat02,
  70736. omat10 * mat00 + omat11 * mat10,
  70737. omat10 * mat01 + omat11 * mat11,
  70738. omat10 * mat02 + omat11 * mat12 + omat12);
  70739. }
  70740. const AffineTransform AffineTransform::translated (const float dx,
  70741. const float dy) const throw()
  70742. {
  70743. return AffineTransform (mat00, mat01, mat02 + dx,
  70744. mat10, mat11, mat12 + dy);
  70745. }
  70746. const AffineTransform AffineTransform::translation (const float dx,
  70747. const float dy) throw()
  70748. {
  70749. return AffineTransform (1.0f, 0, dx,
  70750. 0, 1.0f, dy);
  70751. }
  70752. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70753. {
  70754. const float cosRad = cosf (rad);
  70755. const float sinRad = sinf (rad);
  70756. return followedBy (cosRad, -sinRad, 0,
  70757. sinRad, cosRad, 0);
  70758. }
  70759. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70760. {
  70761. const float cosRad = cosf (rad);
  70762. const float sinRad = sinf (rad);
  70763. return AffineTransform (cosRad, -sinRad, 0,
  70764. sinRad, cosRad, 0);
  70765. }
  70766. const AffineTransform AffineTransform::rotated (const float angle,
  70767. const float pivotX,
  70768. const float pivotY) const throw()
  70769. {
  70770. return translated (-pivotX, -pivotY)
  70771. .rotated (angle)
  70772. .translated (pivotX, pivotY);
  70773. }
  70774. const AffineTransform AffineTransform::rotation (const float angle,
  70775. const float pivotX,
  70776. const float pivotY) throw()
  70777. {
  70778. return translation (-pivotX, -pivotY)
  70779. .rotated (angle)
  70780. .translated (pivotX, pivotY);
  70781. }
  70782. const AffineTransform AffineTransform::scaled (const float factorX,
  70783. const float factorY) const throw()
  70784. {
  70785. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70786. factorY * mat10, factorY * mat11, factorY * mat12);
  70787. }
  70788. const AffineTransform AffineTransform::scale (const float factorX,
  70789. const float factorY) throw()
  70790. {
  70791. return AffineTransform (factorX, 0, 0,
  70792. 0, factorY, 0);
  70793. }
  70794. const AffineTransform AffineTransform::sheared (const float shearX,
  70795. const float shearY) const throw()
  70796. {
  70797. return followedBy (1.0f, shearX, 0,
  70798. shearY, 1.0f, 0);
  70799. }
  70800. const AffineTransform AffineTransform::inverted() const throw()
  70801. {
  70802. double determinant = (mat00 * mat11 - mat10 * mat01);
  70803. if (determinant != 0.0)
  70804. {
  70805. determinant = 1.0 / determinant;
  70806. const float dst00 = (float) (mat11 * determinant);
  70807. const float dst10 = (float) (-mat10 * determinant);
  70808. const float dst01 = (float) (-mat01 * determinant);
  70809. const float dst11 = (float) (mat00 * determinant);
  70810. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70811. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70812. }
  70813. else
  70814. {
  70815. // singularity..
  70816. return *this;
  70817. }
  70818. }
  70819. bool AffineTransform::isSingularity() const throw()
  70820. {
  70821. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70822. }
  70823. bool AffineTransform::isOnlyTranslation() const throw()
  70824. {
  70825. return (mat01 == 0)
  70826. && (mat10 == 0)
  70827. && (mat00 == 1.0f)
  70828. && (mat11 == 1.0f);
  70829. }
  70830. void AffineTransform::transformPoint (float& x,
  70831. float& y) const throw()
  70832. {
  70833. const float oldX = x;
  70834. x = mat00 * oldX + mat01 * y + mat02;
  70835. y = mat10 * oldX + mat11 * y + mat12;
  70836. }
  70837. void AffineTransform::transformPoint (double& x,
  70838. double& y) const throw()
  70839. {
  70840. const double oldX = x;
  70841. x = mat00 * oldX + mat01 * y + mat02;
  70842. y = mat10 * oldX + mat11 * y + mat12;
  70843. }
  70844. END_JUCE_NAMESPACE
  70845. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70846. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70847. BEGIN_JUCE_NAMESPACE
  70848. BorderSize::BorderSize() throw()
  70849. : top (0),
  70850. left (0),
  70851. bottom (0),
  70852. right (0)
  70853. {
  70854. }
  70855. BorderSize::BorderSize (const BorderSize& other) throw()
  70856. : top (other.top),
  70857. left (other.left),
  70858. bottom (other.bottom),
  70859. right (other.right)
  70860. {
  70861. }
  70862. BorderSize::BorderSize (const int topGap,
  70863. const int leftGap,
  70864. const int bottomGap,
  70865. const int rightGap) throw()
  70866. : top (topGap),
  70867. left (leftGap),
  70868. bottom (bottomGap),
  70869. right (rightGap)
  70870. {
  70871. }
  70872. BorderSize::BorderSize (const int allGaps) throw()
  70873. : top (allGaps),
  70874. left (allGaps),
  70875. bottom (allGaps),
  70876. right (allGaps)
  70877. {
  70878. }
  70879. BorderSize::~BorderSize() throw()
  70880. {
  70881. }
  70882. void BorderSize::setTop (const int newTopGap) throw()
  70883. {
  70884. top = newTopGap;
  70885. }
  70886. void BorderSize::setLeft (const int newLeftGap) throw()
  70887. {
  70888. left = newLeftGap;
  70889. }
  70890. void BorderSize::setBottom (const int newBottomGap) throw()
  70891. {
  70892. bottom = newBottomGap;
  70893. }
  70894. void BorderSize::setRight (const int newRightGap) throw()
  70895. {
  70896. right = newRightGap;
  70897. }
  70898. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70899. {
  70900. return Rectangle<int> (r.getX() + left,
  70901. r.getY() + top,
  70902. r.getWidth() - (left + right),
  70903. r.getHeight() - (top + bottom));
  70904. }
  70905. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70906. {
  70907. r.setBounds (r.getX() + left,
  70908. r.getY() + top,
  70909. r.getWidth() - (left + right),
  70910. r.getHeight() - (top + bottom));
  70911. }
  70912. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70913. {
  70914. return Rectangle<int> (r.getX() - left,
  70915. r.getY() - top,
  70916. r.getWidth() + (left + right),
  70917. r.getHeight() + (top + bottom));
  70918. }
  70919. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70920. {
  70921. r.setBounds (r.getX() - left,
  70922. r.getY() - top,
  70923. r.getWidth() + (left + right),
  70924. r.getHeight() + (top + bottom));
  70925. }
  70926. bool BorderSize::operator== (const BorderSize& other) const throw()
  70927. {
  70928. return top == other.top
  70929. && left == other.left
  70930. && bottom == other.bottom
  70931. && right == other.right;
  70932. }
  70933. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70934. {
  70935. return ! operator== (other);
  70936. }
  70937. END_JUCE_NAMESPACE
  70938. /*** End of inlined file: juce_BorderSize.cpp ***/
  70939. /*** Start of inlined file: juce_Line.cpp ***/
  70940. BEGIN_JUCE_NAMESPACE
  70941. static bool juce_lineIntersection (const float x1, const float y1,
  70942. const float x2, const float y2,
  70943. const float x3, const float y3,
  70944. const float x4, const float y4,
  70945. float& intersectionX,
  70946. float& intersectionY) throw()
  70947. {
  70948. if (x2 != x3 || y2 != y3)
  70949. {
  70950. const float dx1 = x2 - x1;
  70951. const float dy1 = y2 - y1;
  70952. const float dx2 = x4 - x3;
  70953. const float dy2 = y4 - y3;
  70954. const float divisor = dx1 * dy2 - dx2 * dy1;
  70955. if (divisor == 0)
  70956. {
  70957. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70958. {
  70959. if (dy1 == 0 && dy2 != 0)
  70960. {
  70961. const float along = (y1 - y3) / dy2;
  70962. intersectionX = x3 + along * dx2;
  70963. intersectionY = y1;
  70964. return along >= 0 && along <= 1.0f;
  70965. }
  70966. else if (dy2 == 0 && dy1 != 0)
  70967. {
  70968. const float along = (y3 - y1) / dy1;
  70969. intersectionX = x1 + along * dx1;
  70970. intersectionY = y3;
  70971. return along >= 0 && along <= 1.0f;
  70972. }
  70973. else if (dx1 == 0 && dx2 != 0)
  70974. {
  70975. const float along = (x1 - x3) / dx2;
  70976. intersectionX = x1;
  70977. intersectionY = y3 + along * dy2;
  70978. return along >= 0 && along <= 1.0f;
  70979. }
  70980. else if (dx2 == 0 && dx1 != 0)
  70981. {
  70982. const float along = (x3 - x1) / dx1;
  70983. intersectionX = x3;
  70984. intersectionY = y1 + along * dy1;
  70985. return along >= 0 && along <= 1.0f;
  70986. }
  70987. }
  70988. intersectionX = 0.5f * (x2 + x3);
  70989. intersectionY = 0.5f * (y2 + y3);
  70990. return false;
  70991. }
  70992. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70993. intersectionX = x1 + along1 * dx1;
  70994. intersectionY = y1 + along1 * dy1;
  70995. if (along1 < 0 || along1 > 1.0f)
  70996. return false;
  70997. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70998. return along2 >= 0 && along2 <= 1.0f;
  70999. }
  71000. intersectionX = x2;
  71001. intersectionY = y2;
  71002. return true;
  71003. }
  71004. Line::Line() throw()
  71005. : startX (0.0f),
  71006. startY (0.0f),
  71007. endX (0.0f),
  71008. endY (0.0f)
  71009. {
  71010. }
  71011. Line::Line (const Line& other) throw()
  71012. : startX (other.startX),
  71013. startY (other.startY),
  71014. endX (other.endX),
  71015. endY (other.endY)
  71016. {
  71017. }
  71018. Line::Line (const float startX_, const float startY_,
  71019. const float endX_, const float endY_) throw()
  71020. : startX (startX_),
  71021. startY (startY_),
  71022. endX (endX_),
  71023. endY (endY_)
  71024. {
  71025. }
  71026. Line::Line (const Point<float>& start,
  71027. const Point<float>& end) throw()
  71028. : startX (start.getX()),
  71029. startY (start.getY()),
  71030. endX (end.getX()),
  71031. endY (end.getY())
  71032. {
  71033. }
  71034. const Line& Line::operator= (const Line& other) throw()
  71035. {
  71036. startX = other.startX;
  71037. startY = other.startY;
  71038. endX = other.endX;
  71039. endY = other.endY;
  71040. return *this;
  71041. }
  71042. Line::~Line() throw()
  71043. {
  71044. }
  71045. const Point<float> Line::getStart() const throw()
  71046. {
  71047. return Point<float> (startX, startY);
  71048. }
  71049. const Point<float> Line::getEnd() const throw()
  71050. {
  71051. return Point<float> (endX, endY);
  71052. }
  71053. void Line::setStart (const float newStartX,
  71054. const float newStartY) throw()
  71055. {
  71056. startX = newStartX;
  71057. startY = newStartY;
  71058. }
  71059. void Line::setStart (const Point<float>& newStart) throw()
  71060. {
  71061. startX = newStart.getX();
  71062. startY = newStart.getY();
  71063. }
  71064. void Line::setEnd (const float newEndX,
  71065. const float newEndY) throw()
  71066. {
  71067. endX = newEndX;
  71068. endY = newEndY;
  71069. }
  71070. void Line::setEnd (const Point<float>& newEnd) throw()
  71071. {
  71072. endX = newEnd.getX();
  71073. endY = newEnd.getY();
  71074. }
  71075. bool Line::operator== (const Line& other) const throw()
  71076. {
  71077. return startX == other.startX
  71078. && startY == other.startY
  71079. && endX == other.endX
  71080. && endY == other.endY;
  71081. }
  71082. bool Line::operator!= (const Line& other) const throw()
  71083. {
  71084. return startX != other.startX
  71085. || startY != other.startY
  71086. || endX != other.endX
  71087. || endY != other.endY;
  71088. }
  71089. void Line::applyTransform (const AffineTransform& transform) throw()
  71090. {
  71091. transform.transformPoint (startX, startY);
  71092. transform.transformPoint (endX, endY);
  71093. }
  71094. float Line::getLength() const throw()
  71095. {
  71096. return (float) juce_hypot (startX - endX,
  71097. startY - endY);
  71098. }
  71099. float Line::getAngle() const throw()
  71100. {
  71101. return atan2f (endX - startX,
  71102. endY - startY);
  71103. }
  71104. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  71105. {
  71106. const float alpha = distanceFromStart / getLength();
  71107. return Point<float> (startX + (endX - startX) * alpha,
  71108. startY + (endY - startY) * alpha);
  71109. }
  71110. const Point<float> Line::getPointAlongLine (const float offsetX,
  71111. const float offsetY) const throw()
  71112. {
  71113. const float dx = endX - startX;
  71114. const float dy = endY - startY;
  71115. const double length = juce_hypot (dx, dy);
  71116. if (length == 0)
  71117. return Point<float> (startX, startY);
  71118. else
  71119. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  71120. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  71121. }
  71122. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  71123. {
  71124. return Point<float> (startX + (endX - startX) * alpha,
  71125. startY + (endY - startY) * alpha);
  71126. }
  71127. float Line::getDistanceFromLine (const float x,
  71128. const float y) const throw()
  71129. {
  71130. const double dx = endX - startX;
  71131. const double dy = endY - startY;
  71132. const double length = dx * dx + dy * dy;
  71133. if (length > 0)
  71134. {
  71135. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  71136. if (prop >= 0.0f && prop < 1.0f)
  71137. {
  71138. return (float) juce_hypot (x - (startX + prop * dx),
  71139. y - (startY + prop * dy));
  71140. }
  71141. }
  71142. return (float) jmin (juce_hypot (x - startX, y - startY),
  71143. juce_hypot (x - endX, y - endY));
  71144. }
  71145. float Line::findNearestPointTo (const float x,
  71146. const float y) const throw()
  71147. {
  71148. const double dx = endX - startX;
  71149. const double dy = endY - startY;
  71150. const double length = dx * dx + dy * dy;
  71151. if (length <= 0.0)
  71152. return 0.0f;
  71153. return jlimit (0.0f, 1.0f,
  71154. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  71155. }
  71156. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  71157. {
  71158. const float length = getLength();
  71159. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  71160. getEnd());
  71161. }
  71162. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  71163. {
  71164. const float length = getLength();
  71165. return Line (getStart(),
  71166. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  71167. }
  71168. bool Line::clipToPath (const Path& path,
  71169. const bool keepSectionOutsidePath) throw()
  71170. {
  71171. const bool startInside = path.contains (startX, startY);
  71172. const bool endInside = path.contains (endX, endY);
  71173. if (startInside == endInside)
  71174. {
  71175. if (keepSectionOutsidePath != startInside)
  71176. {
  71177. // entirely outside the path
  71178. return false;
  71179. }
  71180. else
  71181. {
  71182. // entirely inside the path
  71183. startX = 0.0f;
  71184. startY = 0.0f;
  71185. endX = 0.0f;
  71186. endY = 0.0f;
  71187. return true;
  71188. }
  71189. }
  71190. else
  71191. {
  71192. bool changed = false;
  71193. PathFlatteningIterator iter (path, AffineTransform::identity);
  71194. while (iter.next())
  71195. {
  71196. float ix, iy;
  71197. if (intersects (Line (iter.x1, iter.y1,
  71198. iter.x2, iter.y2),
  71199. ix, iy))
  71200. {
  71201. if ((startInside && keepSectionOutsidePath)
  71202. || (endInside && ! keepSectionOutsidePath))
  71203. {
  71204. setStart (ix, iy);
  71205. }
  71206. else
  71207. {
  71208. setEnd (ix, iy);
  71209. }
  71210. changed = true;
  71211. }
  71212. }
  71213. return changed;
  71214. }
  71215. }
  71216. bool Line::intersects (const Line& line,
  71217. float& intersectionX,
  71218. float& intersectionY) const throw()
  71219. {
  71220. return juce_lineIntersection (startX, startY,
  71221. endX, endY,
  71222. line.startX, line.startY,
  71223. line.endX, line.endY,
  71224. intersectionX,
  71225. intersectionY);
  71226. }
  71227. bool Line::isVertical() const throw()
  71228. {
  71229. return startX == endX;
  71230. }
  71231. bool Line::isHorizontal() const throw()
  71232. {
  71233. return startY == endY;
  71234. }
  71235. bool Line::isPointAbove (const float x, const float y) const throw()
  71236. {
  71237. return startX != endX
  71238. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  71239. }
  71240. END_JUCE_NAMESPACE
  71241. /*** End of inlined file: juce_Line.cpp ***/
  71242. /*** Start of inlined file: juce_Path.cpp ***/
  71243. BEGIN_JUCE_NAMESPACE
  71244. // tests that some co-ords aren't NaNs
  71245. #define CHECK_COORDS_ARE_VALID(x, y) \
  71246. jassert (x == x && y == y);
  71247. const float Path::lineMarker = 100001.0f;
  71248. const float Path::moveMarker = 100002.0f;
  71249. const float Path::quadMarker = 100003.0f;
  71250. const float Path::cubicMarker = 100004.0f;
  71251. const float Path::closeSubPathMarker = 100005.0f;
  71252. static const int defaultGranularity = 32;
  71253. Path::Path() throw()
  71254. : numElements (0),
  71255. pathXMin (0),
  71256. pathXMax (0),
  71257. pathYMin (0),
  71258. pathYMax (0),
  71259. useNonZeroWinding (true)
  71260. {
  71261. }
  71262. Path::~Path() throw()
  71263. {
  71264. }
  71265. Path::Path (const Path& other) throw()
  71266. : numElements (other.numElements),
  71267. pathXMin (other.pathXMin),
  71268. pathXMax (other.pathXMax),
  71269. pathYMin (other.pathYMin),
  71270. pathYMax (other.pathYMax),
  71271. useNonZeroWinding (other.useNonZeroWinding)
  71272. {
  71273. if (numElements > 0)
  71274. {
  71275. data.setAllocatedSize (numElements);
  71276. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71277. }
  71278. }
  71279. const Path& Path::operator= (const Path& other) throw()
  71280. {
  71281. if (this != &other)
  71282. {
  71283. data.ensureAllocatedSize (other.numElements);
  71284. numElements = other.numElements;
  71285. pathXMin = other.pathXMin;
  71286. pathXMax = other.pathXMax;
  71287. pathYMin = other.pathYMin;
  71288. pathYMax = other.pathYMax;
  71289. useNonZeroWinding = other.useNonZeroWinding;
  71290. if (numElements > 0)
  71291. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71292. }
  71293. return *this;
  71294. }
  71295. void Path::clear() throw()
  71296. {
  71297. numElements = 0;
  71298. pathXMin = 0;
  71299. pathYMin = 0;
  71300. pathYMax = 0;
  71301. pathXMax = 0;
  71302. }
  71303. void Path::swapWithPath (Path& other)
  71304. {
  71305. data.swapWith (other.data);
  71306. swapVariables <int> (numElements, other.numElements);
  71307. swapVariables <float> (pathXMin, other.pathXMin);
  71308. swapVariables <float> (pathXMax, other.pathXMax);
  71309. swapVariables <float> (pathYMin, other.pathYMin);
  71310. swapVariables <float> (pathYMax, other.pathYMax);
  71311. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  71312. }
  71313. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  71314. {
  71315. useNonZeroWinding = isNonZero;
  71316. }
  71317. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  71318. const bool preserveProportions) throw()
  71319. {
  71320. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  71321. }
  71322. bool Path::isEmpty() const throw()
  71323. {
  71324. int i = 0;
  71325. while (i < numElements)
  71326. {
  71327. const float type = data.elements [i++];
  71328. if (type == moveMarker)
  71329. {
  71330. i += 2;
  71331. }
  71332. else if (type == lineMarker
  71333. || type == quadMarker
  71334. || type == cubicMarker)
  71335. {
  71336. return false;
  71337. }
  71338. }
  71339. return true;
  71340. }
  71341. const Rectangle<float> Path::getBounds () const throw()
  71342. {
  71343. return Rectangle<float> (pathXMin, pathYMin,
  71344. pathXMax - pathXMin,
  71345. pathYMax - pathYMin);
  71346. }
  71347. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  71348. {
  71349. return getBounds().transformed (transform);
  71350. }
  71351. void Path::startNewSubPath (const float x,
  71352. const float y) throw()
  71353. {
  71354. CHECK_COORDS_ARE_VALID (x, y);
  71355. if (numElements == 0)
  71356. {
  71357. pathXMin = pathXMax = x;
  71358. pathYMin = pathYMax = y;
  71359. }
  71360. else
  71361. {
  71362. pathXMin = jmin (pathXMin, x);
  71363. pathXMax = jmax (pathXMax, x);
  71364. pathYMin = jmin (pathYMin, y);
  71365. pathYMax = jmax (pathYMax, y);
  71366. }
  71367. data.ensureAllocatedSize (numElements + 3);
  71368. data.elements [numElements++] = moveMarker;
  71369. data.elements [numElements++] = x;
  71370. data.elements [numElements++] = y;
  71371. }
  71372. void Path::lineTo (const float x, const float y) throw()
  71373. {
  71374. CHECK_COORDS_ARE_VALID (x, y);
  71375. if (numElements == 0)
  71376. startNewSubPath (0, 0);
  71377. data.ensureAllocatedSize (numElements + 3);
  71378. data.elements [numElements++] = lineMarker;
  71379. data.elements [numElements++] = x;
  71380. data.elements [numElements++] = y;
  71381. pathXMin = jmin (pathXMin, x);
  71382. pathXMax = jmax (pathXMax, x);
  71383. pathYMin = jmin (pathYMin, y);
  71384. pathYMax = jmax (pathYMax, y);
  71385. }
  71386. void Path::quadraticTo (const float x1, const float y1,
  71387. const float x2, const float y2) throw()
  71388. {
  71389. CHECK_COORDS_ARE_VALID (x1, y1);
  71390. CHECK_COORDS_ARE_VALID (x2, y2);
  71391. if (numElements == 0)
  71392. startNewSubPath (0, 0);
  71393. data.ensureAllocatedSize (numElements + 5);
  71394. data.elements [numElements++] = quadMarker;
  71395. data.elements [numElements++] = x1;
  71396. data.elements [numElements++] = y1;
  71397. data.elements [numElements++] = x2;
  71398. data.elements [numElements++] = y2;
  71399. pathXMin = jmin (pathXMin, x1, x2);
  71400. pathXMax = jmax (pathXMax, x1, x2);
  71401. pathYMin = jmin (pathYMin, y1, y2);
  71402. pathYMax = jmax (pathYMax, y1, y2);
  71403. }
  71404. void Path::cubicTo (const float x1, const float y1,
  71405. const float x2, const float y2,
  71406. const float x3, const float y3) throw()
  71407. {
  71408. CHECK_COORDS_ARE_VALID (x1, y1);
  71409. CHECK_COORDS_ARE_VALID (x2, y2);
  71410. CHECK_COORDS_ARE_VALID (x3, y3);
  71411. if (numElements == 0)
  71412. startNewSubPath (0, 0);
  71413. data.ensureAllocatedSize (numElements + 7);
  71414. data.elements [numElements++] = cubicMarker;
  71415. data.elements [numElements++] = x1;
  71416. data.elements [numElements++] = y1;
  71417. data.elements [numElements++] = x2;
  71418. data.elements [numElements++] = y2;
  71419. data.elements [numElements++] = x3;
  71420. data.elements [numElements++] = y3;
  71421. pathXMin = jmin (pathXMin, x1, x2, x3);
  71422. pathXMax = jmax (pathXMax, x1, x2, x3);
  71423. pathYMin = jmin (pathYMin, y1, y2, y3);
  71424. pathYMax = jmax (pathYMax, y1, y2, y3);
  71425. }
  71426. void Path::closeSubPath() throw()
  71427. {
  71428. if (numElements > 0
  71429. && data.elements [numElements - 1] != closeSubPathMarker)
  71430. {
  71431. data.ensureAllocatedSize (numElements + 1);
  71432. data.elements [numElements++] = closeSubPathMarker;
  71433. }
  71434. }
  71435. const Point<float> Path::getCurrentPosition() const
  71436. {
  71437. int i = numElements - 1;
  71438. if (i > 0 && data.elements[i] == closeSubPathMarker)
  71439. {
  71440. while (i >= 0)
  71441. {
  71442. if (data.elements[i] == moveMarker)
  71443. {
  71444. i += 2;
  71445. break;
  71446. }
  71447. --i;
  71448. }
  71449. }
  71450. if (i > 0)
  71451. return Point<float> (data.elements [i - 1], data.elements [i]);
  71452. return Point<float>();
  71453. }
  71454. void Path::addRectangle (const float x, const float y,
  71455. const float w, const float h) throw()
  71456. {
  71457. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  71458. if (w < 0)
  71459. swapVariables (x1, x2);
  71460. if (h < 0)
  71461. swapVariables (y1, y2);
  71462. data.ensureAllocatedSize (numElements + 13);
  71463. if (numElements == 0)
  71464. {
  71465. pathXMin = x1;
  71466. pathXMax = x2;
  71467. pathYMin = y1;
  71468. pathYMax = y2;
  71469. }
  71470. else
  71471. {
  71472. pathXMin = jmin (pathXMin, x1);
  71473. pathXMax = jmax (pathXMax, x2);
  71474. pathYMin = jmin (pathYMin, y1);
  71475. pathYMax = jmax (pathYMax, y2);
  71476. }
  71477. data.elements [numElements++] = moveMarker;
  71478. data.elements [numElements++] = x1;
  71479. data.elements [numElements++] = y2;
  71480. data.elements [numElements++] = lineMarker;
  71481. data.elements [numElements++] = x1;
  71482. data.elements [numElements++] = y1;
  71483. data.elements [numElements++] = lineMarker;
  71484. data.elements [numElements++] = x2;
  71485. data.elements [numElements++] = y1;
  71486. data.elements [numElements++] = lineMarker;
  71487. data.elements [numElements++] = x2;
  71488. data.elements [numElements++] = y2;
  71489. data.elements [numElements++] = closeSubPathMarker;
  71490. }
  71491. void Path::addRectangle (const Rectangle<int>& rectangle) throw()
  71492. {
  71493. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  71494. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  71495. }
  71496. void Path::addRoundedRectangle (const float x, const float y,
  71497. const float w, const float h,
  71498. float csx,
  71499. float csy) throw()
  71500. {
  71501. csx = jmin (csx, w * 0.5f);
  71502. csy = jmin (csy, h * 0.5f);
  71503. const float cs45x = csx * 0.45f;
  71504. const float cs45y = csy * 0.45f;
  71505. const float x2 = x + w;
  71506. const float y2 = y + h;
  71507. startNewSubPath (x + csx, y);
  71508. lineTo (x2 - csx, y);
  71509. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  71510. lineTo (x2, y2 - csy);
  71511. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  71512. lineTo (x + csx, y2);
  71513. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  71514. lineTo (x, y + csy);
  71515. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71516. closeSubPath();
  71517. }
  71518. void Path::addRoundedRectangle (const float x, const float y,
  71519. const float w, const float h,
  71520. float cs) throw()
  71521. {
  71522. addRoundedRectangle (x, y, w, h, cs, cs);
  71523. }
  71524. void Path::addTriangle (const float x1, const float y1,
  71525. const float x2, const float y2,
  71526. const float x3, const float y3) throw()
  71527. {
  71528. startNewSubPath (x1, y1);
  71529. lineTo (x2, y2);
  71530. lineTo (x3, y3);
  71531. closeSubPath();
  71532. }
  71533. void Path::addQuadrilateral (const float x1, const float y1,
  71534. const float x2, const float y2,
  71535. const float x3, const float y3,
  71536. const float x4, const float y4) throw()
  71537. {
  71538. startNewSubPath (x1, y1);
  71539. lineTo (x2, y2);
  71540. lineTo (x3, y3);
  71541. lineTo (x4, y4);
  71542. closeSubPath();
  71543. }
  71544. void Path::addEllipse (const float x, const float y,
  71545. const float w, const float h) throw()
  71546. {
  71547. const float hw = w * 0.5f;
  71548. const float hw55 = hw * 0.55f;
  71549. const float hh = h * 0.5f;
  71550. const float hh45 = hh * 0.55f;
  71551. const float cx = x + hw;
  71552. const float cy = y + hh;
  71553. startNewSubPath (cx, cy - hh);
  71554. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  71555. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  71556. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71557. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71558. closeSubPath();
  71559. }
  71560. void Path::addArc (const float x, const float y,
  71561. const float w, const float h,
  71562. const float fromRadians,
  71563. const float toRadians,
  71564. const bool startAsNewSubPath) throw()
  71565. {
  71566. const float radiusX = w / 2.0f;
  71567. const float radiusY = h / 2.0f;
  71568. addCentredArc (x + radiusX,
  71569. y + radiusY,
  71570. radiusX, radiusY,
  71571. 0.0f,
  71572. fromRadians, toRadians,
  71573. startAsNewSubPath);
  71574. }
  71575. static const float ellipseAngularIncrement = 0.05f;
  71576. void Path::addCentredArc (const float centreX, const float centreY,
  71577. const float radiusX, const float radiusY,
  71578. const float rotationOfEllipse,
  71579. const float fromRadians,
  71580. const float toRadians,
  71581. const bool startAsNewSubPath) throw()
  71582. {
  71583. if (radiusX > 0.0f && radiusY > 0.0f)
  71584. {
  71585. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71586. float angle = fromRadians;
  71587. if (startAsNewSubPath)
  71588. {
  71589. float x = centreX + radiusX * sinf (angle);
  71590. float y = centreY - radiusY * cosf (angle);
  71591. if (rotationOfEllipse != 0)
  71592. rotation.transformPoint (x, y);
  71593. startNewSubPath (x, y);
  71594. }
  71595. if (fromRadians < toRadians)
  71596. {
  71597. if (startAsNewSubPath)
  71598. angle += ellipseAngularIncrement;
  71599. while (angle < toRadians)
  71600. {
  71601. float x = centreX + radiusX * sinf (angle);
  71602. float y = centreY - radiusY * cosf (angle);
  71603. if (rotationOfEllipse != 0)
  71604. rotation.transformPoint (x, y);
  71605. lineTo (x, y);
  71606. angle += ellipseAngularIncrement;
  71607. }
  71608. }
  71609. else
  71610. {
  71611. if (startAsNewSubPath)
  71612. angle -= ellipseAngularIncrement;
  71613. while (angle > toRadians)
  71614. {
  71615. float x = centreX + radiusX * sinf (angle);
  71616. float y = centreY - radiusY * cosf (angle);
  71617. if (rotationOfEllipse != 0)
  71618. rotation.transformPoint (x, y);
  71619. lineTo (x, y);
  71620. angle -= ellipseAngularIncrement;
  71621. }
  71622. }
  71623. float x = centreX + radiusX * sinf (toRadians);
  71624. float y = centreY - radiusY * cosf (toRadians);
  71625. if (rotationOfEllipse != 0)
  71626. rotation.transformPoint (x, y);
  71627. lineTo (x, y);
  71628. }
  71629. }
  71630. void Path::addPieSegment (const float x, const float y,
  71631. const float width, const float height,
  71632. const float fromRadians,
  71633. const float toRadians,
  71634. const float innerCircleProportionalSize)
  71635. {
  71636. float hw = width * 0.5f;
  71637. float hh = height * 0.5f;
  71638. const float centreX = x + hw;
  71639. const float centreY = y + hh;
  71640. startNewSubPath (centreX + hw * sinf (fromRadians),
  71641. centreY - hh * cosf (fromRadians));
  71642. addArc (x, y, width, height, fromRadians, toRadians);
  71643. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71644. {
  71645. closeSubPath();
  71646. if (innerCircleProportionalSize > 0)
  71647. {
  71648. hw *= innerCircleProportionalSize;
  71649. hh *= innerCircleProportionalSize;
  71650. startNewSubPath (centreX + hw * sinf (toRadians),
  71651. centreY - hh * cosf (toRadians));
  71652. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71653. toRadians, fromRadians);
  71654. }
  71655. }
  71656. else
  71657. {
  71658. if (innerCircleProportionalSize > 0)
  71659. {
  71660. hw *= innerCircleProportionalSize;
  71661. hh *= innerCircleProportionalSize;
  71662. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71663. toRadians, fromRadians);
  71664. }
  71665. else
  71666. {
  71667. lineTo (centreX, centreY);
  71668. }
  71669. }
  71670. closeSubPath();
  71671. }
  71672. static void perpendicularOffset (const float x1, const float y1,
  71673. const float x2, const float y2,
  71674. const float offsetX, const float offsetY,
  71675. float& resultX, float& resultY) throw()
  71676. {
  71677. const float dx = x2 - x1;
  71678. const float dy = y2 - y1;
  71679. const float len = juce_hypotf (dx, dy);
  71680. if (len == 0)
  71681. {
  71682. resultX = x1;
  71683. resultY = y1;
  71684. }
  71685. else
  71686. {
  71687. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  71688. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  71689. }
  71690. }
  71691. void Path::addLineSegment (const float startX, const float startY,
  71692. const float endX, const float endY,
  71693. float lineThickness) throw()
  71694. {
  71695. lineThickness *= 0.5f;
  71696. float x, y;
  71697. perpendicularOffset (startX, startY, endX, endY,
  71698. 0, lineThickness, x, y);
  71699. startNewSubPath (x, y);
  71700. perpendicularOffset (startX, startY, endX, endY,
  71701. 0, -lineThickness, x, y);
  71702. lineTo (x, y);
  71703. perpendicularOffset (endX, endY, startX, startY,
  71704. 0, lineThickness, x, y);
  71705. lineTo (x, y);
  71706. perpendicularOffset (endX, endY, startX, startY,
  71707. 0, -lineThickness, x, y);
  71708. lineTo (x, y);
  71709. closeSubPath();
  71710. }
  71711. void Path::addArrow (const float startX, const float startY,
  71712. const float endX, const float endY,
  71713. float lineThickness,
  71714. float arrowheadWidth,
  71715. float arrowheadLength) throw()
  71716. {
  71717. lineThickness *= 0.5f;
  71718. arrowheadWidth *= 0.5f;
  71719. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71720. startY - endY));
  71721. float x, y;
  71722. perpendicularOffset (startX, startY, endX, endY,
  71723. 0, lineThickness, x, y);
  71724. startNewSubPath (x, y);
  71725. perpendicularOffset (startX, startY, endX, endY,
  71726. 0, -lineThickness, x, y);
  71727. lineTo (x, y);
  71728. perpendicularOffset (endX, endY, startX, startY,
  71729. arrowheadLength, lineThickness, x, y);
  71730. lineTo (x, y);
  71731. perpendicularOffset (endX, endY, startX, startY,
  71732. arrowheadLength, arrowheadWidth, x, y);
  71733. lineTo (x, y);
  71734. perpendicularOffset (endX, endY, startX, startY,
  71735. 0, 0, x, y);
  71736. lineTo (x, y);
  71737. perpendicularOffset (endX, endY, startX, startY,
  71738. arrowheadLength, -arrowheadWidth, x, y);
  71739. lineTo (x, y);
  71740. perpendicularOffset (endX, endY, startX, startY,
  71741. arrowheadLength, -lineThickness, x, y);
  71742. lineTo (x, y);
  71743. closeSubPath();
  71744. }
  71745. void Path::addStar (const float centreX,
  71746. const float centreY,
  71747. const int numberOfPoints,
  71748. const float innerRadius,
  71749. const float outerRadius,
  71750. const float startAngle)
  71751. {
  71752. jassert (numberOfPoints > 1); // this would be silly.
  71753. if (numberOfPoints > 1)
  71754. {
  71755. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71756. for (int i = 0; i < numberOfPoints; ++i)
  71757. {
  71758. float angle = startAngle + i * angleBetweenPoints;
  71759. const float x = centreX + outerRadius * sinf (angle);
  71760. const float y = centreY - outerRadius * cosf (angle);
  71761. if (i == 0)
  71762. startNewSubPath (x, y);
  71763. else
  71764. lineTo (x, y);
  71765. angle += angleBetweenPoints * 0.5f;
  71766. lineTo (centreX + innerRadius * sinf (angle),
  71767. centreY - innerRadius * cosf (angle));
  71768. }
  71769. closeSubPath();
  71770. }
  71771. }
  71772. void Path::addBubble (float x, float y,
  71773. float w, float h,
  71774. float cs,
  71775. float tipX,
  71776. float tipY,
  71777. int whichSide,
  71778. float arrowPos,
  71779. float arrowWidth)
  71780. {
  71781. if (w > 1.0f && h > 1.0f)
  71782. {
  71783. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71784. const float cs2 = 2.0f * cs;
  71785. startNewSubPath (x + cs, y);
  71786. if (whichSide == 0)
  71787. {
  71788. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71789. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71790. lineTo (arrowX1, y);
  71791. lineTo (tipX, tipY);
  71792. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71793. }
  71794. lineTo (x + w - cs, y);
  71795. if (cs > 0.0f)
  71796. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71797. if (whichSide == 3)
  71798. {
  71799. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71800. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71801. lineTo (x + w, arrowY1);
  71802. lineTo (tipX, tipY);
  71803. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71804. }
  71805. lineTo (x + w, y + h - cs);
  71806. if (cs > 0.0f)
  71807. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71808. if (whichSide == 2)
  71809. {
  71810. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71811. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71812. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71813. lineTo (tipX, tipY);
  71814. lineTo (arrowX1, y + h);
  71815. }
  71816. lineTo (x + cs, y + h);
  71817. if (cs > 0.0f)
  71818. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71819. if (whichSide == 1)
  71820. {
  71821. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71822. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71823. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71824. lineTo (tipX, tipY);
  71825. lineTo (x, arrowY1);
  71826. }
  71827. lineTo (x, y + cs);
  71828. if (cs > 0.0f)
  71829. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - ellipseAngularIncrement);
  71830. closeSubPath();
  71831. }
  71832. }
  71833. void Path::addPath (const Path& other) throw()
  71834. {
  71835. int i = 0;
  71836. while (i < other.numElements)
  71837. {
  71838. const float type = other.data.elements [i++];
  71839. if (type == moveMarker)
  71840. {
  71841. startNewSubPath (other.data.elements [i],
  71842. other.data.elements [i + 1]);
  71843. i += 2;
  71844. }
  71845. else if (type == lineMarker)
  71846. {
  71847. lineTo (other.data.elements [i],
  71848. other.data.elements [i + 1]);
  71849. i += 2;
  71850. }
  71851. else if (type == quadMarker)
  71852. {
  71853. quadraticTo (other.data.elements [i],
  71854. other.data.elements [i + 1],
  71855. other.data.elements [i + 2],
  71856. other.data.elements [i + 3]);
  71857. i += 4;
  71858. }
  71859. else if (type == cubicMarker)
  71860. {
  71861. cubicTo (other.data.elements [i],
  71862. other.data.elements [i + 1],
  71863. other.data.elements [i + 2],
  71864. other.data.elements [i + 3],
  71865. other.data.elements [i + 4],
  71866. other.data.elements [i + 5]);
  71867. i += 6;
  71868. }
  71869. else if (type == closeSubPathMarker)
  71870. {
  71871. closeSubPath();
  71872. }
  71873. else
  71874. {
  71875. // something's gone wrong with the element list!
  71876. jassertfalse
  71877. }
  71878. }
  71879. }
  71880. void Path::addPath (const Path& other,
  71881. const AffineTransform& transformToApply) throw()
  71882. {
  71883. int i = 0;
  71884. while (i < other.numElements)
  71885. {
  71886. const float type = other.data.elements [i++];
  71887. if (type == closeSubPathMarker)
  71888. {
  71889. closeSubPath();
  71890. }
  71891. else
  71892. {
  71893. float x = other.data.elements [i++];
  71894. float y = other.data.elements [i++];
  71895. transformToApply.transformPoint (x, y);
  71896. if (type == moveMarker)
  71897. {
  71898. startNewSubPath (x, y);
  71899. }
  71900. else if (type == lineMarker)
  71901. {
  71902. lineTo (x, y);
  71903. }
  71904. else if (type == quadMarker)
  71905. {
  71906. float x2 = other.data.elements [i++];
  71907. float y2 = other.data.elements [i++];
  71908. transformToApply.transformPoint (x2, y2);
  71909. quadraticTo (x, y, x2, y2);
  71910. }
  71911. else if (type == cubicMarker)
  71912. {
  71913. float x2 = other.data.elements [i++];
  71914. float y2 = other.data.elements [i++];
  71915. float x3 = other.data.elements [i++];
  71916. float y3 = other.data.elements [i++];
  71917. transformToApply.transformPoint (x2, y2);
  71918. transformToApply.transformPoint (x3, y3);
  71919. cubicTo (x, y, x2, y2, x3, y3);
  71920. }
  71921. else
  71922. {
  71923. // something's gone wrong with the element list!
  71924. jassertfalse
  71925. }
  71926. }
  71927. }
  71928. }
  71929. void Path::applyTransform (const AffineTransform& transform) throw()
  71930. {
  71931. int i = 0;
  71932. pathYMin = pathXMin = 0;
  71933. pathYMax = pathXMax = 0;
  71934. bool setMaxMin = false;
  71935. while (i < numElements)
  71936. {
  71937. const float type = data.elements [i++];
  71938. if (type == moveMarker)
  71939. {
  71940. transform.transformPoint (data.elements [i],
  71941. data.elements [i + 1]);
  71942. if (setMaxMin)
  71943. {
  71944. pathXMin = jmin (pathXMin, data.elements [i]);
  71945. pathXMax = jmax (pathXMax, data.elements [i]);
  71946. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71947. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71948. }
  71949. else
  71950. {
  71951. pathXMin = pathXMax = data.elements [i];
  71952. pathYMin = pathYMax = data.elements [i + 1];
  71953. setMaxMin = true;
  71954. }
  71955. i += 2;
  71956. }
  71957. else if (type == lineMarker)
  71958. {
  71959. transform.transformPoint (data.elements [i],
  71960. data.elements [i + 1]);
  71961. pathXMin = jmin (pathXMin, data.elements [i]);
  71962. pathXMax = jmax (pathXMax, data.elements [i]);
  71963. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71964. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71965. i += 2;
  71966. }
  71967. else if (type == quadMarker)
  71968. {
  71969. transform.transformPoint (data.elements [i],
  71970. data.elements [i + 1]);
  71971. transform.transformPoint (data.elements [i + 2],
  71972. data.elements [i + 3]);
  71973. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71974. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71975. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71976. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71977. i += 4;
  71978. }
  71979. else if (type == cubicMarker)
  71980. {
  71981. transform.transformPoint (data.elements [i],
  71982. data.elements [i + 1]);
  71983. transform.transformPoint (data.elements [i + 2],
  71984. data.elements [i + 3]);
  71985. transform.transformPoint (data.elements [i + 4],
  71986. data.elements [i + 5]);
  71987. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71988. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71989. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71990. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71991. i += 6;
  71992. }
  71993. }
  71994. }
  71995. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71996. const float w, const float h,
  71997. const bool preserveProportions,
  71998. const Justification& justification) const throw()
  71999. {
  72000. Rectangle<float> bounds (getBounds());
  72001. if (preserveProportions)
  72002. {
  72003. if (w <= 0 || h <= 0 || bounds.isEmpty())
  72004. return AffineTransform::identity;
  72005. float newW, newH;
  72006. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  72007. if (srcRatio > h / w)
  72008. {
  72009. newW = h / srcRatio;
  72010. newH = h;
  72011. }
  72012. else
  72013. {
  72014. newW = w;
  72015. newH = w * srcRatio;
  72016. }
  72017. float newXCentre = x;
  72018. float newYCentre = y;
  72019. if (justification.testFlags (Justification::left))
  72020. newXCentre += newW * 0.5f;
  72021. else if (justification.testFlags (Justification::right))
  72022. newXCentre += w - newW * 0.5f;
  72023. else
  72024. newXCentre += w * 0.5f;
  72025. if (justification.testFlags (Justification::top))
  72026. newYCentre += newH * 0.5f;
  72027. else if (justification.testFlags (Justification::bottom))
  72028. newYCentre += h - newH * 0.5f;
  72029. else
  72030. newYCentre += h * 0.5f;
  72031. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  72032. bounds.getHeight() * -0.5f - bounds.getY())
  72033. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  72034. .translated (newXCentre, newYCentre);
  72035. }
  72036. else
  72037. {
  72038. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  72039. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  72040. .translated (x, y);
  72041. }
  72042. }
  72043. bool Path::contains (const float x, const float y, const float tolerence) const throw()
  72044. {
  72045. if (x <= pathXMin || x >= pathXMax
  72046. || y <= pathYMin || y >= pathYMax)
  72047. return false;
  72048. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  72049. int positiveCrossings = 0;
  72050. int negativeCrossings = 0;
  72051. while (i.next())
  72052. {
  72053. if ((i.y1 <= y && i.y2 > y)
  72054. || (i.y2 <= y && i.y1 > y))
  72055. {
  72056. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  72057. if (intersectX <= x)
  72058. {
  72059. if (i.y1 < i.y2)
  72060. ++positiveCrossings;
  72061. else
  72062. ++negativeCrossings;
  72063. }
  72064. }
  72065. }
  72066. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  72067. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  72068. }
  72069. bool Path::intersectsLine (const float x1, const float y1,
  72070. const float x2, const float y2,
  72071. const float tolerence) throw()
  72072. {
  72073. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  72074. const Line line1 (x1, y1, x2, y2);
  72075. while (i.next())
  72076. {
  72077. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  72078. float ix, iy;
  72079. if (line1.intersects (line2, ix, iy))
  72080. return true;
  72081. }
  72082. return false;
  72083. }
  72084. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const throw()
  72085. {
  72086. if (cornerRadius <= 0.01f)
  72087. return *this;
  72088. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  72089. int n = 0;
  72090. bool lastWasLine = false, firstWasLine = false;
  72091. Path p;
  72092. while (n < numElements)
  72093. {
  72094. const float type = data.elements [n++];
  72095. if (type == moveMarker)
  72096. {
  72097. indexOfPathStart = p.numElements;
  72098. indexOfPathStartThis = n - 1;
  72099. const float x = data.elements [n++];
  72100. const float y = data.elements [n++];
  72101. p.startNewSubPath (x, y);
  72102. lastWasLine = false;
  72103. firstWasLine = (data.elements [n] == lineMarker);
  72104. }
  72105. else if (type == lineMarker || type == closeSubPathMarker)
  72106. {
  72107. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  72108. if (type == lineMarker)
  72109. {
  72110. endX = data.elements [n++];
  72111. endY = data.elements [n++];
  72112. if (n > 8)
  72113. {
  72114. startX = data.elements [n - 8];
  72115. startY = data.elements [n - 7];
  72116. joinX = data.elements [n - 5];
  72117. joinY = data.elements [n - 4];
  72118. }
  72119. }
  72120. else
  72121. {
  72122. endX = data.elements [indexOfPathStartThis + 1];
  72123. endY = data.elements [indexOfPathStartThis + 2];
  72124. if (n > 6)
  72125. {
  72126. startX = data.elements [n - 6];
  72127. startY = data.elements [n - 5];
  72128. joinX = data.elements [n - 3];
  72129. joinY = data.elements [n - 2];
  72130. }
  72131. }
  72132. if (lastWasLine)
  72133. {
  72134. const double len1 = juce_hypot (startX - joinX,
  72135. startY - joinY);
  72136. if (len1 > 0)
  72137. {
  72138. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72139. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72140. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72141. }
  72142. const double len2 = juce_hypot (endX - joinX,
  72143. endY - joinY);
  72144. if (len2 > 0)
  72145. {
  72146. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72147. p.quadraticTo (joinX, joinY,
  72148. (float) (joinX + (endX - joinX) * propNeeded),
  72149. (float) (joinY + (endY - joinY) * propNeeded));
  72150. }
  72151. p.lineTo (endX, endY);
  72152. }
  72153. else if (type == lineMarker)
  72154. {
  72155. p.lineTo (endX, endY);
  72156. lastWasLine = true;
  72157. }
  72158. if (type == closeSubPathMarker)
  72159. {
  72160. if (firstWasLine)
  72161. {
  72162. startX = data.elements [n - 3];
  72163. startY = data.elements [n - 2];
  72164. joinX = endX;
  72165. joinY = endY;
  72166. endX = data.elements [indexOfPathStartThis + 4];
  72167. endY = data.elements [indexOfPathStartThis + 5];
  72168. const double len1 = juce_hypot (startX - joinX,
  72169. startY - joinY);
  72170. if (len1 > 0)
  72171. {
  72172. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72173. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72174. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72175. }
  72176. const double len2 = juce_hypot (endX - joinX,
  72177. endY - joinY);
  72178. if (len2 > 0)
  72179. {
  72180. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72181. endX = (float) (joinX + (endX - joinX) * propNeeded);
  72182. endY = (float) (joinY + (endY - joinY) * propNeeded);
  72183. p.quadraticTo (joinX, joinY, endX, endY);
  72184. p.data.elements [indexOfPathStart + 1] = endX;
  72185. p.data.elements [indexOfPathStart + 2] = endY;
  72186. }
  72187. }
  72188. p.closeSubPath();
  72189. }
  72190. }
  72191. else if (type == quadMarker)
  72192. {
  72193. lastWasLine = false;
  72194. const float x1 = data.elements [n++];
  72195. const float y1 = data.elements [n++];
  72196. const float x2 = data.elements [n++];
  72197. const float y2 = data.elements [n++];
  72198. p.quadraticTo (x1, y1, x2, y2);
  72199. }
  72200. else if (type == cubicMarker)
  72201. {
  72202. lastWasLine = false;
  72203. const float x1 = data.elements [n++];
  72204. const float y1 = data.elements [n++];
  72205. const float x2 = data.elements [n++];
  72206. const float y2 = data.elements [n++];
  72207. const float x3 = data.elements [n++];
  72208. const float y3 = data.elements [n++];
  72209. p.cubicTo (x1, y1, x2, y2, x3, y3);
  72210. }
  72211. }
  72212. return p;
  72213. }
  72214. void Path::loadPathFromStream (InputStream& source)
  72215. {
  72216. while (! source.isExhausted())
  72217. {
  72218. switch (source.readByte())
  72219. {
  72220. case 'm':
  72221. {
  72222. const float x = source.readFloat();
  72223. const float y = source.readFloat();
  72224. startNewSubPath (x, y);
  72225. break;
  72226. }
  72227. case 'l':
  72228. {
  72229. const float x = source.readFloat();
  72230. const float y = source.readFloat();
  72231. lineTo (x, y);
  72232. break;
  72233. }
  72234. case 'q':
  72235. {
  72236. const float x1 = source.readFloat();
  72237. const float y1 = source.readFloat();
  72238. const float x2 = source.readFloat();
  72239. const float y2 = source.readFloat();
  72240. quadraticTo (x1, y1, x2, y2);
  72241. break;
  72242. }
  72243. case 'b':
  72244. {
  72245. const float x1 = source.readFloat();
  72246. const float y1 = source.readFloat();
  72247. const float x2 = source.readFloat();
  72248. const float y2 = source.readFloat();
  72249. const float x3 = source.readFloat();
  72250. const float y3 = source.readFloat();
  72251. cubicTo (x1, y1, x2, y2, x3, y3);
  72252. break;
  72253. }
  72254. case 'c':
  72255. closeSubPath();
  72256. break;
  72257. case 'n':
  72258. useNonZeroWinding = true;
  72259. break;
  72260. case 'z':
  72261. useNonZeroWinding = false;
  72262. break;
  72263. case 'e':
  72264. return; // end of path marker
  72265. default:
  72266. jassertfalse // illegal char in the stream
  72267. break;
  72268. }
  72269. }
  72270. }
  72271. void Path::loadPathFromData (const unsigned char* const data,
  72272. const int numberOfBytes) throw()
  72273. {
  72274. MemoryInputStream in ((const char*) data, numberOfBytes, false);
  72275. loadPathFromStream (in);
  72276. }
  72277. void Path::writePathToStream (OutputStream& dest) const
  72278. {
  72279. dest.writeByte ((useNonZeroWinding) ? 'n' : 'z');
  72280. int i = 0;
  72281. while (i < numElements)
  72282. {
  72283. const float type = data.elements [i++];
  72284. if (type == moveMarker)
  72285. {
  72286. dest.writeByte ('m');
  72287. dest.writeFloat (data.elements [i++]);
  72288. dest.writeFloat (data.elements [i++]);
  72289. }
  72290. else if (type == lineMarker)
  72291. {
  72292. dest.writeByte ('l');
  72293. dest.writeFloat (data.elements [i++]);
  72294. dest.writeFloat (data.elements [i++]);
  72295. }
  72296. else if (type == quadMarker)
  72297. {
  72298. dest.writeByte ('q');
  72299. dest.writeFloat (data.elements [i++]);
  72300. dest.writeFloat (data.elements [i++]);
  72301. dest.writeFloat (data.elements [i++]);
  72302. dest.writeFloat (data.elements [i++]);
  72303. }
  72304. else if (type == cubicMarker)
  72305. {
  72306. dest.writeByte ('b');
  72307. dest.writeFloat (data.elements [i++]);
  72308. dest.writeFloat (data.elements [i++]);
  72309. dest.writeFloat (data.elements [i++]);
  72310. dest.writeFloat (data.elements [i++]);
  72311. dest.writeFloat (data.elements [i++]);
  72312. dest.writeFloat (data.elements [i++]);
  72313. }
  72314. else if (type == closeSubPathMarker)
  72315. {
  72316. dest.writeByte ('c');
  72317. }
  72318. }
  72319. dest.writeByte ('e'); // marks the end-of-path
  72320. }
  72321. const String Path::toString() const
  72322. {
  72323. MemoryOutputStream s (2048, 2048);
  72324. if (! useNonZeroWinding)
  72325. s << "a ";
  72326. int i = 0;
  72327. float lastMarker = 0.0f;
  72328. while (i < numElements)
  72329. {
  72330. const float marker = data.elements [i++];
  72331. char markerChar = 0;
  72332. int numCoords = 0;
  72333. if (marker == moveMarker)
  72334. {
  72335. markerChar = 'm';
  72336. numCoords = 2;
  72337. }
  72338. else if (marker == lineMarker)
  72339. {
  72340. markerChar = 'l';
  72341. numCoords = 2;
  72342. }
  72343. else if (marker == quadMarker)
  72344. {
  72345. markerChar = 'q';
  72346. numCoords = 4;
  72347. }
  72348. else if (marker == cubicMarker)
  72349. {
  72350. markerChar = 'c';
  72351. numCoords = 6;
  72352. }
  72353. else
  72354. {
  72355. jassert (marker == closeSubPathMarker);
  72356. markerChar = 'z';
  72357. }
  72358. if (marker != lastMarker)
  72359. {
  72360. s << markerChar << ' ';
  72361. lastMarker = marker;
  72362. }
  72363. while (--numCoords >= 0 && i < numElements)
  72364. {
  72365. String n (data.elements [i++], 3);
  72366. if (n.endsWithChar (T('0')))
  72367. {
  72368. do
  72369. {
  72370. n = n.dropLastCharacters (1);
  72371. } while (n.endsWithChar (T('0')));
  72372. if (n.endsWithChar (T('.')))
  72373. n = n.dropLastCharacters (1);
  72374. }
  72375. s << n << ' ';
  72376. }
  72377. }
  72378. const char* const result = (const char*) s.getData();
  72379. size_t len = s.getDataSize();
  72380. while (len > 0 && CharacterFunctions::isWhitespace (result [len - 1]))
  72381. --len;
  72382. return String (result, len);
  72383. }
  72384. static const String nextToken (const tchar*& t)
  72385. {
  72386. while (CharacterFunctions::isWhitespace (*t))
  72387. ++t;
  72388. const tchar* const start = t;
  72389. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  72390. ++t;
  72391. const int length = (int) (t - start);
  72392. while (CharacterFunctions::isWhitespace (*t))
  72393. ++t;
  72394. return String (start, length);
  72395. }
  72396. void Path::restoreFromString (const String& stringVersion)
  72397. {
  72398. clear();
  72399. setUsingNonZeroWinding (true);
  72400. const tchar* t = stringVersion;
  72401. tchar marker = T('m');
  72402. int numValues = 2;
  72403. float values [6];
  72404. while (*t != 0)
  72405. {
  72406. const String token (nextToken (t));
  72407. const tchar firstChar = token[0];
  72408. int startNum = 0;
  72409. if (firstChar == T('m') || firstChar == T('l'))
  72410. {
  72411. marker = firstChar;
  72412. numValues = 2;
  72413. }
  72414. else if (firstChar == T('q'))
  72415. {
  72416. marker = firstChar;
  72417. numValues = 4;
  72418. }
  72419. else if (firstChar == T('c'))
  72420. {
  72421. marker = firstChar;
  72422. numValues = 6;
  72423. }
  72424. else if (firstChar == T('z'))
  72425. {
  72426. marker = firstChar;
  72427. numValues = 0;
  72428. }
  72429. else if (firstChar == T('a'))
  72430. {
  72431. setUsingNonZeroWinding (false);
  72432. continue;
  72433. }
  72434. else
  72435. {
  72436. ++startNum;
  72437. values [0] = token.getFloatValue();
  72438. }
  72439. for (int i = startNum; i < numValues; ++i)
  72440. values [i] = nextToken (t).getFloatValue();
  72441. switch (marker)
  72442. {
  72443. case T('m'):
  72444. startNewSubPath (values[0], values[1]);
  72445. break;
  72446. case T('l'):
  72447. lineTo (values[0], values[1]);
  72448. break;
  72449. case T('q'):
  72450. quadraticTo (values[0], values[1],
  72451. values[2], values[3]);
  72452. break;
  72453. case T('c'):
  72454. cubicTo (values[0], values[1],
  72455. values[2], values[3],
  72456. values[4], values[5]);
  72457. break;
  72458. case T('z'):
  72459. closeSubPath();
  72460. break;
  72461. default:
  72462. jassertfalse // illegal string format?
  72463. break;
  72464. }
  72465. }
  72466. }
  72467. Path::Iterator::Iterator (const Path& path_)
  72468. : path (path_),
  72469. index (0)
  72470. {
  72471. }
  72472. Path::Iterator::~Iterator()
  72473. {
  72474. }
  72475. bool Path::Iterator::next()
  72476. {
  72477. const float* const elements = path.data.elements;
  72478. if (index < path.numElements)
  72479. {
  72480. const float type = elements [index++];
  72481. if (type == moveMarker)
  72482. {
  72483. elementType = startNewSubPath;
  72484. x1 = elements [index++];
  72485. y1 = elements [index++];
  72486. }
  72487. else if (type == lineMarker)
  72488. {
  72489. elementType = lineTo;
  72490. x1 = elements [index++];
  72491. y1 = elements [index++];
  72492. }
  72493. else if (type == quadMarker)
  72494. {
  72495. elementType = quadraticTo;
  72496. x1 = elements [index++];
  72497. y1 = elements [index++];
  72498. x2 = elements [index++];
  72499. y2 = elements [index++];
  72500. }
  72501. else if (type == cubicMarker)
  72502. {
  72503. elementType = cubicTo;
  72504. x1 = elements [index++];
  72505. y1 = elements [index++];
  72506. x2 = elements [index++];
  72507. y2 = elements [index++];
  72508. x3 = elements [index++];
  72509. y3 = elements [index++];
  72510. }
  72511. else if (type == closeSubPathMarker)
  72512. {
  72513. elementType = closePath;
  72514. }
  72515. return true;
  72516. }
  72517. return false;
  72518. }
  72519. END_JUCE_NAMESPACE
  72520. /*** End of inlined file: juce_Path.cpp ***/
  72521. /*** Start of inlined file: juce_PathIterator.cpp ***/
  72522. BEGIN_JUCE_NAMESPACE
  72523. #if JUCE_MSVC
  72524. #pragma optimize ("t", on)
  72525. #endif
  72526. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  72527. const AffineTransform& transform_,
  72528. float tolerence_) throw()
  72529. : x2 (0),
  72530. y2 (0),
  72531. closesSubPath (false),
  72532. subPathIndex (-1),
  72533. path (path_),
  72534. transform (transform_),
  72535. points (path_.data.elements),
  72536. tolerence (tolerence_ * tolerence_),
  72537. subPathCloseX (0),
  72538. subPathCloseY (0),
  72539. stackBase (32),
  72540. index (0),
  72541. stackSize (32)
  72542. {
  72543. isIdentityTransform = transform.isIdentity();
  72544. stackPos = stackBase;
  72545. }
  72546. PathFlatteningIterator::~PathFlatteningIterator() throw()
  72547. {
  72548. }
  72549. bool PathFlatteningIterator::next() throw()
  72550. {
  72551. x1 = x2;
  72552. y1 = y2;
  72553. float x3 = 0;
  72554. float y3 = 0;
  72555. float x4 = 0;
  72556. float y4 = 0;
  72557. float type;
  72558. for (;;)
  72559. {
  72560. if (stackPos == stackBase)
  72561. {
  72562. if (index >= path.numElements)
  72563. {
  72564. return false;
  72565. }
  72566. else
  72567. {
  72568. type = points [index++];
  72569. if (type != Path::closeSubPathMarker)
  72570. {
  72571. x2 = points [index++];
  72572. y2 = points [index++];
  72573. if (! isIdentityTransform)
  72574. transform.transformPoint (x2, y2);
  72575. if (type == Path::quadMarker)
  72576. {
  72577. x3 = points [index++];
  72578. y3 = points [index++];
  72579. if (! isIdentityTransform)
  72580. transform.transformPoint (x3, y3);
  72581. }
  72582. else if (type == Path::cubicMarker)
  72583. {
  72584. x3 = points [index++];
  72585. y3 = points [index++];
  72586. x4 = points [index++];
  72587. y4 = points [index++];
  72588. if (! isIdentityTransform)
  72589. {
  72590. transform.transformPoint (x3, y3);
  72591. transform.transformPoint (x4, y4);
  72592. }
  72593. }
  72594. }
  72595. }
  72596. }
  72597. else
  72598. {
  72599. type = *--stackPos;
  72600. if (type != Path::closeSubPathMarker)
  72601. {
  72602. x2 = *--stackPos;
  72603. y2 = *--stackPos;
  72604. if (type == Path::quadMarker)
  72605. {
  72606. x3 = *--stackPos;
  72607. y3 = *--stackPos;
  72608. }
  72609. else if (type == Path::cubicMarker)
  72610. {
  72611. x3 = *--stackPos;
  72612. y3 = *--stackPos;
  72613. x4 = *--stackPos;
  72614. y4 = *--stackPos;
  72615. }
  72616. }
  72617. }
  72618. if (type == Path::lineMarker)
  72619. {
  72620. ++subPathIndex;
  72621. closesSubPath = (stackPos == stackBase)
  72622. && (index < path.numElements)
  72623. && (points [index] == Path::closeSubPathMarker)
  72624. && x2 == subPathCloseX
  72625. && y2 == subPathCloseY;
  72626. return true;
  72627. }
  72628. else if (type == Path::quadMarker)
  72629. {
  72630. const int offset = (int) (stackPos - stackBase);
  72631. if (offset >= stackSize - 10)
  72632. {
  72633. stackSize <<= 1;
  72634. stackBase.realloc (stackSize);
  72635. stackPos = stackBase + offset;
  72636. }
  72637. const float dx1 = x1 - x2;
  72638. const float dy1 = y1 - y2;
  72639. const float dx2 = x2 - x3;
  72640. const float dy2 = y2 - y3;
  72641. const float m1x = (x1 + x2) * 0.5f;
  72642. const float m1y = (y1 + y2) * 0.5f;
  72643. const float m2x = (x2 + x3) * 0.5f;
  72644. const float m2y = (y2 + y3) * 0.5f;
  72645. const float m3x = (m1x + m2x) * 0.5f;
  72646. const float m3y = (m1y + m2y) * 0.5f;
  72647. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72648. {
  72649. *stackPos++ = y3;
  72650. *stackPos++ = x3;
  72651. *stackPos++ = m2y;
  72652. *stackPos++ = m2x;
  72653. *stackPos++ = Path::quadMarker;
  72654. *stackPos++ = m3y;
  72655. *stackPos++ = m3x;
  72656. *stackPos++ = m1y;
  72657. *stackPos++ = m1x;
  72658. *stackPos++ = Path::quadMarker;
  72659. }
  72660. else
  72661. {
  72662. *stackPos++ = y3;
  72663. *stackPos++ = x3;
  72664. *stackPos++ = Path::lineMarker;
  72665. *stackPos++ = m3y;
  72666. *stackPos++ = m3x;
  72667. *stackPos++ = Path::lineMarker;
  72668. }
  72669. jassert (stackPos < stackBase + stackSize);
  72670. }
  72671. else if (type == Path::cubicMarker)
  72672. {
  72673. const int offset = (int) (stackPos - stackBase);
  72674. if (offset >= stackSize - 16)
  72675. {
  72676. stackSize <<= 1;
  72677. stackBase.realloc (stackSize);
  72678. stackPos = stackBase + offset;
  72679. }
  72680. const float dx1 = x1 - x2;
  72681. const float dy1 = y1 - y2;
  72682. const float dx2 = x2 - x3;
  72683. const float dy2 = y2 - y3;
  72684. const float dx3 = x3 - x4;
  72685. const float dy3 = y3 - y4;
  72686. const float m1x = (x1 + x2) * 0.5f;
  72687. const float m1y = (y1 + y2) * 0.5f;
  72688. const float m2x = (x3 + x2) * 0.5f;
  72689. const float m2y = (y3 + y2) * 0.5f;
  72690. const float m3x = (x3 + x4) * 0.5f;
  72691. const float m3y = (y3 + y4) * 0.5f;
  72692. const float m4x = (m1x + m2x) * 0.5f;
  72693. const float m4y = (m1y + m2y) * 0.5f;
  72694. const float m5x = (m3x + m2x) * 0.5f;
  72695. const float m5y = (m3y + m2y) * 0.5f;
  72696. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72697. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72698. {
  72699. *stackPos++ = y4;
  72700. *stackPos++ = x4;
  72701. *stackPos++ = m3y;
  72702. *stackPos++ = m3x;
  72703. *stackPos++ = m5y;
  72704. *stackPos++ = m5x;
  72705. *stackPos++ = Path::cubicMarker;
  72706. *stackPos++ = (m4y + m5y) * 0.5f;
  72707. *stackPos++ = (m4x + m5x) * 0.5f;
  72708. *stackPos++ = m4y;
  72709. *stackPos++ = m4x;
  72710. *stackPos++ = m1y;
  72711. *stackPos++ = m1x;
  72712. *stackPos++ = Path::cubicMarker;
  72713. }
  72714. else
  72715. {
  72716. *stackPos++ = y4;
  72717. *stackPos++ = x4;
  72718. *stackPos++ = Path::lineMarker;
  72719. *stackPos++ = m5y;
  72720. *stackPos++ = m5x;
  72721. *stackPos++ = Path::lineMarker;
  72722. *stackPos++ = m4y;
  72723. *stackPos++ = m4x;
  72724. *stackPos++ = Path::lineMarker;
  72725. }
  72726. }
  72727. else if (type == Path::closeSubPathMarker)
  72728. {
  72729. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72730. {
  72731. x1 = x2;
  72732. y1 = y2;
  72733. x2 = subPathCloseX;
  72734. y2 = subPathCloseY;
  72735. closesSubPath = true;
  72736. return true;
  72737. }
  72738. }
  72739. else
  72740. {
  72741. jassert (type == Path::moveMarker);
  72742. subPathIndex = -1;
  72743. subPathCloseX = x1 = x2;
  72744. subPathCloseY = y1 = y2;
  72745. }
  72746. }
  72747. }
  72748. END_JUCE_NAMESPACE
  72749. /*** End of inlined file: juce_PathIterator.cpp ***/
  72750. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72751. BEGIN_JUCE_NAMESPACE
  72752. PathStrokeType::PathStrokeType (const float strokeThickness,
  72753. const JointStyle jointStyle_,
  72754. const EndCapStyle endStyle_) throw()
  72755. : thickness (strokeThickness),
  72756. jointStyle (jointStyle_),
  72757. endStyle (endStyle_)
  72758. {
  72759. }
  72760. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72761. : thickness (other.thickness),
  72762. jointStyle (other.jointStyle),
  72763. endStyle (other.endStyle)
  72764. {
  72765. }
  72766. const PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72767. {
  72768. thickness = other.thickness;
  72769. jointStyle = other.jointStyle;
  72770. endStyle = other.endStyle;
  72771. return *this;
  72772. }
  72773. PathStrokeType::~PathStrokeType() throw()
  72774. {
  72775. }
  72776. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72777. {
  72778. return thickness == other.thickness
  72779. && jointStyle == other.jointStyle
  72780. && endStyle == other.endStyle;
  72781. }
  72782. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72783. {
  72784. return ! operator== (other);
  72785. }
  72786. static bool lineIntersection (const float x1, const float y1,
  72787. const float x2, const float y2,
  72788. const float x3, const float y3,
  72789. const float x4, const float y4,
  72790. float& intersectionX,
  72791. float& intersectionY,
  72792. float& distanceBeyondLine1EndSquared) throw()
  72793. {
  72794. if (x2 != x3 || y2 != y3)
  72795. {
  72796. const float dx1 = x2 - x1;
  72797. const float dy1 = y2 - y1;
  72798. const float dx2 = x4 - x3;
  72799. const float dy2 = y4 - y3;
  72800. const float divisor = dx1 * dy2 - dx2 * dy1;
  72801. if (divisor == 0)
  72802. {
  72803. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72804. {
  72805. if (dy1 == 0 && dy2 != 0)
  72806. {
  72807. const float along = (y1 - y3) / dy2;
  72808. intersectionX = x3 + along * dx2;
  72809. intersectionY = y1;
  72810. distanceBeyondLine1EndSquared = intersectionX - x2;
  72811. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72812. if ((x2 > x1) == (intersectionX < x2))
  72813. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72814. return along >= 0 && along <= 1.0f;
  72815. }
  72816. else if (dy2 == 0 && dy1 != 0)
  72817. {
  72818. const float along = (y3 - y1) / dy1;
  72819. intersectionX = x1 + along * dx1;
  72820. intersectionY = y3;
  72821. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72822. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72823. if (along < 1.0f)
  72824. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72825. return along >= 0 && along <= 1.0f;
  72826. }
  72827. else if (dx1 == 0 && dx2 != 0)
  72828. {
  72829. const float along = (x1 - x3) / dx2;
  72830. intersectionX = x1;
  72831. intersectionY = y3 + along * dy2;
  72832. distanceBeyondLine1EndSquared = intersectionY - y2;
  72833. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72834. if ((y2 > y1) == (intersectionY < y2))
  72835. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72836. return along >= 0 && along <= 1.0f;
  72837. }
  72838. else if (dx2 == 0 && dx1 != 0)
  72839. {
  72840. const float along = (x3 - x1) / dx1;
  72841. intersectionX = x3;
  72842. intersectionY = y1 + along * dy1;
  72843. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72844. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72845. if (along < 1.0f)
  72846. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72847. return along >= 0 && along <= 1.0f;
  72848. }
  72849. }
  72850. intersectionX = 0.5f * (x2 + x3);
  72851. intersectionY = 0.5f * (y2 + y3);
  72852. distanceBeyondLine1EndSquared = 0.0f;
  72853. return false;
  72854. }
  72855. else
  72856. {
  72857. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72858. intersectionX = x1 + along1 * dx1;
  72859. intersectionY = y1 + along1 * dy1;
  72860. if (along1 >= 0 && along1 <= 1.0f)
  72861. {
  72862. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72863. if (along2 >= 0 && along2 <= divisor)
  72864. {
  72865. distanceBeyondLine1EndSquared = 0.0f;
  72866. return true;
  72867. }
  72868. }
  72869. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72870. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72871. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72872. if (along1 < 1.0f)
  72873. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72874. return false;
  72875. }
  72876. }
  72877. intersectionX = x2;
  72878. intersectionY = y2;
  72879. distanceBeyondLine1EndSquared = 0.0f;
  72880. return true;
  72881. }
  72882. // part of stroke drawing stuff
  72883. static void addEdgeAndJoint (Path& destPath,
  72884. const PathStrokeType::JointStyle style,
  72885. const float maxMiterExtensionSquared, const float width,
  72886. const float x1, const float y1,
  72887. const float x2, const float y2,
  72888. const float x3, const float y3,
  72889. const float x4, const float y4,
  72890. const float midX, const float midY) throw()
  72891. {
  72892. if (style == PathStrokeType::beveled
  72893. || (x3 == x4 && y3 == y4)
  72894. || (x1 == x2 && y1 == y2))
  72895. {
  72896. destPath.lineTo (x2, y2);
  72897. destPath.lineTo (x3, y3);
  72898. }
  72899. else
  72900. {
  72901. float jx, jy, distanceBeyondLine1EndSquared;
  72902. // if they intersect, use this point..
  72903. if (lineIntersection (x1, y1, x2, y2,
  72904. x3, y3, x4, y4,
  72905. jx, jy, distanceBeyondLine1EndSquared))
  72906. {
  72907. destPath.lineTo (jx, jy);
  72908. }
  72909. else
  72910. {
  72911. if (style == PathStrokeType::mitered)
  72912. {
  72913. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72914. && distanceBeyondLine1EndSquared > 0.0f)
  72915. {
  72916. destPath.lineTo (jx, jy);
  72917. }
  72918. else
  72919. {
  72920. // the end sticks out too far, so just use a blunt joint
  72921. destPath.lineTo (x2, y2);
  72922. destPath.lineTo (x3, y3);
  72923. }
  72924. }
  72925. else
  72926. {
  72927. // curved joints
  72928. float angle1 = atan2f (x2 - midX, y2 - midY);
  72929. float angle2 = atan2f (x3 - midX, y3 - midY);
  72930. const float angleIncrement = 0.1f;
  72931. destPath.lineTo (x2, y2);
  72932. if (fabs (angle1 - angle2) > angleIncrement)
  72933. {
  72934. if (angle2 > angle1 + float_Pi
  72935. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72936. {
  72937. if (angle2 > angle1)
  72938. angle2 -= float_Pi * 2.0f;
  72939. jassert (angle1 <= angle2 + float_Pi);
  72940. angle1 -= angleIncrement;
  72941. while (angle1 > angle2)
  72942. {
  72943. destPath.lineTo (midX + width * sinf (angle1),
  72944. midY + width * cosf (angle1));
  72945. angle1 -= angleIncrement;
  72946. }
  72947. }
  72948. else
  72949. {
  72950. if (angle1 > angle2)
  72951. angle1 -= float_Pi * 2.0f;
  72952. jassert (angle1 >= angle2 - float_Pi);
  72953. angle1 += angleIncrement;
  72954. while (angle1 < angle2)
  72955. {
  72956. destPath.lineTo (midX + width * sinf (angle1),
  72957. midY + width * cosf (angle1));
  72958. angle1 += angleIncrement;
  72959. }
  72960. }
  72961. }
  72962. destPath.lineTo (x3, y3);
  72963. }
  72964. }
  72965. }
  72966. }
  72967. static inline void addLineEnd (Path& destPath,
  72968. const PathStrokeType::EndCapStyle style,
  72969. const float x1, const float y1,
  72970. const float x2, const float y2,
  72971. const float width) throw()
  72972. {
  72973. if (style == PathStrokeType::butt)
  72974. {
  72975. destPath.lineTo (x2, y2);
  72976. }
  72977. else
  72978. {
  72979. float offx1, offy1, offx2, offy2;
  72980. float dx = x2 - x1;
  72981. float dy = y2 - y1;
  72982. const float len = juce_hypotf (dx, dy);
  72983. if (len == 0)
  72984. {
  72985. offx1 = offx2 = x1;
  72986. offy1 = offy2 = y1;
  72987. }
  72988. else
  72989. {
  72990. const float offset = width / len;
  72991. dx *= offset;
  72992. dy *= offset;
  72993. offx1 = x1 + dy;
  72994. offy1 = y1 - dx;
  72995. offx2 = x2 + dy;
  72996. offy2 = y2 - dx;
  72997. }
  72998. if (style == PathStrokeType::square)
  72999. {
  73000. // sqaure ends
  73001. destPath.lineTo (offx1, offy1);
  73002. destPath.lineTo (offx2, offy2);
  73003. destPath.lineTo (x2, y2);
  73004. }
  73005. else
  73006. {
  73007. // rounded ends
  73008. const float midx = (offx1 + offx2) * 0.5f;
  73009. const float midy = (offy1 + offy2) * 0.5f;
  73010. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  73011. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  73012. midx, midy);
  73013. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  73014. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  73015. x2, y2);
  73016. }
  73017. }
  73018. }
  73019. struct LineSection
  73020. {
  73021. LineSection() {}
  73022. LineSection (int) {}
  73023. float x1, y1, x2, y2; // original line
  73024. float lx1, ly1, lx2, ly2; // the left-hand stroke
  73025. float rx1, ry1, rx2, ry2; // the right-hand stroke
  73026. };
  73027. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  73028. const bool isClosed,
  73029. const float width, const float maxMiterExtensionSquared,
  73030. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle) throw()
  73031. {
  73032. jassert (subPath.size() > 0);
  73033. const LineSection& firstLine = subPath.getReference (0);
  73034. float lastX1 = firstLine.lx1;
  73035. float lastY1 = firstLine.ly1;
  73036. float lastX2 = firstLine.lx2;
  73037. float lastY2 = firstLine.ly2;
  73038. if (isClosed)
  73039. {
  73040. destPath.startNewSubPath (lastX1, lastY1);
  73041. }
  73042. else
  73043. {
  73044. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  73045. addLineEnd (destPath, endStyle,
  73046. firstLine.rx2, firstLine.ry2,
  73047. lastX1, lastY1,
  73048. width);
  73049. }
  73050. int i;
  73051. for (i = 1; i < subPath.size(); ++i)
  73052. {
  73053. const LineSection& l = subPath.getReference (i);
  73054. addEdgeAndJoint (destPath, jointStyle,
  73055. maxMiterExtensionSquared, width,
  73056. lastX1, lastY1, lastX2, lastY2,
  73057. l.lx1, l.ly1, l.lx2, l.ly2,
  73058. l.x1, l.y1);
  73059. lastX1 = l.lx1;
  73060. lastY1 = l.ly1;
  73061. lastX2 = l.lx2;
  73062. lastY2 = l.ly2;
  73063. }
  73064. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  73065. if (isClosed)
  73066. {
  73067. const LineSection& l = subPath.getReference (0);
  73068. addEdgeAndJoint (destPath, jointStyle,
  73069. maxMiterExtensionSquared, width,
  73070. lastX1, lastY1, lastX2, lastY2,
  73071. l.lx1, l.ly1, l.lx2, l.ly2,
  73072. l.x1, l.y1);
  73073. destPath.closeSubPath();
  73074. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  73075. }
  73076. else
  73077. {
  73078. destPath.lineTo (lastX2, lastY2);
  73079. addLineEnd (destPath, endStyle,
  73080. lastX2, lastY2,
  73081. lastLine.rx1, lastLine.ry1,
  73082. width);
  73083. }
  73084. lastX1 = lastLine.rx1;
  73085. lastY1 = lastLine.ry1;
  73086. lastX2 = lastLine.rx2;
  73087. lastY2 = lastLine.ry2;
  73088. for (i = subPath.size() - 1; --i >= 0;)
  73089. {
  73090. const LineSection& l = subPath.getReference (i);
  73091. addEdgeAndJoint (destPath, jointStyle,
  73092. maxMiterExtensionSquared, width,
  73093. lastX1, lastY1, lastX2, lastY2,
  73094. l.rx1, l.ry1, l.rx2, l.ry2,
  73095. l.x2, l.y2);
  73096. lastX1 = l.rx1;
  73097. lastY1 = l.ry1;
  73098. lastX2 = l.rx2;
  73099. lastY2 = l.ry2;
  73100. }
  73101. if (isClosed)
  73102. {
  73103. addEdgeAndJoint (destPath, jointStyle,
  73104. maxMiterExtensionSquared, width,
  73105. lastX1, lastY1, lastX2, lastY2,
  73106. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  73107. lastLine.x2, lastLine.y2);
  73108. }
  73109. else
  73110. {
  73111. // do the last line
  73112. destPath.lineTo (lastX2, lastY2);
  73113. }
  73114. destPath.closeSubPath();
  73115. }
  73116. void PathStrokeType::createStrokedPath (Path& destPath,
  73117. const Path& source,
  73118. const AffineTransform& transform,
  73119. const float extraAccuracy) const throw()
  73120. {
  73121. if (thickness <= 0)
  73122. {
  73123. destPath.clear();
  73124. return;
  73125. }
  73126. const Path* sourcePath = &source;
  73127. Path temp;
  73128. if (sourcePath == &destPath)
  73129. {
  73130. destPath.swapWithPath (temp);
  73131. sourcePath = &temp;
  73132. }
  73133. else
  73134. {
  73135. destPath.clear();
  73136. }
  73137. destPath.setUsingNonZeroWinding (true);
  73138. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  73139. const float width = 0.5f * thickness;
  73140. // Iterate the path, creating a list of the
  73141. // left/right-hand lines along either side of it...
  73142. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  73143. Array <LineSection> subPath;
  73144. LineSection l;
  73145. l.x1 = 0;
  73146. l.y1 = 0;
  73147. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  73148. while (it.next())
  73149. {
  73150. if (it.subPathIndex == 0)
  73151. {
  73152. if (subPath.size() > 0)
  73153. {
  73154. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73155. subPath.clearQuick();
  73156. }
  73157. l.x1 = it.x1;
  73158. l.y1 = it.y1;
  73159. }
  73160. l.x2 = it.x2;
  73161. l.y2 = it.y2;
  73162. float dx = l.x2 - l.x1;
  73163. float dy = l.y2 - l.y1;
  73164. const float hypotSquared = dx*dx + dy*dy;
  73165. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  73166. {
  73167. const float len = sqrtf (hypotSquared);
  73168. if (len == 0)
  73169. {
  73170. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  73171. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  73172. }
  73173. else
  73174. {
  73175. const float offset = width / len;
  73176. dx *= offset;
  73177. dy *= offset;
  73178. l.rx2 = l.x1 - dy;
  73179. l.ry2 = l.y1 + dx;
  73180. l.lx1 = l.x1 + dy;
  73181. l.ly1 = l.y1 - dx;
  73182. l.lx2 = l.x2 + dy;
  73183. l.ly2 = l.y2 - dx;
  73184. l.rx1 = l.x2 - dy;
  73185. l.ry1 = l.y2 + dx;
  73186. }
  73187. subPath.add (l);
  73188. if (it.closesSubPath)
  73189. {
  73190. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73191. subPath.clearQuick();
  73192. }
  73193. else
  73194. {
  73195. l.x1 = it.x2;
  73196. l.y1 = it.y2;
  73197. }
  73198. }
  73199. }
  73200. if (subPath.size() > 0)
  73201. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73202. }
  73203. void PathStrokeType::createDashedStroke (Path& destPath,
  73204. const Path& sourcePath,
  73205. const float* dashLengths,
  73206. int numDashLengths,
  73207. const AffineTransform& transform,
  73208. const float extraAccuracy) const throw()
  73209. {
  73210. if (thickness <= 0)
  73211. return;
  73212. // this should really be an even number..
  73213. jassert ((numDashLengths & 1) == 0);
  73214. Path newDestPath;
  73215. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  73216. bool first = true;
  73217. int dashNum = 0;
  73218. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  73219. float dx = 0.0f, dy = 0.0f;
  73220. for (;;)
  73221. {
  73222. const bool isSolid = ((dashNum & 1) == 0);
  73223. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  73224. jassert (dashLen > 0); // must be a positive increment!
  73225. if (dashLen <= 0)
  73226. break;
  73227. pos += dashLen;
  73228. while (pos > lineEndPos)
  73229. {
  73230. if (! it.next())
  73231. {
  73232. if (isSolid && ! first)
  73233. newDestPath.lineTo (it.x2, it.y2);
  73234. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  73235. return;
  73236. }
  73237. if (isSolid && ! first)
  73238. newDestPath.lineTo (it.x1, it.y1);
  73239. else
  73240. newDestPath.startNewSubPath (it.x1, it.y1);
  73241. dx = it.x2 - it.x1;
  73242. dy = it.y2 - it.y1;
  73243. lineLen = juce_hypotf (dx, dy);
  73244. lineEndPos += lineLen;
  73245. first = it.closesSubPath;
  73246. }
  73247. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  73248. if (isSolid)
  73249. newDestPath.lineTo (it.x1 + dx * alpha,
  73250. it.y1 + dy * alpha);
  73251. else
  73252. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  73253. it.y1 + dy * alpha);
  73254. }
  73255. }
  73256. END_JUCE_NAMESPACE
  73257. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  73258. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  73259. BEGIN_JUCE_NAMESPACE
  73260. PositionedRectangle::PositionedRectangle() throw()
  73261. : x (0.0),
  73262. y (0.0),
  73263. w (0.0),
  73264. h (0.0),
  73265. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73266. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73267. wMode (absoluteSize),
  73268. hMode (absoluteSize)
  73269. {
  73270. }
  73271. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  73272. : x (other.x),
  73273. y (other.y),
  73274. w (other.w),
  73275. h (other.h),
  73276. xMode (other.xMode),
  73277. yMode (other.yMode),
  73278. wMode (other.wMode),
  73279. hMode (other.hMode)
  73280. {
  73281. }
  73282. const PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  73283. {
  73284. x = other.x;
  73285. y = other.y;
  73286. w = other.w;
  73287. h = other.h;
  73288. xMode = other.xMode;
  73289. yMode = other.yMode;
  73290. wMode = other.wMode;
  73291. hMode = other.hMode;
  73292. return *this;
  73293. }
  73294. PositionedRectangle::~PositionedRectangle() throw()
  73295. {
  73296. }
  73297. const bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  73298. {
  73299. return x == other.x
  73300. && y == other.y
  73301. && w == other.w
  73302. && h == other.h
  73303. && xMode == other.xMode
  73304. && yMode == other.yMode
  73305. && wMode == other.wMode
  73306. && hMode == other.hMode;
  73307. }
  73308. const bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  73309. {
  73310. return ! operator== (other);
  73311. }
  73312. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  73313. {
  73314. StringArray tokens;
  73315. tokens.addTokens (stringVersion, false);
  73316. decodePosString (tokens [0], xMode, x);
  73317. decodePosString (tokens [1], yMode, y);
  73318. decodeSizeString (tokens [2], wMode, w);
  73319. decodeSizeString (tokens [3], hMode, h);
  73320. }
  73321. const String PositionedRectangle::toString() const throw()
  73322. {
  73323. String s;
  73324. s.preallocateStorage (12);
  73325. addPosDescription (s, xMode, x);
  73326. s << T(' ');
  73327. addPosDescription (s, yMode, y);
  73328. s << T(' ');
  73329. addSizeDescription (s, wMode, w);
  73330. s << T(' ');
  73331. addSizeDescription (s, hMode, h);
  73332. return s;
  73333. }
  73334. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  73335. {
  73336. jassert (! target.isEmpty());
  73337. double x_, y_, w_, h_;
  73338. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73339. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73340. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  73341. roundToInt (w_), roundToInt (h_));
  73342. }
  73343. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  73344. double& x_, double& y_,
  73345. double& w_, double& h_) const throw()
  73346. {
  73347. jassert (! target.isEmpty());
  73348. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73349. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73350. }
  73351. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  73352. {
  73353. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  73354. }
  73355. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  73356. const Rectangle<int>& target) throw()
  73357. {
  73358. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  73359. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  73360. }
  73361. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  73362. const double newW, const double newH,
  73363. const Rectangle<int>& target) throw()
  73364. {
  73365. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  73366. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  73367. }
  73368. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  73369. {
  73370. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  73371. updateFrom (comp.getBounds(), Rectangle<int>());
  73372. else
  73373. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  73374. }
  73375. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  73376. {
  73377. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73378. }
  73379. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  73380. {
  73381. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  73382. | absoluteFromParentBottomRight
  73383. | absoluteFromParentCentre
  73384. | proportionOfParentSize));
  73385. }
  73386. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  73387. {
  73388. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73389. }
  73390. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  73391. {
  73392. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  73393. | absoluteFromParentBottomRight
  73394. | absoluteFromParentCentre
  73395. | proportionOfParentSize));
  73396. }
  73397. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  73398. {
  73399. return (SizeMode) wMode;
  73400. }
  73401. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  73402. {
  73403. return (SizeMode) hMode;
  73404. }
  73405. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  73406. const PositionMode xMode_,
  73407. const AnchorPoint yAnchor,
  73408. const PositionMode yMode_,
  73409. const SizeMode widthMode,
  73410. const SizeMode heightMode,
  73411. const Rectangle<int>& target) throw()
  73412. {
  73413. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  73414. {
  73415. double tx, tw;
  73416. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  73417. xMode = (uint8) (xAnchor | xMode_);
  73418. wMode = (uint8) widthMode;
  73419. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  73420. }
  73421. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  73422. {
  73423. double ty, th;
  73424. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  73425. yMode = (uint8) (yAnchor | yMode_);
  73426. hMode = (uint8) heightMode;
  73427. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  73428. }
  73429. }
  73430. bool PositionedRectangle::isPositionAbsolute() const throw()
  73431. {
  73432. return xMode == absoluteFromParentTopLeft
  73433. && yMode == absoluteFromParentTopLeft
  73434. && wMode == absoluteSize
  73435. && hMode == absoluteSize;
  73436. }
  73437. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  73438. {
  73439. if ((mode & proportionOfParentSize) != 0)
  73440. {
  73441. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73442. }
  73443. else
  73444. {
  73445. s << (roundToInt (value * 100.0) / 100.0);
  73446. if ((mode & absoluteFromParentBottomRight) != 0)
  73447. s << T('R');
  73448. else if ((mode & absoluteFromParentCentre) != 0)
  73449. s << T('C');
  73450. }
  73451. if ((mode & anchorAtRightOrBottom) != 0)
  73452. s << T('r');
  73453. else if ((mode & anchorAtCentre) != 0)
  73454. s << T('c');
  73455. }
  73456. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  73457. {
  73458. if (mode == proportionalSize)
  73459. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73460. else if (mode == parentSizeMinusAbsolute)
  73461. s << (roundToInt (value * 100.0) / 100.0) << T('M');
  73462. else
  73463. s << (roundToInt (value * 100.0) / 100.0);
  73464. }
  73465. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  73466. {
  73467. if (s.containsChar (T('r')))
  73468. mode = anchorAtRightOrBottom;
  73469. else if (s.containsChar (T('c')))
  73470. mode = anchorAtCentre;
  73471. else
  73472. mode = anchorAtLeftOrTop;
  73473. if (s.containsChar (T('%')))
  73474. {
  73475. mode |= proportionOfParentSize;
  73476. value = s.removeCharacters (T("%rcRC")).getDoubleValue() / 100.0;
  73477. }
  73478. else
  73479. {
  73480. if (s.containsChar (T('R')))
  73481. mode |= absoluteFromParentBottomRight;
  73482. else if (s.containsChar (T('C')))
  73483. mode |= absoluteFromParentCentre;
  73484. else
  73485. mode |= absoluteFromParentTopLeft;
  73486. value = s.removeCharacters (T("rcRC")).getDoubleValue();
  73487. }
  73488. }
  73489. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  73490. {
  73491. if (s.containsChar (T('%')))
  73492. {
  73493. mode = proportionalSize;
  73494. value = s.upToFirstOccurrenceOf (T("%"), false, false).getDoubleValue() / 100.0;
  73495. }
  73496. else if (s.containsChar (T('M')))
  73497. {
  73498. mode = parentSizeMinusAbsolute;
  73499. value = s.getDoubleValue();
  73500. }
  73501. else
  73502. {
  73503. mode = absoluteSize;
  73504. value = s.getDoubleValue();
  73505. }
  73506. }
  73507. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  73508. const double x_, const double w_,
  73509. const uint8 xMode_, const uint8 wMode_,
  73510. const int parentPos,
  73511. const int parentSize) const throw()
  73512. {
  73513. if (wMode_ == proportionalSize)
  73514. wOut = roundToInt (w_ * parentSize);
  73515. else if (wMode_ == parentSizeMinusAbsolute)
  73516. wOut = jmax (0, parentSize - roundToInt (w_));
  73517. else
  73518. wOut = roundToInt (w_);
  73519. if ((xMode_ & proportionOfParentSize) != 0)
  73520. xOut = parentPos + x_ * parentSize;
  73521. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73522. xOut = (parentPos + parentSize) - x_;
  73523. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73524. xOut = x_ + (parentPos + parentSize / 2);
  73525. else
  73526. xOut = x_ + parentPos;
  73527. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73528. xOut -= wOut;
  73529. else if ((xMode_ & anchorAtCentre) != 0)
  73530. xOut -= wOut / 2;
  73531. }
  73532. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  73533. double x_, const double w_,
  73534. const uint8 xMode_, const uint8 wMode_,
  73535. const int parentPos,
  73536. const int parentSize) const throw()
  73537. {
  73538. if (wMode_ == proportionalSize)
  73539. {
  73540. if (parentSize > 0)
  73541. wOut = w_ / parentSize;
  73542. }
  73543. else if (wMode_ == parentSizeMinusAbsolute)
  73544. wOut = parentSize - w_;
  73545. else
  73546. wOut = w_;
  73547. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73548. x_ += w_;
  73549. else if ((xMode_ & anchorAtCentre) != 0)
  73550. x_ += w_ / 2;
  73551. if ((xMode_ & proportionOfParentSize) != 0)
  73552. {
  73553. if (parentSize > 0)
  73554. xOut = (x_ - parentPos) / parentSize;
  73555. }
  73556. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73557. xOut = (parentPos + parentSize) - x_;
  73558. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73559. xOut = x_ - (parentPos + parentSize / 2);
  73560. else
  73561. xOut = x_ - parentPos;
  73562. }
  73563. END_JUCE_NAMESPACE
  73564. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  73565. /*** Start of inlined file: juce_RectangleList.cpp ***/
  73566. BEGIN_JUCE_NAMESPACE
  73567. RectangleList::RectangleList() throw()
  73568. {
  73569. }
  73570. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  73571. {
  73572. if (! rect.isEmpty())
  73573. rects.add (rect);
  73574. }
  73575. RectangleList::RectangleList (const RectangleList& other) throw()
  73576. : rects (other.rects)
  73577. {
  73578. }
  73579. const RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73580. {
  73581. rects = other.rects;
  73582. return *this;
  73583. }
  73584. RectangleList::~RectangleList() throw()
  73585. {
  73586. }
  73587. void RectangleList::clear() throw()
  73588. {
  73589. rects.clearQuick();
  73590. }
  73591. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  73592. {
  73593. if (((unsigned int) index) < (unsigned int) rects.size())
  73594. return rects.getReference (index);
  73595. return Rectangle<int>();
  73596. }
  73597. bool RectangleList::isEmpty() const throw()
  73598. {
  73599. return rects.size() == 0;
  73600. }
  73601. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73602. : current (0),
  73603. owner (list),
  73604. index (list.rects.size())
  73605. {
  73606. }
  73607. RectangleList::Iterator::~Iterator() throw()
  73608. {
  73609. }
  73610. bool RectangleList::Iterator::next() throw()
  73611. {
  73612. if (--index >= 0)
  73613. {
  73614. current = & (owner.rects.getReference (index));
  73615. return true;
  73616. }
  73617. return false;
  73618. }
  73619. void RectangleList::add (const Rectangle<int>& rect) throw()
  73620. {
  73621. if (! rect.isEmpty())
  73622. {
  73623. if (rects.size() == 0)
  73624. {
  73625. rects.add (rect);
  73626. }
  73627. else
  73628. {
  73629. bool anyOverlaps = false;
  73630. int i;
  73631. for (i = rects.size(); --i >= 0;)
  73632. {
  73633. Rectangle<int>& ourRect = rects.getReference (i);
  73634. if (rect.intersects (ourRect))
  73635. {
  73636. if (rect.contains (ourRect))
  73637. rects.remove (i);
  73638. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73639. anyOverlaps = true;
  73640. }
  73641. }
  73642. if (anyOverlaps && rects.size() > 0)
  73643. {
  73644. RectangleList r (rect);
  73645. for (i = rects.size(); --i >= 0;)
  73646. {
  73647. const Rectangle<int>& ourRect = rects.getReference (i);
  73648. if (rect.intersects (ourRect))
  73649. {
  73650. r.subtract (ourRect);
  73651. if (r.rects.size() == 0)
  73652. return;
  73653. }
  73654. }
  73655. for (i = r.getNumRectangles(); --i >= 0;)
  73656. rects.add (r.rects.getReference (i));
  73657. }
  73658. else
  73659. {
  73660. rects.add (rect);
  73661. }
  73662. }
  73663. }
  73664. }
  73665. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73666. {
  73667. rects.add (rect);
  73668. }
  73669. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73670. {
  73671. if (rects.size() == 0)
  73672. {
  73673. if (w > 0 && h > 0)
  73674. rects.add (Rectangle<int> (x, y, w, h));
  73675. }
  73676. else
  73677. {
  73678. add (Rectangle<int> (x, y, w, h));
  73679. }
  73680. }
  73681. void RectangleList::add (const RectangleList& other) throw()
  73682. {
  73683. for (int i = 0; i < other.rects.size(); ++i)
  73684. add (other.rects.getReference (i));
  73685. }
  73686. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73687. {
  73688. const int originalNumRects = rects.size();
  73689. if (originalNumRects > 0)
  73690. {
  73691. const int x1 = rect.x;
  73692. const int y1 = rect.y;
  73693. const int x2 = x1 + rect.w;
  73694. const int y2 = y1 + rect.h;
  73695. for (int i = getNumRectangles(); --i >= 0;)
  73696. {
  73697. Rectangle<int>& r = rects.getReference (i);
  73698. const int rx1 = r.x;
  73699. const int ry1 = r.y;
  73700. const int rx2 = rx1 + r.w;
  73701. const int ry2 = ry1 + r.h;
  73702. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73703. {
  73704. if (x1 > rx1 && x1 < rx2)
  73705. {
  73706. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73707. {
  73708. r.w = x1 - rx1;
  73709. }
  73710. else
  73711. {
  73712. r.x = x1;
  73713. r.w = rx2 - x1;
  73714. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73715. i += 2;
  73716. }
  73717. }
  73718. else if (x2 > rx1 && x2 < rx2)
  73719. {
  73720. r.x = x2;
  73721. r.w = rx2 - x2;
  73722. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73723. {
  73724. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73725. i += 2;
  73726. }
  73727. }
  73728. else if (y1 > ry1 && y1 < ry2)
  73729. {
  73730. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73731. {
  73732. r.h = y1 - ry1;
  73733. }
  73734. else
  73735. {
  73736. r.y = y1;
  73737. r.h = ry2 - y1;
  73738. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73739. i += 2;
  73740. }
  73741. }
  73742. else if (y2 > ry1 && y2 < ry2)
  73743. {
  73744. r.y = y2;
  73745. r.h = ry2 - y2;
  73746. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73747. {
  73748. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73749. i += 2;
  73750. }
  73751. }
  73752. else
  73753. {
  73754. rects.remove (i);
  73755. }
  73756. }
  73757. }
  73758. if (rects.size() > originalNumRects + 10)
  73759. consolidate();
  73760. }
  73761. }
  73762. void RectangleList::subtract (const RectangleList& otherList) throw()
  73763. {
  73764. for (int i = otherList.rects.size(); --i >= 0;)
  73765. subtract (otherList.rects.getReference (i));
  73766. }
  73767. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73768. {
  73769. bool notEmpty = false;
  73770. if (rect.isEmpty())
  73771. {
  73772. clear();
  73773. }
  73774. else
  73775. {
  73776. for (int i = rects.size(); --i >= 0;)
  73777. {
  73778. Rectangle<int>& r = rects.getReference (i);
  73779. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73780. rects.remove (i);
  73781. else
  73782. notEmpty = true;
  73783. }
  73784. }
  73785. return notEmpty;
  73786. }
  73787. bool RectangleList::clipTo (const RectangleList& other) throw()
  73788. {
  73789. if (rects.size() == 0)
  73790. return false;
  73791. RectangleList result;
  73792. for (int j = 0; j < rects.size(); ++j)
  73793. {
  73794. const Rectangle<int>& rect = rects.getReference (j);
  73795. for (int i = other.rects.size(); --i >= 0;)
  73796. {
  73797. Rectangle<int> r (other.rects.getReference (i));
  73798. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73799. result.rects.add (r);
  73800. }
  73801. }
  73802. swapWith (result);
  73803. return ! isEmpty();
  73804. }
  73805. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73806. {
  73807. destRegion.clear();
  73808. if (! rect.isEmpty())
  73809. {
  73810. for (int i = rects.size(); --i >= 0;)
  73811. {
  73812. Rectangle<int> r (rects.getReference (i));
  73813. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73814. destRegion.rects.add (r);
  73815. }
  73816. }
  73817. return destRegion.rects.size() > 0;
  73818. }
  73819. void RectangleList::swapWith (RectangleList& otherList) throw()
  73820. {
  73821. rects.swapWithArray (otherList.rects);
  73822. }
  73823. void RectangleList::consolidate() throw()
  73824. {
  73825. int i;
  73826. for (i = 0; i < getNumRectangles() - 1; ++i)
  73827. {
  73828. Rectangle<int>& r = rects.getReference (i);
  73829. const int rx1 = r.x;
  73830. const int ry1 = r.y;
  73831. const int rx2 = rx1 + r.w;
  73832. const int ry2 = ry1 + r.h;
  73833. for (int j = rects.size(); --j > i;)
  73834. {
  73835. Rectangle<int>& r2 = rects.getReference (j);
  73836. const int jrx1 = r2.x;
  73837. const int jry1 = r2.y;
  73838. const int jrx2 = jrx1 + r2.w;
  73839. const int jry2 = jry1 + r2.h;
  73840. // if the vertical edges of any blocks are touching and their horizontals don't
  73841. // line up, split them horizontally..
  73842. if (jrx1 == rx2 || jrx2 == rx1)
  73843. {
  73844. if (jry1 > ry1 && jry1 < ry2)
  73845. {
  73846. r.h = jry1 - ry1;
  73847. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73848. i = -1;
  73849. break;
  73850. }
  73851. if (jry2 > ry1 && jry2 < ry2)
  73852. {
  73853. r.h = jry2 - ry1;
  73854. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73855. i = -1;
  73856. break;
  73857. }
  73858. else if (ry1 > jry1 && ry1 < jry2)
  73859. {
  73860. r2.h = ry1 - jry1;
  73861. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73862. i = -1;
  73863. break;
  73864. }
  73865. else if (ry2 > jry1 && ry2 < jry2)
  73866. {
  73867. r2.h = ry2 - jry1;
  73868. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73869. i = -1;
  73870. break;
  73871. }
  73872. }
  73873. }
  73874. }
  73875. for (i = 0; i < rects.size() - 1; ++i)
  73876. {
  73877. Rectangle<int>& r = rects.getReference (i);
  73878. for (int j = rects.size(); --j > i;)
  73879. {
  73880. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73881. {
  73882. rects.remove (j);
  73883. i = -1;
  73884. break;
  73885. }
  73886. }
  73887. }
  73888. }
  73889. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73890. {
  73891. for (int i = getNumRectangles(); --i >= 0;)
  73892. if (rects.getReference (i).contains (x, y))
  73893. return true;
  73894. return false;
  73895. }
  73896. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73897. {
  73898. if (rects.size() > 1)
  73899. {
  73900. RectangleList r (rectangleToCheck);
  73901. for (int i = rects.size(); --i >= 0;)
  73902. {
  73903. r.subtract (rects.getReference (i));
  73904. if (r.rects.size() == 0)
  73905. return true;
  73906. }
  73907. }
  73908. else if (rects.size() > 0)
  73909. {
  73910. return rects.getReference (0).contains (rectangleToCheck);
  73911. }
  73912. return false;
  73913. }
  73914. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73915. {
  73916. for (int i = rects.size(); --i >= 0;)
  73917. if (rects.getReference (i).intersects (rectangleToCheck))
  73918. return true;
  73919. return false;
  73920. }
  73921. bool RectangleList::intersects (const RectangleList& other) const throw()
  73922. {
  73923. for (int i = rects.size(); --i >= 0;)
  73924. if (other.intersectsRectangle (rects.getReference (i)))
  73925. return true;
  73926. return false;
  73927. }
  73928. const Rectangle<int> RectangleList::getBounds() const throw()
  73929. {
  73930. if (rects.size() <= 1)
  73931. {
  73932. if (rects.size() == 0)
  73933. return Rectangle<int>();
  73934. else
  73935. return rects.getReference (0);
  73936. }
  73937. else
  73938. {
  73939. const Rectangle<int>& r = rects.getReference (0);
  73940. int minX = r.x;
  73941. int minY = r.y;
  73942. int maxX = minX + r.w;
  73943. int maxY = minY + r.h;
  73944. for (int i = rects.size(); --i > 0;)
  73945. {
  73946. const Rectangle<int>& r2 = rects.getReference (i);
  73947. minX = jmin (minX, r2.x);
  73948. minY = jmin (minY, r2.y);
  73949. maxX = jmax (maxX, r2.getRight());
  73950. maxY = jmax (maxY, r2.getBottom());
  73951. }
  73952. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73953. }
  73954. }
  73955. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73956. {
  73957. for (int i = rects.size(); --i >= 0;)
  73958. {
  73959. Rectangle<int>& r = rects.getReference (i);
  73960. r.x += dx;
  73961. r.y += dy;
  73962. }
  73963. }
  73964. const Path RectangleList::toPath() const throw()
  73965. {
  73966. Path p;
  73967. for (int i = rects.size(); --i >= 0;)
  73968. {
  73969. const Rectangle<int>& r = rects.getReference (i);
  73970. p.addRectangle ((float) r.x,
  73971. (float) r.y,
  73972. (float) r.w,
  73973. (float) r.h);
  73974. }
  73975. return p;
  73976. }
  73977. END_JUCE_NAMESPACE
  73978. /*** End of inlined file: juce_RectangleList.cpp ***/
  73979. /*** Start of inlined file: juce_Image.cpp ***/
  73980. BEGIN_JUCE_NAMESPACE
  73981. static const int fullAlphaThreshold = 253;
  73982. Image::Image (const PixelFormat format_,
  73983. const int imageWidth_,
  73984. const int imageHeight_)
  73985. : format (format_),
  73986. imageWidth (imageWidth_),
  73987. imageHeight (imageHeight_),
  73988. imageData (0)
  73989. {
  73990. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73991. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73992. // actual image will be at least 1x1.
  73993. }
  73994. Image::Image (const PixelFormat format_,
  73995. const int imageWidth_,
  73996. const int imageHeight_,
  73997. const bool clearImage)
  73998. : format (format_),
  73999. imageWidth (imageWidth_),
  74000. imageHeight (imageHeight_)
  74001. {
  74002. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  74003. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  74004. // actual image will be at least 1x1.
  74005. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  74006. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  74007. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  74008. imageData = imageDataAllocated;
  74009. }
  74010. Image::Image (const Image& other)
  74011. : format (other.format),
  74012. imageWidth (other.imageWidth),
  74013. imageHeight (other.imageHeight)
  74014. {
  74015. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  74016. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  74017. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  74018. imageData = imageDataAllocated;
  74019. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  74020. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  74021. }
  74022. Image::~Image()
  74023. {
  74024. }
  74025. LowLevelGraphicsContext* Image::createLowLevelContext()
  74026. {
  74027. return new LowLevelGraphicsSoftwareRenderer (*this);
  74028. }
  74029. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  74030. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  74031. lineStride (image.lineStride),
  74032. pixelStride (image.pixelStride),
  74033. width (w),
  74034. height (h)
  74035. {
  74036. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  74037. }
  74038. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  74039. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  74040. lineStride (image.lineStride),
  74041. pixelStride (image.pixelStride),
  74042. width (w),
  74043. height (h)
  74044. {
  74045. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  74046. }
  74047. Image::BitmapData::~BitmapData()
  74048. {
  74049. }
  74050. void Image::setPixelData (int x, int y, int w, int h,
  74051. const uint8* sourcePixelData, int sourceLineStride)
  74052. {
  74053. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  74054. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  74055. {
  74056. const BitmapData dest (*this, x, y, w, h, true);
  74057. for (int i = 0; i < h; ++i)
  74058. {
  74059. memcpy (dest.getLinePointer(i),
  74060. sourcePixelData + sourceLineStride * i,
  74061. w * dest.pixelStride);
  74062. }
  74063. }
  74064. }
  74065. void Image::clear (int dx, int dy, int dw, int dh,
  74066. const Colour& colourToClearTo)
  74067. {
  74068. const PixelARGB col (colourToClearTo.getPixelARGB());
  74069. const BitmapData destData (*this, dx, dy, dw, dh, true);
  74070. uint8* dest = destData.data;
  74071. while (--dh >= 0)
  74072. {
  74073. uint8* line = dest;
  74074. dest += destData.lineStride;
  74075. if (isARGB())
  74076. {
  74077. for (int x = dw; --x >= 0;)
  74078. {
  74079. ((PixelARGB*) line)->set (col);
  74080. line += destData.pixelStride;
  74081. }
  74082. }
  74083. else if (isRGB())
  74084. {
  74085. for (int x = dw; --x >= 0;)
  74086. {
  74087. ((PixelRGB*) line)->set (col);
  74088. line += destData.pixelStride;
  74089. }
  74090. }
  74091. else
  74092. {
  74093. for (int x = dw; --x >= 0;)
  74094. {
  74095. *line = col.getAlpha();
  74096. line += destData.pixelStride;
  74097. }
  74098. }
  74099. }
  74100. }
  74101. Image* Image::createCopy (int newWidth, int newHeight,
  74102. const Graphics::ResamplingQuality quality) const
  74103. {
  74104. if (newWidth < 0)
  74105. newWidth = imageWidth;
  74106. if (newHeight < 0)
  74107. newHeight = imageHeight;
  74108. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  74109. Graphics g (*newImage);
  74110. g.setImageResamplingQuality (quality);
  74111. g.drawImage (this,
  74112. 0, 0, newWidth, newHeight,
  74113. 0, 0, imageWidth, imageHeight,
  74114. false);
  74115. return newImage;
  74116. }
  74117. Image* Image::createCopyOfAlphaChannel() const
  74118. {
  74119. jassert (format != SingleChannel);
  74120. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  74121. if (! hasAlphaChannel())
  74122. {
  74123. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  74124. }
  74125. else
  74126. {
  74127. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  74128. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  74129. for (int y = 0; y < imageHeight; ++y)
  74130. {
  74131. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  74132. uint8* dst = destData.getLinePointer (y);
  74133. for (int x = imageWidth; --x >= 0;)
  74134. {
  74135. *dst++ = src->getAlpha();
  74136. ++src;
  74137. }
  74138. }
  74139. }
  74140. return newImage;
  74141. }
  74142. const Colour Image::getPixelAt (const int x, const int y) const
  74143. {
  74144. Colour c;
  74145. if (((unsigned int) x) < (unsigned int) imageWidth
  74146. && ((unsigned int) y) < (unsigned int) imageHeight)
  74147. {
  74148. const BitmapData srcData (*this, x, y, 1, 1);
  74149. if (isARGB())
  74150. {
  74151. PixelARGB p (*(const PixelARGB*) srcData.data);
  74152. p.unpremultiply();
  74153. c = Colour (p.getARGB());
  74154. }
  74155. else if (isRGB())
  74156. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  74157. else
  74158. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  74159. }
  74160. return c;
  74161. }
  74162. void Image::setPixelAt (const int x, const int y,
  74163. const Colour& colour)
  74164. {
  74165. if (((unsigned int) x) < (unsigned int) imageWidth
  74166. && ((unsigned int) y) < (unsigned int) imageHeight)
  74167. {
  74168. const BitmapData destData (*this, x, y, 1, 1, true);
  74169. const PixelARGB col (colour.getPixelARGB());
  74170. if (isARGB())
  74171. ((PixelARGB*) destData.data)->set (col);
  74172. else if (isRGB())
  74173. ((PixelRGB*) destData.data)->set (col);
  74174. else
  74175. *(destData.data) = col.getAlpha();
  74176. }
  74177. }
  74178. void Image::multiplyAlphaAt (const int x, const int y,
  74179. const float multiplier)
  74180. {
  74181. if (((unsigned int) x) < (unsigned int) imageWidth
  74182. && ((unsigned int) y) < (unsigned int) imageHeight
  74183. && hasAlphaChannel())
  74184. {
  74185. const BitmapData destData (*this, x, y, 1, 1, true);
  74186. if (isARGB())
  74187. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  74188. else
  74189. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  74190. }
  74191. }
  74192. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  74193. {
  74194. if (hasAlphaChannel())
  74195. {
  74196. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74197. if (isARGB())
  74198. {
  74199. for (int y = 0; y < imageHeight; ++y)
  74200. {
  74201. uint8* p = destData.getLinePointer (y);
  74202. for (int x = 0; x < imageWidth; ++x)
  74203. {
  74204. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  74205. p += destData.pixelStride;
  74206. }
  74207. }
  74208. }
  74209. else
  74210. {
  74211. for (int y = 0; y < imageHeight; ++y)
  74212. {
  74213. uint8* p = destData.getLinePointer (y);
  74214. for (int x = 0; x < imageWidth; ++x)
  74215. {
  74216. *p = (uint8) (*p * amountToMultiplyBy);
  74217. p += destData.pixelStride;
  74218. }
  74219. }
  74220. }
  74221. }
  74222. else
  74223. {
  74224. jassertfalse // can't do this without an alpha-channel!
  74225. }
  74226. }
  74227. void Image::desaturate()
  74228. {
  74229. if (isARGB() || isRGB())
  74230. {
  74231. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74232. if (isARGB())
  74233. {
  74234. for (int y = 0; y < imageHeight; ++y)
  74235. {
  74236. uint8* p = destData.getLinePointer (y);
  74237. for (int x = 0; x < imageWidth; ++x)
  74238. {
  74239. ((PixelARGB*) p)->desaturate();
  74240. p += destData.pixelStride;
  74241. }
  74242. }
  74243. }
  74244. else
  74245. {
  74246. for (int y = 0; y < imageHeight; ++y)
  74247. {
  74248. uint8* p = destData.getLinePointer (y);
  74249. for (int x = 0; x < imageWidth; ++x)
  74250. {
  74251. ((PixelRGB*) p)->desaturate();
  74252. p += destData.pixelStride;
  74253. }
  74254. }
  74255. }
  74256. }
  74257. }
  74258. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  74259. {
  74260. if (hasAlphaChannel())
  74261. {
  74262. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  74263. SparseSet <int> pixelsOnRow;
  74264. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  74265. for (int y = 0; y < imageHeight; ++y)
  74266. {
  74267. pixelsOnRow.clear();
  74268. const uint8* lineData = srcData.getLinePointer (y);
  74269. if (isARGB())
  74270. {
  74271. for (int x = 0; x < imageWidth; ++x)
  74272. {
  74273. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  74274. pixelsOnRow.addRange (x, 1);
  74275. lineData += srcData.pixelStride;
  74276. }
  74277. }
  74278. else
  74279. {
  74280. for (int x = 0; x < imageWidth; ++x)
  74281. {
  74282. if (*lineData >= threshold)
  74283. pixelsOnRow.addRange (x, 1);
  74284. lineData += srcData.pixelStride;
  74285. }
  74286. }
  74287. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  74288. {
  74289. int x, w;
  74290. if (pixelsOnRow.getRange (i, x, w))
  74291. result.add (Rectangle<int> (x, y, w, 1));
  74292. }
  74293. result.consolidate();
  74294. }
  74295. }
  74296. else
  74297. {
  74298. result.add (0, 0, imageWidth, imageHeight);
  74299. }
  74300. }
  74301. void Image::moveImageSection (int dx, int dy,
  74302. int sx, int sy,
  74303. int w, int h)
  74304. {
  74305. if (dx < 0)
  74306. {
  74307. w += dx;
  74308. sx -= dx;
  74309. dx = 0;
  74310. }
  74311. if (dy < 0)
  74312. {
  74313. h += dy;
  74314. sy -= dy;
  74315. dy = 0;
  74316. }
  74317. if (sx < 0)
  74318. {
  74319. w += sx;
  74320. dx -= sx;
  74321. sx = 0;
  74322. }
  74323. if (sy < 0)
  74324. {
  74325. h += sy;
  74326. dy -= sy;
  74327. sy = 0;
  74328. }
  74329. const int minX = jmin (dx, sx);
  74330. const int minY = jmin (dy, sy);
  74331. w = jmin (w, getWidth() - jmax (sx, dx));
  74332. h = jmin (h, getHeight() - jmax (sy, dy));
  74333. if (w > 0 && h > 0)
  74334. {
  74335. const int maxX = jmax (dx, sx) + w;
  74336. const int maxY = jmax (dy, sy) + h;
  74337. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  74338. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  74339. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  74340. const int lineSize = destData.pixelStride * w;
  74341. if (dy > sy)
  74342. {
  74343. while (--h >= 0)
  74344. {
  74345. const int offset = h * destData.lineStride;
  74346. memmove (dst + offset, src + offset, lineSize);
  74347. }
  74348. }
  74349. else if (dst != src)
  74350. {
  74351. while (--h >= 0)
  74352. {
  74353. memmove (dst, src, lineSize);
  74354. dst += destData.lineStride;
  74355. src += destData.lineStride;
  74356. }
  74357. }
  74358. }
  74359. }
  74360. END_JUCE_NAMESPACE
  74361. /*** End of inlined file: juce_Image.cpp ***/
  74362. /*** Start of inlined file: juce_ImageCache.cpp ***/
  74363. BEGIN_JUCE_NAMESPACE
  74364. struct ImageCacheItem
  74365. {
  74366. ScopedPointer <Image> image;
  74367. int64 hashCode;
  74368. int refCount;
  74369. uint32 releaseTime;
  74370. juce_UseDebuggingNewOperator
  74371. };
  74372. static ImageCache* instance = 0;
  74373. static int cacheTimeout = 5000;
  74374. ImageCache::ImageCache()
  74375. {
  74376. }
  74377. ImageCache::~ImageCache()
  74378. {
  74379. jassert (instance == this);
  74380. instance = 0;
  74381. }
  74382. Image* ImageCache::getFromHashCode (const int64 hashCode)
  74383. {
  74384. if (instance != 0)
  74385. {
  74386. const ScopedLock sl (instance->lock);
  74387. for (int i = instance->images.size(); --i >= 0;)
  74388. {
  74389. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74390. if (ci->hashCode == hashCode)
  74391. {
  74392. ci->refCount++;
  74393. return ci->image;
  74394. }
  74395. }
  74396. }
  74397. return 0;
  74398. }
  74399. void ImageCache::addImageToCache (Image* const image,
  74400. const int64 hashCode)
  74401. {
  74402. if (image != 0)
  74403. {
  74404. if (instance == 0)
  74405. instance = new ImageCache();
  74406. ImageCacheItem* const newC = new ImageCacheItem();
  74407. newC->hashCode = hashCode;
  74408. newC->image = image;
  74409. newC->refCount = 1;
  74410. newC->releaseTime = 0;
  74411. const ScopedLock sl (instance->lock);
  74412. instance->images.add (newC);
  74413. }
  74414. }
  74415. void ImageCache::release (Image* const imageToRelease)
  74416. {
  74417. if (imageToRelease != 0 && instance != 0)
  74418. {
  74419. const ScopedLock sl (instance->lock);
  74420. for (int i = instance->images.size(); --i >= 0;)
  74421. {
  74422. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74423. if ((Image*) ci->image == imageToRelease)
  74424. {
  74425. if (--(ci->refCount) == 0)
  74426. ci->releaseTime = Time::getApproximateMillisecondCounter();
  74427. if (! instance->isTimerRunning())
  74428. instance->startTimer (999);
  74429. break;
  74430. }
  74431. }
  74432. }
  74433. }
  74434. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  74435. {
  74436. if (isImageInCache (imageToRelease))
  74437. release (imageToRelease);
  74438. else
  74439. delete imageToRelease;
  74440. }
  74441. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  74442. {
  74443. if (instance != 0)
  74444. {
  74445. const ScopedLock sl (instance->lock);
  74446. for (int i = instance->images.size(); --i >= 0;)
  74447. if ((Image*) instance->images.getUnchecked(i)->image == imageToLookFor)
  74448. return true;
  74449. }
  74450. return false;
  74451. }
  74452. void ImageCache::incReferenceCount (Image* const image)
  74453. {
  74454. if (instance != 0)
  74455. {
  74456. const ScopedLock sl (instance->lock);
  74457. for (int i = instance->images.size(); --i >= 0;)
  74458. {
  74459. ImageCacheItem* const ci = (ImageCacheItem*) instance->images.getUnchecked(i);
  74460. if ((Image*) ci->image == image)
  74461. {
  74462. ci->refCount++;
  74463. return;
  74464. }
  74465. }
  74466. }
  74467. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  74468. }
  74469. void ImageCache::timerCallback()
  74470. {
  74471. int numberStillNeedingReleasing = 0;
  74472. const unsigned int now = Time::getApproximateMillisecondCounter();
  74473. const ScopedLock sl (lock);
  74474. for (int i = images.size(); --i >= 0;)
  74475. {
  74476. ImageCacheItem* const ci = images.getUnchecked(i);
  74477. if (ci->refCount <= 0)
  74478. {
  74479. if (now > ci->releaseTime + cacheTimeout
  74480. || now < ci->releaseTime - 1000)
  74481. {
  74482. images.remove (i);
  74483. }
  74484. else
  74485. {
  74486. ++numberStillNeedingReleasing;
  74487. }
  74488. }
  74489. }
  74490. if (numberStillNeedingReleasing == 0)
  74491. stopTimer();
  74492. }
  74493. Image* ImageCache::getFromFile (const File& file)
  74494. {
  74495. const int64 hashCode = file.hashCode64();
  74496. Image* image = getFromHashCode (hashCode);
  74497. if (image == 0)
  74498. {
  74499. image = ImageFileFormat::loadFrom (file);
  74500. addImageToCache (image, hashCode);
  74501. }
  74502. return image;
  74503. }
  74504. Image* ImageCache::getFromMemory (const void* imageData,
  74505. const int dataSize)
  74506. {
  74507. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  74508. Image* image = getFromHashCode (hashCode);
  74509. if (image == 0)
  74510. {
  74511. image = ImageFileFormat::loadFrom (imageData, dataSize);
  74512. addImageToCache (image, hashCode);
  74513. }
  74514. return image;
  74515. }
  74516. void ImageCache::setCacheTimeout (const int millisecs)
  74517. {
  74518. cacheTimeout = millisecs;
  74519. }
  74520. END_JUCE_NAMESPACE
  74521. /*** End of inlined file: juce_ImageCache.cpp ***/
  74522. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74523. BEGIN_JUCE_NAMESPACE
  74524. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  74525. : values (size_ * size_),
  74526. size (size_)
  74527. {
  74528. clear();
  74529. }
  74530. ImageConvolutionKernel::~ImageConvolutionKernel()
  74531. {
  74532. }
  74533. void ImageConvolutionKernel::setKernelValue (const int x,
  74534. const int y,
  74535. const float value)
  74536. {
  74537. if (((unsigned int) x) < (unsigned int) size
  74538. && ((unsigned int) y) < (unsigned int) size)
  74539. {
  74540. values [x + y * size] = value;
  74541. }
  74542. else
  74543. {
  74544. jassertfalse
  74545. }
  74546. }
  74547. void ImageConvolutionKernel::clear()
  74548. {
  74549. for (int i = size * size; --i >= 0;)
  74550. values[i] = 0;
  74551. }
  74552. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74553. {
  74554. double currentTotal = 0.0;
  74555. for (int i = size * size; --i >= 0;)
  74556. currentTotal += values[i];
  74557. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74558. }
  74559. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74560. {
  74561. for (int i = size * size; --i >= 0;)
  74562. values[i] *= multiplier;
  74563. }
  74564. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74565. {
  74566. const double radiusFactor = -1.0 / (radius * radius * 2);
  74567. const int centre = size >> 1;
  74568. for (int y = size; --y >= 0;)
  74569. {
  74570. for (int x = size; --x >= 0;)
  74571. {
  74572. const int cx = x - centre;
  74573. const int cy = y - centre;
  74574. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74575. }
  74576. }
  74577. setOverallSum (1.0f);
  74578. }
  74579. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74580. const Image* sourceImage,
  74581. int dx,
  74582. int dy,
  74583. int dw,
  74584. int dh) const
  74585. {
  74586. ScopedPointer <Image> imageCreated;
  74587. if (sourceImage == 0)
  74588. {
  74589. sourceImage = imageCreated = destImage.createCopy();
  74590. }
  74591. else
  74592. {
  74593. jassert (sourceImage->getWidth() == destImage.getWidth()
  74594. && sourceImage->getHeight() == destImage.getHeight()
  74595. && sourceImage->getFormat() == destImage.getFormat());
  74596. if (sourceImage->getWidth() != destImage.getWidth()
  74597. || sourceImage->getHeight() != destImage.getHeight()
  74598. || sourceImage->getFormat() != destImage.getFormat())
  74599. return;
  74600. }
  74601. const int imageWidth = destImage.getWidth();
  74602. const int imageHeight = destImage.getHeight();
  74603. if (dx >= imageWidth || dy >= imageHeight)
  74604. return;
  74605. if (dx + dw > imageWidth)
  74606. dw = imageWidth - dx;
  74607. if (dy + dh > imageHeight)
  74608. dh = imageHeight - dy;
  74609. const int dx2 = dx + dw;
  74610. const int dy2 = dy + dh;
  74611. const Image::BitmapData destData (destImage, dx, dy, dw, dh, true);
  74612. uint8* line = destData.data;
  74613. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74614. if (destData.pixelStride == 4)
  74615. {
  74616. for (int y = dy; y < dy2; ++y)
  74617. {
  74618. uint8* dest = line;
  74619. line += destData.lineStride;
  74620. for (int x = dx; x < dx2; ++x)
  74621. {
  74622. float c1 = 0;
  74623. float c2 = 0;
  74624. float c3 = 0;
  74625. float c4 = 0;
  74626. for (int yy = 0; yy < size; ++yy)
  74627. {
  74628. const int sy = y + yy - (size >> 1);
  74629. if (sy >= imageHeight)
  74630. break;
  74631. if (sy >= 0)
  74632. {
  74633. int sx = x - (size >> 1);
  74634. const uint8* src = srcData.getPixelPointer (sx, sy);
  74635. for (int xx = 0; xx < size; ++xx)
  74636. {
  74637. if (sx >= imageWidth)
  74638. break;
  74639. if (sx >= 0)
  74640. {
  74641. const float kernelMult = values [xx + yy * size];
  74642. c1 += kernelMult * *src++;
  74643. c2 += kernelMult * *src++;
  74644. c3 += kernelMult * *src++;
  74645. c4 += kernelMult * *src++;
  74646. }
  74647. else
  74648. {
  74649. src += 4;
  74650. }
  74651. ++sx;
  74652. }
  74653. }
  74654. }
  74655. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74656. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74657. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74658. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74659. }
  74660. }
  74661. }
  74662. else if (destData.pixelStride == 3)
  74663. {
  74664. for (int y = dy; y < dy2; ++y)
  74665. {
  74666. uint8* dest = line;
  74667. line += destData.lineStride;
  74668. for (int x = dx; x < dx2; ++x)
  74669. {
  74670. float c1 = 0;
  74671. float c2 = 0;
  74672. float c3 = 0;
  74673. for (int yy = 0; yy < size; ++yy)
  74674. {
  74675. const int sy = y + yy - (size >> 1);
  74676. if (sy >= imageHeight)
  74677. break;
  74678. if (sy >= 0)
  74679. {
  74680. int sx = x - (size >> 1);
  74681. const uint8* src = srcData.getPixelPointer (sx, sy);
  74682. for (int xx = 0; xx < size; ++xx)
  74683. {
  74684. if (sx >= imageWidth)
  74685. break;
  74686. if (sx >= 0)
  74687. {
  74688. const float kernelMult = values [xx + yy * size];
  74689. c1 += kernelMult * *src++;
  74690. c2 += kernelMult * *src++;
  74691. c3 += kernelMult * *src++;
  74692. }
  74693. else
  74694. {
  74695. src += 3;
  74696. }
  74697. ++sx;
  74698. }
  74699. }
  74700. }
  74701. *dest++ = (uint8) roundToInt (c1);
  74702. *dest++ = (uint8) roundToInt (c2);
  74703. *dest++ = (uint8) roundToInt (c3);
  74704. }
  74705. }
  74706. }
  74707. }
  74708. END_JUCE_NAMESPACE
  74709. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74710. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74711. BEGIN_JUCE_NAMESPACE
  74712. /*** Start of inlined file: juce_GIFLoader.h ***/
  74713. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74714. #define __JUCE_GIFLOADER_JUCEHEADER__
  74715. #ifndef DOXYGEN
  74716. class GIFLoader
  74717. {
  74718. public:
  74719. GIFLoader (InputStream& in);
  74720. ~GIFLoader();
  74721. Image* getImage() const { return image; }
  74722. private:
  74723. Image* image;
  74724. InputStream& input;
  74725. uint8 buffer [300];
  74726. uint8 palette [256][4];
  74727. bool dataBlockIsZero, fresh, finished;
  74728. int currentBit, lastBit, lastByteIndex;
  74729. int codeSize, setCodeSize;
  74730. int maxCode, maxCodeSize;
  74731. int firstcode, oldcode;
  74732. int clearCode, end_code;
  74733. enum { maxGifCode = 1 << 12 };
  74734. int table [2] [maxGifCode];
  74735. int stack [2 * maxGifCode];
  74736. int *sp;
  74737. bool getSizeFromHeader (int& width, int& height);
  74738. bool readPalette (const int numCols);
  74739. int readDataBlock (unsigned char* dest);
  74740. int processExtension (int type, int& transparent);
  74741. int readLZWByte (bool initialise, int input_code_size);
  74742. int getCode (int code_size, bool initialise);
  74743. bool readImage (int width, int height, int interlace, int transparent);
  74744. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74745. GIFLoader (const GIFLoader&);
  74746. const GIFLoader& operator= (const GIFLoader&);
  74747. };
  74748. #endif // DOXYGEN
  74749. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74750. /*** End of inlined file: juce_GIFLoader.h ***/
  74751. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74752. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74753. PNGImageFormat::PNGImageFormat() {}
  74754. PNGImageFormat::~PNGImageFormat() {}
  74755. const String PNGImageFormat::getFormatName()
  74756. {
  74757. return T("PNG");
  74758. }
  74759. bool PNGImageFormat::canUnderstand (InputStream& in)
  74760. {
  74761. const int bytesNeeded = 4;
  74762. char header [bytesNeeded];
  74763. return in.read (header, bytesNeeded) == bytesNeeded
  74764. && header[1] == 'P'
  74765. && header[2] == 'N'
  74766. && header[3] == 'G';
  74767. }
  74768. Image* PNGImageFormat::decodeImage (InputStream& in)
  74769. {
  74770. return juce_loadPNGImageFromStream (in);
  74771. }
  74772. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74773. OutputStream& destStream)
  74774. {
  74775. return juce_writePNGImageToStream (sourceImage, destStream);
  74776. }
  74777. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74778. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74779. JPEGImageFormat::JPEGImageFormat()
  74780. : quality (-1.0f)
  74781. {
  74782. }
  74783. JPEGImageFormat::~JPEGImageFormat() {}
  74784. void JPEGImageFormat::setQuality (const float newQuality)
  74785. {
  74786. quality = newQuality;
  74787. }
  74788. const String JPEGImageFormat::getFormatName()
  74789. {
  74790. return T("JPEG");
  74791. }
  74792. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74793. {
  74794. const int bytesNeeded = 10;
  74795. uint8 header [bytesNeeded];
  74796. if (in.read (header, bytesNeeded) == bytesNeeded)
  74797. {
  74798. return header[0] == 0xff
  74799. && header[1] == 0xd8
  74800. && header[2] == 0xff
  74801. && (header[3] == 0xe0 || header[3] == 0xe1);
  74802. }
  74803. return false;
  74804. }
  74805. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74806. {
  74807. return juce_loadJPEGImageFromStream (in);
  74808. }
  74809. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74810. OutputStream& destStream)
  74811. {
  74812. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74813. }
  74814. class GIFImageFormat : public ImageFileFormat
  74815. {
  74816. public:
  74817. GIFImageFormat() {}
  74818. ~GIFImageFormat() {}
  74819. const String getFormatName()
  74820. {
  74821. return T("GIF");
  74822. }
  74823. bool canUnderstand (InputStream& in)
  74824. {
  74825. const int bytesNeeded = 4;
  74826. char header [bytesNeeded];
  74827. return (in.read (header, bytesNeeded) == bytesNeeded)
  74828. && header[0] == 'G'
  74829. && header[1] == 'I'
  74830. && header[2] == 'F';
  74831. }
  74832. Image* decodeImage (InputStream& in)
  74833. {
  74834. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74835. return loader->getImage();
  74836. }
  74837. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74838. {
  74839. return false;
  74840. }
  74841. };
  74842. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74843. {
  74844. static PNGImageFormat png;
  74845. static JPEGImageFormat jpg;
  74846. static GIFImageFormat gif;
  74847. ImageFileFormat* formats[4];
  74848. int numFormats = 0;
  74849. formats [numFormats++] = &png;
  74850. formats [numFormats++] = &jpg;
  74851. formats [numFormats++] = &gif;
  74852. const int64 streamPos = input.getPosition();
  74853. for (int i = 0; i < numFormats; ++i)
  74854. {
  74855. const bool found = formats[i]->canUnderstand (input);
  74856. input.setPosition (streamPos);
  74857. if (found)
  74858. return formats[i];
  74859. }
  74860. return 0;
  74861. }
  74862. Image* ImageFileFormat::loadFrom (InputStream& input)
  74863. {
  74864. ImageFileFormat* const format = findImageFormatForStream (input);
  74865. if (format != 0)
  74866. return format->decodeImage (input);
  74867. return 0;
  74868. }
  74869. Image* ImageFileFormat::loadFrom (const File& file)
  74870. {
  74871. InputStream* const in = file.createInputStream();
  74872. if (in != 0)
  74873. {
  74874. BufferedInputStream b (in, 8192, true);
  74875. return loadFrom (b);
  74876. }
  74877. return 0;
  74878. }
  74879. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74880. {
  74881. if (rawData != 0 && numBytes > 4)
  74882. {
  74883. MemoryInputStream stream (rawData, numBytes, false);
  74884. return loadFrom (stream);
  74885. }
  74886. return 0;
  74887. }
  74888. END_JUCE_NAMESPACE
  74889. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74890. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74891. BEGIN_JUCE_NAMESPACE
  74892. GIFLoader::GIFLoader (InputStream& in)
  74893. : image (0),
  74894. input (in),
  74895. dataBlockIsZero (false),
  74896. fresh (false),
  74897. finished (false)
  74898. {
  74899. currentBit = lastBit = lastByteIndex = 0;
  74900. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74901. firstcode = oldcode = 0;
  74902. clearCode = end_code = 0;
  74903. int imageWidth, imageHeight;
  74904. int transparent = -1;
  74905. if (! getSizeFromHeader (imageWidth, imageHeight))
  74906. return;
  74907. if ((imageWidth <= 0) || (imageHeight <= 0))
  74908. return;
  74909. unsigned char buf [16];
  74910. if (in.read (buf, 3) != 3)
  74911. return;
  74912. int numColours = 2 << (buf[0] & 7);
  74913. if ((buf[0] & 0x80) != 0)
  74914. readPalette (numColours);
  74915. for (;;)
  74916. {
  74917. if (input.read (buf, 1) != 1)
  74918. break;
  74919. if (buf[0] == ';')
  74920. break;
  74921. if (buf[0] == '!')
  74922. {
  74923. if (input.read (buf, 1) != 1)
  74924. break;
  74925. if (processExtension (buf[0], transparent) < 0)
  74926. break;
  74927. continue;
  74928. }
  74929. if (buf[0] != ',')
  74930. continue;
  74931. if (input.read (buf, 9) != 9)
  74932. break;
  74933. imageWidth = makeWord (buf[4], buf[5]);
  74934. imageHeight = makeWord (buf[6], buf[7]);
  74935. numColours = 2 << (buf[8] & 7);
  74936. if ((buf[8] & 0x80) != 0)
  74937. if (! readPalette (numColours))
  74938. break;
  74939. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74940. imageWidth, imageHeight, (transparent >= 0));
  74941. readImage (imageWidth, imageHeight,
  74942. (buf[8] & 0x40) != 0,
  74943. transparent);
  74944. break;
  74945. }
  74946. }
  74947. GIFLoader::~GIFLoader()
  74948. {
  74949. }
  74950. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74951. {
  74952. unsigned char b [8];
  74953. if (input.read (b, 6) == 6)
  74954. {
  74955. if ((strncmp ("GIF87a", (char*) b, 6) == 0)
  74956. || (strncmp ("GIF89a", (char*) b, 6) == 0))
  74957. {
  74958. if (input.read (b, 4) == 4)
  74959. {
  74960. w = makeWord (b[0], b[1]);
  74961. h = makeWord (b[2], b[3]);
  74962. return true;
  74963. }
  74964. }
  74965. }
  74966. return false;
  74967. }
  74968. bool GIFLoader::readPalette (const int numCols)
  74969. {
  74970. unsigned char rgb[4];
  74971. for (int i = 0; i < numCols; ++i)
  74972. {
  74973. input.read (rgb, 3);
  74974. palette [i][0] = rgb[0];
  74975. palette [i][1] = rgb[1];
  74976. palette [i][2] = rgb[2];
  74977. palette [i][3] = 0xff;
  74978. }
  74979. return true;
  74980. }
  74981. int GIFLoader::readDataBlock (unsigned char* const dest)
  74982. {
  74983. unsigned char n;
  74984. if (input.read (&n, 1) == 1)
  74985. {
  74986. dataBlockIsZero = (n == 0);
  74987. if (dataBlockIsZero || (input.read (dest, n) == n))
  74988. return n;
  74989. }
  74990. return -1;
  74991. }
  74992. int GIFLoader::processExtension (const int type, int& transparent)
  74993. {
  74994. unsigned char b [300];
  74995. int n = 0;
  74996. if (type == 0xf9)
  74997. {
  74998. n = readDataBlock (b);
  74999. if (n < 0)
  75000. return 1;
  75001. if ((b[0] & 0x1) != 0)
  75002. transparent = b[3];
  75003. }
  75004. do
  75005. {
  75006. n = readDataBlock (b);
  75007. }
  75008. while (n > 0);
  75009. return n;
  75010. }
  75011. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  75012. {
  75013. if (initialise)
  75014. {
  75015. currentBit = 0;
  75016. lastBit = 0;
  75017. finished = false;
  75018. return 0;
  75019. }
  75020. if ((currentBit + codeSize_) >= lastBit)
  75021. {
  75022. if (finished)
  75023. return -1;
  75024. buffer[0] = buffer [lastByteIndex - 2];
  75025. buffer[1] = buffer [lastByteIndex - 1];
  75026. const int n = readDataBlock (&buffer[2]);
  75027. if (n == 0)
  75028. finished = true;
  75029. lastByteIndex = 2 + n;
  75030. currentBit = (currentBit - lastBit) + 16;
  75031. lastBit = (2 + n) * 8 ;
  75032. }
  75033. int result = 0;
  75034. int i = currentBit;
  75035. for (int j = 0; j < codeSize_; ++j)
  75036. {
  75037. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  75038. ++i;
  75039. }
  75040. currentBit += codeSize_;
  75041. return result;
  75042. }
  75043. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  75044. {
  75045. int code, incode, i;
  75046. if (initialise)
  75047. {
  75048. setCodeSize = inputCodeSize;
  75049. codeSize = setCodeSize + 1;
  75050. clearCode = 1 << setCodeSize;
  75051. end_code = clearCode + 1;
  75052. maxCodeSize = 2 * clearCode;
  75053. maxCode = clearCode + 2;
  75054. getCode (0, true);
  75055. fresh = true;
  75056. for (i = 0; i < clearCode; ++i)
  75057. {
  75058. table[0][i] = 0;
  75059. table[1][i] = i;
  75060. }
  75061. for (; i < maxGifCode; ++i)
  75062. {
  75063. table[0][i] = 0;
  75064. table[1][i] = 0;
  75065. }
  75066. sp = stack;
  75067. return 0;
  75068. }
  75069. else if (fresh)
  75070. {
  75071. fresh = false;
  75072. do
  75073. {
  75074. firstcode = oldcode
  75075. = getCode (codeSize, false);
  75076. }
  75077. while (firstcode == clearCode);
  75078. return firstcode;
  75079. }
  75080. if (sp > stack)
  75081. return *--sp;
  75082. while ((code = getCode (codeSize, false)) >= 0)
  75083. {
  75084. if (code == clearCode)
  75085. {
  75086. for (i = 0; i < clearCode; ++i)
  75087. {
  75088. table[0][i] = 0;
  75089. table[1][i] = i;
  75090. }
  75091. for (; i < maxGifCode; ++i)
  75092. {
  75093. table[0][i] = 0;
  75094. table[1][i] = 0;
  75095. }
  75096. codeSize = setCodeSize + 1;
  75097. maxCodeSize = 2 * clearCode;
  75098. maxCode = clearCode + 2;
  75099. sp = stack;
  75100. firstcode = oldcode = getCode (codeSize, false);
  75101. return firstcode;
  75102. }
  75103. else if (code == end_code)
  75104. {
  75105. if (dataBlockIsZero)
  75106. return -2;
  75107. unsigned char buf [260];
  75108. int n;
  75109. while ((n = readDataBlock (buf)) > 0)
  75110. {}
  75111. if (n != 0)
  75112. return -2;
  75113. }
  75114. incode = code;
  75115. if (code >= maxCode)
  75116. {
  75117. *sp++ = firstcode;
  75118. code = oldcode;
  75119. }
  75120. while (code >= clearCode)
  75121. {
  75122. *sp++ = table[1][code];
  75123. if (code == table[0][code])
  75124. return -2;
  75125. code = table[0][code];
  75126. }
  75127. *sp++ = firstcode = table[1][code];
  75128. if ((code = maxCode) < maxGifCode)
  75129. {
  75130. table[0][code] = oldcode;
  75131. table[1][code] = firstcode;
  75132. ++maxCode;
  75133. if ((maxCode >= maxCodeSize)
  75134. && (maxCodeSize < maxGifCode))
  75135. {
  75136. maxCodeSize <<= 1;
  75137. ++codeSize;
  75138. }
  75139. }
  75140. oldcode = incode;
  75141. if (sp > stack)
  75142. return *--sp;
  75143. }
  75144. return code;
  75145. }
  75146. bool GIFLoader::readImage (const int width, const int height,
  75147. const int interlace, const int transparent)
  75148. {
  75149. unsigned char c;
  75150. if (input.read (&c, 1) != 1
  75151. || readLZWByte (true, c) < 0)
  75152. return false;
  75153. if (transparent >= 0)
  75154. {
  75155. palette [transparent][0] = 0;
  75156. palette [transparent][1] = 0;
  75157. palette [transparent][2] = 0;
  75158. palette [transparent][3] = 0;
  75159. }
  75160. int index;
  75161. int xpos = 0, ypos = 0, pass = 0;
  75162. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  75163. uint8* p = destData.data;
  75164. const bool hasAlpha = image->hasAlphaChannel();
  75165. while ((index = readLZWByte (false, c)) >= 0)
  75166. {
  75167. const uint8* const paletteEntry = palette [index];
  75168. if (hasAlpha)
  75169. {
  75170. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  75171. paletteEntry[0],
  75172. paletteEntry[1],
  75173. paletteEntry[2]);
  75174. ((PixelARGB*) p)->premultiply();
  75175. }
  75176. else
  75177. {
  75178. ((PixelRGB*) p)->setARGB (0,
  75179. paletteEntry[0],
  75180. paletteEntry[1],
  75181. paletteEntry[2]);
  75182. }
  75183. p += destData.pixelStride;
  75184. ++xpos;
  75185. if (xpos == width)
  75186. {
  75187. xpos = 0;
  75188. if (interlace)
  75189. {
  75190. switch (pass)
  75191. {
  75192. case 0:
  75193. case 1:
  75194. ypos += 8;
  75195. break;
  75196. case 2:
  75197. ypos += 4;
  75198. break;
  75199. case 3:
  75200. ypos += 2;
  75201. break;
  75202. }
  75203. while (ypos >= height)
  75204. {
  75205. ++pass;
  75206. switch (pass)
  75207. {
  75208. case 1:
  75209. ypos = 4;
  75210. break;
  75211. case 2:
  75212. ypos = 2;
  75213. break;
  75214. case 3:
  75215. ypos = 1;
  75216. break;
  75217. default:
  75218. return true;
  75219. }
  75220. }
  75221. }
  75222. else
  75223. {
  75224. ++ypos;
  75225. }
  75226. p = destData.getPixelPointer (xpos, ypos);
  75227. }
  75228. if (ypos >= height)
  75229. break;
  75230. }
  75231. return true;
  75232. }
  75233. END_JUCE_NAMESPACE
  75234. /*** End of inlined file: juce_GIFLoader.cpp ***/
  75235. #endif
  75236. //==============================================================================
  75237. // some files include lots of library code, so leave them to the end to avoid cluttering
  75238. // up the build for the clean files.
  75239. #if JUCE_BUILD_CORE
  75240. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75241. namespace zlibNamespace
  75242. {
  75243. #if JUCE_INCLUDE_ZLIB_CODE
  75244. #undef OS_CODE
  75245. #undef fdopen
  75246. /*** Start of inlined file: zlib.h ***/
  75247. #ifndef ZLIB_H
  75248. #define ZLIB_H
  75249. /*** Start of inlined file: zconf.h ***/
  75250. #ifndef ZCONF_H
  75251. #define ZCONF_H
  75252. // *** Just a few hacks here to make it compile nicely with Juce..
  75253. #define Z_PREFIX 1
  75254. #undef __MACTYPES__
  75255. #ifdef _MSC_VER
  75256. #pragma warning (disable : 4131 4127 4244 4267)
  75257. #endif
  75258. #ifdef Z_PREFIX
  75259. # define deflateInit_ z_deflateInit_
  75260. # define deflate z_deflate
  75261. # define deflateEnd z_deflateEnd
  75262. # define inflateInit_ z_inflateInit_
  75263. # define inflate z_inflate
  75264. # define inflateEnd z_inflateEnd
  75265. # define deflateInit2_ z_deflateInit2_
  75266. # define deflateSetDictionary z_deflateSetDictionary
  75267. # define deflateCopy z_deflateCopy
  75268. # define deflateReset z_deflateReset
  75269. # define deflateParams z_deflateParams
  75270. # define deflateBound z_deflateBound
  75271. # define deflatePrime z_deflatePrime
  75272. # define inflateInit2_ z_inflateInit2_
  75273. # define inflateSetDictionary z_inflateSetDictionary
  75274. # define inflateSync z_inflateSync
  75275. # define inflateSyncPoint z_inflateSyncPoint
  75276. # define inflateCopy z_inflateCopy
  75277. # define inflateReset z_inflateReset
  75278. # define inflateBack z_inflateBack
  75279. # define inflateBackEnd z_inflateBackEnd
  75280. # define compress z_compress
  75281. # define compress2 z_compress2
  75282. # define compressBound z_compressBound
  75283. # define uncompress z_uncompress
  75284. # define adler32 z_adler32
  75285. # define crc32 z_crc32
  75286. # define get_crc_table z_get_crc_table
  75287. # define zError z_zError
  75288. # define alloc_func z_alloc_func
  75289. # define free_func z_free_func
  75290. # define in_func z_in_func
  75291. # define out_func z_out_func
  75292. # define Byte z_Byte
  75293. # define uInt z_uInt
  75294. # define uLong z_uLong
  75295. # define Bytef z_Bytef
  75296. # define charf z_charf
  75297. # define intf z_intf
  75298. # define uIntf z_uIntf
  75299. # define uLongf z_uLongf
  75300. # define voidpf z_voidpf
  75301. # define voidp z_voidp
  75302. #endif
  75303. #if defined(__MSDOS__) && !defined(MSDOS)
  75304. # define MSDOS
  75305. #endif
  75306. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  75307. # define OS2
  75308. #endif
  75309. #if defined(_WINDOWS) && !defined(WINDOWS)
  75310. # define WINDOWS
  75311. #endif
  75312. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  75313. # ifndef WIN32
  75314. # define WIN32
  75315. # endif
  75316. #endif
  75317. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  75318. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  75319. # ifndef SYS16BIT
  75320. # define SYS16BIT
  75321. # endif
  75322. # endif
  75323. #endif
  75324. #ifdef SYS16BIT
  75325. # define MAXSEG_64K
  75326. #endif
  75327. #ifdef MSDOS
  75328. # define UNALIGNED_OK
  75329. #endif
  75330. #ifdef __STDC_VERSION__
  75331. # ifndef STDC
  75332. # define STDC
  75333. # endif
  75334. # if __STDC_VERSION__ >= 199901L
  75335. # ifndef STDC99
  75336. # define STDC99
  75337. # endif
  75338. # endif
  75339. #endif
  75340. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  75341. # define STDC
  75342. #endif
  75343. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  75344. # define STDC
  75345. #endif
  75346. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  75347. # define STDC
  75348. #endif
  75349. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  75350. # define STDC
  75351. #endif
  75352. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  75353. # define STDC
  75354. #endif
  75355. #ifndef STDC
  75356. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  75357. # define const /* note: need a more gentle solution here */
  75358. # endif
  75359. #endif
  75360. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  75361. # define NO_DUMMY_DECL
  75362. #endif
  75363. #ifndef MAX_MEM_LEVEL
  75364. # ifdef MAXSEG_64K
  75365. # define MAX_MEM_LEVEL 8
  75366. # else
  75367. # define MAX_MEM_LEVEL 9
  75368. # endif
  75369. #endif
  75370. #ifndef MAX_WBITS
  75371. # define MAX_WBITS 15 /* 32K LZ77 window */
  75372. #endif
  75373. #ifndef OF /* function prototypes */
  75374. # ifdef STDC
  75375. # define OF(args) args
  75376. # else
  75377. # define OF(args) ()
  75378. # endif
  75379. #endif
  75380. #ifdef SYS16BIT
  75381. # if defined(M_I86SM) || defined(M_I86MM)
  75382. # define SMALL_MEDIUM
  75383. # ifdef _MSC_VER
  75384. # define FAR _far
  75385. # else
  75386. # define FAR far
  75387. # endif
  75388. # endif
  75389. # if (defined(__SMALL__) || defined(__MEDIUM__))
  75390. # define SMALL_MEDIUM
  75391. # ifdef __BORLANDC__
  75392. # define FAR _far
  75393. # else
  75394. # define FAR far
  75395. # endif
  75396. # endif
  75397. #endif
  75398. #if defined(WINDOWS) || defined(WIN32)
  75399. # ifdef ZLIB_DLL
  75400. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  75401. # ifdef ZLIB_INTERNAL
  75402. # define ZEXTERN extern __declspec(dllexport)
  75403. # else
  75404. # define ZEXTERN extern __declspec(dllimport)
  75405. # endif
  75406. # endif
  75407. # endif /* ZLIB_DLL */
  75408. # ifdef ZLIB_WINAPI
  75409. # ifdef FAR
  75410. # undef FAR
  75411. # endif
  75412. # include <windows.h>
  75413. # define ZEXPORT WINAPI
  75414. # ifdef WIN32
  75415. # define ZEXPORTVA WINAPIV
  75416. # else
  75417. # define ZEXPORTVA FAR CDECL
  75418. # endif
  75419. # endif
  75420. #endif
  75421. #if defined (__BEOS__)
  75422. # ifdef ZLIB_DLL
  75423. # ifdef ZLIB_INTERNAL
  75424. # define ZEXPORT __declspec(dllexport)
  75425. # define ZEXPORTVA __declspec(dllexport)
  75426. # else
  75427. # define ZEXPORT __declspec(dllimport)
  75428. # define ZEXPORTVA __declspec(dllimport)
  75429. # endif
  75430. # endif
  75431. #endif
  75432. #ifndef ZEXTERN
  75433. # define ZEXTERN extern
  75434. #endif
  75435. #ifndef ZEXPORT
  75436. # define ZEXPORT
  75437. #endif
  75438. #ifndef ZEXPORTVA
  75439. # define ZEXPORTVA
  75440. #endif
  75441. #ifndef FAR
  75442. # define FAR
  75443. #endif
  75444. #if !defined(__MACTYPES__)
  75445. typedef unsigned char Byte; /* 8 bits */
  75446. #endif
  75447. typedef unsigned int uInt; /* 16 bits or more */
  75448. typedef unsigned long uLong; /* 32 bits or more */
  75449. #ifdef SMALL_MEDIUM
  75450. # define Bytef Byte FAR
  75451. #else
  75452. typedef Byte FAR Bytef;
  75453. #endif
  75454. typedef char FAR charf;
  75455. typedef int FAR intf;
  75456. typedef uInt FAR uIntf;
  75457. typedef uLong FAR uLongf;
  75458. #ifdef STDC
  75459. typedef void const *voidpc;
  75460. typedef void FAR *voidpf;
  75461. typedef void *voidp;
  75462. #else
  75463. typedef Byte const *voidpc;
  75464. typedef Byte FAR *voidpf;
  75465. typedef Byte *voidp;
  75466. #endif
  75467. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  75468. # include <sys/types.h> /* for off_t */
  75469. # include <unistd.h> /* for SEEK_* and off_t */
  75470. # ifdef VMS
  75471. # include <unixio.h> /* for off_t */
  75472. # endif
  75473. # define z_off_t off_t
  75474. #endif
  75475. #ifndef SEEK_SET
  75476. # define SEEK_SET 0 /* Seek from beginning of file. */
  75477. # define SEEK_CUR 1 /* Seek from current position. */
  75478. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  75479. #endif
  75480. #ifndef z_off_t
  75481. # define z_off_t long
  75482. #endif
  75483. #if defined(__OS400__)
  75484. # define NO_vsnprintf
  75485. #endif
  75486. #if defined(__MVS__)
  75487. # define NO_vsnprintf
  75488. # ifdef FAR
  75489. # undef FAR
  75490. # endif
  75491. #endif
  75492. #if defined(__MVS__)
  75493. # pragma map(deflateInit_,"DEIN")
  75494. # pragma map(deflateInit2_,"DEIN2")
  75495. # pragma map(deflateEnd,"DEEND")
  75496. # pragma map(deflateBound,"DEBND")
  75497. # pragma map(inflateInit_,"ININ")
  75498. # pragma map(inflateInit2_,"ININ2")
  75499. # pragma map(inflateEnd,"INEND")
  75500. # pragma map(inflateSync,"INSY")
  75501. # pragma map(inflateSetDictionary,"INSEDI")
  75502. # pragma map(compressBound,"CMBND")
  75503. # pragma map(inflate_table,"INTABL")
  75504. # pragma map(inflate_fast,"INFA")
  75505. # pragma map(inflate_copyright,"INCOPY")
  75506. #endif
  75507. #endif /* ZCONF_H */
  75508. /*** End of inlined file: zconf.h ***/
  75509. #ifdef __cplusplus
  75510. extern "C" {
  75511. #endif
  75512. #define ZLIB_VERSION "1.2.3"
  75513. #define ZLIB_VERNUM 0x1230
  75514. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  75515. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  75516. struct internal_state;
  75517. typedef struct z_stream_s {
  75518. Bytef *next_in; /* next input byte */
  75519. uInt avail_in; /* number of bytes available at next_in */
  75520. uLong total_in; /* total nb of input bytes read so far */
  75521. Bytef *next_out; /* next output byte should be put there */
  75522. uInt avail_out; /* remaining free space at next_out */
  75523. uLong total_out; /* total nb of bytes output so far */
  75524. char *msg; /* last error message, NULL if no error */
  75525. struct internal_state FAR *state; /* not visible by applications */
  75526. alloc_func zalloc; /* used to allocate the internal state */
  75527. free_func zfree; /* used to free the internal state */
  75528. voidpf opaque; /* private data object passed to zalloc and zfree */
  75529. int data_type; /* best guess about the data type: binary or text */
  75530. uLong adler; /* adler32 value of the uncompressed data */
  75531. uLong reserved; /* reserved for future use */
  75532. } z_stream;
  75533. typedef z_stream FAR *z_streamp;
  75534. typedef struct gz_header_s {
  75535. int text; /* true if compressed data believed to be text */
  75536. uLong time; /* modification time */
  75537. int xflags; /* extra flags (not used when writing a gzip file) */
  75538. int os; /* operating system */
  75539. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  75540. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  75541. uInt extra_max; /* space at extra (only when reading header) */
  75542. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75543. uInt name_max; /* space at name (only when reading header) */
  75544. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75545. uInt comm_max; /* space at comment (only when reading header) */
  75546. int hcrc; /* true if there was or will be a header crc */
  75547. int done; /* true when done reading gzip header (not used
  75548. when writing a gzip file) */
  75549. } gz_header;
  75550. typedef gz_header FAR *gz_headerp;
  75551. #define Z_NO_FLUSH 0
  75552. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75553. #define Z_SYNC_FLUSH 2
  75554. #define Z_FULL_FLUSH 3
  75555. #define Z_FINISH 4
  75556. #define Z_BLOCK 5
  75557. #define Z_OK 0
  75558. #define Z_STREAM_END 1
  75559. #define Z_NEED_DICT 2
  75560. #define Z_ERRNO (-1)
  75561. #define Z_STREAM_ERROR (-2)
  75562. #define Z_DATA_ERROR (-3)
  75563. #define Z_MEM_ERROR (-4)
  75564. #define Z_BUF_ERROR (-5)
  75565. #define Z_VERSION_ERROR (-6)
  75566. #define Z_NO_COMPRESSION 0
  75567. #define Z_BEST_SPEED 1
  75568. #define Z_BEST_COMPRESSION 9
  75569. #define Z_DEFAULT_COMPRESSION (-1)
  75570. #define Z_FILTERED 1
  75571. #define Z_HUFFMAN_ONLY 2
  75572. #define Z_RLE 3
  75573. #define Z_FIXED 4
  75574. #define Z_DEFAULT_STRATEGY 0
  75575. #define Z_BINARY 0
  75576. #define Z_TEXT 1
  75577. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75578. #define Z_UNKNOWN 2
  75579. #define Z_DEFLATED 8
  75580. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75581. #define zlib_version zlibVersion()
  75582. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75583. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75584. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75585. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75586. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75587. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75588. const Bytef *dictionary,
  75589. uInt dictLength));
  75590. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75591. z_streamp source));
  75592. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75593. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75594. int level,
  75595. int strategy));
  75596. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75597. int good_length,
  75598. int max_lazy,
  75599. int nice_length,
  75600. int max_chain));
  75601. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75602. uLong sourceLen));
  75603. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75604. int bits,
  75605. int value));
  75606. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75607. gz_headerp head));
  75608. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75609. const Bytef *dictionary,
  75610. uInt dictLength));
  75611. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75612. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75613. z_streamp source));
  75614. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75615. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75616. int bits,
  75617. int value));
  75618. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75619. gz_headerp head));
  75620. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75621. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75622. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75623. in_func in, void FAR *in_desc,
  75624. out_func out, void FAR *out_desc));
  75625. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75626. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75627. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75628. const Bytef *source, uLong sourceLen));
  75629. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75630. const Bytef *source, uLong sourceLen,
  75631. int level));
  75632. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75633. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75634. const Bytef *source, uLong sourceLen));
  75635. typedef voidp gzFile;
  75636. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75637. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75638. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75639. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75640. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75641. voidpc buf, unsigned len));
  75642. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75643. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75644. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75645. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75646. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75647. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75648. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75649. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75650. z_off_t offset, int whence));
  75651. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75652. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75653. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75654. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75655. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75656. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75657. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75658. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75659. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75660. z_off_t len2));
  75661. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75662. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75663. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75664. const char *version, int stream_size));
  75665. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75666. const char *version, int stream_size));
  75667. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75668. int windowBits, int memLevel,
  75669. int strategy, const char *version,
  75670. int stream_size));
  75671. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75672. const char *version, int stream_size));
  75673. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75674. unsigned char FAR *window,
  75675. const char *version,
  75676. int stream_size));
  75677. #define deflateInit(strm, level) \
  75678. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75679. #define inflateInit(strm) \
  75680. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75681. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75682. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75683. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75684. #define inflateInit2(strm, windowBits) \
  75685. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75686. #define inflateBackInit(strm, windowBits, window) \
  75687. inflateBackInit_((strm), (windowBits), (window), \
  75688. ZLIB_VERSION, sizeof(z_stream))
  75689. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75690. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75691. #endif
  75692. ZEXTERN const char * ZEXPORT zError OF((int));
  75693. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75694. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75695. #ifdef __cplusplus
  75696. }
  75697. #endif
  75698. #endif /* ZLIB_H */
  75699. /*** End of inlined file: zlib.h ***/
  75700. #undef OS_CODE
  75701. #else
  75702. #include <zlib.h>
  75703. #endif
  75704. }
  75705. BEGIN_JUCE_NAMESPACE
  75706. using namespace zlibNamespace;
  75707. // internal helper object that holds the zlib structures so they don't have to be
  75708. // included publicly.
  75709. class GZIPCompressorHelper
  75710. {
  75711. public:
  75712. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75713. : data (0),
  75714. dataSize (0),
  75715. compLevel (compressionLevel),
  75716. strategy (0),
  75717. setParams (true),
  75718. streamIsValid (false),
  75719. finished (false),
  75720. shouldFinish (false)
  75721. {
  75722. zerostruct (stream);
  75723. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75724. nowrap ? -MAX_WBITS : MAX_WBITS,
  75725. 8, strategy) == Z_OK);
  75726. }
  75727. ~GZIPCompressorHelper()
  75728. {
  75729. if (streamIsValid)
  75730. deflateEnd (&stream);
  75731. }
  75732. bool needsInput() const throw()
  75733. {
  75734. return dataSize <= 0;
  75735. }
  75736. void setInput (uint8* const newData, const int size) throw()
  75737. {
  75738. data = newData;
  75739. dataSize = size;
  75740. }
  75741. int doNextBlock (uint8* const dest, const int destSize) throw()
  75742. {
  75743. if (streamIsValid)
  75744. {
  75745. stream.next_in = data;
  75746. stream.next_out = dest;
  75747. stream.avail_in = dataSize;
  75748. stream.avail_out = destSize;
  75749. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75750. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75751. setParams = false;
  75752. switch (result)
  75753. {
  75754. case Z_STREAM_END:
  75755. finished = true;
  75756. // Deliberate fall-through..
  75757. case Z_OK:
  75758. data += dataSize - stream.avail_in;
  75759. dataSize = stream.avail_in;
  75760. return destSize - stream.avail_out;
  75761. default:
  75762. break;
  75763. }
  75764. }
  75765. return 0;
  75766. }
  75767. private:
  75768. z_stream stream;
  75769. uint8* data;
  75770. int dataSize, compLevel, strategy;
  75771. bool setParams, streamIsValid;
  75772. public:
  75773. bool finished, shouldFinish;
  75774. };
  75775. const int gzipCompBufferSize = 32768;
  75776. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75777. int compressionLevel,
  75778. const bool deleteDestStream,
  75779. const bool noWrap)
  75780. : destStream (destStream_),
  75781. streamToDelete (deleteDestStream ? destStream_ : 0),
  75782. buffer (gzipCompBufferSize)
  75783. {
  75784. if (compressionLevel < 1 || compressionLevel > 9)
  75785. compressionLevel = -1;
  75786. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75787. }
  75788. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75789. {
  75790. flush();
  75791. }
  75792. void GZIPCompressorOutputStream::flush()
  75793. {
  75794. if (! helper->finished)
  75795. {
  75796. helper->shouldFinish = true;
  75797. while (! helper->finished)
  75798. doNextBlock();
  75799. }
  75800. destStream->flush();
  75801. }
  75802. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75803. {
  75804. if (! helper->finished)
  75805. {
  75806. helper->setInput ((uint8*) destBuffer, howMany);
  75807. while (! helper->needsInput())
  75808. {
  75809. if (! doNextBlock())
  75810. return false;
  75811. }
  75812. }
  75813. return true;
  75814. }
  75815. bool GZIPCompressorOutputStream::doNextBlock()
  75816. {
  75817. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75818. if (len > 0)
  75819. return destStream->write (buffer, len);
  75820. else
  75821. return true;
  75822. }
  75823. int64 GZIPCompressorOutputStream::getPosition()
  75824. {
  75825. return destStream->getPosition();
  75826. }
  75827. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75828. {
  75829. jassertfalse // can't do it!
  75830. return false;
  75831. }
  75832. END_JUCE_NAMESPACE
  75833. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75834. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75835. #if JUCE_MSVC
  75836. #pragma warning (push)
  75837. #pragma warning (disable: 4309 4305)
  75838. #endif
  75839. namespace zlibNamespace
  75840. {
  75841. #if JUCE_INCLUDE_ZLIB_CODE
  75842. extern "C"
  75843. {
  75844. #undef OS_CODE
  75845. #undef fdopen
  75846. #define ZLIB_INTERNAL
  75847. #define NO_DUMMY_DECL
  75848. /*** Start of inlined file: adler32.c ***/
  75849. #define ZLIB_INTERNAL
  75850. #define BASE 65521UL /* largest prime smaller than 65536 */
  75851. #define NMAX 5552
  75852. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75853. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75854. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75855. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75856. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75857. #ifdef NO_DIVIDE
  75858. # define MOD(a) \
  75859. do { \
  75860. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75861. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75862. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75863. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75864. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75865. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75866. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75867. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75868. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75869. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75870. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75871. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75872. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75873. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75874. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75875. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75876. if (a >= BASE) a -= BASE; \
  75877. } while (0)
  75878. # define MOD4(a) \
  75879. do { \
  75880. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75881. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75882. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75883. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75884. if (a >= BASE) a -= BASE; \
  75885. } while (0)
  75886. #else
  75887. # define MOD(a) a %= BASE
  75888. # define MOD4(a) a %= BASE
  75889. #endif
  75890. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75891. {
  75892. unsigned long sum2;
  75893. unsigned n;
  75894. sum2 = (adler >> 16) & 0xffff;
  75895. adler &= 0xffff;
  75896. if (len == 1) {
  75897. adler += buf[0];
  75898. if (adler >= BASE)
  75899. adler -= BASE;
  75900. sum2 += adler;
  75901. if (sum2 >= BASE)
  75902. sum2 -= BASE;
  75903. return adler | (sum2 << 16);
  75904. }
  75905. if (buf == Z_NULL)
  75906. return 1L;
  75907. if (len < 16) {
  75908. while (len--) {
  75909. adler += *buf++;
  75910. sum2 += adler;
  75911. }
  75912. if (adler >= BASE)
  75913. adler -= BASE;
  75914. MOD4(sum2); /* only added so many BASE's */
  75915. return adler | (sum2 << 16);
  75916. }
  75917. while (len >= NMAX) {
  75918. len -= NMAX;
  75919. n = NMAX / 16; /* NMAX is divisible by 16 */
  75920. do {
  75921. DO16(buf); /* 16 sums unrolled */
  75922. buf += 16;
  75923. } while (--n);
  75924. MOD(adler);
  75925. MOD(sum2);
  75926. }
  75927. if (len) { /* avoid modulos if none remaining */
  75928. while (len >= 16) {
  75929. len -= 16;
  75930. DO16(buf);
  75931. buf += 16;
  75932. }
  75933. while (len--) {
  75934. adler += *buf++;
  75935. sum2 += adler;
  75936. }
  75937. MOD(adler);
  75938. MOD(sum2);
  75939. }
  75940. return adler | (sum2 << 16);
  75941. }
  75942. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75943. {
  75944. unsigned long sum1;
  75945. unsigned long sum2;
  75946. unsigned rem;
  75947. rem = (unsigned)(len2 % BASE);
  75948. sum1 = adler1 & 0xffff;
  75949. sum2 = rem * sum1;
  75950. MOD(sum2);
  75951. sum1 += (adler2 & 0xffff) + BASE - 1;
  75952. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75953. if (sum1 > BASE) sum1 -= BASE;
  75954. if (sum1 > BASE) sum1 -= BASE;
  75955. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75956. if (sum2 > BASE) sum2 -= BASE;
  75957. return sum1 | (sum2 << 16);
  75958. }
  75959. /*** End of inlined file: adler32.c ***/
  75960. /*** Start of inlined file: compress.c ***/
  75961. #define ZLIB_INTERNAL
  75962. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75963. uLong sourceLen, int level)
  75964. {
  75965. z_stream stream;
  75966. int err;
  75967. stream.next_in = (Bytef*)source;
  75968. stream.avail_in = (uInt)sourceLen;
  75969. #ifdef MAXSEG_64K
  75970. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75971. #endif
  75972. stream.next_out = dest;
  75973. stream.avail_out = (uInt)*destLen;
  75974. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75975. stream.zalloc = (alloc_func)0;
  75976. stream.zfree = (free_func)0;
  75977. stream.opaque = (voidpf)0;
  75978. err = deflateInit(&stream, level);
  75979. if (err != Z_OK) return err;
  75980. err = deflate(&stream, Z_FINISH);
  75981. if (err != Z_STREAM_END) {
  75982. deflateEnd(&stream);
  75983. return err == Z_OK ? Z_BUF_ERROR : err;
  75984. }
  75985. *destLen = stream.total_out;
  75986. err = deflateEnd(&stream);
  75987. return err;
  75988. }
  75989. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75990. {
  75991. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75992. }
  75993. uLong ZEXPORT compressBound (uLong sourceLen)
  75994. {
  75995. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75996. }
  75997. /*** End of inlined file: compress.c ***/
  75998. #undef DO1
  75999. #undef DO8
  76000. /*** Start of inlined file: crc32.c ***/
  76001. #ifdef MAKECRCH
  76002. # include <stdio.h>
  76003. # ifndef DYNAMIC_CRC_TABLE
  76004. # define DYNAMIC_CRC_TABLE
  76005. # endif /* !DYNAMIC_CRC_TABLE */
  76006. #endif /* MAKECRCH */
  76007. /*** Start of inlined file: zutil.h ***/
  76008. #ifndef ZUTIL_H
  76009. #define ZUTIL_H
  76010. #define ZLIB_INTERNAL
  76011. #ifdef STDC
  76012. # ifndef _WIN32_WCE
  76013. # include <stddef.h>
  76014. # endif
  76015. # include <string.h>
  76016. # include <stdlib.h>
  76017. #endif
  76018. #ifdef NO_ERRNO_H
  76019. # ifdef _WIN32_WCE
  76020. # define errno z_errno
  76021. # endif
  76022. extern int errno;
  76023. #else
  76024. # ifndef _WIN32_WCE
  76025. # include <errno.h>
  76026. # endif
  76027. #endif
  76028. #ifndef local
  76029. # define local static
  76030. #endif
  76031. typedef unsigned char uch;
  76032. typedef uch FAR uchf;
  76033. typedef unsigned short ush;
  76034. typedef ush FAR ushf;
  76035. typedef unsigned long ulg;
  76036. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  76037. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  76038. #define ERR_RETURN(strm,err) \
  76039. return (strm->msg = (char*)ERR_MSG(err), (err))
  76040. #ifndef DEF_WBITS
  76041. # define DEF_WBITS MAX_WBITS
  76042. #endif
  76043. #if MAX_MEM_LEVEL >= 8
  76044. # define DEF_MEM_LEVEL 8
  76045. #else
  76046. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  76047. #endif
  76048. #define STORED_BLOCK 0
  76049. #define STATIC_TREES 1
  76050. #define DYN_TREES 2
  76051. #define MIN_MATCH 3
  76052. #define MAX_MATCH 258
  76053. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  76054. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  76055. # define OS_CODE 0x00
  76056. # if defined(__TURBOC__) || defined(__BORLANDC__)
  76057. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  76058. void _Cdecl farfree( void *block );
  76059. void *_Cdecl farmalloc( unsigned long nbytes );
  76060. # else
  76061. # include <alloc.h>
  76062. # endif
  76063. # else /* MSC or DJGPP */
  76064. # include <malloc.h>
  76065. # endif
  76066. #endif
  76067. #ifdef AMIGA
  76068. # define OS_CODE 0x01
  76069. #endif
  76070. #if defined(VAXC) || defined(VMS)
  76071. # define OS_CODE 0x02
  76072. # define F_OPEN(name, mode) \
  76073. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  76074. #endif
  76075. #if defined(ATARI) || defined(atarist)
  76076. # define OS_CODE 0x05
  76077. #endif
  76078. #ifdef OS2
  76079. # define OS_CODE 0x06
  76080. # ifdef M_I86
  76081. #include <malloc.h>
  76082. # endif
  76083. #endif
  76084. #if defined(MACOS) || TARGET_OS_MAC
  76085. # define OS_CODE 0x07
  76086. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  76087. # include <unix.h> /* for fdopen */
  76088. # else
  76089. # ifndef fdopen
  76090. # define fdopen(fd,mode) NULL /* No fdopen() */
  76091. # endif
  76092. # endif
  76093. #endif
  76094. #ifdef TOPS20
  76095. # define OS_CODE 0x0a
  76096. #endif
  76097. #ifdef WIN32
  76098. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  76099. # define OS_CODE 0x0b
  76100. # endif
  76101. #endif
  76102. #ifdef __50SERIES /* Prime/PRIMOS */
  76103. # define OS_CODE 0x0f
  76104. #endif
  76105. #if defined(_BEOS_) || defined(RISCOS)
  76106. # define fdopen(fd,mode) NULL /* No fdopen() */
  76107. #endif
  76108. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  76109. # if defined(_WIN32_WCE)
  76110. # define fdopen(fd,mode) NULL /* No fdopen() */
  76111. # ifndef _PTRDIFF_T_DEFINED
  76112. typedef int ptrdiff_t;
  76113. # define _PTRDIFF_T_DEFINED
  76114. # endif
  76115. # else
  76116. # define fdopen(fd,type) _fdopen(fd,type)
  76117. # endif
  76118. #endif
  76119. #ifndef OS_CODE
  76120. # define OS_CODE 0x03 /* assume Unix */
  76121. #endif
  76122. #ifndef F_OPEN
  76123. # define F_OPEN(name, mode) fopen((name), (mode))
  76124. #endif
  76125. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  76126. # ifndef HAVE_VSNPRINTF
  76127. # define HAVE_VSNPRINTF
  76128. # endif
  76129. #endif
  76130. #if defined(__CYGWIN__)
  76131. # ifndef HAVE_VSNPRINTF
  76132. # define HAVE_VSNPRINTF
  76133. # endif
  76134. #endif
  76135. #ifndef HAVE_VSNPRINTF
  76136. # ifdef MSDOS
  76137. # define NO_vsnprintf
  76138. # endif
  76139. # ifdef __TURBOC__
  76140. # define NO_vsnprintf
  76141. # endif
  76142. # ifdef WIN32
  76143. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  76144. # define vsnprintf _vsnprintf
  76145. # endif
  76146. # endif
  76147. # ifdef __SASC
  76148. # define NO_vsnprintf
  76149. # endif
  76150. #endif
  76151. #ifdef VMS
  76152. # define NO_vsnprintf
  76153. #endif
  76154. #if defined(pyr)
  76155. # define NO_MEMCPY
  76156. #endif
  76157. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  76158. # define NO_MEMCPY
  76159. #endif
  76160. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  76161. # define HAVE_MEMCPY
  76162. #endif
  76163. #ifdef HAVE_MEMCPY
  76164. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  76165. # define zmemcpy _fmemcpy
  76166. # define zmemcmp _fmemcmp
  76167. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  76168. # else
  76169. # define zmemcpy memcpy
  76170. # define zmemcmp memcmp
  76171. # define zmemzero(dest, len) memset(dest, 0, len)
  76172. # endif
  76173. #else
  76174. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  76175. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  76176. extern void zmemzero OF((Bytef* dest, uInt len));
  76177. #endif
  76178. #ifdef DEBUG
  76179. # include <stdio.h>
  76180. extern int z_verbose;
  76181. extern void z_error OF((const char *m));
  76182. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  76183. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  76184. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  76185. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  76186. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  76187. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  76188. #else
  76189. # define Assert(cond,msg)
  76190. # define Trace(x)
  76191. # define Tracev(x)
  76192. # define Tracevv(x)
  76193. # define Tracec(c,x)
  76194. # define Tracecv(c,x)
  76195. #endif
  76196. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  76197. void zcfree OF((voidpf opaque, voidpf ptr));
  76198. #define ZALLOC(strm, items, size) \
  76199. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  76200. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  76201. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  76202. #endif /* ZUTIL_H */
  76203. /*** End of inlined file: zutil.h ***/
  76204. /* for STDC and FAR definitions */
  76205. #define local static
  76206. #ifndef NOBYFOUR
  76207. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  76208. # include <limits.h>
  76209. # define BYFOUR
  76210. # if (UINT_MAX == 0xffffffffUL)
  76211. typedef unsigned int u4;
  76212. # else
  76213. # if (ULONG_MAX == 0xffffffffUL)
  76214. typedef unsigned long u4;
  76215. # else
  76216. # if (USHRT_MAX == 0xffffffffUL)
  76217. typedef unsigned short u4;
  76218. # else
  76219. # undef BYFOUR /* can't find a four-byte integer type! */
  76220. # endif
  76221. # endif
  76222. # endif
  76223. # endif /* STDC */
  76224. #endif /* !NOBYFOUR */
  76225. #ifdef BYFOUR
  76226. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  76227. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  76228. local unsigned long crc32_little OF((unsigned long,
  76229. const unsigned char FAR *, unsigned));
  76230. local unsigned long crc32_big OF((unsigned long,
  76231. const unsigned char FAR *, unsigned));
  76232. # define TBLS 8
  76233. #else
  76234. # define TBLS 1
  76235. #endif /* BYFOUR */
  76236. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  76237. unsigned long vec));
  76238. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  76239. #ifdef DYNAMIC_CRC_TABLE
  76240. local volatile int crc_table_empty = 1;
  76241. local unsigned long FAR crc_table[TBLS][256];
  76242. local void make_crc_table OF((void));
  76243. #ifdef MAKECRCH
  76244. local void write_table OF((FILE *, const unsigned long FAR *));
  76245. #endif /* MAKECRCH */
  76246. local void make_crc_table()
  76247. {
  76248. unsigned long c;
  76249. int n, k;
  76250. unsigned long poly; /* polynomial exclusive-or pattern */
  76251. static volatile int first = 1; /* flag to limit concurrent making */
  76252. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  76253. if (first) {
  76254. first = 0;
  76255. poly = 0UL;
  76256. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  76257. poly |= 1UL << (31 - p[n]);
  76258. for (n = 0; n < 256; n++) {
  76259. c = (unsigned long)n;
  76260. for (k = 0; k < 8; k++)
  76261. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  76262. crc_table[0][n] = c;
  76263. }
  76264. #ifdef BYFOUR
  76265. for (n = 0; n < 256; n++) {
  76266. c = crc_table[0][n];
  76267. crc_table[4][n] = REV(c);
  76268. for (k = 1; k < 4; k++) {
  76269. c = crc_table[0][c & 0xff] ^ (c >> 8);
  76270. crc_table[k][n] = c;
  76271. crc_table[k + 4][n] = REV(c);
  76272. }
  76273. }
  76274. #endif /* BYFOUR */
  76275. crc_table_empty = 0;
  76276. }
  76277. else { /* not first */
  76278. while (crc_table_empty)
  76279. ;
  76280. }
  76281. #ifdef MAKECRCH
  76282. {
  76283. FILE *out;
  76284. out = fopen("crc32.h", "w");
  76285. if (out == NULL) return;
  76286. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  76287. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  76288. fprintf(out, "local const unsigned long FAR ");
  76289. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  76290. write_table(out, crc_table[0]);
  76291. # ifdef BYFOUR
  76292. fprintf(out, "#ifdef BYFOUR\n");
  76293. for (k = 1; k < 8; k++) {
  76294. fprintf(out, " },\n {\n");
  76295. write_table(out, crc_table[k]);
  76296. }
  76297. fprintf(out, "#endif\n");
  76298. # endif /* BYFOUR */
  76299. fprintf(out, " }\n};\n");
  76300. fclose(out);
  76301. }
  76302. #endif /* MAKECRCH */
  76303. }
  76304. #ifdef MAKECRCH
  76305. local void write_table(out, table)
  76306. FILE *out;
  76307. const unsigned long FAR *table;
  76308. {
  76309. int n;
  76310. for (n = 0; n < 256; n++)
  76311. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  76312. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  76313. }
  76314. #endif /* MAKECRCH */
  76315. #else /* !DYNAMIC_CRC_TABLE */
  76316. /*** Start of inlined file: crc32.h ***/
  76317. local const unsigned long FAR crc_table[TBLS][256] =
  76318. {
  76319. {
  76320. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  76321. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  76322. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  76323. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  76324. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  76325. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  76326. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  76327. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  76328. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  76329. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  76330. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  76331. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  76332. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  76333. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  76334. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  76335. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  76336. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  76337. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  76338. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  76339. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  76340. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  76341. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  76342. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  76343. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  76344. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  76345. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  76346. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  76347. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  76348. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  76349. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  76350. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  76351. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  76352. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  76353. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  76354. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  76355. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  76356. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  76357. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  76358. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  76359. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  76360. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  76361. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  76362. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  76363. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  76364. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  76365. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  76366. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  76367. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  76368. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  76369. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  76370. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  76371. 0x2d02ef8dUL
  76372. #ifdef BYFOUR
  76373. },
  76374. {
  76375. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  76376. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  76377. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  76378. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  76379. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  76380. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  76381. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  76382. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  76383. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  76384. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  76385. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  76386. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  76387. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  76388. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  76389. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  76390. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  76391. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  76392. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  76393. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  76394. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  76395. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  76396. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  76397. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  76398. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  76399. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  76400. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  76401. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  76402. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  76403. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  76404. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  76405. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  76406. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  76407. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  76408. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  76409. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  76410. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  76411. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  76412. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  76413. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  76414. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  76415. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  76416. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  76417. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  76418. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  76419. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  76420. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  76421. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  76422. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  76423. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  76424. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  76425. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  76426. 0x9324fd72UL
  76427. },
  76428. {
  76429. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  76430. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  76431. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  76432. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  76433. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  76434. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  76435. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  76436. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  76437. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  76438. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  76439. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  76440. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  76441. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  76442. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  76443. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  76444. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  76445. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  76446. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  76447. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  76448. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  76449. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  76450. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  76451. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  76452. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  76453. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  76454. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  76455. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  76456. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  76457. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  76458. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  76459. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  76460. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  76461. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  76462. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  76463. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  76464. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  76465. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  76466. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  76467. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  76468. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  76469. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  76470. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  76471. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  76472. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  76473. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  76474. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  76475. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  76476. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  76477. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  76478. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  76479. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  76480. 0xbe9834edUL
  76481. },
  76482. {
  76483. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  76484. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  76485. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  76486. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  76487. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  76488. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  76489. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  76490. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  76491. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  76492. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  76493. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  76494. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  76495. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  76496. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  76497. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  76498. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  76499. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  76500. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  76501. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  76502. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  76503. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  76504. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  76505. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  76506. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  76507. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  76508. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  76509. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  76510. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  76511. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  76512. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  76513. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  76514. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  76515. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  76516. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  76517. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  76518. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  76519. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  76520. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  76521. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  76522. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  76523. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  76524. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  76525. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  76526. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  76527. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  76528. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  76529. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  76530. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  76531. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  76532. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  76533. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  76534. 0xde0506f1UL
  76535. },
  76536. {
  76537. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  76538. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  76539. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76540. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76541. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76542. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76543. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76544. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76545. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76546. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76547. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76548. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76549. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76550. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76551. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76552. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76553. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76554. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76555. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76556. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76557. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76558. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76559. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76560. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76561. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76562. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76563. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76564. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76565. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76566. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76567. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76568. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76569. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76570. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76571. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76572. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76573. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76574. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76575. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76576. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76577. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76578. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76579. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76580. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76581. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76582. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76583. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76584. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76585. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76586. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76587. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76588. 0x8def022dUL
  76589. },
  76590. {
  76591. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76592. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76593. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76594. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76595. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76596. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76597. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76598. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76599. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76600. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76601. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76602. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76603. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76604. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76605. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76606. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76607. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76608. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76609. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76610. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76611. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76612. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76613. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76614. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76615. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76616. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76617. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76618. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76619. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76620. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76621. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76622. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76623. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76624. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76625. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76626. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76627. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76628. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76629. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76630. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76631. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76632. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76633. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76634. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76635. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76636. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76637. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76638. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76639. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76640. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76641. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76642. 0x72fd2493UL
  76643. },
  76644. {
  76645. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76646. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76647. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76648. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76649. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76650. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76651. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76652. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76653. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76654. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76655. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76656. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76657. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76658. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76659. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76660. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76661. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76662. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76663. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76664. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76665. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76666. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76667. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76668. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76669. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76670. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76671. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76672. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76673. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76674. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76675. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76676. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76677. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76678. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76679. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76680. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76681. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76682. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76683. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76684. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76685. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76686. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76687. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76688. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76689. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76690. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76691. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76692. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76693. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76694. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76695. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76696. 0xed3498beUL
  76697. },
  76698. {
  76699. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76700. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76701. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76702. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76703. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76704. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76705. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76706. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76707. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76708. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76709. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76710. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76711. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76712. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76713. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76714. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76715. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76716. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76717. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76718. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76719. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76720. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76721. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76722. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76723. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76724. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76725. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76726. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76727. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76728. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76729. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76730. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76731. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76732. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76733. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76734. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76735. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76736. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76737. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76738. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76739. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76740. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76741. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76742. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76743. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76744. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76745. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76746. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76747. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76748. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76749. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76750. 0xf10605deUL
  76751. #endif
  76752. }
  76753. };
  76754. /*** End of inlined file: crc32.h ***/
  76755. #endif /* DYNAMIC_CRC_TABLE */
  76756. const unsigned long FAR * ZEXPORT get_crc_table()
  76757. {
  76758. #ifdef DYNAMIC_CRC_TABLE
  76759. if (crc_table_empty)
  76760. make_crc_table();
  76761. #endif /* DYNAMIC_CRC_TABLE */
  76762. return (const unsigned long FAR *)crc_table;
  76763. }
  76764. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76765. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76766. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76767. {
  76768. if (buf == Z_NULL) return 0UL;
  76769. #ifdef DYNAMIC_CRC_TABLE
  76770. if (crc_table_empty)
  76771. make_crc_table();
  76772. #endif /* DYNAMIC_CRC_TABLE */
  76773. #ifdef BYFOUR
  76774. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76775. u4 endian;
  76776. endian = 1;
  76777. if (*((unsigned char *)(&endian)))
  76778. return crc32_little(crc, buf, len);
  76779. else
  76780. return crc32_big(crc, buf, len);
  76781. }
  76782. #endif /* BYFOUR */
  76783. crc = crc ^ 0xffffffffUL;
  76784. while (len >= 8) {
  76785. DO8;
  76786. len -= 8;
  76787. }
  76788. if (len) do {
  76789. DO1;
  76790. } while (--len);
  76791. return crc ^ 0xffffffffUL;
  76792. }
  76793. #ifdef BYFOUR
  76794. #define DOLIT4 c ^= *buf4++; \
  76795. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76796. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76797. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76798. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76799. {
  76800. register u4 c;
  76801. register const u4 FAR *buf4;
  76802. c = (u4)crc;
  76803. c = ~c;
  76804. while (len && ((ptrdiff_t)buf & 3)) {
  76805. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76806. len--;
  76807. }
  76808. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76809. while (len >= 32) {
  76810. DOLIT32;
  76811. len -= 32;
  76812. }
  76813. while (len >= 4) {
  76814. DOLIT4;
  76815. len -= 4;
  76816. }
  76817. buf = (const unsigned char FAR *)buf4;
  76818. if (len) do {
  76819. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76820. } while (--len);
  76821. c = ~c;
  76822. return (unsigned long)c;
  76823. }
  76824. #define DOBIG4 c ^= *++buf4; \
  76825. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76826. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76827. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76828. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76829. {
  76830. register u4 c;
  76831. register const u4 FAR *buf4;
  76832. c = REV((u4)crc);
  76833. c = ~c;
  76834. while (len && ((ptrdiff_t)buf & 3)) {
  76835. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76836. len--;
  76837. }
  76838. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76839. buf4--;
  76840. while (len >= 32) {
  76841. DOBIG32;
  76842. len -= 32;
  76843. }
  76844. while (len >= 4) {
  76845. DOBIG4;
  76846. len -= 4;
  76847. }
  76848. buf4++;
  76849. buf = (const unsigned char FAR *)buf4;
  76850. if (len) do {
  76851. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76852. } while (--len);
  76853. c = ~c;
  76854. return (unsigned long)(REV(c));
  76855. }
  76856. #endif /* BYFOUR */
  76857. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76858. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76859. {
  76860. unsigned long sum;
  76861. sum = 0;
  76862. while (vec) {
  76863. if (vec & 1)
  76864. sum ^= *mat;
  76865. vec >>= 1;
  76866. mat++;
  76867. }
  76868. return sum;
  76869. }
  76870. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76871. {
  76872. int n;
  76873. for (n = 0; n < GF2_DIM; n++)
  76874. square[n] = gf2_matrix_times(mat, mat[n]);
  76875. }
  76876. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76877. {
  76878. int n;
  76879. unsigned long row;
  76880. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76881. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76882. if (len2 == 0)
  76883. return crc1;
  76884. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76885. row = 1;
  76886. for (n = 1; n < GF2_DIM; n++) {
  76887. odd[n] = row;
  76888. row <<= 1;
  76889. }
  76890. gf2_matrix_square(even, odd);
  76891. gf2_matrix_square(odd, even);
  76892. do {
  76893. gf2_matrix_square(even, odd);
  76894. if (len2 & 1)
  76895. crc1 = gf2_matrix_times(even, crc1);
  76896. len2 >>= 1;
  76897. if (len2 == 0)
  76898. break;
  76899. gf2_matrix_square(odd, even);
  76900. if (len2 & 1)
  76901. crc1 = gf2_matrix_times(odd, crc1);
  76902. len2 >>= 1;
  76903. } while (len2 != 0);
  76904. crc1 ^= crc2;
  76905. return crc1;
  76906. }
  76907. /*** End of inlined file: crc32.c ***/
  76908. /*** Start of inlined file: deflate.c ***/
  76909. /*** Start of inlined file: deflate.h ***/
  76910. #ifndef DEFLATE_H
  76911. #define DEFLATE_H
  76912. #ifndef NO_GZIP
  76913. # define GZIP
  76914. #endif
  76915. #define NO_DUMMY_DECL
  76916. #define LENGTH_CODES 29
  76917. #define LITERALS 256
  76918. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76919. #define D_CODES 30
  76920. #define BL_CODES 19
  76921. #define HEAP_SIZE (2*L_CODES+1)
  76922. #define MAX_BITS 15
  76923. #define INIT_STATE 42
  76924. #define EXTRA_STATE 69
  76925. #define NAME_STATE 73
  76926. #define COMMENT_STATE 91
  76927. #define HCRC_STATE 103
  76928. #define BUSY_STATE 113
  76929. #define FINISH_STATE 666
  76930. typedef struct ct_data_s {
  76931. union {
  76932. ush freq; /* frequency count */
  76933. ush code; /* bit string */
  76934. } fc;
  76935. union {
  76936. ush dad; /* father node in Huffman tree */
  76937. ush len; /* length of bit string */
  76938. } dl;
  76939. } FAR ct_data;
  76940. #define Freq fc.freq
  76941. #define Code fc.code
  76942. #define Dad dl.dad
  76943. #define Len dl.len
  76944. typedef struct static_tree_desc_s static_tree_desc;
  76945. typedef struct tree_desc_s {
  76946. ct_data *dyn_tree; /* the dynamic tree */
  76947. int max_code; /* largest code with non zero frequency */
  76948. static_tree_desc *stat_desc; /* the corresponding static tree */
  76949. } FAR tree_desc;
  76950. typedef ush Pos;
  76951. typedef Pos FAR Posf;
  76952. typedef unsigned IPos;
  76953. typedef struct internal_state {
  76954. z_streamp strm; /* pointer back to this zlib stream */
  76955. int status; /* as the name implies */
  76956. Bytef *pending_buf; /* output still pending */
  76957. ulg pending_buf_size; /* size of pending_buf */
  76958. Bytef *pending_out; /* next pending byte to output to the stream */
  76959. uInt pending; /* nb of bytes in the pending buffer */
  76960. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76961. gz_headerp gzhead; /* gzip header information to write */
  76962. uInt gzindex; /* where in extra, name, or comment */
  76963. Byte method; /* STORED (for zip only) or DEFLATED */
  76964. int last_flush; /* value of flush param for previous deflate call */
  76965. uInt w_size; /* LZ77 window size (32K by default) */
  76966. uInt w_bits; /* log2(w_size) (8..16) */
  76967. uInt w_mask; /* w_size - 1 */
  76968. Bytef *window;
  76969. ulg window_size;
  76970. Posf *prev;
  76971. Posf *head; /* Heads of the hash chains or NIL. */
  76972. uInt ins_h; /* hash index of string to be inserted */
  76973. uInt hash_size; /* number of elements in hash table */
  76974. uInt hash_bits; /* log2(hash_size) */
  76975. uInt hash_mask; /* hash_size-1 */
  76976. uInt hash_shift;
  76977. long block_start;
  76978. uInt match_length; /* length of best match */
  76979. IPos prev_match; /* previous match */
  76980. int match_available; /* set if previous match exists */
  76981. uInt strstart; /* start of string to insert */
  76982. uInt match_start; /* start of matching string */
  76983. uInt lookahead; /* number of valid bytes ahead in window */
  76984. uInt prev_length;
  76985. uInt max_chain_length;
  76986. uInt max_lazy_match;
  76987. # define max_insert_length max_lazy_match
  76988. int level; /* compression level (1..9) */
  76989. int strategy; /* favor or force Huffman coding*/
  76990. uInt good_match;
  76991. int nice_match; /* Stop searching when current match exceeds this */
  76992. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76993. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76994. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76995. struct tree_desc_s l_desc; /* desc. for literal tree */
  76996. struct tree_desc_s d_desc; /* desc. for distance tree */
  76997. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76998. ush bl_count[MAX_BITS+1];
  76999. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  77000. int heap_len; /* number of elements in the heap */
  77001. int heap_max; /* element of largest frequency */
  77002. uch depth[2*L_CODES+1];
  77003. uchf *l_buf; /* buffer for literals or lengths */
  77004. uInt lit_bufsize;
  77005. uInt last_lit; /* running index in l_buf */
  77006. ushf *d_buf;
  77007. ulg opt_len; /* bit length of current block with optimal trees */
  77008. ulg static_len; /* bit length of current block with static trees */
  77009. uInt matches; /* number of string matches in current block */
  77010. int last_eob_len; /* bit length of EOB code for last block */
  77011. #ifdef DEBUG
  77012. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  77013. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  77014. #endif
  77015. ush bi_buf;
  77016. int bi_valid;
  77017. } FAR deflate_state;
  77018. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  77019. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  77020. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  77021. void _tr_init OF((deflate_state *s));
  77022. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  77023. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  77024. int eof));
  77025. void _tr_align OF((deflate_state *s));
  77026. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  77027. int eof));
  77028. #define d_code(dist) \
  77029. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  77030. #ifndef DEBUG
  77031. #if defined(GEN_TREES_H) || !defined(STDC)
  77032. extern uch _length_code[];
  77033. extern uch _dist_code[];
  77034. #else
  77035. extern const uch _length_code[];
  77036. extern const uch _dist_code[];
  77037. #endif
  77038. # define _tr_tally_lit(s, c, flush) \
  77039. { uch cc = (c); \
  77040. s->d_buf[s->last_lit] = 0; \
  77041. s->l_buf[s->last_lit++] = cc; \
  77042. s->dyn_ltree[cc].Freq++; \
  77043. flush = (s->last_lit == s->lit_bufsize-1); \
  77044. }
  77045. # define _tr_tally_dist(s, distance, length, flush) \
  77046. { uch len = (length); \
  77047. ush dist = (distance); \
  77048. s->d_buf[s->last_lit] = dist; \
  77049. s->l_buf[s->last_lit++] = len; \
  77050. dist--; \
  77051. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  77052. s->dyn_dtree[d_code(dist)].Freq++; \
  77053. flush = (s->last_lit == s->lit_bufsize-1); \
  77054. }
  77055. #else
  77056. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  77057. # define _tr_tally_dist(s, distance, length, flush) \
  77058. flush = _tr_tally(s, distance, length)
  77059. #endif
  77060. #endif /* DEFLATE_H */
  77061. /*** End of inlined file: deflate.h ***/
  77062. const char deflate_copyright[] =
  77063. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  77064. typedef enum {
  77065. need_more, /* block not completed, need more input or more output */
  77066. block_done, /* block flush performed */
  77067. finish_started, /* finish started, need only more output at next deflate */
  77068. finish_done /* finish done, accept no more input or output */
  77069. } block_state;
  77070. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  77071. local void fill_window OF((deflate_state *s));
  77072. local block_state deflate_stored OF((deflate_state *s, int flush));
  77073. local block_state deflate_fast OF((deflate_state *s, int flush));
  77074. #ifndef FASTEST
  77075. local block_state deflate_slow OF((deflate_state *s, int flush));
  77076. #endif
  77077. local void lm_init OF((deflate_state *s));
  77078. local void putShortMSB OF((deflate_state *s, uInt b));
  77079. local void flush_pending OF((z_streamp strm));
  77080. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  77081. #ifndef FASTEST
  77082. #ifdef ASMV
  77083. void match_init OF((void)); /* asm code initialization */
  77084. uInt longest_match OF((deflate_state *s, IPos cur_match));
  77085. #else
  77086. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  77087. #endif
  77088. #endif
  77089. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  77090. #ifdef DEBUG
  77091. local void check_match OF((deflate_state *s, IPos start, IPos match,
  77092. int length));
  77093. #endif
  77094. #define NIL 0
  77095. #ifndef TOO_FAR
  77096. # define TOO_FAR 4096
  77097. #endif
  77098. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  77099. typedef struct config_s {
  77100. ush good_length; /* reduce lazy search above this match length */
  77101. ush max_lazy; /* do not perform lazy search above this match length */
  77102. ush nice_length; /* quit search above this match length */
  77103. ush max_chain;
  77104. compress_func func;
  77105. } config;
  77106. #ifdef FASTEST
  77107. local const config configuration_table[2] = {
  77108. {0, 0, 0, 0, deflate_stored}, /* store only */
  77109. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  77110. #else
  77111. local const config configuration_table[10] = {
  77112. {0, 0, 0, 0, deflate_stored}, /* store only */
  77113. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  77114. {4, 5, 16, 8, deflate_fast},
  77115. {4, 6, 32, 32, deflate_fast},
  77116. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  77117. {8, 16, 32, 32, deflate_slow},
  77118. {8, 16, 128, 128, deflate_slow},
  77119. {8, 32, 128, 256, deflate_slow},
  77120. {32, 128, 258, 1024, deflate_slow},
  77121. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  77122. #endif
  77123. #define EQUAL 0
  77124. #ifndef NO_DUMMY_DECL
  77125. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  77126. #endif
  77127. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  77128. #ifdef FASTEST
  77129. #define INSERT_STRING(s, str, match_head) \
  77130. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77131. match_head = s->head[s->ins_h], \
  77132. s->head[s->ins_h] = (Pos)(str))
  77133. #else
  77134. #define INSERT_STRING(s, str, match_head) \
  77135. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77136. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  77137. s->head[s->ins_h] = (Pos)(str))
  77138. #endif
  77139. #define CLEAR_HASH(s) \
  77140. s->head[s->hash_size-1] = NIL; \
  77141. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  77142. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  77143. {
  77144. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  77145. Z_DEFAULT_STRATEGY, version, stream_size);
  77146. }
  77147. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  77148. {
  77149. deflate_state *s;
  77150. int wrap = 1;
  77151. static const char my_version[] = ZLIB_VERSION;
  77152. ushf *overlay;
  77153. if (version == Z_NULL || version[0] != my_version[0] ||
  77154. stream_size != sizeof(z_stream)) {
  77155. return Z_VERSION_ERROR;
  77156. }
  77157. if (strm == Z_NULL) return Z_STREAM_ERROR;
  77158. strm->msg = Z_NULL;
  77159. if (strm->zalloc == (alloc_func)0) {
  77160. strm->zalloc = zcalloc;
  77161. strm->opaque = (voidpf)0;
  77162. }
  77163. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  77164. #ifdef FASTEST
  77165. if (level != 0) level = 1;
  77166. #else
  77167. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77168. #endif
  77169. if (windowBits < 0) { /* suppress zlib wrapper */
  77170. wrap = 0;
  77171. windowBits = -windowBits;
  77172. }
  77173. #ifdef GZIP
  77174. else if (windowBits > 15) {
  77175. wrap = 2; /* write gzip wrapper instead */
  77176. windowBits -= 16;
  77177. }
  77178. #endif
  77179. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  77180. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  77181. strategy < 0 || strategy > Z_FIXED) {
  77182. return Z_STREAM_ERROR;
  77183. }
  77184. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  77185. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  77186. if (s == Z_NULL) return Z_MEM_ERROR;
  77187. strm->state = (struct internal_state FAR *)s;
  77188. s->strm = strm;
  77189. s->wrap = wrap;
  77190. s->gzhead = Z_NULL;
  77191. s->w_bits = windowBits;
  77192. s->w_size = 1 << s->w_bits;
  77193. s->w_mask = s->w_size - 1;
  77194. s->hash_bits = memLevel + 7;
  77195. s->hash_size = 1 << s->hash_bits;
  77196. s->hash_mask = s->hash_size - 1;
  77197. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  77198. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  77199. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  77200. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  77201. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  77202. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  77203. s->pending_buf = (uchf *) overlay;
  77204. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  77205. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  77206. s->pending_buf == Z_NULL) {
  77207. s->status = FINISH_STATE;
  77208. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  77209. deflateEnd (strm);
  77210. return Z_MEM_ERROR;
  77211. }
  77212. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  77213. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  77214. s->level = level;
  77215. s->strategy = strategy;
  77216. s->method = (Byte)method;
  77217. return deflateReset(strm);
  77218. }
  77219. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  77220. {
  77221. deflate_state *s;
  77222. uInt length = dictLength;
  77223. uInt n;
  77224. IPos hash_head = 0;
  77225. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  77226. strm->state->wrap == 2 ||
  77227. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  77228. return Z_STREAM_ERROR;
  77229. s = strm->state;
  77230. if (s->wrap)
  77231. strm->adler = adler32(strm->adler, dictionary, dictLength);
  77232. if (length < MIN_MATCH) return Z_OK;
  77233. if (length > MAX_DIST(s)) {
  77234. length = MAX_DIST(s);
  77235. dictionary += dictLength - length; /* use the tail of the dictionary */
  77236. }
  77237. zmemcpy(s->window, dictionary, length);
  77238. s->strstart = length;
  77239. s->block_start = (long)length;
  77240. s->ins_h = s->window[0];
  77241. UPDATE_HASH(s, s->ins_h, s->window[1]);
  77242. for (n = 0; n <= length - MIN_MATCH; n++) {
  77243. INSERT_STRING(s, n, hash_head);
  77244. }
  77245. if (hash_head) hash_head = 0; /* to make compiler happy */
  77246. return Z_OK;
  77247. }
  77248. int ZEXPORT deflateReset (z_streamp strm)
  77249. {
  77250. deflate_state *s;
  77251. if (strm == Z_NULL || strm->state == Z_NULL ||
  77252. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  77253. return Z_STREAM_ERROR;
  77254. }
  77255. strm->total_in = strm->total_out = 0;
  77256. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  77257. strm->data_type = Z_UNKNOWN;
  77258. s = (deflate_state *)strm->state;
  77259. s->pending = 0;
  77260. s->pending_out = s->pending_buf;
  77261. if (s->wrap < 0) {
  77262. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  77263. }
  77264. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  77265. strm->adler =
  77266. #ifdef GZIP
  77267. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  77268. #endif
  77269. adler32(0L, Z_NULL, 0);
  77270. s->last_flush = Z_NO_FLUSH;
  77271. _tr_init(s);
  77272. lm_init(s);
  77273. return Z_OK;
  77274. }
  77275. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  77276. {
  77277. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77278. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  77279. strm->state->gzhead = head;
  77280. return Z_OK;
  77281. }
  77282. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  77283. {
  77284. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77285. strm->state->bi_valid = bits;
  77286. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  77287. return Z_OK;
  77288. }
  77289. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  77290. {
  77291. deflate_state *s;
  77292. compress_func func;
  77293. int err = Z_OK;
  77294. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77295. s = strm->state;
  77296. #ifdef FASTEST
  77297. if (level != 0) level = 1;
  77298. #else
  77299. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77300. #endif
  77301. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  77302. return Z_STREAM_ERROR;
  77303. }
  77304. func = configuration_table[s->level].func;
  77305. if (func != configuration_table[level].func && strm->total_in != 0) {
  77306. err = deflate(strm, Z_PARTIAL_FLUSH);
  77307. }
  77308. if (s->level != level) {
  77309. s->level = level;
  77310. s->max_lazy_match = configuration_table[level].max_lazy;
  77311. s->good_match = configuration_table[level].good_length;
  77312. s->nice_match = configuration_table[level].nice_length;
  77313. s->max_chain_length = configuration_table[level].max_chain;
  77314. }
  77315. s->strategy = strategy;
  77316. return err;
  77317. }
  77318. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  77319. {
  77320. deflate_state *s;
  77321. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77322. s = strm->state;
  77323. s->good_match = good_length;
  77324. s->max_lazy_match = max_lazy;
  77325. s->nice_match = nice_length;
  77326. s->max_chain_length = max_chain;
  77327. return Z_OK;
  77328. }
  77329. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  77330. {
  77331. deflate_state *s;
  77332. uLong destLen;
  77333. destLen = sourceLen +
  77334. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  77335. if (strm == Z_NULL || strm->state == Z_NULL)
  77336. return destLen;
  77337. s = strm->state;
  77338. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  77339. return destLen;
  77340. return compressBound(sourceLen);
  77341. }
  77342. local void putShortMSB (deflate_state *s, uInt b)
  77343. {
  77344. put_byte(s, (Byte)(b >> 8));
  77345. put_byte(s, (Byte)(b & 0xff));
  77346. }
  77347. local void flush_pending (z_streamp strm)
  77348. {
  77349. unsigned len = strm->state->pending;
  77350. if (len > strm->avail_out) len = strm->avail_out;
  77351. if (len == 0) return;
  77352. zmemcpy(strm->next_out, strm->state->pending_out, len);
  77353. strm->next_out += len;
  77354. strm->state->pending_out += len;
  77355. strm->total_out += len;
  77356. strm->avail_out -= len;
  77357. strm->state->pending -= len;
  77358. if (strm->state->pending == 0) {
  77359. strm->state->pending_out = strm->state->pending_buf;
  77360. }
  77361. }
  77362. int ZEXPORT deflate (z_streamp strm, int flush)
  77363. {
  77364. int old_flush; /* value of flush param for previous deflate call */
  77365. deflate_state *s;
  77366. if (strm == Z_NULL || strm->state == Z_NULL ||
  77367. flush > Z_FINISH || flush < 0) {
  77368. return Z_STREAM_ERROR;
  77369. }
  77370. s = strm->state;
  77371. if (strm->next_out == Z_NULL ||
  77372. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  77373. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  77374. ERR_RETURN(strm, Z_STREAM_ERROR);
  77375. }
  77376. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  77377. s->strm = strm; /* just in case */
  77378. old_flush = s->last_flush;
  77379. s->last_flush = flush;
  77380. if (s->status == INIT_STATE) {
  77381. #ifdef GZIP
  77382. if (s->wrap == 2) {
  77383. strm->adler = crc32(0L, Z_NULL, 0);
  77384. put_byte(s, 31);
  77385. put_byte(s, 139);
  77386. put_byte(s, 8);
  77387. if (s->gzhead == NULL) {
  77388. put_byte(s, 0);
  77389. put_byte(s, 0);
  77390. put_byte(s, 0);
  77391. put_byte(s, 0);
  77392. put_byte(s, 0);
  77393. put_byte(s, s->level == 9 ? 2 :
  77394. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77395. 4 : 0));
  77396. put_byte(s, OS_CODE);
  77397. s->status = BUSY_STATE;
  77398. }
  77399. else {
  77400. put_byte(s, (s->gzhead->text ? 1 : 0) +
  77401. (s->gzhead->hcrc ? 2 : 0) +
  77402. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  77403. (s->gzhead->name == Z_NULL ? 0 : 8) +
  77404. (s->gzhead->comment == Z_NULL ? 0 : 16)
  77405. );
  77406. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  77407. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  77408. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  77409. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  77410. put_byte(s, s->level == 9 ? 2 :
  77411. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77412. 4 : 0));
  77413. put_byte(s, s->gzhead->os & 0xff);
  77414. if (s->gzhead->extra != NULL) {
  77415. put_byte(s, s->gzhead->extra_len & 0xff);
  77416. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  77417. }
  77418. if (s->gzhead->hcrc)
  77419. strm->adler = crc32(strm->adler, s->pending_buf,
  77420. s->pending);
  77421. s->gzindex = 0;
  77422. s->status = EXTRA_STATE;
  77423. }
  77424. }
  77425. else
  77426. #endif
  77427. {
  77428. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  77429. uInt level_flags;
  77430. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  77431. level_flags = 0;
  77432. else if (s->level < 6)
  77433. level_flags = 1;
  77434. else if (s->level == 6)
  77435. level_flags = 2;
  77436. else
  77437. level_flags = 3;
  77438. header |= (level_flags << 6);
  77439. if (s->strstart != 0) header |= PRESET_DICT;
  77440. header += 31 - (header % 31);
  77441. s->status = BUSY_STATE;
  77442. putShortMSB(s, header);
  77443. if (s->strstart != 0) {
  77444. putShortMSB(s, (uInt)(strm->adler >> 16));
  77445. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77446. }
  77447. strm->adler = adler32(0L, Z_NULL, 0);
  77448. }
  77449. }
  77450. #ifdef GZIP
  77451. if (s->status == EXTRA_STATE) {
  77452. if (s->gzhead->extra != NULL) {
  77453. uInt beg = s->pending; /* start of bytes to update crc */
  77454. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  77455. if (s->pending == s->pending_buf_size) {
  77456. if (s->gzhead->hcrc && s->pending > beg)
  77457. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77458. s->pending - beg);
  77459. flush_pending(strm);
  77460. beg = s->pending;
  77461. if (s->pending == s->pending_buf_size)
  77462. break;
  77463. }
  77464. put_byte(s, s->gzhead->extra[s->gzindex]);
  77465. s->gzindex++;
  77466. }
  77467. if (s->gzhead->hcrc && s->pending > beg)
  77468. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77469. s->pending - beg);
  77470. if (s->gzindex == s->gzhead->extra_len) {
  77471. s->gzindex = 0;
  77472. s->status = NAME_STATE;
  77473. }
  77474. }
  77475. else
  77476. s->status = NAME_STATE;
  77477. }
  77478. if (s->status == NAME_STATE) {
  77479. if (s->gzhead->name != NULL) {
  77480. uInt beg = s->pending; /* start of bytes to update crc */
  77481. int val;
  77482. do {
  77483. if (s->pending == s->pending_buf_size) {
  77484. if (s->gzhead->hcrc && s->pending > beg)
  77485. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77486. s->pending - beg);
  77487. flush_pending(strm);
  77488. beg = s->pending;
  77489. if (s->pending == s->pending_buf_size) {
  77490. val = 1;
  77491. break;
  77492. }
  77493. }
  77494. val = s->gzhead->name[s->gzindex++];
  77495. put_byte(s, val);
  77496. } while (val != 0);
  77497. if (s->gzhead->hcrc && s->pending > beg)
  77498. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77499. s->pending - beg);
  77500. if (val == 0) {
  77501. s->gzindex = 0;
  77502. s->status = COMMENT_STATE;
  77503. }
  77504. }
  77505. else
  77506. s->status = COMMENT_STATE;
  77507. }
  77508. if (s->status == COMMENT_STATE) {
  77509. if (s->gzhead->comment != NULL) {
  77510. uInt beg = s->pending; /* start of bytes to update crc */
  77511. int val;
  77512. do {
  77513. if (s->pending == s->pending_buf_size) {
  77514. if (s->gzhead->hcrc && s->pending > beg)
  77515. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77516. s->pending - beg);
  77517. flush_pending(strm);
  77518. beg = s->pending;
  77519. if (s->pending == s->pending_buf_size) {
  77520. val = 1;
  77521. break;
  77522. }
  77523. }
  77524. val = s->gzhead->comment[s->gzindex++];
  77525. put_byte(s, val);
  77526. } while (val != 0);
  77527. if (s->gzhead->hcrc && s->pending > beg)
  77528. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77529. s->pending - beg);
  77530. if (val == 0)
  77531. s->status = HCRC_STATE;
  77532. }
  77533. else
  77534. s->status = HCRC_STATE;
  77535. }
  77536. if (s->status == HCRC_STATE) {
  77537. if (s->gzhead->hcrc) {
  77538. if (s->pending + 2 > s->pending_buf_size)
  77539. flush_pending(strm);
  77540. if (s->pending + 2 <= s->pending_buf_size) {
  77541. put_byte(s, (Byte)(strm->adler & 0xff));
  77542. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77543. strm->adler = crc32(0L, Z_NULL, 0);
  77544. s->status = BUSY_STATE;
  77545. }
  77546. }
  77547. else
  77548. s->status = BUSY_STATE;
  77549. }
  77550. #endif
  77551. if (s->pending != 0) {
  77552. flush_pending(strm);
  77553. if (strm->avail_out == 0) {
  77554. s->last_flush = -1;
  77555. return Z_OK;
  77556. }
  77557. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77558. flush != Z_FINISH) {
  77559. ERR_RETURN(strm, Z_BUF_ERROR);
  77560. }
  77561. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77562. ERR_RETURN(strm, Z_BUF_ERROR);
  77563. }
  77564. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77565. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77566. block_state bstate;
  77567. bstate = (*(configuration_table[s->level].func))(s, flush);
  77568. if (bstate == finish_started || bstate == finish_done) {
  77569. s->status = FINISH_STATE;
  77570. }
  77571. if (bstate == need_more || bstate == finish_started) {
  77572. if (strm->avail_out == 0) {
  77573. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77574. }
  77575. return Z_OK;
  77576. }
  77577. if (bstate == block_done) {
  77578. if (flush == Z_PARTIAL_FLUSH) {
  77579. _tr_align(s);
  77580. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77581. _tr_stored_block(s, (char*)0, 0L, 0);
  77582. if (flush == Z_FULL_FLUSH) {
  77583. CLEAR_HASH(s); /* forget history */
  77584. }
  77585. }
  77586. flush_pending(strm);
  77587. if (strm->avail_out == 0) {
  77588. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77589. return Z_OK;
  77590. }
  77591. }
  77592. }
  77593. Assert(strm->avail_out > 0, "bug2");
  77594. if (flush != Z_FINISH) return Z_OK;
  77595. if (s->wrap <= 0) return Z_STREAM_END;
  77596. #ifdef GZIP
  77597. if (s->wrap == 2) {
  77598. put_byte(s, (Byte)(strm->adler & 0xff));
  77599. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77600. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77601. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77602. put_byte(s, (Byte)(strm->total_in & 0xff));
  77603. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77604. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77605. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77606. }
  77607. else
  77608. #endif
  77609. {
  77610. putShortMSB(s, (uInt)(strm->adler >> 16));
  77611. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77612. }
  77613. flush_pending(strm);
  77614. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77615. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77616. }
  77617. int ZEXPORT deflateEnd (z_streamp strm)
  77618. {
  77619. int status;
  77620. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77621. status = strm->state->status;
  77622. if (status != INIT_STATE &&
  77623. status != EXTRA_STATE &&
  77624. status != NAME_STATE &&
  77625. status != COMMENT_STATE &&
  77626. status != HCRC_STATE &&
  77627. status != BUSY_STATE &&
  77628. status != FINISH_STATE) {
  77629. return Z_STREAM_ERROR;
  77630. }
  77631. TRY_FREE(strm, strm->state->pending_buf);
  77632. TRY_FREE(strm, strm->state->head);
  77633. TRY_FREE(strm, strm->state->prev);
  77634. TRY_FREE(strm, strm->state->window);
  77635. ZFREE(strm, strm->state);
  77636. strm->state = Z_NULL;
  77637. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77638. }
  77639. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77640. {
  77641. #ifdef MAXSEG_64K
  77642. return Z_STREAM_ERROR;
  77643. #else
  77644. deflate_state *ds;
  77645. deflate_state *ss;
  77646. ushf *overlay;
  77647. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77648. return Z_STREAM_ERROR;
  77649. }
  77650. ss = source->state;
  77651. zmemcpy(dest, source, sizeof(z_stream));
  77652. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77653. if (ds == Z_NULL) return Z_MEM_ERROR;
  77654. dest->state = (struct internal_state FAR *) ds;
  77655. zmemcpy(ds, ss, sizeof(deflate_state));
  77656. ds->strm = dest;
  77657. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77658. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77659. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77660. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77661. ds->pending_buf = (uchf *) overlay;
  77662. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77663. ds->pending_buf == Z_NULL) {
  77664. deflateEnd (dest);
  77665. return Z_MEM_ERROR;
  77666. }
  77667. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77668. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77669. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77670. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77671. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77672. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77673. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77674. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77675. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77676. ds->bl_desc.dyn_tree = ds->bl_tree;
  77677. return Z_OK;
  77678. #endif /* MAXSEG_64K */
  77679. }
  77680. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77681. {
  77682. unsigned len = strm->avail_in;
  77683. if (len > size) len = size;
  77684. if (len == 0) return 0;
  77685. strm->avail_in -= len;
  77686. if (strm->state->wrap == 1) {
  77687. strm->adler = adler32(strm->adler, strm->next_in, len);
  77688. }
  77689. #ifdef GZIP
  77690. else if (strm->state->wrap == 2) {
  77691. strm->adler = crc32(strm->adler, strm->next_in, len);
  77692. }
  77693. #endif
  77694. zmemcpy(buf, strm->next_in, len);
  77695. strm->next_in += len;
  77696. strm->total_in += len;
  77697. return (int)len;
  77698. }
  77699. local void lm_init (deflate_state *s)
  77700. {
  77701. s->window_size = (ulg)2L*s->w_size;
  77702. CLEAR_HASH(s);
  77703. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77704. s->good_match = configuration_table[s->level].good_length;
  77705. s->nice_match = configuration_table[s->level].nice_length;
  77706. s->max_chain_length = configuration_table[s->level].max_chain;
  77707. s->strstart = 0;
  77708. s->block_start = 0L;
  77709. s->lookahead = 0;
  77710. s->match_length = s->prev_length = MIN_MATCH-1;
  77711. s->match_available = 0;
  77712. s->ins_h = 0;
  77713. #ifndef FASTEST
  77714. #ifdef ASMV
  77715. match_init(); /* initialize the asm code */
  77716. #endif
  77717. #endif
  77718. }
  77719. #ifndef FASTEST
  77720. #ifndef ASMV
  77721. local uInt longest_match(deflate_state *s, IPos cur_match)
  77722. {
  77723. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77724. register Bytef *scan = s->window + s->strstart; /* current string */
  77725. register Bytef *match; /* matched string */
  77726. register int len; /* length of current match */
  77727. int best_len = s->prev_length; /* best match length so far */
  77728. int nice_match = s->nice_match; /* stop if match long enough */
  77729. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77730. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77731. Posf *prev = s->prev;
  77732. uInt wmask = s->w_mask;
  77733. #ifdef UNALIGNED_OK
  77734. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77735. register ush scan_start = *(ushf*)scan;
  77736. register ush scan_end = *(ushf*)(scan+best_len-1);
  77737. #else
  77738. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77739. register Byte scan_end1 = scan[best_len-1];
  77740. register Byte scan_end = scan[best_len];
  77741. #endif
  77742. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77743. if (s->prev_length >= s->good_match) {
  77744. chain_length >>= 2;
  77745. }
  77746. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77747. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77748. do {
  77749. Assert(cur_match < s->strstart, "no future");
  77750. match = s->window + cur_match;
  77751. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77752. if (*(ushf*)(match+best_len-1) != scan_end ||
  77753. *(ushf*)match != scan_start) continue;
  77754. Assert(scan[2] == match[2], "scan[2]?");
  77755. scan++, match++;
  77756. do {
  77757. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77758. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77759. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77760. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77761. scan < strend);
  77762. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77763. if (*scan == *match) scan++;
  77764. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77765. scan = strend - (MAX_MATCH-1);
  77766. #else /* UNALIGNED_OK */
  77767. if (match[best_len] != scan_end ||
  77768. match[best_len-1] != scan_end1 ||
  77769. *match != *scan ||
  77770. *++match != scan[1]) continue;
  77771. scan += 2, match++;
  77772. Assert(*scan == *match, "match[2]?");
  77773. do {
  77774. } while (*++scan == *++match && *++scan == *++match &&
  77775. *++scan == *++match && *++scan == *++match &&
  77776. *++scan == *++match && *++scan == *++match &&
  77777. *++scan == *++match && *++scan == *++match &&
  77778. scan < strend);
  77779. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77780. len = MAX_MATCH - (int)(strend - scan);
  77781. scan = strend - MAX_MATCH;
  77782. #endif /* UNALIGNED_OK */
  77783. if (len > best_len) {
  77784. s->match_start = cur_match;
  77785. best_len = len;
  77786. if (len >= nice_match) break;
  77787. #ifdef UNALIGNED_OK
  77788. scan_end = *(ushf*)(scan+best_len-1);
  77789. #else
  77790. scan_end1 = scan[best_len-1];
  77791. scan_end = scan[best_len];
  77792. #endif
  77793. }
  77794. } while ((cur_match = prev[cur_match & wmask]) > limit
  77795. && --chain_length != 0);
  77796. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77797. return s->lookahead;
  77798. }
  77799. #endif /* ASMV */
  77800. #endif /* FASTEST */
  77801. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77802. {
  77803. register Bytef *scan = s->window + s->strstart; /* current string */
  77804. register Bytef *match; /* matched string */
  77805. register int len; /* length of current match */
  77806. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77807. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77808. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77809. Assert(cur_match < s->strstart, "no future");
  77810. match = s->window + cur_match;
  77811. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77812. scan += 2, match += 2;
  77813. Assert(*scan == *match, "match[2]?");
  77814. do {
  77815. } while (*++scan == *++match && *++scan == *++match &&
  77816. *++scan == *++match && *++scan == *++match &&
  77817. *++scan == *++match && *++scan == *++match &&
  77818. *++scan == *++match && *++scan == *++match &&
  77819. scan < strend);
  77820. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77821. len = MAX_MATCH - (int)(strend - scan);
  77822. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77823. s->match_start = cur_match;
  77824. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77825. }
  77826. #ifdef DEBUG
  77827. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77828. {
  77829. if (zmemcmp(s->window + match,
  77830. s->window + start, length) != EQUAL) {
  77831. fprintf(stderr, " start %u, match %u, length %d\n",
  77832. start, match, length);
  77833. do {
  77834. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77835. } while (--length != 0);
  77836. z_error("invalid match");
  77837. }
  77838. if (z_verbose > 1) {
  77839. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77840. do { putc(s->window[start++], stderr); } while (--length != 0);
  77841. }
  77842. }
  77843. #else
  77844. # define check_match(s, start, match, length)
  77845. #endif /* DEBUG */
  77846. local void fill_window (deflate_state *s)
  77847. {
  77848. register unsigned n, m;
  77849. register Posf *p;
  77850. unsigned more; /* Amount of free space at the end of the window. */
  77851. uInt wsize = s->w_size;
  77852. do {
  77853. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77854. if (sizeof(int) <= 2) {
  77855. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77856. more = wsize;
  77857. } else if (more == (unsigned)(-1)) {
  77858. more--;
  77859. }
  77860. }
  77861. if (s->strstart >= wsize+MAX_DIST(s)) {
  77862. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77863. s->match_start -= wsize;
  77864. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77865. s->block_start -= (long) wsize;
  77866. n = s->hash_size;
  77867. p = &s->head[n];
  77868. do {
  77869. m = *--p;
  77870. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77871. } while (--n);
  77872. n = wsize;
  77873. #ifndef FASTEST
  77874. p = &s->prev[n];
  77875. do {
  77876. m = *--p;
  77877. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77878. } while (--n);
  77879. #endif
  77880. more += wsize;
  77881. }
  77882. if (s->strm->avail_in == 0) return;
  77883. Assert(more >= 2, "more < 2");
  77884. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77885. s->lookahead += n;
  77886. if (s->lookahead >= MIN_MATCH) {
  77887. s->ins_h = s->window[s->strstart];
  77888. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77889. #if MIN_MATCH != 3
  77890. Call UPDATE_HASH() MIN_MATCH-3 more times
  77891. #endif
  77892. }
  77893. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77894. }
  77895. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77896. _tr_flush_block(s, (s->block_start >= 0L ? \
  77897. (charf *)&s->window[(unsigned)s->block_start] : \
  77898. (charf *)Z_NULL), \
  77899. (ulg)((long)s->strstart - s->block_start), \
  77900. (eof)); \
  77901. s->block_start = s->strstart; \
  77902. flush_pending(s->strm); \
  77903. Tracev((stderr,"[FLUSH]")); \
  77904. }
  77905. #define FLUSH_BLOCK(s, eof) { \
  77906. FLUSH_BLOCK_ONLY(s, eof); \
  77907. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77908. }
  77909. local block_state deflate_stored(deflate_state *s, int flush)
  77910. {
  77911. ulg max_block_size = 0xffff;
  77912. ulg max_start;
  77913. if (max_block_size > s->pending_buf_size - 5) {
  77914. max_block_size = s->pending_buf_size - 5;
  77915. }
  77916. for (;;) {
  77917. if (s->lookahead <= 1) {
  77918. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77919. s->block_start >= (long)s->w_size, "slide too late");
  77920. fill_window(s);
  77921. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77922. if (s->lookahead == 0) break; /* flush the current block */
  77923. }
  77924. Assert(s->block_start >= 0L, "block gone");
  77925. s->strstart += s->lookahead;
  77926. s->lookahead = 0;
  77927. max_start = s->block_start + max_block_size;
  77928. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77929. s->lookahead = (uInt)(s->strstart - max_start);
  77930. s->strstart = (uInt)max_start;
  77931. FLUSH_BLOCK(s, 0);
  77932. }
  77933. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77934. FLUSH_BLOCK(s, 0);
  77935. }
  77936. }
  77937. FLUSH_BLOCK(s, flush == Z_FINISH);
  77938. return flush == Z_FINISH ? finish_done : block_done;
  77939. }
  77940. local block_state deflate_fast(deflate_state *s, int flush)
  77941. {
  77942. IPos hash_head = NIL; /* head of the hash chain */
  77943. int bflush; /* set if current block must be flushed */
  77944. for (;;) {
  77945. if (s->lookahead < MIN_LOOKAHEAD) {
  77946. fill_window(s);
  77947. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77948. return need_more;
  77949. }
  77950. if (s->lookahead == 0) break; /* flush the current block */
  77951. }
  77952. if (s->lookahead >= MIN_MATCH) {
  77953. INSERT_STRING(s, s->strstart, hash_head);
  77954. }
  77955. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77956. #ifdef FASTEST
  77957. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77958. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77959. s->match_length = longest_match_fast (s, hash_head);
  77960. }
  77961. #else
  77962. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77963. s->match_length = longest_match (s, hash_head);
  77964. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77965. s->match_length = longest_match_fast (s, hash_head);
  77966. }
  77967. #endif
  77968. }
  77969. if (s->match_length >= MIN_MATCH) {
  77970. check_match(s, s->strstart, s->match_start, s->match_length);
  77971. _tr_tally_dist(s, s->strstart - s->match_start,
  77972. s->match_length - MIN_MATCH, bflush);
  77973. s->lookahead -= s->match_length;
  77974. #ifndef FASTEST
  77975. if (s->match_length <= s->max_insert_length &&
  77976. s->lookahead >= MIN_MATCH) {
  77977. s->match_length--; /* string at strstart already in table */
  77978. do {
  77979. s->strstart++;
  77980. INSERT_STRING(s, s->strstart, hash_head);
  77981. } while (--s->match_length != 0);
  77982. s->strstart++;
  77983. } else
  77984. #endif
  77985. {
  77986. s->strstart += s->match_length;
  77987. s->match_length = 0;
  77988. s->ins_h = s->window[s->strstart];
  77989. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77990. #if MIN_MATCH != 3
  77991. Call UPDATE_HASH() MIN_MATCH-3 more times
  77992. #endif
  77993. }
  77994. } else {
  77995. Tracevv((stderr,"%c", s->window[s->strstart]));
  77996. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77997. s->lookahead--;
  77998. s->strstart++;
  77999. }
  78000. if (bflush) FLUSH_BLOCK(s, 0);
  78001. }
  78002. FLUSH_BLOCK(s, flush == Z_FINISH);
  78003. return flush == Z_FINISH ? finish_done : block_done;
  78004. }
  78005. #ifndef FASTEST
  78006. local block_state deflate_slow(deflate_state *s, int flush)
  78007. {
  78008. IPos hash_head = NIL; /* head of hash chain */
  78009. int bflush; /* set if current block must be flushed */
  78010. for (;;) {
  78011. if (s->lookahead < MIN_LOOKAHEAD) {
  78012. fill_window(s);
  78013. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  78014. return need_more;
  78015. }
  78016. if (s->lookahead == 0) break; /* flush the current block */
  78017. }
  78018. if (s->lookahead >= MIN_MATCH) {
  78019. INSERT_STRING(s, s->strstart, hash_head);
  78020. }
  78021. s->prev_length = s->match_length, s->prev_match = s->match_start;
  78022. s->match_length = MIN_MATCH-1;
  78023. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  78024. s->strstart - hash_head <= MAX_DIST(s)) {
  78025. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  78026. s->match_length = longest_match (s, hash_head);
  78027. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  78028. s->match_length = longest_match_fast (s, hash_head);
  78029. }
  78030. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  78031. #if TOO_FAR <= 32767
  78032. || (s->match_length == MIN_MATCH &&
  78033. s->strstart - s->match_start > TOO_FAR)
  78034. #endif
  78035. )) {
  78036. s->match_length = MIN_MATCH-1;
  78037. }
  78038. }
  78039. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  78040. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  78041. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  78042. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  78043. s->prev_length - MIN_MATCH, bflush);
  78044. s->lookahead -= s->prev_length-1;
  78045. s->prev_length -= 2;
  78046. do {
  78047. if (++s->strstart <= max_insert) {
  78048. INSERT_STRING(s, s->strstart, hash_head);
  78049. }
  78050. } while (--s->prev_length != 0);
  78051. s->match_available = 0;
  78052. s->match_length = MIN_MATCH-1;
  78053. s->strstart++;
  78054. if (bflush) FLUSH_BLOCK(s, 0);
  78055. } else if (s->match_available) {
  78056. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  78057. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  78058. if (bflush) {
  78059. FLUSH_BLOCK_ONLY(s, 0);
  78060. }
  78061. s->strstart++;
  78062. s->lookahead--;
  78063. if (s->strm->avail_out == 0) return need_more;
  78064. } else {
  78065. s->match_available = 1;
  78066. s->strstart++;
  78067. s->lookahead--;
  78068. }
  78069. }
  78070. Assert (flush != Z_NO_FLUSH, "no flush?");
  78071. if (s->match_available) {
  78072. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  78073. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  78074. s->match_available = 0;
  78075. }
  78076. FLUSH_BLOCK(s, flush == Z_FINISH);
  78077. return flush == Z_FINISH ? finish_done : block_done;
  78078. }
  78079. #endif /* FASTEST */
  78080. #if 0
  78081. local block_state deflate_rle(s, flush)
  78082. deflate_state *s;
  78083. int flush;
  78084. {
  78085. int bflush; /* set if current block must be flushed */
  78086. uInt run; /* length of run */
  78087. uInt max; /* maximum length of run */
  78088. uInt prev; /* byte at distance one to match */
  78089. Bytef *scan; /* scan for end of run */
  78090. for (;;) {
  78091. if (s->lookahead < MAX_MATCH) {
  78092. fill_window(s);
  78093. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  78094. return need_more;
  78095. }
  78096. if (s->lookahead == 0) break; /* flush the current block */
  78097. }
  78098. run = 0;
  78099. if (s->strstart > 0) { /* if there is a previous byte, that is */
  78100. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  78101. scan = s->window + s->strstart - 1;
  78102. prev = *scan++;
  78103. do {
  78104. if (*scan++ != prev)
  78105. break;
  78106. } while (++run < max);
  78107. }
  78108. if (run >= MIN_MATCH) {
  78109. check_match(s, s->strstart, s->strstart - 1, run);
  78110. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  78111. s->lookahead -= run;
  78112. s->strstart += run;
  78113. } else {
  78114. Tracevv((stderr,"%c", s->window[s->strstart]));
  78115. _tr_tally_lit (s, s->window[s->strstart], bflush);
  78116. s->lookahead--;
  78117. s->strstart++;
  78118. }
  78119. if (bflush) FLUSH_BLOCK(s, 0);
  78120. }
  78121. FLUSH_BLOCK(s, flush == Z_FINISH);
  78122. return flush == Z_FINISH ? finish_done : block_done;
  78123. }
  78124. #endif
  78125. /*** End of inlined file: deflate.c ***/
  78126. /*** Start of inlined file: inffast.c ***/
  78127. /*** Start of inlined file: inftrees.h ***/
  78128. #ifndef _INFTREES_H_
  78129. #define _INFTREES_H_
  78130. typedef struct {
  78131. unsigned char op; /* operation, extra bits, table bits */
  78132. unsigned char bits; /* bits in this part of the code */
  78133. unsigned short val; /* offset in table or code value */
  78134. } code;
  78135. #define ENOUGH 2048
  78136. #define MAXD 592
  78137. typedef enum {
  78138. CODES,
  78139. LENS,
  78140. DISTS
  78141. } codetype;
  78142. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  78143. unsigned codes, code FAR * FAR *table,
  78144. unsigned FAR *bits, unsigned short FAR *work));
  78145. #endif
  78146. /*** End of inlined file: inftrees.h ***/
  78147. /*** Start of inlined file: inflate.h ***/
  78148. #ifndef _INFLATE_H_
  78149. #define _INFLATE_H_
  78150. #ifndef NO_GZIP
  78151. # define GUNZIP
  78152. #endif
  78153. typedef enum {
  78154. HEAD, /* i: waiting for magic header */
  78155. FLAGS, /* i: waiting for method and flags (gzip) */
  78156. TIME, /* i: waiting for modification time (gzip) */
  78157. OS, /* i: waiting for extra flags and operating system (gzip) */
  78158. EXLEN, /* i: waiting for extra length (gzip) */
  78159. EXTRA, /* i: waiting for extra bytes (gzip) */
  78160. NAME, /* i: waiting for end of file name (gzip) */
  78161. COMMENT, /* i: waiting for end of comment (gzip) */
  78162. HCRC, /* i: waiting for header crc (gzip) */
  78163. DICTID, /* i: waiting for dictionary check value */
  78164. DICT, /* waiting for inflateSetDictionary() call */
  78165. TYPE, /* i: waiting for type bits, including last-flag bit */
  78166. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  78167. STORED, /* i: waiting for stored size (length and complement) */
  78168. COPY, /* i/o: waiting for input or output to copy stored block */
  78169. TABLE, /* i: waiting for dynamic block table lengths */
  78170. LENLENS, /* i: waiting for code length code lengths */
  78171. CODELENS, /* i: waiting for length/lit and distance code lengths */
  78172. LEN, /* i: waiting for length/lit code */
  78173. LENEXT, /* i: waiting for length extra bits */
  78174. DIST, /* i: waiting for distance code */
  78175. DISTEXT, /* i: waiting for distance extra bits */
  78176. MATCH, /* o: waiting for output space to copy string */
  78177. LIT, /* o: waiting for output space to write literal */
  78178. CHECK, /* i: waiting for 32-bit check value */
  78179. LENGTH, /* i: waiting for 32-bit length (gzip) */
  78180. DONE, /* finished check, done -- remain here until reset */
  78181. BAD, /* got a data error -- remain here until reset */
  78182. MEM, /* got an inflate() memory error -- remain here until reset */
  78183. SYNC /* looking for synchronization bytes to restart inflate() */
  78184. } inflate_mode;
  78185. struct inflate_state {
  78186. inflate_mode mode; /* current inflate mode */
  78187. int last; /* true if processing last block */
  78188. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  78189. int havedict; /* true if dictionary provided */
  78190. int flags; /* gzip header method and flags (0 if zlib) */
  78191. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  78192. unsigned long check; /* protected copy of check value */
  78193. unsigned long total; /* protected copy of output count */
  78194. gz_headerp head; /* where to save gzip header information */
  78195. unsigned wbits; /* log base 2 of requested window size */
  78196. unsigned wsize; /* window size or zero if not using window */
  78197. unsigned whave; /* valid bytes in the window */
  78198. unsigned write; /* window write index */
  78199. unsigned char FAR *window; /* allocated sliding window, if needed */
  78200. unsigned long hold; /* input bit accumulator */
  78201. unsigned bits; /* number of bits in "in" */
  78202. unsigned length; /* literal or length of data to copy */
  78203. unsigned offset; /* distance back to copy string from */
  78204. unsigned extra; /* extra bits needed */
  78205. code const FAR *lencode; /* starting table for length/literal codes */
  78206. code const FAR *distcode; /* starting table for distance codes */
  78207. unsigned lenbits; /* index bits for lencode */
  78208. unsigned distbits; /* index bits for distcode */
  78209. unsigned ncode; /* number of code length code lengths */
  78210. unsigned nlen; /* number of length code lengths */
  78211. unsigned ndist; /* number of distance code lengths */
  78212. unsigned have; /* number of code lengths in lens[] */
  78213. code FAR *next; /* next available space in codes[] */
  78214. unsigned short lens[320]; /* temporary storage for code lengths */
  78215. unsigned short work[288]; /* work area for code table building */
  78216. code codes[ENOUGH]; /* space for code tables */
  78217. };
  78218. #endif
  78219. /*** End of inlined file: inflate.h ***/
  78220. /*** Start of inlined file: inffast.h ***/
  78221. void inflate_fast OF((z_streamp strm, unsigned start));
  78222. /*** End of inlined file: inffast.h ***/
  78223. #ifndef ASMINF
  78224. #ifdef POSTINC
  78225. # define OFF 0
  78226. # define PUP(a) *(a)++
  78227. #else
  78228. # define OFF 1
  78229. # define PUP(a) *++(a)
  78230. #endif
  78231. void inflate_fast (z_streamp strm, unsigned start)
  78232. {
  78233. struct inflate_state FAR *state;
  78234. unsigned char FAR *in; /* local strm->next_in */
  78235. unsigned char FAR *last; /* while in < last, enough input available */
  78236. unsigned char FAR *out; /* local strm->next_out */
  78237. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  78238. unsigned char FAR *end; /* while out < end, enough space available */
  78239. #ifdef INFLATE_STRICT
  78240. unsigned dmax; /* maximum distance from zlib header */
  78241. #endif
  78242. unsigned wsize; /* window size or zero if not using window */
  78243. unsigned whave; /* valid bytes in the window */
  78244. unsigned write; /* window write index */
  78245. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  78246. unsigned long hold; /* local strm->hold */
  78247. unsigned bits; /* local strm->bits */
  78248. code const FAR *lcode; /* local strm->lencode */
  78249. code const FAR *dcode; /* local strm->distcode */
  78250. unsigned lmask; /* mask for first level of length codes */
  78251. unsigned dmask; /* mask for first level of distance codes */
  78252. code thisx; /* retrieved table entry */
  78253. unsigned op; /* code bits, operation, extra bits, or */
  78254. unsigned len; /* match length, unused bytes */
  78255. unsigned dist; /* match distance */
  78256. unsigned char FAR *from; /* where to copy match from */
  78257. state = (struct inflate_state FAR *)strm->state;
  78258. in = strm->next_in - OFF;
  78259. last = in + (strm->avail_in - 5);
  78260. out = strm->next_out - OFF;
  78261. beg = out - (start - strm->avail_out);
  78262. end = out + (strm->avail_out - 257);
  78263. #ifdef INFLATE_STRICT
  78264. dmax = state->dmax;
  78265. #endif
  78266. wsize = state->wsize;
  78267. whave = state->whave;
  78268. write = state->write;
  78269. window = state->window;
  78270. hold = state->hold;
  78271. bits = state->bits;
  78272. lcode = state->lencode;
  78273. dcode = state->distcode;
  78274. lmask = (1U << state->lenbits) - 1;
  78275. dmask = (1U << state->distbits) - 1;
  78276. do {
  78277. if (bits < 15) {
  78278. hold += (unsigned long)(PUP(in)) << bits;
  78279. bits += 8;
  78280. hold += (unsigned long)(PUP(in)) << bits;
  78281. bits += 8;
  78282. }
  78283. thisx = lcode[hold & lmask];
  78284. dolen:
  78285. op = (unsigned)(thisx.bits);
  78286. hold >>= op;
  78287. bits -= op;
  78288. op = (unsigned)(thisx.op);
  78289. if (op == 0) { /* literal */
  78290. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78291. "inflate: literal '%c'\n" :
  78292. "inflate: literal 0x%02x\n", thisx.val));
  78293. PUP(out) = (unsigned char)(thisx.val);
  78294. }
  78295. else if (op & 16) { /* length base */
  78296. len = (unsigned)(thisx.val);
  78297. op &= 15; /* number of extra bits */
  78298. if (op) {
  78299. if (bits < op) {
  78300. hold += (unsigned long)(PUP(in)) << bits;
  78301. bits += 8;
  78302. }
  78303. len += (unsigned)hold & ((1U << op) - 1);
  78304. hold >>= op;
  78305. bits -= op;
  78306. }
  78307. Tracevv((stderr, "inflate: length %u\n", len));
  78308. if (bits < 15) {
  78309. hold += (unsigned long)(PUP(in)) << bits;
  78310. bits += 8;
  78311. hold += (unsigned long)(PUP(in)) << bits;
  78312. bits += 8;
  78313. }
  78314. thisx = dcode[hold & dmask];
  78315. dodist:
  78316. op = (unsigned)(thisx.bits);
  78317. hold >>= op;
  78318. bits -= op;
  78319. op = (unsigned)(thisx.op);
  78320. if (op & 16) { /* distance base */
  78321. dist = (unsigned)(thisx.val);
  78322. op &= 15; /* number of extra bits */
  78323. if (bits < op) {
  78324. hold += (unsigned long)(PUP(in)) << bits;
  78325. bits += 8;
  78326. if (bits < op) {
  78327. hold += (unsigned long)(PUP(in)) << bits;
  78328. bits += 8;
  78329. }
  78330. }
  78331. dist += (unsigned)hold & ((1U << op) - 1);
  78332. #ifdef INFLATE_STRICT
  78333. if (dist > dmax) {
  78334. strm->msg = (char *)"invalid distance too far back";
  78335. state->mode = BAD;
  78336. break;
  78337. }
  78338. #endif
  78339. hold >>= op;
  78340. bits -= op;
  78341. Tracevv((stderr, "inflate: distance %u\n", dist));
  78342. op = (unsigned)(out - beg); /* max distance in output */
  78343. if (dist > op) { /* see if copy from window */
  78344. op = dist - op; /* distance back in window */
  78345. if (op > whave) {
  78346. strm->msg = (char *)"invalid distance too far back";
  78347. state->mode = BAD;
  78348. break;
  78349. }
  78350. from = window - OFF;
  78351. if (write == 0) { /* very common case */
  78352. from += wsize - op;
  78353. if (op < len) { /* some from window */
  78354. len -= op;
  78355. do {
  78356. PUP(out) = PUP(from);
  78357. } while (--op);
  78358. from = out - dist; /* rest from output */
  78359. }
  78360. }
  78361. else if (write < op) { /* wrap around window */
  78362. from += wsize + write - op;
  78363. op -= write;
  78364. if (op < len) { /* some from end of window */
  78365. len -= op;
  78366. do {
  78367. PUP(out) = PUP(from);
  78368. } while (--op);
  78369. from = window - OFF;
  78370. if (write < len) { /* some from start of window */
  78371. op = write;
  78372. len -= op;
  78373. do {
  78374. PUP(out) = PUP(from);
  78375. } while (--op);
  78376. from = out - dist; /* rest from output */
  78377. }
  78378. }
  78379. }
  78380. else { /* contiguous in window */
  78381. from += write - op;
  78382. if (op < len) { /* some from window */
  78383. len -= op;
  78384. do {
  78385. PUP(out) = PUP(from);
  78386. } while (--op);
  78387. from = out - dist; /* rest from output */
  78388. }
  78389. }
  78390. while (len > 2) {
  78391. PUP(out) = PUP(from);
  78392. PUP(out) = PUP(from);
  78393. PUP(out) = PUP(from);
  78394. len -= 3;
  78395. }
  78396. if (len) {
  78397. PUP(out) = PUP(from);
  78398. if (len > 1)
  78399. PUP(out) = PUP(from);
  78400. }
  78401. }
  78402. else {
  78403. from = out - dist; /* copy direct from output */
  78404. do { /* minimum length is three */
  78405. PUP(out) = PUP(from);
  78406. PUP(out) = PUP(from);
  78407. PUP(out) = PUP(from);
  78408. len -= 3;
  78409. } while (len > 2);
  78410. if (len) {
  78411. PUP(out) = PUP(from);
  78412. if (len > 1)
  78413. PUP(out) = PUP(from);
  78414. }
  78415. }
  78416. }
  78417. else if ((op & 64) == 0) { /* 2nd level distance code */
  78418. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  78419. goto dodist;
  78420. }
  78421. else {
  78422. strm->msg = (char *)"invalid distance code";
  78423. state->mode = BAD;
  78424. break;
  78425. }
  78426. }
  78427. else if ((op & 64) == 0) { /* 2nd level length code */
  78428. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  78429. goto dolen;
  78430. }
  78431. else if (op & 32) { /* end-of-block */
  78432. Tracevv((stderr, "inflate: end of block\n"));
  78433. state->mode = TYPE;
  78434. break;
  78435. }
  78436. else {
  78437. strm->msg = (char *)"invalid literal/length code";
  78438. state->mode = BAD;
  78439. break;
  78440. }
  78441. } while (in < last && out < end);
  78442. len = bits >> 3;
  78443. in -= len;
  78444. bits -= len << 3;
  78445. hold &= (1U << bits) - 1;
  78446. strm->next_in = in + OFF;
  78447. strm->next_out = out + OFF;
  78448. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  78449. strm->avail_out = (unsigned)(out < end ?
  78450. 257 + (end - out) : 257 - (out - end));
  78451. state->hold = hold;
  78452. state->bits = bits;
  78453. return;
  78454. }
  78455. #endif /* !ASMINF */
  78456. /*** End of inlined file: inffast.c ***/
  78457. #undef PULLBYTE
  78458. #undef LOAD
  78459. #undef RESTORE
  78460. #undef INITBITS
  78461. #undef NEEDBITS
  78462. #undef DROPBITS
  78463. #undef BYTEBITS
  78464. /*** Start of inlined file: inflate.c ***/
  78465. /*** Start of inlined file: inffast.h ***/
  78466. void inflate_fast OF((z_streamp strm, unsigned start));
  78467. /*** End of inlined file: inffast.h ***/
  78468. #ifdef MAKEFIXED
  78469. # ifndef BUILDFIXED
  78470. # define BUILDFIXED
  78471. # endif
  78472. #endif
  78473. local void fixedtables OF((struct inflate_state FAR *state));
  78474. local int updatewindow OF((z_streamp strm, unsigned out));
  78475. #ifdef BUILDFIXED
  78476. void makefixed OF((void));
  78477. #endif
  78478. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  78479. unsigned len));
  78480. int ZEXPORT inflateReset (z_streamp strm)
  78481. {
  78482. struct inflate_state FAR *state;
  78483. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78484. state = (struct inflate_state FAR *)strm->state;
  78485. strm->total_in = strm->total_out = state->total = 0;
  78486. strm->msg = Z_NULL;
  78487. strm->adler = 1; /* to support ill-conceived Java test suite */
  78488. state->mode = HEAD;
  78489. state->last = 0;
  78490. state->havedict = 0;
  78491. state->dmax = 32768U;
  78492. state->head = Z_NULL;
  78493. state->wsize = 0;
  78494. state->whave = 0;
  78495. state->write = 0;
  78496. state->hold = 0;
  78497. state->bits = 0;
  78498. state->lencode = state->distcode = state->next = state->codes;
  78499. Tracev((stderr, "inflate: reset\n"));
  78500. return Z_OK;
  78501. }
  78502. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  78503. {
  78504. struct inflate_state FAR *state;
  78505. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78506. state = (struct inflate_state FAR *)strm->state;
  78507. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  78508. value &= (1L << bits) - 1;
  78509. state->hold += value << state->bits;
  78510. state->bits += bits;
  78511. return Z_OK;
  78512. }
  78513. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  78514. {
  78515. struct inflate_state FAR *state;
  78516. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  78517. stream_size != (int)(sizeof(z_stream)))
  78518. return Z_VERSION_ERROR;
  78519. if (strm == Z_NULL) return Z_STREAM_ERROR;
  78520. strm->msg = Z_NULL; /* in case we return an error */
  78521. if (strm->zalloc == (alloc_func)0) {
  78522. strm->zalloc = zcalloc;
  78523. strm->opaque = (voidpf)0;
  78524. }
  78525. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  78526. state = (struct inflate_state FAR *)
  78527. ZALLOC(strm, 1, sizeof(struct inflate_state));
  78528. if (state == Z_NULL) return Z_MEM_ERROR;
  78529. Tracev((stderr, "inflate: allocated\n"));
  78530. strm->state = (struct internal_state FAR *)state;
  78531. if (windowBits < 0) {
  78532. state->wrap = 0;
  78533. windowBits = -windowBits;
  78534. }
  78535. else {
  78536. state->wrap = (windowBits >> 4) + 1;
  78537. #ifdef GUNZIP
  78538. if (windowBits < 48) windowBits &= 15;
  78539. #endif
  78540. }
  78541. if (windowBits < 8 || windowBits > 15) {
  78542. ZFREE(strm, state);
  78543. strm->state = Z_NULL;
  78544. return Z_STREAM_ERROR;
  78545. }
  78546. state->wbits = (unsigned)windowBits;
  78547. state->window = Z_NULL;
  78548. return inflateReset(strm);
  78549. }
  78550. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78551. {
  78552. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78553. }
  78554. local void fixedtables (struct inflate_state FAR *state)
  78555. {
  78556. #ifdef BUILDFIXED
  78557. static int virgin = 1;
  78558. static code *lenfix, *distfix;
  78559. static code fixed[544];
  78560. if (virgin) {
  78561. unsigned sym, bits;
  78562. static code *next;
  78563. sym = 0;
  78564. while (sym < 144) state->lens[sym++] = 8;
  78565. while (sym < 256) state->lens[sym++] = 9;
  78566. while (sym < 280) state->lens[sym++] = 7;
  78567. while (sym < 288) state->lens[sym++] = 8;
  78568. next = fixed;
  78569. lenfix = next;
  78570. bits = 9;
  78571. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78572. sym = 0;
  78573. while (sym < 32) state->lens[sym++] = 5;
  78574. distfix = next;
  78575. bits = 5;
  78576. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78577. virgin = 0;
  78578. }
  78579. #else /* !BUILDFIXED */
  78580. /*** Start of inlined file: inffixed.h ***/
  78581. static const code lenfix[512] = {
  78582. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78583. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78584. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78585. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78586. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78587. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78588. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78589. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78590. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78591. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78592. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78593. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78594. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78595. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78596. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78597. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78598. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78599. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78600. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78601. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78602. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78603. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78604. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78605. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78606. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78607. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78608. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78609. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78610. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78611. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78612. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78613. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78614. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78615. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78616. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78617. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78618. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78619. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78620. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78621. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78622. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78623. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78624. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78625. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78626. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78627. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78628. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78629. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78630. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78631. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78632. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78633. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78634. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78635. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78636. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78637. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78638. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78639. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78640. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78641. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78642. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78643. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78644. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78645. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78646. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78647. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78648. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78649. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78650. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78651. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78652. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78653. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78654. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78655. {0,9,255}
  78656. };
  78657. static const code distfix[32] = {
  78658. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78659. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78660. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78661. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78662. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78663. {22,5,193},{64,5,0}
  78664. };
  78665. /*** End of inlined file: inffixed.h ***/
  78666. #endif /* BUILDFIXED */
  78667. state->lencode = lenfix;
  78668. state->lenbits = 9;
  78669. state->distcode = distfix;
  78670. state->distbits = 5;
  78671. }
  78672. #ifdef MAKEFIXED
  78673. #include <stdio.h>
  78674. void makefixed()
  78675. {
  78676. unsigned low, size;
  78677. struct inflate_state state;
  78678. fixedtables(&state);
  78679. puts(" /* inffixed.h -- table for decoding fixed codes");
  78680. puts(" * Generated automatically by makefixed().");
  78681. puts(" */");
  78682. puts("");
  78683. puts(" /* WARNING: this file should *not* be used by applications.");
  78684. puts(" It is part of the implementation of this library and is");
  78685. puts(" subject to change. Applications should only use zlib.h.");
  78686. puts(" */");
  78687. puts("");
  78688. size = 1U << 9;
  78689. printf(" static const code lenfix[%u] = {", size);
  78690. low = 0;
  78691. for (;;) {
  78692. if ((low % 7) == 0) printf("\n ");
  78693. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78694. state.lencode[low].val);
  78695. if (++low == size) break;
  78696. putchar(',');
  78697. }
  78698. puts("\n };");
  78699. size = 1U << 5;
  78700. printf("\n static const code distfix[%u] = {", size);
  78701. low = 0;
  78702. for (;;) {
  78703. if ((low % 6) == 0) printf("\n ");
  78704. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78705. state.distcode[low].val);
  78706. if (++low == size) break;
  78707. putchar(',');
  78708. }
  78709. puts("\n };");
  78710. }
  78711. #endif /* MAKEFIXED */
  78712. local int updatewindow (z_streamp strm, unsigned out)
  78713. {
  78714. struct inflate_state FAR *state;
  78715. unsigned copy, dist;
  78716. state = (struct inflate_state FAR *)strm->state;
  78717. if (state->window == Z_NULL) {
  78718. state->window = (unsigned char FAR *)
  78719. ZALLOC(strm, 1U << state->wbits,
  78720. sizeof(unsigned char));
  78721. if (state->window == Z_NULL) return 1;
  78722. }
  78723. if (state->wsize == 0) {
  78724. state->wsize = 1U << state->wbits;
  78725. state->write = 0;
  78726. state->whave = 0;
  78727. }
  78728. copy = out - strm->avail_out;
  78729. if (copy >= state->wsize) {
  78730. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78731. state->write = 0;
  78732. state->whave = state->wsize;
  78733. }
  78734. else {
  78735. dist = state->wsize - state->write;
  78736. if (dist > copy) dist = copy;
  78737. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78738. copy -= dist;
  78739. if (copy) {
  78740. zmemcpy(state->window, strm->next_out - copy, copy);
  78741. state->write = copy;
  78742. state->whave = state->wsize;
  78743. }
  78744. else {
  78745. state->write += dist;
  78746. if (state->write == state->wsize) state->write = 0;
  78747. if (state->whave < state->wsize) state->whave += dist;
  78748. }
  78749. }
  78750. return 0;
  78751. }
  78752. #ifdef GUNZIP
  78753. # define UPDATE(check, buf, len) \
  78754. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78755. #else
  78756. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78757. #endif
  78758. #ifdef GUNZIP
  78759. # define CRC2(check, word) \
  78760. do { \
  78761. hbuf[0] = (unsigned char)(word); \
  78762. hbuf[1] = (unsigned char)((word) >> 8); \
  78763. check = crc32(check, hbuf, 2); \
  78764. } while (0)
  78765. # define CRC4(check, word) \
  78766. do { \
  78767. hbuf[0] = (unsigned char)(word); \
  78768. hbuf[1] = (unsigned char)((word) >> 8); \
  78769. hbuf[2] = (unsigned char)((word) >> 16); \
  78770. hbuf[3] = (unsigned char)((word) >> 24); \
  78771. check = crc32(check, hbuf, 4); \
  78772. } while (0)
  78773. #endif
  78774. #define LOAD() \
  78775. do { \
  78776. put = strm->next_out; \
  78777. left = strm->avail_out; \
  78778. next = strm->next_in; \
  78779. have = strm->avail_in; \
  78780. hold = state->hold; \
  78781. bits = state->bits; \
  78782. } while (0)
  78783. #define RESTORE() \
  78784. do { \
  78785. strm->next_out = put; \
  78786. strm->avail_out = left; \
  78787. strm->next_in = next; \
  78788. strm->avail_in = have; \
  78789. state->hold = hold; \
  78790. state->bits = bits; \
  78791. } while (0)
  78792. #define INITBITS() \
  78793. do { \
  78794. hold = 0; \
  78795. bits = 0; \
  78796. } while (0)
  78797. #define PULLBYTE() \
  78798. do { \
  78799. if (have == 0) goto inf_leave; \
  78800. have--; \
  78801. hold += (unsigned long)(*next++) << bits; \
  78802. bits += 8; \
  78803. } while (0)
  78804. #define NEEDBITS(n) \
  78805. do { \
  78806. while (bits < (unsigned)(n)) \
  78807. PULLBYTE(); \
  78808. } while (0)
  78809. #define BITS(n) \
  78810. ((unsigned)hold & ((1U << (n)) - 1))
  78811. #define DROPBITS(n) \
  78812. do { \
  78813. hold >>= (n); \
  78814. bits -= (unsigned)(n); \
  78815. } while (0)
  78816. #define BYTEBITS() \
  78817. do { \
  78818. hold >>= bits & 7; \
  78819. bits -= bits & 7; \
  78820. } while (0)
  78821. #define REVERSE(q) \
  78822. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78823. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78824. int ZEXPORT inflate (z_streamp strm, int flush)
  78825. {
  78826. struct inflate_state FAR *state;
  78827. unsigned char FAR *next; /* next input */
  78828. unsigned char FAR *put; /* next output */
  78829. unsigned have, left; /* available input and output */
  78830. unsigned long hold; /* bit buffer */
  78831. unsigned bits; /* bits in bit buffer */
  78832. unsigned in, out; /* save starting available input and output */
  78833. unsigned copy; /* number of stored or match bytes to copy */
  78834. unsigned char FAR *from; /* where to copy match bytes from */
  78835. code thisx; /* current decoding table entry */
  78836. code last; /* parent table entry */
  78837. unsigned len; /* length to copy for repeats, bits to drop */
  78838. int ret; /* return code */
  78839. #ifdef GUNZIP
  78840. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78841. #endif
  78842. static const unsigned short order[19] = /* permutation of code lengths */
  78843. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78844. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78845. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78846. return Z_STREAM_ERROR;
  78847. state = (struct inflate_state FAR *)strm->state;
  78848. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78849. LOAD();
  78850. in = have;
  78851. out = left;
  78852. ret = Z_OK;
  78853. for (;;)
  78854. switch (state->mode) {
  78855. case HEAD:
  78856. if (state->wrap == 0) {
  78857. state->mode = TYPEDO;
  78858. break;
  78859. }
  78860. NEEDBITS(16);
  78861. #ifdef GUNZIP
  78862. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78863. state->check = crc32(0L, Z_NULL, 0);
  78864. CRC2(state->check, hold);
  78865. INITBITS();
  78866. state->mode = FLAGS;
  78867. break;
  78868. }
  78869. state->flags = 0; /* expect zlib header */
  78870. if (state->head != Z_NULL)
  78871. state->head->done = -1;
  78872. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78873. #else
  78874. if (
  78875. #endif
  78876. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78877. strm->msg = (char *)"incorrect header check";
  78878. state->mode = BAD;
  78879. break;
  78880. }
  78881. if (BITS(4) != Z_DEFLATED) {
  78882. strm->msg = (char *)"unknown compression method";
  78883. state->mode = BAD;
  78884. break;
  78885. }
  78886. DROPBITS(4);
  78887. len = BITS(4) + 8;
  78888. if (len > state->wbits) {
  78889. strm->msg = (char *)"invalid window size";
  78890. state->mode = BAD;
  78891. break;
  78892. }
  78893. state->dmax = 1U << len;
  78894. Tracev((stderr, "inflate: zlib header ok\n"));
  78895. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78896. state->mode = hold & 0x200 ? DICTID : TYPE;
  78897. INITBITS();
  78898. break;
  78899. #ifdef GUNZIP
  78900. case FLAGS:
  78901. NEEDBITS(16);
  78902. state->flags = (int)(hold);
  78903. if ((state->flags & 0xff) != Z_DEFLATED) {
  78904. strm->msg = (char *)"unknown compression method";
  78905. state->mode = BAD;
  78906. break;
  78907. }
  78908. if (state->flags & 0xe000) {
  78909. strm->msg = (char *)"unknown header flags set";
  78910. state->mode = BAD;
  78911. break;
  78912. }
  78913. if (state->head != Z_NULL)
  78914. state->head->text = (int)((hold >> 8) & 1);
  78915. if (state->flags & 0x0200) CRC2(state->check, hold);
  78916. INITBITS();
  78917. state->mode = TIME;
  78918. case TIME:
  78919. NEEDBITS(32);
  78920. if (state->head != Z_NULL)
  78921. state->head->time = hold;
  78922. if (state->flags & 0x0200) CRC4(state->check, hold);
  78923. INITBITS();
  78924. state->mode = OS;
  78925. case OS:
  78926. NEEDBITS(16);
  78927. if (state->head != Z_NULL) {
  78928. state->head->xflags = (int)(hold & 0xff);
  78929. state->head->os = (int)(hold >> 8);
  78930. }
  78931. if (state->flags & 0x0200) CRC2(state->check, hold);
  78932. INITBITS();
  78933. state->mode = EXLEN;
  78934. case EXLEN:
  78935. if (state->flags & 0x0400) {
  78936. NEEDBITS(16);
  78937. state->length = (unsigned)(hold);
  78938. if (state->head != Z_NULL)
  78939. state->head->extra_len = (unsigned)hold;
  78940. if (state->flags & 0x0200) CRC2(state->check, hold);
  78941. INITBITS();
  78942. }
  78943. else if (state->head != Z_NULL)
  78944. state->head->extra = Z_NULL;
  78945. state->mode = EXTRA;
  78946. case EXTRA:
  78947. if (state->flags & 0x0400) {
  78948. copy = state->length;
  78949. if (copy > have) copy = have;
  78950. if (copy) {
  78951. if (state->head != Z_NULL &&
  78952. state->head->extra != Z_NULL) {
  78953. len = state->head->extra_len - state->length;
  78954. zmemcpy(state->head->extra + len, next,
  78955. len + copy > state->head->extra_max ?
  78956. state->head->extra_max - len : copy);
  78957. }
  78958. if (state->flags & 0x0200)
  78959. state->check = crc32(state->check, next, copy);
  78960. have -= copy;
  78961. next += copy;
  78962. state->length -= copy;
  78963. }
  78964. if (state->length) goto inf_leave;
  78965. }
  78966. state->length = 0;
  78967. state->mode = NAME;
  78968. case NAME:
  78969. if (state->flags & 0x0800) {
  78970. if (have == 0) goto inf_leave;
  78971. copy = 0;
  78972. do {
  78973. len = (unsigned)(next[copy++]);
  78974. if (state->head != Z_NULL &&
  78975. state->head->name != Z_NULL &&
  78976. state->length < state->head->name_max)
  78977. state->head->name[state->length++] = len;
  78978. } while (len && copy < have);
  78979. if (state->flags & 0x0200)
  78980. state->check = crc32(state->check, next, copy);
  78981. have -= copy;
  78982. next += copy;
  78983. if (len) goto inf_leave;
  78984. }
  78985. else if (state->head != Z_NULL)
  78986. state->head->name = Z_NULL;
  78987. state->length = 0;
  78988. state->mode = COMMENT;
  78989. case COMMENT:
  78990. if (state->flags & 0x1000) {
  78991. if (have == 0) goto inf_leave;
  78992. copy = 0;
  78993. do {
  78994. len = (unsigned)(next[copy++]);
  78995. if (state->head != Z_NULL &&
  78996. state->head->comment != Z_NULL &&
  78997. state->length < state->head->comm_max)
  78998. state->head->comment[state->length++] = len;
  78999. } while (len && copy < have);
  79000. if (state->flags & 0x0200)
  79001. state->check = crc32(state->check, next, copy);
  79002. have -= copy;
  79003. next += copy;
  79004. if (len) goto inf_leave;
  79005. }
  79006. else if (state->head != Z_NULL)
  79007. state->head->comment = Z_NULL;
  79008. state->mode = HCRC;
  79009. case HCRC:
  79010. if (state->flags & 0x0200) {
  79011. NEEDBITS(16);
  79012. if (hold != (state->check & 0xffff)) {
  79013. strm->msg = (char *)"header crc mismatch";
  79014. state->mode = BAD;
  79015. break;
  79016. }
  79017. INITBITS();
  79018. }
  79019. if (state->head != Z_NULL) {
  79020. state->head->hcrc = (int)((state->flags >> 9) & 1);
  79021. state->head->done = 1;
  79022. }
  79023. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  79024. state->mode = TYPE;
  79025. break;
  79026. #endif
  79027. case DICTID:
  79028. NEEDBITS(32);
  79029. strm->adler = state->check = REVERSE(hold);
  79030. INITBITS();
  79031. state->mode = DICT;
  79032. case DICT:
  79033. if (state->havedict == 0) {
  79034. RESTORE();
  79035. return Z_NEED_DICT;
  79036. }
  79037. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  79038. state->mode = TYPE;
  79039. case TYPE:
  79040. if (flush == Z_BLOCK) goto inf_leave;
  79041. case TYPEDO:
  79042. if (state->last) {
  79043. BYTEBITS();
  79044. state->mode = CHECK;
  79045. break;
  79046. }
  79047. NEEDBITS(3);
  79048. state->last = BITS(1);
  79049. DROPBITS(1);
  79050. switch (BITS(2)) {
  79051. case 0: /* stored block */
  79052. Tracev((stderr, "inflate: stored block%s\n",
  79053. state->last ? " (last)" : ""));
  79054. state->mode = STORED;
  79055. break;
  79056. case 1: /* fixed block */
  79057. fixedtables(state);
  79058. Tracev((stderr, "inflate: fixed codes block%s\n",
  79059. state->last ? " (last)" : ""));
  79060. state->mode = LEN; /* decode codes */
  79061. break;
  79062. case 2: /* dynamic block */
  79063. Tracev((stderr, "inflate: dynamic codes block%s\n",
  79064. state->last ? " (last)" : ""));
  79065. state->mode = TABLE;
  79066. break;
  79067. case 3:
  79068. strm->msg = (char *)"invalid block type";
  79069. state->mode = BAD;
  79070. }
  79071. DROPBITS(2);
  79072. break;
  79073. case STORED:
  79074. BYTEBITS(); /* go to byte boundary */
  79075. NEEDBITS(32);
  79076. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  79077. strm->msg = (char *)"invalid stored block lengths";
  79078. state->mode = BAD;
  79079. break;
  79080. }
  79081. state->length = (unsigned)hold & 0xffff;
  79082. Tracev((stderr, "inflate: stored length %u\n",
  79083. state->length));
  79084. INITBITS();
  79085. state->mode = COPY;
  79086. case COPY:
  79087. copy = state->length;
  79088. if (copy) {
  79089. if (copy > have) copy = have;
  79090. if (copy > left) copy = left;
  79091. if (copy == 0) goto inf_leave;
  79092. zmemcpy(put, next, copy);
  79093. have -= copy;
  79094. next += copy;
  79095. left -= copy;
  79096. put += copy;
  79097. state->length -= copy;
  79098. break;
  79099. }
  79100. Tracev((stderr, "inflate: stored end\n"));
  79101. state->mode = TYPE;
  79102. break;
  79103. case TABLE:
  79104. NEEDBITS(14);
  79105. state->nlen = BITS(5) + 257;
  79106. DROPBITS(5);
  79107. state->ndist = BITS(5) + 1;
  79108. DROPBITS(5);
  79109. state->ncode = BITS(4) + 4;
  79110. DROPBITS(4);
  79111. #ifndef PKZIP_BUG_WORKAROUND
  79112. if (state->nlen > 286 || state->ndist > 30) {
  79113. strm->msg = (char *)"too many length or distance symbols";
  79114. state->mode = BAD;
  79115. break;
  79116. }
  79117. #endif
  79118. Tracev((stderr, "inflate: table sizes ok\n"));
  79119. state->have = 0;
  79120. state->mode = LENLENS;
  79121. case LENLENS:
  79122. while (state->have < state->ncode) {
  79123. NEEDBITS(3);
  79124. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  79125. DROPBITS(3);
  79126. }
  79127. while (state->have < 19)
  79128. state->lens[order[state->have++]] = 0;
  79129. state->next = state->codes;
  79130. state->lencode = (code const FAR *)(state->next);
  79131. state->lenbits = 7;
  79132. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  79133. &(state->lenbits), state->work);
  79134. if (ret) {
  79135. strm->msg = (char *)"invalid code lengths set";
  79136. state->mode = BAD;
  79137. break;
  79138. }
  79139. Tracev((stderr, "inflate: code lengths ok\n"));
  79140. state->have = 0;
  79141. state->mode = CODELENS;
  79142. case CODELENS:
  79143. while (state->have < state->nlen + state->ndist) {
  79144. for (;;) {
  79145. thisx = state->lencode[BITS(state->lenbits)];
  79146. if ((unsigned)(thisx.bits) <= bits) break;
  79147. PULLBYTE();
  79148. }
  79149. if (thisx.val < 16) {
  79150. NEEDBITS(thisx.bits);
  79151. DROPBITS(thisx.bits);
  79152. state->lens[state->have++] = thisx.val;
  79153. }
  79154. else {
  79155. if (thisx.val == 16) {
  79156. NEEDBITS(thisx.bits + 2);
  79157. DROPBITS(thisx.bits);
  79158. if (state->have == 0) {
  79159. strm->msg = (char *)"invalid bit length repeat";
  79160. state->mode = BAD;
  79161. break;
  79162. }
  79163. len = state->lens[state->have - 1];
  79164. copy = 3 + BITS(2);
  79165. DROPBITS(2);
  79166. }
  79167. else if (thisx.val == 17) {
  79168. NEEDBITS(thisx.bits + 3);
  79169. DROPBITS(thisx.bits);
  79170. len = 0;
  79171. copy = 3 + BITS(3);
  79172. DROPBITS(3);
  79173. }
  79174. else {
  79175. NEEDBITS(thisx.bits + 7);
  79176. DROPBITS(thisx.bits);
  79177. len = 0;
  79178. copy = 11 + BITS(7);
  79179. DROPBITS(7);
  79180. }
  79181. if (state->have + copy > state->nlen + state->ndist) {
  79182. strm->msg = (char *)"invalid bit length repeat";
  79183. state->mode = BAD;
  79184. break;
  79185. }
  79186. while (copy--)
  79187. state->lens[state->have++] = (unsigned short)len;
  79188. }
  79189. }
  79190. if (state->mode == BAD) break;
  79191. state->next = state->codes;
  79192. state->lencode = (code const FAR *)(state->next);
  79193. state->lenbits = 9;
  79194. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  79195. &(state->lenbits), state->work);
  79196. if (ret) {
  79197. strm->msg = (char *)"invalid literal/lengths set";
  79198. state->mode = BAD;
  79199. break;
  79200. }
  79201. state->distcode = (code const FAR *)(state->next);
  79202. state->distbits = 6;
  79203. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  79204. &(state->next), &(state->distbits), state->work);
  79205. if (ret) {
  79206. strm->msg = (char *)"invalid distances set";
  79207. state->mode = BAD;
  79208. break;
  79209. }
  79210. Tracev((stderr, "inflate: codes ok\n"));
  79211. state->mode = LEN;
  79212. case LEN:
  79213. if (have >= 6 && left >= 258) {
  79214. RESTORE();
  79215. inflate_fast(strm, out);
  79216. LOAD();
  79217. break;
  79218. }
  79219. for (;;) {
  79220. thisx = state->lencode[BITS(state->lenbits)];
  79221. if ((unsigned)(thisx.bits) <= bits) break;
  79222. PULLBYTE();
  79223. }
  79224. if (thisx.op && (thisx.op & 0xf0) == 0) {
  79225. last = thisx;
  79226. for (;;) {
  79227. thisx = state->lencode[last.val +
  79228. (BITS(last.bits + last.op) >> last.bits)];
  79229. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79230. PULLBYTE();
  79231. }
  79232. DROPBITS(last.bits);
  79233. }
  79234. DROPBITS(thisx.bits);
  79235. state->length = (unsigned)thisx.val;
  79236. if ((int)(thisx.op) == 0) {
  79237. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  79238. "inflate: literal '%c'\n" :
  79239. "inflate: literal 0x%02x\n", thisx.val));
  79240. state->mode = LIT;
  79241. break;
  79242. }
  79243. if (thisx.op & 32) {
  79244. Tracevv((stderr, "inflate: end of block\n"));
  79245. state->mode = TYPE;
  79246. break;
  79247. }
  79248. if (thisx.op & 64) {
  79249. strm->msg = (char *)"invalid literal/length code";
  79250. state->mode = BAD;
  79251. break;
  79252. }
  79253. state->extra = (unsigned)(thisx.op) & 15;
  79254. state->mode = LENEXT;
  79255. case LENEXT:
  79256. if (state->extra) {
  79257. NEEDBITS(state->extra);
  79258. state->length += BITS(state->extra);
  79259. DROPBITS(state->extra);
  79260. }
  79261. Tracevv((stderr, "inflate: length %u\n", state->length));
  79262. state->mode = DIST;
  79263. case DIST:
  79264. for (;;) {
  79265. thisx = state->distcode[BITS(state->distbits)];
  79266. if ((unsigned)(thisx.bits) <= bits) break;
  79267. PULLBYTE();
  79268. }
  79269. if ((thisx.op & 0xf0) == 0) {
  79270. last = thisx;
  79271. for (;;) {
  79272. thisx = state->distcode[last.val +
  79273. (BITS(last.bits + last.op) >> last.bits)];
  79274. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79275. PULLBYTE();
  79276. }
  79277. DROPBITS(last.bits);
  79278. }
  79279. DROPBITS(thisx.bits);
  79280. if (thisx.op & 64) {
  79281. strm->msg = (char *)"invalid distance code";
  79282. state->mode = BAD;
  79283. break;
  79284. }
  79285. state->offset = (unsigned)thisx.val;
  79286. state->extra = (unsigned)(thisx.op) & 15;
  79287. state->mode = DISTEXT;
  79288. case DISTEXT:
  79289. if (state->extra) {
  79290. NEEDBITS(state->extra);
  79291. state->offset += BITS(state->extra);
  79292. DROPBITS(state->extra);
  79293. }
  79294. #ifdef INFLATE_STRICT
  79295. if (state->offset > state->dmax) {
  79296. strm->msg = (char *)"invalid distance too far back";
  79297. state->mode = BAD;
  79298. break;
  79299. }
  79300. #endif
  79301. if (state->offset > state->whave + out - left) {
  79302. strm->msg = (char *)"invalid distance too far back";
  79303. state->mode = BAD;
  79304. break;
  79305. }
  79306. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  79307. state->mode = MATCH;
  79308. case MATCH:
  79309. if (left == 0) goto inf_leave;
  79310. copy = out - left;
  79311. if (state->offset > copy) { /* copy from window */
  79312. copy = state->offset - copy;
  79313. if (copy > state->write) {
  79314. copy -= state->write;
  79315. from = state->window + (state->wsize - copy);
  79316. }
  79317. else
  79318. from = state->window + (state->write - copy);
  79319. if (copy > state->length) copy = state->length;
  79320. }
  79321. else { /* copy from output */
  79322. from = put - state->offset;
  79323. copy = state->length;
  79324. }
  79325. if (copy > left) copy = left;
  79326. left -= copy;
  79327. state->length -= copy;
  79328. do {
  79329. *put++ = *from++;
  79330. } while (--copy);
  79331. if (state->length == 0) state->mode = LEN;
  79332. break;
  79333. case LIT:
  79334. if (left == 0) goto inf_leave;
  79335. *put++ = (unsigned char)(state->length);
  79336. left--;
  79337. state->mode = LEN;
  79338. break;
  79339. case CHECK:
  79340. if (state->wrap) {
  79341. NEEDBITS(32);
  79342. out -= left;
  79343. strm->total_out += out;
  79344. state->total += out;
  79345. if (out)
  79346. strm->adler = state->check =
  79347. UPDATE(state->check, put - out, out);
  79348. out = left;
  79349. if ((
  79350. #ifdef GUNZIP
  79351. state->flags ? hold :
  79352. #endif
  79353. REVERSE(hold)) != state->check) {
  79354. strm->msg = (char *)"incorrect data check";
  79355. state->mode = BAD;
  79356. break;
  79357. }
  79358. INITBITS();
  79359. Tracev((stderr, "inflate: check matches trailer\n"));
  79360. }
  79361. #ifdef GUNZIP
  79362. state->mode = LENGTH;
  79363. case LENGTH:
  79364. if (state->wrap && state->flags) {
  79365. NEEDBITS(32);
  79366. if (hold != (state->total & 0xffffffffUL)) {
  79367. strm->msg = (char *)"incorrect length check";
  79368. state->mode = BAD;
  79369. break;
  79370. }
  79371. INITBITS();
  79372. Tracev((stderr, "inflate: length matches trailer\n"));
  79373. }
  79374. #endif
  79375. state->mode = DONE;
  79376. case DONE:
  79377. ret = Z_STREAM_END;
  79378. goto inf_leave;
  79379. case BAD:
  79380. ret = Z_DATA_ERROR;
  79381. goto inf_leave;
  79382. case MEM:
  79383. return Z_MEM_ERROR;
  79384. case SYNC:
  79385. default:
  79386. return Z_STREAM_ERROR;
  79387. }
  79388. inf_leave:
  79389. RESTORE();
  79390. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  79391. if (updatewindow(strm, out)) {
  79392. state->mode = MEM;
  79393. return Z_MEM_ERROR;
  79394. }
  79395. in -= strm->avail_in;
  79396. out -= strm->avail_out;
  79397. strm->total_in += in;
  79398. strm->total_out += out;
  79399. state->total += out;
  79400. if (state->wrap && out)
  79401. strm->adler = state->check =
  79402. UPDATE(state->check, strm->next_out - out, out);
  79403. strm->data_type = state->bits + (state->last ? 64 : 0) +
  79404. (state->mode == TYPE ? 128 : 0);
  79405. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  79406. ret = Z_BUF_ERROR;
  79407. return ret;
  79408. }
  79409. int ZEXPORT inflateEnd (z_streamp strm)
  79410. {
  79411. struct inflate_state FAR *state;
  79412. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  79413. return Z_STREAM_ERROR;
  79414. state = (struct inflate_state FAR *)strm->state;
  79415. if (state->window != Z_NULL) ZFREE(strm, state->window);
  79416. ZFREE(strm, strm->state);
  79417. strm->state = Z_NULL;
  79418. Tracev((stderr, "inflate: end\n"));
  79419. return Z_OK;
  79420. }
  79421. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  79422. {
  79423. struct inflate_state FAR *state;
  79424. unsigned long id_;
  79425. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79426. state = (struct inflate_state FAR *)strm->state;
  79427. if (state->wrap != 0 && state->mode != DICT)
  79428. return Z_STREAM_ERROR;
  79429. if (state->mode == DICT) {
  79430. id_ = adler32(0L, Z_NULL, 0);
  79431. id_ = adler32(id_, dictionary, dictLength);
  79432. if (id_ != state->check)
  79433. return Z_DATA_ERROR;
  79434. }
  79435. if (updatewindow(strm, strm->avail_out)) {
  79436. state->mode = MEM;
  79437. return Z_MEM_ERROR;
  79438. }
  79439. if (dictLength > state->wsize) {
  79440. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  79441. state->wsize);
  79442. state->whave = state->wsize;
  79443. }
  79444. else {
  79445. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  79446. dictLength);
  79447. state->whave = dictLength;
  79448. }
  79449. state->havedict = 1;
  79450. Tracev((stderr, "inflate: dictionary set\n"));
  79451. return Z_OK;
  79452. }
  79453. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  79454. {
  79455. struct inflate_state FAR *state;
  79456. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79457. state = (struct inflate_state FAR *)strm->state;
  79458. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  79459. state->head = head;
  79460. head->done = 0;
  79461. return Z_OK;
  79462. }
  79463. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  79464. {
  79465. unsigned got;
  79466. unsigned next;
  79467. got = *have;
  79468. next = 0;
  79469. while (next < len && got < 4) {
  79470. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  79471. got++;
  79472. else if (buf[next])
  79473. got = 0;
  79474. else
  79475. got = 4 - got;
  79476. next++;
  79477. }
  79478. *have = got;
  79479. return next;
  79480. }
  79481. int ZEXPORT inflateSync (z_streamp strm)
  79482. {
  79483. unsigned len; /* number of bytes to look at or looked at */
  79484. unsigned long in, out; /* temporary to save total_in and total_out */
  79485. unsigned char buf[4]; /* to restore bit buffer to byte string */
  79486. struct inflate_state FAR *state;
  79487. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79488. state = (struct inflate_state FAR *)strm->state;
  79489. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  79490. if (state->mode != SYNC) {
  79491. state->mode = SYNC;
  79492. state->hold <<= state->bits & 7;
  79493. state->bits -= state->bits & 7;
  79494. len = 0;
  79495. while (state->bits >= 8) {
  79496. buf[len++] = (unsigned char)(state->hold);
  79497. state->hold >>= 8;
  79498. state->bits -= 8;
  79499. }
  79500. state->have = 0;
  79501. syncsearch(&(state->have), buf, len);
  79502. }
  79503. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  79504. strm->avail_in -= len;
  79505. strm->next_in += len;
  79506. strm->total_in += len;
  79507. if (state->have != 4) return Z_DATA_ERROR;
  79508. in = strm->total_in; out = strm->total_out;
  79509. inflateReset(strm);
  79510. strm->total_in = in; strm->total_out = out;
  79511. state->mode = TYPE;
  79512. return Z_OK;
  79513. }
  79514. int ZEXPORT inflateSyncPoint (z_streamp strm)
  79515. {
  79516. struct inflate_state FAR *state;
  79517. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79518. state = (struct inflate_state FAR *)strm->state;
  79519. return state->mode == STORED && state->bits == 0;
  79520. }
  79521. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  79522. {
  79523. struct inflate_state FAR *state;
  79524. struct inflate_state FAR *copy;
  79525. unsigned char FAR *window;
  79526. unsigned wsize;
  79527. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  79528. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  79529. return Z_STREAM_ERROR;
  79530. state = (struct inflate_state FAR *)source->state;
  79531. copy = (struct inflate_state FAR *)
  79532. ZALLOC(source, 1, sizeof(struct inflate_state));
  79533. if (copy == Z_NULL) return Z_MEM_ERROR;
  79534. window = Z_NULL;
  79535. if (state->window != Z_NULL) {
  79536. window = (unsigned char FAR *)
  79537. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  79538. if (window == Z_NULL) {
  79539. ZFREE(source, copy);
  79540. return Z_MEM_ERROR;
  79541. }
  79542. }
  79543. zmemcpy(dest, source, sizeof(z_stream));
  79544. zmemcpy(copy, state, sizeof(struct inflate_state));
  79545. if (state->lencode >= state->codes &&
  79546. state->lencode <= state->codes + ENOUGH - 1) {
  79547. copy->lencode = copy->codes + (state->lencode - state->codes);
  79548. copy->distcode = copy->codes + (state->distcode - state->codes);
  79549. }
  79550. copy->next = copy->codes + (state->next - state->codes);
  79551. if (window != Z_NULL) {
  79552. wsize = 1U << state->wbits;
  79553. zmemcpy(window, state->window, wsize);
  79554. }
  79555. copy->window = window;
  79556. dest->state = (struct internal_state FAR *)copy;
  79557. return Z_OK;
  79558. }
  79559. /*** End of inlined file: inflate.c ***/
  79560. /*** Start of inlined file: inftrees.c ***/
  79561. #define MAXBITS 15
  79562. const char inflate_copyright[] =
  79563. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79564. int inflate_table (codetype type,
  79565. unsigned short FAR *lens,
  79566. unsigned codes,
  79567. code FAR * FAR *table,
  79568. unsigned FAR *bits,
  79569. unsigned short FAR *work)
  79570. {
  79571. unsigned len; /* a code's length in bits */
  79572. unsigned sym; /* index of code symbols */
  79573. unsigned min, max; /* minimum and maximum code lengths */
  79574. unsigned root; /* number of index bits for root table */
  79575. unsigned curr; /* number of index bits for current table */
  79576. unsigned drop; /* code bits to drop for sub-table */
  79577. int left; /* number of prefix codes available */
  79578. unsigned used; /* code entries in table used */
  79579. unsigned huff; /* Huffman code */
  79580. unsigned incr; /* for incrementing code, index */
  79581. unsigned fill; /* index for replicating entries */
  79582. unsigned low; /* low bits for current root entry */
  79583. unsigned mask; /* mask for low root bits */
  79584. code thisx; /* table entry for duplication */
  79585. code FAR *next; /* next available space in table */
  79586. const unsigned short FAR *base; /* base value table to use */
  79587. const unsigned short FAR *extra; /* extra bits table to use */
  79588. int end; /* use base and extra for symbol > end */
  79589. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79590. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79591. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79592. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79593. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79594. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79595. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79596. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79597. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79598. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79599. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79600. 8193, 12289, 16385, 24577, 0, 0};
  79601. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79602. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79603. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79604. 28, 28, 29, 29, 64, 64};
  79605. for (len = 0; len <= MAXBITS; len++)
  79606. count[len] = 0;
  79607. for (sym = 0; sym < codes; sym++)
  79608. count[lens[sym]]++;
  79609. root = *bits;
  79610. for (max = MAXBITS; max >= 1; max--)
  79611. if (count[max] != 0) break;
  79612. if (root > max) root = max;
  79613. if (max == 0) { /* no symbols to code at all */
  79614. thisx.op = (unsigned char)64; /* invalid code marker */
  79615. thisx.bits = (unsigned char)1;
  79616. thisx.val = (unsigned short)0;
  79617. *(*table)++ = thisx; /* make a table to force an error */
  79618. *(*table)++ = thisx;
  79619. *bits = 1;
  79620. return 0; /* no symbols, but wait for decoding to report error */
  79621. }
  79622. for (min = 1; min <= MAXBITS; min++)
  79623. if (count[min] != 0) break;
  79624. if (root < min) root = min;
  79625. left = 1;
  79626. for (len = 1; len <= MAXBITS; len++) {
  79627. left <<= 1;
  79628. left -= count[len];
  79629. if (left < 0) return -1; /* over-subscribed */
  79630. }
  79631. if (left > 0 && (type == CODES || max != 1))
  79632. return -1; /* incomplete set */
  79633. offs[1] = 0;
  79634. for (len = 1; len < MAXBITS; len++)
  79635. offs[len + 1] = offs[len] + count[len];
  79636. for (sym = 0; sym < codes; sym++)
  79637. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79638. switch (type) {
  79639. case CODES:
  79640. base = extra = work; /* dummy value--not used */
  79641. end = 19;
  79642. break;
  79643. case LENS:
  79644. base = lbase;
  79645. base -= 257;
  79646. extra = lext;
  79647. extra -= 257;
  79648. end = 256;
  79649. break;
  79650. default: /* DISTS */
  79651. base = dbase;
  79652. extra = dext;
  79653. end = -1;
  79654. }
  79655. huff = 0; /* starting code */
  79656. sym = 0; /* starting code symbol */
  79657. len = min; /* starting code length */
  79658. next = *table; /* current table to fill in */
  79659. curr = root; /* current table index bits */
  79660. drop = 0; /* current bits to drop from code for index */
  79661. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79662. used = 1U << root; /* use root table entries */
  79663. mask = used - 1; /* mask for comparing low */
  79664. if (type == LENS && used >= ENOUGH - MAXD)
  79665. return 1;
  79666. for (;;) {
  79667. thisx.bits = (unsigned char)(len - drop);
  79668. if ((int)(work[sym]) < end) {
  79669. thisx.op = (unsigned char)0;
  79670. thisx.val = work[sym];
  79671. }
  79672. else if ((int)(work[sym]) > end) {
  79673. thisx.op = (unsigned char)(extra[work[sym]]);
  79674. thisx.val = base[work[sym]];
  79675. }
  79676. else {
  79677. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79678. thisx.val = 0;
  79679. }
  79680. incr = 1U << (len - drop);
  79681. fill = 1U << curr;
  79682. min = fill; /* save offset to next table */
  79683. do {
  79684. fill -= incr;
  79685. next[(huff >> drop) + fill] = thisx;
  79686. } while (fill != 0);
  79687. incr = 1U << (len - 1);
  79688. while (huff & incr)
  79689. incr >>= 1;
  79690. if (incr != 0) {
  79691. huff &= incr - 1;
  79692. huff += incr;
  79693. }
  79694. else
  79695. huff = 0;
  79696. sym++;
  79697. if (--(count[len]) == 0) {
  79698. if (len == max) break;
  79699. len = lens[work[sym]];
  79700. }
  79701. if (len > root && (huff & mask) != low) {
  79702. if (drop == 0)
  79703. drop = root;
  79704. next += min; /* here min is 1 << curr */
  79705. curr = len - drop;
  79706. left = (int)(1 << curr);
  79707. while (curr + drop < max) {
  79708. left -= count[curr + drop];
  79709. if (left <= 0) break;
  79710. curr++;
  79711. left <<= 1;
  79712. }
  79713. used += 1U << curr;
  79714. if (type == LENS && used >= ENOUGH - MAXD)
  79715. return 1;
  79716. low = huff & mask;
  79717. (*table)[low].op = (unsigned char)curr;
  79718. (*table)[low].bits = (unsigned char)root;
  79719. (*table)[low].val = (unsigned short)(next - *table);
  79720. }
  79721. }
  79722. thisx.op = (unsigned char)64; /* invalid code marker */
  79723. thisx.bits = (unsigned char)(len - drop);
  79724. thisx.val = (unsigned short)0;
  79725. while (huff != 0) {
  79726. if (drop != 0 && (huff & mask) != low) {
  79727. drop = 0;
  79728. len = root;
  79729. next = *table;
  79730. thisx.bits = (unsigned char)len;
  79731. }
  79732. next[huff >> drop] = thisx;
  79733. incr = 1U << (len - 1);
  79734. while (huff & incr)
  79735. incr >>= 1;
  79736. if (incr != 0) {
  79737. huff &= incr - 1;
  79738. huff += incr;
  79739. }
  79740. else
  79741. huff = 0;
  79742. }
  79743. *table += used;
  79744. *bits = root;
  79745. return 0;
  79746. }
  79747. /*** End of inlined file: inftrees.c ***/
  79748. /*** Start of inlined file: trees.c ***/
  79749. #ifdef DEBUG
  79750. # include <ctype.h>
  79751. #endif
  79752. #define MAX_BL_BITS 7
  79753. #define END_BLOCK 256
  79754. #define REP_3_6 16
  79755. #define REPZ_3_10 17
  79756. #define REPZ_11_138 18
  79757. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79758. = {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};
  79759. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79760. = {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};
  79761. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79762. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79763. local const uch bl_order[BL_CODES]
  79764. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79765. #define Buf_size (8 * 2*sizeof(char))
  79766. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79767. #if defined(GEN_TREES_H) || !defined(STDC)
  79768. local ct_data static_ltree[L_CODES+2];
  79769. local ct_data static_dtree[D_CODES];
  79770. uch _dist_code[DIST_CODE_LEN];
  79771. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79772. local int base_length[LENGTH_CODES];
  79773. local int base_dist[D_CODES];
  79774. #else
  79775. /*** Start of inlined file: trees.h ***/
  79776. local const ct_data static_ltree[L_CODES+2] = {
  79777. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79778. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79779. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79780. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79781. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79782. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79783. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79784. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79785. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79786. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79787. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79788. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79789. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79790. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79791. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79792. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79793. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79794. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79795. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79796. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79797. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79798. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79799. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79800. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79801. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79802. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79803. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79804. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79805. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79806. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79807. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79808. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79809. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79810. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79811. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79812. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79813. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79814. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79815. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79816. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79817. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79818. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79819. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79820. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79821. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79822. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79823. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79824. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79825. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79826. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79827. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79828. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79829. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79830. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79831. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79832. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79833. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79834. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79835. };
  79836. local const ct_data static_dtree[D_CODES] = {
  79837. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79838. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79839. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79840. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79841. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79842. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79843. };
  79844. const uch _dist_code[DIST_CODE_LEN] = {
  79845. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79846. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79847. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79848. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79849. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79850. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79851. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79852. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79853. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79854. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79855. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79856. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79857. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79858. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79859. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79860. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79861. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79862. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79863. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79864. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79865. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79866. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79867. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79868. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79869. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79870. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79871. };
  79872. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79873. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79874. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79875. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79876. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79877. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79878. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79879. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79880. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79881. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79882. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79883. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79884. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79885. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79886. };
  79887. local const int base_length[LENGTH_CODES] = {
  79888. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79889. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79890. };
  79891. local const int base_dist[D_CODES] = {
  79892. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79893. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79894. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79895. };
  79896. /*** End of inlined file: trees.h ***/
  79897. #endif /* GEN_TREES_H */
  79898. struct static_tree_desc_s {
  79899. const ct_data *static_tree; /* static tree or NULL */
  79900. const intf *extra_bits; /* extra bits for each code or NULL */
  79901. int extra_base; /* base index for extra_bits */
  79902. int elems; /* max number of elements in the tree */
  79903. int max_length; /* max bit length for the codes */
  79904. };
  79905. local static_tree_desc static_l_desc =
  79906. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79907. local static_tree_desc static_d_desc =
  79908. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79909. local static_tree_desc static_bl_desc =
  79910. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79911. local void tr_static_init OF((void));
  79912. local void init_block OF((deflate_state *s));
  79913. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79914. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79915. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79916. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79917. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79918. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79919. local int build_bl_tree OF((deflate_state *s));
  79920. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79921. int blcodes));
  79922. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79923. ct_data *dtree));
  79924. local void set_data_type OF((deflate_state *s));
  79925. local unsigned bi_reverse OF((unsigned value, int length));
  79926. local void bi_windup OF((deflate_state *s));
  79927. local void bi_flush OF((deflate_state *s));
  79928. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79929. int header));
  79930. #ifdef GEN_TREES_H
  79931. local void gen_trees_header OF((void));
  79932. #endif
  79933. #ifndef DEBUG
  79934. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79935. #else /* DEBUG */
  79936. # define send_code(s, c, tree) \
  79937. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79938. send_bits(s, tree[c].Code, tree[c].Len); }
  79939. #endif
  79940. #define put_short(s, w) { \
  79941. put_byte(s, (uch)((w) & 0xff)); \
  79942. put_byte(s, (uch)((ush)(w) >> 8)); \
  79943. }
  79944. #ifdef DEBUG
  79945. local void send_bits OF((deflate_state *s, int value, int length));
  79946. local void send_bits (deflate_state *s, int value, int length)
  79947. {
  79948. Tracevv((stderr," l %2d v %4x ", length, value));
  79949. Assert(length > 0 && length <= 15, "invalid length");
  79950. s->bits_sent += (ulg)length;
  79951. if (s->bi_valid > (int)Buf_size - length) {
  79952. s->bi_buf |= (value << s->bi_valid);
  79953. put_short(s, s->bi_buf);
  79954. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79955. s->bi_valid += length - Buf_size;
  79956. } else {
  79957. s->bi_buf |= value << s->bi_valid;
  79958. s->bi_valid += length;
  79959. }
  79960. }
  79961. #else /* !DEBUG */
  79962. #define send_bits(s, value, length) \
  79963. { int len = length;\
  79964. if (s->bi_valid > (int)Buf_size - len) {\
  79965. int val = value;\
  79966. s->bi_buf |= (val << s->bi_valid);\
  79967. put_short(s, s->bi_buf);\
  79968. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79969. s->bi_valid += len - Buf_size;\
  79970. } else {\
  79971. s->bi_buf |= (value) << s->bi_valid;\
  79972. s->bi_valid += len;\
  79973. }\
  79974. }
  79975. #endif /* DEBUG */
  79976. local void tr_static_init()
  79977. {
  79978. #if defined(GEN_TREES_H) || !defined(STDC)
  79979. static int static_init_done = 0;
  79980. int n; /* iterates over tree elements */
  79981. int bits; /* bit counter */
  79982. int length; /* length value */
  79983. int code; /* code value */
  79984. int dist; /* distance index */
  79985. ush bl_count[MAX_BITS+1];
  79986. if (static_init_done) return;
  79987. static_l_desc.static_tree = static_ltree;
  79988. static_l_desc.extra_bits = extra_lbits;
  79989. static_d_desc.static_tree = static_dtree;
  79990. static_d_desc.extra_bits = extra_dbits;
  79991. static_bl_desc.extra_bits = extra_blbits;
  79992. length = 0;
  79993. for (code = 0; code < LENGTH_CODES-1; code++) {
  79994. base_length[code] = length;
  79995. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79996. _length_code[length++] = (uch)code;
  79997. }
  79998. }
  79999. Assert (length == 256, "tr_static_init: length != 256");
  80000. _length_code[length-1] = (uch)code;
  80001. dist = 0;
  80002. for (code = 0 ; code < 16; code++) {
  80003. base_dist[code] = dist;
  80004. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  80005. _dist_code[dist++] = (uch)code;
  80006. }
  80007. }
  80008. Assert (dist == 256, "tr_static_init: dist != 256");
  80009. dist >>= 7; /* from now on, all distances are divided by 128 */
  80010. for ( ; code < D_CODES; code++) {
  80011. base_dist[code] = dist << 7;
  80012. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  80013. _dist_code[256 + dist++] = (uch)code;
  80014. }
  80015. }
  80016. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  80017. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  80018. n = 0;
  80019. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  80020. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  80021. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  80022. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  80023. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  80024. for (n = 0; n < D_CODES; n++) {
  80025. static_dtree[n].Len = 5;
  80026. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  80027. }
  80028. static_init_done = 1;
  80029. # ifdef GEN_TREES_H
  80030. gen_trees_header();
  80031. # endif
  80032. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  80033. }
  80034. #ifdef GEN_TREES_H
  80035. # ifndef DEBUG
  80036. # include <stdio.h>
  80037. # endif
  80038. # define SEPARATOR(i, last, width) \
  80039. ((i) == (last)? "\n};\n\n" : \
  80040. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  80041. void gen_trees_header()
  80042. {
  80043. FILE *header = fopen("trees.h", "w");
  80044. int i;
  80045. Assert (header != NULL, "Can't open trees.h");
  80046. fprintf(header,
  80047. "/* header created automatically with -DGEN_TREES_H */\n\n");
  80048. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  80049. for (i = 0; i < L_CODES+2; i++) {
  80050. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  80051. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  80052. }
  80053. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  80054. for (i = 0; i < D_CODES; i++) {
  80055. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  80056. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  80057. }
  80058. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  80059. for (i = 0; i < DIST_CODE_LEN; i++) {
  80060. fprintf(header, "%2u%s", _dist_code[i],
  80061. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  80062. }
  80063. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  80064. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  80065. fprintf(header, "%2u%s", _length_code[i],
  80066. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  80067. }
  80068. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  80069. for (i = 0; i < LENGTH_CODES; i++) {
  80070. fprintf(header, "%1u%s", base_length[i],
  80071. SEPARATOR(i, LENGTH_CODES-1, 20));
  80072. }
  80073. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  80074. for (i = 0; i < D_CODES; i++) {
  80075. fprintf(header, "%5u%s", base_dist[i],
  80076. SEPARATOR(i, D_CODES-1, 10));
  80077. }
  80078. fclose(header);
  80079. }
  80080. #endif /* GEN_TREES_H */
  80081. void _tr_init(deflate_state *s)
  80082. {
  80083. tr_static_init();
  80084. s->l_desc.dyn_tree = s->dyn_ltree;
  80085. s->l_desc.stat_desc = &static_l_desc;
  80086. s->d_desc.dyn_tree = s->dyn_dtree;
  80087. s->d_desc.stat_desc = &static_d_desc;
  80088. s->bl_desc.dyn_tree = s->bl_tree;
  80089. s->bl_desc.stat_desc = &static_bl_desc;
  80090. s->bi_buf = 0;
  80091. s->bi_valid = 0;
  80092. s->last_eob_len = 8; /* enough lookahead for inflate */
  80093. #ifdef DEBUG
  80094. s->compressed_len = 0L;
  80095. s->bits_sent = 0L;
  80096. #endif
  80097. init_block(s);
  80098. }
  80099. local void init_block (deflate_state *s)
  80100. {
  80101. int n; /* iterates over tree elements */
  80102. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  80103. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  80104. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  80105. s->dyn_ltree[END_BLOCK].Freq = 1;
  80106. s->opt_len = s->static_len = 0L;
  80107. s->last_lit = s->matches = 0;
  80108. }
  80109. #define SMALLEST 1
  80110. #define pqremove(s, tree, top) \
  80111. {\
  80112. top = s->heap[SMALLEST]; \
  80113. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  80114. pqdownheap(s, tree, SMALLEST); \
  80115. }
  80116. #define smaller(tree, n, m, depth) \
  80117. (tree[n].Freq < tree[m].Freq || \
  80118. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  80119. local void pqdownheap (deflate_state *s,
  80120. ct_data *tree, /* the tree to restore */
  80121. int k) /* node to move down */
  80122. {
  80123. int v = s->heap[k];
  80124. int j = k << 1; /* left son of k */
  80125. while (j <= s->heap_len) {
  80126. if (j < s->heap_len &&
  80127. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  80128. j++;
  80129. }
  80130. if (smaller(tree, v, s->heap[j], s->depth)) break;
  80131. s->heap[k] = s->heap[j]; k = j;
  80132. j <<= 1;
  80133. }
  80134. s->heap[k] = v;
  80135. }
  80136. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  80137. {
  80138. ct_data *tree = desc->dyn_tree;
  80139. int max_code = desc->max_code;
  80140. const ct_data *stree = desc->stat_desc->static_tree;
  80141. const intf *extra = desc->stat_desc->extra_bits;
  80142. int base = desc->stat_desc->extra_base;
  80143. int max_length = desc->stat_desc->max_length;
  80144. int h; /* heap index */
  80145. int n, m; /* iterate over the tree elements */
  80146. int bits; /* bit length */
  80147. int xbits; /* extra bits */
  80148. ush f; /* frequency */
  80149. int overflow = 0; /* number of elements with bit length too large */
  80150. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  80151. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  80152. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  80153. n = s->heap[h];
  80154. bits = tree[tree[n].Dad].Len + 1;
  80155. if (bits > max_length) bits = max_length, overflow++;
  80156. tree[n].Len = (ush)bits;
  80157. if (n > max_code) continue; /* not a leaf node */
  80158. s->bl_count[bits]++;
  80159. xbits = 0;
  80160. if (n >= base) xbits = extra[n-base];
  80161. f = tree[n].Freq;
  80162. s->opt_len += (ulg)f * (bits + xbits);
  80163. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  80164. }
  80165. if (overflow == 0) return;
  80166. Trace((stderr,"\nbit length overflow\n"));
  80167. do {
  80168. bits = max_length-1;
  80169. while (s->bl_count[bits] == 0) bits--;
  80170. s->bl_count[bits]--; /* move one leaf down the tree */
  80171. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  80172. s->bl_count[max_length]--;
  80173. overflow -= 2;
  80174. } while (overflow > 0);
  80175. for (bits = max_length; bits != 0; bits--) {
  80176. n = s->bl_count[bits];
  80177. while (n != 0) {
  80178. m = s->heap[--h];
  80179. if (m > max_code) continue;
  80180. if ((unsigned) tree[m].Len != (unsigned) bits) {
  80181. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  80182. s->opt_len += ((long)bits - (long)tree[m].Len)
  80183. *(long)tree[m].Freq;
  80184. tree[m].Len = (ush)bits;
  80185. }
  80186. n--;
  80187. }
  80188. }
  80189. }
  80190. local void gen_codes (ct_data *tree, /* the tree to decorate */
  80191. int max_code, /* largest code with non zero frequency */
  80192. ushf *bl_count) /* number of codes at each bit length */
  80193. {
  80194. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  80195. ush code = 0; /* running code value */
  80196. int bits; /* bit index */
  80197. int n; /* code index */
  80198. for (bits = 1; bits <= MAX_BITS; bits++) {
  80199. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  80200. }
  80201. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  80202. "inconsistent bit counts");
  80203. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  80204. for (n = 0; n <= max_code; n++) {
  80205. int len = tree[n].Len;
  80206. if (len == 0) continue;
  80207. tree[n].Code = bi_reverse(next_code[len]++, len);
  80208. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  80209. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  80210. }
  80211. }
  80212. local void build_tree (deflate_state *s,
  80213. tree_desc *desc) /* the tree descriptor */
  80214. {
  80215. ct_data *tree = desc->dyn_tree;
  80216. const ct_data *stree = desc->stat_desc->static_tree;
  80217. int elems = desc->stat_desc->elems;
  80218. int n, m; /* iterate over heap elements */
  80219. int max_code = -1; /* largest code with non zero frequency */
  80220. int node; /* new node being created */
  80221. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  80222. for (n = 0; n < elems; n++) {
  80223. if (tree[n].Freq != 0) {
  80224. s->heap[++(s->heap_len)] = max_code = n;
  80225. s->depth[n] = 0;
  80226. } else {
  80227. tree[n].Len = 0;
  80228. }
  80229. }
  80230. while (s->heap_len < 2) {
  80231. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  80232. tree[node].Freq = 1;
  80233. s->depth[node] = 0;
  80234. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  80235. }
  80236. desc->max_code = max_code;
  80237. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  80238. node = elems; /* next internal node of the tree */
  80239. do {
  80240. pqremove(s, tree, n); /* n = node of least frequency */
  80241. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  80242. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  80243. s->heap[--(s->heap_max)] = m;
  80244. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  80245. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  80246. s->depth[n] : s->depth[m]) + 1);
  80247. tree[n].Dad = tree[m].Dad = (ush)node;
  80248. #ifdef DUMP_BL_TREE
  80249. if (tree == s->bl_tree) {
  80250. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  80251. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  80252. }
  80253. #endif
  80254. s->heap[SMALLEST] = node++;
  80255. pqdownheap(s, tree, SMALLEST);
  80256. } while (s->heap_len >= 2);
  80257. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  80258. gen_bitlen(s, (tree_desc *)desc);
  80259. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  80260. }
  80261. local void scan_tree (deflate_state *s,
  80262. ct_data *tree, /* the tree to be scanned */
  80263. int max_code) /* and its largest code of non zero frequency */
  80264. {
  80265. int n; /* iterates over all tree elements */
  80266. int prevlen = -1; /* last emitted length */
  80267. int curlen; /* length of current code */
  80268. int nextlen = tree[0].Len; /* length of next code */
  80269. int count = 0; /* repeat count of the current code */
  80270. int max_count = 7; /* max repeat count */
  80271. int min_count = 4; /* min repeat count */
  80272. if (nextlen == 0) max_count = 138, min_count = 3;
  80273. tree[max_code+1].Len = (ush)0xffff; /* guard */
  80274. for (n = 0; n <= max_code; n++) {
  80275. curlen = nextlen; nextlen = tree[n+1].Len;
  80276. if (++count < max_count && curlen == nextlen) {
  80277. continue;
  80278. } else if (count < min_count) {
  80279. s->bl_tree[curlen].Freq += count;
  80280. } else if (curlen != 0) {
  80281. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  80282. s->bl_tree[REP_3_6].Freq++;
  80283. } else if (count <= 10) {
  80284. s->bl_tree[REPZ_3_10].Freq++;
  80285. } else {
  80286. s->bl_tree[REPZ_11_138].Freq++;
  80287. }
  80288. count = 0; prevlen = curlen;
  80289. if (nextlen == 0) {
  80290. max_count = 138, min_count = 3;
  80291. } else if (curlen == nextlen) {
  80292. max_count = 6, min_count = 3;
  80293. } else {
  80294. max_count = 7, min_count = 4;
  80295. }
  80296. }
  80297. }
  80298. local void send_tree (deflate_state *s,
  80299. ct_data *tree, /* the tree to be scanned */
  80300. int max_code) /* and its largest code of non zero frequency */
  80301. {
  80302. int n; /* iterates over all tree elements */
  80303. int prevlen = -1; /* last emitted length */
  80304. int curlen; /* length of current code */
  80305. int nextlen = tree[0].Len; /* length of next code */
  80306. int count = 0; /* repeat count of the current code */
  80307. int max_count = 7; /* max repeat count */
  80308. int min_count = 4; /* min repeat count */
  80309. /* guard already set */
  80310. if (nextlen == 0) max_count = 138, min_count = 3;
  80311. for (n = 0; n <= max_code; n++) {
  80312. curlen = nextlen; nextlen = tree[n+1].Len;
  80313. if (++count < max_count && curlen == nextlen) {
  80314. continue;
  80315. } else if (count < min_count) {
  80316. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  80317. } else if (curlen != 0) {
  80318. if (curlen != prevlen) {
  80319. send_code(s, curlen, s->bl_tree); count--;
  80320. }
  80321. Assert(count >= 3 && count <= 6, " 3_6?");
  80322. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  80323. } else if (count <= 10) {
  80324. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  80325. } else {
  80326. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  80327. }
  80328. count = 0; prevlen = curlen;
  80329. if (nextlen == 0) {
  80330. max_count = 138, min_count = 3;
  80331. } else if (curlen == nextlen) {
  80332. max_count = 6, min_count = 3;
  80333. } else {
  80334. max_count = 7, min_count = 4;
  80335. }
  80336. }
  80337. }
  80338. local int build_bl_tree (deflate_state *s)
  80339. {
  80340. int max_blindex; /* index of last bit length code of non zero freq */
  80341. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  80342. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  80343. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  80344. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  80345. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  80346. }
  80347. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  80348. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  80349. s->opt_len, s->static_len));
  80350. return max_blindex;
  80351. }
  80352. local void send_all_trees (deflate_state *s,
  80353. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  80354. {
  80355. int rank; /* index in bl_order */
  80356. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  80357. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  80358. "too many codes");
  80359. Tracev((stderr, "\nbl counts: "));
  80360. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  80361. send_bits(s, dcodes-1, 5);
  80362. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  80363. for (rank = 0; rank < blcodes; rank++) {
  80364. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  80365. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  80366. }
  80367. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  80368. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  80369. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  80370. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  80371. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  80372. }
  80373. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  80374. {
  80375. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  80376. #ifdef DEBUG
  80377. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  80378. s->compressed_len += (stored_len + 4) << 3;
  80379. #endif
  80380. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  80381. }
  80382. void _tr_align (deflate_state *s)
  80383. {
  80384. send_bits(s, STATIC_TREES<<1, 3);
  80385. send_code(s, END_BLOCK, static_ltree);
  80386. #ifdef DEBUG
  80387. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  80388. #endif
  80389. bi_flush(s);
  80390. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  80391. send_bits(s, STATIC_TREES<<1, 3);
  80392. send_code(s, END_BLOCK, static_ltree);
  80393. #ifdef DEBUG
  80394. s->compressed_len += 10L;
  80395. #endif
  80396. bi_flush(s);
  80397. }
  80398. s->last_eob_len = 7;
  80399. }
  80400. void _tr_flush_block (deflate_state *s,
  80401. charf *buf, /* input block, or NULL if too old */
  80402. ulg stored_len, /* length of input block */
  80403. int eof) /* true if this is the last block for a file */
  80404. {
  80405. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  80406. int max_blindex = 0; /* index of last bit length code of non zero freq */
  80407. if (s->level > 0) {
  80408. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  80409. set_data_type(s);
  80410. build_tree(s, (tree_desc *)(&(s->l_desc)));
  80411. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  80412. s->static_len));
  80413. build_tree(s, (tree_desc *)(&(s->d_desc)));
  80414. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  80415. s->static_len));
  80416. max_blindex = build_bl_tree(s);
  80417. opt_lenb = (s->opt_len+3+7)>>3;
  80418. static_lenb = (s->static_len+3+7)>>3;
  80419. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  80420. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  80421. s->last_lit));
  80422. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  80423. } else {
  80424. Assert(buf != (char*)0, "lost buf");
  80425. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  80426. }
  80427. #ifdef FORCE_STORED
  80428. if (buf != (char*)0) { /* force stored block */
  80429. #else
  80430. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  80431. #endif
  80432. _tr_stored_block(s, buf, stored_len, eof);
  80433. #ifdef FORCE_STATIC
  80434. } else if (static_lenb >= 0) { /* force static trees */
  80435. #else
  80436. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  80437. #endif
  80438. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  80439. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  80440. #ifdef DEBUG
  80441. s->compressed_len += 3 + s->static_len;
  80442. #endif
  80443. } else {
  80444. send_bits(s, (DYN_TREES<<1)+eof, 3);
  80445. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  80446. max_blindex+1);
  80447. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  80448. #ifdef DEBUG
  80449. s->compressed_len += 3 + s->opt_len;
  80450. #endif
  80451. }
  80452. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  80453. init_block(s);
  80454. if (eof) {
  80455. bi_windup(s);
  80456. #ifdef DEBUG
  80457. s->compressed_len += 7; /* align on byte boundary */
  80458. #endif
  80459. }
  80460. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  80461. s->compressed_len-7*eof));
  80462. }
  80463. int _tr_tally (deflate_state *s,
  80464. unsigned dist, /* distance of matched string */
  80465. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  80466. {
  80467. s->d_buf[s->last_lit] = (ush)dist;
  80468. s->l_buf[s->last_lit++] = (uch)lc;
  80469. if (dist == 0) {
  80470. s->dyn_ltree[lc].Freq++;
  80471. } else {
  80472. s->matches++;
  80473. dist--; /* dist = match distance - 1 */
  80474. Assert((ush)dist < (ush)MAX_DIST(s) &&
  80475. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  80476. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  80477. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  80478. s->dyn_dtree[d_code(dist)].Freq++;
  80479. }
  80480. #ifdef TRUNCATE_BLOCK
  80481. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  80482. ulg out_length = (ulg)s->last_lit*8L;
  80483. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  80484. int dcode;
  80485. for (dcode = 0; dcode < D_CODES; dcode++) {
  80486. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  80487. (5L+extra_dbits[dcode]);
  80488. }
  80489. out_length >>= 3;
  80490. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  80491. s->last_lit, in_length, out_length,
  80492. 100L - out_length*100L/in_length));
  80493. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  80494. }
  80495. #endif
  80496. return (s->last_lit == s->lit_bufsize-1);
  80497. }
  80498. local void compress_block (deflate_state *s,
  80499. ct_data *ltree, /* literal tree */
  80500. ct_data *dtree) /* distance tree */
  80501. {
  80502. unsigned dist; /* distance of matched string */
  80503. int lc; /* match length or unmatched char (if dist == 0) */
  80504. unsigned lx = 0; /* running index in l_buf */
  80505. unsigned code; /* the code to send */
  80506. int extra; /* number of extra bits to send */
  80507. if (s->last_lit != 0) do {
  80508. dist = s->d_buf[lx];
  80509. lc = s->l_buf[lx++];
  80510. if (dist == 0) {
  80511. send_code(s, lc, ltree); /* send a literal byte */
  80512. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  80513. } else {
  80514. code = _length_code[lc];
  80515. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  80516. extra = extra_lbits[code];
  80517. if (extra != 0) {
  80518. lc -= base_length[code];
  80519. send_bits(s, lc, extra); /* send the extra length bits */
  80520. }
  80521. dist--; /* dist is now the match distance - 1 */
  80522. code = d_code(dist);
  80523. Assert (code < D_CODES, "bad d_code");
  80524. send_code(s, code, dtree); /* send the distance code */
  80525. extra = extra_dbits[code];
  80526. if (extra != 0) {
  80527. dist -= base_dist[code];
  80528. send_bits(s, dist, extra); /* send the extra distance bits */
  80529. }
  80530. } /* literal or match pair ? */
  80531. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  80532. "pendingBuf overflow");
  80533. } while (lx < s->last_lit);
  80534. send_code(s, END_BLOCK, ltree);
  80535. s->last_eob_len = ltree[END_BLOCK].Len;
  80536. }
  80537. local void set_data_type (deflate_state *s)
  80538. {
  80539. int n;
  80540. for (n = 0; n < 9; n++)
  80541. if (s->dyn_ltree[n].Freq != 0)
  80542. break;
  80543. if (n == 9)
  80544. for (n = 14; n < 32; n++)
  80545. if (s->dyn_ltree[n].Freq != 0)
  80546. break;
  80547. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80548. }
  80549. local unsigned bi_reverse (unsigned code, int len)
  80550. {
  80551. register unsigned res = 0;
  80552. do {
  80553. res |= code & 1;
  80554. code >>= 1, res <<= 1;
  80555. } while (--len > 0);
  80556. return res >> 1;
  80557. }
  80558. local void bi_flush (deflate_state *s)
  80559. {
  80560. if (s->bi_valid == 16) {
  80561. put_short(s, s->bi_buf);
  80562. s->bi_buf = 0;
  80563. s->bi_valid = 0;
  80564. } else if (s->bi_valid >= 8) {
  80565. put_byte(s, (Byte)s->bi_buf);
  80566. s->bi_buf >>= 8;
  80567. s->bi_valid -= 8;
  80568. }
  80569. }
  80570. local void bi_windup (deflate_state *s)
  80571. {
  80572. if (s->bi_valid > 8) {
  80573. put_short(s, s->bi_buf);
  80574. } else if (s->bi_valid > 0) {
  80575. put_byte(s, (Byte)s->bi_buf);
  80576. }
  80577. s->bi_buf = 0;
  80578. s->bi_valid = 0;
  80579. #ifdef DEBUG
  80580. s->bits_sent = (s->bits_sent+7) & ~7;
  80581. #endif
  80582. }
  80583. local void copy_block(deflate_state *s,
  80584. charf *buf, /* the input data */
  80585. unsigned len, /* its length */
  80586. int header) /* true if block header must be written */
  80587. {
  80588. bi_windup(s); /* align on byte boundary */
  80589. s->last_eob_len = 8; /* enough lookahead for inflate */
  80590. if (header) {
  80591. put_short(s, (ush)len);
  80592. put_short(s, (ush)~len);
  80593. #ifdef DEBUG
  80594. s->bits_sent += 2*16;
  80595. #endif
  80596. }
  80597. #ifdef DEBUG
  80598. s->bits_sent += (ulg)len<<3;
  80599. #endif
  80600. while (len--) {
  80601. put_byte(s, *buf++);
  80602. }
  80603. }
  80604. /*** End of inlined file: trees.c ***/
  80605. /*** Start of inlined file: zutil.c ***/
  80606. #ifndef NO_DUMMY_DECL
  80607. struct internal_state {int dummy;}; /* for buggy compilers */
  80608. #endif
  80609. const char * const z_errmsg[10] = {
  80610. "need dictionary", /* Z_NEED_DICT 2 */
  80611. "stream end", /* Z_STREAM_END 1 */
  80612. "", /* Z_OK 0 */
  80613. "file error", /* Z_ERRNO (-1) */
  80614. "stream error", /* Z_STREAM_ERROR (-2) */
  80615. "data error", /* Z_DATA_ERROR (-3) */
  80616. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80617. "buffer error", /* Z_BUF_ERROR (-5) */
  80618. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80619. ""};
  80620. #ifdef DEBUG
  80621. # ifndef verbose
  80622. # define verbose 0
  80623. # endif
  80624. int z_verbose = verbose;
  80625. void z_error (const char *m)
  80626. {
  80627. fprintf(stderr, "%s\n", m);
  80628. exit(1);
  80629. }
  80630. #endif
  80631. const char * ZEXPORT zError(int err)
  80632. {
  80633. return ERR_MSG(err);
  80634. }
  80635. #if defined(_WIN32_WCE)
  80636. int errno = 0;
  80637. #endif
  80638. #ifndef HAVE_MEMCPY
  80639. void zmemcpy(dest, source, len)
  80640. Bytef* dest;
  80641. const Bytef* source;
  80642. uInt len;
  80643. {
  80644. if (len == 0) return;
  80645. do {
  80646. *dest++ = *source++; /* ??? to be unrolled */
  80647. } while (--len != 0);
  80648. }
  80649. int zmemcmp(s1, s2, len)
  80650. const Bytef* s1;
  80651. const Bytef* s2;
  80652. uInt len;
  80653. {
  80654. uInt j;
  80655. for (j = 0; j < len; j++) {
  80656. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80657. }
  80658. return 0;
  80659. }
  80660. void zmemzero(dest, len)
  80661. Bytef* dest;
  80662. uInt len;
  80663. {
  80664. if (len == 0) return;
  80665. do {
  80666. *dest++ = 0; /* ??? to be unrolled */
  80667. } while (--len != 0);
  80668. }
  80669. #endif
  80670. #ifdef SYS16BIT
  80671. #ifdef __TURBOC__
  80672. # define MY_ZCALLOC
  80673. #define MAX_PTR 10
  80674. local int next_ptr = 0;
  80675. typedef struct ptr_table_s {
  80676. voidpf org_ptr;
  80677. voidpf new_ptr;
  80678. } ptr_table;
  80679. local ptr_table table[MAX_PTR];
  80680. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80681. {
  80682. voidpf buf = opaque; /* just to make some compilers happy */
  80683. ulg bsize = (ulg)items*size;
  80684. if (bsize < 65520L) {
  80685. buf = farmalloc(bsize);
  80686. if (*(ush*)&buf != 0) return buf;
  80687. } else {
  80688. buf = farmalloc(bsize + 16L);
  80689. }
  80690. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80691. table[next_ptr].org_ptr = buf;
  80692. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80693. *(ush*)&buf = 0;
  80694. table[next_ptr++].new_ptr = buf;
  80695. return buf;
  80696. }
  80697. void zcfree (voidpf opaque, voidpf ptr)
  80698. {
  80699. int n;
  80700. if (*(ush*)&ptr != 0) { /* object < 64K */
  80701. farfree(ptr);
  80702. return;
  80703. }
  80704. for (n = 0; n < next_ptr; n++) {
  80705. if (ptr != table[n].new_ptr) continue;
  80706. farfree(table[n].org_ptr);
  80707. while (++n < next_ptr) {
  80708. table[n-1] = table[n];
  80709. }
  80710. next_ptr--;
  80711. return;
  80712. }
  80713. ptr = opaque; /* just to make some compilers happy */
  80714. Assert(0, "zcfree: ptr not found");
  80715. }
  80716. #endif /* __TURBOC__ */
  80717. #ifdef M_I86
  80718. # define MY_ZCALLOC
  80719. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80720. # define _halloc halloc
  80721. # define _hfree hfree
  80722. #endif
  80723. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80724. {
  80725. if (opaque) opaque = 0; /* to make compiler happy */
  80726. return _halloc((long)items, size);
  80727. }
  80728. void zcfree (voidpf opaque, voidpf ptr)
  80729. {
  80730. if (opaque) opaque = 0; /* to make compiler happy */
  80731. _hfree(ptr);
  80732. }
  80733. #endif /* M_I86 */
  80734. #endif /* SYS16BIT */
  80735. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80736. #ifndef STDC
  80737. extern voidp malloc OF((uInt size));
  80738. extern voidp calloc OF((uInt items, uInt size));
  80739. extern void free OF((voidpf ptr));
  80740. #endif
  80741. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80742. {
  80743. if (opaque) items += size - size; /* make compiler happy */
  80744. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80745. (voidpf)calloc(items, size);
  80746. }
  80747. void zcfree (voidpf opaque, voidpf ptr)
  80748. {
  80749. free(ptr);
  80750. if (opaque) return; /* make compiler happy */
  80751. }
  80752. #endif /* MY_ZCALLOC */
  80753. /*** End of inlined file: zutil.c ***/
  80754. #undef Byte
  80755. }
  80756. #else
  80757. #include <zlib.h>
  80758. #endif
  80759. }
  80760. #if JUCE_MSVC
  80761. #pragma warning (pop)
  80762. #endif
  80763. BEGIN_JUCE_NAMESPACE
  80764. using namespace zlibNamespace;
  80765. // internal helper object that holds the zlib structures so they don't have to be
  80766. // included publicly.
  80767. class GZIPDecompressHelper
  80768. {
  80769. public:
  80770. GZIPDecompressHelper (const bool noWrap) throw()
  80771. : data (0),
  80772. dataSize (0),
  80773. finished (true),
  80774. needsDictionary (false),
  80775. error (true),
  80776. streamIsValid (false)
  80777. {
  80778. zerostruct (stream);
  80779. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80780. finished = error = ! streamIsValid;
  80781. }
  80782. ~GZIPDecompressHelper() throw()
  80783. {
  80784. if (streamIsValid)
  80785. inflateEnd (&stream);
  80786. }
  80787. bool needsInput() const throw() { return dataSize <= 0; }
  80788. void setInput (uint8* const data_, const int size) throw()
  80789. {
  80790. data = data_;
  80791. dataSize = size;
  80792. }
  80793. int doNextBlock (uint8* const dest, const int destSize) throw()
  80794. {
  80795. if (streamIsValid && data != 0 && ! finished)
  80796. {
  80797. stream.next_in = data;
  80798. stream.next_out = dest;
  80799. stream.avail_in = dataSize;
  80800. stream.avail_out = destSize;
  80801. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80802. {
  80803. case Z_STREAM_END:
  80804. finished = true;
  80805. // deliberate fall-through
  80806. case Z_OK:
  80807. data += dataSize - stream.avail_in;
  80808. dataSize = stream.avail_in;
  80809. return destSize - stream.avail_out;
  80810. case Z_NEED_DICT:
  80811. needsDictionary = true;
  80812. data += dataSize - stream.avail_in;
  80813. dataSize = stream.avail_in;
  80814. break;
  80815. case Z_DATA_ERROR:
  80816. case Z_MEM_ERROR:
  80817. error = true;
  80818. default:
  80819. break;
  80820. }
  80821. }
  80822. return 0;
  80823. }
  80824. private:
  80825. z_stream stream;
  80826. uint8* data;
  80827. int dataSize;
  80828. public:
  80829. bool finished, needsDictionary, error, streamIsValid;
  80830. };
  80831. const int gzipDecompBufferSize = 32768;
  80832. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80833. const bool deleteSourceWhenDestroyed,
  80834. const bool noWrap_,
  80835. const int64 uncompressedStreamLength_)
  80836. : sourceStream (sourceStream_),
  80837. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80838. uncompressedStreamLength (uncompressedStreamLength_),
  80839. noWrap (noWrap_),
  80840. isEof (false),
  80841. activeBufferSize (0),
  80842. originalSourcePos (sourceStream_->getPosition()),
  80843. currentPos (0),
  80844. buffer (gzipDecompBufferSize),
  80845. helper (new GZIPDecompressHelper (noWrap_))
  80846. {
  80847. }
  80848. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80849. {
  80850. }
  80851. int64 GZIPDecompressorInputStream::getTotalLength()
  80852. {
  80853. return uncompressedStreamLength;
  80854. }
  80855. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80856. {
  80857. if ((howMany > 0) && ! isEof)
  80858. {
  80859. jassert (destBuffer != 0);
  80860. if (destBuffer != 0)
  80861. {
  80862. int numRead = 0;
  80863. uint8* d = (uint8*) destBuffer;
  80864. while (! helper->error)
  80865. {
  80866. const int n = helper->doNextBlock (d, howMany);
  80867. currentPos += n;
  80868. if (n == 0)
  80869. {
  80870. if (helper->finished || helper->needsDictionary)
  80871. {
  80872. isEof = true;
  80873. return numRead;
  80874. }
  80875. if (helper->needsInput())
  80876. {
  80877. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80878. if (activeBufferSize > 0)
  80879. {
  80880. helper->setInput ((uint8*) buffer, activeBufferSize);
  80881. }
  80882. else
  80883. {
  80884. isEof = true;
  80885. return numRead;
  80886. }
  80887. }
  80888. }
  80889. else
  80890. {
  80891. numRead += n;
  80892. howMany -= n;
  80893. d += n;
  80894. if (howMany <= 0)
  80895. return numRead;
  80896. }
  80897. }
  80898. }
  80899. }
  80900. return 0;
  80901. }
  80902. bool GZIPDecompressorInputStream::isExhausted()
  80903. {
  80904. return helper->error || isEof;
  80905. }
  80906. int64 GZIPDecompressorInputStream::getPosition()
  80907. {
  80908. return currentPos;
  80909. }
  80910. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80911. {
  80912. if (newPos < currentPos)
  80913. {
  80914. // to go backwards, reset the stream and start again..
  80915. isEof = false;
  80916. activeBufferSize = 0;
  80917. currentPos = 0;
  80918. helper = new GZIPDecompressHelper (noWrap);
  80919. sourceStream->setPosition (originalSourcePos);
  80920. }
  80921. skipNextBytes (newPos - currentPos);
  80922. return true;
  80923. }
  80924. END_JUCE_NAMESPACE
  80925. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80926. #endif
  80927. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80928. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80929. #if JUCE_USE_FLAC
  80930. #if JUCE_WINDOWS
  80931. #include <windows.h>
  80932. #endif
  80933. #ifdef _MSC_VER
  80934. #pragma warning (disable : 4505)
  80935. #pragma warning (push)
  80936. #endif
  80937. namespace FlacNamespace
  80938. {
  80939. #if JUCE_INCLUDE_FLAC_CODE
  80940. #define FLAC__NO_DLL 1
  80941. #if ! defined (SIZE_MAX)
  80942. #define SIZE_MAX 0xffffffff
  80943. #endif
  80944. #define __STDC_LIMIT_MACROS 1
  80945. /*** Start of inlined file: all.h ***/
  80946. #ifndef FLAC__ALL_H
  80947. #define FLAC__ALL_H
  80948. /*** Start of inlined file: export.h ***/
  80949. #ifndef FLAC__EXPORT_H
  80950. #define FLAC__EXPORT_H
  80951. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80952. #define FLAC_API
  80953. #else
  80954. #ifdef FLAC_API_EXPORTS
  80955. #define FLAC_API _declspec(dllexport)
  80956. #else
  80957. #define FLAC_API _declspec(dllimport)
  80958. #endif
  80959. #endif
  80960. #define FLAC_API_VERSION_CURRENT 10
  80961. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80962. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80963. #ifdef __cplusplus
  80964. extern "C" {
  80965. #endif
  80966. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80967. #ifdef __cplusplus
  80968. }
  80969. #endif
  80970. #endif
  80971. /*** End of inlined file: export.h ***/
  80972. /*** Start of inlined file: assert.h ***/
  80973. #ifndef FLAC__ASSERT_H
  80974. #define FLAC__ASSERT_H
  80975. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80976. #ifdef DEBUG
  80977. #include <assert.h>
  80978. #define FLAC__ASSERT(x) assert(x)
  80979. #define FLAC__ASSERT_DECLARATION(x) x
  80980. #else
  80981. #define FLAC__ASSERT(x)
  80982. #define FLAC__ASSERT_DECLARATION(x)
  80983. #endif
  80984. #endif
  80985. /*** End of inlined file: assert.h ***/
  80986. /*** Start of inlined file: callback.h ***/
  80987. #ifndef FLAC__CALLBACK_H
  80988. #define FLAC__CALLBACK_H
  80989. /*** Start of inlined file: ordinals.h ***/
  80990. #ifndef FLAC__ORDINALS_H
  80991. #define FLAC__ORDINALS_H
  80992. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80993. #include <inttypes.h>
  80994. #endif
  80995. typedef signed char FLAC__int8;
  80996. typedef unsigned char FLAC__uint8;
  80997. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80998. typedef __int16 FLAC__int16;
  80999. typedef __int32 FLAC__int32;
  81000. typedef __int64 FLAC__int64;
  81001. typedef unsigned __int16 FLAC__uint16;
  81002. typedef unsigned __int32 FLAC__uint32;
  81003. typedef unsigned __int64 FLAC__uint64;
  81004. #elif defined(__EMX__)
  81005. typedef short FLAC__int16;
  81006. typedef long FLAC__int32;
  81007. typedef long long FLAC__int64;
  81008. typedef unsigned short FLAC__uint16;
  81009. typedef unsigned long FLAC__uint32;
  81010. typedef unsigned long long FLAC__uint64;
  81011. #else
  81012. typedef int16_t FLAC__int16;
  81013. typedef int32_t FLAC__int32;
  81014. typedef int64_t FLAC__int64;
  81015. typedef uint16_t FLAC__uint16;
  81016. typedef uint32_t FLAC__uint32;
  81017. typedef uint64_t FLAC__uint64;
  81018. #endif
  81019. typedef int FLAC__bool;
  81020. typedef FLAC__uint8 FLAC__byte;
  81021. #ifdef true
  81022. #undef true
  81023. #endif
  81024. #ifdef false
  81025. #undef false
  81026. #endif
  81027. #ifndef __cplusplus
  81028. #define true 1
  81029. #define false 0
  81030. #endif
  81031. #endif
  81032. /*** End of inlined file: ordinals.h ***/
  81033. #include <stdlib.h> /* for size_t */
  81034. #ifdef __cplusplus
  81035. extern "C" {
  81036. #endif
  81037. typedef void* FLAC__IOHandle;
  81038. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  81039. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  81040. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  81041. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  81042. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  81043. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  81044. typedef struct {
  81045. FLAC__IOCallback_Read read;
  81046. FLAC__IOCallback_Write write;
  81047. FLAC__IOCallback_Seek seek;
  81048. FLAC__IOCallback_Tell tell;
  81049. FLAC__IOCallback_Eof eof;
  81050. FLAC__IOCallback_Close close;
  81051. } FLAC__IOCallbacks;
  81052. #ifdef __cplusplus
  81053. }
  81054. #endif
  81055. #endif
  81056. /*** End of inlined file: callback.h ***/
  81057. /*** Start of inlined file: format.h ***/
  81058. #ifndef FLAC__FORMAT_H
  81059. #define FLAC__FORMAT_H
  81060. #ifdef __cplusplus
  81061. extern "C" {
  81062. #endif
  81063. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  81064. #define FLAC__MIN_BLOCK_SIZE (16u)
  81065. #define FLAC__MAX_BLOCK_SIZE (65535u)
  81066. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  81067. #define FLAC__MAX_CHANNELS (8u)
  81068. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  81069. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  81070. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  81071. #define FLAC__MAX_SAMPLE_RATE (655350u)
  81072. #define FLAC__MAX_LPC_ORDER (32u)
  81073. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  81074. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  81075. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  81076. #define FLAC__MAX_FIXED_ORDER (4u)
  81077. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  81078. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  81079. extern FLAC_API const char *FLAC__VERSION_STRING;
  81080. extern FLAC_API const char *FLAC__VENDOR_STRING;
  81081. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  81082. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  81083. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  81084. #define FLAC__STREAM_SYNC_LENGTH (4u)
  81085. typedef enum {
  81086. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  81087. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  81088. } FLAC__EntropyCodingMethodType;
  81089. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  81090. typedef struct {
  81091. unsigned *parameters;
  81092. unsigned *raw_bits;
  81093. unsigned capacity_by_order;
  81094. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  81095. typedef struct {
  81096. unsigned order;
  81097. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  81098. } FLAC__EntropyCodingMethod_PartitionedRice;
  81099. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  81100. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  81101. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  81102. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  81103. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  81104. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  81105. typedef struct {
  81106. FLAC__EntropyCodingMethodType type;
  81107. union {
  81108. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  81109. } data;
  81110. } FLAC__EntropyCodingMethod;
  81111. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  81112. typedef enum {
  81113. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  81114. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  81115. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  81116. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  81117. } FLAC__SubframeType;
  81118. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  81119. typedef struct {
  81120. FLAC__int32 value; /**< The constant signal value. */
  81121. } FLAC__Subframe_Constant;
  81122. typedef struct {
  81123. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  81124. } FLAC__Subframe_Verbatim;
  81125. typedef struct {
  81126. FLAC__EntropyCodingMethod entropy_coding_method;
  81127. unsigned order;
  81128. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  81129. const FLAC__int32 *residual;
  81130. } FLAC__Subframe_Fixed;
  81131. typedef struct {
  81132. FLAC__EntropyCodingMethod entropy_coding_method;
  81133. unsigned order;
  81134. unsigned qlp_coeff_precision;
  81135. int quantization_level;
  81136. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  81137. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  81138. const FLAC__int32 *residual;
  81139. } FLAC__Subframe_LPC;
  81140. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  81141. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  81142. typedef struct {
  81143. FLAC__SubframeType type;
  81144. union {
  81145. FLAC__Subframe_Constant constant;
  81146. FLAC__Subframe_Fixed fixed;
  81147. FLAC__Subframe_LPC lpc;
  81148. FLAC__Subframe_Verbatim verbatim;
  81149. } data;
  81150. unsigned wasted_bits;
  81151. } FLAC__Subframe;
  81152. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  81153. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  81154. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  81155. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  81156. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  81157. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  81158. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  81159. typedef enum {
  81160. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  81161. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  81162. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  81163. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  81164. } FLAC__ChannelAssignment;
  81165. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  81166. typedef enum {
  81167. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  81168. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  81169. } FLAC__FrameNumberType;
  81170. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  81171. typedef struct {
  81172. unsigned blocksize;
  81173. unsigned sample_rate;
  81174. unsigned channels;
  81175. FLAC__ChannelAssignment channel_assignment;
  81176. unsigned bits_per_sample;
  81177. FLAC__FrameNumberType number_type;
  81178. union {
  81179. FLAC__uint32 frame_number;
  81180. FLAC__uint64 sample_number;
  81181. } number;
  81182. FLAC__uint8 crc;
  81183. } FLAC__FrameHeader;
  81184. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  81185. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  81186. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  81187. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  81188. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  81189. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  81190. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  81191. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  81192. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  81193. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  81194. typedef struct {
  81195. FLAC__uint16 crc;
  81196. } FLAC__FrameFooter;
  81197. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  81198. typedef struct {
  81199. FLAC__FrameHeader header;
  81200. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  81201. FLAC__FrameFooter footer;
  81202. } FLAC__Frame;
  81203. typedef enum {
  81204. FLAC__METADATA_TYPE_STREAMINFO = 0,
  81205. FLAC__METADATA_TYPE_PADDING = 1,
  81206. FLAC__METADATA_TYPE_APPLICATION = 2,
  81207. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  81208. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  81209. FLAC__METADATA_TYPE_CUESHEET = 5,
  81210. FLAC__METADATA_TYPE_PICTURE = 6,
  81211. FLAC__METADATA_TYPE_UNDEFINED = 7
  81212. } FLAC__MetadataType;
  81213. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  81214. typedef struct {
  81215. unsigned min_blocksize, max_blocksize;
  81216. unsigned min_framesize, max_framesize;
  81217. unsigned sample_rate;
  81218. unsigned channels;
  81219. unsigned bits_per_sample;
  81220. FLAC__uint64 total_samples;
  81221. FLAC__byte md5sum[16];
  81222. } FLAC__StreamMetadata_StreamInfo;
  81223. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81224. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81225. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81226. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81227. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  81228. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  81229. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  81230. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  81231. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  81232. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  81233. typedef struct {
  81234. int dummy;
  81235. } FLAC__StreamMetadata_Padding;
  81236. typedef struct {
  81237. FLAC__byte id[4];
  81238. FLAC__byte *data;
  81239. } FLAC__StreamMetadata_Application;
  81240. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  81241. typedef struct {
  81242. FLAC__uint64 sample_number;
  81243. FLAC__uint64 stream_offset;
  81244. unsigned frame_samples;
  81245. } FLAC__StreamMetadata_SeekPoint;
  81246. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  81247. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  81248. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  81249. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  81250. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  81251. typedef struct {
  81252. unsigned num_points;
  81253. FLAC__StreamMetadata_SeekPoint *points;
  81254. } FLAC__StreamMetadata_SeekTable;
  81255. typedef struct {
  81256. FLAC__uint32 length;
  81257. FLAC__byte *entry;
  81258. } FLAC__StreamMetadata_VorbisComment_Entry;
  81259. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  81260. typedef struct {
  81261. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  81262. FLAC__uint32 num_comments;
  81263. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  81264. } FLAC__StreamMetadata_VorbisComment;
  81265. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  81266. typedef struct {
  81267. FLAC__uint64 offset;
  81268. FLAC__byte number;
  81269. } FLAC__StreamMetadata_CueSheet_Index;
  81270. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  81271. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  81272. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  81273. typedef struct {
  81274. FLAC__uint64 offset;
  81275. FLAC__byte number;
  81276. char isrc[13];
  81277. unsigned type:1;
  81278. unsigned pre_emphasis:1;
  81279. FLAC__byte num_indices;
  81280. FLAC__StreamMetadata_CueSheet_Index *indices;
  81281. } FLAC__StreamMetadata_CueSheet_Track;
  81282. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  81283. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  81284. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  81285. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  81286. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  81287. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  81288. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  81289. typedef struct {
  81290. char media_catalog_number[129];
  81291. FLAC__uint64 lead_in;
  81292. FLAC__bool is_cd;
  81293. unsigned num_tracks;
  81294. FLAC__StreamMetadata_CueSheet_Track *tracks;
  81295. } FLAC__StreamMetadata_CueSheet;
  81296. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  81297. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  81298. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  81299. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  81300. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  81301. typedef enum {
  81302. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  81303. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  81304. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  81305. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  81306. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  81307. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  81308. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  81309. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  81310. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  81311. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  81312. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  81313. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  81314. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  81315. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  81316. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  81317. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  81318. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  81319. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  81320. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  81321. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  81322. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  81323. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  81324. } FLAC__StreamMetadata_Picture_Type;
  81325. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  81326. typedef struct {
  81327. FLAC__StreamMetadata_Picture_Type type;
  81328. char *mime_type;
  81329. FLAC__byte *description;
  81330. FLAC__uint32 width;
  81331. FLAC__uint32 height;
  81332. FLAC__uint32 depth;
  81333. FLAC__uint32 colors;
  81334. FLAC__uint32 data_length;
  81335. FLAC__byte *data;
  81336. } FLAC__StreamMetadata_Picture;
  81337. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  81338. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  81339. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  81340. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  81341. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  81342. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  81343. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  81344. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  81345. typedef struct {
  81346. FLAC__byte *data;
  81347. } FLAC__StreamMetadata_Unknown;
  81348. typedef struct {
  81349. FLAC__MetadataType type;
  81350. FLAC__bool is_last;
  81351. unsigned length;
  81352. union {
  81353. FLAC__StreamMetadata_StreamInfo stream_info;
  81354. FLAC__StreamMetadata_Padding padding;
  81355. FLAC__StreamMetadata_Application application;
  81356. FLAC__StreamMetadata_SeekTable seek_table;
  81357. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  81358. FLAC__StreamMetadata_CueSheet cue_sheet;
  81359. FLAC__StreamMetadata_Picture picture;
  81360. FLAC__StreamMetadata_Unknown unknown;
  81361. } data;
  81362. } FLAC__StreamMetadata;
  81363. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  81364. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  81365. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  81366. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  81367. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  81368. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  81369. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  81370. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  81371. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  81372. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  81373. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  81374. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  81375. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  81376. #ifdef __cplusplus
  81377. }
  81378. #endif
  81379. #endif
  81380. /*** End of inlined file: format.h ***/
  81381. /*** Start of inlined file: metadata.h ***/
  81382. #ifndef FLAC__METADATA_H
  81383. #define FLAC__METADATA_H
  81384. #include <sys/types.h> /* for off_t */
  81385. #ifdef __cplusplus
  81386. extern "C" {
  81387. #endif
  81388. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  81389. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  81390. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  81391. 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);
  81392. struct FLAC__Metadata_SimpleIterator;
  81393. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  81394. typedef enum {
  81395. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  81396. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  81397. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  81398. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  81399. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  81400. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  81401. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  81402. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  81403. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  81404. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  81405. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  81406. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  81407. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  81408. } FLAC__Metadata_SimpleIteratorStatus;
  81409. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  81410. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  81411. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  81412. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  81413. 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);
  81414. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  81415. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  81416. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  81417. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  81418. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  81419. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  81420. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  81421. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  81422. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  81423. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81424. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81425. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  81426. struct FLAC__Metadata_Chain;
  81427. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  81428. struct FLAC__Metadata_Iterator;
  81429. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  81430. typedef enum {
  81431. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  81432. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  81433. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  81434. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  81435. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  81436. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  81437. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  81438. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  81439. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  81440. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  81441. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  81442. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  81443. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  81444. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  81445. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  81446. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  81447. } FLAC__Metadata_ChainStatus;
  81448. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  81449. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  81450. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  81451. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  81452. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  81453. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  81454. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81455. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81456. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  81457. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  81458. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81459. 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);
  81460. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  81461. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  81462. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  81463. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  81464. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  81465. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  81466. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  81467. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  81468. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  81469. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81470. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  81471. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81472. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81473. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  81474. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  81475. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  81476. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  81477. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  81478. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  81479. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81480. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81481. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  81482. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  81483. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  81484. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  81485. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  81486. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  81487. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  81488. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  81489. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81490. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  81491. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81492. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81493. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81494. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  81495. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  81496. 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);
  81497. 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);
  81498. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  81499. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  81500. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  81501. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  81502. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  81503. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  81504. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  81505. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  81506. 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);
  81507. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81508. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81509. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  81510. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81511. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81512. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  81513. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  81514. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  81515. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  81516. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  81517. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  81518. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  81519. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  81520. #ifdef __cplusplus
  81521. }
  81522. #endif
  81523. #endif
  81524. /*** End of inlined file: metadata.h ***/
  81525. /*** Start of inlined file: stream_decoder.h ***/
  81526. #ifndef FLAC__STREAM_DECODER_H
  81527. #define FLAC__STREAM_DECODER_H
  81528. #include <stdio.h> /* for FILE */
  81529. #ifdef __cplusplus
  81530. extern "C" {
  81531. #endif
  81532. typedef enum {
  81533. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  81534. FLAC__STREAM_DECODER_READ_METADATA,
  81535. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  81536. FLAC__STREAM_DECODER_READ_FRAME,
  81537. FLAC__STREAM_DECODER_END_OF_STREAM,
  81538. FLAC__STREAM_DECODER_OGG_ERROR,
  81539. FLAC__STREAM_DECODER_SEEK_ERROR,
  81540. FLAC__STREAM_DECODER_ABORTED,
  81541. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81542. FLAC__STREAM_DECODER_UNINITIALIZED
  81543. } FLAC__StreamDecoderState;
  81544. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81545. typedef enum {
  81546. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81547. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81548. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81549. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81550. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81551. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81552. } FLAC__StreamDecoderInitStatus;
  81553. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81554. typedef enum {
  81555. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81556. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81557. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81558. } FLAC__StreamDecoderReadStatus;
  81559. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81560. typedef enum {
  81561. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81562. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81563. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81564. } FLAC__StreamDecoderSeekStatus;
  81565. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81566. typedef enum {
  81567. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81568. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81569. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81570. } FLAC__StreamDecoderTellStatus;
  81571. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81572. typedef enum {
  81573. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81574. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81575. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81576. } FLAC__StreamDecoderLengthStatus;
  81577. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81578. typedef enum {
  81579. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81580. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81581. } FLAC__StreamDecoderWriteStatus;
  81582. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81583. typedef enum {
  81584. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81585. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81586. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81587. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81588. } FLAC__StreamDecoderErrorStatus;
  81589. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81590. struct FLAC__StreamDecoderProtected;
  81591. struct FLAC__StreamDecoderPrivate;
  81592. typedef struct {
  81593. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81594. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81595. } FLAC__StreamDecoder;
  81596. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81597. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81598. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81599. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81600. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81601. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81602. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81603. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81604. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81605. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81606. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81607. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81608. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81609. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81610. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81611. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81612. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81613. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81614. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81615. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81616. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81617. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81618. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81619. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81620. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81621. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81622. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81623. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81624. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81625. FLAC__StreamDecoder *decoder,
  81626. FLAC__StreamDecoderReadCallback read_callback,
  81627. FLAC__StreamDecoderSeekCallback seek_callback,
  81628. FLAC__StreamDecoderTellCallback tell_callback,
  81629. FLAC__StreamDecoderLengthCallback length_callback,
  81630. FLAC__StreamDecoderEofCallback eof_callback,
  81631. FLAC__StreamDecoderWriteCallback write_callback,
  81632. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81633. FLAC__StreamDecoderErrorCallback error_callback,
  81634. void *client_data
  81635. );
  81636. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81637. FLAC__StreamDecoder *decoder,
  81638. FLAC__StreamDecoderReadCallback read_callback,
  81639. FLAC__StreamDecoderSeekCallback seek_callback,
  81640. FLAC__StreamDecoderTellCallback tell_callback,
  81641. FLAC__StreamDecoderLengthCallback length_callback,
  81642. FLAC__StreamDecoderEofCallback eof_callback,
  81643. FLAC__StreamDecoderWriteCallback write_callback,
  81644. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81645. FLAC__StreamDecoderErrorCallback error_callback,
  81646. void *client_data
  81647. );
  81648. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81649. FLAC__StreamDecoder *decoder,
  81650. FILE *file,
  81651. FLAC__StreamDecoderWriteCallback write_callback,
  81652. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81653. FLAC__StreamDecoderErrorCallback error_callback,
  81654. void *client_data
  81655. );
  81656. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81657. FLAC__StreamDecoder *decoder,
  81658. FILE *file,
  81659. FLAC__StreamDecoderWriteCallback write_callback,
  81660. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81661. FLAC__StreamDecoderErrorCallback error_callback,
  81662. void *client_data
  81663. );
  81664. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81665. FLAC__StreamDecoder *decoder,
  81666. const char *filename,
  81667. FLAC__StreamDecoderWriteCallback write_callback,
  81668. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81669. FLAC__StreamDecoderErrorCallback error_callback,
  81670. void *client_data
  81671. );
  81672. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81673. FLAC__StreamDecoder *decoder,
  81674. const char *filename,
  81675. FLAC__StreamDecoderWriteCallback write_callback,
  81676. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81677. FLAC__StreamDecoderErrorCallback error_callback,
  81678. void *client_data
  81679. );
  81680. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81681. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81682. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81683. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81684. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81685. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81686. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81687. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81688. #ifdef __cplusplus
  81689. }
  81690. #endif
  81691. #endif
  81692. /*** End of inlined file: stream_decoder.h ***/
  81693. /*** Start of inlined file: stream_encoder.h ***/
  81694. #ifndef FLAC__STREAM_ENCODER_H
  81695. #define FLAC__STREAM_ENCODER_H
  81696. #include <stdio.h> /* for FILE */
  81697. #ifdef __cplusplus
  81698. extern "C" {
  81699. #endif
  81700. typedef enum {
  81701. FLAC__STREAM_ENCODER_OK = 0,
  81702. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81703. FLAC__STREAM_ENCODER_OGG_ERROR,
  81704. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81705. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81706. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81707. FLAC__STREAM_ENCODER_IO_ERROR,
  81708. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81709. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81710. } FLAC__StreamEncoderState;
  81711. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81712. typedef enum {
  81713. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81714. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81715. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81716. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81717. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81718. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81719. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81720. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81721. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81722. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81723. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81724. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81725. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81726. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81727. } FLAC__StreamEncoderInitStatus;
  81728. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81729. typedef enum {
  81730. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81731. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81732. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81733. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81734. } FLAC__StreamEncoderReadStatus;
  81735. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81736. typedef enum {
  81737. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81738. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81739. } FLAC__StreamEncoderWriteStatus;
  81740. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81741. typedef enum {
  81742. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81743. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81744. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81745. } FLAC__StreamEncoderSeekStatus;
  81746. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81747. typedef enum {
  81748. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81749. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81750. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81751. } FLAC__StreamEncoderTellStatus;
  81752. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81753. struct FLAC__StreamEncoderProtected;
  81754. struct FLAC__StreamEncoderPrivate;
  81755. typedef struct {
  81756. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81757. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81758. } FLAC__StreamEncoder;
  81759. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81760. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81761. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81762. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81763. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81764. 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);
  81765. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81766. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81767. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81768. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81769. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81770. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81771. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81772. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81773. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81774. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81775. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81776. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81777. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81778. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81779. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81780. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81781. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81782. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81783. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81784. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81785. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81786. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81787. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81788. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81789. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81790. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81791. 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);
  81792. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81793. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81794. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81795. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81796. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81797. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81798. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81799. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81800. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81801. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81802. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81803. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81804. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81805. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81806. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81807. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81808. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81809. 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);
  81810. 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);
  81811. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81812. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81813. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81814. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81815. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81816. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81817. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81818. #ifdef __cplusplus
  81819. }
  81820. #endif
  81821. #endif
  81822. /*** End of inlined file: stream_encoder.h ***/
  81823. #ifdef _MSC_VER
  81824. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81825. {
  81826. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81827. return (x>>16) | (x<<16);
  81828. }
  81829. #endif
  81830. #if defined(_MSC_VER) && defined(_X86_)
  81831. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81832. {
  81833. __asm {
  81834. mov edx, start
  81835. mov ecx, len
  81836. test ecx, ecx
  81837. loop1:
  81838. jz done1
  81839. mov eax, [edx]
  81840. bswap eax
  81841. mov [edx], eax
  81842. add edx, 4
  81843. dec ecx
  81844. jmp short loop1
  81845. done1:
  81846. }
  81847. }
  81848. #endif
  81849. #endif
  81850. /*** End of inlined file: all.h ***/
  81851. /*** Start of inlined file: bitmath.c ***/
  81852. /*** Start of inlined file: juce_FlacHeader.h ***/
  81853. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81854. // tasks..
  81855. #define VERSION "1.2.1"
  81856. #define FLAC__NO_DLL 1
  81857. #if JUCE_MSVC
  81858. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81859. #endif
  81860. #if JUCE_MAC
  81861. #define FLAC__SYS_DARWIN 1
  81862. #endif
  81863. /*** End of inlined file: juce_FlacHeader.h ***/
  81864. #if JUCE_USE_FLAC
  81865. #if HAVE_CONFIG_H
  81866. # include <config.h>
  81867. #endif
  81868. /*** Start of inlined file: bitmath.h ***/
  81869. #ifndef FLAC__PRIVATE__BITMATH_H
  81870. #define FLAC__PRIVATE__BITMATH_H
  81871. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81872. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81873. unsigned FLAC__bitmath_silog2(int v);
  81874. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81875. #endif
  81876. /*** End of inlined file: bitmath.h ***/
  81877. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81878. {
  81879. unsigned l = 0;
  81880. FLAC__ASSERT(v > 0);
  81881. while(v >>= 1)
  81882. l++;
  81883. return l;
  81884. }
  81885. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81886. {
  81887. unsigned l = 0;
  81888. FLAC__ASSERT(v > 0);
  81889. while(v >>= 1)
  81890. l++;
  81891. return l;
  81892. }
  81893. unsigned FLAC__bitmath_silog2(int v)
  81894. {
  81895. while(1) {
  81896. if(v == 0) {
  81897. return 0;
  81898. }
  81899. else if(v > 0) {
  81900. unsigned l = 0;
  81901. while(v) {
  81902. l++;
  81903. v >>= 1;
  81904. }
  81905. return l+1;
  81906. }
  81907. else if(v == -1) {
  81908. return 2;
  81909. }
  81910. else {
  81911. v++;
  81912. v = -v;
  81913. }
  81914. }
  81915. }
  81916. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81917. {
  81918. while(1) {
  81919. if(v == 0) {
  81920. return 0;
  81921. }
  81922. else if(v > 0) {
  81923. unsigned l = 0;
  81924. while(v) {
  81925. l++;
  81926. v >>= 1;
  81927. }
  81928. return l+1;
  81929. }
  81930. else if(v == -1) {
  81931. return 2;
  81932. }
  81933. else {
  81934. v++;
  81935. v = -v;
  81936. }
  81937. }
  81938. }
  81939. #endif
  81940. /*** End of inlined file: bitmath.c ***/
  81941. /*** Start of inlined file: bitreader.c ***/
  81942. /*** Start of inlined file: juce_FlacHeader.h ***/
  81943. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81944. // tasks..
  81945. #define VERSION "1.2.1"
  81946. #define FLAC__NO_DLL 1
  81947. #if JUCE_MSVC
  81948. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81949. #endif
  81950. #if JUCE_MAC
  81951. #define FLAC__SYS_DARWIN 1
  81952. #endif
  81953. /*** End of inlined file: juce_FlacHeader.h ***/
  81954. #if JUCE_USE_FLAC
  81955. #if HAVE_CONFIG_H
  81956. # include <config.h>
  81957. #endif
  81958. #include <stdlib.h> /* for malloc() */
  81959. #include <string.h> /* for memcpy(), memset() */
  81960. #ifdef _MSC_VER
  81961. #include <winsock.h> /* for ntohl() */
  81962. #elif defined FLAC__SYS_DARWIN
  81963. #include <machine/endian.h> /* for ntohl() */
  81964. #elif defined __MINGW32__
  81965. #include <winsock.h> /* for ntohl() */
  81966. #else
  81967. #include <netinet/in.h> /* for ntohl() */
  81968. #endif
  81969. /*** Start of inlined file: bitreader.h ***/
  81970. #ifndef FLAC__PRIVATE__BITREADER_H
  81971. #define FLAC__PRIVATE__BITREADER_H
  81972. #include <stdio.h> /* for FILE */
  81973. /*** Start of inlined file: cpu.h ***/
  81974. #ifndef FLAC__PRIVATE__CPU_H
  81975. #define FLAC__PRIVATE__CPU_H
  81976. #ifdef HAVE_CONFIG_H
  81977. #include <config.h>
  81978. #endif
  81979. typedef enum {
  81980. FLAC__CPUINFO_TYPE_IA32,
  81981. FLAC__CPUINFO_TYPE_PPC,
  81982. FLAC__CPUINFO_TYPE_UNKNOWN
  81983. } FLAC__CPUInfo_Type;
  81984. typedef struct {
  81985. FLAC__bool cpuid;
  81986. FLAC__bool bswap;
  81987. FLAC__bool cmov;
  81988. FLAC__bool mmx;
  81989. FLAC__bool fxsr;
  81990. FLAC__bool sse;
  81991. FLAC__bool sse2;
  81992. FLAC__bool sse3;
  81993. FLAC__bool ssse3;
  81994. FLAC__bool _3dnow;
  81995. FLAC__bool ext3dnow;
  81996. FLAC__bool extmmx;
  81997. } FLAC__CPUInfo_IA32;
  81998. typedef struct {
  81999. FLAC__bool altivec;
  82000. FLAC__bool ppc64;
  82001. } FLAC__CPUInfo_PPC;
  82002. typedef struct {
  82003. FLAC__bool use_asm;
  82004. FLAC__CPUInfo_Type type;
  82005. union {
  82006. FLAC__CPUInfo_IA32 ia32;
  82007. FLAC__CPUInfo_PPC ppc;
  82008. } data;
  82009. } FLAC__CPUInfo;
  82010. void FLAC__cpu_info(FLAC__CPUInfo *info);
  82011. #ifndef FLAC__NO_ASM
  82012. #ifdef FLAC__CPU_IA32
  82013. #ifdef FLAC__HAS_NASM
  82014. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  82015. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  82016. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  82017. #endif
  82018. #endif
  82019. #endif
  82020. #endif
  82021. /*** End of inlined file: cpu.h ***/
  82022. struct FLAC__BitReader;
  82023. typedef struct FLAC__BitReader FLAC__BitReader;
  82024. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  82025. FLAC__BitReader *FLAC__bitreader_new(void);
  82026. void FLAC__bitreader_delete(FLAC__BitReader *br);
  82027. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  82028. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  82029. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  82030. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  82031. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  82032. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  82033. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  82034. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  82035. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  82036. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  82037. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  82038. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  82039. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  82040. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  82041. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  82042. 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! */
  82043. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  82044. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  82045. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  82046. #ifndef FLAC__NO_ASM
  82047. # ifdef FLAC__CPU_IA32
  82048. # ifdef FLAC__HAS_NASM
  82049. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  82050. # endif
  82051. # endif
  82052. #endif
  82053. #if 0 /* UNUSED */
  82054. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  82055. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  82056. #endif
  82057. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  82058. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  82059. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  82060. #endif
  82061. /*** End of inlined file: bitreader.h ***/
  82062. /*** Start of inlined file: crc.h ***/
  82063. #ifndef FLAC__PRIVATE__CRC_H
  82064. #define FLAC__PRIVATE__CRC_H
  82065. extern FLAC__byte const FLAC__crc8_table[256];
  82066. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  82067. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  82068. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  82069. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  82070. extern unsigned FLAC__crc16_table[256];
  82071. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  82072. #if 0
  82073. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  82074. #endif
  82075. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  82076. #endif
  82077. /*** End of inlined file: crc.h ***/
  82078. typedef FLAC__uint32 brword;
  82079. #define FLAC__BYTES_PER_WORD 4
  82080. #define FLAC__BITS_PER_WORD 32
  82081. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82082. #if WORDS_BIGENDIAN
  82083. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82084. #else
  82085. #if defined (_MSC_VER) && defined (_X86_)
  82086. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82087. #else
  82088. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82089. #endif
  82090. #endif
  82091. #define COUNT_ZERO_MSBS(word) ( \
  82092. (word) <= 0xffff ? \
  82093. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  82094. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  82095. )
  82096. #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])) )
  82097. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  82098. static const unsigned char byte_to_unary_table[] = {
  82099. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  82100. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  82101. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  82102. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  82103. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82104. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82105. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82106. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  82115. };
  82116. #ifdef min
  82117. #undef min
  82118. #endif
  82119. #define min(x,y) ((x)<(y)?(x):(y))
  82120. #ifdef max
  82121. #undef max
  82122. #endif
  82123. #define max(x,y) ((x)>(y)?(x):(y))
  82124. #ifdef _MSC_VER
  82125. #define FLAC__U64L(x) x
  82126. #else
  82127. #define FLAC__U64L(x) x##LLU
  82128. #endif
  82129. #ifndef FLaC__INLINE
  82130. #define FLaC__INLINE
  82131. #endif
  82132. struct FLAC__BitReader {
  82133. brword *buffer;
  82134. unsigned capacity; /* in words */
  82135. unsigned words; /* # of completed words in buffer */
  82136. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  82137. unsigned consumed_words; /* #words ... */
  82138. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  82139. unsigned read_crc16; /* the running frame CRC */
  82140. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  82141. FLAC__BitReaderReadCallback read_callback;
  82142. void *client_data;
  82143. FLAC__CPUInfo cpu_info;
  82144. };
  82145. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  82146. {
  82147. register unsigned crc = br->read_crc16;
  82148. #if FLAC__BYTES_PER_WORD == 4
  82149. switch(br->crc16_align) {
  82150. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  82151. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82152. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82153. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82154. }
  82155. #elif FLAC__BYTES_PER_WORD == 8
  82156. switch(br->crc16_align) {
  82157. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  82158. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  82159. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  82160. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  82161. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  82162. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82163. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82164. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82165. }
  82166. #else
  82167. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  82168. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  82169. br->read_crc16 = crc;
  82170. #endif
  82171. br->crc16_align = 0;
  82172. }
  82173. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  82174. {
  82175. unsigned start, end;
  82176. size_t bytes;
  82177. FLAC__byte *target;
  82178. if(br->consumed_words > 0) {
  82179. start = br->consumed_words;
  82180. end = br->words + (br->bytes? 1:0);
  82181. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  82182. br->words -= start;
  82183. br->consumed_words = 0;
  82184. }
  82185. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  82186. if(bytes == 0)
  82187. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  82188. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  82189. #if WORDS_BIGENDIAN
  82190. #else
  82191. if(br->bytes)
  82192. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  82193. #endif
  82194. if(!br->read_callback(target, &bytes, br->client_data))
  82195. return false;
  82196. #if WORDS_BIGENDIAN
  82197. #else
  82198. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  82199. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  82200. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  82201. start = br->words;
  82202. local_swap32_block_(br->buffer + start, end - start);
  82203. }
  82204. else
  82205. # endif
  82206. for(start = br->words; start < end; start++)
  82207. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  82208. #endif
  82209. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  82210. br->words = end / FLAC__BYTES_PER_WORD;
  82211. br->bytes = end % FLAC__BYTES_PER_WORD;
  82212. return true;
  82213. }
  82214. FLAC__BitReader *FLAC__bitreader_new(void)
  82215. {
  82216. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  82217. return br;
  82218. }
  82219. void FLAC__bitreader_delete(FLAC__BitReader *br)
  82220. {
  82221. FLAC__ASSERT(0 != br);
  82222. FLAC__bitreader_free(br);
  82223. free(br);
  82224. }
  82225. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  82226. {
  82227. FLAC__ASSERT(0 != br);
  82228. br->words = br->bytes = 0;
  82229. br->consumed_words = br->consumed_bits = 0;
  82230. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  82231. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  82232. if(br->buffer == 0)
  82233. return false;
  82234. br->read_callback = rcb;
  82235. br->client_data = cd;
  82236. br->cpu_info = cpu;
  82237. return true;
  82238. }
  82239. void FLAC__bitreader_free(FLAC__BitReader *br)
  82240. {
  82241. FLAC__ASSERT(0 != br);
  82242. if(0 != br->buffer)
  82243. free(br->buffer);
  82244. br->buffer = 0;
  82245. br->capacity = 0;
  82246. br->words = br->bytes = 0;
  82247. br->consumed_words = br->consumed_bits = 0;
  82248. br->read_callback = 0;
  82249. br->client_data = 0;
  82250. }
  82251. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  82252. {
  82253. br->words = br->bytes = 0;
  82254. br->consumed_words = br->consumed_bits = 0;
  82255. return true;
  82256. }
  82257. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  82258. {
  82259. unsigned i, j;
  82260. if(br == 0) {
  82261. fprintf(out, "bitreader is NULL\n");
  82262. }
  82263. else {
  82264. 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);
  82265. for(i = 0; i < br->words; i++) {
  82266. fprintf(out, "%08X: ", i);
  82267. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82268. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82269. fprintf(out, ".");
  82270. else
  82271. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82272. fprintf(out, "\n");
  82273. }
  82274. if(br->bytes > 0) {
  82275. fprintf(out, "%08X: ", i);
  82276. for(j = 0; j < br->bytes*8; j++)
  82277. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82278. fprintf(out, ".");
  82279. else
  82280. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  82281. fprintf(out, "\n");
  82282. }
  82283. }
  82284. }
  82285. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  82286. {
  82287. FLAC__ASSERT(0 != br);
  82288. FLAC__ASSERT(0 != br->buffer);
  82289. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82290. br->read_crc16 = (unsigned)seed;
  82291. br->crc16_align = br->consumed_bits;
  82292. }
  82293. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  82294. {
  82295. FLAC__ASSERT(0 != br);
  82296. FLAC__ASSERT(0 != br->buffer);
  82297. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82298. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  82299. if(br->consumed_bits) {
  82300. const brword tail = br->buffer[br->consumed_words];
  82301. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  82302. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  82303. }
  82304. return br->read_crc16;
  82305. }
  82306. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  82307. {
  82308. return ((br->consumed_bits & 7) == 0);
  82309. }
  82310. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  82311. {
  82312. return 8 - (br->consumed_bits & 7);
  82313. }
  82314. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  82315. {
  82316. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  82317. }
  82318. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  82319. {
  82320. FLAC__ASSERT(0 != br);
  82321. FLAC__ASSERT(0 != br->buffer);
  82322. FLAC__ASSERT(bits <= 32);
  82323. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  82324. FLAC__ASSERT(br->consumed_words <= br->words);
  82325. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82326. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  82327. *val = 0;
  82328. return true;
  82329. }
  82330. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  82331. if(!bitreader_read_from_client_(br))
  82332. return false;
  82333. }
  82334. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82335. if(br->consumed_bits) {
  82336. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  82337. const brword word = br->buffer[br->consumed_words];
  82338. if(bits < n) {
  82339. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  82340. br->consumed_bits += bits;
  82341. return true;
  82342. }
  82343. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  82344. bits -= n;
  82345. crc16_update_word_(br, word);
  82346. br->consumed_words++;
  82347. br->consumed_bits = 0;
  82348. 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 */
  82349. *val <<= bits;
  82350. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  82351. br->consumed_bits = bits;
  82352. }
  82353. return true;
  82354. }
  82355. else {
  82356. const brword word = br->buffer[br->consumed_words];
  82357. if(bits < FLAC__BITS_PER_WORD) {
  82358. *val = word >> (FLAC__BITS_PER_WORD-bits);
  82359. br->consumed_bits = bits;
  82360. return true;
  82361. }
  82362. *val = word;
  82363. crc16_update_word_(br, word);
  82364. br->consumed_words++;
  82365. return true;
  82366. }
  82367. }
  82368. else {
  82369. if(br->consumed_bits) {
  82370. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  82371. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  82372. br->consumed_bits += bits;
  82373. return true;
  82374. }
  82375. else {
  82376. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  82377. br->consumed_bits += bits;
  82378. return true;
  82379. }
  82380. }
  82381. }
  82382. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  82383. {
  82384. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  82385. return false;
  82386. *val <<= (32-bits);
  82387. *val >>= (32-bits);
  82388. return true;
  82389. }
  82390. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  82391. {
  82392. FLAC__uint32 hi, lo;
  82393. if(bits > 32) {
  82394. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  82395. return false;
  82396. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  82397. return false;
  82398. *val = hi;
  82399. *val <<= 32;
  82400. *val |= lo;
  82401. }
  82402. else {
  82403. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  82404. return false;
  82405. *val = lo;
  82406. }
  82407. return true;
  82408. }
  82409. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  82410. {
  82411. FLAC__uint32 x8, x32 = 0;
  82412. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  82413. return false;
  82414. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82415. return false;
  82416. x32 |= (x8 << 8);
  82417. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82418. return false;
  82419. x32 |= (x8 << 16);
  82420. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82421. return false;
  82422. x32 |= (x8 << 24);
  82423. *val = x32;
  82424. return true;
  82425. }
  82426. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  82427. {
  82428. FLAC__ASSERT(0 != br);
  82429. FLAC__ASSERT(0 != br->buffer);
  82430. if(bits > 0) {
  82431. const unsigned n = br->consumed_bits & 7;
  82432. unsigned m;
  82433. FLAC__uint32 x;
  82434. if(n != 0) {
  82435. m = min(8-n, bits);
  82436. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  82437. return false;
  82438. bits -= m;
  82439. }
  82440. m = bits / 8;
  82441. if(m > 0) {
  82442. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  82443. return false;
  82444. bits %= 8;
  82445. }
  82446. if(bits > 0) {
  82447. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  82448. return false;
  82449. }
  82450. }
  82451. return true;
  82452. }
  82453. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  82454. {
  82455. FLAC__uint32 x;
  82456. FLAC__ASSERT(0 != br);
  82457. FLAC__ASSERT(0 != br->buffer);
  82458. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82459. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82460. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82461. return false;
  82462. nvals--;
  82463. }
  82464. if(0 == nvals)
  82465. return true;
  82466. while(nvals >= FLAC__BYTES_PER_WORD) {
  82467. if(br->consumed_words < br->words) {
  82468. br->consumed_words++;
  82469. nvals -= FLAC__BYTES_PER_WORD;
  82470. }
  82471. else if(!bitreader_read_from_client_(br))
  82472. return false;
  82473. }
  82474. while(nvals) {
  82475. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82476. return false;
  82477. nvals--;
  82478. }
  82479. return true;
  82480. }
  82481. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  82482. {
  82483. FLAC__uint32 x;
  82484. FLAC__ASSERT(0 != br);
  82485. FLAC__ASSERT(0 != br->buffer);
  82486. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82487. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82488. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82489. return false;
  82490. *val++ = (FLAC__byte)x;
  82491. nvals--;
  82492. }
  82493. if(0 == nvals)
  82494. return true;
  82495. while(nvals >= FLAC__BYTES_PER_WORD) {
  82496. if(br->consumed_words < br->words) {
  82497. const brword word = br->buffer[br->consumed_words++];
  82498. #if FLAC__BYTES_PER_WORD == 4
  82499. val[0] = (FLAC__byte)(word >> 24);
  82500. val[1] = (FLAC__byte)(word >> 16);
  82501. val[2] = (FLAC__byte)(word >> 8);
  82502. val[3] = (FLAC__byte)word;
  82503. #elif FLAC__BYTES_PER_WORD == 8
  82504. val[0] = (FLAC__byte)(word >> 56);
  82505. val[1] = (FLAC__byte)(word >> 48);
  82506. val[2] = (FLAC__byte)(word >> 40);
  82507. val[3] = (FLAC__byte)(word >> 32);
  82508. val[4] = (FLAC__byte)(word >> 24);
  82509. val[5] = (FLAC__byte)(word >> 16);
  82510. val[6] = (FLAC__byte)(word >> 8);
  82511. val[7] = (FLAC__byte)word;
  82512. #else
  82513. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  82514. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  82515. #endif
  82516. val += FLAC__BYTES_PER_WORD;
  82517. nvals -= FLAC__BYTES_PER_WORD;
  82518. }
  82519. else if(!bitreader_read_from_client_(br))
  82520. return false;
  82521. }
  82522. while(nvals) {
  82523. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82524. return false;
  82525. *val++ = (FLAC__byte)x;
  82526. nvals--;
  82527. }
  82528. return true;
  82529. }
  82530. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  82531. #if 0 /* slow but readable version */
  82532. {
  82533. unsigned bit;
  82534. FLAC__ASSERT(0 != br);
  82535. FLAC__ASSERT(0 != br->buffer);
  82536. *val = 0;
  82537. while(1) {
  82538. if(!FLAC__bitreader_read_bit(br, &bit))
  82539. return false;
  82540. if(bit)
  82541. break;
  82542. else
  82543. *val++;
  82544. }
  82545. return true;
  82546. }
  82547. #else
  82548. {
  82549. unsigned i;
  82550. FLAC__ASSERT(0 != br);
  82551. FLAC__ASSERT(0 != br->buffer);
  82552. *val = 0;
  82553. while(1) {
  82554. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82555. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82556. if(b) {
  82557. i = COUNT_ZERO_MSBS(b);
  82558. *val += i;
  82559. i++;
  82560. br->consumed_bits += i;
  82561. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82562. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82563. br->consumed_words++;
  82564. br->consumed_bits = 0;
  82565. }
  82566. return true;
  82567. }
  82568. else {
  82569. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82570. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82571. br->consumed_words++;
  82572. br->consumed_bits = 0;
  82573. }
  82574. }
  82575. if(br->bytes) {
  82576. const unsigned end = br->bytes * 8;
  82577. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82578. if(b) {
  82579. i = COUNT_ZERO_MSBS(b);
  82580. *val += i;
  82581. i++;
  82582. br->consumed_bits += i;
  82583. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82584. return true;
  82585. }
  82586. else {
  82587. *val += end - br->consumed_bits;
  82588. br->consumed_bits += end;
  82589. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82590. }
  82591. }
  82592. if(!bitreader_read_from_client_(br))
  82593. return false;
  82594. }
  82595. }
  82596. #endif
  82597. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82598. {
  82599. FLAC__uint32 lsbs = 0, msbs = 0;
  82600. unsigned uval;
  82601. FLAC__ASSERT(0 != br);
  82602. FLAC__ASSERT(0 != br->buffer);
  82603. FLAC__ASSERT(parameter <= 31);
  82604. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82605. return false;
  82606. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82607. return false;
  82608. uval = (msbs << parameter) | lsbs;
  82609. if(uval & 1)
  82610. *val = -((int)(uval >> 1)) - 1;
  82611. else
  82612. *val = (int)(uval >> 1);
  82613. return true;
  82614. }
  82615. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82616. #ifdef _MSC_VER
  82617. {
  82618. unsigned i;
  82619. unsigned uval = 0;
  82620. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82621. register unsigned cwords;
  82622. register unsigned cbits;
  82623. FLAC__ASSERT(0 != br);
  82624. FLAC__ASSERT(0 != br->buffer);
  82625. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82626. FLAC__ASSERT(parameter < 32);
  82627. if(nvals == 0)
  82628. return true;
  82629. cbits = br->consumed_bits;
  82630. cwords = br->consumed_words;
  82631. while(1) {
  82632. while(1) {
  82633. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82634. brword b = br->buffer[cwords] << cbits;
  82635. if(b) {
  82636. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82637. __asm {
  82638. bsr eax, b
  82639. not eax
  82640. and eax, 31
  82641. mov i, eax
  82642. }
  82643. #else
  82644. i = COUNT_ZERO_MSBS(b);
  82645. #endif
  82646. uval += i;
  82647. bits = parameter;
  82648. i++;
  82649. cbits += i;
  82650. if(cbits == FLAC__BITS_PER_WORD) {
  82651. crc16_update_word_(br, br->buffer[cwords]);
  82652. cwords++;
  82653. cbits = 0;
  82654. }
  82655. goto break1;
  82656. }
  82657. else {
  82658. uval += FLAC__BITS_PER_WORD - cbits;
  82659. crc16_update_word_(br, br->buffer[cwords]);
  82660. cwords++;
  82661. cbits = 0;
  82662. }
  82663. }
  82664. if(br->bytes) {
  82665. const unsigned end = br->bytes * 8;
  82666. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82667. if(b) {
  82668. i = COUNT_ZERO_MSBS(b);
  82669. uval += i;
  82670. bits = parameter;
  82671. i++;
  82672. cbits += i;
  82673. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82674. goto break1;
  82675. }
  82676. else {
  82677. uval += end - cbits;
  82678. cbits += end;
  82679. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82680. }
  82681. }
  82682. br->consumed_bits = cbits;
  82683. br->consumed_words = cwords;
  82684. if(!bitreader_read_from_client_(br))
  82685. return false;
  82686. cwords = br->consumed_words;
  82687. }
  82688. break1:
  82689. FLAC__ASSERT(cwords <= br->words);
  82690. if(bits) {
  82691. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82692. br->consumed_bits = cbits;
  82693. br->consumed_words = cwords;
  82694. if(!bitreader_read_from_client_(br))
  82695. return false;
  82696. cwords = br->consumed_words;
  82697. }
  82698. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82699. if(cbits) {
  82700. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82701. const brword word = br->buffer[cwords];
  82702. if(bits < n) {
  82703. uval <<= bits;
  82704. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82705. cbits += bits;
  82706. goto break2;
  82707. }
  82708. uval <<= n;
  82709. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82710. bits -= n;
  82711. crc16_update_word_(br, word);
  82712. cwords++;
  82713. cbits = 0;
  82714. 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 */
  82715. uval <<= bits;
  82716. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82717. cbits = bits;
  82718. }
  82719. goto break2;
  82720. }
  82721. else {
  82722. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82723. uval <<= bits;
  82724. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82725. cbits = bits;
  82726. goto break2;
  82727. }
  82728. }
  82729. else {
  82730. uval <<= bits;
  82731. if(cbits) {
  82732. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82733. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82734. cbits += bits;
  82735. goto break2;
  82736. }
  82737. else {
  82738. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82739. cbits += bits;
  82740. goto break2;
  82741. }
  82742. }
  82743. }
  82744. break2:
  82745. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82746. --nvals;
  82747. if(nvals == 0) {
  82748. br->consumed_bits = cbits;
  82749. br->consumed_words = cwords;
  82750. return true;
  82751. }
  82752. uval = 0;
  82753. ++vals;
  82754. }
  82755. }
  82756. #else
  82757. {
  82758. unsigned i;
  82759. unsigned uval = 0;
  82760. register unsigned cwords;
  82761. register unsigned cbits;
  82762. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82763. FLAC__ASSERT(0 != br);
  82764. FLAC__ASSERT(0 != br->buffer);
  82765. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82766. FLAC__ASSERT(parameter < 32);
  82767. if(nvals == 0)
  82768. return true;
  82769. cbits = br->consumed_bits;
  82770. cwords = br->consumed_words;
  82771. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82772. while(1) {
  82773. while(1) {
  82774. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82775. brword b = br->buffer[cwords] << cbits;
  82776. if(b) {
  82777. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82778. asm volatile (
  82779. "bsrl %1, %0;"
  82780. "notl %0;"
  82781. "andl $31, %0;"
  82782. : "=r"(i)
  82783. : "r"(b)
  82784. );
  82785. #else
  82786. i = COUNT_ZERO_MSBS(b);
  82787. #endif
  82788. uval += i;
  82789. cbits += i;
  82790. cbits++; /* skip over stop bit */
  82791. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82792. crc16_update_word_(br, br->buffer[cwords]);
  82793. cwords++;
  82794. cbits = 0;
  82795. }
  82796. goto break1;
  82797. }
  82798. else {
  82799. uval += FLAC__BITS_PER_WORD - cbits;
  82800. crc16_update_word_(br, br->buffer[cwords]);
  82801. cwords++;
  82802. cbits = 0;
  82803. }
  82804. }
  82805. if(br->bytes) {
  82806. const unsigned end = br->bytes * 8;
  82807. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82808. if(b) {
  82809. i = COUNT_ZERO_MSBS(b);
  82810. uval += i;
  82811. cbits += i;
  82812. cbits++; /* skip over stop bit */
  82813. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82814. goto break1;
  82815. }
  82816. else {
  82817. uval += end - cbits;
  82818. cbits += end;
  82819. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82820. }
  82821. }
  82822. br->consumed_bits = cbits;
  82823. br->consumed_words = cwords;
  82824. if(!bitreader_read_from_client_(br))
  82825. return false;
  82826. cwords = br->consumed_words;
  82827. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82828. }
  82829. break1:
  82830. ucbits -= uval;
  82831. ucbits--; /* account for stop bit */
  82832. FLAC__ASSERT(cwords <= br->words);
  82833. if(parameter) {
  82834. while(ucbits < parameter) {
  82835. br->consumed_bits = cbits;
  82836. br->consumed_words = cwords;
  82837. if(!bitreader_read_from_client_(br))
  82838. return false;
  82839. cwords = br->consumed_words;
  82840. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82841. }
  82842. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82843. if(cbits) {
  82844. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82845. const brword word = br->buffer[cwords];
  82846. if(parameter < n) {
  82847. uval <<= parameter;
  82848. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82849. cbits += parameter;
  82850. }
  82851. else {
  82852. uval <<= n;
  82853. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82854. crc16_update_word_(br, word);
  82855. cwords++;
  82856. cbits = parameter - n;
  82857. 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 */
  82858. uval <<= cbits;
  82859. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82860. }
  82861. }
  82862. }
  82863. else {
  82864. cbits = parameter;
  82865. uval <<= parameter;
  82866. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82867. }
  82868. }
  82869. else {
  82870. uval <<= parameter;
  82871. if(cbits) {
  82872. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82873. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82874. cbits += parameter;
  82875. }
  82876. else {
  82877. cbits = parameter;
  82878. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82879. }
  82880. }
  82881. }
  82882. ucbits -= parameter;
  82883. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82884. --nvals;
  82885. if(nvals == 0) {
  82886. br->consumed_bits = cbits;
  82887. br->consumed_words = cwords;
  82888. return true;
  82889. }
  82890. uval = 0;
  82891. ++vals;
  82892. }
  82893. }
  82894. #endif
  82895. #if 0 /* UNUSED */
  82896. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82897. {
  82898. FLAC__uint32 lsbs = 0, msbs = 0;
  82899. unsigned bit, uval, k;
  82900. FLAC__ASSERT(0 != br);
  82901. FLAC__ASSERT(0 != br->buffer);
  82902. k = FLAC__bitmath_ilog2(parameter);
  82903. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82904. return false;
  82905. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82906. return false;
  82907. if(parameter == 1u<<k) {
  82908. uval = (msbs << k) | lsbs;
  82909. }
  82910. else {
  82911. unsigned d = (1 << (k+1)) - parameter;
  82912. if(lsbs >= d) {
  82913. if(!FLAC__bitreader_read_bit(br, &bit))
  82914. return false;
  82915. lsbs <<= 1;
  82916. lsbs |= bit;
  82917. lsbs -= d;
  82918. }
  82919. uval = msbs * parameter + lsbs;
  82920. }
  82921. if(uval & 1)
  82922. *val = -((int)(uval >> 1)) - 1;
  82923. else
  82924. *val = (int)(uval >> 1);
  82925. return true;
  82926. }
  82927. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82928. {
  82929. FLAC__uint32 lsbs, msbs = 0;
  82930. unsigned bit, k;
  82931. FLAC__ASSERT(0 != br);
  82932. FLAC__ASSERT(0 != br->buffer);
  82933. k = FLAC__bitmath_ilog2(parameter);
  82934. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82935. return false;
  82936. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82937. return false;
  82938. if(parameter == 1u<<k) {
  82939. *val = (msbs << k) | lsbs;
  82940. }
  82941. else {
  82942. unsigned d = (1 << (k+1)) - parameter;
  82943. if(lsbs >= d) {
  82944. if(!FLAC__bitreader_read_bit(br, &bit))
  82945. return false;
  82946. lsbs <<= 1;
  82947. lsbs |= bit;
  82948. lsbs -= d;
  82949. }
  82950. *val = msbs * parameter + lsbs;
  82951. }
  82952. return true;
  82953. }
  82954. #endif /* UNUSED */
  82955. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82956. {
  82957. FLAC__uint32 v = 0;
  82958. FLAC__uint32 x;
  82959. unsigned i;
  82960. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82961. return false;
  82962. if(raw)
  82963. raw[(*rawlen)++] = (FLAC__byte)x;
  82964. if(!(x & 0x80)) { /* 0xxxxxxx */
  82965. v = x;
  82966. i = 0;
  82967. }
  82968. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82969. v = x & 0x1F;
  82970. i = 1;
  82971. }
  82972. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82973. v = x & 0x0F;
  82974. i = 2;
  82975. }
  82976. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82977. v = x & 0x07;
  82978. i = 3;
  82979. }
  82980. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82981. v = x & 0x03;
  82982. i = 4;
  82983. }
  82984. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82985. v = x & 0x01;
  82986. i = 5;
  82987. }
  82988. else {
  82989. *val = 0xffffffff;
  82990. return true;
  82991. }
  82992. for( ; i; i--) {
  82993. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82994. return false;
  82995. if(raw)
  82996. raw[(*rawlen)++] = (FLAC__byte)x;
  82997. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82998. *val = 0xffffffff;
  82999. return true;
  83000. }
  83001. v <<= 6;
  83002. v |= (x & 0x3F);
  83003. }
  83004. *val = v;
  83005. return true;
  83006. }
  83007. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  83008. {
  83009. FLAC__uint64 v = 0;
  83010. FLAC__uint32 x;
  83011. unsigned i;
  83012. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  83013. return false;
  83014. if(raw)
  83015. raw[(*rawlen)++] = (FLAC__byte)x;
  83016. if(!(x & 0x80)) { /* 0xxxxxxx */
  83017. v = x;
  83018. i = 0;
  83019. }
  83020. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  83021. v = x & 0x1F;
  83022. i = 1;
  83023. }
  83024. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  83025. v = x & 0x0F;
  83026. i = 2;
  83027. }
  83028. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  83029. v = x & 0x07;
  83030. i = 3;
  83031. }
  83032. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  83033. v = x & 0x03;
  83034. i = 4;
  83035. }
  83036. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  83037. v = x & 0x01;
  83038. i = 5;
  83039. }
  83040. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  83041. v = 0;
  83042. i = 6;
  83043. }
  83044. else {
  83045. *val = FLAC__U64L(0xffffffffffffffff);
  83046. return true;
  83047. }
  83048. for( ; i; i--) {
  83049. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  83050. return false;
  83051. if(raw)
  83052. raw[(*rawlen)++] = (FLAC__byte)x;
  83053. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  83054. *val = FLAC__U64L(0xffffffffffffffff);
  83055. return true;
  83056. }
  83057. v <<= 6;
  83058. v |= (x & 0x3F);
  83059. }
  83060. *val = v;
  83061. return true;
  83062. }
  83063. #endif
  83064. /*** End of inlined file: bitreader.c ***/
  83065. /*** Start of inlined file: bitwriter.c ***/
  83066. /*** Start of inlined file: juce_FlacHeader.h ***/
  83067. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83068. // tasks..
  83069. #define VERSION "1.2.1"
  83070. #define FLAC__NO_DLL 1
  83071. #if JUCE_MSVC
  83072. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83073. #endif
  83074. #if JUCE_MAC
  83075. #define FLAC__SYS_DARWIN 1
  83076. #endif
  83077. /*** End of inlined file: juce_FlacHeader.h ***/
  83078. #if JUCE_USE_FLAC
  83079. #if HAVE_CONFIG_H
  83080. # include <config.h>
  83081. #endif
  83082. #include <stdlib.h> /* for malloc() */
  83083. #include <string.h> /* for memcpy(), memset() */
  83084. #ifdef _MSC_VER
  83085. #include <winsock.h> /* for ntohl() */
  83086. #elif defined FLAC__SYS_DARWIN
  83087. #include <machine/endian.h> /* for ntohl() */
  83088. #elif defined __MINGW32__
  83089. #include <winsock.h> /* for ntohl() */
  83090. #else
  83091. #include <netinet/in.h> /* for ntohl() */
  83092. #endif
  83093. #if 0 /* UNUSED */
  83094. #endif
  83095. /*** Start of inlined file: bitwriter.h ***/
  83096. #ifndef FLAC__PRIVATE__BITWRITER_H
  83097. #define FLAC__PRIVATE__BITWRITER_H
  83098. #include <stdio.h> /* for FILE */
  83099. struct FLAC__BitWriter;
  83100. typedef struct FLAC__BitWriter FLAC__BitWriter;
  83101. FLAC__BitWriter *FLAC__bitwriter_new(void);
  83102. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  83103. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  83104. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  83105. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  83106. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  83107. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  83108. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  83109. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  83110. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  83111. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  83112. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  83113. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  83114. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  83115. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  83116. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  83117. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  83118. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  83119. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  83120. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  83121. #if 0 /* UNUSED */
  83122. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  83123. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  83124. #endif
  83125. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  83126. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  83127. #if 0 /* UNUSED */
  83128. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  83129. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  83130. #endif
  83131. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  83132. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  83133. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  83134. #endif
  83135. /*** End of inlined file: bitwriter.h ***/
  83136. /*** Start of inlined file: alloc.h ***/
  83137. #ifndef FLAC__SHARE__ALLOC_H
  83138. #define FLAC__SHARE__ALLOC_H
  83139. #if HAVE_CONFIG_H
  83140. # include <config.h>
  83141. #endif
  83142. #include <limits.h> /* for SIZE_MAX */
  83143. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  83144. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  83145. #endif
  83146. #include <stdlib.h> /* for size_t, malloc(), etc */
  83147. #ifndef SIZE_MAX
  83148. # ifndef SIZE_T_MAX
  83149. # ifdef _MSC_VER
  83150. # define SIZE_T_MAX UINT_MAX
  83151. # else
  83152. # error
  83153. # endif
  83154. # endif
  83155. # define SIZE_MAX SIZE_T_MAX
  83156. #endif
  83157. #ifndef FLaC__INLINE
  83158. #define FLaC__INLINE
  83159. #endif
  83160. static FLaC__INLINE void *safe_malloc_(size_t size)
  83161. {
  83162. if(!size)
  83163. size++;
  83164. return malloc(size);
  83165. }
  83166. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  83167. {
  83168. if(!nmemb || !size)
  83169. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83170. return calloc(nmemb, size);
  83171. }
  83172. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  83173. {
  83174. size2 += size1;
  83175. if(size2 < size1)
  83176. return 0;
  83177. return safe_malloc_(size2);
  83178. }
  83179. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  83180. {
  83181. size2 += size1;
  83182. if(size2 < size1)
  83183. return 0;
  83184. size3 += size2;
  83185. if(size3 < size2)
  83186. return 0;
  83187. return safe_malloc_(size3);
  83188. }
  83189. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  83190. {
  83191. size2 += size1;
  83192. if(size2 < size1)
  83193. return 0;
  83194. size3 += size2;
  83195. if(size3 < size2)
  83196. return 0;
  83197. size4 += size3;
  83198. if(size4 < size3)
  83199. return 0;
  83200. return safe_malloc_(size4);
  83201. }
  83202. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  83203. #if 0
  83204. needs support for cases where sizeof(size_t) != 4
  83205. {
  83206. if(sizeof(size_t) == 4) {
  83207. if ((double)size1 * (double)size2 < 4294967296.0)
  83208. return malloc(size1*size2);
  83209. }
  83210. return 0;
  83211. }
  83212. #else
  83213. {
  83214. if(!size1 || !size2)
  83215. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83216. if(size1 > SIZE_MAX / size2)
  83217. return 0;
  83218. return malloc(size1*size2);
  83219. }
  83220. #endif
  83221. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  83222. {
  83223. if(!size1 || !size2 || !size3)
  83224. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83225. if(size1 > SIZE_MAX / size2)
  83226. return 0;
  83227. size1 *= size2;
  83228. if(size1 > SIZE_MAX / size3)
  83229. return 0;
  83230. return malloc(size1*size3);
  83231. }
  83232. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  83233. {
  83234. if(!size1 || !size2)
  83235. return safe_malloc_(size3);
  83236. if(size1 > SIZE_MAX / size2)
  83237. return 0;
  83238. return safe_malloc_add_2op_(size1*size2, size3);
  83239. }
  83240. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  83241. {
  83242. if(!size1 || (!size2 && !size3))
  83243. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83244. size2 += size3;
  83245. if(size2 < size3)
  83246. return 0;
  83247. return safe_malloc_mul_2op_(size1, size2);
  83248. }
  83249. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  83250. {
  83251. size2 += size1;
  83252. if(size2 < size1)
  83253. return 0;
  83254. return realloc(ptr, size2);
  83255. }
  83256. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  83257. {
  83258. size2 += size1;
  83259. if(size2 < size1)
  83260. return 0;
  83261. size3 += size2;
  83262. if(size3 < size2)
  83263. return 0;
  83264. return realloc(ptr, size3);
  83265. }
  83266. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  83267. {
  83268. size2 += size1;
  83269. if(size2 < size1)
  83270. return 0;
  83271. size3 += size2;
  83272. if(size3 < size2)
  83273. return 0;
  83274. size4 += size3;
  83275. if(size4 < size3)
  83276. return 0;
  83277. return realloc(ptr, size4);
  83278. }
  83279. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  83280. {
  83281. if(!size1 || !size2)
  83282. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83283. if(size1 > SIZE_MAX / size2)
  83284. return 0;
  83285. return realloc(ptr, size1*size2);
  83286. }
  83287. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  83288. {
  83289. if(!size1 || (!size2 && !size3))
  83290. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83291. size2 += size3;
  83292. if(size2 < size3)
  83293. return 0;
  83294. return safe_realloc_mul_2op_(ptr, size1, size2);
  83295. }
  83296. #endif
  83297. /*** End of inlined file: alloc.h ***/
  83298. typedef FLAC__uint32 bwword;
  83299. #define FLAC__BYTES_PER_WORD 4
  83300. #define FLAC__BITS_PER_WORD 32
  83301. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  83302. #if WORDS_BIGENDIAN
  83303. #define SWAP_BE_WORD_TO_HOST(x) (x)
  83304. #else
  83305. #ifdef _MSC_VER
  83306. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  83307. #else
  83308. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  83309. #endif
  83310. #endif
  83311. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  83312. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  83313. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  83314. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  83315. #ifdef min
  83316. #undef min
  83317. #endif
  83318. #define min(x,y) ((x)<(y)?(x):(y))
  83319. #ifdef _MSC_VER
  83320. #define FLAC__U64L(x) x
  83321. #else
  83322. #define FLAC__U64L(x) x##LLU
  83323. #endif
  83324. #ifndef FLaC__INLINE
  83325. #define FLaC__INLINE
  83326. #endif
  83327. struct FLAC__BitWriter {
  83328. bwword *buffer;
  83329. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  83330. unsigned capacity; /* capacity of buffer in words */
  83331. unsigned words; /* # of complete words in buffer */
  83332. unsigned bits; /* # of used bits in accum */
  83333. };
  83334. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  83335. {
  83336. unsigned new_capacity;
  83337. bwword *new_buffer;
  83338. FLAC__ASSERT(0 != bw);
  83339. FLAC__ASSERT(0 != bw->buffer);
  83340. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  83341. if(bw->capacity >= new_capacity)
  83342. return true;
  83343. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  83344. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83345. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83346. FLAC__ASSERT(new_capacity > bw->capacity);
  83347. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  83348. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  83349. if(new_buffer == 0)
  83350. return false;
  83351. bw->buffer = new_buffer;
  83352. bw->capacity = new_capacity;
  83353. return true;
  83354. }
  83355. FLAC__BitWriter *FLAC__bitwriter_new(void)
  83356. {
  83357. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  83358. return bw;
  83359. }
  83360. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  83361. {
  83362. FLAC__ASSERT(0 != bw);
  83363. FLAC__bitwriter_free(bw);
  83364. free(bw);
  83365. }
  83366. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  83367. {
  83368. FLAC__ASSERT(0 != bw);
  83369. bw->words = bw->bits = 0;
  83370. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  83371. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  83372. if(bw->buffer == 0)
  83373. return false;
  83374. return true;
  83375. }
  83376. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  83377. {
  83378. FLAC__ASSERT(0 != bw);
  83379. if(0 != bw->buffer)
  83380. free(bw->buffer);
  83381. bw->buffer = 0;
  83382. bw->capacity = 0;
  83383. bw->words = bw->bits = 0;
  83384. }
  83385. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  83386. {
  83387. bw->words = bw->bits = 0;
  83388. }
  83389. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  83390. {
  83391. unsigned i, j;
  83392. if(bw == 0) {
  83393. fprintf(out, "bitwriter is NULL\n");
  83394. }
  83395. else {
  83396. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  83397. for(i = 0; i < bw->words; i++) {
  83398. fprintf(out, "%08X: ", i);
  83399. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  83400. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  83401. fprintf(out, "\n");
  83402. }
  83403. if(bw->bits > 0) {
  83404. fprintf(out, "%08X: ", i);
  83405. for(j = 0; j < bw->bits; j++)
  83406. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  83407. fprintf(out, "\n");
  83408. }
  83409. }
  83410. }
  83411. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  83412. {
  83413. const FLAC__byte *buffer;
  83414. size_t bytes;
  83415. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83416. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83417. return false;
  83418. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  83419. FLAC__bitwriter_release_buffer(bw);
  83420. return true;
  83421. }
  83422. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  83423. {
  83424. const FLAC__byte *buffer;
  83425. size_t bytes;
  83426. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83427. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83428. return false;
  83429. *crc = FLAC__crc8(buffer, bytes);
  83430. FLAC__bitwriter_release_buffer(bw);
  83431. return true;
  83432. }
  83433. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  83434. {
  83435. return ((bw->bits & 7) == 0);
  83436. }
  83437. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  83438. {
  83439. return FLAC__TOTAL_BITS(bw);
  83440. }
  83441. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  83442. {
  83443. FLAC__ASSERT((bw->bits & 7) == 0);
  83444. if(bw->bits & 7)
  83445. return false;
  83446. if(bw->bits) {
  83447. FLAC__ASSERT(bw->words <= bw->capacity);
  83448. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  83449. return false;
  83450. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  83451. }
  83452. *buffer = (FLAC__byte*)bw->buffer;
  83453. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  83454. return true;
  83455. }
  83456. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  83457. {
  83458. (void)bw;
  83459. }
  83460. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  83461. {
  83462. unsigned n;
  83463. FLAC__ASSERT(0 != bw);
  83464. FLAC__ASSERT(0 != bw->buffer);
  83465. if(bits == 0)
  83466. return true;
  83467. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83468. return false;
  83469. if(bw->bits) {
  83470. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  83471. bw->accum <<= n;
  83472. bits -= n;
  83473. bw->bits += n;
  83474. if(bw->bits == FLAC__BITS_PER_WORD) {
  83475. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83476. bw->bits = 0;
  83477. }
  83478. else
  83479. return true;
  83480. }
  83481. while(bits >= FLAC__BITS_PER_WORD) {
  83482. bw->buffer[bw->words++] = 0;
  83483. bits -= FLAC__BITS_PER_WORD;
  83484. }
  83485. if(bits > 0) {
  83486. bw->accum = 0;
  83487. bw->bits = bits;
  83488. }
  83489. return true;
  83490. }
  83491. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  83492. {
  83493. register unsigned left;
  83494. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83495. FLAC__ASSERT(0 != bw);
  83496. FLAC__ASSERT(0 != bw->buffer);
  83497. FLAC__ASSERT(bits <= 32);
  83498. if(bits == 0)
  83499. return true;
  83500. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83501. return false;
  83502. left = FLAC__BITS_PER_WORD - bw->bits;
  83503. if(bits < left) {
  83504. bw->accum <<= bits;
  83505. bw->accum |= val;
  83506. bw->bits += bits;
  83507. }
  83508. 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 */
  83509. bw->accum <<= left;
  83510. bw->accum |= val >> (bw->bits = bits - left);
  83511. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83512. bw->accum = val;
  83513. }
  83514. else {
  83515. bw->accum = val;
  83516. bw->bits = 0;
  83517. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  83518. }
  83519. return true;
  83520. }
  83521. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  83522. {
  83523. if(bits < 32)
  83524. val &= (~(0xffffffff << bits));
  83525. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83526. }
  83527. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  83528. {
  83529. if(bits > 32) {
  83530. return
  83531. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  83532. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  83533. }
  83534. else
  83535. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83536. }
  83537. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83538. {
  83539. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83540. return false;
  83541. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83542. return false;
  83543. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83544. return false;
  83545. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83546. return false;
  83547. return true;
  83548. }
  83549. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83550. {
  83551. unsigned i;
  83552. for(i = 0; i < nvals; i++) {
  83553. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83554. return false;
  83555. }
  83556. return true;
  83557. }
  83558. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83559. {
  83560. if(val < 32)
  83561. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83562. else
  83563. return
  83564. FLAC__bitwriter_write_zeroes(bw, val) &&
  83565. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83566. }
  83567. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83568. {
  83569. FLAC__uint32 uval;
  83570. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83571. uval = (val<<1) ^ (val>>31);
  83572. return 1 + parameter + (uval >> parameter);
  83573. }
  83574. #if 0 /* UNUSED */
  83575. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83576. {
  83577. unsigned bits, msbs, uval;
  83578. unsigned k;
  83579. FLAC__ASSERT(parameter > 0);
  83580. if(val < 0)
  83581. uval = (unsigned)(((-(++val)) << 1) + 1);
  83582. else
  83583. uval = (unsigned)(val << 1);
  83584. k = FLAC__bitmath_ilog2(parameter);
  83585. if(parameter == 1u<<k) {
  83586. FLAC__ASSERT(k <= 30);
  83587. msbs = uval >> k;
  83588. bits = 1 + k + msbs;
  83589. }
  83590. else {
  83591. unsigned q, r, d;
  83592. d = (1 << (k+1)) - parameter;
  83593. q = uval / parameter;
  83594. r = uval - (q * parameter);
  83595. bits = 1 + q + k;
  83596. if(r >= d)
  83597. bits++;
  83598. }
  83599. return bits;
  83600. }
  83601. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83602. {
  83603. unsigned bits, msbs;
  83604. unsigned k;
  83605. FLAC__ASSERT(parameter > 0);
  83606. k = FLAC__bitmath_ilog2(parameter);
  83607. if(parameter == 1u<<k) {
  83608. FLAC__ASSERT(k <= 30);
  83609. msbs = uval >> k;
  83610. bits = 1 + k + msbs;
  83611. }
  83612. else {
  83613. unsigned q, r, d;
  83614. d = (1 << (k+1)) - parameter;
  83615. q = uval / parameter;
  83616. r = uval - (q * parameter);
  83617. bits = 1 + q + k;
  83618. if(r >= d)
  83619. bits++;
  83620. }
  83621. return bits;
  83622. }
  83623. #endif /* UNUSED */
  83624. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83625. {
  83626. unsigned total_bits, interesting_bits, msbs;
  83627. FLAC__uint32 uval, pattern;
  83628. FLAC__ASSERT(0 != bw);
  83629. FLAC__ASSERT(0 != bw->buffer);
  83630. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83631. uval = (val<<1) ^ (val>>31);
  83632. msbs = uval >> parameter;
  83633. interesting_bits = 1 + parameter;
  83634. total_bits = interesting_bits + msbs;
  83635. pattern = 1 << parameter; /* the unary end bit */
  83636. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83637. if(total_bits <= 32)
  83638. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83639. else
  83640. return
  83641. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83642. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83643. }
  83644. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83645. {
  83646. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83647. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83648. FLAC__uint32 uval;
  83649. unsigned left;
  83650. const unsigned lsbits = 1 + parameter;
  83651. unsigned msbits;
  83652. FLAC__ASSERT(0 != bw);
  83653. FLAC__ASSERT(0 != bw->buffer);
  83654. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83655. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83656. while(nvals) {
  83657. uval = (*vals<<1) ^ (*vals>>31);
  83658. msbits = uval >> parameter;
  83659. #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) */
  83660. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83661. bw->bits = bw->bits + msbits + lsbits;
  83662. uval |= mask1; /* set stop bit */
  83663. uval &= mask2; /* mask off unused top bits */
  83664. bw->accum <<= msbits;
  83665. bw->accum <<= lsbits;
  83666. bw->accum |= uval;
  83667. if(bw->bits == FLAC__BITS_PER_WORD) {
  83668. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83669. bw->bits = 0;
  83670. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83671. FLAC__ASSERT(bw->capacity == bw->words);
  83672. return false;
  83673. }
  83674. }
  83675. }
  83676. else {
  83677. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83678. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83679. bw->bits = bw->bits + msbits + lsbits;
  83680. uval |= mask1; /* set stop bit */
  83681. uval &= mask2; /* mask off unused top bits */
  83682. bw->accum <<= msbits + lsbits;
  83683. bw->accum |= uval;
  83684. }
  83685. else {
  83686. #endif
  83687. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83688. return false;
  83689. if(msbits) {
  83690. if(bw->bits) {
  83691. left = FLAC__BITS_PER_WORD - bw->bits;
  83692. if(msbits < left) {
  83693. bw->accum <<= msbits;
  83694. bw->bits += msbits;
  83695. goto break1;
  83696. }
  83697. else {
  83698. bw->accum <<= left;
  83699. msbits -= left;
  83700. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83701. bw->bits = 0;
  83702. }
  83703. }
  83704. while(msbits >= FLAC__BITS_PER_WORD) {
  83705. bw->buffer[bw->words++] = 0;
  83706. msbits -= FLAC__BITS_PER_WORD;
  83707. }
  83708. if(msbits > 0) {
  83709. bw->accum = 0;
  83710. bw->bits = msbits;
  83711. }
  83712. }
  83713. break1:
  83714. uval |= mask1; /* set stop bit */
  83715. uval &= mask2; /* mask off unused top bits */
  83716. left = FLAC__BITS_PER_WORD - bw->bits;
  83717. if(lsbits < left) {
  83718. bw->accum <<= lsbits;
  83719. bw->accum |= uval;
  83720. bw->bits += lsbits;
  83721. }
  83722. else {
  83723. FLAC__ASSERT(bw->bits);
  83724. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83725. bw->accum <<= left;
  83726. bw->accum |= uval >> (bw->bits = lsbits - left);
  83727. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83728. bw->accum = uval;
  83729. }
  83730. #if 1
  83731. }
  83732. #endif
  83733. vals++;
  83734. nvals--;
  83735. }
  83736. return true;
  83737. }
  83738. #if 0 /* UNUSED */
  83739. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83740. {
  83741. unsigned total_bits, msbs, uval;
  83742. unsigned k;
  83743. FLAC__ASSERT(0 != bw);
  83744. FLAC__ASSERT(0 != bw->buffer);
  83745. FLAC__ASSERT(parameter > 0);
  83746. if(val < 0)
  83747. uval = (unsigned)(((-(++val)) << 1) + 1);
  83748. else
  83749. uval = (unsigned)(val << 1);
  83750. k = FLAC__bitmath_ilog2(parameter);
  83751. if(parameter == 1u<<k) {
  83752. unsigned pattern;
  83753. FLAC__ASSERT(k <= 30);
  83754. msbs = uval >> k;
  83755. total_bits = 1 + k + msbs;
  83756. pattern = 1 << k; /* the unary end bit */
  83757. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83758. if(total_bits <= 32) {
  83759. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83760. return false;
  83761. }
  83762. else {
  83763. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83764. return false;
  83765. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83766. return false;
  83767. }
  83768. }
  83769. else {
  83770. unsigned q, r, d;
  83771. d = (1 << (k+1)) - parameter;
  83772. q = uval / parameter;
  83773. r = uval - (q * parameter);
  83774. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83775. return false;
  83776. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83777. return false;
  83778. if(r >= d) {
  83779. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83780. return false;
  83781. }
  83782. else {
  83783. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83784. return false;
  83785. }
  83786. }
  83787. return true;
  83788. }
  83789. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83790. {
  83791. unsigned total_bits, msbs;
  83792. unsigned k;
  83793. FLAC__ASSERT(0 != bw);
  83794. FLAC__ASSERT(0 != bw->buffer);
  83795. FLAC__ASSERT(parameter > 0);
  83796. k = FLAC__bitmath_ilog2(parameter);
  83797. if(parameter == 1u<<k) {
  83798. unsigned pattern;
  83799. FLAC__ASSERT(k <= 30);
  83800. msbs = uval >> k;
  83801. total_bits = 1 + k + msbs;
  83802. pattern = 1 << k; /* the unary end bit */
  83803. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83804. if(total_bits <= 32) {
  83805. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83806. return false;
  83807. }
  83808. else {
  83809. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83810. return false;
  83811. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83812. return false;
  83813. }
  83814. }
  83815. else {
  83816. unsigned q, r, d;
  83817. d = (1 << (k+1)) - parameter;
  83818. q = uval / parameter;
  83819. r = uval - (q * parameter);
  83820. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83821. return false;
  83822. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83823. return false;
  83824. if(r >= d) {
  83825. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83826. return false;
  83827. }
  83828. else {
  83829. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83830. return false;
  83831. }
  83832. }
  83833. return true;
  83834. }
  83835. #endif /* UNUSED */
  83836. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83837. {
  83838. FLAC__bool ok = 1;
  83839. FLAC__ASSERT(0 != bw);
  83840. FLAC__ASSERT(0 != bw->buffer);
  83841. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83842. if(val < 0x80) {
  83843. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83844. }
  83845. else if(val < 0x800) {
  83846. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83847. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83848. }
  83849. else if(val < 0x10000) {
  83850. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83851. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83852. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83853. }
  83854. else if(val < 0x200000) {
  83855. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83856. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83857. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83858. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83859. }
  83860. else if(val < 0x4000000) {
  83861. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83862. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83863. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83864. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83865. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83866. }
  83867. else {
  83868. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83869. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83870. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83871. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83872. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83873. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83874. }
  83875. return ok;
  83876. }
  83877. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83878. {
  83879. FLAC__bool ok = 1;
  83880. FLAC__ASSERT(0 != bw);
  83881. FLAC__ASSERT(0 != bw->buffer);
  83882. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83883. if(val < 0x80) {
  83884. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83885. }
  83886. else if(val < 0x800) {
  83887. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83888. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83889. }
  83890. else if(val < 0x10000) {
  83891. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83892. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83893. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83894. }
  83895. else if(val < 0x200000) {
  83896. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83897. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83898. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83899. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83900. }
  83901. else if(val < 0x4000000) {
  83902. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83903. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83904. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83905. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83906. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83907. }
  83908. else if(val < 0x80000000) {
  83909. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83910. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83911. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83912. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83913. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83914. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83915. }
  83916. else {
  83917. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83918. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83919. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83920. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83921. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83922. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83923. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83924. }
  83925. return ok;
  83926. }
  83927. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83928. {
  83929. if(bw->bits & 7u)
  83930. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83931. else
  83932. return true;
  83933. }
  83934. #endif
  83935. /*** End of inlined file: bitwriter.c ***/
  83936. /*** Start of inlined file: cpu.c ***/
  83937. /*** Start of inlined file: juce_FlacHeader.h ***/
  83938. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83939. // tasks..
  83940. #define VERSION "1.2.1"
  83941. #define FLAC__NO_DLL 1
  83942. #if JUCE_MSVC
  83943. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83944. #endif
  83945. #if JUCE_MAC
  83946. #define FLAC__SYS_DARWIN 1
  83947. #endif
  83948. /*** End of inlined file: juce_FlacHeader.h ***/
  83949. #if JUCE_USE_FLAC
  83950. #if HAVE_CONFIG_H
  83951. # include <config.h>
  83952. #endif
  83953. #include <stdlib.h>
  83954. #include <stdio.h>
  83955. #if defined FLAC__CPU_IA32
  83956. # include <signal.h>
  83957. #elif defined FLAC__CPU_PPC
  83958. # if !defined FLAC__NO_ASM
  83959. # if defined FLAC__SYS_DARWIN
  83960. # include <sys/sysctl.h>
  83961. # include <mach/mach.h>
  83962. # include <mach/mach_host.h>
  83963. # include <mach/host_info.h>
  83964. # include <mach/machine.h>
  83965. # ifndef CPU_SUBTYPE_POWERPC_970
  83966. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83967. # endif
  83968. # else /* FLAC__SYS_DARWIN */
  83969. # include <signal.h>
  83970. # include <setjmp.h>
  83971. static sigjmp_buf jmpbuf;
  83972. static volatile sig_atomic_t canjump = 0;
  83973. static void sigill_handler (int sig)
  83974. {
  83975. if (!canjump) {
  83976. signal (sig, SIG_DFL);
  83977. raise (sig);
  83978. }
  83979. canjump = 0;
  83980. siglongjmp (jmpbuf, 1);
  83981. }
  83982. # endif /* FLAC__SYS_DARWIN */
  83983. # endif /* FLAC__NO_ASM */
  83984. #endif /* FLAC__CPU_PPC */
  83985. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83986. #include <sys/param.h>
  83987. #include <sys/sysctl.h>
  83988. #include <machine/cpu.h>
  83989. #endif
  83990. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83991. #include <sys/types.h>
  83992. #include <sys/sysctl.h>
  83993. #endif
  83994. #if defined(__APPLE__)
  83995. #endif
  83996. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83997. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83998. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83999. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  84000. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  84001. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  84002. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  84003. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  84004. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  84005. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  84006. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  84007. # if defined(__linux__)
  84008. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  84009. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  84010. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  84011. {
  84012. (void)signal;
  84013. sc.eip += 3 + 3 + 6;
  84014. }
  84015. # else
  84016. # include <sys/ucontext.h>
  84017. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  84018. {
  84019. (void)signal, (void)si;
  84020. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  84021. }
  84022. # endif
  84023. # elif defined(_MSC_VER)
  84024. # include <windows.h>
  84025. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  84026. # ifdef USE_TRY_CATCH_FLAVOR
  84027. # else
  84028. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  84029. {
  84030. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  84031. ep->ContextRecord->Eip += 3 + 3 + 6;
  84032. return EXCEPTION_CONTINUE_EXECUTION;
  84033. }
  84034. return EXCEPTION_CONTINUE_SEARCH;
  84035. }
  84036. # endif
  84037. # endif
  84038. #endif
  84039. void FLAC__cpu_info(FLAC__CPUInfo *info)
  84040. {
  84041. #ifdef FLAC__CPU_IA32
  84042. info->type = FLAC__CPUINFO_TYPE_IA32;
  84043. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  84044. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  84045. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  84046. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  84047. info->data.ia32.cmov = false;
  84048. info->data.ia32.mmx = false;
  84049. info->data.ia32.fxsr = false;
  84050. info->data.ia32.sse = false;
  84051. info->data.ia32.sse2 = false;
  84052. info->data.ia32.sse3 = false;
  84053. info->data.ia32.ssse3 = false;
  84054. info->data.ia32._3dnow = false;
  84055. info->data.ia32.ext3dnow = false;
  84056. info->data.ia32.extmmx = false;
  84057. if(info->data.ia32.cpuid) {
  84058. FLAC__uint32 flags_edx, flags_ecx;
  84059. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  84060. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  84061. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  84062. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  84063. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  84064. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  84065. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  84066. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  84067. #ifdef FLAC__USE_3DNOW
  84068. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  84069. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  84070. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  84071. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  84072. #else
  84073. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  84074. #endif
  84075. #ifdef DEBUG
  84076. fprintf(stderr, "CPU info (IA-32):\n");
  84077. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  84078. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  84079. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  84080. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  84081. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  84082. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  84083. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  84084. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  84085. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  84086. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  84087. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  84088. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  84089. #endif
  84090. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  84091. #if defined FLAC__NO_SSE_OS
  84092. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84093. #elif defined FLAC__SSE_OS
  84094. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  84095. int sse = 0;
  84096. size_t len;
  84097. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  84098. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  84099. if(!sse)
  84100. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84101. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  84102. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  84103. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  84104. size_t len = sizeof(val);
  84105. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  84106. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84107. else { /* double-check SSE2 */
  84108. mib[1] = CPU_SSE2;
  84109. len = sizeof(val);
  84110. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  84111. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84112. }
  84113. # else
  84114. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84115. # endif
  84116. #elif defined(__linux__)
  84117. int sse = 0;
  84118. struct sigaction sigill_save;
  84119. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  84120. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  84121. #else
  84122. struct sigaction sigill_sse;
  84123. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  84124. __sigemptyset(&sigill_sse.sa_mask);
  84125. 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 */
  84126. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  84127. #endif
  84128. {
  84129. asm volatile (
  84130. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  84131. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  84132. "incl %0\n\t" /* SIGILL handler will jump over this */
  84133. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  84134. "nop\n\t"
  84135. "nop\n\t"
  84136. "nop\n\t"
  84137. "nop\n\t"
  84138. "nop\n\t"
  84139. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  84140. "nop\n\t"
  84141. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  84142. : "=r"(sse)
  84143. : "r"(sse)
  84144. );
  84145. sigaction(SIGILL, &sigill_save, NULL);
  84146. }
  84147. if(!sse)
  84148. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84149. #elif defined(_MSC_VER)
  84150. # ifdef USE_TRY_CATCH_FLAVOR
  84151. _try {
  84152. __asm {
  84153. # if _MSC_VER <= 1200
  84154. _emit 0x0F
  84155. _emit 0x57
  84156. _emit 0xC0
  84157. # else
  84158. xorps xmm0,xmm0
  84159. # endif
  84160. }
  84161. }
  84162. _except(EXCEPTION_EXECUTE_HANDLER) {
  84163. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  84164. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84165. }
  84166. # else
  84167. int sse = 0;
  84168. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  84169. __asm {
  84170. # if _MSC_VER <= 1200
  84171. _emit 0x0F
  84172. _emit 0x57
  84173. _emit 0xC0
  84174. # else
  84175. xorps xmm0,xmm0
  84176. # endif
  84177. inc sse
  84178. nop
  84179. nop
  84180. nop
  84181. nop
  84182. nop
  84183. nop
  84184. nop
  84185. nop
  84186. nop
  84187. }
  84188. SetUnhandledExceptionFilter(save);
  84189. if(!sse)
  84190. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84191. # endif
  84192. #else
  84193. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84194. #endif
  84195. #ifdef DEBUG
  84196. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  84197. #endif
  84198. }
  84199. }
  84200. #else
  84201. info->use_asm = false;
  84202. #endif
  84203. #elif defined FLAC__CPU_PPC
  84204. info->type = FLAC__CPUINFO_TYPE_PPC;
  84205. # if !defined FLAC__NO_ASM
  84206. info->use_asm = true;
  84207. # ifdef FLAC__USE_ALTIVEC
  84208. # if defined FLAC__SYS_DARWIN
  84209. {
  84210. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  84211. size_t len = sizeof(val);
  84212. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  84213. }
  84214. {
  84215. host_basic_info_data_t hostInfo;
  84216. mach_msg_type_number_t infoCount;
  84217. infoCount = HOST_BASIC_INFO_COUNT;
  84218. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  84219. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  84220. }
  84221. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  84222. {
  84223. info->data.ppc.altivec = 0;
  84224. info->data.ppc.ppc64 = 0;
  84225. signal (SIGILL, sigill_handler);
  84226. canjump = 0;
  84227. if (!sigsetjmp (jmpbuf, 1)) {
  84228. canjump = 1;
  84229. asm volatile (
  84230. "mtspr 256, %0\n\t"
  84231. "vand %%v0, %%v0, %%v0"
  84232. :
  84233. : "r" (-1)
  84234. );
  84235. info->data.ppc.altivec = 1;
  84236. }
  84237. canjump = 0;
  84238. if (!sigsetjmp (jmpbuf, 1)) {
  84239. int x = 0;
  84240. canjump = 1;
  84241. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  84242. info->data.ppc.ppc64 = 1;
  84243. }
  84244. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  84245. }
  84246. # endif
  84247. # else /* !FLAC__USE_ALTIVEC */
  84248. info->data.ppc.altivec = 0;
  84249. info->data.ppc.ppc64 = 0;
  84250. # endif
  84251. # else
  84252. info->use_asm = false;
  84253. # endif
  84254. #else
  84255. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  84256. info->use_asm = false;
  84257. #endif
  84258. }
  84259. #endif
  84260. /*** End of inlined file: cpu.c ***/
  84261. /*** Start of inlined file: crc.c ***/
  84262. /*** Start of inlined file: juce_FlacHeader.h ***/
  84263. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84264. // tasks..
  84265. #define VERSION "1.2.1"
  84266. #define FLAC__NO_DLL 1
  84267. #if JUCE_MSVC
  84268. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84269. #endif
  84270. #if JUCE_MAC
  84271. #define FLAC__SYS_DARWIN 1
  84272. #endif
  84273. /*** End of inlined file: juce_FlacHeader.h ***/
  84274. #if JUCE_USE_FLAC
  84275. #if HAVE_CONFIG_H
  84276. # include <config.h>
  84277. #endif
  84278. FLAC__byte const FLAC__crc8_table[256] = {
  84279. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  84280. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  84281. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  84282. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  84283. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  84284. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  84285. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  84286. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  84287. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  84288. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  84289. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  84290. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  84291. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  84292. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  84293. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  84294. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  84295. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  84296. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  84297. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  84298. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  84299. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  84300. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  84301. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  84302. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  84303. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  84304. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  84305. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  84306. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  84307. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  84308. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  84309. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  84310. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  84311. };
  84312. unsigned FLAC__crc16_table[256] = {
  84313. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  84314. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  84315. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  84316. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  84317. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  84318. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  84319. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  84320. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  84321. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  84322. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  84323. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  84324. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  84325. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  84326. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  84327. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  84328. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  84329. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  84330. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  84331. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  84332. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  84333. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  84334. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  84335. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  84336. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  84337. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  84338. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  84339. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  84340. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  84341. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  84342. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  84343. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  84344. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  84345. };
  84346. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  84347. {
  84348. *crc = FLAC__crc8_table[*crc ^ data];
  84349. }
  84350. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  84351. {
  84352. while(len--)
  84353. *crc = FLAC__crc8_table[*crc ^ *data++];
  84354. }
  84355. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  84356. {
  84357. FLAC__uint8 crc = 0;
  84358. while(len--)
  84359. crc = FLAC__crc8_table[crc ^ *data++];
  84360. return crc;
  84361. }
  84362. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  84363. {
  84364. unsigned crc = 0;
  84365. while(len--)
  84366. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  84367. return crc;
  84368. }
  84369. #endif
  84370. /*** End of inlined file: crc.c ***/
  84371. /*** Start of inlined file: fixed.c ***/
  84372. /*** Start of inlined file: juce_FlacHeader.h ***/
  84373. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84374. // tasks..
  84375. #define VERSION "1.2.1"
  84376. #define FLAC__NO_DLL 1
  84377. #if JUCE_MSVC
  84378. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84379. #endif
  84380. #if JUCE_MAC
  84381. #define FLAC__SYS_DARWIN 1
  84382. #endif
  84383. /*** End of inlined file: juce_FlacHeader.h ***/
  84384. #if JUCE_USE_FLAC
  84385. #if HAVE_CONFIG_H
  84386. # include <config.h>
  84387. #endif
  84388. #include <math.h>
  84389. #include <string.h>
  84390. /*** Start of inlined file: fixed.h ***/
  84391. #ifndef FLAC__PRIVATE__FIXED_H
  84392. #define FLAC__PRIVATE__FIXED_H
  84393. #ifdef HAVE_CONFIG_H
  84394. #include <config.h>
  84395. #endif
  84396. /*** Start of inlined file: float.h ***/
  84397. #ifndef FLAC__PRIVATE__FLOAT_H
  84398. #define FLAC__PRIVATE__FLOAT_H
  84399. #ifdef HAVE_CONFIG_H
  84400. #include <config.h>
  84401. #endif
  84402. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84403. typedef double FLAC__double;
  84404. typedef float FLAC__float;
  84405. typedef float FLAC__real;
  84406. #else
  84407. typedef FLAC__int32 FLAC__fixedpoint;
  84408. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  84409. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  84410. extern const FLAC__fixedpoint FLAC__FP_ONE;
  84411. extern const FLAC__fixedpoint FLAC__FP_LN2;
  84412. extern const FLAC__fixedpoint FLAC__FP_E;
  84413. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  84414. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  84415. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  84416. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  84417. #endif
  84418. #endif
  84419. /*** End of inlined file: float.h ***/
  84420. /*** Start of inlined file: format.h ***/
  84421. #ifndef FLAC__PRIVATE__FORMAT_H
  84422. #define FLAC__PRIVATE__FORMAT_H
  84423. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  84424. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  84425. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  84426. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84427. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84428. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  84429. #endif
  84430. /*** End of inlined file: format.h ***/
  84431. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84432. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84433. # ifndef FLAC__NO_ASM
  84434. # ifdef FLAC__CPU_IA32
  84435. # ifdef FLAC__HAS_NASM
  84436. 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]);
  84437. # endif
  84438. # endif
  84439. # endif
  84440. 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]);
  84441. #else
  84442. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84443. 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]);
  84444. #endif
  84445. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  84446. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  84447. #endif
  84448. /*** End of inlined file: fixed.h ***/
  84449. #ifndef M_LN2
  84450. #define M_LN2 0.69314718055994530942
  84451. #endif
  84452. #ifdef min
  84453. #undef min
  84454. #endif
  84455. #define min(x,y) ((x) < (y)? (x) : (y))
  84456. #ifdef local_abs
  84457. #undef local_abs
  84458. #endif
  84459. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  84460. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84461. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  84462. {
  84463. FLAC__uint32 rbps;
  84464. unsigned bits; /* the number of bits required to represent a number */
  84465. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84466. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84467. FLAC__ASSERT(err > 0);
  84468. FLAC__ASSERT(n > 0);
  84469. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84470. if(err <= n)
  84471. return 0;
  84472. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  84473. err <<= fracbits;
  84474. err /= n;
  84475. FLAC__ASSERT(err > 0);
  84476. bits = FLAC__bitmath_ilog2(err)+1;
  84477. if(bits > 16) {
  84478. err >>= (bits-16);
  84479. fracbits -= (bits-16);
  84480. }
  84481. rbps = (FLAC__uint32)err;
  84482. rbps *= FLAC__FP_LN2;
  84483. fracbits += 16;
  84484. FLAC__ASSERT(fracbits >= 0);
  84485. {
  84486. const int f = fracbits & 3;
  84487. if(f) {
  84488. rbps >>= f;
  84489. fracbits -= f;
  84490. }
  84491. }
  84492. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84493. if(rbps == 0)
  84494. return 0;
  84495. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84496. FLAC__ASSERT(fracbits >= -3);
  84497. if(fracbits < 16)
  84498. return rbps << (16-fracbits);
  84499. else if(fracbits > 16)
  84500. return rbps >> (fracbits-16);
  84501. else
  84502. return rbps;
  84503. }
  84504. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  84505. {
  84506. FLAC__uint32 rbps;
  84507. unsigned bits; /* the number of bits required to represent a number */
  84508. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84509. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84510. FLAC__ASSERT(err > 0);
  84511. FLAC__ASSERT(n > 0);
  84512. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84513. if(err <= n)
  84514. return 0;
  84515. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  84516. err <<= fracbits;
  84517. err /= n;
  84518. FLAC__ASSERT(err > 0);
  84519. bits = FLAC__bitmath_ilog2_wide(err)+1;
  84520. if(bits > 16) {
  84521. err >>= (bits-16);
  84522. fracbits -= (bits-16);
  84523. }
  84524. rbps = (FLAC__uint32)err;
  84525. rbps *= FLAC__FP_LN2;
  84526. fracbits += 16;
  84527. FLAC__ASSERT(fracbits >= 0);
  84528. {
  84529. const int f = fracbits & 3;
  84530. if(f) {
  84531. rbps >>= f;
  84532. fracbits -= f;
  84533. }
  84534. }
  84535. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84536. if(rbps == 0)
  84537. return 0;
  84538. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84539. FLAC__ASSERT(fracbits >= -3);
  84540. if(fracbits < 16)
  84541. return rbps << (16-fracbits);
  84542. else if(fracbits > 16)
  84543. return rbps >> (fracbits-16);
  84544. else
  84545. return rbps;
  84546. }
  84547. #endif
  84548. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84549. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84550. #else
  84551. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84552. #endif
  84553. {
  84554. FLAC__int32 last_error_0 = data[-1];
  84555. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84556. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84557. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84558. FLAC__int32 error, save;
  84559. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84560. unsigned i, order;
  84561. for(i = 0; i < data_len; i++) {
  84562. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84563. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84564. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84565. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84566. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84567. }
  84568. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84569. order = 0;
  84570. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84571. order = 1;
  84572. else if(total_error_2 < min(total_error_3, total_error_4))
  84573. order = 2;
  84574. else if(total_error_3 < total_error_4)
  84575. order = 3;
  84576. else
  84577. order = 4;
  84578. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84579. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84580. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84581. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84582. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84583. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84584. 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);
  84585. 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);
  84586. 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);
  84587. 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);
  84588. 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);
  84589. #else
  84590. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84591. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84592. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84593. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84594. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84595. #endif
  84596. return order;
  84597. }
  84598. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84599. 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])
  84600. #else
  84601. 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])
  84602. #endif
  84603. {
  84604. FLAC__int32 last_error_0 = data[-1];
  84605. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84606. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84607. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84608. FLAC__int32 error, save;
  84609. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84610. unsigned i, order;
  84611. for(i = 0; i < data_len; i++) {
  84612. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84613. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84614. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84615. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84616. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84617. }
  84618. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84619. order = 0;
  84620. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84621. order = 1;
  84622. else if(total_error_2 < min(total_error_3, total_error_4))
  84623. order = 2;
  84624. else if(total_error_3 < total_error_4)
  84625. order = 3;
  84626. else
  84627. order = 4;
  84628. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84629. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84630. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84631. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84632. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84633. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84634. #if defined _MSC_VER || defined __MINGW32__
  84635. 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);
  84636. 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);
  84637. 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);
  84638. 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);
  84639. 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);
  84640. #else
  84641. 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);
  84642. 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);
  84643. 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);
  84644. 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);
  84645. 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);
  84646. #endif
  84647. #else
  84648. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84649. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84650. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84651. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84652. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84653. #endif
  84654. return order;
  84655. }
  84656. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84657. {
  84658. const int idata_len = (int)data_len;
  84659. int i;
  84660. switch(order) {
  84661. case 0:
  84662. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84663. memcpy(residual, data, sizeof(residual[0])*data_len);
  84664. break;
  84665. case 1:
  84666. for(i = 0; i < idata_len; i++)
  84667. residual[i] = data[i] - data[i-1];
  84668. break;
  84669. case 2:
  84670. for(i = 0; i < idata_len; i++)
  84671. #if 1 /* OPT: may be faster with some compilers on some systems */
  84672. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84673. #else
  84674. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84675. #endif
  84676. break;
  84677. case 3:
  84678. for(i = 0; i < idata_len; i++)
  84679. #if 1 /* OPT: may be faster with some compilers on some systems */
  84680. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84681. #else
  84682. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84683. #endif
  84684. break;
  84685. case 4:
  84686. for(i = 0; i < idata_len; i++)
  84687. #if 1 /* OPT: may be faster with some compilers on some systems */
  84688. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84689. #else
  84690. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84691. #endif
  84692. break;
  84693. default:
  84694. FLAC__ASSERT(0);
  84695. }
  84696. }
  84697. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84698. {
  84699. int i, idata_len = (int)data_len;
  84700. switch(order) {
  84701. case 0:
  84702. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84703. memcpy(data, residual, sizeof(residual[0])*data_len);
  84704. break;
  84705. case 1:
  84706. for(i = 0; i < idata_len; i++)
  84707. data[i] = residual[i] + data[i-1];
  84708. break;
  84709. case 2:
  84710. for(i = 0; i < idata_len; i++)
  84711. #if 1 /* OPT: may be faster with some compilers on some systems */
  84712. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84713. #else
  84714. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84715. #endif
  84716. break;
  84717. case 3:
  84718. for(i = 0; i < idata_len; i++)
  84719. #if 1 /* OPT: may be faster with some compilers on some systems */
  84720. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84721. #else
  84722. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84723. #endif
  84724. break;
  84725. case 4:
  84726. for(i = 0; i < idata_len; i++)
  84727. #if 1 /* OPT: may be faster with some compilers on some systems */
  84728. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84729. #else
  84730. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84731. #endif
  84732. break;
  84733. default:
  84734. FLAC__ASSERT(0);
  84735. }
  84736. }
  84737. #endif
  84738. /*** End of inlined file: fixed.c ***/
  84739. /*** Start of inlined file: float.c ***/
  84740. /*** Start of inlined file: juce_FlacHeader.h ***/
  84741. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84742. // tasks..
  84743. #define VERSION "1.2.1"
  84744. #define FLAC__NO_DLL 1
  84745. #if JUCE_MSVC
  84746. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84747. #endif
  84748. #if JUCE_MAC
  84749. #define FLAC__SYS_DARWIN 1
  84750. #endif
  84751. /*** End of inlined file: juce_FlacHeader.h ***/
  84752. #if JUCE_USE_FLAC
  84753. #if HAVE_CONFIG_H
  84754. # include <config.h>
  84755. #endif
  84756. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84757. #ifdef _MSC_VER
  84758. #define FLAC__U64L(x) x
  84759. #else
  84760. #define FLAC__U64L(x) x##LLU
  84761. #endif
  84762. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84763. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84764. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84765. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84766. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84767. #define LOG2_LOOKUP_PRECISION 16
  84768. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84769. {
  84770. 0x00000000,
  84771. 0x00000001,
  84772. 0x00000000,
  84773. 0x00000000,
  84774. 0x00000000,
  84775. 0x00000000,
  84776. 0x00000000,
  84777. 0x00000000,
  84778. 0x00000000,
  84779. 0x00000000,
  84780. 0x00000000,
  84781. 0x00000000,
  84782. 0x00000000,
  84783. 0x00000000,
  84784. 0x00000000,
  84785. 0x00000000
  84786. },
  84787. {
  84788. 0x00000000,
  84789. 0x00000010,
  84790. 0x00000007,
  84791. 0x00000003,
  84792. 0x00000001,
  84793. 0x00000001,
  84794. 0x00000000,
  84795. 0x00000000,
  84796. 0x00000000,
  84797. 0x00000000,
  84798. 0x00000000,
  84799. 0x00000000,
  84800. 0x00000000,
  84801. 0x00000000,
  84802. 0x00000000,
  84803. 0x00000000
  84804. },
  84805. {
  84806. 0x00000000,
  84807. 0x00000100,
  84808. 0x0000006a,
  84809. 0x00000031,
  84810. 0x00000018,
  84811. 0x0000000c,
  84812. 0x00000006,
  84813. 0x00000003,
  84814. 0x00000001,
  84815. 0x00000001,
  84816. 0x00000000,
  84817. 0x00000000,
  84818. 0x00000000,
  84819. 0x00000000,
  84820. 0x00000000,
  84821. 0x00000000
  84822. },
  84823. {
  84824. 0x00000000,
  84825. 0x00001000,
  84826. 0x000006a4,
  84827. 0x00000315,
  84828. 0x0000017d,
  84829. 0x000000bc,
  84830. 0x0000005d,
  84831. 0x0000002e,
  84832. 0x00000017,
  84833. 0x0000000c,
  84834. 0x00000006,
  84835. 0x00000003,
  84836. 0x00000001,
  84837. 0x00000001,
  84838. 0x00000000,
  84839. 0x00000000
  84840. },
  84841. {
  84842. 0x00000000,
  84843. 0x00010000,
  84844. 0x00006a40,
  84845. 0x00003151,
  84846. 0x000017d6,
  84847. 0x00000bba,
  84848. 0x000005d1,
  84849. 0x000002e6,
  84850. 0x00000172,
  84851. 0x000000b9,
  84852. 0x0000005c,
  84853. 0x0000002e,
  84854. 0x00000017,
  84855. 0x0000000c,
  84856. 0x00000006,
  84857. 0x00000003
  84858. },
  84859. {
  84860. 0x00000000,
  84861. 0x00100000,
  84862. 0x0006a3fe,
  84863. 0x00031513,
  84864. 0x00017d60,
  84865. 0x0000bb9d,
  84866. 0x00005d10,
  84867. 0x00002e59,
  84868. 0x00001721,
  84869. 0x00000b8e,
  84870. 0x000005c6,
  84871. 0x000002e3,
  84872. 0x00000171,
  84873. 0x000000b9,
  84874. 0x0000005c,
  84875. 0x0000002e
  84876. },
  84877. {
  84878. 0x00000000,
  84879. 0x01000000,
  84880. 0x006a3fe6,
  84881. 0x00315130,
  84882. 0x0017d605,
  84883. 0x000bb9ca,
  84884. 0x0005d0fc,
  84885. 0x0002e58f,
  84886. 0x0001720e,
  84887. 0x0000b8d8,
  84888. 0x00005c61,
  84889. 0x00002e2d,
  84890. 0x00001716,
  84891. 0x00000b8b,
  84892. 0x000005c5,
  84893. 0x000002e3
  84894. },
  84895. {
  84896. 0x00000000,
  84897. 0x10000000,
  84898. 0x06a3fe5c,
  84899. 0x03151301,
  84900. 0x017d6049,
  84901. 0x00bb9ca6,
  84902. 0x005d0fba,
  84903. 0x002e58f7,
  84904. 0x001720da,
  84905. 0x000b8d87,
  84906. 0x0005c60b,
  84907. 0x0002e2d7,
  84908. 0x00017160,
  84909. 0x0000b8ad,
  84910. 0x00005c56,
  84911. 0x00002e2b
  84912. }
  84913. };
  84914. #if 0
  84915. static const FLAC__uint64 log2_lookup_wide[] = {
  84916. {
  84917. 0x00000000,
  84918. FLAC__U64L(0x100000000),
  84919. FLAC__U64L(0x6a3fe5c6),
  84920. FLAC__U64L(0x31513015),
  84921. FLAC__U64L(0x17d60497),
  84922. FLAC__U64L(0x0bb9ca65),
  84923. FLAC__U64L(0x05d0fba2),
  84924. FLAC__U64L(0x02e58f74),
  84925. FLAC__U64L(0x01720d9c),
  84926. FLAC__U64L(0x00b8d875),
  84927. FLAC__U64L(0x005c60aa),
  84928. FLAC__U64L(0x002e2d72),
  84929. FLAC__U64L(0x00171600),
  84930. FLAC__U64L(0x000b8ad2),
  84931. FLAC__U64L(0x0005c55d),
  84932. FLAC__U64L(0x0002e2ac)
  84933. },
  84934. {
  84935. 0x00000000,
  84936. FLAC__U64L(0x1000000000000),
  84937. FLAC__U64L(0x6a3fe5c60429),
  84938. FLAC__U64L(0x315130157f7a),
  84939. FLAC__U64L(0x17d60496cfbb),
  84940. FLAC__U64L(0xbb9ca64ecac),
  84941. FLAC__U64L(0x5d0fba187cd),
  84942. FLAC__U64L(0x2e58f7441ee),
  84943. FLAC__U64L(0x1720d9c06a8),
  84944. FLAC__U64L(0xb8d8752173),
  84945. FLAC__U64L(0x5c60aa252e),
  84946. FLAC__U64L(0x2e2d71b0d8),
  84947. FLAC__U64L(0x1716001719),
  84948. FLAC__U64L(0xb8ad1de1b),
  84949. FLAC__U64L(0x5c55d640d),
  84950. FLAC__U64L(0x2e2abcf52)
  84951. }
  84952. };
  84953. #endif
  84954. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84955. {
  84956. const FLAC__uint32 ONE = (1u << fracbits);
  84957. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84958. FLAC__ASSERT(fracbits < 32);
  84959. FLAC__ASSERT((fracbits & 0x3) == 0);
  84960. if(x < ONE)
  84961. return 0;
  84962. if(precision > LOG2_LOOKUP_PRECISION)
  84963. precision = LOG2_LOOKUP_PRECISION;
  84964. {
  84965. FLAC__uint32 y = 0;
  84966. FLAC__uint32 z = x >> 1, k = 1;
  84967. while (x > ONE && k < precision) {
  84968. if (x - z >= ONE) {
  84969. x -= z;
  84970. z = x >> k;
  84971. y += table[k];
  84972. }
  84973. else {
  84974. z >>= 1;
  84975. k++;
  84976. }
  84977. }
  84978. return y;
  84979. }
  84980. }
  84981. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84982. #endif
  84983. /*** End of inlined file: float.c ***/
  84984. /*** Start of inlined file: format.c ***/
  84985. /*** Start of inlined file: juce_FlacHeader.h ***/
  84986. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84987. // tasks..
  84988. #define VERSION "1.2.1"
  84989. #define FLAC__NO_DLL 1
  84990. #if JUCE_MSVC
  84991. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84992. #endif
  84993. #if JUCE_MAC
  84994. #define FLAC__SYS_DARWIN 1
  84995. #endif
  84996. /*** End of inlined file: juce_FlacHeader.h ***/
  84997. #if JUCE_USE_FLAC
  84998. #if HAVE_CONFIG_H
  84999. # include <config.h>
  85000. #endif
  85001. #include <stdio.h>
  85002. #include <stdlib.h> /* for qsort() */
  85003. #include <string.h> /* for memset() */
  85004. #ifndef FLaC__INLINE
  85005. #define FLaC__INLINE
  85006. #endif
  85007. #ifdef min
  85008. #undef min
  85009. #endif
  85010. #define min(a,b) ((a)<(b)?(a):(b))
  85011. #ifdef _MSC_VER
  85012. #define FLAC__U64L(x) x
  85013. #else
  85014. #define FLAC__U64L(x) x##LLU
  85015. #endif
  85016. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  85017. ;
  85018. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  85019. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  85020. #else
  85021. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  85022. #endif
  85023. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  85024. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  85025. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  85026. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  85027. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  85028. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  85029. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  85030. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  85031. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  85032. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  85033. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  85034. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  85035. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  85036. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  85037. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  85038. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  85039. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  85040. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  85041. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  85042. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  85043. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  85044. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  85045. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  85046. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  85047. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  85048. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  85049. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  85050. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  85051. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  85052. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  85053. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  85054. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  85055. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  85056. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  85057. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  85058. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  85059. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  85060. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  85061. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  85062. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  85063. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  85064. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  85065. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  85066. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  85067. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  85068. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  85069. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  85070. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  85071. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  85072. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  85073. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  85074. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  85075. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  85076. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  85077. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  85078. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  85079. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  85080. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  85081. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  85082. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  85083. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  85084. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  85085. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  85086. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  85087. "PARTITIONED_RICE",
  85088. "PARTITIONED_RICE2"
  85089. };
  85090. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  85091. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  85092. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  85093. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  85094. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  85095. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  85096. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  85097. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  85098. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  85099. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  85100. "CONSTANT",
  85101. "VERBATIM",
  85102. "FIXED",
  85103. "LPC"
  85104. };
  85105. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  85106. "INDEPENDENT",
  85107. "LEFT_SIDE",
  85108. "RIGHT_SIDE",
  85109. "MID_SIDE"
  85110. };
  85111. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  85112. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  85113. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  85114. };
  85115. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  85116. "STREAMINFO",
  85117. "PADDING",
  85118. "APPLICATION",
  85119. "SEEKTABLE",
  85120. "VORBIS_COMMENT",
  85121. "CUESHEET",
  85122. "PICTURE"
  85123. };
  85124. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  85125. "Other",
  85126. "32x32 pixels 'file icon' (PNG only)",
  85127. "Other file icon",
  85128. "Cover (front)",
  85129. "Cover (back)",
  85130. "Leaflet page",
  85131. "Media (e.g. label side of CD)",
  85132. "Lead artist/lead performer/soloist",
  85133. "Artist/performer",
  85134. "Conductor",
  85135. "Band/Orchestra",
  85136. "Composer",
  85137. "Lyricist/text writer",
  85138. "Recording Location",
  85139. "During recording",
  85140. "During performance",
  85141. "Movie/video screen capture",
  85142. "A bright coloured fish",
  85143. "Illustration",
  85144. "Band/artist logotype",
  85145. "Publisher/Studio logotype"
  85146. };
  85147. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  85148. {
  85149. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  85150. return false;
  85151. }
  85152. else
  85153. return true;
  85154. }
  85155. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  85156. {
  85157. if(
  85158. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  85159. (
  85160. sample_rate >= (1u << 16) &&
  85161. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  85162. )
  85163. ) {
  85164. return false;
  85165. }
  85166. else
  85167. return true;
  85168. }
  85169. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  85170. {
  85171. unsigned i;
  85172. FLAC__uint64 prev_sample_number = 0;
  85173. FLAC__bool got_prev = false;
  85174. FLAC__ASSERT(0 != seek_table);
  85175. for(i = 0; i < seek_table->num_points; i++) {
  85176. if(got_prev) {
  85177. if(
  85178. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  85179. seek_table->points[i].sample_number <= prev_sample_number
  85180. )
  85181. return false;
  85182. }
  85183. prev_sample_number = seek_table->points[i].sample_number;
  85184. got_prev = true;
  85185. }
  85186. return true;
  85187. }
  85188. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  85189. {
  85190. if(l->sample_number == r->sample_number)
  85191. return 0;
  85192. else if(l->sample_number < r->sample_number)
  85193. return -1;
  85194. else
  85195. return 1;
  85196. }
  85197. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  85198. {
  85199. unsigned i, j;
  85200. FLAC__bool first;
  85201. FLAC__ASSERT(0 != seek_table);
  85202. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  85203. first = true;
  85204. for(i = j = 0; i < seek_table->num_points; i++) {
  85205. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  85206. if(!first) {
  85207. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  85208. continue;
  85209. }
  85210. }
  85211. first = false;
  85212. seek_table->points[j++] = seek_table->points[i];
  85213. }
  85214. for(i = j; i < seek_table->num_points; i++) {
  85215. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  85216. seek_table->points[i].stream_offset = 0;
  85217. seek_table->points[i].frame_samples = 0;
  85218. }
  85219. return j;
  85220. }
  85221. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  85222. {
  85223. FLAC__ASSERT(0 != utf8);
  85224. if ((utf8[0] & 0x80) == 0) {
  85225. return 1;
  85226. }
  85227. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  85228. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  85229. return 0;
  85230. return 2;
  85231. }
  85232. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  85233. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  85234. return 0;
  85235. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  85236. return 0;
  85237. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  85238. return 0;
  85239. return 3;
  85240. }
  85241. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  85242. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  85243. return 0;
  85244. return 4;
  85245. }
  85246. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  85247. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  85248. return 0;
  85249. return 5;
  85250. }
  85251. 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) {
  85252. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  85253. return 0;
  85254. return 6;
  85255. }
  85256. else {
  85257. return 0;
  85258. }
  85259. }
  85260. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  85261. {
  85262. char c;
  85263. for(c = *name; c; c = *(++name))
  85264. if(c < 0x20 || c == 0x3d || c > 0x7d)
  85265. return false;
  85266. return true;
  85267. }
  85268. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  85269. {
  85270. if(length == (unsigned)(-1)) {
  85271. while(*value) {
  85272. unsigned n = utf8len_(value);
  85273. if(n == 0)
  85274. return false;
  85275. value += n;
  85276. }
  85277. }
  85278. else {
  85279. const FLAC__byte *end = value + length;
  85280. while(value < end) {
  85281. unsigned n = utf8len_(value);
  85282. if(n == 0)
  85283. return false;
  85284. value += n;
  85285. }
  85286. if(value != end)
  85287. return false;
  85288. }
  85289. return true;
  85290. }
  85291. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  85292. {
  85293. const FLAC__byte *s, *end;
  85294. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  85295. if(*s < 0x20 || *s > 0x7D)
  85296. return false;
  85297. }
  85298. if(s == end)
  85299. return false;
  85300. s++; /* skip '=' */
  85301. while(s < end) {
  85302. unsigned n = utf8len_(s);
  85303. if(n == 0)
  85304. return false;
  85305. s += n;
  85306. }
  85307. if(s != end)
  85308. return false;
  85309. return true;
  85310. }
  85311. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  85312. {
  85313. unsigned i, j;
  85314. if(check_cd_da_subset) {
  85315. if(cue_sheet->lead_in < 2 * 44100) {
  85316. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  85317. return false;
  85318. }
  85319. if(cue_sheet->lead_in % 588 != 0) {
  85320. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  85321. return false;
  85322. }
  85323. }
  85324. if(cue_sheet->num_tracks == 0) {
  85325. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  85326. return false;
  85327. }
  85328. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  85329. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  85330. return false;
  85331. }
  85332. for(i = 0; i < cue_sheet->num_tracks; i++) {
  85333. if(cue_sheet->tracks[i].number == 0) {
  85334. if(violation) *violation = "cue sheet may not have a track number 0";
  85335. return false;
  85336. }
  85337. if(check_cd_da_subset) {
  85338. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  85339. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  85340. return false;
  85341. }
  85342. }
  85343. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  85344. if(violation) {
  85345. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  85346. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  85347. else
  85348. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  85349. }
  85350. return false;
  85351. }
  85352. if(i < cue_sheet->num_tracks - 1) {
  85353. if(cue_sheet->tracks[i].num_indices == 0) {
  85354. if(violation) *violation = "cue sheet track must have at least one index point";
  85355. return false;
  85356. }
  85357. if(cue_sheet->tracks[i].indices[0].number > 1) {
  85358. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  85359. return false;
  85360. }
  85361. }
  85362. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  85363. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  85364. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  85365. return false;
  85366. }
  85367. if(j > 0) {
  85368. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  85369. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  85370. return false;
  85371. }
  85372. }
  85373. }
  85374. }
  85375. return true;
  85376. }
  85377. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  85378. {
  85379. char *p;
  85380. FLAC__byte *b;
  85381. for(p = picture->mime_type; *p; p++) {
  85382. if(*p < 0x20 || *p > 0x7e) {
  85383. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  85384. return false;
  85385. }
  85386. }
  85387. for(b = picture->description; *b; ) {
  85388. unsigned n = utf8len_(b);
  85389. if(n == 0) {
  85390. if(violation) *violation = "description string must be valid UTF-8";
  85391. return false;
  85392. }
  85393. b += n;
  85394. }
  85395. return true;
  85396. }
  85397. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  85398. {
  85399. return
  85400. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  85401. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  85402. blocksize,
  85403. predictor_order
  85404. );
  85405. }
  85406. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  85407. {
  85408. unsigned max_rice_partition_order = 0;
  85409. while(!(blocksize & 1)) {
  85410. max_rice_partition_order++;
  85411. blocksize >>= 1;
  85412. }
  85413. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  85414. }
  85415. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  85416. {
  85417. unsigned max_rice_partition_order = limit;
  85418. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  85419. max_rice_partition_order--;
  85420. FLAC__ASSERT(
  85421. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  85422. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  85423. );
  85424. return max_rice_partition_order;
  85425. }
  85426. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85427. {
  85428. FLAC__ASSERT(0 != object);
  85429. object->parameters = 0;
  85430. object->raw_bits = 0;
  85431. object->capacity_by_order = 0;
  85432. }
  85433. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85434. {
  85435. FLAC__ASSERT(0 != object);
  85436. if(0 != object->parameters)
  85437. free(object->parameters);
  85438. if(0 != object->raw_bits)
  85439. free(object->raw_bits);
  85440. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  85441. }
  85442. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  85443. {
  85444. FLAC__ASSERT(0 != object);
  85445. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  85446. if(object->capacity_by_order < max_partition_order) {
  85447. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  85448. return false;
  85449. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  85450. return false;
  85451. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  85452. object->capacity_by_order = max_partition_order;
  85453. }
  85454. return true;
  85455. }
  85456. #endif
  85457. /*** End of inlined file: format.c ***/
  85458. /*** Start of inlined file: lpc_flac.c ***/
  85459. /*** Start of inlined file: juce_FlacHeader.h ***/
  85460. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  85461. // tasks..
  85462. #define VERSION "1.2.1"
  85463. #define FLAC__NO_DLL 1
  85464. #if JUCE_MSVC
  85465. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  85466. #endif
  85467. #if JUCE_MAC
  85468. #define FLAC__SYS_DARWIN 1
  85469. #endif
  85470. /*** End of inlined file: juce_FlacHeader.h ***/
  85471. #if JUCE_USE_FLAC
  85472. #if HAVE_CONFIG_H
  85473. # include <config.h>
  85474. #endif
  85475. #include <math.h>
  85476. /*** Start of inlined file: lpc.h ***/
  85477. #ifndef FLAC__PRIVATE__LPC_H
  85478. #define FLAC__PRIVATE__LPC_H
  85479. #ifdef HAVE_CONFIG_H
  85480. #include <config.h>
  85481. #endif
  85482. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85483. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  85484. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85485. #ifndef FLAC__NO_ASM
  85486. # ifdef FLAC__CPU_IA32
  85487. # ifdef FLAC__HAS_NASM
  85488. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85489. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85490. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85491. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85492. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85493. # endif
  85494. # endif
  85495. #endif
  85496. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  85497. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  85498. 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[]);
  85499. 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[]);
  85500. #ifndef FLAC__NO_ASM
  85501. # ifdef FLAC__CPU_IA32
  85502. # ifdef FLAC__HAS_NASM
  85503. 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[]);
  85504. 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[]);
  85505. # endif
  85506. # endif
  85507. #endif
  85508. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85509. 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[]);
  85510. 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[]);
  85511. #ifndef FLAC__NO_ASM
  85512. # ifdef FLAC__CPU_IA32
  85513. # ifdef FLAC__HAS_NASM
  85514. 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[]);
  85515. 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[]);
  85516. # endif /* FLAC__HAS_NASM */
  85517. # elif defined FLAC__CPU_PPC
  85518. 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[]);
  85519. 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[]);
  85520. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  85521. #endif /* FLAC__NO_ASM */
  85522. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85523. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  85524. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  85525. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  85526. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85527. #endif
  85528. /*** End of inlined file: lpc.h ***/
  85529. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  85530. #include <stdio.h>
  85531. #endif
  85532. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85533. #ifndef M_LN2
  85534. #define M_LN2 0.69314718055994530942
  85535. #endif
  85536. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85537. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85538. {
  85539. unsigned i;
  85540. for(i = 0; i < data_len; i++)
  85541. out[i] = in[i] * window[i];
  85542. }
  85543. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85544. {
  85545. #if 0
  85546. FLAC__real d;
  85547. unsigned i;
  85548. FLAC__ASSERT(lag > 0);
  85549. FLAC__ASSERT(lag <= data_len);
  85550. while(lag--) {
  85551. for(i = lag, d = 0.0; i < data_len; i++)
  85552. d += data[i] * data[i - lag];
  85553. autoc[lag] = d;
  85554. }
  85555. #endif
  85556. FLAC__real d;
  85557. unsigned sample, coeff;
  85558. const unsigned limit = data_len - lag;
  85559. FLAC__ASSERT(lag > 0);
  85560. FLAC__ASSERT(lag <= data_len);
  85561. for(coeff = 0; coeff < lag; coeff++)
  85562. autoc[coeff] = 0.0;
  85563. for(sample = 0; sample <= limit; sample++) {
  85564. d = data[sample];
  85565. for(coeff = 0; coeff < lag; coeff++)
  85566. autoc[coeff] += d * data[sample+coeff];
  85567. }
  85568. for(; sample < data_len; sample++) {
  85569. d = data[sample];
  85570. for(coeff = 0; coeff < data_len - sample; coeff++)
  85571. autoc[coeff] += d * data[sample+coeff];
  85572. }
  85573. }
  85574. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85575. {
  85576. unsigned i, j;
  85577. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85578. FLAC__ASSERT(0 != max_order);
  85579. FLAC__ASSERT(0 < *max_order);
  85580. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85581. FLAC__ASSERT(autoc[0] != 0.0);
  85582. err = autoc[0];
  85583. for(i = 0; i < *max_order; i++) {
  85584. r = -autoc[i+1];
  85585. for(j = 0; j < i; j++)
  85586. r -= lpc[j] * autoc[i-j];
  85587. ref[i] = (r/=err);
  85588. lpc[i]=r;
  85589. for(j = 0; j < (i>>1); j++) {
  85590. FLAC__double tmp = lpc[j];
  85591. lpc[j] += r * lpc[i-1-j];
  85592. lpc[i-1-j] += r * tmp;
  85593. }
  85594. if(i & 1)
  85595. lpc[j] += lpc[j] * r;
  85596. err *= (1.0 - r * r);
  85597. for(j = 0; j <= i; j++)
  85598. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85599. error[i] = err;
  85600. if(err == 0.0) {
  85601. *max_order = i+1;
  85602. return;
  85603. }
  85604. }
  85605. }
  85606. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85607. {
  85608. unsigned i;
  85609. FLAC__double cmax;
  85610. FLAC__int32 qmax, qmin;
  85611. FLAC__ASSERT(precision > 0);
  85612. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85613. precision--;
  85614. qmax = 1 << precision;
  85615. qmin = -qmax;
  85616. qmax--;
  85617. cmax = 0.0;
  85618. for(i = 0; i < order; i++) {
  85619. const FLAC__double d = fabs(lp_coeff[i]);
  85620. if(d > cmax)
  85621. cmax = d;
  85622. }
  85623. if(cmax <= 0.0) {
  85624. return 2;
  85625. }
  85626. else {
  85627. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85628. const int min_shiftlimit = -max_shiftlimit - 1;
  85629. int log2cmax;
  85630. (void)frexp(cmax, &log2cmax);
  85631. log2cmax--;
  85632. *shift = (int)precision - log2cmax - 1;
  85633. if(*shift > max_shiftlimit)
  85634. *shift = max_shiftlimit;
  85635. else if(*shift < min_shiftlimit)
  85636. return 1;
  85637. }
  85638. if(*shift >= 0) {
  85639. FLAC__double error = 0.0;
  85640. FLAC__int32 q;
  85641. for(i = 0; i < order; i++) {
  85642. error += lp_coeff[i] * (1 << *shift);
  85643. #if 1 /* unfortunately lround() is C99 */
  85644. if(error >= 0.0)
  85645. q = (FLAC__int32)(error + 0.5);
  85646. else
  85647. q = (FLAC__int32)(error - 0.5);
  85648. #else
  85649. q = lround(error);
  85650. #endif
  85651. #ifdef FLAC__OVERFLOW_DETECT
  85652. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85653. 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]);
  85654. else if(q < qmin)
  85655. 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]);
  85656. #endif
  85657. if(q > qmax)
  85658. q = qmax;
  85659. else if(q < qmin)
  85660. q = qmin;
  85661. error -= q;
  85662. qlp_coeff[i] = q;
  85663. }
  85664. }
  85665. else {
  85666. const int nshift = -(*shift);
  85667. FLAC__double error = 0.0;
  85668. FLAC__int32 q;
  85669. #ifdef DEBUG
  85670. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85671. #endif
  85672. for(i = 0; i < order; i++) {
  85673. error += lp_coeff[i] / (1 << nshift);
  85674. #if 1 /* unfortunately lround() is C99 */
  85675. if(error >= 0.0)
  85676. q = (FLAC__int32)(error + 0.5);
  85677. else
  85678. q = (FLAC__int32)(error - 0.5);
  85679. #else
  85680. q = lround(error);
  85681. #endif
  85682. #ifdef FLAC__OVERFLOW_DETECT
  85683. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85684. 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]);
  85685. else if(q < qmin)
  85686. 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]);
  85687. #endif
  85688. if(q > qmax)
  85689. q = qmax;
  85690. else if(q < qmin)
  85691. q = qmin;
  85692. error -= q;
  85693. qlp_coeff[i] = q;
  85694. }
  85695. *shift = 0;
  85696. }
  85697. return 0;
  85698. }
  85699. 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[])
  85700. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85701. {
  85702. FLAC__int64 sumo;
  85703. unsigned i, j;
  85704. FLAC__int32 sum;
  85705. const FLAC__int32 *history;
  85706. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85707. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85708. for(i=0;i<order;i++)
  85709. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85710. fprintf(stderr,"\n");
  85711. #endif
  85712. FLAC__ASSERT(order > 0);
  85713. for(i = 0; i < data_len; i++) {
  85714. sumo = 0;
  85715. sum = 0;
  85716. history = data;
  85717. for(j = 0; j < order; j++) {
  85718. sum += qlp_coeff[j] * (*(--history));
  85719. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85720. #if defined _MSC_VER
  85721. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85722. 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);
  85723. #else
  85724. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85725. 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);
  85726. #endif
  85727. }
  85728. *(residual++) = *(data++) - (sum >> lp_quantization);
  85729. }
  85730. }
  85731. #else /* fully unrolled version for normal use */
  85732. {
  85733. int i;
  85734. FLAC__int32 sum;
  85735. FLAC__ASSERT(order > 0);
  85736. FLAC__ASSERT(order <= 32);
  85737. if(order <= 12) {
  85738. if(order > 8) {
  85739. if(order > 10) {
  85740. if(order == 12) {
  85741. for(i = 0; i < (int)data_len; i++) {
  85742. sum = 0;
  85743. sum += qlp_coeff[11] * data[i-12];
  85744. sum += qlp_coeff[10] * data[i-11];
  85745. sum += qlp_coeff[9] * data[i-10];
  85746. sum += qlp_coeff[8] * data[i-9];
  85747. sum += qlp_coeff[7] * data[i-8];
  85748. sum += qlp_coeff[6] * data[i-7];
  85749. sum += qlp_coeff[5] * data[i-6];
  85750. sum += qlp_coeff[4] * data[i-5];
  85751. sum += qlp_coeff[3] * data[i-4];
  85752. sum += qlp_coeff[2] * data[i-3];
  85753. sum += qlp_coeff[1] * data[i-2];
  85754. sum += qlp_coeff[0] * data[i-1];
  85755. residual[i] = data[i] - (sum >> lp_quantization);
  85756. }
  85757. }
  85758. else { /* order == 11 */
  85759. for(i = 0; i < (int)data_len; i++) {
  85760. sum = 0;
  85761. sum += qlp_coeff[10] * data[i-11];
  85762. sum += qlp_coeff[9] * data[i-10];
  85763. sum += qlp_coeff[8] * data[i-9];
  85764. sum += qlp_coeff[7] * data[i-8];
  85765. sum += qlp_coeff[6] * data[i-7];
  85766. sum += qlp_coeff[5] * data[i-6];
  85767. sum += qlp_coeff[4] * data[i-5];
  85768. sum += qlp_coeff[3] * data[i-4];
  85769. sum += qlp_coeff[2] * data[i-3];
  85770. sum += qlp_coeff[1] * data[i-2];
  85771. sum += qlp_coeff[0] * data[i-1];
  85772. residual[i] = data[i] - (sum >> lp_quantization);
  85773. }
  85774. }
  85775. }
  85776. else {
  85777. if(order == 10) {
  85778. for(i = 0; i < (int)data_len; i++) {
  85779. sum = 0;
  85780. sum += qlp_coeff[9] * data[i-10];
  85781. sum += qlp_coeff[8] * data[i-9];
  85782. sum += qlp_coeff[7] * data[i-8];
  85783. sum += qlp_coeff[6] * data[i-7];
  85784. sum += qlp_coeff[5] * data[i-6];
  85785. sum += qlp_coeff[4] * data[i-5];
  85786. sum += qlp_coeff[3] * data[i-4];
  85787. sum += qlp_coeff[2] * data[i-3];
  85788. sum += qlp_coeff[1] * data[i-2];
  85789. sum += qlp_coeff[0] * data[i-1];
  85790. residual[i] = data[i] - (sum >> lp_quantization);
  85791. }
  85792. }
  85793. else { /* order == 9 */
  85794. for(i = 0; i < (int)data_len; i++) {
  85795. sum = 0;
  85796. sum += qlp_coeff[8] * data[i-9];
  85797. sum += qlp_coeff[7] * data[i-8];
  85798. sum += qlp_coeff[6] * data[i-7];
  85799. sum += qlp_coeff[5] * data[i-6];
  85800. sum += qlp_coeff[4] * data[i-5];
  85801. sum += qlp_coeff[3] * data[i-4];
  85802. sum += qlp_coeff[2] * data[i-3];
  85803. sum += qlp_coeff[1] * data[i-2];
  85804. sum += qlp_coeff[0] * data[i-1];
  85805. residual[i] = data[i] - (sum >> lp_quantization);
  85806. }
  85807. }
  85808. }
  85809. }
  85810. else if(order > 4) {
  85811. if(order > 6) {
  85812. if(order == 8) {
  85813. for(i = 0; i < (int)data_len; i++) {
  85814. sum = 0;
  85815. sum += qlp_coeff[7] * data[i-8];
  85816. sum += qlp_coeff[6] * data[i-7];
  85817. sum += qlp_coeff[5] * data[i-6];
  85818. sum += qlp_coeff[4] * data[i-5];
  85819. sum += qlp_coeff[3] * data[i-4];
  85820. sum += qlp_coeff[2] * data[i-3];
  85821. sum += qlp_coeff[1] * data[i-2];
  85822. sum += qlp_coeff[0] * data[i-1];
  85823. residual[i] = data[i] - (sum >> lp_quantization);
  85824. }
  85825. }
  85826. else { /* order == 7 */
  85827. for(i = 0; i < (int)data_len; i++) {
  85828. sum = 0;
  85829. sum += qlp_coeff[6] * data[i-7];
  85830. sum += qlp_coeff[5] * data[i-6];
  85831. sum += qlp_coeff[4] * data[i-5];
  85832. sum += qlp_coeff[3] * data[i-4];
  85833. sum += qlp_coeff[2] * data[i-3];
  85834. sum += qlp_coeff[1] * data[i-2];
  85835. sum += qlp_coeff[0] * data[i-1];
  85836. residual[i] = data[i] - (sum >> lp_quantization);
  85837. }
  85838. }
  85839. }
  85840. else {
  85841. if(order == 6) {
  85842. for(i = 0; i < (int)data_len; i++) {
  85843. sum = 0;
  85844. sum += qlp_coeff[5] * data[i-6];
  85845. sum += qlp_coeff[4] * data[i-5];
  85846. sum += qlp_coeff[3] * data[i-4];
  85847. sum += qlp_coeff[2] * data[i-3];
  85848. sum += qlp_coeff[1] * data[i-2];
  85849. sum += qlp_coeff[0] * data[i-1];
  85850. residual[i] = data[i] - (sum >> lp_quantization);
  85851. }
  85852. }
  85853. else { /* order == 5 */
  85854. for(i = 0; i < (int)data_len; i++) {
  85855. sum = 0;
  85856. sum += qlp_coeff[4] * data[i-5];
  85857. sum += qlp_coeff[3] * data[i-4];
  85858. sum += qlp_coeff[2] * data[i-3];
  85859. sum += qlp_coeff[1] * data[i-2];
  85860. sum += qlp_coeff[0] * data[i-1];
  85861. residual[i] = data[i] - (sum >> lp_quantization);
  85862. }
  85863. }
  85864. }
  85865. }
  85866. else {
  85867. if(order > 2) {
  85868. if(order == 4) {
  85869. for(i = 0; i < (int)data_len; i++) {
  85870. sum = 0;
  85871. sum += qlp_coeff[3] * data[i-4];
  85872. sum += qlp_coeff[2] * data[i-3];
  85873. sum += qlp_coeff[1] * data[i-2];
  85874. sum += qlp_coeff[0] * data[i-1];
  85875. residual[i] = data[i] - (sum >> lp_quantization);
  85876. }
  85877. }
  85878. else { /* order == 3 */
  85879. for(i = 0; i < (int)data_len; i++) {
  85880. sum = 0;
  85881. sum += qlp_coeff[2] * data[i-3];
  85882. sum += qlp_coeff[1] * data[i-2];
  85883. sum += qlp_coeff[0] * data[i-1];
  85884. residual[i] = data[i] - (sum >> lp_quantization);
  85885. }
  85886. }
  85887. }
  85888. else {
  85889. if(order == 2) {
  85890. for(i = 0; i < (int)data_len; i++) {
  85891. sum = 0;
  85892. sum += qlp_coeff[1] * data[i-2];
  85893. sum += qlp_coeff[0] * data[i-1];
  85894. residual[i] = data[i] - (sum >> lp_quantization);
  85895. }
  85896. }
  85897. else { /* order == 1 */
  85898. for(i = 0; i < (int)data_len; i++)
  85899. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85900. }
  85901. }
  85902. }
  85903. }
  85904. else { /* order > 12 */
  85905. for(i = 0; i < (int)data_len; i++) {
  85906. sum = 0;
  85907. switch(order) {
  85908. case 32: sum += qlp_coeff[31] * data[i-32];
  85909. case 31: sum += qlp_coeff[30] * data[i-31];
  85910. case 30: sum += qlp_coeff[29] * data[i-30];
  85911. case 29: sum += qlp_coeff[28] * data[i-29];
  85912. case 28: sum += qlp_coeff[27] * data[i-28];
  85913. case 27: sum += qlp_coeff[26] * data[i-27];
  85914. case 26: sum += qlp_coeff[25] * data[i-26];
  85915. case 25: sum += qlp_coeff[24] * data[i-25];
  85916. case 24: sum += qlp_coeff[23] * data[i-24];
  85917. case 23: sum += qlp_coeff[22] * data[i-23];
  85918. case 22: sum += qlp_coeff[21] * data[i-22];
  85919. case 21: sum += qlp_coeff[20] * data[i-21];
  85920. case 20: sum += qlp_coeff[19] * data[i-20];
  85921. case 19: sum += qlp_coeff[18] * data[i-19];
  85922. case 18: sum += qlp_coeff[17] * data[i-18];
  85923. case 17: sum += qlp_coeff[16] * data[i-17];
  85924. case 16: sum += qlp_coeff[15] * data[i-16];
  85925. case 15: sum += qlp_coeff[14] * data[i-15];
  85926. case 14: sum += qlp_coeff[13] * data[i-14];
  85927. case 13: sum += qlp_coeff[12] * data[i-13];
  85928. sum += qlp_coeff[11] * data[i-12];
  85929. sum += qlp_coeff[10] * data[i-11];
  85930. sum += qlp_coeff[ 9] * data[i-10];
  85931. sum += qlp_coeff[ 8] * data[i- 9];
  85932. sum += qlp_coeff[ 7] * data[i- 8];
  85933. sum += qlp_coeff[ 6] * data[i- 7];
  85934. sum += qlp_coeff[ 5] * data[i- 6];
  85935. sum += qlp_coeff[ 4] * data[i- 5];
  85936. sum += qlp_coeff[ 3] * data[i- 4];
  85937. sum += qlp_coeff[ 2] * data[i- 3];
  85938. sum += qlp_coeff[ 1] * data[i- 2];
  85939. sum += qlp_coeff[ 0] * data[i- 1];
  85940. }
  85941. residual[i] = data[i] - (sum >> lp_quantization);
  85942. }
  85943. }
  85944. }
  85945. #endif
  85946. 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[])
  85947. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85948. {
  85949. unsigned i, j;
  85950. FLAC__int64 sum;
  85951. const FLAC__int32 *history;
  85952. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85953. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85954. for(i=0;i<order;i++)
  85955. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85956. fprintf(stderr,"\n");
  85957. #endif
  85958. FLAC__ASSERT(order > 0);
  85959. for(i = 0; i < data_len; i++) {
  85960. sum = 0;
  85961. history = data;
  85962. for(j = 0; j < order; j++)
  85963. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85964. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85965. #if defined _MSC_VER
  85966. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85967. #else
  85968. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85969. #endif
  85970. break;
  85971. }
  85972. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85973. #if defined _MSC_VER
  85974. 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));
  85975. #else
  85976. 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)));
  85977. #endif
  85978. break;
  85979. }
  85980. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85981. }
  85982. }
  85983. #else /* fully unrolled version for normal use */
  85984. {
  85985. int i;
  85986. FLAC__int64 sum;
  85987. FLAC__ASSERT(order > 0);
  85988. FLAC__ASSERT(order <= 32);
  85989. if(order <= 12) {
  85990. if(order > 8) {
  85991. if(order > 10) {
  85992. if(order == 12) {
  85993. for(i = 0; i < (int)data_len; i++) {
  85994. sum = 0;
  85995. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85996. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85997. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85998. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85999. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86000. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86001. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86002. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86003. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86004. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86005. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86006. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86007. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86008. }
  86009. }
  86010. else { /* order == 11 */
  86011. for(i = 0; i < (int)data_len; i++) {
  86012. sum = 0;
  86013. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86014. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86015. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86016. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86017. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86018. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86019. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86020. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86021. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86022. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86023. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86024. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86025. }
  86026. }
  86027. }
  86028. else {
  86029. if(order == 10) {
  86030. for(i = 0; i < (int)data_len; i++) {
  86031. sum = 0;
  86032. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86033. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86034. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86035. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86036. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86037. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86038. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86039. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86040. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86041. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86042. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86043. }
  86044. }
  86045. else { /* order == 9 */
  86046. for(i = 0; i < (int)data_len; i++) {
  86047. sum = 0;
  86048. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86049. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86050. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86051. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86052. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86053. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86054. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86055. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86056. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86057. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86058. }
  86059. }
  86060. }
  86061. }
  86062. else if(order > 4) {
  86063. if(order > 6) {
  86064. if(order == 8) {
  86065. for(i = 0; i < (int)data_len; i++) {
  86066. sum = 0;
  86067. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86068. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86069. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86070. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86071. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86072. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86073. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86074. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86075. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86076. }
  86077. }
  86078. else { /* order == 7 */
  86079. for(i = 0; i < (int)data_len; i++) {
  86080. sum = 0;
  86081. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86082. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86083. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86084. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86085. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86086. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86087. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86088. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86089. }
  86090. }
  86091. }
  86092. else {
  86093. if(order == 6) {
  86094. for(i = 0; i < (int)data_len; i++) {
  86095. sum = 0;
  86096. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86097. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86098. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86099. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86100. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86101. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86102. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86103. }
  86104. }
  86105. else { /* order == 5 */
  86106. for(i = 0; i < (int)data_len; i++) {
  86107. sum = 0;
  86108. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86109. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86110. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86111. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86112. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86113. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86114. }
  86115. }
  86116. }
  86117. }
  86118. else {
  86119. if(order > 2) {
  86120. if(order == 4) {
  86121. for(i = 0; i < (int)data_len; i++) {
  86122. sum = 0;
  86123. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86124. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86125. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86126. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86127. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86128. }
  86129. }
  86130. else { /* order == 3 */
  86131. for(i = 0; i < (int)data_len; i++) {
  86132. sum = 0;
  86133. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86134. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86135. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86136. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86137. }
  86138. }
  86139. }
  86140. else {
  86141. if(order == 2) {
  86142. for(i = 0; i < (int)data_len; i++) {
  86143. sum = 0;
  86144. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86145. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86146. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86147. }
  86148. }
  86149. else { /* order == 1 */
  86150. for(i = 0; i < (int)data_len; i++)
  86151. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86152. }
  86153. }
  86154. }
  86155. }
  86156. else { /* order > 12 */
  86157. for(i = 0; i < (int)data_len; i++) {
  86158. sum = 0;
  86159. switch(order) {
  86160. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86161. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86162. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86163. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86164. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86165. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86166. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86167. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86168. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86169. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86170. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86171. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86172. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86173. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86174. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86175. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86176. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86177. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86178. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86179. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86180. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86181. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86182. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86183. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86184. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86185. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86186. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86187. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86188. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86189. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86190. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86191. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86192. }
  86193. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86194. }
  86195. }
  86196. }
  86197. #endif
  86198. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86199. 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[])
  86200. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86201. {
  86202. FLAC__int64 sumo;
  86203. unsigned i, j;
  86204. FLAC__int32 sum;
  86205. const FLAC__int32 *r = residual, *history;
  86206. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86207. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86208. for(i=0;i<order;i++)
  86209. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86210. fprintf(stderr,"\n");
  86211. #endif
  86212. FLAC__ASSERT(order > 0);
  86213. for(i = 0; i < data_len; i++) {
  86214. sumo = 0;
  86215. sum = 0;
  86216. history = data;
  86217. for(j = 0; j < order; j++) {
  86218. sum += qlp_coeff[j] * (*(--history));
  86219. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  86220. #if defined _MSC_VER
  86221. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  86222. 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);
  86223. #else
  86224. if(sumo > 2147483647ll || sumo < -2147483648ll)
  86225. 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);
  86226. #endif
  86227. }
  86228. *(data++) = *(r++) + (sum >> lp_quantization);
  86229. }
  86230. }
  86231. #else /* fully unrolled version for normal use */
  86232. {
  86233. int i;
  86234. FLAC__int32 sum;
  86235. FLAC__ASSERT(order > 0);
  86236. FLAC__ASSERT(order <= 32);
  86237. if(order <= 12) {
  86238. if(order > 8) {
  86239. if(order > 10) {
  86240. if(order == 12) {
  86241. for(i = 0; i < (int)data_len; i++) {
  86242. sum = 0;
  86243. sum += qlp_coeff[11] * data[i-12];
  86244. sum += qlp_coeff[10] * data[i-11];
  86245. sum += qlp_coeff[9] * data[i-10];
  86246. sum += qlp_coeff[8] * data[i-9];
  86247. sum += qlp_coeff[7] * data[i-8];
  86248. sum += qlp_coeff[6] * data[i-7];
  86249. sum += qlp_coeff[5] * data[i-6];
  86250. sum += qlp_coeff[4] * data[i-5];
  86251. sum += qlp_coeff[3] * data[i-4];
  86252. sum += qlp_coeff[2] * data[i-3];
  86253. sum += qlp_coeff[1] * data[i-2];
  86254. sum += qlp_coeff[0] * data[i-1];
  86255. data[i] = residual[i] + (sum >> lp_quantization);
  86256. }
  86257. }
  86258. else { /* order == 11 */
  86259. for(i = 0; i < (int)data_len; i++) {
  86260. sum = 0;
  86261. sum += qlp_coeff[10] * data[i-11];
  86262. sum += qlp_coeff[9] * data[i-10];
  86263. sum += qlp_coeff[8] * data[i-9];
  86264. sum += qlp_coeff[7] * data[i-8];
  86265. sum += qlp_coeff[6] * data[i-7];
  86266. sum += qlp_coeff[5] * data[i-6];
  86267. sum += qlp_coeff[4] * data[i-5];
  86268. sum += qlp_coeff[3] * data[i-4];
  86269. sum += qlp_coeff[2] * data[i-3];
  86270. sum += qlp_coeff[1] * data[i-2];
  86271. sum += qlp_coeff[0] * data[i-1];
  86272. data[i] = residual[i] + (sum >> lp_quantization);
  86273. }
  86274. }
  86275. }
  86276. else {
  86277. if(order == 10) {
  86278. for(i = 0; i < (int)data_len; i++) {
  86279. sum = 0;
  86280. sum += qlp_coeff[9] * data[i-10];
  86281. sum += qlp_coeff[8] * data[i-9];
  86282. sum += qlp_coeff[7] * data[i-8];
  86283. sum += qlp_coeff[6] * data[i-7];
  86284. sum += qlp_coeff[5] * data[i-6];
  86285. sum += qlp_coeff[4] * data[i-5];
  86286. sum += qlp_coeff[3] * data[i-4];
  86287. sum += qlp_coeff[2] * data[i-3];
  86288. sum += qlp_coeff[1] * data[i-2];
  86289. sum += qlp_coeff[0] * data[i-1];
  86290. data[i] = residual[i] + (sum >> lp_quantization);
  86291. }
  86292. }
  86293. else { /* order == 9 */
  86294. for(i = 0; i < (int)data_len; i++) {
  86295. sum = 0;
  86296. sum += qlp_coeff[8] * data[i-9];
  86297. sum += qlp_coeff[7] * data[i-8];
  86298. sum += qlp_coeff[6] * data[i-7];
  86299. sum += qlp_coeff[5] * data[i-6];
  86300. sum += qlp_coeff[4] * data[i-5];
  86301. sum += qlp_coeff[3] * data[i-4];
  86302. sum += qlp_coeff[2] * data[i-3];
  86303. sum += qlp_coeff[1] * data[i-2];
  86304. sum += qlp_coeff[0] * data[i-1];
  86305. data[i] = residual[i] + (sum >> lp_quantization);
  86306. }
  86307. }
  86308. }
  86309. }
  86310. else if(order > 4) {
  86311. if(order > 6) {
  86312. if(order == 8) {
  86313. for(i = 0; i < (int)data_len; i++) {
  86314. sum = 0;
  86315. sum += qlp_coeff[7] * data[i-8];
  86316. sum += qlp_coeff[6] * data[i-7];
  86317. sum += qlp_coeff[5] * data[i-6];
  86318. sum += qlp_coeff[4] * data[i-5];
  86319. sum += qlp_coeff[3] * data[i-4];
  86320. sum += qlp_coeff[2] * data[i-3];
  86321. sum += qlp_coeff[1] * data[i-2];
  86322. sum += qlp_coeff[0] * data[i-1];
  86323. data[i] = residual[i] + (sum >> lp_quantization);
  86324. }
  86325. }
  86326. else { /* order == 7 */
  86327. for(i = 0; i < (int)data_len; i++) {
  86328. sum = 0;
  86329. sum += qlp_coeff[6] * data[i-7];
  86330. sum += qlp_coeff[5] * data[i-6];
  86331. sum += qlp_coeff[4] * data[i-5];
  86332. sum += qlp_coeff[3] * data[i-4];
  86333. sum += qlp_coeff[2] * data[i-3];
  86334. sum += qlp_coeff[1] * data[i-2];
  86335. sum += qlp_coeff[0] * data[i-1];
  86336. data[i] = residual[i] + (sum >> lp_quantization);
  86337. }
  86338. }
  86339. }
  86340. else {
  86341. if(order == 6) {
  86342. for(i = 0; i < (int)data_len; i++) {
  86343. sum = 0;
  86344. sum += qlp_coeff[5] * data[i-6];
  86345. sum += qlp_coeff[4] * data[i-5];
  86346. sum += qlp_coeff[3] * data[i-4];
  86347. sum += qlp_coeff[2] * data[i-3];
  86348. sum += qlp_coeff[1] * data[i-2];
  86349. sum += qlp_coeff[0] * data[i-1];
  86350. data[i] = residual[i] + (sum >> lp_quantization);
  86351. }
  86352. }
  86353. else { /* order == 5 */
  86354. for(i = 0; i < (int)data_len; i++) {
  86355. sum = 0;
  86356. sum += qlp_coeff[4] * data[i-5];
  86357. sum += qlp_coeff[3] * data[i-4];
  86358. sum += qlp_coeff[2] * data[i-3];
  86359. sum += qlp_coeff[1] * data[i-2];
  86360. sum += qlp_coeff[0] * data[i-1];
  86361. data[i] = residual[i] + (sum >> lp_quantization);
  86362. }
  86363. }
  86364. }
  86365. }
  86366. else {
  86367. if(order > 2) {
  86368. if(order == 4) {
  86369. for(i = 0; i < (int)data_len; i++) {
  86370. sum = 0;
  86371. sum += qlp_coeff[3] * data[i-4];
  86372. sum += qlp_coeff[2] * data[i-3];
  86373. sum += qlp_coeff[1] * data[i-2];
  86374. sum += qlp_coeff[0] * data[i-1];
  86375. data[i] = residual[i] + (sum >> lp_quantization);
  86376. }
  86377. }
  86378. else { /* order == 3 */
  86379. for(i = 0; i < (int)data_len; i++) {
  86380. sum = 0;
  86381. sum += qlp_coeff[2] * data[i-3];
  86382. sum += qlp_coeff[1] * data[i-2];
  86383. sum += qlp_coeff[0] * data[i-1];
  86384. data[i] = residual[i] + (sum >> lp_quantization);
  86385. }
  86386. }
  86387. }
  86388. else {
  86389. if(order == 2) {
  86390. for(i = 0; i < (int)data_len; i++) {
  86391. sum = 0;
  86392. sum += qlp_coeff[1] * data[i-2];
  86393. sum += qlp_coeff[0] * data[i-1];
  86394. data[i] = residual[i] + (sum >> lp_quantization);
  86395. }
  86396. }
  86397. else { /* order == 1 */
  86398. for(i = 0; i < (int)data_len; i++)
  86399. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  86400. }
  86401. }
  86402. }
  86403. }
  86404. else { /* order > 12 */
  86405. for(i = 0; i < (int)data_len; i++) {
  86406. sum = 0;
  86407. switch(order) {
  86408. case 32: sum += qlp_coeff[31] * data[i-32];
  86409. case 31: sum += qlp_coeff[30] * data[i-31];
  86410. case 30: sum += qlp_coeff[29] * data[i-30];
  86411. case 29: sum += qlp_coeff[28] * data[i-29];
  86412. case 28: sum += qlp_coeff[27] * data[i-28];
  86413. case 27: sum += qlp_coeff[26] * data[i-27];
  86414. case 26: sum += qlp_coeff[25] * data[i-26];
  86415. case 25: sum += qlp_coeff[24] * data[i-25];
  86416. case 24: sum += qlp_coeff[23] * data[i-24];
  86417. case 23: sum += qlp_coeff[22] * data[i-23];
  86418. case 22: sum += qlp_coeff[21] * data[i-22];
  86419. case 21: sum += qlp_coeff[20] * data[i-21];
  86420. case 20: sum += qlp_coeff[19] * data[i-20];
  86421. case 19: sum += qlp_coeff[18] * data[i-19];
  86422. case 18: sum += qlp_coeff[17] * data[i-18];
  86423. case 17: sum += qlp_coeff[16] * data[i-17];
  86424. case 16: sum += qlp_coeff[15] * data[i-16];
  86425. case 15: sum += qlp_coeff[14] * data[i-15];
  86426. case 14: sum += qlp_coeff[13] * data[i-14];
  86427. case 13: sum += qlp_coeff[12] * data[i-13];
  86428. sum += qlp_coeff[11] * data[i-12];
  86429. sum += qlp_coeff[10] * data[i-11];
  86430. sum += qlp_coeff[ 9] * data[i-10];
  86431. sum += qlp_coeff[ 8] * data[i- 9];
  86432. sum += qlp_coeff[ 7] * data[i- 8];
  86433. sum += qlp_coeff[ 6] * data[i- 7];
  86434. sum += qlp_coeff[ 5] * data[i- 6];
  86435. sum += qlp_coeff[ 4] * data[i- 5];
  86436. sum += qlp_coeff[ 3] * data[i- 4];
  86437. sum += qlp_coeff[ 2] * data[i- 3];
  86438. sum += qlp_coeff[ 1] * data[i- 2];
  86439. sum += qlp_coeff[ 0] * data[i- 1];
  86440. }
  86441. data[i] = residual[i] + (sum >> lp_quantization);
  86442. }
  86443. }
  86444. }
  86445. #endif
  86446. 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[])
  86447. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86448. {
  86449. unsigned i, j;
  86450. FLAC__int64 sum;
  86451. const FLAC__int32 *r = residual, *history;
  86452. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86453. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86454. for(i=0;i<order;i++)
  86455. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86456. fprintf(stderr,"\n");
  86457. #endif
  86458. FLAC__ASSERT(order > 0);
  86459. for(i = 0; i < data_len; i++) {
  86460. sum = 0;
  86461. history = data;
  86462. for(j = 0; j < order; j++)
  86463. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  86464. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  86465. #ifdef _MSC_VER
  86466. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  86467. #else
  86468. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  86469. #endif
  86470. break;
  86471. }
  86472. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  86473. #ifdef _MSC_VER
  86474. 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));
  86475. #else
  86476. 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)));
  86477. #endif
  86478. break;
  86479. }
  86480. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  86481. }
  86482. }
  86483. #else /* fully unrolled version for normal use */
  86484. {
  86485. int i;
  86486. FLAC__int64 sum;
  86487. FLAC__ASSERT(order > 0);
  86488. FLAC__ASSERT(order <= 32);
  86489. if(order <= 12) {
  86490. if(order > 8) {
  86491. if(order > 10) {
  86492. if(order == 12) {
  86493. for(i = 0; i < (int)data_len; i++) {
  86494. sum = 0;
  86495. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86496. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86497. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86498. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86499. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86500. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86501. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86502. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86503. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86504. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86505. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86506. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86507. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86508. }
  86509. }
  86510. else { /* order == 11 */
  86511. for(i = 0; i < (int)data_len; i++) {
  86512. sum = 0;
  86513. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86514. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86515. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86516. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86517. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86518. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86519. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86520. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86521. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86522. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86523. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86524. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86525. }
  86526. }
  86527. }
  86528. else {
  86529. if(order == 10) {
  86530. for(i = 0; i < (int)data_len; i++) {
  86531. sum = 0;
  86532. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86533. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86534. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86535. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86536. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86537. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86538. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86539. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86540. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86541. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86542. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86543. }
  86544. }
  86545. else { /* order == 9 */
  86546. for(i = 0; i < (int)data_len; i++) {
  86547. sum = 0;
  86548. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86549. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86550. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86551. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86552. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86553. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86554. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86555. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86556. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86557. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86558. }
  86559. }
  86560. }
  86561. }
  86562. else if(order > 4) {
  86563. if(order > 6) {
  86564. if(order == 8) {
  86565. for(i = 0; i < (int)data_len; i++) {
  86566. sum = 0;
  86567. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86568. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86569. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86570. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86571. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86572. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86573. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86574. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86575. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86576. }
  86577. }
  86578. else { /* order == 7 */
  86579. for(i = 0; i < (int)data_len; i++) {
  86580. sum = 0;
  86581. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86582. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86583. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86584. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86585. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86586. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86587. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86588. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86589. }
  86590. }
  86591. }
  86592. else {
  86593. if(order == 6) {
  86594. for(i = 0; i < (int)data_len; i++) {
  86595. sum = 0;
  86596. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86597. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86598. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86599. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86600. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86601. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86602. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86603. }
  86604. }
  86605. else { /* order == 5 */
  86606. for(i = 0; i < (int)data_len; i++) {
  86607. sum = 0;
  86608. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86609. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86610. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86611. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86612. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86613. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86614. }
  86615. }
  86616. }
  86617. }
  86618. else {
  86619. if(order > 2) {
  86620. if(order == 4) {
  86621. for(i = 0; i < (int)data_len; i++) {
  86622. sum = 0;
  86623. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86624. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86625. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86626. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86627. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86628. }
  86629. }
  86630. else { /* order == 3 */
  86631. for(i = 0; i < (int)data_len; i++) {
  86632. sum = 0;
  86633. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86634. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86635. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86636. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86637. }
  86638. }
  86639. }
  86640. else {
  86641. if(order == 2) {
  86642. for(i = 0; i < (int)data_len; i++) {
  86643. sum = 0;
  86644. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86645. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86646. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86647. }
  86648. }
  86649. else { /* order == 1 */
  86650. for(i = 0; i < (int)data_len; i++)
  86651. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86652. }
  86653. }
  86654. }
  86655. }
  86656. else { /* order > 12 */
  86657. for(i = 0; i < (int)data_len; i++) {
  86658. sum = 0;
  86659. switch(order) {
  86660. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86661. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86662. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86663. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86664. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86665. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86666. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86667. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86668. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86669. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86670. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86671. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86672. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86673. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86674. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86675. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86676. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86677. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86678. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86679. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86680. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86681. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86682. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86683. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86684. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86685. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86686. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86687. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86688. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86689. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86690. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86691. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86692. }
  86693. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86694. }
  86695. }
  86696. }
  86697. #endif
  86698. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86699. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86700. {
  86701. FLAC__double error_scale;
  86702. FLAC__ASSERT(total_samples > 0);
  86703. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86704. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86705. }
  86706. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86707. {
  86708. if(lpc_error > 0.0) {
  86709. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86710. if(bps >= 0.0)
  86711. return bps;
  86712. else
  86713. return 0.0;
  86714. }
  86715. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86716. return 1e32;
  86717. }
  86718. else {
  86719. return 0.0;
  86720. }
  86721. }
  86722. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86723. {
  86724. 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 */
  86725. FLAC__double bits, best_bits, error_scale;
  86726. FLAC__ASSERT(max_order > 0);
  86727. FLAC__ASSERT(total_samples > 0);
  86728. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86729. best_index = 0;
  86730. best_bits = (unsigned)(-1);
  86731. for(index = 0, order = 1; index < max_order; index++, order++) {
  86732. 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);
  86733. if(bits < best_bits) {
  86734. best_index = index;
  86735. best_bits = bits;
  86736. }
  86737. }
  86738. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86739. }
  86740. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86741. #endif
  86742. /*** End of inlined file: lpc_flac.c ***/
  86743. /*** Start of inlined file: md5.c ***/
  86744. /*** Start of inlined file: juce_FlacHeader.h ***/
  86745. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86746. // tasks..
  86747. #define VERSION "1.2.1"
  86748. #define FLAC__NO_DLL 1
  86749. #if JUCE_MSVC
  86750. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86751. #endif
  86752. #if JUCE_MAC
  86753. #define FLAC__SYS_DARWIN 1
  86754. #endif
  86755. /*** End of inlined file: juce_FlacHeader.h ***/
  86756. #if JUCE_USE_FLAC
  86757. #if HAVE_CONFIG_H
  86758. # include <config.h>
  86759. #endif
  86760. #include <stdlib.h> /* for malloc() */
  86761. #include <string.h> /* for memcpy() */
  86762. /*** Start of inlined file: md5.h ***/
  86763. #ifndef FLAC__PRIVATE__MD5_H
  86764. #define FLAC__PRIVATE__MD5_H
  86765. typedef struct {
  86766. FLAC__uint32 in[16];
  86767. FLAC__uint32 buf[4];
  86768. FLAC__uint32 bytes[2];
  86769. FLAC__byte *internal_buf;
  86770. size_t capacity;
  86771. } FLAC__MD5Context;
  86772. void FLAC__MD5Init(FLAC__MD5Context *context);
  86773. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86774. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86775. #endif
  86776. /*** End of inlined file: md5.h ***/
  86777. #ifndef FLaC__INLINE
  86778. #define FLaC__INLINE
  86779. #endif
  86780. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86781. #define F2(x, y, z) F1(z, x, y)
  86782. #define F3(x, y, z) (x ^ y ^ z)
  86783. #define F4(x, y, z) (y ^ (x | ~z))
  86784. #define MD5STEP(f,w,x,y,z,in,s) \
  86785. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86786. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86787. {
  86788. register FLAC__uint32 a, b, c, d;
  86789. a = buf[0];
  86790. b = buf[1];
  86791. c = buf[2];
  86792. d = buf[3];
  86793. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86794. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86795. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86796. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86797. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86798. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86799. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86800. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86801. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86802. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86803. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86804. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86805. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86806. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86807. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86808. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86809. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86810. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86811. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86812. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86813. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86814. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86815. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86816. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86817. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86818. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86819. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86820. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86821. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86822. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86823. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86824. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86825. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86826. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86827. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86828. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86829. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86830. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86831. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86832. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86833. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86834. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86835. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86836. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86837. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86838. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86839. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86840. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86841. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86842. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86843. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86844. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86845. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86846. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86847. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86848. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86849. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86850. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86851. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86852. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86853. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86854. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86855. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86856. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86857. buf[0] += a;
  86858. buf[1] += b;
  86859. buf[2] += c;
  86860. buf[3] += d;
  86861. }
  86862. #if WORDS_BIGENDIAN
  86863. //@@@@@@ OPT: use bswap/intrinsics
  86864. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86865. {
  86866. register FLAC__uint32 x;
  86867. do {
  86868. x = *buf;
  86869. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86870. *buf++ = (x >> 16) | (x << 16);
  86871. } while (--words);
  86872. }
  86873. static void byteSwapX16(FLAC__uint32 *buf)
  86874. {
  86875. register FLAC__uint32 x;
  86876. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86877. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86878. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86879. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86880. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86881. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86882. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86883. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86884. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86885. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86886. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86887. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86888. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86889. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86890. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86891. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  86892. }
  86893. #else
  86894. #define byteSwap(buf, words)
  86895. #define byteSwapX16(buf)
  86896. #endif
  86897. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86898. {
  86899. FLAC__uint32 t;
  86900. t = ctx->bytes[0];
  86901. if ((ctx->bytes[0] = t + len) < t)
  86902. ctx->bytes[1]++; /* Carry from low to high */
  86903. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86904. if (t > len) {
  86905. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86906. return;
  86907. }
  86908. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86909. byteSwapX16(ctx->in);
  86910. FLAC__MD5Transform(ctx->buf, ctx->in);
  86911. buf += t;
  86912. len -= t;
  86913. while (len >= 64) {
  86914. memcpy(ctx->in, buf, 64);
  86915. byteSwapX16(ctx->in);
  86916. FLAC__MD5Transform(ctx->buf, ctx->in);
  86917. buf += 64;
  86918. len -= 64;
  86919. }
  86920. memcpy(ctx->in, buf, len);
  86921. }
  86922. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86923. {
  86924. ctx->buf[0] = 0x67452301;
  86925. ctx->buf[1] = 0xefcdab89;
  86926. ctx->buf[2] = 0x98badcfe;
  86927. ctx->buf[3] = 0x10325476;
  86928. ctx->bytes[0] = 0;
  86929. ctx->bytes[1] = 0;
  86930. ctx->internal_buf = 0;
  86931. ctx->capacity = 0;
  86932. }
  86933. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86934. {
  86935. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86936. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86937. *p++ = 0x80;
  86938. count = 56 - 1 - count;
  86939. if (count < 0) { /* Padding forces an extra block */
  86940. memset(p, 0, count + 8);
  86941. byteSwapX16(ctx->in);
  86942. FLAC__MD5Transform(ctx->buf, ctx->in);
  86943. p = (FLAC__byte *)ctx->in;
  86944. count = 56;
  86945. }
  86946. memset(p, 0, count);
  86947. byteSwap(ctx->in, 14);
  86948. ctx->in[14] = ctx->bytes[0] << 3;
  86949. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86950. FLAC__MD5Transform(ctx->buf, ctx->in);
  86951. byteSwap(ctx->buf, 4);
  86952. memcpy(digest, ctx->buf, 16);
  86953. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86954. if(0 != ctx->internal_buf) {
  86955. free(ctx->internal_buf);
  86956. ctx->internal_buf = 0;
  86957. ctx->capacity = 0;
  86958. }
  86959. }
  86960. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86961. {
  86962. unsigned channel, sample;
  86963. register FLAC__int32 a_word;
  86964. register FLAC__byte *buf_ = buf;
  86965. #if WORDS_BIGENDIAN
  86966. #else
  86967. if(channels == 2 && bytes_per_sample == 2) {
  86968. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86969. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86970. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86971. *buf1_ = (FLAC__int16)signal[1][sample];
  86972. }
  86973. else if(channels == 1 && bytes_per_sample == 2) {
  86974. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86975. for(sample = 0; sample < samples; sample++)
  86976. *buf1_++ = (FLAC__int16)signal[0][sample];
  86977. }
  86978. else
  86979. #endif
  86980. if(bytes_per_sample == 2) {
  86981. if(channels == 2) {
  86982. for(sample = 0; sample < samples; sample++) {
  86983. a_word = signal[0][sample];
  86984. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86985. *buf_++ = (FLAC__byte)a_word;
  86986. a_word = signal[1][sample];
  86987. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86988. *buf_++ = (FLAC__byte)a_word;
  86989. }
  86990. }
  86991. else if(channels == 1) {
  86992. for(sample = 0; sample < samples; sample++) {
  86993. a_word = signal[0][sample];
  86994. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86995. *buf_++ = (FLAC__byte)a_word;
  86996. }
  86997. }
  86998. else {
  86999. for(sample = 0; sample < samples; sample++) {
  87000. for(channel = 0; channel < channels; channel++) {
  87001. a_word = signal[channel][sample];
  87002. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87003. *buf_++ = (FLAC__byte)a_word;
  87004. }
  87005. }
  87006. }
  87007. }
  87008. else if(bytes_per_sample == 3) {
  87009. if(channels == 2) {
  87010. for(sample = 0; sample < samples; sample++) {
  87011. a_word = signal[0][sample];
  87012. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87013. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87014. *buf_++ = (FLAC__byte)a_word;
  87015. a_word = signal[1][sample];
  87016. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87017. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87018. *buf_++ = (FLAC__byte)a_word;
  87019. }
  87020. }
  87021. else if(channels == 1) {
  87022. for(sample = 0; sample < samples; sample++) {
  87023. a_word = signal[0][sample];
  87024. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87025. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87026. *buf_++ = (FLAC__byte)a_word;
  87027. }
  87028. }
  87029. else {
  87030. for(sample = 0; sample < samples; sample++) {
  87031. for(channel = 0; channel < channels; channel++) {
  87032. a_word = signal[channel][sample];
  87033. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87034. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87035. *buf_++ = (FLAC__byte)a_word;
  87036. }
  87037. }
  87038. }
  87039. }
  87040. else if(bytes_per_sample == 1) {
  87041. if(channels == 2) {
  87042. for(sample = 0; sample < samples; sample++) {
  87043. a_word = signal[0][sample];
  87044. *buf_++ = (FLAC__byte)a_word;
  87045. a_word = signal[1][sample];
  87046. *buf_++ = (FLAC__byte)a_word;
  87047. }
  87048. }
  87049. else if(channels == 1) {
  87050. for(sample = 0; sample < samples; sample++) {
  87051. a_word = signal[0][sample];
  87052. *buf_++ = (FLAC__byte)a_word;
  87053. }
  87054. }
  87055. else {
  87056. for(sample = 0; sample < samples; sample++) {
  87057. for(channel = 0; channel < channels; channel++) {
  87058. a_word = signal[channel][sample];
  87059. *buf_++ = (FLAC__byte)a_word;
  87060. }
  87061. }
  87062. }
  87063. }
  87064. else { /* bytes_per_sample == 4, maybe optimize more later */
  87065. for(sample = 0; sample < samples; sample++) {
  87066. for(channel = 0; channel < channels; channel++) {
  87067. a_word = signal[channel][sample];
  87068. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87069. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87070. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87071. *buf_++ = (FLAC__byte)a_word;
  87072. }
  87073. }
  87074. }
  87075. }
  87076. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  87077. {
  87078. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  87079. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  87080. return false;
  87081. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  87082. return false;
  87083. if(ctx->capacity < bytes_needed) {
  87084. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  87085. if(0 == tmp) {
  87086. free(ctx->internal_buf);
  87087. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  87088. return false;
  87089. }
  87090. ctx->internal_buf = tmp;
  87091. ctx->capacity = bytes_needed;
  87092. }
  87093. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  87094. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  87095. return true;
  87096. }
  87097. #endif
  87098. /*** End of inlined file: md5.c ***/
  87099. /*** Start of inlined file: memory.c ***/
  87100. /*** Start of inlined file: juce_FlacHeader.h ***/
  87101. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87102. // tasks..
  87103. #define VERSION "1.2.1"
  87104. #define FLAC__NO_DLL 1
  87105. #if JUCE_MSVC
  87106. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87107. #endif
  87108. #if JUCE_MAC
  87109. #define FLAC__SYS_DARWIN 1
  87110. #endif
  87111. /*** End of inlined file: juce_FlacHeader.h ***/
  87112. #if JUCE_USE_FLAC
  87113. #if HAVE_CONFIG_H
  87114. # include <config.h>
  87115. #endif
  87116. /*** Start of inlined file: memory.h ***/
  87117. #ifndef FLAC__PRIVATE__MEMORY_H
  87118. #define FLAC__PRIVATE__MEMORY_H
  87119. #ifdef HAVE_CONFIG_H
  87120. #include <config.h>
  87121. #endif
  87122. #include <stdlib.h> /* for size_t */
  87123. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  87124. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  87125. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  87126. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  87127. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  87128. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87129. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  87130. #endif
  87131. #endif
  87132. /*** End of inlined file: memory.h ***/
  87133. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  87134. {
  87135. void *x;
  87136. FLAC__ASSERT(0 != aligned_address);
  87137. #ifdef FLAC__ALIGN_MALLOC_DATA
  87138. x = safe_malloc_add_2op_(bytes, /*+*/31);
  87139. #ifdef SIZEOF_VOIDP
  87140. #if SIZEOF_VOIDP == 4
  87141. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87142. #elif SIZEOF_VOIDP == 8
  87143. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87144. #else
  87145. # error Unsupported sizeof(void*)
  87146. #endif
  87147. #else
  87148. if(sizeof(void*) == sizeof(unsigned))
  87149. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87150. else if(sizeof(void*) == sizeof(FLAC__uint64))
  87151. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87152. else
  87153. return 0;
  87154. #endif
  87155. #else
  87156. x = safe_malloc_(bytes);
  87157. *aligned_address = x;
  87158. #endif
  87159. return x;
  87160. }
  87161. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  87162. {
  87163. FLAC__int32 *pu; /* unaligned pointer */
  87164. union { /* union needed to comply with C99 pointer aliasing rules */
  87165. FLAC__int32 *pa; /* aligned pointer */
  87166. void *pv; /* aligned pointer alias */
  87167. } u;
  87168. FLAC__ASSERT(elements > 0);
  87169. FLAC__ASSERT(0 != unaligned_pointer);
  87170. FLAC__ASSERT(0 != aligned_pointer);
  87171. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87172. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  87173. if(0 == pu) {
  87174. return false;
  87175. }
  87176. else {
  87177. if(*unaligned_pointer != 0)
  87178. free(*unaligned_pointer);
  87179. *unaligned_pointer = pu;
  87180. *aligned_pointer = u.pa;
  87181. return true;
  87182. }
  87183. }
  87184. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  87185. {
  87186. FLAC__uint32 *pu; /* unaligned pointer */
  87187. union { /* union needed to comply with C99 pointer aliasing rules */
  87188. FLAC__uint32 *pa; /* aligned pointer */
  87189. void *pv; /* aligned pointer alias */
  87190. } u;
  87191. FLAC__ASSERT(elements > 0);
  87192. FLAC__ASSERT(0 != unaligned_pointer);
  87193. FLAC__ASSERT(0 != aligned_pointer);
  87194. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87195. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87196. if(0 == pu) {
  87197. return false;
  87198. }
  87199. else {
  87200. if(*unaligned_pointer != 0)
  87201. free(*unaligned_pointer);
  87202. *unaligned_pointer = pu;
  87203. *aligned_pointer = u.pa;
  87204. return true;
  87205. }
  87206. }
  87207. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  87208. {
  87209. FLAC__uint64 *pu; /* unaligned pointer */
  87210. union { /* union needed to comply with C99 pointer aliasing rules */
  87211. FLAC__uint64 *pa; /* aligned pointer */
  87212. void *pv; /* aligned pointer alias */
  87213. } u;
  87214. FLAC__ASSERT(elements > 0);
  87215. FLAC__ASSERT(0 != unaligned_pointer);
  87216. FLAC__ASSERT(0 != aligned_pointer);
  87217. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87218. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87219. if(0 == pu) {
  87220. return false;
  87221. }
  87222. else {
  87223. if(*unaligned_pointer != 0)
  87224. free(*unaligned_pointer);
  87225. *unaligned_pointer = pu;
  87226. *aligned_pointer = u.pa;
  87227. return true;
  87228. }
  87229. }
  87230. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  87231. {
  87232. unsigned *pu; /* unaligned pointer */
  87233. union { /* union needed to comply with C99 pointer aliasing rules */
  87234. unsigned *pa; /* aligned pointer */
  87235. void *pv; /* aligned pointer alias */
  87236. } u;
  87237. FLAC__ASSERT(elements > 0);
  87238. FLAC__ASSERT(0 != unaligned_pointer);
  87239. FLAC__ASSERT(0 != aligned_pointer);
  87240. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87241. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87242. if(0 == pu) {
  87243. return false;
  87244. }
  87245. else {
  87246. if(*unaligned_pointer != 0)
  87247. free(*unaligned_pointer);
  87248. *unaligned_pointer = pu;
  87249. *aligned_pointer = u.pa;
  87250. return true;
  87251. }
  87252. }
  87253. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87254. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  87255. {
  87256. FLAC__real *pu; /* unaligned pointer */
  87257. union { /* union needed to comply with C99 pointer aliasing rules */
  87258. FLAC__real *pa; /* aligned pointer */
  87259. void *pv; /* aligned pointer alias */
  87260. } u;
  87261. FLAC__ASSERT(elements > 0);
  87262. FLAC__ASSERT(0 != unaligned_pointer);
  87263. FLAC__ASSERT(0 != aligned_pointer);
  87264. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87265. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87266. if(0 == pu) {
  87267. return false;
  87268. }
  87269. else {
  87270. if(*unaligned_pointer != 0)
  87271. free(*unaligned_pointer);
  87272. *unaligned_pointer = pu;
  87273. *aligned_pointer = u.pa;
  87274. return true;
  87275. }
  87276. }
  87277. #endif
  87278. #endif
  87279. /*** End of inlined file: memory.c ***/
  87280. /*** Start of inlined file: stream_decoder.c ***/
  87281. /*** Start of inlined file: juce_FlacHeader.h ***/
  87282. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87283. // tasks..
  87284. #define VERSION "1.2.1"
  87285. #define FLAC__NO_DLL 1
  87286. #if JUCE_MSVC
  87287. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87288. #endif
  87289. #if JUCE_MAC
  87290. #define FLAC__SYS_DARWIN 1
  87291. #endif
  87292. /*** End of inlined file: juce_FlacHeader.h ***/
  87293. #if JUCE_USE_FLAC
  87294. #if HAVE_CONFIG_H
  87295. # include <config.h>
  87296. #endif
  87297. #if defined _MSC_VER || defined __MINGW32__
  87298. #include <io.h> /* for _setmode() */
  87299. #include <fcntl.h> /* for _O_BINARY */
  87300. #endif
  87301. #if defined __CYGWIN__ || defined __EMX__
  87302. #include <io.h> /* for setmode(), O_BINARY */
  87303. #include <fcntl.h> /* for _O_BINARY */
  87304. #endif
  87305. #include <stdio.h>
  87306. #include <stdlib.h> /* for malloc() */
  87307. #include <string.h> /* for memset/memcpy() */
  87308. #include <sys/stat.h> /* for stat() */
  87309. #include <sys/types.h> /* for off_t */
  87310. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  87311. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  87312. #define fseeko fseek
  87313. #define ftello ftell
  87314. #endif
  87315. #endif
  87316. /*** Start of inlined file: stream_decoder.h ***/
  87317. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  87318. #define FLAC__PROTECTED__STREAM_DECODER_H
  87319. #if FLAC__HAS_OGG
  87320. #include "include/private/ogg_decoder_aspect.h"
  87321. #endif
  87322. typedef struct FLAC__StreamDecoderProtected {
  87323. FLAC__StreamDecoderState state;
  87324. unsigned channels;
  87325. FLAC__ChannelAssignment channel_assignment;
  87326. unsigned bits_per_sample;
  87327. unsigned sample_rate; /* in Hz */
  87328. unsigned blocksize; /* in samples (per channel) */
  87329. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  87330. #if FLAC__HAS_OGG
  87331. FLAC__OggDecoderAspect ogg_decoder_aspect;
  87332. #endif
  87333. } FLAC__StreamDecoderProtected;
  87334. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  87335. #endif
  87336. /*** End of inlined file: stream_decoder.h ***/
  87337. #ifdef max
  87338. #undef max
  87339. #endif
  87340. #define max(a,b) ((a)>(b)?(a):(b))
  87341. #ifdef _MSC_VER
  87342. #define FLAC__U64L(x) x
  87343. #else
  87344. #define FLAC__U64L(x) x##LLU
  87345. #endif
  87346. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  87347. #if FLAC__HAS_OGG
  87348. 1
  87349. #else
  87350. 0
  87351. #endif
  87352. ;
  87353. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  87354. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  87355. static FILE *get_binary_stdin_(void);
  87356. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  87357. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  87358. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  87359. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  87360. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87361. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87362. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  87363. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  87364. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  87365. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  87366. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  87367. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  87368. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  87369. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87370. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87371. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87372. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87373. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87374. 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);
  87375. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  87376. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  87377. #if FLAC__HAS_OGG
  87378. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  87379. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87380. #endif
  87381. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  87382. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  87383. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87384. #if FLAC__HAS_OGG
  87385. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87386. #endif
  87387. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87388. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  87389. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  87390. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  87391. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  87392. typedef struct FLAC__StreamDecoderPrivate {
  87393. #if FLAC__HAS_OGG
  87394. FLAC__bool is_ogg;
  87395. #endif
  87396. FLAC__StreamDecoderReadCallback read_callback;
  87397. FLAC__StreamDecoderSeekCallback seek_callback;
  87398. FLAC__StreamDecoderTellCallback tell_callback;
  87399. FLAC__StreamDecoderLengthCallback length_callback;
  87400. FLAC__StreamDecoderEofCallback eof_callback;
  87401. FLAC__StreamDecoderWriteCallback write_callback;
  87402. FLAC__StreamDecoderMetadataCallback metadata_callback;
  87403. FLAC__StreamDecoderErrorCallback error_callback;
  87404. 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[]);
  87405. 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[]);
  87406. 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[]);
  87407. 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[]);
  87408. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  87409. void *client_data;
  87410. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  87411. FLAC__BitReader *input;
  87412. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  87413. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  87414. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  87415. unsigned output_capacity, output_channels;
  87416. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  87417. FLAC__uint64 samples_decoded;
  87418. FLAC__bool has_stream_info, has_seek_table;
  87419. FLAC__StreamMetadata stream_info;
  87420. FLAC__StreamMetadata seek_table;
  87421. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  87422. FLAC__byte *metadata_filter_ids;
  87423. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  87424. FLAC__Frame frame;
  87425. FLAC__bool cached; /* true if there is a byte in lookahead */
  87426. FLAC__CPUInfo cpuinfo;
  87427. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  87428. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  87429. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  87430. 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 */
  87431. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  87432. FLAC__bool is_seeking;
  87433. FLAC__MD5Context md5context;
  87434. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  87435. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  87436. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  87437. FLAC__uint64 target_sample;
  87438. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  87439. #if FLAC__HAS_OGG
  87440. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  87441. #endif
  87442. } FLAC__StreamDecoderPrivate;
  87443. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  87444. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  87445. "FLAC__STREAM_DECODER_READ_METADATA",
  87446. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  87447. "FLAC__STREAM_DECODER_READ_FRAME",
  87448. "FLAC__STREAM_DECODER_END_OF_STREAM",
  87449. "FLAC__STREAM_DECODER_OGG_ERROR",
  87450. "FLAC__STREAM_DECODER_SEEK_ERROR",
  87451. "FLAC__STREAM_DECODER_ABORTED",
  87452. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  87453. "FLAC__STREAM_DECODER_UNINITIALIZED"
  87454. };
  87455. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  87456. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  87457. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  87458. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  87459. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  87460. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  87461. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  87462. };
  87463. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  87464. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  87465. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  87466. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  87467. };
  87468. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  87469. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  87470. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  87471. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  87472. };
  87473. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  87474. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  87475. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  87476. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  87477. };
  87478. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  87479. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  87480. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  87481. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  87482. };
  87483. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  87484. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  87485. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  87486. };
  87487. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  87488. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  87489. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  87490. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  87491. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  87492. };
  87493. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  87494. {
  87495. FLAC__StreamDecoder *decoder;
  87496. unsigned i;
  87497. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  87498. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  87499. if(decoder == 0) {
  87500. return 0;
  87501. }
  87502. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  87503. if(decoder->protected_ == 0) {
  87504. free(decoder);
  87505. return 0;
  87506. }
  87507. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  87508. if(decoder->private_ == 0) {
  87509. free(decoder->protected_);
  87510. free(decoder);
  87511. return 0;
  87512. }
  87513. decoder->private_->input = FLAC__bitreader_new();
  87514. if(decoder->private_->input == 0) {
  87515. free(decoder->private_);
  87516. free(decoder->protected_);
  87517. free(decoder);
  87518. return 0;
  87519. }
  87520. decoder->private_->metadata_filter_ids_capacity = 16;
  87521. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  87522. FLAC__bitreader_delete(decoder->private_->input);
  87523. free(decoder->private_);
  87524. free(decoder->protected_);
  87525. free(decoder);
  87526. return 0;
  87527. }
  87528. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87529. decoder->private_->output[i] = 0;
  87530. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87531. }
  87532. decoder->private_->output_capacity = 0;
  87533. decoder->private_->output_channels = 0;
  87534. decoder->private_->has_seek_table = false;
  87535. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87536. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87537. decoder->private_->file = 0;
  87538. set_defaults_dec(decoder);
  87539. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87540. return decoder;
  87541. }
  87542. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87543. {
  87544. unsigned i;
  87545. FLAC__ASSERT(0 != decoder);
  87546. FLAC__ASSERT(0 != decoder->protected_);
  87547. FLAC__ASSERT(0 != decoder->private_);
  87548. FLAC__ASSERT(0 != decoder->private_->input);
  87549. (void)FLAC__stream_decoder_finish(decoder);
  87550. if(0 != decoder->private_->metadata_filter_ids)
  87551. free(decoder->private_->metadata_filter_ids);
  87552. FLAC__bitreader_delete(decoder->private_->input);
  87553. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87554. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87555. free(decoder->private_);
  87556. free(decoder->protected_);
  87557. free(decoder);
  87558. }
  87559. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87560. FLAC__StreamDecoder *decoder,
  87561. FLAC__StreamDecoderReadCallback read_callback,
  87562. FLAC__StreamDecoderSeekCallback seek_callback,
  87563. FLAC__StreamDecoderTellCallback tell_callback,
  87564. FLAC__StreamDecoderLengthCallback length_callback,
  87565. FLAC__StreamDecoderEofCallback eof_callback,
  87566. FLAC__StreamDecoderWriteCallback write_callback,
  87567. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87568. FLAC__StreamDecoderErrorCallback error_callback,
  87569. void *client_data,
  87570. FLAC__bool is_ogg
  87571. )
  87572. {
  87573. FLAC__ASSERT(0 != decoder);
  87574. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87575. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87576. #if !FLAC__HAS_OGG
  87577. if(is_ogg)
  87578. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87579. #endif
  87580. if(
  87581. 0 == read_callback ||
  87582. 0 == write_callback ||
  87583. 0 == error_callback ||
  87584. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87585. )
  87586. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87587. #if FLAC__HAS_OGG
  87588. decoder->private_->is_ogg = is_ogg;
  87589. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87590. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87591. #endif
  87592. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87593. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87594. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87595. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87596. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87597. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87598. #ifndef FLAC__NO_ASM
  87599. if(decoder->private_->cpuinfo.use_asm) {
  87600. #ifdef FLAC__CPU_IA32
  87601. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87602. #ifdef FLAC__HAS_NASM
  87603. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87604. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87605. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87606. #endif
  87607. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87608. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87609. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87610. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87611. }
  87612. else {
  87613. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87614. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87615. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87616. }
  87617. #endif
  87618. #elif defined FLAC__CPU_PPC
  87619. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87620. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87621. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87622. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87623. }
  87624. #endif
  87625. }
  87626. #endif
  87627. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87628. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87629. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87630. }
  87631. decoder->private_->read_callback = read_callback;
  87632. decoder->private_->seek_callback = seek_callback;
  87633. decoder->private_->tell_callback = tell_callback;
  87634. decoder->private_->length_callback = length_callback;
  87635. decoder->private_->eof_callback = eof_callback;
  87636. decoder->private_->write_callback = write_callback;
  87637. decoder->private_->metadata_callback = metadata_callback;
  87638. decoder->private_->error_callback = error_callback;
  87639. decoder->private_->client_data = client_data;
  87640. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87641. decoder->private_->samples_decoded = 0;
  87642. decoder->private_->has_stream_info = false;
  87643. decoder->private_->cached = false;
  87644. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87645. decoder->private_->is_seeking = false;
  87646. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87647. if(!FLAC__stream_decoder_reset(decoder)) {
  87648. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87649. }
  87650. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87651. }
  87652. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87653. FLAC__StreamDecoder *decoder,
  87654. FLAC__StreamDecoderReadCallback read_callback,
  87655. FLAC__StreamDecoderSeekCallback seek_callback,
  87656. FLAC__StreamDecoderTellCallback tell_callback,
  87657. FLAC__StreamDecoderLengthCallback length_callback,
  87658. FLAC__StreamDecoderEofCallback eof_callback,
  87659. FLAC__StreamDecoderWriteCallback write_callback,
  87660. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87661. FLAC__StreamDecoderErrorCallback error_callback,
  87662. void *client_data
  87663. )
  87664. {
  87665. return init_stream_internal_dec(
  87666. decoder,
  87667. read_callback,
  87668. seek_callback,
  87669. tell_callback,
  87670. length_callback,
  87671. eof_callback,
  87672. write_callback,
  87673. metadata_callback,
  87674. error_callback,
  87675. client_data,
  87676. false
  87677. );
  87678. }
  87679. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87680. FLAC__StreamDecoder *decoder,
  87681. FLAC__StreamDecoderReadCallback read_callback,
  87682. FLAC__StreamDecoderSeekCallback seek_callback,
  87683. FLAC__StreamDecoderTellCallback tell_callback,
  87684. FLAC__StreamDecoderLengthCallback length_callback,
  87685. FLAC__StreamDecoderEofCallback eof_callback,
  87686. FLAC__StreamDecoderWriteCallback write_callback,
  87687. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87688. FLAC__StreamDecoderErrorCallback error_callback,
  87689. void *client_data
  87690. )
  87691. {
  87692. return init_stream_internal_dec(
  87693. decoder,
  87694. read_callback,
  87695. seek_callback,
  87696. tell_callback,
  87697. length_callback,
  87698. eof_callback,
  87699. write_callback,
  87700. metadata_callback,
  87701. error_callback,
  87702. client_data,
  87703. true
  87704. );
  87705. }
  87706. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87707. FLAC__StreamDecoder *decoder,
  87708. FILE *file,
  87709. FLAC__StreamDecoderWriteCallback write_callback,
  87710. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87711. FLAC__StreamDecoderErrorCallback error_callback,
  87712. void *client_data,
  87713. FLAC__bool is_ogg
  87714. )
  87715. {
  87716. FLAC__ASSERT(0 != decoder);
  87717. FLAC__ASSERT(0 != file);
  87718. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87719. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87720. if(0 == write_callback || 0 == error_callback)
  87721. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87722. if(file == stdin)
  87723. file = get_binary_stdin_(); /* just to be safe */
  87724. decoder->private_->file = file;
  87725. return init_stream_internal_dec(
  87726. decoder,
  87727. file_read_callback_dec,
  87728. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87729. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87730. decoder->private_->file == stdin? 0: file_length_callback_,
  87731. file_eof_callback_,
  87732. write_callback,
  87733. metadata_callback,
  87734. error_callback,
  87735. client_data,
  87736. is_ogg
  87737. );
  87738. }
  87739. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87740. FLAC__StreamDecoder *decoder,
  87741. FILE *file,
  87742. FLAC__StreamDecoderWriteCallback write_callback,
  87743. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87744. FLAC__StreamDecoderErrorCallback error_callback,
  87745. void *client_data
  87746. )
  87747. {
  87748. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87749. }
  87750. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87751. FLAC__StreamDecoder *decoder,
  87752. FILE *file,
  87753. FLAC__StreamDecoderWriteCallback write_callback,
  87754. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87755. FLAC__StreamDecoderErrorCallback error_callback,
  87756. void *client_data
  87757. )
  87758. {
  87759. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87760. }
  87761. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87762. FLAC__StreamDecoder *decoder,
  87763. const char *filename,
  87764. FLAC__StreamDecoderWriteCallback write_callback,
  87765. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87766. FLAC__StreamDecoderErrorCallback error_callback,
  87767. void *client_data,
  87768. FLAC__bool is_ogg
  87769. )
  87770. {
  87771. FILE *file;
  87772. FLAC__ASSERT(0 != decoder);
  87773. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87774. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87775. if(0 == write_callback || 0 == error_callback)
  87776. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87777. file = filename? fopen(filename, "rb") : stdin;
  87778. if(0 == file)
  87779. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87780. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87781. }
  87782. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87783. FLAC__StreamDecoder *decoder,
  87784. const char *filename,
  87785. FLAC__StreamDecoderWriteCallback write_callback,
  87786. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87787. FLAC__StreamDecoderErrorCallback error_callback,
  87788. void *client_data
  87789. )
  87790. {
  87791. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87792. }
  87793. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87794. FLAC__StreamDecoder *decoder,
  87795. const char *filename,
  87796. FLAC__StreamDecoderWriteCallback write_callback,
  87797. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87798. FLAC__StreamDecoderErrorCallback error_callback,
  87799. void *client_data
  87800. )
  87801. {
  87802. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87803. }
  87804. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87805. {
  87806. FLAC__bool md5_failed = false;
  87807. unsigned i;
  87808. FLAC__ASSERT(0 != decoder);
  87809. FLAC__ASSERT(0 != decoder->private_);
  87810. FLAC__ASSERT(0 != decoder->protected_);
  87811. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87812. return true;
  87813. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87814. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87815. free(decoder->private_->seek_table.data.seek_table.points);
  87816. decoder->private_->seek_table.data.seek_table.points = 0;
  87817. decoder->private_->has_seek_table = false;
  87818. }
  87819. FLAC__bitreader_free(decoder->private_->input);
  87820. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87821. if(0 != decoder->private_->output[i]) {
  87822. free(decoder->private_->output[i]-4);
  87823. decoder->private_->output[i] = 0;
  87824. }
  87825. if(0 != decoder->private_->residual_unaligned[i]) {
  87826. free(decoder->private_->residual_unaligned[i]);
  87827. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87828. }
  87829. }
  87830. decoder->private_->output_capacity = 0;
  87831. decoder->private_->output_channels = 0;
  87832. #if FLAC__HAS_OGG
  87833. if(decoder->private_->is_ogg)
  87834. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87835. #endif
  87836. if(0 != decoder->private_->file) {
  87837. if(decoder->private_->file != stdin)
  87838. fclose(decoder->private_->file);
  87839. decoder->private_->file = 0;
  87840. }
  87841. if(decoder->private_->do_md5_checking) {
  87842. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87843. md5_failed = true;
  87844. }
  87845. decoder->private_->is_seeking = false;
  87846. set_defaults_dec(decoder);
  87847. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87848. return !md5_failed;
  87849. }
  87850. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87851. {
  87852. FLAC__ASSERT(0 != decoder);
  87853. FLAC__ASSERT(0 != decoder->private_);
  87854. FLAC__ASSERT(0 != decoder->protected_);
  87855. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87856. return false;
  87857. #if FLAC__HAS_OGG
  87858. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87859. return true;
  87860. #else
  87861. (void)value;
  87862. return false;
  87863. #endif
  87864. }
  87865. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87866. {
  87867. FLAC__ASSERT(0 != decoder);
  87868. FLAC__ASSERT(0 != decoder->protected_);
  87869. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87870. return false;
  87871. decoder->protected_->md5_checking = value;
  87872. return true;
  87873. }
  87874. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87875. {
  87876. FLAC__ASSERT(0 != decoder);
  87877. FLAC__ASSERT(0 != decoder->private_);
  87878. FLAC__ASSERT(0 != decoder->protected_);
  87879. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87880. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87881. return false;
  87882. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87883. return false;
  87884. decoder->private_->metadata_filter[type] = true;
  87885. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87886. decoder->private_->metadata_filter_ids_count = 0;
  87887. return true;
  87888. }
  87889. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87890. {
  87891. FLAC__ASSERT(0 != decoder);
  87892. FLAC__ASSERT(0 != decoder->private_);
  87893. FLAC__ASSERT(0 != decoder->protected_);
  87894. FLAC__ASSERT(0 != id);
  87895. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87896. return false;
  87897. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87898. return true;
  87899. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87900. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87901. 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))) {
  87902. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87903. return false;
  87904. }
  87905. decoder->private_->metadata_filter_ids_capacity *= 2;
  87906. }
  87907. 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));
  87908. decoder->private_->metadata_filter_ids_count++;
  87909. return true;
  87910. }
  87911. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87912. {
  87913. unsigned i;
  87914. FLAC__ASSERT(0 != decoder);
  87915. FLAC__ASSERT(0 != decoder->private_);
  87916. FLAC__ASSERT(0 != decoder->protected_);
  87917. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87918. return false;
  87919. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87920. decoder->private_->metadata_filter[i] = true;
  87921. decoder->private_->metadata_filter_ids_count = 0;
  87922. return true;
  87923. }
  87924. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87925. {
  87926. FLAC__ASSERT(0 != decoder);
  87927. FLAC__ASSERT(0 != decoder->private_);
  87928. FLAC__ASSERT(0 != decoder->protected_);
  87929. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87930. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87931. return false;
  87932. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87933. return false;
  87934. decoder->private_->metadata_filter[type] = false;
  87935. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87936. decoder->private_->metadata_filter_ids_count = 0;
  87937. return true;
  87938. }
  87939. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87940. {
  87941. FLAC__ASSERT(0 != decoder);
  87942. FLAC__ASSERT(0 != decoder->private_);
  87943. FLAC__ASSERT(0 != decoder->protected_);
  87944. FLAC__ASSERT(0 != id);
  87945. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87946. return false;
  87947. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87948. return true;
  87949. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87950. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87951. 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))) {
  87952. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87953. return false;
  87954. }
  87955. decoder->private_->metadata_filter_ids_capacity *= 2;
  87956. }
  87957. 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));
  87958. decoder->private_->metadata_filter_ids_count++;
  87959. return true;
  87960. }
  87961. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87962. {
  87963. FLAC__ASSERT(0 != decoder);
  87964. FLAC__ASSERT(0 != decoder->private_);
  87965. FLAC__ASSERT(0 != decoder->protected_);
  87966. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87967. return false;
  87968. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87969. decoder->private_->metadata_filter_ids_count = 0;
  87970. return true;
  87971. }
  87972. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87973. {
  87974. FLAC__ASSERT(0 != decoder);
  87975. FLAC__ASSERT(0 != decoder->protected_);
  87976. return decoder->protected_->state;
  87977. }
  87978. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87979. {
  87980. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87981. }
  87982. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87983. {
  87984. FLAC__ASSERT(0 != decoder);
  87985. FLAC__ASSERT(0 != decoder->protected_);
  87986. return decoder->protected_->md5_checking;
  87987. }
  87988. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87989. {
  87990. FLAC__ASSERT(0 != decoder);
  87991. FLAC__ASSERT(0 != decoder->protected_);
  87992. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87993. }
  87994. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87995. {
  87996. FLAC__ASSERT(0 != decoder);
  87997. FLAC__ASSERT(0 != decoder->protected_);
  87998. return decoder->protected_->channels;
  87999. }
  88000. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  88001. {
  88002. FLAC__ASSERT(0 != decoder);
  88003. FLAC__ASSERT(0 != decoder->protected_);
  88004. return decoder->protected_->channel_assignment;
  88005. }
  88006. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  88007. {
  88008. FLAC__ASSERT(0 != decoder);
  88009. FLAC__ASSERT(0 != decoder->protected_);
  88010. return decoder->protected_->bits_per_sample;
  88011. }
  88012. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  88013. {
  88014. FLAC__ASSERT(0 != decoder);
  88015. FLAC__ASSERT(0 != decoder->protected_);
  88016. return decoder->protected_->sample_rate;
  88017. }
  88018. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  88019. {
  88020. FLAC__ASSERT(0 != decoder);
  88021. FLAC__ASSERT(0 != decoder->protected_);
  88022. return decoder->protected_->blocksize;
  88023. }
  88024. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  88025. {
  88026. FLAC__ASSERT(0 != decoder);
  88027. FLAC__ASSERT(0 != decoder->private_);
  88028. FLAC__ASSERT(0 != position);
  88029. #if FLAC__HAS_OGG
  88030. if(decoder->private_->is_ogg)
  88031. return false;
  88032. #endif
  88033. if(0 == decoder->private_->tell_callback)
  88034. return false;
  88035. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  88036. return false;
  88037. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  88038. return false;
  88039. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  88040. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  88041. return true;
  88042. }
  88043. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  88044. {
  88045. FLAC__ASSERT(0 != decoder);
  88046. FLAC__ASSERT(0 != decoder->private_);
  88047. FLAC__ASSERT(0 != decoder->protected_);
  88048. decoder->private_->samples_decoded = 0;
  88049. decoder->private_->do_md5_checking = false;
  88050. #if FLAC__HAS_OGG
  88051. if(decoder->private_->is_ogg)
  88052. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  88053. #endif
  88054. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  88055. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88056. return false;
  88057. }
  88058. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88059. return true;
  88060. }
  88061. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  88062. {
  88063. FLAC__ASSERT(0 != decoder);
  88064. FLAC__ASSERT(0 != decoder->private_);
  88065. FLAC__ASSERT(0 != decoder->protected_);
  88066. if(!FLAC__stream_decoder_flush(decoder)) {
  88067. return false;
  88068. }
  88069. #if FLAC__HAS_OGG
  88070. if(decoder->private_->is_ogg)
  88071. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  88072. #endif
  88073. if(!decoder->private_->internal_reset_hack) {
  88074. if(decoder->private_->file == stdin)
  88075. return false; /* can't rewind stdin, reset fails */
  88076. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  88077. return false; /* seekable and seek fails, reset fails */
  88078. }
  88079. else
  88080. decoder->private_->internal_reset_hack = false;
  88081. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  88082. decoder->private_->has_stream_info = false;
  88083. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  88084. free(decoder->private_->seek_table.data.seek_table.points);
  88085. decoder->private_->seek_table.data.seek_table.points = 0;
  88086. decoder->private_->has_seek_table = false;
  88087. }
  88088. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  88089. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  88090. FLAC__MD5Init(&decoder->private_->md5context);
  88091. decoder->private_->first_frame_offset = 0;
  88092. decoder->private_->unparseable_frame_count = 0;
  88093. return true;
  88094. }
  88095. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  88096. {
  88097. FLAC__bool got_a_frame;
  88098. FLAC__ASSERT(0 != decoder);
  88099. FLAC__ASSERT(0 != decoder->protected_);
  88100. while(1) {
  88101. switch(decoder->protected_->state) {
  88102. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88103. if(!find_metadata_(decoder))
  88104. return false; /* above function sets the status for us */
  88105. break;
  88106. case FLAC__STREAM_DECODER_READ_METADATA:
  88107. if(!read_metadata_(decoder))
  88108. return false; /* above function sets the status for us */
  88109. else
  88110. return true;
  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=*/true))
  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_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  88131. {
  88132. FLAC__ASSERT(0 != decoder);
  88133. FLAC__ASSERT(0 != decoder->protected_);
  88134. while(1) {
  88135. switch(decoder->protected_->state) {
  88136. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88137. if(!find_metadata_(decoder))
  88138. return false; /* above function sets the status for us */
  88139. break;
  88140. case FLAC__STREAM_DECODER_READ_METADATA:
  88141. if(!read_metadata_(decoder))
  88142. return false; /* above function sets the status for us */
  88143. break;
  88144. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88145. case FLAC__STREAM_DECODER_READ_FRAME:
  88146. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88147. case FLAC__STREAM_DECODER_ABORTED:
  88148. return true;
  88149. default:
  88150. FLAC__ASSERT(0);
  88151. return false;
  88152. }
  88153. }
  88154. }
  88155. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  88156. {
  88157. FLAC__bool dummy;
  88158. FLAC__ASSERT(0 != decoder);
  88159. FLAC__ASSERT(0 != decoder->protected_);
  88160. while(1) {
  88161. switch(decoder->protected_->state) {
  88162. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88163. if(!find_metadata_(decoder))
  88164. return false; /* above function sets the status for us */
  88165. break;
  88166. case FLAC__STREAM_DECODER_READ_METADATA:
  88167. if(!read_metadata_(decoder))
  88168. return false; /* above function sets the status for us */
  88169. break;
  88170. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88171. if(!frame_sync_(decoder))
  88172. return true; /* above function sets the status for us */
  88173. break;
  88174. case FLAC__STREAM_DECODER_READ_FRAME:
  88175. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  88176. return false; /* above function sets the status for us */
  88177. break;
  88178. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88179. case FLAC__STREAM_DECODER_ABORTED:
  88180. return true;
  88181. default:
  88182. FLAC__ASSERT(0);
  88183. return false;
  88184. }
  88185. }
  88186. }
  88187. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  88188. {
  88189. FLAC__bool got_a_frame;
  88190. FLAC__ASSERT(0 != decoder);
  88191. FLAC__ASSERT(0 != decoder->protected_);
  88192. while(1) {
  88193. switch(decoder->protected_->state) {
  88194. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88195. case FLAC__STREAM_DECODER_READ_METADATA:
  88196. return false; /* above function sets the status for us */
  88197. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88198. if(!frame_sync_(decoder))
  88199. return true; /* above function sets the status for us */
  88200. break;
  88201. case FLAC__STREAM_DECODER_READ_FRAME:
  88202. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  88203. return false; /* above function sets the status for us */
  88204. if(got_a_frame)
  88205. return true; /* above function sets the status for us */
  88206. break;
  88207. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88208. case FLAC__STREAM_DECODER_ABORTED:
  88209. return true;
  88210. default:
  88211. FLAC__ASSERT(0);
  88212. return false;
  88213. }
  88214. }
  88215. }
  88216. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  88217. {
  88218. FLAC__uint64 length;
  88219. FLAC__ASSERT(0 != decoder);
  88220. if(
  88221. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  88222. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  88223. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  88224. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  88225. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  88226. )
  88227. return false;
  88228. if(0 == decoder->private_->seek_callback)
  88229. return false;
  88230. FLAC__ASSERT(decoder->private_->seek_callback);
  88231. FLAC__ASSERT(decoder->private_->tell_callback);
  88232. FLAC__ASSERT(decoder->private_->length_callback);
  88233. FLAC__ASSERT(decoder->private_->eof_callback);
  88234. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  88235. return false;
  88236. decoder->private_->is_seeking = true;
  88237. decoder->private_->do_md5_checking = false;
  88238. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  88239. decoder->private_->is_seeking = false;
  88240. return false;
  88241. }
  88242. if(
  88243. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  88244. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  88245. ) {
  88246. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  88247. decoder->private_->is_seeking = false;
  88248. return false;
  88249. }
  88250. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88251. decoder->private_->is_seeking = false;
  88252. return false;
  88253. }
  88254. }
  88255. {
  88256. const FLAC__bool ok =
  88257. #if FLAC__HAS_OGG
  88258. decoder->private_->is_ogg?
  88259. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  88260. #endif
  88261. seek_to_absolute_sample_(decoder, length, sample)
  88262. ;
  88263. decoder->private_->is_seeking = false;
  88264. return ok;
  88265. }
  88266. }
  88267. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  88268. {
  88269. FLAC__ASSERT(0 != decoder);
  88270. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88271. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  88272. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  88273. }
  88274. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  88275. {
  88276. #if FLAC__HAS_OGG
  88277. decoder->private_->is_ogg = false;
  88278. #endif
  88279. decoder->private_->read_callback = 0;
  88280. decoder->private_->seek_callback = 0;
  88281. decoder->private_->tell_callback = 0;
  88282. decoder->private_->length_callback = 0;
  88283. decoder->private_->eof_callback = 0;
  88284. decoder->private_->write_callback = 0;
  88285. decoder->private_->metadata_callback = 0;
  88286. decoder->private_->error_callback = 0;
  88287. decoder->private_->client_data = 0;
  88288. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  88289. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  88290. decoder->private_->metadata_filter_ids_count = 0;
  88291. decoder->protected_->md5_checking = false;
  88292. #if FLAC__HAS_OGG
  88293. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  88294. #endif
  88295. }
  88296. FILE *get_binary_stdin_(void)
  88297. {
  88298. #if defined _MSC_VER || defined __MINGW32__
  88299. _setmode(_fileno(stdin), _O_BINARY);
  88300. #elif defined __CYGWIN__
  88301. setmode(_fileno(stdin), _O_BINARY);
  88302. #elif defined __EMX__
  88303. setmode(fileno(stdin), O_BINARY);
  88304. #endif
  88305. return stdin;
  88306. }
  88307. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  88308. {
  88309. unsigned i;
  88310. FLAC__int32 *tmp;
  88311. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  88312. return true;
  88313. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  88314. if(0 != decoder->private_->output[i]) {
  88315. free(decoder->private_->output[i]-4);
  88316. decoder->private_->output[i] = 0;
  88317. }
  88318. if(0 != decoder->private_->residual_unaligned[i]) {
  88319. free(decoder->private_->residual_unaligned[i]);
  88320. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  88321. }
  88322. }
  88323. for(i = 0; i < channels; i++) {
  88324. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  88325. if(tmp == 0) {
  88326. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88327. return false;
  88328. }
  88329. memset(tmp, 0, sizeof(FLAC__int32)*4);
  88330. decoder->private_->output[i] = tmp + 4;
  88331. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  88332. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88333. return false;
  88334. }
  88335. }
  88336. decoder->private_->output_capacity = size;
  88337. decoder->private_->output_channels = channels;
  88338. return true;
  88339. }
  88340. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  88341. {
  88342. size_t i;
  88343. FLAC__ASSERT(0 != decoder);
  88344. FLAC__ASSERT(0 != decoder->private_);
  88345. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  88346. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  88347. return true;
  88348. return false;
  88349. }
  88350. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  88351. {
  88352. FLAC__uint32 x;
  88353. unsigned i, id_;
  88354. FLAC__bool first = true;
  88355. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88356. for(i = id_ = 0; i < 4; ) {
  88357. if(decoder->private_->cached) {
  88358. x = (FLAC__uint32)decoder->private_->lookahead;
  88359. decoder->private_->cached = false;
  88360. }
  88361. else {
  88362. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88363. return false; /* read_callback_ sets the state for us */
  88364. }
  88365. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  88366. first = true;
  88367. i++;
  88368. id_ = 0;
  88369. continue;
  88370. }
  88371. if(x == ID3V2_TAG_[id_]) {
  88372. id_++;
  88373. i = 0;
  88374. if(id_ == 3) {
  88375. if(!skip_id3v2_tag_(decoder))
  88376. return false; /* skip_id3v2_tag_ sets the state for us */
  88377. }
  88378. continue;
  88379. }
  88380. id_ = 0;
  88381. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88382. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88383. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88384. return false; /* read_callback_ sets the state for us */
  88385. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88386. decoder->private_->lookahead = (FLAC__byte)x;
  88387. decoder->private_->cached = true;
  88388. }
  88389. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88390. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88391. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88392. return true;
  88393. }
  88394. }
  88395. i = 0;
  88396. if(first) {
  88397. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88398. first = false;
  88399. }
  88400. }
  88401. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  88402. return true;
  88403. }
  88404. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  88405. {
  88406. FLAC__bool is_last;
  88407. FLAC__uint32 i, x, type, length;
  88408. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88409. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  88410. return false; /* read_callback_ sets the state for us */
  88411. is_last = x? true : false;
  88412. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  88413. return false; /* read_callback_ sets the state for us */
  88414. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  88415. return false; /* read_callback_ sets the state for us */
  88416. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  88417. if(!read_metadata_streaminfo_(decoder, is_last, length))
  88418. return false;
  88419. decoder->private_->has_stream_info = true;
  88420. 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))
  88421. decoder->private_->do_md5_checking = false;
  88422. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  88423. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  88424. }
  88425. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  88426. if(!read_metadata_seektable_(decoder, is_last, length))
  88427. return false;
  88428. decoder->private_->has_seek_table = true;
  88429. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  88430. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  88431. }
  88432. else {
  88433. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  88434. unsigned real_length = length;
  88435. FLAC__StreamMetadata block;
  88436. block.is_last = is_last;
  88437. block.type = (FLAC__MetadataType)type;
  88438. block.length = length;
  88439. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  88440. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  88441. return false; /* read_callback_ sets the state for us */
  88442. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  88443. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  88444. return false;
  88445. }
  88446. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  88447. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  88448. skip_it = !skip_it;
  88449. }
  88450. if(skip_it) {
  88451. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88452. return false; /* read_callback_ sets the state for us */
  88453. }
  88454. else {
  88455. switch(type) {
  88456. case FLAC__METADATA_TYPE_PADDING:
  88457. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88458. return false; /* read_callback_ sets the state for us */
  88459. break;
  88460. case FLAC__METADATA_TYPE_APPLICATION:
  88461. if(real_length > 0) {
  88462. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  88463. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88464. return false;
  88465. }
  88466. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  88467. return false; /* read_callback_ sets the state for us */
  88468. }
  88469. else
  88470. block.data.application.data = 0;
  88471. break;
  88472. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88473. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  88474. return false;
  88475. break;
  88476. case FLAC__METADATA_TYPE_CUESHEET:
  88477. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  88478. return false;
  88479. break;
  88480. case FLAC__METADATA_TYPE_PICTURE:
  88481. if(!read_metadata_picture_(decoder, &block.data.picture))
  88482. return false;
  88483. break;
  88484. case FLAC__METADATA_TYPE_STREAMINFO:
  88485. case FLAC__METADATA_TYPE_SEEKTABLE:
  88486. FLAC__ASSERT(0);
  88487. break;
  88488. default:
  88489. if(real_length > 0) {
  88490. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  88491. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88492. return false;
  88493. }
  88494. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  88495. return false; /* read_callback_ sets the state for us */
  88496. }
  88497. else
  88498. block.data.unknown.data = 0;
  88499. break;
  88500. }
  88501. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  88502. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  88503. switch(type) {
  88504. case FLAC__METADATA_TYPE_PADDING:
  88505. break;
  88506. case FLAC__METADATA_TYPE_APPLICATION:
  88507. if(0 != block.data.application.data)
  88508. free(block.data.application.data);
  88509. break;
  88510. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88511. if(0 != block.data.vorbis_comment.vendor_string.entry)
  88512. free(block.data.vorbis_comment.vendor_string.entry);
  88513. if(block.data.vorbis_comment.num_comments > 0)
  88514. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  88515. if(0 != block.data.vorbis_comment.comments[i].entry)
  88516. free(block.data.vorbis_comment.comments[i].entry);
  88517. if(0 != block.data.vorbis_comment.comments)
  88518. free(block.data.vorbis_comment.comments);
  88519. break;
  88520. case FLAC__METADATA_TYPE_CUESHEET:
  88521. if(block.data.cue_sheet.num_tracks > 0)
  88522. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  88523. if(0 != block.data.cue_sheet.tracks[i].indices)
  88524. free(block.data.cue_sheet.tracks[i].indices);
  88525. if(0 != block.data.cue_sheet.tracks)
  88526. free(block.data.cue_sheet.tracks);
  88527. break;
  88528. case FLAC__METADATA_TYPE_PICTURE:
  88529. if(0 != block.data.picture.mime_type)
  88530. free(block.data.picture.mime_type);
  88531. if(0 != block.data.picture.description)
  88532. free(block.data.picture.description);
  88533. if(0 != block.data.picture.data)
  88534. free(block.data.picture.data);
  88535. break;
  88536. case FLAC__METADATA_TYPE_STREAMINFO:
  88537. case FLAC__METADATA_TYPE_SEEKTABLE:
  88538. FLAC__ASSERT(0);
  88539. default:
  88540. if(0 != block.data.unknown.data)
  88541. free(block.data.unknown.data);
  88542. break;
  88543. }
  88544. }
  88545. }
  88546. if(is_last) {
  88547. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88548. decoder->private_->first_frame_offset = 0;
  88549. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88550. }
  88551. return true;
  88552. }
  88553. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88554. {
  88555. FLAC__uint32 x;
  88556. unsigned bits, used_bits = 0;
  88557. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88558. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88559. decoder->private_->stream_info.is_last = is_last;
  88560. decoder->private_->stream_info.length = length;
  88561. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88562. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88563. return false; /* read_callback_ sets the state for us */
  88564. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88565. used_bits += bits;
  88566. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88567. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88568. return false; /* read_callback_ sets the state for us */
  88569. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88570. used_bits += bits;
  88571. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88572. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88573. return false; /* read_callback_ sets the state for us */
  88574. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88575. used_bits += bits;
  88576. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88577. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88578. return false; /* read_callback_ sets the state for us */
  88579. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88580. used_bits += bits;
  88581. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88582. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88583. return false; /* read_callback_ sets the state for us */
  88584. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88585. used_bits += bits;
  88586. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88587. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88588. return false; /* read_callback_ sets the state for us */
  88589. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88590. used_bits += bits;
  88591. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88592. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88593. return false; /* read_callback_ sets the state for us */
  88594. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88595. used_bits += bits;
  88596. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88597. 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))
  88598. return false; /* read_callback_ sets the state for us */
  88599. used_bits += bits;
  88600. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88601. return false; /* read_callback_ sets the state for us */
  88602. used_bits += 16*8;
  88603. FLAC__ASSERT(used_bits % 8 == 0);
  88604. length -= (used_bits / 8);
  88605. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88606. return false; /* read_callback_ sets the state for us */
  88607. return true;
  88608. }
  88609. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88610. {
  88611. FLAC__uint32 i, x;
  88612. FLAC__uint64 xx;
  88613. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88614. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88615. decoder->private_->seek_table.is_last = is_last;
  88616. decoder->private_->seek_table.length = length;
  88617. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88618. 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)))) {
  88619. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88620. return false;
  88621. }
  88622. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88623. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88624. return false; /* read_callback_ sets the state for us */
  88625. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88626. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88627. return false; /* read_callback_ sets the state for us */
  88628. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88629. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88630. return false; /* read_callback_ sets the state for us */
  88631. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88632. }
  88633. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88634. if(length > 0) {
  88635. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88636. return false; /* read_callback_ sets the state for us */
  88637. }
  88638. return true;
  88639. }
  88640. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88641. {
  88642. FLAC__uint32 i;
  88643. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88644. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88645. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88646. return false; /* read_callback_ sets the state for us */
  88647. if(obj->vendor_string.length > 0) {
  88648. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88649. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88650. return false;
  88651. }
  88652. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88653. return false; /* read_callback_ sets the state for us */
  88654. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88655. }
  88656. else
  88657. obj->vendor_string.entry = 0;
  88658. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88659. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88660. return false; /* read_callback_ sets the state for us */
  88661. if(obj->num_comments > 0) {
  88662. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88663. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88664. return false;
  88665. }
  88666. for(i = 0; i < obj->num_comments; i++) {
  88667. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88668. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88669. return false; /* read_callback_ sets the state for us */
  88670. if(obj->comments[i].length > 0) {
  88671. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88672. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88673. return false;
  88674. }
  88675. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88676. return false; /* read_callback_ sets the state for us */
  88677. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88678. }
  88679. else
  88680. obj->comments[i].entry = 0;
  88681. }
  88682. }
  88683. else {
  88684. obj->comments = 0;
  88685. }
  88686. return true;
  88687. }
  88688. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88689. {
  88690. FLAC__uint32 i, j, x;
  88691. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88692. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88693. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88694. 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))
  88695. return false; /* read_callback_ sets the state for us */
  88696. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88697. return false; /* read_callback_ sets the state for us */
  88698. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88699. return false; /* read_callback_ sets the state for us */
  88700. obj->is_cd = x? true : false;
  88701. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88702. return false; /* read_callback_ sets the state for us */
  88703. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88704. return false; /* read_callback_ sets the state for us */
  88705. obj->num_tracks = x;
  88706. if(obj->num_tracks > 0) {
  88707. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88708. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88709. return false;
  88710. }
  88711. for(i = 0; i < obj->num_tracks; i++) {
  88712. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88713. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88714. return false; /* read_callback_ sets the state for us */
  88715. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88716. return false; /* read_callback_ sets the state for us */
  88717. track->number = (FLAC__byte)x;
  88718. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88719. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88720. return false; /* read_callback_ sets the state for us */
  88721. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88722. return false; /* read_callback_ sets the state for us */
  88723. track->type = x;
  88724. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88725. return false; /* read_callback_ sets the state for us */
  88726. track->pre_emphasis = x;
  88727. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88728. return false; /* read_callback_ sets the state for us */
  88729. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88730. return false; /* read_callback_ sets the state for us */
  88731. track->num_indices = (FLAC__byte)x;
  88732. if(track->num_indices > 0) {
  88733. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88734. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88735. return false;
  88736. }
  88737. for(j = 0; j < track->num_indices; j++) {
  88738. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88739. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88740. return false; /* read_callback_ sets the state for us */
  88741. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88742. return false; /* read_callback_ sets the state for us */
  88743. index->number = (FLAC__byte)x;
  88744. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88745. return false; /* read_callback_ sets the state for us */
  88746. }
  88747. }
  88748. }
  88749. }
  88750. return true;
  88751. }
  88752. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88753. {
  88754. FLAC__uint32 x;
  88755. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88756. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88757. return false; /* read_callback_ sets the state for us */
  88758. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88759. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88760. return false; /* read_callback_ sets the state for us */
  88761. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88762. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88763. return false;
  88764. }
  88765. if(x > 0) {
  88766. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88767. return false; /* read_callback_ sets the state for us */
  88768. }
  88769. obj->mime_type[x] = '\0';
  88770. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88771. return false; /* read_callback_ sets the state for us */
  88772. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88773. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88774. return false;
  88775. }
  88776. if(x > 0) {
  88777. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88778. return false; /* read_callback_ sets the state for us */
  88779. }
  88780. obj->description[x] = '\0';
  88781. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88782. return false; /* read_callback_ sets the state for us */
  88783. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88784. return false; /* read_callback_ sets the state for us */
  88785. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88786. return false; /* read_callback_ sets the state for us */
  88787. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88788. return false; /* read_callback_ sets the state for us */
  88789. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88790. return false; /* read_callback_ sets the state for us */
  88791. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88792. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88793. return false;
  88794. }
  88795. if(obj->data_length > 0) {
  88796. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88797. return false; /* read_callback_ sets the state for us */
  88798. }
  88799. return true;
  88800. }
  88801. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88802. {
  88803. FLAC__uint32 x;
  88804. unsigned i, skip;
  88805. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88806. return false; /* read_callback_ sets the state for us */
  88807. skip = 0;
  88808. for(i = 0; i < 4; i++) {
  88809. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88810. return false; /* read_callback_ sets the state for us */
  88811. skip <<= 7;
  88812. skip |= (x & 0x7f);
  88813. }
  88814. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88815. return false; /* read_callback_ sets the state for us */
  88816. return true;
  88817. }
  88818. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88819. {
  88820. FLAC__uint32 x;
  88821. FLAC__bool first = true;
  88822. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88823. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88824. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88825. return true;
  88826. }
  88827. }
  88828. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88829. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88830. return false; /* read_callback_ sets the state for us */
  88831. }
  88832. while(1) {
  88833. if(decoder->private_->cached) {
  88834. x = (FLAC__uint32)decoder->private_->lookahead;
  88835. decoder->private_->cached = false;
  88836. }
  88837. else {
  88838. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88839. return false; /* read_callback_ sets the state for us */
  88840. }
  88841. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88842. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88843. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88844. return false; /* read_callback_ sets the state for us */
  88845. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88846. decoder->private_->lookahead = (FLAC__byte)x;
  88847. decoder->private_->cached = true;
  88848. }
  88849. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88850. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88851. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88852. return true;
  88853. }
  88854. }
  88855. if(first) {
  88856. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88857. first = false;
  88858. }
  88859. }
  88860. return true;
  88861. }
  88862. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88863. {
  88864. unsigned channel;
  88865. unsigned i;
  88866. FLAC__int32 mid, side;
  88867. unsigned frame_crc; /* the one we calculate from the input stream */
  88868. FLAC__uint32 x;
  88869. *got_a_frame = false;
  88870. frame_crc = 0;
  88871. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88872. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88873. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88874. if(!read_frame_header_(decoder))
  88875. return false;
  88876. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88877. return true;
  88878. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88879. return false;
  88880. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88881. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88882. switch(decoder->private_->frame.header.channel_assignment) {
  88883. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88884. break;
  88885. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88886. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88887. if(channel == 1)
  88888. bps++;
  88889. break;
  88890. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88891. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88892. if(channel == 0)
  88893. bps++;
  88894. break;
  88895. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88896. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88897. if(channel == 1)
  88898. bps++;
  88899. break;
  88900. default:
  88901. FLAC__ASSERT(0);
  88902. }
  88903. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88904. return false;
  88905. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88906. return true;
  88907. }
  88908. if(!read_zero_padding_(decoder))
  88909. return false;
  88910. 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) */
  88911. return true;
  88912. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88913. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88914. return false; /* read_callback_ sets the state for us */
  88915. if(frame_crc == x) {
  88916. if(do_full_decode) {
  88917. switch(decoder->private_->frame.header.channel_assignment) {
  88918. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88919. break;
  88920. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88921. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88922. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88923. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88924. break;
  88925. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88926. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88927. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88928. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88929. break;
  88930. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88931. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88932. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88933. #if 1
  88934. mid = decoder->private_->output[0][i];
  88935. side = decoder->private_->output[1][i];
  88936. mid <<= 1;
  88937. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88938. decoder->private_->output[0][i] = (mid + side) >> 1;
  88939. decoder->private_->output[1][i] = (mid - side) >> 1;
  88940. #else
  88941. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88942. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88943. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88944. #endif
  88945. }
  88946. break;
  88947. default:
  88948. FLAC__ASSERT(0);
  88949. break;
  88950. }
  88951. }
  88952. }
  88953. else {
  88954. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88955. if(do_full_decode) {
  88956. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88957. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88958. }
  88959. }
  88960. }
  88961. *got_a_frame = true;
  88962. if(decoder->private_->next_fixed_block_size)
  88963. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88964. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88965. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88966. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88967. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88968. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88969. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88970. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88971. if(do_full_decode) {
  88972. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88973. return false;
  88974. }
  88975. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88976. return true;
  88977. }
  88978. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88979. {
  88980. FLAC__uint32 x;
  88981. FLAC__uint64 xx;
  88982. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88983. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88984. unsigned raw_header_len;
  88985. FLAC__bool is_unparseable = false;
  88986. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88987. raw_header[0] = decoder->private_->header_warmup[0];
  88988. raw_header[1] = decoder->private_->header_warmup[1];
  88989. raw_header_len = 2;
  88990. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88991. is_unparseable = true;
  88992. for(i = 0; i < 2; i++) {
  88993. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88994. return false; /* read_callback_ sets the state for us */
  88995. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88996. decoder->private_->lookahead = (FLAC__byte)x;
  88997. decoder->private_->cached = true;
  88998. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88999. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89000. return true;
  89001. }
  89002. raw_header[raw_header_len++] = (FLAC__byte)x;
  89003. }
  89004. switch(x = raw_header[2] >> 4) {
  89005. case 0:
  89006. is_unparseable = true;
  89007. break;
  89008. case 1:
  89009. decoder->private_->frame.header.blocksize = 192;
  89010. break;
  89011. case 2:
  89012. case 3:
  89013. case 4:
  89014. case 5:
  89015. decoder->private_->frame.header.blocksize = 576 << (x-2);
  89016. break;
  89017. case 6:
  89018. case 7:
  89019. blocksize_hint = x;
  89020. break;
  89021. case 8:
  89022. case 9:
  89023. case 10:
  89024. case 11:
  89025. case 12:
  89026. case 13:
  89027. case 14:
  89028. case 15:
  89029. decoder->private_->frame.header.blocksize = 256 << (x-8);
  89030. break;
  89031. default:
  89032. FLAC__ASSERT(0);
  89033. break;
  89034. }
  89035. switch(x = raw_header[2] & 0x0f) {
  89036. case 0:
  89037. if(decoder->private_->has_stream_info)
  89038. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  89039. else
  89040. is_unparseable = true;
  89041. break;
  89042. case 1:
  89043. decoder->private_->frame.header.sample_rate = 88200;
  89044. break;
  89045. case 2:
  89046. decoder->private_->frame.header.sample_rate = 176400;
  89047. break;
  89048. case 3:
  89049. decoder->private_->frame.header.sample_rate = 192000;
  89050. break;
  89051. case 4:
  89052. decoder->private_->frame.header.sample_rate = 8000;
  89053. break;
  89054. case 5:
  89055. decoder->private_->frame.header.sample_rate = 16000;
  89056. break;
  89057. case 6:
  89058. decoder->private_->frame.header.sample_rate = 22050;
  89059. break;
  89060. case 7:
  89061. decoder->private_->frame.header.sample_rate = 24000;
  89062. break;
  89063. case 8:
  89064. decoder->private_->frame.header.sample_rate = 32000;
  89065. break;
  89066. case 9:
  89067. decoder->private_->frame.header.sample_rate = 44100;
  89068. break;
  89069. case 10:
  89070. decoder->private_->frame.header.sample_rate = 48000;
  89071. break;
  89072. case 11:
  89073. decoder->private_->frame.header.sample_rate = 96000;
  89074. break;
  89075. case 12:
  89076. case 13:
  89077. case 14:
  89078. sample_rate_hint = x;
  89079. break;
  89080. case 15:
  89081. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89082. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89083. return true;
  89084. default:
  89085. FLAC__ASSERT(0);
  89086. }
  89087. x = (unsigned)(raw_header[3] >> 4);
  89088. if(x & 8) {
  89089. decoder->private_->frame.header.channels = 2;
  89090. switch(x & 7) {
  89091. case 0:
  89092. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  89093. break;
  89094. case 1:
  89095. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  89096. break;
  89097. case 2:
  89098. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  89099. break;
  89100. default:
  89101. is_unparseable = true;
  89102. break;
  89103. }
  89104. }
  89105. else {
  89106. decoder->private_->frame.header.channels = (unsigned)x + 1;
  89107. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  89108. }
  89109. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  89110. case 0:
  89111. if(decoder->private_->has_stream_info)
  89112. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89113. else
  89114. is_unparseable = true;
  89115. break;
  89116. case 1:
  89117. decoder->private_->frame.header.bits_per_sample = 8;
  89118. break;
  89119. case 2:
  89120. decoder->private_->frame.header.bits_per_sample = 12;
  89121. break;
  89122. case 4:
  89123. decoder->private_->frame.header.bits_per_sample = 16;
  89124. break;
  89125. case 5:
  89126. decoder->private_->frame.header.bits_per_sample = 20;
  89127. break;
  89128. case 6:
  89129. decoder->private_->frame.header.bits_per_sample = 24;
  89130. break;
  89131. case 3:
  89132. case 7:
  89133. is_unparseable = true;
  89134. break;
  89135. default:
  89136. FLAC__ASSERT(0);
  89137. break;
  89138. }
  89139. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  89140. is_unparseable = true;
  89141. if(
  89142. raw_header[1] & 0x01 ||
  89143. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  89144. ) { /* variable blocksize */
  89145. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  89146. return false; /* read_callback_ sets the state for us */
  89147. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  89148. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89149. decoder->private_->cached = true;
  89150. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89151. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89152. return true;
  89153. }
  89154. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89155. decoder->private_->frame.header.number.sample_number = xx;
  89156. }
  89157. else { /* fixed blocksize */
  89158. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  89159. return false; /* read_callback_ sets the state for us */
  89160. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  89161. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89162. decoder->private_->cached = true;
  89163. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89164. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89165. return true;
  89166. }
  89167. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  89168. decoder->private_->frame.header.number.frame_number = x;
  89169. }
  89170. if(blocksize_hint) {
  89171. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89172. return false; /* read_callback_ sets the state for us */
  89173. raw_header[raw_header_len++] = (FLAC__byte)x;
  89174. if(blocksize_hint == 7) {
  89175. FLAC__uint32 _x;
  89176. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89177. return false; /* read_callback_ sets the state for us */
  89178. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89179. x = (x << 8) | _x;
  89180. }
  89181. decoder->private_->frame.header.blocksize = x+1;
  89182. }
  89183. if(sample_rate_hint) {
  89184. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89185. return false; /* read_callback_ sets the state for us */
  89186. raw_header[raw_header_len++] = (FLAC__byte)x;
  89187. if(sample_rate_hint != 12) {
  89188. FLAC__uint32 _x;
  89189. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89190. return false; /* read_callback_ sets the state for us */
  89191. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89192. x = (x << 8) | _x;
  89193. }
  89194. if(sample_rate_hint == 12)
  89195. decoder->private_->frame.header.sample_rate = x*1000;
  89196. else if(sample_rate_hint == 13)
  89197. decoder->private_->frame.header.sample_rate = x;
  89198. else
  89199. decoder->private_->frame.header.sample_rate = x*10;
  89200. }
  89201. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89202. return false; /* read_callback_ sets the state for us */
  89203. crc8 = (FLAC__byte)x;
  89204. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  89205. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89206. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89207. return true;
  89208. }
  89209. decoder->private_->next_fixed_block_size = 0;
  89210. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  89211. x = decoder->private_->frame.header.number.frame_number;
  89212. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89213. if(decoder->private_->fixed_block_size)
  89214. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  89215. else if(decoder->private_->has_stream_info) {
  89216. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  89217. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  89218. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89219. }
  89220. else
  89221. is_unparseable = true;
  89222. }
  89223. else if(x == 0) {
  89224. decoder->private_->frame.header.number.sample_number = 0;
  89225. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  89226. }
  89227. else {
  89228. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  89229. }
  89230. }
  89231. if(is_unparseable) {
  89232. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89233. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89234. return true;
  89235. }
  89236. return true;
  89237. }
  89238. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89239. {
  89240. FLAC__uint32 x;
  89241. FLAC__bool wasted_bits;
  89242. unsigned i;
  89243. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  89244. return false; /* read_callback_ sets the state for us */
  89245. wasted_bits = (x & 1);
  89246. x &= 0xfe;
  89247. if(wasted_bits) {
  89248. unsigned u;
  89249. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  89250. return false; /* read_callback_ sets the state for us */
  89251. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  89252. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  89253. }
  89254. else
  89255. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  89256. if(x & 0x80) {
  89257. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89258. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89259. return true;
  89260. }
  89261. else if(x == 0) {
  89262. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  89263. return false;
  89264. }
  89265. else if(x == 2) {
  89266. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  89267. return false;
  89268. }
  89269. else if(x < 16) {
  89270. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89271. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89272. return true;
  89273. }
  89274. else if(x <= 24) {
  89275. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  89276. return false;
  89277. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89278. return true;
  89279. }
  89280. else if(x < 64) {
  89281. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89282. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89283. return true;
  89284. }
  89285. else {
  89286. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  89287. return false;
  89288. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89289. return true;
  89290. }
  89291. if(wasted_bits && do_full_decode) {
  89292. x = decoder->private_->frame.subframes[channel].wasted_bits;
  89293. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89294. decoder->private_->output[channel][i] <<= x;
  89295. }
  89296. return true;
  89297. }
  89298. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89299. {
  89300. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  89301. FLAC__int32 x;
  89302. unsigned i;
  89303. FLAC__int32 *output = decoder->private_->output[channel];
  89304. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  89305. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89306. return false; /* read_callback_ sets the state for us */
  89307. subframe->value = x;
  89308. if(do_full_decode) {
  89309. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89310. output[i] = x;
  89311. }
  89312. return true;
  89313. }
  89314. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89315. {
  89316. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  89317. FLAC__int32 i32;
  89318. FLAC__uint32 u32;
  89319. unsigned u;
  89320. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  89321. subframe->residual = decoder->private_->residual[channel];
  89322. subframe->order = order;
  89323. for(u = 0; u < order; u++) {
  89324. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89325. return false; /* read_callback_ sets the state for us */
  89326. subframe->warmup[u] = i32;
  89327. }
  89328. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89329. return false; /* read_callback_ sets the state for us */
  89330. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89331. switch(subframe->entropy_coding_method.type) {
  89332. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89333. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89334. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89335. return false; /* read_callback_ sets the state for us */
  89336. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89337. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89338. break;
  89339. default:
  89340. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89341. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89342. return true;
  89343. }
  89344. switch(subframe->entropy_coding_method.type) {
  89345. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89346. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89347. 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))
  89348. return false;
  89349. break;
  89350. default:
  89351. FLAC__ASSERT(0);
  89352. }
  89353. if(do_full_decode) {
  89354. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89355. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  89356. }
  89357. return true;
  89358. }
  89359. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89360. {
  89361. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  89362. FLAC__int32 i32;
  89363. FLAC__uint32 u32;
  89364. unsigned u;
  89365. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  89366. subframe->residual = decoder->private_->residual[channel];
  89367. subframe->order = order;
  89368. for(u = 0; u < order; u++) {
  89369. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89370. return false; /* read_callback_ sets the state for us */
  89371. subframe->warmup[u] = i32;
  89372. }
  89373. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  89374. return false; /* read_callback_ sets the state for us */
  89375. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  89376. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89377. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89378. return true;
  89379. }
  89380. subframe->qlp_coeff_precision = u32+1;
  89381. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  89382. return false; /* read_callback_ sets the state for us */
  89383. subframe->quantization_level = i32;
  89384. for(u = 0; u < order; u++) {
  89385. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  89386. return false; /* read_callback_ sets the state for us */
  89387. subframe->qlp_coeff[u] = i32;
  89388. }
  89389. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89390. return false; /* read_callback_ sets the state for us */
  89391. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89392. switch(subframe->entropy_coding_method.type) {
  89393. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89394. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89395. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89396. return false; /* read_callback_ sets the state for us */
  89397. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89398. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89399. break;
  89400. default:
  89401. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89402. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89403. return true;
  89404. }
  89405. switch(subframe->entropy_coding_method.type) {
  89406. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89407. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89408. 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))
  89409. return false;
  89410. break;
  89411. default:
  89412. FLAC__ASSERT(0);
  89413. }
  89414. if(do_full_decode) {
  89415. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89416. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  89417. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  89418. if(order <= 8)
  89419. 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);
  89420. else
  89421. 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);
  89422. }
  89423. else
  89424. 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);
  89425. else
  89426. 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);
  89427. }
  89428. return true;
  89429. }
  89430. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89431. {
  89432. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  89433. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  89434. unsigned i;
  89435. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  89436. subframe->data = residual;
  89437. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  89438. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89439. return false; /* read_callback_ sets the state for us */
  89440. residual[i] = x;
  89441. }
  89442. if(do_full_decode)
  89443. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  89444. return true;
  89445. }
  89446. 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)
  89447. {
  89448. FLAC__uint32 rice_parameter;
  89449. int i;
  89450. unsigned partition, sample, u;
  89451. const unsigned partitions = 1u << partition_order;
  89452. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  89453. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  89454. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  89455. if(partition_order == 0) {
  89456. if(decoder->private_->frame.header.blocksize < predictor_order) {
  89457. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89458. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89459. return true;
  89460. }
  89461. }
  89462. else {
  89463. if(partition_samples < predictor_order) {
  89464. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89465. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89466. return true;
  89467. }
  89468. }
  89469. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  89470. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89471. return false;
  89472. }
  89473. sample = 0;
  89474. for(partition = 0; partition < partitions; partition++) {
  89475. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  89476. return false; /* read_callback_ sets the state for us */
  89477. partitioned_rice_contents->parameters[partition] = rice_parameter;
  89478. if(rice_parameter < pesc) {
  89479. partitioned_rice_contents->raw_bits[partition] = 0;
  89480. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  89481. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  89482. return false; /* read_callback_ sets the state for us */
  89483. sample += u;
  89484. }
  89485. else {
  89486. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  89487. return false; /* read_callback_ sets the state for us */
  89488. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  89489. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  89490. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  89491. return false; /* read_callback_ sets the state for us */
  89492. residual[sample] = i;
  89493. }
  89494. }
  89495. }
  89496. return true;
  89497. }
  89498. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  89499. {
  89500. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  89501. FLAC__uint32 zero = 0;
  89502. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  89503. return false; /* read_callback_ sets the state for us */
  89504. if(zero != 0) {
  89505. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89506. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89507. }
  89508. }
  89509. return true;
  89510. }
  89511. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  89512. {
  89513. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  89514. if(
  89515. #if FLAC__HAS_OGG
  89516. !decoder->private_->is_ogg &&
  89517. #endif
  89518. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89519. ) {
  89520. *bytes = 0;
  89521. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89522. return false;
  89523. }
  89524. else if(*bytes > 0) {
  89525. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  89526. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89527. return false;
  89528. }
  89529. else {
  89530. const FLAC__StreamDecoderReadStatus status =
  89531. #if FLAC__HAS_OGG
  89532. decoder->private_->is_ogg?
  89533. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  89534. #endif
  89535. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  89536. ;
  89537. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89538. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89539. return false;
  89540. }
  89541. else if(*bytes == 0) {
  89542. if(
  89543. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89544. (
  89545. #if FLAC__HAS_OGG
  89546. !decoder->private_->is_ogg &&
  89547. #endif
  89548. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89549. )
  89550. ) {
  89551. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89552. return false;
  89553. }
  89554. else
  89555. return true;
  89556. }
  89557. else
  89558. return true;
  89559. }
  89560. }
  89561. else {
  89562. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89563. return false;
  89564. }
  89565. }
  89566. #if FLAC__HAS_OGG
  89567. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89568. {
  89569. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89570. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89571. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89572. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89573. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89574. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89575. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89576. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89577. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89578. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89579. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89580. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89581. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89582. default:
  89583. FLAC__ASSERT(0);
  89584. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89585. }
  89586. }
  89587. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89588. {
  89589. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89590. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89591. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89592. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89593. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89594. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89595. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89596. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89597. default:
  89598. FLAC__ASSERT(0);
  89599. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89600. }
  89601. }
  89602. #endif
  89603. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89604. {
  89605. if(decoder->private_->is_seeking) {
  89606. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89607. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89608. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89609. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89610. #if FLAC__HAS_OGG
  89611. decoder->private_->got_a_frame = true;
  89612. #endif
  89613. decoder->private_->last_frame = *frame; /* save the frame */
  89614. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89615. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89616. decoder->private_->is_seeking = false;
  89617. if(delta > 0) {
  89618. unsigned channel;
  89619. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89620. for(channel = 0; channel < frame->header.channels; channel++)
  89621. newbuffer[channel] = buffer[channel] + delta;
  89622. decoder->private_->last_frame.header.blocksize -= delta;
  89623. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89624. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89625. }
  89626. else {
  89627. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89628. }
  89629. }
  89630. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89631. }
  89632. if(!decoder->private_->has_stream_info)
  89633. decoder->private_->do_md5_checking = false;
  89634. if(decoder->private_->do_md5_checking) {
  89635. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89636. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89637. }
  89638. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89639. }
  89640. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89641. {
  89642. if(!decoder->private_->is_seeking)
  89643. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89644. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89645. decoder->private_->unparseable_frame_count++;
  89646. }
  89647. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89648. {
  89649. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89650. FLAC__int64 pos = -1;
  89651. int i;
  89652. unsigned approx_bytes_per_frame;
  89653. FLAC__bool first_seek = true;
  89654. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89655. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89656. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89657. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89658. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89659. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89660. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89661. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89662. if(channels == 0)
  89663. channels = decoder->private_->stream_info.data.stream_info.channels;
  89664. if(bps == 0)
  89665. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89666. if(max_framesize > 0)
  89667. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89668. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89669. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89670. }
  89671. else
  89672. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89673. lower_bound = first_frame_offset;
  89674. lower_bound_sample = 0;
  89675. upper_bound = stream_length;
  89676. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89677. if(seek_table) {
  89678. FLAC__uint64 new_lower_bound = lower_bound;
  89679. FLAC__uint64 new_upper_bound = upper_bound;
  89680. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89681. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89682. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89683. if(
  89684. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89685. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89686. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89687. seek_table->points[i].sample_number <= target_sample
  89688. )
  89689. break;
  89690. }
  89691. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89692. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89693. new_lower_bound_sample = seek_table->points[i].sample_number;
  89694. }
  89695. for(i = 0; i < (int)seek_table->num_points; i++) {
  89696. if(
  89697. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89698. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89699. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89700. seek_table->points[i].sample_number > target_sample
  89701. )
  89702. break;
  89703. }
  89704. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89705. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89706. new_upper_bound_sample = seek_table->points[i].sample_number;
  89707. }
  89708. if(new_upper_bound >= new_lower_bound) {
  89709. lower_bound = new_lower_bound;
  89710. upper_bound = new_upper_bound;
  89711. lower_bound_sample = new_lower_bound_sample;
  89712. upper_bound_sample = new_upper_bound_sample;
  89713. }
  89714. }
  89715. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89716. if(upper_bound_sample == lower_bound_sample)
  89717. upper_bound_sample++;
  89718. decoder->private_->target_sample = target_sample;
  89719. while(1) {
  89720. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89721. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89722. return false;
  89723. }
  89724. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89725. #if defined _MSC_VER || defined __MINGW32__
  89726. 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;
  89727. #else
  89728. 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;
  89729. #endif
  89730. #else
  89731. if(upper_bound - lower_bound < 0xffffffff)
  89732. 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;
  89733. else /* @@@ WATCHOUT, ~2TB limit */
  89734. 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;
  89735. #endif
  89736. if(pos >= (FLAC__int64)upper_bound)
  89737. pos = (FLAC__int64)upper_bound - 1;
  89738. if(pos < (FLAC__int64)lower_bound)
  89739. pos = (FLAC__int64)lower_bound;
  89740. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89741. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89742. return false;
  89743. }
  89744. if(!FLAC__stream_decoder_flush(decoder)) {
  89745. return false;
  89746. }
  89747. decoder->private_->unparseable_frame_count = 0;
  89748. if(!FLAC__stream_decoder_process_single(decoder)) {
  89749. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89750. return false;
  89751. }
  89752. #if 0
  89753. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89754. break;
  89755. #endif
  89756. if(!decoder->private_->is_seeking)
  89757. break;
  89758. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89759. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89760. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89761. if (pos == (FLAC__int64)lower_bound) {
  89762. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89763. return false;
  89764. }
  89765. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89766. continue;
  89767. }
  89768. first_seek = false;
  89769. if (this_frame_sample < lower_bound_sample) {
  89770. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89771. return false;
  89772. }
  89773. if(target_sample < this_frame_sample) {
  89774. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89775. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89776. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89777. return false;
  89778. }
  89779. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89780. }
  89781. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89782. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89783. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89784. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89785. return false;
  89786. }
  89787. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89788. }
  89789. }
  89790. return true;
  89791. }
  89792. #if FLAC__HAS_OGG
  89793. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89794. {
  89795. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89796. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89797. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89798. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89799. FLAC__bool did_a_seek;
  89800. unsigned iteration = 0;
  89801. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89802. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89803. if(right_sample == 0) {
  89804. right_sample = (FLAC__uint64)(-1);
  89805. BINARY_SEARCH_AFTER_ITERATION = 0;
  89806. }
  89807. decoder->private_->target_sample = target_sample;
  89808. for( ; ; iteration++) {
  89809. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89810. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89811. pos = (right_pos + left_pos) / 2;
  89812. }
  89813. else {
  89814. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89815. #if defined _MSC_VER || defined __MINGW32__
  89816. 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));
  89817. #else
  89818. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89819. #endif
  89820. #else
  89821. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89822. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89823. else /* @@@ WATCHOUT, ~2TB limit */
  89824. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89825. #endif
  89826. }
  89827. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89828. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89829. return false;
  89830. }
  89831. if(!FLAC__stream_decoder_flush(decoder)) {
  89832. return false;
  89833. }
  89834. did_a_seek = true;
  89835. }
  89836. else
  89837. did_a_seek = false;
  89838. decoder->private_->got_a_frame = false;
  89839. if(!FLAC__stream_decoder_process_single(decoder)) {
  89840. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89841. return false;
  89842. }
  89843. if(!decoder->private_->got_a_frame) {
  89844. if(did_a_seek) {
  89845. right_pos = pos;
  89846. BINARY_SEARCH_AFTER_ITERATION = 0;
  89847. }
  89848. else {
  89849. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89850. return false;
  89851. }
  89852. }
  89853. else if(!decoder->private_->is_seeking) {
  89854. break;
  89855. }
  89856. else {
  89857. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89858. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89859. if (did_a_seek) {
  89860. if (this_frame_sample <= target_sample) {
  89861. FLAC__ASSERT(this_frame_sample != target_sample);
  89862. left_sample = this_frame_sample;
  89863. if (left_pos == pos) {
  89864. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89865. return false;
  89866. }
  89867. left_pos = pos;
  89868. }
  89869. else if(this_frame_sample > target_sample) {
  89870. right_sample = this_frame_sample;
  89871. if (right_pos == pos) {
  89872. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89873. return false;
  89874. }
  89875. right_pos = pos;
  89876. }
  89877. }
  89878. }
  89879. }
  89880. return true;
  89881. }
  89882. #endif
  89883. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89884. {
  89885. (void)client_data;
  89886. if(*bytes > 0) {
  89887. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89888. if(ferror(decoder->private_->file))
  89889. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89890. else if(*bytes == 0)
  89891. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89892. else
  89893. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89894. }
  89895. else
  89896. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89897. }
  89898. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89899. {
  89900. (void)client_data;
  89901. if(decoder->private_->file == stdin)
  89902. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89903. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89904. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89905. else
  89906. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89907. }
  89908. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89909. {
  89910. off_t pos;
  89911. (void)client_data;
  89912. if(decoder->private_->file == stdin)
  89913. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89914. else if((pos = ftello(decoder->private_->file)) < 0)
  89915. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89916. else {
  89917. *absolute_byte_offset = (FLAC__uint64)pos;
  89918. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89919. }
  89920. }
  89921. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89922. {
  89923. struct stat filestats;
  89924. (void)client_data;
  89925. if(decoder->private_->file == stdin)
  89926. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89927. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89928. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89929. else {
  89930. *stream_length = (FLAC__uint64)filestats.st_size;
  89931. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89932. }
  89933. }
  89934. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89935. {
  89936. (void)client_data;
  89937. return feof(decoder->private_->file)? true : false;
  89938. }
  89939. #endif
  89940. /*** End of inlined file: stream_decoder.c ***/
  89941. /*** Start of inlined file: stream_encoder.c ***/
  89942. /*** Start of inlined file: juce_FlacHeader.h ***/
  89943. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89944. // tasks..
  89945. #define VERSION "1.2.1"
  89946. #define FLAC__NO_DLL 1
  89947. #if JUCE_MSVC
  89948. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89949. #endif
  89950. #if JUCE_MAC
  89951. #define FLAC__SYS_DARWIN 1
  89952. #endif
  89953. /*** End of inlined file: juce_FlacHeader.h ***/
  89954. #if JUCE_USE_FLAC
  89955. #if HAVE_CONFIG_H
  89956. # include <config.h>
  89957. #endif
  89958. #if defined _MSC_VER || defined __MINGW32__
  89959. #include <io.h> /* for _setmode() */
  89960. #include <fcntl.h> /* for _O_BINARY */
  89961. #endif
  89962. #if defined __CYGWIN__ || defined __EMX__
  89963. #include <io.h> /* for setmode(), O_BINARY */
  89964. #include <fcntl.h> /* for _O_BINARY */
  89965. #endif
  89966. #include <limits.h>
  89967. #include <stdio.h>
  89968. #include <stdlib.h> /* for malloc() */
  89969. #include <string.h> /* for memcpy() */
  89970. #include <sys/types.h> /* for off_t */
  89971. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89972. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89973. #define fseeko fseek
  89974. #define ftello ftell
  89975. #endif
  89976. #endif
  89977. /*** Start of inlined file: stream_encoder.h ***/
  89978. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89979. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89980. #if FLAC__HAS_OGG
  89981. #include "private/ogg_encoder_aspect.h"
  89982. #endif
  89983. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89984. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89985. typedef enum {
  89986. FLAC__APODIZATION_BARTLETT,
  89987. FLAC__APODIZATION_BARTLETT_HANN,
  89988. FLAC__APODIZATION_BLACKMAN,
  89989. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89990. FLAC__APODIZATION_CONNES,
  89991. FLAC__APODIZATION_FLATTOP,
  89992. FLAC__APODIZATION_GAUSS,
  89993. FLAC__APODIZATION_HAMMING,
  89994. FLAC__APODIZATION_HANN,
  89995. FLAC__APODIZATION_KAISER_BESSEL,
  89996. FLAC__APODIZATION_NUTTALL,
  89997. FLAC__APODIZATION_RECTANGLE,
  89998. FLAC__APODIZATION_TRIANGLE,
  89999. FLAC__APODIZATION_TUKEY,
  90000. FLAC__APODIZATION_WELCH
  90001. } FLAC__ApodizationFunction;
  90002. typedef struct {
  90003. FLAC__ApodizationFunction type;
  90004. union {
  90005. struct {
  90006. FLAC__real stddev;
  90007. } gauss;
  90008. struct {
  90009. FLAC__real p;
  90010. } tukey;
  90011. } parameters;
  90012. } FLAC__ApodizationSpecification;
  90013. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90014. typedef struct FLAC__StreamEncoderProtected {
  90015. FLAC__StreamEncoderState state;
  90016. FLAC__bool verify;
  90017. FLAC__bool streamable_subset;
  90018. FLAC__bool do_md5;
  90019. FLAC__bool do_mid_side_stereo;
  90020. FLAC__bool loose_mid_side_stereo;
  90021. unsigned channels;
  90022. unsigned bits_per_sample;
  90023. unsigned sample_rate;
  90024. unsigned blocksize;
  90025. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90026. unsigned num_apodizations;
  90027. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  90028. #endif
  90029. unsigned max_lpc_order;
  90030. unsigned qlp_coeff_precision;
  90031. FLAC__bool do_qlp_coeff_prec_search;
  90032. FLAC__bool do_exhaustive_model_search;
  90033. FLAC__bool do_escape_coding;
  90034. unsigned min_residual_partition_order;
  90035. unsigned max_residual_partition_order;
  90036. unsigned rice_parameter_search_dist;
  90037. FLAC__uint64 total_samples_estimate;
  90038. FLAC__StreamMetadata **metadata;
  90039. unsigned num_metadata_blocks;
  90040. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  90041. #if FLAC__HAS_OGG
  90042. FLAC__OggEncoderAspect ogg_encoder_aspect;
  90043. #endif
  90044. } FLAC__StreamEncoderProtected;
  90045. #endif
  90046. /*** End of inlined file: stream_encoder.h ***/
  90047. #if FLAC__HAS_OGG
  90048. #include "include/private/ogg_helper.h"
  90049. #include "include/private/ogg_mapping.h"
  90050. #endif
  90051. /*** Start of inlined file: stream_encoder_framing.h ***/
  90052. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  90053. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  90054. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  90055. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  90056. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90057. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90058. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90059. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90060. #endif
  90061. /*** End of inlined file: stream_encoder_framing.h ***/
  90062. /*** Start of inlined file: window.h ***/
  90063. #ifndef FLAC__PRIVATE__WINDOW_H
  90064. #define FLAC__PRIVATE__WINDOW_H
  90065. #ifdef HAVE_CONFIG_H
  90066. #include <config.h>
  90067. #endif
  90068. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90069. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  90070. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  90071. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  90072. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  90073. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  90074. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  90075. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  90076. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  90077. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  90078. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  90079. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  90080. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  90081. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  90082. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  90083. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  90084. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  90085. #endif
  90086. /*** End of inlined file: window.h ***/
  90087. #ifndef FLaC__INLINE
  90088. #define FLaC__INLINE
  90089. #endif
  90090. #ifdef min
  90091. #undef min
  90092. #endif
  90093. #define min(x,y) ((x)<(y)?(x):(y))
  90094. #ifdef max
  90095. #undef max
  90096. #endif
  90097. #define max(x,y) ((x)>(y)?(x):(y))
  90098. #undef EXACT_RICE_BITS_CALCULATION
  90099. #undef ENABLE_RICE_PARAMETER_SEARCH
  90100. typedef struct {
  90101. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  90102. unsigned size; /* of each data[] in samples */
  90103. unsigned tail;
  90104. } verify_input_fifo;
  90105. typedef struct {
  90106. const FLAC__byte *data;
  90107. unsigned capacity;
  90108. unsigned bytes;
  90109. } verify_output;
  90110. typedef enum {
  90111. ENCODER_IN_MAGIC = 0,
  90112. ENCODER_IN_METADATA = 1,
  90113. ENCODER_IN_AUDIO = 2
  90114. } EncoderStateHint;
  90115. static struct CompressionLevels {
  90116. FLAC__bool do_mid_side_stereo;
  90117. FLAC__bool loose_mid_side_stereo;
  90118. unsigned max_lpc_order;
  90119. unsigned qlp_coeff_precision;
  90120. FLAC__bool do_qlp_coeff_prec_search;
  90121. FLAC__bool do_escape_coding;
  90122. FLAC__bool do_exhaustive_model_search;
  90123. unsigned min_residual_partition_order;
  90124. unsigned max_residual_partition_order;
  90125. unsigned rice_parameter_search_dist;
  90126. } compression_levels_[] = {
  90127. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  90128. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  90129. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  90130. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  90131. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  90132. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  90133. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  90134. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  90135. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  90136. };
  90137. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  90138. static void free_(FLAC__StreamEncoder *encoder);
  90139. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  90140. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  90141. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  90142. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  90143. #if FLAC__HAS_OGG
  90144. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  90145. #endif
  90146. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  90147. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  90148. static FLAC__bool process_subframe_(
  90149. FLAC__StreamEncoder *encoder,
  90150. unsigned min_partition_order,
  90151. unsigned max_partition_order,
  90152. const FLAC__FrameHeader *frame_header,
  90153. unsigned subframe_bps,
  90154. const FLAC__int32 integer_signal[],
  90155. FLAC__Subframe *subframe[2],
  90156. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  90157. FLAC__int32 *residual[2],
  90158. unsigned *best_subframe,
  90159. unsigned *best_bits
  90160. );
  90161. static FLAC__bool add_subframe_(
  90162. FLAC__StreamEncoder *encoder,
  90163. unsigned blocksize,
  90164. unsigned subframe_bps,
  90165. const FLAC__Subframe *subframe,
  90166. FLAC__BitWriter *frame
  90167. );
  90168. static unsigned evaluate_constant_subframe_(
  90169. FLAC__StreamEncoder *encoder,
  90170. const FLAC__int32 signal,
  90171. unsigned blocksize,
  90172. unsigned subframe_bps,
  90173. FLAC__Subframe *subframe
  90174. );
  90175. static unsigned evaluate_fixed_subframe_(
  90176. FLAC__StreamEncoder *encoder,
  90177. const FLAC__int32 signal[],
  90178. FLAC__int32 residual[],
  90179. FLAC__uint64 abs_residual_partition_sums[],
  90180. unsigned raw_bits_per_partition[],
  90181. unsigned blocksize,
  90182. unsigned subframe_bps,
  90183. unsigned order,
  90184. unsigned rice_parameter,
  90185. unsigned rice_parameter_limit,
  90186. unsigned min_partition_order,
  90187. unsigned max_partition_order,
  90188. FLAC__bool do_escape_coding,
  90189. unsigned rice_parameter_search_dist,
  90190. FLAC__Subframe *subframe,
  90191. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90192. );
  90193. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90194. static unsigned evaluate_lpc_subframe_(
  90195. FLAC__StreamEncoder *encoder,
  90196. const FLAC__int32 signal[],
  90197. FLAC__int32 residual[],
  90198. FLAC__uint64 abs_residual_partition_sums[],
  90199. unsigned raw_bits_per_partition[],
  90200. const FLAC__real lp_coeff[],
  90201. unsigned blocksize,
  90202. unsigned subframe_bps,
  90203. unsigned order,
  90204. unsigned qlp_coeff_precision,
  90205. unsigned rice_parameter,
  90206. unsigned rice_parameter_limit,
  90207. unsigned min_partition_order,
  90208. unsigned max_partition_order,
  90209. FLAC__bool do_escape_coding,
  90210. unsigned rice_parameter_search_dist,
  90211. FLAC__Subframe *subframe,
  90212. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90213. );
  90214. #endif
  90215. static unsigned evaluate_verbatim_subframe_(
  90216. FLAC__StreamEncoder *encoder,
  90217. const FLAC__int32 signal[],
  90218. unsigned blocksize,
  90219. unsigned subframe_bps,
  90220. FLAC__Subframe *subframe
  90221. );
  90222. static unsigned find_best_partition_order_(
  90223. struct FLAC__StreamEncoderPrivate *private_,
  90224. const FLAC__int32 residual[],
  90225. FLAC__uint64 abs_residual_partition_sums[],
  90226. unsigned raw_bits_per_partition[],
  90227. unsigned residual_samples,
  90228. unsigned predictor_order,
  90229. unsigned rice_parameter,
  90230. unsigned rice_parameter_limit,
  90231. unsigned min_partition_order,
  90232. unsigned max_partition_order,
  90233. unsigned bps,
  90234. FLAC__bool do_escape_coding,
  90235. unsigned rice_parameter_search_dist,
  90236. FLAC__EntropyCodingMethod *best_ecm
  90237. );
  90238. static void precompute_partition_info_sums_(
  90239. const FLAC__int32 residual[],
  90240. FLAC__uint64 abs_residual_partition_sums[],
  90241. unsigned residual_samples,
  90242. unsigned predictor_order,
  90243. unsigned min_partition_order,
  90244. unsigned max_partition_order,
  90245. unsigned bps
  90246. );
  90247. static void precompute_partition_info_escapes_(
  90248. const FLAC__int32 residual[],
  90249. unsigned raw_bits_per_partition[],
  90250. unsigned residual_samples,
  90251. unsigned predictor_order,
  90252. unsigned min_partition_order,
  90253. unsigned max_partition_order
  90254. );
  90255. static FLAC__bool set_partitioned_rice_(
  90256. #ifdef EXACT_RICE_BITS_CALCULATION
  90257. const FLAC__int32 residual[],
  90258. #endif
  90259. const FLAC__uint64 abs_residual_partition_sums[],
  90260. const unsigned raw_bits_per_partition[],
  90261. const unsigned residual_samples,
  90262. const unsigned predictor_order,
  90263. const unsigned suggested_rice_parameter,
  90264. const unsigned rice_parameter_limit,
  90265. const unsigned rice_parameter_search_dist,
  90266. const unsigned partition_order,
  90267. const FLAC__bool search_for_escapes,
  90268. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  90269. unsigned *bits
  90270. );
  90271. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  90272. static void append_to_verify_fifo_(
  90273. verify_input_fifo *fifo,
  90274. const FLAC__int32 * const input[],
  90275. unsigned input_offset,
  90276. unsigned channels,
  90277. unsigned wide_samples
  90278. );
  90279. static void append_to_verify_fifo_interleaved_(
  90280. verify_input_fifo *fifo,
  90281. const FLAC__int32 input[],
  90282. unsigned input_offset,
  90283. unsigned channels,
  90284. unsigned wide_samples
  90285. );
  90286. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90287. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  90288. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  90289. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  90290. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90291. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  90292. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  90293. 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);
  90294. static FILE *get_binary_stdout_(void);
  90295. typedef struct FLAC__StreamEncoderPrivate {
  90296. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  90297. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  90298. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  90299. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90300. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  90301. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  90302. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  90303. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  90304. #endif
  90305. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  90306. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  90307. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  90308. FLAC__int32 *residual_workspace_mid_side[2][2];
  90309. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  90310. FLAC__Subframe subframe_workspace_mid_side[2][2];
  90311. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90312. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  90313. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  90314. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  90315. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90316. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  90317. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  90318. unsigned best_subframe_mid_side[2];
  90319. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  90320. unsigned best_subframe_bits_mid_side[2];
  90321. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  90322. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  90323. FLAC__BitWriter *frame; /* the current frame being worked on */
  90324. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  90325. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  90326. FLAC__ChannelAssignment last_channel_assignment;
  90327. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  90328. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  90329. unsigned current_sample_number;
  90330. unsigned current_frame_number;
  90331. FLAC__MD5Context md5context;
  90332. FLAC__CPUInfo cpuinfo;
  90333. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90334. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90335. #else
  90336. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90337. #endif
  90338. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90339. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  90340. 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[]);
  90341. 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[]);
  90342. 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[]);
  90343. #endif
  90344. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  90345. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  90346. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  90347. FLAC__bool disable_constant_subframes;
  90348. FLAC__bool disable_fixed_subframes;
  90349. FLAC__bool disable_verbatim_subframes;
  90350. #if FLAC__HAS_OGG
  90351. FLAC__bool is_ogg;
  90352. #endif
  90353. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  90354. FLAC__StreamEncoderSeekCallback seek_callback;
  90355. FLAC__StreamEncoderTellCallback tell_callback;
  90356. FLAC__StreamEncoderWriteCallback write_callback;
  90357. FLAC__StreamEncoderMetadataCallback metadata_callback;
  90358. FLAC__StreamEncoderProgressCallback progress_callback;
  90359. void *client_data;
  90360. unsigned first_seekpoint_to_check;
  90361. FILE *file; /* only used when encoding to a file */
  90362. FLAC__uint64 bytes_written;
  90363. FLAC__uint64 samples_written;
  90364. unsigned frames_written;
  90365. unsigned total_frames_estimate;
  90366. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  90367. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  90368. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90369. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  90370. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  90371. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  90372. FLAC__real *windowed_signal_unaligned;
  90373. #endif
  90374. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  90375. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  90376. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  90377. unsigned *raw_bits_per_partition_unaligned;
  90378. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90379. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  90380. #endif
  90381. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  90382. struct {
  90383. FLAC__StreamDecoder *decoder;
  90384. EncoderStateHint state_hint;
  90385. FLAC__bool needs_magic_hack;
  90386. verify_input_fifo input_fifo;
  90387. verify_output output;
  90388. struct {
  90389. FLAC__uint64 absolute_sample;
  90390. unsigned frame_number;
  90391. unsigned channel;
  90392. unsigned sample;
  90393. FLAC__int32 expected;
  90394. FLAC__int32 got;
  90395. } error_stats;
  90396. } verify;
  90397. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  90398. } FLAC__StreamEncoderPrivate;
  90399. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  90400. "FLAC__STREAM_ENCODER_OK",
  90401. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  90402. "FLAC__STREAM_ENCODER_OGG_ERROR",
  90403. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  90404. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  90405. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  90406. "FLAC__STREAM_ENCODER_IO_ERROR",
  90407. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  90408. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  90409. };
  90410. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  90411. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  90412. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  90413. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  90414. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  90415. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  90416. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  90417. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  90418. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  90419. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  90420. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  90421. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  90422. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  90423. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  90424. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  90425. };
  90426. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  90427. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  90428. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  90429. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  90430. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  90431. };
  90432. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  90433. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  90434. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  90435. };
  90436. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  90437. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  90438. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  90439. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  90440. };
  90441. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  90442. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  90443. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  90444. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  90445. };
  90446. static const unsigned OVERREAD_ = 1;
  90447. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  90448. {
  90449. FLAC__StreamEncoder *encoder;
  90450. unsigned i;
  90451. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  90452. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  90453. if(encoder == 0) {
  90454. return 0;
  90455. }
  90456. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  90457. if(encoder->protected_ == 0) {
  90458. free(encoder);
  90459. return 0;
  90460. }
  90461. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  90462. if(encoder->private_ == 0) {
  90463. free(encoder->protected_);
  90464. free(encoder);
  90465. return 0;
  90466. }
  90467. encoder->private_->frame = FLAC__bitwriter_new();
  90468. if(encoder->private_->frame == 0) {
  90469. free(encoder->private_);
  90470. free(encoder->protected_);
  90471. free(encoder);
  90472. return 0;
  90473. }
  90474. encoder->private_->file = 0;
  90475. set_defaults_enc(encoder);
  90476. encoder->private_->is_being_deleted = false;
  90477. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90478. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  90479. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  90480. }
  90481. for(i = 0; i < 2; i++) {
  90482. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  90483. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  90484. }
  90485. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90486. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  90487. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  90488. }
  90489. for(i = 0; i < 2; i++) {
  90490. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  90491. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  90492. }
  90493. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90494. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90495. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90496. }
  90497. for(i = 0; i < 2; i++) {
  90498. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90499. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90500. }
  90501. for(i = 0; i < 2; i++)
  90502. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  90503. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90504. return encoder;
  90505. }
  90506. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  90507. {
  90508. unsigned i;
  90509. FLAC__ASSERT(0 != encoder);
  90510. FLAC__ASSERT(0 != encoder->protected_);
  90511. FLAC__ASSERT(0 != encoder->private_);
  90512. FLAC__ASSERT(0 != encoder->private_->frame);
  90513. encoder->private_->is_being_deleted = true;
  90514. (void)FLAC__stream_encoder_finish(encoder);
  90515. if(0 != encoder->private_->verify.decoder)
  90516. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  90517. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90518. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90519. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90520. }
  90521. for(i = 0; i < 2; i++) {
  90522. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90523. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90524. }
  90525. for(i = 0; i < 2; i++)
  90526. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  90527. FLAC__bitwriter_delete(encoder->private_->frame);
  90528. free(encoder->private_);
  90529. free(encoder->protected_);
  90530. free(encoder);
  90531. }
  90532. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  90533. FLAC__StreamEncoder *encoder,
  90534. FLAC__StreamEncoderReadCallback read_callback,
  90535. FLAC__StreamEncoderWriteCallback write_callback,
  90536. FLAC__StreamEncoderSeekCallback seek_callback,
  90537. FLAC__StreamEncoderTellCallback tell_callback,
  90538. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90539. void *client_data,
  90540. FLAC__bool is_ogg
  90541. )
  90542. {
  90543. unsigned i;
  90544. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90545. FLAC__ASSERT(0 != encoder);
  90546. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90547. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90548. #if !FLAC__HAS_OGG
  90549. if(is_ogg)
  90550. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90551. #endif
  90552. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90553. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90554. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90555. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90556. if(encoder->protected_->channels != 2) {
  90557. encoder->protected_->do_mid_side_stereo = false;
  90558. encoder->protected_->loose_mid_side_stereo = false;
  90559. }
  90560. else if(!encoder->protected_->do_mid_side_stereo)
  90561. encoder->protected_->loose_mid_side_stereo = false;
  90562. if(encoder->protected_->bits_per_sample >= 32)
  90563. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90564. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90565. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90566. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90567. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90568. if(encoder->protected_->blocksize == 0) {
  90569. if(encoder->protected_->max_lpc_order == 0)
  90570. encoder->protected_->blocksize = 1152;
  90571. else
  90572. encoder->protected_->blocksize = 4096;
  90573. }
  90574. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90575. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90576. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90577. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90578. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90579. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90580. if(encoder->protected_->qlp_coeff_precision == 0) {
  90581. if(encoder->protected_->bits_per_sample < 16) {
  90582. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90583. }
  90584. else if(encoder->protected_->bits_per_sample == 16) {
  90585. if(encoder->protected_->blocksize <= 192)
  90586. encoder->protected_->qlp_coeff_precision = 7;
  90587. else if(encoder->protected_->blocksize <= 384)
  90588. encoder->protected_->qlp_coeff_precision = 8;
  90589. else if(encoder->protected_->blocksize <= 576)
  90590. encoder->protected_->qlp_coeff_precision = 9;
  90591. else if(encoder->protected_->blocksize <= 1152)
  90592. encoder->protected_->qlp_coeff_precision = 10;
  90593. else if(encoder->protected_->blocksize <= 2304)
  90594. encoder->protected_->qlp_coeff_precision = 11;
  90595. else if(encoder->protected_->blocksize <= 4608)
  90596. encoder->protected_->qlp_coeff_precision = 12;
  90597. else
  90598. encoder->protected_->qlp_coeff_precision = 13;
  90599. }
  90600. else {
  90601. if(encoder->protected_->blocksize <= 384)
  90602. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90603. else if(encoder->protected_->blocksize <= 1152)
  90604. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90605. else
  90606. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90607. }
  90608. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90609. }
  90610. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90611. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90612. if(encoder->protected_->streamable_subset) {
  90613. if(
  90614. encoder->protected_->blocksize != 192 &&
  90615. encoder->protected_->blocksize != 576 &&
  90616. encoder->protected_->blocksize != 1152 &&
  90617. encoder->protected_->blocksize != 2304 &&
  90618. encoder->protected_->blocksize != 4608 &&
  90619. encoder->protected_->blocksize != 256 &&
  90620. encoder->protected_->blocksize != 512 &&
  90621. encoder->protected_->blocksize != 1024 &&
  90622. encoder->protected_->blocksize != 2048 &&
  90623. encoder->protected_->blocksize != 4096 &&
  90624. encoder->protected_->blocksize != 8192 &&
  90625. encoder->protected_->blocksize != 16384
  90626. )
  90627. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90628. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90629. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90630. if(
  90631. encoder->protected_->bits_per_sample != 8 &&
  90632. encoder->protected_->bits_per_sample != 12 &&
  90633. encoder->protected_->bits_per_sample != 16 &&
  90634. encoder->protected_->bits_per_sample != 20 &&
  90635. encoder->protected_->bits_per_sample != 24
  90636. )
  90637. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90638. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90639. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90640. if(
  90641. encoder->protected_->sample_rate <= 48000 &&
  90642. (
  90643. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90644. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90645. )
  90646. ) {
  90647. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90648. }
  90649. }
  90650. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90651. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90652. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90653. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90654. #if FLAC__HAS_OGG
  90655. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90656. unsigned i;
  90657. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90658. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90659. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90660. for( ; i > 0; i--)
  90661. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90662. encoder->protected_->metadata[0] = vc;
  90663. break;
  90664. }
  90665. }
  90666. }
  90667. #endif
  90668. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90669. unsigned i;
  90670. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90671. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90672. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90673. break; /* take only the first one */
  90674. }
  90675. }
  90676. }
  90677. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90678. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90679. metadata_has_seektable = false;
  90680. metadata_has_vorbis_comment = false;
  90681. metadata_picture_has_type1 = false;
  90682. metadata_picture_has_type2 = false;
  90683. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90684. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90685. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90686. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90687. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90688. if(metadata_has_seektable) /* only one is allowed */
  90689. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90690. metadata_has_seektable = true;
  90691. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90692. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90693. }
  90694. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90695. if(metadata_has_vorbis_comment) /* only one is allowed */
  90696. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90697. metadata_has_vorbis_comment = true;
  90698. }
  90699. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90700. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90701. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90702. }
  90703. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90704. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90705. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90706. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90707. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90708. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90709. metadata_picture_has_type1 = true;
  90710. if(
  90711. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90712. (
  90713. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90714. m->data.picture.width != 32 ||
  90715. m->data.picture.height != 32
  90716. )
  90717. )
  90718. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90719. }
  90720. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90721. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90722. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90723. metadata_picture_has_type2 = true;
  90724. }
  90725. }
  90726. }
  90727. encoder->private_->input_capacity = 0;
  90728. for(i = 0; i < encoder->protected_->channels; i++) {
  90729. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90730. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90731. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90732. #endif
  90733. }
  90734. for(i = 0; i < 2; i++) {
  90735. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90736. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90737. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90738. #endif
  90739. }
  90740. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90741. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90742. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90743. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90744. #endif
  90745. for(i = 0; i < encoder->protected_->channels; i++) {
  90746. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90747. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90748. encoder->private_->best_subframe[i] = 0;
  90749. }
  90750. for(i = 0; i < 2; i++) {
  90751. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90752. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90753. encoder->private_->best_subframe_mid_side[i] = 0;
  90754. }
  90755. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90756. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90757. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90758. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90759. #else
  90760. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90761. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90762. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90763. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90764. 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);
  90765. #endif
  90766. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90767. encoder->private_->loose_mid_side_stereo_frames = 1;
  90768. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90769. encoder->private_->current_sample_number = 0;
  90770. encoder->private_->current_frame_number = 0;
  90771. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90772. 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? */
  90773. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90774. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90775. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90776. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90777. #endif
  90778. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90779. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90780. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90781. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90782. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90783. #endif
  90784. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90785. # ifndef FLAC__NO_ASM
  90786. if(encoder->private_->cpuinfo.use_asm) {
  90787. # ifdef FLAC__CPU_IA32
  90788. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90789. # ifdef FLAC__HAS_NASM
  90790. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90791. if(encoder->protected_->max_lpc_order < 4)
  90792. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90793. else if(encoder->protected_->max_lpc_order < 8)
  90794. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90795. else if(encoder->protected_->max_lpc_order < 12)
  90796. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90797. else
  90798. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90799. }
  90800. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90801. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90802. else
  90803. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90804. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90805. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90806. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90807. }
  90808. else {
  90809. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90810. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90811. }
  90812. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90813. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90814. # endif /* FLAC__HAS_NASM */
  90815. # endif /* FLAC__CPU_IA32 */
  90816. }
  90817. # endif /* !FLAC__NO_ASM */
  90818. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90819. if(encoder->private_->use_wide_by_block) {
  90820. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90821. }
  90822. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90823. #if FLAC__HAS_OGG
  90824. encoder->private_->is_ogg = is_ogg;
  90825. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90826. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90827. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90828. }
  90829. #endif
  90830. encoder->private_->read_callback = read_callback;
  90831. encoder->private_->write_callback = write_callback;
  90832. encoder->private_->seek_callback = seek_callback;
  90833. encoder->private_->tell_callback = tell_callback;
  90834. encoder->private_->metadata_callback = metadata_callback;
  90835. encoder->private_->client_data = client_data;
  90836. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90837. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90838. }
  90839. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90840. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90841. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90842. }
  90843. if(encoder->protected_->verify) {
  90844. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90845. for(i = 0; i < encoder->protected_->channels; i++) {
  90846. 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))) {
  90847. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90848. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90849. }
  90850. }
  90851. encoder->private_->verify.input_fifo.tail = 0;
  90852. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90853. if(0 == encoder->private_->verify.decoder) {
  90854. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90855. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90856. }
  90857. 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) {
  90858. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90859. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90860. }
  90861. }
  90862. encoder->private_->verify.error_stats.absolute_sample = 0;
  90863. encoder->private_->verify.error_stats.frame_number = 0;
  90864. encoder->private_->verify.error_stats.channel = 0;
  90865. encoder->private_->verify.error_stats.sample = 0;
  90866. encoder->private_->verify.error_stats.expected = 0;
  90867. encoder->private_->verify.error_stats.got = 0;
  90868. encoder->private_->first_seekpoint_to_check = 0;
  90869. encoder->private_->samples_written = 0;
  90870. encoder->protected_->streaminfo_offset = 0;
  90871. encoder->protected_->seektable_offset = 0;
  90872. encoder->protected_->audio_offset = 0;
  90873. if(encoder->protected_->verify)
  90874. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90875. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90876. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90877. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90878. }
  90879. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90880. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90881. }
  90882. if(encoder->protected_->verify)
  90883. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90884. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90885. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90886. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90887. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90888. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90889. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90890. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90891. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90892. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90893. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90894. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90895. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90896. if(encoder->protected_->do_md5)
  90897. FLAC__MD5Init(&encoder->private_->md5context);
  90898. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90899. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90900. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90901. }
  90902. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90903. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90904. }
  90905. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90906. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90907. if(!metadata_has_vorbis_comment) {
  90908. FLAC__StreamMetadata vorbis_comment;
  90909. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90910. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90911. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90912. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90913. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90914. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90915. vorbis_comment.data.vorbis_comment.comments = 0;
  90916. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90917. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90918. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90919. }
  90920. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90921. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90922. }
  90923. }
  90924. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90925. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90926. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90927. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90928. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90929. }
  90930. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90931. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90932. }
  90933. }
  90934. 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 */
  90935. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90936. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90937. }
  90938. if(encoder->protected_->verify)
  90939. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90940. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90941. }
  90942. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90943. FLAC__StreamEncoder *encoder,
  90944. FLAC__StreamEncoderWriteCallback write_callback,
  90945. FLAC__StreamEncoderSeekCallback seek_callback,
  90946. FLAC__StreamEncoderTellCallback tell_callback,
  90947. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90948. void *client_data
  90949. )
  90950. {
  90951. return init_stream_internal_enc(
  90952. encoder,
  90953. 0,
  90954. write_callback,
  90955. seek_callback,
  90956. tell_callback,
  90957. metadata_callback,
  90958. client_data,
  90959. false
  90960. );
  90961. }
  90962. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90963. FLAC__StreamEncoder *encoder,
  90964. FLAC__StreamEncoderReadCallback read_callback,
  90965. FLAC__StreamEncoderWriteCallback write_callback,
  90966. FLAC__StreamEncoderSeekCallback seek_callback,
  90967. FLAC__StreamEncoderTellCallback tell_callback,
  90968. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90969. void *client_data
  90970. )
  90971. {
  90972. return init_stream_internal_enc(
  90973. encoder,
  90974. read_callback,
  90975. write_callback,
  90976. seek_callback,
  90977. tell_callback,
  90978. metadata_callback,
  90979. client_data,
  90980. true
  90981. );
  90982. }
  90983. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90984. FLAC__StreamEncoder *encoder,
  90985. FILE *file,
  90986. FLAC__StreamEncoderProgressCallback progress_callback,
  90987. void *client_data,
  90988. FLAC__bool is_ogg
  90989. )
  90990. {
  90991. FLAC__StreamEncoderInitStatus init_status;
  90992. FLAC__ASSERT(0 != encoder);
  90993. FLAC__ASSERT(0 != file);
  90994. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90995. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90996. if(file == 0) {
  90997. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90998. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90999. }
  91000. if(file == stdout)
  91001. file = get_binary_stdout_(); /* just to be safe */
  91002. encoder->private_->file = file;
  91003. encoder->private_->progress_callback = progress_callback;
  91004. encoder->private_->bytes_written = 0;
  91005. encoder->private_->samples_written = 0;
  91006. encoder->private_->frames_written = 0;
  91007. init_status = init_stream_internal_enc(
  91008. encoder,
  91009. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  91010. file_write_callback_,
  91011. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  91012. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  91013. 0,
  91014. client_data,
  91015. is_ogg
  91016. );
  91017. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  91018. return init_status;
  91019. }
  91020. {
  91021. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91022. FLAC__ASSERT(blocksize != 0);
  91023. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  91024. }
  91025. return init_status;
  91026. }
  91027. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  91028. FLAC__StreamEncoder *encoder,
  91029. FILE *file,
  91030. FLAC__StreamEncoderProgressCallback progress_callback,
  91031. void *client_data
  91032. )
  91033. {
  91034. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  91035. }
  91036. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  91037. FLAC__StreamEncoder *encoder,
  91038. FILE *file,
  91039. FLAC__StreamEncoderProgressCallback progress_callback,
  91040. void *client_data
  91041. )
  91042. {
  91043. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  91044. }
  91045. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  91046. FLAC__StreamEncoder *encoder,
  91047. const char *filename,
  91048. FLAC__StreamEncoderProgressCallback progress_callback,
  91049. void *client_data,
  91050. FLAC__bool is_ogg
  91051. )
  91052. {
  91053. FILE *file;
  91054. FLAC__ASSERT(0 != encoder);
  91055. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91056. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  91057. file = filename? fopen(filename, "w+b") : stdout;
  91058. if(file == 0) {
  91059. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  91060. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91061. }
  91062. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  91063. }
  91064. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  91065. FLAC__StreamEncoder *encoder,
  91066. const char *filename,
  91067. FLAC__StreamEncoderProgressCallback progress_callback,
  91068. void *client_data
  91069. )
  91070. {
  91071. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  91072. }
  91073. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  91074. FLAC__StreamEncoder *encoder,
  91075. const char *filename,
  91076. FLAC__StreamEncoderProgressCallback progress_callback,
  91077. void *client_data
  91078. )
  91079. {
  91080. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  91081. }
  91082. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  91083. {
  91084. FLAC__bool error = false;
  91085. FLAC__ASSERT(0 != encoder);
  91086. FLAC__ASSERT(0 != encoder->private_);
  91087. FLAC__ASSERT(0 != encoder->protected_);
  91088. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  91089. return true;
  91090. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  91091. if(encoder->private_->current_sample_number != 0) {
  91092. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  91093. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  91094. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  91095. error = true;
  91096. }
  91097. }
  91098. if(encoder->protected_->do_md5)
  91099. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  91100. if(!encoder->private_->is_being_deleted) {
  91101. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  91102. if(encoder->private_->seek_callback) {
  91103. #if FLAC__HAS_OGG
  91104. if(encoder->private_->is_ogg)
  91105. update_ogg_metadata_(encoder);
  91106. else
  91107. #endif
  91108. update_metadata_(encoder);
  91109. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  91110. error = true;
  91111. }
  91112. if(encoder->private_->metadata_callback)
  91113. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  91114. }
  91115. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  91116. if(!error)
  91117. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  91118. error = true;
  91119. }
  91120. }
  91121. if(0 != encoder->private_->file) {
  91122. if(encoder->private_->file != stdout)
  91123. fclose(encoder->private_->file);
  91124. encoder->private_->file = 0;
  91125. }
  91126. #if FLAC__HAS_OGG
  91127. if(encoder->private_->is_ogg)
  91128. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  91129. #endif
  91130. free_(encoder);
  91131. set_defaults_enc(encoder);
  91132. if(!error)
  91133. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  91134. return !error;
  91135. }
  91136. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  91137. {
  91138. FLAC__ASSERT(0 != encoder);
  91139. FLAC__ASSERT(0 != encoder->private_);
  91140. FLAC__ASSERT(0 != encoder->protected_);
  91141. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91142. return false;
  91143. #if FLAC__HAS_OGG
  91144. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  91145. return true;
  91146. #else
  91147. (void)value;
  91148. return false;
  91149. #endif
  91150. }
  91151. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91152. {
  91153. FLAC__ASSERT(0 != encoder);
  91154. FLAC__ASSERT(0 != encoder->private_);
  91155. FLAC__ASSERT(0 != encoder->protected_);
  91156. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91157. return false;
  91158. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91159. encoder->protected_->verify = value;
  91160. #endif
  91161. return true;
  91162. }
  91163. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91164. {
  91165. FLAC__ASSERT(0 != encoder);
  91166. FLAC__ASSERT(0 != encoder->private_);
  91167. FLAC__ASSERT(0 != encoder->protected_);
  91168. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91169. return false;
  91170. encoder->protected_->streamable_subset = value;
  91171. return true;
  91172. }
  91173. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91174. {
  91175. FLAC__ASSERT(0 != encoder);
  91176. FLAC__ASSERT(0 != encoder->private_);
  91177. FLAC__ASSERT(0 != encoder->protected_);
  91178. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91179. return false;
  91180. encoder->protected_->do_md5 = value;
  91181. return true;
  91182. }
  91183. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  91184. {
  91185. FLAC__ASSERT(0 != encoder);
  91186. FLAC__ASSERT(0 != encoder->private_);
  91187. FLAC__ASSERT(0 != encoder->protected_);
  91188. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91189. return false;
  91190. encoder->protected_->channels = value;
  91191. return true;
  91192. }
  91193. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  91194. {
  91195. FLAC__ASSERT(0 != encoder);
  91196. FLAC__ASSERT(0 != encoder->private_);
  91197. FLAC__ASSERT(0 != encoder->protected_);
  91198. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91199. return false;
  91200. encoder->protected_->bits_per_sample = value;
  91201. return true;
  91202. }
  91203. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  91204. {
  91205. FLAC__ASSERT(0 != encoder);
  91206. FLAC__ASSERT(0 != encoder->private_);
  91207. FLAC__ASSERT(0 != encoder->protected_);
  91208. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91209. return false;
  91210. encoder->protected_->sample_rate = value;
  91211. return true;
  91212. }
  91213. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  91214. {
  91215. FLAC__bool ok = true;
  91216. FLAC__ASSERT(0 != encoder);
  91217. FLAC__ASSERT(0 != encoder->private_);
  91218. FLAC__ASSERT(0 != encoder->protected_);
  91219. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91220. return false;
  91221. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  91222. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  91223. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  91224. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  91225. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91226. #if 0
  91227. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  91228. #else
  91229. encoder->protected_->num_apodizations = 1;
  91230. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91231. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91232. #endif
  91233. #endif
  91234. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  91235. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  91236. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  91237. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  91238. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  91239. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  91240. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  91241. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  91242. return ok;
  91243. }
  91244. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  91245. {
  91246. FLAC__ASSERT(0 != encoder);
  91247. FLAC__ASSERT(0 != encoder->private_);
  91248. FLAC__ASSERT(0 != encoder->protected_);
  91249. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91250. return false;
  91251. encoder->protected_->blocksize = value;
  91252. return true;
  91253. }
  91254. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91255. {
  91256. FLAC__ASSERT(0 != encoder);
  91257. FLAC__ASSERT(0 != encoder->private_);
  91258. FLAC__ASSERT(0 != encoder->protected_);
  91259. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91260. return false;
  91261. encoder->protected_->do_mid_side_stereo = value;
  91262. return true;
  91263. }
  91264. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91265. {
  91266. FLAC__ASSERT(0 != encoder);
  91267. FLAC__ASSERT(0 != encoder->private_);
  91268. FLAC__ASSERT(0 != encoder->protected_);
  91269. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91270. return false;
  91271. encoder->protected_->loose_mid_side_stereo = value;
  91272. return true;
  91273. }
  91274. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  91275. {
  91276. FLAC__ASSERT(0 != encoder);
  91277. FLAC__ASSERT(0 != encoder->private_);
  91278. FLAC__ASSERT(0 != encoder->protected_);
  91279. FLAC__ASSERT(0 != specification);
  91280. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91281. return false;
  91282. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  91283. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  91284. #else
  91285. encoder->protected_->num_apodizations = 0;
  91286. while(1) {
  91287. const char *s = strchr(specification, ';');
  91288. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  91289. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  91290. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  91291. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  91292. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  91293. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  91294. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  91295. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  91296. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  91297. else if(n==6 && 0 == strncmp("connes" , specification, n))
  91298. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  91299. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  91300. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  91301. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  91302. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  91303. if (stddev > 0.0 && stddev <= 0.5) {
  91304. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  91305. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  91306. }
  91307. }
  91308. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  91309. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  91310. else if(n==4 && 0 == strncmp("hann" , specification, n))
  91311. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  91312. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  91313. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  91314. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  91315. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  91316. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  91317. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  91318. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  91319. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  91320. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  91321. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  91322. if (p >= 0.0 && p <= 1.0) {
  91323. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  91324. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  91325. }
  91326. }
  91327. else if(n==5 && 0 == strncmp("welch" , specification, n))
  91328. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  91329. if (encoder->protected_->num_apodizations == 32)
  91330. break;
  91331. if (s)
  91332. specification = s+1;
  91333. else
  91334. break;
  91335. }
  91336. if(encoder->protected_->num_apodizations == 0) {
  91337. encoder->protected_->num_apodizations = 1;
  91338. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91339. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91340. }
  91341. #endif
  91342. return true;
  91343. }
  91344. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  91345. {
  91346. FLAC__ASSERT(0 != encoder);
  91347. FLAC__ASSERT(0 != encoder->private_);
  91348. FLAC__ASSERT(0 != encoder->protected_);
  91349. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91350. return false;
  91351. encoder->protected_->max_lpc_order = value;
  91352. return true;
  91353. }
  91354. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  91355. {
  91356. FLAC__ASSERT(0 != encoder);
  91357. FLAC__ASSERT(0 != encoder->private_);
  91358. FLAC__ASSERT(0 != encoder->protected_);
  91359. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91360. return false;
  91361. encoder->protected_->qlp_coeff_precision = value;
  91362. return true;
  91363. }
  91364. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91365. {
  91366. FLAC__ASSERT(0 != encoder);
  91367. FLAC__ASSERT(0 != encoder->private_);
  91368. FLAC__ASSERT(0 != encoder->protected_);
  91369. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91370. return false;
  91371. encoder->protected_->do_qlp_coeff_prec_search = value;
  91372. return true;
  91373. }
  91374. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91375. {
  91376. FLAC__ASSERT(0 != encoder);
  91377. FLAC__ASSERT(0 != encoder->private_);
  91378. FLAC__ASSERT(0 != encoder->protected_);
  91379. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91380. return false;
  91381. #if 0
  91382. encoder->protected_->do_escape_coding = value;
  91383. #else
  91384. (void)value;
  91385. #endif
  91386. return true;
  91387. }
  91388. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91389. {
  91390. FLAC__ASSERT(0 != encoder);
  91391. FLAC__ASSERT(0 != encoder->private_);
  91392. FLAC__ASSERT(0 != encoder->protected_);
  91393. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91394. return false;
  91395. encoder->protected_->do_exhaustive_model_search = value;
  91396. return true;
  91397. }
  91398. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91399. {
  91400. FLAC__ASSERT(0 != encoder);
  91401. FLAC__ASSERT(0 != encoder->private_);
  91402. FLAC__ASSERT(0 != encoder->protected_);
  91403. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91404. return false;
  91405. encoder->protected_->min_residual_partition_order = value;
  91406. return true;
  91407. }
  91408. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91409. {
  91410. FLAC__ASSERT(0 != encoder);
  91411. FLAC__ASSERT(0 != encoder->private_);
  91412. FLAC__ASSERT(0 != encoder->protected_);
  91413. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91414. return false;
  91415. encoder->protected_->max_residual_partition_order = value;
  91416. return true;
  91417. }
  91418. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  91419. {
  91420. FLAC__ASSERT(0 != encoder);
  91421. FLAC__ASSERT(0 != encoder->private_);
  91422. FLAC__ASSERT(0 != encoder->protected_);
  91423. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91424. return false;
  91425. #if 0
  91426. encoder->protected_->rice_parameter_search_dist = value;
  91427. #else
  91428. (void)value;
  91429. #endif
  91430. return true;
  91431. }
  91432. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  91433. {
  91434. FLAC__ASSERT(0 != encoder);
  91435. FLAC__ASSERT(0 != encoder->private_);
  91436. FLAC__ASSERT(0 != encoder->protected_);
  91437. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91438. return false;
  91439. encoder->protected_->total_samples_estimate = value;
  91440. return true;
  91441. }
  91442. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  91443. {
  91444. FLAC__ASSERT(0 != encoder);
  91445. FLAC__ASSERT(0 != encoder->private_);
  91446. FLAC__ASSERT(0 != encoder->protected_);
  91447. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91448. return false;
  91449. if(0 == metadata)
  91450. num_blocks = 0;
  91451. if(0 == num_blocks)
  91452. metadata = 0;
  91453. if(encoder->protected_->metadata) {
  91454. free(encoder->protected_->metadata);
  91455. encoder->protected_->metadata = 0;
  91456. encoder->protected_->num_metadata_blocks = 0;
  91457. }
  91458. if(num_blocks) {
  91459. FLAC__StreamMetadata **m;
  91460. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  91461. return false;
  91462. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  91463. encoder->protected_->metadata = m;
  91464. encoder->protected_->num_metadata_blocks = num_blocks;
  91465. }
  91466. #if FLAC__HAS_OGG
  91467. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  91468. return false;
  91469. #endif
  91470. return true;
  91471. }
  91472. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91473. {
  91474. FLAC__ASSERT(0 != encoder);
  91475. FLAC__ASSERT(0 != encoder->private_);
  91476. FLAC__ASSERT(0 != encoder->protected_);
  91477. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91478. return false;
  91479. encoder->private_->disable_constant_subframes = value;
  91480. return true;
  91481. }
  91482. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91483. {
  91484. FLAC__ASSERT(0 != encoder);
  91485. FLAC__ASSERT(0 != encoder->private_);
  91486. FLAC__ASSERT(0 != encoder->protected_);
  91487. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91488. return false;
  91489. encoder->private_->disable_fixed_subframes = value;
  91490. return true;
  91491. }
  91492. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91493. {
  91494. FLAC__ASSERT(0 != encoder);
  91495. FLAC__ASSERT(0 != encoder->private_);
  91496. FLAC__ASSERT(0 != encoder->protected_);
  91497. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91498. return false;
  91499. encoder->private_->disable_verbatim_subframes = value;
  91500. return true;
  91501. }
  91502. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  91503. {
  91504. FLAC__ASSERT(0 != encoder);
  91505. FLAC__ASSERT(0 != encoder->private_);
  91506. FLAC__ASSERT(0 != encoder->protected_);
  91507. return encoder->protected_->state;
  91508. }
  91509. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  91510. {
  91511. FLAC__ASSERT(0 != encoder);
  91512. FLAC__ASSERT(0 != encoder->private_);
  91513. FLAC__ASSERT(0 != encoder->protected_);
  91514. if(encoder->protected_->verify)
  91515. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  91516. else
  91517. return FLAC__STREAM_DECODER_UNINITIALIZED;
  91518. }
  91519. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  91520. {
  91521. FLAC__ASSERT(0 != encoder);
  91522. FLAC__ASSERT(0 != encoder->private_);
  91523. FLAC__ASSERT(0 != encoder->protected_);
  91524. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  91525. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  91526. else
  91527. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  91528. }
  91529. 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)
  91530. {
  91531. FLAC__ASSERT(0 != encoder);
  91532. FLAC__ASSERT(0 != encoder->private_);
  91533. FLAC__ASSERT(0 != encoder->protected_);
  91534. if(0 != absolute_sample)
  91535. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  91536. if(0 != frame_number)
  91537. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91538. if(0 != channel)
  91539. *channel = encoder->private_->verify.error_stats.channel;
  91540. if(0 != sample)
  91541. *sample = encoder->private_->verify.error_stats.sample;
  91542. if(0 != expected)
  91543. *expected = encoder->private_->verify.error_stats.expected;
  91544. if(0 != got)
  91545. *got = encoder->private_->verify.error_stats.got;
  91546. }
  91547. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91548. {
  91549. FLAC__ASSERT(0 != encoder);
  91550. FLAC__ASSERT(0 != encoder->private_);
  91551. FLAC__ASSERT(0 != encoder->protected_);
  91552. return encoder->protected_->verify;
  91553. }
  91554. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91555. {
  91556. FLAC__ASSERT(0 != encoder);
  91557. FLAC__ASSERT(0 != encoder->private_);
  91558. FLAC__ASSERT(0 != encoder->protected_);
  91559. return encoder->protected_->streamable_subset;
  91560. }
  91561. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91562. {
  91563. FLAC__ASSERT(0 != encoder);
  91564. FLAC__ASSERT(0 != encoder->private_);
  91565. FLAC__ASSERT(0 != encoder->protected_);
  91566. return encoder->protected_->do_md5;
  91567. }
  91568. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91569. {
  91570. FLAC__ASSERT(0 != encoder);
  91571. FLAC__ASSERT(0 != encoder->private_);
  91572. FLAC__ASSERT(0 != encoder->protected_);
  91573. return encoder->protected_->channels;
  91574. }
  91575. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91576. {
  91577. FLAC__ASSERT(0 != encoder);
  91578. FLAC__ASSERT(0 != encoder->private_);
  91579. FLAC__ASSERT(0 != encoder->protected_);
  91580. return encoder->protected_->bits_per_sample;
  91581. }
  91582. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91583. {
  91584. FLAC__ASSERT(0 != encoder);
  91585. FLAC__ASSERT(0 != encoder->private_);
  91586. FLAC__ASSERT(0 != encoder->protected_);
  91587. return encoder->protected_->sample_rate;
  91588. }
  91589. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91590. {
  91591. FLAC__ASSERT(0 != encoder);
  91592. FLAC__ASSERT(0 != encoder->private_);
  91593. FLAC__ASSERT(0 != encoder->protected_);
  91594. return encoder->protected_->blocksize;
  91595. }
  91596. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91597. {
  91598. FLAC__ASSERT(0 != encoder);
  91599. FLAC__ASSERT(0 != encoder->private_);
  91600. FLAC__ASSERT(0 != encoder->protected_);
  91601. return encoder->protected_->do_mid_side_stereo;
  91602. }
  91603. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91604. {
  91605. FLAC__ASSERT(0 != encoder);
  91606. FLAC__ASSERT(0 != encoder->private_);
  91607. FLAC__ASSERT(0 != encoder->protected_);
  91608. return encoder->protected_->loose_mid_side_stereo;
  91609. }
  91610. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91611. {
  91612. FLAC__ASSERT(0 != encoder);
  91613. FLAC__ASSERT(0 != encoder->private_);
  91614. FLAC__ASSERT(0 != encoder->protected_);
  91615. return encoder->protected_->max_lpc_order;
  91616. }
  91617. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91618. {
  91619. FLAC__ASSERT(0 != encoder);
  91620. FLAC__ASSERT(0 != encoder->private_);
  91621. FLAC__ASSERT(0 != encoder->protected_);
  91622. return encoder->protected_->qlp_coeff_precision;
  91623. }
  91624. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91625. {
  91626. FLAC__ASSERT(0 != encoder);
  91627. FLAC__ASSERT(0 != encoder->private_);
  91628. FLAC__ASSERT(0 != encoder->protected_);
  91629. return encoder->protected_->do_qlp_coeff_prec_search;
  91630. }
  91631. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91632. {
  91633. FLAC__ASSERT(0 != encoder);
  91634. FLAC__ASSERT(0 != encoder->private_);
  91635. FLAC__ASSERT(0 != encoder->protected_);
  91636. return encoder->protected_->do_escape_coding;
  91637. }
  91638. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91639. {
  91640. FLAC__ASSERT(0 != encoder);
  91641. FLAC__ASSERT(0 != encoder->private_);
  91642. FLAC__ASSERT(0 != encoder->protected_);
  91643. return encoder->protected_->do_exhaustive_model_search;
  91644. }
  91645. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91646. {
  91647. FLAC__ASSERT(0 != encoder);
  91648. FLAC__ASSERT(0 != encoder->private_);
  91649. FLAC__ASSERT(0 != encoder->protected_);
  91650. return encoder->protected_->min_residual_partition_order;
  91651. }
  91652. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91653. {
  91654. FLAC__ASSERT(0 != encoder);
  91655. FLAC__ASSERT(0 != encoder->private_);
  91656. FLAC__ASSERT(0 != encoder->protected_);
  91657. return encoder->protected_->max_residual_partition_order;
  91658. }
  91659. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91660. {
  91661. FLAC__ASSERT(0 != encoder);
  91662. FLAC__ASSERT(0 != encoder->private_);
  91663. FLAC__ASSERT(0 != encoder->protected_);
  91664. return encoder->protected_->rice_parameter_search_dist;
  91665. }
  91666. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91667. {
  91668. FLAC__ASSERT(0 != encoder);
  91669. FLAC__ASSERT(0 != encoder->private_);
  91670. FLAC__ASSERT(0 != encoder->protected_);
  91671. return encoder->protected_->total_samples_estimate;
  91672. }
  91673. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91674. {
  91675. unsigned i, j = 0, channel;
  91676. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91677. FLAC__ASSERT(0 != encoder);
  91678. FLAC__ASSERT(0 != encoder->private_);
  91679. FLAC__ASSERT(0 != encoder->protected_);
  91680. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91681. do {
  91682. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91683. if(encoder->protected_->verify)
  91684. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91685. for(channel = 0; channel < channels; channel++)
  91686. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91687. if(encoder->protected_->do_mid_side_stereo) {
  91688. FLAC__ASSERT(channels == 2);
  91689. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91690. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91691. 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' ! */
  91692. }
  91693. }
  91694. else
  91695. j += n;
  91696. encoder->private_->current_sample_number += n;
  91697. if(encoder->private_->current_sample_number > blocksize) {
  91698. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91699. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91700. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91701. return false;
  91702. for(channel = 0; channel < channels; channel++)
  91703. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91704. if(encoder->protected_->do_mid_side_stereo) {
  91705. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91706. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91707. }
  91708. encoder->private_->current_sample_number = 1;
  91709. }
  91710. } while(j < samples);
  91711. return true;
  91712. }
  91713. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91714. {
  91715. unsigned i, j, k, channel;
  91716. FLAC__int32 x, mid, side;
  91717. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91718. FLAC__ASSERT(0 != encoder);
  91719. FLAC__ASSERT(0 != encoder->private_);
  91720. FLAC__ASSERT(0 != encoder->protected_);
  91721. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91722. j = k = 0;
  91723. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91724. do {
  91725. if(encoder->protected_->verify)
  91726. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91727. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91728. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91729. x = buffer[k++];
  91730. encoder->private_->integer_signal[1][i] = x;
  91731. mid += x;
  91732. side -= x;
  91733. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91734. encoder->private_->integer_signal_mid_side[1][i] = side;
  91735. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91736. }
  91737. encoder->private_->current_sample_number = i;
  91738. if(i > blocksize) {
  91739. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91740. return false;
  91741. /* move unprocessed overread samples to beginnings of arrays */
  91742. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91743. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91744. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91745. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91746. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91747. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91748. encoder->private_->current_sample_number = 1;
  91749. }
  91750. } while(j < samples);
  91751. }
  91752. else {
  91753. do {
  91754. if(encoder->protected_->verify)
  91755. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91756. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91757. for(channel = 0; channel < channels; channel++)
  91758. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91759. }
  91760. encoder->private_->current_sample_number = i;
  91761. if(i > blocksize) {
  91762. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91763. return false;
  91764. /* move unprocessed overread samples to beginnings of arrays */
  91765. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91766. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91767. for(channel = 0; channel < channels; channel++)
  91768. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91769. encoder->private_->current_sample_number = 1;
  91770. }
  91771. } while(j < samples);
  91772. }
  91773. return true;
  91774. }
  91775. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91776. {
  91777. FLAC__ASSERT(0 != encoder);
  91778. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91779. encoder->protected_->verify = true;
  91780. #else
  91781. encoder->protected_->verify = false;
  91782. #endif
  91783. encoder->protected_->streamable_subset = true;
  91784. encoder->protected_->do_md5 = true;
  91785. encoder->protected_->do_mid_side_stereo = false;
  91786. encoder->protected_->loose_mid_side_stereo = false;
  91787. encoder->protected_->channels = 2;
  91788. encoder->protected_->bits_per_sample = 16;
  91789. encoder->protected_->sample_rate = 44100;
  91790. encoder->protected_->blocksize = 0;
  91791. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91792. encoder->protected_->num_apodizations = 1;
  91793. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91794. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91795. #endif
  91796. encoder->protected_->max_lpc_order = 0;
  91797. encoder->protected_->qlp_coeff_precision = 0;
  91798. encoder->protected_->do_qlp_coeff_prec_search = false;
  91799. encoder->protected_->do_exhaustive_model_search = false;
  91800. encoder->protected_->do_escape_coding = false;
  91801. encoder->protected_->min_residual_partition_order = 0;
  91802. encoder->protected_->max_residual_partition_order = 0;
  91803. encoder->protected_->rice_parameter_search_dist = 0;
  91804. encoder->protected_->total_samples_estimate = 0;
  91805. encoder->protected_->metadata = 0;
  91806. encoder->protected_->num_metadata_blocks = 0;
  91807. encoder->private_->seek_table = 0;
  91808. encoder->private_->disable_constant_subframes = false;
  91809. encoder->private_->disable_fixed_subframes = false;
  91810. encoder->private_->disable_verbatim_subframes = false;
  91811. #if FLAC__HAS_OGG
  91812. encoder->private_->is_ogg = false;
  91813. #endif
  91814. encoder->private_->read_callback = 0;
  91815. encoder->private_->write_callback = 0;
  91816. encoder->private_->seek_callback = 0;
  91817. encoder->private_->tell_callback = 0;
  91818. encoder->private_->metadata_callback = 0;
  91819. encoder->private_->progress_callback = 0;
  91820. encoder->private_->client_data = 0;
  91821. #if FLAC__HAS_OGG
  91822. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91823. #endif
  91824. }
  91825. void free_(FLAC__StreamEncoder *encoder)
  91826. {
  91827. unsigned i, channel;
  91828. FLAC__ASSERT(0 != encoder);
  91829. if(encoder->protected_->metadata) {
  91830. free(encoder->protected_->metadata);
  91831. encoder->protected_->metadata = 0;
  91832. encoder->protected_->num_metadata_blocks = 0;
  91833. }
  91834. for(i = 0; i < encoder->protected_->channels; i++) {
  91835. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91836. free(encoder->private_->integer_signal_unaligned[i]);
  91837. encoder->private_->integer_signal_unaligned[i] = 0;
  91838. }
  91839. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91840. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91841. free(encoder->private_->real_signal_unaligned[i]);
  91842. encoder->private_->real_signal_unaligned[i] = 0;
  91843. }
  91844. #endif
  91845. }
  91846. for(i = 0; i < 2; i++) {
  91847. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91848. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91849. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91850. }
  91851. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91852. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91853. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91854. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91855. }
  91856. #endif
  91857. }
  91858. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91859. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91860. if(0 != encoder->private_->window_unaligned[i]) {
  91861. free(encoder->private_->window_unaligned[i]);
  91862. encoder->private_->window_unaligned[i] = 0;
  91863. }
  91864. }
  91865. if(0 != encoder->private_->windowed_signal_unaligned) {
  91866. free(encoder->private_->windowed_signal_unaligned);
  91867. encoder->private_->windowed_signal_unaligned = 0;
  91868. }
  91869. #endif
  91870. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91871. for(i = 0; i < 2; i++) {
  91872. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91873. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91874. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91875. }
  91876. }
  91877. }
  91878. for(channel = 0; channel < 2; channel++) {
  91879. for(i = 0; i < 2; i++) {
  91880. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91881. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91882. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91883. }
  91884. }
  91885. }
  91886. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91887. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91888. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91889. }
  91890. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91891. free(encoder->private_->raw_bits_per_partition_unaligned);
  91892. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91893. }
  91894. if(encoder->protected_->verify) {
  91895. for(i = 0; i < encoder->protected_->channels; i++) {
  91896. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91897. free(encoder->private_->verify.input_fifo.data[i]);
  91898. encoder->private_->verify.input_fifo.data[i] = 0;
  91899. }
  91900. }
  91901. }
  91902. FLAC__bitwriter_free(encoder->private_->frame);
  91903. }
  91904. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91905. {
  91906. FLAC__bool ok;
  91907. unsigned i, channel;
  91908. FLAC__ASSERT(new_blocksize > 0);
  91909. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91910. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91911. if(new_blocksize <= encoder->private_->input_capacity)
  91912. return true;
  91913. ok = true;
  91914. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91915. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91916. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91917. encoder->private_->integer_signal[i] += 4;
  91918. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91919. #if 0 /* @@@ currently unused */
  91920. if(encoder->protected_->max_lpc_order > 0)
  91921. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91922. #endif
  91923. #endif
  91924. }
  91925. for(i = 0; ok && i < 2; i++) {
  91926. 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]);
  91927. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91928. encoder->private_->integer_signal_mid_side[i] += 4;
  91929. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91930. #if 0 /* @@@ currently unused */
  91931. if(encoder->protected_->max_lpc_order > 0)
  91932. 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]);
  91933. #endif
  91934. #endif
  91935. }
  91936. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91937. if(ok && encoder->protected_->max_lpc_order > 0) {
  91938. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91939. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91940. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91941. }
  91942. #endif
  91943. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91944. for(i = 0; ok && i < 2; i++) {
  91945. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91946. }
  91947. }
  91948. for(channel = 0; ok && channel < 2; channel++) {
  91949. for(i = 0; ok && i < 2; i++) {
  91950. 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]);
  91951. }
  91952. }
  91953. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91954. if(encoder->protected_->do_escape_coding)
  91955. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91956. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91957. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91958. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91959. switch(encoder->protected_->apodizations[i].type) {
  91960. case FLAC__APODIZATION_BARTLETT:
  91961. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91962. break;
  91963. case FLAC__APODIZATION_BARTLETT_HANN:
  91964. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91965. break;
  91966. case FLAC__APODIZATION_BLACKMAN:
  91967. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91968. break;
  91969. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91970. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91971. break;
  91972. case FLAC__APODIZATION_CONNES:
  91973. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91974. break;
  91975. case FLAC__APODIZATION_FLATTOP:
  91976. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91977. break;
  91978. case FLAC__APODIZATION_GAUSS:
  91979. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91980. break;
  91981. case FLAC__APODIZATION_HAMMING:
  91982. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91983. break;
  91984. case FLAC__APODIZATION_HANN:
  91985. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91986. break;
  91987. case FLAC__APODIZATION_KAISER_BESSEL:
  91988. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91989. break;
  91990. case FLAC__APODIZATION_NUTTALL:
  91991. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91992. break;
  91993. case FLAC__APODIZATION_RECTANGLE:
  91994. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91995. break;
  91996. case FLAC__APODIZATION_TRIANGLE:
  91997. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91998. break;
  91999. case FLAC__APODIZATION_TUKEY:
  92000. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  92001. break;
  92002. case FLAC__APODIZATION_WELCH:
  92003. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  92004. break;
  92005. default:
  92006. FLAC__ASSERT(0);
  92007. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  92008. break;
  92009. }
  92010. }
  92011. }
  92012. #endif
  92013. if(ok)
  92014. encoder->private_->input_capacity = new_blocksize;
  92015. else
  92016. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92017. return ok;
  92018. }
  92019. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  92020. {
  92021. const FLAC__byte *buffer;
  92022. size_t bytes;
  92023. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  92024. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  92025. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92026. return false;
  92027. }
  92028. if(encoder->protected_->verify) {
  92029. encoder->private_->verify.output.data = buffer;
  92030. encoder->private_->verify.output.bytes = bytes;
  92031. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  92032. encoder->private_->verify.needs_magic_hack = true;
  92033. }
  92034. else {
  92035. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  92036. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92037. FLAC__bitwriter_clear(encoder->private_->frame);
  92038. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  92039. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  92040. return false;
  92041. }
  92042. }
  92043. }
  92044. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92045. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92046. FLAC__bitwriter_clear(encoder->private_->frame);
  92047. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92048. return false;
  92049. }
  92050. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92051. FLAC__bitwriter_clear(encoder->private_->frame);
  92052. if(samples > 0) {
  92053. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  92054. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  92055. }
  92056. return true;
  92057. }
  92058. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  92059. {
  92060. FLAC__StreamEncoderWriteStatus status;
  92061. FLAC__uint64 output_position = 0;
  92062. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  92063. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92064. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  92065. }
  92066. if(samples == 0) {
  92067. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  92068. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  92069. encoder->protected_->streaminfo_offset = output_position;
  92070. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  92071. encoder->protected_->seektable_offset = output_position;
  92072. }
  92073. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  92074. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  92075. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  92076. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  92077. FLAC__uint64 test_sample;
  92078. unsigned i;
  92079. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  92080. test_sample = encoder->private_->seek_table->points[i].sample_number;
  92081. if(test_sample > frame_last_sample) {
  92082. break;
  92083. }
  92084. else if(test_sample >= frame_first_sample) {
  92085. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  92086. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  92087. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  92088. encoder->private_->first_seekpoint_to_check++;
  92089. }
  92090. else {
  92091. encoder->private_->first_seekpoint_to_check++;
  92092. }
  92093. }
  92094. }
  92095. #if FLAC__HAS_OGG
  92096. if(encoder->private_->is_ogg) {
  92097. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  92098. &encoder->protected_->ogg_encoder_aspect,
  92099. buffer,
  92100. bytes,
  92101. samples,
  92102. encoder->private_->current_frame_number,
  92103. is_last_block,
  92104. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  92105. encoder,
  92106. encoder->private_->client_data
  92107. );
  92108. }
  92109. else
  92110. #endif
  92111. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  92112. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92113. encoder->private_->bytes_written += bytes;
  92114. encoder->private_->samples_written += samples;
  92115. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  92116. }
  92117. else
  92118. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92119. return status;
  92120. }
  92121. void update_metadata_(const FLAC__StreamEncoder *encoder)
  92122. {
  92123. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92124. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92125. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92126. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92127. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92128. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  92129. FLAC__StreamEncoderSeekStatus seek_status;
  92130. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92131. {
  92132. const unsigned md5_offset =
  92133. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92134. (
  92135. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92136. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92137. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92138. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92139. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92140. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92141. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92142. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92143. ) / 8;
  92144. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  92145. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92146. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92147. return;
  92148. }
  92149. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92150. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92151. return;
  92152. }
  92153. }
  92154. {
  92155. const unsigned total_samples_byte_offset =
  92156. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92157. (
  92158. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92159. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92160. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92161. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92162. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92163. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92164. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92165. - 4
  92166. ) / 8;
  92167. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  92168. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92169. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92170. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92171. b[4] = (FLAC__byte)(samples & 0xFF);
  92172. 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) {
  92173. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92174. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92175. return;
  92176. }
  92177. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92178. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92179. return;
  92180. }
  92181. }
  92182. {
  92183. const unsigned min_framesize_offset =
  92184. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92185. (
  92186. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92187. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92188. ) / 8;
  92189. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92190. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92191. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92192. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92193. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92194. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92195. 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) {
  92196. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92197. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92198. return;
  92199. }
  92200. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92201. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92202. return;
  92203. }
  92204. }
  92205. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92206. unsigned i;
  92207. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92208. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92209. 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) {
  92210. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92211. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92212. return;
  92213. }
  92214. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  92215. FLAC__uint64 xx;
  92216. unsigned x;
  92217. xx = encoder->private_->seek_table->points[i].sample_number;
  92218. b[7] = (FLAC__byte)xx; xx >>= 8;
  92219. b[6] = (FLAC__byte)xx; xx >>= 8;
  92220. b[5] = (FLAC__byte)xx; xx >>= 8;
  92221. b[4] = (FLAC__byte)xx; xx >>= 8;
  92222. b[3] = (FLAC__byte)xx; xx >>= 8;
  92223. b[2] = (FLAC__byte)xx; xx >>= 8;
  92224. b[1] = (FLAC__byte)xx; xx >>= 8;
  92225. b[0] = (FLAC__byte)xx; xx >>= 8;
  92226. xx = encoder->private_->seek_table->points[i].stream_offset;
  92227. b[15] = (FLAC__byte)xx; xx >>= 8;
  92228. b[14] = (FLAC__byte)xx; xx >>= 8;
  92229. b[13] = (FLAC__byte)xx; xx >>= 8;
  92230. b[12] = (FLAC__byte)xx; xx >>= 8;
  92231. b[11] = (FLAC__byte)xx; xx >>= 8;
  92232. b[10] = (FLAC__byte)xx; xx >>= 8;
  92233. b[9] = (FLAC__byte)xx; xx >>= 8;
  92234. b[8] = (FLAC__byte)xx; xx >>= 8;
  92235. x = encoder->private_->seek_table->points[i].frame_samples;
  92236. b[17] = (FLAC__byte)x; x >>= 8;
  92237. b[16] = (FLAC__byte)x; x >>= 8;
  92238. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92239. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92240. return;
  92241. }
  92242. }
  92243. }
  92244. }
  92245. #if FLAC__HAS_OGG
  92246. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  92247. {
  92248. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  92249. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  92250. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  92251. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  92252. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  92253. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  92254. FLAC__STREAM_SYNC_LENGTH
  92255. ;
  92256. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92257. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92258. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92259. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92260. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92261. ogg_page page;
  92262. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92263. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  92264. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  92265. return;
  92266. simple_ogg_page__init(&page);
  92267. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92268. simple_ogg_page__clear(&page);
  92269. return; /* state already set */
  92270. }
  92271. {
  92272. const unsigned md5_offset =
  92273. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92274. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92275. (
  92276. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92277. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92278. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92279. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92280. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92281. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92282. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92283. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92284. ) / 8;
  92285. if(md5_offset + 16 > (unsigned)page.body_len) {
  92286. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92287. simple_ogg_page__clear(&page);
  92288. return;
  92289. }
  92290. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  92291. }
  92292. {
  92293. const unsigned total_samples_byte_offset =
  92294. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92295. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92296. (
  92297. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92298. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92299. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92300. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92301. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92302. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92303. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92304. - 4
  92305. ) / 8;
  92306. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  92307. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92308. simple_ogg_page__clear(&page);
  92309. return;
  92310. }
  92311. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  92312. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  92313. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92314. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92315. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92316. b[4] = (FLAC__byte)(samples & 0xFF);
  92317. memcpy(page.body + total_samples_byte_offset, b, 5);
  92318. }
  92319. {
  92320. const unsigned min_framesize_offset =
  92321. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92322. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92323. (
  92324. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92325. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92326. ) / 8;
  92327. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  92328. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92329. simple_ogg_page__clear(&page);
  92330. return;
  92331. }
  92332. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92333. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92334. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92335. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92336. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92337. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92338. memcpy(page.body + min_framesize_offset, b, 6);
  92339. }
  92340. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92341. simple_ogg_page__clear(&page);
  92342. return; /* state already set */
  92343. }
  92344. simple_ogg_page__clear(&page);
  92345. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92346. unsigned i;
  92347. FLAC__byte *p;
  92348. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92349. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92350. simple_ogg_page__init(&page);
  92351. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92352. simple_ogg_page__clear(&page);
  92353. return; /* state already set */
  92354. }
  92355. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  92356. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92357. simple_ogg_page__clear(&page);
  92358. return;
  92359. }
  92360. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  92361. FLAC__uint64 xx;
  92362. unsigned x;
  92363. xx = encoder->private_->seek_table->points[i].sample_number;
  92364. b[7] = (FLAC__byte)xx; xx >>= 8;
  92365. b[6] = (FLAC__byte)xx; xx >>= 8;
  92366. b[5] = (FLAC__byte)xx; xx >>= 8;
  92367. b[4] = (FLAC__byte)xx; xx >>= 8;
  92368. b[3] = (FLAC__byte)xx; xx >>= 8;
  92369. b[2] = (FLAC__byte)xx; xx >>= 8;
  92370. b[1] = (FLAC__byte)xx; xx >>= 8;
  92371. b[0] = (FLAC__byte)xx; xx >>= 8;
  92372. xx = encoder->private_->seek_table->points[i].stream_offset;
  92373. b[15] = (FLAC__byte)xx; xx >>= 8;
  92374. b[14] = (FLAC__byte)xx; xx >>= 8;
  92375. b[13] = (FLAC__byte)xx; xx >>= 8;
  92376. b[12] = (FLAC__byte)xx; xx >>= 8;
  92377. b[11] = (FLAC__byte)xx; xx >>= 8;
  92378. b[10] = (FLAC__byte)xx; xx >>= 8;
  92379. b[9] = (FLAC__byte)xx; xx >>= 8;
  92380. b[8] = (FLAC__byte)xx; xx >>= 8;
  92381. x = encoder->private_->seek_table->points[i].frame_samples;
  92382. b[17] = (FLAC__byte)x; x >>= 8;
  92383. b[16] = (FLAC__byte)x; x >>= 8;
  92384. memcpy(p, b, 18);
  92385. }
  92386. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92387. simple_ogg_page__clear(&page);
  92388. return; /* state already set */
  92389. }
  92390. simple_ogg_page__clear(&page);
  92391. }
  92392. }
  92393. #endif
  92394. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  92395. {
  92396. FLAC__uint16 crc;
  92397. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  92398. 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)) {
  92399. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92400. return false;
  92401. }
  92402. if(!process_subframes_(encoder, is_fractional_block)) {
  92403. return false;
  92404. }
  92405. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  92406. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92407. return false;
  92408. }
  92409. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  92410. if(
  92411. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  92412. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  92413. ) {
  92414. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92415. return false;
  92416. }
  92417. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  92418. return false;
  92419. }
  92420. encoder->private_->current_sample_number = 0;
  92421. encoder->private_->current_frame_number++;
  92422. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  92423. return true;
  92424. }
  92425. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  92426. {
  92427. FLAC__FrameHeader frame_header;
  92428. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  92429. FLAC__bool do_independent, do_mid_side;
  92430. if(is_fractional_block) {
  92431. max_partition_order = 0;
  92432. }
  92433. else {
  92434. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  92435. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  92436. }
  92437. min_partition_order = min(min_partition_order, max_partition_order);
  92438. frame_header.blocksize = encoder->protected_->blocksize;
  92439. frame_header.sample_rate = encoder->protected_->sample_rate;
  92440. frame_header.channels = encoder->protected_->channels;
  92441. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  92442. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  92443. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  92444. frame_header.number.frame_number = encoder->private_->current_frame_number;
  92445. if(encoder->protected_->do_mid_side_stereo) {
  92446. if(encoder->protected_->loose_mid_side_stereo) {
  92447. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  92448. do_independent = true;
  92449. do_mid_side = true;
  92450. }
  92451. else {
  92452. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  92453. do_mid_side = !do_independent;
  92454. }
  92455. }
  92456. else {
  92457. do_independent = true;
  92458. do_mid_side = true;
  92459. }
  92460. }
  92461. else {
  92462. do_independent = true;
  92463. do_mid_side = false;
  92464. }
  92465. FLAC__ASSERT(do_independent || do_mid_side);
  92466. if(do_independent) {
  92467. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92468. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  92469. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  92470. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  92471. }
  92472. }
  92473. if(do_mid_side) {
  92474. FLAC__ASSERT(encoder->protected_->channels == 2);
  92475. for(channel = 0; channel < 2; channel++) {
  92476. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  92477. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  92478. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  92479. }
  92480. }
  92481. if(do_independent) {
  92482. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92483. if(!
  92484. process_subframe_(
  92485. encoder,
  92486. min_partition_order,
  92487. max_partition_order,
  92488. &frame_header,
  92489. encoder->private_->subframe_bps[channel],
  92490. encoder->private_->integer_signal[channel],
  92491. encoder->private_->subframe_workspace_ptr[channel],
  92492. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  92493. encoder->private_->residual_workspace[channel],
  92494. encoder->private_->best_subframe+channel,
  92495. encoder->private_->best_subframe_bits+channel
  92496. )
  92497. )
  92498. return false;
  92499. }
  92500. }
  92501. if(do_mid_side) {
  92502. FLAC__ASSERT(encoder->protected_->channels == 2);
  92503. for(channel = 0; channel < 2; channel++) {
  92504. if(!
  92505. process_subframe_(
  92506. encoder,
  92507. min_partition_order,
  92508. max_partition_order,
  92509. &frame_header,
  92510. encoder->private_->subframe_bps_mid_side[channel],
  92511. encoder->private_->integer_signal_mid_side[channel],
  92512. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  92513. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  92514. encoder->private_->residual_workspace_mid_side[channel],
  92515. encoder->private_->best_subframe_mid_side+channel,
  92516. encoder->private_->best_subframe_bits_mid_side+channel
  92517. )
  92518. )
  92519. return false;
  92520. }
  92521. }
  92522. if(do_mid_side) {
  92523. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  92524. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  92525. FLAC__ChannelAssignment channel_assignment;
  92526. FLAC__ASSERT(encoder->protected_->channels == 2);
  92527. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  92528. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  92529. }
  92530. else {
  92531. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  92532. unsigned min_bits;
  92533. int ca;
  92534. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  92535. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  92536. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92537. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92538. FLAC__ASSERT(do_independent && do_mid_side);
  92539. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92540. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92541. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92542. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92543. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92544. min_bits = bits[channel_assignment];
  92545. for(ca = 1; ca <= 3; ca++) {
  92546. if(bits[ca] < min_bits) {
  92547. min_bits = bits[ca];
  92548. channel_assignment = (FLAC__ChannelAssignment)ca;
  92549. }
  92550. }
  92551. }
  92552. frame_header.channel_assignment = channel_assignment;
  92553. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92554. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92555. return false;
  92556. }
  92557. switch(channel_assignment) {
  92558. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92559. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92560. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92561. break;
  92562. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92563. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92564. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92565. break;
  92566. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92567. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92568. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92569. break;
  92570. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92571. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92572. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92573. break;
  92574. default:
  92575. FLAC__ASSERT(0);
  92576. }
  92577. switch(channel_assignment) {
  92578. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92579. left_bps = encoder->private_->subframe_bps [0];
  92580. right_bps = encoder->private_->subframe_bps [1];
  92581. break;
  92582. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92583. left_bps = encoder->private_->subframe_bps [0];
  92584. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92585. break;
  92586. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92587. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92588. right_bps = encoder->private_->subframe_bps [1];
  92589. break;
  92590. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92591. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92592. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92593. break;
  92594. default:
  92595. FLAC__ASSERT(0);
  92596. }
  92597. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92598. return false;
  92599. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92600. return false;
  92601. }
  92602. else {
  92603. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92604. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92605. return false;
  92606. }
  92607. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92608. 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)) {
  92609. return false;
  92610. }
  92611. }
  92612. }
  92613. if(encoder->protected_->loose_mid_side_stereo) {
  92614. encoder->private_->loose_mid_side_stereo_frame_count++;
  92615. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92616. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92617. }
  92618. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92619. return true;
  92620. }
  92621. FLAC__bool process_subframe_(
  92622. FLAC__StreamEncoder *encoder,
  92623. unsigned min_partition_order,
  92624. unsigned max_partition_order,
  92625. const FLAC__FrameHeader *frame_header,
  92626. unsigned subframe_bps,
  92627. const FLAC__int32 integer_signal[],
  92628. FLAC__Subframe *subframe[2],
  92629. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92630. FLAC__int32 *residual[2],
  92631. unsigned *best_subframe,
  92632. unsigned *best_bits
  92633. )
  92634. {
  92635. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92636. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92637. #else
  92638. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92639. #endif
  92640. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92641. FLAC__double lpc_residual_bits_per_sample;
  92642. 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 */
  92643. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92644. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92645. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92646. #endif
  92647. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92648. unsigned rice_parameter;
  92649. unsigned _candidate_bits, _best_bits;
  92650. unsigned _best_subframe;
  92651. 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;
  92652. FLAC__ASSERT(frame_header->blocksize > 0);
  92653. _best_subframe = 0;
  92654. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92655. _best_bits = UINT_MAX;
  92656. else
  92657. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92658. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92659. unsigned signal_is_constant = false;
  92660. 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);
  92661. if(
  92662. !encoder->private_->disable_constant_subframes &&
  92663. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92664. fixed_residual_bits_per_sample[1] == 0.0
  92665. #else
  92666. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92667. #endif
  92668. ) {
  92669. unsigned i;
  92670. signal_is_constant = true;
  92671. for(i = 1; i < frame_header->blocksize; i++) {
  92672. if(integer_signal[0] != integer_signal[i]) {
  92673. signal_is_constant = false;
  92674. break;
  92675. }
  92676. }
  92677. }
  92678. if(signal_is_constant) {
  92679. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92680. if(_candidate_bits < _best_bits) {
  92681. _best_subframe = !_best_subframe;
  92682. _best_bits = _candidate_bits;
  92683. }
  92684. }
  92685. else {
  92686. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92687. if(encoder->protected_->do_exhaustive_model_search) {
  92688. min_fixed_order = 0;
  92689. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92690. }
  92691. else {
  92692. min_fixed_order = max_fixed_order = guess_fixed_order;
  92693. }
  92694. if(max_fixed_order >= frame_header->blocksize)
  92695. max_fixed_order = frame_header->blocksize - 1;
  92696. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92697. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92698. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92699. continue; /* don't even try */
  92700. 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 */
  92701. #else
  92702. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92703. continue; /* don't even try */
  92704. 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 */
  92705. #endif
  92706. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92707. if(rice_parameter >= rice_parameter_limit) {
  92708. #ifdef DEBUG_VERBOSE
  92709. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92710. #endif
  92711. rice_parameter = rice_parameter_limit - 1;
  92712. }
  92713. _candidate_bits =
  92714. evaluate_fixed_subframe_(
  92715. encoder,
  92716. integer_signal,
  92717. residual[!_best_subframe],
  92718. encoder->private_->abs_residual_partition_sums,
  92719. encoder->private_->raw_bits_per_partition,
  92720. frame_header->blocksize,
  92721. subframe_bps,
  92722. fixed_order,
  92723. rice_parameter,
  92724. rice_parameter_limit,
  92725. min_partition_order,
  92726. max_partition_order,
  92727. encoder->protected_->do_escape_coding,
  92728. encoder->protected_->rice_parameter_search_dist,
  92729. subframe[!_best_subframe],
  92730. partitioned_rice_contents[!_best_subframe]
  92731. );
  92732. if(_candidate_bits < _best_bits) {
  92733. _best_subframe = !_best_subframe;
  92734. _best_bits = _candidate_bits;
  92735. }
  92736. }
  92737. }
  92738. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92739. if(encoder->protected_->max_lpc_order > 0) {
  92740. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92741. max_lpc_order = frame_header->blocksize-1;
  92742. else
  92743. max_lpc_order = encoder->protected_->max_lpc_order;
  92744. if(max_lpc_order > 0) {
  92745. unsigned a;
  92746. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92747. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92748. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92749. if(autoc[0] != 0.0) {
  92750. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92751. if(encoder->protected_->do_exhaustive_model_search) {
  92752. min_lpc_order = 1;
  92753. }
  92754. else {
  92755. const unsigned guess_lpc_order =
  92756. FLAC__lpc_compute_best_order(
  92757. lpc_error,
  92758. max_lpc_order,
  92759. frame_header->blocksize,
  92760. subframe_bps + (
  92761. encoder->protected_->do_qlp_coeff_prec_search?
  92762. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92763. encoder->protected_->qlp_coeff_precision
  92764. )
  92765. );
  92766. min_lpc_order = max_lpc_order = guess_lpc_order;
  92767. }
  92768. if(max_lpc_order >= frame_header->blocksize)
  92769. max_lpc_order = frame_header->blocksize - 1;
  92770. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92771. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92772. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92773. continue; /* don't even try */
  92774. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92775. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92776. if(rice_parameter >= rice_parameter_limit) {
  92777. #ifdef DEBUG_VERBOSE
  92778. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92779. #endif
  92780. rice_parameter = rice_parameter_limit - 1;
  92781. }
  92782. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92783. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92784. if(subframe_bps <= 17) {
  92785. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92786. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92787. }
  92788. else
  92789. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92790. }
  92791. else {
  92792. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92793. }
  92794. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92795. _candidate_bits =
  92796. evaluate_lpc_subframe_(
  92797. encoder,
  92798. integer_signal,
  92799. residual[!_best_subframe],
  92800. encoder->private_->abs_residual_partition_sums,
  92801. encoder->private_->raw_bits_per_partition,
  92802. encoder->private_->lp_coeff[lpc_order-1],
  92803. frame_header->blocksize,
  92804. subframe_bps,
  92805. lpc_order,
  92806. qlp_coeff_precision,
  92807. rice_parameter,
  92808. rice_parameter_limit,
  92809. min_partition_order,
  92810. max_partition_order,
  92811. encoder->protected_->do_escape_coding,
  92812. encoder->protected_->rice_parameter_search_dist,
  92813. subframe[!_best_subframe],
  92814. partitioned_rice_contents[!_best_subframe]
  92815. );
  92816. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92817. if(_candidate_bits < _best_bits) {
  92818. _best_subframe = !_best_subframe;
  92819. _best_bits = _candidate_bits;
  92820. }
  92821. }
  92822. }
  92823. }
  92824. }
  92825. }
  92826. }
  92827. }
  92828. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92829. }
  92830. }
  92831. if(_best_bits == UINT_MAX) {
  92832. FLAC__ASSERT(_best_subframe == 0);
  92833. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92834. }
  92835. *best_subframe = _best_subframe;
  92836. *best_bits = _best_bits;
  92837. return true;
  92838. }
  92839. FLAC__bool add_subframe_(
  92840. FLAC__StreamEncoder *encoder,
  92841. unsigned blocksize,
  92842. unsigned subframe_bps,
  92843. const FLAC__Subframe *subframe,
  92844. FLAC__BitWriter *frame
  92845. )
  92846. {
  92847. switch(subframe->type) {
  92848. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92849. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92850. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92851. return false;
  92852. }
  92853. break;
  92854. case FLAC__SUBFRAME_TYPE_FIXED:
  92855. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92856. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92857. return false;
  92858. }
  92859. break;
  92860. case FLAC__SUBFRAME_TYPE_LPC:
  92861. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92862. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92863. return false;
  92864. }
  92865. break;
  92866. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92867. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92868. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92869. return false;
  92870. }
  92871. break;
  92872. default:
  92873. FLAC__ASSERT(0);
  92874. }
  92875. return true;
  92876. }
  92877. #define SPOTCHECK_ESTIMATE 0
  92878. #if SPOTCHECK_ESTIMATE
  92879. static void spotcheck_subframe_estimate_(
  92880. FLAC__StreamEncoder *encoder,
  92881. unsigned blocksize,
  92882. unsigned subframe_bps,
  92883. const FLAC__Subframe *subframe,
  92884. unsigned estimate
  92885. )
  92886. {
  92887. FLAC__bool ret;
  92888. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92889. if(frame == 0) {
  92890. fprintf(stderr, "EST: can't allocate frame\n");
  92891. return;
  92892. }
  92893. if(!FLAC__bitwriter_init(frame)) {
  92894. fprintf(stderr, "EST: can't init frame\n");
  92895. return;
  92896. }
  92897. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92898. FLAC__ASSERT(ret);
  92899. {
  92900. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92901. if(estimate != actual)
  92902. 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);
  92903. }
  92904. FLAC__bitwriter_delete(frame);
  92905. }
  92906. #endif
  92907. unsigned evaluate_constant_subframe_(
  92908. FLAC__StreamEncoder *encoder,
  92909. const FLAC__int32 signal,
  92910. unsigned blocksize,
  92911. unsigned subframe_bps,
  92912. FLAC__Subframe *subframe
  92913. )
  92914. {
  92915. unsigned estimate;
  92916. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92917. subframe->data.constant.value = signal;
  92918. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92919. #if SPOTCHECK_ESTIMATE
  92920. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92921. #else
  92922. (void)encoder, (void)blocksize;
  92923. #endif
  92924. return estimate;
  92925. }
  92926. unsigned evaluate_fixed_subframe_(
  92927. FLAC__StreamEncoder *encoder,
  92928. const FLAC__int32 signal[],
  92929. FLAC__int32 residual[],
  92930. FLAC__uint64 abs_residual_partition_sums[],
  92931. unsigned raw_bits_per_partition[],
  92932. unsigned blocksize,
  92933. unsigned subframe_bps,
  92934. unsigned order,
  92935. unsigned rice_parameter,
  92936. unsigned rice_parameter_limit,
  92937. unsigned min_partition_order,
  92938. unsigned max_partition_order,
  92939. FLAC__bool do_escape_coding,
  92940. unsigned rice_parameter_search_dist,
  92941. FLAC__Subframe *subframe,
  92942. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92943. )
  92944. {
  92945. unsigned i, residual_bits, estimate;
  92946. const unsigned residual_samples = blocksize - order;
  92947. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92948. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92949. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92950. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92951. subframe->data.fixed.residual = residual;
  92952. residual_bits =
  92953. find_best_partition_order_(
  92954. encoder->private_,
  92955. residual,
  92956. abs_residual_partition_sums,
  92957. raw_bits_per_partition,
  92958. residual_samples,
  92959. order,
  92960. rice_parameter,
  92961. rice_parameter_limit,
  92962. min_partition_order,
  92963. max_partition_order,
  92964. subframe_bps,
  92965. do_escape_coding,
  92966. rice_parameter_search_dist,
  92967. &subframe->data.fixed.entropy_coding_method
  92968. );
  92969. subframe->data.fixed.order = order;
  92970. for(i = 0; i < order; i++)
  92971. subframe->data.fixed.warmup[i] = signal[i];
  92972. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92973. #if SPOTCHECK_ESTIMATE
  92974. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92975. #endif
  92976. return estimate;
  92977. }
  92978. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92979. unsigned evaluate_lpc_subframe_(
  92980. FLAC__StreamEncoder *encoder,
  92981. const FLAC__int32 signal[],
  92982. FLAC__int32 residual[],
  92983. FLAC__uint64 abs_residual_partition_sums[],
  92984. unsigned raw_bits_per_partition[],
  92985. const FLAC__real lp_coeff[],
  92986. unsigned blocksize,
  92987. unsigned subframe_bps,
  92988. unsigned order,
  92989. unsigned qlp_coeff_precision,
  92990. unsigned rice_parameter,
  92991. unsigned rice_parameter_limit,
  92992. unsigned min_partition_order,
  92993. unsigned max_partition_order,
  92994. FLAC__bool do_escape_coding,
  92995. unsigned rice_parameter_search_dist,
  92996. FLAC__Subframe *subframe,
  92997. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92998. )
  92999. {
  93000. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  93001. unsigned i, residual_bits, estimate;
  93002. int quantization, ret;
  93003. const unsigned residual_samples = blocksize - order;
  93004. if(subframe_bps <= 16) {
  93005. FLAC__ASSERT(order > 0);
  93006. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  93007. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  93008. }
  93009. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  93010. if(ret != 0)
  93011. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  93012. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  93013. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  93014. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  93015. else
  93016. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  93017. else
  93018. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  93019. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  93020. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  93021. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  93022. subframe->data.lpc.residual = residual;
  93023. residual_bits =
  93024. find_best_partition_order_(
  93025. encoder->private_,
  93026. residual,
  93027. abs_residual_partition_sums,
  93028. raw_bits_per_partition,
  93029. residual_samples,
  93030. order,
  93031. rice_parameter,
  93032. rice_parameter_limit,
  93033. min_partition_order,
  93034. max_partition_order,
  93035. subframe_bps,
  93036. do_escape_coding,
  93037. rice_parameter_search_dist,
  93038. &subframe->data.lpc.entropy_coding_method
  93039. );
  93040. subframe->data.lpc.order = order;
  93041. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  93042. subframe->data.lpc.quantization_level = quantization;
  93043. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  93044. for(i = 0; i < order; i++)
  93045. subframe->data.lpc.warmup[i] = signal[i];
  93046. 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;
  93047. #if SPOTCHECK_ESTIMATE
  93048. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  93049. #endif
  93050. return estimate;
  93051. }
  93052. #endif
  93053. unsigned evaluate_verbatim_subframe_(
  93054. FLAC__StreamEncoder *encoder,
  93055. const FLAC__int32 signal[],
  93056. unsigned blocksize,
  93057. unsigned subframe_bps,
  93058. FLAC__Subframe *subframe
  93059. )
  93060. {
  93061. unsigned estimate;
  93062. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  93063. subframe->data.verbatim.data = signal;
  93064. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  93065. #if SPOTCHECK_ESTIMATE
  93066. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  93067. #else
  93068. (void)encoder;
  93069. #endif
  93070. return estimate;
  93071. }
  93072. unsigned find_best_partition_order_(
  93073. FLAC__StreamEncoderPrivate *private_,
  93074. const FLAC__int32 residual[],
  93075. FLAC__uint64 abs_residual_partition_sums[],
  93076. unsigned raw_bits_per_partition[],
  93077. unsigned residual_samples,
  93078. unsigned predictor_order,
  93079. unsigned rice_parameter,
  93080. unsigned rice_parameter_limit,
  93081. unsigned min_partition_order,
  93082. unsigned max_partition_order,
  93083. unsigned bps,
  93084. FLAC__bool do_escape_coding,
  93085. unsigned rice_parameter_search_dist,
  93086. FLAC__EntropyCodingMethod *best_ecm
  93087. )
  93088. {
  93089. unsigned residual_bits, best_residual_bits = 0;
  93090. unsigned best_parameters_index = 0;
  93091. unsigned best_partition_order = 0;
  93092. const unsigned blocksize = residual_samples + predictor_order;
  93093. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  93094. min_partition_order = min(min_partition_order, max_partition_order);
  93095. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  93096. if(do_escape_coding)
  93097. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  93098. {
  93099. int partition_order;
  93100. unsigned sum;
  93101. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  93102. if(!
  93103. set_partitioned_rice_(
  93104. #ifdef EXACT_RICE_BITS_CALCULATION
  93105. residual,
  93106. #endif
  93107. abs_residual_partition_sums+sum,
  93108. raw_bits_per_partition+sum,
  93109. residual_samples,
  93110. predictor_order,
  93111. rice_parameter,
  93112. rice_parameter_limit,
  93113. rice_parameter_search_dist,
  93114. (unsigned)partition_order,
  93115. do_escape_coding,
  93116. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  93117. &residual_bits
  93118. )
  93119. )
  93120. {
  93121. FLAC__ASSERT(best_residual_bits != 0);
  93122. break;
  93123. }
  93124. sum += 1u << partition_order;
  93125. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  93126. best_residual_bits = residual_bits;
  93127. best_parameters_index = !best_parameters_index;
  93128. best_partition_order = partition_order;
  93129. }
  93130. }
  93131. }
  93132. best_ecm->data.partitioned_rice.order = best_partition_order;
  93133. {
  93134. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  93135. unsigned partition;
  93136. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  93137. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  93138. if(do_escape_coding)
  93139. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  93140. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  93141. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  93142. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  93143. break;
  93144. }
  93145. }
  93146. }
  93147. return best_residual_bits;
  93148. }
  93149. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93150. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  93151. const FLAC__int32 residual[],
  93152. FLAC__uint64 abs_residual_partition_sums[],
  93153. unsigned blocksize,
  93154. unsigned predictor_order,
  93155. unsigned min_partition_order,
  93156. unsigned max_partition_order
  93157. );
  93158. #endif
  93159. void precompute_partition_info_sums_(
  93160. const FLAC__int32 residual[],
  93161. FLAC__uint64 abs_residual_partition_sums[],
  93162. unsigned residual_samples,
  93163. unsigned predictor_order,
  93164. unsigned min_partition_order,
  93165. unsigned max_partition_order,
  93166. unsigned bps
  93167. )
  93168. {
  93169. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  93170. unsigned partitions = 1u << max_partition_order;
  93171. FLAC__ASSERT(default_partition_samples > predictor_order);
  93172. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93173. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93174. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  93175. return;
  93176. }
  93177. #endif
  93178. {
  93179. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  93180. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93181. FLAC__uint32 abs_residual_partition_sum;
  93182. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93183. end += default_partition_samples;
  93184. abs_residual_partition_sum = 0;
  93185. for( ; residual_sample < end; residual_sample++)
  93186. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93187. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93188. }
  93189. }
  93190. else { /* have to pessimistically use 64 bits for accumulator */
  93191. FLAC__uint64 abs_residual_partition_sum;
  93192. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93193. end += default_partition_samples;
  93194. abs_residual_partition_sum = 0;
  93195. for( ; residual_sample < end; residual_sample++)
  93196. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93197. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93198. }
  93199. }
  93200. }
  93201. {
  93202. unsigned from_partition = 0, to_partition = partitions;
  93203. int partition_order;
  93204. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  93205. unsigned i;
  93206. partitions >>= 1;
  93207. for(i = 0; i < partitions; i++) {
  93208. abs_residual_partition_sums[to_partition++] =
  93209. abs_residual_partition_sums[from_partition ] +
  93210. abs_residual_partition_sums[from_partition+1];
  93211. from_partition += 2;
  93212. }
  93213. }
  93214. }
  93215. }
  93216. void precompute_partition_info_escapes_(
  93217. const FLAC__int32 residual[],
  93218. unsigned raw_bits_per_partition[],
  93219. unsigned residual_samples,
  93220. unsigned predictor_order,
  93221. unsigned min_partition_order,
  93222. unsigned max_partition_order
  93223. )
  93224. {
  93225. int partition_order;
  93226. unsigned from_partition, to_partition = 0;
  93227. const unsigned blocksize = residual_samples + predictor_order;
  93228. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  93229. FLAC__int32 r;
  93230. FLAC__uint32 rmax;
  93231. unsigned partition, partition_sample, partition_samples, residual_sample;
  93232. const unsigned partitions = 1u << partition_order;
  93233. const unsigned default_partition_samples = blocksize >> partition_order;
  93234. FLAC__ASSERT(default_partition_samples > predictor_order);
  93235. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93236. partition_samples = default_partition_samples;
  93237. if(partition == 0)
  93238. partition_samples -= predictor_order;
  93239. rmax = 0;
  93240. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  93241. r = residual[residual_sample++];
  93242. if(r < 0)
  93243. rmax |= ~r;
  93244. else
  93245. rmax |= r;
  93246. }
  93247. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  93248. }
  93249. to_partition = partitions;
  93250. break; /*@@@ yuck, should remove the 'for' loop instead */
  93251. }
  93252. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  93253. unsigned m;
  93254. unsigned i;
  93255. const unsigned partitions = 1u << partition_order;
  93256. for(i = 0; i < partitions; i++) {
  93257. m = raw_bits_per_partition[from_partition];
  93258. from_partition++;
  93259. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  93260. from_partition++;
  93261. to_partition++;
  93262. }
  93263. }
  93264. }
  93265. #ifdef EXACT_RICE_BITS_CALCULATION
  93266. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93267. const unsigned rice_parameter,
  93268. const unsigned partition_samples,
  93269. const FLAC__int32 *residual
  93270. )
  93271. {
  93272. unsigned i, partition_bits =
  93273. 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 */
  93274. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  93275. ;
  93276. for(i = 0; i < partition_samples; i++)
  93277. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  93278. return partition_bits;
  93279. }
  93280. #else
  93281. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93282. const unsigned rice_parameter,
  93283. const unsigned partition_samples,
  93284. const FLAC__uint64 abs_residual_partition_sum
  93285. )
  93286. {
  93287. return
  93288. 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 */
  93289. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  93290. (
  93291. rice_parameter?
  93292. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  93293. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  93294. )
  93295. - (partition_samples >> 1)
  93296. ;
  93297. }
  93298. #endif
  93299. FLAC__bool set_partitioned_rice_(
  93300. #ifdef EXACT_RICE_BITS_CALCULATION
  93301. const FLAC__int32 residual[],
  93302. #endif
  93303. const FLAC__uint64 abs_residual_partition_sums[],
  93304. const unsigned raw_bits_per_partition[],
  93305. const unsigned residual_samples,
  93306. const unsigned predictor_order,
  93307. const unsigned suggested_rice_parameter,
  93308. const unsigned rice_parameter_limit,
  93309. const unsigned rice_parameter_search_dist,
  93310. const unsigned partition_order,
  93311. const FLAC__bool search_for_escapes,
  93312. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  93313. unsigned *bits
  93314. )
  93315. {
  93316. unsigned rice_parameter, partition_bits;
  93317. unsigned best_partition_bits, best_rice_parameter = 0;
  93318. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  93319. unsigned *parameters, *raw_bits;
  93320. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93321. unsigned min_rice_parameter, max_rice_parameter;
  93322. #else
  93323. (void)rice_parameter_search_dist;
  93324. #endif
  93325. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93326. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93327. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  93328. parameters = partitioned_rice_contents->parameters;
  93329. raw_bits = partitioned_rice_contents->raw_bits;
  93330. if(partition_order == 0) {
  93331. best_partition_bits = (unsigned)(-1);
  93332. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93333. if(rice_parameter_search_dist) {
  93334. if(suggested_rice_parameter < rice_parameter_search_dist)
  93335. min_rice_parameter = 0;
  93336. else
  93337. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  93338. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  93339. if(max_rice_parameter >= rice_parameter_limit) {
  93340. #ifdef DEBUG_VERBOSE
  93341. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  93342. #endif
  93343. max_rice_parameter = rice_parameter_limit - 1;
  93344. }
  93345. }
  93346. else
  93347. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  93348. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93349. #else
  93350. rice_parameter = suggested_rice_parameter;
  93351. #endif
  93352. #ifdef EXACT_RICE_BITS_CALCULATION
  93353. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  93354. #else
  93355. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  93356. #endif
  93357. if(partition_bits < best_partition_bits) {
  93358. best_rice_parameter = rice_parameter;
  93359. best_partition_bits = partition_bits;
  93360. }
  93361. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93362. }
  93363. #endif
  93364. if(search_for_escapes) {
  93365. 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;
  93366. if(partition_bits <= best_partition_bits) {
  93367. raw_bits[0] = raw_bits_per_partition[0];
  93368. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93369. best_partition_bits = partition_bits;
  93370. }
  93371. else
  93372. raw_bits[0] = 0;
  93373. }
  93374. parameters[0] = best_rice_parameter;
  93375. bits_ += best_partition_bits;
  93376. }
  93377. else {
  93378. unsigned partition, residual_sample;
  93379. unsigned partition_samples;
  93380. FLAC__uint64 mean, k;
  93381. const unsigned partitions = 1u << partition_order;
  93382. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93383. partition_samples = (residual_samples+predictor_order) >> partition_order;
  93384. if(partition == 0) {
  93385. if(partition_samples <= predictor_order)
  93386. return false;
  93387. else
  93388. partition_samples -= predictor_order;
  93389. }
  93390. mean = abs_residual_partition_sums[partition];
  93391. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  93392. ;
  93393. if(rice_parameter >= rice_parameter_limit) {
  93394. #ifdef DEBUG_VERBOSE
  93395. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  93396. #endif
  93397. rice_parameter = rice_parameter_limit - 1;
  93398. }
  93399. best_partition_bits = (unsigned)(-1);
  93400. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93401. if(rice_parameter_search_dist) {
  93402. if(rice_parameter < rice_parameter_search_dist)
  93403. min_rice_parameter = 0;
  93404. else
  93405. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  93406. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  93407. if(max_rice_parameter >= rice_parameter_limit) {
  93408. #ifdef DEBUG_VERBOSE
  93409. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  93410. #endif
  93411. max_rice_parameter = rice_parameter_limit - 1;
  93412. }
  93413. }
  93414. else
  93415. min_rice_parameter = max_rice_parameter = rice_parameter;
  93416. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93417. #endif
  93418. #ifdef EXACT_RICE_BITS_CALCULATION
  93419. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  93420. #else
  93421. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  93422. #endif
  93423. if(partition_bits < best_partition_bits) {
  93424. best_rice_parameter = rice_parameter;
  93425. best_partition_bits = partition_bits;
  93426. }
  93427. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93428. }
  93429. #endif
  93430. if(search_for_escapes) {
  93431. 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;
  93432. if(partition_bits <= best_partition_bits) {
  93433. raw_bits[partition] = raw_bits_per_partition[partition];
  93434. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93435. best_partition_bits = partition_bits;
  93436. }
  93437. else
  93438. raw_bits[partition] = 0;
  93439. }
  93440. parameters[partition] = best_rice_parameter;
  93441. bits_ += best_partition_bits;
  93442. residual_sample += partition_samples;
  93443. }
  93444. }
  93445. *bits = bits_;
  93446. return true;
  93447. }
  93448. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  93449. {
  93450. unsigned i, shift;
  93451. FLAC__int32 x = 0;
  93452. for(i = 0; i < samples && !(x&1); i++)
  93453. x |= signal[i];
  93454. if(x == 0) {
  93455. shift = 0;
  93456. }
  93457. else {
  93458. for(shift = 0; !(x&1); shift++)
  93459. x >>= 1;
  93460. }
  93461. if(shift > 0) {
  93462. for(i = 0; i < samples; i++)
  93463. signal[i] >>= shift;
  93464. }
  93465. return shift;
  93466. }
  93467. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93468. {
  93469. unsigned channel;
  93470. for(channel = 0; channel < channels; channel++)
  93471. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  93472. fifo->tail += wide_samples;
  93473. FLAC__ASSERT(fifo->tail <= fifo->size);
  93474. }
  93475. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93476. {
  93477. unsigned channel;
  93478. unsigned sample, wide_sample;
  93479. unsigned tail = fifo->tail;
  93480. sample = input_offset * channels;
  93481. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  93482. for(channel = 0; channel < channels; channel++)
  93483. fifo->data[channel][tail] = input[sample++];
  93484. tail++;
  93485. }
  93486. fifo->tail = tail;
  93487. FLAC__ASSERT(fifo->tail <= fifo->size);
  93488. }
  93489. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93490. {
  93491. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93492. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  93493. (void)decoder;
  93494. if(encoder->private_->verify.needs_magic_hack) {
  93495. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  93496. *bytes = FLAC__STREAM_SYNC_LENGTH;
  93497. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  93498. encoder->private_->verify.needs_magic_hack = false;
  93499. }
  93500. else {
  93501. if(encoded_bytes == 0) {
  93502. FLAC__ASSERT(0);
  93503. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  93504. }
  93505. else if(encoded_bytes < *bytes)
  93506. *bytes = encoded_bytes;
  93507. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  93508. encoder->private_->verify.output.data += *bytes;
  93509. encoder->private_->verify.output.bytes -= *bytes;
  93510. }
  93511. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93512. }
  93513. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  93514. {
  93515. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  93516. unsigned channel;
  93517. const unsigned channels = frame->header.channels;
  93518. const unsigned blocksize = frame->header.blocksize;
  93519. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  93520. (void)decoder;
  93521. for(channel = 0; channel < channels; channel++) {
  93522. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  93523. unsigned i, sample = 0;
  93524. FLAC__int32 expect = 0, got = 0;
  93525. for(i = 0; i < blocksize; i++) {
  93526. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  93527. sample = i;
  93528. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  93529. got = (FLAC__int32)buffer[channel][i];
  93530. break;
  93531. }
  93532. }
  93533. FLAC__ASSERT(i < blocksize);
  93534. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  93535. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  93536. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93537. encoder->private_->verify.error_stats.channel = channel;
  93538. encoder->private_->verify.error_stats.sample = sample;
  93539. encoder->private_->verify.error_stats.expected = expect;
  93540. encoder->private_->verify.error_stats.got = got;
  93541. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93542. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93543. }
  93544. }
  93545. encoder->private_->verify.input_fifo.tail -= blocksize;
  93546. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93547. for(channel = 0; channel < channels; channel++)
  93548. 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]));
  93549. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93550. }
  93551. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93552. {
  93553. (void)decoder, (void)metadata, (void)client_data;
  93554. }
  93555. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93556. {
  93557. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93558. (void)decoder, (void)status;
  93559. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93560. }
  93561. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93562. {
  93563. (void)client_data;
  93564. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93565. if (*bytes == 0) {
  93566. if (feof(encoder->private_->file))
  93567. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93568. else if (ferror(encoder->private_->file))
  93569. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93570. }
  93571. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93572. }
  93573. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93574. {
  93575. (void)client_data;
  93576. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93577. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93578. else
  93579. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93580. }
  93581. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93582. {
  93583. off_t offset;
  93584. (void)client_data;
  93585. offset = ftello(encoder->private_->file);
  93586. if(offset < 0) {
  93587. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93588. }
  93589. else {
  93590. *absolute_byte_offset = (FLAC__uint64)offset;
  93591. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93592. }
  93593. }
  93594. #ifdef FLAC__VALGRIND_TESTING
  93595. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93596. {
  93597. size_t ret = fwrite(ptr, size, nmemb, stream);
  93598. if(!ferror(stream))
  93599. fflush(stream);
  93600. return ret;
  93601. }
  93602. #else
  93603. #define local__fwrite fwrite
  93604. #endif
  93605. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93606. {
  93607. (void)client_data, (void)current_frame;
  93608. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93609. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93610. #if FLAC__HAS_OGG
  93611. encoder->private_->is_ogg? true :
  93612. #endif
  93613. samples > 0
  93614. );
  93615. if(call_it) {
  93616. 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);
  93617. }
  93618. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93619. }
  93620. else
  93621. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93622. }
  93623. FILE *get_binary_stdout_(void)
  93624. {
  93625. #if defined _MSC_VER || defined __MINGW32__
  93626. _setmode(_fileno(stdout), _O_BINARY);
  93627. #elif defined __CYGWIN__
  93628. setmode(_fileno(stdout), _O_BINARY);
  93629. #elif defined __EMX__
  93630. setmode(fileno(stdout), O_BINARY);
  93631. #endif
  93632. return stdout;
  93633. }
  93634. #endif
  93635. /*** End of inlined file: stream_encoder.c ***/
  93636. /*** Start of inlined file: stream_encoder_framing.c ***/
  93637. /*** Start of inlined file: juce_FlacHeader.h ***/
  93638. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93639. // tasks..
  93640. #define VERSION "1.2.1"
  93641. #define FLAC__NO_DLL 1
  93642. #if JUCE_MSVC
  93643. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93644. #endif
  93645. #if JUCE_MAC
  93646. #define FLAC__SYS_DARWIN 1
  93647. #endif
  93648. /*** End of inlined file: juce_FlacHeader.h ***/
  93649. #if JUCE_USE_FLAC
  93650. #if HAVE_CONFIG_H
  93651. # include <config.h>
  93652. #endif
  93653. #include <stdio.h>
  93654. #include <string.h> /* for strlen() */
  93655. #ifdef max
  93656. #undef max
  93657. #endif
  93658. #define max(x,y) ((x)>(y)?(x):(y))
  93659. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93660. 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);
  93661. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93662. {
  93663. unsigned i, j;
  93664. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93665. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93666. return false;
  93667. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93668. return false;
  93669. i = metadata->length;
  93670. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93671. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93672. i -= metadata->data.vorbis_comment.vendor_string.length;
  93673. i += vendor_string_length;
  93674. }
  93675. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93676. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93677. return false;
  93678. switch(metadata->type) {
  93679. case FLAC__METADATA_TYPE_STREAMINFO:
  93680. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93681. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93682. return false;
  93683. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93684. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93685. return false;
  93686. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93687. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93688. return false;
  93689. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93690. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93691. return false;
  93692. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93693. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93694. return false;
  93695. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93696. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93697. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93698. return false;
  93699. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93700. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93701. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93702. return false;
  93703. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93704. return false;
  93705. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93706. return false;
  93707. break;
  93708. case FLAC__METADATA_TYPE_PADDING:
  93709. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93710. return false;
  93711. break;
  93712. case FLAC__METADATA_TYPE_APPLICATION:
  93713. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93714. return false;
  93715. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93716. return false;
  93717. break;
  93718. case FLAC__METADATA_TYPE_SEEKTABLE:
  93719. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93720. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93721. return false;
  93722. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93723. return false;
  93724. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93725. return false;
  93726. }
  93727. break;
  93728. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93729. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93730. return false;
  93731. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93732. return false;
  93733. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93734. return false;
  93735. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93736. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93737. return false;
  93738. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93739. return false;
  93740. }
  93741. break;
  93742. case FLAC__METADATA_TYPE_CUESHEET:
  93743. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93744. 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))
  93745. return false;
  93746. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93747. return false;
  93748. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93749. return false;
  93750. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93751. return false;
  93752. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93753. return false;
  93754. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93755. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93756. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93757. return false;
  93758. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93759. return false;
  93760. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93761. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93762. return false;
  93763. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93764. return false;
  93765. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93766. return false;
  93767. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93768. return false;
  93769. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93770. return false;
  93771. for(j = 0; j < track->num_indices; j++) {
  93772. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93773. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93774. return false;
  93775. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93776. return false;
  93777. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93778. return false;
  93779. }
  93780. }
  93781. break;
  93782. case FLAC__METADATA_TYPE_PICTURE:
  93783. {
  93784. size_t len;
  93785. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93786. return false;
  93787. len = strlen(metadata->data.picture.mime_type);
  93788. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93789. return false;
  93790. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93791. return false;
  93792. len = strlen((const char *)metadata->data.picture.description);
  93793. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93794. return false;
  93795. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93796. return false;
  93797. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93798. return false;
  93799. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93800. return false;
  93801. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93802. return false;
  93803. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93804. return false;
  93805. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93806. return false;
  93807. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93808. return false;
  93809. }
  93810. break;
  93811. default:
  93812. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93813. return false;
  93814. break;
  93815. }
  93816. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93817. return true;
  93818. }
  93819. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93820. {
  93821. unsigned u, blocksize_hint, sample_rate_hint;
  93822. FLAC__byte crc;
  93823. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93824. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93825. return false;
  93826. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93827. return false;
  93828. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93829. return false;
  93830. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93831. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93832. blocksize_hint = 0;
  93833. switch(header->blocksize) {
  93834. case 192: u = 1; break;
  93835. case 576: u = 2; break;
  93836. case 1152: u = 3; break;
  93837. case 2304: u = 4; break;
  93838. case 4608: u = 5; break;
  93839. case 256: u = 8; break;
  93840. case 512: u = 9; break;
  93841. case 1024: u = 10; break;
  93842. case 2048: u = 11; break;
  93843. case 4096: u = 12; break;
  93844. case 8192: u = 13; break;
  93845. case 16384: u = 14; break;
  93846. case 32768: u = 15; break;
  93847. default:
  93848. if(header->blocksize <= 0x100)
  93849. blocksize_hint = u = 6;
  93850. else
  93851. blocksize_hint = u = 7;
  93852. break;
  93853. }
  93854. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93855. return false;
  93856. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93857. sample_rate_hint = 0;
  93858. switch(header->sample_rate) {
  93859. case 88200: u = 1; break;
  93860. case 176400: u = 2; break;
  93861. case 192000: u = 3; break;
  93862. case 8000: u = 4; break;
  93863. case 16000: u = 5; break;
  93864. case 22050: u = 6; break;
  93865. case 24000: u = 7; break;
  93866. case 32000: u = 8; break;
  93867. case 44100: u = 9; break;
  93868. case 48000: u = 10; break;
  93869. case 96000: u = 11; break;
  93870. default:
  93871. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93872. sample_rate_hint = u = 12;
  93873. else if(header->sample_rate % 10 == 0)
  93874. sample_rate_hint = u = 14;
  93875. else if(header->sample_rate <= 0xffff)
  93876. sample_rate_hint = u = 13;
  93877. else
  93878. u = 0;
  93879. break;
  93880. }
  93881. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93882. return false;
  93883. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93884. switch(header->channel_assignment) {
  93885. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93886. u = header->channels - 1;
  93887. break;
  93888. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93889. FLAC__ASSERT(header->channels == 2);
  93890. u = 8;
  93891. break;
  93892. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93893. FLAC__ASSERT(header->channels == 2);
  93894. u = 9;
  93895. break;
  93896. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93897. FLAC__ASSERT(header->channels == 2);
  93898. u = 10;
  93899. break;
  93900. default:
  93901. FLAC__ASSERT(0);
  93902. }
  93903. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93904. return false;
  93905. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93906. switch(header->bits_per_sample) {
  93907. case 8 : u = 1; break;
  93908. case 12: u = 2; break;
  93909. case 16: u = 4; break;
  93910. case 20: u = 5; break;
  93911. case 24: u = 6; break;
  93912. default: u = 0; break;
  93913. }
  93914. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93915. return false;
  93916. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93917. return false;
  93918. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93919. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93920. return false;
  93921. }
  93922. else {
  93923. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93924. return false;
  93925. }
  93926. if(blocksize_hint)
  93927. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93928. return false;
  93929. switch(sample_rate_hint) {
  93930. case 12:
  93931. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93932. return false;
  93933. break;
  93934. case 13:
  93935. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93936. return false;
  93937. break;
  93938. case 14:
  93939. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93940. return false;
  93941. break;
  93942. }
  93943. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93944. return false;
  93945. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93946. return false;
  93947. return true;
  93948. }
  93949. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93950. {
  93951. FLAC__bool ok;
  93952. ok =
  93953. 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) &&
  93954. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93955. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93956. ;
  93957. return ok;
  93958. }
  93959. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93960. {
  93961. unsigned i;
  93962. 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))
  93963. return false;
  93964. if(wasted_bits)
  93965. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93966. return false;
  93967. for(i = 0; i < subframe->order; i++)
  93968. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93969. return false;
  93970. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93971. return false;
  93972. switch(subframe->entropy_coding_method.type) {
  93973. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93974. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93975. if(!add_residual_partitioned_rice_(
  93976. bw,
  93977. subframe->residual,
  93978. residual_samples,
  93979. subframe->order,
  93980. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93981. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93982. subframe->entropy_coding_method.data.partitioned_rice.order,
  93983. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93984. ))
  93985. return false;
  93986. break;
  93987. default:
  93988. FLAC__ASSERT(0);
  93989. }
  93990. return true;
  93991. }
  93992. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93993. {
  93994. unsigned i;
  93995. 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))
  93996. return false;
  93997. if(wasted_bits)
  93998. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93999. return false;
  94000. for(i = 0; i < subframe->order; i++)
  94001. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  94002. return false;
  94003. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  94004. return false;
  94005. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  94006. return false;
  94007. for(i = 0; i < subframe->order; i++)
  94008. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  94009. return false;
  94010. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  94011. return false;
  94012. switch(subframe->entropy_coding_method.type) {
  94013. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  94014. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  94015. if(!add_residual_partitioned_rice_(
  94016. bw,
  94017. subframe->residual,
  94018. residual_samples,
  94019. subframe->order,
  94020. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  94021. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  94022. subframe->entropy_coding_method.data.partitioned_rice.order,
  94023. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  94024. ))
  94025. return false;
  94026. break;
  94027. default:
  94028. FLAC__ASSERT(0);
  94029. }
  94030. return true;
  94031. }
  94032. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  94033. {
  94034. unsigned i;
  94035. const FLAC__int32 *signal = subframe->data;
  94036. 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))
  94037. return false;
  94038. if(wasted_bits)
  94039. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  94040. return false;
  94041. for(i = 0; i < samples; i++)
  94042. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  94043. return false;
  94044. return true;
  94045. }
  94046. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  94047. {
  94048. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  94049. return false;
  94050. switch(method->type) {
  94051. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  94052. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  94053. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  94054. return false;
  94055. break;
  94056. default:
  94057. FLAC__ASSERT(0);
  94058. }
  94059. return true;
  94060. }
  94061. 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)
  94062. {
  94063. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  94064. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  94065. if(partition_order == 0) {
  94066. unsigned i;
  94067. if(raw_bits[0] == 0) {
  94068. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  94069. return false;
  94070. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  94071. return false;
  94072. }
  94073. else {
  94074. FLAC__ASSERT(rice_parameters[0] == 0);
  94075. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  94076. return false;
  94077. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  94078. return false;
  94079. for(i = 0; i < residual_samples; i++) {
  94080. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  94081. return false;
  94082. }
  94083. }
  94084. return true;
  94085. }
  94086. else {
  94087. unsigned i, j, k = 0, k_last = 0;
  94088. unsigned partition_samples;
  94089. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  94090. for(i = 0; i < (1u<<partition_order); i++) {
  94091. partition_samples = default_partition_samples;
  94092. if(i == 0)
  94093. partition_samples -= predictor_order;
  94094. k += partition_samples;
  94095. if(raw_bits[i] == 0) {
  94096. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  94097. return false;
  94098. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  94099. return false;
  94100. }
  94101. else {
  94102. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  94103. return false;
  94104. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  94105. return false;
  94106. for(j = k_last; j < k; j++) {
  94107. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  94108. return false;
  94109. }
  94110. }
  94111. k_last = k;
  94112. }
  94113. return true;
  94114. }
  94115. }
  94116. #endif
  94117. /*** End of inlined file: stream_encoder_framing.c ***/
  94118. /*** Start of inlined file: window_flac.c ***/
  94119. /*** Start of inlined file: juce_FlacHeader.h ***/
  94120. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  94121. // tasks..
  94122. #define VERSION "1.2.1"
  94123. #define FLAC__NO_DLL 1
  94124. #if JUCE_MSVC
  94125. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  94126. #endif
  94127. #if JUCE_MAC
  94128. #define FLAC__SYS_DARWIN 1
  94129. #endif
  94130. /*** End of inlined file: juce_FlacHeader.h ***/
  94131. #if JUCE_USE_FLAC
  94132. #if HAVE_CONFIG_H
  94133. # include <config.h>
  94134. #endif
  94135. #include <math.h>
  94136. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  94137. #ifndef M_PI
  94138. #define M_PI 3.14159265358979323846
  94139. #endif
  94140. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  94141. {
  94142. const FLAC__int32 N = L - 1;
  94143. FLAC__int32 n;
  94144. if (L & 1) {
  94145. for (n = 0; n <= N/2; n++)
  94146. window[n] = 2.0f * n / (float)N;
  94147. for (; n <= N; n++)
  94148. window[n] = 2.0f - 2.0f * n / (float)N;
  94149. }
  94150. else {
  94151. for (n = 0; n <= L/2-1; n++)
  94152. window[n] = 2.0f * n / (float)N;
  94153. for (; n <= N; n++)
  94154. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  94155. }
  94156. }
  94157. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  94158. {
  94159. const FLAC__int32 N = L - 1;
  94160. FLAC__int32 n;
  94161. for (n = 0; n < L; n++)
  94162. 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)));
  94163. }
  94164. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  94165. {
  94166. const FLAC__int32 N = L - 1;
  94167. FLAC__int32 n;
  94168. for (n = 0; n < L; n++)
  94169. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  94170. }
  94171. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  94172. {
  94173. const FLAC__int32 N = L - 1;
  94174. FLAC__int32 n;
  94175. for (n = 0; n <= N; n++)
  94176. 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));
  94177. }
  94178. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  94179. {
  94180. const FLAC__int32 N = L - 1;
  94181. const double N2 = (double)N / 2.;
  94182. FLAC__int32 n;
  94183. for (n = 0; n <= N; n++) {
  94184. double k = ((double)n - N2) / N2;
  94185. k = 1.0f - k * k;
  94186. window[n] = (FLAC__real)(k * k);
  94187. }
  94188. }
  94189. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  94190. {
  94191. const FLAC__int32 N = L - 1;
  94192. FLAC__int32 n;
  94193. for (n = 0; n < L; n++)
  94194. 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));
  94195. }
  94196. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  94197. {
  94198. const FLAC__int32 N = L - 1;
  94199. const double N2 = (double)N / 2.;
  94200. FLAC__int32 n;
  94201. for (n = 0; n <= N; n++) {
  94202. const double k = ((double)n - N2) / (stddev * N2);
  94203. window[n] = (FLAC__real)exp(-0.5f * k * k);
  94204. }
  94205. }
  94206. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  94207. {
  94208. const FLAC__int32 N = L - 1;
  94209. FLAC__int32 n;
  94210. for (n = 0; n < L; n++)
  94211. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  94212. }
  94213. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  94214. {
  94215. const FLAC__int32 N = L - 1;
  94216. FLAC__int32 n;
  94217. for (n = 0; n < L; n++)
  94218. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  94219. }
  94220. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  94221. {
  94222. const FLAC__int32 N = L - 1;
  94223. FLAC__int32 n;
  94224. for (n = 0; n < L; n++)
  94225. 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));
  94226. }
  94227. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  94228. {
  94229. const FLAC__int32 N = L - 1;
  94230. FLAC__int32 n;
  94231. for (n = 0; n < L; n++)
  94232. 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));
  94233. }
  94234. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  94235. {
  94236. FLAC__int32 n;
  94237. for (n = 0; n < L; n++)
  94238. window[n] = 1.0f;
  94239. }
  94240. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  94241. {
  94242. FLAC__int32 n;
  94243. if (L & 1) {
  94244. for (n = 1; n <= L+1/2; n++)
  94245. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  94246. for (; n <= L; n++)
  94247. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  94248. }
  94249. else {
  94250. for (n = 1; n <= L/2; n++)
  94251. window[n-1] = 2.0f * n / (float)L;
  94252. for (; n <= L; n++)
  94253. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  94254. }
  94255. }
  94256. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  94257. {
  94258. if (p <= 0.0)
  94259. FLAC__window_rectangle(window, L);
  94260. else if (p >= 1.0)
  94261. FLAC__window_hann(window, L);
  94262. else {
  94263. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  94264. FLAC__int32 n;
  94265. FLAC__window_rectangle(window, L);
  94266. if (Np > 0) {
  94267. for (n = 0; n <= Np; n++) {
  94268. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  94269. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  94270. }
  94271. }
  94272. }
  94273. }
  94274. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  94275. {
  94276. const FLAC__int32 N = L - 1;
  94277. const double N2 = (double)N / 2.;
  94278. FLAC__int32 n;
  94279. for (n = 0; n <= N; n++) {
  94280. const double k = ((double)n - N2) / N2;
  94281. window[n] = (FLAC__real)(1.0f - k * k);
  94282. }
  94283. }
  94284. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  94285. #endif
  94286. /*** End of inlined file: window_flac.c ***/
  94287. #else
  94288. #include <FLAC/all.h>
  94289. #endif
  94290. }
  94291. #ifdef _MSC_VER
  94292. #pragma warning (pop)
  94293. #endif
  94294. BEGIN_JUCE_NAMESPACE
  94295. using namespace FlacNamespace;
  94296. static const char* const flacFormatName = "FLAC file";
  94297. static const tchar* const flacExtensions[] = { T(".flac"), 0 };
  94298. class FlacReader : public AudioFormatReader
  94299. {
  94300. FLAC__StreamDecoder* decoder;
  94301. AudioSampleBuffer reservoir;
  94302. int reservoirStart, samplesInReservoir;
  94303. bool ok, scanningForLength;
  94304. public:
  94305. FlacReader (InputStream* const in)
  94306. : AudioFormatReader (in, TRANS (flacFormatName)),
  94307. reservoir (2, 0),
  94308. reservoirStart (0),
  94309. samplesInReservoir (0),
  94310. scanningForLength (false)
  94311. {
  94312. using namespace FlacNamespace;
  94313. lengthInSamples = 0;
  94314. decoder = FLAC__stream_decoder_new();
  94315. ok = FLAC__stream_decoder_init_stream (decoder,
  94316. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  94317. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  94318. (void*) this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  94319. if (ok)
  94320. {
  94321. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94322. if (lengthInSamples == 0 && sampleRate > 0)
  94323. {
  94324. // the length hasn't been stored in the metadata, so we'll need to
  94325. // work it out the length the hard way, by scanning the whole file..
  94326. scanningForLength = true;
  94327. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  94328. scanningForLength = false;
  94329. const int64 tempLength = lengthInSamples;
  94330. FLAC__stream_decoder_reset (decoder);
  94331. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94332. lengthInSamples = tempLength;
  94333. }
  94334. }
  94335. }
  94336. ~FlacReader()
  94337. {
  94338. FLAC__stream_decoder_delete (decoder);
  94339. }
  94340. void useMetadata (const FLAC__StreamMetadata_StreamInfo& info)
  94341. {
  94342. sampleRate = info.sample_rate;
  94343. bitsPerSample = info.bits_per_sample;
  94344. lengthInSamples = (unsigned int) info.total_samples;
  94345. numChannels = info.channels;
  94346. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  94347. }
  94348. // returns the number of samples read
  94349. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  94350. int64 startSampleInFile, int numSamples)
  94351. {
  94352. using namespace FlacNamespace;
  94353. if (! ok)
  94354. return false;
  94355. while (numSamples > 0)
  94356. {
  94357. if (startSampleInFile >= reservoirStart
  94358. && startSampleInFile < reservoirStart + samplesInReservoir)
  94359. {
  94360. const int num = (int) jmin ((int64) numSamples,
  94361. reservoirStart + samplesInReservoir - startSampleInFile);
  94362. jassert (num > 0);
  94363. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  94364. if (destSamples[i] != 0)
  94365. memcpy (destSamples[i] + startOffsetInDestBuffer,
  94366. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  94367. sizeof (int) * num);
  94368. startOffsetInDestBuffer += num;
  94369. startSampleInFile += num;
  94370. numSamples -= num;
  94371. }
  94372. else
  94373. {
  94374. if (startSampleInFile >= (int) lengthInSamples)
  94375. {
  94376. samplesInReservoir = 0;
  94377. }
  94378. else if (startSampleInFile < reservoirStart
  94379. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  94380. {
  94381. // had some problems with flac crashing if the read pos is aligned more
  94382. // accurately than this. Probably fixed in newer versions of the library, though.
  94383. reservoirStart = (int) (startSampleInFile & ~511);
  94384. samplesInReservoir = 0;
  94385. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  94386. }
  94387. else
  94388. {
  94389. reservoirStart += samplesInReservoir;
  94390. samplesInReservoir = 0;
  94391. FLAC__stream_decoder_process_single (decoder);
  94392. }
  94393. if (samplesInReservoir == 0)
  94394. break;
  94395. }
  94396. }
  94397. if (numSamples > 0)
  94398. {
  94399. for (int i = numDestChannels; --i >= 0;)
  94400. if (destSamples[i] != 0)
  94401. zeromem (destSamples[i] + startOffsetInDestBuffer,
  94402. sizeof (int) * numSamples);
  94403. }
  94404. return true;
  94405. }
  94406. void useSamples (const FLAC__int32* const buffer[], int numSamples)
  94407. {
  94408. if (scanningForLength)
  94409. {
  94410. lengthInSamples += numSamples;
  94411. }
  94412. else
  94413. {
  94414. if (numSamples > reservoir.getNumSamples())
  94415. reservoir.setSize (numChannels, numSamples, false, false, true);
  94416. const int bitsToShift = 32 - bitsPerSample;
  94417. for (int i = 0; i < (int) numChannels; ++i)
  94418. {
  94419. const FLAC__int32* src = buffer[i];
  94420. int n = i;
  94421. while (src == 0 && n > 0)
  94422. src = buffer [--n];
  94423. if (src != 0)
  94424. {
  94425. int* dest = (int*) reservoir.getSampleData(i);
  94426. for (int j = 0; j < numSamples; ++j)
  94427. dest[j] = src[j] << bitsToShift;
  94428. }
  94429. }
  94430. samplesInReservoir = numSamples;
  94431. }
  94432. }
  94433. static FLAC__StreamDecoderReadStatus readCallback_ (const FLAC__StreamDecoder*, FLAC__byte buffer[], size_t* bytes, void* client_data)
  94434. {
  94435. *bytes = (unsigned int) ((const FlacReader*) client_data)->input->read (buffer, (int) *bytes);
  94436. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  94437. }
  94438. static FLAC__StreamDecoderSeekStatus seekCallback_ (const FLAC__StreamDecoder*, FLAC__uint64 absolute_byte_offset, void* client_data)
  94439. {
  94440. ((const FlacReader*) client_data)->input->setPosition ((int) absolute_byte_offset);
  94441. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  94442. }
  94443. static FLAC__StreamDecoderTellStatus tellCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94444. {
  94445. *absolute_byte_offset = ((const FlacReader*) client_data)->input->getPosition();
  94446. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  94447. }
  94448. static FLAC__StreamDecoderLengthStatus lengthCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* stream_length, void* client_data)
  94449. {
  94450. *stream_length = ((const FlacReader*) client_data)->input->getTotalLength();
  94451. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  94452. }
  94453. static FLAC__bool eofCallback_ (const FLAC__StreamDecoder*, void* client_data)
  94454. {
  94455. return ((const FlacReader*) client_data)->input->isExhausted();
  94456. }
  94457. static FLAC__StreamDecoderWriteStatus writeCallback_ (const FLAC__StreamDecoder*,
  94458. const FLAC__Frame* frame,
  94459. const FLAC__int32* const buffer[],
  94460. void* client_data)
  94461. {
  94462. ((FlacReader*) client_data)->useSamples (buffer, frame->header.blocksize);
  94463. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  94464. }
  94465. static void metadataCallback_ (const FLAC__StreamDecoder*,
  94466. const FLAC__StreamMetadata* metadata,
  94467. void* client_data)
  94468. {
  94469. ((FlacReader*) client_data)->useMetadata (metadata->data.stream_info);
  94470. }
  94471. static void errorCallback_ (const FLAC__StreamDecoder*, FLAC__StreamDecoderErrorStatus, void*)
  94472. {
  94473. }
  94474. juce_UseDebuggingNewOperator
  94475. };
  94476. class FlacWriter : public AudioFormatWriter
  94477. {
  94478. FLAC__StreamEncoder* encoder;
  94479. MemoryBlock temp;
  94480. public:
  94481. bool ok;
  94482. FlacWriter (OutputStream* const out,
  94483. const double sampleRate_,
  94484. const int numChannels_,
  94485. const int bitsPerSample_)
  94486. : AudioFormatWriter (out, TRANS (flacFormatName),
  94487. sampleRate_,
  94488. numChannels_,
  94489. bitsPerSample_)
  94490. {
  94491. using namespace FlacNamespace;
  94492. encoder = FLAC__stream_encoder_new();
  94493. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  94494. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  94495. FLAC__stream_encoder_set_channels (encoder, numChannels);
  94496. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  94497. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  94498. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  94499. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  94500. ok = FLAC__stream_encoder_init_stream (encoder,
  94501. encodeWriteCallback, encodeSeekCallback,
  94502. encodeTellCallback, encodeMetadataCallback,
  94503. (void*) this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  94504. }
  94505. ~FlacWriter()
  94506. {
  94507. if (ok)
  94508. {
  94509. FLAC__stream_encoder_finish (encoder);
  94510. output->flush();
  94511. }
  94512. else
  94513. {
  94514. output = 0; // to stop the base class deleting this, as it needs to be returned
  94515. // to the caller of createWriter()
  94516. }
  94517. FLAC__stream_encoder_delete (encoder);
  94518. }
  94519. bool write (const int** samplesToWrite, int numSamples)
  94520. {
  94521. if (! ok)
  94522. return false;
  94523. int* buf[3];
  94524. const int bitsToShift = 32 - bitsPerSample;
  94525. if (bitsToShift > 0)
  94526. {
  94527. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  94528. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  94529. buf[0] = (int*) temp.getData();
  94530. buf[1] = buf[0] + numSamples;
  94531. buf[2] = 0;
  94532. for (int i = numChannelsToWrite; --i >= 0;)
  94533. {
  94534. if (samplesToWrite[i] != 0)
  94535. {
  94536. for (int j = 0; j < numSamples; ++j)
  94537. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94538. }
  94539. }
  94540. samplesToWrite = (const int**) buf;
  94541. }
  94542. return FLAC__stream_encoder_process (encoder,
  94543. (const FLAC__int32**) samplesToWrite,
  94544. numSamples) != 0;
  94545. }
  94546. bool writeData (const void* const data, const int size) const
  94547. {
  94548. return output->write (data, size);
  94549. }
  94550. static void packUint32 (FLAC__uint32 val, FLAC__byte* b, const int bytes)
  94551. {
  94552. b += bytes;
  94553. for (int i = 0; i < bytes; ++i)
  94554. {
  94555. *(--b) = (FLAC__byte) (val & 0xff);
  94556. val >>= 8;
  94557. }
  94558. }
  94559. void writeMetaData (const FLAC__StreamMetadata* metadata)
  94560. {
  94561. using namespace FlacNamespace;
  94562. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94563. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94564. const unsigned int channelsMinus1 = info.channels - 1;
  94565. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94566. packUint32 (info.min_blocksize, buffer, 2);
  94567. packUint32 (info.max_blocksize, buffer + 2, 2);
  94568. packUint32 (info.min_framesize, buffer + 4, 3);
  94569. packUint32 (info.max_framesize, buffer + 7, 3);
  94570. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94571. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94572. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94573. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94574. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94575. memcpy (buffer + 18, info.md5sum, 16);
  94576. const bool seekOk = output->setPosition (4);
  94577. (void) seekOk;
  94578. // if this fails, you've given it an output stream that can't seek! It needs
  94579. // to be able to seek back to write the header
  94580. jassert (seekOk);
  94581. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94582. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94583. }
  94584. static FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FLAC__StreamEncoder*,
  94585. const FLAC__byte buffer[],
  94586. size_t bytes,
  94587. unsigned int /*samples*/,
  94588. unsigned int /*current_frame*/,
  94589. void* client_data)
  94590. {
  94591. using namespace FlacNamespace;
  94592. return ((FlacWriter*) client_data)->writeData (buffer, (int) bytes)
  94593. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94594. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94595. }
  94596. static FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FLAC__StreamEncoder*, FLAC__uint64, void*)
  94597. {
  94598. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94599. }
  94600. static FLAC__StreamEncoderTellStatus encodeTellCallback (const FLAC__StreamEncoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94601. {
  94602. if (client_data == 0)
  94603. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94604. *absolute_byte_offset = (FLAC__uint64) ((FlacWriter*) client_data)->output->getPosition();
  94605. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94606. }
  94607. static void encodeMetadataCallback (const FLAC__StreamEncoder*,
  94608. const FLAC__StreamMetadata* metadata,
  94609. void* client_data)
  94610. {
  94611. ((FlacWriter*) client_data)->writeMetaData (metadata);
  94612. }
  94613. juce_UseDebuggingNewOperator
  94614. };
  94615. FlacAudioFormat::FlacAudioFormat()
  94616. : AudioFormat (TRANS (flacFormatName), (const tchar**) flacExtensions)
  94617. {
  94618. }
  94619. FlacAudioFormat::~FlacAudioFormat()
  94620. {
  94621. }
  94622. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94623. {
  94624. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94625. return Array <int> (rates);
  94626. }
  94627. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94628. {
  94629. const int depths[] = { 16, 24, 0 };
  94630. return Array <int> (depths);
  94631. }
  94632. bool FlacAudioFormat::canDoStereo()
  94633. {
  94634. return true;
  94635. }
  94636. bool FlacAudioFormat::canDoMono()
  94637. {
  94638. return true;
  94639. }
  94640. bool FlacAudioFormat::isCompressed()
  94641. {
  94642. return true;
  94643. }
  94644. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94645. const bool deleteStreamIfOpeningFails)
  94646. {
  94647. ScopedPointer <FlacReader> r (new FlacReader (in));
  94648. if (r->sampleRate != 0)
  94649. return r.release();
  94650. if (! deleteStreamIfOpeningFails)
  94651. r->input = 0;
  94652. return 0;
  94653. }
  94654. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94655. double sampleRate,
  94656. unsigned int numberOfChannels,
  94657. int bitsPerSample,
  94658. const StringPairArray& /*metadataValues*/,
  94659. int /*qualityOptionIndex*/)
  94660. {
  94661. if (getPossibleBitDepths().contains (bitsPerSample))
  94662. {
  94663. ScopedPointer <FlacWriter> w (new FlacWriter (out,
  94664. sampleRate,
  94665. numberOfChannels,
  94666. bitsPerSample));
  94667. if (w->ok)
  94668. return w.release();
  94669. }
  94670. return 0;
  94671. }
  94672. END_JUCE_NAMESPACE
  94673. #endif
  94674. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94675. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94676. #if JUCE_USE_OGGVORBIS
  94677. #if JUCE_MAC
  94678. #define __MACOSX__ 1
  94679. #endif
  94680. namespace OggVorbisNamespace
  94681. {
  94682. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94683. /*** Start of inlined file: vorbisenc.h ***/
  94684. #ifndef _OV_ENC_H_
  94685. #define _OV_ENC_H_
  94686. #ifdef __cplusplus
  94687. extern "C"
  94688. {
  94689. #endif /* __cplusplus */
  94690. /*** Start of inlined file: codec.h ***/
  94691. #ifndef _vorbis_codec_h_
  94692. #define _vorbis_codec_h_
  94693. #ifdef __cplusplus
  94694. extern "C"
  94695. {
  94696. #endif /* __cplusplus */
  94697. /*** Start of inlined file: ogg.h ***/
  94698. #ifndef _OGG_H
  94699. #define _OGG_H
  94700. #ifdef __cplusplus
  94701. extern "C" {
  94702. #endif
  94703. /*** Start of inlined file: os_types.h ***/
  94704. #ifndef _OS_TYPES_H
  94705. #define _OS_TYPES_H
  94706. #define _ogg_malloc malloc
  94707. #define _ogg_calloc calloc
  94708. #define _ogg_realloc realloc
  94709. #define _ogg_free free
  94710. #if defined(_WIN32)
  94711. # if defined(__CYGWIN__)
  94712. # include <_G_config.h>
  94713. typedef _G_int64_t ogg_int64_t;
  94714. typedef _G_int32_t ogg_int32_t;
  94715. typedef _G_uint32_t ogg_uint32_t;
  94716. typedef _G_int16_t ogg_int16_t;
  94717. typedef _G_uint16_t ogg_uint16_t;
  94718. # elif defined(__MINGW32__)
  94719. typedef short ogg_int16_t;
  94720. typedef unsigned short ogg_uint16_t;
  94721. typedef int ogg_int32_t;
  94722. typedef unsigned int ogg_uint32_t;
  94723. typedef long long ogg_int64_t;
  94724. typedef unsigned long long ogg_uint64_t;
  94725. # elif defined(__MWERKS__)
  94726. typedef long long ogg_int64_t;
  94727. typedef int ogg_int32_t;
  94728. typedef unsigned int ogg_uint32_t;
  94729. typedef short ogg_int16_t;
  94730. typedef unsigned short ogg_uint16_t;
  94731. # else
  94732. typedef __int64 ogg_int64_t;
  94733. typedef __int32 ogg_int32_t;
  94734. typedef unsigned __int32 ogg_uint32_t;
  94735. typedef __int16 ogg_int16_t;
  94736. typedef unsigned __int16 ogg_uint16_t;
  94737. # endif
  94738. #elif defined(__MACOS__)
  94739. # include <sys/types.h>
  94740. typedef SInt16 ogg_int16_t;
  94741. typedef UInt16 ogg_uint16_t;
  94742. typedef SInt32 ogg_int32_t;
  94743. typedef UInt32 ogg_uint32_t;
  94744. typedef SInt64 ogg_int64_t;
  94745. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94746. # include <sys/types.h>
  94747. typedef int16_t ogg_int16_t;
  94748. typedef u_int16_t ogg_uint16_t;
  94749. typedef int32_t ogg_int32_t;
  94750. typedef u_int32_t ogg_uint32_t;
  94751. typedef int64_t ogg_int64_t;
  94752. #elif defined(__BEOS__)
  94753. # include <inttypes.h>
  94754. typedef int16_t ogg_int16_t;
  94755. typedef u_int16_t ogg_uint16_t;
  94756. typedef int32_t ogg_int32_t;
  94757. typedef u_int32_t ogg_uint32_t;
  94758. typedef int64_t ogg_int64_t;
  94759. #elif defined (__EMX__)
  94760. typedef short ogg_int16_t;
  94761. typedef unsigned short ogg_uint16_t;
  94762. typedef int ogg_int32_t;
  94763. typedef unsigned int ogg_uint32_t;
  94764. typedef long long ogg_int64_t;
  94765. #elif defined (DJGPP)
  94766. typedef short ogg_int16_t;
  94767. typedef int ogg_int32_t;
  94768. typedef unsigned int ogg_uint32_t;
  94769. typedef long long ogg_int64_t;
  94770. #elif defined(R5900)
  94771. typedef long ogg_int64_t;
  94772. typedef int ogg_int32_t;
  94773. typedef unsigned ogg_uint32_t;
  94774. typedef short ogg_int16_t;
  94775. #elif defined(__SYMBIAN32__)
  94776. typedef signed short ogg_int16_t;
  94777. typedef unsigned short ogg_uint16_t;
  94778. typedef signed int ogg_int32_t;
  94779. typedef unsigned int ogg_uint32_t;
  94780. typedef long long int ogg_int64_t;
  94781. #else
  94782. # include <sys/types.h>
  94783. /*** Start of inlined file: config_types.h ***/
  94784. #ifndef __CONFIG_TYPES_H__
  94785. #define __CONFIG_TYPES_H__
  94786. typedef int16_t ogg_int16_t;
  94787. typedef unsigned short ogg_uint16_t;
  94788. typedef int32_t ogg_int32_t;
  94789. typedef unsigned int ogg_uint32_t;
  94790. typedef int64_t ogg_int64_t;
  94791. #endif
  94792. /*** End of inlined file: config_types.h ***/
  94793. #endif
  94794. #endif /* _OS_TYPES_H */
  94795. /*** End of inlined file: os_types.h ***/
  94796. typedef struct {
  94797. long endbyte;
  94798. int endbit;
  94799. unsigned char *buffer;
  94800. unsigned char *ptr;
  94801. long storage;
  94802. } oggpack_buffer;
  94803. typedef struct {
  94804. unsigned char *header;
  94805. long header_len;
  94806. unsigned char *body;
  94807. long body_len;
  94808. } ogg_page;
  94809. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94810. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94811. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94812. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94813. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94814. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94815. }
  94816. typedef struct {
  94817. unsigned char *body_data; /* bytes from packet bodies */
  94818. long body_storage; /* storage elements allocated */
  94819. long body_fill; /* elements stored; fill mark */
  94820. long body_returned; /* elements of fill returned */
  94821. int *lacing_vals; /* The values that will go to the segment table */
  94822. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94823. this way, but it is simple coupled to the
  94824. lacing fifo */
  94825. long lacing_storage;
  94826. long lacing_fill;
  94827. long lacing_packet;
  94828. long lacing_returned;
  94829. unsigned char header[282]; /* working space for header encode */
  94830. int header_fill;
  94831. int e_o_s; /* set when we have buffered the last packet in the
  94832. logical bitstream */
  94833. int b_o_s; /* set after we've written the initial page
  94834. of a logical bitstream */
  94835. long serialno;
  94836. long pageno;
  94837. ogg_int64_t packetno; /* sequence number for decode; the framing
  94838. knows where there's a hole in the data,
  94839. but we need coupling so that the codec
  94840. (which is in a seperate abstraction
  94841. layer) also knows about the gap */
  94842. ogg_int64_t granulepos;
  94843. } ogg_stream_state;
  94844. typedef struct {
  94845. unsigned char *packet;
  94846. long bytes;
  94847. long b_o_s;
  94848. long e_o_s;
  94849. ogg_int64_t granulepos;
  94850. ogg_int64_t packetno; /* sequence number for decode; the framing
  94851. knows where there's a hole in the data,
  94852. but we need coupling so that the codec
  94853. (which is in a seperate abstraction
  94854. layer) also knows about the gap */
  94855. } ogg_packet;
  94856. typedef struct {
  94857. unsigned char *data;
  94858. int storage;
  94859. int fill;
  94860. int returned;
  94861. int unsynced;
  94862. int headerbytes;
  94863. int bodybytes;
  94864. } ogg_sync_state;
  94865. extern void oggpack_writeinit(oggpack_buffer *b);
  94866. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94867. extern void oggpack_writealign(oggpack_buffer *b);
  94868. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94869. extern void oggpack_reset(oggpack_buffer *b);
  94870. extern void oggpack_writeclear(oggpack_buffer *b);
  94871. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94872. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94873. extern long oggpack_look(oggpack_buffer *b,int bits);
  94874. extern long oggpack_look1(oggpack_buffer *b);
  94875. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94876. extern void oggpack_adv1(oggpack_buffer *b);
  94877. extern long oggpack_read(oggpack_buffer *b,int bits);
  94878. extern long oggpack_read1(oggpack_buffer *b);
  94879. extern long oggpack_bytes(oggpack_buffer *b);
  94880. extern long oggpack_bits(oggpack_buffer *b);
  94881. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94882. extern void oggpackB_writeinit(oggpack_buffer *b);
  94883. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94884. extern void oggpackB_writealign(oggpack_buffer *b);
  94885. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94886. extern void oggpackB_reset(oggpack_buffer *b);
  94887. extern void oggpackB_writeclear(oggpack_buffer *b);
  94888. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94889. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94890. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94891. extern long oggpackB_look1(oggpack_buffer *b);
  94892. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94893. extern void oggpackB_adv1(oggpack_buffer *b);
  94894. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94895. extern long oggpackB_read1(oggpack_buffer *b);
  94896. extern long oggpackB_bytes(oggpack_buffer *b);
  94897. extern long oggpackB_bits(oggpack_buffer *b);
  94898. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94899. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94900. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94901. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94902. extern int ogg_sync_init(ogg_sync_state *oy);
  94903. extern int ogg_sync_clear(ogg_sync_state *oy);
  94904. extern int ogg_sync_reset(ogg_sync_state *oy);
  94905. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94906. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94907. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94908. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94909. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94910. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94911. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94912. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94913. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94914. extern int ogg_stream_clear(ogg_stream_state *os);
  94915. extern int ogg_stream_reset(ogg_stream_state *os);
  94916. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94917. extern int ogg_stream_destroy(ogg_stream_state *os);
  94918. extern int ogg_stream_eos(ogg_stream_state *os);
  94919. extern void ogg_page_checksum_set(ogg_page *og);
  94920. extern int ogg_page_version(ogg_page *og);
  94921. extern int ogg_page_continued(ogg_page *og);
  94922. extern int ogg_page_bos(ogg_page *og);
  94923. extern int ogg_page_eos(ogg_page *og);
  94924. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94925. extern int ogg_page_serialno(ogg_page *og);
  94926. extern long ogg_page_pageno(ogg_page *og);
  94927. extern int ogg_page_packets(ogg_page *og);
  94928. extern void ogg_packet_clear(ogg_packet *op);
  94929. #ifdef __cplusplus
  94930. }
  94931. #endif
  94932. #endif /* _OGG_H */
  94933. /*** End of inlined file: ogg.h ***/
  94934. typedef struct vorbis_info{
  94935. int version;
  94936. int channels;
  94937. long rate;
  94938. long bitrate_upper;
  94939. long bitrate_nominal;
  94940. long bitrate_lower;
  94941. long bitrate_window;
  94942. void *codec_setup;
  94943. } vorbis_info;
  94944. typedef struct vorbis_dsp_state{
  94945. int analysisp;
  94946. vorbis_info *vi;
  94947. float **pcm;
  94948. float **pcmret;
  94949. int pcm_storage;
  94950. int pcm_current;
  94951. int pcm_returned;
  94952. int preextrapolate;
  94953. int eofflag;
  94954. long lW;
  94955. long W;
  94956. long nW;
  94957. long centerW;
  94958. ogg_int64_t granulepos;
  94959. ogg_int64_t sequence;
  94960. ogg_int64_t glue_bits;
  94961. ogg_int64_t time_bits;
  94962. ogg_int64_t floor_bits;
  94963. ogg_int64_t res_bits;
  94964. void *backend_state;
  94965. } vorbis_dsp_state;
  94966. typedef struct vorbis_block{
  94967. float **pcm; /* this is a pointer into local storage */
  94968. oggpack_buffer opb;
  94969. long lW;
  94970. long W;
  94971. long nW;
  94972. int pcmend;
  94973. int mode;
  94974. int eofflag;
  94975. ogg_int64_t granulepos;
  94976. ogg_int64_t sequence;
  94977. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94978. void *localstore;
  94979. long localtop;
  94980. long localalloc;
  94981. long totaluse;
  94982. struct alloc_chain *reap;
  94983. long glue_bits;
  94984. long time_bits;
  94985. long floor_bits;
  94986. long res_bits;
  94987. void *internal;
  94988. } vorbis_block;
  94989. struct alloc_chain{
  94990. void *ptr;
  94991. struct alloc_chain *next;
  94992. };
  94993. typedef struct vorbis_comment{
  94994. char **user_comments;
  94995. int *comment_lengths;
  94996. int comments;
  94997. char *vendor;
  94998. } vorbis_comment;
  94999. extern void vorbis_info_init(vorbis_info *vi);
  95000. extern void vorbis_info_clear(vorbis_info *vi);
  95001. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  95002. extern void vorbis_comment_init(vorbis_comment *vc);
  95003. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  95004. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  95005. const char *tag, char *contents);
  95006. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  95007. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  95008. extern void vorbis_comment_clear(vorbis_comment *vc);
  95009. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  95010. extern int vorbis_block_clear(vorbis_block *vb);
  95011. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  95012. extern double vorbis_granule_time(vorbis_dsp_state *v,
  95013. ogg_int64_t granulepos);
  95014. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  95015. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  95016. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  95017. vorbis_comment *vc,
  95018. ogg_packet *op,
  95019. ogg_packet *op_comm,
  95020. ogg_packet *op_code);
  95021. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  95022. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  95023. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  95024. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  95025. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  95026. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  95027. ogg_packet *op);
  95028. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  95029. ogg_packet *op);
  95030. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  95031. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  95032. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  95033. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  95034. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  95035. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  95036. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  95037. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  95038. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  95039. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  95040. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  95041. #define OV_FALSE -1
  95042. #define OV_EOF -2
  95043. #define OV_HOLE -3
  95044. #define OV_EREAD -128
  95045. #define OV_EFAULT -129
  95046. #define OV_EIMPL -130
  95047. #define OV_EINVAL -131
  95048. #define OV_ENOTVORBIS -132
  95049. #define OV_EBADHEADER -133
  95050. #define OV_EVERSION -134
  95051. #define OV_ENOTAUDIO -135
  95052. #define OV_EBADPACKET -136
  95053. #define OV_EBADLINK -137
  95054. #define OV_ENOSEEK -138
  95055. #ifdef __cplusplus
  95056. }
  95057. #endif /* __cplusplus */
  95058. #endif
  95059. /*** End of inlined file: codec.h ***/
  95060. extern int vorbis_encode_init(vorbis_info *vi,
  95061. long channels,
  95062. long rate,
  95063. long max_bitrate,
  95064. long nominal_bitrate,
  95065. long min_bitrate);
  95066. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  95067. long channels,
  95068. long rate,
  95069. long max_bitrate,
  95070. long nominal_bitrate,
  95071. long min_bitrate);
  95072. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  95073. long channels,
  95074. long rate,
  95075. float quality /* quality level from 0. (lo) to 1. (hi) */
  95076. );
  95077. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  95078. long channels,
  95079. long rate,
  95080. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  95081. );
  95082. extern int vorbis_encode_setup_init(vorbis_info *vi);
  95083. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  95084. #define OV_ECTL_RATEMANAGE_GET 0x10
  95085. #define OV_ECTL_RATEMANAGE_SET 0x11
  95086. #define OV_ECTL_RATEMANAGE_AVG 0x12
  95087. #define OV_ECTL_RATEMANAGE_HARD 0x13
  95088. struct ovectl_ratemanage_arg {
  95089. int management_active;
  95090. long bitrate_hard_min;
  95091. long bitrate_hard_max;
  95092. double bitrate_hard_window;
  95093. long bitrate_av_lo;
  95094. long bitrate_av_hi;
  95095. double bitrate_av_window;
  95096. double bitrate_av_window_center;
  95097. };
  95098. #define OV_ECTL_RATEMANAGE2_GET 0x14
  95099. #define OV_ECTL_RATEMANAGE2_SET 0x15
  95100. struct ovectl_ratemanage2_arg {
  95101. int management_active;
  95102. long bitrate_limit_min_kbps;
  95103. long bitrate_limit_max_kbps;
  95104. long bitrate_limit_reservoir_bits;
  95105. double bitrate_limit_reservoir_bias;
  95106. long bitrate_average_kbps;
  95107. double bitrate_average_damping;
  95108. };
  95109. #define OV_ECTL_LOWPASS_GET 0x20
  95110. #define OV_ECTL_LOWPASS_SET 0x21
  95111. #define OV_ECTL_IBLOCK_GET 0x30
  95112. #define OV_ECTL_IBLOCK_SET 0x31
  95113. #ifdef __cplusplus
  95114. }
  95115. #endif /* __cplusplus */
  95116. #endif
  95117. /*** End of inlined file: vorbisenc.h ***/
  95118. /*** Start of inlined file: vorbisfile.h ***/
  95119. #ifndef _OV_FILE_H_
  95120. #define _OV_FILE_H_
  95121. #ifdef __cplusplus
  95122. extern "C"
  95123. {
  95124. #endif /* __cplusplus */
  95125. #include <stdio.h>
  95126. typedef struct {
  95127. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  95128. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  95129. int (*close_func) (void *datasource);
  95130. long (*tell_func) (void *datasource);
  95131. } ov_callbacks;
  95132. #define NOTOPEN 0
  95133. #define PARTOPEN 1
  95134. #define OPENED 2
  95135. #define STREAMSET 3
  95136. #define INITSET 4
  95137. typedef struct OggVorbis_File {
  95138. void *datasource; /* Pointer to a FILE *, etc. */
  95139. int seekable;
  95140. ogg_int64_t offset;
  95141. ogg_int64_t end;
  95142. ogg_sync_state oy;
  95143. int links;
  95144. ogg_int64_t *offsets;
  95145. ogg_int64_t *dataoffsets;
  95146. long *serialnos;
  95147. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  95148. compatability; x2 size, stores both
  95149. beginning and end values */
  95150. vorbis_info *vi;
  95151. vorbis_comment *vc;
  95152. ogg_int64_t pcm_offset;
  95153. int ready_state;
  95154. long current_serialno;
  95155. int current_link;
  95156. double bittrack;
  95157. double samptrack;
  95158. ogg_stream_state os; /* take physical pages, weld into a logical
  95159. stream of packets */
  95160. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  95161. vorbis_block vb; /* local working space for packet->PCM decode */
  95162. ov_callbacks callbacks;
  95163. } OggVorbis_File;
  95164. extern int ov_clear(OggVorbis_File *vf);
  95165. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95166. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  95167. char *initial, long ibytes, ov_callbacks callbacks);
  95168. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95169. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  95170. char *initial, long ibytes, ov_callbacks callbacks);
  95171. extern int ov_test_open(OggVorbis_File *vf);
  95172. extern long ov_bitrate(OggVorbis_File *vf,int i);
  95173. extern long ov_bitrate_instant(OggVorbis_File *vf);
  95174. extern long ov_streams(OggVorbis_File *vf);
  95175. extern long ov_seekable(OggVorbis_File *vf);
  95176. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  95177. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  95178. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  95179. extern double ov_time_total(OggVorbis_File *vf,int i);
  95180. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95181. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95182. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  95183. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  95184. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  95185. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95186. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95187. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95188. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  95189. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  95190. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  95191. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  95192. extern double ov_time_tell(OggVorbis_File *vf);
  95193. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  95194. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  95195. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  95196. int *bitstream);
  95197. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  95198. int bigendianp,int word,int sgned,int *bitstream);
  95199. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  95200. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  95201. extern int ov_halfrate_p(OggVorbis_File *vf);
  95202. #ifdef __cplusplus
  95203. }
  95204. #endif /* __cplusplus */
  95205. #endif
  95206. /*** End of inlined file: vorbisfile.h ***/
  95207. /*** Start of inlined file: bitwise.c ***/
  95208. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95209. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95210. // tasks..
  95211. #if JUCE_MSVC
  95212. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95213. #endif
  95214. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95215. #if JUCE_USE_OGGVORBIS
  95216. #include <string.h>
  95217. #include <stdlib.h>
  95218. #define BUFFER_INCREMENT 256
  95219. static const unsigned long mask[]=
  95220. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  95221. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  95222. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  95223. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  95224. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  95225. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  95226. 0x3fffffff,0x7fffffff,0xffffffff };
  95227. static const unsigned int mask8B[]=
  95228. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  95229. void oggpack_writeinit(oggpack_buffer *b){
  95230. memset(b,0,sizeof(*b));
  95231. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  95232. b->buffer[0]='\0';
  95233. b->storage=BUFFER_INCREMENT;
  95234. }
  95235. void oggpackB_writeinit(oggpack_buffer *b){
  95236. oggpack_writeinit(b);
  95237. }
  95238. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  95239. long bytes=bits>>3;
  95240. bits-=bytes*8;
  95241. b->ptr=b->buffer+bytes;
  95242. b->endbit=bits;
  95243. b->endbyte=bytes;
  95244. *b->ptr&=mask[bits];
  95245. }
  95246. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  95247. long bytes=bits>>3;
  95248. bits-=bytes*8;
  95249. b->ptr=b->buffer+bytes;
  95250. b->endbit=bits;
  95251. b->endbyte=bytes;
  95252. *b->ptr&=mask8B[bits];
  95253. }
  95254. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  95255. if(b->endbyte+4>=b->storage){
  95256. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95257. b->storage+=BUFFER_INCREMENT;
  95258. b->ptr=b->buffer+b->endbyte;
  95259. }
  95260. value&=mask[bits];
  95261. bits+=b->endbit;
  95262. b->ptr[0]|=value<<b->endbit;
  95263. if(bits>=8){
  95264. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  95265. if(bits>=16){
  95266. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  95267. if(bits>=24){
  95268. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  95269. if(bits>=32){
  95270. if(b->endbit)
  95271. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  95272. else
  95273. b->ptr[4]=0;
  95274. }
  95275. }
  95276. }
  95277. }
  95278. b->endbyte+=bits/8;
  95279. b->ptr+=bits/8;
  95280. b->endbit=bits&7;
  95281. }
  95282. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  95283. if(b->endbyte+4>=b->storage){
  95284. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95285. b->storage+=BUFFER_INCREMENT;
  95286. b->ptr=b->buffer+b->endbyte;
  95287. }
  95288. value=(value&mask[bits])<<(32-bits);
  95289. bits+=b->endbit;
  95290. b->ptr[0]|=value>>(24+b->endbit);
  95291. if(bits>=8){
  95292. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  95293. if(bits>=16){
  95294. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  95295. if(bits>=24){
  95296. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  95297. if(bits>=32){
  95298. if(b->endbit)
  95299. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  95300. else
  95301. b->ptr[4]=0;
  95302. }
  95303. }
  95304. }
  95305. }
  95306. b->endbyte+=bits/8;
  95307. b->ptr+=bits/8;
  95308. b->endbit=bits&7;
  95309. }
  95310. void oggpack_writealign(oggpack_buffer *b){
  95311. int bits=8-b->endbit;
  95312. if(bits<8)
  95313. oggpack_write(b,0,bits);
  95314. }
  95315. void oggpackB_writealign(oggpack_buffer *b){
  95316. int bits=8-b->endbit;
  95317. if(bits<8)
  95318. oggpackB_write(b,0,bits);
  95319. }
  95320. static void oggpack_writecopy_helper(oggpack_buffer *b,
  95321. void *source,
  95322. long bits,
  95323. void (*w)(oggpack_buffer *,
  95324. unsigned long,
  95325. int),
  95326. int msb){
  95327. unsigned char *ptr=(unsigned char *)source;
  95328. long bytes=bits/8;
  95329. bits-=bytes*8;
  95330. if(b->endbit){
  95331. int i;
  95332. for(i=0;i<bytes;i++)
  95333. w(b,(unsigned long)(ptr[i]),8);
  95334. }else{
  95335. if(b->endbyte+bytes+1>=b->storage){
  95336. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  95337. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  95338. b->ptr=b->buffer+b->endbyte;
  95339. }
  95340. memmove(b->ptr,source,bytes);
  95341. b->ptr+=bytes;
  95342. b->endbyte+=bytes;
  95343. *b->ptr=0;
  95344. }
  95345. if(bits){
  95346. if(msb)
  95347. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  95348. else
  95349. w(b,(unsigned long)(ptr[bytes]),bits);
  95350. }
  95351. }
  95352. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  95353. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  95354. }
  95355. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  95356. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  95357. }
  95358. void oggpack_reset(oggpack_buffer *b){
  95359. b->ptr=b->buffer;
  95360. b->buffer[0]=0;
  95361. b->endbit=b->endbyte=0;
  95362. }
  95363. void oggpackB_reset(oggpack_buffer *b){
  95364. oggpack_reset(b);
  95365. }
  95366. void oggpack_writeclear(oggpack_buffer *b){
  95367. _ogg_free(b->buffer);
  95368. memset(b,0,sizeof(*b));
  95369. }
  95370. void oggpackB_writeclear(oggpack_buffer *b){
  95371. oggpack_writeclear(b);
  95372. }
  95373. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95374. memset(b,0,sizeof(*b));
  95375. b->buffer=b->ptr=buf;
  95376. b->storage=bytes;
  95377. }
  95378. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95379. oggpack_readinit(b,buf,bytes);
  95380. }
  95381. long oggpack_look(oggpack_buffer *b,int bits){
  95382. unsigned long ret;
  95383. unsigned long m=mask[bits];
  95384. bits+=b->endbit;
  95385. if(b->endbyte+4>=b->storage){
  95386. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95387. }
  95388. ret=b->ptr[0]>>b->endbit;
  95389. if(bits>8){
  95390. ret|=b->ptr[1]<<(8-b->endbit);
  95391. if(bits>16){
  95392. ret|=b->ptr[2]<<(16-b->endbit);
  95393. if(bits>24){
  95394. ret|=b->ptr[3]<<(24-b->endbit);
  95395. if(bits>32 && b->endbit)
  95396. ret|=b->ptr[4]<<(32-b->endbit);
  95397. }
  95398. }
  95399. }
  95400. return(m&ret);
  95401. }
  95402. long oggpackB_look(oggpack_buffer *b,int bits){
  95403. unsigned long ret;
  95404. int m=32-bits;
  95405. bits+=b->endbit;
  95406. if(b->endbyte+4>=b->storage){
  95407. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95408. }
  95409. ret=b->ptr[0]<<(24+b->endbit);
  95410. if(bits>8){
  95411. ret|=b->ptr[1]<<(16+b->endbit);
  95412. if(bits>16){
  95413. ret|=b->ptr[2]<<(8+b->endbit);
  95414. if(bits>24){
  95415. ret|=b->ptr[3]<<(b->endbit);
  95416. if(bits>32 && b->endbit)
  95417. ret|=b->ptr[4]>>(8-b->endbit);
  95418. }
  95419. }
  95420. }
  95421. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  95422. }
  95423. long oggpack_look1(oggpack_buffer *b){
  95424. if(b->endbyte>=b->storage)return(-1);
  95425. return((b->ptr[0]>>b->endbit)&1);
  95426. }
  95427. long oggpackB_look1(oggpack_buffer *b){
  95428. if(b->endbyte>=b->storage)return(-1);
  95429. return((b->ptr[0]>>(7-b->endbit))&1);
  95430. }
  95431. void oggpack_adv(oggpack_buffer *b,int bits){
  95432. bits+=b->endbit;
  95433. b->ptr+=bits/8;
  95434. b->endbyte+=bits/8;
  95435. b->endbit=bits&7;
  95436. }
  95437. void oggpackB_adv(oggpack_buffer *b,int bits){
  95438. oggpack_adv(b,bits);
  95439. }
  95440. void oggpack_adv1(oggpack_buffer *b){
  95441. if(++(b->endbit)>7){
  95442. b->endbit=0;
  95443. b->ptr++;
  95444. b->endbyte++;
  95445. }
  95446. }
  95447. void oggpackB_adv1(oggpack_buffer *b){
  95448. oggpack_adv1(b);
  95449. }
  95450. long oggpack_read(oggpack_buffer *b,int bits){
  95451. long ret;
  95452. unsigned long m=mask[bits];
  95453. bits+=b->endbit;
  95454. if(b->endbyte+4>=b->storage){
  95455. ret=-1L;
  95456. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95457. }
  95458. ret=b->ptr[0]>>b->endbit;
  95459. if(bits>8){
  95460. ret|=b->ptr[1]<<(8-b->endbit);
  95461. if(bits>16){
  95462. ret|=b->ptr[2]<<(16-b->endbit);
  95463. if(bits>24){
  95464. ret|=b->ptr[3]<<(24-b->endbit);
  95465. if(bits>32 && b->endbit){
  95466. ret|=b->ptr[4]<<(32-b->endbit);
  95467. }
  95468. }
  95469. }
  95470. }
  95471. ret&=m;
  95472. overflow:
  95473. b->ptr+=bits/8;
  95474. b->endbyte+=bits/8;
  95475. b->endbit=bits&7;
  95476. return(ret);
  95477. }
  95478. long oggpackB_read(oggpack_buffer *b,int bits){
  95479. long ret;
  95480. long m=32-bits;
  95481. bits+=b->endbit;
  95482. if(b->endbyte+4>=b->storage){
  95483. ret=-1L;
  95484. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95485. }
  95486. ret=b->ptr[0]<<(24+b->endbit);
  95487. if(bits>8){
  95488. ret|=b->ptr[1]<<(16+b->endbit);
  95489. if(bits>16){
  95490. ret|=b->ptr[2]<<(8+b->endbit);
  95491. if(bits>24){
  95492. ret|=b->ptr[3]<<(b->endbit);
  95493. if(bits>32 && b->endbit)
  95494. ret|=b->ptr[4]>>(8-b->endbit);
  95495. }
  95496. }
  95497. }
  95498. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  95499. overflow:
  95500. b->ptr+=bits/8;
  95501. b->endbyte+=bits/8;
  95502. b->endbit=bits&7;
  95503. return(ret);
  95504. }
  95505. long oggpack_read1(oggpack_buffer *b){
  95506. long ret;
  95507. if(b->endbyte>=b->storage){
  95508. ret=-1L;
  95509. goto overflow;
  95510. }
  95511. ret=(b->ptr[0]>>b->endbit)&1;
  95512. overflow:
  95513. b->endbit++;
  95514. if(b->endbit>7){
  95515. b->endbit=0;
  95516. b->ptr++;
  95517. b->endbyte++;
  95518. }
  95519. return(ret);
  95520. }
  95521. long oggpackB_read1(oggpack_buffer *b){
  95522. long ret;
  95523. if(b->endbyte>=b->storage){
  95524. ret=-1L;
  95525. goto overflow;
  95526. }
  95527. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95528. overflow:
  95529. b->endbit++;
  95530. if(b->endbit>7){
  95531. b->endbit=0;
  95532. b->ptr++;
  95533. b->endbyte++;
  95534. }
  95535. return(ret);
  95536. }
  95537. long oggpack_bytes(oggpack_buffer *b){
  95538. return(b->endbyte+(b->endbit+7)/8);
  95539. }
  95540. long oggpack_bits(oggpack_buffer *b){
  95541. return(b->endbyte*8+b->endbit);
  95542. }
  95543. long oggpackB_bytes(oggpack_buffer *b){
  95544. return oggpack_bytes(b);
  95545. }
  95546. long oggpackB_bits(oggpack_buffer *b){
  95547. return oggpack_bits(b);
  95548. }
  95549. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95550. return(b->buffer);
  95551. }
  95552. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95553. return oggpack_get_buffer(b);
  95554. }
  95555. #ifdef _V_SELFTEST
  95556. #include <stdio.h>
  95557. static int ilog(unsigned int v){
  95558. int ret=0;
  95559. while(v){
  95560. ret++;
  95561. v>>=1;
  95562. }
  95563. return(ret);
  95564. }
  95565. oggpack_buffer o;
  95566. oggpack_buffer r;
  95567. void report(char *in){
  95568. fprintf(stderr,"%s",in);
  95569. exit(1);
  95570. }
  95571. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95572. long bytes,i;
  95573. unsigned char *buffer;
  95574. oggpack_reset(&o);
  95575. for(i=0;i<vals;i++)
  95576. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95577. buffer=oggpack_get_buffer(&o);
  95578. bytes=oggpack_bytes(&o);
  95579. if(bytes!=compsize)report("wrong number of bytes!\n");
  95580. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95581. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95582. report("wrote incorrect value!\n");
  95583. }
  95584. oggpack_readinit(&r,buffer,bytes);
  95585. for(i=0;i<vals;i++){
  95586. int tbit=bits?bits:ilog(b[i]);
  95587. if(oggpack_look(&r,tbit)==-1)
  95588. report("out of data!\n");
  95589. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95590. report("looked at incorrect value!\n");
  95591. if(tbit==1)
  95592. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95593. report("looked at single bit incorrect value!\n");
  95594. if(tbit==1){
  95595. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95596. report("read incorrect single bit value!\n");
  95597. }else{
  95598. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95599. report("read incorrect value!\n");
  95600. }
  95601. }
  95602. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95603. }
  95604. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95605. long bytes,i;
  95606. unsigned char *buffer;
  95607. oggpackB_reset(&o);
  95608. for(i=0;i<vals;i++)
  95609. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95610. buffer=oggpackB_get_buffer(&o);
  95611. bytes=oggpackB_bytes(&o);
  95612. if(bytes!=compsize)report("wrong number of bytes!\n");
  95613. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95614. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95615. report("wrote incorrect value!\n");
  95616. }
  95617. oggpackB_readinit(&r,buffer,bytes);
  95618. for(i=0;i<vals;i++){
  95619. int tbit=bits?bits:ilog(b[i]);
  95620. if(oggpackB_look(&r,tbit)==-1)
  95621. report("out of data!\n");
  95622. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95623. report("looked at incorrect value!\n");
  95624. if(tbit==1)
  95625. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95626. report("looked at single bit incorrect value!\n");
  95627. if(tbit==1){
  95628. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95629. report("read incorrect single bit value!\n");
  95630. }else{
  95631. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95632. report("read incorrect value!\n");
  95633. }
  95634. }
  95635. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95636. }
  95637. int main(void){
  95638. unsigned char *buffer;
  95639. long bytes,i;
  95640. static unsigned long testbuffer1[]=
  95641. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95642. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95643. int test1size=43;
  95644. static unsigned long testbuffer2[]=
  95645. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95646. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95647. 85525151,0,12321,1,349528352};
  95648. int test2size=21;
  95649. static unsigned long testbuffer3[]=
  95650. {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,
  95651. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95652. int test3size=56;
  95653. static unsigned long large[]=
  95654. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95655. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95656. 85525151,0,12321,1,2146528352};
  95657. int onesize=33;
  95658. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95659. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95660. 223,4};
  95661. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95662. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95663. 245,251,128};
  95664. int twosize=6;
  95665. static int two[6]={61,255,255,251,231,29};
  95666. static int twoB[6]={247,63,255,253,249,120};
  95667. int threesize=54;
  95668. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95669. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95670. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95671. 100,52,4,14,18,86,77,1};
  95672. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95673. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95674. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95675. 200,20,254,4,58,106,176,144,0};
  95676. int foursize=38;
  95677. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95678. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95679. 28,2,133,0,1};
  95680. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95681. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95682. 129,10,4,32};
  95683. int fivesize=45;
  95684. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95685. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95686. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95687. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95688. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95689. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95690. int sixsize=7;
  95691. static int six[7]={17,177,170,242,169,19,148};
  95692. static int sixB[7]={136,141,85,79,149,200,41};
  95693. oggpack_writeinit(&o);
  95694. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95695. cliptest(testbuffer1,test1size,0,one,onesize);
  95696. fprintf(stderr,"ok.");
  95697. fprintf(stderr,"\nNull bit call (LSb): ");
  95698. cliptest(testbuffer3,test3size,0,two,twosize);
  95699. fprintf(stderr,"ok.");
  95700. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95701. cliptest(testbuffer2,test2size,0,three,threesize);
  95702. fprintf(stderr,"ok.");
  95703. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95704. oggpack_reset(&o);
  95705. for(i=0;i<test2size;i++)
  95706. oggpack_write(&o,large[i],32);
  95707. buffer=oggpack_get_buffer(&o);
  95708. bytes=oggpack_bytes(&o);
  95709. oggpack_readinit(&r,buffer,bytes);
  95710. for(i=0;i<test2size;i++){
  95711. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95712. if(oggpack_look(&r,32)!=large[i]){
  95713. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95714. oggpack_look(&r,32),large[i]);
  95715. report("read incorrect value!\n");
  95716. }
  95717. oggpack_adv(&r,32);
  95718. }
  95719. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95720. fprintf(stderr,"ok.");
  95721. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95722. cliptest(testbuffer1,test1size,7,four,foursize);
  95723. fprintf(stderr,"ok.");
  95724. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95725. cliptest(testbuffer2,test2size,17,five,fivesize);
  95726. fprintf(stderr,"ok.");
  95727. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95728. cliptest(testbuffer3,test3size,1,six,sixsize);
  95729. fprintf(stderr,"ok.");
  95730. fprintf(stderr,"\nTesting read past end (LSb): ");
  95731. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95732. for(i=0;i<64;i++){
  95733. if(oggpack_read(&r,1)!=0){
  95734. fprintf(stderr,"failed; got -1 prematurely.\n");
  95735. exit(1);
  95736. }
  95737. }
  95738. if(oggpack_look(&r,1)!=-1 ||
  95739. oggpack_read(&r,1)!=-1){
  95740. fprintf(stderr,"failed; read past end without -1.\n");
  95741. exit(1);
  95742. }
  95743. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95744. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95745. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95746. exit(1);
  95747. }
  95748. if(oggpack_look(&r,18)!=0 ||
  95749. oggpack_look(&r,18)!=0){
  95750. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95751. exit(1);
  95752. }
  95753. if(oggpack_look(&r,19)!=-1 ||
  95754. oggpack_look(&r,19)!=-1){
  95755. fprintf(stderr,"failed; read past end without -1.\n");
  95756. exit(1);
  95757. }
  95758. if(oggpack_look(&r,32)!=-1 ||
  95759. oggpack_look(&r,32)!=-1){
  95760. fprintf(stderr,"failed; read past end without -1.\n");
  95761. exit(1);
  95762. }
  95763. oggpack_writeclear(&o);
  95764. fprintf(stderr,"ok.\n");
  95765. oggpackB_writeinit(&o);
  95766. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95767. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95768. fprintf(stderr,"ok.");
  95769. fprintf(stderr,"\nNull bit call (MSb): ");
  95770. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95771. fprintf(stderr,"ok.");
  95772. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95773. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95774. fprintf(stderr,"ok.");
  95775. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95776. oggpackB_reset(&o);
  95777. for(i=0;i<test2size;i++)
  95778. oggpackB_write(&o,large[i],32);
  95779. buffer=oggpackB_get_buffer(&o);
  95780. bytes=oggpackB_bytes(&o);
  95781. oggpackB_readinit(&r,buffer,bytes);
  95782. for(i=0;i<test2size;i++){
  95783. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95784. if(oggpackB_look(&r,32)!=large[i]){
  95785. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95786. oggpackB_look(&r,32),large[i]);
  95787. report("read incorrect value!\n");
  95788. }
  95789. oggpackB_adv(&r,32);
  95790. }
  95791. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95792. fprintf(stderr,"ok.");
  95793. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95794. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95795. fprintf(stderr,"ok.");
  95796. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95797. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95798. fprintf(stderr,"ok.");
  95799. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95800. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95801. fprintf(stderr,"ok.");
  95802. fprintf(stderr,"\nTesting read past end (MSb): ");
  95803. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95804. for(i=0;i<64;i++){
  95805. if(oggpackB_read(&r,1)!=0){
  95806. fprintf(stderr,"failed; got -1 prematurely.\n");
  95807. exit(1);
  95808. }
  95809. }
  95810. if(oggpackB_look(&r,1)!=-1 ||
  95811. oggpackB_read(&r,1)!=-1){
  95812. fprintf(stderr,"failed; read past end without -1.\n");
  95813. exit(1);
  95814. }
  95815. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95816. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95817. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95818. exit(1);
  95819. }
  95820. if(oggpackB_look(&r,18)!=0 ||
  95821. oggpackB_look(&r,18)!=0){
  95822. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95823. exit(1);
  95824. }
  95825. if(oggpackB_look(&r,19)!=-1 ||
  95826. oggpackB_look(&r,19)!=-1){
  95827. fprintf(stderr,"failed; read past end without -1.\n");
  95828. exit(1);
  95829. }
  95830. if(oggpackB_look(&r,32)!=-1 ||
  95831. oggpackB_look(&r,32)!=-1){
  95832. fprintf(stderr,"failed; read past end without -1.\n");
  95833. exit(1);
  95834. }
  95835. oggpackB_writeclear(&o);
  95836. fprintf(stderr,"ok.\n\n");
  95837. return(0);
  95838. }
  95839. #endif /* _V_SELFTEST */
  95840. #undef BUFFER_INCREMENT
  95841. #endif
  95842. /*** End of inlined file: bitwise.c ***/
  95843. /*** Start of inlined file: framing.c ***/
  95844. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95845. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95846. // tasks..
  95847. #if JUCE_MSVC
  95848. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95849. #endif
  95850. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95851. #if JUCE_USE_OGGVORBIS
  95852. #include <stdlib.h>
  95853. #include <string.h>
  95854. int ogg_page_version(ogg_page *og){
  95855. return((int)(og->header[4]));
  95856. }
  95857. int ogg_page_continued(ogg_page *og){
  95858. return((int)(og->header[5]&0x01));
  95859. }
  95860. int ogg_page_bos(ogg_page *og){
  95861. return((int)(og->header[5]&0x02));
  95862. }
  95863. int ogg_page_eos(ogg_page *og){
  95864. return((int)(og->header[5]&0x04));
  95865. }
  95866. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95867. unsigned char *page=og->header;
  95868. ogg_int64_t granulepos=page[13]&(0xff);
  95869. granulepos= (granulepos<<8)|(page[12]&0xff);
  95870. granulepos= (granulepos<<8)|(page[11]&0xff);
  95871. granulepos= (granulepos<<8)|(page[10]&0xff);
  95872. granulepos= (granulepos<<8)|(page[9]&0xff);
  95873. granulepos= (granulepos<<8)|(page[8]&0xff);
  95874. granulepos= (granulepos<<8)|(page[7]&0xff);
  95875. granulepos= (granulepos<<8)|(page[6]&0xff);
  95876. return(granulepos);
  95877. }
  95878. int ogg_page_serialno(ogg_page *og){
  95879. return(og->header[14] |
  95880. (og->header[15]<<8) |
  95881. (og->header[16]<<16) |
  95882. (og->header[17]<<24));
  95883. }
  95884. long ogg_page_pageno(ogg_page *og){
  95885. return(og->header[18] |
  95886. (og->header[19]<<8) |
  95887. (og->header[20]<<16) |
  95888. (og->header[21]<<24));
  95889. }
  95890. int ogg_page_packets(ogg_page *og){
  95891. int i,n=og->header[26],count=0;
  95892. for(i=0;i<n;i++)
  95893. if(og->header[27+i]<255)count++;
  95894. return(count);
  95895. }
  95896. #if 0
  95897. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95898. int i;
  95899. unsigned long r;
  95900. r = index << 24;
  95901. for (i=0; i<8; i++)
  95902. if (r & 0x80000000UL)
  95903. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95904. polynomial, although we use an
  95905. unreflected alg and an init/final
  95906. of 0, not 0xffffffff */
  95907. else
  95908. r<<=1;
  95909. return (r & 0xffffffffUL);
  95910. }
  95911. #endif
  95912. static const ogg_uint32_t crc_lookup[256]={
  95913. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95914. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95915. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95916. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95917. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95918. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95919. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95920. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95921. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95922. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95923. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95924. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95925. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95926. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95927. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95928. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95929. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95930. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95931. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95932. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95933. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95934. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95935. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95936. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95937. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95938. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95939. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95940. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95941. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95942. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95943. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95944. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95945. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95946. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95947. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95948. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95949. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95950. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95951. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95952. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95953. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95954. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95955. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95956. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95957. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95958. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95959. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95960. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95961. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95962. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95963. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95964. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95965. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95966. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95967. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95968. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95969. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95970. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95971. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95972. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95973. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95974. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95975. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95976. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95977. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95978. if(os){
  95979. memset(os,0,sizeof(*os));
  95980. os->body_storage=16*1024;
  95981. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95982. os->lacing_storage=1024;
  95983. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95984. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95985. os->serialno=serialno;
  95986. return(0);
  95987. }
  95988. return(-1);
  95989. }
  95990. int ogg_stream_clear(ogg_stream_state *os){
  95991. if(os){
  95992. if(os->body_data)_ogg_free(os->body_data);
  95993. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95994. if(os->granule_vals)_ogg_free(os->granule_vals);
  95995. memset(os,0,sizeof(*os));
  95996. }
  95997. return(0);
  95998. }
  95999. int ogg_stream_destroy(ogg_stream_state *os){
  96000. if(os){
  96001. ogg_stream_clear(os);
  96002. _ogg_free(os);
  96003. }
  96004. return(0);
  96005. }
  96006. static void _os_body_expand(ogg_stream_state *os,int needed){
  96007. if(os->body_storage<=os->body_fill+needed){
  96008. os->body_storage+=(needed+1024);
  96009. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  96010. }
  96011. }
  96012. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  96013. if(os->lacing_storage<=os->lacing_fill+needed){
  96014. os->lacing_storage+=(needed+32);
  96015. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  96016. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  96017. }
  96018. }
  96019. void ogg_page_checksum_set(ogg_page *og){
  96020. if(og){
  96021. ogg_uint32_t crc_reg=0;
  96022. int i;
  96023. og->header[22]=0;
  96024. og->header[23]=0;
  96025. og->header[24]=0;
  96026. og->header[25]=0;
  96027. for(i=0;i<og->header_len;i++)
  96028. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  96029. for(i=0;i<og->body_len;i++)
  96030. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  96031. og->header[22]=(unsigned char)(crc_reg&0xff);
  96032. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  96033. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  96034. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  96035. }
  96036. }
  96037. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  96038. int lacing_vals=op->bytes/255+1,i;
  96039. if(os->body_returned){
  96040. os->body_fill-=os->body_returned;
  96041. if(os->body_fill)
  96042. memmove(os->body_data,os->body_data+os->body_returned,
  96043. os->body_fill);
  96044. os->body_returned=0;
  96045. }
  96046. _os_body_expand(os,op->bytes);
  96047. _os_lacing_expand(os,lacing_vals);
  96048. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  96049. os->body_fill+=op->bytes;
  96050. for(i=0;i<lacing_vals-1;i++){
  96051. os->lacing_vals[os->lacing_fill+i]=255;
  96052. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  96053. }
  96054. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  96055. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  96056. os->lacing_vals[os->lacing_fill]|= 0x100;
  96057. os->lacing_fill+=lacing_vals;
  96058. os->packetno++;
  96059. if(op->e_o_s)os->e_o_s=1;
  96060. return(0);
  96061. }
  96062. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  96063. int i;
  96064. int vals=0;
  96065. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  96066. int bytes=0;
  96067. long acc=0;
  96068. ogg_int64_t granule_pos=-1;
  96069. if(maxvals==0)return(0);
  96070. if(os->b_o_s==0){ /* 'initial header page' case */
  96071. granule_pos=0;
  96072. for(vals=0;vals<maxvals;vals++){
  96073. if((os->lacing_vals[vals]&0x0ff)<255){
  96074. vals++;
  96075. break;
  96076. }
  96077. }
  96078. }else{
  96079. for(vals=0;vals<maxvals;vals++){
  96080. if(acc>4096)break;
  96081. acc+=os->lacing_vals[vals]&0x0ff;
  96082. if((os->lacing_vals[vals]&0xff)<255)
  96083. granule_pos=os->granule_vals[vals];
  96084. }
  96085. }
  96086. memcpy(os->header,"OggS",4);
  96087. os->header[4]=0x00;
  96088. os->header[5]=0x00;
  96089. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  96090. if(os->b_o_s==0)os->header[5]|=0x02;
  96091. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  96092. os->b_o_s=1;
  96093. for(i=6;i<14;i++){
  96094. os->header[i]=(unsigned char)(granule_pos&0xff);
  96095. granule_pos>>=8;
  96096. }
  96097. {
  96098. long serialno=os->serialno;
  96099. for(i=14;i<18;i++){
  96100. os->header[i]=(unsigned char)(serialno&0xff);
  96101. serialno>>=8;
  96102. }
  96103. }
  96104. if(os->pageno==-1)os->pageno=0; /* because someone called
  96105. stream_reset; this would be a
  96106. strange thing to do in an
  96107. encode stream, but it has
  96108. plausible uses */
  96109. {
  96110. long pageno=os->pageno++;
  96111. for(i=18;i<22;i++){
  96112. os->header[i]=(unsigned char)(pageno&0xff);
  96113. pageno>>=8;
  96114. }
  96115. }
  96116. os->header[22]=0;
  96117. os->header[23]=0;
  96118. os->header[24]=0;
  96119. os->header[25]=0;
  96120. os->header[26]=(unsigned char)(vals&0xff);
  96121. for(i=0;i<vals;i++)
  96122. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  96123. og->header=os->header;
  96124. og->header_len=os->header_fill=vals+27;
  96125. og->body=os->body_data+os->body_returned;
  96126. og->body_len=bytes;
  96127. os->lacing_fill-=vals;
  96128. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  96129. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  96130. os->body_returned+=bytes;
  96131. ogg_page_checksum_set(og);
  96132. return(1);
  96133. }
  96134. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  96135. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  96136. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  96137. os->lacing_fill>=255 || /* 'segment table full' case */
  96138. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  96139. return(ogg_stream_flush(os,og));
  96140. }
  96141. return(0);
  96142. }
  96143. int ogg_stream_eos(ogg_stream_state *os){
  96144. return os->e_o_s;
  96145. }
  96146. int ogg_sync_init(ogg_sync_state *oy){
  96147. if(oy){
  96148. memset(oy,0,sizeof(*oy));
  96149. }
  96150. return(0);
  96151. }
  96152. int ogg_sync_clear(ogg_sync_state *oy){
  96153. if(oy){
  96154. if(oy->data)_ogg_free(oy->data);
  96155. ogg_sync_init(oy);
  96156. }
  96157. return(0);
  96158. }
  96159. int ogg_sync_destroy(ogg_sync_state *oy){
  96160. if(oy){
  96161. ogg_sync_clear(oy);
  96162. _ogg_free(oy);
  96163. }
  96164. return(0);
  96165. }
  96166. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  96167. if(oy->returned){
  96168. oy->fill-=oy->returned;
  96169. if(oy->fill>0)
  96170. memmove(oy->data,oy->data+oy->returned,oy->fill);
  96171. oy->returned=0;
  96172. }
  96173. if(size>oy->storage-oy->fill){
  96174. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  96175. if(oy->data)
  96176. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  96177. else
  96178. oy->data=(unsigned char*) _ogg_malloc(newsize);
  96179. oy->storage=newsize;
  96180. }
  96181. return((char *)oy->data+oy->fill);
  96182. }
  96183. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  96184. if(oy->fill+bytes>oy->storage)return(-1);
  96185. oy->fill+=bytes;
  96186. return(0);
  96187. }
  96188. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  96189. unsigned char *page=oy->data+oy->returned;
  96190. unsigned char *next;
  96191. long bytes=oy->fill-oy->returned;
  96192. if(oy->headerbytes==0){
  96193. int headerbytes,i;
  96194. if(bytes<27)return(0); /* not enough for a header */
  96195. if(memcmp(page,"OggS",4))goto sync_fail;
  96196. headerbytes=page[26]+27;
  96197. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  96198. for(i=0;i<page[26];i++)
  96199. oy->bodybytes+=page[27+i];
  96200. oy->headerbytes=headerbytes;
  96201. }
  96202. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  96203. {
  96204. char chksum[4];
  96205. ogg_page log;
  96206. memcpy(chksum,page+22,4);
  96207. memset(page+22,0,4);
  96208. log.header=page;
  96209. log.header_len=oy->headerbytes;
  96210. log.body=page+oy->headerbytes;
  96211. log.body_len=oy->bodybytes;
  96212. ogg_page_checksum_set(&log);
  96213. if(memcmp(chksum,page+22,4)){
  96214. memcpy(page+22,chksum,4);
  96215. goto sync_fail;
  96216. }
  96217. }
  96218. {
  96219. unsigned char *page=oy->data+oy->returned;
  96220. long bytes;
  96221. if(og){
  96222. og->header=page;
  96223. og->header_len=oy->headerbytes;
  96224. og->body=page+oy->headerbytes;
  96225. og->body_len=oy->bodybytes;
  96226. }
  96227. oy->unsynced=0;
  96228. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  96229. oy->headerbytes=0;
  96230. oy->bodybytes=0;
  96231. return(bytes);
  96232. }
  96233. sync_fail:
  96234. oy->headerbytes=0;
  96235. oy->bodybytes=0;
  96236. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  96237. if(!next)
  96238. next=oy->data+oy->fill;
  96239. oy->returned=next-oy->data;
  96240. return(-(next-page));
  96241. }
  96242. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  96243. for(;;){
  96244. long ret=ogg_sync_pageseek(oy,og);
  96245. if(ret>0){
  96246. return(1);
  96247. }
  96248. if(ret==0){
  96249. return(0);
  96250. }
  96251. if(!oy->unsynced){
  96252. oy->unsynced=1;
  96253. return(-1);
  96254. }
  96255. }
  96256. }
  96257. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  96258. unsigned char *header=og->header;
  96259. unsigned char *body=og->body;
  96260. long bodysize=og->body_len;
  96261. int segptr=0;
  96262. int version=ogg_page_version(og);
  96263. int continued=ogg_page_continued(og);
  96264. int bos=ogg_page_bos(og);
  96265. int eos=ogg_page_eos(og);
  96266. ogg_int64_t granulepos=ogg_page_granulepos(og);
  96267. int serialno=ogg_page_serialno(og);
  96268. long pageno=ogg_page_pageno(og);
  96269. int segments=header[26];
  96270. {
  96271. long lr=os->lacing_returned;
  96272. long br=os->body_returned;
  96273. if(br){
  96274. os->body_fill-=br;
  96275. if(os->body_fill)
  96276. memmove(os->body_data,os->body_data+br,os->body_fill);
  96277. os->body_returned=0;
  96278. }
  96279. if(lr){
  96280. if(os->lacing_fill-lr){
  96281. memmove(os->lacing_vals,os->lacing_vals+lr,
  96282. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  96283. memmove(os->granule_vals,os->granule_vals+lr,
  96284. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  96285. }
  96286. os->lacing_fill-=lr;
  96287. os->lacing_packet-=lr;
  96288. os->lacing_returned=0;
  96289. }
  96290. }
  96291. if(serialno!=os->serialno)return(-1);
  96292. if(version>0)return(-1);
  96293. _os_lacing_expand(os,segments+1);
  96294. if(pageno!=os->pageno){
  96295. int i;
  96296. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  96297. os->body_fill-=os->lacing_vals[i]&0xff;
  96298. os->lacing_fill=os->lacing_packet;
  96299. if(os->pageno!=-1){
  96300. os->lacing_vals[os->lacing_fill++]=0x400;
  96301. os->lacing_packet++;
  96302. }
  96303. }
  96304. if(continued){
  96305. if(os->lacing_fill<1 ||
  96306. os->lacing_vals[os->lacing_fill-1]==0x400){
  96307. bos=0;
  96308. for(;segptr<segments;segptr++){
  96309. int val=header[27+segptr];
  96310. body+=val;
  96311. bodysize-=val;
  96312. if(val<255){
  96313. segptr++;
  96314. break;
  96315. }
  96316. }
  96317. }
  96318. }
  96319. if(bodysize){
  96320. _os_body_expand(os,bodysize);
  96321. memcpy(os->body_data+os->body_fill,body,bodysize);
  96322. os->body_fill+=bodysize;
  96323. }
  96324. {
  96325. int saved=-1;
  96326. while(segptr<segments){
  96327. int val=header[27+segptr];
  96328. os->lacing_vals[os->lacing_fill]=val;
  96329. os->granule_vals[os->lacing_fill]=-1;
  96330. if(bos){
  96331. os->lacing_vals[os->lacing_fill]|=0x100;
  96332. bos=0;
  96333. }
  96334. if(val<255)saved=os->lacing_fill;
  96335. os->lacing_fill++;
  96336. segptr++;
  96337. if(val<255)os->lacing_packet=os->lacing_fill;
  96338. }
  96339. if(saved!=-1){
  96340. os->granule_vals[saved]=granulepos;
  96341. }
  96342. }
  96343. if(eos){
  96344. os->e_o_s=1;
  96345. if(os->lacing_fill>0)
  96346. os->lacing_vals[os->lacing_fill-1]|=0x200;
  96347. }
  96348. os->pageno=pageno+1;
  96349. return(0);
  96350. }
  96351. int ogg_sync_reset(ogg_sync_state *oy){
  96352. oy->fill=0;
  96353. oy->returned=0;
  96354. oy->unsynced=0;
  96355. oy->headerbytes=0;
  96356. oy->bodybytes=0;
  96357. return(0);
  96358. }
  96359. int ogg_stream_reset(ogg_stream_state *os){
  96360. os->body_fill=0;
  96361. os->body_returned=0;
  96362. os->lacing_fill=0;
  96363. os->lacing_packet=0;
  96364. os->lacing_returned=0;
  96365. os->header_fill=0;
  96366. os->e_o_s=0;
  96367. os->b_o_s=0;
  96368. os->pageno=-1;
  96369. os->packetno=0;
  96370. os->granulepos=0;
  96371. return(0);
  96372. }
  96373. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  96374. ogg_stream_reset(os);
  96375. os->serialno=serialno;
  96376. return(0);
  96377. }
  96378. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  96379. int ptr=os->lacing_returned;
  96380. if(os->lacing_packet<=ptr)return(0);
  96381. if(os->lacing_vals[ptr]&0x400){
  96382. os->lacing_returned++;
  96383. os->packetno++;
  96384. return(-1);
  96385. }
  96386. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  96387. to ask if there's a whole packet
  96388. waiting */
  96389. {
  96390. int size=os->lacing_vals[ptr]&0xff;
  96391. int bytes=size;
  96392. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  96393. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  96394. while(size==255){
  96395. int val=os->lacing_vals[++ptr];
  96396. size=val&0xff;
  96397. if(val&0x200)eos=0x200;
  96398. bytes+=size;
  96399. }
  96400. if(op){
  96401. op->e_o_s=eos;
  96402. op->b_o_s=bos;
  96403. op->packet=os->body_data+os->body_returned;
  96404. op->packetno=os->packetno;
  96405. op->granulepos=os->granule_vals[ptr];
  96406. op->bytes=bytes;
  96407. }
  96408. if(adv){
  96409. os->body_returned+=bytes;
  96410. os->lacing_returned=ptr+1;
  96411. os->packetno++;
  96412. }
  96413. }
  96414. return(1);
  96415. }
  96416. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  96417. return _packetout(os,op,1);
  96418. }
  96419. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  96420. return _packetout(os,op,0);
  96421. }
  96422. void ogg_packet_clear(ogg_packet *op) {
  96423. _ogg_free(op->packet);
  96424. memset(op, 0, sizeof(*op));
  96425. }
  96426. #ifdef _V_SELFTEST
  96427. #include <stdio.h>
  96428. ogg_stream_state os_en, os_de;
  96429. ogg_sync_state oy;
  96430. void checkpacket(ogg_packet *op,int len, int no, int pos){
  96431. long j;
  96432. static int sequence=0;
  96433. static int lastno=0;
  96434. if(op->bytes!=len){
  96435. fprintf(stderr,"incorrect packet length!\n");
  96436. exit(1);
  96437. }
  96438. if(op->granulepos!=pos){
  96439. fprintf(stderr,"incorrect packet position!\n");
  96440. exit(1);
  96441. }
  96442. if(no==0){
  96443. sequence=0;
  96444. }else{
  96445. sequence++;
  96446. if(no>lastno+1)
  96447. sequence++;
  96448. }
  96449. lastno=no;
  96450. if(op->packetno!=sequence){
  96451. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  96452. (long)(op->packetno),sequence);
  96453. exit(1);
  96454. }
  96455. for(j=0;j<op->bytes;j++)
  96456. if(op->packet[j]!=((j+no)&0xff)){
  96457. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  96458. j,op->packet[j],(j+no)&0xff);
  96459. exit(1);
  96460. }
  96461. }
  96462. void check_page(unsigned char *data,const int *header,ogg_page *og){
  96463. long j;
  96464. for(j=0;j<og->body_len;j++)
  96465. if(og->body[j]!=data[j]){
  96466. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  96467. j,data[j],og->body[j]);
  96468. exit(1);
  96469. }
  96470. for(j=0;j<og->header_len;j++){
  96471. if(og->header[j]!=header[j]){
  96472. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  96473. for(j=0;j<header[26]+27;j++)
  96474. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  96475. fprintf(stderr,"\n");
  96476. exit(1);
  96477. }
  96478. }
  96479. if(og->header_len!=header[26]+27){
  96480. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  96481. og->header_len,header[26]+27);
  96482. exit(1);
  96483. }
  96484. }
  96485. void print_header(ogg_page *og){
  96486. int j;
  96487. fprintf(stderr,"\nHEADER:\n");
  96488. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  96489. og->header[0],og->header[1],og->header[2],og->header[3],
  96490. (int)og->header[4],(int)og->header[5]);
  96491. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  96492. (og->header[9]<<24)|(og->header[8]<<16)|
  96493. (og->header[7]<<8)|og->header[6],
  96494. (og->header[17]<<24)|(og->header[16]<<16)|
  96495. (og->header[15]<<8)|og->header[14],
  96496. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  96497. (og->header[19]<<8)|og->header[18]);
  96498. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  96499. (int)og->header[22],(int)og->header[23],
  96500. (int)og->header[24],(int)og->header[25],
  96501. (int)og->header[26]);
  96502. for(j=27;j<og->header_len;j++)
  96503. fprintf(stderr,"%d ",(int)og->header[j]);
  96504. fprintf(stderr,")\n\n");
  96505. }
  96506. void copy_page(ogg_page *og){
  96507. unsigned char *temp=_ogg_malloc(og->header_len);
  96508. memcpy(temp,og->header,og->header_len);
  96509. og->header=temp;
  96510. temp=_ogg_malloc(og->body_len);
  96511. memcpy(temp,og->body,og->body_len);
  96512. og->body=temp;
  96513. }
  96514. void free_page(ogg_page *og){
  96515. _ogg_free (og->header);
  96516. _ogg_free (og->body);
  96517. }
  96518. void error(void){
  96519. fprintf(stderr,"error!\n");
  96520. exit(1);
  96521. }
  96522. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  96523. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96524. 0x01,0x02,0x03,0x04,0,0,0,0,
  96525. 0x15,0xed,0xec,0x91,
  96526. 1,
  96527. 17};
  96528. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96529. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96530. 0x01,0x02,0x03,0x04,0,0,0,0,
  96531. 0x59,0x10,0x6c,0x2c,
  96532. 1,
  96533. 17};
  96534. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96535. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96536. 0x01,0x02,0x03,0x04,1,0,0,0,
  96537. 0x89,0x33,0x85,0xce,
  96538. 13,
  96539. 254,255,0,255,1,255,245,255,255,0,
  96540. 255,255,90};
  96541. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96542. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96543. 0x01,0x02,0x03,0x04,0,0,0,0,
  96544. 0xff,0x7b,0x23,0x17,
  96545. 1,
  96546. 0};
  96547. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96548. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96549. 0x01,0x02,0x03,0x04,1,0,0,0,
  96550. 0x5c,0x3f,0x66,0xcb,
  96551. 17,
  96552. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96553. 255,255,90,0};
  96554. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96555. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96556. 0x01,0x02,0x03,0x04,0,0,0,0,
  96557. 0x01,0x27,0x31,0xaa,
  96558. 18,
  96559. 255,255,255,255,255,255,255,255,
  96560. 255,255,255,255,255,255,255,255,255,10};
  96561. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96562. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96563. 0x01,0x02,0x03,0x04,1,0,0,0,
  96564. 0x7f,0x4e,0x8a,0xd2,
  96565. 4,
  96566. 255,4,255,0};
  96567. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96568. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96569. 0x01,0x02,0x03,0x04,0,0,0,0,
  96570. 0xff,0x7b,0x23,0x17,
  96571. 1,
  96572. 0};
  96573. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96574. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96575. 0x01,0x02,0x03,0x04,1,0,0,0,
  96576. 0x54,0x05,0x51,0xc8,
  96577. 17,
  96578. 255,255,255,255,255,255,255,255,
  96579. 255,255,255,255,255,255,255,255,255};
  96580. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96581. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96582. 0x01,0x02,0x03,0x04,2,0,0,0,
  96583. 0xc8,0xc3,0xcb,0xed,
  96584. 5,
  96585. 10,255,4,255,0};
  96586. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96587. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96588. 0x01,0x02,0x03,0x04,0,0,0,0,
  96589. 0xff,0x7b,0x23,0x17,
  96590. 1,
  96591. 0};
  96592. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96593. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96594. 0x01,0x02,0x03,0x04,1,0,0,0,
  96595. 0xed,0x2a,0x2e,0xa7,
  96596. 255,
  96597. 10,10,10,10,10,10,10,10,
  96598. 10,10,10,10,10,10,10,10,
  96599. 10,10,10,10,10,10,10,10,
  96600. 10,10,10,10,10,10,10,10,
  96601. 10,10,10,10,10,10,10,10,
  96602. 10,10,10,10,10,10,10,10,
  96603. 10,10,10,10,10,10,10,10,
  96604. 10,10,10,10,10,10,10,10,
  96605. 10,10,10,10,10,10,10,10,
  96606. 10,10,10,10,10,10,10,10,
  96607. 10,10,10,10,10,10,10,10,
  96608. 10,10,10,10,10,10,10,10,
  96609. 10,10,10,10,10,10,10,10,
  96610. 10,10,10,10,10,10,10,10,
  96611. 10,10,10,10,10,10,10,10,
  96612. 10,10,10,10,10,10,10,10,
  96613. 10,10,10,10,10,10,10,10,
  96614. 10,10,10,10,10,10,10,10,
  96615. 10,10,10,10,10,10,10,10,
  96616. 10,10,10,10,10,10,10,10,
  96617. 10,10,10,10,10,10,10,10,
  96618. 10,10,10,10,10,10,10,10,
  96619. 10,10,10,10,10,10,10,10,
  96620. 10,10,10,10,10,10,10,10,
  96621. 10,10,10,10,10,10,10,10,
  96622. 10,10,10,10,10,10,10,10,
  96623. 10,10,10,10,10,10,10,10,
  96624. 10,10,10,10,10,10,10,10,
  96625. 10,10,10,10,10,10,10,10,
  96626. 10,10,10,10,10,10,10,10,
  96627. 10,10,10,10,10,10,10,10,
  96628. 10,10,10,10,10,10,10};
  96629. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96630. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96631. 0x01,0x02,0x03,0x04,2,0,0,0,
  96632. 0x6c,0x3b,0x82,0x3d,
  96633. 1,
  96634. 50};
  96635. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96636. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96637. 0x01,0x02,0x03,0x04,0,0,0,0,
  96638. 0xff,0x7b,0x23,0x17,
  96639. 1,
  96640. 0};
  96641. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96642. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96643. 0x01,0x02,0x03,0x04,1,0,0,0,
  96644. 0x3c,0xd9,0x4d,0x3f,
  96645. 17,
  96646. 100,255,255,255,255,255,255,255,255,
  96647. 255,255,255,255,255,255,255,255};
  96648. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96649. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96650. 0x01,0x02,0x03,0x04,2,0,0,0,
  96651. 0x01,0xd2,0xe5,0xe5,
  96652. 17,
  96653. 255,255,255,255,255,255,255,255,
  96654. 255,255,255,255,255,255,255,255,255};
  96655. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96656. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96657. 0x01,0x02,0x03,0x04,3,0,0,0,
  96658. 0xef,0xdd,0x88,0xde,
  96659. 7,
  96660. 255,255,75,255,4,255,0};
  96661. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96662. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96663. 0x01,0x02,0x03,0x04,0,0,0,0,
  96664. 0xff,0x7b,0x23,0x17,
  96665. 1,
  96666. 0};
  96667. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96668. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96669. 0x01,0x02,0x03,0x04,1,0,0,0,
  96670. 0x3c,0xd9,0x4d,0x3f,
  96671. 17,
  96672. 100,255,255,255,255,255,255,255,255,
  96673. 255,255,255,255,255,255,255,255};
  96674. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96675. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96676. 0x01,0x02,0x03,0x04,2,0,0,0,
  96677. 0xd4,0xe0,0x60,0xe5,
  96678. 1,0};
  96679. void test_pack(const int *pl, const int **headers, int byteskip,
  96680. int pageskip, int packetskip){
  96681. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96682. long inptr=0;
  96683. long outptr=0;
  96684. long deptr=0;
  96685. long depacket=0;
  96686. long granule_pos=7,pageno=0;
  96687. int i,j,packets,pageout=pageskip;
  96688. int eosflag=0;
  96689. int bosflag=0;
  96690. int byteskipcount=0;
  96691. ogg_stream_reset(&os_en);
  96692. ogg_stream_reset(&os_de);
  96693. ogg_sync_reset(&oy);
  96694. for(packets=0;packets<packetskip;packets++)
  96695. depacket+=pl[packets];
  96696. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96697. for(i=0;i<packets;i++){
  96698. ogg_packet op;
  96699. int len=pl[i];
  96700. op.packet=data+inptr;
  96701. op.bytes=len;
  96702. op.e_o_s=(pl[i+1]<0?1:0);
  96703. op.granulepos=granule_pos;
  96704. granule_pos+=1024;
  96705. for(j=0;j<len;j++)data[inptr++]=i+j;
  96706. ogg_stream_packetin(&os_en,&op);
  96707. {
  96708. ogg_page og;
  96709. while(ogg_stream_pageout(&os_en,&og)){
  96710. fprintf(stderr,"%ld, ",pageno);
  96711. if(headers[pageno]==NULL){
  96712. fprintf(stderr,"coded too many pages!\n");
  96713. exit(1);
  96714. }
  96715. check_page(data+outptr,headers[pageno],&og);
  96716. outptr+=og.body_len;
  96717. pageno++;
  96718. if(pageskip){
  96719. bosflag=1;
  96720. pageskip--;
  96721. deptr+=og.body_len;
  96722. }
  96723. {
  96724. ogg_page og_de;
  96725. ogg_packet op_de,op_de2;
  96726. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96727. char *next=buf;
  96728. byteskipcount+=og.header_len;
  96729. if(byteskipcount>byteskip){
  96730. memcpy(next,og.header,byteskipcount-byteskip);
  96731. next+=byteskipcount-byteskip;
  96732. byteskipcount=byteskip;
  96733. }
  96734. byteskipcount+=og.body_len;
  96735. if(byteskipcount>byteskip){
  96736. memcpy(next,og.body,byteskipcount-byteskip);
  96737. next+=byteskipcount-byteskip;
  96738. byteskipcount=byteskip;
  96739. }
  96740. ogg_sync_wrote(&oy,next-buf);
  96741. while(1){
  96742. int ret=ogg_sync_pageout(&oy,&og_de);
  96743. if(ret==0)break;
  96744. if(ret<0)continue;
  96745. fprintf(stderr,"(%ld), ",pageout);
  96746. check_page(data+deptr,headers[pageout],&og_de);
  96747. deptr+=og_de.body_len;
  96748. pageout++;
  96749. ogg_stream_pagein(&os_de,&og_de);
  96750. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96751. ogg_stream_packetpeek(&os_de,NULL);
  96752. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96753. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96754. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96755. depacket);
  96756. exit(1);
  96757. }
  96758. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96759. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96760. depacket);
  96761. exit(1);
  96762. }
  96763. if(bosflag==0 && op_de.b_o_s==0){
  96764. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96765. exit(1);
  96766. }
  96767. if(bosflag && op_de.b_o_s){
  96768. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96769. exit(1);
  96770. }
  96771. bosflag=1;
  96772. depacket+=op_de.bytes;
  96773. if(eosflag){
  96774. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96775. exit(1);
  96776. }
  96777. if(op_de.e_o_s)eosflag=1;
  96778. if(op_de.granulepos!=-1){
  96779. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96780. }
  96781. }
  96782. }
  96783. }
  96784. }
  96785. }
  96786. }
  96787. _ogg_free(data);
  96788. if(headers[pageno]!=NULL){
  96789. fprintf(stderr,"did not write last page!\n");
  96790. exit(1);
  96791. }
  96792. if(headers[pageout]!=NULL){
  96793. fprintf(stderr,"did not decode last page!\n");
  96794. exit(1);
  96795. }
  96796. if(inptr!=outptr){
  96797. fprintf(stderr,"encoded page data incomplete!\n");
  96798. exit(1);
  96799. }
  96800. if(inptr!=deptr){
  96801. fprintf(stderr,"decoded page data incomplete!\n");
  96802. exit(1);
  96803. }
  96804. if(inptr!=depacket){
  96805. fprintf(stderr,"decoded packet data incomplete!\n");
  96806. exit(1);
  96807. }
  96808. if(!eosflag){
  96809. fprintf(stderr,"Never got a packet with EOS set!\n");
  96810. exit(1);
  96811. }
  96812. fprintf(stderr,"ok.\n");
  96813. }
  96814. int main(void){
  96815. ogg_stream_init(&os_en,0x04030201);
  96816. ogg_stream_init(&os_de,0x04030201);
  96817. ogg_sync_init(&oy);
  96818. {
  96819. const int packets[]={17, -1};
  96820. const int *headret[]={head1_0,NULL};
  96821. fprintf(stderr,"testing single page encoding... ");
  96822. test_pack(packets,headret,0,0,0);
  96823. }
  96824. {
  96825. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96826. const int *headret[]={head1_1,head2_1,NULL};
  96827. fprintf(stderr,"testing basic page encoding... ");
  96828. test_pack(packets,headret,0,0,0);
  96829. }
  96830. {
  96831. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96832. const int *headret[]={head1_2,head2_2,NULL};
  96833. fprintf(stderr,"testing basic nil packets... ");
  96834. test_pack(packets,headret,0,0,0);
  96835. }
  96836. {
  96837. const int packets[]={4345,259,255,-1};
  96838. const int *headret[]={head1_3,head2_3,NULL};
  96839. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96840. test_pack(packets,headret,0,0,0);
  96841. }
  96842. {
  96843. const int packets[]={0,4345,259,255,-1};
  96844. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96845. fprintf(stderr,"testing single packet page span... ");
  96846. test_pack(packets,headret,0,0,0);
  96847. }
  96848. {
  96849. const int packets[]={0,10,10,10,10,10,10,10,10,
  96850. 10,10,10,10,10,10,10,10,
  96851. 10,10,10,10,10,10,10,10,
  96852. 10,10,10,10,10,10,10,10,
  96853. 10,10,10,10,10,10,10,10,
  96854. 10,10,10,10,10,10,10,10,
  96855. 10,10,10,10,10,10,10,10,
  96856. 10,10,10,10,10,10,10,10,
  96857. 10,10,10,10,10,10,10,10,
  96858. 10,10,10,10,10,10,10,10,
  96859. 10,10,10,10,10,10,10,10,
  96860. 10,10,10,10,10,10,10,10,
  96861. 10,10,10,10,10,10,10,10,
  96862. 10,10,10,10,10,10,10,10,
  96863. 10,10,10,10,10,10,10,10,
  96864. 10,10,10,10,10,10,10,10,
  96865. 10,10,10,10,10,10,10,10,
  96866. 10,10,10,10,10,10,10,10,
  96867. 10,10,10,10,10,10,10,10,
  96868. 10,10,10,10,10,10,10,10,
  96869. 10,10,10,10,10,10,10,10,
  96870. 10,10,10,10,10,10,10,10,
  96871. 10,10,10,10,10,10,10,10,
  96872. 10,10,10,10,10,10,10,10,
  96873. 10,10,10,10,10,10,10,10,
  96874. 10,10,10,10,10,10,10,10,
  96875. 10,10,10,10,10,10,10,10,
  96876. 10,10,10,10,10,10,10,10,
  96877. 10,10,10,10,10,10,10,10,
  96878. 10,10,10,10,10,10,10,10,
  96879. 10,10,10,10,10,10,10,10,
  96880. 10,10,10,10,10,10,10,50,-1};
  96881. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96882. fprintf(stderr,"testing max packet segments... ");
  96883. test_pack(packets,headret,0,0,0);
  96884. }
  96885. {
  96886. const int packets[]={0,100,9000,259,255,-1};
  96887. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96888. fprintf(stderr,"testing very large packets... ");
  96889. test_pack(packets,headret,0,0,0);
  96890. }
  96891. {
  96892. const int packets[]={0,100,9000,259,255,-1};
  96893. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96894. fprintf(stderr,"testing continuation resync in very large packets... ");
  96895. test_pack(packets,headret,100,2,3);
  96896. }
  96897. {
  96898. const int packets[]={0,100,4080,-1};
  96899. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96900. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96901. test_pack(packets,headret,0,0,0);
  96902. }
  96903. {
  96904. unsigned char *data=_ogg_malloc(1024*1024);
  96905. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96906. int inptr=0,i,j;
  96907. ogg_page og[5];
  96908. ogg_stream_reset(&os_en);
  96909. for(i=0;pl[i]!=-1;i++){
  96910. ogg_packet op;
  96911. int len=pl[i];
  96912. op.packet=data+inptr;
  96913. op.bytes=len;
  96914. op.e_o_s=(pl[i+1]<0?1:0);
  96915. op.granulepos=(i+1)*1000;
  96916. for(j=0;j<len;j++)data[inptr++]=i+j;
  96917. ogg_stream_packetin(&os_en,&op);
  96918. }
  96919. _ogg_free(data);
  96920. for(i=0;i<5;i++){
  96921. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96922. fprintf(stderr,"Too few pages output building sync tests!\n");
  96923. exit(1);
  96924. }
  96925. copy_page(&og[i]);
  96926. }
  96927. {
  96928. ogg_page temp;
  96929. ogg_packet test;
  96930. fprintf(stderr,"Testing loss of pages... ");
  96931. ogg_sync_reset(&oy);
  96932. ogg_stream_reset(&os_de);
  96933. for(i=0;i<5;i++){
  96934. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96935. og[i].header_len);
  96936. ogg_sync_wrote(&oy,og[i].header_len);
  96937. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96938. ogg_sync_wrote(&oy,og[i].body_len);
  96939. }
  96940. ogg_sync_pageout(&oy,&temp);
  96941. ogg_stream_pagein(&os_de,&temp);
  96942. ogg_sync_pageout(&oy,&temp);
  96943. ogg_stream_pagein(&os_de,&temp);
  96944. ogg_sync_pageout(&oy,&temp);
  96945. ogg_sync_pageout(&oy,&temp);
  96946. ogg_stream_pagein(&os_de,&temp);
  96947. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96948. checkpacket(&test,0,0,0);
  96949. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96950. checkpacket(&test,100,1,-1);
  96951. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96952. checkpacket(&test,4079,2,3000);
  96953. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96954. fprintf(stderr,"Error: loss of page did not return error\n");
  96955. exit(1);
  96956. }
  96957. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96958. checkpacket(&test,76,5,-1);
  96959. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96960. checkpacket(&test,34,6,-1);
  96961. fprintf(stderr,"ok.\n");
  96962. }
  96963. {
  96964. ogg_page temp;
  96965. ogg_packet test;
  96966. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96967. ogg_sync_reset(&oy);
  96968. ogg_stream_reset(&os_de);
  96969. for(i=0;i<5;i++){
  96970. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96971. og[i].header_len);
  96972. ogg_sync_wrote(&oy,og[i].header_len);
  96973. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96974. ogg_sync_wrote(&oy,og[i].body_len);
  96975. }
  96976. ogg_sync_pageout(&oy,&temp);
  96977. ogg_stream_pagein(&os_de,&temp);
  96978. ogg_sync_pageout(&oy,&temp);
  96979. ogg_stream_pagein(&os_de,&temp);
  96980. ogg_sync_pageout(&oy,&temp);
  96981. ogg_stream_pagein(&os_de,&temp);
  96982. ogg_sync_pageout(&oy,&temp);
  96983. ogg_sync_pageout(&oy,&temp);
  96984. ogg_stream_pagein(&os_de,&temp);
  96985. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96986. checkpacket(&test,0,0,0);
  96987. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96988. checkpacket(&test,100,1,-1);
  96989. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96990. checkpacket(&test,4079,2,3000);
  96991. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96992. checkpacket(&test,2956,3,4000);
  96993. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96994. fprintf(stderr,"Error: loss of page did not return error\n");
  96995. exit(1);
  96996. }
  96997. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96998. checkpacket(&test,300,13,14000);
  96999. fprintf(stderr,"ok.\n");
  97000. }
  97001. {
  97002. ogg_page og_de;
  97003. fprintf(stderr,"Testing sync on partial inputs... ");
  97004. ogg_sync_reset(&oy);
  97005. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97006. 3);
  97007. ogg_sync_wrote(&oy,3);
  97008. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97009. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  97010. 20);
  97011. ogg_sync_wrote(&oy,20);
  97012. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97013. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  97014. 5);
  97015. ogg_sync_wrote(&oy,5);
  97016. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97017. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  97018. og[1].header_len-28);
  97019. ogg_sync_wrote(&oy,og[1].header_len-28);
  97020. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97021. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  97022. ogg_sync_wrote(&oy,1000);
  97023. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97024. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  97025. og[1].body_len-1000);
  97026. ogg_sync_wrote(&oy,og[1].body_len-1000);
  97027. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97028. fprintf(stderr,"ok.\n");
  97029. }
  97030. {
  97031. ogg_page og_de;
  97032. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  97033. ogg_sync_reset(&oy);
  97034. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97035. og[1].header_len);
  97036. ogg_sync_wrote(&oy,og[1].header_len);
  97037. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97038. og[1].body_len);
  97039. ogg_sync_wrote(&oy,og[1].body_len);
  97040. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97041. 20);
  97042. ogg_sync_wrote(&oy,20);
  97043. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97044. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97045. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  97046. og[1].header_len-20);
  97047. ogg_sync_wrote(&oy,og[1].header_len-20);
  97048. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97049. og[1].body_len);
  97050. ogg_sync_wrote(&oy,og[1].body_len);
  97051. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97052. fprintf(stderr,"ok.\n");
  97053. }
  97054. {
  97055. ogg_page og_de;
  97056. fprintf(stderr,"Testing search for capture... ");
  97057. ogg_sync_reset(&oy);
  97058. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97059. og[1].body_len);
  97060. ogg_sync_wrote(&oy,og[1].body_len);
  97061. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97062. og[1].header_len);
  97063. ogg_sync_wrote(&oy,og[1].header_len);
  97064. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97065. og[1].body_len);
  97066. ogg_sync_wrote(&oy,og[1].body_len);
  97067. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97068. 20);
  97069. ogg_sync_wrote(&oy,20);
  97070. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97071. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97072. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97073. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  97074. og[2].header_len-20);
  97075. ogg_sync_wrote(&oy,og[2].header_len-20);
  97076. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  97077. og[2].body_len);
  97078. ogg_sync_wrote(&oy,og[2].body_len);
  97079. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97080. fprintf(stderr,"ok.\n");
  97081. }
  97082. {
  97083. ogg_page og_de;
  97084. fprintf(stderr,"Testing recapture... ");
  97085. ogg_sync_reset(&oy);
  97086. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97087. og[1].header_len);
  97088. ogg_sync_wrote(&oy,og[1].header_len);
  97089. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97090. og[1].body_len);
  97091. ogg_sync_wrote(&oy,og[1].body_len);
  97092. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97093. og[2].header_len);
  97094. ogg_sync_wrote(&oy,og[2].header_len);
  97095. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97096. og[2].header_len);
  97097. ogg_sync_wrote(&oy,og[2].header_len);
  97098. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97099. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  97100. og[2].body_len-5);
  97101. ogg_sync_wrote(&oy,og[2].body_len-5);
  97102. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  97103. og[3].header_len);
  97104. ogg_sync_wrote(&oy,og[3].header_len);
  97105. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  97106. og[3].body_len);
  97107. ogg_sync_wrote(&oy,og[3].body_len);
  97108. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97109. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97110. fprintf(stderr,"ok.\n");
  97111. }
  97112. {
  97113. for(i=0;i<5;i++){
  97114. free_page(&og[i]);
  97115. }
  97116. }
  97117. }
  97118. return(0);
  97119. }
  97120. #endif
  97121. #endif
  97122. /*** End of inlined file: framing.c ***/
  97123. /*** Start of inlined file: analysis.c ***/
  97124. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97125. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97126. // tasks..
  97127. #if JUCE_MSVC
  97128. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97129. #endif
  97130. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97131. #if JUCE_USE_OGGVORBIS
  97132. #include <stdio.h>
  97133. #include <string.h>
  97134. #include <math.h>
  97135. /*** Start of inlined file: codec_internal.h ***/
  97136. #ifndef _V_CODECI_H_
  97137. #define _V_CODECI_H_
  97138. /*** Start of inlined file: envelope.h ***/
  97139. #ifndef _V_ENVELOPE_
  97140. #define _V_ENVELOPE_
  97141. /*** Start of inlined file: mdct.h ***/
  97142. #ifndef _OGG_mdct_H_
  97143. #define _OGG_mdct_H_
  97144. #ifdef MDCT_INTEGERIZED
  97145. #define DATA_TYPE int
  97146. #define REG_TYPE register int
  97147. #define TRIGBITS 14
  97148. #define cPI3_8 6270
  97149. #define cPI2_8 11585
  97150. #define cPI1_8 15137
  97151. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  97152. #define MULT_NORM(x) ((x)>>TRIGBITS)
  97153. #define HALVE(x) ((x)>>1)
  97154. #else
  97155. #define DATA_TYPE float
  97156. #define REG_TYPE float
  97157. #define cPI3_8 .38268343236508977175F
  97158. #define cPI2_8 .70710678118654752441F
  97159. #define cPI1_8 .92387953251128675613F
  97160. #define FLOAT_CONV(x) (x)
  97161. #define MULT_NORM(x) (x)
  97162. #define HALVE(x) ((x)*.5f)
  97163. #endif
  97164. typedef struct {
  97165. int n;
  97166. int log2n;
  97167. DATA_TYPE *trig;
  97168. int *bitrev;
  97169. DATA_TYPE scale;
  97170. } mdct_lookup;
  97171. extern void mdct_init(mdct_lookup *lookup,int n);
  97172. extern void mdct_clear(mdct_lookup *l);
  97173. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97174. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97175. #endif
  97176. /*** End of inlined file: mdct.h ***/
  97177. #define VE_PRE 16
  97178. #define VE_WIN 4
  97179. #define VE_POST 2
  97180. #define VE_AMP (VE_PRE+VE_POST-1)
  97181. #define VE_BANDS 7
  97182. #define VE_NEARDC 15
  97183. #define VE_MINSTRETCH 2 /* a bit less than short block */
  97184. #define VE_MAXSTRETCH 12 /* one-third full block */
  97185. typedef struct {
  97186. float ampbuf[VE_AMP];
  97187. int ampptr;
  97188. float nearDC[VE_NEARDC];
  97189. float nearDC_acc;
  97190. float nearDC_partialacc;
  97191. int nearptr;
  97192. } envelope_filter_state;
  97193. typedef struct {
  97194. int begin;
  97195. int end;
  97196. float *window;
  97197. float total;
  97198. } envelope_band;
  97199. typedef struct {
  97200. int ch;
  97201. int winlength;
  97202. int searchstep;
  97203. float minenergy;
  97204. mdct_lookup mdct;
  97205. float *mdct_win;
  97206. envelope_band band[VE_BANDS];
  97207. envelope_filter_state *filter;
  97208. int stretch;
  97209. int *mark;
  97210. long storage;
  97211. long current;
  97212. long curmark;
  97213. long cursor;
  97214. } envelope_lookup;
  97215. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  97216. extern void _ve_envelope_clear(envelope_lookup *e);
  97217. extern long _ve_envelope_search(vorbis_dsp_state *v);
  97218. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  97219. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  97220. #endif
  97221. /*** End of inlined file: envelope.h ***/
  97222. /*** Start of inlined file: codebook.h ***/
  97223. #ifndef _V_CODEBOOK_H_
  97224. #define _V_CODEBOOK_H_
  97225. typedef struct static_codebook{
  97226. long dim; /* codebook dimensions (elements per vector) */
  97227. long entries; /* codebook entries */
  97228. long *lengthlist; /* codeword lengths in bits */
  97229. int maptype; /* 0=none
  97230. 1=implicitly populated values from map column
  97231. 2=listed arbitrary values */
  97232. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  97233. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  97234. int q_quant; /* bits: 0 < quant <= 16 */
  97235. int q_sequencep; /* bitflag */
  97236. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  97237. map == 2: list of dim*entries quantized entry vals
  97238. */
  97239. struct encode_aux_nearestmatch *nearest_tree;
  97240. struct encode_aux_threshmatch *thresh_tree;
  97241. struct encode_aux_pigeonhole *pigeon_tree;
  97242. int allocedp;
  97243. } static_codebook;
  97244. typedef struct encode_aux_nearestmatch{
  97245. long *ptr0;
  97246. long *ptr1;
  97247. long *p; /* decision points (each is an entry) */
  97248. long *q; /* decision points (each is an entry) */
  97249. long aux; /* number of tree entries */
  97250. long alloc;
  97251. } encode_aux_nearestmatch;
  97252. typedef struct encode_aux_threshmatch{
  97253. float *quantthresh;
  97254. long *quantmap;
  97255. int quantvals;
  97256. int threshvals;
  97257. } encode_aux_threshmatch;
  97258. typedef struct encode_aux_pigeonhole{
  97259. float min;
  97260. float del;
  97261. int mapentries;
  97262. int quantvals;
  97263. long *pigeonmap;
  97264. long fittotal;
  97265. long *fitlist;
  97266. long *fitmap;
  97267. long *fitlength;
  97268. } encode_aux_pigeonhole;
  97269. typedef struct codebook{
  97270. long dim; /* codebook dimensions (elements per vector) */
  97271. long entries; /* codebook entries */
  97272. long used_entries; /* populated codebook entries */
  97273. const static_codebook *c;
  97274. float *valuelist; /* list of dim*entries actual entry values */
  97275. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  97276. int *dec_index; /* only used if sparseness collapsed */
  97277. char *dec_codelengths;
  97278. ogg_uint32_t *dec_firsttable;
  97279. int dec_firsttablen;
  97280. int dec_maxlength;
  97281. } codebook;
  97282. extern void vorbis_staticbook_clear(static_codebook *b);
  97283. extern void vorbis_staticbook_destroy(static_codebook *b);
  97284. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  97285. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  97286. extern void vorbis_book_clear(codebook *b);
  97287. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  97288. extern float *_book_logdist(const static_codebook *b,float *vals);
  97289. extern float _float32_unpack(long val);
  97290. extern long _float32_pack(float val);
  97291. extern int _best(codebook *book, float *a, int step);
  97292. extern int _ilog(unsigned int v);
  97293. extern long _book_maptype1_quantvals(const static_codebook *b);
  97294. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  97295. extern long vorbis_book_codeword(codebook *book,int entry);
  97296. extern long vorbis_book_codelen(codebook *book,int entry);
  97297. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  97298. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  97299. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  97300. extern int vorbis_book_errorv(codebook *book, float *a);
  97301. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  97302. oggpack_buffer *b);
  97303. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  97304. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  97305. oggpack_buffer *b,int n);
  97306. extern long vorbis_book_decodev_set(codebook *book, float *a,
  97307. oggpack_buffer *b,int n);
  97308. extern long vorbis_book_decodev_add(codebook *book, float *a,
  97309. oggpack_buffer *b,int n);
  97310. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  97311. long off,int ch,
  97312. oggpack_buffer *b,int n);
  97313. #endif
  97314. /*** End of inlined file: codebook.h ***/
  97315. #define BLOCKTYPE_IMPULSE 0
  97316. #define BLOCKTYPE_PADDING 1
  97317. #define BLOCKTYPE_TRANSITION 0
  97318. #define BLOCKTYPE_LONG 1
  97319. #define PACKETBLOBS 15
  97320. typedef struct vorbis_block_internal{
  97321. float **pcmdelay; /* this is a pointer into local storage */
  97322. float ampmax;
  97323. int blocktype;
  97324. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  97325. blob [PACKETBLOBS/2] points to
  97326. the oggpack_buffer in the
  97327. main vorbis_block */
  97328. } vorbis_block_internal;
  97329. typedef void vorbis_look_floor;
  97330. typedef void vorbis_look_residue;
  97331. typedef void vorbis_look_transform;
  97332. typedef struct {
  97333. int blockflag;
  97334. int windowtype;
  97335. int transformtype;
  97336. int mapping;
  97337. } vorbis_info_mode;
  97338. typedef void vorbis_info_floor;
  97339. typedef void vorbis_info_residue;
  97340. typedef void vorbis_info_mapping;
  97341. /*** Start of inlined file: psy.h ***/
  97342. #ifndef _V_PSY_H_
  97343. #define _V_PSY_H_
  97344. /*** Start of inlined file: smallft.h ***/
  97345. #ifndef _V_SMFT_H_
  97346. #define _V_SMFT_H_
  97347. typedef struct {
  97348. int n;
  97349. float *trigcache;
  97350. int *splitcache;
  97351. } drft_lookup;
  97352. extern void drft_forward(drft_lookup *l,float *data);
  97353. extern void drft_backward(drft_lookup *l,float *data);
  97354. extern void drft_init(drft_lookup *l,int n);
  97355. extern void drft_clear(drft_lookup *l);
  97356. #endif
  97357. /*** End of inlined file: smallft.h ***/
  97358. /*** Start of inlined file: backends.h ***/
  97359. #ifndef _vorbis_backend_h_
  97360. #define _vorbis_backend_h_
  97361. typedef struct{
  97362. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  97363. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  97364. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  97365. void (*free_info) (vorbis_info_floor *);
  97366. void (*free_look) (vorbis_look_floor *);
  97367. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  97368. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  97369. void *buffer,float *);
  97370. } vorbis_func_floor;
  97371. typedef struct{
  97372. int order;
  97373. long rate;
  97374. long barkmap;
  97375. int ampbits;
  97376. int ampdB;
  97377. int numbooks; /* <= 16 */
  97378. int books[16];
  97379. float lessthan; /* encode-only config setting hacks for libvorbis */
  97380. float greaterthan; /* encode-only config setting hacks for libvorbis */
  97381. } vorbis_info_floor0;
  97382. #define VIF_POSIT 63
  97383. #define VIF_CLASS 16
  97384. #define VIF_PARTS 31
  97385. typedef struct{
  97386. int partitions; /* 0 to 31 */
  97387. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  97388. int class_dim[VIF_CLASS]; /* 1 to 8 */
  97389. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  97390. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  97391. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  97392. int mult; /* 1 2 3 or 4 */
  97393. int postlist[VIF_POSIT+2]; /* first two implicit */
  97394. float maxover;
  97395. float maxunder;
  97396. float maxerr;
  97397. float twofitweight;
  97398. float twofitatten;
  97399. int n;
  97400. } vorbis_info_floor1;
  97401. typedef struct{
  97402. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  97403. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  97404. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  97405. vorbis_info_residue *);
  97406. void (*free_info) (vorbis_info_residue *);
  97407. void (*free_look) (vorbis_look_residue *);
  97408. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  97409. float **,int *,int);
  97410. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  97411. vorbis_look_residue *,
  97412. float **,float **,int *,int,long **);
  97413. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  97414. float **,int *,int);
  97415. } vorbis_func_residue;
  97416. typedef struct vorbis_info_residue0{
  97417. long begin;
  97418. long end;
  97419. int grouping; /* group n vectors per partition */
  97420. int partitions; /* possible codebooks for a partition */
  97421. int groupbook; /* huffbook for partitioning */
  97422. int secondstages[64]; /* expanded out to pointers in lookup */
  97423. int booklist[256]; /* list of second stage books */
  97424. float classmetric1[64];
  97425. float classmetric2[64];
  97426. } vorbis_info_residue0;
  97427. typedef struct{
  97428. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  97429. oggpack_buffer *);
  97430. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  97431. void (*free_info) (vorbis_info_mapping *);
  97432. int (*forward) (struct vorbis_block *vb);
  97433. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  97434. } vorbis_func_mapping;
  97435. typedef struct vorbis_info_mapping0{
  97436. int submaps; /* <= 16 */
  97437. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  97438. int floorsubmap[16]; /* [mux] submap to floors */
  97439. int residuesubmap[16]; /* [mux] submap to residue */
  97440. int coupling_steps;
  97441. int coupling_mag[256];
  97442. int coupling_ang[256];
  97443. } vorbis_info_mapping0;
  97444. #endif
  97445. /*** End of inlined file: backends.h ***/
  97446. #ifndef EHMER_MAX
  97447. #define EHMER_MAX 56
  97448. #endif
  97449. #define P_BANDS 17 /* 62Hz to 16kHz */
  97450. #define P_LEVELS 8 /* 30dB to 100dB */
  97451. #define P_LEVEL_0 30. /* 30 dB */
  97452. #define P_NOISECURVES 3
  97453. #define NOISE_COMPAND_LEVELS 40
  97454. typedef struct vorbis_info_psy{
  97455. int blockflag;
  97456. float ath_adjatt;
  97457. float ath_maxatt;
  97458. float tone_masteratt[P_NOISECURVES];
  97459. float tone_centerboost;
  97460. float tone_decay;
  97461. float tone_abs_limit;
  97462. float toneatt[P_BANDS];
  97463. int noisemaskp;
  97464. float noisemaxsupp;
  97465. float noisewindowlo;
  97466. float noisewindowhi;
  97467. int noisewindowlomin;
  97468. int noisewindowhimin;
  97469. int noisewindowfixed;
  97470. float noiseoff[P_NOISECURVES][P_BANDS];
  97471. float noisecompand[NOISE_COMPAND_LEVELS];
  97472. float max_curve_dB;
  97473. int normal_channel_p;
  97474. int normal_point_p;
  97475. int normal_start;
  97476. int normal_partition;
  97477. double normal_thresh;
  97478. } vorbis_info_psy;
  97479. typedef struct{
  97480. int eighth_octave_lines;
  97481. float preecho_thresh[VE_BANDS];
  97482. float postecho_thresh[VE_BANDS];
  97483. float stretch_penalty;
  97484. float preecho_minenergy;
  97485. float ampmax_att_per_sec;
  97486. int coupling_pkHz[PACKETBLOBS];
  97487. int coupling_pointlimit[2][PACKETBLOBS];
  97488. int coupling_prepointamp[PACKETBLOBS];
  97489. int coupling_postpointamp[PACKETBLOBS];
  97490. int sliding_lowpass[2][PACKETBLOBS];
  97491. } vorbis_info_psy_global;
  97492. typedef struct {
  97493. float ampmax;
  97494. int channels;
  97495. vorbis_info_psy_global *gi;
  97496. int coupling_pointlimit[2][P_NOISECURVES];
  97497. } vorbis_look_psy_global;
  97498. typedef struct {
  97499. int n;
  97500. struct vorbis_info_psy *vi;
  97501. float ***tonecurves;
  97502. float **noiseoffset;
  97503. float *ath;
  97504. long *octave; /* in n.ocshift format */
  97505. long *bark;
  97506. long firstoc;
  97507. long shiftoc;
  97508. int eighth_octave_lines; /* power of two, please */
  97509. int total_octave_lines;
  97510. long rate; /* cache it */
  97511. float m_val; /* Masking compensation value */
  97512. } vorbis_look_psy;
  97513. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  97514. vorbis_info_psy_global *gi,int n,long rate);
  97515. extern void _vp_psy_clear(vorbis_look_psy *p);
  97516. extern void *_vi_psy_dup(void *source);
  97517. extern void _vi_psy_free(vorbis_info_psy *i);
  97518. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  97519. extern void _vp_remove_floor(vorbis_look_psy *p,
  97520. float *mdct,
  97521. int *icodedflr,
  97522. float *residue,
  97523. int sliding_lowpass);
  97524. extern void _vp_noisemask(vorbis_look_psy *p,
  97525. float *logmdct,
  97526. float *logmask);
  97527. extern void _vp_tonemask(vorbis_look_psy *p,
  97528. float *logfft,
  97529. float *logmask,
  97530. float global_specmax,
  97531. float local_specmax);
  97532. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97533. float *noise,
  97534. float *tone,
  97535. int offset_select,
  97536. float *logmask,
  97537. float *mdct,
  97538. float *logmdct);
  97539. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97540. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97541. vorbis_info_psy_global *g,
  97542. vorbis_look_psy *p,
  97543. vorbis_info_mapping0 *vi,
  97544. float **mdct);
  97545. extern void _vp_couple(int blobno,
  97546. vorbis_info_psy_global *g,
  97547. vorbis_look_psy *p,
  97548. vorbis_info_mapping0 *vi,
  97549. float **res,
  97550. float **mag_memo,
  97551. int **mag_sort,
  97552. int **ifloor,
  97553. int *nonzero,
  97554. int sliding_lowpass);
  97555. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97556. float *in,float *out,int *sortedindex);
  97557. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97558. float *magnitudes,int *sortedindex);
  97559. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97560. vorbis_look_psy *p,
  97561. vorbis_info_mapping0 *vi,
  97562. float **mags);
  97563. extern void hf_reduction(vorbis_info_psy_global *g,
  97564. vorbis_look_psy *p,
  97565. vorbis_info_mapping0 *vi,
  97566. float **mdct);
  97567. #endif
  97568. /*** End of inlined file: psy.h ***/
  97569. /*** Start of inlined file: bitrate.h ***/
  97570. #ifndef _V_BITRATE_H_
  97571. #define _V_BITRATE_H_
  97572. /*** Start of inlined file: os.h ***/
  97573. #ifndef _OS_H
  97574. #define _OS_H
  97575. #ifdef HAVE_CONFIG_H
  97576. #include "config.h"
  97577. #endif
  97578. #include <math.h>
  97579. /*** Start of inlined file: misc.h ***/
  97580. #ifndef _V_RANDOM_H_
  97581. #define _V_RANDOM_H_
  97582. extern int analysis_noisy;
  97583. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97584. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97585. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97586. ogg_int64_t off);
  97587. #ifdef DEBUG_MALLOC
  97588. #define _VDBG_GRAPHFILE "malloc.m"
  97589. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97590. extern void _VDBG_free(void *ptr,char *file,long line);
  97591. #ifndef MISC_C
  97592. #undef _ogg_malloc
  97593. #undef _ogg_calloc
  97594. #undef _ogg_realloc
  97595. #undef _ogg_free
  97596. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97597. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97598. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97599. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97600. #endif
  97601. #endif
  97602. #endif
  97603. /*** End of inlined file: misc.h ***/
  97604. #ifndef _V_IFDEFJAIL_H_
  97605. # define _V_IFDEFJAIL_H_
  97606. # ifdef __GNUC__
  97607. # define STIN static __inline__
  97608. # elif _WIN32
  97609. # define STIN static __inline
  97610. # else
  97611. # define STIN static
  97612. # endif
  97613. #ifdef DJGPP
  97614. # define rint(x) (floor((x)+0.5f))
  97615. #endif
  97616. #ifndef M_PI
  97617. # define M_PI (3.1415926536f)
  97618. #endif
  97619. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97620. # include <malloc.h>
  97621. # define rint(x) (floor((x)+0.5f))
  97622. # define NO_FLOAT_MATH_LIB
  97623. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97624. #endif
  97625. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97626. void *_alloca(size_t size);
  97627. # define alloca _alloca
  97628. #endif
  97629. #ifndef FAST_HYPOT
  97630. # define FAST_HYPOT hypot
  97631. #endif
  97632. #endif
  97633. #ifdef HAVE_ALLOCA_H
  97634. # include <alloca.h>
  97635. #endif
  97636. #ifdef USE_MEMORY_H
  97637. # include <memory.h>
  97638. #endif
  97639. #ifndef min
  97640. # define min(x,y) ((x)>(y)?(y):(x))
  97641. #endif
  97642. #ifndef max
  97643. # define max(x,y) ((x)<(y)?(y):(x))
  97644. #endif
  97645. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97646. # define VORBIS_FPU_CONTROL
  97647. typedef ogg_int16_t vorbis_fpu_control;
  97648. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97649. ogg_int16_t ret;
  97650. ogg_int16_t temp;
  97651. __asm__ __volatile__("fnstcw %0\n\t"
  97652. "movw %0,%%dx\n\t"
  97653. "orw $62463,%%dx\n\t"
  97654. "movw %%dx,%1\n\t"
  97655. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97656. *fpu=ret;
  97657. }
  97658. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97659. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97660. }
  97661. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97662. we get extra fst/fld to
  97663. truncate precision */
  97664. int i;
  97665. __asm__("fistl %0": "=m"(i) : "t"(f));
  97666. return(i);
  97667. }
  97668. #endif
  97669. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97670. # define VORBIS_FPU_CONTROL
  97671. typedef ogg_int16_t vorbis_fpu_control;
  97672. static __inline int vorbis_ftoi(double f){
  97673. int i;
  97674. __asm{
  97675. fld f
  97676. fistp i
  97677. }
  97678. return i;
  97679. }
  97680. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97681. }
  97682. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97683. }
  97684. #endif
  97685. #ifndef VORBIS_FPU_CONTROL
  97686. typedef int vorbis_fpu_control;
  97687. static int vorbis_ftoi(double f){
  97688. return (int)(f+.5);
  97689. }
  97690. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97691. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97692. #endif
  97693. #endif /* _OS_H */
  97694. /*** End of inlined file: os.h ***/
  97695. typedef struct bitrate_manager_state {
  97696. int managed;
  97697. long avg_reservoir;
  97698. long minmax_reservoir;
  97699. long avg_bitsper;
  97700. long min_bitsper;
  97701. long max_bitsper;
  97702. long short_per_long;
  97703. double avgfloat;
  97704. vorbis_block *vb;
  97705. int choice;
  97706. } bitrate_manager_state;
  97707. typedef struct bitrate_manager_info{
  97708. long avg_rate;
  97709. long min_rate;
  97710. long max_rate;
  97711. long reservoir_bits;
  97712. double reservoir_bias;
  97713. double slew_damp;
  97714. } bitrate_manager_info;
  97715. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97716. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97717. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97718. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97719. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97720. #endif
  97721. /*** End of inlined file: bitrate.h ***/
  97722. static int ilog(unsigned int v){
  97723. int ret=0;
  97724. while(v){
  97725. ret++;
  97726. v>>=1;
  97727. }
  97728. return(ret);
  97729. }
  97730. static int ilog2(unsigned int v){
  97731. int ret=0;
  97732. if(v)--v;
  97733. while(v){
  97734. ret++;
  97735. v>>=1;
  97736. }
  97737. return(ret);
  97738. }
  97739. typedef struct private_state {
  97740. envelope_lookup *ve; /* envelope lookup */
  97741. int window[2];
  97742. vorbis_look_transform **transform[2]; /* block, type */
  97743. drft_lookup fft_look[2];
  97744. int modebits;
  97745. vorbis_look_floor **flr;
  97746. vorbis_look_residue **residue;
  97747. vorbis_look_psy *psy;
  97748. vorbis_look_psy_global *psy_g_look;
  97749. unsigned char *header;
  97750. unsigned char *header1;
  97751. unsigned char *header2;
  97752. bitrate_manager_state bms;
  97753. ogg_int64_t sample_count;
  97754. } private_state;
  97755. /*** Start of inlined file: highlevel.h ***/
  97756. typedef struct highlevel_byblocktype {
  97757. double tone_mask_setting;
  97758. double tone_peaklimit_setting;
  97759. double noise_bias_setting;
  97760. double noise_compand_setting;
  97761. } highlevel_byblocktype;
  97762. typedef struct highlevel_encode_setup {
  97763. void *setup;
  97764. int set_in_stone;
  97765. double base_setting;
  97766. double long_setting;
  97767. double short_setting;
  97768. double impulse_noisetune;
  97769. int managed;
  97770. long bitrate_min;
  97771. long bitrate_av;
  97772. double bitrate_av_damp;
  97773. long bitrate_max;
  97774. long bitrate_reservoir;
  97775. double bitrate_reservoir_bias;
  97776. int impulse_block_p;
  97777. int noise_normalize_p;
  97778. double stereo_point_setting;
  97779. double lowpass_kHz;
  97780. double ath_floating_dB;
  97781. double ath_absolute_dB;
  97782. double amplitude_track_dBpersec;
  97783. double trigger_setting;
  97784. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97785. } highlevel_encode_setup;
  97786. /*** End of inlined file: highlevel.h ***/
  97787. typedef struct codec_setup_info {
  97788. long blocksizes[2];
  97789. int modes;
  97790. int maps;
  97791. int floors;
  97792. int residues;
  97793. int books;
  97794. int psys; /* encode only */
  97795. vorbis_info_mode *mode_param[64];
  97796. int map_type[64];
  97797. vorbis_info_mapping *map_param[64];
  97798. int floor_type[64];
  97799. vorbis_info_floor *floor_param[64];
  97800. int residue_type[64];
  97801. vorbis_info_residue *residue_param[64];
  97802. static_codebook *book_param[256];
  97803. codebook *fullbooks;
  97804. vorbis_info_psy *psy_param[4]; /* encode only */
  97805. vorbis_info_psy_global psy_g_param;
  97806. bitrate_manager_info bi;
  97807. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97808. highly redundant structure, but
  97809. improves clarity of program flow. */
  97810. int halfrate_flag; /* painless downsample for decode */
  97811. } codec_setup_info;
  97812. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97813. extern void _vp_global_free(vorbis_look_psy_global *look);
  97814. #endif
  97815. /*** End of inlined file: codec_internal.h ***/
  97816. /*** Start of inlined file: registry.h ***/
  97817. #ifndef _V_REG_H_
  97818. #define _V_REG_H_
  97819. #define VI_TRANSFORMB 1
  97820. #define VI_WINDOWB 1
  97821. #define VI_TIMEB 1
  97822. #define VI_FLOORB 2
  97823. #define VI_RESB 3
  97824. #define VI_MAPB 1
  97825. extern vorbis_func_floor *_floor_P[];
  97826. extern vorbis_func_residue *_residue_P[];
  97827. extern vorbis_func_mapping *_mapping_P[];
  97828. #endif
  97829. /*** End of inlined file: registry.h ***/
  97830. /*** Start of inlined file: scales.h ***/
  97831. #ifndef _V_SCALES_H_
  97832. #define _V_SCALES_H_
  97833. #include <math.h>
  97834. #define VORBIS_IEEE_FLOAT32 1
  97835. #ifdef VORBIS_IEEE_FLOAT32
  97836. static float unitnorm(float x){
  97837. union {
  97838. ogg_uint32_t i;
  97839. float f;
  97840. } ix;
  97841. ix.f = x;
  97842. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97843. return ix.f;
  97844. }
  97845. static float todB(const float *x){
  97846. union {
  97847. ogg_uint32_t i;
  97848. float f;
  97849. } ix;
  97850. ix.f = *x;
  97851. ix.i = ix.i&0x7fffffff;
  97852. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97853. }
  97854. #define todB_nn(x) todB(x)
  97855. #else
  97856. static float unitnorm(float x){
  97857. if(x<0)return(-1.f);
  97858. return(1.f);
  97859. }
  97860. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97861. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97862. #endif
  97863. #define fromdB(x) (exp((x)*.11512925f))
  97864. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97865. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97866. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97867. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97868. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97869. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97870. #endif
  97871. /*** End of inlined file: scales.h ***/
  97872. int analysis_noisy=1;
  97873. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97874. int ret,i;
  97875. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97876. vb->glue_bits=0;
  97877. vb->time_bits=0;
  97878. vb->floor_bits=0;
  97879. vb->res_bits=0;
  97880. for(i=0;i<PACKETBLOBS;i++)
  97881. oggpack_reset(vbi->packetblob[i]);
  97882. if((ret=_mapping_P[0]->forward(vb)))
  97883. return(ret);
  97884. if(op){
  97885. if(vorbis_bitrate_managed(vb))
  97886. return(OV_EINVAL);
  97887. op->packet=oggpack_get_buffer(&vb->opb);
  97888. op->bytes=oggpack_bytes(&vb->opb);
  97889. op->b_o_s=0;
  97890. op->e_o_s=vb->eofflag;
  97891. op->granulepos=vb->granulepos;
  97892. op->packetno=vb->sequence; /* for sake of completeness */
  97893. }
  97894. return(0);
  97895. }
  97896. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97897. int j;
  97898. FILE *of;
  97899. char buffer[80];
  97900. sprintf(buffer,"%s_%d.m",base,i);
  97901. of=fopen(buffer,"w");
  97902. if(!of)perror("failed to open data dump file");
  97903. for(j=0;j<n;j++){
  97904. if(bark){
  97905. float b=toBARK((4000.f*j/n)+.25);
  97906. fprintf(of,"%f ",b);
  97907. }else
  97908. if(off!=0)
  97909. fprintf(of,"%f ",(double)(j+off)/8000.);
  97910. else
  97911. fprintf(of,"%f ",(double)j);
  97912. if(dB){
  97913. float val;
  97914. if(v[j]==0.)
  97915. val=-140.;
  97916. else
  97917. val=todB(v+j);
  97918. fprintf(of,"%f\n",val);
  97919. }else{
  97920. fprintf(of,"%f\n",v[j]);
  97921. }
  97922. }
  97923. fclose(of);
  97924. }
  97925. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97926. ogg_int64_t off){
  97927. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97928. }
  97929. #endif
  97930. /*** End of inlined file: analysis.c ***/
  97931. /*** Start of inlined file: bitrate.c ***/
  97932. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97933. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97934. // tasks..
  97935. #if JUCE_MSVC
  97936. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97937. #endif
  97938. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97939. #if JUCE_USE_OGGVORBIS
  97940. #include <stdlib.h>
  97941. #include <string.h>
  97942. #include <math.h>
  97943. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97944. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97945. bitrate_manager_info *bi=&ci->bi;
  97946. memset(bm,0,sizeof(*bm));
  97947. if(bi && (bi->reservoir_bits>0)){
  97948. long ratesamples=vi->rate;
  97949. int halfsamples=ci->blocksizes[0]>>1;
  97950. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97951. bm->managed=1;
  97952. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97953. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97954. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97955. bm->avgfloat=PACKETBLOBS/2;
  97956. {
  97957. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97958. bm->minmax_reservoir=desired_fill;
  97959. bm->avg_reservoir=desired_fill;
  97960. }
  97961. }
  97962. }
  97963. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97964. memset(bm,0,sizeof(*bm));
  97965. return;
  97966. }
  97967. int vorbis_bitrate_managed(vorbis_block *vb){
  97968. vorbis_dsp_state *vd=vb->vd;
  97969. private_state *b=(private_state*)vd->backend_state;
  97970. bitrate_manager_state *bm=&b->bms;
  97971. if(bm && bm->managed)return(1);
  97972. return(0);
  97973. }
  97974. int vorbis_bitrate_addblock(vorbis_block *vb){
  97975. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97976. vorbis_dsp_state *vd=vb->vd;
  97977. private_state *b=(private_state*)vd->backend_state;
  97978. bitrate_manager_state *bm=&b->bms;
  97979. vorbis_info *vi=vd->vi;
  97980. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97981. bitrate_manager_info *bi=&ci->bi;
  97982. int choice=rint(bm->avgfloat);
  97983. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97984. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97985. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97986. int samples=ci->blocksizes[vb->W]>>1;
  97987. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97988. if(!bm->managed){
  97989. if(bm->vb)return(-1); /* one has been submitted without
  97990. being claimed */
  97991. bm->vb=vb;
  97992. return(0);
  97993. }
  97994. bm->vb=vb;
  97995. if(bm->avg_bitsper>0){
  97996. double slew=0.;
  97997. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97998. double slewlimit= 15./bi->slew_damp;
  97999. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  98000. while(choice>0 && this_bits>avg_target_bits &&
  98001. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  98002. choice--;
  98003. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98004. }
  98005. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  98006. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  98007. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  98008. choice++;
  98009. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98010. }
  98011. }
  98012. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  98013. if(slew<-slewlimit)slew=-slewlimit;
  98014. if(slew>slewlimit)slew=slewlimit;
  98015. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  98016. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98017. }
  98018. if(bm->min_bitsper>0){
  98019. if(this_bits<min_target_bits){
  98020. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  98021. choice++;
  98022. if(choice>=PACKETBLOBS)break;
  98023. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98024. }
  98025. }
  98026. }
  98027. if(bm->max_bitsper>0){
  98028. if(this_bits>max_target_bits){
  98029. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  98030. choice--;
  98031. if(choice<0)break;
  98032. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98033. }
  98034. }
  98035. }
  98036. if(choice<0){
  98037. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  98038. bm->choice=choice=0;
  98039. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  98040. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  98041. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98042. }
  98043. }else{
  98044. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  98045. if(choice>=PACKETBLOBS)
  98046. choice=PACKETBLOBS-1;
  98047. bm->choice=choice;
  98048. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  98049. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  98050. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98051. }
  98052. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  98053. if(max_target_bits>0 && this_bits>max_target_bits){
  98054. bm->minmax_reservoir+=(this_bits-max_target_bits);
  98055. }else if(min_target_bits>0 && this_bits<min_target_bits){
  98056. bm->minmax_reservoir+=(this_bits-min_target_bits);
  98057. }else{
  98058. if(bm->minmax_reservoir>desired_fill){
  98059. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  98060. bm->minmax_reservoir+=(this_bits-max_target_bits);
  98061. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  98062. }else{
  98063. bm->minmax_reservoir=desired_fill;
  98064. }
  98065. }else{
  98066. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  98067. bm->minmax_reservoir+=(this_bits-min_target_bits);
  98068. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  98069. }else{
  98070. bm->minmax_reservoir=desired_fill;
  98071. }
  98072. }
  98073. }
  98074. }
  98075. if(bm->avg_bitsper>0){
  98076. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  98077. bm->avg_reservoir+=this_bits-avg_target_bits;
  98078. }
  98079. return(0);
  98080. }
  98081. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  98082. private_state *b=(private_state*)vd->backend_state;
  98083. bitrate_manager_state *bm=&b->bms;
  98084. vorbis_block *vb=bm->vb;
  98085. int choice=PACKETBLOBS/2;
  98086. if(!vb)return 0;
  98087. if(op){
  98088. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98089. if(vorbis_bitrate_managed(vb))
  98090. choice=bm->choice;
  98091. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  98092. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  98093. op->b_o_s=0;
  98094. op->e_o_s=vb->eofflag;
  98095. op->granulepos=vb->granulepos;
  98096. op->packetno=vb->sequence; /* for sake of completeness */
  98097. }
  98098. bm->vb=0;
  98099. return(1);
  98100. }
  98101. #endif
  98102. /*** End of inlined file: bitrate.c ***/
  98103. /*** Start of inlined file: block.c ***/
  98104. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98105. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98106. // tasks..
  98107. #if JUCE_MSVC
  98108. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98109. #endif
  98110. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98111. #if JUCE_USE_OGGVORBIS
  98112. #include <stdio.h>
  98113. #include <stdlib.h>
  98114. #include <string.h>
  98115. /*** Start of inlined file: window.h ***/
  98116. #ifndef _V_WINDOW_
  98117. #define _V_WINDOW_
  98118. extern float *_vorbis_window_get(int n);
  98119. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  98120. int lW,int W,int nW);
  98121. #endif
  98122. /*** End of inlined file: window.h ***/
  98123. /*** Start of inlined file: lpc.h ***/
  98124. #ifndef _V_LPC_H_
  98125. #define _V_LPC_H_
  98126. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  98127. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  98128. float *data,long n);
  98129. #endif
  98130. /*** End of inlined file: lpc.h ***/
  98131. #ifndef WORD_ALIGN
  98132. #define WORD_ALIGN 8
  98133. #endif
  98134. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  98135. int i;
  98136. memset(vb,0,sizeof(*vb));
  98137. vb->vd=v;
  98138. vb->localalloc=0;
  98139. vb->localstore=NULL;
  98140. if(v->analysisp){
  98141. vorbis_block_internal *vbi=(vorbis_block_internal*)
  98142. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  98143. vbi->ampmax=-9999;
  98144. for(i=0;i<PACKETBLOBS;i++){
  98145. if(i==PACKETBLOBS/2){
  98146. vbi->packetblob[i]=&vb->opb;
  98147. }else{
  98148. vbi->packetblob[i]=
  98149. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  98150. }
  98151. oggpack_writeinit(vbi->packetblob[i]);
  98152. }
  98153. }
  98154. return(0);
  98155. }
  98156. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  98157. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  98158. if(bytes+vb->localtop>vb->localalloc){
  98159. if(vb->localstore){
  98160. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  98161. vb->totaluse+=vb->localtop;
  98162. link->next=vb->reap;
  98163. link->ptr=vb->localstore;
  98164. vb->reap=link;
  98165. }
  98166. vb->localalloc=bytes;
  98167. vb->localstore=_ogg_malloc(vb->localalloc);
  98168. vb->localtop=0;
  98169. }
  98170. {
  98171. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  98172. vb->localtop+=bytes;
  98173. return ret;
  98174. }
  98175. }
  98176. void _vorbis_block_ripcord(vorbis_block *vb){
  98177. struct alloc_chain *reap=vb->reap;
  98178. while(reap){
  98179. struct alloc_chain *next=reap->next;
  98180. _ogg_free(reap->ptr);
  98181. memset(reap,0,sizeof(*reap));
  98182. _ogg_free(reap);
  98183. reap=next;
  98184. }
  98185. if(vb->totaluse){
  98186. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  98187. vb->localalloc+=vb->totaluse;
  98188. vb->totaluse=0;
  98189. }
  98190. vb->localtop=0;
  98191. vb->reap=NULL;
  98192. }
  98193. int vorbis_block_clear(vorbis_block *vb){
  98194. int i;
  98195. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98196. _vorbis_block_ripcord(vb);
  98197. if(vb->localstore)_ogg_free(vb->localstore);
  98198. if(vbi){
  98199. for(i=0;i<PACKETBLOBS;i++){
  98200. oggpack_writeclear(vbi->packetblob[i]);
  98201. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  98202. }
  98203. _ogg_free(vbi);
  98204. }
  98205. memset(vb,0,sizeof(*vb));
  98206. return(0);
  98207. }
  98208. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  98209. int i;
  98210. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98211. private_state *b=NULL;
  98212. int hs;
  98213. if(ci==NULL) return 1;
  98214. hs=ci->halfrate_flag;
  98215. memset(v,0,sizeof(*v));
  98216. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  98217. v->vi=vi;
  98218. b->modebits=ilog2(ci->modes);
  98219. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  98220. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  98221. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98222. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98223. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  98224. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  98225. b->window[0]=ilog2(ci->blocksizes[0])-6;
  98226. b->window[1]=ilog2(ci->blocksizes[1])-6;
  98227. if(encp){ /* encode/decode differ here */
  98228. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  98229. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  98230. if(!ci->fullbooks){
  98231. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98232. for(i=0;i<ci->books;i++)
  98233. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  98234. }
  98235. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  98236. for(i=0;i<ci->psys;i++){
  98237. _vp_psy_init(b->psy+i,
  98238. ci->psy_param[i],
  98239. &ci->psy_g_param,
  98240. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  98241. vi->rate);
  98242. }
  98243. v->analysisp=1;
  98244. }else{
  98245. if(!ci->fullbooks){
  98246. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98247. for(i=0;i<ci->books;i++){
  98248. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  98249. vorbis_staticbook_destroy(ci->book_param[i]);
  98250. ci->book_param[i]=NULL;
  98251. }
  98252. }
  98253. }
  98254. v->pcm_storage=ci->blocksizes[1];
  98255. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  98256. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  98257. {
  98258. int i;
  98259. for(i=0;i<vi->channels;i++)
  98260. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  98261. }
  98262. v->lW=0; /* previous window size */
  98263. v->W=0; /* current window size */
  98264. v->centerW=ci->blocksizes[1]/2;
  98265. v->pcm_current=v->centerW;
  98266. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  98267. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  98268. for(i=0;i<ci->floors;i++)
  98269. b->flr[i]=_floor_P[ci->floor_type[i]]->
  98270. look(v,ci->floor_param[i]);
  98271. for(i=0;i<ci->residues;i++)
  98272. b->residue[i]=_residue_P[ci->residue_type[i]]->
  98273. look(v,ci->residue_param[i]);
  98274. return 0;
  98275. }
  98276. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98277. private_state *b=NULL;
  98278. if(_vds_shared_init(v,vi,1))return 1;
  98279. b=(private_state*)v->backend_state;
  98280. b->psy_g_look=_vp_global_look(vi);
  98281. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  98282. _ve_envelope_init(b->ve,vi);
  98283. vorbis_bitrate_init(vi,&b->bms);
  98284. v->sequence=3;
  98285. return(0);
  98286. }
  98287. void vorbis_dsp_clear(vorbis_dsp_state *v){
  98288. int i;
  98289. if(v){
  98290. vorbis_info *vi=v->vi;
  98291. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  98292. private_state *b=(private_state*)v->backend_state;
  98293. if(b){
  98294. if(b->ve){
  98295. _ve_envelope_clear(b->ve);
  98296. _ogg_free(b->ve);
  98297. }
  98298. if(b->transform[0]){
  98299. mdct_clear((mdct_lookup*) b->transform[0][0]);
  98300. _ogg_free(b->transform[0][0]);
  98301. _ogg_free(b->transform[0]);
  98302. }
  98303. if(b->transform[1]){
  98304. mdct_clear((mdct_lookup*) b->transform[1][0]);
  98305. _ogg_free(b->transform[1][0]);
  98306. _ogg_free(b->transform[1]);
  98307. }
  98308. if(b->flr){
  98309. for(i=0;i<ci->floors;i++)
  98310. _floor_P[ci->floor_type[i]]->
  98311. free_look(b->flr[i]);
  98312. _ogg_free(b->flr);
  98313. }
  98314. if(b->residue){
  98315. for(i=0;i<ci->residues;i++)
  98316. _residue_P[ci->residue_type[i]]->
  98317. free_look(b->residue[i]);
  98318. _ogg_free(b->residue);
  98319. }
  98320. if(b->psy){
  98321. for(i=0;i<ci->psys;i++)
  98322. _vp_psy_clear(b->psy+i);
  98323. _ogg_free(b->psy);
  98324. }
  98325. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  98326. vorbis_bitrate_clear(&b->bms);
  98327. drft_clear(&b->fft_look[0]);
  98328. drft_clear(&b->fft_look[1]);
  98329. }
  98330. if(v->pcm){
  98331. for(i=0;i<vi->channels;i++)
  98332. if(v->pcm[i])_ogg_free(v->pcm[i]);
  98333. _ogg_free(v->pcm);
  98334. if(v->pcmret)_ogg_free(v->pcmret);
  98335. }
  98336. if(b){
  98337. if(b->header)_ogg_free(b->header);
  98338. if(b->header1)_ogg_free(b->header1);
  98339. if(b->header2)_ogg_free(b->header2);
  98340. _ogg_free(b);
  98341. }
  98342. memset(v,0,sizeof(*v));
  98343. }
  98344. }
  98345. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  98346. int i;
  98347. vorbis_info *vi=v->vi;
  98348. private_state *b=(private_state*)v->backend_state;
  98349. if(b->header)_ogg_free(b->header);b->header=NULL;
  98350. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  98351. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  98352. if(v->pcm_current+vals>=v->pcm_storage){
  98353. v->pcm_storage=v->pcm_current+vals*2;
  98354. for(i=0;i<vi->channels;i++){
  98355. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  98356. }
  98357. }
  98358. for(i=0;i<vi->channels;i++)
  98359. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  98360. return(v->pcmret);
  98361. }
  98362. static void _preextrapolate_helper(vorbis_dsp_state *v){
  98363. int i;
  98364. int order=32;
  98365. float *lpc=(float*)alloca(order*sizeof(*lpc));
  98366. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  98367. long j;
  98368. v->preextrapolate=1;
  98369. if(v->pcm_current-v->centerW>order*2){ /* safety */
  98370. for(i=0;i<v->vi->channels;i++){
  98371. for(j=0;j<v->pcm_current;j++)
  98372. work[j]=v->pcm[i][v->pcm_current-j-1];
  98373. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  98374. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  98375. order,
  98376. work+v->pcm_current-v->centerW,
  98377. v->centerW);
  98378. for(j=0;j<v->pcm_current;j++)
  98379. v->pcm[i][v->pcm_current-j-1]=work[j];
  98380. }
  98381. }
  98382. }
  98383. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  98384. vorbis_info *vi=v->vi;
  98385. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98386. if(vals<=0){
  98387. int order=32;
  98388. int i;
  98389. float *lpc=(float*) alloca(order*sizeof(*lpc));
  98390. if(!v->preextrapolate)
  98391. _preextrapolate_helper(v);
  98392. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  98393. v->eofflag=v->pcm_current;
  98394. v->pcm_current+=ci->blocksizes[1]*3;
  98395. for(i=0;i<vi->channels;i++){
  98396. if(v->eofflag>order*2){
  98397. long n;
  98398. n=v->eofflag;
  98399. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  98400. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  98401. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  98402. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  98403. }else{
  98404. memset(v->pcm[i]+v->eofflag,0,
  98405. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  98406. }
  98407. }
  98408. }else{
  98409. if(v->pcm_current+vals>v->pcm_storage)
  98410. return(OV_EINVAL);
  98411. v->pcm_current+=vals;
  98412. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  98413. _preextrapolate_helper(v);
  98414. }
  98415. return(0);
  98416. }
  98417. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  98418. int i;
  98419. vorbis_info *vi=v->vi;
  98420. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98421. private_state *b=(private_state*)v->backend_state;
  98422. vorbis_look_psy_global *g=b->psy_g_look;
  98423. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  98424. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  98425. if(!v->preextrapolate)return(0);
  98426. if(v->eofflag==-1)return(0);
  98427. {
  98428. long bp=_ve_envelope_search(v);
  98429. if(bp==-1){
  98430. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  98431. full long block */
  98432. v->nW=0;
  98433. }else{
  98434. if(ci->blocksizes[0]==ci->blocksizes[1])
  98435. v->nW=0;
  98436. else
  98437. v->nW=bp;
  98438. }
  98439. }
  98440. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  98441. {
  98442. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  98443. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  98444. although this check is
  98445. less strict that the
  98446. _ve_envelope_search,
  98447. the search is not run
  98448. if we only use one
  98449. block size */
  98450. }
  98451. _vorbis_block_ripcord(vb);
  98452. vb->lW=v->lW;
  98453. vb->W=v->W;
  98454. vb->nW=v->nW;
  98455. if(v->W){
  98456. if(!v->lW || !v->nW){
  98457. vbi->blocktype=BLOCKTYPE_TRANSITION;
  98458. }else{
  98459. vbi->blocktype=BLOCKTYPE_LONG;
  98460. }
  98461. }else{
  98462. if(_ve_envelope_mark(v)){
  98463. vbi->blocktype=BLOCKTYPE_IMPULSE;
  98464. }else{
  98465. vbi->blocktype=BLOCKTYPE_PADDING;
  98466. }
  98467. }
  98468. vb->vd=v;
  98469. vb->sequence=v->sequence++;
  98470. vb->granulepos=v->granulepos;
  98471. vb->pcmend=ci->blocksizes[v->W];
  98472. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  98473. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  98474. vbi->ampmax=g->ampmax;
  98475. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  98476. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  98477. for(i=0;i<vi->channels;i++){
  98478. vbi->pcmdelay[i]=
  98479. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98480. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98481. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  98482. }
  98483. if(v->eofflag){
  98484. if(v->centerW>=v->eofflag){
  98485. v->eofflag=-1;
  98486. vb->eofflag=1;
  98487. return(1);
  98488. }
  98489. }
  98490. {
  98491. int new_centerNext=ci->blocksizes[1]/2;
  98492. int movementW=centerNext-new_centerNext;
  98493. if(movementW>0){
  98494. _ve_envelope_shift(b->ve,movementW);
  98495. v->pcm_current-=movementW;
  98496. for(i=0;i<vi->channels;i++)
  98497. memmove(v->pcm[i],v->pcm[i]+movementW,
  98498. v->pcm_current*sizeof(*v->pcm[i]));
  98499. v->lW=v->W;
  98500. v->W=v->nW;
  98501. v->centerW=new_centerNext;
  98502. if(v->eofflag){
  98503. v->eofflag-=movementW;
  98504. if(v->eofflag<=0)v->eofflag=-1;
  98505. if(v->centerW>=v->eofflag){
  98506. v->granulepos+=movementW-(v->centerW-v->eofflag);
  98507. }else{
  98508. v->granulepos+=movementW;
  98509. }
  98510. }else{
  98511. v->granulepos+=movementW;
  98512. }
  98513. }
  98514. }
  98515. return(1);
  98516. }
  98517. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  98518. vorbis_info *vi=v->vi;
  98519. codec_setup_info *ci;
  98520. int hs;
  98521. if(!v->backend_state)return -1;
  98522. if(!vi)return -1;
  98523. ci=(codec_setup_info*) vi->codec_setup;
  98524. if(!ci)return -1;
  98525. hs=ci->halfrate_flag;
  98526. v->centerW=ci->blocksizes[1]>>(hs+1);
  98527. v->pcm_current=v->centerW>>hs;
  98528. v->pcm_returned=-1;
  98529. v->granulepos=-1;
  98530. v->sequence=-1;
  98531. v->eofflag=0;
  98532. ((private_state *)(v->backend_state))->sample_count=-1;
  98533. return(0);
  98534. }
  98535. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98536. if(_vds_shared_init(v,vi,0)) return 1;
  98537. vorbis_synthesis_restart(v);
  98538. return 0;
  98539. }
  98540. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98541. vorbis_info *vi=v->vi;
  98542. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98543. private_state *b=(private_state*)v->backend_state;
  98544. int hs=ci->halfrate_flag;
  98545. int i,j;
  98546. if(!vb)return(OV_EINVAL);
  98547. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98548. v->lW=v->W;
  98549. v->W=vb->W;
  98550. v->nW=-1;
  98551. if((v->sequence==-1)||
  98552. (v->sequence+1 != vb->sequence)){
  98553. v->granulepos=-1; /* out of sequence; lose count */
  98554. b->sample_count=-1;
  98555. }
  98556. v->sequence=vb->sequence;
  98557. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98558. was called on block */
  98559. int n=ci->blocksizes[v->W]>>(hs+1);
  98560. int n0=ci->blocksizes[0]>>(hs+1);
  98561. int n1=ci->blocksizes[1]>>(hs+1);
  98562. int thisCenter;
  98563. int prevCenter;
  98564. v->glue_bits+=vb->glue_bits;
  98565. v->time_bits+=vb->time_bits;
  98566. v->floor_bits+=vb->floor_bits;
  98567. v->res_bits+=vb->res_bits;
  98568. if(v->centerW){
  98569. thisCenter=n1;
  98570. prevCenter=0;
  98571. }else{
  98572. thisCenter=0;
  98573. prevCenter=n1;
  98574. }
  98575. for(j=0;j<vi->channels;j++){
  98576. if(v->lW){
  98577. if(v->W){
  98578. float *w=_vorbis_window_get(b->window[1]-hs);
  98579. float *pcm=v->pcm[j]+prevCenter;
  98580. float *p=vb->pcm[j];
  98581. for(i=0;i<n1;i++)
  98582. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98583. }else{
  98584. float *w=_vorbis_window_get(b->window[0]-hs);
  98585. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98586. float *p=vb->pcm[j];
  98587. for(i=0;i<n0;i++)
  98588. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98589. }
  98590. }else{
  98591. if(v->W){
  98592. float *w=_vorbis_window_get(b->window[0]-hs);
  98593. float *pcm=v->pcm[j]+prevCenter;
  98594. float *p=vb->pcm[j]+n1/2-n0/2;
  98595. for(i=0;i<n0;i++)
  98596. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98597. for(;i<n1/2+n0/2;i++)
  98598. pcm[i]=p[i];
  98599. }else{
  98600. float *w=_vorbis_window_get(b->window[0]-hs);
  98601. float *pcm=v->pcm[j]+prevCenter;
  98602. float *p=vb->pcm[j];
  98603. for(i=0;i<n0;i++)
  98604. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98605. }
  98606. }
  98607. {
  98608. float *pcm=v->pcm[j]+thisCenter;
  98609. float *p=vb->pcm[j]+n;
  98610. for(i=0;i<n;i++)
  98611. pcm[i]=p[i];
  98612. }
  98613. }
  98614. if(v->centerW)
  98615. v->centerW=0;
  98616. else
  98617. v->centerW=n1;
  98618. if(v->pcm_returned==-1){
  98619. v->pcm_returned=thisCenter;
  98620. v->pcm_current=thisCenter;
  98621. }else{
  98622. v->pcm_returned=prevCenter;
  98623. v->pcm_current=prevCenter+
  98624. ((ci->blocksizes[v->lW]/4+
  98625. ci->blocksizes[v->W]/4)>>hs);
  98626. }
  98627. }
  98628. if(b->sample_count==-1){
  98629. b->sample_count=0;
  98630. }else{
  98631. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98632. }
  98633. if(v->granulepos==-1){
  98634. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98635. v->granulepos=vb->granulepos;
  98636. if(b->sample_count>v->granulepos){
  98637. if(vb->eofflag){
  98638. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98639. }else{
  98640. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98641. if(v->pcm_returned>v->pcm_current)
  98642. v->pcm_returned=v->pcm_current;
  98643. }
  98644. }
  98645. }
  98646. }else{
  98647. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98648. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98649. if(v->granulepos>vb->granulepos){
  98650. long extra=v->granulepos-vb->granulepos;
  98651. if(extra)
  98652. if(vb->eofflag){
  98653. v->pcm_current-=extra>>hs;
  98654. } /* else {Shouldn't happen *unless* the bitstream is out of
  98655. spec. Either way, believe the bitstream } */
  98656. } /* else {Shouldn't happen *unless* the bitstream is out of
  98657. spec. Either way, believe the bitstream } */
  98658. v->granulepos=vb->granulepos;
  98659. }
  98660. }
  98661. if(vb->eofflag)v->eofflag=1;
  98662. return(0);
  98663. }
  98664. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98665. vorbis_info *vi=v->vi;
  98666. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98667. if(pcm){
  98668. int i;
  98669. for(i=0;i<vi->channels;i++)
  98670. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98671. *pcm=v->pcmret;
  98672. }
  98673. return(v->pcm_current-v->pcm_returned);
  98674. }
  98675. return(0);
  98676. }
  98677. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98678. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98679. v->pcm_returned+=n;
  98680. return(0);
  98681. }
  98682. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98683. vorbis_info *vi=v->vi;
  98684. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98685. int hs=ci->halfrate_flag;
  98686. int n=ci->blocksizes[v->W]>>(hs+1);
  98687. int n0=ci->blocksizes[0]>>(hs+1);
  98688. int n1=ci->blocksizes[1]>>(hs+1);
  98689. int i,j;
  98690. if(v->pcm_returned<0)return 0;
  98691. if(v->centerW==n1){
  98692. for(j=0;j<vi->channels;j++){
  98693. float *p=v->pcm[j];
  98694. for(i=0;i<n1;i++){
  98695. float temp=p[i];
  98696. p[i]=p[i+n1];
  98697. p[i+n1]=temp;
  98698. }
  98699. }
  98700. v->pcm_current-=n1;
  98701. v->pcm_returned-=n1;
  98702. v->centerW=0;
  98703. }
  98704. if((v->lW^v->W)==1){
  98705. for(j=0;j<vi->channels;j++){
  98706. float *s=v->pcm[j];
  98707. float *d=v->pcm[j]+(n1-n0)/2;
  98708. for(i=(n1+n0)/2-1;i>=0;--i)
  98709. d[i]=s[i];
  98710. }
  98711. v->pcm_returned+=(n1-n0)/2;
  98712. v->pcm_current+=(n1-n0)/2;
  98713. }else{
  98714. if(v->lW==0){
  98715. for(j=0;j<vi->channels;j++){
  98716. float *s=v->pcm[j];
  98717. float *d=v->pcm[j]+n1-n0;
  98718. for(i=n0-1;i>=0;--i)
  98719. d[i]=s[i];
  98720. }
  98721. v->pcm_returned+=n1-n0;
  98722. v->pcm_current+=n1-n0;
  98723. }
  98724. }
  98725. if(pcm){
  98726. int i;
  98727. for(i=0;i<vi->channels;i++)
  98728. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98729. *pcm=v->pcmret;
  98730. }
  98731. return(n1+n-v->pcm_returned);
  98732. }
  98733. float *vorbis_window(vorbis_dsp_state *v,int W){
  98734. vorbis_info *vi=v->vi;
  98735. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98736. int hs=ci->halfrate_flag;
  98737. private_state *b=(private_state*)v->backend_state;
  98738. if(b->window[W]-1<0)return NULL;
  98739. return _vorbis_window_get(b->window[W]-hs);
  98740. }
  98741. #endif
  98742. /*** End of inlined file: block.c ***/
  98743. /*** Start of inlined file: codebook.c ***/
  98744. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98745. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98746. // tasks..
  98747. #if JUCE_MSVC
  98748. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98749. #endif
  98750. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98751. #if JUCE_USE_OGGVORBIS
  98752. #include <stdlib.h>
  98753. #include <string.h>
  98754. #include <math.h>
  98755. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98756. long i,j;
  98757. int ordered=0;
  98758. oggpack_write(opb,0x564342,24);
  98759. oggpack_write(opb,c->dim,16);
  98760. oggpack_write(opb,c->entries,24);
  98761. for(i=1;i<c->entries;i++)
  98762. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98763. if(i==c->entries)ordered=1;
  98764. if(ordered){
  98765. long count=0;
  98766. oggpack_write(opb,1,1); /* ordered */
  98767. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98768. for(i=1;i<c->entries;i++){
  98769. long thisx=c->lengthlist[i];
  98770. long last=c->lengthlist[i-1];
  98771. if(thisx>last){
  98772. for(j=last;j<thisx;j++){
  98773. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98774. count=i;
  98775. }
  98776. }
  98777. }
  98778. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98779. }else{
  98780. oggpack_write(opb,0,1); /* unordered */
  98781. for(i=0;i<c->entries;i++)
  98782. if(c->lengthlist[i]==0)break;
  98783. if(i==c->entries){
  98784. oggpack_write(opb,0,1); /* no unused entries */
  98785. for(i=0;i<c->entries;i++)
  98786. oggpack_write(opb,c->lengthlist[i]-1,5);
  98787. }else{
  98788. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98789. for(i=0;i<c->entries;i++){
  98790. if(c->lengthlist[i]==0){
  98791. oggpack_write(opb,0,1);
  98792. }else{
  98793. oggpack_write(opb,1,1);
  98794. oggpack_write(opb,c->lengthlist[i]-1,5);
  98795. }
  98796. }
  98797. }
  98798. }
  98799. oggpack_write(opb,c->maptype,4);
  98800. switch(c->maptype){
  98801. case 0:
  98802. break;
  98803. case 1:case 2:
  98804. if(!c->quantlist){
  98805. return(-1);
  98806. }
  98807. oggpack_write(opb,c->q_min,32);
  98808. oggpack_write(opb,c->q_delta,32);
  98809. oggpack_write(opb,c->q_quant-1,4);
  98810. oggpack_write(opb,c->q_sequencep,1);
  98811. {
  98812. int quantvals;
  98813. switch(c->maptype){
  98814. case 1:
  98815. quantvals=_book_maptype1_quantvals(c);
  98816. break;
  98817. case 2:
  98818. quantvals=c->entries*c->dim;
  98819. break;
  98820. default: /* NOT_REACHABLE */
  98821. quantvals=-1;
  98822. }
  98823. for(i=0;i<quantvals;i++)
  98824. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98825. }
  98826. break;
  98827. default:
  98828. return(-1);
  98829. }
  98830. return(0);
  98831. }
  98832. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98833. long i,j;
  98834. memset(s,0,sizeof(*s));
  98835. s->allocedp=1;
  98836. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98837. s->dim=oggpack_read(opb,16);
  98838. s->entries=oggpack_read(opb,24);
  98839. if(s->entries==-1)goto _eofout;
  98840. switch((int)oggpack_read(opb,1)){
  98841. case 0:
  98842. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98843. if(oggpack_read(opb,1)){
  98844. for(i=0;i<s->entries;i++){
  98845. if(oggpack_read(opb,1)){
  98846. long num=oggpack_read(opb,5);
  98847. if(num==-1)goto _eofout;
  98848. s->lengthlist[i]=num+1;
  98849. }else
  98850. s->lengthlist[i]=0;
  98851. }
  98852. }else{
  98853. for(i=0;i<s->entries;i++){
  98854. long num=oggpack_read(opb,5);
  98855. if(num==-1)goto _eofout;
  98856. s->lengthlist[i]=num+1;
  98857. }
  98858. }
  98859. break;
  98860. case 1:
  98861. {
  98862. long length=oggpack_read(opb,5)+1;
  98863. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98864. for(i=0;i<s->entries;){
  98865. long num=oggpack_read(opb,_ilog(s->entries-i));
  98866. if(num==-1)goto _eofout;
  98867. for(j=0;j<num && i<s->entries;j++,i++)
  98868. s->lengthlist[i]=length;
  98869. length++;
  98870. }
  98871. }
  98872. break;
  98873. default:
  98874. return(-1);
  98875. }
  98876. switch((s->maptype=oggpack_read(opb,4))){
  98877. case 0:
  98878. break;
  98879. case 1: case 2:
  98880. s->q_min=oggpack_read(opb,32);
  98881. s->q_delta=oggpack_read(opb,32);
  98882. s->q_quant=oggpack_read(opb,4)+1;
  98883. s->q_sequencep=oggpack_read(opb,1);
  98884. {
  98885. int quantvals=0;
  98886. switch(s->maptype){
  98887. case 1:
  98888. quantvals=_book_maptype1_quantvals(s);
  98889. break;
  98890. case 2:
  98891. quantvals=s->entries*s->dim;
  98892. break;
  98893. }
  98894. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98895. for(i=0;i<quantvals;i++)
  98896. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98897. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98898. }
  98899. break;
  98900. default:
  98901. goto _errout;
  98902. }
  98903. return(0);
  98904. _errout:
  98905. _eofout:
  98906. vorbis_staticbook_clear(s);
  98907. return(-1);
  98908. }
  98909. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98910. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98911. return(book->c->lengthlist[a]);
  98912. }
  98913. int vorbis_book_errorv(codebook *book,float *a){
  98914. int dim=book->dim,k;
  98915. int best=_best(book,a,1);
  98916. for(k=0;k<dim;k++)
  98917. a[k]=(book->valuelist+best*dim)[k];
  98918. return(best);
  98919. }
  98920. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98921. int k,dim=book->dim;
  98922. for(k=0;k<dim;k++)
  98923. a[k]=(book->valuelist+best*dim)[k];
  98924. return(vorbis_book_encode(book,best,b));
  98925. }
  98926. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98927. int read=book->dec_maxlength;
  98928. long lo,hi;
  98929. long lok = oggpack_look(b,book->dec_firsttablen);
  98930. if (lok >= 0) {
  98931. long entry = book->dec_firsttable[lok];
  98932. if(entry&0x80000000UL){
  98933. lo=(entry>>15)&0x7fff;
  98934. hi=book->used_entries-(entry&0x7fff);
  98935. }else{
  98936. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98937. return(entry-1);
  98938. }
  98939. }else{
  98940. lo=0;
  98941. hi=book->used_entries;
  98942. }
  98943. lok = oggpack_look(b, read);
  98944. while(lok<0 && read>1)
  98945. lok = oggpack_look(b, --read);
  98946. if(lok<0)return -1;
  98947. {
  98948. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98949. while(hi-lo>1){
  98950. long p=(hi-lo)>>1;
  98951. long test=book->codelist[lo+p]>testword;
  98952. lo+=p&(test-1);
  98953. hi-=p&(-test);
  98954. }
  98955. if(book->dec_codelengths[lo]<=read){
  98956. oggpack_adv(b, book->dec_codelengths[lo]);
  98957. return(lo);
  98958. }
  98959. }
  98960. oggpack_adv(b, read);
  98961. return(-1);
  98962. }
  98963. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98964. long packed_entry=decode_packed_entry_number(book,b);
  98965. if(packed_entry>=0)
  98966. return(book->dec_index[packed_entry]);
  98967. return(packed_entry);
  98968. }
  98969. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98970. int step=n/book->dim;
  98971. long *entry = (long*)alloca(sizeof(*entry)*step);
  98972. float **t = (float**)alloca(sizeof(*t)*step);
  98973. int i,j,o;
  98974. for (i = 0; i < step; i++) {
  98975. entry[i]=decode_packed_entry_number(book,b);
  98976. if(entry[i]==-1)return(-1);
  98977. t[i] = book->valuelist+entry[i]*book->dim;
  98978. }
  98979. for(i=0,o=0;i<book->dim;i++,o+=step)
  98980. for (j=0;j<step;j++)
  98981. a[o+j]+=t[j][i];
  98982. return(0);
  98983. }
  98984. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98985. int i,j,entry;
  98986. float *t;
  98987. if(book->dim>8){
  98988. for(i=0;i<n;){
  98989. entry = decode_packed_entry_number(book,b);
  98990. if(entry==-1)return(-1);
  98991. t = book->valuelist+entry*book->dim;
  98992. for (j=0;j<book->dim;)
  98993. a[i++]+=t[j++];
  98994. }
  98995. }else{
  98996. for(i=0;i<n;){
  98997. entry = decode_packed_entry_number(book,b);
  98998. if(entry==-1)return(-1);
  98999. t = book->valuelist+entry*book->dim;
  99000. j=0;
  99001. switch((int)book->dim){
  99002. case 8:
  99003. a[i++]+=t[j++];
  99004. case 7:
  99005. a[i++]+=t[j++];
  99006. case 6:
  99007. a[i++]+=t[j++];
  99008. case 5:
  99009. a[i++]+=t[j++];
  99010. case 4:
  99011. a[i++]+=t[j++];
  99012. case 3:
  99013. a[i++]+=t[j++];
  99014. case 2:
  99015. a[i++]+=t[j++];
  99016. case 1:
  99017. a[i++]+=t[j++];
  99018. case 0:
  99019. break;
  99020. }
  99021. }
  99022. }
  99023. return(0);
  99024. }
  99025. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  99026. int i,j,entry;
  99027. float *t;
  99028. for(i=0;i<n;){
  99029. entry = decode_packed_entry_number(book,b);
  99030. if(entry==-1)return(-1);
  99031. t = book->valuelist+entry*book->dim;
  99032. for (j=0;j<book->dim;)
  99033. a[i++]=t[j++];
  99034. }
  99035. return(0);
  99036. }
  99037. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  99038. oggpack_buffer *b,int n){
  99039. long i,j,entry;
  99040. int chptr=0;
  99041. for(i=offset/ch;i<(offset+n)/ch;){
  99042. entry = decode_packed_entry_number(book,b);
  99043. if(entry==-1)return(-1);
  99044. {
  99045. const float *t = book->valuelist+entry*book->dim;
  99046. for (j=0;j<book->dim;j++){
  99047. a[chptr++][i]+=t[j];
  99048. if(chptr==ch){
  99049. chptr=0;
  99050. i++;
  99051. }
  99052. }
  99053. }
  99054. }
  99055. return(0);
  99056. }
  99057. #ifdef _V_SELFTEST
  99058. #include <stdio.h>
  99059. #include "vorbis/book/lsp20_0.vqh"
  99060. #include "vorbis/book/res0a_13.vqh"
  99061. #define TESTSIZE 40
  99062. float test1[TESTSIZE]={
  99063. 0.105939f,
  99064. 0.215373f,
  99065. 0.429117f,
  99066. 0.587974f,
  99067. 0.181173f,
  99068. 0.296583f,
  99069. 0.515707f,
  99070. 0.715261f,
  99071. 0.162327f,
  99072. 0.263834f,
  99073. 0.342876f,
  99074. 0.406025f,
  99075. 0.103571f,
  99076. 0.223561f,
  99077. 0.368513f,
  99078. 0.540313f,
  99079. 0.136672f,
  99080. 0.395882f,
  99081. 0.587183f,
  99082. 0.652476f,
  99083. 0.114338f,
  99084. 0.417300f,
  99085. 0.525486f,
  99086. 0.698679f,
  99087. 0.147492f,
  99088. 0.324481f,
  99089. 0.643089f,
  99090. 0.757582f,
  99091. 0.139556f,
  99092. 0.215795f,
  99093. 0.324559f,
  99094. 0.399387f,
  99095. 0.120236f,
  99096. 0.267420f,
  99097. 0.446940f,
  99098. 0.608760f,
  99099. 0.115587f,
  99100. 0.287234f,
  99101. 0.571081f,
  99102. 0.708603f,
  99103. };
  99104. float test3[TESTSIZE]={
  99105. 0,1,-2,3,4,-5,6,7,8,9,
  99106. 8,-2,7,-1,4,6,8,3,1,-9,
  99107. 10,11,12,13,14,15,26,17,18,19,
  99108. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  99109. static_codebook *testlist[]={&_vq_book_lsp20_0,
  99110. &_vq_book_res0a_13,NULL};
  99111. float *testvec[]={test1,test3};
  99112. int main(){
  99113. oggpack_buffer write;
  99114. oggpack_buffer read;
  99115. long ptr=0,i;
  99116. oggpack_writeinit(&write);
  99117. fprintf(stderr,"Testing codebook abstraction...:\n");
  99118. while(testlist[ptr]){
  99119. codebook c;
  99120. static_codebook s;
  99121. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  99122. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  99123. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  99124. memset(iv,0,sizeof(*iv)*TESTSIZE);
  99125. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  99126. oggpack_reset(&write);
  99127. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  99128. we can write */
  99129. vorbis_staticbook_pack(testlist[ptr],&write);
  99130. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  99131. for(i=0;i<TESTSIZE;i+=c.dim){
  99132. int best=_best(&c,qv+i,1);
  99133. vorbis_book_encodev(&c,best,qv+i,&write);
  99134. }
  99135. vorbis_book_clear(&c);
  99136. fprintf(stderr,"OK.\n");
  99137. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  99138. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  99139. if(vorbis_staticbook_unpack(&read,&s)){
  99140. fprintf(stderr,"Error unpacking codebook.\n");
  99141. exit(1);
  99142. }
  99143. if(vorbis_book_init_decode(&c,&s)){
  99144. fprintf(stderr,"Error initializing codebook.\n");
  99145. exit(1);
  99146. }
  99147. for(i=0;i<TESTSIZE;i+=c.dim)
  99148. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  99149. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  99150. exit(1);
  99151. }
  99152. for(i=0;i<TESTSIZE;i++)
  99153. if(fabs(qv[i]-iv[i])>.000001){
  99154. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  99155. iv[i],qv[i],i);
  99156. exit(1);
  99157. }
  99158. fprintf(stderr,"OK\n");
  99159. ptr++;
  99160. }
  99161. exit(0);
  99162. }
  99163. #endif
  99164. #endif
  99165. /*** End of inlined file: codebook.c ***/
  99166. /*** Start of inlined file: envelope.c ***/
  99167. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99168. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99169. // tasks..
  99170. #if JUCE_MSVC
  99171. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99172. #endif
  99173. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99174. #if JUCE_USE_OGGVORBIS
  99175. #include <stdlib.h>
  99176. #include <string.h>
  99177. #include <stdio.h>
  99178. #include <math.h>
  99179. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  99180. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99181. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99182. int ch=vi->channels;
  99183. int i,j;
  99184. int n=e->winlength=128;
  99185. e->searchstep=64; /* not random */
  99186. e->minenergy=gi->preecho_minenergy;
  99187. e->ch=ch;
  99188. e->storage=128;
  99189. e->cursor=ci->blocksizes[1]/2;
  99190. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  99191. mdct_init(&e->mdct,n);
  99192. for(i=0;i<n;i++){
  99193. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  99194. e->mdct_win[i]*=e->mdct_win[i];
  99195. }
  99196. e->band[0].begin=2; e->band[0].end=4;
  99197. e->band[1].begin=4; e->band[1].end=5;
  99198. e->band[2].begin=6; e->band[2].end=6;
  99199. e->band[3].begin=9; e->band[3].end=8;
  99200. e->band[4].begin=13; e->band[4].end=8;
  99201. e->band[5].begin=17; e->band[5].end=8;
  99202. e->band[6].begin=22; e->band[6].end=8;
  99203. for(j=0;j<VE_BANDS;j++){
  99204. n=e->band[j].end;
  99205. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  99206. for(i=0;i<n;i++){
  99207. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  99208. e->band[j].total+=e->band[j].window[i];
  99209. }
  99210. e->band[j].total=1./e->band[j].total;
  99211. }
  99212. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  99213. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  99214. }
  99215. void _ve_envelope_clear(envelope_lookup *e){
  99216. int i;
  99217. mdct_clear(&e->mdct);
  99218. for(i=0;i<VE_BANDS;i++)
  99219. _ogg_free(e->band[i].window);
  99220. _ogg_free(e->mdct_win);
  99221. _ogg_free(e->filter);
  99222. _ogg_free(e->mark);
  99223. memset(e,0,sizeof(*e));
  99224. }
  99225. static int _ve_amp(envelope_lookup *ve,
  99226. vorbis_info_psy_global *gi,
  99227. float *data,
  99228. envelope_band *bands,
  99229. envelope_filter_state *filters,
  99230. long pos){
  99231. long n=ve->winlength;
  99232. int ret=0;
  99233. long i,j;
  99234. float decay;
  99235. float minV=ve->minenergy;
  99236. float *vec=(float*) alloca(n*sizeof(*vec));
  99237. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  99238. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  99239. if(penalty<0.f)penalty=0.f;
  99240. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  99241. for(i=0;i<n;i++)
  99242. vec[i]=data[i]*ve->mdct_win[i];
  99243. mdct_forward(&ve->mdct,vec,vec);
  99244. {
  99245. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  99246. int ptr=filters->nearptr;
  99247. if(ptr==0){
  99248. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  99249. filters->nearDC_partialacc=temp;
  99250. }else{
  99251. decay=filters->nearDC_acc+=temp;
  99252. filters->nearDC_partialacc+=temp;
  99253. }
  99254. filters->nearDC_acc-=filters->nearDC[ptr];
  99255. filters->nearDC[ptr]=temp;
  99256. decay*=(1./(VE_NEARDC+1));
  99257. filters->nearptr++;
  99258. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  99259. decay=todB(&decay)*.5-15.f;
  99260. }
  99261. for(i=0;i<n/2;i+=2){
  99262. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  99263. val=todB(&val)*.5f;
  99264. if(val<decay)val=decay;
  99265. if(val<minV)val=minV;
  99266. vec[i>>1]=val;
  99267. decay-=8.;
  99268. }
  99269. for(j=0;j<VE_BANDS;j++){
  99270. float acc=0.;
  99271. float valmax,valmin;
  99272. for(i=0;i<bands[j].end;i++)
  99273. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  99274. acc*=bands[j].total;
  99275. {
  99276. int p,thisx=filters[j].ampptr;
  99277. float postmax,postmin,premax=-99999.f,premin=99999.f;
  99278. p=thisx;
  99279. p--;
  99280. if(p<0)p+=VE_AMP;
  99281. postmax=max(acc,filters[j].ampbuf[p]);
  99282. postmin=min(acc,filters[j].ampbuf[p]);
  99283. for(i=0;i<stretch;i++){
  99284. p--;
  99285. if(p<0)p+=VE_AMP;
  99286. premax=max(premax,filters[j].ampbuf[p]);
  99287. premin=min(premin,filters[j].ampbuf[p]);
  99288. }
  99289. valmin=postmin-premin;
  99290. valmax=postmax-premax;
  99291. filters[j].ampbuf[thisx]=acc;
  99292. filters[j].ampptr++;
  99293. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  99294. }
  99295. if(valmax>gi->preecho_thresh[j]+penalty){
  99296. ret|=1;
  99297. ret|=4;
  99298. }
  99299. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  99300. }
  99301. return(ret);
  99302. }
  99303. #if 0
  99304. static int seq=0;
  99305. static ogg_int64_t totalshift=-1024;
  99306. #endif
  99307. long _ve_envelope_search(vorbis_dsp_state *v){
  99308. vorbis_info *vi=v->vi;
  99309. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  99310. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99311. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99312. long i,j;
  99313. int first=ve->current/ve->searchstep;
  99314. int last=v->pcm_current/ve->searchstep-VE_WIN;
  99315. if(first<0)first=0;
  99316. if(last+VE_WIN+VE_POST>ve->storage){
  99317. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  99318. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  99319. }
  99320. for(j=first;j<last;j++){
  99321. int ret=0;
  99322. ve->stretch++;
  99323. if(ve->stretch>VE_MAXSTRETCH*2)
  99324. ve->stretch=VE_MAXSTRETCH*2;
  99325. for(i=0;i<ve->ch;i++){
  99326. float *pcm=v->pcm[i]+ve->searchstep*(j);
  99327. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  99328. }
  99329. ve->mark[j+VE_POST]=0;
  99330. if(ret&1){
  99331. ve->mark[j]=1;
  99332. ve->mark[j+1]=1;
  99333. }
  99334. if(ret&2){
  99335. ve->mark[j]=1;
  99336. if(j>0)ve->mark[j-1]=1;
  99337. }
  99338. if(ret&4)ve->stretch=-1;
  99339. }
  99340. ve->current=last*ve->searchstep;
  99341. {
  99342. long centerW=v->centerW;
  99343. long testW=
  99344. centerW+
  99345. ci->blocksizes[v->W]/4+
  99346. ci->blocksizes[1]/2+
  99347. ci->blocksizes[0]/4;
  99348. j=ve->cursor;
  99349. while(j<ve->current-(ve->searchstep)){/* account for postecho
  99350. working back one window */
  99351. if(j>=testW)return(1);
  99352. ve->cursor=j;
  99353. if(ve->mark[j/ve->searchstep]){
  99354. if(j>centerW){
  99355. #if 0
  99356. if(j>ve->curmark){
  99357. float *marker=alloca(v->pcm_current*sizeof(*marker));
  99358. int l,m;
  99359. memset(marker,0,sizeof(*marker)*v->pcm_current);
  99360. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  99361. seq,
  99362. (totalshift+ve->cursor)/44100.,
  99363. (totalshift+j)/44100.);
  99364. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  99365. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  99366. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  99367. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  99368. for(m=0;m<VE_BANDS;m++){
  99369. char buf[80];
  99370. sprintf(buf,"delL%d",m);
  99371. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  99372. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99373. }
  99374. for(m=0;m<VE_BANDS;m++){
  99375. char buf[80];
  99376. sprintf(buf,"delR%d",m);
  99377. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  99378. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99379. }
  99380. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  99381. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  99382. seq++;
  99383. }
  99384. #endif
  99385. ve->curmark=j;
  99386. if(j>=testW)return(1);
  99387. return(0);
  99388. }
  99389. }
  99390. j+=ve->searchstep;
  99391. }
  99392. }
  99393. return(-1);
  99394. }
  99395. int _ve_envelope_mark(vorbis_dsp_state *v){
  99396. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99397. vorbis_info *vi=v->vi;
  99398. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99399. long centerW=v->centerW;
  99400. long beginW=centerW-ci->blocksizes[v->W]/4;
  99401. long endW=centerW+ci->blocksizes[v->W]/4;
  99402. if(v->W){
  99403. beginW-=ci->blocksizes[v->lW]/4;
  99404. endW+=ci->blocksizes[v->nW]/4;
  99405. }else{
  99406. beginW-=ci->blocksizes[0]/4;
  99407. endW+=ci->blocksizes[0]/4;
  99408. }
  99409. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  99410. {
  99411. long first=beginW/ve->searchstep;
  99412. long last=endW/ve->searchstep;
  99413. long i;
  99414. for(i=first;i<last;i++)
  99415. if(ve->mark[i])return(1);
  99416. }
  99417. return(0);
  99418. }
  99419. void _ve_envelope_shift(envelope_lookup *e,long shift){
  99420. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  99421. ahead of ve->current */
  99422. int smallshift=shift/e->searchstep;
  99423. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  99424. #if 0
  99425. for(i=0;i<VE_BANDS*e->ch;i++)
  99426. memmove(e->filter[i].markers,
  99427. e->filter[i].markers+smallshift,
  99428. (1024-smallshift)*sizeof(*(*e->filter).markers));
  99429. totalshift+=shift;
  99430. #endif
  99431. e->current-=shift;
  99432. if(e->curmark>=0)
  99433. e->curmark-=shift;
  99434. e->cursor-=shift;
  99435. }
  99436. #endif
  99437. /*** End of inlined file: envelope.c ***/
  99438. /*** Start of inlined file: floor0.c ***/
  99439. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99440. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99441. // tasks..
  99442. #if JUCE_MSVC
  99443. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99444. #endif
  99445. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99446. #if JUCE_USE_OGGVORBIS
  99447. #include <stdlib.h>
  99448. #include <string.h>
  99449. #include <math.h>
  99450. /*** Start of inlined file: lsp.h ***/
  99451. #ifndef _V_LSP_H_
  99452. #define _V_LSP_H_
  99453. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  99454. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  99455. float *lsp,int m,
  99456. float amp,float ampoffset);
  99457. #endif
  99458. /*** End of inlined file: lsp.h ***/
  99459. #include <stdio.h>
  99460. typedef struct {
  99461. int ln;
  99462. int m;
  99463. int **linearmap;
  99464. int n[2];
  99465. vorbis_info_floor0 *vi;
  99466. long bits;
  99467. long frames;
  99468. } vorbis_look_floor0;
  99469. static void floor0_free_info(vorbis_info_floor *i){
  99470. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  99471. if(info){
  99472. memset(info,0,sizeof(*info));
  99473. _ogg_free(info);
  99474. }
  99475. }
  99476. static void floor0_free_look(vorbis_look_floor *i){
  99477. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99478. if(look){
  99479. if(look->linearmap){
  99480. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  99481. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  99482. _ogg_free(look->linearmap);
  99483. }
  99484. memset(look,0,sizeof(*look));
  99485. _ogg_free(look);
  99486. }
  99487. }
  99488. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99489. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99490. int j;
  99491. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  99492. info->order=oggpack_read(opb,8);
  99493. info->rate=oggpack_read(opb,16);
  99494. info->barkmap=oggpack_read(opb,16);
  99495. info->ampbits=oggpack_read(opb,6);
  99496. info->ampdB=oggpack_read(opb,8);
  99497. info->numbooks=oggpack_read(opb,4)+1;
  99498. if(info->order<1)goto err_out;
  99499. if(info->rate<1)goto err_out;
  99500. if(info->barkmap<1)goto err_out;
  99501. if(info->numbooks<1)goto err_out;
  99502. for(j=0;j<info->numbooks;j++){
  99503. info->books[j]=oggpack_read(opb,8);
  99504. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  99505. }
  99506. return(info);
  99507. err_out:
  99508. floor0_free_info(info);
  99509. return(NULL);
  99510. }
  99511. static void floor0_map_lazy_init(vorbis_block *vb,
  99512. vorbis_info_floor *infoX,
  99513. vorbis_look_floor0 *look){
  99514. if(!look->linearmap[vb->W]){
  99515. vorbis_dsp_state *vd=vb->vd;
  99516. vorbis_info *vi=vd->vi;
  99517. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99518. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  99519. int W=vb->W;
  99520. int n=ci->blocksizes[W]/2,j;
  99521. float scale=look->ln/toBARK(info->rate/2.f);
  99522. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  99523. for(j=0;j<n;j++){
  99524. int val=floor( toBARK((info->rate/2.f)/n*j)
  99525. *scale); /* bark numbers represent band edges */
  99526. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99527. look->linearmap[W][j]=val;
  99528. }
  99529. look->linearmap[W][j]=-1;
  99530. look->n[W]=n;
  99531. }
  99532. }
  99533. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99534. vorbis_info_floor *i){
  99535. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99536. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99537. look->m=info->order;
  99538. look->ln=info->barkmap;
  99539. look->vi=info;
  99540. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99541. return look;
  99542. }
  99543. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99544. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99545. vorbis_info_floor0 *info=look->vi;
  99546. int j,k;
  99547. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99548. if(ampraw>0){ /* also handles the -1 out of data case */
  99549. long maxval=(1<<info->ampbits)-1;
  99550. float amp=(float)ampraw/maxval*info->ampdB;
  99551. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99552. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99553. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99554. codebook *b=ci->fullbooks+info->books[booknum];
  99555. float last=0.f;
  99556. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99557. for(j=0;j<look->m;j+=b->dim)
  99558. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99559. for(j=0;j<look->m;){
  99560. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99561. last=lsp[j-1];
  99562. }
  99563. lsp[look->m]=amp;
  99564. return(lsp);
  99565. }
  99566. }
  99567. eop:
  99568. return(NULL);
  99569. }
  99570. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99571. void *memo,float *out){
  99572. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99573. vorbis_info_floor0 *info=look->vi;
  99574. floor0_map_lazy_init(vb,info,look);
  99575. if(memo){
  99576. float *lsp=(float *)memo;
  99577. float amp=lsp[look->m];
  99578. vorbis_lsp_to_curve(out,
  99579. look->linearmap[vb->W],
  99580. look->n[vb->W],
  99581. look->ln,
  99582. lsp,look->m,amp,(float)info->ampdB);
  99583. return(1);
  99584. }
  99585. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99586. return(0);
  99587. }
  99588. vorbis_func_floor floor0_exportbundle={
  99589. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99590. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99591. };
  99592. #endif
  99593. /*** End of inlined file: floor0.c ***/
  99594. /*** Start of inlined file: floor1.c ***/
  99595. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99596. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99597. // tasks..
  99598. #if JUCE_MSVC
  99599. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99600. #endif
  99601. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99602. #if JUCE_USE_OGGVORBIS
  99603. #include <stdlib.h>
  99604. #include <string.h>
  99605. #include <math.h>
  99606. #include <stdio.h>
  99607. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99608. typedef struct {
  99609. int sorted_index[VIF_POSIT+2];
  99610. int forward_index[VIF_POSIT+2];
  99611. int reverse_index[VIF_POSIT+2];
  99612. int hineighbor[VIF_POSIT];
  99613. int loneighbor[VIF_POSIT];
  99614. int posts;
  99615. int n;
  99616. int quant_q;
  99617. vorbis_info_floor1 *vi;
  99618. long phrasebits;
  99619. long postbits;
  99620. long frames;
  99621. } vorbis_look_floor1;
  99622. typedef struct lsfit_acc{
  99623. long x0;
  99624. long x1;
  99625. long xa;
  99626. long ya;
  99627. long x2a;
  99628. long y2a;
  99629. long xya;
  99630. long an;
  99631. } lsfit_acc;
  99632. static void floor1_free_info(vorbis_info_floor *i){
  99633. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99634. if(info){
  99635. memset(info,0,sizeof(*info));
  99636. _ogg_free(info);
  99637. }
  99638. }
  99639. static void floor1_free_look(vorbis_look_floor *i){
  99640. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99641. if(look){
  99642. memset(look,0,sizeof(*look));
  99643. _ogg_free(look);
  99644. }
  99645. }
  99646. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99647. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99648. int j,k;
  99649. int count=0;
  99650. int rangebits;
  99651. int maxposit=info->postlist[1];
  99652. int maxclass=-1;
  99653. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99654. for(j=0;j<info->partitions;j++){
  99655. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99656. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99657. }
  99658. for(j=0;j<maxclass+1;j++){
  99659. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99660. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99661. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99662. for(k=0;k<(1<<info->class_subs[j]);k++)
  99663. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99664. }
  99665. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99666. oggpack_write(opb,ilog2(maxposit),4);
  99667. rangebits=ilog2(maxposit);
  99668. for(j=0,k=0;j<info->partitions;j++){
  99669. count+=info->class_dim[info->partitionclass[j]];
  99670. for(;k<count;k++)
  99671. oggpack_write(opb,info->postlist[k+2],rangebits);
  99672. }
  99673. }
  99674. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99675. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99676. int j,k,count=0,maxclass=-1,rangebits;
  99677. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99678. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99679. for(j=0;j<info->partitions;j++){
  99680. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99681. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99682. }
  99683. for(j=0;j<maxclass+1;j++){
  99684. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99685. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99686. if(info->class_subs[j]<0)
  99687. goto err_out;
  99688. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99689. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99690. goto err_out;
  99691. for(k=0;k<(1<<info->class_subs[j]);k++){
  99692. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99693. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99694. goto err_out;
  99695. }
  99696. }
  99697. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99698. rangebits=oggpack_read(opb,4);
  99699. for(j=0,k=0;j<info->partitions;j++){
  99700. count+=info->class_dim[info->partitionclass[j]];
  99701. for(;k<count;k++){
  99702. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99703. if(t<0 || t>=(1<<rangebits))
  99704. goto err_out;
  99705. }
  99706. }
  99707. info->postlist[0]=0;
  99708. info->postlist[1]=1<<rangebits;
  99709. return(info);
  99710. err_out:
  99711. floor1_free_info(info);
  99712. return(NULL);
  99713. }
  99714. static int icomp(const void *a,const void *b){
  99715. return(**(int **)a-**(int **)b);
  99716. }
  99717. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99718. vorbis_info_floor *in){
  99719. int *sortpointer[VIF_POSIT+2];
  99720. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99721. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99722. int i,j,n=0;
  99723. look->vi=info;
  99724. look->n=info->postlist[1];
  99725. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99726. n+=2;
  99727. look->posts=n;
  99728. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99729. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99730. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99731. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99732. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99733. switch(info->mult){
  99734. case 1: /* 1024 -> 256 */
  99735. look->quant_q=256;
  99736. break;
  99737. case 2: /* 1024 -> 128 */
  99738. look->quant_q=128;
  99739. break;
  99740. case 3: /* 1024 -> 86 */
  99741. look->quant_q=86;
  99742. break;
  99743. case 4: /* 1024 -> 64 */
  99744. look->quant_q=64;
  99745. break;
  99746. }
  99747. for(i=0;i<n-2;i++){
  99748. int lo=0;
  99749. int hi=1;
  99750. int lx=0;
  99751. int hx=look->n;
  99752. int currentx=info->postlist[i+2];
  99753. for(j=0;j<i+2;j++){
  99754. int x=info->postlist[j];
  99755. if(x>lx && x<currentx){
  99756. lo=j;
  99757. lx=x;
  99758. }
  99759. if(x<hx && x>currentx){
  99760. hi=j;
  99761. hx=x;
  99762. }
  99763. }
  99764. look->loneighbor[i]=lo;
  99765. look->hineighbor[i]=hi;
  99766. }
  99767. return(look);
  99768. }
  99769. static int render_point(int x0,int x1,int y0,int y1,int x){
  99770. y0&=0x7fff; /* mask off flag */
  99771. y1&=0x7fff;
  99772. {
  99773. int dy=y1-y0;
  99774. int adx=x1-x0;
  99775. int ady=abs(dy);
  99776. int err=ady*(x-x0);
  99777. int off=err/adx;
  99778. if(dy<0)return(y0-off);
  99779. return(y0+off);
  99780. }
  99781. }
  99782. static int vorbis_dBquant(const float *x){
  99783. int i= *x*7.3142857f+1023.5f;
  99784. if(i>1023)return(1023);
  99785. if(i<0)return(0);
  99786. return i;
  99787. }
  99788. static float FLOOR1_fromdB_LOOKUP[256]={
  99789. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99790. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99791. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99792. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99793. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99794. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99795. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99796. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99797. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99798. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99799. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99800. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99801. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99802. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99803. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99804. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99805. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99806. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99807. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99808. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99809. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99810. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99811. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99812. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99813. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99814. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99815. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99816. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99817. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99818. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99819. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99820. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99821. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99822. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99823. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99824. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99825. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99826. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99827. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99828. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99829. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99830. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99831. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99832. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99833. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99834. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99835. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99836. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99837. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99838. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99839. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99840. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99841. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99842. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99843. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99844. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99845. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99846. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99847. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99848. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99849. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99850. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99851. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99852. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99853. };
  99854. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99855. int dy=y1-y0;
  99856. int adx=x1-x0;
  99857. int ady=abs(dy);
  99858. int base=dy/adx;
  99859. int sy=(dy<0?base-1:base+1);
  99860. int x=x0;
  99861. int y=y0;
  99862. int err=0;
  99863. ady-=abs(base*adx);
  99864. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99865. while(++x<x1){
  99866. err=err+ady;
  99867. if(err>=adx){
  99868. err-=adx;
  99869. y+=sy;
  99870. }else{
  99871. y+=base;
  99872. }
  99873. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99874. }
  99875. }
  99876. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99877. int dy=y1-y0;
  99878. int adx=x1-x0;
  99879. int ady=abs(dy);
  99880. int base=dy/adx;
  99881. int sy=(dy<0?base-1:base+1);
  99882. int x=x0;
  99883. int y=y0;
  99884. int err=0;
  99885. ady-=abs(base*adx);
  99886. d[x]=y;
  99887. while(++x<x1){
  99888. err=err+ady;
  99889. if(err>=adx){
  99890. err-=adx;
  99891. y+=sy;
  99892. }else{
  99893. y+=base;
  99894. }
  99895. d[x]=y;
  99896. }
  99897. }
  99898. static int accumulate_fit(const float *flr,const float *mdct,
  99899. int x0, int x1,lsfit_acc *a,
  99900. int n,vorbis_info_floor1 *info){
  99901. long i;
  99902. 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;
  99903. memset(a,0,sizeof(*a));
  99904. a->x0=x0;
  99905. a->x1=x1;
  99906. if(x1>=n)x1=n-1;
  99907. for(i=x0;i<=x1;i++){
  99908. int quantized=vorbis_dBquant(flr+i);
  99909. if(quantized){
  99910. if(mdct[i]+info->twofitatten>=flr[i]){
  99911. xa += i;
  99912. ya += quantized;
  99913. x2a += i*i;
  99914. y2a += quantized*quantized;
  99915. xya += i*quantized;
  99916. na++;
  99917. }else{
  99918. xb += i;
  99919. yb += quantized;
  99920. x2b += i*i;
  99921. y2b += quantized*quantized;
  99922. xyb += i*quantized;
  99923. nb++;
  99924. }
  99925. }
  99926. }
  99927. xb+=xa;
  99928. yb+=ya;
  99929. x2b+=x2a;
  99930. y2b+=y2a;
  99931. xyb+=xya;
  99932. nb+=na;
  99933. {
  99934. int weight=nb*info->twofitweight/(na+1);
  99935. a->xa=xa*weight+xb;
  99936. a->ya=ya*weight+yb;
  99937. a->x2a=x2a*weight+x2b;
  99938. a->y2a=y2a*weight+y2b;
  99939. a->xya=xya*weight+xyb;
  99940. a->an=na*weight+nb;
  99941. }
  99942. return(na);
  99943. }
  99944. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99945. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99946. long x0=a[0].x0;
  99947. long x1=a[fits-1].x1;
  99948. for(i=0;i<fits;i++){
  99949. x+=a[i].xa;
  99950. y+=a[i].ya;
  99951. x2+=a[i].x2a;
  99952. y2+=a[i].y2a;
  99953. xy+=a[i].xya;
  99954. an+=a[i].an;
  99955. }
  99956. if(*y0>=0){
  99957. x+= x0;
  99958. y+= *y0;
  99959. x2+= x0 * x0;
  99960. y2+= *y0 * *y0;
  99961. xy+= *y0 * x0;
  99962. an++;
  99963. }
  99964. if(*y1>=0){
  99965. x+= x1;
  99966. y+= *y1;
  99967. x2+= x1 * x1;
  99968. y2+= *y1 * *y1;
  99969. xy+= *y1 * x1;
  99970. an++;
  99971. }
  99972. if(an){
  99973. double fx=x;
  99974. double fy=y;
  99975. double fx2=x2;
  99976. double fxy=xy;
  99977. double denom=1./(an*fx2-fx*fx);
  99978. double a=(fy*fx2-fxy*fx)*denom;
  99979. double b=(an*fxy-fx*fy)*denom;
  99980. *y0=rint(a+b*x0);
  99981. *y1=rint(a+b*x1);
  99982. if(*y0>1023)*y0=1023;
  99983. if(*y1>1023)*y1=1023;
  99984. if(*y0<0)*y0=0;
  99985. if(*y1<0)*y1=0;
  99986. }else{
  99987. *y0=0;
  99988. *y1=0;
  99989. }
  99990. }
  99991. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99992. const float *mdct,
  99993. vorbis_info_floor1 *info){
  99994. int dy=y1-y0;
  99995. int adx=x1-x0;
  99996. int ady=abs(dy);
  99997. int base=dy/adx;
  99998. int sy=(dy<0?base-1:base+1);
  99999. int x=x0;
  100000. int y=y0;
  100001. int err=0;
  100002. int val=vorbis_dBquant(mask+x);
  100003. int mse=0;
  100004. int n=0;
  100005. ady-=abs(base*adx);
  100006. mse=(y-val);
  100007. mse*=mse;
  100008. n++;
  100009. if(mdct[x]+info->twofitatten>=mask[x]){
  100010. if(y+info->maxover<val)return(1);
  100011. if(y-info->maxunder>val)return(1);
  100012. }
  100013. while(++x<x1){
  100014. err=err+ady;
  100015. if(err>=adx){
  100016. err-=adx;
  100017. y+=sy;
  100018. }else{
  100019. y+=base;
  100020. }
  100021. val=vorbis_dBquant(mask+x);
  100022. mse+=((y-val)*(y-val));
  100023. n++;
  100024. if(mdct[x]+info->twofitatten>=mask[x]){
  100025. if(val){
  100026. if(y+info->maxover<val)return(1);
  100027. if(y-info->maxunder>val)return(1);
  100028. }
  100029. }
  100030. }
  100031. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  100032. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  100033. if(mse/n>info->maxerr)return(1);
  100034. return(0);
  100035. }
  100036. static int post_Y(int *A,int *B,int pos){
  100037. if(A[pos]<0)
  100038. return B[pos];
  100039. if(B[pos]<0)
  100040. return A[pos];
  100041. return (A[pos]+B[pos])>>1;
  100042. }
  100043. int *floor1_fit(vorbis_block *vb,void *look_,
  100044. const float *logmdct, /* in */
  100045. const float *logmask){
  100046. long i,j;
  100047. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  100048. vorbis_info_floor1 *info=look->vi;
  100049. long n=look->n;
  100050. long posts=look->posts;
  100051. long nonzero=0;
  100052. lsfit_acc fits[VIF_POSIT+1];
  100053. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  100054. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  100055. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  100056. int hineighbor[VIF_POSIT+2];
  100057. int *output=NULL;
  100058. int memo[VIF_POSIT+2];
  100059. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  100060. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  100061. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  100062. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  100063. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  100064. if(posts==0){
  100065. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  100066. }else{
  100067. for(i=0;i<posts-1;i++)
  100068. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  100069. look->sorted_index[i+1],fits+i,
  100070. n,info);
  100071. }
  100072. if(nonzero){
  100073. int y0=-200;
  100074. int y1=-200;
  100075. fit_line(fits,posts-1,&y0,&y1);
  100076. fit_valueA[0]=y0;
  100077. fit_valueB[0]=y0;
  100078. fit_valueB[1]=y1;
  100079. fit_valueA[1]=y1;
  100080. for(i=2;i<posts;i++){
  100081. int sortpos=look->reverse_index[i];
  100082. int ln=loneighbor[sortpos];
  100083. int hn=hineighbor[sortpos];
  100084. if(memo[ln]!=hn){
  100085. int lsortpos=look->reverse_index[ln];
  100086. int hsortpos=look->reverse_index[hn];
  100087. memo[ln]=hn;
  100088. {
  100089. int lx=info->postlist[ln];
  100090. int hx=info->postlist[hn];
  100091. int ly=post_Y(fit_valueA,fit_valueB,ln);
  100092. int hy=post_Y(fit_valueA,fit_valueB,hn);
  100093. if(ly==-1 || hy==-1){
  100094. exit(1);
  100095. }
  100096. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  100097. int ly0=-200;
  100098. int ly1=-200;
  100099. int hy0=-200;
  100100. int hy1=-200;
  100101. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  100102. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  100103. fit_valueB[ln]=ly0;
  100104. if(ln==0)fit_valueA[ln]=ly0;
  100105. fit_valueA[i]=ly1;
  100106. fit_valueB[i]=hy0;
  100107. fit_valueA[hn]=hy1;
  100108. if(hn==1)fit_valueB[hn]=hy1;
  100109. if(ly1>=0 || hy0>=0){
  100110. for(j=sortpos-1;j>=0;j--)
  100111. if(hineighbor[j]==hn)
  100112. hineighbor[j]=i;
  100113. else
  100114. break;
  100115. for(j=sortpos+1;j<posts;j++)
  100116. if(loneighbor[j]==ln)
  100117. loneighbor[j]=i;
  100118. else
  100119. break;
  100120. }
  100121. }else{
  100122. fit_valueA[i]=-200;
  100123. fit_valueB[i]=-200;
  100124. }
  100125. }
  100126. }
  100127. }
  100128. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100129. output[0]=post_Y(fit_valueA,fit_valueB,0);
  100130. output[1]=post_Y(fit_valueA,fit_valueB,1);
  100131. for(i=2;i<posts;i++){
  100132. int ln=look->loneighbor[i-2];
  100133. int hn=look->hineighbor[i-2];
  100134. int x0=info->postlist[ln];
  100135. int x1=info->postlist[hn];
  100136. int y0=output[ln];
  100137. int y1=output[hn];
  100138. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100139. int vx=post_Y(fit_valueA,fit_valueB,i);
  100140. if(vx>=0 && predicted!=vx){
  100141. output[i]=vx;
  100142. }else{
  100143. output[i]= predicted|0x8000;
  100144. }
  100145. }
  100146. }
  100147. return(output);
  100148. }
  100149. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  100150. int *A,int *B,
  100151. int del){
  100152. long i;
  100153. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  100154. long posts=look->posts;
  100155. int *output=NULL;
  100156. if(A && B){
  100157. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100158. for(i=0;i<posts;i++){
  100159. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  100160. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  100161. }
  100162. }
  100163. return(output);
  100164. }
  100165. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  100166. void*look_,
  100167. int *post,int *ilogmask){
  100168. long i,j;
  100169. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  100170. vorbis_info_floor1 *info=look->vi;
  100171. long posts=look->posts;
  100172. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100173. int out[VIF_POSIT+2];
  100174. static_codebook **sbooks=ci->book_param;
  100175. codebook *books=ci->fullbooks;
  100176. static long seq=0;
  100177. if(post){
  100178. for(i=0;i<posts;i++){
  100179. int val=post[i]&0x7fff;
  100180. switch(info->mult){
  100181. case 1: /* 1024 -> 256 */
  100182. val>>=2;
  100183. break;
  100184. case 2: /* 1024 -> 128 */
  100185. val>>=3;
  100186. break;
  100187. case 3: /* 1024 -> 86 */
  100188. val/=12;
  100189. break;
  100190. case 4: /* 1024 -> 64 */
  100191. val>>=4;
  100192. break;
  100193. }
  100194. post[i]=val | (post[i]&0x8000);
  100195. }
  100196. out[0]=post[0];
  100197. out[1]=post[1];
  100198. for(i=2;i<posts;i++){
  100199. int ln=look->loneighbor[i-2];
  100200. int hn=look->hineighbor[i-2];
  100201. int x0=info->postlist[ln];
  100202. int x1=info->postlist[hn];
  100203. int y0=post[ln];
  100204. int y1=post[hn];
  100205. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100206. if((post[i]&0x8000) || (predicted==post[i])){
  100207. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  100208. in interpolation */
  100209. out[i]=0;
  100210. }else{
  100211. int headroom=(look->quant_q-predicted<predicted?
  100212. look->quant_q-predicted:predicted);
  100213. int val=post[i]-predicted;
  100214. if(val<0)
  100215. if(val<-headroom)
  100216. val=headroom-val-1;
  100217. else
  100218. val=-1-(val<<1);
  100219. else
  100220. if(val>=headroom)
  100221. val= val+headroom;
  100222. else
  100223. val<<=1;
  100224. out[i]=val;
  100225. post[ln]&=0x7fff;
  100226. post[hn]&=0x7fff;
  100227. }
  100228. }
  100229. oggpack_write(opb,1,1);
  100230. look->frames++;
  100231. look->postbits+=ilog(look->quant_q-1)*2;
  100232. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  100233. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  100234. for(i=0,j=2;i<info->partitions;i++){
  100235. int classx=info->partitionclass[i];
  100236. int cdim=info->class_dim[classx];
  100237. int csubbits=info->class_subs[classx];
  100238. int csub=1<<csubbits;
  100239. int bookas[8]={0,0,0,0,0,0,0,0};
  100240. int cval=0;
  100241. int cshift=0;
  100242. int k,l;
  100243. if(csubbits){
  100244. int maxval[8];
  100245. for(k=0;k<csub;k++){
  100246. int booknum=info->class_subbook[classx][k];
  100247. if(booknum<0){
  100248. maxval[k]=1;
  100249. }else{
  100250. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  100251. }
  100252. }
  100253. for(k=0;k<cdim;k++){
  100254. for(l=0;l<csub;l++){
  100255. int val=out[j+k];
  100256. if(val<maxval[l]){
  100257. bookas[k]=l;
  100258. break;
  100259. }
  100260. }
  100261. cval|= bookas[k]<<cshift;
  100262. cshift+=csubbits;
  100263. }
  100264. look->phrasebits+=
  100265. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  100266. #ifdef TRAIN_FLOOR1
  100267. {
  100268. FILE *of;
  100269. char buffer[80];
  100270. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  100271. vb->pcmend/2,posts-2,class);
  100272. of=fopen(buffer,"a");
  100273. fprintf(of,"%d\n",cval);
  100274. fclose(of);
  100275. }
  100276. #endif
  100277. }
  100278. for(k=0;k<cdim;k++){
  100279. int book=info->class_subbook[classx][bookas[k]];
  100280. if(book>=0){
  100281. if(out[j+k]<(books+book)->entries)
  100282. look->postbits+=vorbis_book_encode(books+book,
  100283. out[j+k],opb);
  100284. #ifdef TRAIN_FLOOR1
  100285. {
  100286. FILE *of;
  100287. char buffer[80];
  100288. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  100289. vb->pcmend/2,posts-2,class,bookas[k]);
  100290. of=fopen(buffer,"a");
  100291. fprintf(of,"%d\n",out[j+k]);
  100292. fclose(of);
  100293. }
  100294. #endif
  100295. }
  100296. }
  100297. j+=cdim;
  100298. }
  100299. {
  100300. int hx=0;
  100301. int lx=0;
  100302. int ly=post[0]*info->mult;
  100303. for(j=1;j<look->posts;j++){
  100304. int current=look->forward_index[j];
  100305. int hy=post[current]&0x7fff;
  100306. if(hy==post[current]){
  100307. hy*=info->mult;
  100308. hx=info->postlist[current];
  100309. render_line0(lx,hx,ly,hy,ilogmask);
  100310. lx=hx;
  100311. ly=hy;
  100312. }
  100313. }
  100314. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  100315. seq++;
  100316. return(1);
  100317. }
  100318. }else{
  100319. oggpack_write(opb,0,1);
  100320. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  100321. seq++;
  100322. return(0);
  100323. }
  100324. }
  100325. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  100326. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100327. vorbis_info_floor1 *info=look->vi;
  100328. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100329. int i,j,k;
  100330. codebook *books=ci->fullbooks;
  100331. if(oggpack_read(&vb->opb,1)==1){
  100332. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  100333. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100334. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100335. for(i=0,j=2;i<info->partitions;i++){
  100336. int classx=info->partitionclass[i];
  100337. int cdim=info->class_dim[classx];
  100338. int csubbits=info->class_subs[classx];
  100339. int csub=1<<csubbits;
  100340. int cval=0;
  100341. if(csubbits){
  100342. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  100343. if(cval==-1)goto eop;
  100344. }
  100345. for(k=0;k<cdim;k++){
  100346. int book=info->class_subbook[classx][cval&(csub-1)];
  100347. cval>>=csubbits;
  100348. if(book>=0){
  100349. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  100350. goto eop;
  100351. }else{
  100352. fit_value[j+k]=0;
  100353. }
  100354. }
  100355. j+=cdim;
  100356. }
  100357. for(i=2;i<look->posts;i++){
  100358. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  100359. info->postlist[look->hineighbor[i-2]],
  100360. fit_value[look->loneighbor[i-2]],
  100361. fit_value[look->hineighbor[i-2]],
  100362. info->postlist[i]);
  100363. int hiroom=look->quant_q-predicted;
  100364. int loroom=predicted;
  100365. int room=(hiroom<loroom?hiroom:loroom)<<1;
  100366. int val=fit_value[i];
  100367. if(val){
  100368. if(val>=room){
  100369. if(hiroom>loroom){
  100370. val = val-loroom;
  100371. }else{
  100372. val = -1-(val-hiroom);
  100373. }
  100374. }else{
  100375. if(val&1){
  100376. val= -((val+1)>>1);
  100377. }else{
  100378. val>>=1;
  100379. }
  100380. }
  100381. fit_value[i]=val+predicted;
  100382. fit_value[look->loneighbor[i-2]]&=0x7fff;
  100383. fit_value[look->hineighbor[i-2]]&=0x7fff;
  100384. }else{
  100385. fit_value[i]=predicted|0x8000;
  100386. }
  100387. }
  100388. return(fit_value);
  100389. }
  100390. eop:
  100391. return(NULL);
  100392. }
  100393. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  100394. float *out){
  100395. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100396. vorbis_info_floor1 *info=look->vi;
  100397. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100398. int n=ci->blocksizes[vb->W]/2;
  100399. int j;
  100400. if(memo){
  100401. int *fit_value=(int *)memo;
  100402. int hx=0;
  100403. int lx=0;
  100404. int ly=fit_value[0]*info->mult;
  100405. for(j=1;j<look->posts;j++){
  100406. int current=look->forward_index[j];
  100407. int hy=fit_value[current]&0x7fff;
  100408. if(hy==fit_value[current]){
  100409. hy*=info->mult;
  100410. hx=info->postlist[current];
  100411. render_line(lx,hx,ly,hy,out);
  100412. lx=hx;
  100413. ly=hy;
  100414. }
  100415. }
  100416. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  100417. return(1);
  100418. }
  100419. memset(out,0,sizeof(*out)*n);
  100420. return(0);
  100421. }
  100422. vorbis_func_floor floor1_exportbundle={
  100423. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  100424. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  100425. };
  100426. #endif
  100427. /*** End of inlined file: floor1.c ***/
  100428. /*** Start of inlined file: info.c ***/
  100429. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100430. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100431. // tasks..
  100432. #if JUCE_MSVC
  100433. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100434. #endif
  100435. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100436. #if JUCE_USE_OGGVORBIS
  100437. #include <stdlib.h>
  100438. #include <string.h>
  100439. #include <ctype.h>
  100440. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  100441. while(bytes--){
  100442. oggpack_write(o,*s++,8);
  100443. }
  100444. }
  100445. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  100446. while(bytes--){
  100447. *buf++=oggpack_read(o,8);
  100448. }
  100449. }
  100450. void vorbis_comment_init(vorbis_comment *vc){
  100451. memset(vc,0,sizeof(*vc));
  100452. }
  100453. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  100454. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  100455. (vc->comments+2)*sizeof(*vc->user_comments));
  100456. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  100457. (vc->comments+2)*sizeof(*vc->comment_lengths));
  100458. vc->comment_lengths[vc->comments]=strlen(comment);
  100459. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  100460. strcpy(vc->user_comments[vc->comments], comment);
  100461. vc->comments++;
  100462. vc->user_comments[vc->comments]=NULL;
  100463. }
  100464. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  100465. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  100466. strcpy(comment, tag);
  100467. strcat(comment, "=");
  100468. strcat(comment, contents);
  100469. vorbis_comment_add(vc, comment);
  100470. }
  100471. static int tagcompare(const char *s1, const char *s2, int n){
  100472. int c=0;
  100473. while(c < n){
  100474. if(toupper(s1[c]) != toupper(s2[c]))
  100475. return !0;
  100476. c++;
  100477. }
  100478. return 0;
  100479. }
  100480. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  100481. long i;
  100482. int found = 0;
  100483. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100484. char *fulltag = (char*)alloca(taglen+ 1);
  100485. strcpy(fulltag, tag);
  100486. strcat(fulltag, "=");
  100487. for(i=0;i<vc->comments;i++){
  100488. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  100489. if(count == found)
  100490. return vc->user_comments[i] + taglen;
  100491. else
  100492. found++;
  100493. }
  100494. }
  100495. return NULL; /* didn't find anything */
  100496. }
  100497. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  100498. int i,count=0;
  100499. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100500. char *fulltag = (char*)alloca(taglen+1);
  100501. strcpy(fulltag,tag);
  100502. strcat(fulltag, "=");
  100503. for(i=0;i<vc->comments;i++){
  100504. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  100505. count++;
  100506. }
  100507. return count;
  100508. }
  100509. void vorbis_comment_clear(vorbis_comment *vc){
  100510. if(vc){
  100511. long i;
  100512. for(i=0;i<vc->comments;i++)
  100513. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  100514. if(vc->user_comments)_ogg_free(vc->user_comments);
  100515. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  100516. if(vc->vendor)_ogg_free(vc->vendor);
  100517. }
  100518. memset(vc,0,sizeof(*vc));
  100519. }
  100520. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  100521. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  100522. return ci ? ci->blocksizes[zo] : -1;
  100523. }
  100524. void vorbis_info_init(vorbis_info *vi){
  100525. memset(vi,0,sizeof(*vi));
  100526. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100527. }
  100528. void vorbis_info_clear(vorbis_info *vi){
  100529. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100530. int i;
  100531. if(ci){
  100532. for(i=0;i<ci->modes;i++)
  100533. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100534. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100535. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100536. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100537. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100538. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100539. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100540. for(i=0;i<ci->books;i++){
  100541. if(ci->book_param[i]){
  100542. vorbis_staticbook_destroy(ci->book_param[i]);
  100543. }
  100544. if(ci->fullbooks)
  100545. vorbis_book_clear(ci->fullbooks+i);
  100546. }
  100547. if(ci->fullbooks)
  100548. _ogg_free(ci->fullbooks);
  100549. for(i=0;i<ci->psys;i++)
  100550. _vi_psy_free(ci->psy_param[i]);
  100551. _ogg_free(ci);
  100552. }
  100553. memset(vi,0,sizeof(*vi));
  100554. }
  100555. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100556. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100557. if(!ci)return(OV_EFAULT);
  100558. vi->version=oggpack_read(opb,32);
  100559. if(vi->version!=0)return(OV_EVERSION);
  100560. vi->channels=oggpack_read(opb,8);
  100561. vi->rate=oggpack_read(opb,32);
  100562. vi->bitrate_upper=oggpack_read(opb,32);
  100563. vi->bitrate_nominal=oggpack_read(opb,32);
  100564. vi->bitrate_lower=oggpack_read(opb,32);
  100565. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100566. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100567. if(vi->rate<1)goto err_out;
  100568. if(vi->channels<1)goto err_out;
  100569. if(ci->blocksizes[0]<8)goto err_out;
  100570. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100571. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100572. return(0);
  100573. err_out:
  100574. vorbis_info_clear(vi);
  100575. return(OV_EBADHEADER);
  100576. }
  100577. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100578. int i;
  100579. int vendorlen=oggpack_read(opb,32);
  100580. if(vendorlen<0)goto err_out;
  100581. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100582. _v_readstring(opb,vc->vendor,vendorlen);
  100583. vc->comments=oggpack_read(opb,32);
  100584. if(vc->comments<0)goto err_out;
  100585. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100586. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100587. for(i=0;i<vc->comments;i++){
  100588. int len=oggpack_read(opb,32);
  100589. if(len<0)goto err_out;
  100590. vc->comment_lengths[i]=len;
  100591. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100592. _v_readstring(opb,vc->user_comments[i],len);
  100593. }
  100594. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100595. return(0);
  100596. err_out:
  100597. vorbis_comment_clear(vc);
  100598. return(OV_EBADHEADER);
  100599. }
  100600. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100601. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100602. int i;
  100603. if(!ci)return(OV_EFAULT);
  100604. ci->books=oggpack_read(opb,8)+1;
  100605. for(i=0;i<ci->books;i++){
  100606. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100607. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100608. }
  100609. {
  100610. int times=oggpack_read(opb,6)+1;
  100611. for(i=0;i<times;i++){
  100612. int test=oggpack_read(opb,16);
  100613. if(test<0 || test>=VI_TIMEB)goto err_out;
  100614. }
  100615. }
  100616. ci->floors=oggpack_read(opb,6)+1;
  100617. for(i=0;i<ci->floors;i++){
  100618. ci->floor_type[i]=oggpack_read(opb,16);
  100619. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100620. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100621. if(!ci->floor_param[i])goto err_out;
  100622. }
  100623. ci->residues=oggpack_read(opb,6)+1;
  100624. for(i=0;i<ci->residues;i++){
  100625. ci->residue_type[i]=oggpack_read(opb,16);
  100626. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100627. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100628. if(!ci->residue_param[i])goto err_out;
  100629. }
  100630. ci->maps=oggpack_read(opb,6)+1;
  100631. for(i=0;i<ci->maps;i++){
  100632. ci->map_type[i]=oggpack_read(opb,16);
  100633. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100634. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100635. if(!ci->map_param[i])goto err_out;
  100636. }
  100637. ci->modes=oggpack_read(opb,6)+1;
  100638. for(i=0;i<ci->modes;i++){
  100639. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100640. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100641. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100642. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100643. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100644. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100645. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100646. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100647. }
  100648. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100649. return(0);
  100650. err_out:
  100651. vorbis_info_clear(vi);
  100652. return(OV_EBADHEADER);
  100653. }
  100654. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100655. oggpack_buffer opb;
  100656. if(op){
  100657. oggpack_readinit(&opb,op->packet,op->bytes);
  100658. {
  100659. char buffer[6];
  100660. int packtype=oggpack_read(&opb,8);
  100661. memset(buffer,0,6);
  100662. _v_readstring(&opb,buffer,6);
  100663. if(memcmp(buffer,"vorbis",6)){
  100664. return(OV_ENOTVORBIS);
  100665. }
  100666. switch(packtype){
  100667. case 0x01: /* least significant *bit* is read first */
  100668. if(!op->b_o_s){
  100669. return(OV_EBADHEADER);
  100670. }
  100671. if(vi->rate!=0){
  100672. return(OV_EBADHEADER);
  100673. }
  100674. return(_vorbis_unpack_info(vi,&opb));
  100675. case 0x03: /* least significant *bit* is read first */
  100676. if(vi->rate==0){
  100677. return(OV_EBADHEADER);
  100678. }
  100679. return(_vorbis_unpack_comment(vc,&opb));
  100680. case 0x05: /* least significant *bit* is read first */
  100681. if(vi->rate==0 || vc->vendor==NULL){
  100682. return(OV_EBADHEADER);
  100683. }
  100684. return(_vorbis_unpack_books(vi,&opb));
  100685. default:
  100686. return(OV_EBADHEADER);
  100687. break;
  100688. }
  100689. }
  100690. }
  100691. return(OV_EBADHEADER);
  100692. }
  100693. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100694. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100695. if(!ci)return(OV_EFAULT);
  100696. oggpack_write(opb,0x01,8);
  100697. _v_writestring(opb,"vorbis", 6);
  100698. oggpack_write(opb,0x00,32);
  100699. oggpack_write(opb,vi->channels,8);
  100700. oggpack_write(opb,vi->rate,32);
  100701. oggpack_write(opb,vi->bitrate_upper,32);
  100702. oggpack_write(opb,vi->bitrate_nominal,32);
  100703. oggpack_write(opb,vi->bitrate_lower,32);
  100704. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100705. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100706. oggpack_write(opb,1,1);
  100707. return(0);
  100708. }
  100709. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100710. char temp[]="Xiph.Org libVorbis I 20050304";
  100711. int bytes = strlen(temp);
  100712. oggpack_write(opb,0x03,8);
  100713. _v_writestring(opb,"vorbis", 6);
  100714. oggpack_write(opb,bytes,32);
  100715. _v_writestring(opb,temp, bytes);
  100716. oggpack_write(opb,vc->comments,32);
  100717. if(vc->comments){
  100718. int i;
  100719. for(i=0;i<vc->comments;i++){
  100720. if(vc->user_comments[i]){
  100721. oggpack_write(opb,vc->comment_lengths[i],32);
  100722. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100723. }else{
  100724. oggpack_write(opb,0,32);
  100725. }
  100726. }
  100727. }
  100728. oggpack_write(opb,1,1);
  100729. return(0);
  100730. }
  100731. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100732. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100733. int i;
  100734. if(!ci)return(OV_EFAULT);
  100735. oggpack_write(opb,0x05,8);
  100736. _v_writestring(opb,"vorbis", 6);
  100737. oggpack_write(opb,ci->books-1,8);
  100738. for(i=0;i<ci->books;i++)
  100739. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100740. oggpack_write(opb,0,6);
  100741. oggpack_write(opb,0,16);
  100742. oggpack_write(opb,ci->floors-1,6);
  100743. for(i=0;i<ci->floors;i++){
  100744. oggpack_write(opb,ci->floor_type[i],16);
  100745. if(_floor_P[ci->floor_type[i]]->pack)
  100746. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100747. else
  100748. goto err_out;
  100749. }
  100750. oggpack_write(opb,ci->residues-1,6);
  100751. for(i=0;i<ci->residues;i++){
  100752. oggpack_write(opb,ci->residue_type[i],16);
  100753. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100754. }
  100755. oggpack_write(opb,ci->maps-1,6);
  100756. for(i=0;i<ci->maps;i++){
  100757. oggpack_write(opb,ci->map_type[i],16);
  100758. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100759. }
  100760. oggpack_write(opb,ci->modes-1,6);
  100761. for(i=0;i<ci->modes;i++){
  100762. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100763. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100764. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100765. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100766. }
  100767. oggpack_write(opb,1,1);
  100768. return(0);
  100769. err_out:
  100770. return(-1);
  100771. }
  100772. int vorbis_commentheader_out(vorbis_comment *vc,
  100773. ogg_packet *op){
  100774. oggpack_buffer opb;
  100775. oggpack_writeinit(&opb);
  100776. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100777. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100778. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100779. op->bytes=oggpack_bytes(&opb);
  100780. op->b_o_s=0;
  100781. op->e_o_s=0;
  100782. op->granulepos=0;
  100783. op->packetno=1;
  100784. return 0;
  100785. }
  100786. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100787. vorbis_comment *vc,
  100788. ogg_packet *op,
  100789. ogg_packet *op_comm,
  100790. ogg_packet *op_code){
  100791. int ret=OV_EIMPL;
  100792. vorbis_info *vi=v->vi;
  100793. oggpack_buffer opb;
  100794. private_state *b=(private_state*)v->backend_state;
  100795. if(!b){
  100796. ret=OV_EFAULT;
  100797. goto err_out;
  100798. }
  100799. oggpack_writeinit(&opb);
  100800. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100801. if(b->header)_ogg_free(b->header);
  100802. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100803. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100804. op->packet=b->header;
  100805. op->bytes=oggpack_bytes(&opb);
  100806. op->b_o_s=1;
  100807. op->e_o_s=0;
  100808. op->granulepos=0;
  100809. op->packetno=0;
  100810. oggpack_reset(&opb);
  100811. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100812. if(b->header1)_ogg_free(b->header1);
  100813. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100814. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100815. op_comm->packet=b->header1;
  100816. op_comm->bytes=oggpack_bytes(&opb);
  100817. op_comm->b_o_s=0;
  100818. op_comm->e_o_s=0;
  100819. op_comm->granulepos=0;
  100820. op_comm->packetno=1;
  100821. oggpack_reset(&opb);
  100822. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100823. if(b->header2)_ogg_free(b->header2);
  100824. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100825. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100826. op_code->packet=b->header2;
  100827. op_code->bytes=oggpack_bytes(&opb);
  100828. op_code->b_o_s=0;
  100829. op_code->e_o_s=0;
  100830. op_code->granulepos=0;
  100831. op_code->packetno=2;
  100832. oggpack_writeclear(&opb);
  100833. return(0);
  100834. err_out:
  100835. oggpack_writeclear(&opb);
  100836. memset(op,0,sizeof(*op));
  100837. memset(op_comm,0,sizeof(*op_comm));
  100838. memset(op_code,0,sizeof(*op_code));
  100839. if(b->header)_ogg_free(b->header);
  100840. if(b->header1)_ogg_free(b->header1);
  100841. if(b->header2)_ogg_free(b->header2);
  100842. b->header=NULL;
  100843. b->header1=NULL;
  100844. b->header2=NULL;
  100845. return(ret);
  100846. }
  100847. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100848. if(granulepos>=0)
  100849. return((double)granulepos/v->vi->rate);
  100850. return(-1);
  100851. }
  100852. #endif
  100853. /*** End of inlined file: info.c ***/
  100854. /*** Start of inlined file: lpc.c ***/
  100855. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100856. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100857. // tasks..
  100858. #if JUCE_MSVC
  100859. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100860. #endif
  100861. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100862. #if JUCE_USE_OGGVORBIS
  100863. #include <stdlib.h>
  100864. #include <string.h>
  100865. #include <math.h>
  100866. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100867. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100868. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100869. double error;
  100870. int i,j;
  100871. j=m+1;
  100872. while(j--){
  100873. double d=0; /* double needed for accumulator depth */
  100874. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100875. aut[j]=d;
  100876. }
  100877. error=aut[0];
  100878. for(i=0;i<m;i++){
  100879. double r= -aut[i+1];
  100880. if(error==0){
  100881. memset(lpci,0,m*sizeof(*lpci));
  100882. return 0;
  100883. }
  100884. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100885. r/=error;
  100886. lpc[i]=r;
  100887. for(j=0;j<i/2;j++){
  100888. double tmp=lpc[j];
  100889. lpc[j]+=r*lpc[i-1-j];
  100890. lpc[i-1-j]+=r*tmp;
  100891. }
  100892. if(i%2)lpc[j]+=lpc[j]*r;
  100893. error*=1.f-r*r;
  100894. }
  100895. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100896. return error;
  100897. }
  100898. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100899. float *data,long n){
  100900. long i,j,o,p;
  100901. float y;
  100902. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100903. if(!prime)
  100904. for(i=0;i<m;i++)
  100905. work[i]=0.f;
  100906. else
  100907. for(i=0;i<m;i++)
  100908. work[i]=prime[i];
  100909. for(i=0;i<n;i++){
  100910. y=0;
  100911. o=i;
  100912. p=m;
  100913. for(j=0;j<m;j++)
  100914. y-=work[o++]*coeff[--p];
  100915. data[i]=work[o]=y;
  100916. }
  100917. }
  100918. #endif
  100919. /*** End of inlined file: lpc.c ***/
  100920. /*** Start of inlined file: lsp.c ***/
  100921. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100922. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100923. // tasks..
  100924. #if JUCE_MSVC
  100925. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100926. #endif
  100927. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100928. #if JUCE_USE_OGGVORBIS
  100929. #include <math.h>
  100930. #include <string.h>
  100931. #include <stdlib.h>
  100932. /*** Start of inlined file: lookup.h ***/
  100933. #ifndef _V_LOOKUP_H_
  100934. #ifdef FLOAT_LOOKUP
  100935. extern float vorbis_coslook(float a);
  100936. extern float vorbis_invsqlook(float a);
  100937. extern float vorbis_invsq2explook(int a);
  100938. extern float vorbis_fromdBlook(float a);
  100939. #endif
  100940. #ifdef INT_LOOKUP
  100941. extern long vorbis_invsqlook_i(long a,long e);
  100942. extern long vorbis_coslook_i(long a);
  100943. extern float vorbis_fromdBlook_i(long a);
  100944. #endif
  100945. #endif
  100946. /*** End of inlined file: lookup.h ***/
  100947. #define FLOAT_LOOKUP
  100948. #undef INT_LOOKUP
  100949. #ifdef FLOAT_LOOKUP
  100950. /*** Start of inlined file: lookup.c ***/
  100951. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100952. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100953. // tasks..
  100954. #if JUCE_MSVC
  100955. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100956. #endif
  100957. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100958. #if JUCE_USE_OGGVORBIS
  100959. #include <math.h>
  100960. /*** Start of inlined file: lookup.h ***/
  100961. #ifndef _V_LOOKUP_H_
  100962. #ifdef FLOAT_LOOKUP
  100963. extern float vorbis_coslook(float a);
  100964. extern float vorbis_invsqlook(float a);
  100965. extern float vorbis_invsq2explook(int a);
  100966. extern float vorbis_fromdBlook(float a);
  100967. #endif
  100968. #ifdef INT_LOOKUP
  100969. extern long vorbis_invsqlook_i(long a,long e);
  100970. extern long vorbis_coslook_i(long a);
  100971. extern float vorbis_fromdBlook_i(long a);
  100972. #endif
  100973. #endif
  100974. /*** End of inlined file: lookup.h ***/
  100975. /*** Start of inlined file: lookup_data.h ***/
  100976. #ifndef _V_LOOKUP_DATA_H_
  100977. #ifdef FLOAT_LOOKUP
  100978. #define COS_LOOKUP_SZ 128
  100979. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100980. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100981. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100982. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100983. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100984. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100985. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100986. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100987. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100988. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100989. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100990. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100991. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100992. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100993. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100994. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100995. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100996. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100997. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100998. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100999. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  101000. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  101001. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  101002. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  101003. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  101004. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  101005. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  101006. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  101007. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  101008. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  101009. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  101010. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  101011. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  101012. -1.0000000000000f,
  101013. };
  101014. #define INVSQ_LOOKUP_SZ 32
  101015. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  101016. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  101017. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  101018. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  101019. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  101020. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  101021. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  101022. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  101023. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  101024. 1.000000000000f,
  101025. };
  101026. #define INVSQ2EXP_LOOKUP_MIN (-32)
  101027. #define INVSQ2EXP_LOOKUP_MAX 32
  101028. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  101029. INVSQ2EXP_LOOKUP_MIN+1]={
  101030. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  101031. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  101032. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  101033. 1024.f, 724.0773439f, 512.f, 362.038672f,
  101034. 256.f, 181.019336f, 128.f, 90.50966799f,
  101035. 64.f, 45.254834f, 32.f, 22.627417f,
  101036. 16.f, 11.3137085f, 8.f, 5.656854249f,
  101037. 4.f, 2.828427125f, 2.f, 1.414213562f,
  101038. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  101039. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  101040. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  101041. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  101042. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  101043. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  101044. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  101045. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  101046. 1.525878906e-05f,
  101047. };
  101048. #endif
  101049. #define FROMdB_LOOKUP_SZ 35
  101050. #define FROMdB2_LOOKUP_SZ 32
  101051. #define FROMdB_SHIFT 5
  101052. #define FROMdB2_SHIFT 3
  101053. #define FROMdB2_MASK 31
  101054. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  101055. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  101056. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  101057. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  101058. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  101059. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  101060. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  101061. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  101062. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  101063. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  101064. };
  101065. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  101066. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  101067. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  101068. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  101069. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  101070. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  101071. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  101072. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  101073. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  101074. };
  101075. #ifdef INT_LOOKUP
  101076. #define INVSQ_LOOKUP_I_SHIFT 10
  101077. #define INVSQ_LOOKUP_I_MASK 1023
  101078. static long INVSQ_LOOKUP_I[64+1]={
  101079. 92682l, 91966l, 91267l, 90583l,
  101080. 89915l, 89261l, 88621l, 87995l,
  101081. 87381l, 86781l, 86192l, 85616l,
  101082. 85051l, 84497l, 83953l, 83420l,
  101083. 82897l, 82384l, 81880l, 81385l,
  101084. 80899l, 80422l, 79953l, 79492l,
  101085. 79039l, 78594l, 78156l, 77726l,
  101086. 77302l, 76885l, 76475l, 76072l,
  101087. 75674l, 75283l, 74898l, 74519l,
  101088. 74146l, 73778l, 73415l, 73058l,
  101089. 72706l, 72359l, 72016l, 71679l,
  101090. 71347l, 71019l, 70695l, 70376l,
  101091. 70061l, 69750l, 69444l, 69141l,
  101092. 68842l, 68548l, 68256l, 67969l,
  101093. 67685l, 67405l, 67128l, 66855l,
  101094. 66585l, 66318l, 66054l, 65794l,
  101095. 65536l,
  101096. };
  101097. #define COS_LOOKUP_I_SHIFT 9
  101098. #define COS_LOOKUP_I_MASK 511
  101099. #define COS_LOOKUP_I_SZ 128
  101100. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101101. 16384l, 16379l, 16364l, 16340l,
  101102. 16305l, 16261l, 16207l, 16143l,
  101103. 16069l, 15986l, 15893l, 15791l,
  101104. 15679l, 15557l, 15426l, 15286l,
  101105. 15137l, 14978l, 14811l, 14635l,
  101106. 14449l, 14256l, 14053l, 13842l,
  101107. 13623l, 13395l, 13160l, 12916l,
  101108. 12665l, 12406l, 12140l, 11866l,
  101109. 11585l, 11297l, 11003l, 10702l,
  101110. 10394l, 10080l, 9760l, 9434l,
  101111. 9102l, 8765l, 8423l, 8076l,
  101112. 7723l, 7366l, 7005l, 6639l,
  101113. 6270l, 5897l, 5520l, 5139l,
  101114. 4756l, 4370l, 3981l, 3590l,
  101115. 3196l, 2801l, 2404l, 2006l,
  101116. 1606l, 1205l, 804l, 402l,
  101117. 0l, -401l, -803l, -1204l,
  101118. -1605l, -2005l, -2403l, -2800l,
  101119. -3195l, -3589l, -3980l, -4369l,
  101120. -4755l, -5138l, -5519l, -5896l,
  101121. -6269l, -6638l, -7004l, -7365l,
  101122. -7722l, -8075l, -8422l, -8764l,
  101123. -9101l, -9433l, -9759l, -10079l,
  101124. -10393l, -10701l, -11002l, -11296l,
  101125. -11584l, -11865l, -12139l, -12405l,
  101126. -12664l, -12915l, -13159l, -13394l,
  101127. -13622l, -13841l, -14052l, -14255l,
  101128. -14448l, -14634l, -14810l, -14977l,
  101129. -15136l, -15285l, -15425l, -15556l,
  101130. -15678l, -15790l, -15892l, -15985l,
  101131. -16068l, -16142l, -16206l, -16260l,
  101132. -16304l, -16339l, -16363l, -16378l,
  101133. -16383l,
  101134. };
  101135. #endif
  101136. #endif
  101137. /*** End of inlined file: lookup_data.h ***/
  101138. #ifdef FLOAT_LOOKUP
  101139. float vorbis_coslook(float a){
  101140. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101141. int i=vorbis_ftoi(d-.5);
  101142. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101143. }
  101144. float vorbis_invsqlook(float a){
  101145. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101146. int i=vorbis_ftoi(d-.5f);
  101147. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101148. }
  101149. float vorbis_invsq2explook(int a){
  101150. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101151. }
  101152. #include <stdio.h>
  101153. float vorbis_fromdBlook(float a){
  101154. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101155. return (i<0)?1.f:
  101156. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101157. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101158. }
  101159. #endif
  101160. #ifdef INT_LOOKUP
  101161. long vorbis_invsqlook_i(long a,long e){
  101162. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101163. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101164. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101165. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101166. d)>>16); /* result 1.16 */
  101167. e+=32;
  101168. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101169. e=(e>>1)-8;
  101170. return(val>>e);
  101171. }
  101172. float vorbis_fromdBlook_i(long a){
  101173. int i=(-a)>>(12-FROMdB2_SHIFT);
  101174. return (i<0)?1.f:
  101175. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101176. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101177. }
  101178. long vorbis_coslook_i(long a){
  101179. int i=a>>COS_LOOKUP_I_SHIFT;
  101180. int d=a&COS_LOOKUP_I_MASK;
  101181. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101182. COS_LOOKUP_I_SHIFT);
  101183. }
  101184. #endif
  101185. #endif
  101186. /*** End of inlined file: lookup.c ***/
  101187. /* catch this in the build system; we #include for
  101188. compilers (like gcc) that can't inline across
  101189. modules */
  101190. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101191. float amp,float ampoffset){
  101192. int i;
  101193. float wdel=M_PI/ln;
  101194. vorbis_fpu_control fpu;
  101195. (void) fpu; // to avoid an unused variable warning
  101196. vorbis_fpu_setround(&fpu);
  101197. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  101198. i=0;
  101199. while(i<n){
  101200. int k=map[i];
  101201. int qexp;
  101202. float p=.7071067812f;
  101203. float q=.7071067812f;
  101204. float w=vorbis_coslook(wdel*k);
  101205. float *ftmp=lsp;
  101206. int c=m>>1;
  101207. do{
  101208. q*=ftmp[0]-w;
  101209. p*=ftmp[1]-w;
  101210. ftmp+=2;
  101211. }while(--c);
  101212. if(m&1){
  101213. q*=ftmp[0]-w;
  101214. q*=q;
  101215. p*=p*(1.f-w*w);
  101216. }else{
  101217. q*=q*(1.f+w);
  101218. p*=p*(1.f-w);
  101219. }
  101220. q=frexp(p+q,&qexp);
  101221. q=vorbis_fromdBlook(amp*
  101222. vorbis_invsqlook(q)*
  101223. vorbis_invsq2explook(qexp+m)-
  101224. ampoffset);
  101225. do{
  101226. curve[i++]*=q;
  101227. }while(map[i]==k);
  101228. }
  101229. vorbis_fpu_restore(fpu);
  101230. }
  101231. #else
  101232. #ifdef INT_LOOKUP
  101233. /*** Start of inlined file: lookup.c ***/
  101234. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101235. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101236. // tasks..
  101237. #if JUCE_MSVC
  101238. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101239. #endif
  101240. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101241. #if JUCE_USE_OGGVORBIS
  101242. #include <math.h>
  101243. /*** Start of inlined file: lookup.h ***/
  101244. #ifndef _V_LOOKUP_H_
  101245. #ifdef FLOAT_LOOKUP
  101246. extern float vorbis_coslook(float a);
  101247. extern float vorbis_invsqlook(float a);
  101248. extern float vorbis_invsq2explook(int a);
  101249. extern float vorbis_fromdBlook(float a);
  101250. #endif
  101251. #ifdef INT_LOOKUP
  101252. extern long vorbis_invsqlook_i(long a,long e);
  101253. extern long vorbis_coslook_i(long a);
  101254. extern float vorbis_fromdBlook_i(long a);
  101255. #endif
  101256. #endif
  101257. /*** End of inlined file: lookup.h ***/
  101258. /*** Start of inlined file: lookup_data.h ***/
  101259. #ifndef _V_LOOKUP_DATA_H_
  101260. #ifdef FLOAT_LOOKUP
  101261. #define COS_LOOKUP_SZ 128
  101262. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  101263. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  101264. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  101265. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  101266. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  101267. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  101268. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  101269. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  101270. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  101271. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  101272. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  101273. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  101274. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  101275. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  101276. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  101277. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  101278. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  101279. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  101280. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  101281. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  101282. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  101283. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  101284. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  101285. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  101286. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  101287. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  101288. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  101289. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  101290. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  101291. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  101292. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  101293. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  101294. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  101295. -1.0000000000000f,
  101296. };
  101297. #define INVSQ_LOOKUP_SZ 32
  101298. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  101299. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  101300. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  101301. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  101302. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  101303. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  101304. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  101305. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  101306. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  101307. 1.000000000000f,
  101308. };
  101309. #define INVSQ2EXP_LOOKUP_MIN (-32)
  101310. #define INVSQ2EXP_LOOKUP_MAX 32
  101311. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  101312. INVSQ2EXP_LOOKUP_MIN+1]={
  101313. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  101314. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  101315. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  101316. 1024.f, 724.0773439f, 512.f, 362.038672f,
  101317. 256.f, 181.019336f, 128.f, 90.50966799f,
  101318. 64.f, 45.254834f, 32.f, 22.627417f,
  101319. 16.f, 11.3137085f, 8.f, 5.656854249f,
  101320. 4.f, 2.828427125f, 2.f, 1.414213562f,
  101321. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  101322. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  101323. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  101324. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  101325. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  101326. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  101327. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  101328. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  101329. 1.525878906e-05f,
  101330. };
  101331. #endif
  101332. #define FROMdB_LOOKUP_SZ 35
  101333. #define FROMdB2_LOOKUP_SZ 32
  101334. #define FROMdB_SHIFT 5
  101335. #define FROMdB2_SHIFT 3
  101336. #define FROMdB2_MASK 31
  101337. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  101338. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  101339. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  101340. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  101341. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  101342. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  101343. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  101344. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  101345. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  101346. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  101347. };
  101348. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  101349. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  101350. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  101351. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  101352. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  101353. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  101354. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  101355. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  101356. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  101357. };
  101358. #ifdef INT_LOOKUP
  101359. #define INVSQ_LOOKUP_I_SHIFT 10
  101360. #define INVSQ_LOOKUP_I_MASK 1023
  101361. static long INVSQ_LOOKUP_I[64+1]={
  101362. 92682l, 91966l, 91267l, 90583l,
  101363. 89915l, 89261l, 88621l, 87995l,
  101364. 87381l, 86781l, 86192l, 85616l,
  101365. 85051l, 84497l, 83953l, 83420l,
  101366. 82897l, 82384l, 81880l, 81385l,
  101367. 80899l, 80422l, 79953l, 79492l,
  101368. 79039l, 78594l, 78156l, 77726l,
  101369. 77302l, 76885l, 76475l, 76072l,
  101370. 75674l, 75283l, 74898l, 74519l,
  101371. 74146l, 73778l, 73415l, 73058l,
  101372. 72706l, 72359l, 72016l, 71679l,
  101373. 71347l, 71019l, 70695l, 70376l,
  101374. 70061l, 69750l, 69444l, 69141l,
  101375. 68842l, 68548l, 68256l, 67969l,
  101376. 67685l, 67405l, 67128l, 66855l,
  101377. 66585l, 66318l, 66054l, 65794l,
  101378. 65536l,
  101379. };
  101380. #define COS_LOOKUP_I_SHIFT 9
  101381. #define COS_LOOKUP_I_MASK 511
  101382. #define COS_LOOKUP_I_SZ 128
  101383. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101384. 16384l, 16379l, 16364l, 16340l,
  101385. 16305l, 16261l, 16207l, 16143l,
  101386. 16069l, 15986l, 15893l, 15791l,
  101387. 15679l, 15557l, 15426l, 15286l,
  101388. 15137l, 14978l, 14811l, 14635l,
  101389. 14449l, 14256l, 14053l, 13842l,
  101390. 13623l, 13395l, 13160l, 12916l,
  101391. 12665l, 12406l, 12140l, 11866l,
  101392. 11585l, 11297l, 11003l, 10702l,
  101393. 10394l, 10080l, 9760l, 9434l,
  101394. 9102l, 8765l, 8423l, 8076l,
  101395. 7723l, 7366l, 7005l, 6639l,
  101396. 6270l, 5897l, 5520l, 5139l,
  101397. 4756l, 4370l, 3981l, 3590l,
  101398. 3196l, 2801l, 2404l, 2006l,
  101399. 1606l, 1205l, 804l, 402l,
  101400. 0l, -401l, -803l, -1204l,
  101401. -1605l, -2005l, -2403l, -2800l,
  101402. -3195l, -3589l, -3980l, -4369l,
  101403. -4755l, -5138l, -5519l, -5896l,
  101404. -6269l, -6638l, -7004l, -7365l,
  101405. -7722l, -8075l, -8422l, -8764l,
  101406. -9101l, -9433l, -9759l, -10079l,
  101407. -10393l, -10701l, -11002l, -11296l,
  101408. -11584l, -11865l, -12139l, -12405l,
  101409. -12664l, -12915l, -13159l, -13394l,
  101410. -13622l, -13841l, -14052l, -14255l,
  101411. -14448l, -14634l, -14810l, -14977l,
  101412. -15136l, -15285l, -15425l, -15556l,
  101413. -15678l, -15790l, -15892l, -15985l,
  101414. -16068l, -16142l, -16206l, -16260l,
  101415. -16304l, -16339l, -16363l, -16378l,
  101416. -16383l,
  101417. };
  101418. #endif
  101419. #endif
  101420. /*** End of inlined file: lookup_data.h ***/
  101421. #ifdef FLOAT_LOOKUP
  101422. float vorbis_coslook(float a){
  101423. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101424. int i=vorbis_ftoi(d-.5);
  101425. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101426. }
  101427. float vorbis_invsqlook(float a){
  101428. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101429. int i=vorbis_ftoi(d-.5f);
  101430. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101431. }
  101432. float vorbis_invsq2explook(int a){
  101433. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101434. }
  101435. #include <stdio.h>
  101436. float vorbis_fromdBlook(float a){
  101437. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101438. return (i<0)?1.f:
  101439. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101440. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101441. }
  101442. #endif
  101443. #ifdef INT_LOOKUP
  101444. long vorbis_invsqlook_i(long a,long e){
  101445. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101446. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101447. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101448. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101449. d)>>16); /* result 1.16 */
  101450. e+=32;
  101451. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101452. e=(e>>1)-8;
  101453. return(val>>e);
  101454. }
  101455. float vorbis_fromdBlook_i(long a){
  101456. int i=(-a)>>(12-FROMdB2_SHIFT);
  101457. return (i<0)?1.f:
  101458. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101459. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101460. }
  101461. long vorbis_coslook_i(long a){
  101462. int i=a>>COS_LOOKUP_I_SHIFT;
  101463. int d=a&COS_LOOKUP_I_MASK;
  101464. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101465. COS_LOOKUP_I_SHIFT);
  101466. }
  101467. #endif
  101468. #endif
  101469. /*** End of inlined file: lookup.c ***/
  101470. /* catch this in the build system; we #include for
  101471. compilers (like gcc) that can't inline across
  101472. modules */
  101473. static int MLOOP_1[64]={
  101474. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  101475. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  101476. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101477. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101478. };
  101479. static int MLOOP_2[64]={
  101480. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  101481. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  101482. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101483. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101484. };
  101485. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  101486. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101487. float amp,float ampoffset){
  101488. int i;
  101489. int ampoffseti=rint(ampoffset*4096.f);
  101490. int ampi=rint(amp*16.f);
  101491. long *ilsp=alloca(m*sizeof(*ilsp));
  101492. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  101493. i=0;
  101494. while(i<n){
  101495. int j,k=map[i];
  101496. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  101497. unsigned long qi=46341;
  101498. int qexp=0,shift;
  101499. long wi=vorbis_coslook_i(k*65536/ln);
  101500. qi*=labs(ilsp[0]-wi);
  101501. pi*=labs(ilsp[1]-wi);
  101502. for(j=3;j<m;j+=2){
  101503. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101504. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101505. shift=MLOOP_3[(pi|qi)>>16];
  101506. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101507. pi=(pi>>shift)*labs(ilsp[j]-wi);
  101508. qexp+=shift;
  101509. }
  101510. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101511. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101512. shift=MLOOP_3[(pi|qi)>>16];
  101513. if(m&1){
  101514. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101515. pi=(pi>>shift)<<14;
  101516. qexp+=shift;
  101517. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101518. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101519. shift=MLOOP_3[(pi|qi)>>16];
  101520. pi>>=shift;
  101521. qi>>=shift;
  101522. qexp+=shift-14*((m+1)>>1);
  101523. pi=((pi*pi)>>16);
  101524. qi=((qi*qi)>>16);
  101525. qexp=qexp*2+m;
  101526. pi*=(1<<14)-((wi*wi)>>14);
  101527. qi+=pi>>14;
  101528. }else{
  101529. pi>>=shift;
  101530. qi>>=shift;
  101531. qexp+=shift-7*m;
  101532. pi=((pi*pi)>>16);
  101533. qi=((qi*qi)>>16);
  101534. qexp=qexp*2+m;
  101535. pi*=(1<<14)-wi;
  101536. qi*=(1<<14)+wi;
  101537. qi=(qi+pi)>>14;
  101538. }
  101539. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101540. qi>>=1; qexp++;
  101541. }else
  101542. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101543. qi<<=1; qexp--;
  101544. }
  101545. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101546. vorbis_invsqlook_i(qi,qexp)-
  101547. ampoffseti); /* 8.12[0] */
  101548. curve[i]*=amp;
  101549. while(map[++i]==k)curve[i]*=amp;
  101550. }
  101551. }
  101552. #else
  101553. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101554. float amp,float ampoffset){
  101555. int i;
  101556. float wdel=M_PI/ln;
  101557. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101558. i=0;
  101559. while(i<n){
  101560. int j,k=map[i];
  101561. float p=.5f;
  101562. float q=.5f;
  101563. float w=2.f*cos(wdel*k);
  101564. for(j=1;j<m;j+=2){
  101565. q *= w-lsp[j-1];
  101566. p *= w-lsp[j];
  101567. }
  101568. if(j==m){
  101569. q*=w-lsp[j-1];
  101570. p*=p*(4.f-w*w);
  101571. q*=q;
  101572. }else{
  101573. p*=p*(2.f-w);
  101574. q*=q*(2.f+w);
  101575. }
  101576. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101577. curve[i]*=q;
  101578. while(map[++i]==k)curve[i]*=q;
  101579. }
  101580. }
  101581. #endif
  101582. #endif
  101583. static void cheby(float *g, int ord) {
  101584. int i, j;
  101585. g[0] *= .5f;
  101586. for(i=2; i<= ord; i++) {
  101587. for(j=ord; j >= i; j--) {
  101588. g[j-2] -= g[j];
  101589. g[j] += g[j];
  101590. }
  101591. }
  101592. }
  101593. static int comp(const void *a,const void *b){
  101594. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101595. }
  101596. #define EPSILON 10e-7
  101597. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101598. int i,m;
  101599. double lastdelta=0.f;
  101600. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101601. for(i=0;i<=ord;i++)defl[i]=a[i];
  101602. for(m=ord;m>0;m--){
  101603. double newx=0.f,delta;
  101604. while(1){
  101605. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101606. for(i=m;i>0;i--){
  101607. ppp = newx*ppp + pp;
  101608. pp = newx*pp + p;
  101609. p = newx*p + defl[i-1];
  101610. }
  101611. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101612. if(denom<0)
  101613. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101614. if(pp>0){
  101615. denom = pp + sqrt(denom);
  101616. if(denom<EPSILON)denom=EPSILON;
  101617. }else{
  101618. denom = pp - sqrt(denom);
  101619. if(denom>-(EPSILON))denom=-(EPSILON);
  101620. }
  101621. delta = m*p/denom;
  101622. newx -= delta;
  101623. if(delta<0.f)delta*=-1;
  101624. if(fabs(delta/newx)<10e-12)break;
  101625. lastdelta=delta;
  101626. }
  101627. r[m-1]=newx;
  101628. for(i=m;i>0;i--)
  101629. defl[i-1]+=newx*defl[i];
  101630. defl++;
  101631. }
  101632. return(0);
  101633. }
  101634. static int Newton_Raphson(float *a,int ord,float *r){
  101635. int i, k, count=0;
  101636. double error=1.f;
  101637. double *root=(double*)alloca(ord*sizeof(*root));
  101638. for(i=0; i<ord;i++) root[i] = r[i];
  101639. while(error>1e-20){
  101640. error=0;
  101641. for(i=0; i<ord; i++) { /* Update each point. */
  101642. double pp=0.,delta;
  101643. double rooti=root[i];
  101644. double p=a[ord];
  101645. for(k=ord-1; k>= 0; k--) {
  101646. pp= pp* rooti + p;
  101647. p = p * rooti + a[k];
  101648. }
  101649. delta = p/pp;
  101650. root[i] -= delta;
  101651. error+= delta*delta;
  101652. }
  101653. if(count>40)return(-1);
  101654. count++;
  101655. }
  101656. for(i=0; i<ord;i++) r[i] = root[i];
  101657. return(0);
  101658. }
  101659. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101660. int order2=(m+1)>>1;
  101661. int g1_order,g2_order;
  101662. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101663. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101664. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101665. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101666. int i;
  101667. g1_order=(m+1)>>1;
  101668. g2_order=(m) >>1;
  101669. g1[g1_order] = 1.f;
  101670. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101671. g2[g2_order] = 1.f;
  101672. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101673. if(g1_order>g2_order){
  101674. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101675. }else{
  101676. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101677. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101678. }
  101679. cheby(g1,g1_order);
  101680. cheby(g2,g2_order);
  101681. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101682. Laguerre_With_Deflation(g2,g2_order,g2r))
  101683. return(-1);
  101684. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101685. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101686. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101687. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101688. for(i=0;i<g1_order;i++)
  101689. lsp[i*2] = acos(g1r[i]);
  101690. for(i=0;i<g2_order;i++)
  101691. lsp[i*2+1] = acos(g2r[i]);
  101692. return(0);
  101693. }
  101694. #endif
  101695. /*** End of inlined file: lsp.c ***/
  101696. /*** Start of inlined file: mapping0.c ***/
  101697. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101698. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101699. // tasks..
  101700. #if JUCE_MSVC
  101701. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101702. #endif
  101703. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101704. #if JUCE_USE_OGGVORBIS
  101705. #include <stdlib.h>
  101706. #include <stdio.h>
  101707. #include <string.h>
  101708. #include <math.h>
  101709. static void mapping0_free_info(vorbis_info_mapping *i){
  101710. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101711. if(info){
  101712. memset(info,0,sizeof(*info));
  101713. _ogg_free(info);
  101714. }
  101715. }
  101716. static int ilog3(unsigned int v){
  101717. int ret=0;
  101718. if(v)--v;
  101719. while(v){
  101720. ret++;
  101721. v>>=1;
  101722. }
  101723. return(ret);
  101724. }
  101725. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101726. oggpack_buffer *opb){
  101727. int i;
  101728. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101729. if(info->submaps>1){
  101730. oggpack_write(opb,1,1);
  101731. oggpack_write(opb,info->submaps-1,4);
  101732. }else
  101733. oggpack_write(opb,0,1);
  101734. if(info->coupling_steps>0){
  101735. oggpack_write(opb,1,1);
  101736. oggpack_write(opb,info->coupling_steps-1,8);
  101737. for(i=0;i<info->coupling_steps;i++){
  101738. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101739. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101740. }
  101741. }else
  101742. oggpack_write(opb,0,1);
  101743. oggpack_write(opb,0,2); /* 2,3:reserved */
  101744. if(info->submaps>1){
  101745. for(i=0;i<vi->channels;i++)
  101746. oggpack_write(opb,info->chmuxlist[i],4);
  101747. }
  101748. for(i=0;i<info->submaps;i++){
  101749. oggpack_write(opb,0,8); /* time submap unused */
  101750. oggpack_write(opb,info->floorsubmap[i],8);
  101751. oggpack_write(opb,info->residuesubmap[i],8);
  101752. }
  101753. }
  101754. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101755. int i;
  101756. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101757. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101758. memset(info,0,sizeof(*info));
  101759. if(oggpack_read(opb,1))
  101760. info->submaps=oggpack_read(opb,4)+1;
  101761. else
  101762. info->submaps=1;
  101763. if(oggpack_read(opb,1)){
  101764. info->coupling_steps=oggpack_read(opb,8)+1;
  101765. for(i=0;i<info->coupling_steps;i++){
  101766. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101767. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101768. if(testM<0 ||
  101769. testA<0 ||
  101770. testM==testA ||
  101771. testM>=vi->channels ||
  101772. testA>=vi->channels) goto err_out;
  101773. }
  101774. }
  101775. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101776. if(info->submaps>1){
  101777. for(i=0;i<vi->channels;i++){
  101778. info->chmuxlist[i]=oggpack_read(opb,4);
  101779. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101780. }
  101781. }
  101782. for(i=0;i<info->submaps;i++){
  101783. oggpack_read(opb,8); /* time submap unused */
  101784. info->floorsubmap[i]=oggpack_read(opb,8);
  101785. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101786. info->residuesubmap[i]=oggpack_read(opb,8);
  101787. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101788. }
  101789. return info;
  101790. err_out:
  101791. mapping0_free_info(info);
  101792. return(NULL);
  101793. }
  101794. #if 0
  101795. static long seq=0;
  101796. static ogg_int64_t total=0;
  101797. static float FLOOR1_fromdB_LOOKUP[256]={
  101798. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101799. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101800. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101801. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101802. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101803. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101804. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101805. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101806. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101807. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101808. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101809. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101810. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101811. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101812. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101813. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101814. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101815. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101816. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101817. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101818. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101819. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101820. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101821. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101822. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101823. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101824. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101825. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101826. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101827. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101828. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101829. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101830. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101831. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101832. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101833. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101834. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101835. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101836. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101837. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101838. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101839. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101840. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101841. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101842. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101843. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101844. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101845. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101846. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101847. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101848. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101849. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101850. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101851. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101852. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101853. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101854. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101855. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101856. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101857. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101858. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101859. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101860. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101861. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101862. };
  101863. #endif
  101864. extern int *floor1_fit(vorbis_block *vb,void *look,
  101865. const float *logmdct, /* in */
  101866. const float *logmask);
  101867. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101868. int *A,int *B,
  101869. int del);
  101870. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101871. void*look,
  101872. int *post,int *ilogmask);
  101873. static int mapping0_forward(vorbis_block *vb){
  101874. vorbis_dsp_state *vd=vb->vd;
  101875. vorbis_info *vi=vd->vi;
  101876. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101877. private_state *b=(private_state*)vb->vd->backend_state;
  101878. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101879. int n=vb->pcmend;
  101880. int i,j,k;
  101881. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101882. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101883. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101884. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101885. float global_ampmax=vbi->ampmax;
  101886. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101887. int blocktype=vbi->blocktype;
  101888. int modenumber=vb->W;
  101889. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101890. vorbis_look_psy *psy_look=
  101891. b->psy+blocktype+(vb->W?2:0);
  101892. vb->mode=modenumber;
  101893. for(i=0;i<vi->channels;i++){
  101894. float scale=4.f/n;
  101895. float scale_dB;
  101896. float *pcm =vb->pcm[i];
  101897. float *logfft =pcm;
  101898. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101899. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101900. todB estimation used on IEEE 754
  101901. compliant machines had a bug that
  101902. returned dB values about a third
  101903. of a decibel too high. The bug
  101904. was harmless because tunings
  101905. implicitly took that into
  101906. account. However, fixing the bug
  101907. in the estimator requires
  101908. changing all the tunings as well.
  101909. For now, it's easier to sync
  101910. things back up here, and
  101911. recalibrate the tunings in the
  101912. next major model upgrade. */
  101913. #if 0
  101914. if(vi->channels==2)
  101915. if(i==0)
  101916. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101917. else
  101918. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101919. #endif
  101920. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101921. #if 0
  101922. if(vi->channels==2)
  101923. if(i==0)
  101924. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101925. else
  101926. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101927. #endif
  101928. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101929. drft_forward(&b->fft_look[vb->W],pcm);
  101930. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101931. original todB estimation used on
  101932. IEEE 754 compliant machines had a
  101933. bug that returned dB values about
  101934. a third of a decibel too high.
  101935. The bug was harmless because
  101936. tunings implicitly took that into
  101937. account. However, fixing the bug
  101938. in the estimator requires
  101939. changing all the tunings as well.
  101940. For now, it's easier to sync
  101941. things back up here, and
  101942. recalibrate the tunings in the
  101943. next major model upgrade. */
  101944. local_ampmax[i]=logfft[0];
  101945. for(j=1;j<n-1;j+=2){
  101946. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101947. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101948. .345 is a hack; the original todB
  101949. estimation used on IEEE 754
  101950. compliant machines had a bug that
  101951. returned dB values about a third
  101952. of a decibel too high. The bug
  101953. was harmless because tunings
  101954. implicitly took that into
  101955. account. However, fixing the bug
  101956. in the estimator requires
  101957. changing all the tunings as well.
  101958. For now, it's easier to sync
  101959. things back up here, and
  101960. recalibrate the tunings in the
  101961. next major model upgrade. */
  101962. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101963. }
  101964. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101965. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101966. #if 0
  101967. if(vi->channels==2){
  101968. if(i==0){
  101969. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101970. }else{
  101971. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101972. }
  101973. }
  101974. #endif
  101975. }
  101976. {
  101977. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101978. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101979. for(i=0;i<vi->channels;i++){
  101980. int submap=info->chmuxlist[i];
  101981. float *mdct =gmdct[i];
  101982. float *logfft =vb->pcm[i];
  101983. float *logmdct =logfft+n/2;
  101984. float *logmask =logfft;
  101985. vb->mode=modenumber;
  101986. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101987. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101988. for(j=0;j<n/2;j++)
  101989. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101990. todB estimation used on IEEE 754
  101991. compliant machines had a bug that
  101992. returned dB values about a third
  101993. of a decibel too high. The bug
  101994. was harmless because tunings
  101995. implicitly took that into
  101996. account. However, fixing the bug
  101997. in the estimator requires
  101998. changing all the tunings as well.
  101999. For now, it's easier to sync
  102000. things back up here, and
  102001. recalibrate the tunings in the
  102002. next major model upgrade. */
  102003. #if 0
  102004. if(vi->channels==2){
  102005. if(i==0)
  102006. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  102007. else
  102008. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  102009. }else{
  102010. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  102011. }
  102012. #endif
  102013. _vp_noisemask(psy_look,
  102014. logmdct,
  102015. noise); /* noise does not have by-frequency offset
  102016. bias applied yet */
  102017. #if 0
  102018. if(vi->channels==2){
  102019. if(i==0)
  102020. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  102021. else
  102022. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  102023. }
  102024. #endif
  102025. _vp_tonemask(psy_look,
  102026. logfft,
  102027. tone,
  102028. global_ampmax,
  102029. local_ampmax[i]);
  102030. #if 0
  102031. if(vi->channels==2){
  102032. if(i==0)
  102033. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  102034. else
  102035. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  102036. }
  102037. #endif
  102038. #if 0
  102039. {
  102040. float aotuv[psy_look->n];
  102041. #endif
  102042. _vp_offset_and_mix(psy_look,
  102043. noise,
  102044. tone,
  102045. 1,
  102046. logmask,
  102047. mdct,
  102048. logmdct);
  102049. #if 0
  102050. if(vi->channels==2){
  102051. if(i==0)
  102052. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  102053. else
  102054. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  102055. }
  102056. }
  102057. #endif
  102058. #if 0
  102059. if(vi->channels==2){
  102060. if(i==0)
  102061. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  102062. else
  102063. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  102064. }
  102065. #endif
  102066. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  102067. floor_posts[i][PACKETBLOBS/2]=
  102068. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102069. logmdct,
  102070. logmask);
  102071. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  102072. _vp_offset_and_mix(psy_look,
  102073. noise,
  102074. tone,
  102075. 2,
  102076. logmask,
  102077. mdct,
  102078. logmdct);
  102079. #if 0
  102080. if(vi->channels==2){
  102081. if(i==0)
  102082. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  102083. else
  102084. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  102085. }
  102086. #endif
  102087. floor_posts[i][PACKETBLOBS-1]=
  102088. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102089. logmdct,
  102090. logmask);
  102091. _vp_offset_and_mix(psy_look,
  102092. noise,
  102093. tone,
  102094. 0,
  102095. logmask,
  102096. mdct,
  102097. logmdct);
  102098. #if 0
  102099. if(vi->channels==2)
  102100. if(i==0)
  102101. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  102102. else
  102103. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  102104. #endif
  102105. floor_posts[i][0]=
  102106. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102107. logmdct,
  102108. logmask);
  102109. for(k=1;k<PACKETBLOBS/2;k++)
  102110. floor_posts[i][k]=
  102111. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  102112. floor_posts[i][0],
  102113. floor_posts[i][PACKETBLOBS/2],
  102114. k*65536/(PACKETBLOBS/2));
  102115. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  102116. floor_posts[i][k]=
  102117. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  102118. floor_posts[i][PACKETBLOBS/2],
  102119. floor_posts[i][PACKETBLOBS-1],
  102120. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  102121. }
  102122. }
  102123. }
  102124. vbi->ampmax=global_ampmax;
  102125. {
  102126. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  102127. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  102128. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102129. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  102130. float **mag_memo;
  102131. int **mag_sort;
  102132. if(info->coupling_steps){
  102133. mag_memo=_vp_quantize_couple_memo(vb,
  102134. &ci->psy_g_param,
  102135. psy_look,
  102136. info,
  102137. gmdct);
  102138. mag_sort=_vp_quantize_couple_sort(vb,
  102139. psy_look,
  102140. info,
  102141. mag_memo);
  102142. hf_reduction(&ci->psy_g_param,
  102143. psy_look,
  102144. info,
  102145. mag_memo);
  102146. }
  102147. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  102148. if(psy_look->vi->normal_channel_p){
  102149. for(i=0;i<vi->channels;i++){
  102150. float *mdct =gmdct[i];
  102151. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  102152. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  102153. }
  102154. }
  102155. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  102156. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  102157. k++){
  102158. oggpack_buffer *opb=vbi->packetblob[k];
  102159. oggpack_write(opb,0,1);
  102160. oggpack_write(opb,modenumber,b->modebits);
  102161. if(vb->W){
  102162. oggpack_write(opb,vb->lW,1);
  102163. oggpack_write(opb,vb->nW,1);
  102164. }
  102165. for(i=0;i<vi->channels;i++){
  102166. int submap=info->chmuxlist[i];
  102167. float *mdct =gmdct[i];
  102168. float *res =vb->pcm[i];
  102169. int *ilogmask=ilogmaskch[i]=
  102170. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  102171. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  102172. floor_posts[i][k],
  102173. ilogmask);
  102174. #if 0
  102175. {
  102176. char buf[80];
  102177. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  102178. float work[n/2];
  102179. for(j=0;j<n/2;j++)
  102180. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  102181. _analysis_output(buf,seq,work,n/2,1,1,0);
  102182. }
  102183. #endif
  102184. _vp_remove_floor(psy_look,
  102185. mdct,
  102186. ilogmask,
  102187. res,
  102188. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102189. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  102190. #if 0
  102191. {
  102192. char buf[80];
  102193. float work[n/2];
  102194. for(j=0;j<n/2;j++)
  102195. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  102196. sprintf(buf,"resI%c%d",i?'R':'L',k);
  102197. _analysis_output(buf,seq,work,n/2,1,1,0);
  102198. }
  102199. #endif
  102200. }
  102201. if(info->coupling_steps){
  102202. _vp_couple(k,
  102203. &ci->psy_g_param,
  102204. psy_look,
  102205. info,
  102206. vb->pcm,
  102207. mag_memo,
  102208. mag_sort,
  102209. ilogmaskch,
  102210. nonzero,
  102211. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102212. }
  102213. for(i=0;i<info->submaps;i++){
  102214. int ch_in_bundle=0;
  102215. long **classifications;
  102216. int resnum=info->residuesubmap[i];
  102217. for(j=0;j<vi->channels;j++){
  102218. if(info->chmuxlist[j]==i){
  102219. zerobundle[ch_in_bundle]=0;
  102220. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  102221. res_bundle[ch_in_bundle]=vb->pcm[j];
  102222. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  102223. }
  102224. }
  102225. classifications=_residue_P[ci->residue_type[resnum]]->
  102226. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  102227. _residue_P[ci->residue_type[resnum]]->
  102228. forward(opb,vb,b->residue[resnum],
  102229. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  102230. }
  102231. }
  102232. }
  102233. #if 0
  102234. seq++;
  102235. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  102236. #endif
  102237. return(0);
  102238. }
  102239. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  102240. vorbis_dsp_state *vd=vb->vd;
  102241. vorbis_info *vi=vd->vi;
  102242. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  102243. private_state *b=(private_state*)vd->backend_state;
  102244. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  102245. int i,j;
  102246. long n=vb->pcmend=ci->blocksizes[vb->W];
  102247. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  102248. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102249. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  102250. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  102251. for(i=0;i<vi->channels;i++){
  102252. int submap=info->chmuxlist[i];
  102253. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102254. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  102255. if(floormemo[i])
  102256. nonzero[i]=1;
  102257. else
  102258. nonzero[i]=0;
  102259. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  102260. }
  102261. for(i=0;i<info->coupling_steps;i++){
  102262. if(nonzero[info->coupling_mag[i]] ||
  102263. nonzero[info->coupling_ang[i]]){
  102264. nonzero[info->coupling_mag[i]]=1;
  102265. nonzero[info->coupling_ang[i]]=1;
  102266. }
  102267. }
  102268. for(i=0;i<info->submaps;i++){
  102269. int ch_in_bundle=0;
  102270. for(j=0;j<vi->channels;j++){
  102271. if(info->chmuxlist[j]==i){
  102272. if(nonzero[j])
  102273. zerobundle[ch_in_bundle]=1;
  102274. else
  102275. zerobundle[ch_in_bundle]=0;
  102276. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  102277. }
  102278. }
  102279. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  102280. inverse(vb,b->residue[info->residuesubmap[i]],
  102281. pcmbundle,zerobundle,ch_in_bundle);
  102282. }
  102283. for(i=info->coupling_steps-1;i>=0;i--){
  102284. float *pcmM=vb->pcm[info->coupling_mag[i]];
  102285. float *pcmA=vb->pcm[info->coupling_ang[i]];
  102286. for(j=0;j<n/2;j++){
  102287. float mag=pcmM[j];
  102288. float ang=pcmA[j];
  102289. if(mag>0)
  102290. if(ang>0){
  102291. pcmM[j]=mag;
  102292. pcmA[j]=mag-ang;
  102293. }else{
  102294. pcmA[j]=mag;
  102295. pcmM[j]=mag+ang;
  102296. }
  102297. else
  102298. if(ang>0){
  102299. pcmM[j]=mag;
  102300. pcmA[j]=mag+ang;
  102301. }else{
  102302. pcmA[j]=mag;
  102303. pcmM[j]=mag-ang;
  102304. }
  102305. }
  102306. }
  102307. for(i=0;i<vi->channels;i++){
  102308. float *pcm=vb->pcm[i];
  102309. int submap=info->chmuxlist[i];
  102310. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102311. inverse2(vb,b->flr[info->floorsubmap[submap]],
  102312. floormemo[i],pcm);
  102313. }
  102314. for(i=0;i<vi->channels;i++){
  102315. float *pcm=vb->pcm[i];
  102316. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  102317. }
  102318. return(0);
  102319. }
  102320. vorbis_func_mapping mapping0_exportbundle={
  102321. &mapping0_pack,
  102322. &mapping0_unpack,
  102323. &mapping0_free_info,
  102324. &mapping0_forward,
  102325. &mapping0_inverse
  102326. };
  102327. #endif
  102328. /*** End of inlined file: mapping0.c ***/
  102329. /*** Start of inlined file: mdct.c ***/
  102330. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102331. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102332. // tasks..
  102333. #if JUCE_MSVC
  102334. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102335. #endif
  102336. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102337. #if JUCE_USE_OGGVORBIS
  102338. #include <stdio.h>
  102339. #include <stdlib.h>
  102340. #include <string.h>
  102341. #include <math.h>
  102342. void mdct_init(mdct_lookup *lookup,int n){
  102343. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  102344. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  102345. int i;
  102346. int n2=n>>1;
  102347. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  102348. lookup->n=n;
  102349. lookup->trig=T;
  102350. lookup->bitrev=bitrev;
  102351. for(i=0;i<n/4;i++){
  102352. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  102353. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  102354. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  102355. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  102356. }
  102357. for(i=0;i<n/8;i++){
  102358. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  102359. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  102360. }
  102361. {
  102362. int mask=(1<<(log2n-1))-1,i,j;
  102363. int msb=1<<(log2n-2);
  102364. for(i=0;i<n/8;i++){
  102365. int acc=0;
  102366. for(j=0;msb>>j;j++)
  102367. if((msb>>j)&i)acc|=1<<j;
  102368. bitrev[i*2]=((~acc)&mask)-1;
  102369. bitrev[i*2+1]=acc;
  102370. }
  102371. }
  102372. lookup->scale=FLOAT_CONV(4.f/n);
  102373. }
  102374. STIN void mdct_butterfly_8(DATA_TYPE *x){
  102375. REG_TYPE r0 = x[6] + x[2];
  102376. REG_TYPE r1 = x[6] - x[2];
  102377. REG_TYPE r2 = x[4] + x[0];
  102378. REG_TYPE r3 = x[4] - x[0];
  102379. x[6] = r0 + r2;
  102380. x[4] = r0 - r2;
  102381. r0 = x[5] - x[1];
  102382. r2 = x[7] - x[3];
  102383. x[0] = r1 + r0;
  102384. x[2] = r1 - r0;
  102385. r0 = x[5] + x[1];
  102386. r1 = x[7] + x[3];
  102387. x[3] = r2 + r3;
  102388. x[1] = r2 - r3;
  102389. x[7] = r1 + r0;
  102390. x[5] = r1 - r0;
  102391. }
  102392. STIN void mdct_butterfly_16(DATA_TYPE *x){
  102393. REG_TYPE r0 = x[1] - x[9];
  102394. REG_TYPE r1 = x[0] - x[8];
  102395. x[8] += x[0];
  102396. x[9] += x[1];
  102397. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  102398. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  102399. r0 = x[3] - x[11];
  102400. r1 = x[10] - x[2];
  102401. x[10] += x[2];
  102402. x[11] += x[3];
  102403. x[2] = r0;
  102404. x[3] = r1;
  102405. r0 = x[12] - x[4];
  102406. r1 = x[13] - x[5];
  102407. x[12] += x[4];
  102408. x[13] += x[5];
  102409. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  102410. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  102411. r0 = x[14] - x[6];
  102412. r1 = x[15] - x[7];
  102413. x[14] += x[6];
  102414. x[15] += x[7];
  102415. x[6] = r0;
  102416. x[7] = r1;
  102417. mdct_butterfly_8(x);
  102418. mdct_butterfly_8(x+8);
  102419. }
  102420. STIN void mdct_butterfly_32(DATA_TYPE *x){
  102421. REG_TYPE r0 = x[30] - x[14];
  102422. REG_TYPE r1 = x[31] - x[15];
  102423. x[30] += x[14];
  102424. x[31] += x[15];
  102425. x[14] = r0;
  102426. x[15] = r1;
  102427. r0 = x[28] - x[12];
  102428. r1 = x[29] - x[13];
  102429. x[28] += x[12];
  102430. x[29] += x[13];
  102431. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  102432. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  102433. r0 = x[26] - x[10];
  102434. r1 = x[27] - x[11];
  102435. x[26] += x[10];
  102436. x[27] += x[11];
  102437. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  102438. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  102439. r0 = x[24] - x[8];
  102440. r1 = x[25] - x[9];
  102441. x[24] += x[8];
  102442. x[25] += x[9];
  102443. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  102444. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102445. r0 = x[22] - x[6];
  102446. r1 = x[7] - x[23];
  102447. x[22] += x[6];
  102448. x[23] += x[7];
  102449. x[6] = r1;
  102450. x[7] = r0;
  102451. r0 = x[4] - x[20];
  102452. r1 = x[5] - x[21];
  102453. x[20] += x[4];
  102454. x[21] += x[5];
  102455. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  102456. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  102457. r0 = x[2] - x[18];
  102458. r1 = x[3] - x[19];
  102459. x[18] += x[2];
  102460. x[19] += x[3];
  102461. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  102462. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  102463. r0 = x[0] - x[16];
  102464. r1 = x[1] - x[17];
  102465. x[16] += x[0];
  102466. x[17] += x[1];
  102467. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102468. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  102469. mdct_butterfly_16(x);
  102470. mdct_butterfly_16(x+16);
  102471. }
  102472. STIN void mdct_butterfly_first(DATA_TYPE *T,
  102473. DATA_TYPE *x,
  102474. int points){
  102475. DATA_TYPE *x1 = x + points - 8;
  102476. DATA_TYPE *x2 = x + (points>>1) - 8;
  102477. REG_TYPE r0;
  102478. REG_TYPE r1;
  102479. do{
  102480. r0 = x1[6] - x2[6];
  102481. r1 = x1[7] - x2[7];
  102482. x1[6] += x2[6];
  102483. x1[7] += x2[7];
  102484. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102485. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102486. r0 = x1[4] - x2[4];
  102487. r1 = x1[5] - x2[5];
  102488. x1[4] += x2[4];
  102489. x1[5] += x2[5];
  102490. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  102491. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  102492. r0 = x1[2] - x2[2];
  102493. r1 = x1[3] - x2[3];
  102494. x1[2] += x2[2];
  102495. x1[3] += x2[3];
  102496. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  102497. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  102498. r0 = x1[0] - x2[0];
  102499. r1 = x1[1] - x2[1];
  102500. x1[0] += x2[0];
  102501. x1[1] += x2[1];
  102502. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  102503. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  102504. x1-=8;
  102505. x2-=8;
  102506. T+=16;
  102507. }while(x2>=x);
  102508. }
  102509. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  102510. DATA_TYPE *x,
  102511. int points,
  102512. int trigint){
  102513. DATA_TYPE *x1 = x + points - 8;
  102514. DATA_TYPE *x2 = x + (points>>1) - 8;
  102515. REG_TYPE r0;
  102516. REG_TYPE r1;
  102517. do{
  102518. r0 = x1[6] - x2[6];
  102519. r1 = x1[7] - x2[7];
  102520. x1[6] += x2[6];
  102521. x1[7] += x2[7];
  102522. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102523. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102524. T+=trigint;
  102525. r0 = x1[4] - x2[4];
  102526. r1 = x1[5] - x2[5];
  102527. x1[4] += x2[4];
  102528. x1[5] += x2[5];
  102529. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102530. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102531. T+=trigint;
  102532. r0 = x1[2] - x2[2];
  102533. r1 = x1[3] - x2[3];
  102534. x1[2] += x2[2];
  102535. x1[3] += x2[3];
  102536. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102537. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102538. T+=trigint;
  102539. r0 = x1[0] - x2[0];
  102540. r1 = x1[1] - x2[1];
  102541. x1[0] += x2[0];
  102542. x1[1] += x2[1];
  102543. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102544. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102545. T+=trigint;
  102546. x1-=8;
  102547. x2-=8;
  102548. }while(x2>=x);
  102549. }
  102550. STIN void mdct_butterflies(mdct_lookup *init,
  102551. DATA_TYPE *x,
  102552. int points){
  102553. DATA_TYPE *T=init->trig;
  102554. int stages=init->log2n-5;
  102555. int i,j;
  102556. if(--stages>0){
  102557. mdct_butterfly_first(T,x,points);
  102558. }
  102559. for(i=1;--stages>0;i++){
  102560. for(j=0;j<(1<<i);j++)
  102561. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102562. }
  102563. for(j=0;j<points;j+=32)
  102564. mdct_butterfly_32(x+j);
  102565. }
  102566. void mdct_clear(mdct_lookup *l){
  102567. if(l){
  102568. if(l->trig)_ogg_free(l->trig);
  102569. if(l->bitrev)_ogg_free(l->bitrev);
  102570. memset(l,0,sizeof(*l));
  102571. }
  102572. }
  102573. STIN void mdct_bitreverse(mdct_lookup *init,
  102574. DATA_TYPE *x){
  102575. int n = init->n;
  102576. int *bit = init->bitrev;
  102577. DATA_TYPE *w0 = x;
  102578. DATA_TYPE *w1 = x = w0+(n>>1);
  102579. DATA_TYPE *T = init->trig+n;
  102580. do{
  102581. DATA_TYPE *x0 = x+bit[0];
  102582. DATA_TYPE *x1 = x+bit[1];
  102583. REG_TYPE r0 = x0[1] - x1[1];
  102584. REG_TYPE r1 = x0[0] + x1[0];
  102585. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102586. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102587. w1 -= 4;
  102588. r0 = HALVE(x0[1] + x1[1]);
  102589. r1 = HALVE(x0[0] - x1[0]);
  102590. w0[0] = r0 + r2;
  102591. w1[2] = r0 - r2;
  102592. w0[1] = r1 + r3;
  102593. w1[3] = r3 - r1;
  102594. x0 = x+bit[2];
  102595. x1 = x+bit[3];
  102596. r0 = x0[1] - x1[1];
  102597. r1 = x0[0] + x1[0];
  102598. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102599. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102600. r0 = HALVE(x0[1] + x1[1]);
  102601. r1 = HALVE(x0[0] - x1[0]);
  102602. w0[2] = r0 + r2;
  102603. w1[0] = r0 - r2;
  102604. w0[3] = r1 + r3;
  102605. w1[1] = r3 - r1;
  102606. T += 4;
  102607. bit += 4;
  102608. w0 += 4;
  102609. }while(w0<w1);
  102610. }
  102611. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102612. int n=init->n;
  102613. int n2=n>>1;
  102614. int n4=n>>2;
  102615. DATA_TYPE *iX = in+n2-7;
  102616. DATA_TYPE *oX = out+n2+n4;
  102617. DATA_TYPE *T = init->trig+n4;
  102618. do{
  102619. oX -= 4;
  102620. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102621. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102622. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102623. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102624. iX -= 8;
  102625. T += 4;
  102626. }while(iX>=in);
  102627. iX = in+n2-8;
  102628. oX = out+n2+n4;
  102629. T = init->trig+n4;
  102630. do{
  102631. T -= 4;
  102632. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102633. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102634. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102635. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102636. iX -= 8;
  102637. oX += 4;
  102638. }while(iX>=in);
  102639. mdct_butterflies(init,out+n2,n2);
  102640. mdct_bitreverse(init,out);
  102641. {
  102642. DATA_TYPE *oX1=out+n2+n4;
  102643. DATA_TYPE *oX2=out+n2+n4;
  102644. DATA_TYPE *iX =out;
  102645. T =init->trig+n2;
  102646. do{
  102647. oX1-=4;
  102648. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102649. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102650. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102651. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102652. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102653. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102654. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102655. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102656. oX2+=4;
  102657. iX += 8;
  102658. T += 8;
  102659. }while(iX<oX1);
  102660. iX=out+n2+n4;
  102661. oX1=out+n4;
  102662. oX2=oX1;
  102663. do{
  102664. oX1-=4;
  102665. iX-=4;
  102666. oX2[0] = -(oX1[3] = iX[3]);
  102667. oX2[1] = -(oX1[2] = iX[2]);
  102668. oX2[2] = -(oX1[1] = iX[1]);
  102669. oX2[3] = -(oX1[0] = iX[0]);
  102670. oX2+=4;
  102671. }while(oX2<iX);
  102672. iX=out+n2+n4;
  102673. oX1=out+n2+n4;
  102674. oX2=out+n2;
  102675. do{
  102676. oX1-=4;
  102677. oX1[0]= iX[3];
  102678. oX1[1]= iX[2];
  102679. oX1[2]= iX[1];
  102680. oX1[3]= iX[0];
  102681. iX+=4;
  102682. }while(oX1>oX2);
  102683. }
  102684. }
  102685. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102686. int n=init->n;
  102687. int n2=n>>1;
  102688. int n4=n>>2;
  102689. int n8=n>>3;
  102690. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102691. DATA_TYPE *w2=w+n2;
  102692. REG_TYPE r0;
  102693. REG_TYPE r1;
  102694. DATA_TYPE *x0=in+n2+n4;
  102695. DATA_TYPE *x1=x0+1;
  102696. DATA_TYPE *T=init->trig+n2;
  102697. int i=0;
  102698. for(i=0;i<n8;i+=2){
  102699. x0 -=4;
  102700. T-=2;
  102701. r0= x0[2] + x1[0];
  102702. r1= x0[0] + x1[2];
  102703. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102704. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102705. x1 +=4;
  102706. }
  102707. x1=in+1;
  102708. for(;i<n2-n8;i+=2){
  102709. T-=2;
  102710. x0 -=4;
  102711. r0= x0[2] - x1[0];
  102712. r1= x0[0] - x1[2];
  102713. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102714. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102715. x1 +=4;
  102716. }
  102717. x0=in+n;
  102718. for(;i<n2;i+=2){
  102719. T-=2;
  102720. x0 -=4;
  102721. r0= -x0[2] - x1[0];
  102722. r1= -x0[0] - x1[2];
  102723. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102724. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102725. x1 +=4;
  102726. }
  102727. mdct_butterflies(init,w+n2,n2);
  102728. mdct_bitreverse(init,w);
  102729. T=init->trig+n2;
  102730. x0=out+n2;
  102731. for(i=0;i<n4;i++){
  102732. x0--;
  102733. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102734. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102735. w+=2;
  102736. T+=2;
  102737. }
  102738. }
  102739. #endif
  102740. /*** End of inlined file: mdct.c ***/
  102741. /*** Start of inlined file: psy.c ***/
  102742. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102743. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102744. // tasks..
  102745. #if JUCE_MSVC
  102746. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102747. #endif
  102748. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102749. #if JUCE_USE_OGGVORBIS
  102750. #include <stdlib.h>
  102751. #include <math.h>
  102752. #include <string.h>
  102753. /*** Start of inlined file: masking.h ***/
  102754. #ifndef _V_MASKING_H_
  102755. #define _V_MASKING_H_
  102756. #define MAX_ATH 88
  102757. static float ATH[]={
  102758. -51, -52, -53, -54, -55, -56, -57, -58,
  102759. -59, -60, -61, -62, -63, -64, -65, -66,
  102760. -67, -68, -69, -70, -71, -72, -73, -74,
  102761. -75, -76, -77, -78, -80, -81, -82, -83,
  102762. -84, -85, -86, -87, -88, -88, -89, -89,
  102763. -90, -91, -91, -92, -93, -94, -95, -96,
  102764. -96, -97, -98, -98, -99, -99,-100,-100,
  102765. -101,-102,-103,-104,-106,-107,-107,-107,
  102766. -107,-105,-103,-102,-101, -99, -98, -96,
  102767. -95, -95, -96, -97, -96, -95, -93, -90,
  102768. -80, -70, -50, -40, -30, -30, -30, -30
  102769. };
  102770. #define EHMER_OFFSET 16
  102771. #define EHMER_MAX 56
  102772. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102773. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102774. -60, -60, -60, -60, -62, -62, -65, -73,
  102775. -69, -68, -68, -67, -70, -70, -72, -74,
  102776. -75, -79, -79, -80, -83, -88, -93, -100,
  102777. -110, -999, -999, -999, -999, -999, -999, -999,
  102778. -999, -999, -999, -999, -999, -999, -999, -999,
  102779. -999, -999, -999, -999, -999, -999, -999, -999},
  102780. { -48, -48, -48, -48, -48, -48, -48, -48,
  102781. -48, -48, -48, -48, -48, -53, -61, -66,
  102782. -66, -68, -67, -70, -76, -76, -72, -73,
  102783. -75, -76, -78, -79, -83, -88, -93, -100,
  102784. -110, -999, -999, -999, -999, -999, -999, -999,
  102785. -999, -999, -999, -999, -999, -999, -999, -999,
  102786. -999, -999, -999, -999, -999, -999, -999, -999},
  102787. { -37, -37, -37, -37, -37, -37, -37, -37,
  102788. -38, -40, -42, -46, -48, -53, -55, -62,
  102789. -65, -58, -56, -56, -61, -60, -65, -67,
  102790. -69, -71, -77, -77, -78, -80, -82, -84,
  102791. -88, -93, -98, -106, -112, -999, -999, -999,
  102792. -999, -999, -999, -999, -999, -999, -999, -999,
  102793. -999, -999, -999, -999, -999, -999, -999, -999},
  102794. { -25, -25, -25, -25, -25, -25, -25, -25,
  102795. -25, -26, -27, -29, -32, -38, -48, -52,
  102796. -52, -50, -48, -48, -51, -52, -54, -60,
  102797. -67, -67, -66, -68, -69, -73, -73, -76,
  102798. -80, -81, -81, -85, -85, -86, -88, -93,
  102799. -100, -110, -999, -999, -999, -999, -999, -999,
  102800. -999, -999, -999, -999, -999, -999, -999, -999},
  102801. { -16, -16, -16, -16, -16, -16, -16, -16,
  102802. -17, -19, -20, -22, -26, -28, -31, -40,
  102803. -47, -39, -39, -40, -42, -43, -47, -51,
  102804. -57, -52, -55, -55, -60, -58, -62, -63,
  102805. -70, -67, -69, -72, -73, -77, -80, -82,
  102806. -83, -87, -90, -94, -98, -104, -115, -999,
  102807. -999, -999, -999, -999, -999, -999, -999, -999},
  102808. { -8, -8, -8, -8, -8, -8, -8, -8,
  102809. -8, -8, -10, -11, -15, -19, -25, -30,
  102810. -34, -31, -30, -31, -29, -32, -35, -42,
  102811. -48, -42, -44, -46, -50, -50, -51, -52,
  102812. -59, -54, -55, -55, -58, -62, -63, -66,
  102813. -72, -73, -76, -75, -78, -80, -80, -81,
  102814. -84, -88, -90, -94, -98, -101, -106, -110}},
  102815. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102816. -66, -66, -66, -66, -66, -67, -67, -67,
  102817. -76, -72, -71, -74, -76, -76, -75, -78,
  102818. -79, -79, -81, -83, -86, -89, -93, -97,
  102819. -100, -105, -110, -999, -999, -999, -999, -999,
  102820. -999, -999, -999, -999, -999, -999, -999, -999,
  102821. -999, -999, -999, -999, -999, -999, -999, -999},
  102822. { -47, -47, -47, -47, -47, -47, -47, -47,
  102823. -47, -47, -47, -48, -51, -55, -59, -66,
  102824. -66, -66, -67, -66, -68, -69, -70, -74,
  102825. -79, -77, -77, -78, -80, -81, -82, -84,
  102826. -86, -88, -91, -95, -100, -108, -116, -999,
  102827. -999, -999, -999, -999, -999, -999, -999, -999,
  102828. -999, -999, -999, -999, -999, -999, -999, -999},
  102829. { -36, -36, -36, -36, -36, -36, -36, -36,
  102830. -36, -37, -37, -41, -44, -48, -51, -58,
  102831. -62, -60, -57, -59, -59, -60, -63, -65,
  102832. -72, -71, -70, -72, -74, -77, -76, -78,
  102833. -81, -81, -80, -83, -86, -91, -96, -100,
  102834. -105, -110, -999, -999, -999, -999, -999, -999,
  102835. -999, -999, -999, -999, -999, -999, -999, -999},
  102836. { -28, -28, -28, -28, -28, -28, -28, -28,
  102837. -28, -30, -32, -32, -33, -35, -41, -49,
  102838. -50, -49, -47, -48, -48, -52, -51, -57,
  102839. -65, -61, -59, -61, -64, -69, -70, -74,
  102840. -77, -77, -78, -81, -84, -85, -87, -90,
  102841. -92, -96, -100, -107, -112, -999, -999, -999,
  102842. -999, -999, -999, -999, -999, -999, -999, -999},
  102843. { -19, -19, -19, -19, -19, -19, -19, -19,
  102844. -20, -21, -23, -27, -30, -35, -36, -41,
  102845. -46, -44, -42, -40, -41, -41, -43, -48,
  102846. -55, -53, -52, -53, -56, -59, -58, -60,
  102847. -67, -66, -69, -71, -72, -75, -79, -81,
  102848. -84, -87, -90, -93, -97, -101, -107, -114,
  102849. -999, -999, -999, -999, -999, -999, -999, -999},
  102850. { -9, -9, -9, -9, -9, -9, -9, -9,
  102851. -11, -12, -12, -15, -16, -20, -23, -30,
  102852. -37, -34, -33, -34, -31, -32, -32, -38,
  102853. -47, -44, -41, -40, -47, -49, -46, -46,
  102854. -58, -50, -50, -54, -58, -62, -64, -67,
  102855. -67, -70, -72, -76, -79, -83, -87, -91,
  102856. -96, -100, -104, -110, -999, -999, -999, -999}},
  102857. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102858. -62, -62, -63, -64, -66, -67, -66, -68,
  102859. -75, -72, -76, -75, -76, -78, -79, -82,
  102860. -84, -85, -90, -94, -101, -110, -999, -999,
  102861. -999, -999, -999, -999, -999, -999, -999, -999,
  102862. -999, -999, -999, -999, -999, -999, -999, -999,
  102863. -999, -999, -999, -999, -999, -999, -999, -999},
  102864. { -59, -59, -59, -59, -59, -59, -59, -59,
  102865. -59, -59, -59, -60, -60, -61, -63, -66,
  102866. -71, -68, -70, -70, -71, -72, -72, -75,
  102867. -81, -78, -79, -82, -83, -86, -90, -97,
  102868. -103, -113, -999, -999, -999, -999, -999, -999,
  102869. -999, -999, -999, -999, -999, -999, -999, -999,
  102870. -999, -999, -999, -999, -999, -999, -999, -999},
  102871. { -53, -53, -53, -53, -53, -53, -53, -53,
  102872. -53, -54, -55, -57, -56, -57, -55, -61,
  102873. -65, -60, -60, -62, -63, -63, -66, -68,
  102874. -74, -73, -75, -75, -78, -80, -80, -82,
  102875. -85, -90, -96, -101, -108, -999, -999, -999,
  102876. -999, -999, -999, -999, -999, -999, -999, -999,
  102877. -999, -999, -999, -999, -999, -999, -999, -999},
  102878. { -46, -46, -46, -46, -46, -46, -46, -46,
  102879. -46, -46, -47, -47, -47, -47, -48, -51,
  102880. -57, -51, -49, -50, -51, -53, -54, -59,
  102881. -66, -60, -62, -67, -67, -70, -72, -75,
  102882. -76, -78, -81, -85, -88, -94, -97, -104,
  102883. -112, -999, -999, -999, -999, -999, -999, -999,
  102884. -999, -999, -999, -999, -999, -999, -999, -999},
  102885. { -36, -36, -36, -36, -36, -36, -36, -36,
  102886. -39, -41, -42, -42, -39, -38, -41, -43,
  102887. -52, -44, -40, -39, -37, -37, -40, -47,
  102888. -54, -50, -48, -50, -55, -61, -59, -62,
  102889. -66, -66, -66, -69, -69, -73, -74, -74,
  102890. -75, -77, -79, -82, -87, -91, -95, -100,
  102891. -108, -115, -999, -999, -999, -999, -999, -999},
  102892. { -28, -26, -24, -22, -20, -20, -23, -29,
  102893. -30, -31, -28, -27, -28, -28, -28, -35,
  102894. -40, -33, -32, -29, -30, -30, -30, -37,
  102895. -45, -41, -37, -38, -45, -47, -47, -48,
  102896. -53, -49, -48, -50, -49, -49, -51, -52,
  102897. -58, -56, -57, -56, -60, -61, -62, -70,
  102898. -72, -74, -78, -83, -88, -93, -100, -106}},
  102899. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102900. -999, -110, -105, -100, -95, -91, -87, -83,
  102901. -80, -78, -76, -78, -78, -81, -83, -85,
  102902. -86, -85, -86, -87, -90, -97, -107, -999,
  102903. -999, -999, -999, -999, -999, -999, -999, -999,
  102904. -999, -999, -999, -999, -999, -999, -999, -999,
  102905. -999, -999, -999, -999, -999, -999, -999, -999},
  102906. {-999, -999, -999, -110, -105, -100, -95, -90,
  102907. -85, -81, -77, -73, -70, -67, -67, -68,
  102908. -75, -73, -70, -69, -70, -72, -75, -79,
  102909. -84, -83, -84, -86, -88, -89, -89, -93,
  102910. -98, -105, -112, -999, -999, -999, -999, -999,
  102911. -999, -999, -999, -999, -999, -999, -999, -999,
  102912. -999, -999, -999, -999, -999, -999, -999, -999},
  102913. {-105, -100, -95, -90, -85, -80, -76, -71,
  102914. -68, -68, -65, -63, -63, -62, -62, -64,
  102915. -65, -64, -61, -62, -63, -64, -66, -68,
  102916. -73, -73, -74, -75, -76, -81, -83, -85,
  102917. -88, -89, -92, -95, -100, -108, -999, -999,
  102918. -999, -999, -999, -999, -999, -999, -999, -999,
  102919. -999, -999, -999, -999, -999, -999, -999, -999},
  102920. { -80, -75, -71, -68, -65, -63, -62, -61,
  102921. -61, -61, -61, -59, -56, -57, -53, -50,
  102922. -58, -52, -50, -50, -52, -53, -54, -58,
  102923. -67, -63, -67, -68, -72, -75, -78, -80,
  102924. -81, -81, -82, -85, -89, -90, -93, -97,
  102925. -101, -107, -114, -999, -999, -999, -999, -999,
  102926. -999, -999, -999, -999, -999, -999, -999, -999},
  102927. { -65, -61, -59, -57, -56, -55, -55, -56,
  102928. -56, -57, -55, -53, -52, -47, -44, -44,
  102929. -50, -44, -41, -39, -39, -42, -40, -46,
  102930. -51, -49, -50, -53, -54, -63, -60, -61,
  102931. -62, -66, -66, -66, -70, -73, -74, -75,
  102932. -76, -75, -79, -85, -89, -91, -96, -102,
  102933. -110, -999, -999, -999, -999, -999, -999, -999},
  102934. { -52, -50, -49, -49, -48, -48, -48, -49,
  102935. -50, -50, -49, -46, -43, -39, -35, -33,
  102936. -38, -36, -32, -29, -32, -32, -32, -35,
  102937. -44, -39, -38, -38, -46, -50, -45, -46,
  102938. -53, -50, -50, -50, -54, -54, -53, -53,
  102939. -56, -57, -59, -66, -70, -72, -74, -79,
  102940. -83, -85, -90, -97, -114, -999, -999, -999}},
  102941. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102942. -100, -95, -90, -86, -80, -75, -75, -79,
  102943. -80, -79, -80, -81, -82, -88, -95, -103,
  102944. -110, -999, -999, -999, -999, -999, -999, -999,
  102945. -999, -999, -999, -999, -999, -999, -999, -999,
  102946. -999, -999, -999, -999, -999, -999, -999, -999,
  102947. -999, -999, -999, -999, -999, -999, -999, -999},
  102948. {-999, -999, -999, -999, -108, -103, -98, -93,
  102949. -88, -83, -79, -78, -75, -71, -67, -68,
  102950. -73, -73, -72, -73, -75, -77, -80, -82,
  102951. -88, -93, -100, -107, -114, -999, -999, -999,
  102952. -999, -999, -999, -999, -999, -999, -999, -999,
  102953. -999, -999, -999, -999, -999, -999, -999, -999,
  102954. -999, -999, -999, -999, -999, -999, -999, -999},
  102955. {-999, -999, -999, -110, -105, -101, -96, -90,
  102956. -86, -81, -77, -73, -69, -66, -61, -62,
  102957. -66, -64, -62, -65, -66, -70, -72, -76,
  102958. -81, -80, -84, -90, -95, -102, -110, -999,
  102959. -999, -999, -999, -999, -999, -999, -999, -999,
  102960. -999, -999, -999, -999, -999, -999, -999, -999,
  102961. -999, -999, -999, -999, -999, -999, -999, -999},
  102962. {-999, -999, -999, -107, -103, -97, -92, -88,
  102963. -83, -79, -74, -70, -66, -59, -53, -58,
  102964. -62, -55, -54, -54, -54, -58, -61, -62,
  102965. -72, -70, -72, -75, -78, -80, -81, -80,
  102966. -83, -83, -88, -93, -100, -107, -115, -999,
  102967. -999, -999, -999, -999, -999, -999, -999, -999,
  102968. -999, -999, -999, -999, -999, -999, -999, -999},
  102969. {-999, -999, -999, -105, -100, -95, -90, -85,
  102970. -80, -75, -70, -66, -62, -56, -48, -44,
  102971. -48, -46, -46, -43, -46, -48, -48, -51,
  102972. -58, -58, -59, -60, -62, -62, -61, -61,
  102973. -65, -64, -65, -68, -70, -74, -75, -78,
  102974. -81, -86, -95, -110, -999, -999, -999, -999,
  102975. -999, -999, -999, -999, -999, -999, -999, -999},
  102976. {-999, -999, -105, -100, -95, -90, -85, -80,
  102977. -75, -70, -65, -61, -55, -49, -39, -33,
  102978. -40, -35, -32, -38, -40, -33, -35, -37,
  102979. -46, -41, -45, -44, -46, -42, -45, -46,
  102980. -52, -50, -50, -50, -54, -54, -55, -57,
  102981. -62, -64, -66, -68, -70, -76, -81, -90,
  102982. -100, -110, -999, -999, -999, -999, -999, -999}},
  102983. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102984. -105, -98, -90, -85, -82, -83, -80, -78,
  102985. -84, -79, -80, -83, -87, -89, -91, -93,
  102986. -99, -106, -117, -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, -999, -999, -999, -999, -999, -999, -999},
  102990. {-999, -999, -999, -999, -999, -999, -999, -999,
  102991. -105, -98, -90, -85, -80, -75, -70, -68,
  102992. -74, -72, -74, -77, -80, -82, -85, -87,
  102993. -92, -89, -91, -95, -100, -106, -112, -999,
  102994. -999, -999, -999, -999, -999, -999, -999, -999,
  102995. -999, -999, -999, -999, -999, -999, -999, -999,
  102996. -999, -999, -999, -999, -999, -999, -999, -999},
  102997. {-999, -999, -999, -999, -999, -999, -999, -999,
  102998. -105, -98, -90, -83, -75, -71, -63, -64,
  102999. -67, -62, -64, -67, -70, -73, -77, -81,
  103000. -84, -83, -85, -89, -90, -93, -98, -104,
  103001. -109, -114, -999, -999, -999, -999, -999, -999,
  103002. -999, -999, -999, -999, -999, -999, -999, -999,
  103003. -999, -999, -999, -999, -999, -999, -999, -999},
  103004. {-999, -999, -999, -999, -999, -999, -999, -999,
  103005. -103, -96, -88, -81, -75, -68, -58, -54,
  103006. -56, -54, -56, -56, -58, -60, -63, -66,
  103007. -74, -69, -72, -72, -75, -74, -77, -81,
  103008. -81, -82, -84, -87, -93, -96, -99, -104,
  103009. -110, -999, -999, -999, -999, -999, -999, -999,
  103010. -999, -999, -999, -999, -999, -999, -999, -999},
  103011. {-999, -999, -999, -999, -999, -108, -102, -96,
  103012. -91, -85, -80, -74, -68, -60, -51, -46,
  103013. -48, -46, -43, -45, -47, -47, -49, -48,
  103014. -56, -53, -55, -58, -57, -63, -58, -60,
  103015. -66, -64, -67, -70, -70, -74, -77, -84,
  103016. -86, -89, -91, -93, -94, -101, -109, -118,
  103017. -999, -999, -999, -999, -999, -999, -999, -999},
  103018. {-999, -999, -999, -108, -103, -98, -93, -88,
  103019. -83, -78, -73, -68, -60, -53, -44, -35,
  103020. -38, -38, -34, -34, -36, -40, -41, -44,
  103021. -51, -45, -46, -47, -46, -54, -50, -49,
  103022. -50, -50, -50, -51, -54, -57, -58, -60,
  103023. -66, -66, -66, -64, -65, -68, -77, -82,
  103024. -87, -95, -110, -999, -999, -999, -999, -999}},
  103025. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103026. -107, -102, -97, -92, -87, -83, -78, -75,
  103027. -82, -79, -83, -85, -89, -92, -95, -98,
  103028. -101, -105, -109, -113, -999, -999, -999, -999,
  103029. -999, -999, -999, -999, -999, -999, -999, -999,
  103030. -999, -999, -999, -999, -999, -999, -999, -999,
  103031. -999, -999, -999, -999, -999, -999, -999, -999},
  103032. {-999, -999, -999, -999, -999, -999, -999, -106,
  103033. -100, -95, -90, -86, -81, -78, -74, -69,
  103034. -74, -74, -76, -79, -83, -84, -86, -89,
  103035. -92, -97, -93, -100, -103, -107, -110, -999,
  103036. -999, -999, -999, -999, -999, -999, -999, -999,
  103037. -999, -999, -999, -999, -999, -999, -999, -999,
  103038. -999, -999, -999, -999, -999, -999, -999, -999},
  103039. {-999, -999, -999, -999, -999, -999, -106, -100,
  103040. -95, -90, -87, -83, -80, -75, -69, -60,
  103041. -66, -66, -68, -70, -74, -78, -79, -81,
  103042. -81, -83, -84, -87, -93, -96, -99, -103,
  103043. -107, -110, -999, -999, -999, -999, -999, -999,
  103044. -999, -999, -999, -999, -999, -999, -999, -999,
  103045. -999, -999, -999, -999, -999, -999, -999, -999},
  103046. {-999, -999, -999, -999, -999, -108, -103, -98,
  103047. -93, -89, -85, -82, -78, -71, -62, -55,
  103048. -58, -58, -54, -54, -55, -59, -61, -62,
  103049. -70, -66, -66, -67, -70, -72, -75, -78,
  103050. -84, -84, -84, -88, -91, -90, -95, -98,
  103051. -102, -103, -106, -110, -999, -999, -999, -999,
  103052. -999, -999, -999, -999, -999, -999, -999, -999},
  103053. {-999, -999, -999, -999, -108, -103, -98, -94,
  103054. -90, -87, -82, -79, -73, -67, -58, -47,
  103055. -50, -45, -41, -45, -48, -44, -44, -49,
  103056. -54, -51, -48, -47, -49, -50, -51, -57,
  103057. -58, -60, -63, -69, -70, -69, -71, -74,
  103058. -78, -82, -90, -95, -101, -105, -110, -999,
  103059. -999, -999, -999, -999, -999, -999, -999, -999},
  103060. {-999, -999, -999, -105, -101, -97, -93, -90,
  103061. -85, -80, -77, -72, -65, -56, -48, -37,
  103062. -40, -36, -34, -40, -50, -47, -38, -41,
  103063. -47, -38, -35, -39, -38, -43, -40, -45,
  103064. -50, -45, -44, -47, -50, -55, -48, -48,
  103065. -52, -66, -70, -76, -82, -90, -97, -105,
  103066. -110, -999, -999, -999, -999, -999, -999, -999}},
  103067. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103068. -999, -108, -103, -98, -93, -86, -79, -76,
  103069. -83, -81, -85, -87, -89, -93, -98, -102,
  103070. -107, -112, -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, -999, -999, -999, -999, -999, -999},
  103074. {-999, -999, -999, -999, -999, -999, -999, -999,
  103075. -999, -108, -103, -98, -93, -86, -79, -71,
  103076. -77, -74, -77, -79, -81, -84, -85, -90,
  103077. -92, -93, -92, -98, -101, -108, -112, -999,
  103078. -999, -999, -999, -999, -999, -999, -999, -999,
  103079. -999, -999, -999, -999, -999, -999, -999, -999,
  103080. -999, -999, -999, -999, -999, -999, -999, -999},
  103081. {-999, -999, -999, -999, -999, -999, -999, -999,
  103082. -108, -103, -98, -93, -87, -78, -68, -65,
  103083. -66, -62, -65, -67, -70, -73, -75, -78,
  103084. -82, -82, -83, -84, -91, -93, -98, -102,
  103085. -106, -110, -999, -999, -999, -999, -999, -999,
  103086. -999, -999, -999, -999, -999, -999, -999, -999,
  103087. -999, -999, -999, -999, -999, -999, -999, -999},
  103088. {-999, -999, -999, -999, -999, -999, -999, -999,
  103089. -105, -100, -95, -90, -82, -74, -62, -57,
  103090. -58, -56, -51, -52, -52, -54, -54, -58,
  103091. -66, -59, -60, -63, -66, -69, -73, -79,
  103092. -83, -84, -80, -81, -81, -82, -88, -92,
  103093. -98, -105, -113, -999, -999, -999, -999, -999,
  103094. -999, -999, -999, -999, -999, -999, -999, -999},
  103095. {-999, -999, -999, -999, -999, -999, -999, -107,
  103096. -102, -97, -92, -84, -79, -69, -57, -47,
  103097. -52, -47, -44, -45, -50, -52, -42, -42,
  103098. -53, -43, -43, -48, -51, -56, -55, -52,
  103099. -57, -59, -61, -62, -67, -71, -78, -83,
  103100. -86, -94, -98, -103, -110, -999, -999, -999,
  103101. -999, -999, -999, -999, -999, -999, -999, -999},
  103102. {-999, -999, -999, -999, -999, -999, -105, -100,
  103103. -95, -90, -84, -78, -70, -61, -51, -41,
  103104. -40, -38, -40, -46, -52, -51, -41, -40,
  103105. -46, -40, -38, -38, -41, -46, -41, -46,
  103106. -47, -43, -43, -45, -41, -45, -56, -67,
  103107. -68, -83, -87, -90, -95, -102, -107, -113,
  103108. -999, -999, -999, -999, -999, -999, -999, -999}},
  103109. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103110. -999, -109, -105, -101, -96, -91, -84, -77,
  103111. -82, -82, -85, -89, -94, -100, -106, -110,
  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, -999, -999, -999, -999, -999, -999},
  103116. {-999, -999, -999, -999, -999, -999, -999, -999,
  103117. -999, -106, -103, -98, -92, -85, -80, -71,
  103118. -75, -72, -76, -80, -84, -86, -89, -93,
  103119. -100, -107, -113, -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, -999, -999, -999, -999, -999, -999, -999},
  103123. {-999, -999, -999, -999, -999, -999, -999, -107,
  103124. -104, -101, -97, -92, -88, -84, -80, -64,
  103125. -66, -63, -64, -66, -69, -73, -77, -83,
  103126. -83, -86, -91, -98, -104, -111, -999, -999,
  103127. -999, -999, -999, -999, -999, -999, -999, -999,
  103128. -999, -999, -999, -999, -999, -999, -999, -999,
  103129. -999, -999, -999, -999, -999, -999, -999, -999},
  103130. {-999, -999, -999, -999, -999, -999, -999, -107,
  103131. -104, -101, -97, -92, -90, -84, -74, -57,
  103132. -58, -52, -55, -54, -50, -52, -50, -52,
  103133. -63, -62, -69, -76, -77, -78, -78, -79,
  103134. -82, -88, -94, -100, -106, -111, -999, -999,
  103135. -999, -999, -999, -999, -999, -999, -999, -999,
  103136. -999, -999, -999, -999, -999, -999, -999, -999},
  103137. {-999, -999, -999, -999, -999, -999, -106, -102,
  103138. -98, -95, -90, -85, -83, -78, -70, -50,
  103139. -50, -41, -44, -49, -47, -50, -50, -44,
  103140. -55, -46, -47, -48, -48, -54, -49, -49,
  103141. -58, -62, -71, -81, -87, -92, -97, -102,
  103142. -108, -114, -999, -999, -999, -999, -999, -999,
  103143. -999, -999, -999, -999, -999, -999, -999, -999},
  103144. {-999, -999, -999, -999, -999, -999, -106, -102,
  103145. -98, -95, -90, -85, -83, -78, -70, -45,
  103146. -43, -41, -47, -50, -51, -50, -49, -45,
  103147. -47, -41, -44, -41, -39, -43, -38, -37,
  103148. -40, -41, -44, -50, -58, -65, -73, -79,
  103149. -85, -92, -97, -101, -105, -109, -113, -999,
  103150. -999, -999, -999, -999, -999, -999, -999, -999}},
  103151. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103152. -999, -999, -999, -107, -100, -95, -87, -81,
  103153. -85, -83, -88, -93, -100, -107, -114, -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, -999, -999, -999, -999},
  103158. {-999, -999, -999, -999, -999, -999, -999, -999,
  103159. -999, -999, -107, -101, -95, -88, -83, -76,
  103160. -73, -72, -79, -84, -90, -95, -100, -105,
  103161. -110, -115, -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, -999, -999, -999, -999},
  103165. {-999, -999, -999, -999, -999, -999, -999, -999,
  103166. -999, -999, -104, -98, -92, -87, -81, -70,
  103167. -65, -62, -67, -71, -74, -80, -85, -91,
  103168. -95, -99, -103, -108, -111, -114, -999, -999,
  103169. -999, -999, -999, -999, -999, -999, -999, -999,
  103170. -999, -999, -999, -999, -999, -999, -999, -999,
  103171. -999, -999, -999, -999, -999, -999, -999, -999},
  103172. {-999, -999, -999, -999, -999, -999, -999, -999,
  103173. -999, -999, -103, -97, -90, -85, -76, -60,
  103174. -56, -54, -60, -62, -61, -56, -63, -65,
  103175. -73, -74, -77, -75, -78, -81, -86, -87,
  103176. -88, -91, -94, -98, -103, -110, -999, -999,
  103177. -999, -999, -999, -999, -999, -999, -999, -999,
  103178. -999, -999, -999, -999, -999, -999, -999, -999},
  103179. {-999, -999, -999, -999, -999, -999, -999, -105,
  103180. -100, -97, -92, -86, -81, -79, -70, -57,
  103181. -51, -47, -51, -58, -60, -56, -53, -50,
  103182. -58, -52, -50, -50, -53, -55, -64, -69,
  103183. -71, -85, -82, -78, -81, -85, -95, -102,
  103184. -112, -999, -999, -999, -999, -999, -999, -999,
  103185. -999, -999, -999, -999, -999, -999, -999, -999},
  103186. {-999, -999, -999, -999, -999, -999, -999, -105,
  103187. -100, -97, -92, -85, -83, -79, -72, -49,
  103188. -40, -43, -43, -54, -56, -51, -50, -40,
  103189. -43, -38, -36, -35, -37, -38, -37, -44,
  103190. -54, -60, -57, -60, -70, -75, -84, -92,
  103191. -103, -112, -999, -999, -999, -999, -999, -999,
  103192. -999, -999, -999, -999, -999, -999, -999, -999}},
  103193. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103194. -999, -999, -999, -110, -102, -95, -89, -82,
  103195. -83, -84, -90, -92, -99, -107, -113, -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, -999, -999, -999},
  103200. {-999, -999, -999, -999, -999, -999, -999, -999,
  103201. -999, -999, -107, -101, -95, -89, -83, -72,
  103202. -74, -78, -85, -88, -88, -90, -92, -98,
  103203. -105, -111, -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, -999, -999, -999, -999},
  103207. {-999, -999, -999, -999, -999, -999, -999, -999,
  103208. -999, -109, -103, -97, -93, -87, -81, -70,
  103209. -70, -67, -75, -73, -76, -79, -81, -83,
  103210. -88, -89, -97, -103, -110, -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, -999, -999, -999, -999},
  103214. {-999, -999, -999, -999, -999, -999, -999, -999,
  103215. -999, -107, -100, -94, -88, -83, -75, -63,
  103216. -59, -59, -63, -66, -60, -62, -67, -67,
  103217. -77, -76, -81, -88, -86, -92, -96, -102,
  103218. -109, -116, -999, -999, -999, -999, -999, -999,
  103219. -999, -999, -999, -999, -999, -999, -999, -999,
  103220. -999, -999, -999, -999, -999, -999, -999, -999},
  103221. {-999, -999, -999, -999, -999, -999, -999, -999,
  103222. -999, -105, -98, -92, -86, -81, -73, -56,
  103223. -52, -47, -55, -60, -58, -52, -51, -45,
  103224. -49, -50, -53, -54, -61, -71, -70, -69,
  103225. -78, -79, -87, -90, -96, -104, -112, -999,
  103226. -999, -999, -999, -999, -999, -999, -999, -999,
  103227. -999, -999, -999, -999, -999, -999, -999, -999},
  103228. {-999, -999, -999, -999, -999, -999, -999, -999,
  103229. -999, -103, -96, -90, -86, -78, -70, -51,
  103230. -42, -47, -48, -55, -54, -54, -53, -42,
  103231. -35, -28, -33, -38, -37, -44, -47, -49,
  103232. -54, -63, -68, -78, -82, -89, -94, -99,
  103233. -104, -109, -114, -999, -999, -999, -999, -999,
  103234. -999, -999, -999, -999, -999, -999, -999, -999}},
  103235. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103236. -999, -999, -999, -999, -110, -100, -90, -79,
  103237. -85, -81, -82, -82, -89, -94, -99, -103,
  103238. -109, -115, -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, -999, -999, -999, -999, -999, -999},
  103242. {-999, -999, -999, -999, -999, -999, -999, -999,
  103243. -999, -999, -999, -999, -105, -97, -85, -72,
  103244. -74, -70, -70, -70, -76, -85, -91, -93,
  103245. -97, -103, -109, -115, -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, -999, -999, -999, -999, -999, -999},
  103249. {-999, -999, -999, -999, -999, -999, -999, -999,
  103250. -999, -999, -999, -999, -112, -93, -81, -68,
  103251. -62, -60, -60, -57, -63, -70, -77, -82,
  103252. -90, -93, -98, -104, -109, -113, -999, -999,
  103253. -999, -999, -999, -999, -999, -999, -999, -999,
  103254. -999, -999, -999, -999, -999, -999, -999, -999,
  103255. -999, -999, -999, -999, -999, -999, -999, -999},
  103256. {-999, -999, -999, -999, -999, -999, -999, -999,
  103257. -999, -999, -999, -113, -100, -93, -84, -63,
  103258. -58, -48, -53, -54, -52, -52, -57, -64,
  103259. -66, -76, -83, -81, -85, -85, -90, -95,
  103260. -98, -101, -103, -106, -108, -111, -999, -999,
  103261. -999, -999, -999, -999, -999, -999, -999, -999,
  103262. -999, -999, -999, -999, -999, -999, -999, -999},
  103263. {-999, -999, -999, -999, -999, -999, -999, -999,
  103264. -999, -999, -999, -105, -95, -86, -74, -53,
  103265. -50, -38, -43, -49, -43, -42, -39, -39,
  103266. -46, -52, -57, -56, -72, -69, -74, -81,
  103267. -87, -92, -94, -97, -99, -102, -105, -108,
  103268. -999, -999, -999, -999, -999, -999, -999, -999,
  103269. -999, -999, -999, -999, -999, -999, -999, -999},
  103270. {-999, -999, -999, -999, -999, -999, -999, -999,
  103271. -999, -999, -108, -99, -90, -76, -66, -45,
  103272. -43, -41, -44, -47, -43, -47, -40, -30,
  103273. -31, -31, -39, -33, -40, -41, -43, -53,
  103274. -59, -70, -73, -77, -79, -82, -84, -87,
  103275. -999, -999, -999, -999, -999, -999, -999, -999,
  103276. -999, -999, -999, -999, -999, -999, -999, -999}},
  103277. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103278. -999, -999, -999, -999, -999, -110, -91, -76,
  103279. -75, -85, -93, -98, -104, -110, -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, -999, -999, -999, -999},
  103284. {-999, -999, -999, -999, -999, -999, -999, -999,
  103285. -999, -999, -999, -999, -999, -110, -91, -70,
  103286. -70, -75, -86, -89, -94, -98, -101, -106,
  103287. -110, -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, -999, -999, -999, -999, -999},
  103291. {-999, -999, -999, -999, -999, -999, -999, -999,
  103292. -999, -999, -999, -999, -110, -95, -80, -60,
  103293. -65, -64, -74, -83, -88, -91, -95, -99,
  103294. -103, -107, -110, -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, -999, -999, -999, -999, -999},
  103298. {-999, -999, -999, -999, -999, -999, -999, -999,
  103299. -999, -999, -999, -999, -110, -95, -80, -58,
  103300. -55, -49, -66, -68, -71, -78, -78, -80,
  103301. -88, -85, -89, -97, -100, -105, -110, -999,
  103302. -999, -999, -999, -999, -999, -999, -999, -999,
  103303. -999, -999, -999, -999, -999, -999, -999, -999,
  103304. -999, -999, -999, -999, -999, -999, -999, -999},
  103305. {-999, -999, -999, -999, -999, -999, -999, -999,
  103306. -999, -999, -999, -999, -110, -95, -80, -53,
  103307. -52, -41, -59, -59, -49, -58, -56, -63,
  103308. -86, -79, -90, -93, -98, -103, -107, -112,
  103309. -999, -999, -999, -999, -999, -999, -999, -999,
  103310. -999, -999, -999, -999, -999, -999, -999, -999,
  103311. -999, -999, -999, -999, -999, -999, -999, -999},
  103312. {-999, -999, -999, -999, -999, -999, -999, -999,
  103313. -999, -999, -999, -110, -97, -91, -73, -45,
  103314. -40, -33, -53, -61, -49, -54, -50, -50,
  103315. -60, -52, -67, -74, -81, -92, -96, -100,
  103316. -105, -110, -999, -999, -999, -999, -999, -999,
  103317. -999, -999, -999, -999, -999, -999, -999, -999,
  103318. -999, -999, -999, -999, -999, -999, -999, -999}},
  103319. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103320. -999, -999, -999, -113, -106, -99, -92, -77,
  103321. -80, -88, -97, -106, -115, -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, -999, -999, -999},
  103326. {-999, -999, -999, -999, -999, -999, -999, -999,
  103327. -999, -999, -116, -109, -102, -95, -89, -74,
  103328. -72, -88, -87, -95, -102, -109, -116, -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, -999, -999, -999},
  103333. {-999, -999, -999, -999, -999, -999, -999, -999,
  103334. -999, -999, -116, -109, -102, -95, -89, -75,
  103335. -66, -74, -77, -78, -86, -87, -90, -96,
  103336. -105, -115, -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, -999, -999, -999},
  103340. {-999, -999, -999, -999, -999, -999, -999, -999,
  103341. -999, -999, -115, -108, -101, -94, -88, -66,
  103342. -56, -61, -70, -65, -78, -72, -83, -84,
  103343. -93, -98, -105, -110, -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, -999, -999, -999, -999},
  103347. {-999, -999, -999, -999, -999, -999, -999, -999,
  103348. -999, -999, -110, -105, -95, -89, -82, -57,
  103349. -52, -52, -59, -56, -59, -58, -69, -67,
  103350. -88, -82, -82, -89, -94, -100, -108, -999,
  103351. -999, -999, -999, -999, -999, -999, -999, -999,
  103352. -999, -999, -999, -999, -999, -999, -999, -999,
  103353. -999, -999, -999, -999, -999, -999, -999, -999},
  103354. {-999, -999, -999, -999, -999, -999, -999, -999,
  103355. -999, -110, -101, -96, -90, -83, -77, -54,
  103356. -43, -38, -50, -48, -52, -48, -42, -42,
  103357. -51, -52, -53, -59, -65, -71, -78, -85,
  103358. -95, -999, -999, -999, -999, -999, -999, -999,
  103359. -999, -999, -999, -999, -999, -999, -999, -999,
  103360. -999, -999, -999, -999, -999, -999, -999, -999}},
  103361. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103362. -999, -999, -999, -999, -120, -105, -86, -68,
  103363. -78, -79, -90, -100, -110, -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, -999, -999, -999, -999, -999},
  103368. {-999, -999, -999, -999, -999, -999, -999, -999,
  103369. -999, -999, -999, -999, -120, -105, -86, -66,
  103370. -73, -77, -88, -96, -105, -115, -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, -999, -999, -999, -999, -999},
  103375. {-999, -999, -999, -999, -999, -999, -999, -999,
  103376. -999, -999, -999, -120, -105, -92, -80, -61,
  103377. -64, -68, -80, -87, -92, -100, -110, -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, -999, -999, -999, -999, -999},
  103382. {-999, -999, -999, -999, -999, -999, -999, -999,
  103383. -999, -999, -999, -120, -104, -91, -79, -52,
  103384. -60, -54, -64, -69, -77, -80, -82, -84,
  103385. -85, -87, -88, -90, -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, -999, -999, -999, -999, -999},
  103389. {-999, -999, -999, -999, -999, -999, -999, -999,
  103390. -999, -999, -999, -118, -100, -87, -77, -49,
  103391. -50, -44, -58, -61, -61, -67, -65, -62,
  103392. -62, -62, -65, -68, -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, -999, -999, -999, -999, -999},
  103396. {-999, -999, -999, -999, -999, -999, -999, -999,
  103397. -999, -999, -999, -115, -98, -84, -62, -49,
  103398. -44, -38, -46, -49, -49, -46, -39, -37,
  103399. -39, -40, -42, -43, -999, -999, -999, -999,
  103400. -999, -999, -999, -999, -999, -999, -999, -999,
  103401. -999, -999, -999, -999, -999, -999, -999, -999,
  103402. -999, -999, -999, -999, -999, -999, -999, -999}},
  103403. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103404. -999, -999, -999, -999, -999, -110, -88, -74,
  103405. -77, -82, -82, -85, -90, -94, -99, -104,
  103406. -999, -999, -999, -999, -999, -999, -999, -999,
  103407. -999, -999, -999, -999, -999, -999, -999, -999,
  103408. -999, -999, -999, -999, -999, -999, -999, -999,
  103409. -999, -999, -999, -999, -999, -999, -999, -999},
  103410. {-999, -999, -999, -999, -999, -999, -999, -999,
  103411. -999, -999, -999, -999, -999, -110, -88, -66,
  103412. -70, -81, -80, -81, -84, -88, -91, -93,
  103413. -999, -999, -999, -999, -999, -999, -999, -999,
  103414. -999, -999, -999, -999, -999, -999, -999, -999,
  103415. -999, -999, -999, -999, -999, -999, -999, -999,
  103416. -999, -999, -999, -999, -999, -999, -999, -999},
  103417. {-999, -999, -999, -999, -999, -999, -999, -999,
  103418. -999, -999, -999, -999, -999, -110, -88, -61,
  103419. -63, -70, -71, -74, -77, -80, -83, -85,
  103420. -999, -999, -999, -999, -999, -999, -999, -999,
  103421. -999, -999, -999, -999, -999, -999, -999, -999,
  103422. -999, -999, -999, -999, -999, -999, -999, -999,
  103423. -999, -999, -999, -999, -999, -999, -999, -999},
  103424. {-999, -999, -999, -999, -999, -999, -999, -999,
  103425. -999, -999, -999, -999, -999, -110, -86, -62,
  103426. -63, -62, -62, -58, -52, -50, -50, -52,
  103427. -54, -999, -999, -999, -999, -999, -999, -999,
  103428. -999, -999, -999, -999, -999, -999, -999, -999,
  103429. -999, -999, -999, -999, -999, -999, -999, -999,
  103430. -999, -999, -999, -999, -999, -999, -999, -999},
  103431. {-999, -999, -999, -999, -999, -999, -999, -999,
  103432. -999, -999, -999, -999, -118, -108, -84, -53,
  103433. -50, -50, -50, -55, -47, -45, -40, -40,
  103434. -40, -999, -999, -999, -999, -999, -999, -999,
  103435. -999, -999, -999, -999, -999, -999, -999, -999,
  103436. -999, -999, -999, -999, -999, -999, -999, -999,
  103437. -999, -999, -999, -999, -999, -999, -999, -999},
  103438. {-999, -999, -999, -999, -999, -999, -999, -999,
  103439. -999, -999, -999, -999, -118, -100, -73, -43,
  103440. -37, -42, -43, -53, -38, -37, -35, -35,
  103441. -38, -999, -999, -999, -999, -999, -999, -999,
  103442. -999, -999, -999, -999, -999, -999, -999, -999,
  103443. -999, -999, -999, -999, -999, -999, -999, -999,
  103444. -999, -999, -999, -999, -999, -999, -999, -999}},
  103445. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103446. -999, -999, -999, -110, -100, -91, -84, -74,
  103447. -80, -80, -80, -80, -80, -999, -999, -999,
  103448. -999, -999, -999, -999, -999, -999, -999, -999,
  103449. -999, -999, -999, -999, -999, -999, -999, -999,
  103450. -999, -999, -999, -999, -999, -999, -999, -999,
  103451. -999, -999, -999, -999, -999, -999, -999, -999},
  103452. {-999, -999, -999, -999, -999, -999, -999, -999,
  103453. -999, -999, -999, -110, -100, -91, -84, -74,
  103454. -68, -68, -68, -68, -68, -999, -999, -999,
  103455. -999, -999, -999, -999, -999, -999, -999, -999,
  103456. -999, -999, -999, -999, -999, -999, -999, -999,
  103457. -999, -999, -999, -999, -999, -999, -999, -999,
  103458. -999, -999, -999, -999, -999, -999, -999, -999},
  103459. {-999, -999, -999, -999, -999, -999, -999, -999,
  103460. -999, -999, -999, -110, -100, -86, -78, -70,
  103461. -60, -45, -30, -21, -999, -999, -999, -999,
  103462. -999, -999, -999, -999, -999, -999, -999, -999,
  103463. -999, -999, -999, -999, -999, -999, -999, -999,
  103464. -999, -999, -999, -999, -999, -999, -999, -999,
  103465. -999, -999, -999, -999, -999, -999, -999, -999},
  103466. {-999, -999, -999, -999, -999, -999, -999, -999,
  103467. -999, -999, -999, -110, -100, -87, -78, -67,
  103468. -48, -38, -29, -21, -999, -999, -999, -999,
  103469. -999, -999, -999, -999, -999, -999, -999, -999,
  103470. -999, -999, -999, -999, -999, -999, -999, -999,
  103471. -999, -999, -999, -999, -999, -999, -999, -999,
  103472. -999, -999, -999, -999, -999, -999, -999, -999},
  103473. {-999, -999, -999, -999, -999, -999, -999, -999,
  103474. -999, -999, -999, -110, -100, -86, -69, -56,
  103475. -45, -35, -33, -29, -999, -999, -999, -999,
  103476. -999, -999, -999, -999, -999, -999, -999, -999,
  103477. -999, -999, -999, -999, -999, -999, -999, -999,
  103478. -999, -999, -999, -999, -999, -999, -999, -999,
  103479. -999, -999, -999, -999, -999, -999, -999, -999},
  103480. {-999, -999, -999, -999, -999, -999, -999, -999,
  103481. -999, -999, -999, -110, -100, -83, -71, -48,
  103482. -27, -38, -37, -34, -999, -999, -999, -999,
  103483. -999, -999, -999, -999, -999, -999, -999, -999,
  103484. -999, -999, -999, -999, -999, -999, -999, -999,
  103485. -999, -999, -999, -999, -999, -999, -999, -999,
  103486. -999, -999, -999, -999, -999, -999, -999, -999}}
  103487. };
  103488. #endif
  103489. /*** End of inlined file: masking.h ***/
  103490. #define NEGINF -9999.f
  103491. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  103492. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  103493. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  103494. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103495. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103496. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  103497. look->channels=vi->channels;
  103498. look->ampmax=-9999.;
  103499. look->gi=gi;
  103500. return(look);
  103501. }
  103502. void _vp_global_free(vorbis_look_psy_global *look){
  103503. if(look){
  103504. memset(look,0,sizeof(*look));
  103505. _ogg_free(look);
  103506. }
  103507. }
  103508. void _vi_gpsy_free(vorbis_info_psy_global *i){
  103509. if(i){
  103510. memset(i,0,sizeof(*i));
  103511. _ogg_free(i);
  103512. }
  103513. }
  103514. void _vi_psy_free(vorbis_info_psy *i){
  103515. if(i){
  103516. memset(i,0,sizeof(*i));
  103517. _ogg_free(i);
  103518. }
  103519. }
  103520. static void min_curve(float *c,
  103521. float *c2){
  103522. int i;
  103523. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  103524. }
  103525. static void max_curve(float *c,
  103526. float *c2){
  103527. int i;
  103528. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103529. }
  103530. static void attenuate_curve(float *c,float att){
  103531. int i;
  103532. for(i=0;i<EHMER_MAX;i++)
  103533. c[i]+=att;
  103534. }
  103535. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103536. float center_boost, float center_decay_rate){
  103537. int i,j,k,m;
  103538. float ath[EHMER_MAX];
  103539. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103540. float athc[P_LEVELS][EHMER_MAX];
  103541. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103542. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103543. memset(workc,0,sizeof(workc));
  103544. for(i=0;i<P_BANDS;i++){
  103545. int ath_offset=i*4;
  103546. for(j=0;j<EHMER_MAX;j++){
  103547. float min=999.;
  103548. for(k=0;k<4;k++)
  103549. if(j+k+ath_offset<MAX_ATH){
  103550. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103551. }else{
  103552. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103553. }
  103554. ath[j]=min;
  103555. }
  103556. for(j=0;j<6;j++)
  103557. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103558. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103559. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103560. for(j=0;j<P_LEVELS;j++){
  103561. for(k=0;k<EHMER_MAX;k++){
  103562. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103563. if(adj<0. && center_boost>0)adj=0.;
  103564. if(adj>0. && center_boost<0)adj=0.;
  103565. workc[i][j][k]+=adj;
  103566. }
  103567. }
  103568. for(j=0;j<P_LEVELS;j++){
  103569. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103570. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103571. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103572. max_curve(athc[j],workc[i][j]);
  103573. }
  103574. for(j=1;j<P_LEVELS;j++){
  103575. min_curve(athc[j],athc[j-1]);
  103576. min_curve(workc[i][j],athc[j]);
  103577. }
  103578. }
  103579. for(i=0;i<P_BANDS;i++){
  103580. int hi_curve,lo_curve,bin;
  103581. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103582. bin=floor(fromOC(i*.5)/binHz);
  103583. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103584. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103585. if(lo_curve>i)lo_curve=i;
  103586. if(lo_curve<0)lo_curve=0;
  103587. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103588. for(m=0;m<P_LEVELS;m++){
  103589. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103590. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103591. for(k=lo_curve;k<=hi_curve;k++){
  103592. int l=0;
  103593. for(j=0;j<EHMER_MAX;j++){
  103594. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103595. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103596. if(lo_bin<0)lo_bin=0;
  103597. if(lo_bin>n)lo_bin=n;
  103598. if(lo_bin<l)l=lo_bin;
  103599. if(hi_bin<0)hi_bin=0;
  103600. if(hi_bin>n)hi_bin=n;
  103601. for(;l<hi_bin && l<n;l++)
  103602. if(brute_buffer[l]>workc[k][m][j])
  103603. brute_buffer[l]=workc[k][m][j];
  103604. }
  103605. for(;l<n;l++)
  103606. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103607. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103608. }
  103609. if(i+1<P_BANDS){
  103610. int l=0;
  103611. k=i+1;
  103612. for(j=0;j<EHMER_MAX;j++){
  103613. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103614. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103615. if(lo_bin<0)lo_bin=0;
  103616. if(lo_bin>n)lo_bin=n;
  103617. if(lo_bin<l)l=lo_bin;
  103618. if(hi_bin<0)hi_bin=0;
  103619. if(hi_bin>n)hi_bin=n;
  103620. for(;l<hi_bin && l<n;l++)
  103621. if(brute_buffer[l]>workc[k][m][j])
  103622. brute_buffer[l]=workc[k][m][j];
  103623. }
  103624. for(;l<n;l++)
  103625. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103626. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103627. }
  103628. for(j=0;j<EHMER_MAX;j++){
  103629. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103630. if(bin<0){
  103631. ret[i][m][j+2]=-999.;
  103632. }else{
  103633. if(bin>=n){
  103634. ret[i][m][j+2]=-999.;
  103635. }else{
  103636. ret[i][m][j+2]=brute_buffer[bin];
  103637. }
  103638. }
  103639. }
  103640. for(j=0;j<EHMER_OFFSET;j++)
  103641. if(ret[i][m][j+2]>-200.f)break;
  103642. ret[i][m][0]=j;
  103643. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103644. if(ret[i][m][j+2]>-200.f)
  103645. break;
  103646. ret[i][m][1]=j;
  103647. }
  103648. }
  103649. return(ret);
  103650. }
  103651. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103652. vorbis_info_psy_global *gi,int n,long rate){
  103653. long i,j,lo=-99,hi=1;
  103654. long maxoc;
  103655. memset(p,0,sizeof(*p));
  103656. p->eighth_octave_lines=gi->eighth_octave_lines;
  103657. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103658. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103659. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103660. p->total_octave_lines=maxoc-p->firstoc+1;
  103661. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103662. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103663. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103664. p->vi=vi;
  103665. p->n=n;
  103666. p->rate=rate;
  103667. p->m_val = 1.;
  103668. if(rate < 26000) p->m_val = 0;
  103669. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103670. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103671. for(i=0,j=0;i<MAX_ATH-1;i++){
  103672. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103673. float base=ATH[i];
  103674. if(j<endpos){
  103675. float delta=(ATH[i+1]-base)/(endpos-j);
  103676. for(;j<endpos && j<n;j++){
  103677. p->ath[j]=base+100.;
  103678. base+=delta;
  103679. }
  103680. }
  103681. }
  103682. for(i=0;i<n;i++){
  103683. float bark=toBARK(rate/(2*n)*i);
  103684. for(;lo+vi->noisewindowlomin<i &&
  103685. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103686. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103687. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103688. p->bark[i]=((lo-1)<<16)+(hi-1);
  103689. }
  103690. for(i=0;i<n;i++)
  103691. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103692. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103693. vi->tone_centerboost,vi->tone_decay);
  103694. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103695. for(i=0;i<P_NOISECURVES;i++)
  103696. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103697. for(i=0;i<n;i++){
  103698. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103699. int inthalfoc;
  103700. float del;
  103701. if(halfoc<0)halfoc=0;
  103702. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103703. inthalfoc=(int)halfoc;
  103704. del=halfoc-inthalfoc;
  103705. for(j=0;j<P_NOISECURVES;j++)
  103706. p->noiseoffset[j][i]=
  103707. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103708. p->vi->noiseoff[j][inthalfoc+1]*del;
  103709. }
  103710. #if 0
  103711. {
  103712. static int ls=0;
  103713. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103714. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103715. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103716. }
  103717. #endif
  103718. }
  103719. void _vp_psy_clear(vorbis_look_psy *p){
  103720. int i,j;
  103721. if(p){
  103722. if(p->ath)_ogg_free(p->ath);
  103723. if(p->octave)_ogg_free(p->octave);
  103724. if(p->bark)_ogg_free(p->bark);
  103725. if(p->tonecurves){
  103726. for(i=0;i<P_BANDS;i++){
  103727. for(j=0;j<P_LEVELS;j++){
  103728. _ogg_free(p->tonecurves[i][j]);
  103729. }
  103730. _ogg_free(p->tonecurves[i]);
  103731. }
  103732. _ogg_free(p->tonecurves);
  103733. }
  103734. if(p->noiseoffset){
  103735. for(i=0;i<P_NOISECURVES;i++){
  103736. _ogg_free(p->noiseoffset[i]);
  103737. }
  103738. _ogg_free(p->noiseoffset);
  103739. }
  103740. memset(p,0,sizeof(*p));
  103741. }
  103742. }
  103743. static void seed_curve(float *seed,
  103744. const float **curves,
  103745. float amp,
  103746. int oc, int n,
  103747. int linesper,float dBoffset){
  103748. int i,post1;
  103749. int seedptr;
  103750. const float *posts,*curve;
  103751. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103752. choice=max(choice,0);
  103753. choice=min(choice,P_LEVELS-1);
  103754. posts=curves[choice];
  103755. curve=posts+2;
  103756. post1=(int)posts[1];
  103757. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103758. for(i=posts[0];i<post1;i++){
  103759. if(seedptr>0){
  103760. float lin=amp+curve[i];
  103761. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103762. }
  103763. seedptr+=linesper;
  103764. if(seedptr>=n)break;
  103765. }
  103766. }
  103767. static void seed_loop(vorbis_look_psy *p,
  103768. const float ***curves,
  103769. const float *f,
  103770. const float *flr,
  103771. float *seed,
  103772. float specmax){
  103773. vorbis_info_psy *vi=p->vi;
  103774. long n=p->n,i;
  103775. float dBoffset=vi->max_curve_dB-specmax;
  103776. for(i=0;i<n;i++){
  103777. float max=f[i];
  103778. long oc=p->octave[i];
  103779. while(i+1<n && p->octave[i+1]==oc){
  103780. i++;
  103781. if(f[i]>max)max=f[i];
  103782. }
  103783. if(max+6.f>flr[i]){
  103784. oc=oc>>p->shiftoc;
  103785. if(oc>=P_BANDS)oc=P_BANDS-1;
  103786. if(oc<0)oc=0;
  103787. seed_curve(seed,
  103788. curves[oc],
  103789. max,
  103790. p->octave[i]-p->firstoc,
  103791. p->total_octave_lines,
  103792. p->eighth_octave_lines,
  103793. dBoffset);
  103794. }
  103795. }
  103796. }
  103797. static void seed_chase(float *seeds, int linesper, long n){
  103798. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103799. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103800. long stack=0;
  103801. long pos=0;
  103802. long i;
  103803. for(i=0;i<n;i++){
  103804. if(stack<2){
  103805. posstack[stack]=i;
  103806. ampstack[stack++]=seeds[i];
  103807. }else{
  103808. while(1){
  103809. if(seeds[i]<ampstack[stack-1]){
  103810. posstack[stack]=i;
  103811. ampstack[stack++]=seeds[i];
  103812. break;
  103813. }else{
  103814. if(i<posstack[stack-1]+linesper){
  103815. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103816. i<posstack[stack-2]+linesper){
  103817. stack--;
  103818. continue;
  103819. }
  103820. }
  103821. posstack[stack]=i;
  103822. ampstack[stack++]=seeds[i];
  103823. break;
  103824. }
  103825. }
  103826. }
  103827. }
  103828. for(i=0;i<stack;i++){
  103829. long endpos;
  103830. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103831. endpos=posstack[i+1];
  103832. }else{
  103833. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103834. discarded in short frames */
  103835. }
  103836. if(endpos>n)endpos=n;
  103837. for(;pos<endpos;pos++)
  103838. seeds[pos]=ampstack[i];
  103839. }
  103840. }
  103841. #include<stdio.h>
  103842. static void max_seeds(vorbis_look_psy *p,
  103843. float *seed,
  103844. float *flr){
  103845. long n=p->total_octave_lines;
  103846. int linesper=p->eighth_octave_lines;
  103847. long linpos=0;
  103848. long pos;
  103849. seed_chase(seed,linesper,n); /* for masking */
  103850. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103851. while(linpos+1<p->n){
  103852. float minV=seed[pos];
  103853. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103854. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103855. while(pos+1<=end){
  103856. pos++;
  103857. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103858. minV=seed[pos];
  103859. }
  103860. end=pos+p->firstoc;
  103861. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103862. if(flr[linpos]<minV)flr[linpos]=minV;
  103863. }
  103864. {
  103865. float minV=seed[p->total_octave_lines-1];
  103866. for(;linpos<p->n;linpos++)
  103867. if(flr[linpos]<minV)flr[linpos]=minV;
  103868. }
  103869. }
  103870. static void bark_noise_hybridmp(int n,const long *b,
  103871. const float *f,
  103872. float *noise,
  103873. const float offset,
  103874. const int fixed){
  103875. float *N=(float*) alloca(n*sizeof(*N));
  103876. float *X=(float*) alloca(n*sizeof(*N));
  103877. float *XX=(float*) alloca(n*sizeof(*N));
  103878. float *Y=(float*) alloca(n*sizeof(*N));
  103879. float *XY=(float*) alloca(n*sizeof(*N));
  103880. float tN, tX, tXX, tY, tXY;
  103881. int i;
  103882. int lo, hi;
  103883. float R, A, B, D;
  103884. float w, x, y;
  103885. tN = tX = tXX = tY = tXY = 0.f;
  103886. y = f[0] + offset;
  103887. if (y < 1.f) y = 1.f;
  103888. w = y * y * .5;
  103889. tN += w;
  103890. tX += w;
  103891. tY += w * y;
  103892. N[0] = tN;
  103893. X[0] = tX;
  103894. XX[0] = tXX;
  103895. Y[0] = tY;
  103896. XY[0] = tXY;
  103897. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103898. y = f[i] + offset;
  103899. if (y < 1.f) y = 1.f;
  103900. w = y * y;
  103901. tN += w;
  103902. tX += w * x;
  103903. tXX += w * x * x;
  103904. tY += w * y;
  103905. tXY += w * x * y;
  103906. N[i] = tN;
  103907. X[i] = tX;
  103908. XX[i] = tXX;
  103909. Y[i] = tY;
  103910. XY[i] = tXY;
  103911. }
  103912. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103913. lo = b[i] >> 16;
  103914. if( lo>=0 ) break;
  103915. hi = b[i] & 0xffff;
  103916. tN = N[hi] + N[-lo];
  103917. tX = X[hi] - X[-lo];
  103918. tXX = XX[hi] + XX[-lo];
  103919. tY = Y[hi] + Y[-lo];
  103920. tXY = XY[hi] - XY[-lo];
  103921. A = tY * tXX - tX * tXY;
  103922. B = tN * tXY - tX * tY;
  103923. D = tN * tXX - tX * tX;
  103924. R = (A + x * B) / D;
  103925. if (R < 0.f)
  103926. R = 0.f;
  103927. noise[i] = R - offset;
  103928. }
  103929. for ( ;; i++, x += 1.f) {
  103930. lo = b[i] >> 16;
  103931. hi = b[i] & 0xffff;
  103932. if(hi>=n)break;
  103933. tN = N[hi] - N[lo];
  103934. tX = X[hi] - X[lo];
  103935. tXX = XX[hi] - XX[lo];
  103936. tY = Y[hi] - Y[lo];
  103937. tXY = XY[hi] - XY[lo];
  103938. A = tY * tXX - tX * tXY;
  103939. B = tN * tXY - tX * tY;
  103940. D = tN * tXX - tX * tX;
  103941. R = (A + x * B) / D;
  103942. if (R < 0.f) R = 0.f;
  103943. noise[i] = R - offset;
  103944. }
  103945. for ( ; i < n; i++, x += 1.f) {
  103946. R = (A + x * B) / D;
  103947. if (R < 0.f) R = 0.f;
  103948. noise[i] = R - offset;
  103949. }
  103950. if (fixed <= 0) return;
  103951. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103952. hi = i + fixed / 2;
  103953. lo = hi - fixed;
  103954. if(lo>=0)break;
  103955. tN = N[hi] + N[-lo];
  103956. tX = X[hi] - X[-lo];
  103957. tXX = XX[hi] + XX[-lo];
  103958. tY = Y[hi] + Y[-lo];
  103959. tXY = XY[hi] - XY[-lo];
  103960. A = tY * tXX - tX * tXY;
  103961. B = tN * tXY - tX * tY;
  103962. D = tN * tXX - tX * tX;
  103963. R = (A + x * B) / D;
  103964. if (R - offset < noise[i]) noise[i] = R - offset;
  103965. }
  103966. for ( ;; i++, x += 1.f) {
  103967. hi = i + fixed / 2;
  103968. lo = hi - fixed;
  103969. if(hi>=n)break;
  103970. tN = N[hi] - N[lo];
  103971. tX = X[hi] - X[lo];
  103972. tXX = XX[hi] - XX[lo];
  103973. tY = Y[hi] - Y[lo];
  103974. tXY = XY[hi] - XY[lo];
  103975. A = tY * tXX - tX * tXY;
  103976. B = tN * tXY - tX * tY;
  103977. D = tN * tXX - tX * tX;
  103978. R = (A + x * B) / D;
  103979. if (R - offset < noise[i]) noise[i] = R - offset;
  103980. }
  103981. for ( ; i < n; i++, x += 1.f) {
  103982. R = (A + x * B) / D;
  103983. if (R - offset < noise[i]) noise[i] = R - offset;
  103984. }
  103985. }
  103986. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103987. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103988. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103989. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103990. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103991. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103992. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103993. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103994. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103995. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103996. 973377.F, 913981.F, 858210.F, 805842.F,
  103997. 756669.F, 710497.F, 667142.F, 626433.F,
  103998. 588208.F, 552316.F, 518613.F, 486967.F,
  103999. 457252.F, 429351.F, 403152.F, 378551.F,
  104000. 355452.F, 333762.F, 313396.F, 294273.F,
  104001. 276316.F, 259455.F, 243623.F, 228757.F,
  104002. 214798.F, 201691.F, 189384.F, 177828.F,
  104003. 166977.F, 156788.F, 147221.F, 138237.F,
  104004. 129802.F, 121881.F, 114444.F, 107461.F,
  104005. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  104006. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  104007. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  104008. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  104009. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  104010. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  104011. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  104012. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  104013. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  104014. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  104015. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  104016. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  104017. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  104018. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  104019. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  104020. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  104021. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  104022. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  104023. 1084.32F, 1018.15F, 956.024F, 897.687F,
  104024. 842.910F, 791.475F, 743.179F, 697.830F,
  104025. 655.249F, 615.265F, 577.722F, 542.469F,
  104026. 509.367F, 478.286F, 449.101F, 421.696F,
  104027. 395.964F, 371.803F, 349.115F, 327.812F,
  104028. 307.809F, 289.026F, 271.390F, 254.830F,
  104029. 239.280F, 224.679F, 210.969F, 198.096F,
  104030. 186.008F, 174.658F, 164.000F, 153.993F,
  104031. 144.596F, 135.773F, 127.488F, 119.708F,
  104032. 112.404F, 105.545F, 99.1046F, 93.0572F,
  104033. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  104034. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  104035. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  104036. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  104037. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  104038. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  104039. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  104040. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  104041. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  104042. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  104043. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  104044. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  104045. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  104046. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  104047. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  104048. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  104049. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  104050. 1.20790F, 1.13419F, 1.06499F, 1.F
  104051. };
  104052. void _vp_remove_floor(vorbis_look_psy *p,
  104053. float *mdct,
  104054. int *codedflr,
  104055. float *residue,
  104056. int sliding_lowpass){
  104057. int i,n=p->n;
  104058. if(sliding_lowpass>n)sliding_lowpass=n;
  104059. for(i=0;i<sliding_lowpass;i++){
  104060. residue[i]=
  104061. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  104062. }
  104063. for(;i<n;i++)
  104064. residue[i]=0.;
  104065. }
  104066. void _vp_noisemask(vorbis_look_psy *p,
  104067. float *logmdct,
  104068. float *logmask){
  104069. int i,n=p->n;
  104070. float *work=(float*) alloca(n*sizeof(*work));
  104071. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  104072. 140.,-1);
  104073. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  104074. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  104075. p->vi->noisewindowfixed);
  104076. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  104077. #if 0
  104078. {
  104079. static int seq=0;
  104080. float work2[n];
  104081. for(i=0;i<n;i++){
  104082. work2[i]=logmask[i]+work[i];
  104083. }
  104084. if(seq&1)
  104085. _analysis_output("median2R",seq/2,work,n,1,0,0);
  104086. else
  104087. _analysis_output("median2L",seq/2,work,n,1,0,0);
  104088. if(seq&1)
  104089. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  104090. else
  104091. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  104092. seq++;
  104093. }
  104094. #endif
  104095. for(i=0;i<n;i++){
  104096. int dB=logmask[i]+.5;
  104097. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  104098. if(dB<0)dB=0;
  104099. logmask[i]= work[i]+p->vi->noisecompand[dB];
  104100. }
  104101. }
  104102. void _vp_tonemask(vorbis_look_psy *p,
  104103. float *logfft,
  104104. float *logmask,
  104105. float global_specmax,
  104106. float local_specmax){
  104107. int i,n=p->n;
  104108. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  104109. float att=local_specmax+p->vi->ath_adjatt;
  104110. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  104111. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  104112. for(i=0;i<n;i++)
  104113. logmask[i]=p->ath[i]+att;
  104114. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  104115. max_seeds(p,seed,logmask);
  104116. }
  104117. void _vp_offset_and_mix(vorbis_look_psy *p,
  104118. float *noise,
  104119. float *tone,
  104120. int offset_select,
  104121. float *logmask,
  104122. float *mdct,
  104123. float *logmdct){
  104124. int i,n=p->n;
  104125. float de, coeffi, cx;/* AoTuV */
  104126. float toneatt=p->vi->tone_masteratt[offset_select];
  104127. cx = p->m_val;
  104128. for(i=0;i<n;i++){
  104129. float val= noise[i]+p->noiseoffset[offset_select][i];
  104130. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  104131. logmask[i]=max(val,tone[i]+toneatt);
  104132. if(offset_select == 1) {
  104133. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  104134. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  104135. if(val > coeffi){
  104136. de = 1.0-((val-coeffi)*0.005*cx);
  104137. if(de < 0) de = 0.0001;
  104138. }else
  104139. de = 1.0-((val-coeffi)*0.0003*cx);
  104140. mdct[i] *= de;
  104141. }
  104142. }
  104143. }
  104144. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  104145. vorbis_info *vi=vd->vi;
  104146. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  104147. vorbis_info_psy_global *gi=&ci->psy_g_param;
  104148. int n=ci->blocksizes[vd->W]/2;
  104149. float secs=(float)n/vi->rate;
  104150. amp+=secs*gi->ampmax_att_per_sec;
  104151. if(amp<-9999)amp=-9999;
  104152. return(amp);
  104153. }
  104154. static void couple_lossless(float A, float B,
  104155. float *qA, float *qB){
  104156. int test1=fabs(*qA)>fabs(*qB);
  104157. test1-= fabs(*qA)<fabs(*qB);
  104158. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  104159. if(test1==1){
  104160. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  104161. }else{
  104162. float temp=*qB;
  104163. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  104164. *qA=temp;
  104165. }
  104166. if(*qB>fabs(*qA)*1.9999f){
  104167. *qB= -fabs(*qA)*2.f;
  104168. *qA= -*qA;
  104169. }
  104170. }
  104171. static float hypot_lookup[32]={
  104172. -0.009935, -0.011245, -0.012726, -0.014397,
  104173. -0.016282, -0.018407, -0.020800, -0.023494,
  104174. -0.026522, -0.029923, -0.033737, -0.038010,
  104175. -0.042787, -0.048121, -0.054064, -0.060671,
  104176. -0.068000, -0.076109, -0.085054, -0.094892,
  104177. -0.105675, -0.117451, -0.130260, -0.144134,
  104178. -0.159093, -0.175146, -0.192286, -0.210490,
  104179. -0.229718, -0.249913, -0.271001, -0.292893};
  104180. static void precomputed_couple_point(float premag,
  104181. int floorA,int floorB,
  104182. float *mag, float *ang){
  104183. int test=(floorA>floorB)-1;
  104184. int offset=31-abs(floorA-floorB);
  104185. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  104186. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  104187. *mag=premag*floormag;
  104188. *ang=0.f;
  104189. }
  104190. static float dipole_hypot(float a, float b){
  104191. if(a>0.){
  104192. if(b>0.)return sqrt(a*a+b*b);
  104193. if(a>-b)return sqrt(a*a-b*b);
  104194. return -sqrt(b*b-a*a);
  104195. }
  104196. if(b<0.)return -sqrt(a*a+b*b);
  104197. if(-a>b)return -sqrt(a*a-b*b);
  104198. return sqrt(b*b-a*a);
  104199. }
  104200. static float round_hypot(float a, float b){
  104201. if(a>0.){
  104202. if(b>0.)return sqrt(a*a+b*b);
  104203. if(a>-b)return sqrt(a*a+b*b);
  104204. return -sqrt(b*b+a*a);
  104205. }
  104206. if(b<0.)return -sqrt(a*a+b*b);
  104207. if(-a>b)return -sqrt(a*a+b*b);
  104208. return sqrt(b*b+a*a);
  104209. }
  104210. float **_vp_quantize_couple_memo(vorbis_block *vb,
  104211. vorbis_info_psy_global *g,
  104212. vorbis_look_psy *p,
  104213. vorbis_info_mapping0 *vi,
  104214. float **mdct){
  104215. int i,j,n=p->n;
  104216. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104217. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104218. for(i=0;i<vi->coupling_steps;i++){
  104219. float *mdctM=mdct[vi->coupling_mag[i]];
  104220. float *mdctA=mdct[vi->coupling_ang[i]];
  104221. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104222. for(j=0;j<limit;j++)
  104223. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  104224. for(;j<n;j++)
  104225. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  104226. }
  104227. return(ret);
  104228. }
  104229. static int apsort(const void *a, const void *b){
  104230. float f1=fabs(**(float**)a);
  104231. float f2=fabs(**(float**)b);
  104232. return (f1<f2)-(f1>f2);
  104233. }
  104234. int **_vp_quantize_couple_sort(vorbis_block *vb,
  104235. vorbis_look_psy *p,
  104236. vorbis_info_mapping0 *vi,
  104237. float **mags){
  104238. if(p->vi->normal_point_p){
  104239. int i,j,k,n=p->n;
  104240. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104241. int partition=p->vi->normal_partition;
  104242. float **work=(float**) alloca(sizeof(*work)*partition);
  104243. for(i=0;i<vi->coupling_steps;i++){
  104244. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104245. for(j=0;j<n;j+=partition){
  104246. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  104247. qsort(work,partition,sizeof(*work),apsort);
  104248. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  104249. }
  104250. }
  104251. return(ret);
  104252. }
  104253. return(NULL);
  104254. }
  104255. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  104256. float *magnitudes,int *sortedindex){
  104257. int i,j,n=p->n;
  104258. vorbis_info_psy *vi=p->vi;
  104259. int partition=vi->normal_partition;
  104260. float **work=(float**) alloca(sizeof(*work)*partition);
  104261. int start=vi->normal_start;
  104262. for(j=start;j<n;j+=partition){
  104263. if(j+partition>n)partition=n-j;
  104264. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  104265. qsort(work,partition,sizeof(*work),apsort);
  104266. for(i=0;i<partition;i++){
  104267. sortedindex[i+j-start]=work[i]-magnitudes;
  104268. }
  104269. }
  104270. }
  104271. void _vp_noise_normalize(vorbis_look_psy *p,
  104272. float *in,float *out,int *sortedindex){
  104273. int flag=0,i,j=0,n=p->n;
  104274. vorbis_info_psy *vi=p->vi;
  104275. int partition=vi->normal_partition;
  104276. int start=vi->normal_start;
  104277. if(start>n)start=n;
  104278. if(vi->normal_channel_p){
  104279. for(;j<start;j++)
  104280. out[j]=rint(in[j]);
  104281. for(;j+partition<=n;j+=partition){
  104282. float acc=0.;
  104283. int k;
  104284. for(i=j;i<j+partition;i++)
  104285. acc+=in[i]*in[i];
  104286. for(i=0;i<partition;i++){
  104287. k=sortedindex[i+j-start];
  104288. if(in[k]*in[k]>=.25f){
  104289. out[k]=rint(in[k]);
  104290. acc-=in[k]*in[k];
  104291. flag=1;
  104292. }else{
  104293. if(acc<vi->normal_thresh)break;
  104294. out[k]=unitnorm(in[k]);
  104295. acc-=1.;
  104296. }
  104297. }
  104298. for(;i<partition;i++){
  104299. k=sortedindex[i+j-start];
  104300. out[k]=0.;
  104301. }
  104302. }
  104303. }
  104304. for(;j<n;j++)
  104305. out[j]=rint(in[j]);
  104306. }
  104307. void _vp_couple(int blobno,
  104308. vorbis_info_psy_global *g,
  104309. vorbis_look_psy *p,
  104310. vorbis_info_mapping0 *vi,
  104311. float **res,
  104312. float **mag_memo,
  104313. int **mag_sort,
  104314. int **ifloor,
  104315. int *nonzero,
  104316. int sliding_lowpass){
  104317. int i,j,k,n=p->n;
  104318. for(i=0;i<vi->coupling_steps;i++){
  104319. if(nonzero[vi->coupling_mag[i]] ||
  104320. nonzero[vi->coupling_ang[i]]){
  104321. float *rM=res[vi->coupling_mag[i]];
  104322. float *rA=res[vi->coupling_ang[i]];
  104323. float *qM=rM+n;
  104324. float *qA=rA+n;
  104325. int *floorM=ifloor[vi->coupling_mag[i]];
  104326. int *floorA=ifloor[vi->coupling_ang[i]];
  104327. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  104328. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  104329. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  104330. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  104331. int pointlimit=limit;
  104332. nonzero[vi->coupling_mag[i]]=1;
  104333. nonzero[vi->coupling_ang[i]]=1;
  104334. if(n > 1000)
  104335. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  104336. for(j=0;j<p->n;j+=partition){
  104337. float acc=0.f;
  104338. for(k=0;k<partition;k++){
  104339. int l=k+j;
  104340. if(l<sliding_lowpass){
  104341. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  104342. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  104343. precomputed_couple_point(mag_memo[i][l],
  104344. floorM[l],floorA[l],
  104345. qM+l,qA+l);
  104346. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  104347. }else{
  104348. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  104349. }
  104350. }else{
  104351. qM[l]=0.;
  104352. qA[l]=0.;
  104353. }
  104354. }
  104355. if(p->vi->normal_point_p){
  104356. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  104357. int l=mag_sort[i][j+k];
  104358. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  104359. qM[l]=unitnorm(qM[l]);
  104360. acc-=1.f;
  104361. }
  104362. }
  104363. }
  104364. }
  104365. }
  104366. }
  104367. }
  104368. void hf_reduction(vorbis_info_psy_global *g,
  104369. vorbis_look_psy *p,
  104370. vorbis_info_mapping0 *vi,
  104371. float **mdct){
  104372. int i,j,n=p->n, de=0.3*p->m_val;
  104373. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104374. for(i=0; i<vi->coupling_steps; i++){
  104375. for(j=limit; j<n; j++)
  104376. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  104377. }
  104378. }
  104379. #endif
  104380. /*** End of inlined file: psy.c ***/
  104381. /*** Start of inlined file: registry.c ***/
  104382. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104383. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104384. // tasks..
  104385. #if JUCE_MSVC
  104386. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104387. #endif
  104388. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104389. #if JUCE_USE_OGGVORBIS
  104390. extern vorbis_func_floor floor0_exportbundle;
  104391. extern vorbis_func_floor floor1_exportbundle;
  104392. extern vorbis_func_residue residue0_exportbundle;
  104393. extern vorbis_func_residue residue1_exportbundle;
  104394. extern vorbis_func_residue residue2_exportbundle;
  104395. extern vorbis_func_mapping mapping0_exportbundle;
  104396. vorbis_func_floor *_floor_P[]={
  104397. &floor0_exportbundle,
  104398. &floor1_exportbundle,
  104399. };
  104400. vorbis_func_residue *_residue_P[]={
  104401. &residue0_exportbundle,
  104402. &residue1_exportbundle,
  104403. &residue2_exportbundle,
  104404. };
  104405. vorbis_func_mapping *_mapping_P[]={
  104406. &mapping0_exportbundle,
  104407. };
  104408. #endif
  104409. /*** End of inlined file: registry.c ***/
  104410. /*** Start of inlined file: res0.c ***/
  104411. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104412. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104413. // tasks..
  104414. #if JUCE_MSVC
  104415. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104416. #endif
  104417. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104418. #if JUCE_USE_OGGVORBIS
  104419. #include <stdlib.h>
  104420. #include <string.h>
  104421. #include <math.h>
  104422. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104423. #include <stdio.h>
  104424. #endif
  104425. typedef struct {
  104426. vorbis_info_residue0 *info;
  104427. int parts;
  104428. int stages;
  104429. codebook *fullbooks;
  104430. codebook *phrasebook;
  104431. codebook ***partbooks;
  104432. int partvals;
  104433. int **decodemap;
  104434. long postbits;
  104435. long phrasebits;
  104436. long frames;
  104437. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  104438. int train_seq;
  104439. long *training_data[8][64];
  104440. float training_max[8][64];
  104441. float training_min[8][64];
  104442. float tmin;
  104443. float tmax;
  104444. #endif
  104445. } vorbis_look_residue0;
  104446. void res0_free_info(vorbis_info_residue *i){
  104447. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  104448. if(info){
  104449. memset(info,0,sizeof(*info));
  104450. _ogg_free(info);
  104451. }
  104452. }
  104453. void res0_free_look(vorbis_look_residue *i){
  104454. int j;
  104455. if(i){
  104456. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  104457. #ifdef TRAIN_RES
  104458. {
  104459. int j,k,l;
  104460. for(j=0;j<look->parts;j++){
  104461. for(k=0;k<8;k++)
  104462. if(look->training_data[k][j]){
  104463. char buffer[80];
  104464. FILE *of;
  104465. codebook *statebook=look->partbooks[j][k];
  104466. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  104467. of=fopen(buffer,"a");
  104468. for(l=0;l<statebook->entries;l++)
  104469. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  104470. fclose(of);
  104471. _ogg_free(look->training_data[k][j]);
  104472. look->training_data[k][j]=NULL;
  104473. }
  104474. }
  104475. }
  104476. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  104477. #endif
  104478. for(j=0;j<look->parts;j++)
  104479. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  104480. _ogg_free(look->partbooks);
  104481. for(j=0;j<look->partvals;j++)
  104482. _ogg_free(look->decodemap[j]);
  104483. _ogg_free(look->decodemap);
  104484. memset(look,0,sizeof(*look));
  104485. _ogg_free(look);
  104486. }
  104487. }
  104488. static int icount(unsigned int v){
  104489. int ret=0;
  104490. while(v){
  104491. ret+=v&1;
  104492. v>>=1;
  104493. }
  104494. return(ret);
  104495. }
  104496. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  104497. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104498. int j,acc=0;
  104499. oggpack_write(opb,info->begin,24);
  104500. oggpack_write(opb,info->end,24);
  104501. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  104502. code with a partitioned book */
  104503. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  104504. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  104505. for(j=0;j<info->partitions;j++){
  104506. if(ilog(info->secondstages[j])>3){
  104507. oggpack_write(opb,info->secondstages[j],3);
  104508. oggpack_write(opb,1,1);
  104509. oggpack_write(opb,info->secondstages[j]>>3,5);
  104510. }else
  104511. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  104512. acc+=icount(info->secondstages[j]);
  104513. }
  104514. for(j=0;j<acc;j++)
  104515. oggpack_write(opb,info->booklist[j],8);
  104516. }
  104517. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  104518. int j,acc=0;
  104519. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  104520. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  104521. info->begin=oggpack_read(opb,24);
  104522. info->end=oggpack_read(opb,24);
  104523. info->grouping=oggpack_read(opb,24)+1;
  104524. info->partitions=oggpack_read(opb,6)+1;
  104525. info->groupbook=oggpack_read(opb,8);
  104526. for(j=0;j<info->partitions;j++){
  104527. int cascade=oggpack_read(opb,3);
  104528. if(oggpack_read(opb,1))
  104529. cascade|=(oggpack_read(opb,5)<<3);
  104530. info->secondstages[j]=cascade;
  104531. acc+=icount(cascade);
  104532. }
  104533. for(j=0;j<acc;j++)
  104534. info->booklist[j]=oggpack_read(opb,8);
  104535. if(info->groupbook>=ci->books)goto errout;
  104536. for(j=0;j<acc;j++)
  104537. if(info->booklist[j]>=ci->books)goto errout;
  104538. return(info);
  104539. errout:
  104540. res0_free_info(info);
  104541. return(NULL);
  104542. }
  104543. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104544. vorbis_info_residue *vr){
  104545. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104546. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104547. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104548. int j,k,acc=0;
  104549. int dim;
  104550. int maxstage=0;
  104551. look->info=info;
  104552. look->parts=info->partitions;
  104553. look->fullbooks=ci->fullbooks;
  104554. look->phrasebook=ci->fullbooks+info->groupbook;
  104555. dim=look->phrasebook->dim;
  104556. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104557. for(j=0;j<look->parts;j++){
  104558. int stages=ilog(info->secondstages[j]);
  104559. if(stages){
  104560. if(stages>maxstage)maxstage=stages;
  104561. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104562. for(k=0;k<stages;k++)
  104563. if(info->secondstages[j]&(1<<k)){
  104564. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104565. #ifdef TRAIN_RES
  104566. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104567. sizeof(***look->training_data));
  104568. #endif
  104569. }
  104570. }
  104571. }
  104572. look->partvals=rint(pow((float)look->parts,(float)dim));
  104573. look->stages=maxstage;
  104574. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104575. for(j=0;j<look->partvals;j++){
  104576. long val=j;
  104577. long mult=look->partvals/look->parts;
  104578. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104579. for(k=0;k<dim;k++){
  104580. long deco=val/mult;
  104581. val-=deco*mult;
  104582. mult/=look->parts;
  104583. look->decodemap[j][k]=deco;
  104584. }
  104585. }
  104586. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104587. {
  104588. static int train_seq=0;
  104589. look->train_seq=train_seq++;
  104590. }
  104591. #endif
  104592. return(look);
  104593. }
  104594. static int local_book_besterror(codebook *book,float *a){
  104595. int dim=book->dim,i,k,o;
  104596. int best=0;
  104597. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104598. for(k=0,o=dim;k<dim;++k){
  104599. float val=a[--o];
  104600. i=tt->threshvals>>1;
  104601. if(val<tt->quantthresh[i]){
  104602. if(val<tt->quantthresh[i-1]){
  104603. for(--i;i>0;--i)
  104604. if(val>=tt->quantthresh[i-1])
  104605. break;
  104606. }
  104607. }else{
  104608. for(++i;i<tt->threshvals-1;++i)
  104609. if(val<tt->quantthresh[i])break;
  104610. }
  104611. best=(best*tt->quantvals)+tt->quantmap[i];
  104612. }
  104613. if(book->c->lengthlist[best]<=0){
  104614. const static_codebook *c=book->c;
  104615. int i,j;
  104616. float bestf=0.f;
  104617. float *e=book->valuelist;
  104618. best=-1;
  104619. for(i=0;i<book->entries;i++){
  104620. if(c->lengthlist[i]>0){
  104621. float thisx=0.f;
  104622. for(j=0;j<dim;j++){
  104623. float val=(e[j]-a[j]);
  104624. thisx+=val*val;
  104625. }
  104626. if(best==-1 || thisx<bestf){
  104627. bestf=thisx;
  104628. best=i;
  104629. }
  104630. }
  104631. e+=dim;
  104632. }
  104633. }
  104634. {
  104635. float *ptr=book->valuelist+best*dim;
  104636. for(i=0;i<dim;i++)
  104637. *a++ -= *ptr++;
  104638. }
  104639. return(best);
  104640. }
  104641. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104642. codebook *book,long *acc){
  104643. int i,bits=0;
  104644. int dim=book->dim;
  104645. int step=n/dim;
  104646. for(i=0;i<step;i++){
  104647. int entry=local_book_besterror(book,vec+i*dim);
  104648. #ifdef TRAIN_RES
  104649. acc[entry]++;
  104650. #endif
  104651. bits+=vorbis_book_encode(book,entry,opb);
  104652. }
  104653. return(bits);
  104654. }
  104655. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104656. float **in,int ch){
  104657. long i,j,k;
  104658. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104659. vorbis_info_residue0 *info=look->info;
  104660. int samples_per_partition=info->grouping;
  104661. int possible_partitions=info->partitions;
  104662. int n=info->end-info->begin;
  104663. int partvals=n/samples_per_partition;
  104664. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104665. float scale=100./samples_per_partition;
  104666. for(i=0;i<ch;i++){
  104667. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104668. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104669. }
  104670. for(i=0;i<partvals;i++){
  104671. int offset=i*samples_per_partition+info->begin;
  104672. for(j=0;j<ch;j++){
  104673. float max=0.;
  104674. float ent=0.;
  104675. for(k=0;k<samples_per_partition;k++){
  104676. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104677. ent+=fabs(rint(in[j][offset+k]));
  104678. }
  104679. ent*=scale;
  104680. for(k=0;k<possible_partitions-1;k++)
  104681. if(max<=info->classmetric1[k] &&
  104682. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104683. break;
  104684. partword[j][i]=k;
  104685. }
  104686. }
  104687. #ifdef TRAIN_RESAUX
  104688. {
  104689. FILE *of;
  104690. char buffer[80];
  104691. for(i=0;i<ch;i++){
  104692. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104693. of=fopen(buffer,"a");
  104694. for(j=0;j<partvals;j++)
  104695. fprintf(of,"%ld, ",partword[i][j]);
  104696. fprintf(of,"\n");
  104697. fclose(of);
  104698. }
  104699. }
  104700. #endif
  104701. look->frames++;
  104702. return(partword);
  104703. }
  104704. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104705. int ch){
  104706. long i,j,k,l;
  104707. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104708. vorbis_info_residue0 *info=look->info;
  104709. int samples_per_partition=info->grouping;
  104710. int possible_partitions=info->partitions;
  104711. int n=info->end-info->begin;
  104712. int partvals=n/samples_per_partition;
  104713. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104714. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104715. FILE *of;
  104716. char buffer[80];
  104717. #endif
  104718. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104719. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104720. for(i=0,l=info->begin/ch;i<partvals;i++){
  104721. float magmax=0.f;
  104722. float angmax=0.f;
  104723. for(j=0;j<samples_per_partition;j+=ch){
  104724. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104725. for(k=1;k<ch;k++)
  104726. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104727. l++;
  104728. }
  104729. for(j=0;j<possible_partitions-1;j++)
  104730. if(magmax<=info->classmetric1[j] &&
  104731. angmax<=info->classmetric2[j])
  104732. break;
  104733. partword[0][i]=j;
  104734. }
  104735. #ifdef TRAIN_RESAUX
  104736. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104737. of=fopen(buffer,"a");
  104738. for(i=0;i<partvals;i++)
  104739. fprintf(of,"%ld, ",partword[0][i]);
  104740. fprintf(of,"\n");
  104741. fclose(of);
  104742. #endif
  104743. look->frames++;
  104744. return(partword);
  104745. }
  104746. static int _01forward(oggpack_buffer *opb,
  104747. vorbis_block *vb,vorbis_look_residue *vl,
  104748. float **in,int ch,
  104749. long **partword,
  104750. int (*encode)(oggpack_buffer *,float *,int,
  104751. codebook *,long *)){
  104752. long i,j,k,s;
  104753. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104754. vorbis_info_residue0 *info=look->info;
  104755. int samples_per_partition=info->grouping;
  104756. int possible_partitions=info->partitions;
  104757. int partitions_per_word=look->phrasebook->dim;
  104758. int n=info->end-info->begin;
  104759. int partvals=n/samples_per_partition;
  104760. long resbits[128];
  104761. long resvals[128];
  104762. #ifdef TRAIN_RES
  104763. for(i=0;i<ch;i++)
  104764. for(j=info->begin;j<info->end;j++){
  104765. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104766. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104767. }
  104768. #endif
  104769. memset(resbits,0,sizeof(resbits));
  104770. memset(resvals,0,sizeof(resvals));
  104771. for(s=0;s<look->stages;s++){
  104772. for(i=0;i<partvals;){
  104773. if(s==0){
  104774. for(j=0;j<ch;j++){
  104775. long val=partword[j][i];
  104776. for(k=1;k<partitions_per_word;k++){
  104777. val*=possible_partitions;
  104778. if(i+k<partvals)
  104779. val+=partword[j][i+k];
  104780. }
  104781. if(val<look->phrasebook->entries)
  104782. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104783. #if 0 /*def TRAIN_RES*/
  104784. else
  104785. fprintf(stderr,"!");
  104786. #endif
  104787. }
  104788. }
  104789. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104790. long offset=i*samples_per_partition+info->begin;
  104791. for(j=0;j<ch;j++){
  104792. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104793. if(info->secondstages[partword[j][i]]&(1<<s)){
  104794. codebook *statebook=look->partbooks[partword[j][i]][s];
  104795. if(statebook){
  104796. int ret;
  104797. long *accumulator=NULL;
  104798. #ifdef TRAIN_RES
  104799. accumulator=look->training_data[s][partword[j][i]];
  104800. {
  104801. int l;
  104802. float *samples=in[j]+offset;
  104803. for(l=0;l<samples_per_partition;l++){
  104804. if(samples[l]<look->training_min[s][partword[j][i]])
  104805. look->training_min[s][partword[j][i]]=samples[l];
  104806. if(samples[l]>look->training_max[s][partword[j][i]])
  104807. look->training_max[s][partword[j][i]]=samples[l];
  104808. }
  104809. }
  104810. #endif
  104811. ret=encode(opb,in[j]+offset,samples_per_partition,
  104812. statebook,accumulator);
  104813. look->postbits+=ret;
  104814. resbits[partword[j][i]]+=ret;
  104815. }
  104816. }
  104817. }
  104818. }
  104819. }
  104820. }
  104821. return(0);
  104822. }
  104823. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104824. float **in,int ch,
  104825. long (*decodepart)(codebook *, float *,
  104826. oggpack_buffer *,int)){
  104827. long i,j,k,l,s;
  104828. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104829. vorbis_info_residue0 *info=look->info;
  104830. int samples_per_partition=info->grouping;
  104831. int partitions_per_word=look->phrasebook->dim;
  104832. int n=info->end-info->begin;
  104833. int partvals=n/samples_per_partition;
  104834. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104835. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104836. for(j=0;j<ch;j++)
  104837. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104838. for(s=0;s<look->stages;s++){
  104839. for(i=0,l=0;i<partvals;l++){
  104840. if(s==0){
  104841. for(j=0;j<ch;j++){
  104842. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104843. if(temp==-1)goto eopbreak;
  104844. partword[j][l]=look->decodemap[temp];
  104845. if(partword[j][l]==NULL)goto errout;
  104846. }
  104847. }
  104848. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104849. for(j=0;j<ch;j++){
  104850. long offset=info->begin+i*samples_per_partition;
  104851. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104852. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104853. if(stagebook){
  104854. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104855. samples_per_partition)==-1)goto eopbreak;
  104856. }
  104857. }
  104858. }
  104859. }
  104860. }
  104861. errout:
  104862. eopbreak:
  104863. return(0);
  104864. }
  104865. #if 0
  104866. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104867. float **in,int *nonzero,int ch){
  104868. int i,used=0;
  104869. for(i=0;i<ch;i++)
  104870. if(nonzero[i])
  104871. in[used++]=in[i];
  104872. if(used)
  104873. return(_01class(vb,vl,in,used));
  104874. else
  104875. return(0);
  104876. }
  104877. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104878. float **in,float **out,int *nonzero,int ch,
  104879. long **partword){
  104880. int i,j,used=0,n=vb->pcmend/2;
  104881. for(i=0;i<ch;i++)
  104882. if(nonzero[i]){
  104883. if(out)
  104884. for(j=0;j<n;j++)
  104885. out[i][j]+=in[i][j];
  104886. in[used++]=in[i];
  104887. }
  104888. if(used){
  104889. int ret=_01forward(vb,vl,in,used,partword,
  104890. _interleaved_encodepart);
  104891. if(out){
  104892. used=0;
  104893. for(i=0;i<ch;i++)
  104894. if(nonzero[i]){
  104895. for(j=0;j<n;j++)
  104896. out[i][j]-=in[used][j];
  104897. used++;
  104898. }
  104899. }
  104900. return(ret);
  104901. }else{
  104902. return(0);
  104903. }
  104904. }
  104905. #endif
  104906. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104907. float **in,int *nonzero,int ch){
  104908. int i,used=0;
  104909. for(i=0;i<ch;i++)
  104910. if(nonzero[i])
  104911. in[used++]=in[i];
  104912. if(used)
  104913. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104914. else
  104915. return(0);
  104916. }
  104917. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104918. float **in,float **out,int *nonzero,int ch,
  104919. long **partword){
  104920. int i,j,used=0,n=vb->pcmend/2;
  104921. for(i=0;i<ch;i++)
  104922. if(nonzero[i]){
  104923. if(out)
  104924. for(j=0;j<n;j++)
  104925. out[i][j]+=in[i][j];
  104926. in[used++]=in[i];
  104927. }
  104928. if(used){
  104929. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104930. if(out){
  104931. used=0;
  104932. for(i=0;i<ch;i++)
  104933. if(nonzero[i]){
  104934. for(j=0;j<n;j++)
  104935. out[i][j]-=in[used][j];
  104936. used++;
  104937. }
  104938. }
  104939. return(ret);
  104940. }else{
  104941. return(0);
  104942. }
  104943. }
  104944. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104945. float **in,int *nonzero,int ch){
  104946. int i,used=0;
  104947. for(i=0;i<ch;i++)
  104948. if(nonzero[i])
  104949. in[used++]=in[i];
  104950. if(used)
  104951. return(_01class(vb,vl,in,used));
  104952. else
  104953. return(0);
  104954. }
  104955. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104956. float **in,int *nonzero,int ch){
  104957. int i,used=0;
  104958. for(i=0;i<ch;i++)
  104959. if(nonzero[i])
  104960. in[used++]=in[i];
  104961. if(used)
  104962. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104963. else
  104964. return(0);
  104965. }
  104966. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104967. float **in,int *nonzero,int ch){
  104968. int i,used=0;
  104969. for(i=0;i<ch;i++)
  104970. if(nonzero[i])used++;
  104971. if(used)
  104972. return(_2class(vb,vl,in,ch));
  104973. else
  104974. return(0);
  104975. }
  104976. int res2_forward(oggpack_buffer *opb,
  104977. vorbis_block *vb,vorbis_look_residue *vl,
  104978. float **in,float **out,int *nonzero,int ch,
  104979. long **partword){
  104980. long i,j,k,n=vb->pcmend/2,used=0;
  104981. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104982. for(i=0;i<ch;i++){
  104983. float *pcm=in[i];
  104984. if(nonzero[i])used++;
  104985. for(j=0,k=i;j<n;j++,k+=ch)
  104986. work[k]=pcm[j];
  104987. }
  104988. if(used){
  104989. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104990. if(out){
  104991. for(i=0;i<ch;i++){
  104992. float *pcm=in[i];
  104993. float *sofar=out[i];
  104994. for(j=0,k=i;j<n;j++,k+=ch)
  104995. sofar[j]+=pcm[j]-work[k];
  104996. }
  104997. }
  104998. return(ret);
  104999. }else{
  105000. return(0);
  105001. }
  105002. }
  105003. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  105004. float **in,int *nonzero,int ch){
  105005. long i,k,l,s;
  105006. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  105007. vorbis_info_residue0 *info=look->info;
  105008. int samples_per_partition=info->grouping;
  105009. int partitions_per_word=look->phrasebook->dim;
  105010. int n=info->end-info->begin;
  105011. int partvals=n/samples_per_partition;
  105012. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  105013. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  105014. for(i=0;i<ch;i++)if(nonzero[i])break;
  105015. if(i==ch)return(0); /* no nonzero vectors */
  105016. for(s=0;s<look->stages;s++){
  105017. for(i=0,l=0;i<partvals;l++){
  105018. if(s==0){
  105019. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  105020. if(temp==-1)goto eopbreak;
  105021. partword[l]=look->decodemap[temp];
  105022. if(partword[l]==NULL)goto errout;
  105023. }
  105024. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  105025. if(info->secondstages[partword[l][k]]&(1<<s)){
  105026. codebook *stagebook=look->partbooks[partword[l][k]][s];
  105027. if(stagebook){
  105028. if(vorbis_book_decodevv_add(stagebook,in,
  105029. i*samples_per_partition+info->begin,ch,
  105030. &vb->opb,samples_per_partition)==-1)
  105031. goto eopbreak;
  105032. }
  105033. }
  105034. }
  105035. }
  105036. errout:
  105037. eopbreak:
  105038. return(0);
  105039. }
  105040. vorbis_func_residue residue0_exportbundle={
  105041. NULL,
  105042. &res0_unpack,
  105043. &res0_look,
  105044. &res0_free_info,
  105045. &res0_free_look,
  105046. NULL,
  105047. NULL,
  105048. &res0_inverse
  105049. };
  105050. vorbis_func_residue residue1_exportbundle={
  105051. &res0_pack,
  105052. &res0_unpack,
  105053. &res0_look,
  105054. &res0_free_info,
  105055. &res0_free_look,
  105056. &res1_class,
  105057. &res1_forward,
  105058. &res1_inverse
  105059. };
  105060. vorbis_func_residue residue2_exportbundle={
  105061. &res0_pack,
  105062. &res0_unpack,
  105063. &res0_look,
  105064. &res0_free_info,
  105065. &res0_free_look,
  105066. &res2_class,
  105067. &res2_forward,
  105068. &res2_inverse
  105069. };
  105070. #endif
  105071. /*** End of inlined file: res0.c ***/
  105072. /*** Start of inlined file: sharedbook.c ***/
  105073. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105074. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105075. // tasks..
  105076. #if JUCE_MSVC
  105077. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105078. #endif
  105079. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105080. #if JUCE_USE_OGGVORBIS
  105081. #include <stdlib.h>
  105082. #include <math.h>
  105083. #include <string.h>
  105084. int _ilog(unsigned int v){
  105085. int ret=0;
  105086. while(v){
  105087. ret++;
  105088. v>>=1;
  105089. }
  105090. return(ret);
  105091. }
  105092. #define VQ_FEXP 10
  105093. #define VQ_FMAN 21
  105094. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  105095. long _float32_pack(float val){
  105096. int sign=0;
  105097. long exp;
  105098. long mant;
  105099. if(val<0){
  105100. sign=0x80000000;
  105101. val= -val;
  105102. }
  105103. exp= floor(log(val)/log(2.f));
  105104. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  105105. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  105106. return(sign|exp|mant);
  105107. }
  105108. float _float32_unpack(long val){
  105109. double mant=val&0x1fffff;
  105110. int sign=val&0x80000000;
  105111. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  105112. if(sign)mant= -mant;
  105113. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  105114. }
  105115. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  105116. long i,j,count=0;
  105117. ogg_uint32_t marker[33];
  105118. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  105119. memset(marker,0,sizeof(marker));
  105120. for(i=0;i<n;i++){
  105121. long length=l[i];
  105122. if(length>0){
  105123. ogg_uint32_t entry=marker[length];
  105124. if(length<32 && (entry>>length)){
  105125. _ogg_free(r);
  105126. return(NULL);
  105127. }
  105128. r[count++]=entry;
  105129. {
  105130. for(j=length;j>0;j--){
  105131. if(marker[j]&1){
  105132. if(j==1)
  105133. marker[1]++;
  105134. else
  105135. marker[j]=marker[j-1]<<1;
  105136. break; /* invariant says next upper marker would already
  105137. have been moved if it was on the same path */
  105138. }
  105139. marker[j]++;
  105140. }
  105141. }
  105142. for(j=length+1;j<33;j++)
  105143. if((marker[j]>>1) == entry){
  105144. entry=marker[j];
  105145. marker[j]=marker[j-1]<<1;
  105146. }else
  105147. break;
  105148. }else
  105149. if(sparsecount==0)count++;
  105150. }
  105151. for(i=0,count=0;i<n;i++){
  105152. ogg_uint32_t temp=0;
  105153. for(j=0;j<l[i];j++){
  105154. temp<<=1;
  105155. temp|=(r[count]>>j)&1;
  105156. }
  105157. if(sparsecount){
  105158. if(l[i])
  105159. r[count++]=temp;
  105160. }else
  105161. r[count++]=temp;
  105162. }
  105163. return(r);
  105164. }
  105165. long _book_maptype1_quantvals(const static_codebook *b){
  105166. long vals=floor(pow((float)b->entries,1.f/b->dim));
  105167. while(1){
  105168. long acc=1;
  105169. long acc1=1;
  105170. int i;
  105171. for(i=0;i<b->dim;i++){
  105172. acc*=vals;
  105173. acc1*=vals+1;
  105174. }
  105175. if(acc<=b->entries && acc1>b->entries){
  105176. return(vals);
  105177. }else{
  105178. if(acc>b->entries){
  105179. vals--;
  105180. }else{
  105181. vals++;
  105182. }
  105183. }
  105184. }
  105185. }
  105186. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  105187. long j,k,count=0;
  105188. if(b->maptype==1 || b->maptype==2){
  105189. int quantvals;
  105190. float mindel=_float32_unpack(b->q_min);
  105191. float delta=_float32_unpack(b->q_delta);
  105192. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  105193. switch(b->maptype){
  105194. case 1:
  105195. quantvals=_book_maptype1_quantvals(b);
  105196. for(j=0;j<b->entries;j++){
  105197. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105198. float last=0.f;
  105199. int indexdiv=1;
  105200. for(k=0;k<b->dim;k++){
  105201. int index= (j/indexdiv)%quantvals;
  105202. float val=b->quantlist[index];
  105203. val=fabs(val)*delta+mindel+last;
  105204. if(b->q_sequencep)last=val;
  105205. if(sparsemap)
  105206. r[sparsemap[count]*b->dim+k]=val;
  105207. else
  105208. r[count*b->dim+k]=val;
  105209. indexdiv*=quantvals;
  105210. }
  105211. count++;
  105212. }
  105213. }
  105214. break;
  105215. case 2:
  105216. for(j=0;j<b->entries;j++){
  105217. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105218. float last=0.f;
  105219. for(k=0;k<b->dim;k++){
  105220. float val=b->quantlist[j*b->dim+k];
  105221. val=fabs(val)*delta+mindel+last;
  105222. if(b->q_sequencep)last=val;
  105223. if(sparsemap)
  105224. r[sparsemap[count]*b->dim+k]=val;
  105225. else
  105226. r[count*b->dim+k]=val;
  105227. }
  105228. count++;
  105229. }
  105230. }
  105231. break;
  105232. }
  105233. return(r);
  105234. }
  105235. return(NULL);
  105236. }
  105237. void vorbis_staticbook_clear(static_codebook *b){
  105238. if(b->allocedp){
  105239. if(b->quantlist)_ogg_free(b->quantlist);
  105240. if(b->lengthlist)_ogg_free(b->lengthlist);
  105241. if(b->nearest_tree){
  105242. _ogg_free(b->nearest_tree->ptr0);
  105243. _ogg_free(b->nearest_tree->ptr1);
  105244. _ogg_free(b->nearest_tree->p);
  105245. _ogg_free(b->nearest_tree->q);
  105246. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  105247. _ogg_free(b->nearest_tree);
  105248. }
  105249. if(b->thresh_tree){
  105250. _ogg_free(b->thresh_tree->quantthresh);
  105251. _ogg_free(b->thresh_tree->quantmap);
  105252. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  105253. _ogg_free(b->thresh_tree);
  105254. }
  105255. memset(b,0,sizeof(*b));
  105256. }
  105257. }
  105258. void vorbis_staticbook_destroy(static_codebook *b){
  105259. if(b->allocedp){
  105260. vorbis_staticbook_clear(b);
  105261. _ogg_free(b);
  105262. }
  105263. }
  105264. void vorbis_book_clear(codebook *b){
  105265. if(b->valuelist)_ogg_free(b->valuelist);
  105266. if(b->codelist)_ogg_free(b->codelist);
  105267. if(b->dec_index)_ogg_free(b->dec_index);
  105268. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  105269. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  105270. memset(b,0,sizeof(*b));
  105271. }
  105272. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  105273. memset(c,0,sizeof(*c));
  105274. c->c=s;
  105275. c->entries=s->entries;
  105276. c->used_entries=s->entries;
  105277. c->dim=s->dim;
  105278. c->codelist=_make_words(s->lengthlist,s->entries,0);
  105279. c->valuelist=_book_unquantize(s,s->entries,NULL);
  105280. return(0);
  105281. }
  105282. static int sort32a(const void *a,const void *b){
  105283. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  105284. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  105285. }
  105286. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  105287. int i,j,n=0,tabn;
  105288. int *sortindex;
  105289. memset(c,0,sizeof(*c));
  105290. for(i=0;i<s->entries;i++)
  105291. if(s->lengthlist[i]>0)
  105292. n++;
  105293. c->entries=s->entries;
  105294. c->used_entries=n;
  105295. c->dim=s->dim;
  105296. {
  105297. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  105298. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  105299. if(codes==NULL)goto err_out;
  105300. for(i=0;i<n;i++){
  105301. codes[i]=ogg_bitreverse(codes[i]);
  105302. codep[i]=codes+i;
  105303. }
  105304. qsort(codep,n,sizeof(*codep),sort32a);
  105305. sortindex=(int*)alloca(n*sizeof(*sortindex));
  105306. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  105307. for(i=0;i<n;i++){
  105308. int position=codep[i]-codes;
  105309. sortindex[position]=i;
  105310. }
  105311. for(i=0;i<n;i++)
  105312. c->codelist[sortindex[i]]=codes[i];
  105313. _ogg_free(codes);
  105314. }
  105315. c->valuelist=_book_unquantize(s,n,sortindex);
  105316. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  105317. for(n=0,i=0;i<s->entries;i++)
  105318. if(s->lengthlist[i]>0)
  105319. c->dec_index[sortindex[n++]]=i;
  105320. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  105321. for(n=0,i=0;i<s->entries;i++)
  105322. if(s->lengthlist[i]>0)
  105323. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  105324. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  105325. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  105326. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  105327. tabn=1<<c->dec_firsttablen;
  105328. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  105329. c->dec_maxlength=0;
  105330. for(i=0;i<n;i++){
  105331. if(c->dec_maxlength<c->dec_codelengths[i])
  105332. c->dec_maxlength=c->dec_codelengths[i];
  105333. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  105334. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  105335. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  105336. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  105337. }
  105338. }
  105339. {
  105340. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  105341. long lo=0,hi=0;
  105342. for(i=0;i<tabn;i++){
  105343. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  105344. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  105345. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  105346. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  105347. {
  105348. unsigned long loval=lo;
  105349. unsigned long hival=n-hi;
  105350. if(loval>0x7fff)loval=0x7fff;
  105351. if(hival>0x7fff)hival=0x7fff;
  105352. c->dec_firsttable[ogg_bitreverse(word)]=
  105353. 0x80000000UL | (loval<<15) | hival;
  105354. }
  105355. }
  105356. }
  105357. }
  105358. return(0);
  105359. err_out:
  105360. vorbis_book_clear(c);
  105361. return(-1);
  105362. }
  105363. static float _dist(int el,float *ref, float *b,int step){
  105364. int i;
  105365. float acc=0.f;
  105366. for(i=0;i<el;i++){
  105367. float val=(ref[i]-b[i*step]);
  105368. acc+=val*val;
  105369. }
  105370. return(acc);
  105371. }
  105372. int _best(codebook *book, float *a, int step){
  105373. encode_aux_threshmatch *tt=book->c->thresh_tree;
  105374. #if 0
  105375. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  105376. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  105377. #endif
  105378. int dim=book->dim;
  105379. int k,o;
  105380. if(tt){
  105381. int index=0,i;
  105382. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105383. i=tt->threshvals>>1;
  105384. if(a[o]<tt->quantthresh[i]){
  105385. for(;i>0;i--)
  105386. if(a[o]>=tt->quantthresh[i-1])
  105387. break;
  105388. }else{
  105389. for(i++;i<tt->threshvals-1;i++)
  105390. if(a[o]<tt->quantthresh[i])break;
  105391. }
  105392. index=(index*tt->quantvals)+tt->quantmap[i];
  105393. }
  105394. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  105395. use a decision tree after all
  105396. and fall through*/
  105397. return(index);
  105398. }
  105399. #if 0
  105400. if(pt){
  105401. const static_codebook *c=book->c;
  105402. int i,besti=-1;
  105403. float best=0.f;
  105404. int entry=0;
  105405. if(c->q_sequencep){
  105406. int pv;
  105407. long mul=1;
  105408. float qlast=0;
  105409. for(k=0,o=0;k<dim;k++,o+=step){
  105410. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  105411. if(pv<0 || pv>=pt->mapentries)break;
  105412. entry+=pt->pigeonmap[pv]*mul;
  105413. mul*=pt->quantvals;
  105414. qlast+=pv*pt->del+pt->min;
  105415. }
  105416. }else{
  105417. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105418. int pv=(int)((a[o]-pt->min)/pt->del);
  105419. if(pv<0 || pv>=pt->mapentries)break;
  105420. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  105421. }
  105422. }
  105423. if(k==dim && pt->fitlength[entry]){
  105424. long *list=pt->fitlist+pt->fitmap[entry];
  105425. for(i=0;i<pt->fitlength[entry];i++){
  105426. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  105427. if(besti==-1 || this<best){
  105428. best=this;
  105429. besti=list[i];
  105430. }
  105431. }
  105432. return(besti);
  105433. }
  105434. }
  105435. if(nt){
  105436. while(1){
  105437. float c=0.f;
  105438. float *p=book->valuelist+nt->p[ptr];
  105439. float *q=book->valuelist+nt->q[ptr];
  105440. for(k=0,o=0;k<dim;k++,o+=step)
  105441. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  105442. if(c>0.f) /* in A */
  105443. ptr= -nt->ptr0[ptr];
  105444. else /* in B */
  105445. ptr= -nt->ptr1[ptr];
  105446. if(ptr<=0)break;
  105447. }
  105448. return(-ptr);
  105449. }
  105450. #endif
  105451. {
  105452. const static_codebook *c=book->c;
  105453. int i,besti=-1;
  105454. float best=0.f;
  105455. float *e=book->valuelist;
  105456. for(i=0;i<book->entries;i++){
  105457. if(c->lengthlist[i]>0){
  105458. float thisx=_dist(dim,e,a,step);
  105459. if(besti==-1 || thisx<best){
  105460. best=thisx;
  105461. besti=i;
  105462. }
  105463. }
  105464. e+=dim;
  105465. }
  105466. return(besti);
  105467. }
  105468. }
  105469. long vorbis_book_codeword(codebook *book,int entry){
  105470. if(book->c) /* only use with encode; decode optimizations are
  105471. allowed to break this */
  105472. return book->codelist[entry];
  105473. return -1;
  105474. }
  105475. long vorbis_book_codelen(codebook *book,int entry){
  105476. if(book->c) /* only use with encode; decode optimizations are
  105477. allowed to break this */
  105478. return book->c->lengthlist[entry];
  105479. return -1;
  105480. }
  105481. #ifdef _V_SELFTEST
  105482. #include <stdio.h>
  105483. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  105484. static long partial_quantlist1[]={0,7,2};
  105485. static_codebook test1={
  105486. 4,16,
  105487. NULL,
  105488. 0,
  105489. 0,0,0,0,
  105490. NULL,
  105491. NULL,NULL
  105492. };
  105493. static float *test1_result=NULL;
  105494. static_codebook test2={
  105495. 4,3,
  105496. NULL,
  105497. 2,
  105498. -533200896,1611661312,4,0,
  105499. full_quantlist1,
  105500. NULL,NULL
  105501. };
  105502. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  105503. static_codebook test3={
  105504. 4,3,
  105505. NULL,
  105506. 2,
  105507. -533200896,1611661312,4,1,
  105508. full_quantlist1,
  105509. NULL,NULL
  105510. };
  105511. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  105512. static_codebook test4={
  105513. 3,27,
  105514. NULL,
  105515. 1,
  105516. -533200896,1611661312,4,0,
  105517. partial_quantlist1,
  105518. NULL,NULL
  105519. };
  105520. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  105521. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  105522. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  105523. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  105524. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  105525. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105526. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105527. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105528. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105529. static_codebook test5={
  105530. 3,27,
  105531. NULL,
  105532. 1,
  105533. -533200896,1611661312,4,1,
  105534. partial_quantlist1,
  105535. NULL,NULL
  105536. };
  105537. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105538. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105539. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105540. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105541. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105542. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105543. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105544. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105545. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105546. void run_test(static_codebook *b,float *comp){
  105547. float *out=_book_unquantize(b,b->entries,NULL);
  105548. int i;
  105549. if(comp){
  105550. if(!out){
  105551. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105552. exit(1);
  105553. }
  105554. for(i=0;i<b->entries*b->dim;i++)
  105555. if(fabs(out[i]-comp[i])>.0001){
  105556. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105557. "position %d, %g != %g\n",i,out[i],comp[i]);
  105558. exit(1);
  105559. }
  105560. }else{
  105561. if(out){
  105562. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105563. " correct result should have been NULL\n");
  105564. exit(1);
  105565. }
  105566. }
  105567. }
  105568. int main(){
  105569. fprintf(stderr,"Dequant test 1... ");
  105570. run_test(&test1,test1_result);
  105571. fprintf(stderr,"OK\nDequant test 2... ");
  105572. run_test(&test2,test2_result);
  105573. fprintf(stderr,"OK\nDequant test 3... ");
  105574. run_test(&test3,test3_result);
  105575. fprintf(stderr,"OK\nDequant test 4... ");
  105576. run_test(&test4,test4_result);
  105577. fprintf(stderr,"OK\nDequant test 5... ");
  105578. run_test(&test5,test5_result);
  105579. fprintf(stderr,"OK\n\n");
  105580. return(0);
  105581. }
  105582. #endif
  105583. #endif
  105584. /*** End of inlined file: sharedbook.c ***/
  105585. /*** Start of inlined file: smallft.c ***/
  105586. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105587. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105588. // tasks..
  105589. #if JUCE_MSVC
  105590. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105591. #endif
  105592. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105593. #if JUCE_USE_OGGVORBIS
  105594. #include <stdlib.h>
  105595. #include <string.h>
  105596. #include <math.h>
  105597. static void drfti1(int n, float *wa, int *ifac){
  105598. static int ntryh[4] = { 4,2,3,5 };
  105599. static float tpi = 6.28318530717958648f;
  105600. float arg,argh,argld,fi;
  105601. int ntry=0,i,j=-1;
  105602. int k1, l1, l2, ib;
  105603. int ld, ii, ip, is, nq, nr;
  105604. int ido, ipm, nfm1;
  105605. int nl=n;
  105606. int nf=0;
  105607. L101:
  105608. j++;
  105609. if (j < 4)
  105610. ntry=ntryh[j];
  105611. else
  105612. ntry+=2;
  105613. L104:
  105614. nq=nl/ntry;
  105615. nr=nl-ntry*nq;
  105616. if (nr!=0) goto L101;
  105617. nf++;
  105618. ifac[nf+1]=ntry;
  105619. nl=nq;
  105620. if(ntry!=2)goto L107;
  105621. if(nf==1)goto L107;
  105622. for (i=1;i<nf;i++){
  105623. ib=nf-i+1;
  105624. ifac[ib+1]=ifac[ib];
  105625. }
  105626. ifac[2] = 2;
  105627. L107:
  105628. if(nl!=1)goto L104;
  105629. ifac[0]=n;
  105630. ifac[1]=nf;
  105631. argh=tpi/n;
  105632. is=0;
  105633. nfm1=nf-1;
  105634. l1=1;
  105635. if(nfm1==0)return;
  105636. for (k1=0;k1<nfm1;k1++){
  105637. ip=ifac[k1+2];
  105638. ld=0;
  105639. l2=l1*ip;
  105640. ido=n/l2;
  105641. ipm=ip-1;
  105642. for (j=0;j<ipm;j++){
  105643. ld+=l1;
  105644. i=is;
  105645. argld=(float)ld*argh;
  105646. fi=0.f;
  105647. for (ii=2;ii<ido;ii+=2){
  105648. fi+=1.f;
  105649. arg=fi*argld;
  105650. wa[i++]=cos(arg);
  105651. wa[i++]=sin(arg);
  105652. }
  105653. is+=ido;
  105654. }
  105655. l1=l2;
  105656. }
  105657. }
  105658. static void fdrffti(int n, float *wsave, int *ifac){
  105659. if (n == 1) return;
  105660. drfti1(n, wsave+n, ifac);
  105661. }
  105662. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105663. int i,k;
  105664. float ti2,tr2;
  105665. int t0,t1,t2,t3,t4,t5,t6;
  105666. t1=0;
  105667. t0=(t2=l1*ido);
  105668. t3=ido<<1;
  105669. for(k=0;k<l1;k++){
  105670. ch[t1<<1]=cc[t1]+cc[t2];
  105671. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105672. t1+=ido;
  105673. t2+=ido;
  105674. }
  105675. if(ido<2)return;
  105676. if(ido==2)goto L105;
  105677. t1=0;
  105678. t2=t0;
  105679. for(k=0;k<l1;k++){
  105680. t3=t2;
  105681. t4=(t1<<1)+(ido<<1);
  105682. t5=t1;
  105683. t6=t1+t1;
  105684. for(i=2;i<ido;i+=2){
  105685. t3+=2;
  105686. t4-=2;
  105687. t5+=2;
  105688. t6+=2;
  105689. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105690. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105691. ch[t6]=cc[t5]+ti2;
  105692. ch[t4]=ti2-cc[t5];
  105693. ch[t6-1]=cc[t5-1]+tr2;
  105694. ch[t4-1]=cc[t5-1]-tr2;
  105695. }
  105696. t1+=ido;
  105697. t2+=ido;
  105698. }
  105699. if(ido%2==1)return;
  105700. L105:
  105701. t3=(t2=(t1=ido)-1);
  105702. t2+=t0;
  105703. for(k=0;k<l1;k++){
  105704. ch[t1]=-cc[t2];
  105705. ch[t1-1]=cc[t3];
  105706. t1+=ido<<1;
  105707. t2+=ido;
  105708. t3+=ido;
  105709. }
  105710. }
  105711. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105712. float *wa2,float *wa3){
  105713. static float hsqt2 = .70710678118654752f;
  105714. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105715. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105716. t0=l1*ido;
  105717. t1=t0;
  105718. t4=t1<<1;
  105719. t2=t1+(t1<<1);
  105720. t3=0;
  105721. for(k=0;k<l1;k++){
  105722. tr1=cc[t1]+cc[t2];
  105723. tr2=cc[t3]+cc[t4];
  105724. ch[t5=t3<<2]=tr1+tr2;
  105725. ch[(ido<<2)+t5-1]=tr2-tr1;
  105726. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105727. ch[t5]=cc[t2]-cc[t1];
  105728. t1+=ido;
  105729. t2+=ido;
  105730. t3+=ido;
  105731. t4+=ido;
  105732. }
  105733. if(ido<2)return;
  105734. if(ido==2)goto L105;
  105735. t1=0;
  105736. for(k=0;k<l1;k++){
  105737. t2=t1;
  105738. t4=t1<<2;
  105739. t5=(t6=ido<<1)+t4;
  105740. for(i=2;i<ido;i+=2){
  105741. t3=(t2+=2);
  105742. t4+=2;
  105743. t5-=2;
  105744. t3+=t0;
  105745. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105746. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105747. t3+=t0;
  105748. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105749. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105750. t3+=t0;
  105751. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105752. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105753. tr1=cr2+cr4;
  105754. tr4=cr4-cr2;
  105755. ti1=ci2+ci4;
  105756. ti4=ci2-ci4;
  105757. ti2=cc[t2]+ci3;
  105758. ti3=cc[t2]-ci3;
  105759. tr2=cc[t2-1]+cr3;
  105760. tr3=cc[t2-1]-cr3;
  105761. ch[t4-1]=tr1+tr2;
  105762. ch[t4]=ti1+ti2;
  105763. ch[t5-1]=tr3-ti4;
  105764. ch[t5]=tr4-ti3;
  105765. ch[t4+t6-1]=ti4+tr3;
  105766. ch[t4+t6]=tr4+ti3;
  105767. ch[t5+t6-1]=tr2-tr1;
  105768. ch[t5+t6]=ti1-ti2;
  105769. }
  105770. t1+=ido;
  105771. }
  105772. if(ido&1)return;
  105773. L105:
  105774. t2=(t1=t0+ido-1)+(t0<<1);
  105775. t3=ido<<2;
  105776. t4=ido;
  105777. t5=ido<<1;
  105778. t6=ido;
  105779. for(k=0;k<l1;k++){
  105780. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105781. tr1=hsqt2*(cc[t1]-cc[t2]);
  105782. ch[t4-1]=tr1+cc[t6-1];
  105783. ch[t4+t5-1]=cc[t6-1]-tr1;
  105784. ch[t4]=ti1-cc[t1+t0];
  105785. ch[t4+t5]=ti1+cc[t1+t0];
  105786. t1+=ido;
  105787. t2+=ido;
  105788. t4+=t3;
  105789. t6+=ido;
  105790. }
  105791. }
  105792. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105793. float *c2,float *ch,float *ch2,float *wa){
  105794. static float tpi=6.283185307179586f;
  105795. int idij,ipph,i,j,k,l,ic,ik,is;
  105796. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105797. float dc2,ai1,ai2,ar1,ar2,ds2;
  105798. int nbd;
  105799. float dcp,arg,dsp,ar1h,ar2h;
  105800. int idp2,ipp2;
  105801. arg=tpi/(float)ip;
  105802. dcp=cos(arg);
  105803. dsp=sin(arg);
  105804. ipph=(ip+1)>>1;
  105805. ipp2=ip;
  105806. idp2=ido;
  105807. nbd=(ido-1)>>1;
  105808. t0=l1*ido;
  105809. t10=ip*ido;
  105810. if(ido==1)goto L119;
  105811. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105812. t1=0;
  105813. for(j=1;j<ip;j++){
  105814. t1+=t0;
  105815. t2=t1;
  105816. for(k=0;k<l1;k++){
  105817. ch[t2]=c1[t2];
  105818. t2+=ido;
  105819. }
  105820. }
  105821. is=-ido;
  105822. t1=0;
  105823. if(nbd>l1){
  105824. for(j=1;j<ip;j++){
  105825. t1+=t0;
  105826. is+=ido;
  105827. t2= -ido+t1;
  105828. for(k=0;k<l1;k++){
  105829. idij=is-1;
  105830. t2+=ido;
  105831. t3=t2;
  105832. for(i=2;i<ido;i+=2){
  105833. idij+=2;
  105834. t3+=2;
  105835. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105836. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105837. }
  105838. }
  105839. }
  105840. }else{
  105841. for(j=1;j<ip;j++){
  105842. is+=ido;
  105843. idij=is-1;
  105844. t1+=t0;
  105845. t2=t1;
  105846. for(i=2;i<ido;i+=2){
  105847. idij+=2;
  105848. t2+=2;
  105849. t3=t2;
  105850. for(k=0;k<l1;k++){
  105851. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105852. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105853. t3+=ido;
  105854. }
  105855. }
  105856. }
  105857. }
  105858. t1=0;
  105859. t2=ipp2*t0;
  105860. if(nbd<l1){
  105861. for(j=1;j<ipph;j++){
  105862. t1+=t0;
  105863. t2-=t0;
  105864. t3=t1;
  105865. t4=t2;
  105866. for(i=2;i<ido;i+=2){
  105867. t3+=2;
  105868. t4+=2;
  105869. t5=t3-ido;
  105870. t6=t4-ido;
  105871. for(k=0;k<l1;k++){
  105872. t5+=ido;
  105873. t6+=ido;
  105874. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105875. c1[t6-1]=ch[t5]-ch[t6];
  105876. c1[t5]=ch[t5]+ch[t6];
  105877. c1[t6]=ch[t6-1]-ch[t5-1];
  105878. }
  105879. }
  105880. }
  105881. }else{
  105882. for(j=1;j<ipph;j++){
  105883. t1+=t0;
  105884. t2-=t0;
  105885. t3=t1;
  105886. t4=t2;
  105887. for(k=0;k<l1;k++){
  105888. t5=t3;
  105889. t6=t4;
  105890. for(i=2;i<ido;i+=2){
  105891. t5+=2;
  105892. t6+=2;
  105893. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105894. c1[t6-1]=ch[t5]-ch[t6];
  105895. c1[t5]=ch[t5]+ch[t6];
  105896. c1[t6]=ch[t6-1]-ch[t5-1];
  105897. }
  105898. t3+=ido;
  105899. t4+=ido;
  105900. }
  105901. }
  105902. }
  105903. L119:
  105904. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105905. t1=0;
  105906. t2=ipp2*idl1;
  105907. for(j=1;j<ipph;j++){
  105908. t1+=t0;
  105909. t2-=t0;
  105910. t3=t1-ido;
  105911. t4=t2-ido;
  105912. for(k=0;k<l1;k++){
  105913. t3+=ido;
  105914. t4+=ido;
  105915. c1[t3]=ch[t3]+ch[t4];
  105916. c1[t4]=ch[t4]-ch[t3];
  105917. }
  105918. }
  105919. ar1=1.f;
  105920. ai1=0.f;
  105921. t1=0;
  105922. t2=ipp2*idl1;
  105923. t3=(ip-1)*idl1;
  105924. for(l=1;l<ipph;l++){
  105925. t1+=idl1;
  105926. t2-=idl1;
  105927. ar1h=dcp*ar1-dsp*ai1;
  105928. ai1=dcp*ai1+dsp*ar1;
  105929. ar1=ar1h;
  105930. t4=t1;
  105931. t5=t2;
  105932. t6=t3;
  105933. t7=idl1;
  105934. for(ik=0;ik<idl1;ik++){
  105935. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105936. ch2[t5++]=ai1*c2[t6++];
  105937. }
  105938. dc2=ar1;
  105939. ds2=ai1;
  105940. ar2=ar1;
  105941. ai2=ai1;
  105942. t4=idl1;
  105943. t5=(ipp2-1)*idl1;
  105944. for(j=2;j<ipph;j++){
  105945. t4+=idl1;
  105946. t5-=idl1;
  105947. ar2h=dc2*ar2-ds2*ai2;
  105948. ai2=dc2*ai2+ds2*ar2;
  105949. ar2=ar2h;
  105950. t6=t1;
  105951. t7=t2;
  105952. t8=t4;
  105953. t9=t5;
  105954. for(ik=0;ik<idl1;ik++){
  105955. ch2[t6++]+=ar2*c2[t8++];
  105956. ch2[t7++]+=ai2*c2[t9++];
  105957. }
  105958. }
  105959. }
  105960. t1=0;
  105961. for(j=1;j<ipph;j++){
  105962. t1+=idl1;
  105963. t2=t1;
  105964. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105965. }
  105966. if(ido<l1)goto L132;
  105967. t1=0;
  105968. t2=0;
  105969. for(k=0;k<l1;k++){
  105970. t3=t1;
  105971. t4=t2;
  105972. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105973. t1+=ido;
  105974. t2+=t10;
  105975. }
  105976. goto L135;
  105977. L132:
  105978. for(i=0;i<ido;i++){
  105979. t1=i;
  105980. t2=i;
  105981. for(k=0;k<l1;k++){
  105982. cc[t2]=ch[t1];
  105983. t1+=ido;
  105984. t2+=t10;
  105985. }
  105986. }
  105987. L135:
  105988. t1=0;
  105989. t2=ido<<1;
  105990. t3=0;
  105991. t4=ipp2*t0;
  105992. for(j=1;j<ipph;j++){
  105993. t1+=t2;
  105994. t3+=t0;
  105995. t4-=t0;
  105996. t5=t1;
  105997. t6=t3;
  105998. t7=t4;
  105999. for(k=0;k<l1;k++){
  106000. cc[t5-1]=ch[t6];
  106001. cc[t5]=ch[t7];
  106002. t5+=t10;
  106003. t6+=ido;
  106004. t7+=ido;
  106005. }
  106006. }
  106007. if(ido==1)return;
  106008. if(nbd<l1)goto L141;
  106009. t1=-ido;
  106010. t3=0;
  106011. t4=0;
  106012. t5=ipp2*t0;
  106013. for(j=1;j<ipph;j++){
  106014. t1+=t2;
  106015. t3+=t2;
  106016. t4+=t0;
  106017. t5-=t0;
  106018. t6=t1;
  106019. t7=t3;
  106020. t8=t4;
  106021. t9=t5;
  106022. for(k=0;k<l1;k++){
  106023. for(i=2;i<ido;i+=2){
  106024. ic=idp2-i;
  106025. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  106026. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  106027. cc[i+t7]=ch[i+t8]+ch[i+t9];
  106028. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  106029. }
  106030. t6+=t10;
  106031. t7+=t10;
  106032. t8+=ido;
  106033. t9+=ido;
  106034. }
  106035. }
  106036. return;
  106037. L141:
  106038. t1=-ido;
  106039. t3=0;
  106040. t4=0;
  106041. t5=ipp2*t0;
  106042. for(j=1;j<ipph;j++){
  106043. t1+=t2;
  106044. t3+=t2;
  106045. t4+=t0;
  106046. t5-=t0;
  106047. for(i=2;i<ido;i+=2){
  106048. t6=idp2+t1-i;
  106049. t7=i+t3;
  106050. t8=i+t4;
  106051. t9=i+t5;
  106052. for(k=0;k<l1;k++){
  106053. cc[t7-1]=ch[t8-1]+ch[t9-1];
  106054. cc[t6-1]=ch[t8-1]-ch[t9-1];
  106055. cc[t7]=ch[t8]+ch[t9];
  106056. cc[t6]=ch[t9]-ch[t8];
  106057. t6+=t10;
  106058. t7+=t10;
  106059. t8+=ido;
  106060. t9+=ido;
  106061. }
  106062. }
  106063. }
  106064. }
  106065. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  106066. int i,k1,l1,l2;
  106067. int na,kh,nf;
  106068. int ip,iw,ido,idl1,ix2,ix3;
  106069. nf=ifac[1];
  106070. na=1;
  106071. l2=n;
  106072. iw=n;
  106073. for(k1=0;k1<nf;k1++){
  106074. kh=nf-k1;
  106075. ip=ifac[kh+1];
  106076. l1=l2/ip;
  106077. ido=n/l2;
  106078. idl1=ido*l1;
  106079. iw-=(ip-1)*ido;
  106080. na=1-na;
  106081. if(ip!=4)goto L102;
  106082. ix2=iw+ido;
  106083. ix3=ix2+ido;
  106084. if(na!=0)
  106085. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106086. else
  106087. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106088. goto L110;
  106089. L102:
  106090. if(ip!=2)goto L104;
  106091. if(na!=0)goto L103;
  106092. dradf2(ido,l1,c,ch,wa+iw-1);
  106093. goto L110;
  106094. L103:
  106095. dradf2(ido,l1,ch,c,wa+iw-1);
  106096. goto L110;
  106097. L104:
  106098. if(ido==1)na=1-na;
  106099. if(na!=0)goto L109;
  106100. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106101. na=1;
  106102. goto L110;
  106103. L109:
  106104. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106105. na=0;
  106106. L110:
  106107. l2=l1;
  106108. }
  106109. if(na==1)return;
  106110. for(i=0;i<n;i++)c[i]=ch[i];
  106111. }
  106112. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  106113. int i,k,t0,t1,t2,t3,t4,t5,t6;
  106114. float ti2,tr2;
  106115. t0=l1*ido;
  106116. t1=0;
  106117. t2=0;
  106118. t3=(ido<<1)-1;
  106119. for(k=0;k<l1;k++){
  106120. ch[t1]=cc[t2]+cc[t3+t2];
  106121. ch[t1+t0]=cc[t2]-cc[t3+t2];
  106122. t2=(t1+=ido)<<1;
  106123. }
  106124. if(ido<2)return;
  106125. if(ido==2)goto L105;
  106126. t1=0;
  106127. t2=0;
  106128. for(k=0;k<l1;k++){
  106129. t3=t1;
  106130. t5=(t4=t2)+(ido<<1);
  106131. t6=t0+t1;
  106132. for(i=2;i<ido;i+=2){
  106133. t3+=2;
  106134. t4+=2;
  106135. t5-=2;
  106136. t6+=2;
  106137. ch[t3-1]=cc[t4-1]+cc[t5-1];
  106138. tr2=cc[t4-1]-cc[t5-1];
  106139. ch[t3]=cc[t4]-cc[t5];
  106140. ti2=cc[t4]+cc[t5];
  106141. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  106142. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  106143. }
  106144. t2=(t1+=ido)<<1;
  106145. }
  106146. if(ido%2==1)return;
  106147. L105:
  106148. t1=ido-1;
  106149. t2=ido-1;
  106150. for(k=0;k<l1;k++){
  106151. ch[t1]=cc[t2]+cc[t2];
  106152. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  106153. t1+=ido;
  106154. t2+=ido<<1;
  106155. }
  106156. }
  106157. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  106158. float *wa2){
  106159. static float taur = -.5f;
  106160. static float taui = .8660254037844386f;
  106161. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  106162. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  106163. t0=l1*ido;
  106164. t1=0;
  106165. t2=t0<<1;
  106166. t3=ido<<1;
  106167. t4=ido+(ido<<1);
  106168. t5=0;
  106169. for(k=0;k<l1;k++){
  106170. tr2=cc[t3-1]+cc[t3-1];
  106171. cr2=cc[t5]+(taur*tr2);
  106172. ch[t1]=cc[t5]+tr2;
  106173. ci3=taui*(cc[t3]+cc[t3]);
  106174. ch[t1+t0]=cr2-ci3;
  106175. ch[t1+t2]=cr2+ci3;
  106176. t1+=ido;
  106177. t3+=t4;
  106178. t5+=t4;
  106179. }
  106180. if(ido==1)return;
  106181. t1=0;
  106182. t3=ido<<1;
  106183. for(k=0;k<l1;k++){
  106184. t7=t1+(t1<<1);
  106185. t6=(t5=t7+t3);
  106186. t8=t1;
  106187. t10=(t9=t1+t0)+t0;
  106188. for(i=2;i<ido;i+=2){
  106189. t5+=2;
  106190. t6-=2;
  106191. t7+=2;
  106192. t8+=2;
  106193. t9+=2;
  106194. t10+=2;
  106195. tr2=cc[t5-1]+cc[t6-1];
  106196. cr2=cc[t7-1]+(taur*tr2);
  106197. ch[t8-1]=cc[t7-1]+tr2;
  106198. ti2=cc[t5]-cc[t6];
  106199. ci2=cc[t7]+(taur*ti2);
  106200. ch[t8]=cc[t7]+ti2;
  106201. cr3=taui*(cc[t5-1]-cc[t6-1]);
  106202. ci3=taui*(cc[t5]+cc[t6]);
  106203. dr2=cr2-ci3;
  106204. dr3=cr2+ci3;
  106205. di2=ci2+cr3;
  106206. di3=ci2-cr3;
  106207. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  106208. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  106209. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  106210. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  106211. }
  106212. t1+=ido;
  106213. }
  106214. }
  106215. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  106216. float *wa2,float *wa3){
  106217. static float sqrt2=1.414213562373095f;
  106218. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  106219. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  106220. t0=l1*ido;
  106221. t1=0;
  106222. t2=ido<<2;
  106223. t3=0;
  106224. t6=ido<<1;
  106225. for(k=0;k<l1;k++){
  106226. t4=t3+t6;
  106227. t5=t1;
  106228. tr3=cc[t4-1]+cc[t4-1];
  106229. tr4=cc[t4]+cc[t4];
  106230. tr1=cc[t3]-cc[(t4+=t6)-1];
  106231. tr2=cc[t3]+cc[t4-1];
  106232. ch[t5]=tr2+tr3;
  106233. ch[t5+=t0]=tr1-tr4;
  106234. ch[t5+=t0]=tr2-tr3;
  106235. ch[t5+=t0]=tr1+tr4;
  106236. t1+=ido;
  106237. t3+=t2;
  106238. }
  106239. if(ido<2)return;
  106240. if(ido==2)goto L105;
  106241. t1=0;
  106242. for(k=0;k<l1;k++){
  106243. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  106244. t7=t1;
  106245. for(i=2;i<ido;i+=2){
  106246. t2+=2;
  106247. t3+=2;
  106248. t4-=2;
  106249. t5-=2;
  106250. t7+=2;
  106251. ti1=cc[t2]+cc[t5];
  106252. ti2=cc[t2]-cc[t5];
  106253. ti3=cc[t3]-cc[t4];
  106254. tr4=cc[t3]+cc[t4];
  106255. tr1=cc[t2-1]-cc[t5-1];
  106256. tr2=cc[t2-1]+cc[t5-1];
  106257. ti4=cc[t3-1]-cc[t4-1];
  106258. tr3=cc[t3-1]+cc[t4-1];
  106259. ch[t7-1]=tr2+tr3;
  106260. cr3=tr2-tr3;
  106261. ch[t7]=ti2+ti3;
  106262. ci3=ti2-ti3;
  106263. cr2=tr1-tr4;
  106264. cr4=tr1+tr4;
  106265. ci2=ti1+ti4;
  106266. ci4=ti1-ti4;
  106267. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  106268. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  106269. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  106270. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  106271. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  106272. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  106273. }
  106274. t1+=ido;
  106275. }
  106276. if(ido%2 == 1)return;
  106277. L105:
  106278. t1=ido;
  106279. t2=ido<<2;
  106280. t3=ido-1;
  106281. t4=ido+(ido<<1);
  106282. for(k=0;k<l1;k++){
  106283. t5=t3;
  106284. ti1=cc[t1]+cc[t4];
  106285. ti2=cc[t4]-cc[t1];
  106286. tr1=cc[t1-1]-cc[t4-1];
  106287. tr2=cc[t1-1]+cc[t4-1];
  106288. ch[t5]=tr2+tr2;
  106289. ch[t5+=t0]=sqrt2*(tr1-ti1);
  106290. ch[t5+=t0]=ti2+ti2;
  106291. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  106292. t3+=ido;
  106293. t1+=t2;
  106294. t4+=t2;
  106295. }
  106296. }
  106297. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  106298. float *c2,float *ch,float *ch2,float *wa){
  106299. static float tpi=6.283185307179586f;
  106300. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  106301. t11,t12;
  106302. float dc2,ai1,ai2,ar1,ar2,ds2;
  106303. int nbd;
  106304. float dcp,arg,dsp,ar1h,ar2h;
  106305. int ipp2;
  106306. t10=ip*ido;
  106307. t0=l1*ido;
  106308. arg=tpi/(float)ip;
  106309. dcp=cos(arg);
  106310. dsp=sin(arg);
  106311. nbd=(ido-1)>>1;
  106312. ipp2=ip;
  106313. ipph=(ip+1)>>1;
  106314. if(ido<l1)goto L103;
  106315. t1=0;
  106316. t2=0;
  106317. for(k=0;k<l1;k++){
  106318. t3=t1;
  106319. t4=t2;
  106320. for(i=0;i<ido;i++){
  106321. ch[t3]=cc[t4];
  106322. t3++;
  106323. t4++;
  106324. }
  106325. t1+=ido;
  106326. t2+=t10;
  106327. }
  106328. goto L106;
  106329. L103:
  106330. t1=0;
  106331. for(i=0;i<ido;i++){
  106332. t2=t1;
  106333. t3=t1;
  106334. for(k=0;k<l1;k++){
  106335. ch[t2]=cc[t3];
  106336. t2+=ido;
  106337. t3+=t10;
  106338. }
  106339. t1++;
  106340. }
  106341. L106:
  106342. t1=0;
  106343. t2=ipp2*t0;
  106344. t7=(t5=ido<<1);
  106345. for(j=1;j<ipph;j++){
  106346. t1+=t0;
  106347. t2-=t0;
  106348. t3=t1;
  106349. t4=t2;
  106350. t6=t5;
  106351. for(k=0;k<l1;k++){
  106352. ch[t3]=cc[t6-1]+cc[t6-1];
  106353. ch[t4]=cc[t6]+cc[t6];
  106354. t3+=ido;
  106355. t4+=ido;
  106356. t6+=t10;
  106357. }
  106358. t5+=t7;
  106359. }
  106360. if (ido == 1)goto L116;
  106361. if(nbd<l1)goto L112;
  106362. t1=0;
  106363. t2=ipp2*t0;
  106364. t7=0;
  106365. for(j=1;j<ipph;j++){
  106366. t1+=t0;
  106367. t2-=t0;
  106368. t3=t1;
  106369. t4=t2;
  106370. t7+=(ido<<1);
  106371. t8=t7;
  106372. for(k=0;k<l1;k++){
  106373. t5=t3;
  106374. t6=t4;
  106375. t9=t8;
  106376. t11=t8;
  106377. for(i=2;i<ido;i+=2){
  106378. t5+=2;
  106379. t6+=2;
  106380. t9+=2;
  106381. t11-=2;
  106382. ch[t5-1]=cc[t9-1]+cc[t11-1];
  106383. ch[t6-1]=cc[t9-1]-cc[t11-1];
  106384. ch[t5]=cc[t9]-cc[t11];
  106385. ch[t6]=cc[t9]+cc[t11];
  106386. }
  106387. t3+=ido;
  106388. t4+=ido;
  106389. t8+=t10;
  106390. }
  106391. }
  106392. goto L116;
  106393. L112:
  106394. t1=0;
  106395. t2=ipp2*t0;
  106396. t7=0;
  106397. for(j=1;j<ipph;j++){
  106398. t1+=t0;
  106399. t2-=t0;
  106400. t3=t1;
  106401. t4=t2;
  106402. t7+=(ido<<1);
  106403. t8=t7;
  106404. t9=t7;
  106405. for(i=2;i<ido;i+=2){
  106406. t3+=2;
  106407. t4+=2;
  106408. t8+=2;
  106409. t9-=2;
  106410. t5=t3;
  106411. t6=t4;
  106412. t11=t8;
  106413. t12=t9;
  106414. for(k=0;k<l1;k++){
  106415. ch[t5-1]=cc[t11-1]+cc[t12-1];
  106416. ch[t6-1]=cc[t11-1]-cc[t12-1];
  106417. ch[t5]=cc[t11]-cc[t12];
  106418. ch[t6]=cc[t11]+cc[t12];
  106419. t5+=ido;
  106420. t6+=ido;
  106421. t11+=t10;
  106422. t12+=t10;
  106423. }
  106424. }
  106425. }
  106426. L116:
  106427. ar1=1.f;
  106428. ai1=0.f;
  106429. t1=0;
  106430. t9=(t2=ipp2*idl1);
  106431. t3=(ip-1)*idl1;
  106432. for(l=1;l<ipph;l++){
  106433. t1+=idl1;
  106434. t2-=idl1;
  106435. ar1h=dcp*ar1-dsp*ai1;
  106436. ai1=dcp*ai1+dsp*ar1;
  106437. ar1=ar1h;
  106438. t4=t1;
  106439. t5=t2;
  106440. t6=0;
  106441. t7=idl1;
  106442. t8=t3;
  106443. for(ik=0;ik<idl1;ik++){
  106444. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  106445. c2[t5++]=ai1*ch2[t8++];
  106446. }
  106447. dc2=ar1;
  106448. ds2=ai1;
  106449. ar2=ar1;
  106450. ai2=ai1;
  106451. t6=idl1;
  106452. t7=t9-idl1;
  106453. for(j=2;j<ipph;j++){
  106454. t6+=idl1;
  106455. t7-=idl1;
  106456. ar2h=dc2*ar2-ds2*ai2;
  106457. ai2=dc2*ai2+ds2*ar2;
  106458. ar2=ar2h;
  106459. t4=t1;
  106460. t5=t2;
  106461. t11=t6;
  106462. t12=t7;
  106463. for(ik=0;ik<idl1;ik++){
  106464. c2[t4++]+=ar2*ch2[t11++];
  106465. c2[t5++]+=ai2*ch2[t12++];
  106466. }
  106467. }
  106468. }
  106469. t1=0;
  106470. for(j=1;j<ipph;j++){
  106471. t1+=idl1;
  106472. t2=t1;
  106473. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  106474. }
  106475. t1=0;
  106476. t2=ipp2*t0;
  106477. for(j=1;j<ipph;j++){
  106478. t1+=t0;
  106479. t2-=t0;
  106480. t3=t1;
  106481. t4=t2;
  106482. for(k=0;k<l1;k++){
  106483. ch[t3]=c1[t3]-c1[t4];
  106484. ch[t4]=c1[t3]+c1[t4];
  106485. t3+=ido;
  106486. t4+=ido;
  106487. }
  106488. }
  106489. if(ido==1)goto L132;
  106490. if(nbd<l1)goto L128;
  106491. t1=0;
  106492. t2=ipp2*t0;
  106493. for(j=1;j<ipph;j++){
  106494. t1+=t0;
  106495. t2-=t0;
  106496. t3=t1;
  106497. t4=t2;
  106498. for(k=0;k<l1;k++){
  106499. t5=t3;
  106500. t6=t4;
  106501. for(i=2;i<ido;i+=2){
  106502. t5+=2;
  106503. t6+=2;
  106504. ch[t5-1]=c1[t5-1]-c1[t6];
  106505. ch[t6-1]=c1[t5-1]+c1[t6];
  106506. ch[t5]=c1[t5]+c1[t6-1];
  106507. ch[t6]=c1[t5]-c1[t6-1];
  106508. }
  106509. t3+=ido;
  106510. t4+=ido;
  106511. }
  106512. }
  106513. goto L132;
  106514. L128:
  106515. t1=0;
  106516. t2=ipp2*t0;
  106517. for(j=1;j<ipph;j++){
  106518. t1+=t0;
  106519. t2-=t0;
  106520. t3=t1;
  106521. t4=t2;
  106522. for(i=2;i<ido;i+=2){
  106523. t3+=2;
  106524. t4+=2;
  106525. t5=t3;
  106526. t6=t4;
  106527. for(k=0;k<l1;k++){
  106528. ch[t5-1]=c1[t5-1]-c1[t6];
  106529. ch[t6-1]=c1[t5-1]+c1[t6];
  106530. ch[t5]=c1[t5]+c1[t6-1];
  106531. ch[t6]=c1[t5]-c1[t6-1];
  106532. t5+=ido;
  106533. t6+=ido;
  106534. }
  106535. }
  106536. }
  106537. L132:
  106538. if(ido==1)return;
  106539. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106540. t1=0;
  106541. for(j=1;j<ip;j++){
  106542. t2=(t1+=t0);
  106543. for(k=0;k<l1;k++){
  106544. c1[t2]=ch[t2];
  106545. t2+=ido;
  106546. }
  106547. }
  106548. if(nbd>l1)goto L139;
  106549. is= -ido-1;
  106550. t1=0;
  106551. for(j=1;j<ip;j++){
  106552. is+=ido;
  106553. t1+=t0;
  106554. idij=is;
  106555. t2=t1;
  106556. for(i=2;i<ido;i+=2){
  106557. t2+=2;
  106558. idij+=2;
  106559. t3=t2;
  106560. for(k=0;k<l1;k++){
  106561. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106562. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106563. t3+=ido;
  106564. }
  106565. }
  106566. }
  106567. return;
  106568. L139:
  106569. is= -ido-1;
  106570. t1=0;
  106571. for(j=1;j<ip;j++){
  106572. is+=ido;
  106573. t1+=t0;
  106574. t2=t1;
  106575. for(k=0;k<l1;k++){
  106576. idij=is;
  106577. t3=t2;
  106578. for(i=2;i<ido;i+=2){
  106579. idij+=2;
  106580. t3+=2;
  106581. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106582. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106583. }
  106584. t2+=ido;
  106585. }
  106586. }
  106587. }
  106588. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106589. int i,k1,l1,l2;
  106590. int na;
  106591. int nf,ip,iw,ix2,ix3,ido,idl1;
  106592. nf=ifac[1];
  106593. na=0;
  106594. l1=1;
  106595. iw=1;
  106596. for(k1=0;k1<nf;k1++){
  106597. ip=ifac[k1 + 2];
  106598. l2=ip*l1;
  106599. ido=n/l2;
  106600. idl1=ido*l1;
  106601. if(ip!=4)goto L103;
  106602. ix2=iw+ido;
  106603. ix3=ix2+ido;
  106604. if(na!=0)
  106605. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106606. else
  106607. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106608. na=1-na;
  106609. goto L115;
  106610. L103:
  106611. if(ip!=2)goto L106;
  106612. if(na!=0)
  106613. dradb2(ido,l1,ch,c,wa+iw-1);
  106614. else
  106615. dradb2(ido,l1,c,ch,wa+iw-1);
  106616. na=1-na;
  106617. goto L115;
  106618. L106:
  106619. if(ip!=3)goto L109;
  106620. ix2=iw+ido;
  106621. if(na!=0)
  106622. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106623. else
  106624. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106625. na=1-na;
  106626. goto L115;
  106627. L109:
  106628. if(na!=0)
  106629. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106630. else
  106631. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106632. if(ido==1)na=1-na;
  106633. L115:
  106634. l1=l2;
  106635. iw+=(ip-1)*ido;
  106636. }
  106637. if(na==0)return;
  106638. for(i=0;i<n;i++)c[i]=ch[i];
  106639. }
  106640. void drft_forward(drft_lookup *l,float *data){
  106641. if(l->n==1)return;
  106642. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106643. }
  106644. void drft_backward(drft_lookup *l,float *data){
  106645. if (l->n==1)return;
  106646. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106647. }
  106648. void drft_init(drft_lookup *l,int n){
  106649. l->n=n;
  106650. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106651. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106652. fdrffti(n, l->trigcache, l->splitcache);
  106653. }
  106654. void drft_clear(drft_lookup *l){
  106655. if(l){
  106656. if(l->trigcache)_ogg_free(l->trigcache);
  106657. if(l->splitcache)_ogg_free(l->splitcache);
  106658. memset(l,0,sizeof(*l));
  106659. }
  106660. }
  106661. #endif
  106662. /*** End of inlined file: smallft.c ***/
  106663. /*** Start of inlined file: synthesis.c ***/
  106664. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106665. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106666. // tasks..
  106667. #if JUCE_MSVC
  106668. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106669. #endif
  106670. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106671. #if JUCE_USE_OGGVORBIS
  106672. #include <stdio.h>
  106673. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106674. vorbis_dsp_state *vd=vb->vd;
  106675. private_state *b=(private_state*)vd->backend_state;
  106676. vorbis_info *vi=vd->vi;
  106677. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106678. oggpack_buffer *opb=&vb->opb;
  106679. int type,mode,i;
  106680. _vorbis_block_ripcord(vb);
  106681. oggpack_readinit(opb,op->packet,op->bytes);
  106682. if(oggpack_read(opb,1)!=0){
  106683. return(OV_ENOTAUDIO);
  106684. }
  106685. mode=oggpack_read(opb,b->modebits);
  106686. if(mode==-1)return(OV_EBADPACKET);
  106687. vb->mode=mode;
  106688. vb->W=ci->mode_param[mode]->blockflag;
  106689. if(vb->W){
  106690. vb->lW=oggpack_read(opb,1);
  106691. vb->nW=oggpack_read(opb,1);
  106692. if(vb->nW==-1) return(OV_EBADPACKET);
  106693. }else{
  106694. vb->lW=0;
  106695. vb->nW=0;
  106696. }
  106697. vb->granulepos=op->granulepos;
  106698. vb->sequence=op->packetno;
  106699. vb->eofflag=op->e_o_s;
  106700. vb->pcmend=ci->blocksizes[vb->W];
  106701. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106702. for(i=0;i<vi->channels;i++)
  106703. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106704. type=ci->map_type[ci->mode_param[mode]->mapping];
  106705. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106706. mapping]));
  106707. }
  106708. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106709. vorbis_dsp_state *vd=vb->vd;
  106710. private_state *b=(private_state*)vd->backend_state;
  106711. vorbis_info *vi=vd->vi;
  106712. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106713. oggpack_buffer *opb=&vb->opb;
  106714. int mode;
  106715. _vorbis_block_ripcord(vb);
  106716. oggpack_readinit(opb,op->packet,op->bytes);
  106717. if(oggpack_read(opb,1)!=0){
  106718. return(OV_ENOTAUDIO);
  106719. }
  106720. mode=oggpack_read(opb,b->modebits);
  106721. if(mode==-1)return(OV_EBADPACKET);
  106722. vb->mode=mode;
  106723. vb->W=ci->mode_param[mode]->blockflag;
  106724. if(vb->W){
  106725. vb->lW=oggpack_read(opb,1);
  106726. vb->nW=oggpack_read(opb,1);
  106727. if(vb->nW==-1) return(OV_EBADPACKET);
  106728. }else{
  106729. vb->lW=0;
  106730. vb->nW=0;
  106731. }
  106732. vb->granulepos=op->granulepos;
  106733. vb->sequence=op->packetno;
  106734. vb->eofflag=op->e_o_s;
  106735. vb->pcmend=0;
  106736. vb->pcm=NULL;
  106737. return(0);
  106738. }
  106739. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106740. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106741. oggpack_buffer opb;
  106742. int mode;
  106743. oggpack_readinit(&opb,op->packet,op->bytes);
  106744. if(oggpack_read(&opb,1)!=0){
  106745. return(OV_ENOTAUDIO);
  106746. }
  106747. {
  106748. int modebits=0;
  106749. int v=ci->modes;
  106750. while(v>1){
  106751. modebits++;
  106752. v>>=1;
  106753. }
  106754. mode=oggpack_read(&opb,modebits);
  106755. }
  106756. if(mode==-1)return(OV_EBADPACKET);
  106757. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106758. }
  106759. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106760. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106761. if(ci->blocksizes[0]<=64 && flag)return -1;
  106762. ci->halfrate_flag=(flag?1:0);
  106763. return 0;
  106764. }
  106765. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106766. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106767. return ci->halfrate_flag;
  106768. }
  106769. #endif
  106770. /*** End of inlined file: synthesis.c ***/
  106771. /*** Start of inlined file: vorbisenc.c ***/
  106772. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106773. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106774. // tasks..
  106775. #if JUCE_MSVC
  106776. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106777. #endif
  106778. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106779. #if JUCE_USE_OGGVORBIS
  106780. #include <stdlib.h>
  106781. #include <string.h>
  106782. #include <math.h>
  106783. typedef struct {
  106784. static_codebook *books[12][3];
  106785. } static_bookblock;
  106786. typedef struct {
  106787. int res_type;
  106788. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106789. vorbis_info_residue0 *res;
  106790. static_codebook *book_aux;
  106791. static_codebook *book_aux_managed;
  106792. static_bookblock *books_base;
  106793. static_bookblock *books_base_managed;
  106794. } vorbis_residue_template;
  106795. typedef struct {
  106796. vorbis_info_mapping0 *map;
  106797. vorbis_residue_template *res;
  106798. } vorbis_mapping_template;
  106799. typedef struct vp_adjblock{
  106800. int block[P_BANDS];
  106801. } vp_adjblock;
  106802. typedef struct {
  106803. int data[NOISE_COMPAND_LEVELS];
  106804. } compandblock;
  106805. typedef struct {
  106806. int att[P_NOISECURVES];
  106807. float boost;
  106808. float decay;
  106809. } att3;
  106810. typedef struct { int data[P_NOISECURVES]; } adj3;
  106811. typedef struct {
  106812. int pre[PACKETBLOBS];
  106813. int post[PACKETBLOBS];
  106814. float kHz[PACKETBLOBS];
  106815. float lowpasskHz[PACKETBLOBS];
  106816. } adj_stereo;
  106817. typedef struct {
  106818. int lo;
  106819. int hi;
  106820. int fixed;
  106821. } noiseguard;
  106822. typedef struct {
  106823. int data[P_NOISECURVES][17];
  106824. } noise3;
  106825. typedef struct {
  106826. int mappings;
  106827. double *rate_mapping;
  106828. double *quality_mapping;
  106829. int coupling_restriction;
  106830. long samplerate_min_restriction;
  106831. long samplerate_max_restriction;
  106832. int *blocksize_short;
  106833. int *blocksize_long;
  106834. att3 *psy_tone_masteratt;
  106835. int *psy_tone_0dB;
  106836. int *psy_tone_dBsuppress;
  106837. vp_adjblock *psy_tone_adj_impulse;
  106838. vp_adjblock *psy_tone_adj_long;
  106839. vp_adjblock *psy_tone_adj_other;
  106840. noiseguard *psy_noiseguards;
  106841. noise3 *psy_noise_bias_impulse;
  106842. noise3 *psy_noise_bias_padding;
  106843. noise3 *psy_noise_bias_trans;
  106844. noise3 *psy_noise_bias_long;
  106845. int *psy_noise_dBsuppress;
  106846. compandblock *psy_noise_compand;
  106847. double *psy_noise_compand_short_mapping;
  106848. double *psy_noise_compand_long_mapping;
  106849. int *psy_noise_normal_start[2];
  106850. int *psy_noise_normal_partition[2];
  106851. double *psy_noise_normal_thresh;
  106852. int *psy_ath_float;
  106853. int *psy_ath_abs;
  106854. double *psy_lowpass;
  106855. vorbis_info_psy_global *global_params;
  106856. double *global_mapping;
  106857. adj_stereo *stereo_modes;
  106858. static_codebook ***floor_books;
  106859. vorbis_info_floor1 *floor_params;
  106860. int *floor_short_mapping;
  106861. int *floor_long_mapping;
  106862. vorbis_mapping_template *maps;
  106863. } ve_setup_data_template;
  106864. static vorbis_info_mode _mode_template[2]={
  106865. {0,0,0,0},
  106866. {1,0,0,1}
  106867. };
  106868. static vorbis_info_mapping0 _map_nominal[2]={
  106869. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106870. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106871. };
  106872. /*** Start of inlined file: setup_44.h ***/
  106873. /*** Start of inlined file: floor_all.h ***/
  106874. /*** Start of inlined file: floor_books.h ***/
  106875. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106876. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106877. };
  106878. static static_codebook _huff_book_line_256x7_0sub1 = {
  106879. 1, 9,
  106880. _huff_lengthlist_line_256x7_0sub1,
  106881. 0, 0, 0, 0, 0,
  106882. NULL,
  106883. NULL,
  106884. NULL,
  106885. NULL,
  106886. 0
  106887. };
  106888. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106890. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106891. };
  106892. static static_codebook _huff_book_line_256x7_0sub2 = {
  106893. 1, 25,
  106894. _huff_lengthlist_line_256x7_0sub2,
  106895. 0, 0, 0, 0, 0,
  106896. NULL,
  106897. NULL,
  106898. NULL,
  106899. NULL,
  106900. 0
  106901. };
  106902. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106905. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106906. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106907. };
  106908. static static_codebook _huff_book_line_256x7_0sub3 = {
  106909. 1, 64,
  106910. _huff_lengthlist_line_256x7_0sub3,
  106911. 0, 0, 0, 0, 0,
  106912. NULL,
  106913. NULL,
  106914. NULL,
  106915. NULL,
  106916. 0
  106917. };
  106918. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106919. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106920. };
  106921. static static_codebook _huff_book_line_256x7_1sub1 = {
  106922. 1, 9,
  106923. _huff_lengthlist_line_256x7_1sub1,
  106924. 0, 0, 0, 0, 0,
  106925. NULL,
  106926. NULL,
  106927. NULL,
  106928. NULL,
  106929. 0
  106930. };
  106931. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106933. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106934. };
  106935. static static_codebook _huff_book_line_256x7_1sub2 = {
  106936. 1, 25,
  106937. _huff_lengthlist_line_256x7_1sub2,
  106938. 0, 0, 0, 0, 0,
  106939. NULL,
  106940. NULL,
  106941. NULL,
  106942. NULL,
  106943. 0
  106944. };
  106945. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106948. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106949. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106950. };
  106951. static static_codebook _huff_book_line_256x7_1sub3 = {
  106952. 1, 64,
  106953. _huff_lengthlist_line_256x7_1sub3,
  106954. 0, 0, 0, 0, 0,
  106955. NULL,
  106956. NULL,
  106957. NULL,
  106958. NULL,
  106959. 0
  106960. };
  106961. static long _huff_lengthlist_line_256x7_class0[] = {
  106962. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106963. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106964. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106965. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106966. };
  106967. static static_codebook _huff_book_line_256x7_class0 = {
  106968. 1, 64,
  106969. _huff_lengthlist_line_256x7_class0,
  106970. 0, 0, 0, 0, 0,
  106971. NULL,
  106972. NULL,
  106973. NULL,
  106974. NULL,
  106975. 0
  106976. };
  106977. static long _huff_lengthlist_line_256x7_class1[] = {
  106978. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106979. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106980. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106981. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106982. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106983. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106984. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106985. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106986. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106987. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106988. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106989. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106990. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106991. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106992. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106993. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106994. };
  106995. static static_codebook _huff_book_line_256x7_class1 = {
  106996. 1, 256,
  106997. _huff_lengthlist_line_256x7_class1,
  106998. 0, 0, 0, 0, 0,
  106999. NULL,
  107000. NULL,
  107001. NULL,
  107002. NULL,
  107003. 0
  107004. };
  107005. static long _huff_lengthlist_line_512x17_0sub0[] = {
  107006. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  107007. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  107008. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  107009. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  107010. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  107011. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  107012. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  107013. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107014. };
  107015. static static_codebook _huff_book_line_512x17_0sub0 = {
  107016. 1, 128,
  107017. _huff_lengthlist_line_512x17_0sub0,
  107018. 0, 0, 0, 0, 0,
  107019. NULL,
  107020. NULL,
  107021. NULL,
  107022. NULL,
  107023. 0
  107024. };
  107025. static long _huff_lengthlist_line_512x17_1sub0[] = {
  107026. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107027. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  107028. };
  107029. static static_codebook _huff_book_line_512x17_1sub0 = {
  107030. 1, 32,
  107031. _huff_lengthlist_line_512x17_1sub0,
  107032. 0, 0, 0, 0, 0,
  107033. NULL,
  107034. NULL,
  107035. NULL,
  107036. NULL,
  107037. 0
  107038. };
  107039. static long _huff_lengthlist_line_512x17_1sub1[] = {
  107040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107042. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  107043. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  107044. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  107045. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  107046. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  107047. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  107048. };
  107049. static static_codebook _huff_book_line_512x17_1sub1 = {
  107050. 1, 128,
  107051. _huff_lengthlist_line_512x17_1sub1,
  107052. 0, 0, 0, 0, 0,
  107053. NULL,
  107054. NULL,
  107055. NULL,
  107056. NULL,
  107057. 0
  107058. };
  107059. static long _huff_lengthlist_line_512x17_2sub1[] = {
  107060. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  107061. 5, 3,
  107062. };
  107063. static static_codebook _huff_book_line_512x17_2sub1 = {
  107064. 1, 18,
  107065. _huff_lengthlist_line_512x17_2sub1,
  107066. 0, 0, 0, 0, 0,
  107067. NULL,
  107068. NULL,
  107069. NULL,
  107070. NULL,
  107071. 0
  107072. };
  107073. static long _huff_lengthlist_line_512x17_2sub2[] = {
  107074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107075. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  107076. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  107077. 9, 8,
  107078. };
  107079. static static_codebook _huff_book_line_512x17_2sub2 = {
  107080. 1, 50,
  107081. _huff_lengthlist_line_512x17_2sub2,
  107082. 0, 0, 0, 0, 0,
  107083. NULL,
  107084. NULL,
  107085. NULL,
  107086. NULL,
  107087. 0
  107088. };
  107089. static long _huff_lengthlist_line_512x17_2sub3[] = {
  107090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107093. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  107094. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  107095. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107096. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107097. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107098. };
  107099. static static_codebook _huff_book_line_512x17_2sub3 = {
  107100. 1, 128,
  107101. _huff_lengthlist_line_512x17_2sub3,
  107102. 0, 0, 0, 0, 0,
  107103. NULL,
  107104. NULL,
  107105. NULL,
  107106. NULL,
  107107. 0
  107108. };
  107109. static long _huff_lengthlist_line_512x17_3sub1[] = {
  107110. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  107111. 5, 5,
  107112. };
  107113. static static_codebook _huff_book_line_512x17_3sub1 = {
  107114. 1, 18,
  107115. _huff_lengthlist_line_512x17_3sub1,
  107116. 0, 0, 0, 0, 0,
  107117. NULL,
  107118. NULL,
  107119. NULL,
  107120. NULL,
  107121. 0
  107122. };
  107123. static long _huff_lengthlist_line_512x17_3sub2[] = {
  107124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107125. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  107126. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  107127. 11,14,
  107128. };
  107129. static static_codebook _huff_book_line_512x17_3sub2 = {
  107130. 1, 50,
  107131. _huff_lengthlist_line_512x17_3sub2,
  107132. 0, 0, 0, 0, 0,
  107133. NULL,
  107134. NULL,
  107135. NULL,
  107136. NULL,
  107137. 0
  107138. };
  107139. static long _huff_lengthlist_line_512x17_3sub3[] = {
  107140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107143. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  107144. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107145. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107146. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107147. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107148. };
  107149. static static_codebook _huff_book_line_512x17_3sub3 = {
  107150. 1, 128,
  107151. _huff_lengthlist_line_512x17_3sub3,
  107152. 0, 0, 0, 0, 0,
  107153. NULL,
  107154. NULL,
  107155. NULL,
  107156. NULL,
  107157. 0
  107158. };
  107159. static long _huff_lengthlist_line_512x17_class1[] = {
  107160. 1, 2, 3, 6, 5, 4, 7, 7,
  107161. };
  107162. static static_codebook _huff_book_line_512x17_class1 = {
  107163. 1, 8,
  107164. _huff_lengthlist_line_512x17_class1,
  107165. 0, 0, 0, 0, 0,
  107166. NULL,
  107167. NULL,
  107168. NULL,
  107169. NULL,
  107170. 0
  107171. };
  107172. static long _huff_lengthlist_line_512x17_class2[] = {
  107173. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  107174. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  107175. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  107176. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  107177. };
  107178. static static_codebook _huff_book_line_512x17_class2 = {
  107179. 1, 64,
  107180. _huff_lengthlist_line_512x17_class2,
  107181. 0, 0, 0, 0, 0,
  107182. NULL,
  107183. NULL,
  107184. NULL,
  107185. NULL,
  107186. 0
  107187. };
  107188. static long _huff_lengthlist_line_512x17_class3[] = {
  107189. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  107190. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  107191. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  107192. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  107193. };
  107194. static static_codebook _huff_book_line_512x17_class3 = {
  107195. 1, 64,
  107196. _huff_lengthlist_line_512x17_class3,
  107197. 0, 0, 0, 0, 0,
  107198. NULL,
  107199. NULL,
  107200. NULL,
  107201. NULL,
  107202. 0
  107203. };
  107204. static long _huff_lengthlist_line_128x4_class0[] = {
  107205. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  107206. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  107207. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  107208. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  107209. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  107210. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  107211. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  107212. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  107213. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  107214. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  107215. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  107216. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  107217. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  107218. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  107219. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  107220. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  107221. };
  107222. static static_codebook _huff_book_line_128x4_class0 = {
  107223. 1, 256,
  107224. _huff_lengthlist_line_128x4_class0,
  107225. 0, 0, 0, 0, 0,
  107226. NULL,
  107227. NULL,
  107228. NULL,
  107229. NULL,
  107230. 0
  107231. };
  107232. static long _huff_lengthlist_line_128x4_0sub0[] = {
  107233. 2, 2, 2, 2,
  107234. };
  107235. static static_codebook _huff_book_line_128x4_0sub0 = {
  107236. 1, 4,
  107237. _huff_lengthlist_line_128x4_0sub0,
  107238. 0, 0, 0, 0, 0,
  107239. NULL,
  107240. NULL,
  107241. NULL,
  107242. NULL,
  107243. 0
  107244. };
  107245. static long _huff_lengthlist_line_128x4_0sub1[] = {
  107246. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  107247. };
  107248. static static_codebook _huff_book_line_128x4_0sub1 = {
  107249. 1, 10,
  107250. _huff_lengthlist_line_128x4_0sub1,
  107251. 0, 0, 0, 0, 0,
  107252. NULL,
  107253. NULL,
  107254. NULL,
  107255. NULL,
  107256. 0
  107257. };
  107258. static long _huff_lengthlist_line_128x4_0sub2[] = {
  107259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  107260. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  107261. };
  107262. static static_codebook _huff_book_line_128x4_0sub2 = {
  107263. 1, 25,
  107264. _huff_lengthlist_line_128x4_0sub2,
  107265. 0, 0, 0, 0, 0,
  107266. NULL,
  107267. NULL,
  107268. NULL,
  107269. NULL,
  107270. 0
  107271. };
  107272. static long _huff_lengthlist_line_128x4_0sub3[] = {
  107273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107275. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  107276. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  107277. };
  107278. static static_codebook _huff_book_line_128x4_0sub3 = {
  107279. 1, 64,
  107280. _huff_lengthlist_line_128x4_0sub3,
  107281. 0, 0, 0, 0, 0,
  107282. NULL,
  107283. NULL,
  107284. NULL,
  107285. NULL,
  107286. 0
  107287. };
  107288. static long _huff_lengthlist_line_256x4_class0[] = {
  107289. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  107290. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  107291. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  107292. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  107293. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  107294. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  107295. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  107296. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  107297. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  107298. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  107299. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  107300. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  107301. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  107302. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  107303. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  107304. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  107305. };
  107306. static static_codebook _huff_book_line_256x4_class0 = {
  107307. 1, 256,
  107308. _huff_lengthlist_line_256x4_class0,
  107309. 0, 0, 0, 0, 0,
  107310. NULL,
  107311. NULL,
  107312. NULL,
  107313. NULL,
  107314. 0
  107315. };
  107316. static long _huff_lengthlist_line_256x4_0sub0[] = {
  107317. 2, 2, 2, 2,
  107318. };
  107319. static static_codebook _huff_book_line_256x4_0sub0 = {
  107320. 1, 4,
  107321. _huff_lengthlist_line_256x4_0sub0,
  107322. 0, 0, 0, 0, 0,
  107323. NULL,
  107324. NULL,
  107325. NULL,
  107326. NULL,
  107327. 0
  107328. };
  107329. static long _huff_lengthlist_line_256x4_0sub1[] = {
  107330. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  107331. };
  107332. static static_codebook _huff_book_line_256x4_0sub1 = {
  107333. 1, 10,
  107334. _huff_lengthlist_line_256x4_0sub1,
  107335. 0, 0, 0, 0, 0,
  107336. NULL,
  107337. NULL,
  107338. NULL,
  107339. NULL,
  107340. 0
  107341. };
  107342. static long _huff_lengthlist_line_256x4_0sub2[] = {
  107343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  107344. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  107345. };
  107346. static static_codebook _huff_book_line_256x4_0sub2 = {
  107347. 1, 25,
  107348. _huff_lengthlist_line_256x4_0sub2,
  107349. 0, 0, 0, 0, 0,
  107350. NULL,
  107351. NULL,
  107352. NULL,
  107353. NULL,
  107354. 0
  107355. };
  107356. static long _huff_lengthlist_line_256x4_0sub3[] = {
  107357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107359. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  107360. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  107361. };
  107362. static static_codebook _huff_book_line_256x4_0sub3 = {
  107363. 1, 64,
  107364. _huff_lengthlist_line_256x4_0sub3,
  107365. 0, 0, 0, 0, 0,
  107366. NULL,
  107367. NULL,
  107368. NULL,
  107369. NULL,
  107370. 0
  107371. };
  107372. static long _huff_lengthlist_line_128x7_class0[] = {
  107373. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  107374. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  107375. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  107376. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  107377. };
  107378. static static_codebook _huff_book_line_128x7_class0 = {
  107379. 1, 64,
  107380. _huff_lengthlist_line_128x7_class0,
  107381. 0, 0, 0, 0, 0,
  107382. NULL,
  107383. NULL,
  107384. NULL,
  107385. NULL,
  107386. 0
  107387. };
  107388. static long _huff_lengthlist_line_128x7_class1[] = {
  107389. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  107390. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  107391. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  107392. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107393. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  107394. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  107395. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  107396. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  107397. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  107398. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  107399. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  107400. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  107401. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  107402. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  107403. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  107404. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  107405. };
  107406. static static_codebook _huff_book_line_128x7_class1 = {
  107407. 1, 256,
  107408. _huff_lengthlist_line_128x7_class1,
  107409. 0, 0, 0, 0, 0,
  107410. NULL,
  107411. NULL,
  107412. NULL,
  107413. NULL,
  107414. 0
  107415. };
  107416. static long _huff_lengthlist_line_128x7_0sub1[] = {
  107417. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  107418. };
  107419. static static_codebook _huff_book_line_128x7_0sub1 = {
  107420. 1, 9,
  107421. _huff_lengthlist_line_128x7_0sub1,
  107422. 0, 0, 0, 0, 0,
  107423. NULL,
  107424. NULL,
  107425. NULL,
  107426. NULL,
  107427. 0
  107428. };
  107429. static long _huff_lengthlist_line_128x7_0sub2[] = {
  107430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  107431. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  107432. };
  107433. static static_codebook _huff_book_line_128x7_0sub2 = {
  107434. 1, 25,
  107435. _huff_lengthlist_line_128x7_0sub2,
  107436. 0, 0, 0, 0, 0,
  107437. NULL,
  107438. NULL,
  107439. NULL,
  107440. NULL,
  107441. 0
  107442. };
  107443. static long _huff_lengthlist_line_128x7_0sub3[] = {
  107444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  107446. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107447. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  107448. };
  107449. static static_codebook _huff_book_line_128x7_0sub3 = {
  107450. 1, 64,
  107451. _huff_lengthlist_line_128x7_0sub3,
  107452. 0, 0, 0, 0, 0,
  107453. NULL,
  107454. NULL,
  107455. NULL,
  107456. NULL,
  107457. 0
  107458. };
  107459. static long _huff_lengthlist_line_128x7_1sub1[] = {
  107460. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  107461. };
  107462. static static_codebook _huff_book_line_128x7_1sub1 = {
  107463. 1, 9,
  107464. _huff_lengthlist_line_128x7_1sub1,
  107465. 0, 0, 0, 0, 0,
  107466. NULL,
  107467. NULL,
  107468. NULL,
  107469. NULL,
  107470. 0
  107471. };
  107472. static long _huff_lengthlist_line_128x7_1sub2[] = {
  107473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  107474. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  107475. };
  107476. static static_codebook _huff_book_line_128x7_1sub2 = {
  107477. 1, 25,
  107478. _huff_lengthlist_line_128x7_1sub2,
  107479. 0, 0, 0, 0, 0,
  107480. NULL,
  107481. NULL,
  107482. NULL,
  107483. NULL,
  107484. 0
  107485. };
  107486. static long _huff_lengthlist_line_128x7_1sub3[] = {
  107487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  107489. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  107490. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  107491. };
  107492. static static_codebook _huff_book_line_128x7_1sub3 = {
  107493. 1, 64,
  107494. _huff_lengthlist_line_128x7_1sub3,
  107495. 0, 0, 0, 0, 0,
  107496. NULL,
  107497. NULL,
  107498. NULL,
  107499. NULL,
  107500. 0
  107501. };
  107502. static long _huff_lengthlist_line_128x11_class1[] = {
  107503. 1, 6, 3, 7, 2, 4, 5, 7,
  107504. };
  107505. static static_codebook _huff_book_line_128x11_class1 = {
  107506. 1, 8,
  107507. _huff_lengthlist_line_128x11_class1,
  107508. 0, 0, 0, 0, 0,
  107509. NULL,
  107510. NULL,
  107511. NULL,
  107512. NULL,
  107513. 0
  107514. };
  107515. static long _huff_lengthlist_line_128x11_class2[] = {
  107516. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  107517. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  107518. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  107519. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  107520. };
  107521. static static_codebook _huff_book_line_128x11_class2 = {
  107522. 1, 64,
  107523. _huff_lengthlist_line_128x11_class2,
  107524. 0, 0, 0, 0, 0,
  107525. NULL,
  107526. NULL,
  107527. NULL,
  107528. NULL,
  107529. 0
  107530. };
  107531. static long _huff_lengthlist_line_128x11_class3[] = {
  107532. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107533. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107534. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107535. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107536. };
  107537. static static_codebook _huff_book_line_128x11_class3 = {
  107538. 1, 64,
  107539. _huff_lengthlist_line_128x11_class3,
  107540. 0, 0, 0, 0, 0,
  107541. NULL,
  107542. NULL,
  107543. NULL,
  107544. NULL,
  107545. 0
  107546. };
  107547. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107548. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107549. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107550. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107551. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107552. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107553. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107554. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107555. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107556. };
  107557. static static_codebook _huff_book_line_128x11_0sub0 = {
  107558. 1, 128,
  107559. _huff_lengthlist_line_128x11_0sub0,
  107560. 0, 0, 0, 0, 0,
  107561. NULL,
  107562. NULL,
  107563. NULL,
  107564. NULL,
  107565. 0
  107566. };
  107567. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107568. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107569. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107570. };
  107571. static static_codebook _huff_book_line_128x11_1sub0 = {
  107572. 1, 32,
  107573. _huff_lengthlist_line_128x11_1sub0,
  107574. 0, 0, 0, 0, 0,
  107575. NULL,
  107576. NULL,
  107577. NULL,
  107578. NULL,
  107579. 0
  107580. };
  107581. static long _huff_lengthlist_line_128x11_1sub1[] = {
  107582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107584. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107585. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107586. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107587. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107588. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107589. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107590. };
  107591. static static_codebook _huff_book_line_128x11_1sub1 = {
  107592. 1, 128,
  107593. _huff_lengthlist_line_128x11_1sub1,
  107594. 0, 0, 0, 0, 0,
  107595. NULL,
  107596. NULL,
  107597. NULL,
  107598. NULL,
  107599. 0
  107600. };
  107601. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107602. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107603. 5, 5,
  107604. };
  107605. static static_codebook _huff_book_line_128x11_2sub1 = {
  107606. 1, 18,
  107607. _huff_lengthlist_line_128x11_2sub1,
  107608. 0, 0, 0, 0, 0,
  107609. NULL,
  107610. NULL,
  107611. NULL,
  107612. NULL,
  107613. 0
  107614. };
  107615. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107617. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107618. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107619. 8,11,
  107620. };
  107621. static static_codebook _huff_book_line_128x11_2sub2 = {
  107622. 1, 50,
  107623. _huff_lengthlist_line_128x11_2sub2,
  107624. 0, 0, 0, 0, 0,
  107625. NULL,
  107626. NULL,
  107627. NULL,
  107628. NULL,
  107629. 0
  107630. };
  107631. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107635. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107636. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107637. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107638. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107639. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107640. };
  107641. static static_codebook _huff_book_line_128x11_2sub3 = {
  107642. 1, 128,
  107643. _huff_lengthlist_line_128x11_2sub3,
  107644. 0, 0, 0, 0, 0,
  107645. NULL,
  107646. NULL,
  107647. NULL,
  107648. NULL,
  107649. 0
  107650. };
  107651. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107652. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107653. 5, 4,
  107654. };
  107655. static static_codebook _huff_book_line_128x11_3sub1 = {
  107656. 1, 18,
  107657. _huff_lengthlist_line_128x11_3sub1,
  107658. 0, 0, 0, 0, 0,
  107659. NULL,
  107660. NULL,
  107661. NULL,
  107662. NULL,
  107663. 0
  107664. };
  107665. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107667. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107668. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107669. 12, 6,
  107670. };
  107671. static static_codebook _huff_book_line_128x11_3sub2 = {
  107672. 1, 50,
  107673. _huff_lengthlist_line_128x11_3sub2,
  107674. 0, 0, 0, 0, 0,
  107675. NULL,
  107676. NULL,
  107677. NULL,
  107678. NULL,
  107679. 0
  107680. };
  107681. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107685. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107686. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107687. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107688. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107689. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107690. };
  107691. static static_codebook _huff_book_line_128x11_3sub3 = {
  107692. 1, 128,
  107693. _huff_lengthlist_line_128x11_3sub3,
  107694. 0, 0, 0, 0, 0,
  107695. NULL,
  107696. NULL,
  107697. NULL,
  107698. NULL,
  107699. 0
  107700. };
  107701. static long _huff_lengthlist_line_128x17_class1[] = {
  107702. 1, 3, 4, 7, 2, 5, 6, 7,
  107703. };
  107704. static static_codebook _huff_book_line_128x17_class1 = {
  107705. 1, 8,
  107706. _huff_lengthlist_line_128x17_class1,
  107707. 0, 0, 0, 0, 0,
  107708. NULL,
  107709. NULL,
  107710. NULL,
  107711. NULL,
  107712. 0
  107713. };
  107714. static long _huff_lengthlist_line_128x17_class2[] = {
  107715. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107716. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107717. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107718. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107719. };
  107720. static static_codebook _huff_book_line_128x17_class2 = {
  107721. 1, 64,
  107722. _huff_lengthlist_line_128x17_class2,
  107723. 0, 0, 0, 0, 0,
  107724. NULL,
  107725. NULL,
  107726. NULL,
  107727. NULL,
  107728. 0
  107729. };
  107730. static long _huff_lengthlist_line_128x17_class3[] = {
  107731. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107732. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107733. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107734. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107735. };
  107736. static static_codebook _huff_book_line_128x17_class3 = {
  107737. 1, 64,
  107738. _huff_lengthlist_line_128x17_class3,
  107739. 0, 0, 0, 0, 0,
  107740. NULL,
  107741. NULL,
  107742. NULL,
  107743. NULL,
  107744. 0
  107745. };
  107746. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107747. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107748. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107749. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107750. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107751. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107752. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107753. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107754. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107755. };
  107756. static static_codebook _huff_book_line_128x17_0sub0 = {
  107757. 1, 128,
  107758. _huff_lengthlist_line_128x17_0sub0,
  107759. 0, 0, 0, 0, 0,
  107760. NULL,
  107761. NULL,
  107762. NULL,
  107763. NULL,
  107764. 0
  107765. };
  107766. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107767. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107768. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107769. };
  107770. static static_codebook _huff_book_line_128x17_1sub0 = {
  107771. 1, 32,
  107772. _huff_lengthlist_line_128x17_1sub0,
  107773. 0, 0, 0, 0, 0,
  107774. NULL,
  107775. NULL,
  107776. NULL,
  107777. NULL,
  107778. 0
  107779. };
  107780. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107783. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107784. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107785. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107786. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107787. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107788. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107789. };
  107790. static static_codebook _huff_book_line_128x17_1sub1 = {
  107791. 1, 128,
  107792. _huff_lengthlist_line_128x17_1sub1,
  107793. 0, 0, 0, 0, 0,
  107794. NULL,
  107795. NULL,
  107796. NULL,
  107797. NULL,
  107798. 0
  107799. };
  107800. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107801. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107802. 9, 4,
  107803. };
  107804. static static_codebook _huff_book_line_128x17_2sub1 = {
  107805. 1, 18,
  107806. _huff_lengthlist_line_128x17_2sub1,
  107807. 0, 0, 0, 0, 0,
  107808. NULL,
  107809. NULL,
  107810. NULL,
  107811. NULL,
  107812. 0
  107813. };
  107814. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107816. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107817. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107818. 13,13,
  107819. };
  107820. static static_codebook _huff_book_line_128x17_2sub2 = {
  107821. 1, 50,
  107822. _huff_lengthlist_line_128x17_2sub2,
  107823. 0, 0, 0, 0, 0,
  107824. NULL,
  107825. NULL,
  107826. NULL,
  107827. NULL,
  107828. 0
  107829. };
  107830. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107834. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107835. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107836. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107837. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107838. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107839. };
  107840. static static_codebook _huff_book_line_128x17_2sub3 = {
  107841. 1, 128,
  107842. _huff_lengthlist_line_128x17_2sub3,
  107843. 0, 0, 0, 0, 0,
  107844. NULL,
  107845. NULL,
  107846. NULL,
  107847. NULL,
  107848. 0
  107849. };
  107850. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107851. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107852. 6, 4,
  107853. };
  107854. static static_codebook _huff_book_line_128x17_3sub1 = {
  107855. 1, 18,
  107856. _huff_lengthlist_line_128x17_3sub1,
  107857. 0, 0, 0, 0, 0,
  107858. NULL,
  107859. NULL,
  107860. NULL,
  107861. NULL,
  107862. 0
  107863. };
  107864. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107866. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107867. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107868. 10, 8,
  107869. };
  107870. static static_codebook _huff_book_line_128x17_3sub2 = {
  107871. 1, 50,
  107872. _huff_lengthlist_line_128x17_3sub2,
  107873. 0, 0, 0, 0, 0,
  107874. NULL,
  107875. NULL,
  107876. NULL,
  107877. NULL,
  107878. 0
  107879. };
  107880. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107884. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107885. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107886. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107887. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107888. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107889. };
  107890. static static_codebook _huff_book_line_128x17_3sub3 = {
  107891. 1, 128,
  107892. _huff_lengthlist_line_128x17_3sub3,
  107893. 0, 0, 0, 0, 0,
  107894. NULL,
  107895. NULL,
  107896. NULL,
  107897. NULL,
  107898. 0
  107899. };
  107900. static long _huff_lengthlist_line_1024x27_class1[] = {
  107901. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107902. };
  107903. static static_codebook _huff_book_line_1024x27_class1 = {
  107904. 1, 16,
  107905. _huff_lengthlist_line_1024x27_class1,
  107906. 0, 0, 0, 0, 0,
  107907. NULL,
  107908. NULL,
  107909. NULL,
  107910. NULL,
  107911. 0
  107912. };
  107913. static long _huff_lengthlist_line_1024x27_class2[] = {
  107914. 1, 4, 2, 6, 3, 7, 5, 7,
  107915. };
  107916. static static_codebook _huff_book_line_1024x27_class2 = {
  107917. 1, 8,
  107918. _huff_lengthlist_line_1024x27_class2,
  107919. 0, 0, 0, 0, 0,
  107920. NULL,
  107921. NULL,
  107922. NULL,
  107923. NULL,
  107924. 0
  107925. };
  107926. static long _huff_lengthlist_line_1024x27_class3[] = {
  107927. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107928. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107929. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107930. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107931. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107932. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107933. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107934. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107935. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107936. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107937. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107938. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107939. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107940. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107941. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107942. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107943. };
  107944. static static_codebook _huff_book_line_1024x27_class3 = {
  107945. 1, 256,
  107946. _huff_lengthlist_line_1024x27_class3,
  107947. 0, 0, 0, 0, 0,
  107948. NULL,
  107949. NULL,
  107950. NULL,
  107951. NULL,
  107952. 0
  107953. };
  107954. static long _huff_lengthlist_line_1024x27_class4[] = {
  107955. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107956. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107957. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107958. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107959. };
  107960. static static_codebook _huff_book_line_1024x27_class4 = {
  107961. 1, 64,
  107962. _huff_lengthlist_line_1024x27_class4,
  107963. 0, 0, 0, 0, 0,
  107964. NULL,
  107965. NULL,
  107966. NULL,
  107967. NULL,
  107968. 0
  107969. };
  107970. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107971. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107972. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107973. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107974. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107975. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107976. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107977. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107978. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107979. };
  107980. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107981. 1, 128,
  107982. _huff_lengthlist_line_1024x27_0sub0,
  107983. 0, 0, 0, 0, 0,
  107984. NULL,
  107985. NULL,
  107986. NULL,
  107987. NULL,
  107988. 0
  107989. };
  107990. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107991. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107992. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107993. };
  107994. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107995. 1, 32,
  107996. _huff_lengthlist_line_1024x27_1sub0,
  107997. 0, 0, 0, 0, 0,
  107998. NULL,
  107999. NULL,
  108000. NULL,
  108001. NULL,
  108002. 0
  108003. };
  108004. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  108005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108007. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  108008. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  108009. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  108010. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  108011. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  108012. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  108013. };
  108014. static static_codebook _huff_book_line_1024x27_1sub1 = {
  108015. 1, 128,
  108016. _huff_lengthlist_line_1024x27_1sub1,
  108017. 0, 0, 0, 0, 0,
  108018. NULL,
  108019. NULL,
  108020. NULL,
  108021. NULL,
  108022. 0
  108023. };
  108024. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  108025. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108026. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  108027. };
  108028. static static_codebook _huff_book_line_1024x27_2sub0 = {
  108029. 1, 32,
  108030. _huff_lengthlist_line_1024x27_2sub0,
  108031. 0, 0, 0, 0, 0,
  108032. NULL,
  108033. NULL,
  108034. NULL,
  108035. NULL,
  108036. 0
  108037. };
  108038. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  108039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108041. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  108042. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  108043. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  108044. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  108045. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  108046. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  108047. };
  108048. static static_codebook _huff_book_line_1024x27_2sub1 = {
  108049. 1, 128,
  108050. _huff_lengthlist_line_1024x27_2sub1,
  108051. 0, 0, 0, 0, 0,
  108052. NULL,
  108053. NULL,
  108054. NULL,
  108055. NULL,
  108056. 0
  108057. };
  108058. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  108059. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  108060. 5, 5,
  108061. };
  108062. static static_codebook _huff_book_line_1024x27_3sub1 = {
  108063. 1, 18,
  108064. _huff_lengthlist_line_1024x27_3sub1,
  108065. 0, 0, 0, 0, 0,
  108066. NULL,
  108067. NULL,
  108068. NULL,
  108069. NULL,
  108070. 0
  108071. };
  108072. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  108073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108074. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  108075. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  108076. 9,11,
  108077. };
  108078. static static_codebook _huff_book_line_1024x27_3sub2 = {
  108079. 1, 50,
  108080. _huff_lengthlist_line_1024x27_3sub2,
  108081. 0, 0, 0, 0, 0,
  108082. NULL,
  108083. NULL,
  108084. NULL,
  108085. NULL,
  108086. 0
  108087. };
  108088. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  108089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108092. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  108093. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  108094. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108095. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108096. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108097. };
  108098. static static_codebook _huff_book_line_1024x27_3sub3 = {
  108099. 1, 128,
  108100. _huff_lengthlist_line_1024x27_3sub3,
  108101. 0, 0, 0, 0, 0,
  108102. NULL,
  108103. NULL,
  108104. NULL,
  108105. NULL,
  108106. 0
  108107. };
  108108. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  108109. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  108110. 5, 4,
  108111. };
  108112. static static_codebook _huff_book_line_1024x27_4sub1 = {
  108113. 1, 18,
  108114. _huff_lengthlist_line_1024x27_4sub1,
  108115. 0, 0, 0, 0, 0,
  108116. NULL,
  108117. NULL,
  108118. NULL,
  108119. NULL,
  108120. 0
  108121. };
  108122. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  108123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108124. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  108125. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  108126. 9,12,
  108127. };
  108128. static static_codebook _huff_book_line_1024x27_4sub2 = {
  108129. 1, 50,
  108130. _huff_lengthlist_line_1024x27_4sub2,
  108131. 0, 0, 0, 0, 0,
  108132. NULL,
  108133. NULL,
  108134. NULL,
  108135. NULL,
  108136. 0
  108137. };
  108138. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  108139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108142. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  108143. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  108144. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108145. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108146. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  108147. };
  108148. static static_codebook _huff_book_line_1024x27_4sub3 = {
  108149. 1, 128,
  108150. _huff_lengthlist_line_1024x27_4sub3,
  108151. 0, 0, 0, 0, 0,
  108152. NULL,
  108153. NULL,
  108154. NULL,
  108155. NULL,
  108156. 0
  108157. };
  108158. static long _huff_lengthlist_line_2048x27_class1[] = {
  108159. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  108160. };
  108161. static static_codebook _huff_book_line_2048x27_class1 = {
  108162. 1, 16,
  108163. _huff_lengthlist_line_2048x27_class1,
  108164. 0, 0, 0, 0, 0,
  108165. NULL,
  108166. NULL,
  108167. NULL,
  108168. NULL,
  108169. 0
  108170. };
  108171. static long _huff_lengthlist_line_2048x27_class2[] = {
  108172. 1, 2, 3, 6, 4, 7, 5, 7,
  108173. };
  108174. static static_codebook _huff_book_line_2048x27_class2 = {
  108175. 1, 8,
  108176. _huff_lengthlist_line_2048x27_class2,
  108177. 0, 0, 0, 0, 0,
  108178. NULL,
  108179. NULL,
  108180. NULL,
  108181. NULL,
  108182. 0
  108183. };
  108184. static long _huff_lengthlist_line_2048x27_class3[] = {
  108185. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  108186. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  108187. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  108188. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  108189. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  108190. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  108191. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  108192. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  108193. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  108194. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  108195. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  108196. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108197. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  108198. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  108199. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108200. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108201. };
  108202. static static_codebook _huff_book_line_2048x27_class3 = {
  108203. 1, 256,
  108204. _huff_lengthlist_line_2048x27_class3,
  108205. 0, 0, 0, 0, 0,
  108206. NULL,
  108207. NULL,
  108208. NULL,
  108209. NULL,
  108210. 0
  108211. };
  108212. static long _huff_lengthlist_line_2048x27_class4[] = {
  108213. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  108214. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  108215. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  108216. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  108217. };
  108218. static static_codebook _huff_book_line_2048x27_class4 = {
  108219. 1, 64,
  108220. _huff_lengthlist_line_2048x27_class4,
  108221. 0, 0, 0, 0, 0,
  108222. NULL,
  108223. NULL,
  108224. NULL,
  108225. NULL,
  108226. 0
  108227. };
  108228. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  108229. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108230. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  108231. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  108232. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  108233. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  108234. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  108235. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  108236. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  108237. };
  108238. static static_codebook _huff_book_line_2048x27_0sub0 = {
  108239. 1, 128,
  108240. _huff_lengthlist_line_2048x27_0sub0,
  108241. 0, 0, 0, 0, 0,
  108242. NULL,
  108243. NULL,
  108244. NULL,
  108245. NULL,
  108246. 0
  108247. };
  108248. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  108249. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  108250. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  108251. };
  108252. static static_codebook _huff_book_line_2048x27_1sub0 = {
  108253. 1, 32,
  108254. _huff_lengthlist_line_2048x27_1sub0,
  108255. 0, 0, 0, 0, 0,
  108256. NULL,
  108257. NULL,
  108258. NULL,
  108259. NULL,
  108260. 0
  108261. };
  108262. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  108263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108265. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  108266. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  108267. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  108268. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  108269. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  108270. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  108271. };
  108272. static static_codebook _huff_book_line_2048x27_1sub1 = {
  108273. 1, 128,
  108274. _huff_lengthlist_line_2048x27_1sub1,
  108275. 0, 0, 0, 0, 0,
  108276. NULL,
  108277. NULL,
  108278. NULL,
  108279. NULL,
  108280. 0
  108281. };
  108282. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  108283. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  108284. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  108285. };
  108286. static static_codebook _huff_book_line_2048x27_2sub0 = {
  108287. 1, 32,
  108288. _huff_lengthlist_line_2048x27_2sub0,
  108289. 0, 0, 0, 0, 0,
  108290. NULL,
  108291. NULL,
  108292. NULL,
  108293. NULL,
  108294. 0
  108295. };
  108296. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  108297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108299. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  108300. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  108301. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  108302. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  108303. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  108304. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108305. };
  108306. static static_codebook _huff_book_line_2048x27_2sub1 = {
  108307. 1, 128,
  108308. _huff_lengthlist_line_2048x27_2sub1,
  108309. 0, 0, 0, 0, 0,
  108310. NULL,
  108311. NULL,
  108312. NULL,
  108313. NULL,
  108314. 0
  108315. };
  108316. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  108317. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  108318. 5, 5,
  108319. };
  108320. static static_codebook _huff_book_line_2048x27_3sub1 = {
  108321. 1, 18,
  108322. _huff_lengthlist_line_2048x27_3sub1,
  108323. 0, 0, 0, 0, 0,
  108324. NULL,
  108325. NULL,
  108326. NULL,
  108327. NULL,
  108328. 0
  108329. };
  108330. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  108331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108332. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  108333. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  108334. 10,12,
  108335. };
  108336. static static_codebook _huff_book_line_2048x27_3sub2 = {
  108337. 1, 50,
  108338. _huff_lengthlist_line_2048x27_3sub2,
  108339. 0, 0, 0, 0, 0,
  108340. NULL,
  108341. NULL,
  108342. NULL,
  108343. NULL,
  108344. 0
  108345. };
  108346. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  108347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108350. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  108351. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108352. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108353. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108354. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108355. };
  108356. static static_codebook _huff_book_line_2048x27_3sub3 = {
  108357. 1, 128,
  108358. _huff_lengthlist_line_2048x27_3sub3,
  108359. 0, 0, 0, 0, 0,
  108360. NULL,
  108361. NULL,
  108362. NULL,
  108363. NULL,
  108364. 0
  108365. };
  108366. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  108367. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  108368. 4, 5,
  108369. };
  108370. static static_codebook _huff_book_line_2048x27_4sub1 = {
  108371. 1, 18,
  108372. _huff_lengthlist_line_2048x27_4sub1,
  108373. 0, 0, 0, 0, 0,
  108374. NULL,
  108375. NULL,
  108376. NULL,
  108377. NULL,
  108378. 0
  108379. };
  108380. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  108381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108382. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  108383. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  108384. 10,10,
  108385. };
  108386. static static_codebook _huff_book_line_2048x27_4sub2 = {
  108387. 1, 50,
  108388. _huff_lengthlist_line_2048x27_4sub2,
  108389. 0, 0, 0, 0, 0,
  108390. NULL,
  108391. NULL,
  108392. NULL,
  108393. NULL,
  108394. 0
  108395. };
  108396. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  108397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108400. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  108401. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  108402. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108403. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108404. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108405. };
  108406. static static_codebook _huff_book_line_2048x27_4sub3 = {
  108407. 1, 128,
  108408. _huff_lengthlist_line_2048x27_4sub3,
  108409. 0, 0, 0, 0, 0,
  108410. NULL,
  108411. NULL,
  108412. NULL,
  108413. NULL,
  108414. 0
  108415. };
  108416. static long _huff_lengthlist_line_256x4low_class0[] = {
  108417. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  108418. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  108419. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  108420. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  108421. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  108422. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  108423. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  108424. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  108425. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  108426. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  108427. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  108428. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  108429. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  108430. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  108431. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  108432. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  108433. };
  108434. static static_codebook _huff_book_line_256x4low_class0 = {
  108435. 1, 256,
  108436. _huff_lengthlist_line_256x4low_class0,
  108437. 0, 0, 0, 0, 0,
  108438. NULL,
  108439. NULL,
  108440. NULL,
  108441. NULL,
  108442. 0
  108443. };
  108444. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  108445. 1, 3, 2, 3,
  108446. };
  108447. static static_codebook _huff_book_line_256x4low_0sub0 = {
  108448. 1, 4,
  108449. _huff_lengthlist_line_256x4low_0sub0,
  108450. 0, 0, 0, 0, 0,
  108451. NULL,
  108452. NULL,
  108453. NULL,
  108454. NULL,
  108455. 0
  108456. };
  108457. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  108458. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  108459. };
  108460. static static_codebook _huff_book_line_256x4low_0sub1 = {
  108461. 1, 10,
  108462. _huff_lengthlist_line_256x4low_0sub1,
  108463. 0, 0, 0, 0, 0,
  108464. NULL,
  108465. NULL,
  108466. NULL,
  108467. NULL,
  108468. 0
  108469. };
  108470. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  108471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  108472. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  108473. };
  108474. static static_codebook _huff_book_line_256x4low_0sub2 = {
  108475. 1, 25,
  108476. _huff_lengthlist_line_256x4low_0sub2,
  108477. 0, 0, 0, 0, 0,
  108478. NULL,
  108479. NULL,
  108480. NULL,
  108481. NULL,
  108482. 0
  108483. };
  108484. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  108485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  108487. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  108488. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  108489. };
  108490. static static_codebook _huff_book_line_256x4low_0sub3 = {
  108491. 1, 64,
  108492. _huff_lengthlist_line_256x4low_0sub3,
  108493. 0, 0, 0, 0, 0,
  108494. NULL,
  108495. NULL,
  108496. NULL,
  108497. NULL,
  108498. 0
  108499. };
  108500. /*** End of inlined file: floor_books.h ***/
  108501. static static_codebook *_floor_128x4_books[]={
  108502. &_huff_book_line_128x4_class0,
  108503. &_huff_book_line_128x4_0sub0,
  108504. &_huff_book_line_128x4_0sub1,
  108505. &_huff_book_line_128x4_0sub2,
  108506. &_huff_book_line_128x4_0sub3,
  108507. };
  108508. static static_codebook *_floor_256x4_books[]={
  108509. &_huff_book_line_256x4_class0,
  108510. &_huff_book_line_256x4_0sub0,
  108511. &_huff_book_line_256x4_0sub1,
  108512. &_huff_book_line_256x4_0sub2,
  108513. &_huff_book_line_256x4_0sub3,
  108514. };
  108515. static static_codebook *_floor_128x7_books[]={
  108516. &_huff_book_line_128x7_class0,
  108517. &_huff_book_line_128x7_class1,
  108518. &_huff_book_line_128x7_0sub1,
  108519. &_huff_book_line_128x7_0sub2,
  108520. &_huff_book_line_128x7_0sub3,
  108521. &_huff_book_line_128x7_1sub1,
  108522. &_huff_book_line_128x7_1sub2,
  108523. &_huff_book_line_128x7_1sub3,
  108524. };
  108525. static static_codebook *_floor_256x7_books[]={
  108526. &_huff_book_line_256x7_class0,
  108527. &_huff_book_line_256x7_class1,
  108528. &_huff_book_line_256x7_0sub1,
  108529. &_huff_book_line_256x7_0sub2,
  108530. &_huff_book_line_256x7_0sub3,
  108531. &_huff_book_line_256x7_1sub1,
  108532. &_huff_book_line_256x7_1sub2,
  108533. &_huff_book_line_256x7_1sub3,
  108534. };
  108535. static static_codebook *_floor_128x11_books[]={
  108536. &_huff_book_line_128x11_class1,
  108537. &_huff_book_line_128x11_class2,
  108538. &_huff_book_line_128x11_class3,
  108539. &_huff_book_line_128x11_0sub0,
  108540. &_huff_book_line_128x11_1sub0,
  108541. &_huff_book_line_128x11_1sub1,
  108542. &_huff_book_line_128x11_2sub1,
  108543. &_huff_book_line_128x11_2sub2,
  108544. &_huff_book_line_128x11_2sub3,
  108545. &_huff_book_line_128x11_3sub1,
  108546. &_huff_book_line_128x11_3sub2,
  108547. &_huff_book_line_128x11_3sub3,
  108548. };
  108549. static static_codebook *_floor_128x17_books[]={
  108550. &_huff_book_line_128x17_class1,
  108551. &_huff_book_line_128x17_class2,
  108552. &_huff_book_line_128x17_class3,
  108553. &_huff_book_line_128x17_0sub0,
  108554. &_huff_book_line_128x17_1sub0,
  108555. &_huff_book_line_128x17_1sub1,
  108556. &_huff_book_line_128x17_2sub1,
  108557. &_huff_book_line_128x17_2sub2,
  108558. &_huff_book_line_128x17_2sub3,
  108559. &_huff_book_line_128x17_3sub1,
  108560. &_huff_book_line_128x17_3sub2,
  108561. &_huff_book_line_128x17_3sub3,
  108562. };
  108563. static static_codebook *_floor_256x4low_books[]={
  108564. &_huff_book_line_256x4low_class0,
  108565. &_huff_book_line_256x4low_0sub0,
  108566. &_huff_book_line_256x4low_0sub1,
  108567. &_huff_book_line_256x4low_0sub2,
  108568. &_huff_book_line_256x4low_0sub3,
  108569. };
  108570. static static_codebook *_floor_1024x27_books[]={
  108571. &_huff_book_line_1024x27_class1,
  108572. &_huff_book_line_1024x27_class2,
  108573. &_huff_book_line_1024x27_class3,
  108574. &_huff_book_line_1024x27_class4,
  108575. &_huff_book_line_1024x27_0sub0,
  108576. &_huff_book_line_1024x27_1sub0,
  108577. &_huff_book_line_1024x27_1sub1,
  108578. &_huff_book_line_1024x27_2sub0,
  108579. &_huff_book_line_1024x27_2sub1,
  108580. &_huff_book_line_1024x27_3sub1,
  108581. &_huff_book_line_1024x27_3sub2,
  108582. &_huff_book_line_1024x27_3sub3,
  108583. &_huff_book_line_1024x27_4sub1,
  108584. &_huff_book_line_1024x27_4sub2,
  108585. &_huff_book_line_1024x27_4sub3,
  108586. };
  108587. static static_codebook *_floor_2048x27_books[]={
  108588. &_huff_book_line_2048x27_class1,
  108589. &_huff_book_line_2048x27_class2,
  108590. &_huff_book_line_2048x27_class3,
  108591. &_huff_book_line_2048x27_class4,
  108592. &_huff_book_line_2048x27_0sub0,
  108593. &_huff_book_line_2048x27_1sub0,
  108594. &_huff_book_line_2048x27_1sub1,
  108595. &_huff_book_line_2048x27_2sub0,
  108596. &_huff_book_line_2048x27_2sub1,
  108597. &_huff_book_line_2048x27_3sub1,
  108598. &_huff_book_line_2048x27_3sub2,
  108599. &_huff_book_line_2048x27_3sub3,
  108600. &_huff_book_line_2048x27_4sub1,
  108601. &_huff_book_line_2048x27_4sub2,
  108602. &_huff_book_line_2048x27_4sub3,
  108603. };
  108604. static static_codebook *_floor_512x17_books[]={
  108605. &_huff_book_line_512x17_class1,
  108606. &_huff_book_line_512x17_class2,
  108607. &_huff_book_line_512x17_class3,
  108608. &_huff_book_line_512x17_0sub0,
  108609. &_huff_book_line_512x17_1sub0,
  108610. &_huff_book_line_512x17_1sub1,
  108611. &_huff_book_line_512x17_2sub1,
  108612. &_huff_book_line_512x17_2sub2,
  108613. &_huff_book_line_512x17_2sub3,
  108614. &_huff_book_line_512x17_3sub1,
  108615. &_huff_book_line_512x17_3sub2,
  108616. &_huff_book_line_512x17_3sub3,
  108617. };
  108618. static static_codebook **_floor_books[10]={
  108619. _floor_128x4_books,
  108620. _floor_256x4_books,
  108621. _floor_128x7_books,
  108622. _floor_256x7_books,
  108623. _floor_128x11_books,
  108624. _floor_128x17_books,
  108625. _floor_256x4low_books,
  108626. _floor_1024x27_books,
  108627. _floor_2048x27_books,
  108628. _floor_512x17_books,
  108629. };
  108630. static vorbis_info_floor1 _floor[10]={
  108631. {
  108632. 1,{0},{4},{2},{0},
  108633. {{1,2,3,4}},
  108634. 4,{0,128, 33,8,16,70},
  108635. 60,30,500, 1.,18., -1
  108636. },
  108637. {
  108638. 1,{0},{4},{2},{0},
  108639. {{1,2,3,4}},
  108640. 4,{0,256, 66,16,32,140},
  108641. 60,30,500, 1.,18., -1
  108642. },
  108643. {
  108644. 2,{0,1},{3,4},{2,2},{0,1},
  108645. {{-1,2,3,4},{-1,5,6,7}},
  108646. 4,{0,128, 14,4,58, 2,8,28,90},
  108647. 60,30,500, 1.,18., -1
  108648. },
  108649. {
  108650. 2,{0,1},{3,4},{2,2},{0,1},
  108651. {{-1,2,3,4},{-1,5,6,7}},
  108652. 4,{0,256, 28,8,116, 4,16,56,180},
  108653. 60,30,500, 1.,18., -1
  108654. },
  108655. {
  108656. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108657. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108658. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108659. 60,30,500, 1,18., -1
  108660. },
  108661. {
  108662. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108663. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108664. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108665. 60,30,500, 1,18., -1
  108666. },
  108667. {
  108668. 1,{0},{4},{2},{0},
  108669. {{1,2,3,4}},
  108670. 4,{0,256, 66,16,32,140},
  108671. 60,30,500, 1.,18., -1
  108672. },
  108673. {
  108674. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108675. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108676. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108677. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108678. 60,30,500, 3,18., -1 /* lowpass */
  108679. },
  108680. {
  108681. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108682. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108683. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108684. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108685. 60,30,500, 3,18., -1 /* lowpass */
  108686. },
  108687. {
  108688. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108689. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108690. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108691. 7,23,39, 55,79,110, 156,232,360},
  108692. 60,30,500, 1,18., -1 /* lowpass! */
  108693. },
  108694. };
  108695. /*** End of inlined file: floor_all.h ***/
  108696. /*** Start of inlined file: residue_44.h ***/
  108697. /*** Start of inlined file: res_books_stereo.h ***/
  108698. static long _vq_quantlist__16c0_s_p1_0[] = {
  108699. 1,
  108700. 0,
  108701. 2,
  108702. };
  108703. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108704. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108705. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108710. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108714. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108715. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0,
  108750. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0,
  108755. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 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, 7,10,10, 0, 0,
  108760. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108796. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108801. 0, 0, 0, 0, 0, 9,10,12, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108806. 0, 0, 0, 0, 0, 0, 9,12, 9, 0, 0, 0, 0, 0, 0, 0,
  108807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109114. 0,
  109115. };
  109116. static float _vq_quantthresh__16c0_s_p1_0[] = {
  109117. -0.5, 0.5,
  109118. };
  109119. static long _vq_quantmap__16c0_s_p1_0[] = {
  109120. 1, 0, 2,
  109121. };
  109122. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  109123. _vq_quantthresh__16c0_s_p1_0,
  109124. _vq_quantmap__16c0_s_p1_0,
  109125. 3,
  109126. 3
  109127. };
  109128. static static_codebook _16c0_s_p1_0 = {
  109129. 8, 6561,
  109130. _vq_lengthlist__16c0_s_p1_0,
  109131. 1, -535822336, 1611661312, 2, 0,
  109132. _vq_quantlist__16c0_s_p1_0,
  109133. NULL,
  109134. &_vq_auxt__16c0_s_p1_0,
  109135. NULL,
  109136. 0
  109137. };
  109138. static long _vq_quantlist__16c0_s_p2_0[] = {
  109139. 2,
  109140. 1,
  109141. 3,
  109142. 0,
  109143. 4,
  109144. };
  109145. static long _vq_lengthlist__16c0_s_p2_0[] = {
  109146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109185. 0,
  109186. };
  109187. static float _vq_quantthresh__16c0_s_p2_0[] = {
  109188. -1.5, -0.5, 0.5, 1.5,
  109189. };
  109190. static long _vq_quantmap__16c0_s_p2_0[] = {
  109191. 3, 1, 0, 2, 4,
  109192. };
  109193. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  109194. _vq_quantthresh__16c0_s_p2_0,
  109195. _vq_quantmap__16c0_s_p2_0,
  109196. 5,
  109197. 5
  109198. };
  109199. static static_codebook _16c0_s_p2_0 = {
  109200. 4, 625,
  109201. _vq_lengthlist__16c0_s_p2_0,
  109202. 1, -533725184, 1611661312, 3, 0,
  109203. _vq_quantlist__16c0_s_p2_0,
  109204. NULL,
  109205. &_vq_auxt__16c0_s_p2_0,
  109206. NULL,
  109207. 0
  109208. };
  109209. static long _vq_quantlist__16c0_s_p3_0[] = {
  109210. 2,
  109211. 1,
  109212. 3,
  109213. 0,
  109214. 4,
  109215. };
  109216. static long _vq_lengthlist__16c0_s_p3_0[] = {
  109217. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  109219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109220. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  109222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109223. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  109224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109256. 0,
  109257. };
  109258. static float _vq_quantthresh__16c0_s_p3_0[] = {
  109259. -1.5, -0.5, 0.5, 1.5,
  109260. };
  109261. static long _vq_quantmap__16c0_s_p3_0[] = {
  109262. 3, 1, 0, 2, 4,
  109263. };
  109264. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  109265. _vq_quantthresh__16c0_s_p3_0,
  109266. _vq_quantmap__16c0_s_p3_0,
  109267. 5,
  109268. 5
  109269. };
  109270. static static_codebook _16c0_s_p3_0 = {
  109271. 4, 625,
  109272. _vq_lengthlist__16c0_s_p3_0,
  109273. 1, -533725184, 1611661312, 3, 0,
  109274. _vq_quantlist__16c0_s_p3_0,
  109275. NULL,
  109276. &_vq_auxt__16c0_s_p3_0,
  109277. NULL,
  109278. 0
  109279. };
  109280. static long _vq_quantlist__16c0_s_p4_0[] = {
  109281. 4,
  109282. 3,
  109283. 5,
  109284. 2,
  109285. 6,
  109286. 1,
  109287. 7,
  109288. 0,
  109289. 8,
  109290. };
  109291. static long _vq_lengthlist__16c0_s_p4_0[] = {
  109292. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109293. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109294. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109295. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  109296. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109297. 0,
  109298. };
  109299. static float _vq_quantthresh__16c0_s_p4_0[] = {
  109300. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109301. };
  109302. static long _vq_quantmap__16c0_s_p4_0[] = {
  109303. 7, 5, 3, 1, 0, 2, 4, 6,
  109304. 8,
  109305. };
  109306. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  109307. _vq_quantthresh__16c0_s_p4_0,
  109308. _vq_quantmap__16c0_s_p4_0,
  109309. 9,
  109310. 9
  109311. };
  109312. static static_codebook _16c0_s_p4_0 = {
  109313. 2, 81,
  109314. _vq_lengthlist__16c0_s_p4_0,
  109315. 1, -531628032, 1611661312, 4, 0,
  109316. _vq_quantlist__16c0_s_p4_0,
  109317. NULL,
  109318. &_vq_auxt__16c0_s_p4_0,
  109319. NULL,
  109320. 0
  109321. };
  109322. static long _vq_quantlist__16c0_s_p5_0[] = {
  109323. 4,
  109324. 3,
  109325. 5,
  109326. 2,
  109327. 6,
  109328. 1,
  109329. 7,
  109330. 0,
  109331. 8,
  109332. };
  109333. static long _vq_lengthlist__16c0_s_p5_0[] = {
  109334. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109335. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  109336. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  109337. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  109338. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109339. 10,
  109340. };
  109341. static float _vq_quantthresh__16c0_s_p5_0[] = {
  109342. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109343. };
  109344. static long _vq_quantmap__16c0_s_p5_0[] = {
  109345. 7, 5, 3, 1, 0, 2, 4, 6,
  109346. 8,
  109347. };
  109348. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  109349. _vq_quantthresh__16c0_s_p5_0,
  109350. _vq_quantmap__16c0_s_p5_0,
  109351. 9,
  109352. 9
  109353. };
  109354. static static_codebook _16c0_s_p5_0 = {
  109355. 2, 81,
  109356. _vq_lengthlist__16c0_s_p5_0,
  109357. 1, -531628032, 1611661312, 4, 0,
  109358. _vq_quantlist__16c0_s_p5_0,
  109359. NULL,
  109360. &_vq_auxt__16c0_s_p5_0,
  109361. NULL,
  109362. 0
  109363. };
  109364. static long _vq_quantlist__16c0_s_p6_0[] = {
  109365. 8,
  109366. 7,
  109367. 9,
  109368. 6,
  109369. 10,
  109370. 5,
  109371. 11,
  109372. 4,
  109373. 12,
  109374. 3,
  109375. 13,
  109376. 2,
  109377. 14,
  109378. 1,
  109379. 15,
  109380. 0,
  109381. 16,
  109382. };
  109383. static long _vq_lengthlist__16c0_s_p6_0[] = {
  109384. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  109385. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  109386. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  109387. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  109388. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  109389. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109390. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109391. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109392. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  109393. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109394. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  109395. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  109396. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  109397. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  109398. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  109399. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  109400. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  109401. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  109402. 14,
  109403. };
  109404. static float _vq_quantthresh__16c0_s_p6_0[] = {
  109405. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  109406. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  109407. };
  109408. static long _vq_quantmap__16c0_s_p6_0[] = {
  109409. 15, 13, 11, 9, 7, 5, 3, 1,
  109410. 0, 2, 4, 6, 8, 10, 12, 14,
  109411. 16,
  109412. };
  109413. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  109414. _vq_quantthresh__16c0_s_p6_0,
  109415. _vq_quantmap__16c0_s_p6_0,
  109416. 17,
  109417. 17
  109418. };
  109419. static static_codebook _16c0_s_p6_0 = {
  109420. 2, 289,
  109421. _vq_lengthlist__16c0_s_p6_0,
  109422. 1, -529530880, 1611661312, 5, 0,
  109423. _vq_quantlist__16c0_s_p6_0,
  109424. NULL,
  109425. &_vq_auxt__16c0_s_p6_0,
  109426. NULL,
  109427. 0
  109428. };
  109429. static long _vq_quantlist__16c0_s_p7_0[] = {
  109430. 1,
  109431. 0,
  109432. 2,
  109433. };
  109434. static long _vq_lengthlist__16c0_s_p7_0[] = {
  109435. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  109436. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  109437. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  109438. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  109439. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  109440. 13,
  109441. };
  109442. static float _vq_quantthresh__16c0_s_p7_0[] = {
  109443. -5.5, 5.5,
  109444. };
  109445. static long _vq_quantmap__16c0_s_p7_0[] = {
  109446. 1, 0, 2,
  109447. };
  109448. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  109449. _vq_quantthresh__16c0_s_p7_0,
  109450. _vq_quantmap__16c0_s_p7_0,
  109451. 3,
  109452. 3
  109453. };
  109454. static static_codebook _16c0_s_p7_0 = {
  109455. 4, 81,
  109456. _vq_lengthlist__16c0_s_p7_0,
  109457. 1, -529137664, 1618345984, 2, 0,
  109458. _vq_quantlist__16c0_s_p7_0,
  109459. NULL,
  109460. &_vq_auxt__16c0_s_p7_0,
  109461. NULL,
  109462. 0
  109463. };
  109464. static long _vq_quantlist__16c0_s_p7_1[] = {
  109465. 5,
  109466. 4,
  109467. 6,
  109468. 3,
  109469. 7,
  109470. 2,
  109471. 8,
  109472. 1,
  109473. 9,
  109474. 0,
  109475. 10,
  109476. };
  109477. static long _vq_lengthlist__16c0_s_p7_1[] = {
  109478. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  109479. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  109480. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  109481. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  109482. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  109483. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  109484. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  109485. 11,11,11, 9, 9, 9, 9,10,10,
  109486. };
  109487. static float _vq_quantthresh__16c0_s_p7_1[] = {
  109488. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  109489. 3.5, 4.5,
  109490. };
  109491. static long _vq_quantmap__16c0_s_p7_1[] = {
  109492. 9, 7, 5, 3, 1, 0, 2, 4,
  109493. 6, 8, 10,
  109494. };
  109495. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  109496. _vq_quantthresh__16c0_s_p7_1,
  109497. _vq_quantmap__16c0_s_p7_1,
  109498. 11,
  109499. 11
  109500. };
  109501. static static_codebook _16c0_s_p7_1 = {
  109502. 2, 121,
  109503. _vq_lengthlist__16c0_s_p7_1,
  109504. 1, -531365888, 1611661312, 4, 0,
  109505. _vq_quantlist__16c0_s_p7_1,
  109506. NULL,
  109507. &_vq_auxt__16c0_s_p7_1,
  109508. NULL,
  109509. 0
  109510. };
  109511. static long _vq_quantlist__16c0_s_p8_0[] = {
  109512. 6,
  109513. 5,
  109514. 7,
  109515. 4,
  109516. 8,
  109517. 3,
  109518. 9,
  109519. 2,
  109520. 10,
  109521. 1,
  109522. 11,
  109523. 0,
  109524. 12,
  109525. };
  109526. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109527. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109528. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109529. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109530. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109531. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109532. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109533. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109534. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109535. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109536. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109537. 0,12,13,13,12,13,14,14,14,
  109538. };
  109539. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109540. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109541. 12.5, 17.5, 22.5, 27.5,
  109542. };
  109543. static long _vq_quantmap__16c0_s_p8_0[] = {
  109544. 11, 9, 7, 5, 3, 1, 0, 2,
  109545. 4, 6, 8, 10, 12,
  109546. };
  109547. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109548. _vq_quantthresh__16c0_s_p8_0,
  109549. _vq_quantmap__16c0_s_p8_0,
  109550. 13,
  109551. 13
  109552. };
  109553. static static_codebook _16c0_s_p8_0 = {
  109554. 2, 169,
  109555. _vq_lengthlist__16c0_s_p8_0,
  109556. 1, -526516224, 1616117760, 4, 0,
  109557. _vq_quantlist__16c0_s_p8_0,
  109558. NULL,
  109559. &_vq_auxt__16c0_s_p8_0,
  109560. NULL,
  109561. 0
  109562. };
  109563. static long _vq_quantlist__16c0_s_p8_1[] = {
  109564. 2,
  109565. 1,
  109566. 3,
  109567. 0,
  109568. 4,
  109569. };
  109570. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109571. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109572. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109573. };
  109574. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109575. -1.5, -0.5, 0.5, 1.5,
  109576. };
  109577. static long _vq_quantmap__16c0_s_p8_1[] = {
  109578. 3, 1, 0, 2, 4,
  109579. };
  109580. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109581. _vq_quantthresh__16c0_s_p8_1,
  109582. _vq_quantmap__16c0_s_p8_1,
  109583. 5,
  109584. 5
  109585. };
  109586. static static_codebook _16c0_s_p8_1 = {
  109587. 2, 25,
  109588. _vq_lengthlist__16c0_s_p8_1,
  109589. 1, -533725184, 1611661312, 3, 0,
  109590. _vq_quantlist__16c0_s_p8_1,
  109591. NULL,
  109592. &_vq_auxt__16c0_s_p8_1,
  109593. NULL,
  109594. 0
  109595. };
  109596. static long _vq_quantlist__16c0_s_p9_0[] = {
  109597. 1,
  109598. 0,
  109599. 2,
  109600. };
  109601. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109602. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109603. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109604. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109605. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109606. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109607. 7,
  109608. };
  109609. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109610. -157.5, 157.5,
  109611. };
  109612. static long _vq_quantmap__16c0_s_p9_0[] = {
  109613. 1, 0, 2,
  109614. };
  109615. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109616. _vq_quantthresh__16c0_s_p9_0,
  109617. _vq_quantmap__16c0_s_p9_0,
  109618. 3,
  109619. 3
  109620. };
  109621. static static_codebook _16c0_s_p9_0 = {
  109622. 4, 81,
  109623. _vq_lengthlist__16c0_s_p9_0,
  109624. 1, -518803456, 1628680192, 2, 0,
  109625. _vq_quantlist__16c0_s_p9_0,
  109626. NULL,
  109627. &_vq_auxt__16c0_s_p9_0,
  109628. NULL,
  109629. 0
  109630. };
  109631. static long _vq_quantlist__16c0_s_p9_1[] = {
  109632. 7,
  109633. 6,
  109634. 8,
  109635. 5,
  109636. 9,
  109637. 4,
  109638. 10,
  109639. 3,
  109640. 11,
  109641. 2,
  109642. 12,
  109643. 1,
  109644. 13,
  109645. 0,
  109646. 14,
  109647. };
  109648. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109649. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109650. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109651. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109652. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109653. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109654. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109655. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109656. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109657. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109658. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109659. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109660. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109661. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109662. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109663. 10,
  109664. };
  109665. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109666. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109667. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109668. };
  109669. static long _vq_quantmap__16c0_s_p9_1[] = {
  109670. 13, 11, 9, 7, 5, 3, 1, 0,
  109671. 2, 4, 6, 8, 10, 12, 14,
  109672. };
  109673. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109674. _vq_quantthresh__16c0_s_p9_1,
  109675. _vq_quantmap__16c0_s_p9_1,
  109676. 15,
  109677. 15
  109678. };
  109679. static static_codebook _16c0_s_p9_1 = {
  109680. 2, 225,
  109681. _vq_lengthlist__16c0_s_p9_1,
  109682. 1, -520986624, 1620377600, 4, 0,
  109683. _vq_quantlist__16c0_s_p9_1,
  109684. NULL,
  109685. &_vq_auxt__16c0_s_p9_1,
  109686. NULL,
  109687. 0
  109688. };
  109689. static long _vq_quantlist__16c0_s_p9_2[] = {
  109690. 10,
  109691. 9,
  109692. 11,
  109693. 8,
  109694. 12,
  109695. 7,
  109696. 13,
  109697. 6,
  109698. 14,
  109699. 5,
  109700. 15,
  109701. 4,
  109702. 16,
  109703. 3,
  109704. 17,
  109705. 2,
  109706. 18,
  109707. 1,
  109708. 19,
  109709. 0,
  109710. 20,
  109711. };
  109712. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109713. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109714. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109715. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109716. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109717. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109718. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109719. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109720. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109721. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109722. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109723. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109724. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109725. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109726. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109727. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109728. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109729. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109730. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109731. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109732. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109733. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109734. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109735. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109736. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109737. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109738. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109739. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109740. 10,11,10,10,11, 9,10,10,10,
  109741. };
  109742. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109743. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109744. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109745. 6.5, 7.5, 8.5, 9.5,
  109746. };
  109747. static long _vq_quantmap__16c0_s_p9_2[] = {
  109748. 19, 17, 15, 13, 11, 9, 7, 5,
  109749. 3, 1, 0, 2, 4, 6, 8, 10,
  109750. 12, 14, 16, 18, 20,
  109751. };
  109752. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109753. _vq_quantthresh__16c0_s_p9_2,
  109754. _vq_quantmap__16c0_s_p9_2,
  109755. 21,
  109756. 21
  109757. };
  109758. static static_codebook _16c0_s_p9_2 = {
  109759. 2, 441,
  109760. _vq_lengthlist__16c0_s_p9_2,
  109761. 1, -529268736, 1611661312, 5, 0,
  109762. _vq_quantlist__16c0_s_p9_2,
  109763. NULL,
  109764. &_vq_auxt__16c0_s_p9_2,
  109765. NULL,
  109766. 0
  109767. };
  109768. static long _huff_lengthlist__16c0_s_single[] = {
  109769. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109770. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109771. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109772. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109773. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109774. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109775. 16,16,18,18,
  109776. };
  109777. static static_codebook _huff_book__16c0_s_single = {
  109778. 2, 100,
  109779. _huff_lengthlist__16c0_s_single,
  109780. 0, 0, 0, 0, 0,
  109781. NULL,
  109782. NULL,
  109783. NULL,
  109784. NULL,
  109785. 0
  109786. };
  109787. static long _huff_lengthlist__16c1_s_long[] = {
  109788. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109789. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109790. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109791. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109792. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109793. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109794. 12,11,11,13,
  109795. };
  109796. static static_codebook _huff_book__16c1_s_long = {
  109797. 2, 100,
  109798. _huff_lengthlist__16c1_s_long,
  109799. 0, 0, 0, 0, 0,
  109800. NULL,
  109801. NULL,
  109802. NULL,
  109803. NULL,
  109804. 0
  109805. };
  109806. static long _vq_quantlist__16c1_s_p1_0[] = {
  109807. 1,
  109808. 0,
  109809. 2,
  109810. };
  109811. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109812. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109813. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109818. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109822. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109823. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 7, 0, 0, 0, 0,
  109858. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  109863. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  109868. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109904. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109909. 0, 0, 0, 0, 0, 8, 9,11, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109914. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  109915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110222. 0,
  110223. };
  110224. static float _vq_quantthresh__16c1_s_p1_0[] = {
  110225. -0.5, 0.5,
  110226. };
  110227. static long _vq_quantmap__16c1_s_p1_0[] = {
  110228. 1, 0, 2,
  110229. };
  110230. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  110231. _vq_quantthresh__16c1_s_p1_0,
  110232. _vq_quantmap__16c1_s_p1_0,
  110233. 3,
  110234. 3
  110235. };
  110236. static static_codebook _16c1_s_p1_0 = {
  110237. 8, 6561,
  110238. _vq_lengthlist__16c1_s_p1_0,
  110239. 1, -535822336, 1611661312, 2, 0,
  110240. _vq_quantlist__16c1_s_p1_0,
  110241. NULL,
  110242. &_vq_auxt__16c1_s_p1_0,
  110243. NULL,
  110244. 0
  110245. };
  110246. static long _vq_quantlist__16c1_s_p2_0[] = {
  110247. 2,
  110248. 1,
  110249. 3,
  110250. 0,
  110251. 4,
  110252. };
  110253. static long _vq_lengthlist__16c1_s_p2_0[] = {
  110254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110293. 0,
  110294. };
  110295. static float _vq_quantthresh__16c1_s_p2_0[] = {
  110296. -1.5, -0.5, 0.5, 1.5,
  110297. };
  110298. static long _vq_quantmap__16c1_s_p2_0[] = {
  110299. 3, 1, 0, 2, 4,
  110300. };
  110301. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  110302. _vq_quantthresh__16c1_s_p2_0,
  110303. _vq_quantmap__16c1_s_p2_0,
  110304. 5,
  110305. 5
  110306. };
  110307. static static_codebook _16c1_s_p2_0 = {
  110308. 4, 625,
  110309. _vq_lengthlist__16c1_s_p2_0,
  110310. 1, -533725184, 1611661312, 3, 0,
  110311. _vq_quantlist__16c1_s_p2_0,
  110312. NULL,
  110313. &_vq_auxt__16c1_s_p2_0,
  110314. NULL,
  110315. 0
  110316. };
  110317. static long _vq_quantlist__16c1_s_p3_0[] = {
  110318. 2,
  110319. 1,
  110320. 3,
  110321. 0,
  110322. 4,
  110323. };
  110324. static long _vq_lengthlist__16c1_s_p3_0[] = {
  110325. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  110327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110328. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  110330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110331. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  110332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110364. 0,
  110365. };
  110366. static float _vq_quantthresh__16c1_s_p3_0[] = {
  110367. -1.5, -0.5, 0.5, 1.5,
  110368. };
  110369. static long _vq_quantmap__16c1_s_p3_0[] = {
  110370. 3, 1, 0, 2, 4,
  110371. };
  110372. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  110373. _vq_quantthresh__16c1_s_p3_0,
  110374. _vq_quantmap__16c1_s_p3_0,
  110375. 5,
  110376. 5
  110377. };
  110378. static static_codebook _16c1_s_p3_0 = {
  110379. 4, 625,
  110380. _vq_lengthlist__16c1_s_p3_0,
  110381. 1, -533725184, 1611661312, 3, 0,
  110382. _vq_quantlist__16c1_s_p3_0,
  110383. NULL,
  110384. &_vq_auxt__16c1_s_p3_0,
  110385. NULL,
  110386. 0
  110387. };
  110388. static long _vq_quantlist__16c1_s_p4_0[] = {
  110389. 4,
  110390. 3,
  110391. 5,
  110392. 2,
  110393. 6,
  110394. 1,
  110395. 7,
  110396. 0,
  110397. 8,
  110398. };
  110399. static long _vq_lengthlist__16c1_s_p4_0[] = {
  110400. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  110401. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  110402. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  110403. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  110404. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110405. 0,
  110406. };
  110407. static float _vq_quantthresh__16c1_s_p4_0[] = {
  110408. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110409. };
  110410. static long _vq_quantmap__16c1_s_p4_0[] = {
  110411. 7, 5, 3, 1, 0, 2, 4, 6,
  110412. 8,
  110413. };
  110414. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  110415. _vq_quantthresh__16c1_s_p4_0,
  110416. _vq_quantmap__16c1_s_p4_0,
  110417. 9,
  110418. 9
  110419. };
  110420. static static_codebook _16c1_s_p4_0 = {
  110421. 2, 81,
  110422. _vq_lengthlist__16c1_s_p4_0,
  110423. 1, -531628032, 1611661312, 4, 0,
  110424. _vq_quantlist__16c1_s_p4_0,
  110425. NULL,
  110426. &_vq_auxt__16c1_s_p4_0,
  110427. NULL,
  110428. 0
  110429. };
  110430. static long _vq_quantlist__16c1_s_p5_0[] = {
  110431. 4,
  110432. 3,
  110433. 5,
  110434. 2,
  110435. 6,
  110436. 1,
  110437. 7,
  110438. 0,
  110439. 8,
  110440. };
  110441. static long _vq_lengthlist__16c1_s_p5_0[] = {
  110442. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  110443. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  110444. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  110445. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  110446. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  110447. 10,
  110448. };
  110449. static float _vq_quantthresh__16c1_s_p5_0[] = {
  110450. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110451. };
  110452. static long _vq_quantmap__16c1_s_p5_0[] = {
  110453. 7, 5, 3, 1, 0, 2, 4, 6,
  110454. 8,
  110455. };
  110456. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  110457. _vq_quantthresh__16c1_s_p5_0,
  110458. _vq_quantmap__16c1_s_p5_0,
  110459. 9,
  110460. 9
  110461. };
  110462. static static_codebook _16c1_s_p5_0 = {
  110463. 2, 81,
  110464. _vq_lengthlist__16c1_s_p5_0,
  110465. 1, -531628032, 1611661312, 4, 0,
  110466. _vq_quantlist__16c1_s_p5_0,
  110467. NULL,
  110468. &_vq_auxt__16c1_s_p5_0,
  110469. NULL,
  110470. 0
  110471. };
  110472. static long _vq_quantlist__16c1_s_p6_0[] = {
  110473. 8,
  110474. 7,
  110475. 9,
  110476. 6,
  110477. 10,
  110478. 5,
  110479. 11,
  110480. 4,
  110481. 12,
  110482. 3,
  110483. 13,
  110484. 2,
  110485. 14,
  110486. 1,
  110487. 15,
  110488. 0,
  110489. 16,
  110490. };
  110491. static long _vq_lengthlist__16c1_s_p6_0[] = {
  110492. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  110493. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  110494. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  110495. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  110496. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  110497. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  110498. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  110499. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  110500. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  110501. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  110502. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  110503. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  110504. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  110505. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  110506. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  110507. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  110508. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  110509. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  110510. 14,
  110511. };
  110512. static float _vq_quantthresh__16c1_s_p6_0[] = {
  110513. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110514. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110515. };
  110516. static long _vq_quantmap__16c1_s_p6_0[] = {
  110517. 15, 13, 11, 9, 7, 5, 3, 1,
  110518. 0, 2, 4, 6, 8, 10, 12, 14,
  110519. 16,
  110520. };
  110521. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  110522. _vq_quantthresh__16c1_s_p6_0,
  110523. _vq_quantmap__16c1_s_p6_0,
  110524. 17,
  110525. 17
  110526. };
  110527. static static_codebook _16c1_s_p6_0 = {
  110528. 2, 289,
  110529. _vq_lengthlist__16c1_s_p6_0,
  110530. 1, -529530880, 1611661312, 5, 0,
  110531. _vq_quantlist__16c1_s_p6_0,
  110532. NULL,
  110533. &_vq_auxt__16c1_s_p6_0,
  110534. NULL,
  110535. 0
  110536. };
  110537. static long _vq_quantlist__16c1_s_p7_0[] = {
  110538. 1,
  110539. 0,
  110540. 2,
  110541. };
  110542. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110543. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110544. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110545. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110546. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110547. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110548. 11,
  110549. };
  110550. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110551. -5.5, 5.5,
  110552. };
  110553. static long _vq_quantmap__16c1_s_p7_0[] = {
  110554. 1, 0, 2,
  110555. };
  110556. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110557. _vq_quantthresh__16c1_s_p7_0,
  110558. _vq_quantmap__16c1_s_p7_0,
  110559. 3,
  110560. 3
  110561. };
  110562. static static_codebook _16c1_s_p7_0 = {
  110563. 4, 81,
  110564. _vq_lengthlist__16c1_s_p7_0,
  110565. 1, -529137664, 1618345984, 2, 0,
  110566. _vq_quantlist__16c1_s_p7_0,
  110567. NULL,
  110568. &_vq_auxt__16c1_s_p7_0,
  110569. NULL,
  110570. 0
  110571. };
  110572. static long _vq_quantlist__16c1_s_p7_1[] = {
  110573. 5,
  110574. 4,
  110575. 6,
  110576. 3,
  110577. 7,
  110578. 2,
  110579. 8,
  110580. 1,
  110581. 9,
  110582. 0,
  110583. 10,
  110584. };
  110585. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110586. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110587. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110588. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110589. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110590. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110591. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110592. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110593. 10,10,10, 8, 8, 8, 8, 9, 9,
  110594. };
  110595. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110596. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110597. 3.5, 4.5,
  110598. };
  110599. static long _vq_quantmap__16c1_s_p7_1[] = {
  110600. 9, 7, 5, 3, 1, 0, 2, 4,
  110601. 6, 8, 10,
  110602. };
  110603. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110604. _vq_quantthresh__16c1_s_p7_1,
  110605. _vq_quantmap__16c1_s_p7_1,
  110606. 11,
  110607. 11
  110608. };
  110609. static static_codebook _16c1_s_p7_1 = {
  110610. 2, 121,
  110611. _vq_lengthlist__16c1_s_p7_1,
  110612. 1, -531365888, 1611661312, 4, 0,
  110613. _vq_quantlist__16c1_s_p7_1,
  110614. NULL,
  110615. &_vq_auxt__16c1_s_p7_1,
  110616. NULL,
  110617. 0
  110618. };
  110619. static long _vq_quantlist__16c1_s_p8_0[] = {
  110620. 6,
  110621. 5,
  110622. 7,
  110623. 4,
  110624. 8,
  110625. 3,
  110626. 9,
  110627. 2,
  110628. 10,
  110629. 1,
  110630. 11,
  110631. 0,
  110632. 12,
  110633. };
  110634. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110635. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110636. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110637. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110638. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110639. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110640. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110641. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110642. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110643. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110644. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110645. 0,12,12,12,12,13,13,14,15,
  110646. };
  110647. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110648. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110649. 12.5, 17.5, 22.5, 27.5,
  110650. };
  110651. static long _vq_quantmap__16c1_s_p8_0[] = {
  110652. 11, 9, 7, 5, 3, 1, 0, 2,
  110653. 4, 6, 8, 10, 12,
  110654. };
  110655. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110656. _vq_quantthresh__16c1_s_p8_0,
  110657. _vq_quantmap__16c1_s_p8_0,
  110658. 13,
  110659. 13
  110660. };
  110661. static static_codebook _16c1_s_p8_0 = {
  110662. 2, 169,
  110663. _vq_lengthlist__16c1_s_p8_0,
  110664. 1, -526516224, 1616117760, 4, 0,
  110665. _vq_quantlist__16c1_s_p8_0,
  110666. NULL,
  110667. &_vq_auxt__16c1_s_p8_0,
  110668. NULL,
  110669. 0
  110670. };
  110671. static long _vq_quantlist__16c1_s_p8_1[] = {
  110672. 2,
  110673. 1,
  110674. 3,
  110675. 0,
  110676. 4,
  110677. };
  110678. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110679. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110680. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110681. };
  110682. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110683. -1.5, -0.5, 0.5, 1.5,
  110684. };
  110685. static long _vq_quantmap__16c1_s_p8_1[] = {
  110686. 3, 1, 0, 2, 4,
  110687. };
  110688. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110689. _vq_quantthresh__16c1_s_p8_1,
  110690. _vq_quantmap__16c1_s_p8_1,
  110691. 5,
  110692. 5
  110693. };
  110694. static static_codebook _16c1_s_p8_1 = {
  110695. 2, 25,
  110696. _vq_lengthlist__16c1_s_p8_1,
  110697. 1, -533725184, 1611661312, 3, 0,
  110698. _vq_quantlist__16c1_s_p8_1,
  110699. NULL,
  110700. &_vq_auxt__16c1_s_p8_1,
  110701. NULL,
  110702. 0
  110703. };
  110704. static long _vq_quantlist__16c1_s_p9_0[] = {
  110705. 6,
  110706. 5,
  110707. 7,
  110708. 4,
  110709. 8,
  110710. 3,
  110711. 9,
  110712. 2,
  110713. 10,
  110714. 1,
  110715. 11,
  110716. 0,
  110717. 12,
  110718. };
  110719. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110720. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110721. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110722. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110723. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110724. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110725. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110726. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110727. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110728. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110729. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110730. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110731. };
  110732. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110733. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110734. 787.5, 1102.5, 1417.5, 1732.5,
  110735. };
  110736. static long _vq_quantmap__16c1_s_p9_0[] = {
  110737. 11, 9, 7, 5, 3, 1, 0, 2,
  110738. 4, 6, 8, 10, 12,
  110739. };
  110740. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110741. _vq_quantthresh__16c1_s_p9_0,
  110742. _vq_quantmap__16c1_s_p9_0,
  110743. 13,
  110744. 13
  110745. };
  110746. static static_codebook _16c1_s_p9_0 = {
  110747. 2, 169,
  110748. _vq_lengthlist__16c1_s_p9_0,
  110749. 1, -513964032, 1628680192, 4, 0,
  110750. _vq_quantlist__16c1_s_p9_0,
  110751. NULL,
  110752. &_vq_auxt__16c1_s_p9_0,
  110753. NULL,
  110754. 0
  110755. };
  110756. static long _vq_quantlist__16c1_s_p9_1[] = {
  110757. 7,
  110758. 6,
  110759. 8,
  110760. 5,
  110761. 9,
  110762. 4,
  110763. 10,
  110764. 3,
  110765. 11,
  110766. 2,
  110767. 12,
  110768. 1,
  110769. 13,
  110770. 0,
  110771. 14,
  110772. };
  110773. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110774. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110775. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110776. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110777. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110778. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110779. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110780. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110781. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110782. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110783. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110784. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110785. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110786. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110787. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110788. 13,
  110789. };
  110790. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110791. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110792. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110793. };
  110794. static long _vq_quantmap__16c1_s_p9_1[] = {
  110795. 13, 11, 9, 7, 5, 3, 1, 0,
  110796. 2, 4, 6, 8, 10, 12, 14,
  110797. };
  110798. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110799. _vq_quantthresh__16c1_s_p9_1,
  110800. _vq_quantmap__16c1_s_p9_1,
  110801. 15,
  110802. 15
  110803. };
  110804. static static_codebook _16c1_s_p9_1 = {
  110805. 2, 225,
  110806. _vq_lengthlist__16c1_s_p9_1,
  110807. 1, -520986624, 1620377600, 4, 0,
  110808. _vq_quantlist__16c1_s_p9_1,
  110809. NULL,
  110810. &_vq_auxt__16c1_s_p9_1,
  110811. NULL,
  110812. 0
  110813. };
  110814. static long _vq_quantlist__16c1_s_p9_2[] = {
  110815. 10,
  110816. 9,
  110817. 11,
  110818. 8,
  110819. 12,
  110820. 7,
  110821. 13,
  110822. 6,
  110823. 14,
  110824. 5,
  110825. 15,
  110826. 4,
  110827. 16,
  110828. 3,
  110829. 17,
  110830. 2,
  110831. 18,
  110832. 1,
  110833. 19,
  110834. 0,
  110835. 20,
  110836. };
  110837. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110838. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110839. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110840. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110841. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110842. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110843. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110844. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110845. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110846. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110847. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110848. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110849. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110850. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110851. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110852. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110853. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110854. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110855. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110856. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110857. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110858. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110859. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110860. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110861. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110862. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110863. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110864. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110865. 11,11,11,11,12,11,11,12,11,
  110866. };
  110867. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110868. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110869. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110870. 6.5, 7.5, 8.5, 9.5,
  110871. };
  110872. static long _vq_quantmap__16c1_s_p9_2[] = {
  110873. 19, 17, 15, 13, 11, 9, 7, 5,
  110874. 3, 1, 0, 2, 4, 6, 8, 10,
  110875. 12, 14, 16, 18, 20,
  110876. };
  110877. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110878. _vq_quantthresh__16c1_s_p9_2,
  110879. _vq_quantmap__16c1_s_p9_2,
  110880. 21,
  110881. 21
  110882. };
  110883. static static_codebook _16c1_s_p9_2 = {
  110884. 2, 441,
  110885. _vq_lengthlist__16c1_s_p9_2,
  110886. 1, -529268736, 1611661312, 5, 0,
  110887. _vq_quantlist__16c1_s_p9_2,
  110888. NULL,
  110889. &_vq_auxt__16c1_s_p9_2,
  110890. NULL,
  110891. 0
  110892. };
  110893. static long _huff_lengthlist__16c1_s_short[] = {
  110894. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110895. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110896. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110897. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110898. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110899. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110900. 9, 9,10,13,
  110901. };
  110902. static static_codebook _huff_book__16c1_s_short = {
  110903. 2, 100,
  110904. _huff_lengthlist__16c1_s_short,
  110905. 0, 0, 0, 0, 0,
  110906. NULL,
  110907. NULL,
  110908. NULL,
  110909. NULL,
  110910. 0
  110911. };
  110912. static long _huff_lengthlist__16c2_s_long[] = {
  110913. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110914. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110915. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110916. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110917. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110918. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110919. 14,14,16,18,
  110920. };
  110921. static static_codebook _huff_book__16c2_s_long = {
  110922. 2, 100,
  110923. _huff_lengthlist__16c2_s_long,
  110924. 0, 0, 0, 0, 0,
  110925. NULL,
  110926. NULL,
  110927. NULL,
  110928. NULL,
  110929. 0
  110930. };
  110931. static long _vq_quantlist__16c2_s_p1_0[] = {
  110932. 1,
  110933. 0,
  110934. 2,
  110935. };
  110936. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110937. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110938. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110942. 0,
  110943. };
  110944. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110945. -0.5, 0.5,
  110946. };
  110947. static long _vq_quantmap__16c2_s_p1_0[] = {
  110948. 1, 0, 2,
  110949. };
  110950. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110951. _vq_quantthresh__16c2_s_p1_0,
  110952. _vq_quantmap__16c2_s_p1_0,
  110953. 3,
  110954. 3
  110955. };
  110956. static static_codebook _16c2_s_p1_0 = {
  110957. 4, 81,
  110958. _vq_lengthlist__16c2_s_p1_0,
  110959. 1, -535822336, 1611661312, 2, 0,
  110960. _vq_quantlist__16c2_s_p1_0,
  110961. NULL,
  110962. &_vq_auxt__16c2_s_p1_0,
  110963. NULL,
  110964. 0
  110965. };
  110966. static long _vq_quantlist__16c2_s_p2_0[] = {
  110967. 2,
  110968. 1,
  110969. 3,
  110970. 0,
  110971. 4,
  110972. };
  110973. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110974. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110975. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110976. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110977. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110978. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110979. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110980. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110981. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110986. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110987. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110988. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110989. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110994. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110995. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110996. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110997. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111002. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  111003. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  111004. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  111005. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  111010. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  111011. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  111012. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  111013. 13,
  111014. };
  111015. static float _vq_quantthresh__16c2_s_p2_0[] = {
  111016. -1.5, -0.5, 0.5, 1.5,
  111017. };
  111018. static long _vq_quantmap__16c2_s_p2_0[] = {
  111019. 3, 1, 0, 2, 4,
  111020. };
  111021. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  111022. _vq_quantthresh__16c2_s_p2_0,
  111023. _vq_quantmap__16c2_s_p2_0,
  111024. 5,
  111025. 5
  111026. };
  111027. static static_codebook _16c2_s_p2_0 = {
  111028. 4, 625,
  111029. _vq_lengthlist__16c2_s_p2_0,
  111030. 1, -533725184, 1611661312, 3, 0,
  111031. _vq_quantlist__16c2_s_p2_0,
  111032. NULL,
  111033. &_vq_auxt__16c2_s_p2_0,
  111034. NULL,
  111035. 0
  111036. };
  111037. static long _vq_quantlist__16c2_s_p3_0[] = {
  111038. 4,
  111039. 3,
  111040. 5,
  111041. 2,
  111042. 6,
  111043. 1,
  111044. 7,
  111045. 0,
  111046. 8,
  111047. };
  111048. static long _vq_lengthlist__16c2_s_p3_0[] = {
  111049. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  111050. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  111051. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  111052. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  111053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111054. 0,
  111055. };
  111056. static float _vq_quantthresh__16c2_s_p3_0[] = {
  111057. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111058. };
  111059. static long _vq_quantmap__16c2_s_p3_0[] = {
  111060. 7, 5, 3, 1, 0, 2, 4, 6,
  111061. 8,
  111062. };
  111063. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  111064. _vq_quantthresh__16c2_s_p3_0,
  111065. _vq_quantmap__16c2_s_p3_0,
  111066. 9,
  111067. 9
  111068. };
  111069. static static_codebook _16c2_s_p3_0 = {
  111070. 2, 81,
  111071. _vq_lengthlist__16c2_s_p3_0,
  111072. 1, -531628032, 1611661312, 4, 0,
  111073. _vq_quantlist__16c2_s_p3_0,
  111074. NULL,
  111075. &_vq_auxt__16c2_s_p3_0,
  111076. NULL,
  111077. 0
  111078. };
  111079. static long _vq_quantlist__16c2_s_p4_0[] = {
  111080. 8,
  111081. 7,
  111082. 9,
  111083. 6,
  111084. 10,
  111085. 5,
  111086. 11,
  111087. 4,
  111088. 12,
  111089. 3,
  111090. 13,
  111091. 2,
  111092. 14,
  111093. 1,
  111094. 15,
  111095. 0,
  111096. 16,
  111097. };
  111098. static long _vq_lengthlist__16c2_s_p4_0[] = {
  111099. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  111100. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  111101. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  111102. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  111103. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  111104. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  111105. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  111106. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  111107. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  111108. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  111109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111117. 0,
  111118. };
  111119. static float _vq_quantthresh__16c2_s_p4_0[] = {
  111120. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  111121. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111122. };
  111123. static long _vq_quantmap__16c2_s_p4_0[] = {
  111124. 15, 13, 11, 9, 7, 5, 3, 1,
  111125. 0, 2, 4, 6, 8, 10, 12, 14,
  111126. 16,
  111127. };
  111128. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  111129. _vq_quantthresh__16c2_s_p4_0,
  111130. _vq_quantmap__16c2_s_p4_0,
  111131. 17,
  111132. 17
  111133. };
  111134. static static_codebook _16c2_s_p4_0 = {
  111135. 2, 289,
  111136. _vq_lengthlist__16c2_s_p4_0,
  111137. 1, -529530880, 1611661312, 5, 0,
  111138. _vq_quantlist__16c2_s_p4_0,
  111139. NULL,
  111140. &_vq_auxt__16c2_s_p4_0,
  111141. NULL,
  111142. 0
  111143. };
  111144. static long _vq_quantlist__16c2_s_p5_0[] = {
  111145. 1,
  111146. 0,
  111147. 2,
  111148. };
  111149. static long _vq_lengthlist__16c2_s_p5_0[] = {
  111150. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  111151. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  111152. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  111153. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  111154. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  111155. 12,
  111156. };
  111157. static float _vq_quantthresh__16c2_s_p5_0[] = {
  111158. -5.5, 5.5,
  111159. };
  111160. static long _vq_quantmap__16c2_s_p5_0[] = {
  111161. 1, 0, 2,
  111162. };
  111163. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  111164. _vq_quantthresh__16c2_s_p5_0,
  111165. _vq_quantmap__16c2_s_p5_0,
  111166. 3,
  111167. 3
  111168. };
  111169. static static_codebook _16c2_s_p5_0 = {
  111170. 4, 81,
  111171. _vq_lengthlist__16c2_s_p5_0,
  111172. 1, -529137664, 1618345984, 2, 0,
  111173. _vq_quantlist__16c2_s_p5_0,
  111174. NULL,
  111175. &_vq_auxt__16c2_s_p5_0,
  111176. NULL,
  111177. 0
  111178. };
  111179. static long _vq_quantlist__16c2_s_p5_1[] = {
  111180. 5,
  111181. 4,
  111182. 6,
  111183. 3,
  111184. 7,
  111185. 2,
  111186. 8,
  111187. 1,
  111188. 9,
  111189. 0,
  111190. 10,
  111191. };
  111192. static long _vq_lengthlist__16c2_s_p5_1[] = {
  111193. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  111194. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  111195. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  111196. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  111197. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  111198. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  111199. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  111200. 11,11,11, 7, 7, 8, 8, 8, 8,
  111201. };
  111202. static float _vq_quantthresh__16c2_s_p5_1[] = {
  111203. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111204. 3.5, 4.5,
  111205. };
  111206. static long _vq_quantmap__16c2_s_p5_1[] = {
  111207. 9, 7, 5, 3, 1, 0, 2, 4,
  111208. 6, 8, 10,
  111209. };
  111210. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  111211. _vq_quantthresh__16c2_s_p5_1,
  111212. _vq_quantmap__16c2_s_p5_1,
  111213. 11,
  111214. 11
  111215. };
  111216. static static_codebook _16c2_s_p5_1 = {
  111217. 2, 121,
  111218. _vq_lengthlist__16c2_s_p5_1,
  111219. 1, -531365888, 1611661312, 4, 0,
  111220. _vq_quantlist__16c2_s_p5_1,
  111221. NULL,
  111222. &_vq_auxt__16c2_s_p5_1,
  111223. NULL,
  111224. 0
  111225. };
  111226. static long _vq_quantlist__16c2_s_p6_0[] = {
  111227. 6,
  111228. 5,
  111229. 7,
  111230. 4,
  111231. 8,
  111232. 3,
  111233. 9,
  111234. 2,
  111235. 10,
  111236. 1,
  111237. 11,
  111238. 0,
  111239. 12,
  111240. };
  111241. static long _vq_lengthlist__16c2_s_p6_0[] = {
  111242. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111243. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  111244. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  111245. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  111246. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  111247. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  111248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111252. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111253. };
  111254. static float _vq_quantthresh__16c2_s_p6_0[] = {
  111255. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  111256. 12.5, 17.5, 22.5, 27.5,
  111257. };
  111258. static long _vq_quantmap__16c2_s_p6_0[] = {
  111259. 11, 9, 7, 5, 3, 1, 0, 2,
  111260. 4, 6, 8, 10, 12,
  111261. };
  111262. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  111263. _vq_quantthresh__16c2_s_p6_0,
  111264. _vq_quantmap__16c2_s_p6_0,
  111265. 13,
  111266. 13
  111267. };
  111268. static static_codebook _16c2_s_p6_0 = {
  111269. 2, 169,
  111270. _vq_lengthlist__16c2_s_p6_0,
  111271. 1, -526516224, 1616117760, 4, 0,
  111272. _vq_quantlist__16c2_s_p6_0,
  111273. NULL,
  111274. &_vq_auxt__16c2_s_p6_0,
  111275. NULL,
  111276. 0
  111277. };
  111278. static long _vq_quantlist__16c2_s_p6_1[] = {
  111279. 2,
  111280. 1,
  111281. 3,
  111282. 0,
  111283. 4,
  111284. };
  111285. static long _vq_lengthlist__16c2_s_p6_1[] = {
  111286. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  111287. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  111288. };
  111289. static float _vq_quantthresh__16c2_s_p6_1[] = {
  111290. -1.5, -0.5, 0.5, 1.5,
  111291. };
  111292. static long _vq_quantmap__16c2_s_p6_1[] = {
  111293. 3, 1, 0, 2, 4,
  111294. };
  111295. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  111296. _vq_quantthresh__16c2_s_p6_1,
  111297. _vq_quantmap__16c2_s_p6_1,
  111298. 5,
  111299. 5
  111300. };
  111301. static static_codebook _16c2_s_p6_1 = {
  111302. 2, 25,
  111303. _vq_lengthlist__16c2_s_p6_1,
  111304. 1, -533725184, 1611661312, 3, 0,
  111305. _vq_quantlist__16c2_s_p6_1,
  111306. NULL,
  111307. &_vq_auxt__16c2_s_p6_1,
  111308. NULL,
  111309. 0
  111310. };
  111311. static long _vq_quantlist__16c2_s_p7_0[] = {
  111312. 6,
  111313. 5,
  111314. 7,
  111315. 4,
  111316. 8,
  111317. 3,
  111318. 9,
  111319. 2,
  111320. 10,
  111321. 1,
  111322. 11,
  111323. 0,
  111324. 12,
  111325. };
  111326. static long _vq_lengthlist__16c2_s_p7_0[] = {
  111327. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111328. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  111329. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  111330. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  111331. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  111332. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  111333. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  111334. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  111335. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  111336. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  111337. 18,13,14,13,13,14,13,15,14,
  111338. };
  111339. static float _vq_quantthresh__16c2_s_p7_0[] = {
  111340. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  111341. 27.5, 38.5, 49.5, 60.5,
  111342. };
  111343. static long _vq_quantmap__16c2_s_p7_0[] = {
  111344. 11, 9, 7, 5, 3, 1, 0, 2,
  111345. 4, 6, 8, 10, 12,
  111346. };
  111347. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  111348. _vq_quantthresh__16c2_s_p7_0,
  111349. _vq_quantmap__16c2_s_p7_0,
  111350. 13,
  111351. 13
  111352. };
  111353. static static_codebook _16c2_s_p7_0 = {
  111354. 2, 169,
  111355. _vq_lengthlist__16c2_s_p7_0,
  111356. 1, -523206656, 1618345984, 4, 0,
  111357. _vq_quantlist__16c2_s_p7_0,
  111358. NULL,
  111359. &_vq_auxt__16c2_s_p7_0,
  111360. NULL,
  111361. 0
  111362. };
  111363. static long _vq_quantlist__16c2_s_p7_1[] = {
  111364. 5,
  111365. 4,
  111366. 6,
  111367. 3,
  111368. 7,
  111369. 2,
  111370. 8,
  111371. 1,
  111372. 9,
  111373. 0,
  111374. 10,
  111375. };
  111376. static long _vq_lengthlist__16c2_s_p7_1[] = {
  111377. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  111378. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  111379. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  111380. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111381. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  111382. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  111383. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  111384. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111385. };
  111386. static float _vq_quantthresh__16c2_s_p7_1[] = {
  111387. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111388. 3.5, 4.5,
  111389. };
  111390. static long _vq_quantmap__16c2_s_p7_1[] = {
  111391. 9, 7, 5, 3, 1, 0, 2, 4,
  111392. 6, 8, 10,
  111393. };
  111394. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  111395. _vq_quantthresh__16c2_s_p7_1,
  111396. _vq_quantmap__16c2_s_p7_1,
  111397. 11,
  111398. 11
  111399. };
  111400. static static_codebook _16c2_s_p7_1 = {
  111401. 2, 121,
  111402. _vq_lengthlist__16c2_s_p7_1,
  111403. 1, -531365888, 1611661312, 4, 0,
  111404. _vq_quantlist__16c2_s_p7_1,
  111405. NULL,
  111406. &_vq_auxt__16c2_s_p7_1,
  111407. NULL,
  111408. 0
  111409. };
  111410. static long _vq_quantlist__16c2_s_p8_0[] = {
  111411. 7,
  111412. 6,
  111413. 8,
  111414. 5,
  111415. 9,
  111416. 4,
  111417. 10,
  111418. 3,
  111419. 11,
  111420. 2,
  111421. 12,
  111422. 1,
  111423. 13,
  111424. 0,
  111425. 14,
  111426. };
  111427. static long _vq_lengthlist__16c2_s_p8_0[] = {
  111428. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  111429. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  111430. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  111431. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  111432. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  111433. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  111434. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  111435. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  111436. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  111437. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  111438. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  111439. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  111440. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  111441. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  111442. 13,
  111443. };
  111444. static float _vq_quantthresh__16c2_s_p8_0[] = {
  111445. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  111446. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  111447. };
  111448. static long _vq_quantmap__16c2_s_p8_0[] = {
  111449. 13, 11, 9, 7, 5, 3, 1, 0,
  111450. 2, 4, 6, 8, 10, 12, 14,
  111451. };
  111452. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  111453. _vq_quantthresh__16c2_s_p8_0,
  111454. _vq_quantmap__16c2_s_p8_0,
  111455. 15,
  111456. 15
  111457. };
  111458. static static_codebook _16c2_s_p8_0 = {
  111459. 2, 225,
  111460. _vq_lengthlist__16c2_s_p8_0,
  111461. 1, -520986624, 1620377600, 4, 0,
  111462. _vq_quantlist__16c2_s_p8_0,
  111463. NULL,
  111464. &_vq_auxt__16c2_s_p8_0,
  111465. NULL,
  111466. 0
  111467. };
  111468. static long _vq_quantlist__16c2_s_p8_1[] = {
  111469. 10,
  111470. 9,
  111471. 11,
  111472. 8,
  111473. 12,
  111474. 7,
  111475. 13,
  111476. 6,
  111477. 14,
  111478. 5,
  111479. 15,
  111480. 4,
  111481. 16,
  111482. 3,
  111483. 17,
  111484. 2,
  111485. 18,
  111486. 1,
  111487. 19,
  111488. 0,
  111489. 20,
  111490. };
  111491. static long _vq_lengthlist__16c2_s_p8_1[] = {
  111492. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  111493. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  111494. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  111495. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  111496. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  111497. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  111498. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  111499. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  111500. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  111501. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  111502. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  111503. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  111504. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  111505. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  111506. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  111507. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  111508. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  111509. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  111510. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  111511. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  111512. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  111513. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  111514. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  111515. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  111516. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  111517. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  111518. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  111519. 10,11,10,10,10,10,10,10,10,
  111520. };
  111521. static float _vq_quantthresh__16c2_s_p8_1[] = {
  111522. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111523. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111524. 6.5, 7.5, 8.5, 9.5,
  111525. };
  111526. static long _vq_quantmap__16c2_s_p8_1[] = {
  111527. 19, 17, 15, 13, 11, 9, 7, 5,
  111528. 3, 1, 0, 2, 4, 6, 8, 10,
  111529. 12, 14, 16, 18, 20,
  111530. };
  111531. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111532. _vq_quantthresh__16c2_s_p8_1,
  111533. _vq_quantmap__16c2_s_p8_1,
  111534. 21,
  111535. 21
  111536. };
  111537. static static_codebook _16c2_s_p8_1 = {
  111538. 2, 441,
  111539. _vq_lengthlist__16c2_s_p8_1,
  111540. 1, -529268736, 1611661312, 5, 0,
  111541. _vq_quantlist__16c2_s_p8_1,
  111542. NULL,
  111543. &_vq_auxt__16c2_s_p8_1,
  111544. NULL,
  111545. 0
  111546. };
  111547. static long _vq_quantlist__16c2_s_p9_0[] = {
  111548. 6,
  111549. 5,
  111550. 7,
  111551. 4,
  111552. 8,
  111553. 3,
  111554. 9,
  111555. 2,
  111556. 10,
  111557. 1,
  111558. 11,
  111559. 0,
  111560. 12,
  111561. };
  111562. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111563. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111564. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111565. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111566. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111567. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111568. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111569. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111570. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111571. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111572. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111573. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111574. };
  111575. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111576. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111577. 2327.5, 3258.5, 4189.5, 5120.5,
  111578. };
  111579. static long _vq_quantmap__16c2_s_p9_0[] = {
  111580. 11, 9, 7, 5, 3, 1, 0, 2,
  111581. 4, 6, 8, 10, 12,
  111582. };
  111583. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111584. _vq_quantthresh__16c2_s_p9_0,
  111585. _vq_quantmap__16c2_s_p9_0,
  111586. 13,
  111587. 13
  111588. };
  111589. static static_codebook _16c2_s_p9_0 = {
  111590. 2, 169,
  111591. _vq_lengthlist__16c2_s_p9_0,
  111592. 1, -510275072, 1631393792, 4, 0,
  111593. _vq_quantlist__16c2_s_p9_0,
  111594. NULL,
  111595. &_vq_auxt__16c2_s_p9_0,
  111596. NULL,
  111597. 0
  111598. };
  111599. static long _vq_quantlist__16c2_s_p9_1[] = {
  111600. 8,
  111601. 7,
  111602. 9,
  111603. 6,
  111604. 10,
  111605. 5,
  111606. 11,
  111607. 4,
  111608. 12,
  111609. 3,
  111610. 13,
  111611. 2,
  111612. 14,
  111613. 1,
  111614. 15,
  111615. 0,
  111616. 16,
  111617. };
  111618. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111619. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111620. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111621. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111622. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111623. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111624. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111625. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111626. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111627. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111628. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111629. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111630. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111631. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111632. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111633. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111634. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111635. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111636. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111637. 10,
  111638. };
  111639. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111640. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111641. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111642. };
  111643. static long _vq_quantmap__16c2_s_p9_1[] = {
  111644. 15, 13, 11, 9, 7, 5, 3, 1,
  111645. 0, 2, 4, 6, 8, 10, 12, 14,
  111646. 16,
  111647. };
  111648. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111649. _vq_quantthresh__16c2_s_p9_1,
  111650. _vq_quantmap__16c2_s_p9_1,
  111651. 17,
  111652. 17
  111653. };
  111654. static static_codebook _16c2_s_p9_1 = {
  111655. 2, 289,
  111656. _vq_lengthlist__16c2_s_p9_1,
  111657. 1, -518488064, 1622704128, 5, 0,
  111658. _vq_quantlist__16c2_s_p9_1,
  111659. NULL,
  111660. &_vq_auxt__16c2_s_p9_1,
  111661. NULL,
  111662. 0
  111663. };
  111664. static long _vq_quantlist__16c2_s_p9_2[] = {
  111665. 13,
  111666. 12,
  111667. 14,
  111668. 11,
  111669. 15,
  111670. 10,
  111671. 16,
  111672. 9,
  111673. 17,
  111674. 8,
  111675. 18,
  111676. 7,
  111677. 19,
  111678. 6,
  111679. 20,
  111680. 5,
  111681. 21,
  111682. 4,
  111683. 22,
  111684. 3,
  111685. 23,
  111686. 2,
  111687. 24,
  111688. 1,
  111689. 25,
  111690. 0,
  111691. 26,
  111692. };
  111693. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111694. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111695. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111696. };
  111697. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111698. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111699. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111700. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111701. 11.5, 12.5,
  111702. };
  111703. static long _vq_quantmap__16c2_s_p9_2[] = {
  111704. 25, 23, 21, 19, 17, 15, 13, 11,
  111705. 9, 7, 5, 3, 1, 0, 2, 4,
  111706. 6, 8, 10, 12, 14, 16, 18, 20,
  111707. 22, 24, 26,
  111708. };
  111709. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111710. _vq_quantthresh__16c2_s_p9_2,
  111711. _vq_quantmap__16c2_s_p9_2,
  111712. 27,
  111713. 27
  111714. };
  111715. static static_codebook _16c2_s_p9_2 = {
  111716. 1, 27,
  111717. _vq_lengthlist__16c2_s_p9_2,
  111718. 1, -528875520, 1611661312, 5, 0,
  111719. _vq_quantlist__16c2_s_p9_2,
  111720. NULL,
  111721. &_vq_auxt__16c2_s_p9_2,
  111722. NULL,
  111723. 0
  111724. };
  111725. static long _huff_lengthlist__16c2_s_short[] = {
  111726. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111727. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111728. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111729. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111730. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111731. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111732. 15,12,14,14,
  111733. };
  111734. static static_codebook _huff_book__16c2_s_short = {
  111735. 2, 100,
  111736. _huff_lengthlist__16c2_s_short,
  111737. 0, 0, 0, 0, 0,
  111738. NULL,
  111739. NULL,
  111740. NULL,
  111741. NULL,
  111742. 0
  111743. };
  111744. static long _vq_quantlist__8c0_s_p1_0[] = {
  111745. 1,
  111746. 0,
  111747. 2,
  111748. };
  111749. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111750. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111751. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111756. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111760. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111761. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0,
  111796. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  111801. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 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, 7, 9,10, 0, 0,
  111806. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111842. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111847. 0, 0, 0, 0, 0, 9,10,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111852. 0, 0, 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 0,
  111853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112160. 0,
  112161. };
  112162. static float _vq_quantthresh__8c0_s_p1_0[] = {
  112163. -0.5, 0.5,
  112164. };
  112165. static long _vq_quantmap__8c0_s_p1_0[] = {
  112166. 1, 0, 2,
  112167. };
  112168. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  112169. _vq_quantthresh__8c0_s_p1_0,
  112170. _vq_quantmap__8c0_s_p1_0,
  112171. 3,
  112172. 3
  112173. };
  112174. static static_codebook _8c0_s_p1_0 = {
  112175. 8, 6561,
  112176. _vq_lengthlist__8c0_s_p1_0,
  112177. 1, -535822336, 1611661312, 2, 0,
  112178. _vq_quantlist__8c0_s_p1_0,
  112179. NULL,
  112180. &_vq_auxt__8c0_s_p1_0,
  112181. NULL,
  112182. 0
  112183. };
  112184. static long _vq_quantlist__8c0_s_p2_0[] = {
  112185. 2,
  112186. 1,
  112187. 3,
  112188. 0,
  112189. 4,
  112190. };
  112191. static long _vq_lengthlist__8c0_s_p2_0[] = {
  112192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112231. 0,
  112232. };
  112233. static float _vq_quantthresh__8c0_s_p2_0[] = {
  112234. -1.5, -0.5, 0.5, 1.5,
  112235. };
  112236. static long _vq_quantmap__8c0_s_p2_0[] = {
  112237. 3, 1, 0, 2, 4,
  112238. };
  112239. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  112240. _vq_quantthresh__8c0_s_p2_0,
  112241. _vq_quantmap__8c0_s_p2_0,
  112242. 5,
  112243. 5
  112244. };
  112245. static static_codebook _8c0_s_p2_0 = {
  112246. 4, 625,
  112247. _vq_lengthlist__8c0_s_p2_0,
  112248. 1, -533725184, 1611661312, 3, 0,
  112249. _vq_quantlist__8c0_s_p2_0,
  112250. NULL,
  112251. &_vq_auxt__8c0_s_p2_0,
  112252. NULL,
  112253. 0
  112254. };
  112255. static long _vq_quantlist__8c0_s_p3_0[] = {
  112256. 2,
  112257. 1,
  112258. 3,
  112259. 0,
  112260. 4,
  112261. };
  112262. static long _vq_lengthlist__8c0_s_p3_0[] = {
  112263. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  112265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112266. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  112268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112269. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  112270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112302. 0,
  112303. };
  112304. static float _vq_quantthresh__8c0_s_p3_0[] = {
  112305. -1.5, -0.5, 0.5, 1.5,
  112306. };
  112307. static long _vq_quantmap__8c0_s_p3_0[] = {
  112308. 3, 1, 0, 2, 4,
  112309. };
  112310. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  112311. _vq_quantthresh__8c0_s_p3_0,
  112312. _vq_quantmap__8c0_s_p3_0,
  112313. 5,
  112314. 5
  112315. };
  112316. static static_codebook _8c0_s_p3_0 = {
  112317. 4, 625,
  112318. _vq_lengthlist__8c0_s_p3_0,
  112319. 1, -533725184, 1611661312, 3, 0,
  112320. _vq_quantlist__8c0_s_p3_0,
  112321. NULL,
  112322. &_vq_auxt__8c0_s_p3_0,
  112323. NULL,
  112324. 0
  112325. };
  112326. static long _vq_quantlist__8c0_s_p4_0[] = {
  112327. 4,
  112328. 3,
  112329. 5,
  112330. 2,
  112331. 6,
  112332. 1,
  112333. 7,
  112334. 0,
  112335. 8,
  112336. };
  112337. static long _vq_lengthlist__8c0_s_p4_0[] = {
  112338. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112339. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112340. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112341. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112342. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112343. 0,
  112344. };
  112345. static float _vq_quantthresh__8c0_s_p4_0[] = {
  112346. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112347. };
  112348. static long _vq_quantmap__8c0_s_p4_0[] = {
  112349. 7, 5, 3, 1, 0, 2, 4, 6,
  112350. 8,
  112351. };
  112352. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  112353. _vq_quantthresh__8c0_s_p4_0,
  112354. _vq_quantmap__8c0_s_p4_0,
  112355. 9,
  112356. 9
  112357. };
  112358. static static_codebook _8c0_s_p4_0 = {
  112359. 2, 81,
  112360. _vq_lengthlist__8c0_s_p4_0,
  112361. 1, -531628032, 1611661312, 4, 0,
  112362. _vq_quantlist__8c0_s_p4_0,
  112363. NULL,
  112364. &_vq_auxt__8c0_s_p4_0,
  112365. NULL,
  112366. 0
  112367. };
  112368. static long _vq_quantlist__8c0_s_p5_0[] = {
  112369. 4,
  112370. 3,
  112371. 5,
  112372. 2,
  112373. 6,
  112374. 1,
  112375. 7,
  112376. 0,
  112377. 8,
  112378. };
  112379. static long _vq_lengthlist__8c0_s_p5_0[] = {
  112380. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  112381. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  112382. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  112383. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  112384. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112385. 10,
  112386. };
  112387. static float _vq_quantthresh__8c0_s_p5_0[] = {
  112388. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112389. };
  112390. static long _vq_quantmap__8c0_s_p5_0[] = {
  112391. 7, 5, 3, 1, 0, 2, 4, 6,
  112392. 8,
  112393. };
  112394. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  112395. _vq_quantthresh__8c0_s_p5_0,
  112396. _vq_quantmap__8c0_s_p5_0,
  112397. 9,
  112398. 9
  112399. };
  112400. static static_codebook _8c0_s_p5_0 = {
  112401. 2, 81,
  112402. _vq_lengthlist__8c0_s_p5_0,
  112403. 1, -531628032, 1611661312, 4, 0,
  112404. _vq_quantlist__8c0_s_p5_0,
  112405. NULL,
  112406. &_vq_auxt__8c0_s_p5_0,
  112407. NULL,
  112408. 0
  112409. };
  112410. static long _vq_quantlist__8c0_s_p6_0[] = {
  112411. 8,
  112412. 7,
  112413. 9,
  112414. 6,
  112415. 10,
  112416. 5,
  112417. 11,
  112418. 4,
  112419. 12,
  112420. 3,
  112421. 13,
  112422. 2,
  112423. 14,
  112424. 1,
  112425. 15,
  112426. 0,
  112427. 16,
  112428. };
  112429. static long _vq_lengthlist__8c0_s_p6_0[] = {
  112430. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  112431. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112432. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  112433. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  112434. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  112435. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  112436. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  112437. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  112438. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  112439. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  112440. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  112441. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  112442. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  112443. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  112444. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  112445. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  112446. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  112447. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  112448. 14,
  112449. };
  112450. static float _vq_quantthresh__8c0_s_p6_0[] = {
  112451. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  112452. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  112453. };
  112454. static long _vq_quantmap__8c0_s_p6_0[] = {
  112455. 15, 13, 11, 9, 7, 5, 3, 1,
  112456. 0, 2, 4, 6, 8, 10, 12, 14,
  112457. 16,
  112458. };
  112459. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  112460. _vq_quantthresh__8c0_s_p6_0,
  112461. _vq_quantmap__8c0_s_p6_0,
  112462. 17,
  112463. 17
  112464. };
  112465. static static_codebook _8c0_s_p6_0 = {
  112466. 2, 289,
  112467. _vq_lengthlist__8c0_s_p6_0,
  112468. 1, -529530880, 1611661312, 5, 0,
  112469. _vq_quantlist__8c0_s_p6_0,
  112470. NULL,
  112471. &_vq_auxt__8c0_s_p6_0,
  112472. NULL,
  112473. 0
  112474. };
  112475. static long _vq_quantlist__8c0_s_p7_0[] = {
  112476. 1,
  112477. 0,
  112478. 2,
  112479. };
  112480. static long _vq_lengthlist__8c0_s_p7_0[] = {
  112481. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  112482. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  112483. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  112484. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  112485. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  112486. 10,
  112487. };
  112488. static float _vq_quantthresh__8c0_s_p7_0[] = {
  112489. -5.5, 5.5,
  112490. };
  112491. static long _vq_quantmap__8c0_s_p7_0[] = {
  112492. 1, 0, 2,
  112493. };
  112494. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  112495. _vq_quantthresh__8c0_s_p7_0,
  112496. _vq_quantmap__8c0_s_p7_0,
  112497. 3,
  112498. 3
  112499. };
  112500. static static_codebook _8c0_s_p7_0 = {
  112501. 4, 81,
  112502. _vq_lengthlist__8c0_s_p7_0,
  112503. 1, -529137664, 1618345984, 2, 0,
  112504. _vq_quantlist__8c0_s_p7_0,
  112505. NULL,
  112506. &_vq_auxt__8c0_s_p7_0,
  112507. NULL,
  112508. 0
  112509. };
  112510. static long _vq_quantlist__8c0_s_p7_1[] = {
  112511. 5,
  112512. 4,
  112513. 6,
  112514. 3,
  112515. 7,
  112516. 2,
  112517. 8,
  112518. 1,
  112519. 9,
  112520. 0,
  112521. 10,
  112522. };
  112523. static long _vq_lengthlist__8c0_s_p7_1[] = {
  112524. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  112525. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112526. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112527. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112528. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112529. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112530. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112531. 10,10,10, 9, 9, 9,10,10,10,
  112532. };
  112533. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112534. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112535. 3.5, 4.5,
  112536. };
  112537. static long _vq_quantmap__8c0_s_p7_1[] = {
  112538. 9, 7, 5, 3, 1, 0, 2, 4,
  112539. 6, 8, 10,
  112540. };
  112541. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112542. _vq_quantthresh__8c0_s_p7_1,
  112543. _vq_quantmap__8c0_s_p7_1,
  112544. 11,
  112545. 11
  112546. };
  112547. static static_codebook _8c0_s_p7_1 = {
  112548. 2, 121,
  112549. _vq_lengthlist__8c0_s_p7_1,
  112550. 1, -531365888, 1611661312, 4, 0,
  112551. _vq_quantlist__8c0_s_p7_1,
  112552. NULL,
  112553. &_vq_auxt__8c0_s_p7_1,
  112554. NULL,
  112555. 0
  112556. };
  112557. static long _vq_quantlist__8c0_s_p8_0[] = {
  112558. 6,
  112559. 5,
  112560. 7,
  112561. 4,
  112562. 8,
  112563. 3,
  112564. 9,
  112565. 2,
  112566. 10,
  112567. 1,
  112568. 11,
  112569. 0,
  112570. 12,
  112571. };
  112572. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112573. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112574. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112575. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112576. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112577. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112578. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112579. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112580. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112581. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112582. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112583. 0, 0,13,13,11,13,13,11,12,
  112584. };
  112585. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112586. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112587. 12.5, 17.5, 22.5, 27.5,
  112588. };
  112589. static long _vq_quantmap__8c0_s_p8_0[] = {
  112590. 11, 9, 7, 5, 3, 1, 0, 2,
  112591. 4, 6, 8, 10, 12,
  112592. };
  112593. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112594. _vq_quantthresh__8c0_s_p8_0,
  112595. _vq_quantmap__8c0_s_p8_0,
  112596. 13,
  112597. 13
  112598. };
  112599. static static_codebook _8c0_s_p8_0 = {
  112600. 2, 169,
  112601. _vq_lengthlist__8c0_s_p8_0,
  112602. 1, -526516224, 1616117760, 4, 0,
  112603. _vq_quantlist__8c0_s_p8_0,
  112604. NULL,
  112605. &_vq_auxt__8c0_s_p8_0,
  112606. NULL,
  112607. 0
  112608. };
  112609. static long _vq_quantlist__8c0_s_p8_1[] = {
  112610. 2,
  112611. 1,
  112612. 3,
  112613. 0,
  112614. 4,
  112615. };
  112616. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112617. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112618. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112619. };
  112620. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112621. -1.5, -0.5, 0.5, 1.5,
  112622. };
  112623. static long _vq_quantmap__8c0_s_p8_1[] = {
  112624. 3, 1, 0, 2, 4,
  112625. };
  112626. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112627. _vq_quantthresh__8c0_s_p8_1,
  112628. _vq_quantmap__8c0_s_p8_1,
  112629. 5,
  112630. 5
  112631. };
  112632. static static_codebook _8c0_s_p8_1 = {
  112633. 2, 25,
  112634. _vq_lengthlist__8c0_s_p8_1,
  112635. 1, -533725184, 1611661312, 3, 0,
  112636. _vq_quantlist__8c0_s_p8_1,
  112637. NULL,
  112638. &_vq_auxt__8c0_s_p8_1,
  112639. NULL,
  112640. 0
  112641. };
  112642. static long _vq_quantlist__8c0_s_p9_0[] = {
  112643. 1,
  112644. 0,
  112645. 2,
  112646. };
  112647. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112648. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112649. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112650. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112651. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112652. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112653. 7,
  112654. };
  112655. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112656. -157.5, 157.5,
  112657. };
  112658. static long _vq_quantmap__8c0_s_p9_0[] = {
  112659. 1, 0, 2,
  112660. };
  112661. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112662. _vq_quantthresh__8c0_s_p9_0,
  112663. _vq_quantmap__8c0_s_p9_0,
  112664. 3,
  112665. 3
  112666. };
  112667. static static_codebook _8c0_s_p9_0 = {
  112668. 4, 81,
  112669. _vq_lengthlist__8c0_s_p9_0,
  112670. 1, -518803456, 1628680192, 2, 0,
  112671. _vq_quantlist__8c0_s_p9_0,
  112672. NULL,
  112673. &_vq_auxt__8c0_s_p9_0,
  112674. NULL,
  112675. 0
  112676. };
  112677. static long _vq_quantlist__8c0_s_p9_1[] = {
  112678. 7,
  112679. 6,
  112680. 8,
  112681. 5,
  112682. 9,
  112683. 4,
  112684. 10,
  112685. 3,
  112686. 11,
  112687. 2,
  112688. 12,
  112689. 1,
  112690. 13,
  112691. 0,
  112692. 14,
  112693. };
  112694. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112695. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112696. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112697. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112698. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112699. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112700. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112701. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112702. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112703. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112704. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112705. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112706. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112707. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112708. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112709. 11,
  112710. };
  112711. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112712. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112713. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112714. };
  112715. static long _vq_quantmap__8c0_s_p9_1[] = {
  112716. 13, 11, 9, 7, 5, 3, 1, 0,
  112717. 2, 4, 6, 8, 10, 12, 14,
  112718. };
  112719. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112720. _vq_quantthresh__8c0_s_p9_1,
  112721. _vq_quantmap__8c0_s_p9_1,
  112722. 15,
  112723. 15
  112724. };
  112725. static static_codebook _8c0_s_p9_1 = {
  112726. 2, 225,
  112727. _vq_lengthlist__8c0_s_p9_1,
  112728. 1, -520986624, 1620377600, 4, 0,
  112729. _vq_quantlist__8c0_s_p9_1,
  112730. NULL,
  112731. &_vq_auxt__8c0_s_p9_1,
  112732. NULL,
  112733. 0
  112734. };
  112735. static long _vq_quantlist__8c0_s_p9_2[] = {
  112736. 10,
  112737. 9,
  112738. 11,
  112739. 8,
  112740. 12,
  112741. 7,
  112742. 13,
  112743. 6,
  112744. 14,
  112745. 5,
  112746. 15,
  112747. 4,
  112748. 16,
  112749. 3,
  112750. 17,
  112751. 2,
  112752. 18,
  112753. 1,
  112754. 19,
  112755. 0,
  112756. 20,
  112757. };
  112758. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112759. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112760. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112761. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112762. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112763. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112764. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112765. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112766. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112767. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112768. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112769. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112770. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112771. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112772. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112773. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112774. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112775. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112776. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112777. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112778. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112779. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112780. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112781. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112782. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112783. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112784. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112785. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112786. 10,11, 9,11,10, 9,10, 9,10,
  112787. };
  112788. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112789. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112790. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112791. 6.5, 7.5, 8.5, 9.5,
  112792. };
  112793. static long _vq_quantmap__8c0_s_p9_2[] = {
  112794. 19, 17, 15, 13, 11, 9, 7, 5,
  112795. 3, 1, 0, 2, 4, 6, 8, 10,
  112796. 12, 14, 16, 18, 20,
  112797. };
  112798. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112799. _vq_quantthresh__8c0_s_p9_2,
  112800. _vq_quantmap__8c0_s_p9_2,
  112801. 21,
  112802. 21
  112803. };
  112804. static static_codebook _8c0_s_p9_2 = {
  112805. 2, 441,
  112806. _vq_lengthlist__8c0_s_p9_2,
  112807. 1, -529268736, 1611661312, 5, 0,
  112808. _vq_quantlist__8c0_s_p9_2,
  112809. NULL,
  112810. &_vq_auxt__8c0_s_p9_2,
  112811. NULL,
  112812. 0
  112813. };
  112814. static long _huff_lengthlist__8c0_s_single[] = {
  112815. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112816. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112817. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112818. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112819. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112820. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112821. 17,16,17,17,
  112822. };
  112823. static static_codebook _huff_book__8c0_s_single = {
  112824. 2, 100,
  112825. _huff_lengthlist__8c0_s_single,
  112826. 0, 0, 0, 0, 0,
  112827. NULL,
  112828. NULL,
  112829. NULL,
  112830. NULL,
  112831. 0
  112832. };
  112833. static long _vq_quantlist__8c1_s_p1_0[] = {
  112834. 1,
  112835. 0,
  112836. 2,
  112837. };
  112838. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112839. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112840. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112845. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112849. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112850. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0,
  112885. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  112890. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  112895. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112931. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112936. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112941. 0, 0, 0, 0, 0, 0, 8,10, 8, 0, 0, 0, 0, 0, 0, 0,
  112942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113249. 0,
  113250. };
  113251. static float _vq_quantthresh__8c1_s_p1_0[] = {
  113252. -0.5, 0.5,
  113253. };
  113254. static long _vq_quantmap__8c1_s_p1_0[] = {
  113255. 1, 0, 2,
  113256. };
  113257. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  113258. _vq_quantthresh__8c1_s_p1_0,
  113259. _vq_quantmap__8c1_s_p1_0,
  113260. 3,
  113261. 3
  113262. };
  113263. static static_codebook _8c1_s_p1_0 = {
  113264. 8, 6561,
  113265. _vq_lengthlist__8c1_s_p1_0,
  113266. 1, -535822336, 1611661312, 2, 0,
  113267. _vq_quantlist__8c1_s_p1_0,
  113268. NULL,
  113269. &_vq_auxt__8c1_s_p1_0,
  113270. NULL,
  113271. 0
  113272. };
  113273. static long _vq_quantlist__8c1_s_p2_0[] = {
  113274. 2,
  113275. 1,
  113276. 3,
  113277. 0,
  113278. 4,
  113279. };
  113280. static long _vq_lengthlist__8c1_s_p2_0[] = {
  113281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113320. 0,
  113321. };
  113322. static float _vq_quantthresh__8c1_s_p2_0[] = {
  113323. -1.5, -0.5, 0.5, 1.5,
  113324. };
  113325. static long _vq_quantmap__8c1_s_p2_0[] = {
  113326. 3, 1, 0, 2, 4,
  113327. };
  113328. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  113329. _vq_quantthresh__8c1_s_p2_0,
  113330. _vq_quantmap__8c1_s_p2_0,
  113331. 5,
  113332. 5
  113333. };
  113334. static static_codebook _8c1_s_p2_0 = {
  113335. 4, 625,
  113336. _vq_lengthlist__8c1_s_p2_0,
  113337. 1, -533725184, 1611661312, 3, 0,
  113338. _vq_quantlist__8c1_s_p2_0,
  113339. NULL,
  113340. &_vq_auxt__8c1_s_p2_0,
  113341. NULL,
  113342. 0
  113343. };
  113344. static long _vq_quantlist__8c1_s_p3_0[] = {
  113345. 2,
  113346. 1,
  113347. 3,
  113348. 0,
  113349. 4,
  113350. };
  113351. static long _vq_lengthlist__8c1_s_p3_0[] = {
  113352. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113355. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  113357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113358. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113391. 0,
  113392. };
  113393. static float _vq_quantthresh__8c1_s_p3_0[] = {
  113394. -1.5, -0.5, 0.5, 1.5,
  113395. };
  113396. static long _vq_quantmap__8c1_s_p3_0[] = {
  113397. 3, 1, 0, 2, 4,
  113398. };
  113399. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  113400. _vq_quantthresh__8c1_s_p3_0,
  113401. _vq_quantmap__8c1_s_p3_0,
  113402. 5,
  113403. 5
  113404. };
  113405. static static_codebook _8c1_s_p3_0 = {
  113406. 4, 625,
  113407. _vq_lengthlist__8c1_s_p3_0,
  113408. 1, -533725184, 1611661312, 3, 0,
  113409. _vq_quantlist__8c1_s_p3_0,
  113410. NULL,
  113411. &_vq_auxt__8c1_s_p3_0,
  113412. NULL,
  113413. 0
  113414. };
  113415. static long _vq_quantlist__8c1_s_p4_0[] = {
  113416. 4,
  113417. 3,
  113418. 5,
  113419. 2,
  113420. 6,
  113421. 1,
  113422. 7,
  113423. 0,
  113424. 8,
  113425. };
  113426. static long _vq_lengthlist__8c1_s_p4_0[] = {
  113427. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  113428. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  113429. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113430. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  113431. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113432. 0,
  113433. };
  113434. static float _vq_quantthresh__8c1_s_p4_0[] = {
  113435. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113436. };
  113437. static long _vq_quantmap__8c1_s_p4_0[] = {
  113438. 7, 5, 3, 1, 0, 2, 4, 6,
  113439. 8,
  113440. };
  113441. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  113442. _vq_quantthresh__8c1_s_p4_0,
  113443. _vq_quantmap__8c1_s_p4_0,
  113444. 9,
  113445. 9
  113446. };
  113447. static static_codebook _8c1_s_p4_0 = {
  113448. 2, 81,
  113449. _vq_lengthlist__8c1_s_p4_0,
  113450. 1, -531628032, 1611661312, 4, 0,
  113451. _vq_quantlist__8c1_s_p4_0,
  113452. NULL,
  113453. &_vq_auxt__8c1_s_p4_0,
  113454. NULL,
  113455. 0
  113456. };
  113457. static long _vq_quantlist__8c1_s_p5_0[] = {
  113458. 4,
  113459. 3,
  113460. 5,
  113461. 2,
  113462. 6,
  113463. 1,
  113464. 7,
  113465. 0,
  113466. 8,
  113467. };
  113468. static long _vq_lengthlist__8c1_s_p5_0[] = {
  113469. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  113470. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  113471. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  113472. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  113473. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  113474. 10,
  113475. };
  113476. static float _vq_quantthresh__8c1_s_p5_0[] = {
  113477. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113478. };
  113479. static long _vq_quantmap__8c1_s_p5_0[] = {
  113480. 7, 5, 3, 1, 0, 2, 4, 6,
  113481. 8,
  113482. };
  113483. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  113484. _vq_quantthresh__8c1_s_p5_0,
  113485. _vq_quantmap__8c1_s_p5_0,
  113486. 9,
  113487. 9
  113488. };
  113489. static static_codebook _8c1_s_p5_0 = {
  113490. 2, 81,
  113491. _vq_lengthlist__8c1_s_p5_0,
  113492. 1, -531628032, 1611661312, 4, 0,
  113493. _vq_quantlist__8c1_s_p5_0,
  113494. NULL,
  113495. &_vq_auxt__8c1_s_p5_0,
  113496. NULL,
  113497. 0
  113498. };
  113499. static long _vq_quantlist__8c1_s_p6_0[] = {
  113500. 8,
  113501. 7,
  113502. 9,
  113503. 6,
  113504. 10,
  113505. 5,
  113506. 11,
  113507. 4,
  113508. 12,
  113509. 3,
  113510. 13,
  113511. 2,
  113512. 14,
  113513. 1,
  113514. 15,
  113515. 0,
  113516. 16,
  113517. };
  113518. static long _vq_lengthlist__8c1_s_p6_0[] = {
  113519. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  113520. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113521. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113522. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  113523. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  113524. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  113525. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113526. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113527. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113528. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113529. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113530. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113531. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113532. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113533. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113534. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113535. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113536. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113537. 14,
  113538. };
  113539. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113540. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113541. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113542. };
  113543. static long _vq_quantmap__8c1_s_p6_0[] = {
  113544. 15, 13, 11, 9, 7, 5, 3, 1,
  113545. 0, 2, 4, 6, 8, 10, 12, 14,
  113546. 16,
  113547. };
  113548. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113549. _vq_quantthresh__8c1_s_p6_0,
  113550. _vq_quantmap__8c1_s_p6_0,
  113551. 17,
  113552. 17
  113553. };
  113554. static static_codebook _8c1_s_p6_0 = {
  113555. 2, 289,
  113556. _vq_lengthlist__8c1_s_p6_0,
  113557. 1, -529530880, 1611661312, 5, 0,
  113558. _vq_quantlist__8c1_s_p6_0,
  113559. NULL,
  113560. &_vq_auxt__8c1_s_p6_0,
  113561. NULL,
  113562. 0
  113563. };
  113564. static long _vq_quantlist__8c1_s_p7_0[] = {
  113565. 1,
  113566. 0,
  113567. 2,
  113568. };
  113569. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113570. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113571. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113572. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113573. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113574. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113575. 9,
  113576. };
  113577. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113578. -5.5, 5.5,
  113579. };
  113580. static long _vq_quantmap__8c1_s_p7_0[] = {
  113581. 1, 0, 2,
  113582. };
  113583. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113584. _vq_quantthresh__8c1_s_p7_0,
  113585. _vq_quantmap__8c1_s_p7_0,
  113586. 3,
  113587. 3
  113588. };
  113589. static static_codebook _8c1_s_p7_0 = {
  113590. 4, 81,
  113591. _vq_lengthlist__8c1_s_p7_0,
  113592. 1, -529137664, 1618345984, 2, 0,
  113593. _vq_quantlist__8c1_s_p7_0,
  113594. NULL,
  113595. &_vq_auxt__8c1_s_p7_0,
  113596. NULL,
  113597. 0
  113598. };
  113599. static long _vq_quantlist__8c1_s_p7_1[] = {
  113600. 5,
  113601. 4,
  113602. 6,
  113603. 3,
  113604. 7,
  113605. 2,
  113606. 8,
  113607. 1,
  113608. 9,
  113609. 0,
  113610. 10,
  113611. };
  113612. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113613. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113614. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113615. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113616. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113617. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113618. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113619. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113620. 10,10,10, 8, 8, 8, 8, 8, 8,
  113621. };
  113622. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113623. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113624. 3.5, 4.5,
  113625. };
  113626. static long _vq_quantmap__8c1_s_p7_1[] = {
  113627. 9, 7, 5, 3, 1, 0, 2, 4,
  113628. 6, 8, 10,
  113629. };
  113630. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113631. _vq_quantthresh__8c1_s_p7_1,
  113632. _vq_quantmap__8c1_s_p7_1,
  113633. 11,
  113634. 11
  113635. };
  113636. static static_codebook _8c1_s_p7_1 = {
  113637. 2, 121,
  113638. _vq_lengthlist__8c1_s_p7_1,
  113639. 1, -531365888, 1611661312, 4, 0,
  113640. _vq_quantlist__8c1_s_p7_1,
  113641. NULL,
  113642. &_vq_auxt__8c1_s_p7_1,
  113643. NULL,
  113644. 0
  113645. };
  113646. static long _vq_quantlist__8c1_s_p8_0[] = {
  113647. 6,
  113648. 5,
  113649. 7,
  113650. 4,
  113651. 8,
  113652. 3,
  113653. 9,
  113654. 2,
  113655. 10,
  113656. 1,
  113657. 11,
  113658. 0,
  113659. 12,
  113660. };
  113661. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113662. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113663. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113664. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113665. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113666. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113667. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113668. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113669. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113670. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113671. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113672. 0,12,12,11,10,12,11,13,12,
  113673. };
  113674. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113675. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113676. 12.5, 17.5, 22.5, 27.5,
  113677. };
  113678. static long _vq_quantmap__8c1_s_p8_0[] = {
  113679. 11, 9, 7, 5, 3, 1, 0, 2,
  113680. 4, 6, 8, 10, 12,
  113681. };
  113682. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113683. _vq_quantthresh__8c1_s_p8_0,
  113684. _vq_quantmap__8c1_s_p8_0,
  113685. 13,
  113686. 13
  113687. };
  113688. static static_codebook _8c1_s_p8_0 = {
  113689. 2, 169,
  113690. _vq_lengthlist__8c1_s_p8_0,
  113691. 1, -526516224, 1616117760, 4, 0,
  113692. _vq_quantlist__8c1_s_p8_0,
  113693. NULL,
  113694. &_vq_auxt__8c1_s_p8_0,
  113695. NULL,
  113696. 0
  113697. };
  113698. static long _vq_quantlist__8c1_s_p8_1[] = {
  113699. 2,
  113700. 1,
  113701. 3,
  113702. 0,
  113703. 4,
  113704. };
  113705. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113706. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113707. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113708. };
  113709. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113710. -1.5, -0.5, 0.5, 1.5,
  113711. };
  113712. static long _vq_quantmap__8c1_s_p8_1[] = {
  113713. 3, 1, 0, 2, 4,
  113714. };
  113715. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113716. _vq_quantthresh__8c1_s_p8_1,
  113717. _vq_quantmap__8c1_s_p8_1,
  113718. 5,
  113719. 5
  113720. };
  113721. static static_codebook _8c1_s_p8_1 = {
  113722. 2, 25,
  113723. _vq_lengthlist__8c1_s_p8_1,
  113724. 1, -533725184, 1611661312, 3, 0,
  113725. _vq_quantlist__8c1_s_p8_1,
  113726. NULL,
  113727. &_vq_auxt__8c1_s_p8_1,
  113728. NULL,
  113729. 0
  113730. };
  113731. static long _vq_quantlist__8c1_s_p9_0[] = {
  113732. 6,
  113733. 5,
  113734. 7,
  113735. 4,
  113736. 8,
  113737. 3,
  113738. 9,
  113739. 2,
  113740. 10,
  113741. 1,
  113742. 11,
  113743. 0,
  113744. 12,
  113745. };
  113746. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113747. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113748. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113749. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113750. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113751. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113752. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113753. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113754. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113755. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113756. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113757. 10,10,10,10,10, 9, 9, 9, 9,
  113758. };
  113759. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113760. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113761. 787.5, 1102.5, 1417.5, 1732.5,
  113762. };
  113763. static long _vq_quantmap__8c1_s_p9_0[] = {
  113764. 11, 9, 7, 5, 3, 1, 0, 2,
  113765. 4, 6, 8, 10, 12,
  113766. };
  113767. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113768. _vq_quantthresh__8c1_s_p9_0,
  113769. _vq_quantmap__8c1_s_p9_0,
  113770. 13,
  113771. 13
  113772. };
  113773. static static_codebook _8c1_s_p9_0 = {
  113774. 2, 169,
  113775. _vq_lengthlist__8c1_s_p9_0,
  113776. 1, -513964032, 1628680192, 4, 0,
  113777. _vq_quantlist__8c1_s_p9_0,
  113778. NULL,
  113779. &_vq_auxt__8c1_s_p9_0,
  113780. NULL,
  113781. 0
  113782. };
  113783. static long _vq_quantlist__8c1_s_p9_1[] = {
  113784. 7,
  113785. 6,
  113786. 8,
  113787. 5,
  113788. 9,
  113789. 4,
  113790. 10,
  113791. 3,
  113792. 11,
  113793. 2,
  113794. 12,
  113795. 1,
  113796. 13,
  113797. 0,
  113798. 14,
  113799. };
  113800. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113801. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113802. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113803. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113804. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113805. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113806. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113807. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113808. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113809. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113810. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113811. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113812. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113813. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113814. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113815. 15,
  113816. };
  113817. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113818. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113819. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113820. };
  113821. static long _vq_quantmap__8c1_s_p9_1[] = {
  113822. 13, 11, 9, 7, 5, 3, 1, 0,
  113823. 2, 4, 6, 8, 10, 12, 14,
  113824. };
  113825. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113826. _vq_quantthresh__8c1_s_p9_1,
  113827. _vq_quantmap__8c1_s_p9_1,
  113828. 15,
  113829. 15
  113830. };
  113831. static static_codebook _8c1_s_p9_1 = {
  113832. 2, 225,
  113833. _vq_lengthlist__8c1_s_p9_1,
  113834. 1, -520986624, 1620377600, 4, 0,
  113835. _vq_quantlist__8c1_s_p9_1,
  113836. NULL,
  113837. &_vq_auxt__8c1_s_p9_1,
  113838. NULL,
  113839. 0
  113840. };
  113841. static long _vq_quantlist__8c1_s_p9_2[] = {
  113842. 10,
  113843. 9,
  113844. 11,
  113845. 8,
  113846. 12,
  113847. 7,
  113848. 13,
  113849. 6,
  113850. 14,
  113851. 5,
  113852. 15,
  113853. 4,
  113854. 16,
  113855. 3,
  113856. 17,
  113857. 2,
  113858. 18,
  113859. 1,
  113860. 19,
  113861. 0,
  113862. 20,
  113863. };
  113864. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113865. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113866. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113867. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113868. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113869. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113870. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113871. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113872. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113873. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113874. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113875. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113876. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113877. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113878. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113879. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113880. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113881. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113882. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113883. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113884. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113885. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113886. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113887. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113888. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113889. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113890. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113891. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113892. 10,10,10,10,10,10,10,10,10,
  113893. };
  113894. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113895. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113896. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113897. 6.5, 7.5, 8.5, 9.5,
  113898. };
  113899. static long _vq_quantmap__8c1_s_p9_2[] = {
  113900. 19, 17, 15, 13, 11, 9, 7, 5,
  113901. 3, 1, 0, 2, 4, 6, 8, 10,
  113902. 12, 14, 16, 18, 20,
  113903. };
  113904. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113905. _vq_quantthresh__8c1_s_p9_2,
  113906. _vq_quantmap__8c1_s_p9_2,
  113907. 21,
  113908. 21
  113909. };
  113910. static static_codebook _8c1_s_p9_2 = {
  113911. 2, 441,
  113912. _vq_lengthlist__8c1_s_p9_2,
  113913. 1, -529268736, 1611661312, 5, 0,
  113914. _vq_quantlist__8c1_s_p9_2,
  113915. NULL,
  113916. &_vq_auxt__8c1_s_p9_2,
  113917. NULL,
  113918. 0
  113919. };
  113920. static long _huff_lengthlist__8c1_s_single[] = {
  113921. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113922. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113923. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113924. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113925. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113926. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113927. 9, 7, 7, 8,
  113928. };
  113929. static static_codebook _huff_book__8c1_s_single = {
  113930. 2, 100,
  113931. _huff_lengthlist__8c1_s_single,
  113932. 0, 0, 0, 0, 0,
  113933. NULL,
  113934. NULL,
  113935. NULL,
  113936. NULL,
  113937. 0
  113938. };
  113939. static long _huff_lengthlist__44c2_s_long[] = {
  113940. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113941. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113942. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113943. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113944. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113945. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113946. 10, 8, 8, 9,
  113947. };
  113948. static static_codebook _huff_book__44c2_s_long = {
  113949. 2, 100,
  113950. _huff_lengthlist__44c2_s_long,
  113951. 0, 0, 0, 0, 0,
  113952. NULL,
  113953. NULL,
  113954. NULL,
  113955. NULL,
  113956. 0
  113957. };
  113958. static long _vq_quantlist__44c2_s_p1_0[] = {
  113959. 1,
  113960. 0,
  113961. 2,
  113962. };
  113963. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113964. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113965. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113970. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113974. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113975. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 7, 0, 0, 0, 0,
  114010. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  114015. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  114020. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114056. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114061. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114066. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114374. 0,
  114375. };
  114376. static float _vq_quantthresh__44c2_s_p1_0[] = {
  114377. -0.5, 0.5,
  114378. };
  114379. static long _vq_quantmap__44c2_s_p1_0[] = {
  114380. 1, 0, 2,
  114381. };
  114382. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  114383. _vq_quantthresh__44c2_s_p1_0,
  114384. _vq_quantmap__44c2_s_p1_0,
  114385. 3,
  114386. 3
  114387. };
  114388. static static_codebook _44c2_s_p1_0 = {
  114389. 8, 6561,
  114390. _vq_lengthlist__44c2_s_p1_0,
  114391. 1, -535822336, 1611661312, 2, 0,
  114392. _vq_quantlist__44c2_s_p1_0,
  114393. NULL,
  114394. &_vq_auxt__44c2_s_p1_0,
  114395. NULL,
  114396. 0
  114397. };
  114398. static long _vq_quantlist__44c2_s_p2_0[] = {
  114399. 2,
  114400. 1,
  114401. 3,
  114402. 0,
  114403. 4,
  114404. };
  114405. static long _vq_lengthlist__44c2_s_p2_0[] = {
  114406. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  114407. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  114408. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  114409. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  114410. 0, 0, 9, 9, 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, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  114416. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  114417. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  114418. 12, 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, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  114424. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  114425. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114431. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  114432. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  114433. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  114434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114445. 0,
  114446. };
  114447. static float _vq_quantthresh__44c2_s_p2_0[] = {
  114448. -1.5, -0.5, 0.5, 1.5,
  114449. };
  114450. static long _vq_quantmap__44c2_s_p2_0[] = {
  114451. 3, 1, 0, 2, 4,
  114452. };
  114453. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  114454. _vq_quantthresh__44c2_s_p2_0,
  114455. _vq_quantmap__44c2_s_p2_0,
  114456. 5,
  114457. 5
  114458. };
  114459. static static_codebook _44c2_s_p2_0 = {
  114460. 4, 625,
  114461. _vq_lengthlist__44c2_s_p2_0,
  114462. 1, -533725184, 1611661312, 3, 0,
  114463. _vq_quantlist__44c2_s_p2_0,
  114464. NULL,
  114465. &_vq_auxt__44c2_s_p2_0,
  114466. NULL,
  114467. 0
  114468. };
  114469. static long _vq_quantlist__44c2_s_p3_0[] = {
  114470. 2,
  114471. 1,
  114472. 3,
  114473. 0,
  114474. 4,
  114475. };
  114476. static long _vq_lengthlist__44c2_s_p3_0[] = {
  114477. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114480. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114483. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114516. 0,
  114517. };
  114518. static float _vq_quantthresh__44c2_s_p3_0[] = {
  114519. -1.5, -0.5, 0.5, 1.5,
  114520. };
  114521. static long _vq_quantmap__44c2_s_p3_0[] = {
  114522. 3, 1, 0, 2, 4,
  114523. };
  114524. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  114525. _vq_quantthresh__44c2_s_p3_0,
  114526. _vq_quantmap__44c2_s_p3_0,
  114527. 5,
  114528. 5
  114529. };
  114530. static static_codebook _44c2_s_p3_0 = {
  114531. 4, 625,
  114532. _vq_lengthlist__44c2_s_p3_0,
  114533. 1, -533725184, 1611661312, 3, 0,
  114534. _vq_quantlist__44c2_s_p3_0,
  114535. NULL,
  114536. &_vq_auxt__44c2_s_p3_0,
  114537. NULL,
  114538. 0
  114539. };
  114540. static long _vq_quantlist__44c2_s_p4_0[] = {
  114541. 4,
  114542. 3,
  114543. 5,
  114544. 2,
  114545. 6,
  114546. 1,
  114547. 7,
  114548. 0,
  114549. 8,
  114550. };
  114551. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114552. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114553. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114554. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114555. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114556. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114557. 0,
  114558. };
  114559. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114560. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114561. };
  114562. static long _vq_quantmap__44c2_s_p4_0[] = {
  114563. 7, 5, 3, 1, 0, 2, 4, 6,
  114564. 8,
  114565. };
  114566. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114567. _vq_quantthresh__44c2_s_p4_0,
  114568. _vq_quantmap__44c2_s_p4_0,
  114569. 9,
  114570. 9
  114571. };
  114572. static static_codebook _44c2_s_p4_0 = {
  114573. 2, 81,
  114574. _vq_lengthlist__44c2_s_p4_0,
  114575. 1, -531628032, 1611661312, 4, 0,
  114576. _vq_quantlist__44c2_s_p4_0,
  114577. NULL,
  114578. &_vq_auxt__44c2_s_p4_0,
  114579. NULL,
  114580. 0
  114581. };
  114582. static long _vq_quantlist__44c2_s_p5_0[] = {
  114583. 4,
  114584. 3,
  114585. 5,
  114586. 2,
  114587. 6,
  114588. 1,
  114589. 7,
  114590. 0,
  114591. 8,
  114592. };
  114593. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114594. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114595. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114596. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114597. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114598. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114599. 11,
  114600. };
  114601. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114602. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114603. };
  114604. static long _vq_quantmap__44c2_s_p5_0[] = {
  114605. 7, 5, 3, 1, 0, 2, 4, 6,
  114606. 8,
  114607. };
  114608. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114609. _vq_quantthresh__44c2_s_p5_0,
  114610. _vq_quantmap__44c2_s_p5_0,
  114611. 9,
  114612. 9
  114613. };
  114614. static static_codebook _44c2_s_p5_0 = {
  114615. 2, 81,
  114616. _vq_lengthlist__44c2_s_p5_0,
  114617. 1, -531628032, 1611661312, 4, 0,
  114618. _vq_quantlist__44c2_s_p5_0,
  114619. NULL,
  114620. &_vq_auxt__44c2_s_p5_0,
  114621. NULL,
  114622. 0
  114623. };
  114624. static long _vq_quantlist__44c2_s_p6_0[] = {
  114625. 8,
  114626. 7,
  114627. 9,
  114628. 6,
  114629. 10,
  114630. 5,
  114631. 11,
  114632. 4,
  114633. 12,
  114634. 3,
  114635. 13,
  114636. 2,
  114637. 14,
  114638. 1,
  114639. 15,
  114640. 0,
  114641. 16,
  114642. };
  114643. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114644. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114645. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114646. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114647. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114648. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114649. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114650. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114651. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114652. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114653. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114654. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114655. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114656. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114657. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114658. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114659. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114660. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114661. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114662. 14,
  114663. };
  114664. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114665. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114666. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114667. };
  114668. static long _vq_quantmap__44c2_s_p6_0[] = {
  114669. 15, 13, 11, 9, 7, 5, 3, 1,
  114670. 0, 2, 4, 6, 8, 10, 12, 14,
  114671. 16,
  114672. };
  114673. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114674. _vq_quantthresh__44c2_s_p6_0,
  114675. _vq_quantmap__44c2_s_p6_0,
  114676. 17,
  114677. 17
  114678. };
  114679. static static_codebook _44c2_s_p6_0 = {
  114680. 2, 289,
  114681. _vq_lengthlist__44c2_s_p6_0,
  114682. 1, -529530880, 1611661312, 5, 0,
  114683. _vq_quantlist__44c2_s_p6_0,
  114684. NULL,
  114685. &_vq_auxt__44c2_s_p6_0,
  114686. NULL,
  114687. 0
  114688. };
  114689. static long _vq_quantlist__44c2_s_p7_0[] = {
  114690. 1,
  114691. 0,
  114692. 2,
  114693. };
  114694. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114695. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114696. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114697. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114698. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114699. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114700. 11,
  114701. };
  114702. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114703. -5.5, 5.5,
  114704. };
  114705. static long _vq_quantmap__44c2_s_p7_0[] = {
  114706. 1, 0, 2,
  114707. };
  114708. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114709. _vq_quantthresh__44c2_s_p7_0,
  114710. _vq_quantmap__44c2_s_p7_0,
  114711. 3,
  114712. 3
  114713. };
  114714. static static_codebook _44c2_s_p7_0 = {
  114715. 4, 81,
  114716. _vq_lengthlist__44c2_s_p7_0,
  114717. 1, -529137664, 1618345984, 2, 0,
  114718. _vq_quantlist__44c2_s_p7_0,
  114719. NULL,
  114720. &_vq_auxt__44c2_s_p7_0,
  114721. NULL,
  114722. 0
  114723. };
  114724. static long _vq_quantlist__44c2_s_p7_1[] = {
  114725. 5,
  114726. 4,
  114727. 6,
  114728. 3,
  114729. 7,
  114730. 2,
  114731. 8,
  114732. 1,
  114733. 9,
  114734. 0,
  114735. 10,
  114736. };
  114737. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114738. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114739. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114740. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114741. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114742. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114743. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114744. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114745. 10,10,10, 8, 8, 8, 8, 8, 8,
  114746. };
  114747. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114748. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114749. 3.5, 4.5,
  114750. };
  114751. static long _vq_quantmap__44c2_s_p7_1[] = {
  114752. 9, 7, 5, 3, 1, 0, 2, 4,
  114753. 6, 8, 10,
  114754. };
  114755. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114756. _vq_quantthresh__44c2_s_p7_1,
  114757. _vq_quantmap__44c2_s_p7_1,
  114758. 11,
  114759. 11
  114760. };
  114761. static static_codebook _44c2_s_p7_1 = {
  114762. 2, 121,
  114763. _vq_lengthlist__44c2_s_p7_1,
  114764. 1, -531365888, 1611661312, 4, 0,
  114765. _vq_quantlist__44c2_s_p7_1,
  114766. NULL,
  114767. &_vq_auxt__44c2_s_p7_1,
  114768. NULL,
  114769. 0
  114770. };
  114771. static long _vq_quantlist__44c2_s_p8_0[] = {
  114772. 6,
  114773. 5,
  114774. 7,
  114775. 4,
  114776. 8,
  114777. 3,
  114778. 9,
  114779. 2,
  114780. 10,
  114781. 1,
  114782. 11,
  114783. 0,
  114784. 12,
  114785. };
  114786. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114787. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114788. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114789. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114790. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114791. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114792. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114793. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114794. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114795. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114796. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114797. 0,12,12,12,12,13,12,14,14,
  114798. };
  114799. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114800. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114801. 12.5, 17.5, 22.5, 27.5,
  114802. };
  114803. static long _vq_quantmap__44c2_s_p8_0[] = {
  114804. 11, 9, 7, 5, 3, 1, 0, 2,
  114805. 4, 6, 8, 10, 12,
  114806. };
  114807. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114808. _vq_quantthresh__44c2_s_p8_0,
  114809. _vq_quantmap__44c2_s_p8_0,
  114810. 13,
  114811. 13
  114812. };
  114813. static static_codebook _44c2_s_p8_0 = {
  114814. 2, 169,
  114815. _vq_lengthlist__44c2_s_p8_0,
  114816. 1, -526516224, 1616117760, 4, 0,
  114817. _vq_quantlist__44c2_s_p8_0,
  114818. NULL,
  114819. &_vq_auxt__44c2_s_p8_0,
  114820. NULL,
  114821. 0
  114822. };
  114823. static long _vq_quantlist__44c2_s_p8_1[] = {
  114824. 2,
  114825. 1,
  114826. 3,
  114827. 0,
  114828. 4,
  114829. };
  114830. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114831. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114832. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114833. };
  114834. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114835. -1.5, -0.5, 0.5, 1.5,
  114836. };
  114837. static long _vq_quantmap__44c2_s_p8_1[] = {
  114838. 3, 1, 0, 2, 4,
  114839. };
  114840. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114841. _vq_quantthresh__44c2_s_p8_1,
  114842. _vq_quantmap__44c2_s_p8_1,
  114843. 5,
  114844. 5
  114845. };
  114846. static static_codebook _44c2_s_p8_1 = {
  114847. 2, 25,
  114848. _vq_lengthlist__44c2_s_p8_1,
  114849. 1, -533725184, 1611661312, 3, 0,
  114850. _vq_quantlist__44c2_s_p8_1,
  114851. NULL,
  114852. &_vq_auxt__44c2_s_p8_1,
  114853. NULL,
  114854. 0
  114855. };
  114856. static long _vq_quantlist__44c2_s_p9_0[] = {
  114857. 6,
  114858. 5,
  114859. 7,
  114860. 4,
  114861. 8,
  114862. 3,
  114863. 9,
  114864. 2,
  114865. 10,
  114866. 1,
  114867. 11,
  114868. 0,
  114869. 12,
  114870. };
  114871. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114872. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114873. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114874. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114875. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114876. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114877. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114878. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114879. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114880. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114881. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114882. 11,11,11,11,11,11,11,11,11,
  114883. };
  114884. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114885. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114886. 552.5, 773.5, 994.5, 1215.5,
  114887. };
  114888. static long _vq_quantmap__44c2_s_p9_0[] = {
  114889. 11, 9, 7, 5, 3, 1, 0, 2,
  114890. 4, 6, 8, 10, 12,
  114891. };
  114892. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114893. _vq_quantthresh__44c2_s_p9_0,
  114894. _vq_quantmap__44c2_s_p9_0,
  114895. 13,
  114896. 13
  114897. };
  114898. static static_codebook _44c2_s_p9_0 = {
  114899. 2, 169,
  114900. _vq_lengthlist__44c2_s_p9_0,
  114901. 1, -514541568, 1627103232, 4, 0,
  114902. _vq_quantlist__44c2_s_p9_0,
  114903. NULL,
  114904. &_vq_auxt__44c2_s_p9_0,
  114905. NULL,
  114906. 0
  114907. };
  114908. static long _vq_quantlist__44c2_s_p9_1[] = {
  114909. 6,
  114910. 5,
  114911. 7,
  114912. 4,
  114913. 8,
  114914. 3,
  114915. 9,
  114916. 2,
  114917. 10,
  114918. 1,
  114919. 11,
  114920. 0,
  114921. 12,
  114922. };
  114923. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114924. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114925. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114926. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114927. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114928. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114929. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114930. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114931. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114932. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114933. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114934. 17,13,12,12,10,13,11,14,14,
  114935. };
  114936. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114937. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114938. 42.5, 59.5, 76.5, 93.5,
  114939. };
  114940. static long _vq_quantmap__44c2_s_p9_1[] = {
  114941. 11, 9, 7, 5, 3, 1, 0, 2,
  114942. 4, 6, 8, 10, 12,
  114943. };
  114944. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114945. _vq_quantthresh__44c2_s_p9_1,
  114946. _vq_quantmap__44c2_s_p9_1,
  114947. 13,
  114948. 13
  114949. };
  114950. static static_codebook _44c2_s_p9_1 = {
  114951. 2, 169,
  114952. _vq_lengthlist__44c2_s_p9_1,
  114953. 1, -522616832, 1620115456, 4, 0,
  114954. _vq_quantlist__44c2_s_p9_1,
  114955. NULL,
  114956. &_vq_auxt__44c2_s_p9_1,
  114957. NULL,
  114958. 0
  114959. };
  114960. static long _vq_quantlist__44c2_s_p9_2[] = {
  114961. 8,
  114962. 7,
  114963. 9,
  114964. 6,
  114965. 10,
  114966. 5,
  114967. 11,
  114968. 4,
  114969. 12,
  114970. 3,
  114971. 13,
  114972. 2,
  114973. 14,
  114974. 1,
  114975. 15,
  114976. 0,
  114977. 16,
  114978. };
  114979. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114980. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114981. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114982. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114983. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114984. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114985. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114986. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114987. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114988. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114989. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114990. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114991. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114992. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114993. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114994. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114995. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114996. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114997. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114998. 10,
  114999. };
  115000. static float _vq_quantthresh__44c2_s_p9_2[] = {
  115001. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115002. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115003. };
  115004. static long _vq_quantmap__44c2_s_p9_2[] = {
  115005. 15, 13, 11, 9, 7, 5, 3, 1,
  115006. 0, 2, 4, 6, 8, 10, 12, 14,
  115007. 16,
  115008. };
  115009. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  115010. _vq_quantthresh__44c2_s_p9_2,
  115011. _vq_quantmap__44c2_s_p9_2,
  115012. 17,
  115013. 17
  115014. };
  115015. static static_codebook _44c2_s_p9_2 = {
  115016. 2, 289,
  115017. _vq_lengthlist__44c2_s_p9_2,
  115018. 1, -529530880, 1611661312, 5, 0,
  115019. _vq_quantlist__44c2_s_p9_2,
  115020. NULL,
  115021. &_vq_auxt__44c2_s_p9_2,
  115022. NULL,
  115023. 0
  115024. };
  115025. static long _huff_lengthlist__44c2_s_short[] = {
  115026. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  115027. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  115028. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  115029. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  115030. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  115031. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  115032. 6, 8, 9,12,
  115033. };
  115034. static static_codebook _huff_book__44c2_s_short = {
  115035. 2, 100,
  115036. _huff_lengthlist__44c2_s_short,
  115037. 0, 0, 0, 0, 0,
  115038. NULL,
  115039. NULL,
  115040. NULL,
  115041. NULL,
  115042. 0
  115043. };
  115044. static long _huff_lengthlist__44c3_s_long[] = {
  115045. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  115046. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  115047. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  115048. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  115049. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  115050. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  115051. 9, 8, 8, 8,
  115052. };
  115053. static static_codebook _huff_book__44c3_s_long = {
  115054. 2, 100,
  115055. _huff_lengthlist__44c3_s_long,
  115056. 0, 0, 0, 0, 0,
  115057. NULL,
  115058. NULL,
  115059. NULL,
  115060. NULL,
  115061. 0
  115062. };
  115063. static long _vq_quantlist__44c3_s_p1_0[] = {
  115064. 1,
  115065. 0,
  115066. 2,
  115067. };
  115068. static long _vq_lengthlist__44c3_s_p1_0[] = {
  115069. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115070. 0, 0, 5, 6, 6, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115075. 0, 0, 0, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115079. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115080. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 7, 0, 0, 0, 0,
  115115. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  115120. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  115125. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115161. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115166. 0, 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115171. 0, 0, 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 0,
  115172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115479. 0,
  115480. };
  115481. static float _vq_quantthresh__44c3_s_p1_0[] = {
  115482. -0.5, 0.5,
  115483. };
  115484. static long _vq_quantmap__44c3_s_p1_0[] = {
  115485. 1, 0, 2,
  115486. };
  115487. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  115488. _vq_quantthresh__44c3_s_p1_0,
  115489. _vq_quantmap__44c3_s_p1_0,
  115490. 3,
  115491. 3
  115492. };
  115493. static static_codebook _44c3_s_p1_0 = {
  115494. 8, 6561,
  115495. _vq_lengthlist__44c3_s_p1_0,
  115496. 1, -535822336, 1611661312, 2, 0,
  115497. _vq_quantlist__44c3_s_p1_0,
  115498. NULL,
  115499. &_vq_auxt__44c3_s_p1_0,
  115500. NULL,
  115501. 0
  115502. };
  115503. static long _vq_quantlist__44c3_s_p2_0[] = {
  115504. 2,
  115505. 1,
  115506. 3,
  115507. 0,
  115508. 4,
  115509. };
  115510. static long _vq_lengthlist__44c3_s_p2_0[] = {
  115511. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115512. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115513. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115514. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115515. 0, 0,10,10, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  115521. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115522. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115523. 9, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115529. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115530. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115536. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115537. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115538. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115550. 0,
  115551. };
  115552. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115553. -1.5, -0.5, 0.5, 1.5,
  115554. };
  115555. static long _vq_quantmap__44c3_s_p2_0[] = {
  115556. 3, 1, 0, 2, 4,
  115557. };
  115558. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115559. _vq_quantthresh__44c3_s_p2_0,
  115560. _vq_quantmap__44c3_s_p2_0,
  115561. 5,
  115562. 5
  115563. };
  115564. static static_codebook _44c3_s_p2_0 = {
  115565. 4, 625,
  115566. _vq_lengthlist__44c3_s_p2_0,
  115567. 1, -533725184, 1611661312, 3, 0,
  115568. _vq_quantlist__44c3_s_p2_0,
  115569. NULL,
  115570. &_vq_auxt__44c3_s_p2_0,
  115571. NULL,
  115572. 0
  115573. };
  115574. static long _vq_quantlist__44c3_s_p3_0[] = {
  115575. 2,
  115576. 1,
  115577. 3,
  115578. 0,
  115579. 4,
  115580. };
  115581. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115582. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115585. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115588. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115621. 0,
  115622. };
  115623. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115624. -1.5, -0.5, 0.5, 1.5,
  115625. };
  115626. static long _vq_quantmap__44c3_s_p3_0[] = {
  115627. 3, 1, 0, 2, 4,
  115628. };
  115629. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115630. _vq_quantthresh__44c3_s_p3_0,
  115631. _vq_quantmap__44c3_s_p3_0,
  115632. 5,
  115633. 5
  115634. };
  115635. static static_codebook _44c3_s_p3_0 = {
  115636. 4, 625,
  115637. _vq_lengthlist__44c3_s_p3_0,
  115638. 1, -533725184, 1611661312, 3, 0,
  115639. _vq_quantlist__44c3_s_p3_0,
  115640. NULL,
  115641. &_vq_auxt__44c3_s_p3_0,
  115642. NULL,
  115643. 0
  115644. };
  115645. static long _vq_quantlist__44c3_s_p4_0[] = {
  115646. 4,
  115647. 3,
  115648. 5,
  115649. 2,
  115650. 6,
  115651. 1,
  115652. 7,
  115653. 0,
  115654. 8,
  115655. };
  115656. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115657. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115658. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115659. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115660. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115661. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115662. 0,
  115663. };
  115664. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115665. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115666. };
  115667. static long _vq_quantmap__44c3_s_p4_0[] = {
  115668. 7, 5, 3, 1, 0, 2, 4, 6,
  115669. 8,
  115670. };
  115671. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115672. _vq_quantthresh__44c3_s_p4_0,
  115673. _vq_quantmap__44c3_s_p4_0,
  115674. 9,
  115675. 9
  115676. };
  115677. static static_codebook _44c3_s_p4_0 = {
  115678. 2, 81,
  115679. _vq_lengthlist__44c3_s_p4_0,
  115680. 1, -531628032, 1611661312, 4, 0,
  115681. _vq_quantlist__44c3_s_p4_0,
  115682. NULL,
  115683. &_vq_auxt__44c3_s_p4_0,
  115684. NULL,
  115685. 0
  115686. };
  115687. static long _vq_quantlist__44c3_s_p5_0[] = {
  115688. 4,
  115689. 3,
  115690. 5,
  115691. 2,
  115692. 6,
  115693. 1,
  115694. 7,
  115695. 0,
  115696. 8,
  115697. };
  115698. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115699. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115700. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115701. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115702. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115703. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115704. 11,
  115705. };
  115706. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115707. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115708. };
  115709. static long _vq_quantmap__44c3_s_p5_0[] = {
  115710. 7, 5, 3, 1, 0, 2, 4, 6,
  115711. 8,
  115712. };
  115713. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115714. _vq_quantthresh__44c3_s_p5_0,
  115715. _vq_quantmap__44c3_s_p5_0,
  115716. 9,
  115717. 9
  115718. };
  115719. static static_codebook _44c3_s_p5_0 = {
  115720. 2, 81,
  115721. _vq_lengthlist__44c3_s_p5_0,
  115722. 1, -531628032, 1611661312, 4, 0,
  115723. _vq_quantlist__44c3_s_p5_0,
  115724. NULL,
  115725. &_vq_auxt__44c3_s_p5_0,
  115726. NULL,
  115727. 0
  115728. };
  115729. static long _vq_quantlist__44c3_s_p6_0[] = {
  115730. 8,
  115731. 7,
  115732. 9,
  115733. 6,
  115734. 10,
  115735. 5,
  115736. 11,
  115737. 4,
  115738. 12,
  115739. 3,
  115740. 13,
  115741. 2,
  115742. 14,
  115743. 1,
  115744. 15,
  115745. 0,
  115746. 16,
  115747. };
  115748. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115749. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115750. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115751. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115752. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115753. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115754. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115755. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115756. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115757. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115758. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115759. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115760. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115761. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115762. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115763. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115764. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115765. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115766. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115767. 13,
  115768. };
  115769. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115770. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115771. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115772. };
  115773. static long _vq_quantmap__44c3_s_p6_0[] = {
  115774. 15, 13, 11, 9, 7, 5, 3, 1,
  115775. 0, 2, 4, 6, 8, 10, 12, 14,
  115776. 16,
  115777. };
  115778. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115779. _vq_quantthresh__44c3_s_p6_0,
  115780. _vq_quantmap__44c3_s_p6_0,
  115781. 17,
  115782. 17
  115783. };
  115784. static static_codebook _44c3_s_p6_0 = {
  115785. 2, 289,
  115786. _vq_lengthlist__44c3_s_p6_0,
  115787. 1, -529530880, 1611661312, 5, 0,
  115788. _vq_quantlist__44c3_s_p6_0,
  115789. NULL,
  115790. &_vq_auxt__44c3_s_p6_0,
  115791. NULL,
  115792. 0
  115793. };
  115794. static long _vq_quantlist__44c3_s_p7_0[] = {
  115795. 1,
  115796. 0,
  115797. 2,
  115798. };
  115799. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115800. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115801. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115802. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115803. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115804. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115805. 10,
  115806. };
  115807. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115808. -5.5, 5.5,
  115809. };
  115810. static long _vq_quantmap__44c3_s_p7_0[] = {
  115811. 1, 0, 2,
  115812. };
  115813. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115814. _vq_quantthresh__44c3_s_p7_0,
  115815. _vq_quantmap__44c3_s_p7_0,
  115816. 3,
  115817. 3
  115818. };
  115819. static static_codebook _44c3_s_p7_0 = {
  115820. 4, 81,
  115821. _vq_lengthlist__44c3_s_p7_0,
  115822. 1, -529137664, 1618345984, 2, 0,
  115823. _vq_quantlist__44c3_s_p7_0,
  115824. NULL,
  115825. &_vq_auxt__44c3_s_p7_0,
  115826. NULL,
  115827. 0
  115828. };
  115829. static long _vq_quantlist__44c3_s_p7_1[] = {
  115830. 5,
  115831. 4,
  115832. 6,
  115833. 3,
  115834. 7,
  115835. 2,
  115836. 8,
  115837. 1,
  115838. 9,
  115839. 0,
  115840. 10,
  115841. };
  115842. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115843. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115844. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115845. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115846. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115847. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115848. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115849. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115850. 10,10,10, 8, 8, 8, 8, 8, 8,
  115851. };
  115852. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115853. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115854. 3.5, 4.5,
  115855. };
  115856. static long _vq_quantmap__44c3_s_p7_1[] = {
  115857. 9, 7, 5, 3, 1, 0, 2, 4,
  115858. 6, 8, 10,
  115859. };
  115860. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115861. _vq_quantthresh__44c3_s_p7_1,
  115862. _vq_quantmap__44c3_s_p7_1,
  115863. 11,
  115864. 11
  115865. };
  115866. static static_codebook _44c3_s_p7_1 = {
  115867. 2, 121,
  115868. _vq_lengthlist__44c3_s_p7_1,
  115869. 1, -531365888, 1611661312, 4, 0,
  115870. _vq_quantlist__44c3_s_p7_1,
  115871. NULL,
  115872. &_vq_auxt__44c3_s_p7_1,
  115873. NULL,
  115874. 0
  115875. };
  115876. static long _vq_quantlist__44c3_s_p8_0[] = {
  115877. 6,
  115878. 5,
  115879. 7,
  115880. 4,
  115881. 8,
  115882. 3,
  115883. 9,
  115884. 2,
  115885. 10,
  115886. 1,
  115887. 11,
  115888. 0,
  115889. 12,
  115890. };
  115891. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115892. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115893. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115894. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115895. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115896. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115897. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115898. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115899. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115900. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115901. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115902. 0,13,13,12,12,13,12,14,13,
  115903. };
  115904. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115905. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115906. 12.5, 17.5, 22.5, 27.5,
  115907. };
  115908. static long _vq_quantmap__44c3_s_p8_0[] = {
  115909. 11, 9, 7, 5, 3, 1, 0, 2,
  115910. 4, 6, 8, 10, 12,
  115911. };
  115912. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115913. _vq_quantthresh__44c3_s_p8_0,
  115914. _vq_quantmap__44c3_s_p8_0,
  115915. 13,
  115916. 13
  115917. };
  115918. static static_codebook _44c3_s_p8_0 = {
  115919. 2, 169,
  115920. _vq_lengthlist__44c3_s_p8_0,
  115921. 1, -526516224, 1616117760, 4, 0,
  115922. _vq_quantlist__44c3_s_p8_0,
  115923. NULL,
  115924. &_vq_auxt__44c3_s_p8_0,
  115925. NULL,
  115926. 0
  115927. };
  115928. static long _vq_quantlist__44c3_s_p8_1[] = {
  115929. 2,
  115930. 1,
  115931. 3,
  115932. 0,
  115933. 4,
  115934. };
  115935. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115936. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115937. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115938. };
  115939. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115940. -1.5, -0.5, 0.5, 1.5,
  115941. };
  115942. static long _vq_quantmap__44c3_s_p8_1[] = {
  115943. 3, 1, 0, 2, 4,
  115944. };
  115945. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115946. _vq_quantthresh__44c3_s_p8_1,
  115947. _vq_quantmap__44c3_s_p8_1,
  115948. 5,
  115949. 5
  115950. };
  115951. static static_codebook _44c3_s_p8_1 = {
  115952. 2, 25,
  115953. _vq_lengthlist__44c3_s_p8_1,
  115954. 1, -533725184, 1611661312, 3, 0,
  115955. _vq_quantlist__44c3_s_p8_1,
  115956. NULL,
  115957. &_vq_auxt__44c3_s_p8_1,
  115958. NULL,
  115959. 0
  115960. };
  115961. static long _vq_quantlist__44c3_s_p9_0[] = {
  115962. 6,
  115963. 5,
  115964. 7,
  115965. 4,
  115966. 8,
  115967. 3,
  115968. 9,
  115969. 2,
  115970. 10,
  115971. 1,
  115972. 11,
  115973. 0,
  115974. 12,
  115975. };
  115976. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115977. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115978. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115979. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115980. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115981. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115982. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115983. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115984. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115985. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115986. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115987. 11,11,11,11,11,11,11,11,11,
  115988. };
  115989. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115990. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115991. 637.5, 892.5, 1147.5, 1402.5,
  115992. };
  115993. static long _vq_quantmap__44c3_s_p9_0[] = {
  115994. 11, 9, 7, 5, 3, 1, 0, 2,
  115995. 4, 6, 8, 10, 12,
  115996. };
  115997. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115998. _vq_quantthresh__44c3_s_p9_0,
  115999. _vq_quantmap__44c3_s_p9_0,
  116000. 13,
  116001. 13
  116002. };
  116003. static static_codebook _44c3_s_p9_0 = {
  116004. 2, 169,
  116005. _vq_lengthlist__44c3_s_p9_0,
  116006. 1, -514332672, 1627381760, 4, 0,
  116007. _vq_quantlist__44c3_s_p9_0,
  116008. NULL,
  116009. &_vq_auxt__44c3_s_p9_0,
  116010. NULL,
  116011. 0
  116012. };
  116013. static long _vq_quantlist__44c3_s_p9_1[] = {
  116014. 7,
  116015. 6,
  116016. 8,
  116017. 5,
  116018. 9,
  116019. 4,
  116020. 10,
  116021. 3,
  116022. 11,
  116023. 2,
  116024. 12,
  116025. 1,
  116026. 13,
  116027. 0,
  116028. 14,
  116029. };
  116030. static long _vq_lengthlist__44c3_s_p9_1[] = {
  116031. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  116032. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  116033. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  116034. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  116035. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  116036. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  116037. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  116038. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  116039. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  116040. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  116041. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  116042. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  116043. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  116044. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  116045. 15,
  116046. };
  116047. static float _vq_quantthresh__44c3_s_p9_1[] = {
  116048. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  116049. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  116050. };
  116051. static long _vq_quantmap__44c3_s_p9_1[] = {
  116052. 13, 11, 9, 7, 5, 3, 1, 0,
  116053. 2, 4, 6, 8, 10, 12, 14,
  116054. };
  116055. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  116056. _vq_quantthresh__44c3_s_p9_1,
  116057. _vq_quantmap__44c3_s_p9_1,
  116058. 15,
  116059. 15
  116060. };
  116061. static static_codebook _44c3_s_p9_1 = {
  116062. 2, 225,
  116063. _vq_lengthlist__44c3_s_p9_1,
  116064. 1, -522338304, 1620115456, 4, 0,
  116065. _vq_quantlist__44c3_s_p9_1,
  116066. NULL,
  116067. &_vq_auxt__44c3_s_p9_1,
  116068. NULL,
  116069. 0
  116070. };
  116071. static long _vq_quantlist__44c3_s_p9_2[] = {
  116072. 8,
  116073. 7,
  116074. 9,
  116075. 6,
  116076. 10,
  116077. 5,
  116078. 11,
  116079. 4,
  116080. 12,
  116081. 3,
  116082. 13,
  116083. 2,
  116084. 14,
  116085. 1,
  116086. 15,
  116087. 0,
  116088. 16,
  116089. };
  116090. static long _vq_lengthlist__44c3_s_p9_2[] = {
  116091. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  116092. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  116093. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  116094. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  116095. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  116096. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  116097. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  116098. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  116099. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  116100. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  116101. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  116102. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  116103. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  116104. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  116105. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  116106. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  116107. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  116108. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  116109. 10,
  116110. };
  116111. static float _vq_quantthresh__44c3_s_p9_2[] = {
  116112. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116113. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116114. };
  116115. static long _vq_quantmap__44c3_s_p9_2[] = {
  116116. 15, 13, 11, 9, 7, 5, 3, 1,
  116117. 0, 2, 4, 6, 8, 10, 12, 14,
  116118. 16,
  116119. };
  116120. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  116121. _vq_quantthresh__44c3_s_p9_2,
  116122. _vq_quantmap__44c3_s_p9_2,
  116123. 17,
  116124. 17
  116125. };
  116126. static static_codebook _44c3_s_p9_2 = {
  116127. 2, 289,
  116128. _vq_lengthlist__44c3_s_p9_2,
  116129. 1, -529530880, 1611661312, 5, 0,
  116130. _vq_quantlist__44c3_s_p9_2,
  116131. NULL,
  116132. &_vq_auxt__44c3_s_p9_2,
  116133. NULL,
  116134. 0
  116135. };
  116136. static long _huff_lengthlist__44c3_s_short[] = {
  116137. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  116138. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  116139. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  116140. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  116141. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  116142. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  116143. 6, 8, 9,11,
  116144. };
  116145. static static_codebook _huff_book__44c3_s_short = {
  116146. 2, 100,
  116147. _huff_lengthlist__44c3_s_short,
  116148. 0, 0, 0, 0, 0,
  116149. NULL,
  116150. NULL,
  116151. NULL,
  116152. NULL,
  116153. 0
  116154. };
  116155. static long _huff_lengthlist__44c4_s_long[] = {
  116156. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  116157. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  116158. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  116159. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  116160. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  116161. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  116162. 9, 8, 7, 7,
  116163. };
  116164. static static_codebook _huff_book__44c4_s_long = {
  116165. 2, 100,
  116166. _huff_lengthlist__44c4_s_long,
  116167. 0, 0, 0, 0, 0,
  116168. NULL,
  116169. NULL,
  116170. NULL,
  116171. NULL,
  116172. 0
  116173. };
  116174. static long _vq_quantlist__44c4_s_p1_0[] = {
  116175. 1,
  116176. 0,
  116177. 2,
  116178. };
  116179. static long _vq_lengthlist__44c4_s_p1_0[] = {
  116180. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  116181. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  116186. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116190. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  116191. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 7, 0, 0, 0, 0,
  116226. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  116231. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  116236. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  116272. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  116277. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  116282. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116590. 0,
  116591. };
  116592. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116593. -0.5, 0.5,
  116594. };
  116595. static long _vq_quantmap__44c4_s_p1_0[] = {
  116596. 1, 0, 2,
  116597. };
  116598. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116599. _vq_quantthresh__44c4_s_p1_0,
  116600. _vq_quantmap__44c4_s_p1_0,
  116601. 3,
  116602. 3
  116603. };
  116604. static static_codebook _44c4_s_p1_0 = {
  116605. 8, 6561,
  116606. _vq_lengthlist__44c4_s_p1_0,
  116607. 1, -535822336, 1611661312, 2, 0,
  116608. _vq_quantlist__44c4_s_p1_0,
  116609. NULL,
  116610. &_vq_auxt__44c4_s_p1_0,
  116611. NULL,
  116612. 0
  116613. };
  116614. static long _vq_quantlist__44c4_s_p2_0[] = {
  116615. 2,
  116616. 1,
  116617. 3,
  116618. 0,
  116619. 4,
  116620. };
  116621. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116622. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116623. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116624. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116625. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116626. 0, 0,10,10, 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, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116632. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116633. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116634. 9, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116640. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116641. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116647. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116648. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116649. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116661. 0,
  116662. };
  116663. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116664. -1.5, -0.5, 0.5, 1.5,
  116665. };
  116666. static long _vq_quantmap__44c4_s_p2_0[] = {
  116667. 3, 1, 0, 2, 4,
  116668. };
  116669. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116670. _vq_quantthresh__44c4_s_p2_0,
  116671. _vq_quantmap__44c4_s_p2_0,
  116672. 5,
  116673. 5
  116674. };
  116675. static static_codebook _44c4_s_p2_0 = {
  116676. 4, 625,
  116677. _vq_lengthlist__44c4_s_p2_0,
  116678. 1, -533725184, 1611661312, 3, 0,
  116679. _vq_quantlist__44c4_s_p2_0,
  116680. NULL,
  116681. &_vq_auxt__44c4_s_p2_0,
  116682. NULL,
  116683. 0
  116684. };
  116685. static long _vq_quantlist__44c4_s_p3_0[] = {
  116686. 2,
  116687. 1,
  116688. 3,
  116689. 0,
  116690. 4,
  116691. };
  116692. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116693. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116696. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116699. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116732. 0,
  116733. };
  116734. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116735. -1.5, -0.5, 0.5, 1.5,
  116736. };
  116737. static long _vq_quantmap__44c4_s_p3_0[] = {
  116738. 3, 1, 0, 2, 4,
  116739. };
  116740. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116741. _vq_quantthresh__44c4_s_p3_0,
  116742. _vq_quantmap__44c4_s_p3_0,
  116743. 5,
  116744. 5
  116745. };
  116746. static static_codebook _44c4_s_p3_0 = {
  116747. 4, 625,
  116748. _vq_lengthlist__44c4_s_p3_0,
  116749. 1, -533725184, 1611661312, 3, 0,
  116750. _vq_quantlist__44c4_s_p3_0,
  116751. NULL,
  116752. &_vq_auxt__44c4_s_p3_0,
  116753. NULL,
  116754. 0
  116755. };
  116756. static long _vq_quantlist__44c4_s_p4_0[] = {
  116757. 4,
  116758. 3,
  116759. 5,
  116760. 2,
  116761. 6,
  116762. 1,
  116763. 7,
  116764. 0,
  116765. 8,
  116766. };
  116767. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116768. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116769. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116770. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116771. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116772. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116773. 0,
  116774. };
  116775. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116776. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116777. };
  116778. static long _vq_quantmap__44c4_s_p4_0[] = {
  116779. 7, 5, 3, 1, 0, 2, 4, 6,
  116780. 8,
  116781. };
  116782. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116783. _vq_quantthresh__44c4_s_p4_0,
  116784. _vq_quantmap__44c4_s_p4_0,
  116785. 9,
  116786. 9
  116787. };
  116788. static static_codebook _44c4_s_p4_0 = {
  116789. 2, 81,
  116790. _vq_lengthlist__44c4_s_p4_0,
  116791. 1, -531628032, 1611661312, 4, 0,
  116792. _vq_quantlist__44c4_s_p4_0,
  116793. NULL,
  116794. &_vq_auxt__44c4_s_p4_0,
  116795. NULL,
  116796. 0
  116797. };
  116798. static long _vq_quantlist__44c4_s_p5_0[] = {
  116799. 4,
  116800. 3,
  116801. 5,
  116802. 2,
  116803. 6,
  116804. 1,
  116805. 7,
  116806. 0,
  116807. 8,
  116808. };
  116809. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116810. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116811. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116812. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116813. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116814. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116815. 10,
  116816. };
  116817. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116818. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116819. };
  116820. static long _vq_quantmap__44c4_s_p5_0[] = {
  116821. 7, 5, 3, 1, 0, 2, 4, 6,
  116822. 8,
  116823. };
  116824. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116825. _vq_quantthresh__44c4_s_p5_0,
  116826. _vq_quantmap__44c4_s_p5_0,
  116827. 9,
  116828. 9
  116829. };
  116830. static static_codebook _44c4_s_p5_0 = {
  116831. 2, 81,
  116832. _vq_lengthlist__44c4_s_p5_0,
  116833. 1, -531628032, 1611661312, 4, 0,
  116834. _vq_quantlist__44c4_s_p5_0,
  116835. NULL,
  116836. &_vq_auxt__44c4_s_p5_0,
  116837. NULL,
  116838. 0
  116839. };
  116840. static long _vq_quantlist__44c4_s_p6_0[] = {
  116841. 8,
  116842. 7,
  116843. 9,
  116844. 6,
  116845. 10,
  116846. 5,
  116847. 11,
  116848. 4,
  116849. 12,
  116850. 3,
  116851. 13,
  116852. 2,
  116853. 14,
  116854. 1,
  116855. 15,
  116856. 0,
  116857. 16,
  116858. };
  116859. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116860. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116861. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116862. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116863. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116864. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116865. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116866. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116867. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116868. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116869. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116870. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116871. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116872. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116873. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116874. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116875. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116876. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116877. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116878. 13,
  116879. };
  116880. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116881. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116882. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116883. };
  116884. static long _vq_quantmap__44c4_s_p6_0[] = {
  116885. 15, 13, 11, 9, 7, 5, 3, 1,
  116886. 0, 2, 4, 6, 8, 10, 12, 14,
  116887. 16,
  116888. };
  116889. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116890. _vq_quantthresh__44c4_s_p6_0,
  116891. _vq_quantmap__44c4_s_p6_0,
  116892. 17,
  116893. 17
  116894. };
  116895. static static_codebook _44c4_s_p6_0 = {
  116896. 2, 289,
  116897. _vq_lengthlist__44c4_s_p6_0,
  116898. 1, -529530880, 1611661312, 5, 0,
  116899. _vq_quantlist__44c4_s_p6_0,
  116900. NULL,
  116901. &_vq_auxt__44c4_s_p6_0,
  116902. NULL,
  116903. 0
  116904. };
  116905. static long _vq_quantlist__44c4_s_p7_0[] = {
  116906. 1,
  116907. 0,
  116908. 2,
  116909. };
  116910. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116911. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116912. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116913. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116914. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116915. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116916. 10,
  116917. };
  116918. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116919. -5.5, 5.5,
  116920. };
  116921. static long _vq_quantmap__44c4_s_p7_0[] = {
  116922. 1, 0, 2,
  116923. };
  116924. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116925. _vq_quantthresh__44c4_s_p7_0,
  116926. _vq_quantmap__44c4_s_p7_0,
  116927. 3,
  116928. 3
  116929. };
  116930. static static_codebook _44c4_s_p7_0 = {
  116931. 4, 81,
  116932. _vq_lengthlist__44c4_s_p7_0,
  116933. 1, -529137664, 1618345984, 2, 0,
  116934. _vq_quantlist__44c4_s_p7_0,
  116935. NULL,
  116936. &_vq_auxt__44c4_s_p7_0,
  116937. NULL,
  116938. 0
  116939. };
  116940. static long _vq_quantlist__44c4_s_p7_1[] = {
  116941. 5,
  116942. 4,
  116943. 6,
  116944. 3,
  116945. 7,
  116946. 2,
  116947. 8,
  116948. 1,
  116949. 9,
  116950. 0,
  116951. 10,
  116952. };
  116953. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116954. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116955. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116956. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116957. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116958. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116959. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116960. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116961. 10,10,10, 8, 8, 8, 8, 9, 9,
  116962. };
  116963. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116964. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116965. 3.5, 4.5,
  116966. };
  116967. static long _vq_quantmap__44c4_s_p7_1[] = {
  116968. 9, 7, 5, 3, 1, 0, 2, 4,
  116969. 6, 8, 10,
  116970. };
  116971. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116972. _vq_quantthresh__44c4_s_p7_1,
  116973. _vq_quantmap__44c4_s_p7_1,
  116974. 11,
  116975. 11
  116976. };
  116977. static static_codebook _44c4_s_p7_1 = {
  116978. 2, 121,
  116979. _vq_lengthlist__44c4_s_p7_1,
  116980. 1, -531365888, 1611661312, 4, 0,
  116981. _vq_quantlist__44c4_s_p7_1,
  116982. NULL,
  116983. &_vq_auxt__44c4_s_p7_1,
  116984. NULL,
  116985. 0
  116986. };
  116987. static long _vq_quantlist__44c4_s_p8_0[] = {
  116988. 6,
  116989. 5,
  116990. 7,
  116991. 4,
  116992. 8,
  116993. 3,
  116994. 9,
  116995. 2,
  116996. 10,
  116997. 1,
  116998. 11,
  116999. 0,
  117000. 12,
  117001. };
  117002. static long _vq_lengthlist__44c4_s_p8_0[] = {
  117003. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117004. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  117005. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117006. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117007. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  117008. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  117009. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  117010. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117011. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  117012. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117013. 0,13,12,12,12,12,12,13,13,
  117014. };
  117015. static float _vq_quantthresh__44c4_s_p8_0[] = {
  117016. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117017. 12.5, 17.5, 22.5, 27.5,
  117018. };
  117019. static long _vq_quantmap__44c4_s_p8_0[] = {
  117020. 11, 9, 7, 5, 3, 1, 0, 2,
  117021. 4, 6, 8, 10, 12,
  117022. };
  117023. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  117024. _vq_quantthresh__44c4_s_p8_0,
  117025. _vq_quantmap__44c4_s_p8_0,
  117026. 13,
  117027. 13
  117028. };
  117029. static static_codebook _44c4_s_p8_0 = {
  117030. 2, 169,
  117031. _vq_lengthlist__44c4_s_p8_0,
  117032. 1, -526516224, 1616117760, 4, 0,
  117033. _vq_quantlist__44c4_s_p8_0,
  117034. NULL,
  117035. &_vq_auxt__44c4_s_p8_0,
  117036. NULL,
  117037. 0
  117038. };
  117039. static long _vq_quantlist__44c4_s_p8_1[] = {
  117040. 2,
  117041. 1,
  117042. 3,
  117043. 0,
  117044. 4,
  117045. };
  117046. static long _vq_lengthlist__44c4_s_p8_1[] = {
  117047. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  117048. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117049. };
  117050. static float _vq_quantthresh__44c4_s_p8_1[] = {
  117051. -1.5, -0.5, 0.5, 1.5,
  117052. };
  117053. static long _vq_quantmap__44c4_s_p8_1[] = {
  117054. 3, 1, 0, 2, 4,
  117055. };
  117056. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  117057. _vq_quantthresh__44c4_s_p8_1,
  117058. _vq_quantmap__44c4_s_p8_1,
  117059. 5,
  117060. 5
  117061. };
  117062. static static_codebook _44c4_s_p8_1 = {
  117063. 2, 25,
  117064. _vq_lengthlist__44c4_s_p8_1,
  117065. 1, -533725184, 1611661312, 3, 0,
  117066. _vq_quantlist__44c4_s_p8_1,
  117067. NULL,
  117068. &_vq_auxt__44c4_s_p8_1,
  117069. NULL,
  117070. 0
  117071. };
  117072. static long _vq_quantlist__44c4_s_p9_0[] = {
  117073. 6,
  117074. 5,
  117075. 7,
  117076. 4,
  117077. 8,
  117078. 3,
  117079. 9,
  117080. 2,
  117081. 10,
  117082. 1,
  117083. 11,
  117084. 0,
  117085. 12,
  117086. };
  117087. static long _vq_lengthlist__44c4_s_p9_0[] = {
  117088. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  117089. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  117090. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117091. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117092. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117093. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117094. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117095. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117096. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117097. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117098. 12,12,12,12,12,12,12,12,12,
  117099. };
  117100. static float _vq_quantthresh__44c4_s_p9_0[] = {
  117101. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  117102. 787.5, 1102.5, 1417.5, 1732.5,
  117103. };
  117104. static long _vq_quantmap__44c4_s_p9_0[] = {
  117105. 11, 9, 7, 5, 3, 1, 0, 2,
  117106. 4, 6, 8, 10, 12,
  117107. };
  117108. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  117109. _vq_quantthresh__44c4_s_p9_0,
  117110. _vq_quantmap__44c4_s_p9_0,
  117111. 13,
  117112. 13
  117113. };
  117114. static static_codebook _44c4_s_p9_0 = {
  117115. 2, 169,
  117116. _vq_lengthlist__44c4_s_p9_0,
  117117. 1, -513964032, 1628680192, 4, 0,
  117118. _vq_quantlist__44c4_s_p9_0,
  117119. NULL,
  117120. &_vq_auxt__44c4_s_p9_0,
  117121. NULL,
  117122. 0
  117123. };
  117124. static long _vq_quantlist__44c4_s_p9_1[] = {
  117125. 7,
  117126. 6,
  117127. 8,
  117128. 5,
  117129. 9,
  117130. 4,
  117131. 10,
  117132. 3,
  117133. 11,
  117134. 2,
  117135. 12,
  117136. 1,
  117137. 13,
  117138. 0,
  117139. 14,
  117140. };
  117141. static long _vq_lengthlist__44c4_s_p9_1[] = {
  117142. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  117143. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  117144. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  117145. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  117146. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  117147. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  117148. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  117149. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  117150. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  117151. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  117152. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  117153. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  117154. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  117155. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  117156. 15,
  117157. };
  117158. static float _vq_quantthresh__44c4_s_p9_1[] = {
  117159. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  117160. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  117161. };
  117162. static long _vq_quantmap__44c4_s_p9_1[] = {
  117163. 13, 11, 9, 7, 5, 3, 1, 0,
  117164. 2, 4, 6, 8, 10, 12, 14,
  117165. };
  117166. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  117167. _vq_quantthresh__44c4_s_p9_1,
  117168. _vq_quantmap__44c4_s_p9_1,
  117169. 15,
  117170. 15
  117171. };
  117172. static static_codebook _44c4_s_p9_1 = {
  117173. 2, 225,
  117174. _vq_lengthlist__44c4_s_p9_1,
  117175. 1, -520986624, 1620377600, 4, 0,
  117176. _vq_quantlist__44c4_s_p9_1,
  117177. NULL,
  117178. &_vq_auxt__44c4_s_p9_1,
  117179. NULL,
  117180. 0
  117181. };
  117182. static long _vq_quantlist__44c4_s_p9_2[] = {
  117183. 10,
  117184. 9,
  117185. 11,
  117186. 8,
  117187. 12,
  117188. 7,
  117189. 13,
  117190. 6,
  117191. 14,
  117192. 5,
  117193. 15,
  117194. 4,
  117195. 16,
  117196. 3,
  117197. 17,
  117198. 2,
  117199. 18,
  117200. 1,
  117201. 19,
  117202. 0,
  117203. 20,
  117204. };
  117205. static long _vq_lengthlist__44c4_s_p9_2[] = {
  117206. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117207. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  117208. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  117209. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  117210. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  117211. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  117212. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  117213. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  117214. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  117215. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  117216. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117217. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  117218. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117219. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  117220. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  117221. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  117222. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  117223. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117224. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  117225. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  117226. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117227. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117228. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  117229. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  117230. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  117231. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  117232. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  117233. 10,10,10,10,10,10,10,10,10,
  117234. };
  117235. static float _vq_quantthresh__44c4_s_p9_2[] = {
  117236. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117237. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117238. 6.5, 7.5, 8.5, 9.5,
  117239. };
  117240. static long _vq_quantmap__44c4_s_p9_2[] = {
  117241. 19, 17, 15, 13, 11, 9, 7, 5,
  117242. 3, 1, 0, 2, 4, 6, 8, 10,
  117243. 12, 14, 16, 18, 20,
  117244. };
  117245. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  117246. _vq_quantthresh__44c4_s_p9_2,
  117247. _vq_quantmap__44c4_s_p9_2,
  117248. 21,
  117249. 21
  117250. };
  117251. static static_codebook _44c4_s_p9_2 = {
  117252. 2, 441,
  117253. _vq_lengthlist__44c4_s_p9_2,
  117254. 1, -529268736, 1611661312, 5, 0,
  117255. _vq_quantlist__44c4_s_p9_2,
  117256. NULL,
  117257. &_vq_auxt__44c4_s_p9_2,
  117258. NULL,
  117259. 0
  117260. };
  117261. static long _huff_lengthlist__44c4_s_short[] = {
  117262. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  117263. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  117264. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  117265. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  117266. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  117267. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  117268. 7, 9,12,17,
  117269. };
  117270. static static_codebook _huff_book__44c4_s_short = {
  117271. 2, 100,
  117272. _huff_lengthlist__44c4_s_short,
  117273. 0, 0, 0, 0, 0,
  117274. NULL,
  117275. NULL,
  117276. NULL,
  117277. NULL,
  117278. 0
  117279. };
  117280. static long _huff_lengthlist__44c5_s_long[] = {
  117281. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  117282. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  117283. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  117284. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  117285. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  117286. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  117287. 9, 8, 7, 7,
  117288. };
  117289. static static_codebook _huff_book__44c5_s_long = {
  117290. 2, 100,
  117291. _huff_lengthlist__44c5_s_long,
  117292. 0, 0, 0, 0, 0,
  117293. NULL,
  117294. NULL,
  117295. NULL,
  117296. NULL,
  117297. 0
  117298. };
  117299. static long _vq_quantlist__44c5_s_p1_0[] = {
  117300. 1,
  117301. 0,
  117302. 2,
  117303. };
  117304. static long _vq_lengthlist__44c5_s_p1_0[] = {
  117305. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  117306. 0, 0, 4, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  117311. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117315. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  117316. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0,
  117351. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  117356. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  117361. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117397. 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  117402. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  117407. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  117408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117715. 0,
  117716. };
  117717. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117718. -0.5, 0.5,
  117719. };
  117720. static long _vq_quantmap__44c5_s_p1_0[] = {
  117721. 1, 0, 2,
  117722. };
  117723. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117724. _vq_quantthresh__44c5_s_p1_0,
  117725. _vq_quantmap__44c5_s_p1_0,
  117726. 3,
  117727. 3
  117728. };
  117729. static static_codebook _44c5_s_p1_0 = {
  117730. 8, 6561,
  117731. _vq_lengthlist__44c5_s_p1_0,
  117732. 1, -535822336, 1611661312, 2, 0,
  117733. _vq_quantlist__44c5_s_p1_0,
  117734. NULL,
  117735. &_vq_auxt__44c5_s_p1_0,
  117736. NULL,
  117737. 0
  117738. };
  117739. static long _vq_quantlist__44c5_s_p2_0[] = {
  117740. 2,
  117741. 1,
  117742. 3,
  117743. 0,
  117744. 4,
  117745. };
  117746. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117747. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117748. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117749. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117750. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117751. 0, 0,10,10, 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, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117757. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117758. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117759. 10, 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, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117765. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117766. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117772. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117773. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117774. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  117775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117786. 0,
  117787. };
  117788. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117789. -1.5, -0.5, 0.5, 1.5,
  117790. };
  117791. static long _vq_quantmap__44c5_s_p2_0[] = {
  117792. 3, 1, 0, 2, 4,
  117793. };
  117794. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117795. _vq_quantthresh__44c5_s_p2_0,
  117796. _vq_quantmap__44c5_s_p2_0,
  117797. 5,
  117798. 5
  117799. };
  117800. static static_codebook _44c5_s_p2_0 = {
  117801. 4, 625,
  117802. _vq_lengthlist__44c5_s_p2_0,
  117803. 1, -533725184, 1611661312, 3, 0,
  117804. _vq_quantlist__44c5_s_p2_0,
  117805. NULL,
  117806. &_vq_auxt__44c5_s_p2_0,
  117807. NULL,
  117808. 0
  117809. };
  117810. static long _vq_quantlist__44c5_s_p3_0[] = {
  117811. 2,
  117812. 1,
  117813. 3,
  117814. 0,
  117815. 4,
  117816. };
  117817. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117818. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117821. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117824. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  117825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117857. 0,
  117858. };
  117859. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117860. -1.5, -0.5, 0.5, 1.5,
  117861. };
  117862. static long _vq_quantmap__44c5_s_p3_0[] = {
  117863. 3, 1, 0, 2, 4,
  117864. };
  117865. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117866. _vq_quantthresh__44c5_s_p3_0,
  117867. _vq_quantmap__44c5_s_p3_0,
  117868. 5,
  117869. 5
  117870. };
  117871. static static_codebook _44c5_s_p3_0 = {
  117872. 4, 625,
  117873. _vq_lengthlist__44c5_s_p3_0,
  117874. 1, -533725184, 1611661312, 3, 0,
  117875. _vq_quantlist__44c5_s_p3_0,
  117876. NULL,
  117877. &_vq_auxt__44c5_s_p3_0,
  117878. NULL,
  117879. 0
  117880. };
  117881. static long _vq_quantlist__44c5_s_p4_0[] = {
  117882. 4,
  117883. 3,
  117884. 5,
  117885. 2,
  117886. 6,
  117887. 1,
  117888. 7,
  117889. 0,
  117890. 8,
  117891. };
  117892. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117893. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117894. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117895. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117896. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117897. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117898. 0,
  117899. };
  117900. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117901. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117902. };
  117903. static long _vq_quantmap__44c5_s_p4_0[] = {
  117904. 7, 5, 3, 1, 0, 2, 4, 6,
  117905. 8,
  117906. };
  117907. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117908. _vq_quantthresh__44c5_s_p4_0,
  117909. _vq_quantmap__44c5_s_p4_0,
  117910. 9,
  117911. 9
  117912. };
  117913. static static_codebook _44c5_s_p4_0 = {
  117914. 2, 81,
  117915. _vq_lengthlist__44c5_s_p4_0,
  117916. 1, -531628032, 1611661312, 4, 0,
  117917. _vq_quantlist__44c5_s_p4_0,
  117918. NULL,
  117919. &_vq_auxt__44c5_s_p4_0,
  117920. NULL,
  117921. 0
  117922. };
  117923. static long _vq_quantlist__44c5_s_p5_0[] = {
  117924. 4,
  117925. 3,
  117926. 5,
  117927. 2,
  117928. 6,
  117929. 1,
  117930. 7,
  117931. 0,
  117932. 8,
  117933. };
  117934. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117935. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117936. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117937. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117938. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117939. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117940. 10,
  117941. };
  117942. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117943. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117944. };
  117945. static long _vq_quantmap__44c5_s_p5_0[] = {
  117946. 7, 5, 3, 1, 0, 2, 4, 6,
  117947. 8,
  117948. };
  117949. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117950. _vq_quantthresh__44c5_s_p5_0,
  117951. _vq_quantmap__44c5_s_p5_0,
  117952. 9,
  117953. 9
  117954. };
  117955. static static_codebook _44c5_s_p5_0 = {
  117956. 2, 81,
  117957. _vq_lengthlist__44c5_s_p5_0,
  117958. 1, -531628032, 1611661312, 4, 0,
  117959. _vq_quantlist__44c5_s_p5_0,
  117960. NULL,
  117961. &_vq_auxt__44c5_s_p5_0,
  117962. NULL,
  117963. 0
  117964. };
  117965. static long _vq_quantlist__44c5_s_p6_0[] = {
  117966. 8,
  117967. 7,
  117968. 9,
  117969. 6,
  117970. 10,
  117971. 5,
  117972. 11,
  117973. 4,
  117974. 12,
  117975. 3,
  117976. 13,
  117977. 2,
  117978. 14,
  117979. 1,
  117980. 15,
  117981. 0,
  117982. 16,
  117983. };
  117984. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117985. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117986. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117987. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117988. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117989. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117990. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117991. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117992. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117993. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117994. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117995. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117996. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117997. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117998. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117999. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  118000. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  118001. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  118002. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  118003. 13,
  118004. };
  118005. static float _vq_quantthresh__44c5_s_p6_0[] = {
  118006. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118007. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118008. };
  118009. static long _vq_quantmap__44c5_s_p6_0[] = {
  118010. 15, 13, 11, 9, 7, 5, 3, 1,
  118011. 0, 2, 4, 6, 8, 10, 12, 14,
  118012. 16,
  118013. };
  118014. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  118015. _vq_quantthresh__44c5_s_p6_0,
  118016. _vq_quantmap__44c5_s_p6_0,
  118017. 17,
  118018. 17
  118019. };
  118020. static static_codebook _44c5_s_p6_0 = {
  118021. 2, 289,
  118022. _vq_lengthlist__44c5_s_p6_0,
  118023. 1, -529530880, 1611661312, 5, 0,
  118024. _vq_quantlist__44c5_s_p6_0,
  118025. NULL,
  118026. &_vq_auxt__44c5_s_p6_0,
  118027. NULL,
  118028. 0
  118029. };
  118030. static long _vq_quantlist__44c5_s_p7_0[] = {
  118031. 1,
  118032. 0,
  118033. 2,
  118034. };
  118035. static long _vq_lengthlist__44c5_s_p7_0[] = {
  118036. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  118037. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  118038. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  118039. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  118040. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  118041. 10,
  118042. };
  118043. static float _vq_quantthresh__44c5_s_p7_0[] = {
  118044. -5.5, 5.5,
  118045. };
  118046. static long _vq_quantmap__44c5_s_p7_0[] = {
  118047. 1, 0, 2,
  118048. };
  118049. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  118050. _vq_quantthresh__44c5_s_p7_0,
  118051. _vq_quantmap__44c5_s_p7_0,
  118052. 3,
  118053. 3
  118054. };
  118055. static static_codebook _44c5_s_p7_0 = {
  118056. 4, 81,
  118057. _vq_lengthlist__44c5_s_p7_0,
  118058. 1, -529137664, 1618345984, 2, 0,
  118059. _vq_quantlist__44c5_s_p7_0,
  118060. NULL,
  118061. &_vq_auxt__44c5_s_p7_0,
  118062. NULL,
  118063. 0
  118064. };
  118065. static long _vq_quantlist__44c5_s_p7_1[] = {
  118066. 5,
  118067. 4,
  118068. 6,
  118069. 3,
  118070. 7,
  118071. 2,
  118072. 8,
  118073. 1,
  118074. 9,
  118075. 0,
  118076. 10,
  118077. };
  118078. static long _vq_lengthlist__44c5_s_p7_1[] = {
  118079. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  118080. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  118081. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  118082. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  118083. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  118084. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  118085. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  118086. 10,10,10, 8, 8, 8, 8, 8, 8,
  118087. };
  118088. static float _vq_quantthresh__44c5_s_p7_1[] = {
  118089. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118090. 3.5, 4.5,
  118091. };
  118092. static long _vq_quantmap__44c5_s_p7_1[] = {
  118093. 9, 7, 5, 3, 1, 0, 2, 4,
  118094. 6, 8, 10,
  118095. };
  118096. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  118097. _vq_quantthresh__44c5_s_p7_1,
  118098. _vq_quantmap__44c5_s_p7_1,
  118099. 11,
  118100. 11
  118101. };
  118102. static static_codebook _44c5_s_p7_1 = {
  118103. 2, 121,
  118104. _vq_lengthlist__44c5_s_p7_1,
  118105. 1, -531365888, 1611661312, 4, 0,
  118106. _vq_quantlist__44c5_s_p7_1,
  118107. NULL,
  118108. &_vq_auxt__44c5_s_p7_1,
  118109. NULL,
  118110. 0
  118111. };
  118112. static long _vq_quantlist__44c5_s_p8_0[] = {
  118113. 6,
  118114. 5,
  118115. 7,
  118116. 4,
  118117. 8,
  118118. 3,
  118119. 9,
  118120. 2,
  118121. 10,
  118122. 1,
  118123. 11,
  118124. 0,
  118125. 12,
  118126. };
  118127. static long _vq_lengthlist__44c5_s_p8_0[] = {
  118128. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  118129. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  118130. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  118131. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  118132. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  118133. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  118134. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  118135. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  118136. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  118137. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  118138. 0,12,12,12,12,12,12,13,13,
  118139. };
  118140. static float _vq_quantthresh__44c5_s_p8_0[] = {
  118141. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118142. 12.5, 17.5, 22.5, 27.5,
  118143. };
  118144. static long _vq_quantmap__44c5_s_p8_0[] = {
  118145. 11, 9, 7, 5, 3, 1, 0, 2,
  118146. 4, 6, 8, 10, 12,
  118147. };
  118148. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  118149. _vq_quantthresh__44c5_s_p8_0,
  118150. _vq_quantmap__44c5_s_p8_0,
  118151. 13,
  118152. 13
  118153. };
  118154. static static_codebook _44c5_s_p8_0 = {
  118155. 2, 169,
  118156. _vq_lengthlist__44c5_s_p8_0,
  118157. 1, -526516224, 1616117760, 4, 0,
  118158. _vq_quantlist__44c5_s_p8_0,
  118159. NULL,
  118160. &_vq_auxt__44c5_s_p8_0,
  118161. NULL,
  118162. 0
  118163. };
  118164. static long _vq_quantlist__44c5_s_p8_1[] = {
  118165. 2,
  118166. 1,
  118167. 3,
  118168. 0,
  118169. 4,
  118170. };
  118171. static long _vq_lengthlist__44c5_s_p8_1[] = {
  118172. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  118173. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118174. };
  118175. static float _vq_quantthresh__44c5_s_p8_1[] = {
  118176. -1.5, -0.5, 0.5, 1.5,
  118177. };
  118178. static long _vq_quantmap__44c5_s_p8_1[] = {
  118179. 3, 1, 0, 2, 4,
  118180. };
  118181. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  118182. _vq_quantthresh__44c5_s_p8_1,
  118183. _vq_quantmap__44c5_s_p8_1,
  118184. 5,
  118185. 5
  118186. };
  118187. static static_codebook _44c5_s_p8_1 = {
  118188. 2, 25,
  118189. _vq_lengthlist__44c5_s_p8_1,
  118190. 1, -533725184, 1611661312, 3, 0,
  118191. _vq_quantlist__44c5_s_p8_1,
  118192. NULL,
  118193. &_vq_auxt__44c5_s_p8_1,
  118194. NULL,
  118195. 0
  118196. };
  118197. static long _vq_quantlist__44c5_s_p9_0[] = {
  118198. 7,
  118199. 6,
  118200. 8,
  118201. 5,
  118202. 9,
  118203. 4,
  118204. 10,
  118205. 3,
  118206. 11,
  118207. 2,
  118208. 12,
  118209. 1,
  118210. 13,
  118211. 0,
  118212. 14,
  118213. };
  118214. static long _vq_lengthlist__44c5_s_p9_0[] = {
  118215. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  118216. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  118217. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118218. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118219. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118220. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118221. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118222. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118223. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118224. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118225. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118226. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118227. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118228. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  118229. 12,
  118230. };
  118231. static float _vq_quantthresh__44c5_s_p9_0[] = {
  118232. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  118233. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  118234. };
  118235. static long _vq_quantmap__44c5_s_p9_0[] = {
  118236. 13, 11, 9, 7, 5, 3, 1, 0,
  118237. 2, 4, 6, 8, 10, 12, 14,
  118238. };
  118239. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  118240. _vq_quantthresh__44c5_s_p9_0,
  118241. _vq_quantmap__44c5_s_p9_0,
  118242. 15,
  118243. 15
  118244. };
  118245. static static_codebook _44c5_s_p9_0 = {
  118246. 2, 225,
  118247. _vq_lengthlist__44c5_s_p9_0,
  118248. 1, -512522752, 1628852224, 4, 0,
  118249. _vq_quantlist__44c5_s_p9_0,
  118250. NULL,
  118251. &_vq_auxt__44c5_s_p9_0,
  118252. NULL,
  118253. 0
  118254. };
  118255. static long _vq_quantlist__44c5_s_p9_1[] = {
  118256. 8,
  118257. 7,
  118258. 9,
  118259. 6,
  118260. 10,
  118261. 5,
  118262. 11,
  118263. 4,
  118264. 12,
  118265. 3,
  118266. 13,
  118267. 2,
  118268. 14,
  118269. 1,
  118270. 15,
  118271. 0,
  118272. 16,
  118273. };
  118274. static long _vq_lengthlist__44c5_s_p9_1[] = {
  118275. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  118276. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  118277. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  118278. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  118279. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  118280. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  118281. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  118282. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  118283. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  118284. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  118285. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  118286. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  118287. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  118288. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  118289. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  118290. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  118291. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  118292. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  118293. 15,
  118294. };
  118295. static float _vq_quantthresh__44c5_s_p9_1[] = {
  118296. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  118297. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  118298. };
  118299. static long _vq_quantmap__44c5_s_p9_1[] = {
  118300. 15, 13, 11, 9, 7, 5, 3, 1,
  118301. 0, 2, 4, 6, 8, 10, 12, 14,
  118302. 16,
  118303. };
  118304. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  118305. _vq_quantthresh__44c5_s_p9_1,
  118306. _vq_quantmap__44c5_s_p9_1,
  118307. 17,
  118308. 17
  118309. };
  118310. static static_codebook _44c5_s_p9_1 = {
  118311. 2, 289,
  118312. _vq_lengthlist__44c5_s_p9_1,
  118313. 1, -520814592, 1620377600, 5, 0,
  118314. _vq_quantlist__44c5_s_p9_1,
  118315. NULL,
  118316. &_vq_auxt__44c5_s_p9_1,
  118317. NULL,
  118318. 0
  118319. };
  118320. static long _vq_quantlist__44c5_s_p9_2[] = {
  118321. 10,
  118322. 9,
  118323. 11,
  118324. 8,
  118325. 12,
  118326. 7,
  118327. 13,
  118328. 6,
  118329. 14,
  118330. 5,
  118331. 15,
  118332. 4,
  118333. 16,
  118334. 3,
  118335. 17,
  118336. 2,
  118337. 18,
  118338. 1,
  118339. 19,
  118340. 0,
  118341. 20,
  118342. };
  118343. static long _vq_lengthlist__44c5_s_p9_2[] = {
  118344. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  118345. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  118346. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  118347. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  118348. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  118349. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  118350. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  118351. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  118352. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  118353. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118354. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  118355. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  118356. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  118357. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  118358. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  118359. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  118360. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  118361. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118362. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  118363. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  118364. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118365. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118366. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118367. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118368. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  118369. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118370. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  118371. 10,10,10,10,10,10,10,10,10,
  118372. };
  118373. static float _vq_quantthresh__44c5_s_p9_2[] = {
  118374. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118375. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118376. 6.5, 7.5, 8.5, 9.5,
  118377. };
  118378. static long _vq_quantmap__44c5_s_p9_2[] = {
  118379. 19, 17, 15, 13, 11, 9, 7, 5,
  118380. 3, 1, 0, 2, 4, 6, 8, 10,
  118381. 12, 14, 16, 18, 20,
  118382. };
  118383. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  118384. _vq_quantthresh__44c5_s_p9_2,
  118385. _vq_quantmap__44c5_s_p9_2,
  118386. 21,
  118387. 21
  118388. };
  118389. static static_codebook _44c5_s_p9_2 = {
  118390. 2, 441,
  118391. _vq_lengthlist__44c5_s_p9_2,
  118392. 1, -529268736, 1611661312, 5, 0,
  118393. _vq_quantlist__44c5_s_p9_2,
  118394. NULL,
  118395. &_vq_auxt__44c5_s_p9_2,
  118396. NULL,
  118397. 0
  118398. };
  118399. static long _huff_lengthlist__44c5_s_short[] = {
  118400. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  118401. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  118402. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  118403. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  118404. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  118405. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  118406. 6, 8,11,16,
  118407. };
  118408. static static_codebook _huff_book__44c5_s_short = {
  118409. 2, 100,
  118410. _huff_lengthlist__44c5_s_short,
  118411. 0, 0, 0, 0, 0,
  118412. NULL,
  118413. NULL,
  118414. NULL,
  118415. NULL,
  118416. 0
  118417. };
  118418. static long _huff_lengthlist__44c6_s_long[] = {
  118419. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  118420. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  118421. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  118422. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  118423. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  118424. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  118425. 11,10,10,12,
  118426. };
  118427. static static_codebook _huff_book__44c6_s_long = {
  118428. 2, 100,
  118429. _huff_lengthlist__44c6_s_long,
  118430. 0, 0, 0, 0, 0,
  118431. NULL,
  118432. NULL,
  118433. NULL,
  118434. NULL,
  118435. 0
  118436. };
  118437. static long _vq_quantlist__44c6_s_p1_0[] = {
  118438. 1,
  118439. 0,
  118440. 2,
  118441. };
  118442. static long _vq_lengthlist__44c6_s_p1_0[] = {
  118443. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118444. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118445. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118446. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118447. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  118448. 8,
  118449. };
  118450. static float _vq_quantthresh__44c6_s_p1_0[] = {
  118451. -0.5, 0.5,
  118452. };
  118453. static long _vq_quantmap__44c6_s_p1_0[] = {
  118454. 1, 0, 2,
  118455. };
  118456. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  118457. _vq_quantthresh__44c6_s_p1_0,
  118458. _vq_quantmap__44c6_s_p1_0,
  118459. 3,
  118460. 3
  118461. };
  118462. static static_codebook _44c6_s_p1_0 = {
  118463. 4, 81,
  118464. _vq_lengthlist__44c6_s_p1_0,
  118465. 1, -535822336, 1611661312, 2, 0,
  118466. _vq_quantlist__44c6_s_p1_0,
  118467. NULL,
  118468. &_vq_auxt__44c6_s_p1_0,
  118469. NULL,
  118470. 0
  118471. };
  118472. static long _vq_quantlist__44c6_s_p2_0[] = {
  118473. 2,
  118474. 1,
  118475. 3,
  118476. 0,
  118477. 4,
  118478. };
  118479. static long _vq_lengthlist__44c6_s_p2_0[] = {
  118480. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118481. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118482. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118483. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118484. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  118485. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118486. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  118487. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118489. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118490. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118491. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118492. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118493. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118494. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  118495. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118497. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118498. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  118499. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  118500. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  118501. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  118502. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118503. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118505. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  118506. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118507. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118508. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  118509. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118510. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  118511. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118516. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  118517. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  118518. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118519. 13,
  118520. };
  118521. static float _vq_quantthresh__44c6_s_p2_0[] = {
  118522. -1.5, -0.5, 0.5, 1.5,
  118523. };
  118524. static long _vq_quantmap__44c6_s_p2_0[] = {
  118525. 3, 1, 0, 2, 4,
  118526. };
  118527. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118528. _vq_quantthresh__44c6_s_p2_0,
  118529. _vq_quantmap__44c6_s_p2_0,
  118530. 5,
  118531. 5
  118532. };
  118533. static static_codebook _44c6_s_p2_0 = {
  118534. 4, 625,
  118535. _vq_lengthlist__44c6_s_p2_0,
  118536. 1, -533725184, 1611661312, 3, 0,
  118537. _vq_quantlist__44c6_s_p2_0,
  118538. NULL,
  118539. &_vq_auxt__44c6_s_p2_0,
  118540. NULL,
  118541. 0
  118542. };
  118543. static long _vq_quantlist__44c6_s_p3_0[] = {
  118544. 4,
  118545. 3,
  118546. 5,
  118547. 2,
  118548. 6,
  118549. 1,
  118550. 7,
  118551. 0,
  118552. 8,
  118553. };
  118554. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118555. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118556. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118557. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118558. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118560. 0,
  118561. };
  118562. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118563. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118564. };
  118565. static long _vq_quantmap__44c6_s_p3_0[] = {
  118566. 7, 5, 3, 1, 0, 2, 4, 6,
  118567. 8,
  118568. };
  118569. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118570. _vq_quantthresh__44c6_s_p3_0,
  118571. _vq_quantmap__44c6_s_p3_0,
  118572. 9,
  118573. 9
  118574. };
  118575. static static_codebook _44c6_s_p3_0 = {
  118576. 2, 81,
  118577. _vq_lengthlist__44c6_s_p3_0,
  118578. 1, -531628032, 1611661312, 4, 0,
  118579. _vq_quantlist__44c6_s_p3_0,
  118580. NULL,
  118581. &_vq_auxt__44c6_s_p3_0,
  118582. NULL,
  118583. 0
  118584. };
  118585. static long _vq_quantlist__44c6_s_p4_0[] = {
  118586. 8,
  118587. 7,
  118588. 9,
  118589. 6,
  118590. 10,
  118591. 5,
  118592. 11,
  118593. 4,
  118594. 12,
  118595. 3,
  118596. 13,
  118597. 2,
  118598. 14,
  118599. 1,
  118600. 15,
  118601. 0,
  118602. 16,
  118603. };
  118604. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118605. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118606. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118607. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118608. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118609. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118610. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118611. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118612. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118613. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118614. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118623. 0,
  118624. };
  118625. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118626. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118627. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118628. };
  118629. static long _vq_quantmap__44c6_s_p4_0[] = {
  118630. 15, 13, 11, 9, 7, 5, 3, 1,
  118631. 0, 2, 4, 6, 8, 10, 12, 14,
  118632. 16,
  118633. };
  118634. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118635. _vq_quantthresh__44c6_s_p4_0,
  118636. _vq_quantmap__44c6_s_p4_0,
  118637. 17,
  118638. 17
  118639. };
  118640. static static_codebook _44c6_s_p4_0 = {
  118641. 2, 289,
  118642. _vq_lengthlist__44c6_s_p4_0,
  118643. 1, -529530880, 1611661312, 5, 0,
  118644. _vq_quantlist__44c6_s_p4_0,
  118645. NULL,
  118646. &_vq_auxt__44c6_s_p4_0,
  118647. NULL,
  118648. 0
  118649. };
  118650. static long _vq_quantlist__44c6_s_p5_0[] = {
  118651. 1,
  118652. 0,
  118653. 2,
  118654. };
  118655. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118656. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118657. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118658. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118659. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118660. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118661. 12,
  118662. };
  118663. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118664. -5.5, 5.5,
  118665. };
  118666. static long _vq_quantmap__44c6_s_p5_0[] = {
  118667. 1, 0, 2,
  118668. };
  118669. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118670. _vq_quantthresh__44c6_s_p5_0,
  118671. _vq_quantmap__44c6_s_p5_0,
  118672. 3,
  118673. 3
  118674. };
  118675. static static_codebook _44c6_s_p5_0 = {
  118676. 4, 81,
  118677. _vq_lengthlist__44c6_s_p5_0,
  118678. 1, -529137664, 1618345984, 2, 0,
  118679. _vq_quantlist__44c6_s_p5_0,
  118680. NULL,
  118681. &_vq_auxt__44c6_s_p5_0,
  118682. NULL,
  118683. 0
  118684. };
  118685. static long _vq_quantlist__44c6_s_p5_1[] = {
  118686. 5,
  118687. 4,
  118688. 6,
  118689. 3,
  118690. 7,
  118691. 2,
  118692. 8,
  118693. 1,
  118694. 9,
  118695. 0,
  118696. 10,
  118697. };
  118698. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118699. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118700. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118701. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118702. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118703. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118704. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118705. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118706. 11,10,10, 7, 7, 8, 8, 8, 8,
  118707. };
  118708. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118709. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118710. 3.5, 4.5,
  118711. };
  118712. static long _vq_quantmap__44c6_s_p5_1[] = {
  118713. 9, 7, 5, 3, 1, 0, 2, 4,
  118714. 6, 8, 10,
  118715. };
  118716. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118717. _vq_quantthresh__44c6_s_p5_1,
  118718. _vq_quantmap__44c6_s_p5_1,
  118719. 11,
  118720. 11
  118721. };
  118722. static static_codebook _44c6_s_p5_1 = {
  118723. 2, 121,
  118724. _vq_lengthlist__44c6_s_p5_1,
  118725. 1, -531365888, 1611661312, 4, 0,
  118726. _vq_quantlist__44c6_s_p5_1,
  118727. NULL,
  118728. &_vq_auxt__44c6_s_p5_1,
  118729. NULL,
  118730. 0
  118731. };
  118732. static long _vq_quantlist__44c6_s_p6_0[] = {
  118733. 6,
  118734. 5,
  118735. 7,
  118736. 4,
  118737. 8,
  118738. 3,
  118739. 9,
  118740. 2,
  118741. 10,
  118742. 1,
  118743. 11,
  118744. 0,
  118745. 12,
  118746. };
  118747. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118748. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118749. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118750. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118751. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118752. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118753. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118758. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118759. };
  118760. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118761. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118762. 12.5, 17.5, 22.5, 27.5,
  118763. };
  118764. static long _vq_quantmap__44c6_s_p6_0[] = {
  118765. 11, 9, 7, 5, 3, 1, 0, 2,
  118766. 4, 6, 8, 10, 12,
  118767. };
  118768. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118769. _vq_quantthresh__44c6_s_p6_0,
  118770. _vq_quantmap__44c6_s_p6_0,
  118771. 13,
  118772. 13
  118773. };
  118774. static static_codebook _44c6_s_p6_0 = {
  118775. 2, 169,
  118776. _vq_lengthlist__44c6_s_p6_0,
  118777. 1, -526516224, 1616117760, 4, 0,
  118778. _vq_quantlist__44c6_s_p6_0,
  118779. NULL,
  118780. &_vq_auxt__44c6_s_p6_0,
  118781. NULL,
  118782. 0
  118783. };
  118784. static long _vq_quantlist__44c6_s_p6_1[] = {
  118785. 2,
  118786. 1,
  118787. 3,
  118788. 0,
  118789. 4,
  118790. };
  118791. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118792. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118793. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118794. };
  118795. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118796. -1.5, -0.5, 0.5, 1.5,
  118797. };
  118798. static long _vq_quantmap__44c6_s_p6_1[] = {
  118799. 3, 1, 0, 2, 4,
  118800. };
  118801. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118802. _vq_quantthresh__44c6_s_p6_1,
  118803. _vq_quantmap__44c6_s_p6_1,
  118804. 5,
  118805. 5
  118806. };
  118807. static static_codebook _44c6_s_p6_1 = {
  118808. 2, 25,
  118809. _vq_lengthlist__44c6_s_p6_1,
  118810. 1, -533725184, 1611661312, 3, 0,
  118811. _vq_quantlist__44c6_s_p6_1,
  118812. NULL,
  118813. &_vq_auxt__44c6_s_p6_1,
  118814. NULL,
  118815. 0
  118816. };
  118817. static long _vq_quantlist__44c6_s_p7_0[] = {
  118818. 6,
  118819. 5,
  118820. 7,
  118821. 4,
  118822. 8,
  118823. 3,
  118824. 9,
  118825. 2,
  118826. 10,
  118827. 1,
  118828. 11,
  118829. 0,
  118830. 12,
  118831. };
  118832. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118833. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118834. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118835. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118836. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118837. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118838. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118839. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118840. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118841. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118842. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118843. 20,13,13,13,13,13,13,14,14,
  118844. };
  118845. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118846. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118847. 27.5, 38.5, 49.5, 60.5,
  118848. };
  118849. static long _vq_quantmap__44c6_s_p7_0[] = {
  118850. 11, 9, 7, 5, 3, 1, 0, 2,
  118851. 4, 6, 8, 10, 12,
  118852. };
  118853. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118854. _vq_quantthresh__44c6_s_p7_0,
  118855. _vq_quantmap__44c6_s_p7_0,
  118856. 13,
  118857. 13
  118858. };
  118859. static static_codebook _44c6_s_p7_0 = {
  118860. 2, 169,
  118861. _vq_lengthlist__44c6_s_p7_0,
  118862. 1, -523206656, 1618345984, 4, 0,
  118863. _vq_quantlist__44c6_s_p7_0,
  118864. NULL,
  118865. &_vq_auxt__44c6_s_p7_0,
  118866. NULL,
  118867. 0
  118868. };
  118869. static long _vq_quantlist__44c6_s_p7_1[] = {
  118870. 5,
  118871. 4,
  118872. 6,
  118873. 3,
  118874. 7,
  118875. 2,
  118876. 8,
  118877. 1,
  118878. 9,
  118879. 0,
  118880. 10,
  118881. };
  118882. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118883. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118884. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118885. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118886. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118887. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118888. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118889. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118890. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118891. };
  118892. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118893. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118894. 3.5, 4.5,
  118895. };
  118896. static long _vq_quantmap__44c6_s_p7_1[] = {
  118897. 9, 7, 5, 3, 1, 0, 2, 4,
  118898. 6, 8, 10,
  118899. };
  118900. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118901. _vq_quantthresh__44c6_s_p7_1,
  118902. _vq_quantmap__44c6_s_p7_1,
  118903. 11,
  118904. 11
  118905. };
  118906. static static_codebook _44c6_s_p7_1 = {
  118907. 2, 121,
  118908. _vq_lengthlist__44c6_s_p7_1,
  118909. 1, -531365888, 1611661312, 4, 0,
  118910. _vq_quantlist__44c6_s_p7_1,
  118911. NULL,
  118912. &_vq_auxt__44c6_s_p7_1,
  118913. NULL,
  118914. 0
  118915. };
  118916. static long _vq_quantlist__44c6_s_p8_0[] = {
  118917. 7,
  118918. 6,
  118919. 8,
  118920. 5,
  118921. 9,
  118922. 4,
  118923. 10,
  118924. 3,
  118925. 11,
  118926. 2,
  118927. 12,
  118928. 1,
  118929. 13,
  118930. 0,
  118931. 14,
  118932. };
  118933. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118934. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118935. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118936. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118937. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118938. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118939. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118940. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118941. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118942. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118943. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118944. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118945. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118946. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118947. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118948. 14,
  118949. };
  118950. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118951. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118952. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118953. };
  118954. static long _vq_quantmap__44c6_s_p8_0[] = {
  118955. 13, 11, 9, 7, 5, 3, 1, 0,
  118956. 2, 4, 6, 8, 10, 12, 14,
  118957. };
  118958. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118959. _vq_quantthresh__44c6_s_p8_0,
  118960. _vq_quantmap__44c6_s_p8_0,
  118961. 15,
  118962. 15
  118963. };
  118964. static static_codebook _44c6_s_p8_0 = {
  118965. 2, 225,
  118966. _vq_lengthlist__44c6_s_p8_0,
  118967. 1, -520986624, 1620377600, 4, 0,
  118968. _vq_quantlist__44c6_s_p8_0,
  118969. NULL,
  118970. &_vq_auxt__44c6_s_p8_0,
  118971. NULL,
  118972. 0
  118973. };
  118974. static long _vq_quantlist__44c6_s_p8_1[] = {
  118975. 10,
  118976. 9,
  118977. 11,
  118978. 8,
  118979. 12,
  118980. 7,
  118981. 13,
  118982. 6,
  118983. 14,
  118984. 5,
  118985. 15,
  118986. 4,
  118987. 16,
  118988. 3,
  118989. 17,
  118990. 2,
  118991. 18,
  118992. 1,
  118993. 19,
  118994. 0,
  118995. 20,
  118996. };
  118997. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118998. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118999. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  119000. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119001. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119002. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119003. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  119004. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  119005. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  119006. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119007. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119008. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  119009. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  119010. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  119011. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  119012. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  119013. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  119014. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  119015. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  119016. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  119017. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  119018. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  119019. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  119020. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  119021. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  119022. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  119023. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  119024. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  119025. 10,10,10,10,10,10,10,10,10,
  119026. };
  119027. static float _vq_quantthresh__44c6_s_p8_1[] = {
  119028. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119029. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119030. 6.5, 7.5, 8.5, 9.5,
  119031. };
  119032. static long _vq_quantmap__44c6_s_p8_1[] = {
  119033. 19, 17, 15, 13, 11, 9, 7, 5,
  119034. 3, 1, 0, 2, 4, 6, 8, 10,
  119035. 12, 14, 16, 18, 20,
  119036. };
  119037. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  119038. _vq_quantthresh__44c6_s_p8_1,
  119039. _vq_quantmap__44c6_s_p8_1,
  119040. 21,
  119041. 21
  119042. };
  119043. static static_codebook _44c6_s_p8_1 = {
  119044. 2, 441,
  119045. _vq_lengthlist__44c6_s_p8_1,
  119046. 1, -529268736, 1611661312, 5, 0,
  119047. _vq_quantlist__44c6_s_p8_1,
  119048. NULL,
  119049. &_vq_auxt__44c6_s_p8_1,
  119050. NULL,
  119051. 0
  119052. };
  119053. static long _vq_quantlist__44c6_s_p9_0[] = {
  119054. 6,
  119055. 5,
  119056. 7,
  119057. 4,
  119058. 8,
  119059. 3,
  119060. 9,
  119061. 2,
  119062. 10,
  119063. 1,
  119064. 11,
  119065. 0,
  119066. 12,
  119067. };
  119068. static long _vq_lengthlist__44c6_s_p9_0[] = {
  119069. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  119070. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  119071. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119072. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119073. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119074. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119075. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119076. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119077. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119078. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119079. 10,10,10,10,10,10,10,10,10,
  119080. };
  119081. static float _vq_quantthresh__44c6_s_p9_0[] = {
  119082. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119083. 1592.5, 2229.5, 2866.5, 3503.5,
  119084. };
  119085. static long _vq_quantmap__44c6_s_p9_0[] = {
  119086. 11, 9, 7, 5, 3, 1, 0, 2,
  119087. 4, 6, 8, 10, 12,
  119088. };
  119089. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  119090. _vq_quantthresh__44c6_s_p9_0,
  119091. _vq_quantmap__44c6_s_p9_0,
  119092. 13,
  119093. 13
  119094. };
  119095. static static_codebook _44c6_s_p9_0 = {
  119096. 2, 169,
  119097. _vq_lengthlist__44c6_s_p9_0,
  119098. 1, -511845376, 1630791680, 4, 0,
  119099. _vq_quantlist__44c6_s_p9_0,
  119100. NULL,
  119101. &_vq_auxt__44c6_s_p9_0,
  119102. NULL,
  119103. 0
  119104. };
  119105. static long _vq_quantlist__44c6_s_p9_1[] = {
  119106. 6,
  119107. 5,
  119108. 7,
  119109. 4,
  119110. 8,
  119111. 3,
  119112. 9,
  119113. 2,
  119114. 10,
  119115. 1,
  119116. 11,
  119117. 0,
  119118. 12,
  119119. };
  119120. static long _vq_lengthlist__44c6_s_p9_1[] = {
  119121. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119122. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  119123. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  119124. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  119125. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  119126. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  119127. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  119128. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  119129. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  119130. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  119131. 15,12,10,11,11,13,11,12,13,
  119132. };
  119133. static float _vq_quantthresh__44c6_s_p9_1[] = {
  119134. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119135. 122.5, 171.5, 220.5, 269.5,
  119136. };
  119137. static long _vq_quantmap__44c6_s_p9_1[] = {
  119138. 11, 9, 7, 5, 3, 1, 0, 2,
  119139. 4, 6, 8, 10, 12,
  119140. };
  119141. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  119142. _vq_quantthresh__44c6_s_p9_1,
  119143. _vq_quantmap__44c6_s_p9_1,
  119144. 13,
  119145. 13
  119146. };
  119147. static static_codebook _44c6_s_p9_1 = {
  119148. 2, 169,
  119149. _vq_lengthlist__44c6_s_p9_1,
  119150. 1, -518889472, 1622704128, 4, 0,
  119151. _vq_quantlist__44c6_s_p9_1,
  119152. NULL,
  119153. &_vq_auxt__44c6_s_p9_1,
  119154. NULL,
  119155. 0
  119156. };
  119157. static long _vq_quantlist__44c6_s_p9_2[] = {
  119158. 24,
  119159. 23,
  119160. 25,
  119161. 22,
  119162. 26,
  119163. 21,
  119164. 27,
  119165. 20,
  119166. 28,
  119167. 19,
  119168. 29,
  119169. 18,
  119170. 30,
  119171. 17,
  119172. 31,
  119173. 16,
  119174. 32,
  119175. 15,
  119176. 33,
  119177. 14,
  119178. 34,
  119179. 13,
  119180. 35,
  119181. 12,
  119182. 36,
  119183. 11,
  119184. 37,
  119185. 10,
  119186. 38,
  119187. 9,
  119188. 39,
  119189. 8,
  119190. 40,
  119191. 7,
  119192. 41,
  119193. 6,
  119194. 42,
  119195. 5,
  119196. 43,
  119197. 4,
  119198. 44,
  119199. 3,
  119200. 45,
  119201. 2,
  119202. 46,
  119203. 1,
  119204. 47,
  119205. 0,
  119206. 48,
  119207. };
  119208. static long _vq_lengthlist__44c6_s_p9_2[] = {
  119209. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119210. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119211. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119212. 7,
  119213. };
  119214. static float _vq_quantthresh__44c6_s_p9_2[] = {
  119215. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119216. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119217. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119218. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119219. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119220. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119221. };
  119222. static long _vq_quantmap__44c6_s_p9_2[] = {
  119223. 47, 45, 43, 41, 39, 37, 35, 33,
  119224. 31, 29, 27, 25, 23, 21, 19, 17,
  119225. 15, 13, 11, 9, 7, 5, 3, 1,
  119226. 0, 2, 4, 6, 8, 10, 12, 14,
  119227. 16, 18, 20, 22, 24, 26, 28, 30,
  119228. 32, 34, 36, 38, 40, 42, 44, 46,
  119229. 48,
  119230. };
  119231. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  119232. _vq_quantthresh__44c6_s_p9_2,
  119233. _vq_quantmap__44c6_s_p9_2,
  119234. 49,
  119235. 49
  119236. };
  119237. static static_codebook _44c6_s_p9_2 = {
  119238. 1, 49,
  119239. _vq_lengthlist__44c6_s_p9_2,
  119240. 1, -526909440, 1611661312, 6, 0,
  119241. _vq_quantlist__44c6_s_p9_2,
  119242. NULL,
  119243. &_vq_auxt__44c6_s_p9_2,
  119244. NULL,
  119245. 0
  119246. };
  119247. static long _huff_lengthlist__44c6_s_short[] = {
  119248. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  119249. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  119250. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  119251. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  119252. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  119253. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  119254. 9,10,17,18,
  119255. };
  119256. static static_codebook _huff_book__44c6_s_short = {
  119257. 2, 100,
  119258. _huff_lengthlist__44c6_s_short,
  119259. 0, 0, 0, 0, 0,
  119260. NULL,
  119261. NULL,
  119262. NULL,
  119263. NULL,
  119264. 0
  119265. };
  119266. static long _huff_lengthlist__44c7_s_long[] = {
  119267. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  119268. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  119269. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  119270. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  119271. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  119272. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  119273. 11,10,10,12,
  119274. };
  119275. static static_codebook _huff_book__44c7_s_long = {
  119276. 2, 100,
  119277. _huff_lengthlist__44c7_s_long,
  119278. 0, 0, 0, 0, 0,
  119279. NULL,
  119280. NULL,
  119281. NULL,
  119282. NULL,
  119283. 0
  119284. };
  119285. static long _vq_quantlist__44c7_s_p1_0[] = {
  119286. 1,
  119287. 0,
  119288. 2,
  119289. };
  119290. static long _vq_lengthlist__44c7_s_p1_0[] = {
  119291. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  119292. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119293. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119294. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119295. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119296. 8,
  119297. };
  119298. static float _vq_quantthresh__44c7_s_p1_0[] = {
  119299. -0.5, 0.5,
  119300. };
  119301. static long _vq_quantmap__44c7_s_p1_0[] = {
  119302. 1, 0, 2,
  119303. };
  119304. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  119305. _vq_quantthresh__44c7_s_p1_0,
  119306. _vq_quantmap__44c7_s_p1_0,
  119307. 3,
  119308. 3
  119309. };
  119310. static static_codebook _44c7_s_p1_0 = {
  119311. 4, 81,
  119312. _vq_lengthlist__44c7_s_p1_0,
  119313. 1, -535822336, 1611661312, 2, 0,
  119314. _vq_quantlist__44c7_s_p1_0,
  119315. NULL,
  119316. &_vq_auxt__44c7_s_p1_0,
  119317. NULL,
  119318. 0
  119319. };
  119320. static long _vq_quantlist__44c7_s_p2_0[] = {
  119321. 2,
  119322. 1,
  119323. 3,
  119324. 0,
  119325. 4,
  119326. };
  119327. static long _vq_lengthlist__44c7_s_p2_0[] = {
  119328. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119329. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119330. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119331. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  119332. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119333. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  119334. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  119335. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119337. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119338. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  119339. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119340. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  119341. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  119342. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  119343. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  119344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119345. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  119346. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  119347. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  119348. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  119349. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  119350. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  119351. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119353. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119354. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  119355. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119356. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  119357. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  119358. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  119359. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119364. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  119365. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119366. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  119367. 13,
  119368. };
  119369. static float _vq_quantthresh__44c7_s_p2_0[] = {
  119370. -1.5, -0.5, 0.5, 1.5,
  119371. };
  119372. static long _vq_quantmap__44c7_s_p2_0[] = {
  119373. 3, 1, 0, 2, 4,
  119374. };
  119375. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  119376. _vq_quantthresh__44c7_s_p2_0,
  119377. _vq_quantmap__44c7_s_p2_0,
  119378. 5,
  119379. 5
  119380. };
  119381. static static_codebook _44c7_s_p2_0 = {
  119382. 4, 625,
  119383. _vq_lengthlist__44c7_s_p2_0,
  119384. 1, -533725184, 1611661312, 3, 0,
  119385. _vq_quantlist__44c7_s_p2_0,
  119386. NULL,
  119387. &_vq_auxt__44c7_s_p2_0,
  119388. NULL,
  119389. 0
  119390. };
  119391. static long _vq_quantlist__44c7_s_p3_0[] = {
  119392. 4,
  119393. 3,
  119394. 5,
  119395. 2,
  119396. 6,
  119397. 1,
  119398. 7,
  119399. 0,
  119400. 8,
  119401. };
  119402. static long _vq_lengthlist__44c7_s_p3_0[] = {
  119403. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119404. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119405. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119406. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119408. 0,
  119409. };
  119410. static float _vq_quantthresh__44c7_s_p3_0[] = {
  119411. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119412. };
  119413. static long _vq_quantmap__44c7_s_p3_0[] = {
  119414. 7, 5, 3, 1, 0, 2, 4, 6,
  119415. 8,
  119416. };
  119417. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  119418. _vq_quantthresh__44c7_s_p3_0,
  119419. _vq_quantmap__44c7_s_p3_0,
  119420. 9,
  119421. 9
  119422. };
  119423. static static_codebook _44c7_s_p3_0 = {
  119424. 2, 81,
  119425. _vq_lengthlist__44c7_s_p3_0,
  119426. 1, -531628032, 1611661312, 4, 0,
  119427. _vq_quantlist__44c7_s_p3_0,
  119428. NULL,
  119429. &_vq_auxt__44c7_s_p3_0,
  119430. NULL,
  119431. 0
  119432. };
  119433. static long _vq_quantlist__44c7_s_p4_0[] = {
  119434. 8,
  119435. 7,
  119436. 9,
  119437. 6,
  119438. 10,
  119439. 5,
  119440. 11,
  119441. 4,
  119442. 12,
  119443. 3,
  119444. 13,
  119445. 2,
  119446. 14,
  119447. 1,
  119448. 15,
  119449. 0,
  119450. 16,
  119451. };
  119452. static long _vq_lengthlist__44c7_s_p4_0[] = {
  119453. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119454. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  119455. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119456. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  119457. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  119458. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119459. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119460. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119461. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119462. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119471. 0,
  119472. };
  119473. static float _vq_quantthresh__44c7_s_p4_0[] = {
  119474. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119475. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119476. };
  119477. static long _vq_quantmap__44c7_s_p4_0[] = {
  119478. 15, 13, 11, 9, 7, 5, 3, 1,
  119479. 0, 2, 4, 6, 8, 10, 12, 14,
  119480. 16,
  119481. };
  119482. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  119483. _vq_quantthresh__44c7_s_p4_0,
  119484. _vq_quantmap__44c7_s_p4_0,
  119485. 17,
  119486. 17
  119487. };
  119488. static static_codebook _44c7_s_p4_0 = {
  119489. 2, 289,
  119490. _vq_lengthlist__44c7_s_p4_0,
  119491. 1, -529530880, 1611661312, 5, 0,
  119492. _vq_quantlist__44c7_s_p4_0,
  119493. NULL,
  119494. &_vq_auxt__44c7_s_p4_0,
  119495. NULL,
  119496. 0
  119497. };
  119498. static long _vq_quantlist__44c7_s_p5_0[] = {
  119499. 1,
  119500. 0,
  119501. 2,
  119502. };
  119503. static long _vq_lengthlist__44c7_s_p5_0[] = {
  119504. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  119505. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119506. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119507. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  119508. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  119509. 12,
  119510. };
  119511. static float _vq_quantthresh__44c7_s_p5_0[] = {
  119512. -5.5, 5.5,
  119513. };
  119514. static long _vq_quantmap__44c7_s_p5_0[] = {
  119515. 1, 0, 2,
  119516. };
  119517. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  119518. _vq_quantthresh__44c7_s_p5_0,
  119519. _vq_quantmap__44c7_s_p5_0,
  119520. 3,
  119521. 3
  119522. };
  119523. static static_codebook _44c7_s_p5_0 = {
  119524. 4, 81,
  119525. _vq_lengthlist__44c7_s_p5_0,
  119526. 1, -529137664, 1618345984, 2, 0,
  119527. _vq_quantlist__44c7_s_p5_0,
  119528. NULL,
  119529. &_vq_auxt__44c7_s_p5_0,
  119530. NULL,
  119531. 0
  119532. };
  119533. static long _vq_quantlist__44c7_s_p5_1[] = {
  119534. 5,
  119535. 4,
  119536. 6,
  119537. 3,
  119538. 7,
  119539. 2,
  119540. 8,
  119541. 1,
  119542. 9,
  119543. 0,
  119544. 10,
  119545. };
  119546. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119547. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119548. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119549. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119550. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119551. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119552. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119553. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119554. 11,11,11, 7, 7, 8, 8, 8, 8,
  119555. };
  119556. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119557. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119558. 3.5, 4.5,
  119559. };
  119560. static long _vq_quantmap__44c7_s_p5_1[] = {
  119561. 9, 7, 5, 3, 1, 0, 2, 4,
  119562. 6, 8, 10,
  119563. };
  119564. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119565. _vq_quantthresh__44c7_s_p5_1,
  119566. _vq_quantmap__44c7_s_p5_1,
  119567. 11,
  119568. 11
  119569. };
  119570. static static_codebook _44c7_s_p5_1 = {
  119571. 2, 121,
  119572. _vq_lengthlist__44c7_s_p5_1,
  119573. 1, -531365888, 1611661312, 4, 0,
  119574. _vq_quantlist__44c7_s_p5_1,
  119575. NULL,
  119576. &_vq_auxt__44c7_s_p5_1,
  119577. NULL,
  119578. 0
  119579. };
  119580. static long _vq_quantlist__44c7_s_p6_0[] = {
  119581. 6,
  119582. 5,
  119583. 7,
  119584. 4,
  119585. 8,
  119586. 3,
  119587. 9,
  119588. 2,
  119589. 10,
  119590. 1,
  119591. 11,
  119592. 0,
  119593. 12,
  119594. };
  119595. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119596. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119597. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119598. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119599. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119600. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119601. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119606. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119607. };
  119608. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119609. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119610. 12.5, 17.5, 22.5, 27.5,
  119611. };
  119612. static long _vq_quantmap__44c7_s_p6_0[] = {
  119613. 11, 9, 7, 5, 3, 1, 0, 2,
  119614. 4, 6, 8, 10, 12,
  119615. };
  119616. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119617. _vq_quantthresh__44c7_s_p6_0,
  119618. _vq_quantmap__44c7_s_p6_0,
  119619. 13,
  119620. 13
  119621. };
  119622. static static_codebook _44c7_s_p6_0 = {
  119623. 2, 169,
  119624. _vq_lengthlist__44c7_s_p6_0,
  119625. 1, -526516224, 1616117760, 4, 0,
  119626. _vq_quantlist__44c7_s_p6_0,
  119627. NULL,
  119628. &_vq_auxt__44c7_s_p6_0,
  119629. NULL,
  119630. 0
  119631. };
  119632. static long _vq_quantlist__44c7_s_p6_1[] = {
  119633. 2,
  119634. 1,
  119635. 3,
  119636. 0,
  119637. 4,
  119638. };
  119639. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119640. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119641. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119642. };
  119643. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119644. -1.5, -0.5, 0.5, 1.5,
  119645. };
  119646. static long _vq_quantmap__44c7_s_p6_1[] = {
  119647. 3, 1, 0, 2, 4,
  119648. };
  119649. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119650. _vq_quantthresh__44c7_s_p6_1,
  119651. _vq_quantmap__44c7_s_p6_1,
  119652. 5,
  119653. 5
  119654. };
  119655. static static_codebook _44c7_s_p6_1 = {
  119656. 2, 25,
  119657. _vq_lengthlist__44c7_s_p6_1,
  119658. 1, -533725184, 1611661312, 3, 0,
  119659. _vq_quantlist__44c7_s_p6_1,
  119660. NULL,
  119661. &_vq_auxt__44c7_s_p6_1,
  119662. NULL,
  119663. 0
  119664. };
  119665. static long _vq_quantlist__44c7_s_p7_0[] = {
  119666. 6,
  119667. 5,
  119668. 7,
  119669. 4,
  119670. 8,
  119671. 3,
  119672. 9,
  119673. 2,
  119674. 10,
  119675. 1,
  119676. 11,
  119677. 0,
  119678. 12,
  119679. };
  119680. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119681. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119682. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119683. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119684. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119685. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119686. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119687. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119688. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119689. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119690. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119691. 19,13,13,13,13,14,14,15,15,
  119692. };
  119693. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119694. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119695. 27.5, 38.5, 49.5, 60.5,
  119696. };
  119697. static long _vq_quantmap__44c7_s_p7_0[] = {
  119698. 11, 9, 7, 5, 3, 1, 0, 2,
  119699. 4, 6, 8, 10, 12,
  119700. };
  119701. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119702. _vq_quantthresh__44c7_s_p7_0,
  119703. _vq_quantmap__44c7_s_p7_0,
  119704. 13,
  119705. 13
  119706. };
  119707. static static_codebook _44c7_s_p7_0 = {
  119708. 2, 169,
  119709. _vq_lengthlist__44c7_s_p7_0,
  119710. 1, -523206656, 1618345984, 4, 0,
  119711. _vq_quantlist__44c7_s_p7_0,
  119712. NULL,
  119713. &_vq_auxt__44c7_s_p7_0,
  119714. NULL,
  119715. 0
  119716. };
  119717. static long _vq_quantlist__44c7_s_p7_1[] = {
  119718. 5,
  119719. 4,
  119720. 6,
  119721. 3,
  119722. 7,
  119723. 2,
  119724. 8,
  119725. 1,
  119726. 9,
  119727. 0,
  119728. 10,
  119729. };
  119730. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119731. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119732. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119733. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119734. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119735. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119736. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119737. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119738. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119739. };
  119740. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119741. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119742. 3.5, 4.5,
  119743. };
  119744. static long _vq_quantmap__44c7_s_p7_1[] = {
  119745. 9, 7, 5, 3, 1, 0, 2, 4,
  119746. 6, 8, 10,
  119747. };
  119748. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119749. _vq_quantthresh__44c7_s_p7_1,
  119750. _vq_quantmap__44c7_s_p7_1,
  119751. 11,
  119752. 11
  119753. };
  119754. static static_codebook _44c7_s_p7_1 = {
  119755. 2, 121,
  119756. _vq_lengthlist__44c7_s_p7_1,
  119757. 1, -531365888, 1611661312, 4, 0,
  119758. _vq_quantlist__44c7_s_p7_1,
  119759. NULL,
  119760. &_vq_auxt__44c7_s_p7_1,
  119761. NULL,
  119762. 0
  119763. };
  119764. static long _vq_quantlist__44c7_s_p8_0[] = {
  119765. 7,
  119766. 6,
  119767. 8,
  119768. 5,
  119769. 9,
  119770. 4,
  119771. 10,
  119772. 3,
  119773. 11,
  119774. 2,
  119775. 12,
  119776. 1,
  119777. 13,
  119778. 0,
  119779. 14,
  119780. };
  119781. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119782. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119783. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119784. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119785. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119786. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119787. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119788. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119789. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119790. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119791. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119792. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119793. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119794. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119795. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119796. 14,
  119797. };
  119798. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119799. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119800. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119801. };
  119802. static long _vq_quantmap__44c7_s_p8_0[] = {
  119803. 13, 11, 9, 7, 5, 3, 1, 0,
  119804. 2, 4, 6, 8, 10, 12, 14,
  119805. };
  119806. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119807. _vq_quantthresh__44c7_s_p8_0,
  119808. _vq_quantmap__44c7_s_p8_0,
  119809. 15,
  119810. 15
  119811. };
  119812. static static_codebook _44c7_s_p8_0 = {
  119813. 2, 225,
  119814. _vq_lengthlist__44c7_s_p8_0,
  119815. 1, -520986624, 1620377600, 4, 0,
  119816. _vq_quantlist__44c7_s_p8_0,
  119817. NULL,
  119818. &_vq_auxt__44c7_s_p8_0,
  119819. NULL,
  119820. 0
  119821. };
  119822. static long _vq_quantlist__44c7_s_p8_1[] = {
  119823. 10,
  119824. 9,
  119825. 11,
  119826. 8,
  119827. 12,
  119828. 7,
  119829. 13,
  119830. 6,
  119831. 14,
  119832. 5,
  119833. 15,
  119834. 4,
  119835. 16,
  119836. 3,
  119837. 17,
  119838. 2,
  119839. 18,
  119840. 1,
  119841. 19,
  119842. 0,
  119843. 20,
  119844. };
  119845. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119846. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119847. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119848. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119849. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119850. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119851. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119852. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119853. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119854. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119855. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119856. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119857. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119858. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119859. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119860. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119861. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119862. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119863. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119864. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119865. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119866. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119867. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119868. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119869. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119870. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119871. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119872. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119873. 10,10,10,10,10,10,10,10,10,
  119874. };
  119875. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119876. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119877. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119878. 6.5, 7.5, 8.5, 9.5,
  119879. };
  119880. static long _vq_quantmap__44c7_s_p8_1[] = {
  119881. 19, 17, 15, 13, 11, 9, 7, 5,
  119882. 3, 1, 0, 2, 4, 6, 8, 10,
  119883. 12, 14, 16, 18, 20,
  119884. };
  119885. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119886. _vq_quantthresh__44c7_s_p8_1,
  119887. _vq_quantmap__44c7_s_p8_1,
  119888. 21,
  119889. 21
  119890. };
  119891. static static_codebook _44c7_s_p8_1 = {
  119892. 2, 441,
  119893. _vq_lengthlist__44c7_s_p8_1,
  119894. 1, -529268736, 1611661312, 5, 0,
  119895. _vq_quantlist__44c7_s_p8_1,
  119896. NULL,
  119897. &_vq_auxt__44c7_s_p8_1,
  119898. NULL,
  119899. 0
  119900. };
  119901. static long _vq_quantlist__44c7_s_p9_0[] = {
  119902. 6,
  119903. 5,
  119904. 7,
  119905. 4,
  119906. 8,
  119907. 3,
  119908. 9,
  119909. 2,
  119910. 10,
  119911. 1,
  119912. 11,
  119913. 0,
  119914. 12,
  119915. };
  119916. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119917. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119918. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119919. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119920. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119921. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119922. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119923. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119924. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119925. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119926. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119927. 11,11,11,11,11,11,11,11,11,
  119928. };
  119929. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119930. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119931. 1592.5, 2229.5, 2866.5, 3503.5,
  119932. };
  119933. static long _vq_quantmap__44c7_s_p9_0[] = {
  119934. 11, 9, 7, 5, 3, 1, 0, 2,
  119935. 4, 6, 8, 10, 12,
  119936. };
  119937. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119938. _vq_quantthresh__44c7_s_p9_0,
  119939. _vq_quantmap__44c7_s_p9_0,
  119940. 13,
  119941. 13
  119942. };
  119943. static static_codebook _44c7_s_p9_0 = {
  119944. 2, 169,
  119945. _vq_lengthlist__44c7_s_p9_0,
  119946. 1, -511845376, 1630791680, 4, 0,
  119947. _vq_quantlist__44c7_s_p9_0,
  119948. NULL,
  119949. &_vq_auxt__44c7_s_p9_0,
  119950. NULL,
  119951. 0
  119952. };
  119953. static long _vq_quantlist__44c7_s_p9_1[] = {
  119954. 6,
  119955. 5,
  119956. 7,
  119957. 4,
  119958. 8,
  119959. 3,
  119960. 9,
  119961. 2,
  119962. 10,
  119963. 1,
  119964. 11,
  119965. 0,
  119966. 12,
  119967. };
  119968. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119969. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119970. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119971. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119972. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119973. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119974. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119975. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119976. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119977. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119978. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119979. 15,11,11,10,10,12,12,12,12,
  119980. };
  119981. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119982. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119983. 122.5, 171.5, 220.5, 269.5,
  119984. };
  119985. static long _vq_quantmap__44c7_s_p9_1[] = {
  119986. 11, 9, 7, 5, 3, 1, 0, 2,
  119987. 4, 6, 8, 10, 12,
  119988. };
  119989. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119990. _vq_quantthresh__44c7_s_p9_1,
  119991. _vq_quantmap__44c7_s_p9_1,
  119992. 13,
  119993. 13
  119994. };
  119995. static static_codebook _44c7_s_p9_1 = {
  119996. 2, 169,
  119997. _vq_lengthlist__44c7_s_p9_1,
  119998. 1, -518889472, 1622704128, 4, 0,
  119999. _vq_quantlist__44c7_s_p9_1,
  120000. NULL,
  120001. &_vq_auxt__44c7_s_p9_1,
  120002. NULL,
  120003. 0
  120004. };
  120005. static long _vq_quantlist__44c7_s_p9_2[] = {
  120006. 24,
  120007. 23,
  120008. 25,
  120009. 22,
  120010. 26,
  120011. 21,
  120012. 27,
  120013. 20,
  120014. 28,
  120015. 19,
  120016. 29,
  120017. 18,
  120018. 30,
  120019. 17,
  120020. 31,
  120021. 16,
  120022. 32,
  120023. 15,
  120024. 33,
  120025. 14,
  120026. 34,
  120027. 13,
  120028. 35,
  120029. 12,
  120030. 36,
  120031. 11,
  120032. 37,
  120033. 10,
  120034. 38,
  120035. 9,
  120036. 39,
  120037. 8,
  120038. 40,
  120039. 7,
  120040. 41,
  120041. 6,
  120042. 42,
  120043. 5,
  120044. 43,
  120045. 4,
  120046. 44,
  120047. 3,
  120048. 45,
  120049. 2,
  120050. 46,
  120051. 1,
  120052. 47,
  120053. 0,
  120054. 48,
  120055. };
  120056. static long _vq_lengthlist__44c7_s_p9_2[] = {
  120057. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  120058. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120059. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120060. 7,
  120061. };
  120062. static float _vq_quantthresh__44c7_s_p9_2[] = {
  120063. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120064. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120065. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120066. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120067. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120068. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120069. };
  120070. static long _vq_quantmap__44c7_s_p9_2[] = {
  120071. 47, 45, 43, 41, 39, 37, 35, 33,
  120072. 31, 29, 27, 25, 23, 21, 19, 17,
  120073. 15, 13, 11, 9, 7, 5, 3, 1,
  120074. 0, 2, 4, 6, 8, 10, 12, 14,
  120075. 16, 18, 20, 22, 24, 26, 28, 30,
  120076. 32, 34, 36, 38, 40, 42, 44, 46,
  120077. 48,
  120078. };
  120079. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  120080. _vq_quantthresh__44c7_s_p9_2,
  120081. _vq_quantmap__44c7_s_p9_2,
  120082. 49,
  120083. 49
  120084. };
  120085. static static_codebook _44c7_s_p9_2 = {
  120086. 1, 49,
  120087. _vq_lengthlist__44c7_s_p9_2,
  120088. 1, -526909440, 1611661312, 6, 0,
  120089. _vq_quantlist__44c7_s_p9_2,
  120090. NULL,
  120091. &_vq_auxt__44c7_s_p9_2,
  120092. NULL,
  120093. 0
  120094. };
  120095. static long _huff_lengthlist__44c7_s_short[] = {
  120096. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  120097. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  120098. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  120099. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  120100. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  120101. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  120102. 10, 9,11,14,
  120103. };
  120104. static static_codebook _huff_book__44c7_s_short = {
  120105. 2, 100,
  120106. _huff_lengthlist__44c7_s_short,
  120107. 0, 0, 0, 0, 0,
  120108. NULL,
  120109. NULL,
  120110. NULL,
  120111. NULL,
  120112. 0
  120113. };
  120114. static long _huff_lengthlist__44c8_s_long[] = {
  120115. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  120116. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  120117. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  120118. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  120119. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  120120. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  120121. 11, 9, 9,10,
  120122. };
  120123. static static_codebook _huff_book__44c8_s_long = {
  120124. 2, 100,
  120125. _huff_lengthlist__44c8_s_long,
  120126. 0, 0, 0, 0, 0,
  120127. NULL,
  120128. NULL,
  120129. NULL,
  120130. NULL,
  120131. 0
  120132. };
  120133. static long _vq_quantlist__44c8_s_p1_0[] = {
  120134. 1,
  120135. 0,
  120136. 2,
  120137. };
  120138. static long _vq_lengthlist__44c8_s_p1_0[] = {
  120139. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  120140. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120141. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  120142. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120143. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  120144. 8,
  120145. };
  120146. static float _vq_quantthresh__44c8_s_p1_0[] = {
  120147. -0.5, 0.5,
  120148. };
  120149. static long _vq_quantmap__44c8_s_p1_0[] = {
  120150. 1, 0, 2,
  120151. };
  120152. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  120153. _vq_quantthresh__44c8_s_p1_0,
  120154. _vq_quantmap__44c8_s_p1_0,
  120155. 3,
  120156. 3
  120157. };
  120158. static static_codebook _44c8_s_p1_0 = {
  120159. 4, 81,
  120160. _vq_lengthlist__44c8_s_p1_0,
  120161. 1, -535822336, 1611661312, 2, 0,
  120162. _vq_quantlist__44c8_s_p1_0,
  120163. NULL,
  120164. &_vq_auxt__44c8_s_p1_0,
  120165. NULL,
  120166. 0
  120167. };
  120168. static long _vq_quantlist__44c8_s_p2_0[] = {
  120169. 2,
  120170. 1,
  120171. 3,
  120172. 0,
  120173. 4,
  120174. };
  120175. static long _vq_lengthlist__44c8_s_p2_0[] = {
  120176. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120177. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  120178. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  120179. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  120180. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  120181. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  120182. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  120183. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  120184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120185. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  120186. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  120187. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  120188. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  120189. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  120190. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  120191. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  120192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120193. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  120194. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  120195. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  120196. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  120197. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  120198. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  120199. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120201. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  120202. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  120203. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  120204. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  120205. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  120206. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  120207. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120212. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  120213. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  120214. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  120215. 13,
  120216. };
  120217. static float _vq_quantthresh__44c8_s_p2_0[] = {
  120218. -1.5, -0.5, 0.5, 1.5,
  120219. };
  120220. static long _vq_quantmap__44c8_s_p2_0[] = {
  120221. 3, 1, 0, 2, 4,
  120222. };
  120223. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  120224. _vq_quantthresh__44c8_s_p2_0,
  120225. _vq_quantmap__44c8_s_p2_0,
  120226. 5,
  120227. 5
  120228. };
  120229. static static_codebook _44c8_s_p2_0 = {
  120230. 4, 625,
  120231. _vq_lengthlist__44c8_s_p2_0,
  120232. 1, -533725184, 1611661312, 3, 0,
  120233. _vq_quantlist__44c8_s_p2_0,
  120234. NULL,
  120235. &_vq_auxt__44c8_s_p2_0,
  120236. NULL,
  120237. 0
  120238. };
  120239. static long _vq_quantlist__44c8_s_p3_0[] = {
  120240. 4,
  120241. 3,
  120242. 5,
  120243. 2,
  120244. 6,
  120245. 1,
  120246. 7,
  120247. 0,
  120248. 8,
  120249. };
  120250. static long _vq_lengthlist__44c8_s_p3_0[] = {
  120251. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  120252. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  120253. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  120254. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  120255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120256. 0,
  120257. };
  120258. static float _vq_quantthresh__44c8_s_p3_0[] = {
  120259. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120260. };
  120261. static long _vq_quantmap__44c8_s_p3_0[] = {
  120262. 7, 5, 3, 1, 0, 2, 4, 6,
  120263. 8,
  120264. };
  120265. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  120266. _vq_quantthresh__44c8_s_p3_0,
  120267. _vq_quantmap__44c8_s_p3_0,
  120268. 9,
  120269. 9
  120270. };
  120271. static static_codebook _44c8_s_p3_0 = {
  120272. 2, 81,
  120273. _vq_lengthlist__44c8_s_p3_0,
  120274. 1, -531628032, 1611661312, 4, 0,
  120275. _vq_quantlist__44c8_s_p3_0,
  120276. NULL,
  120277. &_vq_auxt__44c8_s_p3_0,
  120278. NULL,
  120279. 0
  120280. };
  120281. static long _vq_quantlist__44c8_s_p4_0[] = {
  120282. 8,
  120283. 7,
  120284. 9,
  120285. 6,
  120286. 10,
  120287. 5,
  120288. 11,
  120289. 4,
  120290. 12,
  120291. 3,
  120292. 13,
  120293. 2,
  120294. 14,
  120295. 1,
  120296. 15,
  120297. 0,
  120298. 16,
  120299. };
  120300. static long _vq_lengthlist__44c8_s_p4_0[] = {
  120301. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  120302. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  120303. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120304. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  120305. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  120306. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  120307. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  120308. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120309. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120310. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  120311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120319. 0,
  120320. };
  120321. static float _vq_quantthresh__44c8_s_p4_0[] = {
  120322. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120323. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120324. };
  120325. static long _vq_quantmap__44c8_s_p4_0[] = {
  120326. 15, 13, 11, 9, 7, 5, 3, 1,
  120327. 0, 2, 4, 6, 8, 10, 12, 14,
  120328. 16,
  120329. };
  120330. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  120331. _vq_quantthresh__44c8_s_p4_0,
  120332. _vq_quantmap__44c8_s_p4_0,
  120333. 17,
  120334. 17
  120335. };
  120336. static static_codebook _44c8_s_p4_0 = {
  120337. 2, 289,
  120338. _vq_lengthlist__44c8_s_p4_0,
  120339. 1, -529530880, 1611661312, 5, 0,
  120340. _vq_quantlist__44c8_s_p4_0,
  120341. NULL,
  120342. &_vq_auxt__44c8_s_p4_0,
  120343. NULL,
  120344. 0
  120345. };
  120346. static long _vq_quantlist__44c8_s_p5_0[] = {
  120347. 1,
  120348. 0,
  120349. 2,
  120350. };
  120351. static long _vq_lengthlist__44c8_s_p5_0[] = {
  120352. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  120353. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  120354. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  120355. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  120356. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  120357. 12,
  120358. };
  120359. static float _vq_quantthresh__44c8_s_p5_0[] = {
  120360. -5.5, 5.5,
  120361. };
  120362. static long _vq_quantmap__44c8_s_p5_0[] = {
  120363. 1, 0, 2,
  120364. };
  120365. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  120366. _vq_quantthresh__44c8_s_p5_0,
  120367. _vq_quantmap__44c8_s_p5_0,
  120368. 3,
  120369. 3
  120370. };
  120371. static static_codebook _44c8_s_p5_0 = {
  120372. 4, 81,
  120373. _vq_lengthlist__44c8_s_p5_0,
  120374. 1, -529137664, 1618345984, 2, 0,
  120375. _vq_quantlist__44c8_s_p5_0,
  120376. NULL,
  120377. &_vq_auxt__44c8_s_p5_0,
  120378. NULL,
  120379. 0
  120380. };
  120381. static long _vq_quantlist__44c8_s_p5_1[] = {
  120382. 5,
  120383. 4,
  120384. 6,
  120385. 3,
  120386. 7,
  120387. 2,
  120388. 8,
  120389. 1,
  120390. 9,
  120391. 0,
  120392. 10,
  120393. };
  120394. static long _vq_lengthlist__44c8_s_p5_1[] = {
  120395. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  120396. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  120397. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  120398. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  120399. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  120400. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  120401. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  120402. 11,11,11, 7, 7, 7, 7, 8, 8,
  120403. };
  120404. static float _vq_quantthresh__44c8_s_p5_1[] = {
  120405. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120406. 3.5, 4.5,
  120407. };
  120408. static long _vq_quantmap__44c8_s_p5_1[] = {
  120409. 9, 7, 5, 3, 1, 0, 2, 4,
  120410. 6, 8, 10,
  120411. };
  120412. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  120413. _vq_quantthresh__44c8_s_p5_1,
  120414. _vq_quantmap__44c8_s_p5_1,
  120415. 11,
  120416. 11
  120417. };
  120418. static static_codebook _44c8_s_p5_1 = {
  120419. 2, 121,
  120420. _vq_lengthlist__44c8_s_p5_1,
  120421. 1, -531365888, 1611661312, 4, 0,
  120422. _vq_quantlist__44c8_s_p5_1,
  120423. NULL,
  120424. &_vq_auxt__44c8_s_p5_1,
  120425. NULL,
  120426. 0
  120427. };
  120428. static long _vq_quantlist__44c8_s_p6_0[] = {
  120429. 6,
  120430. 5,
  120431. 7,
  120432. 4,
  120433. 8,
  120434. 3,
  120435. 9,
  120436. 2,
  120437. 10,
  120438. 1,
  120439. 11,
  120440. 0,
  120441. 12,
  120442. };
  120443. static long _vq_lengthlist__44c8_s_p6_0[] = {
  120444. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  120445. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  120446. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  120447. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  120448. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  120449. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  120450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120454. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120455. };
  120456. static float _vq_quantthresh__44c8_s_p6_0[] = {
  120457. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120458. 12.5, 17.5, 22.5, 27.5,
  120459. };
  120460. static long _vq_quantmap__44c8_s_p6_0[] = {
  120461. 11, 9, 7, 5, 3, 1, 0, 2,
  120462. 4, 6, 8, 10, 12,
  120463. };
  120464. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  120465. _vq_quantthresh__44c8_s_p6_0,
  120466. _vq_quantmap__44c8_s_p6_0,
  120467. 13,
  120468. 13
  120469. };
  120470. static static_codebook _44c8_s_p6_0 = {
  120471. 2, 169,
  120472. _vq_lengthlist__44c8_s_p6_0,
  120473. 1, -526516224, 1616117760, 4, 0,
  120474. _vq_quantlist__44c8_s_p6_0,
  120475. NULL,
  120476. &_vq_auxt__44c8_s_p6_0,
  120477. NULL,
  120478. 0
  120479. };
  120480. static long _vq_quantlist__44c8_s_p6_1[] = {
  120481. 2,
  120482. 1,
  120483. 3,
  120484. 0,
  120485. 4,
  120486. };
  120487. static long _vq_lengthlist__44c8_s_p6_1[] = {
  120488. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  120489. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  120490. };
  120491. static float _vq_quantthresh__44c8_s_p6_1[] = {
  120492. -1.5, -0.5, 0.5, 1.5,
  120493. };
  120494. static long _vq_quantmap__44c8_s_p6_1[] = {
  120495. 3, 1, 0, 2, 4,
  120496. };
  120497. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  120498. _vq_quantthresh__44c8_s_p6_1,
  120499. _vq_quantmap__44c8_s_p6_1,
  120500. 5,
  120501. 5
  120502. };
  120503. static static_codebook _44c8_s_p6_1 = {
  120504. 2, 25,
  120505. _vq_lengthlist__44c8_s_p6_1,
  120506. 1, -533725184, 1611661312, 3, 0,
  120507. _vq_quantlist__44c8_s_p6_1,
  120508. NULL,
  120509. &_vq_auxt__44c8_s_p6_1,
  120510. NULL,
  120511. 0
  120512. };
  120513. static long _vq_quantlist__44c8_s_p7_0[] = {
  120514. 6,
  120515. 5,
  120516. 7,
  120517. 4,
  120518. 8,
  120519. 3,
  120520. 9,
  120521. 2,
  120522. 10,
  120523. 1,
  120524. 11,
  120525. 0,
  120526. 12,
  120527. };
  120528. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120529. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120530. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120531. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120532. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120533. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120534. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120535. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120536. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120537. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120538. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120539. 20,13,13,13,13,14,13,15,15,
  120540. };
  120541. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120542. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120543. 27.5, 38.5, 49.5, 60.5,
  120544. };
  120545. static long _vq_quantmap__44c8_s_p7_0[] = {
  120546. 11, 9, 7, 5, 3, 1, 0, 2,
  120547. 4, 6, 8, 10, 12,
  120548. };
  120549. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120550. _vq_quantthresh__44c8_s_p7_0,
  120551. _vq_quantmap__44c8_s_p7_0,
  120552. 13,
  120553. 13
  120554. };
  120555. static static_codebook _44c8_s_p7_0 = {
  120556. 2, 169,
  120557. _vq_lengthlist__44c8_s_p7_0,
  120558. 1, -523206656, 1618345984, 4, 0,
  120559. _vq_quantlist__44c8_s_p7_0,
  120560. NULL,
  120561. &_vq_auxt__44c8_s_p7_0,
  120562. NULL,
  120563. 0
  120564. };
  120565. static long _vq_quantlist__44c8_s_p7_1[] = {
  120566. 5,
  120567. 4,
  120568. 6,
  120569. 3,
  120570. 7,
  120571. 2,
  120572. 8,
  120573. 1,
  120574. 9,
  120575. 0,
  120576. 10,
  120577. };
  120578. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120579. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120580. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120581. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120582. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120583. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120584. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120585. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120586. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120587. };
  120588. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120589. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120590. 3.5, 4.5,
  120591. };
  120592. static long _vq_quantmap__44c8_s_p7_1[] = {
  120593. 9, 7, 5, 3, 1, 0, 2, 4,
  120594. 6, 8, 10,
  120595. };
  120596. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120597. _vq_quantthresh__44c8_s_p7_1,
  120598. _vq_quantmap__44c8_s_p7_1,
  120599. 11,
  120600. 11
  120601. };
  120602. static static_codebook _44c8_s_p7_1 = {
  120603. 2, 121,
  120604. _vq_lengthlist__44c8_s_p7_1,
  120605. 1, -531365888, 1611661312, 4, 0,
  120606. _vq_quantlist__44c8_s_p7_1,
  120607. NULL,
  120608. &_vq_auxt__44c8_s_p7_1,
  120609. NULL,
  120610. 0
  120611. };
  120612. static long _vq_quantlist__44c8_s_p8_0[] = {
  120613. 7,
  120614. 6,
  120615. 8,
  120616. 5,
  120617. 9,
  120618. 4,
  120619. 10,
  120620. 3,
  120621. 11,
  120622. 2,
  120623. 12,
  120624. 1,
  120625. 13,
  120626. 0,
  120627. 14,
  120628. };
  120629. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120630. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120631. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120632. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120633. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120634. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120635. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120636. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120637. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120638. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120639. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120640. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120641. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120642. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120643. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120644. 15,
  120645. };
  120646. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120647. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120648. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120649. };
  120650. static long _vq_quantmap__44c8_s_p8_0[] = {
  120651. 13, 11, 9, 7, 5, 3, 1, 0,
  120652. 2, 4, 6, 8, 10, 12, 14,
  120653. };
  120654. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120655. _vq_quantthresh__44c8_s_p8_0,
  120656. _vq_quantmap__44c8_s_p8_0,
  120657. 15,
  120658. 15
  120659. };
  120660. static static_codebook _44c8_s_p8_0 = {
  120661. 2, 225,
  120662. _vq_lengthlist__44c8_s_p8_0,
  120663. 1, -520986624, 1620377600, 4, 0,
  120664. _vq_quantlist__44c8_s_p8_0,
  120665. NULL,
  120666. &_vq_auxt__44c8_s_p8_0,
  120667. NULL,
  120668. 0
  120669. };
  120670. static long _vq_quantlist__44c8_s_p8_1[] = {
  120671. 10,
  120672. 9,
  120673. 11,
  120674. 8,
  120675. 12,
  120676. 7,
  120677. 13,
  120678. 6,
  120679. 14,
  120680. 5,
  120681. 15,
  120682. 4,
  120683. 16,
  120684. 3,
  120685. 17,
  120686. 2,
  120687. 18,
  120688. 1,
  120689. 19,
  120690. 0,
  120691. 20,
  120692. };
  120693. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120694. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120695. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120696. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120697. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120698. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120699. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120700. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120701. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120702. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120703. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120704. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120705. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120706. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120707. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120708. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120709. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120710. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120711. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120712. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120713. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120714. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120715. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120716. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120717. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120718. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120719. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120720. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120721. 10, 9, 9,10,10, 9,10, 9, 9,
  120722. };
  120723. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120724. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120725. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120726. 6.5, 7.5, 8.5, 9.5,
  120727. };
  120728. static long _vq_quantmap__44c8_s_p8_1[] = {
  120729. 19, 17, 15, 13, 11, 9, 7, 5,
  120730. 3, 1, 0, 2, 4, 6, 8, 10,
  120731. 12, 14, 16, 18, 20,
  120732. };
  120733. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120734. _vq_quantthresh__44c8_s_p8_1,
  120735. _vq_quantmap__44c8_s_p8_1,
  120736. 21,
  120737. 21
  120738. };
  120739. static static_codebook _44c8_s_p8_1 = {
  120740. 2, 441,
  120741. _vq_lengthlist__44c8_s_p8_1,
  120742. 1, -529268736, 1611661312, 5, 0,
  120743. _vq_quantlist__44c8_s_p8_1,
  120744. NULL,
  120745. &_vq_auxt__44c8_s_p8_1,
  120746. NULL,
  120747. 0
  120748. };
  120749. static long _vq_quantlist__44c8_s_p9_0[] = {
  120750. 8,
  120751. 7,
  120752. 9,
  120753. 6,
  120754. 10,
  120755. 5,
  120756. 11,
  120757. 4,
  120758. 12,
  120759. 3,
  120760. 13,
  120761. 2,
  120762. 14,
  120763. 1,
  120764. 15,
  120765. 0,
  120766. 16,
  120767. };
  120768. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120769. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120770. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120771. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120772. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120773. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120774. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120775. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120776. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120777. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120778. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120779. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120780. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120781. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120782. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120783. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120784. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120785. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120786. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120787. 10,
  120788. };
  120789. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120790. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120791. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120792. };
  120793. static long _vq_quantmap__44c8_s_p9_0[] = {
  120794. 15, 13, 11, 9, 7, 5, 3, 1,
  120795. 0, 2, 4, 6, 8, 10, 12, 14,
  120796. 16,
  120797. };
  120798. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120799. _vq_quantthresh__44c8_s_p9_0,
  120800. _vq_quantmap__44c8_s_p9_0,
  120801. 17,
  120802. 17
  120803. };
  120804. static static_codebook _44c8_s_p9_0 = {
  120805. 2, 289,
  120806. _vq_lengthlist__44c8_s_p9_0,
  120807. 1, -509798400, 1631393792, 5, 0,
  120808. _vq_quantlist__44c8_s_p9_0,
  120809. NULL,
  120810. &_vq_auxt__44c8_s_p9_0,
  120811. NULL,
  120812. 0
  120813. };
  120814. static long _vq_quantlist__44c8_s_p9_1[] = {
  120815. 9,
  120816. 8,
  120817. 10,
  120818. 7,
  120819. 11,
  120820. 6,
  120821. 12,
  120822. 5,
  120823. 13,
  120824. 4,
  120825. 14,
  120826. 3,
  120827. 15,
  120828. 2,
  120829. 16,
  120830. 1,
  120831. 17,
  120832. 0,
  120833. 18,
  120834. };
  120835. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120836. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120837. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120838. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120839. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120840. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120841. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120842. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120843. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120844. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120845. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120846. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120847. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120848. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120849. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120850. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120851. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120852. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120853. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120854. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120855. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120856. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120857. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120858. 14,13,13,14,14,15,14,15,14,
  120859. };
  120860. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120861. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120862. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120863. 367.5, 416.5,
  120864. };
  120865. static long _vq_quantmap__44c8_s_p9_1[] = {
  120866. 17, 15, 13, 11, 9, 7, 5, 3,
  120867. 1, 0, 2, 4, 6, 8, 10, 12,
  120868. 14, 16, 18,
  120869. };
  120870. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120871. _vq_quantthresh__44c8_s_p9_1,
  120872. _vq_quantmap__44c8_s_p9_1,
  120873. 19,
  120874. 19
  120875. };
  120876. static static_codebook _44c8_s_p9_1 = {
  120877. 2, 361,
  120878. _vq_lengthlist__44c8_s_p9_1,
  120879. 1, -518287360, 1622704128, 5, 0,
  120880. _vq_quantlist__44c8_s_p9_1,
  120881. NULL,
  120882. &_vq_auxt__44c8_s_p9_1,
  120883. NULL,
  120884. 0
  120885. };
  120886. static long _vq_quantlist__44c8_s_p9_2[] = {
  120887. 24,
  120888. 23,
  120889. 25,
  120890. 22,
  120891. 26,
  120892. 21,
  120893. 27,
  120894. 20,
  120895. 28,
  120896. 19,
  120897. 29,
  120898. 18,
  120899. 30,
  120900. 17,
  120901. 31,
  120902. 16,
  120903. 32,
  120904. 15,
  120905. 33,
  120906. 14,
  120907. 34,
  120908. 13,
  120909. 35,
  120910. 12,
  120911. 36,
  120912. 11,
  120913. 37,
  120914. 10,
  120915. 38,
  120916. 9,
  120917. 39,
  120918. 8,
  120919. 40,
  120920. 7,
  120921. 41,
  120922. 6,
  120923. 42,
  120924. 5,
  120925. 43,
  120926. 4,
  120927. 44,
  120928. 3,
  120929. 45,
  120930. 2,
  120931. 46,
  120932. 1,
  120933. 47,
  120934. 0,
  120935. 48,
  120936. };
  120937. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120938. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120939. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120940. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120941. 7,
  120942. };
  120943. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120944. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120945. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120946. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120947. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120948. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120949. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120950. };
  120951. static long _vq_quantmap__44c8_s_p9_2[] = {
  120952. 47, 45, 43, 41, 39, 37, 35, 33,
  120953. 31, 29, 27, 25, 23, 21, 19, 17,
  120954. 15, 13, 11, 9, 7, 5, 3, 1,
  120955. 0, 2, 4, 6, 8, 10, 12, 14,
  120956. 16, 18, 20, 22, 24, 26, 28, 30,
  120957. 32, 34, 36, 38, 40, 42, 44, 46,
  120958. 48,
  120959. };
  120960. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120961. _vq_quantthresh__44c8_s_p9_2,
  120962. _vq_quantmap__44c8_s_p9_2,
  120963. 49,
  120964. 49
  120965. };
  120966. static static_codebook _44c8_s_p9_2 = {
  120967. 1, 49,
  120968. _vq_lengthlist__44c8_s_p9_2,
  120969. 1, -526909440, 1611661312, 6, 0,
  120970. _vq_quantlist__44c8_s_p9_2,
  120971. NULL,
  120972. &_vq_auxt__44c8_s_p9_2,
  120973. NULL,
  120974. 0
  120975. };
  120976. static long _huff_lengthlist__44c8_s_short[] = {
  120977. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120978. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120979. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120980. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120981. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120982. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120983. 10, 9,11,14,
  120984. };
  120985. static static_codebook _huff_book__44c8_s_short = {
  120986. 2, 100,
  120987. _huff_lengthlist__44c8_s_short,
  120988. 0, 0, 0, 0, 0,
  120989. NULL,
  120990. NULL,
  120991. NULL,
  120992. NULL,
  120993. 0
  120994. };
  120995. static long _huff_lengthlist__44c9_s_long[] = {
  120996. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120997. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120998. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120999. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  121000. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  121001. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  121002. 10, 9, 8, 9,
  121003. };
  121004. static static_codebook _huff_book__44c9_s_long = {
  121005. 2, 100,
  121006. _huff_lengthlist__44c9_s_long,
  121007. 0, 0, 0, 0, 0,
  121008. NULL,
  121009. NULL,
  121010. NULL,
  121011. NULL,
  121012. 0
  121013. };
  121014. static long _vq_quantlist__44c9_s_p1_0[] = {
  121015. 1,
  121016. 0,
  121017. 2,
  121018. };
  121019. static long _vq_lengthlist__44c9_s_p1_0[] = {
  121020. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  121021. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  121022. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  121023. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  121024. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  121025. 7,
  121026. };
  121027. static float _vq_quantthresh__44c9_s_p1_0[] = {
  121028. -0.5, 0.5,
  121029. };
  121030. static long _vq_quantmap__44c9_s_p1_0[] = {
  121031. 1, 0, 2,
  121032. };
  121033. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  121034. _vq_quantthresh__44c9_s_p1_0,
  121035. _vq_quantmap__44c9_s_p1_0,
  121036. 3,
  121037. 3
  121038. };
  121039. static static_codebook _44c9_s_p1_0 = {
  121040. 4, 81,
  121041. _vq_lengthlist__44c9_s_p1_0,
  121042. 1, -535822336, 1611661312, 2, 0,
  121043. _vq_quantlist__44c9_s_p1_0,
  121044. NULL,
  121045. &_vq_auxt__44c9_s_p1_0,
  121046. NULL,
  121047. 0
  121048. };
  121049. static long _vq_quantlist__44c9_s_p2_0[] = {
  121050. 2,
  121051. 1,
  121052. 3,
  121053. 0,
  121054. 4,
  121055. };
  121056. static long _vq_lengthlist__44c9_s_p2_0[] = {
  121057. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  121058. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  121059. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  121060. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  121061. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  121062. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  121063. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  121064. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  121065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121066. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  121067. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  121068. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  121069. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  121070. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  121071. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  121072. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  121073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121074. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  121075. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  121076. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  121077. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  121078. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  121079. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  121080. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121082. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  121083. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  121084. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  121085. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  121086. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  121087. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  121088. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  121093. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  121094. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  121095. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  121096. 12,
  121097. };
  121098. static float _vq_quantthresh__44c9_s_p2_0[] = {
  121099. -1.5, -0.5, 0.5, 1.5,
  121100. };
  121101. static long _vq_quantmap__44c9_s_p2_0[] = {
  121102. 3, 1, 0, 2, 4,
  121103. };
  121104. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  121105. _vq_quantthresh__44c9_s_p2_0,
  121106. _vq_quantmap__44c9_s_p2_0,
  121107. 5,
  121108. 5
  121109. };
  121110. static static_codebook _44c9_s_p2_0 = {
  121111. 4, 625,
  121112. _vq_lengthlist__44c9_s_p2_0,
  121113. 1, -533725184, 1611661312, 3, 0,
  121114. _vq_quantlist__44c9_s_p2_0,
  121115. NULL,
  121116. &_vq_auxt__44c9_s_p2_0,
  121117. NULL,
  121118. 0
  121119. };
  121120. static long _vq_quantlist__44c9_s_p3_0[] = {
  121121. 4,
  121122. 3,
  121123. 5,
  121124. 2,
  121125. 6,
  121126. 1,
  121127. 7,
  121128. 0,
  121129. 8,
  121130. };
  121131. static long _vq_lengthlist__44c9_s_p3_0[] = {
  121132. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  121133. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  121134. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  121135. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  121136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121137. 0,
  121138. };
  121139. static float _vq_quantthresh__44c9_s_p3_0[] = {
  121140. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121141. };
  121142. static long _vq_quantmap__44c9_s_p3_0[] = {
  121143. 7, 5, 3, 1, 0, 2, 4, 6,
  121144. 8,
  121145. };
  121146. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  121147. _vq_quantthresh__44c9_s_p3_0,
  121148. _vq_quantmap__44c9_s_p3_0,
  121149. 9,
  121150. 9
  121151. };
  121152. static static_codebook _44c9_s_p3_0 = {
  121153. 2, 81,
  121154. _vq_lengthlist__44c9_s_p3_0,
  121155. 1, -531628032, 1611661312, 4, 0,
  121156. _vq_quantlist__44c9_s_p3_0,
  121157. NULL,
  121158. &_vq_auxt__44c9_s_p3_0,
  121159. NULL,
  121160. 0
  121161. };
  121162. static long _vq_quantlist__44c9_s_p4_0[] = {
  121163. 8,
  121164. 7,
  121165. 9,
  121166. 6,
  121167. 10,
  121168. 5,
  121169. 11,
  121170. 4,
  121171. 12,
  121172. 3,
  121173. 13,
  121174. 2,
  121175. 14,
  121176. 1,
  121177. 15,
  121178. 0,
  121179. 16,
  121180. };
  121181. static long _vq_lengthlist__44c9_s_p4_0[] = {
  121182. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  121183. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  121184. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  121185. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  121186. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  121187. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  121188. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  121189. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  121190. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  121191. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  121192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121200. 0,
  121201. };
  121202. static float _vq_quantthresh__44c9_s_p4_0[] = {
  121203. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121204. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121205. };
  121206. static long _vq_quantmap__44c9_s_p4_0[] = {
  121207. 15, 13, 11, 9, 7, 5, 3, 1,
  121208. 0, 2, 4, 6, 8, 10, 12, 14,
  121209. 16,
  121210. };
  121211. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  121212. _vq_quantthresh__44c9_s_p4_0,
  121213. _vq_quantmap__44c9_s_p4_0,
  121214. 17,
  121215. 17
  121216. };
  121217. static static_codebook _44c9_s_p4_0 = {
  121218. 2, 289,
  121219. _vq_lengthlist__44c9_s_p4_0,
  121220. 1, -529530880, 1611661312, 5, 0,
  121221. _vq_quantlist__44c9_s_p4_0,
  121222. NULL,
  121223. &_vq_auxt__44c9_s_p4_0,
  121224. NULL,
  121225. 0
  121226. };
  121227. static long _vq_quantlist__44c9_s_p5_0[] = {
  121228. 1,
  121229. 0,
  121230. 2,
  121231. };
  121232. static long _vq_lengthlist__44c9_s_p5_0[] = {
  121233. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  121234. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  121235. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  121236. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  121237. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  121238. 12,
  121239. };
  121240. static float _vq_quantthresh__44c9_s_p5_0[] = {
  121241. -5.5, 5.5,
  121242. };
  121243. static long _vq_quantmap__44c9_s_p5_0[] = {
  121244. 1, 0, 2,
  121245. };
  121246. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  121247. _vq_quantthresh__44c9_s_p5_0,
  121248. _vq_quantmap__44c9_s_p5_0,
  121249. 3,
  121250. 3
  121251. };
  121252. static static_codebook _44c9_s_p5_0 = {
  121253. 4, 81,
  121254. _vq_lengthlist__44c9_s_p5_0,
  121255. 1, -529137664, 1618345984, 2, 0,
  121256. _vq_quantlist__44c9_s_p5_0,
  121257. NULL,
  121258. &_vq_auxt__44c9_s_p5_0,
  121259. NULL,
  121260. 0
  121261. };
  121262. static long _vq_quantlist__44c9_s_p5_1[] = {
  121263. 5,
  121264. 4,
  121265. 6,
  121266. 3,
  121267. 7,
  121268. 2,
  121269. 8,
  121270. 1,
  121271. 9,
  121272. 0,
  121273. 10,
  121274. };
  121275. static long _vq_lengthlist__44c9_s_p5_1[] = {
  121276. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  121277. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  121278. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  121279. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  121280. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  121281. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  121282. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  121283. 11,11,11, 7, 7, 7, 7, 7, 7,
  121284. };
  121285. static float _vq_quantthresh__44c9_s_p5_1[] = {
  121286. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121287. 3.5, 4.5,
  121288. };
  121289. static long _vq_quantmap__44c9_s_p5_1[] = {
  121290. 9, 7, 5, 3, 1, 0, 2, 4,
  121291. 6, 8, 10,
  121292. };
  121293. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  121294. _vq_quantthresh__44c9_s_p5_1,
  121295. _vq_quantmap__44c9_s_p5_1,
  121296. 11,
  121297. 11
  121298. };
  121299. static static_codebook _44c9_s_p5_1 = {
  121300. 2, 121,
  121301. _vq_lengthlist__44c9_s_p5_1,
  121302. 1, -531365888, 1611661312, 4, 0,
  121303. _vq_quantlist__44c9_s_p5_1,
  121304. NULL,
  121305. &_vq_auxt__44c9_s_p5_1,
  121306. NULL,
  121307. 0
  121308. };
  121309. static long _vq_quantlist__44c9_s_p6_0[] = {
  121310. 6,
  121311. 5,
  121312. 7,
  121313. 4,
  121314. 8,
  121315. 3,
  121316. 9,
  121317. 2,
  121318. 10,
  121319. 1,
  121320. 11,
  121321. 0,
  121322. 12,
  121323. };
  121324. static long _vq_lengthlist__44c9_s_p6_0[] = {
  121325. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  121326. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  121327. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  121328. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  121329. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  121330. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  121331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121335. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121336. };
  121337. static float _vq_quantthresh__44c9_s_p6_0[] = {
  121338. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  121339. 12.5, 17.5, 22.5, 27.5,
  121340. };
  121341. static long _vq_quantmap__44c9_s_p6_0[] = {
  121342. 11, 9, 7, 5, 3, 1, 0, 2,
  121343. 4, 6, 8, 10, 12,
  121344. };
  121345. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  121346. _vq_quantthresh__44c9_s_p6_0,
  121347. _vq_quantmap__44c9_s_p6_0,
  121348. 13,
  121349. 13
  121350. };
  121351. static static_codebook _44c9_s_p6_0 = {
  121352. 2, 169,
  121353. _vq_lengthlist__44c9_s_p6_0,
  121354. 1, -526516224, 1616117760, 4, 0,
  121355. _vq_quantlist__44c9_s_p6_0,
  121356. NULL,
  121357. &_vq_auxt__44c9_s_p6_0,
  121358. NULL,
  121359. 0
  121360. };
  121361. static long _vq_quantlist__44c9_s_p6_1[] = {
  121362. 2,
  121363. 1,
  121364. 3,
  121365. 0,
  121366. 4,
  121367. };
  121368. static long _vq_lengthlist__44c9_s_p6_1[] = {
  121369. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  121370. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  121371. };
  121372. static float _vq_quantthresh__44c9_s_p6_1[] = {
  121373. -1.5, -0.5, 0.5, 1.5,
  121374. };
  121375. static long _vq_quantmap__44c9_s_p6_1[] = {
  121376. 3, 1, 0, 2, 4,
  121377. };
  121378. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  121379. _vq_quantthresh__44c9_s_p6_1,
  121380. _vq_quantmap__44c9_s_p6_1,
  121381. 5,
  121382. 5
  121383. };
  121384. static static_codebook _44c9_s_p6_1 = {
  121385. 2, 25,
  121386. _vq_lengthlist__44c9_s_p6_1,
  121387. 1, -533725184, 1611661312, 3, 0,
  121388. _vq_quantlist__44c9_s_p6_1,
  121389. NULL,
  121390. &_vq_auxt__44c9_s_p6_1,
  121391. NULL,
  121392. 0
  121393. };
  121394. static long _vq_quantlist__44c9_s_p7_0[] = {
  121395. 6,
  121396. 5,
  121397. 7,
  121398. 4,
  121399. 8,
  121400. 3,
  121401. 9,
  121402. 2,
  121403. 10,
  121404. 1,
  121405. 11,
  121406. 0,
  121407. 12,
  121408. };
  121409. static long _vq_lengthlist__44c9_s_p7_0[] = {
  121410. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  121411. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  121412. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  121413. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  121414. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  121415. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  121416. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  121417. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  121418. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  121419. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  121420. 19,12,12,12,12,13,13,14,14,
  121421. };
  121422. static float _vq_quantthresh__44c9_s_p7_0[] = {
  121423. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  121424. 27.5, 38.5, 49.5, 60.5,
  121425. };
  121426. static long _vq_quantmap__44c9_s_p7_0[] = {
  121427. 11, 9, 7, 5, 3, 1, 0, 2,
  121428. 4, 6, 8, 10, 12,
  121429. };
  121430. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  121431. _vq_quantthresh__44c9_s_p7_0,
  121432. _vq_quantmap__44c9_s_p7_0,
  121433. 13,
  121434. 13
  121435. };
  121436. static static_codebook _44c9_s_p7_0 = {
  121437. 2, 169,
  121438. _vq_lengthlist__44c9_s_p7_0,
  121439. 1, -523206656, 1618345984, 4, 0,
  121440. _vq_quantlist__44c9_s_p7_0,
  121441. NULL,
  121442. &_vq_auxt__44c9_s_p7_0,
  121443. NULL,
  121444. 0
  121445. };
  121446. static long _vq_quantlist__44c9_s_p7_1[] = {
  121447. 5,
  121448. 4,
  121449. 6,
  121450. 3,
  121451. 7,
  121452. 2,
  121453. 8,
  121454. 1,
  121455. 9,
  121456. 0,
  121457. 10,
  121458. };
  121459. static long _vq_lengthlist__44c9_s_p7_1[] = {
  121460. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  121461. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121462. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  121463. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121464. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  121465. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  121466. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  121467. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121468. };
  121469. static float _vq_quantthresh__44c9_s_p7_1[] = {
  121470. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121471. 3.5, 4.5,
  121472. };
  121473. static long _vq_quantmap__44c9_s_p7_1[] = {
  121474. 9, 7, 5, 3, 1, 0, 2, 4,
  121475. 6, 8, 10,
  121476. };
  121477. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  121478. _vq_quantthresh__44c9_s_p7_1,
  121479. _vq_quantmap__44c9_s_p7_1,
  121480. 11,
  121481. 11
  121482. };
  121483. static static_codebook _44c9_s_p7_1 = {
  121484. 2, 121,
  121485. _vq_lengthlist__44c9_s_p7_1,
  121486. 1, -531365888, 1611661312, 4, 0,
  121487. _vq_quantlist__44c9_s_p7_1,
  121488. NULL,
  121489. &_vq_auxt__44c9_s_p7_1,
  121490. NULL,
  121491. 0
  121492. };
  121493. static long _vq_quantlist__44c9_s_p8_0[] = {
  121494. 7,
  121495. 6,
  121496. 8,
  121497. 5,
  121498. 9,
  121499. 4,
  121500. 10,
  121501. 3,
  121502. 11,
  121503. 2,
  121504. 12,
  121505. 1,
  121506. 13,
  121507. 0,
  121508. 14,
  121509. };
  121510. static long _vq_lengthlist__44c9_s_p8_0[] = {
  121511. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  121512. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  121513. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  121514. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  121515. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  121516. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  121517. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  121518. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  121519. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  121520. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  121521. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  121522. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  121523. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  121524. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  121525. 14,
  121526. };
  121527. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121528. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121529. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121530. };
  121531. static long _vq_quantmap__44c9_s_p8_0[] = {
  121532. 13, 11, 9, 7, 5, 3, 1, 0,
  121533. 2, 4, 6, 8, 10, 12, 14,
  121534. };
  121535. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121536. _vq_quantthresh__44c9_s_p8_0,
  121537. _vq_quantmap__44c9_s_p8_0,
  121538. 15,
  121539. 15
  121540. };
  121541. static static_codebook _44c9_s_p8_0 = {
  121542. 2, 225,
  121543. _vq_lengthlist__44c9_s_p8_0,
  121544. 1, -520986624, 1620377600, 4, 0,
  121545. _vq_quantlist__44c9_s_p8_0,
  121546. NULL,
  121547. &_vq_auxt__44c9_s_p8_0,
  121548. NULL,
  121549. 0
  121550. };
  121551. static long _vq_quantlist__44c9_s_p8_1[] = {
  121552. 10,
  121553. 9,
  121554. 11,
  121555. 8,
  121556. 12,
  121557. 7,
  121558. 13,
  121559. 6,
  121560. 14,
  121561. 5,
  121562. 15,
  121563. 4,
  121564. 16,
  121565. 3,
  121566. 17,
  121567. 2,
  121568. 18,
  121569. 1,
  121570. 19,
  121571. 0,
  121572. 20,
  121573. };
  121574. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121575. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121576. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121577. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121578. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121579. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121580. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121581. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121582. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121583. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121584. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121585. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121586. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121587. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121588. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121589. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121590. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121591. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121592. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121593. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121594. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121595. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121596. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121597. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121598. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121599. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121600. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121601. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121602. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121603. };
  121604. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121605. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121606. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121607. 6.5, 7.5, 8.5, 9.5,
  121608. };
  121609. static long _vq_quantmap__44c9_s_p8_1[] = {
  121610. 19, 17, 15, 13, 11, 9, 7, 5,
  121611. 3, 1, 0, 2, 4, 6, 8, 10,
  121612. 12, 14, 16, 18, 20,
  121613. };
  121614. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121615. _vq_quantthresh__44c9_s_p8_1,
  121616. _vq_quantmap__44c9_s_p8_1,
  121617. 21,
  121618. 21
  121619. };
  121620. static static_codebook _44c9_s_p8_1 = {
  121621. 2, 441,
  121622. _vq_lengthlist__44c9_s_p8_1,
  121623. 1, -529268736, 1611661312, 5, 0,
  121624. _vq_quantlist__44c9_s_p8_1,
  121625. NULL,
  121626. &_vq_auxt__44c9_s_p8_1,
  121627. NULL,
  121628. 0
  121629. };
  121630. static long _vq_quantlist__44c9_s_p9_0[] = {
  121631. 9,
  121632. 8,
  121633. 10,
  121634. 7,
  121635. 11,
  121636. 6,
  121637. 12,
  121638. 5,
  121639. 13,
  121640. 4,
  121641. 14,
  121642. 3,
  121643. 15,
  121644. 2,
  121645. 16,
  121646. 1,
  121647. 17,
  121648. 0,
  121649. 18,
  121650. };
  121651. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121652. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121653. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121654. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121655. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121656. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121657. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121658. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121659. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121660. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121661. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121662. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121663. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121664. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121665. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121666. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121667. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121668. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121669. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121670. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121671. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121672. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121673. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121674. 11,11,11,11,11,11,11,11,11,
  121675. };
  121676. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121677. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121678. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121679. 6982.5, 7913.5,
  121680. };
  121681. static long _vq_quantmap__44c9_s_p9_0[] = {
  121682. 17, 15, 13, 11, 9, 7, 5, 3,
  121683. 1, 0, 2, 4, 6, 8, 10, 12,
  121684. 14, 16, 18,
  121685. };
  121686. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121687. _vq_quantthresh__44c9_s_p9_0,
  121688. _vq_quantmap__44c9_s_p9_0,
  121689. 19,
  121690. 19
  121691. };
  121692. static static_codebook _44c9_s_p9_0 = {
  121693. 2, 361,
  121694. _vq_lengthlist__44c9_s_p9_0,
  121695. 1, -508535424, 1631393792, 5, 0,
  121696. _vq_quantlist__44c9_s_p9_0,
  121697. NULL,
  121698. &_vq_auxt__44c9_s_p9_0,
  121699. NULL,
  121700. 0
  121701. };
  121702. static long _vq_quantlist__44c9_s_p9_1[] = {
  121703. 9,
  121704. 8,
  121705. 10,
  121706. 7,
  121707. 11,
  121708. 6,
  121709. 12,
  121710. 5,
  121711. 13,
  121712. 4,
  121713. 14,
  121714. 3,
  121715. 15,
  121716. 2,
  121717. 16,
  121718. 1,
  121719. 17,
  121720. 0,
  121721. 18,
  121722. };
  121723. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121724. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121725. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121726. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121727. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121728. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121729. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121730. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121731. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121732. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121733. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121734. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121735. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121736. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121737. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121738. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121739. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121740. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121741. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121742. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121743. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121744. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121745. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121746. 13,13,13,14,13,14,15,15,15,
  121747. };
  121748. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121749. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121750. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121751. 367.5, 416.5,
  121752. };
  121753. static long _vq_quantmap__44c9_s_p9_1[] = {
  121754. 17, 15, 13, 11, 9, 7, 5, 3,
  121755. 1, 0, 2, 4, 6, 8, 10, 12,
  121756. 14, 16, 18,
  121757. };
  121758. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121759. _vq_quantthresh__44c9_s_p9_1,
  121760. _vq_quantmap__44c9_s_p9_1,
  121761. 19,
  121762. 19
  121763. };
  121764. static static_codebook _44c9_s_p9_1 = {
  121765. 2, 361,
  121766. _vq_lengthlist__44c9_s_p9_1,
  121767. 1, -518287360, 1622704128, 5, 0,
  121768. _vq_quantlist__44c9_s_p9_1,
  121769. NULL,
  121770. &_vq_auxt__44c9_s_p9_1,
  121771. NULL,
  121772. 0
  121773. };
  121774. static long _vq_quantlist__44c9_s_p9_2[] = {
  121775. 24,
  121776. 23,
  121777. 25,
  121778. 22,
  121779. 26,
  121780. 21,
  121781. 27,
  121782. 20,
  121783. 28,
  121784. 19,
  121785. 29,
  121786. 18,
  121787. 30,
  121788. 17,
  121789. 31,
  121790. 16,
  121791. 32,
  121792. 15,
  121793. 33,
  121794. 14,
  121795. 34,
  121796. 13,
  121797. 35,
  121798. 12,
  121799. 36,
  121800. 11,
  121801. 37,
  121802. 10,
  121803. 38,
  121804. 9,
  121805. 39,
  121806. 8,
  121807. 40,
  121808. 7,
  121809. 41,
  121810. 6,
  121811. 42,
  121812. 5,
  121813. 43,
  121814. 4,
  121815. 44,
  121816. 3,
  121817. 45,
  121818. 2,
  121819. 46,
  121820. 1,
  121821. 47,
  121822. 0,
  121823. 48,
  121824. };
  121825. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121826. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121827. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121828. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121829. 7,
  121830. };
  121831. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121832. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121833. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121834. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121835. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121836. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121837. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121838. };
  121839. static long _vq_quantmap__44c9_s_p9_2[] = {
  121840. 47, 45, 43, 41, 39, 37, 35, 33,
  121841. 31, 29, 27, 25, 23, 21, 19, 17,
  121842. 15, 13, 11, 9, 7, 5, 3, 1,
  121843. 0, 2, 4, 6, 8, 10, 12, 14,
  121844. 16, 18, 20, 22, 24, 26, 28, 30,
  121845. 32, 34, 36, 38, 40, 42, 44, 46,
  121846. 48,
  121847. };
  121848. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121849. _vq_quantthresh__44c9_s_p9_2,
  121850. _vq_quantmap__44c9_s_p9_2,
  121851. 49,
  121852. 49
  121853. };
  121854. static static_codebook _44c9_s_p9_2 = {
  121855. 1, 49,
  121856. _vq_lengthlist__44c9_s_p9_2,
  121857. 1, -526909440, 1611661312, 6, 0,
  121858. _vq_quantlist__44c9_s_p9_2,
  121859. NULL,
  121860. &_vq_auxt__44c9_s_p9_2,
  121861. NULL,
  121862. 0
  121863. };
  121864. static long _huff_lengthlist__44c9_s_short[] = {
  121865. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121866. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121867. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121868. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121869. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121870. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121871. 9, 8,10,13,
  121872. };
  121873. static static_codebook _huff_book__44c9_s_short = {
  121874. 2, 100,
  121875. _huff_lengthlist__44c9_s_short,
  121876. 0, 0, 0, 0, 0,
  121877. NULL,
  121878. NULL,
  121879. NULL,
  121880. NULL,
  121881. 0
  121882. };
  121883. static long _huff_lengthlist__44c0_s_long[] = {
  121884. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121885. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121886. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121887. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121888. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121889. 12,
  121890. };
  121891. static static_codebook _huff_book__44c0_s_long = {
  121892. 2, 81,
  121893. _huff_lengthlist__44c0_s_long,
  121894. 0, 0, 0, 0, 0,
  121895. NULL,
  121896. NULL,
  121897. NULL,
  121898. NULL,
  121899. 0
  121900. };
  121901. static long _vq_quantlist__44c0_s_p1_0[] = {
  121902. 1,
  121903. 0,
  121904. 2,
  121905. };
  121906. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121907. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121908. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121913. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121917. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121918. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 7, 0, 0, 0, 0,
  121953. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  121958. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  121963. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121999. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  122004. 0, 0, 0, 0, 0, 9, 9,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  122009. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  122010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122317. 0,
  122318. };
  122319. static float _vq_quantthresh__44c0_s_p1_0[] = {
  122320. -0.5, 0.5,
  122321. };
  122322. static long _vq_quantmap__44c0_s_p1_0[] = {
  122323. 1, 0, 2,
  122324. };
  122325. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  122326. _vq_quantthresh__44c0_s_p1_0,
  122327. _vq_quantmap__44c0_s_p1_0,
  122328. 3,
  122329. 3
  122330. };
  122331. static static_codebook _44c0_s_p1_0 = {
  122332. 8, 6561,
  122333. _vq_lengthlist__44c0_s_p1_0,
  122334. 1, -535822336, 1611661312, 2, 0,
  122335. _vq_quantlist__44c0_s_p1_0,
  122336. NULL,
  122337. &_vq_auxt__44c0_s_p1_0,
  122338. NULL,
  122339. 0
  122340. };
  122341. static long _vq_quantlist__44c0_s_p2_0[] = {
  122342. 2,
  122343. 1,
  122344. 3,
  122345. 0,
  122346. 4,
  122347. };
  122348. static long _vq_lengthlist__44c0_s_p2_0[] = {
  122349. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  122351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122352. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122355. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122388. 0,
  122389. };
  122390. static float _vq_quantthresh__44c0_s_p2_0[] = {
  122391. -1.5, -0.5, 0.5, 1.5,
  122392. };
  122393. static long _vq_quantmap__44c0_s_p2_0[] = {
  122394. 3, 1, 0, 2, 4,
  122395. };
  122396. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  122397. _vq_quantthresh__44c0_s_p2_0,
  122398. _vq_quantmap__44c0_s_p2_0,
  122399. 5,
  122400. 5
  122401. };
  122402. static static_codebook _44c0_s_p2_0 = {
  122403. 4, 625,
  122404. _vq_lengthlist__44c0_s_p2_0,
  122405. 1, -533725184, 1611661312, 3, 0,
  122406. _vq_quantlist__44c0_s_p2_0,
  122407. NULL,
  122408. &_vq_auxt__44c0_s_p2_0,
  122409. NULL,
  122410. 0
  122411. };
  122412. static long _vq_quantlist__44c0_s_p3_0[] = {
  122413. 4,
  122414. 3,
  122415. 5,
  122416. 2,
  122417. 6,
  122418. 1,
  122419. 7,
  122420. 0,
  122421. 8,
  122422. };
  122423. static long _vq_lengthlist__44c0_s_p3_0[] = {
  122424. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  122425. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  122426. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  122427. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  122428. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122429. 0,
  122430. };
  122431. static float _vq_quantthresh__44c0_s_p3_0[] = {
  122432. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122433. };
  122434. static long _vq_quantmap__44c0_s_p3_0[] = {
  122435. 7, 5, 3, 1, 0, 2, 4, 6,
  122436. 8,
  122437. };
  122438. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  122439. _vq_quantthresh__44c0_s_p3_0,
  122440. _vq_quantmap__44c0_s_p3_0,
  122441. 9,
  122442. 9
  122443. };
  122444. static static_codebook _44c0_s_p3_0 = {
  122445. 2, 81,
  122446. _vq_lengthlist__44c0_s_p3_0,
  122447. 1, -531628032, 1611661312, 4, 0,
  122448. _vq_quantlist__44c0_s_p3_0,
  122449. NULL,
  122450. &_vq_auxt__44c0_s_p3_0,
  122451. NULL,
  122452. 0
  122453. };
  122454. static long _vq_quantlist__44c0_s_p4_0[] = {
  122455. 4,
  122456. 3,
  122457. 5,
  122458. 2,
  122459. 6,
  122460. 1,
  122461. 7,
  122462. 0,
  122463. 8,
  122464. };
  122465. static long _vq_lengthlist__44c0_s_p4_0[] = {
  122466. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  122467. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  122468. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  122469. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  122470. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  122471. 10,
  122472. };
  122473. static float _vq_quantthresh__44c0_s_p4_0[] = {
  122474. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122475. };
  122476. static long _vq_quantmap__44c0_s_p4_0[] = {
  122477. 7, 5, 3, 1, 0, 2, 4, 6,
  122478. 8,
  122479. };
  122480. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  122481. _vq_quantthresh__44c0_s_p4_0,
  122482. _vq_quantmap__44c0_s_p4_0,
  122483. 9,
  122484. 9
  122485. };
  122486. static static_codebook _44c0_s_p4_0 = {
  122487. 2, 81,
  122488. _vq_lengthlist__44c0_s_p4_0,
  122489. 1, -531628032, 1611661312, 4, 0,
  122490. _vq_quantlist__44c0_s_p4_0,
  122491. NULL,
  122492. &_vq_auxt__44c0_s_p4_0,
  122493. NULL,
  122494. 0
  122495. };
  122496. static long _vq_quantlist__44c0_s_p5_0[] = {
  122497. 8,
  122498. 7,
  122499. 9,
  122500. 6,
  122501. 10,
  122502. 5,
  122503. 11,
  122504. 4,
  122505. 12,
  122506. 3,
  122507. 13,
  122508. 2,
  122509. 14,
  122510. 1,
  122511. 15,
  122512. 0,
  122513. 16,
  122514. };
  122515. static long _vq_lengthlist__44c0_s_p5_0[] = {
  122516. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  122517. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  122518. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122519. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  122520. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  122521. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  122522. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  122523. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122524. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  122525. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122526. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122527. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122528. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122529. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122530. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122531. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122532. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122533. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122534. 14,
  122535. };
  122536. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122537. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122538. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122539. };
  122540. static long _vq_quantmap__44c0_s_p5_0[] = {
  122541. 15, 13, 11, 9, 7, 5, 3, 1,
  122542. 0, 2, 4, 6, 8, 10, 12, 14,
  122543. 16,
  122544. };
  122545. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122546. _vq_quantthresh__44c0_s_p5_0,
  122547. _vq_quantmap__44c0_s_p5_0,
  122548. 17,
  122549. 17
  122550. };
  122551. static static_codebook _44c0_s_p5_0 = {
  122552. 2, 289,
  122553. _vq_lengthlist__44c0_s_p5_0,
  122554. 1, -529530880, 1611661312, 5, 0,
  122555. _vq_quantlist__44c0_s_p5_0,
  122556. NULL,
  122557. &_vq_auxt__44c0_s_p5_0,
  122558. NULL,
  122559. 0
  122560. };
  122561. static long _vq_quantlist__44c0_s_p6_0[] = {
  122562. 1,
  122563. 0,
  122564. 2,
  122565. };
  122566. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122567. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122568. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122569. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122570. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122571. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122572. 10,
  122573. };
  122574. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122575. -5.5, 5.5,
  122576. };
  122577. static long _vq_quantmap__44c0_s_p6_0[] = {
  122578. 1, 0, 2,
  122579. };
  122580. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122581. _vq_quantthresh__44c0_s_p6_0,
  122582. _vq_quantmap__44c0_s_p6_0,
  122583. 3,
  122584. 3
  122585. };
  122586. static static_codebook _44c0_s_p6_0 = {
  122587. 4, 81,
  122588. _vq_lengthlist__44c0_s_p6_0,
  122589. 1, -529137664, 1618345984, 2, 0,
  122590. _vq_quantlist__44c0_s_p6_0,
  122591. NULL,
  122592. &_vq_auxt__44c0_s_p6_0,
  122593. NULL,
  122594. 0
  122595. };
  122596. static long _vq_quantlist__44c0_s_p6_1[] = {
  122597. 5,
  122598. 4,
  122599. 6,
  122600. 3,
  122601. 7,
  122602. 2,
  122603. 8,
  122604. 1,
  122605. 9,
  122606. 0,
  122607. 10,
  122608. };
  122609. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122610. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122611. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122612. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122613. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122614. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122615. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122616. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122617. 10,10,10, 8, 8, 8, 8, 8, 8,
  122618. };
  122619. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122620. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122621. 3.5, 4.5,
  122622. };
  122623. static long _vq_quantmap__44c0_s_p6_1[] = {
  122624. 9, 7, 5, 3, 1, 0, 2, 4,
  122625. 6, 8, 10,
  122626. };
  122627. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122628. _vq_quantthresh__44c0_s_p6_1,
  122629. _vq_quantmap__44c0_s_p6_1,
  122630. 11,
  122631. 11
  122632. };
  122633. static static_codebook _44c0_s_p6_1 = {
  122634. 2, 121,
  122635. _vq_lengthlist__44c0_s_p6_1,
  122636. 1, -531365888, 1611661312, 4, 0,
  122637. _vq_quantlist__44c0_s_p6_1,
  122638. NULL,
  122639. &_vq_auxt__44c0_s_p6_1,
  122640. NULL,
  122641. 0
  122642. };
  122643. static long _vq_quantlist__44c0_s_p7_0[] = {
  122644. 6,
  122645. 5,
  122646. 7,
  122647. 4,
  122648. 8,
  122649. 3,
  122650. 9,
  122651. 2,
  122652. 10,
  122653. 1,
  122654. 11,
  122655. 0,
  122656. 12,
  122657. };
  122658. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122659. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122660. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122661. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122662. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122663. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122664. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122665. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122666. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122667. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122668. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122669. 0,12,12,11,11,12,12,13,13,
  122670. };
  122671. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122672. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122673. 12.5, 17.5, 22.5, 27.5,
  122674. };
  122675. static long _vq_quantmap__44c0_s_p7_0[] = {
  122676. 11, 9, 7, 5, 3, 1, 0, 2,
  122677. 4, 6, 8, 10, 12,
  122678. };
  122679. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122680. _vq_quantthresh__44c0_s_p7_0,
  122681. _vq_quantmap__44c0_s_p7_0,
  122682. 13,
  122683. 13
  122684. };
  122685. static static_codebook _44c0_s_p7_0 = {
  122686. 2, 169,
  122687. _vq_lengthlist__44c0_s_p7_0,
  122688. 1, -526516224, 1616117760, 4, 0,
  122689. _vq_quantlist__44c0_s_p7_0,
  122690. NULL,
  122691. &_vq_auxt__44c0_s_p7_0,
  122692. NULL,
  122693. 0
  122694. };
  122695. static long _vq_quantlist__44c0_s_p7_1[] = {
  122696. 2,
  122697. 1,
  122698. 3,
  122699. 0,
  122700. 4,
  122701. };
  122702. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122703. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122704. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122705. };
  122706. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122707. -1.5, -0.5, 0.5, 1.5,
  122708. };
  122709. static long _vq_quantmap__44c0_s_p7_1[] = {
  122710. 3, 1, 0, 2, 4,
  122711. };
  122712. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122713. _vq_quantthresh__44c0_s_p7_1,
  122714. _vq_quantmap__44c0_s_p7_1,
  122715. 5,
  122716. 5
  122717. };
  122718. static static_codebook _44c0_s_p7_1 = {
  122719. 2, 25,
  122720. _vq_lengthlist__44c0_s_p7_1,
  122721. 1, -533725184, 1611661312, 3, 0,
  122722. _vq_quantlist__44c0_s_p7_1,
  122723. NULL,
  122724. &_vq_auxt__44c0_s_p7_1,
  122725. NULL,
  122726. 0
  122727. };
  122728. static long _vq_quantlist__44c0_s_p8_0[] = {
  122729. 2,
  122730. 1,
  122731. 3,
  122732. 0,
  122733. 4,
  122734. };
  122735. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122736. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122737. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122738. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122739. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122740. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122741. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122742. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122743. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122744. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122745. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122746. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122747. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122748. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122749. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122750. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122751. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122752. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122753. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122754. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122755. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122756. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122757. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122758. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122759. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122760. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122761. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122762. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122763. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122764. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122765. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122766. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122767. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122768. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122769. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122770. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122771. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122772. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122773. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122774. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122775. 11,
  122776. };
  122777. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122778. -331.5, -110.5, 110.5, 331.5,
  122779. };
  122780. static long _vq_quantmap__44c0_s_p8_0[] = {
  122781. 3, 1, 0, 2, 4,
  122782. };
  122783. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122784. _vq_quantthresh__44c0_s_p8_0,
  122785. _vq_quantmap__44c0_s_p8_0,
  122786. 5,
  122787. 5
  122788. };
  122789. static static_codebook _44c0_s_p8_0 = {
  122790. 4, 625,
  122791. _vq_lengthlist__44c0_s_p8_0,
  122792. 1, -518283264, 1627103232, 3, 0,
  122793. _vq_quantlist__44c0_s_p8_0,
  122794. NULL,
  122795. &_vq_auxt__44c0_s_p8_0,
  122796. NULL,
  122797. 0
  122798. };
  122799. static long _vq_quantlist__44c0_s_p8_1[] = {
  122800. 6,
  122801. 5,
  122802. 7,
  122803. 4,
  122804. 8,
  122805. 3,
  122806. 9,
  122807. 2,
  122808. 10,
  122809. 1,
  122810. 11,
  122811. 0,
  122812. 12,
  122813. };
  122814. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122815. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122816. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122817. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122818. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122819. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122820. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122821. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122822. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122823. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122824. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122825. 16,13,13,12,12,14,14,15,13,
  122826. };
  122827. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122828. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122829. 42.5, 59.5, 76.5, 93.5,
  122830. };
  122831. static long _vq_quantmap__44c0_s_p8_1[] = {
  122832. 11, 9, 7, 5, 3, 1, 0, 2,
  122833. 4, 6, 8, 10, 12,
  122834. };
  122835. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122836. _vq_quantthresh__44c0_s_p8_1,
  122837. _vq_quantmap__44c0_s_p8_1,
  122838. 13,
  122839. 13
  122840. };
  122841. static static_codebook _44c0_s_p8_1 = {
  122842. 2, 169,
  122843. _vq_lengthlist__44c0_s_p8_1,
  122844. 1, -522616832, 1620115456, 4, 0,
  122845. _vq_quantlist__44c0_s_p8_1,
  122846. NULL,
  122847. &_vq_auxt__44c0_s_p8_1,
  122848. NULL,
  122849. 0
  122850. };
  122851. static long _vq_quantlist__44c0_s_p8_2[] = {
  122852. 8,
  122853. 7,
  122854. 9,
  122855. 6,
  122856. 10,
  122857. 5,
  122858. 11,
  122859. 4,
  122860. 12,
  122861. 3,
  122862. 13,
  122863. 2,
  122864. 14,
  122865. 1,
  122866. 15,
  122867. 0,
  122868. 16,
  122869. };
  122870. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122871. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122872. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122873. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122874. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122875. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122876. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122877. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122878. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122879. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122880. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122881. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122882. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122883. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122884. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122885. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122886. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122887. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122888. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122889. 10,
  122890. };
  122891. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122892. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122893. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122894. };
  122895. static long _vq_quantmap__44c0_s_p8_2[] = {
  122896. 15, 13, 11, 9, 7, 5, 3, 1,
  122897. 0, 2, 4, 6, 8, 10, 12, 14,
  122898. 16,
  122899. };
  122900. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122901. _vq_quantthresh__44c0_s_p8_2,
  122902. _vq_quantmap__44c0_s_p8_2,
  122903. 17,
  122904. 17
  122905. };
  122906. static static_codebook _44c0_s_p8_2 = {
  122907. 2, 289,
  122908. _vq_lengthlist__44c0_s_p8_2,
  122909. 1, -529530880, 1611661312, 5, 0,
  122910. _vq_quantlist__44c0_s_p8_2,
  122911. NULL,
  122912. &_vq_auxt__44c0_s_p8_2,
  122913. NULL,
  122914. 0
  122915. };
  122916. static long _huff_lengthlist__44c0_s_short[] = {
  122917. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122918. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122919. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122920. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122921. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122922. 12,
  122923. };
  122924. static static_codebook _huff_book__44c0_s_short = {
  122925. 2, 81,
  122926. _huff_lengthlist__44c0_s_short,
  122927. 0, 0, 0, 0, 0,
  122928. NULL,
  122929. NULL,
  122930. NULL,
  122931. NULL,
  122932. 0
  122933. };
  122934. static long _huff_lengthlist__44c0_sm_long[] = {
  122935. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122936. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122937. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122938. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122939. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122940. 13,
  122941. };
  122942. static static_codebook _huff_book__44c0_sm_long = {
  122943. 2, 81,
  122944. _huff_lengthlist__44c0_sm_long,
  122945. 0, 0, 0, 0, 0,
  122946. NULL,
  122947. NULL,
  122948. NULL,
  122949. NULL,
  122950. 0
  122951. };
  122952. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122953. 1,
  122954. 0,
  122955. 2,
  122956. };
  122957. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122958. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122959. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122964. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122968. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122969. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 7, 0, 0, 0, 0,
  123004. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  123009. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  123014. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  123050. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  123055. 0, 0, 0, 0, 0, 9, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  123060. 0, 0, 0, 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 0,
  123061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123368. 0,
  123369. };
  123370. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  123371. -0.5, 0.5,
  123372. };
  123373. static long _vq_quantmap__44c0_sm_p1_0[] = {
  123374. 1, 0, 2,
  123375. };
  123376. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  123377. _vq_quantthresh__44c0_sm_p1_0,
  123378. _vq_quantmap__44c0_sm_p1_0,
  123379. 3,
  123380. 3
  123381. };
  123382. static static_codebook _44c0_sm_p1_0 = {
  123383. 8, 6561,
  123384. _vq_lengthlist__44c0_sm_p1_0,
  123385. 1, -535822336, 1611661312, 2, 0,
  123386. _vq_quantlist__44c0_sm_p1_0,
  123387. NULL,
  123388. &_vq_auxt__44c0_sm_p1_0,
  123389. NULL,
  123390. 0
  123391. };
  123392. static long _vq_quantlist__44c0_sm_p2_0[] = {
  123393. 2,
  123394. 1,
  123395. 3,
  123396. 0,
  123397. 4,
  123398. };
  123399. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  123400. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  123402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123403. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  123405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123406. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123439. 0,
  123440. };
  123441. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  123442. -1.5, -0.5, 0.5, 1.5,
  123443. };
  123444. static long _vq_quantmap__44c0_sm_p2_0[] = {
  123445. 3, 1, 0, 2, 4,
  123446. };
  123447. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  123448. _vq_quantthresh__44c0_sm_p2_0,
  123449. _vq_quantmap__44c0_sm_p2_0,
  123450. 5,
  123451. 5
  123452. };
  123453. static static_codebook _44c0_sm_p2_0 = {
  123454. 4, 625,
  123455. _vq_lengthlist__44c0_sm_p2_0,
  123456. 1, -533725184, 1611661312, 3, 0,
  123457. _vq_quantlist__44c0_sm_p2_0,
  123458. NULL,
  123459. &_vq_auxt__44c0_sm_p2_0,
  123460. NULL,
  123461. 0
  123462. };
  123463. static long _vq_quantlist__44c0_sm_p3_0[] = {
  123464. 4,
  123465. 3,
  123466. 5,
  123467. 2,
  123468. 6,
  123469. 1,
  123470. 7,
  123471. 0,
  123472. 8,
  123473. };
  123474. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  123475. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  123476. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  123477. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123478. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  123479. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123480. 0,
  123481. };
  123482. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  123483. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123484. };
  123485. static long _vq_quantmap__44c0_sm_p3_0[] = {
  123486. 7, 5, 3, 1, 0, 2, 4, 6,
  123487. 8,
  123488. };
  123489. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  123490. _vq_quantthresh__44c0_sm_p3_0,
  123491. _vq_quantmap__44c0_sm_p3_0,
  123492. 9,
  123493. 9
  123494. };
  123495. static static_codebook _44c0_sm_p3_0 = {
  123496. 2, 81,
  123497. _vq_lengthlist__44c0_sm_p3_0,
  123498. 1, -531628032, 1611661312, 4, 0,
  123499. _vq_quantlist__44c0_sm_p3_0,
  123500. NULL,
  123501. &_vq_auxt__44c0_sm_p3_0,
  123502. NULL,
  123503. 0
  123504. };
  123505. static long _vq_quantlist__44c0_sm_p4_0[] = {
  123506. 4,
  123507. 3,
  123508. 5,
  123509. 2,
  123510. 6,
  123511. 1,
  123512. 7,
  123513. 0,
  123514. 8,
  123515. };
  123516. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  123517. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  123518. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  123519. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  123520. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  123521. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123522. 11,
  123523. };
  123524. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  123525. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123526. };
  123527. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123528. 7, 5, 3, 1, 0, 2, 4, 6,
  123529. 8,
  123530. };
  123531. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123532. _vq_quantthresh__44c0_sm_p4_0,
  123533. _vq_quantmap__44c0_sm_p4_0,
  123534. 9,
  123535. 9
  123536. };
  123537. static static_codebook _44c0_sm_p4_0 = {
  123538. 2, 81,
  123539. _vq_lengthlist__44c0_sm_p4_0,
  123540. 1, -531628032, 1611661312, 4, 0,
  123541. _vq_quantlist__44c0_sm_p4_0,
  123542. NULL,
  123543. &_vq_auxt__44c0_sm_p4_0,
  123544. NULL,
  123545. 0
  123546. };
  123547. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123548. 8,
  123549. 7,
  123550. 9,
  123551. 6,
  123552. 10,
  123553. 5,
  123554. 11,
  123555. 4,
  123556. 12,
  123557. 3,
  123558. 13,
  123559. 2,
  123560. 14,
  123561. 1,
  123562. 15,
  123563. 0,
  123564. 16,
  123565. };
  123566. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123567. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123568. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123569. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123570. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123571. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123572. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123573. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123574. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123575. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123576. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123577. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123578. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123579. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123580. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123581. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123582. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123583. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123584. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123585. 14,
  123586. };
  123587. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123588. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123589. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123590. };
  123591. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123592. 15, 13, 11, 9, 7, 5, 3, 1,
  123593. 0, 2, 4, 6, 8, 10, 12, 14,
  123594. 16,
  123595. };
  123596. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123597. _vq_quantthresh__44c0_sm_p5_0,
  123598. _vq_quantmap__44c0_sm_p5_0,
  123599. 17,
  123600. 17
  123601. };
  123602. static static_codebook _44c0_sm_p5_0 = {
  123603. 2, 289,
  123604. _vq_lengthlist__44c0_sm_p5_0,
  123605. 1, -529530880, 1611661312, 5, 0,
  123606. _vq_quantlist__44c0_sm_p5_0,
  123607. NULL,
  123608. &_vq_auxt__44c0_sm_p5_0,
  123609. NULL,
  123610. 0
  123611. };
  123612. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123613. 1,
  123614. 0,
  123615. 2,
  123616. };
  123617. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123618. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123619. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123620. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123621. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123622. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123623. 11,
  123624. };
  123625. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123626. -5.5, 5.5,
  123627. };
  123628. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123629. 1, 0, 2,
  123630. };
  123631. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123632. _vq_quantthresh__44c0_sm_p6_0,
  123633. _vq_quantmap__44c0_sm_p6_0,
  123634. 3,
  123635. 3
  123636. };
  123637. static static_codebook _44c0_sm_p6_0 = {
  123638. 4, 81,
  123639. _vq_lengthlist__44c0_sm_p6_0,
  123640. 1, -529137664, 1618345984, 2, 0,
  123641. _vq_quantlist__44c0_sm_p6_0,
  123642. NULL,
  123643. &_vq_auxt__44c0_sm_p6_0,
  123644. NULL,
  123645. 0
  123646. };
  123647. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123648. 5,
  123649. 4,
  123650. 6,
  123651. 3,
  123652. 7,
  123653. 2,
  123654. 8,
  123655. 1,
  123656. 9,
  123657. 0,
  123658. 10,
  123659. };
  123660. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123661. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123662. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123663. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123664. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123665. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123666. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123667. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123668. 10,10,10, 8, 8, 8, 8, 8, 8,
  123669. };
  123670. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123671. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123672. 3.5, 4.5,
  123673. };
  123674. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123675. 9, 7, 5, 3, 1, 0, 2, 4,
  123676. 6, 8, 10,
  123677. };
  123678. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123679. _vq_quantthresh__44c0_sm_p6_1,
  123680. _vq_quantmap__44c0_sm_p6_1,
  123681. 11,
  123682. 11
  123683. };
  123684. static static_codebook _44c0_sm_p6_1 = {
  123685. 2, 121,
  123686. _vq_lengthlist__44c0_sm_p6_1,
  123687. 1, -531365888, 1611661312, 4, 0,
  123688. _vq_quantlist__44c0_sm_p6_1,
  123689. NULL,
  123690. &_vq_auxt__44c0_sm_p6_1,
  123691. NULL,
  123692. 0
  123693. };
  123694. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123695. 6,
  123696. 5,
  123697. 7,
  123698. 4,
  123699. 8,
  123700. 3,
  123701. 9,
  123702. 2,
  123703. 10,
  123704. 1,
  123705. 11,
  123706. 0,
  123707. 12,
  123708. };
  123709. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123710. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123711. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123712. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123713. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123714. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123715. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123716. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123717. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123718. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123719. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123720. 0,12,12,11,11,13,12,14,14,
  123721. };
  123722. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123723. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123724. 12.5, 17.5, 22.5, 27.5,
  123725. };
  123726. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123727. 11, 9, 7, 5, 3, 1, 0, 2,
  123728. 4, 6, 8, 10, 12,
  123729. };
  123730. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123731. _vq_quantthresh__44c0_sm_p7_0,
  123732. _vq_quantmap__44c0_sm_p7_0,
  123733. 13,
  123734. 13
  123735. };
  123736. static static_codebook _44c0_sm_p7_0 = {
  123737. 2, 169,
  123738. _vq_lengthlist__44c0_sm_p7_0,
  123739. 1, -526516224, 1616117760, 4, 0,
  123740. _vq_quantlist__44c0_sm_p7_0,
  123741. NULL,
  123742. &_vq_auxt__44c0_sm_p7_0,
  123743. NULL,
  123744. 0
  123745. };
  123746. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123747. 2,
  123748. 1,
  123749. 3,
  123750. 0,
  123751. 4,
  123752. };
  123753. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123754. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123755. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123756. };
  123757. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123758. -1.5, -0.5, 0.5, 1.5,
  123759. };
  123760. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123761. 3, 1, 0, 2, 4,
  123762. };
  123763. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123764. _vq_quantthresh__44c0_sm_p7_1,
  123765. _vq_quantmap__44c0_sm_p7_1,
  123766. 5,
  123767. 5
  123768. };
  123769. static static_codebook _44c0_sm_p7_1 = {
  123770. 2, 25,
  123771. _vq_lengthlist__44c0_sm_p7_1,
  123772. 1, -533725184, 1611661312, 3, 0,
  123773. _vq_quantlist__44c0_sm_p7_1,
  123774. NULL,
  123775. &_vq_auxt__44c0_sm_p7_1,
  123776. NULL,
  123777. 0
  123778. };
  123779. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123780. 4,
  123781. 3,
  123782. 5,
  123783. 2,
  123784. 6,
  123785. 1,
  123786. 7,
  123787. 0,
  123788. 8,
  123789. };
  123790. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123791. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123792. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123793. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123794. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123795. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123796. 12,
  123797. };
  123798. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123799. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123800. };
  123801. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123802. 7, 5, 3, 1, 0, 2, 4, 6,
  123803. 8,
  123804. };
  123805. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123806. _vq_quantthresh__44c0_sm_p8_0,
  123807. _vq_quantmap__44c0_sm_p8_0,
  123808. 9,
  123809. 9
  123810. };
  123811. static static_codebook _44c0_sm_p8_0 = {
  123812. 2, 81,
  123813. _vq_lengthlist__44c0_sm_p8_0,
  123814. 1, -516186112, 1627103232, 4, 0,
  123815. _vq_quantlist__44c0_sm_p8_0,
  123816. NULL,
  123817. &_vq_auxt__44c0_sm_p8_0,
  123818. NULL,
  123819. 0
  123820. };
  123821. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123822. 6,
  123823. 5,
  123824. 7,
  123825. 4,
  123826. 8,
  123827. 3,
  123828. 9,
  123829. 2,
  123830. 10,
  123831. 1,
  123832. 11,
  123833. 0,
  123834. 12,
  123835. };
  123836. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123837. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123838. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123839. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123840. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123841. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123842. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123843. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123844. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123845. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123846. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123847. 20,13,13,12,12,16,13,15,13,
  123848. };
  123849. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123850. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123851. 42.5, 59.5, 76.5, 93.5,
  123852. };
  123853. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123854. 11, 9, 7, 5, 3, 1, 0, 2,
  123855. 4, 6, 8, 10, 12,
  123856. };
  123857. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123858. _vq_quantthresh__44c0_sm_p8_1,
  123859. _vq_quantmap__44c0_sm_p8_1,
  123860. 13,
  123861. 13
  123862. };
  123863. static static_codebook _44c0_sm_p8_1 = {
  123864. 2, 169,
  123865. _vq_lengthlist__44c0_sm_p8_1,
  123866. 1, -522616832, 1620115456, 4, 0,
  123867. _vq_quantlist__44c0_sm_p8_1,
  123868. NULL,
  123869. &_vq_auxt__44c0_sm_p8_1,
  123870. NULL,
  123871. 0
  123872. };
  123873. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123874. 8,
  123875. 7,
  123876. 9,
  123877. 6,
  123878. 10,
  123879. 5,
  123880. 11,
  123881. 4,
  123882. 12,
  123883. 3,
  123884. 13,
  123885. 2,
  123886. 14,
  123887. 1,
  123888. 15,
  123889. 0,
  123890. 16,
  123891. };
  123892. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123893. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123894. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123895. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123896. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123897. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123898. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123899. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123900. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123901. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123902. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123903. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123904. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123905. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123906. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123907. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123908. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123909. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123910. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123911. 9,
  123912. };
  123913. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123914. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123915. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123916. };
  123917. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123918. 15, 13, 11, 9, 7, 5, 3, 1,
  123919. 0, 2, 4, 6, 8, 10, 12, 14,
  123920. 16,
  123921. };
  123922. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123923. _vq_quantthresh__44c0_sm_p8_2,
  123924. _vq_quantmap__44c0_sm_p8_2,
  123925. 17,
  123926. 17
  123927. };
  123928. static static_codebook _44c0_sm_p8_2 = {
  123929. 2, 289,
  123930. _vq_lengthlist__44c0_sm_p8_2,
  123931. 1, -529530880, 1611661312, 5, 0,
  123932. _vq_quantlist__44c0_sm_p8_2,
  123933. NULL,
  123934. &_vq_auxt__44c0_sm_p8_2,
  123935. NULL,
  123936. 0
  123937. };
  123938. static long _huff_lengthlist__44c0_sm_short[] = {
  123939. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123940. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123941. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123942. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123943. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123944. 12,
  123945. };
  123946. static static_codebook _huff_book__44c0_sm_short = {
  123947. 2, 81,
  123948. _huff_lengthlist__44c0_sm_short,
  123949. 0, 0, 0, 0, 0,
  123950. NULL,
  123951. NULL,
  123952. NULL,
  123953. NULL,
  123954. 0
  123955. };
  123956. static long _huff_lengthlist__44c1_s_long[] = {
  123957. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123958. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123959. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123960. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123961. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123962. 11,
  123963. };
  123964. static static_codebook _huff_book__44c1_s_long = {
  123965. 2, 81,
  123966. _huff_lengthlist__44c1_s_long,
  123967. 0, 0, 0, 0, 0,
  123968. NULL,
  123969. NULL,
  123970. NULL,
  123971. NULL,
  123972. 0
  123973. };
  123974. static long _vq_quantlist__44c1_s_p1_0[] = {
  123975. 1,
  123976. 0,
  123977. 2,
  123978. };
  123979. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123980. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123981. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123986. 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123990. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123991. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0,
  124026. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  124031. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  124036. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  124072. 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  124077. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  124082. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  124083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124390. 0,
  124391. };
  124392. static float _vq_quantthresh__44c1_s_p1_0[] = {
  124393. -0.5, 0.5,
  124394. };
  124395. static long _vq_quantmap__44c1_s_p1_0[] = {
  124396. 1, 0, 2,
  124397. };
  124398. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  124399. _vq_quantthresh__44c1_s_p1_0,
  124400. _vq_quantmap__44c1_s_p1_0,
  124401. 3,
  124402. 3
  124403. };
  124404. static static_codebook _44c1_s_p1_0 = {
  124405. 8, 6561,
  124406. _vq_lengthlist__44c1_s_p1_0,
  124407. 1, -535822336, 1611661312, 2, 0,
  124408. _vq_quantlist__44c1_s_p1_0,
  124409. NULL,
  124410. &_vq_auxt__44c1_s_p1_0,
  124411. NULL,
  124412. 0
  124413. };
  124414. static long _vq_quantlist__44c1_s_p2_0[] = {
  124415. 2,
  124416. 1,
  124417. 3,
  124418. 0,
  124419. 4,
  124420. };
  124421. static long _vq_lengthlist__44c1_s_p2_0[] = {
  124422. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124425. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  124427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124428. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  124429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124461. 0,
  124462. };
  124463. static float _vq_quantthresh__44c1_s_p2_0[] = {
  124464. -1.5, -0.5, 0.5, 1.5,
  124465. };
  124466. static long _vq_quantmap__44c1_s_p2_0[] = {
  124467. 3, 1, 0, 2, 4,
  124468. };
  124469. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  124470. _vq_quantthresh__44c1_s_p2_0,
  124471. _vq_quantmap__44c1_s_p2_0,
  124472. 5,
  124473. 5
  124474. };
  124475. static static_codebook _44c1_s_p2_0 = {
  124476. 4, 625,
  124477. _vq_lengthlist__44c1_s_p2_0,
  124478. 1, -533725184, 1611661312, 3, 0,
  124479. _vq_quantlist__44c1_s_p2_0,
  124480. NULL,
  124481. &_vq_auxt__44c1_s_p2_0,
  124482. NULL,
  124483. 0
  124484. };
  124485. static long _vq_quantlist__44c1_s_p3_0[] = {
  124486. 4,
  124487. 3,
  124488. 5,
  124489. 2,
  124490. 6,
  124491. 1,
  124492. 7,
  124493. 0,
  124494. 8,
  124495. };
  124496. static long _vq_lengthlist__44c1_s_p3_0[] = {
  124497. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  124498. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  124499. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124500. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124501. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124502. 0,
  124503. };
  124504. static float _vq_quantthresh__44c1_s_p3_0[] = {
  124505. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124506. };
  124507. static long _vq_quantmap__44c1_s_p3_0[] = {
  124508. 7, 5, 3, 1, 0, 2, 4, 6,
  124509. 8,
  124510. };
  124511. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  124512. _vq_quantthresh__44c1_s_p3_0,
  124513. _vq_quantmap__44c1_s_p3_0,
  124514. 9,
  124515. 9
  124516. };
  124517. static static_codebook _44c1_s_p3_0 = {
  124518. 2, 81,
  124519. _vq_lengthlist__44c1_s_p3_0,
  124520. 1, -531628032, 1611661312, 4, 0,
  124521. _vq_quantlist__44c1_s_p3_0,
  124522. NULL,
  124523. &_vq_auxt__44c1_s_p3_0,
  124524. NULL,
  124525. 0
  124526. };
  124527. static long _vq_quantlist__44c1_s_p4_0[] = {
  124528. 4,
  124529. 3,
  124530. 5,
  124531. 2,
  124532. 6,
  124533. 1,
  124534. 7,
  124535. 0,
  124536. 8,
  124537. };
  124538. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124539. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124540. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124541. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124542. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124543. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124544. 11,
  124545. };
  124546. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124547. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124548. };
  124549. static long _vq_quantmap__44c1_s_p4_0[] = {
  124550. 7, 5, 3, 1, 0, 2, 4, 6,
  124551. 8,
  124552. };
  124553. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124554. _vq_quantthresh__44c1_s_p4_0,
  124555. _vq_quantmap__44c1_s_p4_0,
  124556. 9,
  124557. 9
  124558. };
  124559. static static_codebook _44c1_s_p4_0 = {
  124560. 2, 81,
  124561. _vq_lengthlist__44c1_s_p4_0,
  124562. 1, -531628032, 1611661312, 4, 0,
  124563. _vq_quantlist__44c1_s_p4_0,
  124564. NULL,
  124565. &_vq_auxt__44c1_s_p4_0,
  124566. NULL,
  124567. 0
  124568. };
  124569. static long _vq_quantlist__44c1_s_p5_0[] = {
  124570. 8,
  124571. 7,
  124572. 9,
  124573. 6,
  124574. 10,
  124575. 5,
  124576. 11,
  124577. 4,
  124578. 12,
  124579. 3,
  124580. 13,
  124581. 2,
  124582. 14,
  124583. 1,
  124584. 15,
  124585. 0,
  124586. 16,
  124587. };
  124588. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124589. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124590. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124591. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124592. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124593. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124594. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124595. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124596. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124597. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124598. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124599. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124600. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124601. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124602. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124603. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124604. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124605. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124606. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124607. 14,
  124608. };
  124609. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124610. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124611. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124612. };
  124613. static long _vq_quantmap__44c1_s_p5_0[] = {
  124614. 15, 13, 11, 9, 7, 5, 3, 1,
  124615. 0, 2, 4, 6, 8, 10, 12, 14,
  124616. 16,
  124617. };
  124618. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124619. _vq_quantthresh__44c1_s_p5_0,
  124620. _vq_quantmap__44c1_s_p5_0,
  124621. 17,
  124622. 17
  124623. };
  124624. static static_codebook _44c1_s_p5_0 = {
  124625. 2, 289,
  124626. _vq_lengthlist__44c1_s_p5_0,
  124627. 1, -529530880, 1611661312, 5, 0,
  124628. _vq_quantlist__44c1_s_p5_0,
  124629. NULL,
  124630. &_vq_auxt__44c1_s_p5_0,
  124631. NULL,
  124632. 0
  124633. };
  124634. static long _vq_quantlist__44c1_s_p6_0[] = {
  124635. 1,
  124636. 0,
  124637. 2,
  124638. };
  124639. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124640. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124641. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124642. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124643. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124644. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124645. 11,
  124646. };
  124647. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124648. -5.5, 5.5,
  124649. };
  124650. static long _vq_quantmap__44c1_s_p6_0[] = {
  124651. 1, 0, 2,
  124652. };
  124653. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124654. _vq_quantthresh__44c1_s_p6_0,
  124655. _vq_quantmap__44c1_s_p6_0,
  124656. 3,
  124657. 3
  124658. };
  124659. static static_codebook _44c1_s_p6_0 = {
  124660. 4, 81,
  124661. _vq_lengthlist__44c1_s_p6_0,
  124662. 1, -529137664, 1618345984, 2, 0,
  124663. _vq_quantlist__44c1_s_p6_0,
  124664. NULL,
  124665. &_vq_auxt__44c1_s_p6_0,
  124666. NULL,
  124667. 0
  124668. };
  124669. static long _vq_quantlist__44c1_s_p6_1[] = {
  124670. 5,
  124671. 4,
  124672. 6,
  124673. 3,
  124674. 7,
  124675. 2,
  124676. 8,
  124677. 1,
  124678. 9,
  124679. 0,
  124680. 10,
  124681. };
  124682. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124683. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124684. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124685. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124686. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124687. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124688. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124689. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124690. 10,10,10, 8, 8, 8, 8, 8, 8,
  124691. };
  124692. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124693. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124694. 3.5, 4.5,
  124695. };
  124696. static long _vq_quantmap__44c1_s_p6_1[] = {
  124697. 9, 7, 5, 3, 1, 0, 2, 4,
  124698. 6, 8, 10,
  124699. };
  124700. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124701. _vq_quantthresh__44c1_s_p6_1,
  124702. _vq_quantmap__44c1_s_p6_1,
  124703. 11,
  124704. 11
  124705. };
  124706. static static_codebook _44c1_s_p6_1 = {
  124707. 2, 121,
  124708. _vq_lengthlist__44c1_s_p6_1,
  124709. 1, -531365888, 1611661312, 4, 0,
  124710. _vq_quantlist__44c1_s_p6_1,
  124711. NULL,
  124712. &_vq_auxt__44c1_s_p6_1,
  124713. NULL,
  124714. 0
  124715. };
  124716. static long _vq_quantlist__44c1_s_p7_0[] = {
  124717. 6,
  124718. 5,
  124719. 7,
  124720. 4,
  124721. 8,
  124722. 3,
  124723. 9,
  124724. 2,
  124725. 10,
  124726. 1,
  124727. 11,
  124728. 0,
  124729. 12,
  124730. };
  124731. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124732. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124733. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124734. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124735. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124736. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124737. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124738. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124739. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124740. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124741. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124742. 0,12,11,11,11,13,10,14,13,
  124743. };
  124744. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124745. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124746. 12.5, 17.5, 22.5, 27.5,
  124747. };
  124748. static long _vq_quantmap__44c1_s_p7_0[] = {
  124749. 11, 9, 7, 5, 3, 1, 0, 2,
  124750. 4, 6, 8, 10, 12,
  124751. };
  124752. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124753. _vq_quantthresh__44c1_s_p7_0,
  124754. _vq_quantmap__44c1_s_p7_0,
  124755. 13,
  124756. 13
  124757. };
  124758. static static_codebook _44c1_s_p7_0 = {
  124759. 2, 169,
  124760. _vq_lengthlist__44c1_s_p7_0,
  124761. 1, -526516224, 1616117760, 4, 0,
  124762. _vq_quantlist__44c1_s_p7_0,
  124763. NULL,
  124764. &_vq_auxt__44c1_s_p7_0,
  124765. NULL,
  124766. 0
  124767. };
  124768. static long _vq_quantlist__44c1_s_p7_1[] = {
  124769. 2,
  124770. 1,
  124771. 3,
  124772. 0,
  124773. 4,
  124774. };
  124775. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124776. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124777. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124778. };
  124779. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124780. -1.5, -0.5, 0.5, 1.5,
  124781. };
  124782. static long _vq_quantmap__44c1_s_p7_1[] = {
  124783. 3, 1, 0, 2, 4,
  124784. };
  124785. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124786. _vq_quantthresh__44c1_s_p7_1,
  124787. _vq_quantmap__44c1_s_p7_1,
  124788. 5,
  124789. 5
  124790. };
  124791. static static_codebook _44c1_s_p7_1 = {
  124792. 2, 25,
  124793. _vq_lengthlist__44c1_s_p7_1,
  124794. 1, -533725184, 1611661312, 3, 0,
  124795. _vq_quantlist__44c1_s_p7_1,
  124796. NULL,
  124797. &_vq_auxt__44c1_s_p7_1,
  124798. NULL,
  124799. 0
  124800. };
  124801. static long _vq_quantlist__44c1_s_p8_0[] = {
  124802. 6,
  124803. 5,
  124804. 7,
  124805. 4,
  124806. 8,
  124807. 3,
  124808. 9,
  124809. 2,
  124810. 10,
  124811. 1,
  124812. 11,
  124813. 0,
  124814. 12,
  124815. };
  124816. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124817. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124818. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124819. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124820. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124821. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124822. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124823. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124824. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124825. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124826. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124827. 10,10,10,10,10,10,10,10,10,
  124828. };
  124829. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124830. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124831. 552.5, 773.5, 994.5, 1215.5,
  124832. };
  124833. static long _vq_quantmap__44c1_s_p8_0[] = {
  124834. 11, 9, 7, 5, 3, 1, 0, 2,
  124835. 4, 6, 8, 10, 12,
  124836. };
  124837. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124838. _vq_quantthresh__44c1_s_p8_0,
  124839. _vq_quantmap__44c1_s_p8_0,
  124840. 13,
  124841. 13
  124842. };
  124843. static static_codebook _44c1_s_p8_0 = {
  124844. 2, 169,
  124845. _vq_lengthlist__44c1_s_p8_0,
  124846. 1, -514541568, 1627103232, 4, 0,
  124847. _vq_quantlist__44c1_s_p8_0,
  124848. NULL,
  124849. &_vq_auxt__44c1_s_p8_0,
  124850. NULL,
  124851. 0
  124852. };
  124853. static long _vq_quantlist__44c1_s_p8_1[] = {
  124854. 6,
  124855. 5,
  124856. 7,
  124857. 4,
  124858. 8,
  124859. 3,
  124860. 9,
  124861. 2,
  124862. 10,
  124863. 1,
  124864. 11,
  124865. 0,
  124866. 12,
  124867. };
  124868. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124869. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124870. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124871. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124872. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124873. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124874. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124875. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124876. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124877. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124878. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124879. 16,13,12,12,11,14,12,15,13,
  124880. };
  124881. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124882. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124883. 42.5, 59.5, 76.5, 93.5,
  124884. };
  124885. static long _vq_quantmap__44c1_s_p8_1[] = {
  124886. 11, 9, 7, 5, 3, 1, 0, 2,
  124887. 4, 6, 8, 10, 12,
  124888. };
  124889. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124890. _vq_quantthresh__44c1_s_p8_1,
  124891. _vq_quantmap__44c1_s_p8_1,
  124892. 13,
  124893. 13
  124894. };
  124895. static static_codebook _44c1_s_p8_1 = {
  124896. 2, 169,
  124897. _vq_lengthlist__44c1_s_p8_1,
  124898. 1, -522616832, 1620115456, 4, 0,
  124899. _vq_quantlist__44c1_s_p8_1,
  124900. NULL,
  124901. &_vq_auxt__44c1_s_p8_1,
  124902. NULL,
  124903. 0
  124904. };
  124905. static long _vq_quantlist__44c1_s_p8_2[] = {
  124906. 8,
  124907. 7,
  124908. 9,
  124909. 6,
  124910. 10,
  124911. 5,
  124912. 11,
  124913. 4,
  124914. 12,
  124915. 3,
  124916. 13,
  124917. 2,
  124918. 14,
  124919. 1,
  124920. 15,
  124921. 0,
  124922. 16,
  124923. };
  124924. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124925. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124926. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124927. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124928. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124929. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124930. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124931. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124932. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124933. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124934. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124935. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124936. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124937. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124938. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124939. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124940. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124941. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124942. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124943. 9,
  124944. };
  124945. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124946. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124947. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124948. };
  124949. static long _vq_quantmap__44c1_s_p8_2[] = {
  124950. 15, 13, 11, 9, 7, 5, 3, 1,
  124951. 0, 2, 4, 6, 8, 10, 12, 14,
  124952. 16,
  124953. };
  124954. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124955. _vq_quantthresh__44c1_s_p8_2,
  124956. _vq_quantmap__44c1_s_p8_2,
  124957. 17,
  124958. 17
  124959. };
  124960. static static_codebook _44c1_s_p8_2 = {
  124961. 2, 289,
  124962. _vq_lengthlist__44c1_s_p8_2,
  124963. 1, -529530880, 1611661312, 5, 0,
  124964. _vq_quantlist__44c1_s_p8_2,
  124965. NULL,
  124966. &_vq_auxt__44c1_s_p8_2,
  124967. NULL,
  124968. 0
  124969. };
  124970. static long _huff_lengthlist__44c1_s_short[] = {
  124971. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124972. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124973. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124974. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124975. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124976. 11,
  124977. };
  124978. static static_codebook _huff_book__44c1_s_short = {
  124979. 2, 81,
  124980. _huff_lengthlist__44c1_s_short,
  124981. 0, 0, 0, 0, 0,
  124982. NULL,
  124983. NULL,
  124984. NULL,
  124985. NULL,
  124986. 0
  124987. };
  124988. static long _huff_lengthlist__44c1_sm_long[] = {
  124989. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124990. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124991. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124992. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124993. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124994. 11,
  124995. };
  124996. static static_codebook _huff_book__44c1_sm_long = {
  124997. 2, 81,
  124998. _huff_lengthlist__44c1_sm_long,
  124999. 0, 0, 0, 0, 0,
  125000. NULL,
  125001. NULL,
  125002. NULL,
  125003. NULL,
  125004. 0
  125005. };
  125006. static long _vq_quantlist__44c1_sm_p1_0[] = {
  125007. 1,
  125008. 0,
  125009. 2,
  125010. };
  125011. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  125012. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125013. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  125018. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125022. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  125023. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 7, 0, 0, 0, 0,
  125058. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  125063. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  125068. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  125104. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  125109. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  125114. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  125115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125422. 0,
  125423. };
  125424. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  125425. -0.5, 0.5,
  125426. };
  125427. static long _vq_quantmap__44c1_sm_p1_0[] = {
  125428. 1, 0, 2,
  125429. };
  125430. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  125431. _vq_quantthresh__44c1_sm_p1_0,
  125432. _vq_quantmap__44c1_sm_p1_0,
  125433. 3,
  125434. 3
  125435. };
  125436. static static_codebook _44c1_sm_p1_0 = {
  125437. 8, 6561,
  125438. _vq_lengthlist__44c1_sm_p1_0,
  125439. 1, -535822336, 1611661312, 2, 0,
  125440. _vq_quantlist__44c1_sm_p1_0,
  125441. NULL,
  125442. &_vq_auxt__44c1_sm_p1_0,
  125443. NULL,
  125444. 0
  125445. };
  125446. static long _vq_quantlist__44c1_sm_p2_0[] = {
  125447. 2,
  125448. 1,
  125449. 3,
  125450. 0,
  125451. 4,
  125452. };
  125453. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  125454. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  125456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125457. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  125459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125460. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125493. 0,
  125494. };
  125495. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  125496. -1.5, -0.5, 0.5, 1.5,
  125497. };
  125498. static long _vq_quantmap__44c1_sm_p2_0[] = {
  125499. 3, 1, 0, 2, 4,
  125500. };
  125501. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  125502. _vq_quantthresh__44c1_sm_p2_0,
  125503. _vq_quantmap__44c1_sm_p2_0,
  125504. 5,
  125505. 5
  125506. };
  125507. static static_codebook _44c1_sm_p2_0 = {
  125508. 4, 625,
  125509. _vq_lengthlist__44c1_sm_p2_0,
  125510. 1, -533725184, 1611661312, 3, 0,
  125511. _vq_quantlist__44c1_sm_p2_0,
  125512. NULL,
  125513. &_vq_auxt__44c1_sm_p2_0,
  125514. NULL,
  125515. 0
  125516. };
  125517. static long _vq_quantlist__44c1_sm_p3_0[] = {
  125518. 4,
  125519. 3,
  125520. 5,
  125521. 2,
  125522. 6,
  125523. 1,
  125524. 7,
  125525. 0,
  125526. 8,
  125527. };
  125528. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125529. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125530. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125531. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125532. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125533. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125534. 0,
  125535. };
  125536. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125537. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125538. };
  125539. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125540. 7, 5, 3, 1, 0, 2, 4, 6,
  125541. 8,
  125542. };
  125543. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125544. _vq_quantthresh__44c1_sm_p3_0,
  125545. _vq_quantmap__44c1_sm_p3_0,
  125546. 9,
  125547. 9
  125548. };
  125549. static static_codebook _44c1_sm_p3_0 = {
  125550. 2, 81,
  125551. _vq_lengthlist__44c1_sm_p3_0,
  125552. 1, -531628032, 1611661312, 4, 0,
  125553. _vq_quantlist__44c1_sm_p3_0,
  125554. NULL,
  125555. &_vq_auxt__44c1_sm_p3_0,
  125556. NULL,
  125557. 0
  125558. };
  125559. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125560. 4,
  125561. 3,
  125562. 5,
  125563. 2,
  125564. 6,
  125565. 1,
  125566. 7,
  125567. 0,
  125568. 8,
  125569. };
  125570. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125571. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125572. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125573. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125574. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125575. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125576. 11,
  125577. };
  125578. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125579. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125580. };
  125581. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125582. 7, 5, 3, 1, 0, 2, 4, 6,
  125583. 8,
  125584. };
  125585. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125586. _vq_quantthresh__44c1_sm_p4_0,
  125587. _vq_quantmap__44c1_sm_p4_0,
  125588. 9,
  125589. 9
  125590. };
  125591. static static_codebook _44c1_sm_p4_0 = {
  125592. 2, 81,
  125593. _vq_lengthlist__44c1_sm_p4_0,
  125594. 1, -531628032, 1611661312, 4, 0,
  125595. _vq_quantlist__44c1_sm_p4_0,
  125596. NULL,
  125597. &_vq_auxt__44c1_sm_p4_0,
  125598. NULL,
  125599. 0
  125600. };
  125601. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125602. 8,
  125603. 7,
  125604. 9,
  125605. 6,
  125606. 10,
  125607. 5,
  125608. 11,
  125609. 4,
  125610. 12,
  125611. 3,
  125612. 13,
  125613. 2,
  125614. 14,
  125615. 1,
  125616. 15,
  125617. 0,
  125618. 16,
  125619. };
  125620. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125621. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125622. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125623. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125624. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125625. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125626. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125627. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125628. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125629. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125630. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125631. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125632. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125633. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125634. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125635. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125636. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125637. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125638. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125639. 14,
  125640. };
  125641. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125642. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125643. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125644. };
  125645. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125646. 15, 13, 11, 9, 7, 5, 3, 1,
  125647. 0, 2, 4, 6, 8, 10, 12, 14,
  125648. 16,
  125649. };
  125650. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125651. _vq_quantthresh__44c1_sm_p5_0,
  125652. _vq_quantmap__44c1_sm_p5_0,
  125653. 17,
  125654. 17
  125655. };
  125656. static static_codebook _44c1_sm_p5_0 = {
  125657. 2, 289,
  125658. _vq_lengthlist__44c1_sm_p5_0,
  125659. 1, -529530880, 1611661312, 5, 0,
  125660. _vq_quantlist__44c1_sm_p5_0,
  125661. NULL,
  125662. &_vq_auxt__44c1_sm_p5_0,
  125663. NULL,
  125664. 0
  125665. };
  125666. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125667. 1,
  125668. 0,
  125669. 2,
  125670. };
  125671. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125672. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125673. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125674. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125675. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125676. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125677. 11,
  125678. };
  125679. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125680. -5.5, 5.5,
  125681. };
  125682. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125683. 1, 0, 2,
  125684. };
  125685. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125686. _vq_quantthresh__44c1_sm_p6_0,
  125687. _vq_quantmap__44c1_sm_p6_0,
  125688. 3,
  125689. 3
  125690. };
  125691. static static_codebook _44c1_sm_p6_0 = {
  125692. 4, 81,
  125693. _vq_lengthlist__44c1_sm_p6_0,
  125694. 1, -529137664, 1618345984, 2, 0,
  125695. _vq_quantlist__44c1_sm_p6_0,
  125696. NULL,
  125697. &_vq_auxt__44c1_sm_p6_0,
  125698. NULL,
  125699. 0
  125700. };
  125701. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125702. 5,
  125703. 4,
  125704. 6,
  125705. 3,
  125706. 7,
  125707. 2,
  125708. 8,
  125709. 1,
  125710. 9,
  125711. 0,
  125712. 10,
  125713. };
  125714. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125715. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125716. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125717. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125718. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125719. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125720. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125721. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125722. 10,10,10, 8, 8, 8, 8, 8, 8,
  125723. };
  125724. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125725. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125726. 3.5, 4.5,
  125727. };
  125728. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125729. 9, 7, 5, 3, 1, 0, 2, 4,
  125730. 6, 8, 10,
  125731. };
  125732. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125733. _vq_quantthresh__44c1_sm_p6_1,
  125734. _vq_quantmap__44c1_sm_p6_1,
  125735. 11,
  125736. 11
  125737. };
  125738. static static_codebook _44c1_sm_p6_1 = {
  125739. 2, 121,
  125740. _vq_lengthlist__44c1_sm_p6_1,
  125741. 1, -531365888, 1611661312, 4, 0,
  125742. _vq_quantlist__44c1_sm_p6_1,
  125743. NULL,
  125744. &_vq_auxt__44c1_sm_p6_1,
  125745. NULL,
  125746. 0
  125747. };
  125748. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125749. 6,
  125750. 5,
  125751. 7,
  125752. 4,
  125753. 8,
  125754. 3,
  125755. 9,
  125756. 2,
  125757. 10,
  125758. 1,
  125759. 11,
  125760. 0,
  125761. 12,
  125762. };
  125763. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125764. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125765. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125766. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125767. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125768. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125769. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125770. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125771. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125772. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125773. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125774. 0,12,12,11,11,13,12,14,13,
  125775. };
  125776. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125777. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125778. 12.5, 17.5, 22.5, 27.5,
  125779. };
  125780. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125781. 11, 9, 7, 5, 3, 1, 0, 2,
  125782. 4, 6, 8, 10, 12,
  125783. };
  125784. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125785. _vq_quantthresh__44c1_sm_p7_0,
  125786. _vq_quantmap__44c1_sm_p7_0,
  125787. 13,
  125788. 13
  125789. };
  125790. static static_codebook _44c1_sm_p7_0 = {
  125791. 2, 169,
  125792. _vq_lengthlist__44c1_sm_p7_0,
  125793. 1, -526516224, 1616117760, 4, 0,
  125794. _vq_quantlist__44c1_sm_p7_0,
  125795. NULL,
  125796. &_vq_auxt__44c1_sm_p7_0,
  125797. NULL,
  125798. 0
  125799. };
  125800. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125801. 2,
  125802. 1,
  125803. 3,
  125804. 0,
  125805. 4,
  125806. };
  125807. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125808. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125809. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125810. };
  125811. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125812. -1.5, -0.5, 0.5, 1.5,
  125813. };
  125814. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125815. 3, 1, 0, 2, 4,
  125816. };
  125817. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125818. _vq_quantthresh__44c1_sm_p7_1,
  125819. _vq_quantmap__44c1_sm_p7_1,
  125820. 5,
  125821. 5
  125822. };
  125823. static static_codebook _44c1_sm_p7_1 = {
  125824. 2, 25,
  125825. _vq_lengthlist__44c1_sm_p7_1,
  125826. 1, -533725184, 1611661312, 3, 0,
  125827. _vq_quantlist__44c1_sm_p7_1,
  125828. NULL,
  125829. &_vq_auxt__44c1_sm_p7_1,
  125830. NULL,
  125831. 0
  125832. };
  125833. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125834. 6,
  125835. 5,
  125836. 7,
  125837. 4,
  125838. 8,
  125839. 3,
  125840. 9,
  125841. 2,
  125842. 10,
  125843. 1,
  125844. 11,
  125845. 0,
  125846. 12,
  125847. };
  125848. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125849. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125850. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125851. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125852. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125853. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125854. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125855. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125856. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125857. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125858. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125859. 13,13,13,13,13,13,13,13,13,
  125860. };
  125861. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125862. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125863. 552.5, 773.5, 994.5, 1215.5,
  125864. };
  125865. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125866. 11, 9, 7, 5, 3, 1, 0, 2,
  125867. 4, 6, 8, 10, 12,
  125868. };
  125869. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125870. _vq_quantthresh__44c1_sm_p8_0,
  125871. _vq_quantmap__44c1_sm_p8_0,
  125872. 13,
  125873. 13
  125874. };
  125875. static static_codebook _44c1_sm_p8_0 = {
  125876. 2, 169,
  125877. _vq_lengthlist__44c1_sm_p8_0,
  125878. 1, -514541568, 1627103232, 4, 0,
  125879. _vq_quantlist__44c1_sm_p8_0,
  125880. NULL,
  125881. &_vq_auxt__44c1_sm_p8_0,
  125882. NULL,
  125883. 0
  125884. };
  125885. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125886. 6,
  125887. 5,
  125888. 7,
  125889. 4,
  125890. 8,
  125891. 3,
  125892. 9,
  125893. 2,
  125894. 10,
  125895. 1,
  125896. 11,
  125897. 0,
  125898. 12,
  125899. };
  125900. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125901. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125902. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125903. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125904. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125905. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125906. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125907. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125908. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125909. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125910. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125911. 20,13,12,12,12,14,12,14,13,
  125912. };
  125913. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125914. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125915. 42.5, 59.5, 76.5, 93.5,
  125916. };
  125917. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125918. 11, 9, 7, 5, 3, 1, 0, 2,
  125919. 4, 6, 8, 10, 12,
  125920. };
  125921. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125922. _vq_quantthresh__44c1_sm_p8_1,
  125923. _vq_quantmap__44c1_sm_p8_1,
  125924. 13,
  125925. 13
  125926. };
  125927. static static_codebook _44c1_sm_p8_1 = {
  125928. 2, 169,
  125929. _vq_lengthlist__44c1_sm_p8_1,
  125930. 1, -522616832, 1620115456, 4, 0,
  125931. _vq_quantlist__44c1_sm_p8_1,
  125932. NULL,
  125933. &_vq_auxt__44c1_sm_p8_1,
  125934. NULL,
  125935. 0
  125936. };
  125937. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125938. 8,
  125939. 7,
  125940. 9,
  125941. 6,
  125942. 10,
  125943. 5,
  125944. 11,
  125945. 4,
  125946. 12,
  125947. 3,
  125948. 13,
  125949. 2,
  125950. 14,
  125951. 1,
  125952. 15,
  125953. 0,
  125954. 16,
  125955. };
  125956. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125957. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125958. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125959. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125960. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125961. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125962. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125963. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125964. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125965. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125966. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125967. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125968. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125969. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125970. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125971. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125972. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125973. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125974. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125975. 9,
  125976. };
  125977. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125978. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125979. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125980. };
  125981. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125982. 15, 13, 11, 9, 7, 5, 3, 1,
  125983. 0, 2, 4, 6, 8, 10, 12, 14,
  125984. 16,
  125985. };
  125986. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125987. _vq_quantthresh__44c1_sm_p8_2,
  125988. _vq_quantmap__44c1_sm_p8_2,
  125989. 17,
  125990. 17
  125991. };
  125992. static static_codebook _44c1_sm_p8_2 = {
  125993. 2, 289,
  125994. _vq_lengthlist__44c1_sm_p8_2,
  125995. 1, -529530880, 1611661312, 5, 0,
  125996. _vq_quantlist__44c1_sm_p8_2,
  125997. NULL,
  125998. &_vq_auxt__44c1_sm_p8_2,
  125999. NULL,
  126000. 0
  126001. };
  126002. static long _huff_lengthlist__44c1_sm_short[] = {
  126003. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  126004. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  126005. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  126006. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  126007. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  126008. 11,
  126009. };
  126010. static static_codebook _huff_book__44c1_sm_short = {
  126011. 2, 81,
  126012. _huff_lengthlist__44c1_sm_short,
  126013. 0, 0, 0, 0, 0,
  126014. NULL,
  126015. NULL,
  126016. NULL,
  126017. NULL,
  126018. 0
  126019. };
  126020. static long _huff_lengthlist__44cn1_s_long[] = {
  126021. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  126022. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  126023. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  126024. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  126025. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  126026. 20,
  126027. };
  126028. static static_codebook _huff_book__44cn1_s_long = {
  126029. 2, 81,
  126030. _huff_lengthlist__44cn1_s_long,
  126031. 0, 0, 0, 0, 0,
  126032. NULL,
  126033. NULL,
  126034. NULL,
  126035. NULL,
  126036. 0
  126037. };
  126038. static long _vq_quantlist__44cn1_s_p1_0[] = {
  126039. 1,
  126040. 0,
  126041. 2,
  126042. };
  126043. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  126044. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126045. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126050. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126054. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  126055. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0,
  126090. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 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, 7,10,10, 0, 0, 0,
  126095. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 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, 7,10,10, 0, 0,
  126100. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  126136. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  126141. 0, 0, 0, 0, 0, 9, 9,11, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  126146. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  126147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126454. 0,
  126455. };
  126456. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  126457. -0.5, 0.5,
  126458. };
  126459. static long _vq_quantmap__44cn1_s_p1_0[] = {
  126460. 1, 0, 2,
  126461. };
  126462. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  126463. _vq_quantthresh__44cn1_s_p1_0,
  126464. _vq_quantmap__44cn1_s_p1_0,
  126465. 3,
  126466. 3
  126467. };
  126468. static static_codebook _44cn1_s_p1_0 = {
  126469. 8, 6561,
  126470. _vq_lengthlist__44cn1_s_p1_0,
  126471. 1, -535822336, 1611661312, 2, 0,
  126472. _vq_quantlist__44cn1_s_p1_0,
  126473. NULL,
  126474. &_vq_auxt__44cn1_s_p1_0,
  126475. NULL,
  126476. 0
  126477. };
  126478. static long _vq_quantlist__44cn1_s_p2_0[] = {
  126479. 2,
  126480. 1,
  126481. 3,
  126482. 0,
  126483. 4,
  126484. };
  126485. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  126486. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126489. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126492. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  126493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126525. 0,
  126526. };
  126527. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126528. -1.5, -0.5, 0.5, 1.5,
  126529. };
  126530. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126531. 3, 1, 0, 2, 4,
  126532. };
  126533. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126534. _vq_quantthresh__44cn1_s_p2_0,
  126535. _vq_quantmap__44cn1_s_p2_0,
  126536. 5,
  126537. 5
  126538. };
  126539. static static_codebook _44cn1_s_p2_0 = {
  126540. 4, 625,
  126541. _vq_lengthlist__44cn1_s_p2_0,
  126542. 1, -533725184, 1611661312, 3, 0,
  126543. _vq_quantlist__44cn1_s_p2_0,
  126544. NULL,
  126545. &_vq_auxt__44cn1_s_p2_0,
  126546. NULL,
  126547. 0
  126548. };
  126549. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126550. 4,
  126551. 3,
  126552. 5,
  126553. 2,
  126554. 6,
  126555. 1,
  126556. 7,
  126557. 0,
  126558. 8,
  126559. };
  126560. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126561. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126562. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126563. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126564. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126565. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126566. 0,
  126567. };
  126568. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126569. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126570. };
  126571. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126572. 7, 5, 3, 1, 0, 2, 4, 6,
  126573. 8,
  126574. };
  126575. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126576. _vq_quantthresh__44cn1_s_p3_0,
  126577. _vq_quantmap__44cn1_s_p3_0,
  126578. 9,
  126579. 9
  126580. };
  126581. static static_codebook _44cn1_s_p3_0 = {
  126582. 2, 81,
  126583. _vq_lengthlist__44cn1_s_p3_0,
  126584. 1, -531628032, 1611661312, 4, 0,
  126585. _vq_quantlist__44cn1_s_p3_0,
  126586. NULL,
  126587. &_vq_auxt__44cn1_s_p3_0,
  126588. NULL,
  126589. 0
  126590. };
  126591. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126592. 4,
  126593. 3,
  126594. 5,
  126595. 2,
  126596. 6,
  126597. 1,
  126598. 7,
  126599. 0,
  126600. 8,
  126601. };
  126602. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126603. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126604. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126605. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126606. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126607. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126608. 11,
  126609. };
  126610. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126611. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126612. };
  126613. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126614. 7, 5, 3, 1, 0, 2, 4, 6,
  126615. 8,
  126616. };
  126617. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126618. _vq_quantthresh__44cn1_s_p4_0,
  126619. _vq_quantmap__44cn1_s_p4_0,
  126620. 9,
  126621. 9
  126622. };
  126623. static static_codebook _44cn1_s_p4_0 = {
  126624. 2, 81,
  126625. _vq_lengthlist__44cn1_s_p4_0,
  126626. 1, -531628032, 1611661312, 4, 0,
  126627. _vq_quantlist__44cn1_s_p4_0,
  126628. NULL,
  126629. &_vq_auxt__44cn1_s_p4_0,
  126630. NULL,
  126631. 0
  126632. };
  126633. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126634. 8,
  126635. 7,
  126636. 9,
  126637. 6,
  126638. 10,
  126639. 5,
  126640. 11,
  126641. 4,
  126642. 12,
  126643. 3,
  126644. 13,
  126645. 2,
  126646. 14,
  126647. 1,
  126648. 15,
  126649. 0,
  126650. 16,
  126651. };
  126652. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126653. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126654. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126655. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126656. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126657. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126658. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126659. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126660. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126661. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126662. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126663. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126664. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126665. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126666. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126667. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126668. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126669. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126670. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126671. 14,
  126672. };
  126673. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126674. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126675. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126676. };
  126677. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126678. 15, 13, 11, 9, 7, 5, 3, 1,
  126679. 0, 2, 4, 6, 8, 10, 12, 14,
  126680. 16,
  126681. };
  126682. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126683. _vq_quantthresh__44cn1_s_p5_0,
  126684. _vq_quantmap__44cn1_s_p5_0,
  126685. 17,
  126686. 17
  126687. };
  126688. static static_codebook _44cn1_s_p5_0 = {
  126689. 2, 289,
  126690. _vq_lengthlist__44cn1_s_p5_0,
  126691. 1, -529530880, 1611661312, 5, 0,
  126692. _vq_quantlist__44cn1_s_p5_0,
  126693. NULL,
  126694. &_vq_auxt__44cn1_s_p5_0,
  126695. NULL,
  126696. 0
  126697. };
  126698. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126699. 1,
  126700. 0,
  126701. 2,
  126702. };
  126703. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126704. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126705. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126706. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126707. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126708. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126709. 10,
  126710. };
  126711. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126712. -5.5, 5.5,
  126713. };
  126714. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126715. 1, 0, 2,
  126716. };
  126717. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126718. _vq_quantthresh__44cn1_s_p6_0,
  126719. _vq_quantmap__44cn1_s_p6_0,
  126720. 3,
  126721. 3
  126722. };
  126723. static static_codebook _44cn1_s_p6_0 = {
  126724. 4, 81,
  126725. _vq_lengthlist__44cn1_s_p6_0,
  126726. 1, -529137664, 1618345984, 2, 0,
  126727. _vq_quantlist__44cn1_s_p6_0,
  126728. NULL,
  126729. &_vq_auxt__44cn1_s_p6_0,
  126730. NULL,
  126731. 0
  126732. };
  126733. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126734. 5,
  126735. 4,
  126736. 6,
  126737. 3,
  126738. 7,
  126739. 2,
  126740. 8,
  126741. 1,
  126742. 9,
  126743. 0,
  126744. 10,
  126745. };
  126746. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126747. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126748. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126749. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126750. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126751. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126752. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126753. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126754. 10,10,10, 9, 9, 9, 9, 9, 9,
  126755. };
  126756. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126757. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126758. 3.5, 4.5,
  126759. };
  126760. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126761. 9, 7, 5, 3, 1, 0, 2, 4,
  126762. 6, 8, 10,
  126763. };
  126764. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126765. _vq_quantthresh__44cn1_s_p6_1,
  126766. _vq_quantmap__44cn1_s_p6_1,
  126767. 11,
  126768. 11
  126769. };
  126770. static static_codebook _44cn1_s_p6_1 = {
  126771. 2, 121,
  126772. _vq_lengthlist__44cn1_s_p6_1,
  126773. 1, -531365888, 1611661312, 4, 0,
  126774. _vq_quantlist__44cn1_s_p6_1,
  126775. NULL,
  126776. &_vq_auxt__44cn1_s_p6_1,
  126777. NULL,
  126778. 0
  126779. };
  126780. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126781. 6,
  126782. 5,
  126783. 7,
  126784. 4,
  126785. 8,
  126786. 3,
  126787. 9,
  126788. 2,
  126789. 10,
  126790. 1,
  126791. 11,
  126792. 0,
  126793. 12,
  126794. };
  126795. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126796. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126797. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126798. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126799. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126800. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126801. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126802. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126803. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126804. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126805. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126806. 0,13,13,12,12,13,13,13,14,
  126807. };
  126808. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126809. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126810. 12.5, 17.5, 22.5, 27.5,
  126811. };
  126812. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126813. 11, 9, 7, 5, 3, 1, 0, 2,
  126814. 4, 6, 8, 10, 12,
  126815. };
  126816. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126817. _vq_quantthresh__44cn1_s_p7_0,
  126818. _vq_quantmap__44cn1_s_p7_0,
  126819. 13,
  126820. 13
  126821. };
  126822. static static_codebook _44cn1_s_p7_0 = {
  126823. 2, 169,
  126824. _vq_lengthlist__44cn1_s_p7_0,
  126825. 1, -526516224, 1616117760, 4, 0,
  126826. _vq_quantlist__44cn1_s_p7_0,
  126827. NULL,
  126828. &_vq_auxt__44cn1_s_p7_0,
  126829. NULL,
  126830. 0
  126831. };
  126832. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126833. 2,
  126834. 1,
  126835. 3,
  126836. 0,
  126837. 4,
  126838. };
  126839. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126840. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126841. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126842. };
  126843. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126844. -1.5, -0.5, 0.5, 1.5,
  126845. };
  126846. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126847. 3, 1, 0, 2, 4,
  126848. };
  126849. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126850. _vq_quantthresh__44cn1_s_p7_1,
  126851. _vq_quantmap__44cn1_s_p7_1,
  126852. 5,
  126853. 5
  126854. };
  126855. static static_codebook _44cn1_s_p7_1 = {
  126856. 2, 25,
  126857. _vq_lengthlist__44cn1_s_p7_1,
  126858. 1, -533725184, 1611661312, 3, 0,
  126859. _vq_quantlist__44cn1_s_p7_1,
  126860. NULL,
  126861. &_vq_auxt__44cn1_s_p7_1,
  126862. NULL,
  126863. 0
  126864. };
  126865. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126866. 2,
  126867. 1,
  126868. 3,
  126869. 0,
  126870. 4,
  126871. };
  126872. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126873. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126874. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126875. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126876. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126877. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126878. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126879. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126880. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126881. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126882. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126883. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126884. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126885. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126886. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126887. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126888. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126889. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126890. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126891. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126892. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126893. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126894. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126895. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126896. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126897. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126898. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126899. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126900. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126901. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126902. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126903. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126904. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126905. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126906. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126907. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126908. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126909. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126910. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126911. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126912. 12,
  126913. };
  126914. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126915. -331.5, -110.5, 110.5, 331.5,
  126916. };
  126917. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126918. 3, 1, 0, 2, 4,
  126919. };
  126920. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126921. _vq_quantthresh__44cn1_s_p8_0,
  126922. _vq_quantmap__44cn1_s_p8_0,
  126923. 5,
  126924. 5
  126925. };
  126926. static static_codebook _44cn1_s_p8_0 = {
  126927. 4, 625,
  126928. _vq_lengthlist__44cn1_s_p8_0,
  126929. 1, -518283264, 1627103232, 3, 0,
  126930. _vq_quantlist__44cn1_s_p8_0,
  126931. NULL,
  126932. &_vq_auxt__44cn1_s_p8_0,
  126933. NULL,
  126934. 0
  126935. };
  126936. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126937. 6,
  126938. 5,
  126939. 7,
  126940. 4,
  126941. 8,
  126942. 3,
  126943. 9,
  126944. 2,
  126945. 10,
  126946. 1,
  126947. 11,
  126948. 0,
  126949. 12,
  126950. };
  126951. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126952. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126953. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126954. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126955. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126956. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126957. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126958. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126959. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126960. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126961. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126962. 15,12,12,11,11,14,12,13,14,
  126963. };
  126964. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126965. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126966. 42.5, 59.5, 76.5, 93.5,
  126967. };
  126968. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126969. 11, 9, 7, 5, 3, 1, 0, 2,
  126970. 4, 6, 8, 10, 12,
  126971. };
  126972. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126973. _vq_quantthresh__44cn1_s_p8_1,
  126974. _vq_quantmap__44cn1_s_p8_1,
  126975. 13,
  126976. 13
  126977. };
  126978. static static_codebook _44cn1_s_p8_1 = {
  126979. 2, 169,
  126980. _vq_lengthlist__44cn1_s_p8_1,
  126981. 1, -522616832, 1620115456, 4, 0,
  126982. _vq_quantlist__44cn1_s_p8_1,
  126983. NULL,
  126984. &_vq_auxt__44cn1_s_p8_1,
  126985. NULL,
  126986. 0
  126987. };
  126988. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126989. 8,
  126990. 7,
  126991. 9,
  126992. 6,
  126993. 10,
  126994. 5,
  126995. 11,
  126996. 4,
  126997. 12,
  126998. 3,
  126999. 13,
  127000. 2,
  127001. 14,
  127002. 1,
  127003. 15,
  127004. 0,
  127005. 16,
  127006. };
  127007. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  127008. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  127009. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  127010. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  127011. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  127012. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  127013. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  127014. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  127015. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  127016. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  127017. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  127018. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  127019. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  127020. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  127021. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  127022. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  127023. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127024. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127025. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  127026. 9,
  127027. };
  127028. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  127029. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127030. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127031. };
  127032. static long _vq_quantmap__44cn1_s_p8_2[] = {
  127033. 15, 13, 11, 9, 7, 5, 3, 1,
  127034. 0, 2, 4, 6, 8, 10, 12, 14,
  127035. 16,
  127036. };
  127037. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  127038. _vq_quantthresh__44cn1_s_p8_2,
  127039. _vq_quantmap__44cn1_s_p8_2,
  127040. 17,
  127041. 17
  127042. };
  127043. static static_codebook _44cn1_s_p8_2 = {
  127044. 2, 289,
  127045. _vq_lengthlist__44cn1_s_p8_2,
  127046. 1, -529530880, 1611661312, 5, 0,
  127047. _vq_quantlist__44cn1_s_p8_2,
  127048. NULL,
  127049. &_vq_auxt__44cn1_s_p8_2,
  127050. NULL,
  127051. 0
  127052. };
  127053. static long _huff_lengthlist__44cn1_s_short[] = {
  127054. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  127055. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  127056. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  127057. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  127058. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  127059. 10,
  127060. };
  127061. static static_codebook _huff_book__44cn1_s_short = {
  127062. 2, 81,
  127063. _huff_lengthlist__44cn1_s_short,
  127064. 0, 0, 0, 0, 0,
  127065. NULL,
  127066. NULL,
  127067. NULL,
  127068. NULL,
  127069. 0
  127070. };
  127071. static long _huff_lengthlist__44cn1_sm_long[] = {
  127072. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  127073. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  127074. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  127075. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  127076. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  127077. 17,
  127078. };
  127079. static static_codebook _huff_book__44cn1_sm_long = {
  127080. 2, 81,
  127081. _huff_lengthlist__44cn1_sm_long,
  127082. 0, 0, 0, 0, 0,
  127083. NULL,
  127084. NULL,
  127085. NULL,
  127086. NULL,
  127087. 0
  127088. };
  127089. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  127090. 1,
  127091. 0,
  127092. 2,
  127093. };
  127094. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  127095. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  127096. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  127101. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127105. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  127106. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0,
  127141. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  127146. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  127151. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  127187. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  127192. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  127197. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  127198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127505. 0,
  127506. };
  127507. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  127508. -0.5, 0.5,
  127509. };
  127510. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  127511. 1, 0, 2,
  127512. };
  127513. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  127514. _vq_quantthresh__44cn1_sm_p1_0,
  127515. _vq_quantmap__44cn1_sm_p1_0,
  127516. 3,
  127517. 3
  127518. };
  127519. static static_codebook _44cn1_sm_p1_0 = {
  127520. 8, 6561,
  127521. _vq_lengthlist__44cn1_sm_p1_0,
  127522. 1, -535822336, 1611661312, 2, 0,
  127523. _vq_quantlist__44cn1_sm_p1_0,
  127524. NULL,
  127525. &_vq_auxt__44cn1_sm_p1_0,
  127526. NULL,
  127527. 0
  127528. };
  127529. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127530. 2,
  127531. 1,
  127532. 3,
  127533. 0,
  127534. 4,
  127535. };
  127536. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127537. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127540. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127543. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  127544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127576. 0,
  127577. };
  127578. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127579. -1.5, -0.5, 0.5, 1.5,
  127580. };
  127581. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127582. 3, 1, 0, 2, 4,
  127583. };
  127584. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127585. _vq_quantthresh__44cn1_sm_p2_0,
  127586. _vq_quantmap__44cn1_sm_p2_0,
  127587. 5,
  127588. 5
  127589. };
  127590. static static_codebook _44cn1_sm_p2_0 = {
  127591. 4, 625,
  127592. _vq_lengthlist__44cn1_sm_p2_0,
  127593. 1, -533725184, 1611661312, 3, 0,
  127594. _vq_quantlist__44cn1_sm_p2_0,
  127595. NULL,
  127596. &_vq_auxt__44cn1_sm_p2_0,
  127597. NULL,
  127598. 0
  127599. };
  127600. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127601. 4,
  127602. 3,
  127603. 5,
  127604. 2,
  127605. 6,
  127606. 1,
  127607. 7,
  127608. 0,
  127609. 8,
  127610. };
  127611. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127612. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127613. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127614. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127615. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127616. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127617. 0,
  127618. };
  127619. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127620. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127621. };
  127622. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127623. 7, 5, 3, 1, 0, 2, 4, 6,
  127624. 8,
  127625. };
  127626. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127627. _vq_quantthresh__44cn1_sm_p3_0,
  127628. _vq_quantmap__44cn1_sm_p3_0,
  127629. 9,
  127630. 9
  127631. };
  127632. static static_codebook _44cn1_sm_p3_0 = {
  127633. 2, 81,
  127634. _vq_lengthlist__44cn1_sm_p3_0,
  127635. 1, -531628032, 1611661312, 4, 0,
  127636. _vq_quantlist__44cn1_sm_p3_0,
  127637. NULL,
  127638. &_vq_auxt__44cn1_sm_p3_0,
  127639. NULL,
  127640. 0
  127641. };
  127642. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127643. 4,
  127644. 3,
  127645. 5,
  127646. 2,
  127647. 6,
  127648. 1,
  127649. 7,
  127650. 0,
  127651. 8,
  127652. };
  127653. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127654. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127655. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127656. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127657. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127658. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127659. 11,
  127660. };
  127661. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127662. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127663. };
  127664. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127665. 7, 5, 3, 1, 0, 2, 4, 6,
  127666. 8,
  127667. };
  127668. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127669. _vq_quantthresh__44cn1_sm_p4_0,
  127670. _vq_quantmap__44cn1_sm_p4_0,
  127671. 9,
  127672. 9
  127673. };
  127674. static static_codebook _44cn1_sm_p4_0 = {
  127675. 2, 81,
  127676. _vq_lengthlist__44cn1_sm_p4_0,
  127677. 1, -531628032, 1611661312, 4, 0,
  127678. _vq_quantlist__44cn1_sm_p4_0,
  127679. NULL,
  127680. &_vq_auxt__44cn1_sm_p4_0,
  127681. NULL,
  127682. 0
  127683. };
  127684. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127685. 8,
  127686. 7,
  127687. 9,
  127688. 6,
  127689. 10,
  127690. 5,
  127691. 11,
  127692. 4,
  127693. 12,
  127694. 3,
  127695. 13,
  127696. 2,
  127697. 14,
  127698. 1,
  127699. 15,
  127700. 0,
  127701. 16,
  127702. };
  127703. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127704. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127705. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127706. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127707. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127708. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127709. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127710. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127711. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127712. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127713. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127714. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127715. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127716. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127717. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127718. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127719. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127720. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127721. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127722. 14,
  127723. };
  127724. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127725. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127726. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127727. };
  127728. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127729. 15, 13, 11, 9, 7, 5, 3, 1,
  127730. 0, 2, 4, 6, 8, 10, 12, 14,
  127731. 16,
  127732. };
  127733. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127734. _vq_quantthresh__44cn1_sm_p5_0,
  127735. _vq_quantmap__44cn1_sm_p5_0,
  127736. 17,
  127737. 17
  127738. };
  127739. static static_codebook _44cn1_sm_p5_0 = {
  127740. 2, 289,
  127741. _vq_lengthlist__44cn1_sm_p5_0,
  127742. 1, -529530880, 1611661312, 5, 0,
  127743. _vq_quantlist__44cn1_sm_p5_0,
  127744. NULL,
  127745. &_vq_auxt__44cn1_sm_p5_0,
  127746. NULL,
  127747. 0
  127748. };
  127749. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127750. 1,
  127751. 0,
  127752. 2,
  127753. };
  127754. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127755. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127756. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127757. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127758. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127759. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127760. 10,
  127761. };
  127762. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127763. -5.5, 5.5,
  127764. };
  127765. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127766. 1, 0, 2,
  127767. };
  127768. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127769. _vq_quantthresh__44cn1_sm_p6_0,
  127770. _vq_quantmap__44cn1_sm_p6_0,
  127771. 3,
  127772. 3
  127773. };
  127774. static static_codebook _44cn1_sm_p6_0 = {
  127775. 4, 81,
  127776. _vq_lengthlist__44cn1_sm_p6_0,
  127777. 1, -529137664, 1618345984, 2, 0,
  127778. _vq_quantlist__44cn1_sm_p6_0,
  127779. NULL,
  127780. &_vq_auxt__44cn1_sm_p6_0,
  127781. NULL,
  127782. 0
  127783. };
  127784. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127785. 5,
  127786. 4,
  127787. 6,
  127788. 3,
  127789. 7,
  127790. 2,
  127791. 8,
  127792. 1,
  127793. 9,
  127794. 0,
  127795. 10,
  127796. };
  127797. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127798. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127799. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127800. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127801. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127802. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127803. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127804. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127805. 10,10,10, 8, 9, 8, 8, 9, 8,
  127806. };
  127807. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127808. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127809. 3.5, 4.5,
  127810. };
  127811. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127812. 9, 7, 5, 3, 1, 0, 2, 4,
  127813. 6, 8, 10,
  127814. };
  127815. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127816. _vq_quantthresh__44cn1_sm_p6_1,
  127817. _vq_quantmap__44cn1_sm_p6_1,
  127818. 11,
  127819. 11
  127820. };
  127821. static static_codebook _44cn1_sm_p6_1 = {
  127822. 2, 121,
  127823. _vq_lengthlist__44cn1_sm_p6_1,
  127824. 1, -531365888, 1611661312, 4, 0,
  127825. _vq_quantlist__44cn1_sm_p6_1,
  127826. NULL,
  127827. &_vq_auxt__44cn1_sm_p6_1,
  127828. NULL,
  127829. 0
  127830. };
  127831. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127832. 6,
  127833. 5,
  127834. 7,
  127835. 4,
  127836. 8,
  127837. 3,
  127838. 9,
  127839. 2,
  127840. 10,
  127841. 1,
  127842. 11,
  127843. 0,
  127844. 12,
  127845. };
  127846. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127847. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127848. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127849. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127850. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127851. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127852. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127853. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127854. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127855. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127856. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127857. 0,13,12,12,12,13,13,13,14,
  127858. };
  127859. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127860. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127861. 12.5, 17.5, 22.5, 27.5,
  127862. };
  127863. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127864. 11, 9, 7, 5, 3, 1, 0, 2,
  127865. 4, 6, 8, 10, 12,
  127866. };
  127867. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127868. _vq_quantthresh__44cn1_sm_p7_0,
  127869. _vq_quantmap__44cn1_sm_p7_0,
  127870. 13,
  127871. 13
  127872. };
  127873. static static_codebook _44cn1_sm_p7_0 = {
  127874. 2, 169,
  127875. _vq_lengthlist__44cn1_sm_p7_0,
  127876. 1, -526516224, 1616117760, 4, 0,
  127877. _vq_quantlist__44cn1_sm_p7_0,
  127878. NULL,
  127879. &_vq_auxt__44cn1_sm_p7_0,
  127880. NULL,
  127881. 0
  127882. };
  127883. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127884. 2,
  127885. 1,
  127886. 3,
  127887. 0,
  127888. 4,
  127889. };
  127890. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127891. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127892. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127893. };
  127894. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127895. -1.5, -0.5, 0.5, 1.5,
  127896. };
  127897. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127898. 3, 1, 0, 2, 4,
  127899. };
  127900. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127901. _vq_quantthresh__44cn1_sm_p7_1,
  127902. _vq_quantmap__44cn1_sm_p7_1,
  127903. 5,
  127904. 5
  127905. };
  127906. static static_codebook _44cn1_sm_p7_1 = {
  127907. 2, 25,
  127908. _vq_lengthlist__44cn1_sm_p7_1,
  127909. 1, -533725184, 1611661312, 3, 0,
  127910. _vq_quantlist__44cn1_sm_p7_1,
  127911. NULL,
  127912. &_vq_auxt__44cn1_sm_p7_1,
  127913. NULL,
  127914. 0
  127915. };
  127916. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127917. 4,
  127918. 3,
  127919. 5,
  127920. 2,
  127921. 6,
  127922. 1,
  127923. 7,
  127924. 0,
  127925. 8,
  127926. };
  127927. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127928. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127929. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127930. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127931. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127932. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127933. 14,
  127934. };
  127935. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127936. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127937. };
  127938. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127939. 7, 5, 3, 1, 0, 2, 4, 6,
  127940. 8,
  127941. };
  127942. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127943. _vq_quantthresh__44cn1_sm_p8_0,
  127944. _vq_quantmap__44cn1_sm_p8_0,
  127945. 9,
  127946. 9
  127947. };
  127948. static static_codebook _44cn1_sm_p8_0 = {
  127949. 2, 81,
  127950. _vq_lengthlist__44cn1_sm_p8_0,
  127951. 1, -516186112, 1627103232, 4, 0,
  127952. _vq_quantlist__44cn1_sm_p8_0,
  127953. NULL,
  127954. &_vq_auxt__44cn1_sm_p8_0,
  127955. NULL,
  127956. 0
  127957. };
  127958. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127959. 6,
  127960. 5,
  127961. 7,
  127962. 4,
  127963. 8,
  127964. 3,
  127965. 9,
  127966. 2,
  127967. 10,
  127968. 1,
  127969. 11,
  127970. 0,
  127971. 12,
  127972. };
  127973. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127974. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127975. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127976. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127977. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127978. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127979. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127980. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127981. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127982. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127983. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127984. 17,12,12,11,10,13,11,13,13,
  127985. };
  127986. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127987. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127988. 42.5, 59.5, 76.5, 93.5,
  127989. };
  127990. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127991. 11, 9, 7, 5, 3, 1, 0, 2,
  127992. 4, 6, 8, 10, 12,
  127993. };
  127994. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127995. _vq_quantthresh__44cn1_sm_p8_1,
  127996. _vq_quantmap__44cn1_sm_p8_1,
  127997. 13,
  127998. 13
  127999. };
  128000. static static_codebook _44cn1_sm_p8_1 = {
  128001. 2, 169,
  128002. _vq_lengthlist__44cn1_sm_p8_1,
  128003. 1, -522616832, 1620115456, 4, 0,
  128004. _vq_quantlist__44cn1_sm_p8_1,
  128005. NULL,
  128006. &_vq_auxt__44cn1_sm_p8_1,
  128007. NULL,
  128008. 0
  128009. };
  128010. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  128011. 8,
  128012. 7,
  128013. 9,
  128014. 6,
  128015. 10,
  128016. 5,
  128017. 11,
  128018. 4,
  128019. 12,
  128020. 3,
  128021. 13,
  128022. 2,
  128023. 14,
  128024. 1,
  128025. 15,
  128026. 0,
  128027. 16,
  128028. };
  128029. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  128030. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  128031. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  128032. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  128033. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  128034. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  128035. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  128036. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  128037. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  128038. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  128039. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  128040. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  128041. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  128042. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  128043. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  128044. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  128045. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  128046. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  128047. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  128048. 9,
  128049. };
  128050. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  128051. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  128052. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  128053. };
  128054. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  128055. 15, 13, 11, 9, 7, 5, 3, 1,
  128056. 0, 2, 4, 6, 8, 10, 12, 14,
  128057. 16,
  128058. };
  128059. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  128060. _vq_quantthresh__44cn1_sm_p8_2,
  128061. _vq_quantmap__44cn1_sm_p8_2,
  128062. 17,
  128063. 17
  128064. };
  128065. static static_codebook _44cn1_sm_p8_2 = {
  128066. 2, 289,
  128067. _vq_lengthlist__44cn1_sm_p8_2,
  128068. 1, -529530880, 1611661312, 5, 0,
  128069. _vq_quantlist__44cn1_sm_p8_2,
  128070. NULL,
  128071. &_vq_auxt__44cn1_sm_p8_2,
  128072. NULL,
  128073. 0
  128074. };
  128075. static long _huff_lengthlist__44cn1_sm_short[] = {
  128076. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  128077. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  128078. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  128079. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  128080. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  128081. 9,
  128082. };
  128083. static static_codebook _huff_book__44cn1_sm_short = {
  128084. 2, 81,
  128085. _huff_lengthlist__44cn1_sm_short,
  128086. 0, 0, 0, 0, 0,
  128087. NULL,
  128088. NULL,
  128089. NULL,
  128090. NULL,
  128091. 0
  128092. };
  128093. /*** End of inlined file: res_books_stereo.h ***/
  128094. static vorbis_info_residue0 _residue_44_low={
  128095. 0,-1, -1, 9,-1,
  128096. {0},
  128097. {-1},
  128098. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  128099. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  128100. };
  128101. static vorbis_info_residue0 _residue_44_mid={
  128102. 0,-1, -1, 10,-1,
  128103. {0},
  128104. {-1},
  128105. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  128106. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  128107. };
  128108. static vorbis_info_residue0 _residue_44_high={
  128109. 0,-1, -1, 10,-1,
  128110. {0},
  128111. {-1},
  128112. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  128113. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  128114. };
  128115. static static_bookblock _resbook_44s_n1={
  128116. {
  128117. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  128118. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  128119. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  128120. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  128121. }
  128122. };
  128123. static static_bookblock _resbook_44sm_n1={
  128124. {
  128125. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  128126. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  128127. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  128128. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  128129. }
  128130. };
  128131. static static_bookblock _resbook_44s_0={
  128132. {
  128133. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  128134. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  128135. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  128136. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  128137. }
  128138. };
  128139. static static_bookblock _resbook_44sm_0={
  128140. {
  128141. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  128142. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  128143. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  128144. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  128145. }
  128146. };
  128147. static static_bookblock _resbook_44s_1={
  128148. {
  128149. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  128150. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  128151. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  128152. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  128153. }
  128154. };
  128155. static static_bookblock _resbook_44sm_1={
  128156. {
  128157. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  128158. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  128159. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  128160. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  128161. }
  128162. };
  128163. static static_bookblock _resbook_44s_2={
  128164. {
  128165. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  128166. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  128167. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  128168. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  128169. }
  128170. };
  128171. static static_bookblock _resbook_44s_3={
  128172. {
  128173. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  128174. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  128175. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  128176. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  128177. }
  128178. };
  128179. static static_bookblock _resbook_44s_4={
  128180. {
  128181. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  128182. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  128183. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  128184. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  128185. }
  128186. };
  128187. static static_bookblock _resbook_44s_5={
  128188. {
  128189. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  128190. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  128191. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  128192. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  128193. }
  128194. };
  128195. static static_bookblock _resbook_44s_6={
  128196. {
  128197. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  128198. {0,0,&_44c6_s_p4_0},
  128199. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  128200. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  128201. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  128202. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  128203. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  128204. }
  128205. };
  128206. static static_bookblock _resbook_44s_7={
  128207. {
  128208. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  128209. {0,0,&_44c7_s_p4_0},
  128210. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  128211. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  128212. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  128213. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  128214. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  128215. }
  128216. };
  128217. static static_bookblock _resbook_44s_8={
  128218. {
  128219. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  128220. {0,0,&_44c8_s_p4_0},
  128221. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  128222. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  128223. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  128224. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  128225. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  128226. }
  128227. };
  128228. static static_bookblock _resbook_44s_9={
  128229. {
  128230. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  128231. {0,0,&_44c9_s_p4_0},
  128232. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  128233. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  128234. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  128235. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  128236. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  128237. }
  128238. };
  128239. static vorbis_residue_template _res_44s_n1[]={
  128240. {2,0, &_residue_44_low,
  128241. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  128242. &_resbook_44s_n1,&_resbook_44sm_n1},
  128243. {2,0, &_residue_44_low,
  128244. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  128245. &_resbook_44s_n1,&_resbook_44sm_n1}
  128246. };
  128247. static vorbis_residue_template _res_44s_0[]={
  128248. {2,0, &_residue_44_low,
  128249. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  128250. &_resbook_44s_0,&_resbook_44sm_0},
  128251. {2,0, &_residue_44_low,
  128252. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  128253. &_resbook_44s_0,&_resbook_44sm_0}
  128254. };
  128255. static vorbis_residue_template _res_44s_1[]={
  128256. {2,0, &_residue_44_low,
  128257. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  128258. &_resbook_44s_1,&_resbook_44sm_1},
  128259. {2,0, &_residue_44_low,
  128260. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  128261. &_resbook_44s_1,&_resbook_44sm_1}
  128262. };
  128263. static vorbis_residue_template _res_44s_2[]={
  128264. {2,0, &_residue_44_mid,
  128265. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  128266. &_resbook_44s_2,&_resbook_44s_2},
  128267. {2,0, &_residue_44_mid,
  128268. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  128269. &_resbook_44s_2,&_resbook_44s_2}
  128270. };
  128271. static vorbis_residue_template _res_44s_3[]={
  128272. {2,0, &_residue_44_mid,
  128273. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  128274. &_resbook_44s_3,&_resbook_44s_3},
  128275. {2,0, &_residue_44_mid,
  128276. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  128277. &_resbook_44s_3,&_resbook_44s_3}
  128278. };
  128279. static vorbis_residue_template _res_44s_4[]={
  128280. {2,0, &_residue_44_mid,
  128281. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  128282. &_resbook_44s_4,&_resbook_44s_4},
  128283. {2,0, &_residue_44_mid,
  128284. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  128285. &_resbook_44s_4,&_resbook_44s_4}
  128286. };
  128287. static vorbis_residue_template _res_44s_5[]={
  128288. {2,0, &_residue_44_mid,
  128289. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  128290. &_resbook_44s_5,&_resbook_44s_5},
  128291. {2,0, &_residue_44_mid,
  128292. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  128293. &_resbook_44s_5,&_resbook_44s_5}
  128294. };
  128295. static vorbis_residue_template _res_44s_6[]={
  128296. {2,0, &_residue_44_high,
  128297. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  128298. &_resbook_44s_6,&_resbook_44s_6},
  128299. {2,0, &_residue_44_high,
  128300. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  128301. &_resbook_44s_6,&_resbook_44s_6}
  128302. };
  128303. static vorbis_residue_template _res_44s_7[]={
  128304. {2,0, &_residue_44_high,
  128305. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  128306. &_resbook_44s_7,&_resbook_44s_7},
  128307. {2,0, &_residue_44_high,
  128308. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  128309. &_resbook_44s_7,&_resbook_44s_7}
  128310. };
  128311. static vorbis_residue_template _res_44s_8[]={
  128312. {2,0, &_residue_44_high,
  128313. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  128314. &_resbook_44s_8,&_resbook_44s_8},
  128315. {2,0, &_residue_44_high,
  128316. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  128317. &_resbook_44s_8,&_resbook_44s_8}
  128318. };
  128319. static vorbis_residue_template _res_44s_9[]={
  128320. {2,0, &_residue_44_high,
  128321. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  128322. &_resbook_44s_9,&_resbook_44s_9},
  128323. {2,0, &_residue_44_high,
  128324. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  128325. &_resbook_44s_9,&_resbook_44s_9}
  128326. };
  128327. static vorbis_mapping_template _mapres_template_44_stereo[]={
  128328. { _map_nominal, _res_44s_n1 }, /* -1 */
  128329. { _map_nominal, _res_44s_0 }, /* 0 */
  128330. { _map_nominal, _res_44s_1 }, /* 1 */
  128331. { _map_nominal, _res_44s_2 }, /* 2 */
  128332. { _map_nominal, _res_44s_3 }, /* 3 */
  128333. { _map_nominal, _res_44s_4 }, /* 4 */
  128334. { _map_nominal, _res_44s_5 }, /* 5 */
  128335. { _map_nominal, _res_44s_6 }, /* 6 */
  128336. { _map_nominal, _res_44s_7 }, /* 7 */
  128337. { _map_nominal, _res_44s_8 }, /* 8 */
  128338. { _map_nominal, _res_44s_9 }, /* 9 */
  128339. };
  128340. /*** End of inlined file: residue_44.h ***/
  128341. /*** Start of inlined file: psych_44.h ***/
  128342. static vorbis_info_psy_global _psy_global_44[5]={
  128343. {8, /* lines per eighth octave */
  128344. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  128345. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  128346. -6.f,
  128347. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128348. },
  128349. {8, /* lines per eighth octave */
  128350. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128351. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  128352. -6.f,
  128353. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128354. },
  128355. {8, /* lines per eighth octave */
  128356. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128357. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  128358. -6.f,
  128359. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128360. },
  128361. {8, /* lines per eighth octave */
  128362. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  128363. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  128364. -6.f,
  128365. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128366. },
  128367. {8, /* lines per eighth octave */
  128368. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  128369. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  128370. -6.f,
  128371. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128372. },
  128373. };
  128374. static compandblock _psy_compand_44[6]={
  128375. {{
  128376. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128377. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128378. 16,17,18,19,20,21,22, 23, /* 23dB */
  128379. 24,25,26,27,28,29,30, 31, /* 31dB */
  128380. 32,33,34,35,36,37,38, 39, /* 39dB */
  128381. }},
  128382. {{
  128383. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  128384. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  128385. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  128386. 15,16,17,17,17,18,18, 19, /* 31dB */
  128387. 19,19,20,21,22,23,24, 25, /* 39dB */
  128388. }},
  128389. {{
  128390. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  128391. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  128392. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128393. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128394. 11,12,13,14,15,16,17, 18, /* 39dB */
  128395. }},
  128396. {{
  128397. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128398. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128399. 16,17,18,19,20,21,22, 23, /* 23dB */
  128400. 24,25,26,27,28,29,30, 31, /* 31dB */
  128401. 32,33,34,35,36,37,38, 39, /* 39dB */
  128402. }},
  128403. {{
  128404. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128405. 8, 9,10,11,12,12,13, 13, /* 15dB */
  128406. 13,14,14,14,15,15,15, 15, /* 23dB */
  128407. 16,16,17,17,17,18,18, 19, /* 31dB */
  128408. 19,19,20,21,22,23,24, 25, /* 39dB */
  128409. }},
  128410. {{
  128411. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128412. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  128413. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128414. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128415. 11,12,13,14,15,16,17, 18, /* 39dB */
  128416. }}
  128417. };
  128418. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  128419. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  128420. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  128421. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  128422. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  128423. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  128424. /* 4 */
  128425. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128426. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128427. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128428. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128429. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128430. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128431. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128432. };
  128433. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  128434. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  128435. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  128436. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  128437. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  128438. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  128439. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128440. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128441. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128442. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128443. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128444. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128445. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128446. };
  128447. static noise3 _psy_noisebias_trans[12]={
  128448. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128449. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128450. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128451. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128452. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  128453. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128454. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128455. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128456. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128457. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128458. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128459. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  128460. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128461. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128462. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128463. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128464. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128465. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128466. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128467. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128468. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  128469. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128470. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128471. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128472. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128473. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  128474. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128475. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  128476. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  128477. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128478. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128479. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  128480. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  128481. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  128482. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  128483. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128484. };
  128485. static noise3 _psy_noisebias_long[12]={
  128486. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  128487. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  128488. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128489. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  128490. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  128491. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128492. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128493. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128494. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128495. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128496. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128497. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128498. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128499. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128500. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  128501. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128502. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128503. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  128504. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128505. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128506. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  128507. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128508. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128509. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  128510. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128511. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  128512. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128513. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  128514. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  128515. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128516. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128517. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  128518. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128519. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  128520. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  128521. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128522. };
  128523. static noise3 _psy_noisebias_impulse[12]={
  128524. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128525. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128526. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128527. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128528. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128529. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128530. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128531. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128532. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128533. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128534. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128535. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128536. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128537. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128538. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128539. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128540. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128541. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128542. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128543. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128544. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128545. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128546. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128547. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128548. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128549. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128550. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128551. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128552. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128553. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128554. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128555. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128556. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128557. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128558. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128559. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128560. };
  128561. static noise3 _psy_noisebias_padding[12]={
  128562. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128563. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128564. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128565. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128566. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128567. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128568. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128569. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128570. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128571. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128572. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128573. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128574. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128575. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128576. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128577. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128578. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128579. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128580. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128581. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128582. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128583. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128584. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128585. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128586. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128587. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128588. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128589. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128590. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128591. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128592. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128593. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128594. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128595. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128596. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128597. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128598. };
  128599. static noiseguard _psy_noiseguards_44[4]={
  128600. {3,3,15},
  128601. {3,3,15},
  128602. {10,10,100},
  128603. {10,10,100},
  128604. };
  128605. static int _psy_tone_suppress[12]={
  128606. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128607. };
  128608. static int _psy_tone_0dB[12]={
  128609. 90,90,95,95,95,95,105,105,105,105,105,105,
  128610. };
  128611. static int _psy_noise_suppress[12]={
  128612. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128613. };
  128614. static vorbis_info_psy _psy_info_template={
  128615. -1,
  128616. -140.,-140.,
  128617. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128618. 1, -0.f, .5f, .5f, 0,0,0,
  128619. {{-1},{-1},{-1}},{-1},105.f,
  128620. 0,0,-1,-1,0.,
  128621. };
  128622. static int _psy_ath_floater[12]={
  128623. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128624. };
  128625. static int _psy_ath_abs[12]={
  128626. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128627. };
  128628. static adj_stereo _psy_stereo_modes_44[12]={
  128629. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128630. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128631. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128632. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128633. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128634. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128635. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128636. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128637. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128638. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128639. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128640. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128641. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128642. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128643. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128644. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128645. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128646. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128647. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128648. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128649. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128650. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128651. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128652. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128653. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128654. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128655. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128656. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128657. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128658. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128659. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128660. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128661. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128662. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128663. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128664. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128665. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128666. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128667. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128668. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128669. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128670. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128671. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128672. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128673. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128674. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128675. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128676. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128677. };
  128678. static att3 _psy_tone_masteratt_44[12]={
  128679. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128680. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128681. /* 1 */
  128682. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128683. /* 2 */
  128684. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128685. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128686. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128687. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128688. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128689. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128690. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128691. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128692. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128693. };
  128694. static double _psy_lowpass_44[12]={
  128695. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128696. };
  128697. static int _noise_start_short_44[11]={
  128698. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128699. };
  128700. static int _noise_start_long_44[11]={
  128701. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128702. };
  128703. static int _noise_part_short_44[11]={
  128704. 8,8,8,8,8,8,8,8,8,8,8
  128705. };
  128706. static int _noise_part_long_44[11]={
  128707. 32,32,32,32,32,32,32,32,32,32,32
  128708. };
  128709. static double _noise_thresh_44[11]={
  128710. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128711. };
  128712. static double _noise_thresh_5only[2]={
  128713. .5,.5,
  128714. };
  128715. /*** End of inlined file: psych_44.h ***/
  128716. static double rate_mapping_44_stereo[12]={
  128717. 22500.,32000.,40000.,48000.,56000.,64000.,
  128718. 80000.,96000.,112000.,128000.,160000.,250001.
  128719. };
  128720. static double quality_mapping_44[12]={
  128721. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128722. };
  128723. static int blocksize_short_44[11]={
  128724. 512,256,256,256,256,256,256,256,256,256,256
  128725. };
  128726. static int blocksize_long_44[11]={
  128727. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128728. };
  128729. static double _psy_compand_short_mapping[12]={
  128730. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128731. };
  128732. static double _psy_compand_long_mapping[12]={
  128733. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128734. };
  128735. static double _global_mapping_44[12]={
  128736. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128737. };
  128738. static int _floor_short_mapping_44[11]={
  128739. 1,0,0,2,2,4,5,5,5,5,5
  128740. };
  128741. static int _floor_long_mapping_44[11]={
  128742. 8,7,7,7,7,7,7,7,7,7,7
  128743. };
  128744. ve_setup_data_template ve_setup_44_stereo={
  128745. 11,
  128746. rate_mapping_44_stereo,
  128747. quality_mapping_44,
  128748. 2,
  128749. 40000,
  128750. 50000,
  128751. blocksize_short_44,
  128752. blocksize_long_44,
  128753. _psy_tone_masteratt_44,
  128754. _psy_tone_0dB,
  128755. _psy_tone_suppress,
  128756. _vp_tonemask_adj_otherblock,
  128757. _vp_tonemask_adj_longblock,
  128758. _vp_tonemask_adj_otherblock,
  128759. _psy_noiseguards_44,
  128760. _psy_noisebias_impulse,
  128761. _psy_noisebias_padding,
  128762. _psy_noisebias_trans,
  128763. _psy_noisebias_long,
  128764. _psy_noise_suppress,
  128765. _psy_compand_44,
  128766. _psy_compand_short_mapping,
  128767. _psy_compand_long_mapping,
  128768. {_noise_start_short_44,_noise_start_long_44},
  128769. {_noise_part_short_44,_noise_part_long_44},
  128770. _noise_thresh_44,
  128771. _psy_ath_floater,
  128772. _psy_ath_abs,
  128773. _psy_lowpass_44,
  128774. _psy_global_44,
  128775. _global_mapping_44,
  128776. _psy_stereo_modes_44,
  128777. _floor_books,
  128778. _floor,
  128779. _floor_short_mapping_44,
  128780. _floor_long_mapping_44,
  128781. _mapres_template_44_stereo
  128782. };
  128783. /*** End of inlined file: setup_44.h ***/
  128784. /*** Start of inlined file: setup_44u.h ***/
  128785. /*** Start of inlined file: residue_44u.h ***/
  128786. /*** Start of inlined file: res_books_uncoupled.h ***/
  128787. static long _vq_quantlist__16u0__p1_0[] = {
  128788. 1,
  128789. 0,
  128790. 2,
  128791. };
  128792. static long _vq_lengthlist__16u0__p1_0[] = {
  128793. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128794. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128795. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128796. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128797. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128798. 12,
  128799. };
  128800. static float _vq_quantthresh__16u0__p1_0[] = {
  128801. -0.5, 0.5,
  128802. };
  128803. static long _vq_quantmap__16u0__p1_0[] = {
  128804. 1, 0, 2,
  128805. };
  128806. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128807. _vq_quantthresh__16u0__p1_0,
  128808. _vq_quantmap__16u0__p1_0,
  128809. 3,
  128810. 3
  128811. };
  128812. static static_codebook _16u0__p1_0 = {
  128813. 4, 81,
  128814. _vq_lengthlist__16u0__p1_0,
  128815. 1, -535822336, 1611661312, 2, 0,
  128816. _vq_quantlist__16u0__p1_0,
  128817. NULL,
  128818. &_vq_auxt__16u0__p1_0,
  128819. NULL,
  128820. 0
  128821. };
  128822. static long _vq_quantlist__16u0__p2_0[] = {
  128823. 1,
  128824. 0,
  128825. 2,
  128826. };
  128827. static long _vq_lengthlist__16u0__p2_0[] = {
  128828. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128829. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128830. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128831. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128832. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128833. 8,
  128834. };
  128835. static float _vq_quantthresh__16u0__p2_0[] = {
  128836. -0.5, 0.5,
  128837. };
  128838. static long _vq_quantmap__16u0__p2_0[] = {
  128839. 1, 0, 2,
  128840. };
  128841. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128842. _vq_quantthresh__16u0__p2_0,
  128843. _vq_quantmap__16u0__p2_0,
  128844. 3,
  128845. 3
  128846. };
  128847. static static_codebook _16u0__p2_0 = {
  128848. 4, 81,
  128849. _vq_lengthlist__16u0__p2_0,
  128850. 1, -535822336, 1611661312, 2, 0,
  128851. _vq_quantlist__16u0__p2_0,
  128852. NULL,
  128853. &_vq_auxt__16u0__p2_0,
  128854. NULL,
  128855. 0
  128856. };
  128857. static long _vq_quantlist__16u0__p3_0[] = {
  128858. 2,
  128859. 1,
  128860. 3,
  128861. 0,
  128862. 4,
  128863. };
  128864. static long _vq_lengthlist__16u0__p3_0[] = {
  128865. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128866. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128867. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128868. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128869. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128870. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128871. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128872. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128873. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128874. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128875. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128876. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128877. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128878. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128879. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128880. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128881. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128882. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128883. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128884. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128885. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128886. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128887. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128888. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128889. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128890. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128891. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128892. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128893. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128894. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128895. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128896. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128897. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128898. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128899. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128900. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128901. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128902. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128903. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128904. 18,
  128905. };
  128906. static float _vq_quantthresh__16u0__p3_0[] = {
  128907. -1.5, -0.5, 0.5, 1.5,
  128908. };
  128909. static long _vq_quantmap__16u0__p3_0[] = {
  128910. 3, 1, 0, 2, 4,
  128911. };
  128912. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128913. _vq_quantthresh__16u0__p3_0,
  128914. _vq_quantmap__16u0__p3_0,
  128915. 5,
  128916. 5
  128917. };
  128918. static static_codebook _16u0__p3_0 = {
  128919. 4, 625,
  128920. _vq_lengthlist__16u0__p3_0,
  128921. 1, -533725184, 1611661312, 3, 0,
  128922. _vq_quantlist__16u0__p3_0,
  128923. NULL,
  128924. &_vq_auxt__16u0__p3_0,
  128925. NULL,
  128926. 0
  128927. };
  128928. static long _vq_quantlist__16u0__p4_0[] = {
  128929. 2,
  128930. 1,
  128931. 3,
  128932. 0,
  128933. 4,
  128934. };
  128935. static long _vq_lengthlist__16u0__p4_0[] = {
  128936. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128937. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128938. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128939. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128940. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128941. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128942. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128943. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128944. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128945. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128946. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128947. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128948. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128949. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128950. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128951. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128952. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128953. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128954. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128955. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128956. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128957. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128958. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128959. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128960. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128961. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128962. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128963. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128964. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128965. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128966. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128967. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128968. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128969. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128970. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128971. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128972. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128973. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128974. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128975. 11,
  128976. };
  128977. static float _vq_quantthresh__16u0__p4_0[] = {
  128978. -1.5, -0.5, 0.5, 1.5,
  128979. };
  128980. static long _vq_quantmap__16u0__p4_0[] = {
  128981. 3, 1, 0, 2, 4,
  128982. };
  128983. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128984. _vq_quantthresh__16u0__p4_0,
  128985. _vq_quantmap__16u0__p4_0,
  128986. 5,
  128987. 5
  128988. };
  128989. static static_codebook _16u0__p4_0 = {
  128990. 4, 625,
  128991. _vq_lengthlist__16u0__p4_0,
  128992. 1, -533725184, 1611661312, 3, 0,
  128993. _vq_quantlist__16u0__p4_0,
  128994. NULL,
  128995. &_vq_auxt__16u0__p4_0,
  128996. NULL,
  128997. 0
  128998. };
  128999. static long _vq_quantlist__16u0__p5_0[] = {
  129000. 4,
  129001. 3,
  129002. 5,
  129003. 2,
  129004. 6,
  129005. 1,
  129006. 7,
  129007. 0,
  129008. 8,
  129009. };
  129010. static long _vq_lengthlist__16u0__p5_0[] = {
  129011. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129012. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  129013. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  129014. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  129015. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  129016. 12,
  129017. };
  129018. static float _vq_quantthresh__16u0__p5_0[] = {
  129019. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129020. };
  129021. static long _vq_quantmap__16u0__p5_0[] = {
  129022. 7, 5, 3, 1, 0, 2, 4, 6,
  129023. 8,
  129024. };
  129025. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  129026. _vq_quantthresh__16u0__p5_0,
  129027. _vq_quantmap__16u0__p5_0,
  129028. 9,
  129029. 9
  129030. };
  129031. static static_codebook _16u0__p5_0 = {
  129032. 2, 81,
  129033. _vq_lengthlist__16u0__p5_0,
  129034. 1, -531628032, 1611661312, 4, 0,
  129035. _vq_quantlist__16u0__p5_0,
  129036. NULL,
  129037. &_vq_auxt__16u0__p5_0,
  129038. NULL,
  129039. 0
  129040. };
  129041. static long _vq_quantlist__16u0__p6_0[] = {
  129042. 6,
  129043. 5,
  129044. 7,
  129045. 4,
  129046. 8,
  129047. 3,
  129048. 9,
  129049. 2,
  129050. 10,
  129051. 1,
  129052. 11,
  129053. 0,
  129054. 12,
  129055. };
  129056. static long _vq_lengthlist__16u0__p6_0[] = {
  129057. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  129058. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  129059. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  129060. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  129061. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  129062. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  129063. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  129064. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  129065. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  129066. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  129067. 18, 0,19, 0, 0, 0, 0, 0, 0,
  129068. };
  129069. static float _vq_quantthresh__16u0__p6_0[] = {
  129070. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129071. 12.5, 17.5, 22.5, 27.5,
  129072. };
  129073. static long _vq_quantmap__16u0__p6_0[] = {
  129074. 11, 9, 7, 5, 3, 1, 0, 2,
  129075. 4, 6, 8, 10, 12,
  129076. };
  129077. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  129078. _vq_quantthresh__16u0__p6_0,
  129079. _vq_quantmap__16u0__p6_0,
  129080. 13,
  129081. 13
  129082. };
  129083. static static_codebook _16u0__p6_0 = {
  129084. 2, 169,
  129085. _vq_lengthlist__16u0__p6_0,
  129086. 1, -526516224, 1616117760, 4, 0,
  129087. _vq_quantlist__16u0__p6_0,
  129088. NULL,
  129089. &_vq_auxt__16u0__p6_0,
  129090. NULL,
  129091. 0
  129092. };
  129093. static long _vq_quantlist__16u0__p6_1[] = {
  129094. 2,
  129095. 1,
  129096. 3,
  129097. 0,
  129098. 4,
  129099. };
  129100. static long _vq_lengthlist__16u0__p6_1[] = {
  129101. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  129102. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  129103. };
  129104. static float _vq_quantthresh__16u0__p6_1[] = {
  129105. -1.5, -0.5, 0.5, 1.5,
  129106. };
  129107. static long _vq_quantmap__16u0__p6_1[] = {
  129108. 3, 1, 0, 2, 4,
  129109. };
  129110. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  129111. _vq_quantthresh__16u0__p6_1,
  129112. _vq_quantmap__16u0__p6_1,
  129113. 5,
  129114. 5
  129115. };
  129116. static static_codebook _16u0__p6_1 = {
  129117. 2, 25,
  129118. _vq_lengthlist__16u0__p6_1,
  129119. 1, -533725184, 1611661312, 3, 0,
  129120. _vq_quantlist__16u0__p6_1,
  129121. NULL,
  129122. &_vq_auxt__16u0__p6_1,
  129123. NULL,
  129124. 0
  129125. };
  129126. static long _vq_quantlist__16u0__p7_0[] = {
  129127. 1,
  129128. 0,
  129129. 2,
  129130. };
  129131. static long _vq_lengthlist__16u0__p7_0[] = {
  129132. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129133. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129134. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129135. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129136. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129137. 7,
  129138. };
  129139. static float _vq_quantthresh__16u0__p7_0[] = {
  129140. -157.5, 157.5,
  129141. };
  129142. static long _vq_quantmap__16u0__p7_0[] = {
  129143. 1, 0, 2,
  129144. };
  129145. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  129146. _vq_quantthresh__16u0__p7_0,
  129147. _vq_quantmap__16u0__p7_0,
  129148. 3,
  129149. 3
  129150. };
  129151. static static_codebook _16u0__p7_0 = {
  129152. 4, 81,
  129153. _vq_lengthlist__16u0__p7_0,
  129154. 1, -518803456, 1628680192, 2, 0,
  129155. _vq_quantlist__16u0__p7_0,
  129156. NULL,
  129157. &_vq_auxt__16u0__p7_0,
  129158. NULL,
  129159. 0
  129160. };
  129161. static long _vq_quantlist__16u0__p7_1[] = {
  129162. 7,
  129163. 6,
  129164. 8,
  129165. 5,
  129166. 9,
  129167. 4,
  129168. 10,
  129169. 3,
  129170. 11,
  129171. 2,
  129172. 12,
  129173. 1,
  129174. 13,
  129175. 0,
  129176. 14,
  129177. };
  129178. static long _vq_lengthlist__16u0__p7_1[] = {
  129179. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  129180. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  129181. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  129182. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  129183. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  129184. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  129185. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129186. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129187. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129188. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129189. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129190. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129191. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129192. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129193. 10,
  129194. };
  129195. static float _vq_quantthresh__16u0__p7_1[] = {
  129196. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  129197. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  129198. };
  129199. static long _vq_quantmap__16u0__p7_1[] = {
  129200. 13, 11, 9, 7, 5, 3, 1, 0,
  129201. 2, 4, 6, 8, 10, 12, 14,
  129202. };
  129203. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  129204. _vq_quantthresh__16u0__p7_1,
  129205. _vq_quantmap__16u0__p7_1,
  129206. 15,
  129207. 15
  129208. };
  129209. static static_codebook _16u0__p7_1 = {
  129210. 2, 225,
  129211. _vq_lengthlist__16u0__p7_1,
  129212. 1, -520986624, 1620377600, 4, 0,
  129213. _vq_quantlist__16u0__p7_1,
  129214. NULL,
  129215. &_vq_auxt__16u0__p7_1,
  129216. NULL,
  129217. 0
  129218. };
  129219. static long _vq_quantlist__16u0__p7_2[] = {
  129220. 10,
  129221. 9,
  129222. 11,
  129223. 8,
  129224. 12,
  129225. 7,
  129226. 13,
  129227. 6,
  129228. 14,
  129229. 5,
  129230. 15,
  129231. 4,
  129232. 16,
  129233. 3,
  129234. 17,
  129235. 2,
  129236. 18,
  129237. 1,
  129238. 19,
  129239. 0,
  129240. 20,
  129241. };
  129242. static long _vq_lengthlist__16u0__p7_2[] = {
  129243. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  129244. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  129245. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  129246. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  129247. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  129248. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  129249. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  129250. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  129251. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  129252. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  129253. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  129254. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  129255. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  129256. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  129257. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  129258. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  129259. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  129260. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  129261. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  129262. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  129263. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  129264. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  129265. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  129266. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  129267. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  129268. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  129269. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  129270. 10,10,12,11,10,11,11,11,10,
  129271. };
  129272. static float _vq_quantthresh__16u0__p7_2[] = {
  129273. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  129274. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  129275. 6.5, 7.5, 8.5, 9.5,
  129276. };
  129277. static long _vq_quantmap__16u0__p7_2[] = {
  129278. 19, 17, 15, 13, 11, 9, 7, 5,
  129279. 3, 1, 0, 2, 4, 6, 8, 10,
  129280. 12, 14, 16, 18, 20,
  129281. };
  129282. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  129283. _vq_quantthresh__16u0__p7_2,
  129284. _vq_quantmap__16u0__p7_2,
  129285. 21,
  129286. 21
  129287. };
  129288. static static_codebook _16u0__p7_2 = {
  129289. 2, 441,
  129290. _vq_lengthlist__16u0__p7_2,
  129291. 1, -529268736, 1611661312, 5, 0,
  129292. _vq_quantlist__16u0__p7_2,
  129293. NULL,
  129294. &_vq_auxt__16u0__p7_2,
  129295. NULL,
  129296. 0
  129297. };
  129298. static long _huff_lengthlist__16u0__single[] = {
  129299. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  129300. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  129301. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  129302. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  129303. };
  129304. static static_codebook _huff_book__16u0__single = {
  129305. 2, 64,
  129306. _huff_lengthlist__16u0__single,
  129307. 0, 0, 0, 0, 0,
  129308. NULL,
  129309. NULL,
  129310. NULL,
  129311. NULL,
  129312. 0
  129313. };
  129314. static long _huff_lengthlist__16u1__long[] = {
  129315. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  129316. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  129317. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  129318. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  129319. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  129320. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  129321. 16,13,16,18,
  129322. };
  129323. static static_codebook _huff_book__16u1__long = {
  129324. 2, 100,
  129325. _huff_lengthlist__16u1__long,
  129326. 0, 0, 0, 0, 0,
  129327. NULL,
  129328. NULL,
  129329. NULL,
  129330. NULL,
  129331. 0
  129332. };
  129333. static long _vq_quantlist__16u1__p1_0[] = {
  129334. 1,
  129335. 0,
  129336. 2,
  129337. };
  129338. static long _vq_lengthlist__16u1__p1_0[] = {
  129339. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  129340. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  129341. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  129342. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  129343. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  129344. 11,
  129345. };
  129346. static float _vq_quantthresh__16u1__p1_0[] = {
  129347. -0.5, 0.5,
  129348. };
  129349. static long _vq_quantmap__16u1__p1_0[] = {
  129350. 1, 0, 2,
  129351. };
  129352. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  129353. _vq_quantthresh__16u1__p1_0,
  129354. _vq_quantmap__16u1__p1_0,
  129355. 3,
  129356. 3
  129357. };
  129358. static static_codebook _16u1__p1_0 = {
  129359. 4, 81,
  129360. _vq_lengthlist__16u1__p1_0,
  129361. 1, -535822336, 1611661312, 2, 0,
  129362. _vq_quantlist__16u1__p1_0,
  129363. NULL,
  129364. &_vq_auxt__16u1__p1_0,
  129365. NULL,
  129366. 0
  129367. };
  129368. static long _vq_quantlist__16u1__p2_0[] = {
  129369. 1,
  129370. 0,
  129371. 2,
  129372. };
  129373. static long _vq_lengthlist__16u1__p2_0[] = {
  129374. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  129375. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  129376. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  129377. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  129378. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  129379. 8,
  129380. };
  129381. static float _vq_quantthresh__16u1__p2_0[] = {
  129382. -0.5, 0.5,
  129383. };
  129384. static long _vq_quantmap__16u1__p2_0[] = {
  129385. 1, 0, 2,
  129386. };
  129387. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  129388. _vq_quantthresh__16u1__p2_0,
  129389. _vq_quantmap__16u1__p2_0,
  129390. 3,
  129391. 3
  129392. };
  129393. static static_codebook _16u1__p2_0 = {
  129394. 4, 81,
  129395. _vq_lengthlist__16u1__p2_0,
  129396. 1, -535822336, 1611661312, 2, 0,
  129397. _vq_quantlist__16u1__p2_0,
  129398. NULL,
  129399. &_vq_auxt__16u1__p2_0,
  129400. NULL,
  129401. 0
  129402. };
  129403. static long _vq_quantlist__16u1__p3_0[] = {
  129404. 2,
  129405. 1,
  129406. 3,
  129407. 0,
  129408. 4,
  129409. };
  129410. static long _vq_lengthlist__16u1__p3_0[] = {
  129411. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129412. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  129413. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  129414. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  129415. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  129416. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  129417. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  129418. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  129419. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  129420. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  129421. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  129422. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  129423. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  129424. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  129425. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  129426. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  129427. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  129428. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  129429. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  129430. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  129431. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  129432. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  129433. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  129434. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  129435. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  129436. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  129437. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  129438. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  129439. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  129440. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  129441. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  129442. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  129443. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  129444. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  129445. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  129446. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  129447. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  129448. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  129449. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  129450. 16,
  129451. };
  129452. static float _vq_quantthresh__16u1__p3_0[] = {
  129453. -1.5, -0.5, 0.5, 1.5,
  129454. };
  129455. static long _vq_quantmap__16u1__p3_0[] = {
  129456. 3, 1, 0, 2, 4,
  129457. };
  129458. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  129459. _vq_quantthresh__16u1__p3_0,
  129460. _vq_quantmap__16u1__p3_0,
  129461. 5,
  129462. 5
  129463. };
  129464. static static_codebook _16u1__p3_0 = {
  129465. 4, 625,
  129466. _vq_lengthlist__16u1__p3_0,
  129467. 1, -533725184, 1611661312, 3, 0,
  129468. _vq_quantlist__16u1__p3_0,
  129469. NULL,
  129470. &_vq_auxt__16u1__p3_0,
  129471. NULL,
  129472. 0
  129473. };
  129474. static long _vq_quantlist__16u1__p4_0[] = {
  129475. 2,
  129476. 1,
  129477. 3,
  129478. 0,
  129479. 4,
  129480. };
  129481. static long _vq_lengthlist__16u1__p4_0[] = {
  129482. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  129483. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  129484. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  129485. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  129486. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  129487. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  129488. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  129489. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  129490. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  129491. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  129492. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  129493. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  129494. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  129495. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  129496. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  129497. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  129498. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  129499. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  129500. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  129501. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  129502. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  129503. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  129504. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  129505. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  129506. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  129507. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  129508. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  129509. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  129510. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  129511. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  129512. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  129513. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  129514. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  129515. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  129516. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  129517. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  129518. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  129519. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  129520. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  129521. 11,
  129522. };
  129523. static float _vq_quantthresh__16u1__p4_0[] = {
  129524. -1.5, -0.5, 0.5, 1.5,
  129525. };
  129526. static long _vq_quantmap__16u1__p4_0[] = {
  129527. 3, 1, 0, 2, 4,
  129528. };
  129529. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129530. _vq_quantthresh__16u1__p4_0,
  129531. _vq_quantmap__16u1__p4_0,
  129532. 5,
  129533. 5
  129534. };
  129535. static static_codebook _16u1__p4_0 = {
  129536. 4, 625,
  129537. _vq_lengthlist__16u1__p4_0,
  129538. 1, -533725184, 1611661312, 3, 0,
  129539. _vq_quantlist__16u1__p4_0,
  129540. NULL,
  129541. &_vq_auxt__16u1__p4_0,
  129542. NULL,
  129543. 0
  129544. };
  129545. static long _vq_quantlist__16u1__p5_0[] = {
  129546. 4,
  129547. 3,
  129548. 5,
  129549. 2,
  129550. 6,
  129551. 1,
  129552. 7,
  129553. 0,
  129554. 8,
  129555. };
  129556. static long _vq_lengthlist__16u1__p5_0[] = {
  129557. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129558. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129559. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129560. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129561. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129562. 13,
  129563. };
  129564. static float _vq_quantthresh__16u1__p5_0[] = {
  129565. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129566. };
  129567. static long _vq_quantmap__16u1__p5_0[] = {
  129568. 7, 5, 3, 1, 0, 2, 4, 6,
  129569. 8,
  129570. };
  129571. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129572. _vq_quantthresh__16u1__p5_0,
  129573. _vq_quantmap__16u1__p5_0,
  129574. 9,
  129575. 9
  129576. };
  129577. static static_codebook _16u1__p5_0 = {
  129578. 2, 81,
  129579. _vq_lengthlist__16u1__p5_0,
  129580. 1, -531628032, 1611661312, 4, 0,
  129581. _vq_quantlist__16u1__p5_0,
  129582. NULL,
  129583. &_vq_auxt__16u1__p5_0,
  129584. NULL,
  129585. 0
  129586. };
  129587. static long _vq_quantlist__16u1__p6_0[] = {
  129588. 4,
  129589. 3,
  129590. 5,
  129591. 2,
  129592. 6,
  129593. 1,
  129594. 7,
  129595. 0,
  129596. 8,
  129597. };
  129598. static long _vq_lengthlist__16u1__p6_0[] = {
  129599. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129600. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129601. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129602. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129603. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129604. 11,
  129605. };
  129606. static float _vq_quantthresh__16u1__p6_0[] = {
  129607. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129608. };
  129609. static long _vq_quantmap__16u1__p6_0[] = {
  129610. 7, 5, 3, 1, 0, 2, 4, 6,
  129611. 8,
  129612. };
  129613. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129614. _vq_quantthresh__16u1__p6_0,
  129615. _vq_quantmap__16u1__p6_0,
  129616. 9,
  129617. 9
  129618. };
  129619. static static_codebook _16u1__p6_0 = {
  129620. 2, 81,
  129621. _vq_lengthlist__16u1__p6_0,
  129622. 1, -531628032, 1611661312, 4, 0,
  129623. _vq_quantlist__16u1__p6_0,
  129624. NULL,
  129625. &_vq_auxt__16u1__p6_0,
  129626. NULL,
  129627. 0
  129628. };
  129629. static long _vq_quantlist__16u1__p7_0[] = {
  129630. 1,
  129631. 0,
  129632. 2,
  129633. };
  129634. static long _vq_lengthlist__16u1__p7_0[] = {
  129635. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129636. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129637. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129638. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129639. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129640. 13,
  129641. };
  129642. static float _vq_quantthresh__16u1__p7_0[] = {
  129643. -5.5, 5.5,
  129644. };
  129645. static long _vq_quantmap__16u1__p7_0[] = {
  129646. 1, 0, 2,
  129647. };
  129648. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129649. _vq_quantthresh__16u1__p7_0,
  129650. _vq_quantmap__16u1__p7_0,
  129651. 3,
  129652. 3
  129653. };
  129654. static static_codebook _16u1__p7_0 = {
  129655. 4, 81,
  129656. _vq_lengthlist__16u1__p7_0,
  129657. 1, -529137664, 1618345984, 2, 0,
  129658. _vq_quantlist__16u1__p7_0,
  129659. NULL,
  129660. &_vq_auxt__16u1__p7_0,
  129661. NULL,
  129662. 0
  129663. };
  129664. static long _vq_quantlist__16u1__p7_1[] = {
  129665. 5,
  129666. 4,
  129667. 6,
  129668. 3,
  129669. 7,
  129670. 2,
  129671. 8,
  129672. 1,
  129673. 9,
  129674. 0,
  129675. 10,
  129676. };
  129677. static long _vq_lengthlist__16u1__p7_1[] = {
  129678. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129679. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129680. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129681. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129682. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129683. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129684. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129685. 8, 9, 9,10,10,10,10,10,10,
  129686. };
  129687. static float _vq_quantthresh__16u1__p7_1[] = {
  129688. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129689. 3.5, 4.5,
  129690. };
  129691. static long _vq_quantmap__16u1__p7_1[] = {
  129692. 9, 7, 5, 3, 1, 0, 2, 4,
  129693. 6, 8, 10,
  129694. };
  129695. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129696. _vq_quantthresh__16u1__p7_1,
  129697. _vq_quantmap__16u1__p7_1,
  129698. 11,
  129699. 11
  129700. };
  129701. static static_codebook _16u1__p7_1 = {
  129702. 2, 121,
  129703. _vq_lengthlist__16u1__p7_1,
  129704. 1, -531365888, 1611661312, 4, 0,
  129705. _vq_quantlist__16u1__p7_1,
  129706. NULL,
  129707. &_vq_auxt__16u1__p7_1,
  129708. NULL,
  129709. 0
  129710. };
  129711. static long _vq_quantlist__16u1__p8_0[] = {
  129712. 5,
  129713. 4,
  129714. 6,
  129715. 3,
  129716. 7,
  129717. 2,
  129718. 8,
  129719. 1,
  129720. 9,
  129721. 0,
  129722. 10,
  129723. };
  129724. static long _vq_lengthlist__16u1__p8_0[] = {
  129725. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129726. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129727. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129728. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129729. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129730. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129731. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129732. 13,14,14,15,15,16,16,15,16,
  129733. };
  129734. static float _vq_quantthresh__16u1__p8_0[] = {
  129735. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129736. 38.5, 49.5,
  129737. };
  129738. static long _vq_quantmap__16u1__p8_0[] = {
  129739. 9, 7, 5, 3, 1, 0, 2, 4,
  129740. 6, 8, 10,
  129741. };
  129742. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129743. _vq_quantthresh__16u1__p8_0,
  129744. _vq_quantmap__16u1__p8_0,
  129745. 11,
  129746. 11
  129747. };
  129748. static static_codebook _16u1__p8_0 = {
  129749. 2, 121,
  129750. _vq_lengthlist__16u1__p8_0,
  129751. 1, -524582912, 1618345984, 4, 0,
  129752. _vq_quantlist__16u1__p8_0,
  129753. NULL,
  129754. &_vq_auxt__16u1__p8_0,
  129755. NULL,
  129756. 0
  129757. };
  129758. static long _vq_quantlist__16u1__p8_1[] = {
  129759. 5,
  129760. 4,
  129761. 6,
  129762. 3,
  129763. 7,
  129764. 2,
  129765. 8,
  129766. 1,
  129767. 9,
  129768. 0,
  129769. 10,
  129770. };
  129771. static long _vq_lengthlist__16u1__p8_1[] = {
  129772. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129773. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129774. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129775. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129776. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129777. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129778. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129779. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129780. };
  129781. static float _vq_quantthresh__16u1__p8_1[] = {
  129782. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129783. 3.5, 4.5,
  129784. };
  129785. static long _vq_quantmap__16u1__p8_1[] = {
  129786. 9, 7, 5, 3, 1, 0, 2, 4,
  129787. 6, 8, 10,
  129788. };
  129789. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129790. _vq_quantthresh__16u1__p8_1,
  129791. _vq_quantmap__16u1__p8_1,
  129792. 11,
  129793. 11
  129794. };
  129795. static static_codebook _16u1__p8_1 = {
  129796. 2, 121,
  129797. _vq_lengthlist__16u1__p8_1,
  129798. 1, -531365888, 1611661312, 4, 0,
  129799. _vq_quantlist__16u1__p8_1,
  129800. NULL,
  129801. &_vq_auxt__16u1__p8_1,
  129802. NULL,
  129803. 0
  129804. };
  129805. static long _vq_quantlist__16u1__p9_0[] = {
  129806. 7,
  129807. 6,
  129808. 8,
  129809. 5,
  129810. 9,
  129811. 4,
  129812. 10,
  129813. 3,
  129814. 11,
  129815. 2,
  129816. 12,
  129817. 1,
  129818. 13,
  129819. 0,
  129820. 14,
  129821. };
  129822. static long _vq_lengthlist__16u1__p9_0[] = {
  129823. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129824. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129825. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129826. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129827. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129828. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129829. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129830. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129831. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129832. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129833. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129834. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129835. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129836. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129837. 8,
  129838. };
  129839. static float _vq_quantthresh__16u1__p9_0[] = {
  129840. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129841. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129842. };
  129843. static long _vq_quantmap__16u1__p9_0[] = {
  129844. 13, 11, 9, 7, 5, 3, 1, 0,
  129845. 2, 4, 6, 8, 10, 12, 14,
  129846. };
  129847. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129848. _vq_quantthresh__16u1__p9_0,
  129849. _vq_quantmap__16u1__p9_0,
  129850. 15,
  129851. 15
  129852. };
  129853. static static_codebook _16u1__p9_0 = {
  129854. 2, 225,
  129855. _vq_lengthlist__16u1__p9_0,
  129856. 1, -514071552, 1627381760, 4, 0,
  129857. _vq_quantlist__16u1__p9_0,
  129858. NULL,
  129859. &_vq_auxt__16u1__p9_0,
  129860. NULL,
  129861. 0
  129862. };
  129863. static long _vq_quantlist__16u1__p9_1[] = {
  129864. 7,
  129865. 6,
  129866. 8,
  129867. 5,
  129868. 9,
  129869. 4,
  129870. 10,
  129871. 3,
  129872. 11,
  129873. 2,
  129874. 12,
  129875. 1,
  129876. 13,
  129877. 0,
  129878. 14,
  129879. };
  129880. static long _vq_lengthlist__16u1__p9_1[] = {
  129881. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129882. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129883. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129884. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129885. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129886. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129887. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129888. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129889. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129890. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129891. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129892. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129893. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129894. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129895. 9,
  129896. };
  129897. static float _vq_quantthresh__16u1__p9_1[] = {
  129898. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129899. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129900. };
  129901. static long _vq_quantmap__16u1__p9_1[] = {
  129902. 13, 11, 9, 7, 5, 3, 1, 0,
  129903. 2, 4, 6, 8, 10, 12, 14,
  129904. };
  129905. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129906. _vq_quantthresh__16u1__p9_1,
  129907. _vq_quantmap__16u1__p9_1,
  129908. 15,
  129909. 15
  129910. };
  129911. static static_codebook _16u1__p9_1 = {
  129912. 2, 225,
  129913. _vq_lengthlist__16u1__p9_1,
  129914. 1, -522338304, 1620115456, 4, 0,
  129915. _vq_quantlist__16u1__p9_1,
  129916. NULL,
  129917. &_vq_auxt__16u1__p9_1,
  129918. NULL,
  129919. 0
  129920. };
  129921. static long _vq_quantlist__16u1__p9_2[] = {
  129922. 8,
  129923. 7,
  129924. 9,
  129925. 6,
  129926. 10,
  129927. 5,
  129928. 11,
  129929. 4,
  129930. 12,
  129931. 3,
  129932. 13,
  129933. 2,
  129934. 14,
  129935. 1,
  129936. 15,
  129937. 0,
  129938. 16,
  129939. };
  129940. static long _vq_lengthlist__16u1__p9_2[] = {
  129941. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129942. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129943. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129944. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129945. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129946. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129947. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129948. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129949. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129950. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129951. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129952. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129953. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129954. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129955. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129956. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129957. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129958. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129959. 10,
  129960. };
  129961. static float _vq_quantthresh__16u1__p9_2[] = {
  129962. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129963. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129964. };
  129965. static long _vq_quantmap__16u1__p9_2[] = {
  129966. 15, 13, 11, 9, 7, 5, 3, 1,
  129967. 0, 2, 4, 6, 8, 10, 12, 14,
  129968. 16,
  129969. };
  129970. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129971. _vq_quantthresh__16u1__p9_2,
  129972. _vq_quantmap__16u1__p9_2,
  129973. 17,
  129974. 17
  129975. };
  129976. static static_codebook _16u1__p9_2 = {
  129977. 2, 289,
  129978. _vq_lengthlist__16u1__p9_2,
  129979. 1, -529530880, 1611661312, 5, 0,
  129980. _vq_quantlist__16u1__p9_2,
  129981. NULL,
  129982. &_vq_auxt__16u1__p9_2,
  129983. NULL,
  129984. 0
  129985. };
  129986. static long _huff_lengthlist__16u1__short[] = {
  129987. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129988. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129989. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129990. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129991. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129992. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129993. 16,16,16,16,
  129994. };
  129995. static static_codebook _huff_book__16u1__short = {
  129996. 2, 100,
  129997. _huff_lengthlist__16u1__short,
  129998. 0, 0, 0, 0, 0,
  129999. NULL,
  130000. NULL,
  130001. NULL,
  130002. NULL,
  130003. 0
  130004. };
  130005. static long _huff_lengthlist__16u2__long[] = {
  130006. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  130007. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  130008. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  130009. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  130010. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  130011. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  130012. 13,14,18,18,
  130013. };
  130014. static static_codebook _huff_book__16u2__long = {
  130015. 2, 100,
  130016. _huff_lengthlist__16u2__long,
  130017. 0, 0, 0, 0, 0,
  130018. NULL,
  130019. NULL,
  130020. NULL,
  130021. NULL,
  130022. 0
  130023. };
  130024. static long _huff_lengthlist__16u2__short[] = {
  130025. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  130026. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  130027. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  130028. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  130029. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  130030. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  130031. 16,16,16,16,
  130032. };
  130033. static static_codebook _huff_book__16u2__short = {
  130034. 2, 100,
  130035. _huff_lengthlist__16u2__short,
  130036. 0, 0, 0, 0, 0,
  130037. NULL,
  130038. NULL,
  130039. NULL,
  130040. NULL,
  130041. 0
  130042. };
  130043. static long _vq_quantlist__16u2_p1_0[] = {
  130044. 1,
  130045. 0,
  130046. 2,
  130047. };
  130048. static long _vq_lengthlist__16u2_p1_0[] = {
  130049. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  130050. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  130051. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  130052. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  130053. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  130054. 10,
  130055. };
  130056. static float _vq_quantthresh__16u2_p1_0[] = {
  130057. -0.5, 0.5,
  130058. };
  130059. static long _vq_quantmap__16u2_p1_0[] = {
  130060. 1, 0, 2,
  130061. };
  130062. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  130063. _vq_quantthresh__16u2_p1_0,
  130064. _vq_quantmap__16u2_p1_0,
  130065. 3,
  130066. 3
  130067. };
  130068. static static_codebook _16u2_p1_0 = {
  130069. 4, 81,
  130070. _vq_lengthlist__16u2_p1_0,
  130071. 1, -535822336, 1611661312, 2, 0,
  130072. _vq_quantlist__16u2_p1_0,
  130073. NULL,
  130074. &_vq_auxt__16u2_p1_0,
  130075. NULL,
  130076. 0
  130077. };
  130078. static long _vq_quantlist__16u2_p2_0[] = {
  130079. 2,
  130080. 1,
  130081. 3,
  130082. 0,
  130083. 4,
  130084. };
  130085. static long _vq_lengthlist__16u2_p2_0[] = {
  130086. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  130087. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  130088. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  130089. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  130090. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  130091. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  130092. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  130093. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  130094. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  130095. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  130096. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  130097. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  130098. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  130099. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  130100. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  130101. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  130102. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  130103. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  130104. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  130105. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  130106. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  130107. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  130108. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  130109. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  130110. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  130111. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  130112. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  130113. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  130114. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  130115. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  130116. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  130117. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  130118. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  130119. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  130120. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  130121. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  130122. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  130123. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  130124. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  130125. 13,
  130126. };
  130127. static float _vq_quantthresh__16u2_p2_0[] = {
  130128. -1.5, -0.5, 0.5, 1.5,
  130129. };
  130130. static long _vq_quantmap__16u2_p2_0[] = {
  130131. 3, 1, 0, 2, 4,
  130132. };
  130133. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  130134. _vq_quantthresh__16u2_p2_0,
  130135. _vq_quantmap__16u2_p2_0,
  130136. 5,
  130137. 5
  130138. };
  130139. static static_codebook _16u2_p2_0 = {
  130140. 4, 625,
  130141. _vq_lengthlist__16u2_p2_0,
  130142. 1, -533725184, 1611661312, 3, 0,
  130143. _vq_quantlist__16u2_p2_0,
  130144. NULL,
  130145. &_vq_auxt__16u2_p2_0,
  130146. NULL,
  130147. 0
  130148. };
  130149. static long _vq_quantlist__16u2_p3_0[] = {
  130150. 4,
  130151. 3,
  130152. 5,
  130153. 2,
  130154. 6,
  130155. 1,
  130156. 7,
  130157. 0,
  130158. 8,
  130159. };
  130160. static long _vq_lengthlist__16u2_p3_0[] = {
  130161. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  130162. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  130163. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  130164. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  130165. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  130166. 11,
  130167. };
  130168. static float _vq_quantthresh__16u2_p3_0[] = {
  130169. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130170. };
  130171. static long _vq_quantmap__16u2_p3_0[] = {
  130172. 7, 5, 3, 1, 0, 2, 4, 6,
  130173. 8,
  130174. };
  130175. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  130176. _vq_quantthresh__16u2_p3_0,
  130177. _vq_quantmap__16u2_p3_0,
  130178. 9,
  130179. 9
  130180. };
  130181. static static_codebook _16u2_p3_0 = {
  130182. 2, 81,
  130183. _vq_lengthlist__16u2_p3_0,
  130184. 1, -531628032, 1611661312, 4, 0,
  130185. _vq_quantlist__16u2_p3_0,
  130186. NULL,
  130187. &_vq_auxt__16u2_p3_0,
  130188. NULL,
  130189. 0
  130190. };
  130191. static long _vq_quantlist__16u2_p4_0[] = {
  130192. 8,
  130193. 7,
  130194. 9,
  130195. 6,
  130196. 10,
  130197. 5,
  130198. 11,
  130199. 4,
  130200. 12,
  130201. 3,
  130202. 13,
  130203. 2,
  130204. 14,
  130205. 1,
  130206. 15,
  130207. 0,
  130208. 16,
  130209. };
  130210. static long _vq_lengthlist__16u2_p4_0[] = {
  130211. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  130212. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  130213. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  130214. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  130215. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  130216. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  130217. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  130218. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  130219. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  130220. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  130221. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  130222. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  130223. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  130224. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  130225. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  130226. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  130227. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  130228. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  130229. 14,
  130230. };
  130231. static float _vq_quantthresh__16u2_p4_0[] = {
  130232. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130233. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130234. };
  130235. static long _vq_quantmap__16u2_p4_0[] = {
  130236. 15, 13, 11, 9, 7, 5, 3, 1,
  130237. 0, 2, 4, 6, 8, 10, 12, 14,
  130238. 16,
  130239. };
  130240. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  130241. _vq_quantthresh__16u2_p4_0,
  130242. _vq_quantmap__16u2_p4_0,
  130243. 17,
  130244. 17
  130245. };
  130246. static static_codebook _16u2_p4_0 = {
  130247. 2, 289,
  130248. _vq_lengthlist__16u2_p4_0,
  130249. 1, -529530880, 1611661312, 5, 0,
  130250. _vq_quantlist__16u2_p4_0,
  130251. NULL,
  130252. &_vq_auxt__16u2_p4_0,
  130253. NULL,
  130254. 0
  130255. };
  130256. static long _vq_quantlist__16u2_p5_0[] = {
  130257. 1,
  130258. 0,
  130259. 2,
  130260. };
  130261. static long _vq_lengthlist__16u2_p5_0[] = {
  130262. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  130263. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  130264. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  130265. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  130266. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  130267. 10,
  130268. };
  130269. static float _vq_quantthresh__16u2_p5_0[] = {
  130270. -5.5, 5.5,
  130271. };
  130272. static long _vq_quantmap__16u2_p5_0[] = {
  130273. 1, 0, 2,
  130274. };
  130275. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  130276. _vq_quantthresh__16u2_p5_0,
  130277. _vq_quantmap__16u2_p5_0,
  130278. 3,
  130279. 3
  130280. };
  130281. static static_codebook _16u2_p5_0 = {
  130282. 4, 81,
  130283. _vq_lengthlist__16u2_p5_0,
  130284. 1, -529137664, 1618345984, 2, 0,
  130285. _vq_quantlist__16u2_p5_0,
  130286. NULL,
  130287. &_vq_auxt__16u2_p5_0,
  130288. NULL,
  130289. 0
  130290. };
  130291. static long _vq_quantlist__16u2_p5_1[] = {
  130292. 5,
  130293. 4,
  130294. 6,
  130295. 3,
  130296. 7,
  130297. 2,
  130298. 8,
  130299. 1,
  130300. 9,
  130301. 0,
  130302. 10,
  130303. };
  130304. static long _vq_lengthlist__16u2_p5_1[] = {
  130305. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  130306. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  130307. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  130308. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  130309. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  130310. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  130311. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  130312. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  130313. };
  130314. static float _vq_quantthresh__16u2_p5_1[] = {
  130315. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130316. 3.5, 4.5,
  130317. };
  130318. static long _vq_quantmap__16u2_p5_1[] = {
  130319. 9, 7, 5, 3, 1, 0, 2, 4,
  130320. 6, 8, 10,
  130321. };
  130322. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  130323. _vq_quantthresh__16u2_p5_1,
  130324. _vq_quantmap__16u2_p5_1,
  130325. 11,
  130326. 11
  130327. };
  130328. static static_codebook _16u2_p5_1 = {
  130329. 2, 121,
  130330. _vq_lengthlist__16u2_p5_1,
  130331. 1, -531365888, 1611661312, 4, 0,
  130332. _vq_quantlist__16u2_p5_1,
  130333. NULL,
  130334. &_vq_auxt__16u2_p5_1,
  130335. NULL,
  130336. 0
  130337. };
  130338. static long _vq_quantlist__16u2_p6_0[] = {
  130339. 6,
  130340. 5,
  130341. 7,
  130342. 4,
  130343. 8,
  130344. 3,
  130345. 9,
  130346. 2,
  130347. 10,
  130348. 1,
  130349. 11,
  130350. 0,
  130351. 12,
  130352. };
  130353. static long _vq_lengthlist__16u2_p6_0[] = {
  130354. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  130355. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  130356. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  130357. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  130358. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  130359. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  130360. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  130361. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  130362. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  130363. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  130364. 12,13,13,14,14,14,14,15,15,
  130365. };
  130366. static float _vq_quantthresh__16u2_p6_0[] = {
  130367. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130368. 12.5, 17.5, 22.5, 27.5,
  130369. };
  130370. static long _vq_quantmap__16u2_p6_0[] = {
  130371. 11, 9, 7, 5, 3, 1, 0, 2,
  130372. 4, 6, 8, 10, 12,
  130373. };
  130374. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  130375. _vq_quantthresh__16u2_p6_0,
  130376. _vq_quantmap__16u2_p6_0,
  130377. 13,
  130378. 13
  130379. };
  130380. static static_codebook _16u2_p6_0 = {
  130381. 2, 169,
  130382. _vq_lengthlist__16u2_p6_0,
  130383. 1, -526516224, 1616117760, 4, 0,
  130384. _vq_quantlist__16u2_p6_0,
  130385. NULL,
  130386. &_vq_auxt__16u2_p6_0,
  130387. NULL,
  130388. 0
  130389. };
  130390. static long _vq_quantlist__16u2_p6_1[] = {
  130391. 2,
  130392. 1,
  130393. 3,
  130394. 0,
  130395. 4,
  130396. };
  130397. static long _vq_lengthlist__16u2_p6_1[] = {
  130398. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  130399. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  130400. };
  130401. static float _vq_quantthresh__16u2_p6_1[] = {
  130402. -1.5, -0.5, 0.5, 1.5,
  130403. };
  130404. static long _vq_quantmap__16u2_p6_1[] = {
  130405. 3, 1, 0, 2, 4,
  130406. };
  130407. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  130408. _vq_quantthresh__16u2_p6_1,
  130409. _vq_quantmap__16u2_p6_1,
  130410. 5,
  130411. 5
  130412. };
  130413. static static_codebook _16u2_p6_1 = {
  130414. 2, 25,
  130415. _vq_lengthlist__16u2_p6_1,
  130416. 1, -533725184, 1611661312, 3, 0,
  130417. _vq_quantlist__16u2_p6_1,
  130418. NULL,
  130419. &_vq_auxt__16u2_p6_1,
  130420. NULL,
  130421. 0
  130422. };
  130423. static long _vq_quantlist__16u2_p7_0[] = {
  130424. 6,
  130425. 5,
  130426. 7,
  130427. 4,
  130428. 8,
  130429. 3,
  130430. 9,
  130431. 2,
  130432. 10,
  130433. 1,
  130434. 11,
  130435. 0,
  130436. 12,
  130437. };
  130438. static long _vq_lengthlist__16u2_p7_0[] = {
  130439. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  130440. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  130441. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  130442. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  130443. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  130444. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  130445. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  130446. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  130447. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  130448. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  130449. 12,13,13,13,14,14,14,15,14,
  130450. };
  130451. static float _vq_quantthresh__16u2_p7_0[] = {
  130452. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  130453. 27.5, 38.5, 49.5, 60.5,
  130454. };
  130455. static long _vq_quantmap__16u2_p7_0[] = {
  130456. 11, 9, 7, 5, 3, 1, 0, 2,
  130457. 4, 6, 8, 10, 12,
  130458. };
  130459. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  130460. _vq_quantthresh__16u2_p7_0,
  130461. _vq_quantmap__16u2_p7_0,
  130462. 13,
  130463. 13
  130464. };
  130465. static static_codebook _16u2_p7_0 = {
  130466. 2, 169,
  130467. _vq_lengthlist__16u2_p7_0,
  130468. 1, -523206656, 1618345984, 4, 0,
  130469. _vq_quantlist__16u2_p7_0,
  130470. NULL,
  130471. &_vq_auxt__16u2_p7_0,
  130472. NULL,
  130473. 0
  130474. };
  130475. static long _vq_quantlist__16u2_p7_1[] = {
  130476. 5,
  130477. 4,
  130478. 6,
  130479. 3,
  130480. 7,
  130481. 2,
  130482. 8,
  130483. 1,
  130484. 9,
  130485. 0,
  130486. 10,
  130487. };
  130488. static long _vq_lengthlist__16u2_p7_1[] = {
  130489. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  130490. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  130491. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  130492. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  130493. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  130494. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  130495. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  130496. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130497. };
  130498. static float _vq_quantthresh__16u2_p7_1[] = {
  130499. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130500. 3.5, 4.5,
  130501. };
  130502. static long _vq_quantmap__16u2_p7_1[] = {
  130503. 9, 7, 5, 3, 1, 0, 2, 4,
  130504. 6, 8, 10,
  130505. };
  130506. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  130507. _vq_quantthresh__16u2_p7_1,
  130508. _vq_quantmap__16u2_p7_1,
  130509. 11,
  130510. 11
  130511. };
  130512. static static_codebook _16u2_p7_1 = {
  130513. 2, 121,
  130514. _vq_lengthlist__16u2_p7_1,
  130515. 1, -531365888, 1611661312, 4, 0,
  130516. _vq_quantlist__16u2_p7_1,
  130517. NULL,
  130518. &_vq_auxt__16u2_p7_1,
  130519. NULL,
  130520. 0
  130521. };
  130522. static long _vq_quantlist__16u2_p8_0[] = {
  130523. 7,
  130524. 6,
  130525. 8,
  130526. 5,
  130527. 9,
  130528. 4,
  130529. 10,
  130530. 3,
  130531. 11,
  130532. 2,
  130533. 12,
  130534. 1,
  130535. 13,
  130536. 0,
  130537. 14,
  130538. };
  130539. static long _vq_lengthlist__16u2_p8_0[] = {
  130540. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130541. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130542. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130543. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130544. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130545. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130546. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130547. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130548. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130549. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130550. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130551. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130552. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130553. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130554. 14,
  130555. };
  130556. static float _vq_quantthresh__16u2_p8_0[] = {
  130557. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130558. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130559. };
  130560. static long _vq_quantmap__16u2_p8_0[] = {
  130561. 13, 11, 9, 7, 5, 3, 1, 0,
  130562. 2, 4, 6, 8, 10, 12, 14,
  130563. };
  130564. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130565. _vq_quantthresh__16u2_p8_0,
  130566. _vq_quantmap__16u2_p8_0,
  130567. 15,
  130568. 15
  130569. };
  130570. static static_codebook _16u2_p8_0 = {
  130571. 2, 225,
  130572. _vq_lengthlist__16u2_p8_0,
  130573. 1, -520986624, 1620377600, 4, 0,
  130574. _vq_quantlist__16u2_p8_0,
  130575. NULL,
  130576. &_vq_auxt__16u2_p8_0,
  130577. NULL,
  130578. 0
  130579. };
  130580. static long _vq_quantlist__16u2_p8_1[] = {
  130581. 10,
  130582. 9,
  130583. 11,
  130584. 8,
  130585. 12,
  130586. 7,
  130587. 13,
  130588. 6,
  130589. 14,
  130590. 5,
  130591. 15,
  130592. 4,
  130593. 16,
  130594. 3,
  130595. 17,
  130596. 2,
  130597. 18,
  130598. 1,
  130599. 19,
  130600. 0,
  130601. 20,
  130602. };
  130603. static long _vq_lengthlist__16u2_p8_1[] = {
  130604. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130605. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130606. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130607. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130608. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130609. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130610. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130611. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130612. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130613. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130614. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130615. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130616. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130617. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130618. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130619. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130620. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130621. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130622. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130623. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130624. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130625. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130626. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130627. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130628. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130629. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130630. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130631. 11,11,10,11,11,11,10,11,11,
  130632. };
  130633. static float _vq_quantthresh__16u2_p8_1[] = {
  130634. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130635. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130636. 6.5, 7.5, 8.5, 9.5,
  130637. };
  130638. static long _vq_quantmap__16u2_p8_1[] = {
  130639. 19, 17, 15, 13, 11, 9, 7, 5,
  130640. 3, 1, 0, 2, 4, 6, 8, 10,
  130641. 12, 14, 16, 18, 20,
  130642. };
  130643. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130644. _vq_quantthresh__16u2_p8_1,
  130645. _vq_quantmap__16u2_p8_1,
  130646. 21,
  130647. 21
  130648. };
  130649. static static_codebook _16u2_p8_1 = {
  130650. 2, 441,
  130651. _vq_lengthlist__16u2_p8_1,
  130652. 1, -529268736, 1611661312, 5, 0,
  130653. _vq_quantlist__16u2_p8_1,
  130654. NULL,
  130655. &_vq_auxt__16u2_p8_1,
  130656. NULL,
  130657. 0
  130658. };
  130659. static long _vq_quantlist__16u2_p9_0[] = {
  130660. 5586,
  130661. 4655,
  130662. 6517,
  130663. 3724,
  130664. 7448,
  130665. 2793,
  130666. 8379,
  130667. 1862,
  130668. 9310,
  130669. 931,
  130670. 10241,
  130671. 0,
  130672. 11172,
  130673. 5521,
  130674. 5651,
  130675. };
  130676. static long _vq_lengthlist__16u2_p9_0[] = {
  130677. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130678. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130679. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130680. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130681. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130682. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130683. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130684. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130685. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130686. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130687. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130688. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130689. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130690. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130691. 5,
  130692. };
  130693. static float _vq_quantthresh__16u2_p9_0[] = {
  130694. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130695. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130696. };
  130697. static long _vq_quantmap__16u2_p9_0[] = {
  130698. 11, 9, 7, 5, 3, 1, 13, 0,
  130699. 14, 2, 4, 6, 8, 10, 12,
  130700. };
  130701. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130702. _vq_quantthresh__16u2_p9_0,
  130703. _vq_quantmap__16u2_p9_0,
  130704. 15,
  130705. 15
  130706. };
  130707. static static_codebook _16u2_p9_0 = {
  130708. 2, 225,
  130709. _vq_lengthlist__16u2_p9_0,
  130710. 1, -510275072, 1611661312, 14, 0,
  130711. _vq_quantlist__16u2_p9_0,
  130712. NULL,
  130713. &_vq_auxt__16u2_p9_0,
  130714. NULL,
  130715. 0
  130716. };
  130717. static long _vq_quantlist__16u2_p9_1[] = {
  130718. 392,
  130719. 343,
  130720. 441,
  130721. 294,
  130722. 490,
  130723. 245,
  130724. 539,
  130725. 196,
  130726. 588,
  130727. 147,
  130728. 637,
  130729. 98,
  130730. 686,
  130731. 49,
  130732. 735,
  130733. 0,
  130734. 784,
  130735. 388,
  130736. 396,
  130737. };
  130738. static long _vq_lengthlist__16u2_p9_1[] = {
  130739. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130740. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130741. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130742. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130743. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130744. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130745. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130746. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130747. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130748. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130749. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130750. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130751. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130752. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130753. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130754. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130755. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130756. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130757. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130758. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130759. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130760. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130761. 11,11,11,11,11,11,11, 5, 4,
  130762. };
  130763. static float _vq_quantthresh__16u2_p9_1[] = {
  130764. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130765. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130766. 318.5, 367.5,
  130767. };
  130768. static long _vq_quantmap__16u2_p9_1[] = {
  130769. 15, 13, 11, 9, 7, 5, 3, 1,
  130770. 17, 0, 18, 2, 4, 6, 8, 10,
  130771. 12, 14, 16,
  130772. };
  130773. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130774. _vq_quantthresh__16u2_p9_1,
  130775. _vq_quantmap__16u2_p9_1,
  130776. 19,
  130777. 19
  130778. };
  130779. static static_codebook _16u2_p9_1 = {
  130780. 2, 361,
  130781. _vq_lengthlist__16u2_p9_1,
  130782. 1, -518488064, 1611661312, 10, 0,
  130783. _vq_quantlist__16u2_p9_1,
  130784. NULL,
  130785. &_vq_auxt__16u2_p9_1,
  130786. NULL,
  130787. 0
  130788. };
  130789. static long _vq_quantlist__16u2_p9_2[] = {
  130790. 24,
  130791. 23,
  130792. 25,
  130793. 22,
  130794. 26,
  130795. 21,
  130796. 27,
  130797. 20,
  130798. 28,
  130799. 19,
  130800. 29,
  130801. 18,
  130802. 30,
  130803. 17,
  130804. 31,
  130805. 16,
  130806. 32,
  130807. 15,
  130808. 33,
  130809. 14,
  130810. 34,
  130811. 13,
  130812. 35,
  130813. 12,
  130814. 36,
  130815. 11,
  130816. 37,
  130817. 10,
  130818. 38,
  130819. 9,
  130820. 39,
  130821. 8,
  130822. 40,
  130823. 7,
  130824. 41,
  130825. 6,
  130826. 42,
  130827. 5,
  130828. 43,
  130829. 4,
  130830. 44,
  130831. 3,
  130832. 45,
  130833. 2,
  130834. 46,
  130835. 1,
  130836. 47,
  130837. 0,
  130838. 48,
  130839. };
  130840. static long _vq_lengthlist__16u2_p9_2[] = {
  130841. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130842. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130843. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130844. 11,
  130845. };
  130846. static float _vq_quantthresh__16u2_p9_2[] = {
  130847. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130848. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130849. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130850. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130851. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130852. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130853. };
  130854. static long _vq_quantmap__16u2_p9_2[] = {
  130855. 47, 45, 43, 41, 39, 37, 35, 33,
  130856. 31, 29, 27, 25, 23, 21, 19, 17,
  130857. 15, 13, 11, 9, 7, 5, 3, 1,
  130858. 0, 2, 4, 6, 8, 10, 12, 14,
  130859. 16, 18, 20, 22, 24, 26, 28, 30,
  130860. 32, 34, 36, 38, 40, 42, 44, 46,
  130861. 48,
  130862. };
  130863. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130864. _vq_quantthresh__16u2_p9_2,
  130865. _vq_quantmap__16u2_p9_2,
  130866. 49,
  130867. 49
  130868. };
  130869. static static_codebook _16u2_p9_2 = {
  130870. 1, 49,
  130871. _vq_lengthlist__16u2_p9_2,
  130872. 1, -526909440, 1611661312, 6, 0,
  130873. _vq_quantlist__16u2_p9_2,
  130874. NULL,
  130875. &_vq_auxt__16u2_p9_2,
  130876. NULL,
  130877. 0
  130878. };
  130879. static long _vq_quantlist__8u0__p1_0[] = {
  130880. 1,
  130881. 0,
  130882. 2,
  130883. };
  130884. static long _vq_lengthlist__8u0__p1_0[] = {
  130885. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130886. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130887. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130888. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130889. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130890. 11,
  130891. };
  130892. static float _vq_quantthresh__8u0__p1_0[] = {
  130893. -0.5, 0.5,
  130894. };
  130895. static long _vq_quantmap__8u0__p1_0[] = {
  130896. 1, 0, 2,
  130897. };
  130898. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130899. _vq_quantthresh__8u0__p1_0,
  130900. _vq_quantmap__8u0__p1_0,
  130901. 3,
  130902. 3
  130903. };
  130904. static static_codebook _8u0__p1_0 = {
  130905. 4, 81,
  130906. _vq_lengthlist__8u0__p1_0,
  130907. 1, -535822336, 1611661312, 2, 0,
  130908. _vq_quantlist__8u0__p1_0,
  130909. NULL,
  130910. &_vq_auxt__8u0__p1_0,
  130911. NULL,
  130912. 0
  130913. };
  130914. static long _vq_quantlist__8u0__p2_0[] = {
  130915. 1,
  130916. 0,
  130917. 2,
  130918. };
  130919. static long _vq_lengthlist__8u0__p2_0[] = {
  130920. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130921. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130922. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130923. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130924. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130925. 8,
  130926. };
  130927. static float _vq_quantthresh__8u0__p2_0[] = {
  130928. -0.5, 0.5,
  130929. };
  130930. static long _vq_quantmap__8u0__p2_0[] = {
  130931. 1, 0, 2,
  130932. };
  130933. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130934. _vq_quantthresh__8u0__p2_0,
  130935. _vq_quantmap__8u0__p2_0,
  130936. 3,
  130937. 3
  130938. };
  130939. static static_codebook _8u0__p2_0 = {
  130940. 4, 81,
  130941. _vq_lengthlist__8u0__p2_0,
  130942. 1, -535822336, 1611661312, 2, 0,
  130943. _vq_quantlist__8u0__p2_0,
  130944. NULL,
  130945. &_vq_auxt__8u0__p2_0,
  130946. NULL,
  130947. 0
  130948. };
  130949. static long _vq_quantlist__8u0__p3_0[] = {
  130950. 2,
  130951. 1,
  130952. 3,
  130953. 0,
  130954. 4,
  130955. };
  130956. static long _vq_lengthlist__8u0__p3_0[] = {
  130957. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130958. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130959. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130960. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130961. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130962. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130963. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130964. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130965. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130966. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130967. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130968. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130969. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130970. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130971. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130972. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130973. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130974. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130975. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130976. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130977. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130978. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130979. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130980. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130981. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130982. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130983. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130984. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130985. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130986. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130987. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130988. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130989. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130990. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130991. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130992. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130993. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130994. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130995. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130996. 16,
  130997. };
  130998. static float _vq_quantthresh__8u0__p3_0[] = {
  130999. -1.5, -0.5, 0.5, 1.5,
  131000. };
  131001. static long _vq_quantmap__8u0__p3_0[] = {
  131002. 3, 1, 0, 2, 4,
  131003. };
  131004. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  131005. _vq_quantthresh__8u0__p3_0,
  131006. _vq_quantmap__8u0__p3_0,
  131007. 5,
  131008. 5
  131009. };
  131010. static static_codebook _8u0__p3_0 = {
  131011. 4, 625,
  131012. _vq_lengthlist__8u0__p3_0,
  131013. 1, -533725184, 1611661312, 3, 0,
  131014. _vq_quantlist__8u0__p3_0,
  131015. NULL,
  131016. &_vq_auxt__8u0__p3_0,
  131017. NULL,
  131018. 0
  131019. };
  131020. static long _vq_quantlist__8u0__p4_0[] = {
  131021. 2,
  131022. 1,
  131023. 3,
  131024. 0,
  131025. 4,
  131026. };
  131027. static long _vq_lengthlist__8u0__p4_0[] = {
  131028. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  131029. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  131030. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  131031. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  131032. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  131033. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  131034. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  131035. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  131036. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  131037. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  131038. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  131039. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  131040. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  131041. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  131042. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  131043. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  131044. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  131045. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  131046. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  131047. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  131048. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  131049. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  131050. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  131051. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  131052. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  131053. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  131054. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  131055. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  131056. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  131057. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  131058. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  131059. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  131060. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  131061. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  131062. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  131063. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  131064. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  131065. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  131066. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  131067. 12,
  131068. };
  131069. static float _vq_quantthresh__8u0__p4_0[] = {
  131070. -1.5, -0.5, 0.5, 1.5,
  131071. };
  131072. static long _vq_quantmap__8u0__p4_0[] = {
  131073. 3, 1, 0, 2, 4,
  131074. };
  131075. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  131076. _vq_quantthresh__8u0__p4_0,
  131077. _vq_quantmap__8u0__p4_0,
  131078. 5,
  131079. 5
  131080. };
  131081. static static_codebook _8u0__p4_0 = {
  131082. 4, 625,
  131083. _vq_lengthlist__8u0__p4_0,
  131084. 1, -533725184, 1611661312, 3, 0,
  131085. _vq_quantlist__8u0__p4_0,
  131086. NULL,
  131087. &_vq_auxt__8u0__p4_0,
  131088. NULL,
  131089. 0
  131090. };
  131091. static long _vq_quantlist__8u0__p5_0[] = {
  131092. 4,
  131093. 3,
  131094. 5,
  131095. 2,
  131096. 6,
  131097. 1,
  131098. 7,
  131099. 0,
  131100. 8,
  131101. };
  131102. static long _vq_lengthlist__8u0__p5_0[] = {
  131103. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  131104. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  131105. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  131106. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131107. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  131108. 12,
  131109. };
  131110. static float _vq_quantthresh__8u0__p5_0[] = {
  131111. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131112. };
  131113. static long _vq_quantmap__8u0__p5_0[] = {
  131114. 7, 5, 3, 1, 0, 2, 4, 6,
  131115. 8,
  131116. };
  131117. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  131118. _vq_quantthresh__8u0__p5_0,
  131119. _vq_quantmap__8u0__p5_0,
  131120. 9,
  131121. 9
  131122. };
  131123. static static_codebook _8u0__p5_0 = {
  131124. 2, 81,
  131125. _vq_lengthlist__8u0__p5_0,
  131126. 1, -531628032, 1611661312, 4, 0,
  131127. _vq_quantlist__8u0__p5_0,
  131128. NULL,
  131129. &_vq_auxt__8u0__p5_0,
  131130. NULL,
  131131. 0
  131132. };
  131133. static long _vq_quantlist__8u0__p6_0[] = {
  131134. 6,
  131135. 5,
  131136. 7,
  131137. 4,
  131138. 8,
  131139. 3,
  131140. 9,
  131141. 2,
  131142. 10,
  131143. 1,
  131144. 11,
  131145. 0,
  131146. 12,
  131147. };
  131148. static long _vq_lengthlist__8u0__p6_0[] = {
  131149. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  131150. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  131151. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  131152. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  131153. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  131154. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  131155. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  131156. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  131157. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  131158. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  131159. 16, 0,15, 0,17, 0, 0, 0, 0,
  131160. };
  131161. static float _vq_quantthresh__8u0__p6_0[] = {
  131162. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131163. 12.5, 17.5, 22.5, 27.5,
  131164. };
  131165. static long _vq_quantmap__8u0__p6_0[] = {
  131166. 11, 9, 7, 5, 3, 1, 0, 2,
  131167. 4, 6, 8, 10, 12,
  131168. };
  131169. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  131170. _vq_quantthresh__8u0__p6_0,
  131171. _vq_quantmap__8u0__p6_0,
  131172. 13,
  131173. 13
  131174. };
  131175. static static_codebook _8u0__p6_0 = {
  131176. 2, 169,
  131177. _vq_lengthlist__8u0__p6_0,
  131178. 1, -526516224, 1616117760, 4, 0,
  131179. _vq_quantlist__8u0__p6_0,
  131180. NULL,
  131181. &_vq_auxt__8u0__p6_0,
  131182. NULL,
  131183. 0
  131184. };
  131185. static long _vq_quantlist__8u0__p6_1[] = {
  131186. 2,
  131187. 1,
  131188. 3,
  131189. 0,
  131190. 4,
  131191. };
  131192. static long _vq_lengthlist__8u0__p6_1[] = {
  131193. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  131194. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  131195. };
  131196. static float _vq_quantthresh__8u0__p6_1[] = {
  131197. -1.5, -0.5, 0.5, 1.5,
  131198. };
  131199. static long _vq_quantmap__8u0__p6_1[] = {
  131200. 3, 1, 0, 2, 4,
  131201. };
  131202. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  131203. _vq_quantthresh__8u0__p6_1,
  131204. _vq_quantmap__8u0__p6_1,
  131205. 5,
  131206. 5
  131207. };
  131208. static static_codebook _8u0__p6_1 = {
  131209. 2, 25,
  131210. _vq_lengthlist__8u0__p6_1,
  131211. 1, -533725184, 1611661312, 3, 0,
  131212. _vq_quantlist__8u0__p6_1,
  131213. NULL,
  131214. &_vq_auxt__8u0__p6_1,
  131215. NULL,
  131216. 0
  131217. };
  131218. static long _vq_quantlist__8u0__p7_0[] = {
  131219. 1,
  131220. 0,
  131221. 2,
  131222. };
  131223. static long _vq_lengthlist__8u0__p7_0[] = {
  131224. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131225. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131226. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131227. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131228. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131229. 7,
  131230. };
  131231. static float _vq_quantthresh__8u0__p7_0[] = {
  131232. -157.5, 157.5,
  131233. };
  131234. static long _vq_quantmap__8u0__p7_0[] = {
  131235. 1, 0, 2,
  131236. };
  131237. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  131238. _vq_quantthresh__8u0__p7_0,
  131239. _vq_quantmap__8u0__p7_0,
  131240. 3,
  131241. 3
  131242. };
  131243. static static_codebook _8u0__p7_0 = {
  131244. 4, 81,
  131245. _vq_lengthlist__8u0__p7_0,
  131246. 1, -518803456, 1628680192, 2, 0,
  131247. _vq_quantlist__8u0__p7_0,
  131248. NULL,
  131249. &_vq_auxt__8u0__p7_0,
  131250. NULL,
  131251. 0
  131252. };
  131253. static long _vq_quantlist__8u0__p7_1[] = {
  131254. 7,
  131255. 6,
  131256. 8,
  131257. 5,
  131258. 9,
  131259. 4,
  131260. 10,
  131261. 3,
  131262. 11,
  131263. 2,
  131264. 12,
  131265. 1,
  131266. 13,
  131267. 0,
  131268. 14,
  131269. };
  131270. static long _vq_lengthlist__8u0__p7_1[] = {
  131271. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  131272. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  131273. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  131274. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  131275. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  131276. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  131277. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131278. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131279. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131280. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131281. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131282. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131283. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  131284. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131285. 10,
  131286. };
  131287. static float _vq_quantthresh__8u0__p7_1[] = {
  131288. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  131289. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  131290. };
  131291. static long _vq_quantmap__8u0__p7_1[] = {
  131292. 13, 11, 9, 7, 5, 3, 1, 0,
  131293. 2, 4, 6, 8, 10, 12, 14,
  131294. };
  131295. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  131296. _vq_quantthresh__8u0__p7_1,
  131297. _vq_quantmap__8u0__p7_1,
  131298. 15,
  131299. 15
  131300. };
  131301. static static_codebook _8u0__p7_1 = {
  131302. 2, 225,
  131303. _vq_lengthlist__8u0__p7_1,
  131304. 1, -520986624, 1620377600, 4, 0,
  131305. _vq_quantlist__8u0__p7_1,
  131306. NULL,
  131307. &_vq_auxt__8u0__p7_1,
  131308. NULL,
  131309. 0
  131310. };
  131311. static long _vq_quantlist__8u0__p7_2[] = {
  131312. 10,
  131313. 9,
  131314. 11,
  131315. 8,
  131316. 12,
  131317. 7,
  131318. 13,
  131319. 6,
  131320. 14,
  131321. 5,
  131322. 15,
  131323. 4,
  131324. 16,
  131325. 3,
  131326. 17,
  131327. 2,
  131328. 18,
  131329. 1,
  131330. 19,
  131331. 0,
  131332. 20,
  131333. };
  131334. static long _vq_lengthlist__8u0__p7_2[] = {
  131335. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  131336. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  131337. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  131338. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  131339. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  131340. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  131341. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  131342. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  131343. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  131344. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  131345. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  131346. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  131347. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  131348. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  131349. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  131350. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  131351. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  131352. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  131353. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  131354. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  131355. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  131356. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  131357. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  131358. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  131359. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  131360. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  131361. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  131362. 11,12,11,11,11,10,10,11,11,
  131363. };
  131364. static float _vq_quantthresh__8u0__p7_2[] = {
  131365. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  131366. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  131367. 6.5, 7.5, 8.5, 9.5,
  131368. };
  131369. static long _vq_quantmap__8u0__p7_2[] = {
  131370. 19, 17, 15, 13, 11, 9, 7, 5,
  131371. 3, 1, 0, 2, 4, 6, 8, 10,
  131372. 12, 14, 16, 18, 20,
  131373. };
  131374. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  131375. _vq_quantthresh__8u0__p7_2,
  131376. _vq_quantmap__8u0__p7_2,
  131377. 21,
  131378. 21
  131379. };
  131380. static static_codebook _8u0__p7_2 = {
  131381. 2, 441,
  131382. _vq_lengthlist__8u0__p7_2,
  131383. 1, -529268736, 1611661312, 5, 0,
  131384. _vq_quantlist__8u0__p7_2,
  131385. NULL,
  131386. &_vq_auxt__8u0__p7_2,
  131387. NULL,
  131388. 0
  131389. };
  131390. static long _huff_lengthlist__8u0__single[] = {
  131391. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  131392. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  131393. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  131394. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  131395. };
  131396. static static_codebook _huff_book__8u0__single = {
  131397. 2, 64,
  131398. _huff_lengthlist__8u0__single,
  131399. 0, 0, 0, 0, 0,
  131400. NULL,
  131401. NULL,
  131402. NULL,
  131403. NULL,
  131404. 0
  131405. };
  131406. static long _vq_quantlist__8u1__p1_0[] = {
  131407. 1,
  131408. 0,
  131409. 2,
  131410. };
  131411. static long _vq_lengthlist__8u1__p1_0[] = {
  131412. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  131413. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  131414. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  131415. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  131416. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  131417. 10,
  131418. };
  131419. static float _vq_quantthresh__8u1__p1_0[] = {
  131420. -0.5, 0.5,
  131421. };
  131422. static long _vq_quantmap__8u1__p1_0[] = {
  131423. 1, 0, 2,
  131424. };
  131425. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  131426. _vq_quantthresh__8u1__p1_0,
  131427. _vq_quantmap__8u1__p1_0,
  131428. 3,
  131429. 3
  131430. };
  131431. static static_codebook _8u1__p1_0 = {
  131432. 4, 81,
  131433. _vq_lengthlist__8u1__p1_0,
  131434. 1, -535822336, 1611661312, 2, 0,
  131435. _vq_quantlist__8u1__p1_0,
  131436. NULL,
  131437. &_vq_auxt__8u1__p1_0,
  131438. NULL,
  131439. 0
  131440. };
  131441. static long _vq_quantlist__8u1__p2_0[] = {
  131442. 1,
  131443. 0,
  131444. 2,
  131445. };
  131446. static long _vq_lengthlist__8u1__p2_0[] = {
  131447. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  131448. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  131449. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  131450. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  131451. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  131452. 7,
  131453. };
  131454. static float _vq_quantthresh__8u1__p2_0[] = {
  131455. -0.5, 0.5,
  131456. };
  131457. static long _vq_quantmap__8u1__p2_0[] = {
  131458. 1, 0, 2,
  131459. };
  131460. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  131461. _vq_quantthresh__8u1__p2_0,
  131462. _vq_quantmap__8u1__p2_0,
  131463. 3,
  131464. 3
  131465. };
  131466. static static_codebook _8u1__p2_0 = {
  131467. 4, 81,
  131468. _vq_lengthlist__8u1__p2_0,
  131469. 1, -535822336, 1611661312, 2, 0,
  131470. _vq_quantlist__8u1__p2_0,
  131471. NULL,
  131472. &_vq_auxt__8u1__p2_0,
  131473. NULL,
  131474. 0
  131475. };
  131476. static long _vq_quantlist__8u1__p3_0[] = {
  131477. 2,
  131478. 1,
  131479. 3,
  131480. 0,
  131481. 4,
  131482. };
  131483. static long _vq_lengthlist__8u1__p3_0[] = {
  131484. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  131485. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  131486. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  131487. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  131488. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  131489. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  131490. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  131491. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  131492. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  131493. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  131494. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  131495. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  131496. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  131497. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  131498. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  131499. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  131500. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  131501. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  131502. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  131503. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  131504. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  131505. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  131506. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  131507. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  131508. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  131509. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  131510. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  131511. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  131512. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  131513. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  131514. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  131515. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  131516. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  131517. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  131518. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  131519. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  131520. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  131521. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  131522. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  131523. 16,
  131524. };
  131525. static float _vq_quantthresh__8u1__p3_0[] = {
  131526. -1.5, -0.5, 0.5, 1.5,
  131527. };
  131528. static long _vq_quantmap__8u1__p3_0[] = {
  131529. 3, 1, 0, 2, 4,
  131530. };
  131531. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131532. _vq_quantthresh__8u1__p3_0,
  131533. _vq_quantmap__8u1__p3_0,
  131534. 5,
  131535. 5
  131536. };
  131537. static static_codebook _8u1__p3_0 = {
  131538. 4, 625,
  131539. _vq_lengthlist__8u1__p3_0,
  131540. 1, -533725184, 1611661312, 3, 0,
  131541. _vq_quantlist__8u1__p3_0,
  131542. NULL,
  131543. &_vq_auxt__8u1__p3_0,
  131544. NULL,
  131545. 0
  131546. };
  131547. static long _vq_quantlist__8u1__p4_0[] = {
  131548. 2,
  131549. 1,
  131550. 3,
  131551. 0,
  131552. 4,
  131553. };
  131554. static long _vq_lengthlist__8u1__p4_0[] = {
  131555. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131556. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131557. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131558. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131559. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131560. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131561. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131562. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131563. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131564. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131565. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131566. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131567. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131568. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131569. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131570. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131571. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131572. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131573. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131574. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131575. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131576. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131577. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131578. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131579. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131580. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131581. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131582. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131583. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131584. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131585. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131586. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131587. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131588. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131589. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131590. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131591. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131592. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131593. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131594. 10,
  131595. };
  131596. static float _vq_quantthresh__8u1__p4_0[] = {
  131597. -1.5, -0.5, 0.5, 1.5,
  131598. };
  131599. static long _vq_quantmap__8u1__p4_0[] = {
  131600. 3, 1, 0, 2, 4,
  131601. };
  131602. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131603. _vq_quantthresh__8u1__p4_0,
  131604. _vq_quantmap__8u1__p4_0,
  131605. 5,
  131606. 5
  131607. };
  131608. static static_codebook _8u1__p4_0 = {
  131609. 4, 625,
  131610. _vq_lengthlist__8u1__p4_0,
  131611. 1, -533725184, 1611661312, 3, 0,
  131612. _vq_quantlist__8u1__p4_0,
  131613. NULL,
  131614. &_vq_auxt__8u1__p4_0,
  131615. NULL,
  131616. 0
  131617. };
  131618. static long _vq_quantlist__8u1__p5_0[] = {
  131619. 4,
  131620. 3,
  131621. 5,
  131622. 2,
  131623. 6,
  131624. 1,
  131625. 7,
  131626. 0,
  131627. 8,
  131628. };
  131629. static long _vq_lengthlist__8u1__p5_0[] = {
  131630. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131631. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131632. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131633. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131634. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131635. 13,
  131636. };
  131637. static float _vq_quantthresh__8u1__p5_0[] = {
  131638. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131639. };
  131640. static long _vq_quantmap__8u1__p5_0[] = {
  131641. 7, 5, 3, 1, 0, 2, 4, 6,
  131642. 8,
  131643. };
  131644. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131645. _vq_quantthresh__8u1__p5_0,
  131646. _vq_quantmap__8u1__p5_0,
  131647. 9,
  131648. 9
  131649. };
  131650. static static_codebook _8u1__p5_0 = {
  131651. 2, 81,
  131652. _vq_lengthlist__8u1__p5_0,
  131653. 1, -531628032, 1611661312, 4, 0,
  131654. _vq_quantlist__8u1__p5_0,
  131655. NULL,
  131656. &_vq_auxt__8u1__p5_0,
  131657. NULL,
  131658. 0
  131659. };
  131660. static long _vq_quantlist__8u1__p6_0[] = {
  131661. 4,
  131662. 3,
  131663. 5,
  131664. 2,
  131665. 6,
  131666. 1,
  131667. 7,
  131668. 0,
  131669. 8,
  131670. };
  131671. static long _vq_lengthlist__8u1__p6_0[] = {
  131672. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131673. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131674. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131675. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131676. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131677. 10,
  131678. };
  131679. static float _vq_quantthresh__8u1__p6_0[] = {
  131680. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131681. };
  131682. static long _vq_quantmap__8u1__p6_0[] = {
  131683. 7, 5, 3, 1, 0, 2, 4, 6,
  131684. 8,
  131685. };
  131686. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131687. _vq_quantthresh__8u1__p6_0,
  131688. _vq_quantmap__8u1__p6_0,
  131689. 9,
  131690. 9
  131691. };
  131692. static static_codebook _8u1__p6_0 = {
  131693. 2, 81,
  131694. _vq_lengthlist__8u1__p6_0,
  131695. 1, -531628032, 1611661312, 4, 0,
  131696. _vq_quantlist__8u1__p6_0,
  131697. NULL,
  131698. &_vq_auxt__8u1__p6_0,
  131699. NULL,
  131700. 0
  131701. };
  131702. static long _vq_quantlist__8u1__p7_0[] = {
  131703. 1,
  131704. 0,
  131705. 2,
  131706. };
  131707. static long _vq_lengthlist__8u1__p7_0[] = {
  131708. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131709. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131710. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131711. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131712. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131713. 11,
  131714. };
  131715. static float _vq_quantthresh__8u1__p7_0[] = {
  131716. -5.5, 5.5,
  131717. };
  131718. static long _vq_quantmap__8u1__p7_0[] = {
  131719. 1, 0, 2,
  131720. };
  131721. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131722. _vq_quantthresh__8u1__p7_0,
  131723. _vq_quantmap__8u1__p7_0,
  131724. 3,
  131725. 3
  131726. };
  131727. static static_codebook _8u1__p7_0 = {
  131728. 4, 81,
  131729. _vq_lengthlist__8u1__p7_0,
  131730. 1, -529137664, 1618345984, 2, 0,
  131731. _vq_quantlist__8u1__p7_0,
  131732. NULL,
  131733. &_vq_auxt__8u1__p7_0,
  131734. NULL,
  131735. 0
  131736. };
  131737. static long _vq_quantlist__8u1__p7_1[] = {
  131738. 5,
  131739. 4,
  131740. 6,
  131741. 3,
  131742. 7,
  131743. 2,
  131744. 8,
  131745. 1,
  131746. 9,
  131747. 0,
  131748. 10,
  131749. };
  131750. static long _vq_lengthlist__8u1__p7_1[] = {
  131751. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131752. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131753. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131754. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131755. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131756. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131757. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131758. 9, 9, 9, 9, 9,10,10,10,10,
  131759. };
  131760. static float _vq_quantthresh__8u1__p7_1[] = {
  131761. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131762. 3.5, 4.5,
  131763. };
  131764. static long _vq_quantmap__8u1__p7_1[] = {
  131765. 9, 7, 5, 3, 1, 0, 2, 4,
  131766. 6, 8, 10,
  131767. };
  131768. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131769. _vq_quantthresh__8u1__p7_1,
  131770. _vq_quantmap__8u1__p7_1,
  131771. 11,
  131772. 11
  131773. };
  131774. static static_codebook _8u1__p7_1 = {
  131775. 2, 121,
  131776. _vq_lengthlist__8u1__p7_1,
  131777. 1, -531365888, 1611661312, 4, 0,
  131778. _vq_quantlist__8u1__p7_1,
  131779. NULL,
  131780. &_vq_auxt__8u1__p7_1,
  131781. NULL,
  131782. 0
  131783. };
  131784. static long _vq_quantlist__8u1__p8_0[] = {
  131785. 5,
  131786. 4,
  131787. 6,
  131788. 3,
  131789. 7,
  131790. 2,
  131791. 8,
  131792. 1,
  131793. 9,
  131794. 0,
  131795. 10,
  131796. };
  131797. static long _vq_lengthlist__8u1__p8_0[] = {
  131798. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131799. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131800. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131801. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131802. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131803. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131804. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131805. 12,13,13,14,14,15,15,15,15,
  131806. };
  131807. static float _vq_quantthresh__8u1__p8_0[] = {
  131808. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131809. 38.5, 49.5,
  131810. };
  131811. static long _vq_quantmap__8u1__p8_0[] = {
  131812. 9, 7, 5, 3, 1, 0, 2, 4,
  131813. 6, 8, 10,
  131814. };
  131815. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131816. _vq_quantthresh__8u1__p8_0,
  131817. _vq_quantmap__8u1__p8_0,
  131818. 11,
  131819. 11
  131820. };
  131821. static static_codebook _8u1__p8_0 = {
  131822. 2, 121,
  131823. _vq_lengthlist__8u1__p8_0,
  131824. 1, -524582912, 1618345984, 4, 0,
  131825. _vq_quantlist__8u1__p8_0,
  131826. NULL,
  131827. &_vq_auxt__8u1__p8_0,
  131828. NULL,
  131829. 0
  131830. };
  131831. static long _vq_quantlist__8u1__p8_1[] = {
  131832. 5,
  131833. 4,
  131834. 6,
  131835. 3,
  131836. 7,
  131837. 2,
  131838. 8,
  131839. 1,
  131840. 9,
  131841. 0,
  131842. 10,
  131843. };
  131844. static long _vq_lengthlist__8u1__p8_1[] = {
  131845. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131846. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131847. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131848. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131849. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131850. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131851. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131852. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131853. };
  131854. static float _vq_quantthresh__8u1__p8_1[] = {
  131855. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131856. 3.5, 4.5,
  131857. };
  131858. static long _vq_quantmap__8u1__p8_1[] = {
  131859. 9, 7, 5, 3, 1, 0, 2, 4,
  131860. 6, 8, 10,
  131861. };
  131862. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131863. _vq_quantthresh__8u1__p8_1,
  131864. _vq_quantmap__8u1__p8_1,
  131865. 11,
  131866. 11
  131867. };
  131868. static static_codebook _8u1__p8_1 = {
  131869. 2, 121,
  131870. _vq_lengthlist__8u1__p8_1,
  131871. 1, -531365888, 1611661312, 4, 0,
  131872. _vq_quantlist__8u1__p8_1,
  131873. NULL,
  131874. &_vq_auxt__8u1__p8_1,
  131875. NULL,
  131876. 0
  131877. };
  131878. static long _vq_quantlist__8u1__p9_0[] = {
  131879. 7,
  131880. 6,
  131881. 8,
  131882. 5,
  131883. 9,
  131884. 4,
  131885. 10,
  131886. 3,
  131887. 11,
  131888. 2,
  131889. 12,
  131890. 1,
  131891. 13,
  131892. 0,
  131893. 14,
  131894. };
  131895. static long _vq_lengthlist__8u1__p9_0[] = {
  131896. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131897. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131898. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131899. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131900. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131901. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131902. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131903. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131904. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131905. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131906. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131907. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131908. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131909. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131910. 10,
  131911. };
  131912. static float _vq_quantthresh__8u1__p9_0[] = {
  131913. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131914. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131915. };
  131916. static long _vq_quantmap__8u1__p9_0[] = {
  131917. 13, 11, 9, 7, 5, 3, 1, 0,
  131918. 2, 4, 6, 8, 10, 12, 14,
  131919. };
  131920. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131921. _vq_quantthresh__8u1__p9_0,
  131922. _vq_quantmap__8u1__p9_0,
  131923. 15,
  131924. 15
  131925. };
  131926. static static_codebook _8u1__p9_0 = {
  131927. 2, 225,
  131928. _vq_lengthlist__8u1__p9_0,
  131929. 1, -514071552, 1627381760, 4, 0,
  131930. _vq_quantlist__8u1__p9_0,
  131931. NULL,
  131932. &_vq_auxt__8u1__p9_0,
  131933. NULL,
  131934. 0
  131935. };
  131936. static long _vq_quantlist__8u1__p9_1[] = {
  131937. 7,
  131938. 6,
  131939. 8,
  131940. 5,
  131941. 9,
  131942. 4,
  131943. 10,
  131944. 3,
  131945. 11,
  131946. 2,
  131947. 12,
  131948. 1,
  131949. 13,
  131950. 0,
  131951. 14,
  131952. };
  131953. static long _vq_lengthlist__8u1__p9_1[] = {
  131954. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131955. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131956. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131957. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131958. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131959. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131960. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131961. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131962. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131963. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131964. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131965. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131966. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131967. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131968. 13,
  131969. };
  131970. static float _vq_quantthresh__8u1__p9_1[] = {
  131971. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131972. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131973. };
  131974. static long _vq_quantmap__8u1__p9_1[] = {
  131975. 13, 11, 9, 7, 5, 3, 1, 0,
  131976. 2, 4, 6, 8, 10, 12, 14,
  131977. };
  131978. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131979. _vq_quantthresh__8u1__p9_1,
  131980. _vq_quantmap__8u1__p9_1,
  131981. 15,
  131982. 15
  131983. };
  131984. static static_codebook _8u1__p9_1 = {
  131985. 2, 225,
  131986. _vq_lengthlist__8u1__p9_1,
  131987. 1, -522338304, 1620115456, 4, 0,
  131988. _vq_quantlist__8u1__p9_1,
  131989. NULL,
  131990. &_vq_auxt__8u1__p9_1,
  131991. NULL,
  131992. 0
  131993. };
  131994. static long _vq_quantlist__8u1__p9_2[] = {
  131995. 8,
  131996. 7,
  131997. 9,
  131998. 6,
  131999. 10,
  132000. 5,
  132001. 11,
  132002. 4,
  132003. 12,
  132004. 3,
  132005. 13,
  132006. 2,
  132007. 14,
  132008. 1,
  132009. 15,
  132010. 0,
  132011. 16,
  132012. };
  132013. static long _vq_lengthlist__8u1__p9_2[] = {
  132014. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  132015. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  132016. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  132017. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  132018. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  132019. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  132020. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  132021. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  132022. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  132023. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  132024. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  132025. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  132026. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  132027. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  132028. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  132029. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  132030. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132031. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132032. 10,
  132033. };
  132034. static float _vq_quantthresh__8u1__p9_2[] = {
  132035. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  132036. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  132037. };
  132038. static long _vq_quantmap__8u1__p9_2[] = {
  132039. 15, 13, 11, 9, 7, 5, 3, 1,
  132040. 0, 2, 4, 6, 8, 10, 12, 14,
  132041. 16,
  132042. };
  132043. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  132044. _vq_quantthresh__8u1__p9_2,
  132045. _vq_quantmap__8u1__p9_2,
  132046. 17,
  132047. 17
  132048. };
  132049. static static_codebook _8u1__p9_2 = {
  132050. 2, 289,
  132051. _vq_lengthlist__8u1__p9_2,
  132052. 1, -529530880, 1611661312, 5, 0,
  132053. _vq_quantlist__8u1__p9_2,
  132054. NULL,
  132055. &_vq_auxt__8u1__p9_2,
  132056. NULL,
  132057. 0
  132058. };
  132059. static long _huff_lengthlist__8u1__single[] = {
  132060. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  132061. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  132062. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  132063. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  132064. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  132065. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  132066. 13, 8, 8,15,
  132067. };
  132068. static static_codebook _huff_book__8u1__single = {
  132069. 2, 100,
  132070. _huff_lengthlist__8u1__single,
  132071. 0, 0, 0, 0, 0,
  132072. NULL,
  132073. NULL,
  132074. NULL,
  132075. NULL,
  132076. 0
  132077. };
  132078. static long _huff_lengthlist__44u0__long[] = {
  132079. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132080. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132081. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132082. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132083. };
  132084. static static_codebook _huff_book__44u0__long = {
  132085. 2, 64,
  132086. _huff_lengthlist__44u0__long,
  132087. 0, 0, 0, 0, 0,
  132088. NULL,
  132089. NULL,
  132090. NULL,
  132091. NULL,
  132092. 0
  132093. };
  132094. static long _vq_quantlist__44u0__p1_0[] = {
  132095. 1,
  132096. 0,
  132097. 2,
  132098. };
  132099. static long _vq_lengthlist__44u0__p1_0[] = {
  132100. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132101. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132102. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132103. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132104. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132105. 13,
  132106. };
  132107. static float _vq_quantthresh__44u0__p1_0[] = {
  132108. -0.5, 0.5,
  132109. };
  132110. static long _vq_quantmap__44u0__p1_0[] = {
  132111. 1, 0, 2,
  132112. };
  132113. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  132114. _vq_quantthresh__44u0__p1_0,
  132115. _vq_quantmap__44u0__p1_0,
  132116. 3,
  132117. 3
  132118. };
  132119. static static_codebook _44u0__p1_0 = {
  132120. 4, 81,
  132121. _vq_lengthlist__44u0__p1_0,
  132122. 1, -535822336, 1611661312, 2, 0,
  132123. _vq_quantlist__44u0__p1_0,
  132124. NULL,
  132125. &_vq_auxt__44u0__p1_0,
  132126. NULL,
  132127. 0
  132128. };
  132129. static long _vq_quantlist__44u0__p2_0[] = {
  132130. 1,
  132131. 0,
  132132. 2,
  132133. };
  132134. static long _vq_lengthlist__44u0__p2_0[] = {
  132135. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132136. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132137. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132138. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132139. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132140. 9,
  132141. };
  132142. static float _vq_quantthresh__44u0__p2_0[] = {
  132143. -0.5, 0.5,
  132144. };
  132145. static long _vq_quantmap__44u0__p2_0[] = {
  132146. 1, 0, 2,
  132147. };
  132148. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  132149. _vq_quantthresh__44u0__p2_0,
  132150. _vq_quantmap__44u0__p2_0,
  132151. 3,
  132152. 3
  132153. };
  132154. static static_codebook _44u0__p2_0 = {
  132155. 4, 81,
  132156. _vq_lengthlist__44u0__p2_0,
  132157. 1, -535822336, 1611661312, 2, 0,
  132158. _vq_quantlist__44u0__p2_0,
  132159. NULL,
  132160. &_vq_auxt__44u0__p2_0,
  132161. NULL,
  132162. 0
  132163. };
  132164. static long _vq_quantlist__44u0__p3_0[] = {
  132165. 2,
  132166. 1,
  132167. 3,
  132168. 0,
  132169. 4,
  132170. };
  132171. static long _vq_lengthlist__44u0__p3_0[] = {
  132172. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132173. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132174. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132175. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132176. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132177. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132178. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132179. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132180. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132181. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132182. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132183. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132184. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132185. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132186. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132187. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132188. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132189. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132190. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132191. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132192. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132193. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132194. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132195. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132196. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132197. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132198. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132199. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132200. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132201. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132202. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132203. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132204. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132205. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132206. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132207. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132208. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132209. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132210. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132211. 19,
  132212. };
  132213. static float _vq_quantthresh__44u0__p3_0[] = {
  132214. -1.5, -0.5, 0.5, 1.5,
  132215. };
  132216. static long _vq_quantmap__44u0__p3_0[] = {
  132217. 3, 1, 0, 2, 4,
  132218. };
  132219. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  132220. _vq_quantthresh__44u0__p3_0,
  132221. _vq_quantmap__44u0__p3_0,
  132222. 5,
  132223. 5
  132224. };
  132225. static static_codebook _44u0__p3_0 = {
  132226. 4, 625,
  132227. _vq_lengthlist__44u0__p3_0,
  132228. 1, -533725184, 1611661312, 3, 0,
  132229. _vq_quantlist__44u0__p3_0,
  132230. NULL,
  132231. &_vq_auxt__44u0__p3_0,
  132232. NULL,
  132233. 0
  132234. };
  132235. static long _vq_quantlist__44u0__p4_0[] = {
  132236. 2,
  132237. 1,
  132238. 3,
  132239. 0,
  132240. 4,
  132241. };
  132242. static long _vq_lengthlist__44u0__p4_0[] = {
  132243. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132244. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132245. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132246. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132247. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132248. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132249. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132250. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132251. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132252. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132253. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132254. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132255. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132256. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132257. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132258. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132259. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132260. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132261. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132262. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132263. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132264. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132265. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132266. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132267. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132268. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132269. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132270. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132271. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132272. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132273. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132274. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132275. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132276. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132277. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132278. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132279. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132280. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132281. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132282. 12,
  132283. };
  132284. static float _vq_quantthresh__44u0__p4_0[] = {
  132285. -1.5, -0.5, 0.5, 1.5,
  132286. };
  132287. static long _vq_quantmap__44u0__p4_0[] = {
  132288. 3, 1, 0, 2, 4,
  132289. };
  132290. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  132291. _vq_quantthresh__44u0__p4_0,
  132292. _vq_quantmap__44u0__p4_0,
  132293. 5,
  132294. 5
  132295. };
  132296. static static_codebook _44u0__p4_0 = {
  132297. 4, 625,
  132298. _vq_lengthlist__44u0__p4_0,
  132299. 1, -533725184, 1611661312, 3, 0,
  132300. _vq_quantlist__44u0__p4_0,
  132301. NULL,
  132302. &_vq_auxt__44u0__p4_0,
  132303. NULL,
  132304. 0
  132305. };
  132306. static long _vq_quantlist__44u0__p5_0[] = {
  132307. 4,
  132308. 3,
  132309. 5,
  132310. 2,
  132311. 6,
  132312. 1,
  132313. 7,
  132314. 0,
  132315. 8,
  132316. };
  132317. static long _vq_lengthlist__44u0__p5_0[] = {
  132318. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132319. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132320. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132321. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132322. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132323. 12,
  132324. };
  132325. static float _vq_quantthresh__44u0__p5_0[] = {
  132326. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132327. };
  132328. static long _vq_quantmap__44u0__p5_0[] = {
  132329. 7, 5, 3, 1, 0, 2, 4, 6,
  132330. 8,
  132331. };
  132332. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  132333. _vq_quantthresh__44u0__p5_0,
  132334. _vq_quantmap__44u0__p5_0,
  132335. 9,
  132336. 9
  132337. };
  132338. static static_codebook _44u0__p5_0 = {
  132339. 2, 81,
  132340. _vq_lengthlist__44u0__p5_0,
  132341. 1, -531628032, 1611661312, 4, 0,
  132342. _vq_quantlist__44u0__p5_0,
  132343. NULL,
  132344. &_vq_auxt__44u0__p5_0,
  132345. NULL,
  132346. 0
  132347. };
  132348. static long _vq_quantlist__44u0__p6_0[] = {
  132349. 6,
  132350. 5,
  132351. 7,
  132352. 4,
  132353. 8,
  132354. 3,
  132355. 9,
  132356. 2,
  132357. 10,
  132358. 1,
  132359. 11,
  132360. 0,
  132361. 12,
  132362. };
  132363. static long _vq_lengthlist__44u0__p6_0[] = {
  132364. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132365. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132366. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132367. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132368. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132369. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132370. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132371. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132372. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132373. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132374. 15,17,16,17,18,17,17,18, 0,
  132375. };
  132376. static float _vq_quantthresh__44u0__p6_0[] = {
  132377. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132378. 12.5, 17.5, 22.5, 27.5,
  132379. };
  132380. static long _vq_quantmap__44u0__p6_0[] = {
  132381. 11, 9, 7, 5, 3, 1, 0, 2,
  132382. 4, 6, 8, 10, 12,
  132383. };
  132384. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  132385. _vq_quantthresh__44u0__p6_0,
  132386. _vq_quantmap__44u0__p6_0,
  132387. 13,
  132388. 13
  132389. };
  132390. static static_codebook _44u0__p6_0 = {
  132391. 2, 169,
  132392. _vq_lengthlist__44u0__p6_0,
  132393. 1, -526516224, 1616117760, 4, 0,
  132394. _vq_quantlist__44u0__p6_0,
  132395. NULL,
  132396. &_vq_auxt__44u0__p6_0,
  132397. NULL,
  132398. 0
  132399. };
  132400. static long _vq_quantlist__44u0__p6_1[] = {
  132401. 2,
  132402. 1,
  132403. 3,
  132404. 0,
  132405. 4,
  132406. };
  132407. static long _vq_lengthlist__44u0__p6_1[] = {
  132408. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132409. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132410. };
  132411. static float _vq_quantthresh__44u0__p6_1[] = {
  132412. -1.5, -0.5, 0.5, 1.5,
  132413. };
  132414. static long _vq_quantmap__44u0__p6_1[] = {
  132415. 3, 1, 0, 2, 4,
  132416. };
  132417. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  132418. _vq_quantthresh__44u0__p6_1,
  132419. _vq_quantmap__44u0__p6_1,
  132420. 5,
  132421. 5
  132422. };
  132423. static static_codebook _44u0__p6_1 = {
  132424. 2, 25,
  132425. _vq_lengthlist__44u0__p6_1,
  132426. 1, -533725184, 1611661312, 3, 0,
  132427. _vq_quantlist__44u0__p6_1,
  132428. NULL,
  132429. &_vq_auxt__44u0__p6_1,
  132430. NULL,
  132431. 0
  132432. };
  132433. static long _vq_quantlist__44u0__p7_0[] = {
  132434. 2,
  132435. 1,
  132436. 3,
  132437. 0,
  132438. 4,
  132439. };
  132440. static long _vq_lengthlist__44u0__p7_0[] = {
  132441. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  132442. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132443. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132444. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132445. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132446. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132447. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132448. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  132449. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132450. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132451. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132452. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132453. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132454. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132455. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132456. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132457. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132458. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132459. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132460. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132461. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132462. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132463. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132464. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132465. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132466. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132467. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132468. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132469. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132470. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132471. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  132472. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132473. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132474. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132475. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132476. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132477. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132478. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132479. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132480. 10,
  132481. };
  132482. static float _vq_quantthresh__44u0__p7_0[] = {
  132483. -253.5, -84.5, 84.5, 253.5,
  132484. };
  132485. static long _vq_quantmap__44u0__p7_0[] = {
  132486. 3, 1, 0, 2, 4,
  132487. };
  132488. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  132489. _vq_quantthresh__44u0__p7_0,
  132490. _vq_quantmap__44u0__p7_0,
  132491. 5,
  132492. 5
  132493. };
  132494. static static_codebook _44u0__p7_0 = {
  132495. 4, 625,
  132496. _vq_lengthlist__44u0__p7_0,
  132497. 1, -518709248, 1626677248, 3, 0,
  132498. _vq_quantlist__44u0__p7_0,
  132499. NULL,
  132500. &_vq_auxt__44u0__p7_0,
  132501. NULL,
  132502. 0
  132503. };
  132504. static long _vq_quantlist__44u0__p7_1[] = {
  132505. 6,
  132506. 5,
  132507. 7,
  132508. 4,
  132509. 8,
  132510. 3,
  132511. 9,
  132512. 2,
  132513. 10,
  132514. 1,
  132515. 11,
  132516. 0,
  132517. 12,
  132518. };
  132519. static long _vq_lengthlist__44u0__p7_1[] = {
  132520. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132521. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132522. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132523. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132524. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132525. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132526. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132527. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132528. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132529. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132530. 15,15,15,15,15,15,15,15,15,
  132531. };
  132532. static float _vq_quantthresh__44u0__p7_1[] = {
  132533. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132534. 32.5, 45.5, 58.5, 71.5,
  132535. };
  132536. static long _vq_quantmap__44u0__p7_1[] = {
  132537. 11, 9, 7, 5, 3, 1, 0, 2,
  132538. 4, 6, 8, 10, 12,
  132539. };
  132540. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132541. _vq_quantthresh__44u0__p7_1,
  132542. _vq_quantmap__44u0__p7_1,
  132543. 13,
  132544. 13
  132545. };
  132546. static static_codebook _44u0__p7_1 = {
  132547. 2, 169,
  132548. _vq_lengthlist__44u0__p7_1,
  132549. 1, -523010048, 1618608128, 4, 0,
  132550. _vq_quantlist__44u0__p7_1,
  132551. NULL,
  132552. &_vq_auxt__44u0__p7_1,
  132553. NULL,
  132554. 0
  132555. };
  132556. static long _vq_quantlist__44u0__p7_2[] = {
  132557. 6,
  132558. 5,
  132559. 7,
  132560. 4,
  132561. 8,
  132562. 3,
  132563. 9,
  132564. 2,
  132565. 10,
  132566. 1,
  132567. 11,
  132568. 0,
  132569. 12,
  132570. };
  132571. static long _vq_lengthlist__44u0__p7_2[] = {
  132572. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132573. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132574. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132575. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132576. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132577. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132578. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132579. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132580. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132581. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132582. 9, 9, 9,10, 9, 9,10,10, 9,
  132583. };
  132584. static float _vq_quantthresh__44u0__p7_2[] = {
  132585. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132586. 2.5, 3.5, 4.5, 5.5,
  132587. };
  132588. static long _vq_quantmap__44u0__p7_2[] = {
  132589. 11, 9, 7, 5, 3, 1, 0, 2,
  132590. 4, 6, 8, 10, 12,
  132591. };
  132592. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132593. _vq_quantthresh__44u0__p7_2,
  132594. _vq_quantmap__44u0__p7_2,
  132595. 13,
  132596. 13
  132597. };
  132598. static static_codebook _44u0__p7_2 = {
  132599. 2, 169,
  132600. _vq_lengthlist__44u0__p7_2,
  132601. 1, -531103744, 1611661312, 4, 0,
  132602. _vq_quantlist__44u0__p7_2,
  132603. NULL,
  132604. &_vq_auxt__44u0__p7_2,
  132605. NULL,
  132606. 0
  132607. };
  132608. static long _huff_lengthlist__44u0__short[] = {
  132609. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132610. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132611. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132612. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132613. };
  132614. static static_codebook _huff_book__44u0__short = {
  132615. 2, 64,
  132616. _huff_lengthlist__44u0__short,
  132617. 0, 0, 0, 0, 0,
  132618. NULL,
  132619. NULL,
  132620. NULL,
  132621. NULL,
  132622. 0
  132623. };
  132624. static long _huff_lengthlist__44u1__long[] = {
  132625. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132626. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132627. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132628. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132629. };
  132630. static static_codebook _huff_book__44u1__long = {
  132631. 2, 64,
  132632. _huff_lengthlist__44u1__long,
  132633. 0, 0, 0, 0, 0,
  132634. NULL,
  132635. NULL,
  132636. NULL,
  132637. NULL,
  132638. 0
  132639. };
  132640. static long _vq_quantlist__44u1__p1_0[] = {
  132641. 1,
  132642. 0,
  132643. 2,
  132644. };
  132645. static long _vq_lengthlist__44u1__p1_0[] = {
  132646. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132647. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132648. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132649. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132650. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132651. 13,
  132652. };
  132653. static float _vq_quantthresh__44u1__p1_0[] = {
  132654. -0.5, 0.5,
  132655. };
  132656. static long _vq_quantmap__44u1__p1_0[] = {
  132657. 1, 0, 2,
  132658. };
  132659. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132660. _vq_quantthresh__44u1__p1_0,
  132661. _vq_quantmap__44u1__p1_0,
  132662. 3,
  132663. 3
  132664. };
  132665. static static_codebook _44u1__p1_0 = {
  132666. 4, 81,
  132667. _vq_lengthlist__44u1__p1_0,
  132668. 1, -535822336, 1611661312, 2, 0,
  132669. _vq_quantlist__44u1__p1_0,
  132670. NULL,
  132671. &_vq_auxt__44u1__p1_0,
  132672. NULL,
  132673. 0
  132674. };
  132675. static long _vq_quantlist__44u1__p2_0[] = {
  132676. 1,
  132677. 0,
  132678. 2,
  132679. };
  132680. static long _vq_lengthlist__44u1__p2_0[] = {
  132681. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132682. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132683. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132684. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132685. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132686. 9,
  132687. };
  132688. static float _vq_quantthresh__44u1__p2_0[] = {
  132689. -0.5, 0.5,
  132690. };
  132691. static long _vq_quantmap__44u1__p2_0[] = {
  132692. 1, 0, 2,
  132693. };
  132694. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132695. _vq_quantthresh__44u1__p2_0,
  132696. _vq_quantmap__44u1__p2_0,
  132697. 3,
  132698. 3
  132699. };
  132700. static static_codebook _44u1__p2_0 = {
  132701. 4, 81,
  132702. _vq_lengthlist__44u1__p2_0,
  132703. 1, -535822336, 1611661312, 2, 0,
  132704. _vq_quantlist__44u1__p2_0,
  132705. NULL,
  132706. &_vq_auxt__44u1__p2_0,
  132707. NULL,
  132708. 0
  132709. };
  132710. static long _vq_quantlist__44u1__p3_0[] = {
  132711. 2,
  132712. 1,
  132713. 3,
  132714. 0,
  132715. 4,
  132716. };
  132717. static long _vq_lengthlist__44u1__p3_0[] = {
  132718. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132719. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132720. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132721. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132722. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132723. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132724. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132725. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132726. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132727. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132728. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132729. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132730. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132731. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132732. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132733. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132734. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132735. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132736. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132737. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132738. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132739. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132740. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132741. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132742. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132743. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132744. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132745. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132746. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132747. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132748. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132749. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132750. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132751. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132752. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132753. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132754. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132755. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132756. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132757. 19,
  132758. };
  132759. static float _vq_quantthresh__44u1__p3_0[] = {
  132760. -1.5, -0.5, 0.5, 1.5,
  132761. };
  132762. static long _vq_quantmap__44u1__p3_0[] = {
  132763. 3, 1, 0, 2, 4,
  132764. };
  132765. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132766. _vq_quantthresh__44u1__p3_0,
  132767. _vq_quantmap__44u1__p3_0,
  132768. 5,
  132769. 5
  132770. };
  132771. static static_codebook _44u1__p3_0 = {
  132772. 4, 625,
  132773. _vq_lengthlist__44u1__p3_0,
  132774. 1, -533725184, 1611661312, 3, 0,
  132775. _vq_quantlist__44u1__p3_0,
  132776. NULL,
  132777. &_vq_auxt__44u1__p3_0,
  132778. NULL,
  132779. 0
  132780. };
  132781. static long _vq_quantlist__44u1__p4_0[] = {
  132782. 2,
  132783. 1,
  132784. 3,
  132785. 0,
  132786. 4,
  132787. };
  132788. static long _vq_lengthlist__44u1__p4_0[] = {
  132789. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132790. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132791. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132792. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132793. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132794. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132795. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132796. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132797. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132798. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132799. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132800. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132801. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132802. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132803. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132804. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132805. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132806. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132807. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132808. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132809. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132810. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132811. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132812. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132813. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132814. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132815. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132816. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132817. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132818. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132819. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132820. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132821. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132822. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132823. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132824. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132825. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132826. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132827. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132828. 12,
  132829. };
  132830. static float _vq_quantthresh__44u1__p4_0[] = {
  132831. -1.5, -0.5, 0.5, 1.5,
  132832. };
  132833. static long _vq_quantmap__44u1__p4_0[] = {
  132834. 3, 1, 0, 2, 4,
  132835. };
  132836. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132837. _vq_quantthresh__44u1__p4_0,
  132838. _vq_quantmap__44u1__p4_0,
  132839. 5,
  132840. 5
  132841. };
  132842. static static_codebook _44u1__p4_0 = {
  132843. 4, 625,
  132844. _vq_lengthlist__44u1__p4_0,
  132845. 1, -533725184, 1611661312, 3, 0,
  132846. _vq_quantlist__44u1__p4_0,
  132847. NULL,
  132848. &_vq_auxt__44u1__p4_0,
  132849. NULL,
  132850. 0
  132851. };
  132852. static long _vq_quantlist__44u1__p5_0[] = {
  132853. 4,
  132854. 3,
  132855. 5,
  132856. 2,
  132857. 6,
  132858. 1,
  132859. 7,
  132860. 0,
  132861. 8,
  132862. };
  132863. static long _vq_lengthlist__44u1__p5_0[] = {
  132864. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132865. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132866. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132867. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132868. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132869. 12,
  132870. };
  132871. static float _vq_quantthresh__44u1__p5_0[] = {
  132872. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132873. };
  132874. static long _vq_quantmap__44u1__p5_0[] = {
  132875. 7, 5, 3, 1, 0, 2, 4, 6,
  132876. 8,
  132877. };
  132878. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132879. _vq_quantthresh__44u1__p5_0,
  132880. _vq_quantmap__44u1__p5_0,
  132881. 9,
  132882. 9
  132883. };
  132884. static static_codebook _44u1__p5_0 = {
  132885. 2, 81,
  132886. _vq_lengthlist__44u1__p5_0,
  132887. 1, -531628032, 1611661312, 4, 0,
  132888. _vq_quantlist__44u1__p5_0,
  132889. NULL,
  132890. &_vq_auxt__44u1__p5_0,
  132891. NULL,
  132892. 0
  132893. };
  132894. static long _vq_quantlist__44u1__p6_0[] = {
  132895. 6,
  132896. 5,
  132897. 7,
  132898. 4,
  132899. 8,
  132900. 3,
  132901. 9,
  132902. 2,
  132903. 10,
  132904. 1,
  132905. 11,
  132906. 0,
  132907. 12,
  132908. };
  132909. static long _vq_lengthlist__44u1__p6_0[] = {
  132910. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132911. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132912. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132913. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132914. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132915. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132916. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132917. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132918. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132919. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132920. 15,17,16,17,18,17,17,18, 0,
  132921. };
  132922. static float _vq_quantthresh__44u1__p6_0[] = {
  132923. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132924. 12.5, 17.5, 22.5, 27.5,
  132925. };
  132926. static long _vq_quantmap__44u1__p6_0[] = {
  132927. 11, 9, 7, 5, 3, 1, 0, 2,
  132928. 4, 6, 8, 10, 12,
  132929. };
  132930. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132931. _vq_quantthresh__44u1__p6_0,
  132932. _vq_quantmap__44u1__p6_0,
  132933. 13,
  132934. 13
  132935. };
  132936. static static_codebook _44u1__p6_0 = {
  132937. 2, 169,
  132938. _vq_lengthlist__44u1__p6_0,
  132939. 1, -526516224, 1616117760, 4, 0,
  132940. _vq_quantlist__44u1__p6_0,
  132941. NULL,
  132942. &_vq_auxt__44u1__p6_0,
  132943. NULL,
  132944. 0
  132945. };
  132946. static long _vq_quantlist__44u1__p6_1[] = {
  132947. 2,
  132948. 1,
  132949. 3,
  132950. 0,
  132951. 4,
  132952. };
  132953. static long _vq_lengthlist__44u1__p6_1[] = {
  132954. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132955. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132956. };
  132957. static float _vq_quantthresh__44u1__p6_1[] = {
  132958. -1.5, -0.5, 0.5, 1.5,
  132959. };
  132960. static long _vq_quantmap__44u1__p6_1[] = {
  132961. 3, 1, 0, 2, 4,
  132962. };
  132963. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132964. _vq_quantthresh__44u1__p6_1,
  132965. _vq_quantmap__44u1__p6_1,
  132966. 5,
  132967. 5
  132968. };
  132969. static static_codebook _44u1__p6_1 = {
  132970. 2, 25,
  132971. _vq_lengthlist__44u1__p6_1,
  132972. 1, -533725184, 1611661312, 3, 0,
  132973. _vq_quantlist__44u1__p6_1,
  132974. NULL,
  132975. &_vq_auxt__44u1__p6_1,
  132976. NULL,
  132977. 0
  132978. };
  132979. static long _vq_quantlist__44u1__p7_0[] = {
  132980. 3,
  132981. 2,
  132982. 4,
  132983. 1,
  132984. 5,
  132985. 0,
  132986. 6,
  132987. };
  132988. static long _vq_lengthlist__44u1__p7_0[] = {
  132989. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132990. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132991. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132992. 8,
  132993. };
  132994. static float _vq_quantthresh__44u1__p7_0[] = {
  132995. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132996. };
  132997. static long _vq_quantmap__44u1__p7_0[] = {
  132998. 5, 3, 1, 0, 2, 4, 6,
  132999. };
  133000. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  133001. _vq_quantthresh__44u1__p7_0,
  133002. _vq_quantmap__44u1__p7_0,
  133003. 7,
  133004. 7
  133005. };
  133006. static static_codebook _44u1__p7_0 = {
  133007. 2, 49,
  133008. _vq_lengthlist__44u1__p7_0,
  133009. 1, -518017024, 1626677248, 3, 0,
  133010. _vq_quantlist__44u1__p7_0,
  133011. NULL,
  133012. &_vq_auxt__44u1__p7_0,
  133013. NULL,
  133014. 0
  133015. };
  133016. static long _vq_quantlist__44u1__p7_1[] = {
  133017. 6,
  133018. 5,
  133019. 7,
  133020. 4,
  133021. 8,
  133022. 3,
  133023. 9,
  133024. 2,
  133025. 10,
  133026. 1,
  133027. 11,
  133028. 0,
  133029. 12,
  133030. };
  133031. static long _vq_lengthlist__44u1__p7_1[] = {
  133032. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  133033. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  133034. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  133035. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  133036. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  133037. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  133038. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  133039. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  133040. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  133041. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  133042. 15,15,15,15,15,15,15,15,15,
  133043. };
  133044. static float _vq_quantthresh__44u1__p7_1[] = {
  133045. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133046. 32.5, 45.5, 58.5, 71.5,
  133047. };
  133048. static long _vq_quantmap__44u1__p7_1[] = {
  133049. 11, 9, 7, 5, 3, 1, 0, 2,
  133050. 4, 6, 8, 10, 12,
  133051. };
  133052. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  133053. _vq_quantthresh__44u1__p7_1,
  133054. _vq_quantmap__44u1__p7_1,
  133055. 13,
  133056. 13
  133057. };
  133058. static static_codebook _44u1__p7_1 = {
  133059. 2, 169,
  133060. _vq_lengthlist__44u1__p7_1,
  133061. 1, -523010048, 1618608128, 4, 0,
  133062. _vq_quantlist__44u1__p7_1,
  133063. NULL,
  133064. &_vq_auxt__44u1__p7_1,
  133065. NULL,
  133066. 0
  133067. };
  133068. static long _vq_quantlist__44u1__p7_2[] = {
  133069. 6,
  133070. 5,
  133071. 7,
  133072. 4,
  133073. 8,
  133074. 3,
  133075. 9,
  133076. 2,
  133077. 10,
  133078. 1,
  133079. 11,
  133080. 0,
  133081. 12,
  133082. };
  133083. static long _vq_lengthlist__44u1__p7_2[] = {
  133084. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  133085. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  133086. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  133087. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133088. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  133089. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  133090. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  133091. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133092. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133093. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  133094. 9, 9, 9,10, 9, 9,10,10, 9,
  133095. };
  133096. static float _vq_quantthresh__44u1__p7_2[] = {
  133097. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133098. 2.5, 3.5, 4.5, 5.5,
  133099. };
  133100. static long _vq_quantmap__44u1__p7_2[] = {
  133101. 11, 9, 7, 5, 3, 1, 0, 2,
  133102. 4, 6, 8, 10, 12,
  133103. };
  133104. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  133105. _vq_quantthresh__44u1__p7_2,
  133106. _vq_quantmap__44u1__p7_2,
  133107. 13,
  133108. 13
  133109. };
  133110. static static_codebook _44u1__p7_2 = {
  133111. 2, 169,
  133112. _vq_lengthlist__44u1__p7_2,
  133113. 1, -531103744, 1611661312, 4, 0,
  133114. _vq_quantlist__44u1__p7_2,
  133115. NULL,
  133116. &_vq_auxt__44u1__p7_2,
  133117. NULL,
  133118. 0
  133119. };
  133120. static long _huff_lengthlist__44u1__short[] = {
  133121. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  133122. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  133123. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  133124. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  133125. };
  133126. static static_codebook _huff_book__44u1__short = {
  133127. 2, 64,
  133128. _huff_lengthlist__44u1__short,
  133129. 0, 0, 0, 0, 0,
  133130. NULL,
  133131. NULL,
  133132. NULL,
  133133. NULL,
  133134. 0
  133135. };
  133136. static long _huff_lengthlist__44u2__long[] = {
  133137. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  133138. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  133139. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  133140. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  133141. };
  133142. static static_codebook _huff_book__44u2__long = {
  133143. 2, 64,
  133144. _huff_lengthlist__44u2__long,
  133145. 0, 0, 0, 0, 0,
  133146. NULL,
  133147. NULL,
  133148. NULL,
  133149. NULL,
  133150. 0
  133151. };
  133152. static long _vq_quantlist__44u2__p1_0[] = {
  133153. 1,
  133154. 0,
  133155. 2,
  133156. };
  133157. static long _vq_lengthlist__44u2__p1_0[] = {
  133158. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  133159. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133160. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  133161. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  133162. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  133163. 13,
  133164. };
  133165. static float _vq_quantthresh__44u2__p1_0[] = {
  133166. -0.5, 0.5,
  133167. };
  133168. static long _vq_quantmap__44u2__p1_0[] = {
  133169. 1, 0, 2,
  133170. };
  133171. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  133172. _vq_quantthresh__44u2__p1_0,
  133173. _vq_quantmap__44u2__p1_0,
  133174. 3,
  133175. 3
  133176. };
  133177. static static_codebook _44u2__p1_0 = {
  133178. 4, 81,
  133179. _vq_lengthlist__44u2__p1_0,
  133180. 1, -535822336, 1611661312, 2, 0,
  133181. _vq_quantlist__44u2__p1_0,
  133182. NULL,
  133183. &_vq_auxt__44u2__p1_0,
  133184. NULL,
  133185. 0
  133186. };
  133187. static long _vq_quantlist__44u2__p2_0[] = {
  133188. 1,
  133189. 0,
  133190. 2,
  133191. };
  133192. static long _vq_lengthlist__44u2__p2_0[] = {
  133193. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133194. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  133195. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133196. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133197. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133198. 9,
  133199. };
  133200. static float _vq_quantthresh__44u2__p2_0[] = {
  133201. -0.5, 0.5,
  133202. };
  133203. static long _vq_quantmap__44u2__p2_0[] = {
  133204. 1, 0, 2,
  133205. };
  133206. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  133207. _vq_quantthresh__44u2__p2_0,
  133208. _vq_quantmap__44u2__p2_0,
  133209. 3,
  133210. 3
  133211. };
  133212. static static_codebook _44u2__p2_0 = {
  133213. 4, 81,
  133214. _vq_lengthlist__44u2__p2_0,
  133215. 1, -535822336, 1611661312, 2, 0,
  133216. _vq_quantlist__44u2__p2_0,
  133217. NULL,
  133218. &_vq_auxt__44u2__p2_0,
  133219. NULL,
  133220. 0
  133221. };
  133222. static long _vq_quantlist__44u2__p3_0[] = {
  133223. 2,
  133224. 1,
  133225. 3,
  133226. 0,
  133227. 4,
  133228. };
  133229. static long _vq_lengthlist__44u2__p3_0[] = {
  133230. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133231. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133232. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133233. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133234. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  133235. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  133236. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  133237. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  133238. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133239. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133240. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  133241. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133242. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  133243. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  133244. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  133245. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  133246. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  133247. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  133248. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  133249. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  133250. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  133251. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  133252. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  133253. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  133254. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  133255. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  133256. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  133257. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  133258. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  133259. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  133260. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  133261. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  133262. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  133263. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  133264. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  133265. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  133266. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  133267. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  133268. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  133269. 0,
  133270. };
  133271. static float _vq_quantthresh__44u2__p3_0[] = {
  133272. -1.5, -0.5, 0.5, 1.5,
  133273. };
  133274. static long _vq_quantmap__44u2__p3_0[] = {
  133275. 3, 1, 0, 2, 4,
  133276. };
  133277. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  133278. _vq_quantthresh__44u2__p3_0,
  133279. _vq_quantmap__44u2__p3_0,
  133280. 5,
  133281. 5
  133282. };
  133283. static static_codebook _44u2__p3_0 = {
  133284. 4, 625,
  133285. _vq_lengthlist__44u2__p3_0,
  133286. 1, -533725184, 1611661312, 3, 0,
  133287. _vq_quantlist__44u2__p3_0,
  133288. NULL,
  133289. &_vq_auxt__44u2__p3_0,
  133290. NULL,
  133291. 0
  133292. };
  133293. static long _vq_quantlist__44u2__p4_0[] = {
  133294. 2,
  133295. 1,
  133296. 3,
  133297. 0,
  133298. 4,
  133299. };
  133300. static long _vq_lengthlist__44u2__p4_0[] = {
  133301. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133302. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133303. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  133304. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  133305. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  133306. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133307. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  133308. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  133309. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133310. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133311. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  133312. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133313. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  133314. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  133315. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  133316. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  133317. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  133318. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133319. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133320. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133321. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133322. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  133323. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133324. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133325. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133326. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  133327. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  133328. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  133329. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133330. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  133331. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  133332. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  133333. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  133334. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133335. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133336. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  133337. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133338. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  133339. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  133340. 13,
  133341. };
  133342. static float _vq_quantthresh__44u2__p4_0[] = {
  133343. -1.5, -0.5, 0.5, 1.5,
  133344. };
  133345. static long _vq_quantmap__44u2__p4_0[] = {
  133346. 3, 1, 0, 2, 4,
  133347. };
  133348. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  133349. _vq_quantthresh__44u2__p4_0,
  133350. _vq_quantmap__44u2__p4_0,
  133351. 5,
  133352. 5
  133353. };
  133354. static static_codebook _44u2__p4_0 = {
  133355. 4, 625,
  133356. _vq_lengthlist__44u2__p4_0,
  133357. 1, -533725184, 1611661312, 3, 0,
  133358. _vq_quantlist__44u2__p4_0,
  133359. NULL,
  133360. &_vq_auxt__44u2__p4_0,
  133361. NULL,
  133362. 0
  133363. };
  133364. static long _vq_quantlist__44u2__p5_0[] = {
  133365. 4,
  133366. 3,
  133367. 5,
  133368. 2,
  133369. 6,
  133370. 1,
  133371. 7,
  133372. 0,
  133373. 8,
  133374. };
  133375. static long _vq_lengthlist__44u2__p5_0[] = {
  133376. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  133377. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  133378. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  133379. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  133380. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  133381. 13,
  133382. };
  133383. static float _vq_quantthresh__44u2__p5_0[] = {
  133384. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133385. };
  133386. static long _vq_quantmap__44u2__p5_0[] = {
  133387. 7, 5, 3, 1, 0, 2, 4, 6,
  133388. 8,
  133389. };
  133390. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  133391. _vq_quantthresh__44u2__p5_0,
  133392. _vq_quantmap__44u2__p5_0,
  133393. 9,
  133394. 9
  133395. };
  133396. static static_codebook _44u2__p5_0 = {
  133397. 2, 81,
  133398. _vq_lengthlist__44u2__p5_0,
  133399. 1, -531628032, 1611661312, 4, 0,
  133400. _vq_quantlist__44u2__p5_0,
  133401. NULL,
  133402. &_vq_auxt__44u2__p5_0,
  133403. NULL,
  133404. 0
  133405. };
  133406. static long _vq_quantlist__44u2__p6_0[] = {
  133407. 6,
  133408. 5,
  133409. 7,
  133410. 4,
  133411. 8,
  133412. 3,
  133413. 9,
  133414. 2,
  133415. 10,
  133416. 1,
  133417. 11,
  133418. 0,
  133419. 12,
  133420. };
  133421. static long _vq_lengthlist__44u2__p6_0[] = {
  133422. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  133423. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  133424. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  133425. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  133426. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  133427. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  133428. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  133429. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  133430. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  133431. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  133432. 15,17,17,16,18,17,18, 0, 0,
  133433. };
  133434. static float _vq_quantthresh__44u2__p6_0[] = {
  133435. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133436. 12.5, 17.5, 22.5, 27.5,
  133437. };
  133438. static long _vq_quantmap__44u2__p6_0[] = {
  133439. 11, 9, 7, 5, 3, 1, 0, 2,
  133440. 4, 6, 8, 10, 12,
  133441. };
  133442. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  133443. _vq_quantthresh__44u2__p6_0,
  133444. _vq_quantmap__44u2__p6_0,
  133445. 13,
  133446. 13
  133447. };
  133448. static static_codebook _44u2__p6_0 = {
  133449. 2, 169,
  133450. _vq_lengthlist__44u2__p6_0,
  133451. 1, -526516224, 1616117760, 4, 0,
  133452. _vq_quantlist__44u2__p6_0,
  133453. NULL,
  133454. &_vq_auxt__44u2__p6_0,
  133455. NULL,
  133456. 0
  133457. };
  133458. static long _vq_quantlist__44u2__p6_1[] = {
  133459. 2,
  133460. 1,
  133461. 3,
  133462. 0,
  133463. 4,
  133464. };
  133465. static long _vq_lengthlist__44u2__p6_1[] = {
  133466. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133467. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133468. };
  133469. static float _vq_quantthresh__44u2__p6_1[] = {
  133470. -1.5, -0.5, 0.5, 1.5,
  133471. };
  133472. static long _vq_quantmap__44u2__p6_1[] = {
  133473. 3, 1, 0, 2, 4,
  133474. };
  133475. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  133476. _vq_quantthresh__44u2__p6_1,
  133477. _vq_quantmap__44u2__p6_1,
  133478. 5,
  133479. 5
  133480. };
  133481. static static_codebook _44u2__p6_1 = {
  133482. 2, 25,
  133483. _vq_lengthlist__44u2__p6_1,
  133484. 1, -533725184, 1611661312, 3, 0,
  133485. _vq_quantlist__44u2__p6_1,
  133486. NULL,
  133487. &_vq_auxt__44u2__p6_1,
  133488. NULL,
  133489. 0
  133490. };
  133491. static long _vq_quantlist__44u2__p7_0[] = {
  133492. 4,
  133493. 3,
  133494. 5,
  133495. 2,
  133496. 6,
  133497. 1,
  133498. 7,
  133499. 0,
  133500. 8,
  133501. };
  133502. static long _vq_lengthlist__44u2__p7_0[] = {
  133503. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  133504. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  133505. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133506. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133507. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133508. 11,
  133509. };
  133510. static float _vq_quantthresh__44u2__p7_0[] = {
  133511. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  133512. };
  133513. static long _vq_quantmap__44u2__p7_0[] = {
  133514. 7, 5, 3, 1, 0, 2, 4, 6,
  133515. 8,
  133516. };
  133517. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  133518. _vq_quantthresh__44u2__p7_0,
  133519. _vq_quantmap__44u2__p7_0,
  133520. 9,
  133521. 9
  133522. };
  133523. static static_codebook _44u2__p7_0 = {
  133524. 2, 81,
  133525. _vq_lengthlist__44u2__p7_0,
  133526. 1, -516612096, 1626677248, 4, 0,
  133527. _vq_quantlist__44u2__p7_0,
  133528. NULL,
  133529. &_vq_auxt__44u2__p7_0,
  133530. NULL,
  133531. 0
  133532. };
  133533. static long _vq_quantlist__44u2__p7_1[] = {
  133534. 6,
  133535. 5,
  133536. 7,
  133537. 4,
  133538. 8,
  133539. 3,
  133540. 9,
  133541. 2,
  133542. 10,
  133543. 1,
  133544. 11,
  133545. 0,
  133546. 12,
  133547. };
  133548. static long _vq_lengthlist__44u2__p7_1[] = {
  133549. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133550. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133551. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133552. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133553. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133554. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133555. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133556. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133557. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133558. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133559. 14,14,14,17,15,17,17,17,17,
  133560. };
  133561. static float _vq_quantthresh__44u2__p7_1[] = {
  133562. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133563. 32.5, 45.5, 58.5, 71.5,
  133564. };
  133565. static long _vq_quantmap__44u2__p7_1[] = {
  133566. 11, 9, 7, 5, 3, 1, 0, 2,
  133567. 4, 6, 8, 10, 12,
  133568. };
  133569. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133570. _vq_quantthresh__44u2__p7_1,
  133571. _vq_quantmap__44u2__p7_1,
  133572. 13,
  133573. 13
  133574. };
  133575. static static_codebook _44u2__p7_1 = {
  133576. 2, 169,
  133577. _vq_lengthlist__44u2__p7_1,
  133578. 1, -523010048, 1618608128, 4, 0,
  133579. _vq_quantlist__44u2__p7_1,
  133580. NULL,
  133581. &_vq_auxt__44u2__p7_1,
  133582. NULL,
  133583. 0
  133584. };
  133585. static long _vq_quantlist__44u2__p7_2[] = {
  133586. 6,
  133587. 5,
  133588. 7,
  133589. 4,
  133590. 8,
  133591. 3,
  133592. 9,
  133593. 2,
  133594. 10,
  133595. 1,
  133596. 11,
  133597. 0,
  133598. 12,
  133599. };
  133600. static long _vq_lengthlist__44u2__p7_2[] = {
  133601. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133602. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133603. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133604. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133605. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133606. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133607. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133608. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133609. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133610. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133611. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133612. };
  133613. static float _vq_quantthresh__44u2__p7_2[] = {
  133614. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133615. 2.5, 3.5, 4.5, 5.5,
  133616. };
  133617. static long _vq_quantmap__44u2__p7_2[] = {
  133618. 11, 9, 7, 5, 3, 1, 0, 2,
  133619. 4, 6, 8, 10, 12,
  133620. };
  133621. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133622. _vq_quantthresh__44u2__p7_2,
  133623. _vq_quantmap__44u2__p7_2,
  133624. 13,
  133625. 13
  133626. };
  133627. static static_codebook _44u2__p7_2 = {
  133628. 2, 169,
  133629. _vq_lengthlist__44u2__p7_2,
  133630. 1, -531103744, 1611661312, 4, 0,
  133631. _vq_quantlist__44u2__p7_2,
  133632. NULL,
  133633. &_vq_auxt__44u2__p7_2,
  133634. NULL,
  133635. 0
  133636. };
  133637. static long _huff_lengthlist__44u2__short[] = {
  133638. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133639. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133640. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133641. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133642. };
  133643. static static_codebook _huff_book__44u2__short = {
  133644. 2, 64,
  133645. _huff_lengthlist__44u2__short,
  133646. 0, 0, 0, 0, 0,
  133647. NULL,
  133648. NULL,
  133649. NULL,
  133650. NULL,
  133651. 0
  133652. };
  133653. static long _huff_lengthlist__44u3__long[] = {
  133654. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133655. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133656. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133657. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133658. };
  133659. static static_codebook _huff_book__44u3__long = {
  133660. 2, 64,
  133661. _huff_lengthlist__44u3__long,
  133662. 0, 0, 0, 0, 0,
  133663. NULL,
  133664. NULL,
  133665. NULL,
  133666. NULL,
  133667. 0
  133668. };
  133669. static long _vq_quantlist__44u3__p1_0[] = {
  133670. 1,
  133671. 0,
  133672. 2,
  133673. };
  133674. static long _vq_lengthlist__44u3__p1_0[] = {
  133675. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133676. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133677. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133678. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133679. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133680. 13,
  133681. };
  133682. static float _vq_quantthresh__44u3__p1_0[] = {
  133683. -0.5, 0.5,
  133684. };
  133685. static long _vq_quantmap__44u3__p1_0[] = {
  133686. 1, 0, 2,
  133687. };
  133688. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133689. _vq_quantthresh__44u3__p1_0,
  133690. _vq_quantmap__44u3__p1_0,
  133691. 3,
  133692. 3
  133693. };
  133694. static static_codebook _44u3__p1_0 = {
  133695. 4, 81,
  133696. _vq_lengthlist__44u3__p1_0,
  133697. 1, -535822336, 1611661312, 2, 0,
  133698. _vq_quantlist__44u3__p1_0,
  133699. NULL,
  133700. &_vq_auxt__44u3__p1_0,
  133701. NULL,
  133702. 0
  133703. };
  133704. static long _vq_quantlist__44u3__p2_0[] = {
  133705. 1,
  133706. 0,
  133707. 2,
  133708. };
  133709. static long _vq_lengthlist__44u3__p2_0[] = {
  133710. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133711. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133712. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133713. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133714. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133715. 9,
  133716. };
  133717. static float _vq_quantthresh__44u3__p2_0[] = {
  133718. -0.5, 0.5,
  133719. };
  133720. static long _vq_quantmap__44u3__p2_0[] = {
  133721. 1, 0, 2,
  133722. };
  133723. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133724. _vq_quantthresh__44u3__p2_0,
  133725. _vq_quantmap__44u3__p2_0,
  133726. 3,
  133727. 3
  133728. };
  133729. static static_codebook _44u3__p2_0 = {
  133730. 4, 81,
  133731. _vq_lengthlist__44u3__p2_0,
  133732. 1, -535822336, 1611661312, 2, 0,
  133733. _vq_quantlist__44u3__p2_0,
  133734. NULL,
  133735. &_vq_auxt__44u3__p2_0,
  133736. NULL,
  133737. 0
  133738. };
  133739. static long _vq_quantlist__44u3__p3_0[] = {
  133740. 2,
  133741. 1,
  133742. 3,
  133743. 0,
  133744. 4,
  133745. };
  133746. static long _vq_lengthlist__44u3__p3_0[] = {
  133747. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133748. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133749. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133750. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133751. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133752. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133753. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133754. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133755. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133756. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133757. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133758. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133759. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133760. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133761. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133762. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133763. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133764. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133765. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133766. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133767. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133768. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133769. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133770. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133771. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133772. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133773. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133774. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133775. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133776. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133777. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133778. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133779. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133780. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133781. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133782. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133783. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133784. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133785. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133786. 0,
  133787. };
  133788. static float _vq_quantthresh__44u3__p3_0[] = {
  133789. -1.5, -0.5, 0.5, 1.5,
  133790. };
  133791. static long _vq_quantmap__44u3__p3_0[] = {
  133792. 3, 1, 0, 2, 4,
  133793. };
  133794. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133795. _vq_quantthresh__44u3__p3_0,
  133796. _vq_quantmap__44u3__p3_0,
  133797. 5,
  133798. 5
  133799. };
  133800. static static_codebook _44u3__p3_0 = {
  133801. 4, 625,
  133802. _vq_lengthlist__44u3__p3_0,
  133803. 1, -533725184, 1611661312, 3, 0,
  133804. _vq_quantlist__44u3__p3_0,
  133805. NULL,
  133806. &_vq_auxt__44u3__p3_0,
  133807. NULL,
  133808. 0
  133809. };
  133810. static long _vq_quantlist__44u3__p4_0[] = {
  133811. 2,
  133812. 1,
  133813. 3,
  133814. 0,
  133815. 4,
  133816. };
  133817. static long _vq_lengthlist__44u3__p4_0[] = {
  133818. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133819. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133820. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133821. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133822. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133823. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133824. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133825. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133826. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133827. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133828. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133829. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133830. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133831. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133832. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133833. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133834. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133835. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133836. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133837. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133838. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133839. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133840. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133841. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133842. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133843. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133844. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133845. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133846. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133847. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133848. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133849. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133850. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133851. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133852. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133853. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133854. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133855. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133856. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133857. 13,
  133858. };
  133859. static float _vq_quantthresh__44u3__p4_0[] = {
  133860. -1.5, -0.5, 0.5, 1.5,
  133861. };
  133862. static long _vq_quantmap__44u3__p4_0[] = {
  133863. 3, 1, 0, 2, 4,
  133864. };
  133865. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133866. _vq_quantthresh__44u3__p4_0,
  133867. _vq_quantmap__44u3__p4_0,
  133868. 5,
  133869. 5
  133870. };
  133871. static static_codebook _44u3__p4_0 = {
  133872. 4, 625,
  133873. _vq_lengthlist__44u3__p4_0,
  133874. 1, -533725184, 1611661312, 3, 0,
  133875. _vq_quantlist__44u3__p4_0,
  133876. NULL,
  133877. &_vq_auxt__44u3__p4_0,
  133878. NULL,
  133879. 0
  133880. };
  133881. static long _vq_quantlist__44u3__p5_0[] = {
  133882. 4,
  133883. 3,
  133884. 5,
  133885. 2,
  133886. 6,
  133887. 1,
  133888. 7,
  133889. 0,
  133890. 8,
  133891. };
  133892. static long _vq_lengthlist__44u3__p5_0[] = {
  133893. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133894. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133895. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133896. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133897. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133898. 12,
  133899. };
  133900. static float _vq_quantthresh__44u3__p5_0[] = {
  133901. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133902. };
  133903. static long _vq_quantmap__44u3__p5_0[] = {
  133904. 7, 5, 3, 1, 0, 2, 4, 6,
  133905. 8,
  133906. };
  133907. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133908. _vq_quantthresh__44u3__p5_0,
  133909. _vq_quantmap__44u3__p5_0,
  133910. 9,
  133911. 9
  133912. };
  133913. static static_codebook _44u3__p5_0 = {
  133914. 2, 81,
  133915. _vq_lengthlist__44u3__p5_0,
  133916. 1, -531628032, 1611661312, 4, 0,
  133917. _vq_quantlist__44u3__p5_0,
  133918. NULL,
  133919. &_vq_auxt__44u3__p5_0,
  133920. NULL,
  133921. 0
  133922. };
  133923. static long _vq_quantlist__44u3__p6_0[] = {
  133924. 6,
  133925. 5,
  133926. 7,
  133927. 4,
  133928. 8,
  133929. 3,
  133930. 9,
  133931. 2,
  133932. 10,
  133933. 1,
  133934. 11,
  133935. 0,
  133936. 12,
  133937. };
  133938. static long _vq_lengthlist__44u3__p6_0[] = {
  133939. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133940. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133941. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133942. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133943. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133944. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133945. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133946. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133947. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133948. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133949. 15,16,16,16,17,18,16,20,18,
  133950. };
  133951. static float _vq_quantthresh__44u3__p6_0[] = {
  133952. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133953. 12.5, 17.5, 22.5, 27.5,
  133954. };
  133955. static long _vq_quantmap__44u3__p6_0[] = {
  133956. 11, 9, 7, 5, 3, 1, 0, 2,
  133957. 4, 6, 8, 10, 12,
  133958. };
  133959. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133960. _vq_quantthresh__44u3__p6_0,
  133961. _vq_quantmap__44u3__p6_0,
  133962. 13,
  133963. 13
  133964. };
  133965. static static_codebook _44u3__p6_0 = {
  133966. 2, 169,
  133967. _vq_lengthlist__44u3__p6_0,
  133968. 1, -526516224, 1616117760, 4, 0,
  133969. _vq_quantlist__44u3__p6_0,
  133970. NULL,
  133971. &_vq_auxt__44u3__p6_0,
  133972. NULL,
  133973. 0
  133974. };
  133975. static long _vq_quantlist__44u3__p6_1[] = {
  133976. 2,
  133977. 1,
  133978. 3,
  133979. 0,
  133980. 4,
  133981. };
  133982. static long _vq_lengthlist__44u3__p6_1[] = {
  133983. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133984. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133985. };
  133986. static float _vq_quantthresh__44u3__p6_1[] = {
  133987. -1.5, -0.5, 0.5, 1.5,
  133988. };
  133989. static long _vq_quantmap__44u3__p6_1[] = {
  133990. 3, 1, 0, 2, 4,
  133991. };
  133992. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133993. _vq_quantthresh__44u3__p6_1,
  133994. _vq_quantmap__44u3__p6_1,
  133995. 5,
  133996. 5
  133997. };
  133998. static static_codebook _44u3__p6_1 = {
  133999. 2, 25,
  134000. _vq_lengthlist__44u3__p6_1,
  134001. 1, -533725184, 1611661312, 3, 0,
  134002. _vq_quantlist__44u3__p6_1,
  134003. NULL,
  134004. &_vq_auxt__44u3__p6_1,
  134005. NULL,
  134006. 0
  134007. };
  134008. static long _vq_quantlist__44u3__p7_0[] = {
  134009. 4,
  134010. 3,
  134011. 5,
  134012. 2,
  134013. 6,
  134014. 1,
  134015. 7,
  134016. 0,
  134017. 8,
  134018. };
  134019. static long _vq_lengthlist__44u3__p7_0[] = {
  134020. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  134021. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134022. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  134023. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  134024. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  134025. 9,
  134026. };
  134027. static float _vq_quantthresh__44u3__p7_0[] = {
  134028. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  134029. };
  134030. static long _vq_quantmap__44u3__p7_0[] = {
  134031. 7, 5, 3, 1, 0, 2, 4, 6,
  134032. 8,
  134033. };
  134034. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  134035. _vq_quantthresh__44u3__p7_0,
  134036. _vq_quantmap__44u3__p7_0,
  134037. 9,
  134038. 9
  134039. };
  134040. static static_codebook _44u3__p7_0 = {
  134041. 2, 81,
  134042. _vq_lengthlist__44u3__p7_0,
  134043. 1, -515907584, 1627381760, 4, 0,
  134044. _vq_quantlist__44u3__p7_0,
  134045. NULL,
  134046. &_vq_auxt__44u3__p7_0,
  134047. NULL,
  134048. 0
  134049. };
  134050. static long _vq_quantlist__44u3__p7_1[] = {
  134051. 7,
  134052. 6,
  134053. 8,
  134054. 5,
  134055. 9,
  134056. 4,
  134057. 10,
  134058. 3,
  134059. 11,
  134060. 2,
  134061. 12,
  134062. 1,
  134063. 13,
  134064. 0,
  134065. 14,
  134066. };
  134067. static long _vq_lengthlist__44u3__p7_1[] = {
  134068. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  134069. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  134070. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  134071. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  134072. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  134073. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  134074. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  134075. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  134076. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  134077. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  134078. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  134079. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  134080. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  134081. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  134082. 17,
  134083. };
  134084. static float _vq_quantthresh__44u3__p7_1[] = {
  134085. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134086. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134087. };
  134088. static long _vq_quantmap__44u3__p7_1[] = {
  134089. 13, 11, 9, 7, 5, 3, 1, 0,
  134090. 2, 4, 6, 8, 10, 12, 14,
  134091. };
  134092. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  134093. _vq_quantthresh__44u3__p7_1,
  134094. _vq_quantmap__44u3__p7_1,
  134095. 15,
  134096. 15
  134097. };
  134098. static static_codebook _44u3__p7_1 = {
  134099. 2, 225,
  134100. _vq_lengthlist__44u3__p7_1,
  134101. 1, -522338304, 1620115456, 4, 0,
  134102. _vq_quantlist__44u3__p7_1,
  134103. NULL,
  134104. &_vq_auxt__44u3__p7_1,
  134105. NULL,
  134106. 0
  134107. };
  134108. static long _vq_quantlist__44u3__p7_2[] = {
  134109. 8,
  134110. 7,
  134111. 9,
  134112. 6,
  134113. 10,
  134114. 5,
  134115. 11,
  134116. 4,
  134117. 12,
  134118. 3,
  134119. 13,
  134120. 2,
  134121. 14,
  134122. 1,
  134123. 15,
  134124. 0,
  134125. 16,
  134126. };
  134127. static long _vq_lengthlist__44u3__p7_2[] = {
  134128. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134129. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134130. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  134131. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134132. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134133. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134134. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  134135. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134136. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  134137. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  134138. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134139. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  134140. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  134141. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134142. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  134143. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  134144. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134145. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  134146. 11,
  134147. };
  134148. static float _vq_quantthresh__44u3__p7_2[] = {
  134149. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134150. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134151. };
  134152. static long _vq_quantmap__44u3__p7_2[] = {
  134153. 15, 13, 11, 9, 7, 5, 3, 1,
  134154. 0, 2, 4, 6, 8, 10, 12, 14,
  134155. 16,
  134156. };
  134157. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  134158. _vq_quantthresh__44u3__p7_2,
  134159. _vq_quantmap__44u3__p7_2,
  134160. 17,
  134161. 17
  134162. };
  134163. static static_codebook _44u3__p7_2 = {
  134164. 2, 289,
  134165. _vq_lengthlist__44u3__p7_2,
  134166. 1, -529530880, 1611661312, 5, 0,
  134167. _vq_quantlist__44u3__p7_2,
  134168. NULL,
  134169. &_vq_auxt__44u3__p7_2,
  134170. NULL,
  134171. 0
  134172. };
  134173. static long _huff_lengthlist__44u3__short[] = {
  134174. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  134175. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  134176. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  134177. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  134178. };
  134179. static static_codebook _huff_book__44u3__short = {
  134180. 2, 64,
  134181. _huff_lengthlist__44u3__short,
  134182. 0, 0, 0, 0, 0,
  134183. NULL,
  134184. NULL,
  134185. NULL,
  134186. NULL,
  134187. 0
  134188. };
  134189. static long _huff_lengthlist__44u4__long[] = {
  134190. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  134191. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  134192. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  134193. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  134194. };
  134195. static static_codebook _huff_book__44u4__long = {
  134196. 2, 64,
  134197. _huff_lengthlist__44u4__long,
  134198. 0, 0, 0, 0, 0,
  134199. NULL,
  134200. NULL,
  134201. NULL,
  134202. NULL,
  134203. 0
  134204. };
  134205. static long _vq_quantlist__44u4__p1_0[] = {
  134206. 1,
  134207. 0,
  134208. 2,
  134209. };
  134210. static long _vq_lengthlist__44u4__p1_0[] = {
  134211. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  134212. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  134213. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  134214. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  134215. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  134216. 13,
  134217. };
  134218. static float _vq_quantthresh__44u4__p1_0[] = {
  134219. -0.5, 0.5,
  134220. };
  134221. static long _vq_quantmap__44u4__p1_0[] = {
  134222. 1, 0, 2,
  134223. };
  134224. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  134225. _vq_quantthresh__44u4__p1_0,
  134226. _vq_quantmap__44u4__p1_0,
  134227. 3,
  134228. 3
  134229. };
  134230. static static_codebook _44u4__p1_0 = {
  134231. 4, 81,
  134232. _vq_lengthlist__44u4__p1_0,
  134233. 1, -535822336, 1611661312, 2, 0,
  134234. _vq_quantlist__44u4__p1_0,
  134235. NULL,
  134236. &_vq_auxt__44u4__p1_0,
  134237. NULL,
  134238. 0
  134239. };
  134240. static long _vq_quantlist__44u4__p2_0[] = {
  134241. 1,
  134242. 0,
  134243. 2,
  134244. };
  134245. static long _vq_lengthlist__44u4__p2_0[] = {
  134246. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  134247. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  134248. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  134249. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  134250. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  134251. 9,
  134252. };
  134253. static float _vq_quantthresh__44u4__p2_0[] = {
  134254. -0.5, 0.5,
  134255. };
  134256. static long _vq_quantmap__44u4__p2_0[] = {
  134257. 1, 0, 2,
  134258. };
  134259. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  134260. _vq_quantthresh__44u4__p2_0,
  134261. _vq_quantmap__44u4__p2_0,
  134262. 3,
  134263. 3
  134264. };
  134265. static static_codebook _44u4__p2_0 = {
  134266. 4, 81,
  134267. _vq_lengthlist__44u4__p2_0,
  134268. 1, -535822336, 1611661312, 2, 0,
  134269. _vq_quantlist__44u4__p2_0,
  134270. NULL,
  134271. &_vq_auxt__44u4__p2_0,
  134272. NULL,
  134273. 0
  134274. };
  134275. static long _vq_quantlist__44u4__p3_0[] = {
  134276. 2,
  134277. 1,
  134278. 3,
  134279. 0,
  134280. 4,
  134281. };
  134282. static long _vq_lengthlist__44u4__p3_0[] = {
  134283. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  134284. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134285. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  134286. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  134287. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  134288. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  134289. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  134290. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  134291. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  134292. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  134293. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  134294. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  134295. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  134296. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  134297. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  134298. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  134299. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  134300. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  134301. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  134302. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  134303. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  134304. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  134305. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  134306. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  134307. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  134308. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  134309. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  134310. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  134311. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  134312. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  134313. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  134314. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  134315. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  134316. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  134317. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  134318. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  134319. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  134320. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  134321. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  134322. 0,
  134323. };
  134324. static float _vq_quantthresh__44u4__p3_0[] = {
  134325. -1.5, -0.5, 0.5, 1.5,
  134326. };
  134327. static long _vq_quantmap__44u4__p3_0[] = {
  134328. 3, 1, 0, 2, 4,
  134329. };
  134330. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  134331. _vq_quantthresh__44u4__p3_0,
  134332. _vq_quantmap__44u4__p3_0,
  134333. 5,
  134334. 5
  134335. };
  134336. static static_codebook _44u4__p3_0 = {
  134337. 4, 625,
  134338. _vq_lengthlist__44u4__p3_0,
  134339. 1, -533725184, 1611661312, 3, 0,
  134340. _vq_quantlist__44u4__p3_0,
  134341. NULL,
  134342. &_vq_auxt__44u4__p3_0,
  134343. NULL,
  134344. 0
  134345. };
  134346. static long _vq_quantlist__44u4__p4_0[] = {
  134347. 2,
  134348. 1,
  134349. 3,
  134350. 0,
  134351. 4,
  134352. };
  134353. static long _vq_lengthlist__44u4__p4_0[] = {
  134354. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  134355. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  134356. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  134357. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  134358. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  134359. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  134360. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  134361. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  134362. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  134363. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  134364. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  134365. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134366. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  134367. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  134368. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  134369. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  134370. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  134371. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134372. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  134373. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  134374. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  134375. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  134376. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  134377. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  134378. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  134379. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  134380. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  134381. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  134382. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  134383. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  134384. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  134385. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  134386. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  134387. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  134388. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  134389. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  134390. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  134391. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  134392. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  134393. 13,
  134394. };
  134395. static float _vq_quantthresh__44u4__p4_0[] = {
  134396. -1.5, -0.5, 0.5, 1.5,
  134397. };
  134398. static long _vq_quantmap__44u4__p4_0[] = {
  134399. 3, 1, 0, 2, 4,
  134400. };
  134401. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  134402. _vq_quantthresh__44u4__p4_0,
  134403. _vq_quantmap__44u4__p4_0,
  134404. 5,
  134405. 5
  134406. };
  134407. static static_codebook _44u4__p4_0 = {
  134408. 4, 625,
  134409. _vq_lengthlist__44u4__p4_0,
  134410. 1, -533725184, 1611661312, 3, 0,
  134411. _vq_quantlist__44u4__p4_0,
  134412. NULL,
  134413. &_vq_auxt__44u4__p4_0,
  134414. NULL,
  134415. 0
  134416. };
  134417. static long _vq_quantlist__44u4__p5_0[] = {
  134418. 4,
  134419. 3,
  134420. 5,
  134421. 2,
  134422. 6,
  134423. 1,
  134424. 7,
  134425. 0,
  134426. 8,
  134427. };
  134428. static long _vq_lengthlist__44u4__p5_0[] = {
  134429. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  134430. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  134431. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  134432. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  134433. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  134434. 12,
  134435. };
  134436. static float _vq_quantthresh__44u4__p5_0[] = {
  134437. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134438. };
  134439. static long _vq_quantmap__44u4__p5_0[] = {
  134440. 7, 5, 3, 1, 0, 2, 4, 6,
  134441. 8,
  134442. };
  134443. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  134444. _vq_quantthresh__44u4__p5_0,
  134445. _vq_quantmap__44u4__p5_0,
  134446. 9,
  134447. 9
  134448. };
  134449. static static_codebook _44u4__p5_0 = {
  134450. 2, 81,
  134451. _vq_lengthlist__44u4__p5_0,
  134452. 1, -531628032, 1611661312, 4, 0,
  134453. _vq_quantlist__44u4__p5_0,
  134454. NULL,
  134455. &_vq_auxt__44u4__p5_0,
  134456. NULL,
  134457. 0
  134458. };
  134459. static long _vq_quantlist__44u4__p6_0[] = {
  134460. 6,
  134461. 5,
  134462. 7,
  134463. 4,
  134464. 8,
  134465. 3,
  134466. 9,
  134467. 2,
  134468. 10,
  134469. 1,
  134470. 11,
  134471. 0,
  134472. 12,
  134473. };
  134474. static long _vq_lengthlist__44u4__p6_0[] = {
  134475. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  134476. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  134477. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  134478. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  134479. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  134480. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  134481. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  134482. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  134483. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  134484. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  134485. 16,16,16,17,17,18,17,20,21,
  134486. };
  134487. static float _vq_quantthresh__44u4__p6_0[] = {
  134488. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  134489. 12.5, 17.5, 22.5, 27.5,
  134490. };
  134491. static long _vq_quantmap__44u4__p6_0[] = {
  134492. 11, 9, 7, 5, 3, 1, 0, 2,
  134493. 4, 6, 8, 10, 12,
  134494. };
  134495. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  134496. _vq_quantthresh__44u4__p6_0,
  134497. _vq_quantmap__44u4__p6_0,
  134498. 13,
  134499. 13
  134500. };
  134501. static static_codebook _44u4__p6_0 = {
  134502. 2, 169,
  134503. _vq_lengthlist__44u4__p6_0,
  134504. 1, -526516224, 1616117760, 4, 0,
  134505. _vq_quantlist__44u4__p6_0,
  134506. NULL,
  134507. &_vq_auxt__44u4__p6_0,
  134508. NULL,
  134509. 0
  134510. };
  134511. static long _vq_quantlist__44u4__p6_1[] = {
  134512. 2,
  134513. 1,
  134514. 3,
  134515. 0,
  134516. 4,
  134517. };
  134518. static long _vq_lengthlist__44u4__p6_1[] = {
  134519. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134520. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134521. };
  134522. static float _vq_quantthresh__44u4__p6_1[] = {
  134523. -1.5, -0.5, 0.5, 1.5,
  134524. };
  134525. static long _vq_quantmap__44u4__p6_1[] = {
  134526. 3, 1, 0, 2, 4,
  134527. };
  134528. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134529. _vq_quantthresh__44u4__p6_1,
  134530. _vq_quantmap__44u4__p6_1,
  134531. 5,
  134532. 5
  134533. };
  134534. static static_codebook _44u4__p6_1 = {
  134535. 2, 25,
  134536. _vq_lengthlist__44u4__p6_1,
  134537. 1, -533725184, 1611661312, 3, 0,
  134538. _vq_quantlist__44u4__p6_1,
  134539. NULL,
  134540. &_vq_auxt__44u4__p6_1,
  134541. NULL,
  134542. 0
  134543. };
  134544. static long _vq_quantlist__44u4__p7_0[] = {
  134545. 6,
  134546. 5,
  134547. 7,
  134548. 4,
  134549. 8,
  134550. 3,
  134551. 9,
  134552. 2,
  134553. 10,
  134554. 1,
  134555. 11,
  134556. 0,
  134557. 12,
  134558. };
  134559. static long _vq_lengthlist__44u4__p7_0[] = {
  134560. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134561. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134562. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134563. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134564. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134565. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134566. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134567. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134568. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134569. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134570. 11,11,11,11,11,11,11,11,11,
  134571. };
  134572. static float _vq_quantthresh__44u4__p7_0[] = {
  134573. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134574. 637.5, 892.5, 1147.5, 1402.5,
  134575. };
  134576. static long _vq_quantmap__44u4__p7_0[] = {
  134577. 11, 9, 7, 5, 3, 1, 0, 2,
  134578. 4, 6, 8, 10, 12,
  134579. };
  134580. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134581. _vq_quantthresh__44u4__p7_0,
  134582. _vq_quantmap__44u4__p7_0,
  134583. 13,
  134584. 13
  134585. };
  134586. static static_codebook _44u4__p7_0 = {
  134587. 2, 169,
  134588. _vq_lengthlist__44u4__p7_0,
  134589. 1, -514332672, 1627381760, 4, 0,
  134590. _vq_quantlist__44u4__p7_0,
  134591. NULL,
  134592. &_vq_auxt__44u4__p7_0,
  134593. NULL,
  134594. 0
  134595. };
  134596. static long _vq_quantlist__44u4__p7_1[] = {
  134597. 7,
  134598. 6,
  134599. 8,
  134600. 5,
  134601. 9,
  134602. 4,
  134603. 10,
  134604. 3,
  134605. 11,
  134606. 2,
  134607. 12,
  134608. 1,
  134609. 13,
  134610. 0,
  134611. 14,
  134612. };
  134613. static long _vq_lengthlist__44u4__p7_1[] = {
  134614. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134615. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134616. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134617. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134618. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134619. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134620. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134621. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134622. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134623. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134624. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134625. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134626. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134627. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134628. 16,
  134629. };
  134630. static float _vq_quantthresh__44u4__p7_1[] = {
  134631. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134632. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134633. };
  134634. static long _vq_quantmap__44u4__p7_1[] = {
  134635. 13, 11, 9, 7, 5, 3, 1, 0,
  134636. 2, 4, 6, 8, 10, 12, 14,
  134637. };
  134638. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134639. _vq_quantthresh__44u4__p7_1,
  134640. _vq_quantmap__44u4__p7_1,
  134641. 15,
  134642. 15
  134643. };
  134644. static static_codebook _44u4__p7_1 = {
  134645. 2, 225,
  134646. _vq_lengthlist__44u4__p7_1,
  134647. 1, -522338304, 1620115456, 4, 0,
  134648. _vq_quantlist__44u4__p7_1,
  134649. NULL,
  134650. &_vq_auxt__44u4__p7_1,
  134651. NULL,
  134652. 0
  134653. };
  134654. static long _vq_quantlist__44u4__p7_2[] = {
  134655. 8,
  134656. 7,
  134657. 9,
  134658. 6,
  134659. 10,
  134660. 5,
  134661. 11,
  134662. 4,
  134663. 12,
  134664. 3,
  134665. 13,
  134666. 2,
  134667. 14,
  134668. 1,
  134669. 15,
  134670. 0,
  134671. 16,
  134672. };
  134673. static long _vq_lengthlist__44u4__p7_2[] = {
  134674. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134675. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134676. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134677. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134678. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134679. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134680. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134681. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134682. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134683. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134684. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134685. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134686. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134687. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134688. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134689. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134690. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134691. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134692. 10,
  134693. };
  134694. static float _vq_quantthresh__44u4__p7_2[] = {
  134695. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134696. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134697. };
  134698. static long _vq_quantmap__44u4__p7_2[] = {
  134699. 15, 13, 11, 9, 7, 5, 3, 1,
  134700. 0, 2, 4, 6, 8, 10, 12, 14,
  134701. 16,
  134702. };
  134703. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134704. _vq_quantthresh__44u4__p7_2,
  134705. _vq_quantmap__44u4__p7_2,
  134706. 17,
  134707. 17
  134708. };
  134709. static static_codebook _44u4__p7_2 = {
  134710. 2, 289,
  134711. _vq_lengthlist__44u4__p7_2,
  134712. 1, -529530880, 1611661312, 5, 0,
  134713. _vq_quantlist__44u4__p7_2,
  134714. NULL,
  134715. &_vq_auxt__44u4__p7_2,
  134716. NULL,
  134717. 0
  134718. };
  134719. static long _huff_lengthlist__44u4__short[] = {
  134720. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134721. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134722. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134723. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134724. };
  134725. static static_codebook _huff_book__44u4__short = {
  134726. 2, 64,
  134727. _huff_lengthlist__44u4__short,
  134728. 0, 0, 0, 0, 0,
  134729. NULL,
  134730. NULL,
  134731. NULL,
  134732. NULL,
  134733. 0
  134734. };
  134735. static long _huff_lengthlist__44u5__long[] = {
  134736. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134737. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134738. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134739. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134740. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134741. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134742. 14, 8, 7, 8,
  134743. };
  134744. static static_codebook _huff_book__44u5__long = {
  134745. 2, 100,
  134746. _huff_lengthlist__44u5__long,
  134747. 0, 0, 0, 0, 0,
  134748. NULL,
  134749. NULL,
  134750. NULL,
  134751. NULL,
  134752. 0
  134753. };
  134754. static long _vq_quantlist__44u5__p1_0[] = {
  134755. 1,
  134756. 0,
  134757. 2,
  134758. };
  134759. static long _vq_lengthlist__44u5__p1_0[] = {
  134760. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134761. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134762. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134763. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134764. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134765. 12,
  134766. };
  134767. static float _vq_quantthresh__44u5__p1_0[] = {
  134768. -0.5, 0.5,
  134769. };
  134770. static long _vq_quantmap__44u5__p1_0[] = {
  134771. 1, 0, 2,
  134772. };
  134773. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134774. _vq_quantthresh__44u5__p1_0,
  134775. _vq_quantmap__44u5__p1_0,
  134776. 3,
  134777. 3
  134778. };
  134779. static static_codebook _44u5__p1_0 = {
  134780. 4, 81,
  134781. _vq_lengthlist__44u5__p1_0,
  134782. 1, -535822336, 1611661312, 2, 0,
  134783. _vq_quantlist__44u5__p1_0,
  134784. NULL,
  134785. &_vq_auxt__44u5__p1_0,
  134786. NULL,
  134787. 0
  134788. };
  134789. static long _vq_quantlist__44u5__p2_0[] = {
  134790. 1,
  134791. 0,
  134792. 2,
  134793. };
  134794. static long _vq_lengthlist__44u5__p2_0[] = {
  134795. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134796. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134797. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134798. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134799. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134800. 9,
  134801. };
  134802. static float _vq_quantthresh__44u5__p2_0[] = {
  134803. -0.5, 0.5,
  134804. };
  134805. static long _vq_quantmap__44u5__p2_0[] = {
  134806. 1, 0, 2,
  134807. };
  134808. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134809. _vq_quantthresh__44u5__p2_0,
  134810. _vq_quantmap__44u5__p2_0,
  134811. 3,
  134812. 3
  134813. };
  134814. static static_codebook _44u5__p2_0 = {
  134815. 4, 81,
  134816. _vq_lengthlist__44u5__p2_0,
  134817. 1, -535822336, 1611661312, 2, 0,
  134818. _vq_quantlist__44u5__p2_0,
  134819. NULL,
  134820. &_vq_auxt__44u5__p2_0,
  134821. NULL,
  134822. 0
  134823. };
  134824. static long _vq_quantlist__44u5__p3_0[] = {
  134825. 2,
  134826. 1,
  134827. 3,
  134828. 0,
  134829. 4,
  134830. };
  134831. static long _vq_lengthlist__44u5__p3_0[] = {
  134832. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134833. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134834. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134835. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134836. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134837. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134838. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134839. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134840. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134841. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134842. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134843. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134844. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134845. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134846. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134847. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134848. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134849. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134850. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134851. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134852. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134853. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134854. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134855. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134856. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134857. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134858. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134859. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134860. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134861. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134862. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134863. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134864. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134865. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134866. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134867. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134868. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134869. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134870. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134871. 0,
  134872. };
  134873. static float _vq_quantthresh__44u5__p3_0[] = {
  134874. -1.5, -0.5, 0.5, 1.5,
  134875. };
  134876. static long _vq_quantmap__44u5__p3_0[] = {
  134877. 3, 1, 0, 2, 4,
  134878. };
  134879. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134880. _vq_quantthresh__44u5__p3_0,
  134881. _vq_quantmap__44u5__p3_0,
  134882. 5,
  134883. 5
  134884. };
  134885. static static_codebook _44u5__p3_0 = {
  134886. 4, 625,
  134887. _vq_lengthlist__44u5__p3_0,
  134888. 1, -533725184, 1611661312, 3, 0,
  134889. _vq_quantlist__44u5__p3_0,
  134890. NULL,
  134891. &_vq_auxt__44u5__p3_0,
  134892. NULL,
  134893. 0
  134894. };
  134895. static long _vq_quantlist__44u5__p4_0[] = {
  134896. 2,
  134897. 1,
  134898. 3,
  134899. 0,
  134900. 4,
  134901. };
  134902. static long _vq_lengthlist__44u5__p4_0[] = {
  134903. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134904. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134905. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134906. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134907. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134908. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134909. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134910. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134911. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134912. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134913. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134914. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134915. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134916. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134917. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134918. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134919. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134920. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134921. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134922. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134923. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134924. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134925. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134926. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134927. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134928. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134929. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134930. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134931. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134932. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134933. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134934. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134935. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134936. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134937. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134938. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134939. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134940. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134941. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134942. 12,
  134943. };
  134944. static float _vq_quantthresh__44u5__p4_0[] = {
  134945. -1.5, -0.5, 0.5, 1.5,
  134946. };
  134947. static long _vq_quantmap__44u5__p4_0[] = {
  134948. 3, 1, 0, 2, 4,
  134949. };
  134950. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134951. _vq_quantthresh__44u5__p4_0,
  134952. _vq_quantmap__44u5__p4_0,
  134953. 5,
  134954. 5
  134955. };
  134956. static static_codebook _44u5__p4_0 = {
  134957. 4, 625,
  134958. _vq_lengthlist__44u5__p4_0,
  134959. 1, -533725184, 1611661312, 3, 0,
  134960. _vq_quantlist__44u5__p4_0,
  134961. NULL,
  134962. &_vq_auxt__44u5__p4_0,
  134963. NULL,
  134964. 0
  134965. };
  134966. static long _vq_quantlist__44u5__p5_0[] = {
  134967. 4,
  134968. 3,
  134969. 5,
  134970. 2,
  134971. 6,
  134972. 1,
  134973. 7,
  134974. 0,
  134975. 8,
  134976. };
  134977. static long _vq_lengthlist__44u5__p5_0[] = {
  134978. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134979. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134980. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134981. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134982. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134983. 14,
  134984. };
  134985. static float _vq_quantthresh__44u5__p5_0[] = {
  134986. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134987. };
  134988. static long _vq_quantmap__44u5__p5_0[] = {
  134989. 7, 5, 3, 1, 0, 2, 4, 6,
  134990. 8,
  134991. };
  134992. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134993. _vq_quantthresh__44u5__p5_0,
  134994. _vq_quantmap__44u5__p5_0,
  134995. 9,
  134996. 9
  134997. };
  134998. static static_codebook _44u5__p5_0 = {
  134999. 2, 81,
  135000. _vq_lengthlist__44u5__p5_0,
  135001. 1, -531628032, 1611661312, 4, 0,
  135002. _vq_quantlist__44u5__p5_0,
  135003. NULL,
  135004. &_vq_auxt__44u5__p5_0,
  135005. NULL,
  135006. 0
  135007. };
  135008. static long _vq_quantlist__44u5__p6_0[] = {
  135009. 4,
  135010. 3,
  135011. 5,
  135012. 2,
  135013. 6,
  135014. 1,
  135015. 7,
  135016. 0,
  135017. 8,
  135018. };
  135019. static long _vq_lengthlist__44u5__p6_0[] = {
  135020. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135021. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  135022. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  135023. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  135024. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  135025. 11,
  135026. };
  135027. static float _vq_quantthresh__44u5__p6_0[] = {
  135028. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135029. };
  135030. static long _vq_quantmap__44u5__p6_0[] = {
  135031. 7, 5, 3, 1, 0, 2, 4, 6,
  135032. 8,
  135033. };
  135034. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  135035. _vq_quantthresh__44u5__p6_0,
  135036. _vq_quantmap__44u5__p6_0,
  135037. 9,
  135038. 9
  135039. };
  135040. static static_codebook _44u5__p6_0 = {
  135041. 2, 81,
  135042. _vq_lengthlist__44u5__p6_0,
  135043. 1, -531628032, 1611661312, 4, 0,
  135044. _vq_quantlist__44u5__p6_0,
  135045. NULL,
  135046. &_vq_auxt__44u5__p6_0,
  135047. NULL,
  135048. 0
  135049. };
  135050. static long _vq_quantlist__44u5__p7_0[] = {
  135051. 1,
  135052. 0,
  135053. 2,
  135054. };
  135055. static long _vq_lengthlist__44u5__p7_0[] = {
  135056. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  135057. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  135058. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  135059. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  135060. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  135061. 12,
  135062. };
  135063. static float _vq_quantthresh__44u5__p7_0[] = {
  135064. -5.5, 5.5,
  135065. };
  135066. static long _vq_quantmap__44u5__p7_0[] = {
  135067. 1, 0, 2,
  135068. };
  135069. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  135070. _vq_quantthresh__44u5__p7_0,
  135071. _vq_quantmap__44u5__p7_0,
  135072. 3,
  135073. 3
  135074. };
  135075. static static_codebook _44u5__p7_0 = {
  135076. 4, 81,
  135077. _vq_lengthlist__44u5__p7_0,
  135078. 1, -529137664, 1618345984, 2, 0,
  135079. _vq_quantlist__44u5__p7_0,
  135080. NULL,
  135081. &_vq_auxt__44u5__p7_0,
  135082. NULL,
  135083. 0
  135084. };
  135085. static long _vq_quantlist__44u5__p7_1[] = {
  135086. 5,
  135087. 4,
  135088. 6,
  135089. 3,
  135090. 7,
  135091. 2,
  135092. 8,
  135093. 1,
  135094. 9,
  135095. 0,
  135096. 10,
  135097. };
  135098. static long _vq_lengthlist__44u5__p7_1[] = {
  135099. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  135100. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  135101. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  135102. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  135103. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  135104. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135105. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  135106. 9, 9, 9, 9, 9,10,10,10,10,
  135107. };
  135108. static float _vq_quantthresh__44u5__p7_1[] = {
  135109. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135110. 3.5, 4.5,
  135111. };
  135112. static long _vq_quantmap__44u5__p7_1[] = {
  135113. 9, 7, 5, 3, 1, 0, 2, 4,
  135114. 6, 8, 10,
  135115. };
  135116. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  135117. _vq_quantthresh__44u5__p7_1,
  135118. _vq_quantmap__44u5__p7_1,
  135119. 11,
  135120. 11
  135121. };
  135122. static static_codebook _44u5__p7_1 = {
  135123. 2, 121,
  135124. _vq_lengthlist__44u5__p7_1,
  135125. 1, -531365888, 1611661312, 4, 0,
  135126. _vq_quantlist__44u5__p7_1,
  135127. NULL,
  135128. &_vq_auxt__44u5__p7_1,
  135129. NULL,
  135130. 0
  135131. };
  135132. static long _vq_quantlist__44u5__p8_0[] = {
  135133. 5,
  135134. 4,
  135135. 6,
  135136. 3,
  135137. 7,
  135138. 2,
  135139. 8,
  135140. 1,
  135141. 9,
  135142. 0,
  135143. 10,
  135144. };
  135145. static long _vq_lengthlist__44u5__p8_0[] = {
  135146. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135147. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135148. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  135149. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  135150. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  135151. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  135152. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  135153. 12,13,13,14,14,14,14,15,15,
  135154. };
  135155. static float _vq_quantthresh__44u5__p8_0[] = {
  135156. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135157. 38.5, 49.5,
  135158. };
  135159. static long _vq_quantmap__44u5__p8_0[] = {
  135160. 9, 7, 5, 3, 1, 0, 2, 4,
  135161. 6, 8, 10,
  135162. };
  135163. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  135164. _vq_quantthresh__44u5__p8_0,
  135165. _vq_quantmap__44u5__p8_0,
  135166. 11,
  135167. 11
  135168. };
  135169. static static_codebook _44u5__p8_0 = {
  135170. 2, 121,
  135171. _vq_lengthlist__44u5__p8_0,
  135172. 1, -524582912, 1618345984, 4, 0,
  135173. _vq_quantlist__44u5__p8_0,
  135174. NULL,
  135175. &_vq_auxt__44u5__p8_0,
  135176. NULL,
  135177. 0
  135178. };
  135179. static long _vq_quantlist__44u5__p8_1[] = {
  135180. 5,
  135181. 4,
  135182. 6,
  135183. 3,
  135184. 7,
  135185. 2,
  135186. 8,
  135187. 1,
  135188. 9,
  135189. 0,
  135190. 10,
  135191. };
  135192. static long _vq_lengthlist__44u5__p8_1[] = {
  135193. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  135194. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  135195. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  135196. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135197. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  135198. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135199. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135200. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135201. };
  135202. static float _vq_quantthresh__44u5__p8_1[] = {
  135203. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135204. 3.5, 4.5,
  135205. };
  135206. static long _vq_quantmap__44u5__p8_1[] = {
  135207. 9, 7, 5, 3, 1, 0, 2, 4,
  135208. 6, 8, 10,
  135209. };
  135210. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  135211. _vq_quantthresh__44u5__p8_1,
  135212. _vq_quantmap__44u5__p8_1,
  135213. 11,
  135214. 11
  135215. };
  135216. static static_codebook _44u5__p8_1 = {
  135217. 2, 121,
  135218. _vq_lengthlist__44u5__p8_1,
  135219. 1, -531365888, 1611661312, 4, 0,
  135220. _vq_quantlist__44u5__p8_1,
  135221. NULL,
  135222. &_vq_auxt__44u5__p8_1,
  135223. NULL,
  135224. 0
  135225. };
  135226. static long _vq_quantlist__44u5__p9_0[] = {
  135227. 6,
  135228. 5,
  135229. 7,
  135230. 4,
  135231. 8,
  135232. 3,
  135233. 9,
  135234. 2,
  135235. 10,
  135236. 1,
  135237. 11,
  135238. 0,
  135239. 12,
  135240. };
  135241. static long _vq_lengthlist__44u5__p9_0[] = {
  135242. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  135243. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  135244. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  135245. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  135246. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135247. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135248. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135249. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135250. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  135251. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  135252. 12,12,12,12,12,12,12,12,12,
  135253. };
  135254. static float _vq_quantthresh__44u5__p9_0[] = {
  135255. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  135256. 637.5, 892.5, 1147.5, 1402.5,
  135257. };
  135258. static long _vq_quantmap__44u5__p9_0[] = {
  135259. 11, 9, 7, 5, 3, 1, 0, 2,
  135260. 4, 6, 8, 10, 12,
  135261. };
  135262. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  135263. _vq_quantthresh__44u5__p9_0,
  135264. _vq_quantmap__44u5__p9_0,
  135265. 13,
  135266. 13
  135267. };
  135268. static static_codebook _44u5__p9_0 = {
  135269. 2, 169,
  135270. _vq_lengthlist__44u5__p9_0,
  135271. 1, -514332672, 1627381760, 4, 0,
  135272. _vq_quantlist__44u5__p9_0,
  135273. NULL,
  135274. &_vq_auxt__44u5__p9_0,
  135275. NULL,
  135276. 0
  135277. };
  135278. static long _vq_quantlist__44u5__p9_1[] = {
  135279. 7,
  135280. 6,
  135281. 8,
  135282. 5,
  135283. 9,
  135284. 4,
  135285. 10,
  135286. 3,
  135287. 11,
  135288. 2,
  135289. 12,
  135290. 1,
  135291. 13,
  135292. 0,
  135293. 14,
  135294. };
  135295. static long _vq_lengthlist__44u5__p9_1[] = {
  135296. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  135297. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  135298. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  135299. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  135300. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  135301. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  135302. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  135303. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  135304. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  135305. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  135306. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  135307. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  135308. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  135309. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  135310. 14,
  135311. };
  135312. static float _vq_quantthresh__44u5__p9_1[] = {
  135313. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135314. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135315. };
  135316. static long _vq_quantmap__44u5__p9_1[] = {
  135317. 13, 11, 9, 7, 5, 3, 1, 0,
  135318. 2, 4, 6, 8, 10, 12, 14,
  135319. };
  135320. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  135321. _vq_quantthresh__44u5__p9_1,
  135322. _vq_quantmap__44u5__p9_1,
  135323. 15,
  135324. 15
  135325. };
  135326. static static_codebook _44u5__p9_1 = {
  135327. 2, 225,
  135328. _vq_lengthlist__44u5__p9_1,
  135329. 1, -522338304, 1620115456, 4, 0,
  135330. _vq_quantlist__44u5__p9_1,
  135331. NULL,
  135332. &_vq_auxt__44u5__p9_1,
  135333. NULL,
  135334. 0
  135335. };
  135336. static long _vq_quantlist__44u5__p9_2[] = {
  135337. 8,
  135338. 7,
  135339. 9,
  135340. 6,
  135341. 10,
  135342. 5,
  135343. 11,
  135344. 4,
  135345. 12,
  135346. 3,
  135347. 13,
  135348. 2,
  135349. 14,
  135350. 1,
  135351. 15,
  135352. 0,
  135353. 16,
  135354. };
  135355. static long _vq_lengthlist__44u5__p9_2[] = {
  135356. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135357. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135358. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135359. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135360. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135361. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  135362. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135363. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  135364. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135365. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  135366. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  135367. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  135368. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  135369. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  135370. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  135371. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  135372. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  135373. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  135374. 10,
  135375. };
  135376. static float _vq_quantthresh__44u5__p9_2[] = {
  135377. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135378. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135379. };
  135380. static long _vq_quantmap__44u5__p9_2[] = {
  135381. 15, 13, 11, 9, 7, 5, 3, 1,
  135382. 0, 2, 4, 6, 8, 10, 12, 14,
  135383. 16,
  135384. };
  135385. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  135386. _vq_quantthresh__44u5__p9_2,
  135387. _vq_quantmap__44u5__p9_2,
  135388. 17,
  135389. 17
  135390. };
  135391. static static_codebook _44u5__p9_2 = {
  135392. 2, 289,
  135393. _vq_lengthlist__44u5__p9_2,
  135394. 1, -529530880, 1611661312, 5, 0,
  135395. _vq_quantlist__44u5__p9_2,
  135396. NULL,
  135397. &_vq_auxt__44u5__p9_2,
  135398. NULL,
  135399. 0
  135400. };
  135401. static long _huff_lengthlist__44u5__short[] = {
  135402. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  135403. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  135404. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  135405. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  135406. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  135407. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  135408. 6, 8,15,17,
  135409. };
  135410. static static_codebook _huff_book__44u5__short = {
  135411. 2, 100,
  135412. _huff_lengthlist__44u5__short,
  135413. 0, 0, 0, 0, 0,
  135414. NULL,
  135415. NULL,
  135416. NULL,
  135417. NULL,
  135418. 0
  135419. };
  135420. static long _huff_lengthlist__44u6__long[] = {
  135421. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  135422. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  135423. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  135424. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  135425. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  135426. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  135427. 13, 8, 7, 7,
  135428. };
  135429. static static_codebook _huff_book__44u6__long = {
  135430. 2, 100,
  135431. _huff_lengthlist__44u6__long,
  135432. 0, 0, 0, 0, 0,
  135433. NULL,
  135434. NULL,
  135435. NULL,
  135436. NULL,
  135437. 0
  135438. };
  135439. static long _vq_quantlist__44u6__p1_0[] = {
  135440. 1,
  135441. 0,
  135442. 2,
  135443. };
  135444. static long _vq_lengthlist__44u6__p1_0[] = {
  135445. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135446. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  135447. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135448. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  135449. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  135450. 12,
  135451. };
  135452. static float _vq_quantthresh__44u6__p1_0[] = {
  135453. -0.5, 0.5,
  135454. };
  135455. static long _vq_quantmap__44u6__p1_0[] = {
  135456. 1, 0, 2,
  135457. };
  135458. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  135459. _vq_quantthresh__44u6__p1_0,
  135460. _vq_quantmap__44u6__p1_0,
  135461. 3,
  135462. 3
  135463. };
  135464. static static_codebook _44u6__p1_0 = {
  135465. 4, 81,
  135466. _vq_lengthlist__44u6__p1_0,
  135467. 1, -535822336, 1611661312, 2, 0,
  135468. _vq_quantlist__44u6__p1_0,
  135469. NULL,
  135470. &_vq_auxt__44u6__p1_0,
  135471. NULL,
  135472. 0
  135473. };
  135474. static long _vq_quantlist__44u6__p2_0[] = {
  135475. 1,
  135476. 0,
  135477. 2,
  135478. };
  135479. static long _vq_lengthlist__44u6__p2_0[] = {
  135480. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135481. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135482. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  135483. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135484. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135485. 9,
  135486. };
  135487. static float _vq_quantthresh__44u6__p2_0[] = {
  135488. -0.5, 0.5,
  135489. };
  135490. static long _vq_quantmap__44u6__p2_0[] = {
  135491. 1, 0, 2,
  135492. };
  135493. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  135494. _vq_quantthresh__44u6__p2_0,
  135495. _vq_quantmap__44u6__p2_0,
  135496. 3,
  135497. 3
  135498. };
  135499. static static_codebook _44u6__p2_0 = {
  135500. 4, 81,
  135501. _vq_lengthlist__44u6__p2_0,
  135502. 1, -535822336, 1611661312, 2, 0,
  135503. _vq_quantlist__44u6__p2_0,
  135504. NULL,
  135505. &_vq_auxt__44u6__p2_0,
  135506. NULL,
  135507. 0
  135508. };
  135509. static long _vq_quantlist__44u6__p3_0[] = {
  135510. 2,
  135511. 1,
  135512. 3,
  135513. 0,
  135514. 4,
  135515. };
  135516. static long _vq_lengthlist__44u6__p3_0[] = {
  135517. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135518. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135519. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135520. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  135521. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  135522. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  135523. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  135524. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  135525. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135526. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135527. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135528. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135529. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135530. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135531. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135532. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135533. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135534. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135535. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135536. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135537. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135538. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135539. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135540. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135541. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135542. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135543. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135544. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135545. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135546. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135547. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135548. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135549. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135550. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135551. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135552. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135553. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135554. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135555. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135556. 19,
  135557. };
  135558. static float _vq_quantthresh__44u6__p3_0[] = {
  135559. -1.5, -0.5, 0.5, 1.5,
  135560. };
  135561. static long _vq_quantmap__44u6__p3_0[] = {
  135562. 3, 1, 0, 2, 4,
  135563. };
  135564. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135565. _vq_quantthresh__44u6__p3_0,
  135566. _vq_quantmap__44u6__p3_0,
  135567. 5,
  135568. 5
  135569. };
  135570. static static_codebook _44u6__p3_0 = {
  135571. 4, 625,
  135572. _vq_lengthlist__44u6__p3_0,
  135573. 1, -533725184, 1611661312, 3, 0,
  135574. _vq_quantlist__44u6__p3_0,
  135575. NULL,
  135576. &_vq_auxt__44u6__p3_0,
  135577. NULL,
  135578. 0
  135579. };
  135580. static long _vq_quantlist__44u6__p4_0[] = {
  135581. 2,
  135582. 1,
  135583. 3,
  135584. 0,
  135585. 4,
  135586. };
  135587. static long _vq_lengthlist__44u6__p4_0[] = {
  135588. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135589. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135590. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135591. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135592. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135593. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135594. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135595. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135596. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135597. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135598. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135599. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135600. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135601. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135602. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135603. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135604. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135605. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135606. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135607. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135608. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135609. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135610. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135611. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135612. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135613. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135614. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135615. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135616. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135617. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135618. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135619. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135620. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135621. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135622. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135623. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135624. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135625. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135626. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135627. 13,
  135628. };
  135629. static float _vq_quantthresh__44u6__p4_0[] = {
  135630. -1.5, -0.5, 0.5, 1.5,
  135631. };
  135632. static long _vq_quantmap__44u6__p4_0[] = {
  135633. 3, 1, 0, 2, 4,
  135634. };
  135635. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135636. _vq_quantthresh__44u6__p4_0,
  135637. _vq_quantmap__44u6__p4_0,
  135638. 5,
  135639. 5
  135640. };
  135641. static static_codebook _44u6__p4_0 = {
  135642. 4, 625,
  135643. _vq_lengthlist__44u6__p4_0,
  135644. 1, -533725184, 1611661312, 3, 0,
  135645. _vq_quantlist__44u6__p4_0,
  135646. NULL,
  135647. &_vq_auxt__44u6__p4_0,
  135648. NULL,
  135649. 0
  135650. };
  135651. static long _vq_quantlist__44u6__p5_0[] = {
  135652. 4,
  135653. 3,
  135654. 5,
  135655. 2,
  135656. 6,
  135657. 1,
  135658. 7,
  135659. 0,
  135660. 8,
  135661. };
  135662. static long _vq_lengthlist__44u6__p5_0[] = {
  135663. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135664. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135665. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135666. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135667. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135668. 14,
  135669. };
  135670. static float _vq_quantthresh__44u6__p5_0[] = {
  135671. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135672. };
  135673. static long _vq_quantmap__44u6__p5_0[] = {
  135674. 7, 5, 3, 1, 0, 2, 4, 6,
  135675. 8,
  135676. };
  135677. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135678. _vq_quantthresh__44u6__p5_0,
  135679. _vq_quantmap__44u6__p5_0,
  135680. 9,
  135681. 9
  135682. };
  135683. static static_codebook _44u6__p5_0 = {
  135684. 2, 81,
  135685. _vq_lengthlist__44u6__p5_0,
  135686. 1, -531628032, 1611661312, 4, 0,
  135687. _vq_quantlist__44u6__p5_0,
  135688. NULL,
  135689. &_vq_auxt__44u6__p5_0,
  135690. NULL,
  135691. 0
  135692. };
  135693. static long _vq_quantlist__44u6__p6_0[] = {
  135694. 4,
  135695. 3,
  135696. 5,
  135697. 2,
  135698. 6,
  135699. 1,
  135700. 7,
  135701. 0,
  135702. 8,
  135703. };
  135704. static long _vq_lengthlist__44u6__p6_0[] = {
  135705. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135706. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135707. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135708. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135709. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135710. 12,
  135711. };
  135712. static float _vq_quantthresh__44u6__p6_0[] = {
  135713. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135714. };
  135715. static long _vq_quantmap__44u6__p6_0[] = {
  135716. 7, 5, 3, 1, 0, 2, 4, 6,
  135717. 8,
  135718. };
  135719. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135720. _vq_quantthresh__44u6__p6_0,
  135721. _vq_quantmap__44u6__p6_0,
  135722. 9,
  135723. 9
  135724. };
  135725. static static_codebook _44u6__p6_0 = {
  135726. 2, 81,
  135727. _vq_lengthlist__44u6__p6_0,
  135728. 1, -531628032, 1611661312, 4, 0,
  135729. _vq_quantlist__44u6__p6_0,
  135730. NULL,
  135731. &_vq_auxt__44u6__p6_0,
  135732. NULL,
  135733. 0
  135734. };
  135735. static long _vq_quantlist__44u6__p7_0[] = {
  135736. 1,
  135737. 0,
  135738. 2,
  135739. };
  135740. static long _vq_lengthlist__44u6__p7_0[] = {
  135741. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135742. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135743. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135744. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135745. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135746. 10,
  135747. };
  135748. static float _vq_quantthresh__44u6__p7_0[] = {
  135749. -5.5, 5.5,
  135750. };
  135751. static long _vq_quantmap__44u6__p7_0[] = {
  135752. 1, 0, 2,
  135753. };
  135754. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135755. _vq_quantthresh__44u6__p7_0,
  135756. _vq_quantmap__44u6__p7_0,
  135757. 3,
  135758. 3
  135759. };
  135760. static static_codebook _44u6__p7_0 = {
  135761. 4, 81,
  135762. _vq_lengthlist__44u6__p7_0,
  135763. 1, -529137664, 1618345984, 2, 0,
  135764. _vq_quantlist__44u6__p7_0,
  135765. NULL,
  135766. &_vq_auxt__44u6__p7_0,
  135767. NULL,
  135768. 0
  135769. };
  135770. static long _vq_quantlist__44u6__p7_1[] = {
  135771. 5,
  135772. 4,
  135773. 6,
  135774. 3,
  135775. 7,
  135776. 2,
  135777. 8,
  135778. 1,
  135779. 9,
  135780. 0,
  135781. 10,
  135782. };
  135783. static long _vq_lengthlist__44u6__p7_1[] = {
  135784. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135785. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135786. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135787. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135788. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135789. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135790. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135791. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135792. };
  135793. static float _vq_quantthresh__44u6__p7_1[] = {
  135794. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135795. 3.5, 4.5,
  135796. };
  135797. static long _vq_quantmap__44u6__p7_1[] = {
  135798. 9, 7, 5, 3, 1, 0, 2, 4,
  135799. 6, 8, 10,
  135800. };
  135801. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135802. _vq_quantthresh__44u6__p7_1,
  135803. _vq_quantmap__44u6__p7_1,
  135804. 11,
  135805. 11
  135806. };
  135807. static static_codebook _44u6__p7_1 = {
  135808. 2, 121,
  135809. _vq_lengthlist__44u6__p7_1,
  135810. 1, -531365888, 1611661312, 4, 0,
  135811. _vq_quantlist__44u6__p7_1,
  135812. NULL,
  135813. &_vq_auxt__44u6__p7_1,
  135814. NULL,
  135815. 0
  135816. };
  135817. static long _vq_quantlist__44u6__p8_0[] = {
  135818. 5,
  135819. 4,
  135820. 6,
  135821. 3,
  135822. 7,
  135823. 2,
  135824. 8,
  135825. 1,
  135826. 9,
  135827. 0,
  135828. 10,
  135829. };
  135830. static long _vq_lengthlist__44u6__p8_0[] = {
  135831. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135832. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135833. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135834. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135835. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135836. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135837. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135838. 12,13,13,14,14,14,15,15,15,
  135839. };
  135840. static float _vq_quantthresh__44u6__p8_0[] = {
  135841. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135842. 38.5, 49.5,
  135843. };
  135844. static long _vq_quantmap__44u6__p8_0[] = {
  135845. 9, 7, 5, 3, 1, 0, 2, 4,
  135846. 6, 8, 10,
  135847. };
  135848. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135849. _vq_quantthresh__44u6__p8_0,
  135850. _vq_quantmap__44u6__p8_0,
  135851. 11,
  135852. 11
  135853. };
  135854. static static_codebook _44u6__p8_0 = {
  135855. 2, 121,
  135856. _vq_lengthlist__44u6__p8_0,
  135857. 1, -524582912, 1618345984, 4, 0,
  135858. _vq_quantlist__44u6__p8_0,
  135859. NULL,
  135860. &_vq_auxt__44u6__p8_0,
  135861. NULL,
  135862. 0
  135863. };
  135864. static long _vq_quantlist__44u6__p8_1[] = {
  135865. 5,
  135866. 4,
  135867. 6,
  135868. 3,
  135869. 7,
  135870. 2,
  135871. 8,
  135872. 1,
  135873. 9,
  135874. 0,
  135875. 10,
  135876. };
  135877. static long _vq_lengthlist__44u6__p8_1[] = {
  135878. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135879. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135880. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135881. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135882. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135883. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135884. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135885. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135886. };
  135887. static float _vq_quantthresh__44u6__p8_1[] = {
  135888. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135889. 3.5, 4.5,
  135890. };
  135891. static long _vq_quantmap__44u6__p8_1[] = {
  135892. 9, 7, 5, 3, 1, 0, 2, 4,
  135893. 6, 8, 10,
  135894. };
  135895. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135896. _vq_quantthresh__44u6__p8_1,
  135897. _vq_quantmap__44u6__p8_1,
  135898. 11,
  135899. 11
  135900. };
  135901. static static_codebook _44u6__p8_1 = {
  135902. 2, 121,
  135903. _vq_lengthlist__44u6__p8_1,
  135904. 1, -531365888, 1611661312, 4, 0,
  135905. _vq_quantlist__44u6__p8_1,
  135906. NULL,
  135907. &_vq_auxt__44u6__p8_1,
  135908. NULL,
  135909. 0
  135910. };
  135911. static long _vq_quantlist__44u6__p9_0[] = {
  135912. 7,
  135913. 6,
  135914. 8,
  135915. 5,
  135916. 9,
  135917. 4,
  135918. 10,
  135919. 3,
  135920. 11,
  135921. 2,
  135922. 12,
  135923. 1,
  135924. 13,
  135925. 0,
  135926. 14,
  135927. };
  135928. static long _vq_lengthlist__44u6__p9_0[] = {
  135929. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135930. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135931. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135932. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135933. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135934. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135935. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135936. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135937. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135938. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135939. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135940. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135941. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135942. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135943. 14,
  135944. };
  135945. static float _vq_quantthresh__44u6__p9_0[] = {
  135946. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135947. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135948. };
  135949. static long _vq_quantmap__44u6__p9_0[] = {
  135950. 13, 11, 9, 7, 5, 3, 1, 0,
  135951. 2, 4, 6, 8, 10, 12, 14,
  135952. };
  135953. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135954. _vq_quantthresh__44u6__p9_0,
  135955. _vq_quantmap__44u6__p9_0,
  135956. 15,
  135957. 15
  135958. };
  135959. static static_codebook _44u6__p9_0 = {
  135960. 2, 225,
  135961. _vq_lengthlist__44u6__p9_0,
  135962. 1, -514071552, 1627381760, 4, 0,
  135963. _vq_quantlist__44u6__p9_0,
  135964. NULL,
  135965. &_vq_auxt__44u6__p9_0,
  135966. NULL,
  135967. 0
  135968. };
  135969. static long _vq_quantlist__44u6__p9_1[] = {
  135970. 7,
  135971. 6,
  135972. 8,
  135973. 5,
  135974. 9,
  135975. 4,
  135976. 10,
  135977. 3,
  135978. 11,
  135979. 2,
  135980. 12,
  135981. 1,
  135982. 13,
  135983. 0,
  135984. 14,
  135985. };
  135986. static long _vq_lengthlist__44u6__p9_1[] = {
  135987. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135988. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135989. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135990. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135991. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135992. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135993. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135994. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135995. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135996. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135997. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135998. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135999. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  136000. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  136001. 13,
  136002. };
  136003. static float _vq_quantthresh__44u6__p9_1[] = {
  136004. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  136005. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  136006. };
  136007. static long _vq_quantmap__44u6__p9_1[] = {
  136008. 13, 11, 9, 7, 5, 3, 1, 0,
  136009. 2, 4, 6, 8, 10, 12, 14,
  136010. };
  136011. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  136012. _vq_quantthresh__44u6__p9_1,
  136013. _vq_quantmap__44u6__p9_1,
  136014. 15,
  136015. 15
  136016. };
  136017. static static_codebook _44u6__p9_1 = {
  136018. 2, 225,
  136019. _vq_lengthlist__44u6__p9_1,
  136020. 1, -522338304, 1620115456, 4, 0,
  136021. _vq_quantlist__44u6__p9_1,
  136022. NULL,
  136023. &_vq_auxt__44u6__p9_1,
  136024. NULL,
  136025. 0
  136026. };
  136027. static long _vq_quantlist__44u6__p9_2[] = {
  136028. 8,
  136029. 7,
  136030. 9,
  136031. 6,
  136032. 10,
  136033. 5,
  136034. 11,
  136035. 4,
  136036. 12,
  136037. 3,
  136038. 13,
  136039. 2,
  136040. 14,
  136041. 1,
  136042. 15,
  136043. 0,
  136044. 16,
  136045. };
  136046. static long _vq_lengthlist__44u6__p9_2[] = {
  136047. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  136048. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  136049. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  136050. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136051. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136052. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136053. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136054. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136055. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136056. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  136057. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  136058. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136059. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  136060. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  136061. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  136062. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  136063. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  136064. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  136065. 10,
  136066. };
  136067. static float _vq_quantthresh__44u6__p9_2[] = {
  136068. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136069. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136070. };
  136071. static long _vq_quantmap__44u6__p9_2[] = {
  136072. 15, 13, 11, 9, 7, 5, 3, 1,
  136073. 0, 2, 4, 6, 8, 10, 12, 14,
  136074. 16,
  136075. };
  136076. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  136077. _vq_quantthresh__44u6__p9_2,
  136078. _vq_quantmap__44u6__p9_2,
  136079. 17,
  136080. 17
  136081. };
  136082. static static_codebook _44u6__p9_2 = {
  136083. 2, 289,
  136084. _vq_lengthlist__44u6__p9_2,
  136085. 1, -529530880, 1611661312, 5, 0,
  136086. _vq_quantlist__44u6__p9_2,
  136087. NULL,
  136088. &_vq_auxt__44u6__p9_2,
  136089. NULL,
  136090. 0
  136091. };
  136092. static long _huff_lengthlist__44u6__short[] = {
  136093. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  136094. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  136095. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  136096. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  136097. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  136098. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  136099. 7, 6, 9,16,
  136100. };
  136101. static static_codebook _huff_book__44u6__short = {
  136102. 2, 100,
  136103. _huff_lengthlist__44u6__short,
  136104. 0, 0, 0, 0, 0,
  136105. NULL,
  136106. NULL,
  136107. NULL,
  136108. NULL,
  136109. 0
  136110. };
  136111. static long _huff_lengthlist__44u7__long[] = {
  136112. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  136113. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  136114. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  136115. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  136116. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  136117. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  136118. 12, 8, 6, 7,
  136119. };
  136120. static static_codebook _huff_book__44u7__long = {
  136121. 2, 100,
  136122. _huff_lengthlist__44u7__long,
  136123. 0, 0, 0, 0, 0,
  136124. NULL,
  136125. NULL,
  136126. NULL,
  136127. NULL,
  136128. 0
  136129. };
  136130. static long _vq_quantlist__44u7__p1_0[] = {
  136131. 1,
  136132. 0,
  136133. 2,
  136134. };
  136135. static long _vq_lengthlist__44u7__p1_0[] = {
  136136. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  136137. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  136138. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  136139. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  136140. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  136141. 12,
  136142. };
  136143. static float _vq_quantthresh__44u7__p1_0[] = {
  136144. -0.5, 0.5,
  136145. };
  136146. static long _vq_quantmap__44u7__p1_0[] = {
  136147. 1, 0, 2,
  136148. };
  136149. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  136150. _vq_quantthresh__44u7__p1_0,
  136151. _vq_quantmap__44u7__p1_0,
  136152. 3,
  136153. 3
  136154. };
  136155. static static_codebook _44u7__p1_0 = {
  136156. 4, 81,
  136157. _vq_lengthlist__44u7__p1_0,
  136158. 1, -535822336, 1611661312, 2, 0,
  136159. _vq_quantlist__44u7__p1_0,
  136160. NULL,
  136161. &_vq_auxt__44u7__p1_0,
  136162. NULL,
  136163. 0
  136164. };
  136165. static long _vq_quantlist__44u7__p2_0[] = {
  136166. 1,
  136167. 0,
  136168. 2,
  136169. };
  136170. static long _vq_lengthlist__44u7__p2_0[] = {
  136171. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  136172. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  136173. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  136174. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  136175. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  136176. 9,
  136177. };
  136178. static float _vq_quantthresh__44u7__p2_0[] = {
  136179. -0.5, 0.5,
  136180. };
  136181. static long _vq_quantmap__44u7__p2_0[] = {
  136182. 1, 0, 2,
  136183. };
  136184. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  136185. _vq_quantthresh__44u7__p2_0,
  136186. _vq_quantmap__44u7__p2_0,
  136187. 3,
  136188. 3
  136189. };
  136190. static static_codebook _44u7__p2_0 = {
  136191. 4, 81,
  136192. _vq_lengthlist__44u7__p2_0,
  136193. 1, -535822336, 1611661312, 2, 0,
  136194. _vq_quantlist__44u7__p2_0,
  136195. NULL,
  136196. &_vq_auxt__44u7__p2_0,
  136197. NULL,
  136198. 0
  136199. };
  136200. static long _vq_quantlist__44u7__p3_0[] = {
  136201. 2,
  136202. 1,
  136203. 3,
  136204. 0,
  136205. 4,
  136206. };
  136207. static long _vq_lengthlist__44u7__p3_0[] = {
  136208. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136209. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  136210. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  136211. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  136212. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  136213. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  136214. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  136215. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  136216. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  136217. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  136218. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  136219. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  136220. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  136221. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  136222. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  136223. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  136224. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  136225. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  136226. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  136227. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  136228. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  136229. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  136230. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  136231. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  136232. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  136233. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  136234. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  136235. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  136236. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  136237. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  136238. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  136239. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  136240. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  136241. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  136242. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  136243. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  136244. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  136245. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  136246. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  136247. 0,
  136248. };
  136249. static float _vq_quantthresh__44u7__p3_0[] = {
  136250. -1.5, -0.5, 0.5, 1.5,
  136251. };
  136252. static long _vq_quantmap__44u7__p3_0[] = {
  136253. 3, 1, 0, 2, 4,
  136254. };
  136255. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  136256. _vq_quantthresh__44u7__p3_0,
  136257. _vq_quantmap__44u7__p3_0,
  136258. 5,
  136259. 5
  136260. };
  136261. static static_codebook _44u7__p3_0 = {
  136262. 4, 625,
  136263. _vq_lengthlist__44u7__p3_0,
  136264. 1, -533725184, 1611661312, 3, 0,
  136265. _vq_quantlist__44u7__p3_0,
  136266. NULL,
  136267. &_vq_auxt__44u7__p3_0,
  136268. NULL,
  136269. 0
  136270. };
  136271. static long _vq_quantlist__44u7__p4_0[] = {
  136272. 2,
  136273. 1,
  136274. 3,
  136275. 0,
  136276. 4,
  136277. };
  136278. static long _vq_lengthlist__44u7__p4_0[] = {
  136279. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  136280. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  136281. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  136282. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  136283. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  136284. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  136285. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  136286. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  136287. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  136288. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  136289. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  136290. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  136291. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  136292. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  136293. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  136294. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  136295. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  136296. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  136297. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  136298. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  136299. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  136300. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  136301. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  136302. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136303. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  136304. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  136305. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  136306. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  136307. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  136308. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  136309. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  136310. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136311. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  136312. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  136313. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  136314. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  136315. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  136316. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  136317. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  136318. 14,
  136319. };
  136320. static float _vq_quantthresh__44u7__p4_0[] = {
  136321. -1.5, -0.5, 0.5, 1.5,
  136322. };
  136323. static long _vq_quantmap__44u7__p4_0[] = {
  136324. 3, 1, 0, 2, 4,
  136325. };
  136326. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  136327. _vq_quantthresh__44u7__p4_0,
  136328. _vq_quantmap__44u7__p4_0,
  136329. 5,
  136330. 5
  136331. };
  136332. static static_codebook _44u7__p4_0 = {
  136333. 4, 625,
  136334. _vq_lengthlist__44u7__p4_0,
  136335. 1, -533725184, 1611661312, 3, 0,
  136336. _vq_quantlist__44u7__p4_0,
  136337. NULL,
  136338. &_vq_auxt__44u7__p4_0,
  136339. NULL,
  136340. 0
  136341. };
  136342. static long _vq_quantlist__44u7__p5_0[] = {
  136343. 4,
  136344. 3,
  136345. 5,
  136346. 2,
  136347. 6,
  136348. 1,
  136349. 7,
  136350. 0,
  136351. 8,
  136352. };
  136353. static long _vq_lengthlist__44u7__p5_0[] = {
  136354. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  136355. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  136356. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  136357. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  136358. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  136359. 14,
  136360. };
  136361. static float _vq_quantthresh__44u7__p5_0[] = {
  136362. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136363. };
  136364. static long _vq_quantmap__44u7__p5_0[] = {
  136365. 7, 5, 3, 1, 0, 2, 4, 6,
  136366. 8,
  136367. };
  136368. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  136369. _vq_quantthresh__44u7__p5_0,
  136370. _vq_quantmap__44u7__p5_0,
  136371. 9,
  136372. 9
  136373. };
  136374. static static_codebook _44u7__p5_0 = {
  136375. 2, 81,
  136376. _vq_lengthlist__44u7__p5_0,
  136377. 1, -531628032, 1611661312, 4, 0,
  136378. _vq_quantlist__44u7__p5_0,
  136379. NULL,
  136380. &_vq_auxt__44u7__p5_0,
  136381. NULL,
  136382. 0
  136383. };
  136384. static long _vq_quantlist__44u7__p6_0[] = {
  136385. 4,
  136386. 3,
  136387. 5,
  136388. 2,
  136389. 6,
  136390. 1,
  136391. 7,
  136392. 0,
  136393. 8,
  136394. };
  136395. static long _vq_lengthlist__44u7__p6_0[] = {
  136396. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  136397. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136398. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  136399. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  136400. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  136401. 12,
  136402. };
  136403. static float _vq_quantthresh__44u7__p6_0[] = {
  136404. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136405. };
  136406. static long _vq_quantmap__44u7__p6_0[] = {
  136407. 7, 5, 3, 1, 0, 2, 4, 6,
  136408. 8,
  136409. };
  136410. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  136411. _vq_quantthresh__44u7__p6_0,
  136412. _vq_quantmap__44u7__p6_0,
  136413. 9,
  136414. 9
  136415. };
  136416. static static_codebook _44u7__p6_0 = {
  136417. 2, 81,
  136418. _vq_lengthlist__44u7__p6_0,
  136419. 1, -531628032, 1611661312, 4, 0,
  136420. _vq_quantlist__44u7__p6_0,
  136421. NULL,
  136422. &_vq_auxt__44u7__p6_0,
  136423. NULL,
  136424. 0
  136425. };
  136426. static long _vq_quantlist__44u7__p7_0[] = {
  136427. 1,
  136428. 0,
  136429. 2,
  136430. };
  136431. static long _vq_lengthlist__44u7__p7_0[] = {
  136432. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  136433. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  136434. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  136435. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  136436. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  136437. 10,
  136438. };
  136439. static float _vq_quantthresh__44u7__p7_0[] = {
  136440. -5.5, 5.5,
  136441. };
  136442. static long _vq_quantmap__44u7__p7_0[] = {
  136443. 1, 0, 2,
  136444. };
  136445. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  136446. _vq_quantthresh__44u7__p7_0,
  136447. _vq_quantmap__44u7__p7_0,
  136448. 3,
  136449. 3
  136450. };
  136451. static static_codebook _44u7__p7_0 = {
  136452. 4, 81,
  136453. _vq_lengthlist__44u7__p7_0,
  136454. 1, -529137664, 1618345984, 2, 0,
  136455. _vq_quantlist__44u7__p7_0,
  136456. NULL,
  136457. &_vq_auxt__44u7__p7_0,
  136458. NULL,
  136459. 0
  136460. };
  136461. static long _vq_quantlist__44u7__p7_1[] = {
  136462. 5,
  136463. 4,
  136464. 6,
  136465. 3,
  136466. 7,
  136467. 2,
  136468. 8,
  136469. 1,
  136470. 9,
  136471. 0,
  136472. 10,
  136473. };
  136474. static long _vq_lengthlist__44u7__p7_1[] = {
  136475. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  136476. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  136477. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  136478. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  136479. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136480. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136481. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  136482. 8, 9, 9, 9, 9, 9,10,10,10,
  136483. };
  136484. static float _vq_quantthresh__44u7__p7_1[] = {
  136485. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136486. 3.5, 4.5,
  136487. };
  136488. static long _vq_quantmap__44u7__p7_1[] = {
  136489. 9, 7, 5, 3, 1, 0, 2, 4,
  136490. 6, 8, 10,
  136491. };
  136492. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  136493. _vq_quantthresh__44u7__p7_1,
  136494. _vq_quantmap__44u7__p7_1,
  136495. 11,
  136496. 11
  136497. };
  136498. static static_codebook _44u7__p7_1 = {
  136499. 2, 121,
  136500. _vq_lengthlist__44u7__p7_1,
  136501. 1, -531365888, 1611661312, 4, 0,
  136502. _vq_quantlist__44u7__p7_1,
  136503. NULL,
  136504. &_vq_auxt__44u7__p7_1,
  136505. NULL,
  136506. 0
  136507. };
  136508. static long _vq_quantlist__44u7__p8_0[] = {
  136509. 5,
  136510. 4,
  136511. 6,
  136512. 3,
  136513. 7,
  136514. 2,
  136515. 8,
  136516. 1,
  136517. 9,
  136518. 0,
  136519. 10,
  136520. };
  136521. static long _vq_lengthlist__44u7__p8_0[] = {
  136522. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  136523. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  136524. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  136525. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136526. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136527. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136528. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136529. 12,13,13,14,14,15,15,15,16,
  136530. };
  136531. static float _vq_quantthresh__44u7__p8_0[] = {
  136532. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136533. 38.5, 49.5,
  136534. };
  136535. static long _vq_quantmap__44u7__p8_0[] = {
  136536. 9, 7, 5, 3, 1, 0, 2, 4,
  136537. 6, 8, 10,
  136538. };
  136539. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136540. _vq_quantthresh__44u7__p8_0,
  136541. _vq_quantmap__44u7__p8_0,
  136542. 11,
  136543. 11
  136544. };
  136545. static static_codebook _44u7__p8_0 = {
  136546. 2, 121,
  136547. _vq_lengthlist__44u7__p8_0,
  136548. 1, -524582912, 1618345984, 4, 0,
  136549. _vq_quantlist__44u7__p8_0,
  136550. NULL,
  136551. &_vq_auxt__44u7__p8_0,
  136552. NULL,
  136553. 0
  136554. };
  136555. static long _vq_quantlist__44u7__p8_1[] = {
  136556. 5,
  136557. 4,
  136558. 6,
  136559. 3,
  136560. 7,
  136561. 2,
  136562. 8,
  136563. 1,
  136564. 9,
  136565. 0,
  136566. 10,
  136567. };
  136568. static long _vq_lengthlist__44u7__p8_1[] = {
  136569. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136570. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136571. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136572. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136573. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136574. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136575. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136576. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136577. };
  136578. static float _vq_quantthresh__44u7__p8_1[] = {
  136579. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136580. 3.5, 4.5,
  136581. };
  136582. static long _vq_quantmap__44u7__p8_1[] = {
  136583. 9, 7, 5, 3, 1, 0, 2, 4,
  136584. 6, 8, 10,
  136585. };
  136586. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136587. _vq_quantthresh__44u7__p8_1,
  136588. _vq_quantmap__44u7__p8_1,
  136589. 11,
  136590. 11
  136591. };
  136592. static static_codebook _44u7__p8_1 = {
  136593. 2, 121,
  136594. _vq_lengthlist__44u7__p8_1,
  136595. 1, -531365888, 1611661312, 4, 0,
  136596. _vq_quantlist__44u7__p8_1,
  136597. NULL,
  136598. &_vq_auxt__44u7__p8_1,
  136599. NULL,
  136600. 0
  136601. };
  136602. static long _vq_quantlist__44u7__p9_0[] = {
  136603. 5,
  136604. 4,
  136605. 6,
  136606. 3,
  136607. 7,
  136608. 2,
  136609. 8,
  136610. 1,
  136611. 9,
  136612. 0,
  136613. 10,
  136614. };
  136615. static long _vq_lengthlist__44u7__p9_0[] = {
  136616. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136617. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136618. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136619. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136620. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136621. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136622. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136623. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136624. };
  136625. static float _vq_quantthresh__44u7__p9_0[] = {
  136626. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136627. 2229.5, 2866.5,
  136628. };
  136629. static long _vq_quantmap__44u7__p9_0[] = {
  136630. 9, 7, 5, 3, 1, 0, 2, 4,
  136631. 6, 8, 10,
  136632. };
  136633. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136634. _vq_quantthresh__44u7__p9_0,
  136635. _vq_quantmap__44u7__p9_0,
  136636. 11,
  136637. 11
  136638. };
  136639. static static_codebook _44u7__p9_0 = {
  136640. 2, 121,
  136641. _vq_lengthlist__44u7__p9_0,
  136642. 1, -512171520, 1630791680, 4, 0,
  136643. _vq_quantlist__44u7__p9_0,
  136644. NULL,
  136645. &_vq_auxt__44u7__p9_0,
  136646. NULL,
  136647. 0
  136648. };
  136649. static long _vq_quantlist__44u7__p9_1[] = {
  136650. 6,
  136651. 5,
  136652. 7,
  136653. 4,
  136654. 8,
  136655. 3,
  136656. 9,
  136657. 2,
  136658. 10,
  136659. 1,
  136660. 11,
  136661. 0,
  136662. 12,
  136663. };
  136664. static long _vq_lengthlist__44u7__p9_1[] = {
  136665. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136666. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136667. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136668. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136669. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136670. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136671. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136672. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136673. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136674. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136675. 15,15,15,15,17,17,16,17,16,
  136676. };
  136677. static float _vq_quantthresh__44u7__p9_1[] = {
  136678. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136679. 122.5, 171.5, 220.5, 269.5,
  136680. };
  136681. static long _vq_quantmap__44u7__p9_1[] = {
  136682. 11, 9, 7, 5, 3, 1, 0, 2,
  136683. 4, 6, 8, 10, 12,
  136684. };
  136685. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136686. _vq_quantthresh__44u7__p9_1,
  136687. _vq_quantmap__44u7__p9_1,
  136688. 13,
  136689. 13
  136690. };
  136691. static static_codebook _44u7__p9_1 = {
  136692. 2, 169,
  136693. _vq_lengthlist__44u7__p9_1,
  136694. 1, -518889472, 1622704128, 4, 0,
  136695. _vq_quantlist__44u7__p9_1,
  136696. NULL,
  136697. &_vq_auxt__44u7__p9_1,
  136698. NULL,
  136699. 0
  136700. };
  136701. static long _vq_quantlist__44u7__p9_2[] = {
  136702. 24,
  136703. 23,
  136704. 25,
  136705. 22,
  136706. 26,
  136707. 21,
  136708. 27,
  136709. 20,
  136710. 28,
  136711. 19,
  136712. 29,
  136713. 18,
  136714. 30,
  136715. 17,
  136716. 31,
  136717. 16,
  136718. 32,
  136719. 15,
  136720. 33,
  136721. 14,
  136722. 34,
  136723. 13,
  136724. 35,
  136725. 12,
  136726. 36,
  136727. 11,
  136728. 37,
  136729. 10,
  136730. 38,
  136731. 9,
  136732. 39,
  136733. 8,
  136734. 40,
  136735. 7,
  136736. 41,
  136737. 6,
  136738. 42,
  136739. 5,
  136740. 43,
  136741. 4,
  136742. 44,
  136743. 3,
  136744. 45,
  136745. 2,
  136746. 46,
  136747. 1,
  136748. 47,
  136749. 0,
  136750. 48,
  136751. };
  136752. static long _vq_lengthlist__44u7__p9_2[] = {
  136753. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136754. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136755. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136756. 8,
  136757. };
  136758. static float _vq_quantthresh__44u7__p9_2[] = {
  136759. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136760. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136761. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136762. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136763. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136764. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136765. };
  136766. static long _vq_quantmap__44u7__p9_2[] = {
  136767. 47, 45, 43, 41, 39, 37, 35, 33,
  136768. 31, 29, 27, 25, 23, 21, 19, 17,
  136769. 15, 13, 11, 9, 7, 5, 3, 1,
  136770. 0, 2, 4, 6, 8, 10, 12, 14,
  136771. 16, 18, 20, 22, 24, 26, 28, 30,
  136772. 32, 34, 36, 38, 40, 42, 44, 46,
  136773. 48,
  136774. };
  136775. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136776. _vq_quantthresh__44u7__p9_2,
  136777. _vq_quantmap__44u7__p9_2,
  136778. 49,
  136779. 49
  136780. };
  136781. static static_codebook _44u7__p9_2 = {
  136782. 1, 49,
  136783. _vq_lengthlist__44u7__p9_2,
  136784. 1, -526909440, 1611661312, 6, 0,
  136785. _vq_quantlist__44u7__p9_2,
  136786. NULL,
  136787. &_vq_auxt__44u7__p9_2,
  136788. NULL,
  136789. 0
  136790. };
  136791. static long _huff_lengthlist__44u7__short[] = {
  136792. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136793. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136794. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136795. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136796. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136797. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136798. 6, 8, 5, 9,
  136799. };
  136800. static static_codebook _huff_book__44u7__short = {
  136801. 2, 100,
  136802. _huff_lengthlist__44u7__short,
  136803. 0, 0, 0, 0, 0,
  136804. NULL,
  136805. NULL,
  136806. NULL,
  136807. NULL,
  136808. 0
  136809. };
  136810. static long _huff_lengthlist__44u8__long[] = {
  136811. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136812. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136813. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136814. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136815. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136816. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136817. 10, 8, 8, 9,
  136818. };
  136819. static static_codebook _huff_book__44u8__long = {
  136820. 2, 100,
  136821. _huff_lengthlist__44u8__long,
  136822. 0, 0, 0, 0, 0,
  136823. NULL,
  136824. NULL,
  136825. NULL,
  136826. NULL,
  136827. 0
  136828. };
  136829. static long _huff_lengthlist__44u8__short[] = {
  136830. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136831. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136832. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136833. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136834. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136835. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136836. 10,10,15,17,
  136837. };
  136838. static static_codebook _huff_book__44u8__short = {
  136839. 2, 100,
  136840. _huff_lengthlist__44u8__short,
  136841. 0, 0, 0, 0, 0,
  136842. NULL,
  136843. NULL,
  136844. NULL,
  136845. NULL,
  136846. 0
  136847. };
  136848. static long _vq_quantlist__44u8_p1_0[] = {
  136849. 1,
  136850. 0,
  136851. 2,
  136852. };
  136853. static long _vq_lengthlist__44u8_p1_0[] = {
  136854. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136855. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136856. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136857. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136858. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136859. 10,
  136860. };
  136861. static float _vq_quantthresh__44u8_p1_0[] = {
  136862. -0.5, 0.5,
  136863. };
  136864. static long _vq_quantmap__44u8_p1_0[] = {
  136865. 1, 0, 2,
  136866. };
  136867. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136868. _vq_quantthresh__44u8_p1_0,
  136869. _vq_quantmap__44u8_p1_0,
  136870. 3,
  136871. 3
  136872. };
  136873. static static_codebook _44u8_p1_0 = {
  136874. 4, 81,
  136875. _vq_lengthlist__44u8_p1_0,
  136876. 1, -535822336, 1611661312, 2, 0,
  136877. _vq_quantlist__44u8_p1_0,
  136878. NULL,
  136879. &_vq_auxt__44u8_p1_0,
  136880. NULL,
  136881. 0
  136882. };
  136883. static long _vq_quantlist__44u8_p2_0[] = {
  136884. 2,
  136885. 1,
  136886. 3,
  136887. 0,
  136888. 4,
  136889. };
  136890. static long _vq_lengthlist__44u8_p2_0[] = {
  136891. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136892. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136893. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136894. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136895. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136896. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136897. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136898. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136899. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136900. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136901. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136902. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136903. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136904. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136905. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136906. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136907. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136908. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136909. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136910. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136911. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136912. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136913. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136914. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136915. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136916. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136917. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136918. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136919. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136920. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136921. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136922. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136923. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136924. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136925. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136926. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136927. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136928. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136929. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136930. 14,
  136931. };
  136932. static float _vq_quantthresh__44u8_p2_0[] = {
  136933. -1.5, -0.5, 0.5, 1.5,
  136934. };
  136935. static long _vq_quantmap__44u8_p2_0[] = {
  136936. 3, 1, 0, 2, 4,
  136937. };
  136938. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136939. _vq_quantthresh__44u8_p2_0,
  136940. _vq_quantmap__44u8_p2_0,
  136941. 5,
  136942. 5
  136943. };
  136944. static static_codebook _44u8_p2_0 = {
  136945. 4, 625,
  136946. _vq_lengthlist__44u8_p2_0,
  136947. 1, -533725184, 1611661312, 3, 0,
  136948. _vq_quantlist__44u8_p2_0,
  136949. NULL,
  136950. &_vq_auxt__44u8_p2_0,
  136951. NULL,
  136952. 0
  136953. };
  136954. static long _vq_quantlist__44u8_p3_0[] = {
  136955. 4,
  136956. 3,
  136957. 5,
  136958. 2,
  136959. 6,
  136960. 1,
  136961. 7,
  136962. 0,
  136963. 8,
  136964. };
  136965. static long _vq_lengthlist__44u8_p3_0[] = {
  136966. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136967. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136968. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136969. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136970. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136971. 12,
  136972. };
  136973. static float _vq_quantthresh__44u8_p3_0[] = {
  136974. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136975. };
  136976. static long _vq_quantmap__44u8_p3_0[] = {
  136977. 7, 5, 3, 1, 0, 2, 4, 6,
  136978. 8,
  136979. };
  136980. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136981. _vq_quantthresh__44u8_p3_0,
  136982. _vq_quantmap__44u8_p3_0,
  136983. 9,
  136984. 9
  136985. };
  136986. static static_codebook _44u8_p3_0 = {
  136987. 2, 81,
  136988. _vq_lengthlist__44u8_p3_0,
  136989. 1, -531628032, 1611661312, 4, 0,
  136990. _vq_quantlist__44u8_p3_0,
  136991. NULL,
  136992. &_vq_auxt__44u8_p3_0,
  136993. NULL,
  136994. 0
  136995. };
  136996. static long _vq_quantlist__44u8_p4_0[] = {
  136997. 8,
  136998. 7,
  136999. 9,
  137000. 6,
  137001. 10,
  137002. 5,
  137003. 11,
  137004. 4,
  137005. 12,
  137006. 3,
  137007. 13,
  137008. 2,
  137009. 14,
  137010. 1,
  137011. 15,
  137012. 0,
  137013. 16,
  137014. };
  137015. static long _vq_lengthlist__44u8_p4_0[] = {
  137016. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  137017. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  137018. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  137019. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  137020. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  137021. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  137022. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  137023. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  137024. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  137025. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  137026. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  137027. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  137028. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  137029. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  137030. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  137031. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  137032. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  137033. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  137034. 14,
  137035. };
  137036. static float _vq_quantthresh__44u8_p4_0[] = {
  137037. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137038. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137039. };
  137040. static long _vq_quantmap__44u8_p4_0[] = {
  137041. 15, 13, 11, 9, 7, 5, 3, 1,
  137042. 0, 2, 4, 6, 8, 10, 12, 14,
  137043. 16,
  137044. };
  137045. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  137046. _vq_quantthresh__44u8_p4_0,
  137047. _vq_quantmap__44u8_p4_0,
  137048. 17,
  137049. 17
  137050. };
  137051. static static_codebook _44u8_p4_0 = {
  137052. 2, 289,
  137053. _vq_lengthlist__44u8_p4_0,
  137054. 1, -529530880, 1611661312, 5, 0,
  137055. _vq_quantlist__44u8_p4_0,
  137056. NULL,
  137057. &_vq_auxt__44u8_p4_0,
  137058. NULL,
  137059. 0
  137060. };
  137061. static long _vq_quantlist__44u8_p5_0[] = {
  137062. 1,
  137063. 0,
  137064. 2,
  137065. };
  137066. static long _vq_lengthlist__44u8_p5_0[] = {
  137067. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137068. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137069. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  137070. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137071. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137072. 10,
  137073. };
  137074. static float _vq_quantthresh__44u8_p5_0[] = {
  137075. -5.5, 5.5,
  137076. };
  137077. static long _vq_quantmap__44u8_p5_0[] = {
  137078. 1, 0, 2,
  137079. };
  137080. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  137081. _vq_quantthresh__44u8_p5_0,
  137082. _vq_quantmap__44u8_p5_0,
  137083. 3,
  137084. 3
  137085. };
  137086. static static_codebook _44u8_p5_0 = {
  137087. 4, 81,
  137088. _vq_lengthlist__44u8_p5_0,
  137089. 1, -529137664, 1618345984, 2, 0,
  137090. _vq_quantlist__44u8_p5_0,
  137091. NULL,
  137092. &_vq_auxt__44u8_p5_0,
  137093. NULL,
  137094. 0
  137095. };
  137096. static long _vq_quantlist__44u8_p5_1[] = {
  137097. 5,
  137098. 4,
  137099. 6,
  137100. 3,
  137101. 7,
  137102. 2,
  137103. 8,
  137104. 1,
  137105. 9,
  137106. 0,
  137107. 10,
  137108. };
  137109. static long _vq_lengthlist__44u8_p5_1[] = {
  137110. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  137111. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  137112. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  137113. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137114. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  137115. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  137116. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  137117. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  137118. };
  137119. static float _vq_quantthresh__44u8_p5_1[] = {
  137120. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137121. 3.5, 4.5,
  137122. };
  137123. static long _vq_quantmap__44u8_p5_1[] = {
  137124. 9, 7, 5, 3, 1, 0, 2, 4,
  137125. 6, 8, 10,
  137126. };
  137127. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  137128. _vq_quantthresh__44u8_p5_1,
  137129. _vq_quantmap__44u8_p5_1,
  137130. 11,
  137131. 11
  137132. };
  137133. static static_codebook _44u8_p5_1 = {
  137134. 2, 121,
  137135. _vq_lengthlist__44u8_p5_1,
  137136. 1, -531365888, 1611661312, 4, 0,
  137137. _vq_quantlist__44u8_p5_1,
  137138. NULL,
  137139. &_vq_auxt__44u8_p5_1,
  137140. NULL,
  137141. 0
  137142. };
  137143. static long _vq_quantlist__44u8_p6_0[] = {
  137144. 6,
  137145. 5,
  137146. 7,
  137147. 4,
  137148. 8,
  137149. 3,
  137150. 9,
  137151. 2,
  137152. 10,
  137153. 1,
  137154. 11,
  137155. 0,
  137156. 12,
  137157. };
  137158. static long _vq_lengthlist__44u8_p6_0[] = {
  137159. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137160. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  137161. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  137162. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  137163. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  137164. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137165. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137166. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  137167. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  137168. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137169. 11,11,11,11,11,12,11,12,12,
  137170. };
  137171. static float _vq_quantthresh__44u8_p6_0[] = {
  137172. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137173. 12.5, 17.5, 22.5, 27.5,
  137174. };
  137175. static long _vq_quantmap__44u8_p6_0[] = {
  137176. 11, 9, 7, 5, 3, 1, 0, 2,
  137177. 4, 6, 8, 10, 12,
  137178. };
  137179. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  137180. _vq_quantthresh__44u8_p6_0,
  137181. _vq_quantmap__44u8_p6_0,
  137182. 13,
  137183. 13
  137184. };
  137185. static static_codebook _44u8_p6_0 = {
  137186. 2, 169,
  137187. _vq_lengthlist__44u8_p6_0,
  137188. 1, -526516224, 1616117760, 4, 0,
  137189. _vq_quantlist__44u8_p6_0,
  137190. NULL,
  137191. &_vq_auxt__44u8_p6_0,
  137192. NULL,
  137193. 0
  137194. };
  137195. static long _vq_quantlist__44u8_p6_1[] = {
  137196. 2,
  137197. 1,
  137198. 3,
  137199. 0,
  137200. 4,
  137201. };
  137202. static long _vq_lengthlist__44u8_p6_1[] = {
  137203. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  137204. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137205. };
  137206. static float _vq_quantthresh__44u8_p6_1[] = {
  137207. -1.5, -0.5, 0.5, 1.5,
  137208. };
  137209. static long _vq_quantmap__44u8_p6_1[] = {
  137210. 3, 1, 0, 2, 4,
  137211. };
  137212. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  137213. _vq_quantthresh__44u8_p6_1,
  137214. _vq_quantmap__44u8_p6_1,
  137215. 5,
  137216. 5
  137217. };
  137218. static static_codebook _44u8_p6_1 = {
  137219. 2, 25,
  137220. _vq_lengthlist__44u8_p6_1,
  137221. 1, -533725184, 1611661312, 3, 0,
  137222. _vq_quantlist__44u8_p6_1,
  137223. NULL,
  137224. &_vq_auxt__44u8_p6_1,
  137225. NULL,
  137226. 0
  137227. };
  137228. static long _vq_quantlist__44u8_p7_0[] = {
  137229. 6,
  137230. 5,
  137231. 7,
  137232. 4,
  137233. 8,
  137234. 3,
  137235. 9,
  137236. 2,
  137237. 10,
  137238. 1,
  137239. 11,
  137240. 0,
  137241. 12,
  137242. };
  137243. static long _vq_lengthlist__44u8_p7_0[] = {
  137244. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  137245. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  137246. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  137247. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  137248. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137249. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137250. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  137251. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  137252. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  137253. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  137254. 13,13,14,14,14,15,15,15,16,
  137255. };
  137256. static float _vq_quantthresh__44u8_p7_0[] = {
  137257. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137258. 27.5, 38.5, 49.5, 60.5,
  137259. };
  137260. static long _vq_quantmap__44u8_p7_0[] = {
  137261. 11, 9, 7, 5, 3, 1, 0, 2,
  137262. 4, 6, 8, 10, 12,
  137263. };
  137264. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  137265. _vq_quantthresh__44u8_p7_0,
  137266. _vq_quantmap__44u8_p7_0,
  137267. 13,
  137268. 13
  137269. };
  137270. static static_codebook _44u8_p7_0 = {
  137271. 2, 169,
  137272. _vq_lengthlist__44u8_p7_0,
  137273. 1, -523206656, 1618345984, 4, 0,
  137274. _vq_quantlist__44u8_p7_0,
  137275. NULL,
  137276. &_vq_auxt__44u8_p7_0,
  137277. NULL,
  137278. 0
  137279. };
  137280. static long _vq_quantlist__44u8_p7_1[] = {
  137281. 5,
  137282. 4,
  137283. 6,
  137284. 3,
  137285. 7,
  137286. 2,
  137287. 8,
  137288. 1,
  137289. 9,
  137290. 0,
  137291. 10,
  137292. };
  137293. static long _vq_lengthlist__44u8_p7_1[] = {
  137294. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  137295. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137296. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  137297. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  137298. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  137299. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  137300. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  137301. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  137302. };
  137303. static float _vq_quantthresh__44u8_p7_1[] = {
  137304. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137305. 3.5, 4.5,
  137306. };
  137307. static long _vq_quantmap__44u8_p7_1[] = {
  137308. 9, 7, 5, 3, 1, 0, 2, 4,
  137309. 6, 8, 10,
  137310. };
  137311. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  137312. _vq_quantthresh__44u8_p7_1,
  137313. _vq_quantmap__44u8_p7_1,
  137314. 11,
  137315. 11
  137316. };
  137317. static static_codebook _44u8_p7_1 = {
  137318. 2, 121,
  137319. _vq_lengthlist__44u8_p7_1,
  137320. 1, -531365888, 1611661312, 4, 0,
  137321. _vq_quantlist__44u8_p7_1,
  137322. NULL,
  137323. &_vq_auxt__44u8_p7_1,
  137324. NULL,
  137325. 0
  137326. };
  137327. static long _vq_quantlist__44u8_p8_0[] = {
  137328. 7,
  137329. 6,
  137330. 8,
  137331. 5,
  137332. 9,
  137333. 4,
  137334. 10,
  137335. 3,
  137336. 11,
  137337. 2,
  137338. 12,
  137339. 1,
  137340. 13,
  137341. 0,
  137342. 14,
  137343. };
  137344. static long _vq_lengthlist__44u8_p8_0[] = {
  137345. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  137346. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137347. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  137348. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  137349. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  137350. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  137351. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  137352. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  137353. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  137354. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  137355. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  137356. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  137357. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  137358. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  137359. 17,
  137360. };
  137361. static float _vq_quantthresh__44u8_p8_0[] = {
  137362. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137363. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137364. };
  137365. static long _vq_quantmap__44u8_p8_0[] = {
  137366. 13, 11, 9, 7, 5, 3, 1, 0,
  137367. 2, 4, 6, 8, 10, 12, 14,
  137368. };
  137369. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  137370. _vq_quantthresh__44u8_p8_0,
  137371. _vq_quantmap__44u8_p8_0,
  137372. 15,
  137373. 15
  137374. };
  137375. static static_codebook _44u8_p8_0 = {
  137376. 2, 225,
  137377. _vq_lengthlist__44u8_p8_0,
  137378. 1, -520986624, 1620377600, 4, 0,
  137379. _vq_quantlist__44u8_p8_0,
  137380. NULL,
  137381. &_vq_auxt__44u8_p8_0,
  137382. NULL,
  137383. 0
  137384. };
  137385. static long _vq_quantlist__44u8_p8_1[] = {
  137386. 10,
  137387. 9,
  137388. 11,
  137389. 8,
  137390. 12,
  137391. 7,
  137392. 13,
  137393. 6,
  137394. 14,
  137395. 5,
  137396. 15,
  137397. 4,
  137398. 16,
  137399. 3,
  137400. 17,
  137401. 2,
  137402. 18,
  137403. 1,
  137404. 19,
  137405. 0,
  137406. 20,
  137407. };
  137408. static long _vq_lengthlist__44u8_p8_1[] = {
  137409. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137410. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137411. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  137412. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137413. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137414. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137415. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137416. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  137417. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137418. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137419. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  137420. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  137421. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137422. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137423. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137424. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137425. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  137426. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137427. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137428. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137429. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137430. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137431. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137432. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  137433. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137434. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137435. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  137436. 10,10,10,10,10,10,10,10,10,
  137437. };
  137438. static float _vq_quantthresh__44u8_p8_1[] = {
  137439. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137440. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137441. 6.5, 7.5, 8.5, 9.5,
  137442. };
  137443. static long _vq_quantmap__44u8_p8_1[] = {
  137444. 19, 17, 15, 13, 11, 9, 7, 5,
  137445. 3, 1, 0, 2, 4, 6, 8, 10,
  137446. 12, 14, 16, 18, 20,
  137447. };
  137448. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  137449. _vq_quantthresh__44u8_p8_1,
  137450. _vq_quantmap__44u8_p8_1,
  137451. 21,
  137452. 21
  137453. };
  137454. static static_codebook _44u8_p8_1 = {
  137455. 2, 441,
  137456. _vq_lengthlist__44u8_p8_1,
  137457. 1, -529268736, 1611661312, 5, 0,
  137458. _vq_quantlist__44u8_p8_1,
  137459. NULL,
  137460. &_vq_auxt__44u8_p8_1,
  137461. NULL,
  137462. 0
  137463. };
  137464. static long _vq_quantlist__44u8_p9_0[] = {
  137465. 4,
  137466. 3,
  137467. 5,
  137468. 2,
  137469. 6,
  137470. 1,
  137471. 7,
  137472. 0,
  137473. 8,
  137474. };
  137475. static long _vq_lengthlist__44u8_p9_0[] = {
  137476. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  137477. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137478. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137479. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137480. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  137481. 8,
  137482. };
  137483. static float _vq_quantthresh__44u8_p9_0[] = {
  137484. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  137485. };
  137486. static long _vq_quantmap__44u8_p9_0[] = {
  137487. 7, 5, 3, 1, 0, 2, 4, 6,
  137488. 8,
  137489. };
  137490. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  137491. _vq_quantthresh__44u8_p9_0,
  137492. _vq_quantmap__44u8_p9_0,
  137493. 9,
  137494. 9
  137495. };
  137496. static static_codebook _44u8_p9_0 = {
  137497. 2, 81,
  137498. _vq_lengthlist__44u8_p9_0,
  137499. 1, -511895552, 1631393792, 4, 0,
  137500. _vq_quantlist__44u8_p9_0,
  137501. NULL,
  137502. &_vq_auxt__44u8_p9_0,
  137503. NULL,
  137504. 0
  137505. };
  137506. static long _vq_quantlist__44u8_p9_1[] = {
  137507. 9,
  137508. 8,
  137509. 10,
  137510. 7,
  137511. 11,
  137512. 6,
  137513. 12,
  137514. 5,
  137515. 13,
  137516. 4,
  137517. 14,
  137518. 3,
  137519. 15,
  137520. 2,
  137521. 16,
  137522. 1,
  137523. 17,
  137524. 0,
  137525. 18,
  137526. };
  137527. static long _vq_lengthlist__44u8_p9_1[] = {
  137528. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137529. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137530. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137531. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137532. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137533. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137534. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137535. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137536. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137537. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137538. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137539. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137540. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137541. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137542. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137543. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137544. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137545. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137546. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137547. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137548. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137549. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137550. 16,15,16,16,16,16,16,16,16,
  137551. };
  137552. static float _vq_quantthresh__44u8_p9_1[] = {
  137553. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137554. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137555. 367.5, 416.5,
  137556. };
  137557. static long _vq_quantmap__44u8_p9_1[] = {
  137558. 17, 15, 13, 11, 9, 7, 5, 3,
  137559. 1, 0, 2, 4, 6, 8, 10, 12,
  137560. 14, 16, 18,
  137561. };
  137562. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137563. _vq_quantthresh__44u8_p9_1,
  137564. _vq_quantmap__44u8_p9_1,
  137565. 19,
  137566. 19
  137567. };
  137568. static static_codebook _44u8_p9_1 = {
  137569. 2, 361,
  137570. _vq_lengthlist__44u8_p9_1,
  137571. 1, -518287360, 1622704128, 5, 0,
  137572. _vq_quantlist__44u8_p9_1,
  137573. NULL,
  137574. &_vq_auxt__44u8_p9_1,
  137575. NULL,
  137576. 0
  137577. };
  137578. static long _vq_quantlist__44u8_p9_2[] = {
  137579. 24,
  137580. 23,
  137581. 25,
  137582. 22,
  137583. 26,
  137584. 21,
  137585. 27,
  137586. 20,
  137587. 28,
  137588. 19,
  137589. 29,
  137590. 18,
  137591. 30,
  137592. 17,
  137593. 31,
  137594. 16,
  137595. 32,
  137596. 15,
  137597. 33,
  137598. 14,
  137599. 34,
  137600. 13,
  137601. 35,
  137602. 12,
  137603. 36,
  137604. 11,
  137605. 37,
  137606. 10,
  137607. 38,
  137608. 9,
  137609. 39,
  137610. 8,
  137611. 40,
  137612. 7,
  137613. 41,
  137614. 6,
  137615. 42,
  137616. 5,
  137617. 43,
  137618. 4,
  137619. 44,
  137620. 3,
  137621. 45,
  137622. 2,
  137623. 46,
  137624. 1,
  137625. 47,
  137626. 0,
  137627. 48,
  137628. };
  137629. static long _vq_lengthlist__44u8_p9_2[] = {
  137630. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137631. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137632. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137633. 7,
  137634. };
  137635. static float _vq_quantthresh__44u8_p9_2[] = {
  137636. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137637. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137638. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137639. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137640. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137641. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137642. };
  137643. static long _vq_quantmap__44u8_p9_2[] = {
  137644. 47, 45, 43, 41, 39, 37, 35, 33,
  137645. 31, 29, 27, 25, 23, 21, 19, 17,
  137646. 15, 13, 11, 9, 7, 5, 3, 1,
  137647. 0, 2, 4, 6, 8, 10, 12, 14,
  137648. 16, 18, 20, 22, 24, 26, 28, 30,
  137649. 32, 34, 36, 38, 40, 42, 44, 46,
  137650. 48,
  137651. };
  137652. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137653. _vq_quantthresh__44u8_p9_2,
  137654. _vq_quantmap__44u8_p9_2,
  137655. 49,
  137656. 49
  137657. };
  137658. static static_codebook _44u8_p9_2 = {
  137659. 1, 49,
  137660. _vq_lengthlist__44u8_p9_2,
  137661. 1, -526909440, 1611661312, 6, 0,
  137662. _vq_quantlist__44u8_p9_2,
  137663. NULL,
  137664. &_vq_auxt__44u8_p9_2,
  137665. NULL,
  137666. 0
  137667. };
  137668. static long _huff_lengthlist__44u9__long[] = {
  137669. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137670. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137671. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137672. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137673. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137674. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137675. 10, 8, 8, 9,
  137676. };
  137677. static static_codebook _huff_book__44u9__long = {
  137678. 2, 100,
  137679. _huff_lengthlist__44u9__long,
  137680. 0, 0, 0, 0, 0,
  137681. NULL,
  137682. NULL,
  137683. NULL,
  137684. NULL,
  137685. 0
  137686. };
  137687. static long _huff_lengthlist__44u9__short[] = {
  137688. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137689. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137690. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137691. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137692. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137693. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137694. 9, 9,12,15,
  137695. };
  137696. static static_codebook _huff_book__44u9__short = {
  137697. 2, 100,
  137698. _huff_lengthlist__44u9__short,
  137699. 0, 0, 0, 0, 0,
  137700. NULL,
  137701. NULL,
  137702. NULL,
  137703. NULL,
  137704. 0
  137705. };
  137706. static long _vq_quantlist__44u9_p1_0[] = {
  137707. 1,
  137708. 0,
  137709. 2,
  137710. };
  137711. static long _vq_lengthlist__44u9_p1_0[] = {
  137712. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137713. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137714. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137715. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137716. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137717. 10,
  137718. };
  137719. static float _vq_quantthresh__44u9_p1_0[] = {
  137720. -0.5, 0.5,
  137721. };
  137722. static long _vq_quantmap__44u9_p1_0[] = {
  137723. 1, 0, 2,
  137724. };
  137725. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137726. _vq_quantthresh__44u9_p1_0,
  137727. _vq_quantmap__44u9_p1_0,
  137728. 3,
  137729. 3
  137730. };
  137731. static static_codebook _44u9_p1_0 = {
  137732. 4, 81,
  137733. _vq_lengthlist__44u9_p1_0,
  137734. 1, -535822336, 1611661312, 2, 0,
  137735. _vq_quantlist__44u9_p1_0,
  137736. NULL,
  137737. &_vq_auxt__44u9_p1_0,
  137738. NULL,
  137739. 0
  137740. };
  137741. static long _vq_quantlist__44u9_p2_0[] = {
  137742. 2,
  137743. 1,
  137744. 3,
  137745. 0,
  137746. 4,
  137747. };
  137748. static long _vq_lengthlist__44u9_p2_0[] = {
  137749. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137750. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137751. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137752. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137753. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137754. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137755. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137756. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137757. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137758. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137759. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137760. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137761. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137762. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137763. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137764. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137765. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137766. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137767. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137768. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137769. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137770. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137771. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137772. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137773. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137774. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137775. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137776. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137777. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137778. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137779. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137780. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137781. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137782. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137783. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137784. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137785. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137786. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137787. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137788. 14,
  137789. };
  137790. static float _vq_quantthresh__44u9_p2_0[] = {
  137791. -1.5, -0.5, 0.5, 1.5,
  137792. };
  137793. static long _vq_quantmap__44u9_p2_0[] = {
  137794. 3, 1, 0, 2, 4,
  137795. };
  137796. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137797. _vq_quantthresh__44u9_p2_0,
  137798. _vq_quantmap__44u9_p2_0,
  137799. 5,
  137800. 5
  137801. };
  137802. static static_codebook _44u9_p2_0 = {
  137803. 4, 625,
  137804. _vq_lengthlist__44u9_p2_0,
  137805. 1, -533725184, 1611661312, 3, 0,
  137806. _vq_quantlist__44u9_p2_0,
  137807. NULL,
  137808. &_vq_auxt__44u9_p2_0,
  137809. NULL,
  137810. 0
  137811. };
  137812. static long _vq_quantlist__44u9_p3_0[] = {
  137813. 4,
  137814. 3,
  137815. 5,
  137816. 2,
  137817. 6,
  137818. 1,
  137819. 7,
  137820. 0,
  137821. 8,
  137822. };
  137823. static long _vq_lengthlist__44u9_p3_0[] = {
  137824. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137825. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137826. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137827. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137828. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137829. 11,
  137830. };
  137831. static float _vq_quantthresh__44u9_p3_0[] = {
  137832. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137833. };
  137834. static long _vq_quantmap__44u9_p3_0[] = {
  137835. 7, 5, 3, 1, 0, 2, 4, 6,
  137836. 8,
  137837. };
  137838. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137839. _vq_quantthresh__44u9_p3_0,
  137840. _vq_quantmap__44u9_p3_0,
  137841. 9,
  137842. 9
  137843. };
  137844. static static_codebook _44u9_p3_0 = {
  137845. 2, 81,
  137846. _vq_lengthlist__44u9_p3_0,
  137847. 1, -531628032, 1611661312, 4, 0,
  137848. _vq_quantlist__44u9_p3_0,
  137849. NULL,
  137850. &_vq_auxt__44u9_p3_0,
  137851. NULL,
  137852. 0
  137853. };
  137854. static long _vq_quantlist__44u9_p4_0[] = {
  137855. 8,
  137856. 7,
  137857. 9,
  137858. 6,
  137859. 10,
  137860. 5,
  137861. 11,
  137862. 4,
  137863. 12,
  137864. 3,
  137865. 13,
  137866. 2,
  137867. 14,
  137868. 1,
  137869. 15,
  137870. 0,
  137871. 16,
  137872. };
  137873. static long _vq_lengthlist__44u9_p4_0[] = {
  137874. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137875. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137876. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137877. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137878. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137879. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137880. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137881. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137882. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137883. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137884. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137885. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137886. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137887. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137888. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137889. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137890. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137891. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137892. 14,
  137893. };
  137894. static float _vq_quantthresh__44u9_p4_0[] = {
  137895. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137896. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137897. };
  137898. static long _vq_quantmap__44u9_p4_0[] = {
  137899. 15, 13, 11, 9, 7, 5, 3, 1,
  137900. 0, 2, 4, 6, 8, 10, 12, 14,
  137901. 16,
  137902. };
  137903. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137904. _vq_quantthresh__44u9_p4_0,
  137905. _vq_quantmap__44u9_p4_0,
  137906. 17,
  137907. 17
  137908. };
  137909. static static_codebook _44u9_p4_0 = {
  137910. 2, 289,
  137911. _vq_lengthlist__44u9_p4_0,
  137912. 1, -529530880, 1611661312, 5, 0,
  137913. _vq_quantlist__44u9_p4_0,
  137914. NULL,
  137915. &_vq_auxt__44u9_p4_0,
  137916. NULL,
  137917. 0
  137918. };
  137919. static long _vq_quantlist__44u9_p5_0[] = {
  137920. 1,
  137921. 0,
  137922. 2,
  137923. };
  137924. static long _vq_lengthlist__44u9_p5_0[] = {
  137925. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137926. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137927. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137928. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137929. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137930. 10,
  137931. };
  137932. static float _vq_quantthresh__44u9_p5_0[] = {
  137933. -5.5, 5.5,
  137934. };
  137935. static long _vq_quantmap__44u9_p5_0[] = {
  137936. 1, 0, 2,
  137937. };
  137938. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137939. _vq_quantthresh__44u9_p5_0,
  137940. _vq_quantmap__44u9_p5_0,
  137941. 3,
  137942. 3
  137943. };
  137944. static static_codebook _44u9_p5_0 = {
  137945. 4, 81,
  137946. _vq_lengthlist__44u9_p5_0,
  137947. 1, -529137664, 1618345984, 2, 0,
  137948. _vq_quantlist__44u9_p5_0,
  137949. NULL,
  137950. &_vq_auxt__44u9_p5_0,
  137951. NULL,
  137952. 0
  137953. };
  137954. static long _vq_quantlist__44u9_p5_1[] = {
  137955. 5,
  137956. 4,
  137957. 6,
  137958. 3,
  137959. 7,
  137960. 2,
  137961. 8,
  137962. 1,
  137963. 9,
  137964. 0,
  137965. 10,
  137966. };
  137967. static long _vq_lengthlist__44u9_p5_1[] = {
  137968. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137969. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137970. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137971. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137972. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137973. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137974. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137975. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137976. };
  137977. static float _vq_quantthresh__44u9_p5_1[] = {
  137978. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137979. 3.5, 4.5,
  137980. };
  137981. static long _vq_quantmap__44u9_p5_1[] = {
  137982. 9, 7, 5, 3, 1, 0, 2, 4,
  137983. 6, 8, 10,
  137984. };
  137985. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137986. _vq_quantthresh__44u9_p5_1,
  137987. _vq_quantmap__44u9_p5_1,
  137988. 11,
  137989. 11
  137990. };
  137991. static static_codebook _44u9_p5_1 = {
  137992. 2, 121,
  137993. _vq_lengthlist__44u9_p5_1,
  137994. 1, -531365888, 1611661312, 4, 0,
  137995. _vq_quantlist__44u9_p5_1,
  137996. NULL,
  137997. &_vq_auxt__44u9_p5_1,
  137998. NULL,
  137999. 0
  138000. };
  138001. static long _vq_quantlist__44u9_p6_0[] = {
  138002. 6,
  138003. 5,
  138004. 7,
  138005. 4,
  138006. 8,
  138007. 3,
  138008. 9,
  138009. 2,
  138010. 10,
  138011. 1,
  138012. 11,
  138013. 0,
  138014. 12,
  138015. };
  138016. static long _vq_lengthlist__44u9_p6_0[] = {
  138017. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  138018. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  138019. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  138020. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  138021. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  138022. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  138023. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  138024. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  138025. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  138026. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  138027. 10,11,11,11,11,12,11,12,12,
  138028. };
  138029. static float _vq_quantthresh__44u9_p6_0[] = {
  138030. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138031. 12.5, 17.5, 22.5, 27.5,
  138032. };
  138033. static long _vq_quantmap__44u9_p6_0[] = {
  138034. 11, 9, 7, 5, 3, 1, 0, 2,
  138035. 4, 6, 8, 10, 12,
  138036. };
  138037. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  138038. _vq_quantthresh__44u9_p6_0,
  138039. _vq_quantmap__44u9_p6_0,
  138040. 13,
  138041. 13
  138042. };
  138043. static static_codebook _44u9_p6_0 = {
  138044. 2, 169,
  138045. _vq_lengthlist__44u9_p6_0,
  138046. 1, -526516224, 1616117760, 4, 0,
  138047. _vq_quantlist__44u9_p6_0,
  138048. NULL,
  138049. &_vq_auxt__44u9_p6_0,
  138050. NULL,
  138051. 0
  138052. };
  138053. static long _vq_quantlist__44u9_p6_1[] = {
  138054. 2,
  138055. 1,
  138056. 3,
  138057. 0,
  138058. 4,
  138059. };
  138060. static long _vq_lengthlist__44u9_p6_1[] = {
  138061. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  138062. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  138063. };
  138064. static float _vq_quantthresh__44u9_p6_1[] = {
  138065. -1.5, -0.5, 0.5, 1.5,
  138066. };
  138067. static long _vq_quantmap__44u9_p6_1[] = {
  138068. 3, 1, 0, 2, 4,
  138069. };
  138070. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  138071. _vq_quantthresh__44u9_p6_1,
  138072. _vq_quantmap__44u9_p6_1,
  138073. 5,
  138074. 5
  138075. };
  138076. static static_codebook _44u9_p6_1 = {
  138077. 2, 25,
  138078. _vq_lengthlist__44u9_p6_1,
  138079. 1, -533725184, 1611661312, 3, 0,
  138080. _vq_quantlist__44u9_p6_1,
  138081. NULL,
  138082. &_vq_auxt__44u9_p6_1,
  138083. NULL,
  138084. 0
  138085. };
  138086. static long _vq_quantlist__44u9_p7_0[] = {
  138087. 6,
  138088. 5,
  138089. 7,
  138090. 4,
  138091. 8,
  138092. 3,
  138093. 9,
  138094. 2,
  138095. 10,
  138096. 1,
  138097. 11,
  138098. 0,
  138099. 12,
  138100. };
  138101. static long _vq_lengthlist__44u9_p7_0[] = {
  138102. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  138103. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  138104. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  138105. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  138106. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  138107. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  138108. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  138109. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  138110. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  138111. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  138112. 12,13,13,14,14,14,15,15,15,
  138113. };
  138114. static float _vq_quantthresh__44u9_p7_0[] = {
  138115. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  138116. 27.5, 38.5, 49.5, 60.5,
  138117. };
  138118. static long _vq_quantmap__44u9_p7_0[] = {
  138119. 11, 9, 7, 5, 3, 1, 0, 2,
  138120. 4, 6, 8, 10, 12,
  138121. };
  138122. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  138123. _vq_quantthresh__44u9_p7_0,
  138124. _vq_quantmap__44u9_p7_0,
  138125. 13,
  138126. 13
  138127. };
  138128. static static_codebook _44u9_p7_0 = {
  138129. 2, 169,
  138130. _vq_lengthlist__44u9_p7_0,
  138131. 1, -523206656, 1618345984, 4, 0,
  138132. _vq_quantlist__44u9_p7_0,
  138133. NULL,
  138134. &_vq_auxt__44u9_p7_0,
  138135. NULL,
  138136. 0
  138137. };
  138138. static long _vq_quantlist__44u9_p7_1[] = {
  138139. 5,
  138140. 4,
  138141. 6,
  138142. 3,
  138143. 7,
  138144. 2,
  138145. 8,
  138146. 1,
  138147. 9,
  138148. 0,
  138149. 10,
  138150. };
  138151. static long _vq_lengthlist__44u9_p7_1[] = {
  138152. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  138153. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  138154. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  138155. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138156. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138157. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138158. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  138159. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  138160. };
  138161. static float _vq_quantthresh__44u9_p7_1[] = {
  138162. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  138163. 3.5, 4.5,
  138164. };
  138165. static long _vq_quantmap__44u9_p7_1[] = {
  138166. 9, 7, 5, 3, 1, 0, 2, 4,
  138167. 6, 8, 10,
  138168. };
  138169. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  138170. _vq_quantthresh__44u9_p7_1,
  138171. _vq_quantmap__44u9_p7_1,
  138172. 11,
  138173. 11
  138174. };
  138175. static static_codebook _44u9_p7_1 = {
  138176. 2, 121,
  138177. _vq_lengthlist__44u9_p7_1,
  138178. 1, -531365888, 1611661312, 4, 0,
  138179. _vq_quantlist__44u9_p7_1,
  138180. NULL,
  138181. &_vq_auxt__44u9_p7_1,
  138182. NULL,
  138183. 0
  138184. };
  138185. static long _vq_quantlist__44u9_p8_0[] = {
  138186. 7,
  138187. 6,
  138188. 8,
  138189. 5,
  138190. 9,
  138191. 4,
  138192. 10,
  138193. 3,
  138194. 11,
  138195. 2,
  138196. 12,
  138197. 1,
  138198. 13,
  138199. 0,
  138200. 14,
  138201. };
  138202. static long _vq_lengthlist__44u9_p8_0[] = {
  138203. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  138204. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  138205. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  138206. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  138207. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  138208. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  138209. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  138210. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  138211. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  138212. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  138213. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  138214. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  138215. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  138216. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  138217. 15,
  138218. };
  138219. static float _vq_quantthresh__44u9_p8_0[] = {
  138220. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  138221. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  138222. };
  138223. static long _vq_quantmap__44u9_p8_0[] = {
  138224. 13, 11, 9, 7, 5, 3, 1, 0,
  138225. 2, 4, 6, 8, 10, 12, 14,
  138226. };
  138227. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  138228. _vq_quantthresh__44u9_p8_0,
  138229. _vq_quantmap__44u9_p8_0,
  138230. 15,
  138231. 15
  138232. };
  138233. static static_codebook _44u9_p8_0 = {
  138234. 2, 225,
  138235. _vq_lengthlist__44u9_p8_0,
  138236. 1, -520986624, 1620377600, 4, 0,
  138237. _vq_quantlist__44u9_p8_0,
  138238. NULL,
  138239. &_vq_auxt__44u9_p8_0,
  138240. NULL,
  138241. 0
  138242. };
  138243. static long _vq_quantlist__44u9_p8_1[] = {
  138244. 10,
  138245. 9,
  138246. 11,
  138247. 8,
  138248. 12,
  138249. 7,
  138250. 13,
  138251. 6,
  138252. 14,
  138253. 5,
  138254. 15,
  138255. 4,
  138256. 16,
  138257. 3,
  138258. 17,
  138259. 2,
  138260. 18,
  138261. 1,
  138262. 19,
  138263. 0,
  138264. 20,
  138265. };
  138266. static long _vq_lengthlist__44u9_p8_1[] = {
  138267. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  138268. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  138269. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  138270. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  138271. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  138272. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  138273. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  138274. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  138275. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138276. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138277. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  138278. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  138279. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138280. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  138281. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138282. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  138283. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138284. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138285. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  138286. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  138287. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138288. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  138289. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  138290. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  138291. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  138292. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  138293. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138294. 10,10,10,10,10,10,10,10,10,
  138295. };
  138296. static float _vq_quantthresh__44u9_p8_1[] = {
  138297. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  138298. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  138299. 6.5, 7.5, 8.5, 9.5,
  138300. };
  138301. static long _vq_quantmap__44u9_p8_1[] = {
  138302. 19, 17, 15, 13, 11, 9, 7, 5,
  138303. 3, 1, 0, 2, 4, 6, 8, 10,
  138304. 12, 14, 16, 18, 20,
  138305. };
  138306. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  138307. _vq_quantthresh__44u9_p8_1,
  138308. _vq_quantmap__44u9_p8_1,
  138309. 21,
  138310. 21
  138311. };
  138312. static static_codebook _44u9_p8_1 = {
  138313. 2, 441,
  138314. _vq_lengthlist__44u9_p8_1,
  138315. 1, -529268736, 1611661312, 5, 0,
  138316. _vq_quantlist__44u9_p8_1,
  138317. NULL,
  138318. &_vq_auxt__44u9_p8_1,
  138319. NULL,
  138320. 0
  138321. };
  138322. static long _vq_quantlist__44u9_p9_0[] = {
  138323. 7,
  138324. 6,
  138325. 8,
  138326. 5,
  138327. 9,
  138328. 4,
  138329. 10,
  138330. 3,
  138331. 11,
  138332. 2,
  138333. 12,
  138334. 1,
  138335. 13,
  138336. 0,
  138337. 14,
  138338. };
  138339. static long _vq_lengthlist__44u9_p9_0[] = {
  138340. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  138341. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  138342. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138343. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138344. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138345. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138346. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138347. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138348. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138349. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138350. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138351. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138352. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138353. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138354. 10,
  138355. };
  138356. static float _vq_quantthresh__44u9_p9_0[] = {
  138357. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  138358. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  138359. };
  138360. static long _vq_quantmap__44u9_p9_0[] = {
  138361. 13, 11, 9, 7, 5, 3, 1, 0,
  138362. 2, 4, 6, 8, 10, 12, 14,
  138363. };
  138364. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  138365. _vq_quantthresh__44u9_p9_0,
  138366. _vq_quantmap__44u9_p9_0,
  138367. 15,
  138368. 15
  138369. };
  138370. static static_codebook _44u9_p9_0 = {
  138371. 2, 225,
  138372. _vq_lengthlist__44u9_p9_0,
  138373. 1, -510036736, 1631393792, 4, 0,
  138374. _vq_quantlist__44u9_p9_0,
  138375. NULL,
  138376. &_vq_auxt__44u9_p9_0,
  138377. NULL,
  138378. 0
  138379. };
  138380. static long _vq_quantlist__44u9_p9_1[] = {
  138381. 9,
  138382. 8,
  138383. 10,
  138384. 7,
  138385. 11,
  138386. 6,
  138387. 12,
  138388. 5,
  138389. 13,
  138390. 4,
  138391. 14,
  138392. 3,
  138393. 15,
  138394. 2,
  138395. 16,
  138396. 1,
  138397. 17,
  138398. 0,
  138399. 18,
  138400. };
  138401. static long _vq_lengthlist__44u9_p9_1[] = {
  138402. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  138403. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  138404. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  138405. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  138406. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  138407. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  138408. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  138409. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  138410. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  138411. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  138412. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  138413. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  138414. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  138415. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  138416. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  138417. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  138418. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  138419. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  138420. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  138421. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  138422. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  138423. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  138424. 17,17,15,17,15,17,16,16,17,
  138425. };
  138426. static float _vq_quantthresh__44u9_p9_1[] = {
  138427. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  138428. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  138429. 367.5, 416.5,
  138430. };
  138431. static long _vq_quantmap__44u9_p9_1[] = {
  138432. 17, 15, 13, 11, 9, 7, 5, 3,
  138433. 1, 0, 2, 4, 6, 8, 10, 12,
  138434. 14, 16, 18,
  138435. };
  138436. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  138437. _vq_quantthresh__44u9_p9_1,
  138438. _vq_quantmap__44u9_p9_1,
  138439. 19,
  138440. 19
  138441. };
  138442. static static_codebook _44u9_p9_1 = {
  138443. 2, 361,
  138444. _vq_lengthlist__44u9_p9_1,
  138445. 1, -518287360, 1622704128, 5, 0,
  138446. _vq_quantlist__44u9_p9_1,
  138447. NULL,
  138448. &_vq_auxt__44u9_p9_1,
  138449. NULL,
  138450. 0
  138451. };
  138452. static long _vq_quantlist__44u9_p9_2[] = {
  138453. 24,
  138454. 23,
  138455. 25,
  138456. 22,
  138457. 26,
  138458. 21,
  138459. 27,
  138460. 20,
  138461. 28,
  138462. 19,
  138463. 29,
  138464. 18,
  138465. 30,
  138466. 17,
  138467. 31,
  138468. 16,
  138469. 32,
  138470. 15,
  138471. 33,
  138472. 14,
  138473. 34,
  138474. 13,
  138475. 35,
  138476. 12,
  138477. 36,
  138478. 11,
  138479. 37,
  138480. 10,
  138481. 38,
  138482. 9,
  138483. 39,
  138484. 8,
  138485. 40,
  138486. 7,
  138487. 41,
  138488. 6,
  138489. 42,
  138490. 5,
  138491. 43,
  138492. 4,
  138493. 44,
  138494. 3,
  138495. 45,
  138496. 2,
  138497. 46,
  138498. 1,
  138499. 47,
  138500. 0,
  138501. 48,
  138502. };
  138503. static long _vq_lengthlist__44u9_p9_2[] = {
  138504. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  138505. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138506. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138507. 7,
  138508. };
  138509. static float _vq_quantthresh__44u9_p9_2[] = {
  138510. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  138511. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  138512. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138513. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138514. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  138515. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  138516. };
  138517. static long _vq_quantmap__44u9_p9_2[] = {
  138518. 47, 45, 43, 41, 39, 37, 35, 33,
  138519. 31, 29, 27, 25, 23, 21, 19, 17,
  138520. 15, 13, 11, 9, 7, 5, 3, 1,
  138521. 0, 2, 4, 6, 8, 10, 12, 14,
  138522. 16, 18, 20, 22, 24, 26, 28, 30,
  138523. 32, 34, 36, 38, 40, 42, 44, 46,
  138524. 48,
  138525. };
  138526. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138527. _vq_quantthresh__44u9_p9_2,
  138528. _vq_quantmap__44u9_p9_2,
  138529. 49,
  138530. 49
  138531. };
  138532. static static_codebook _44u9_p9_2 = {
  138533. 1, 49,
  138534. _vq_lengthlist__44u9_p9_2,
  138535. 1, -526909440, 1611661312, 6, 0,
  138536. _vq_quantlist__44u9_p9_2,
  138537. NULL,
  138538. &_vq_auxt__44u9_p9_2,
  138539. NULL,
  138540. 0
  138541. };
  138542. static long _huff_lengthlist__44un1__long[] = {
  138543. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138544. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138545. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138546. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138547. };
  138548. static static_codebook _huff_book__44un1__long = {
  138549. 2, 64,
  138550. _huff_lengthlist__44un1__long,
  138551. 0, 0, 0, 0, 0,
  138552. NULL,
  138553. NULL,
  138554. NULL,
  138555. NULL,
  138556. 0
  138557. };
  138558. static long _vq_quantlist__44un1__p1_0[] = {
  138559. 1,
  138560. 0,
  138561. 2,
  138562. };
  138563. static long _vq_lengthlist__44un1__p1_0[] = {
  138564. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138565. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138566. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138567. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138568. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138569. 12,
  138570. };
  138571. static float _vq_quantthresh__44un1__p1_0[] = {
  138572. -0.5, 0.5,
  138573. };
  138574. static long _vq_quantmap__44un1__p1_0[] = {
  138575. 1, 0, 2,
  138576. };
  138577. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138578. _vq_quantthresh__44un1__p1_0,
  138579. _vq_quantmap__44un1__p1_0,
  138580. 3,
  138581. 3
  138582. };
  138583. static static_codebook _44un1__p1_0 = {
  138584. 4, 81,
  138585. _vq_lengthlist__44un1__p1_0,
  138586. 1, -535822336, 1611661312, 2, 0,
  138587. _vq_quantlist__44un1__p1_0,
  138588. NULL,
  138589. &_vq_auxt__44un1__p1_0,
  138590. NULL,
  138591. 0
  138592. };
  138593. static long _vq_quantlist__44un1__p2_0[] = {
  138594. 1,
  138595. 0,
  138596. 2,
  138597. };
  138598. static long _vq_lengthlist__44un1__p2_0[] = {
  138599. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138600. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138601. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138602. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138603. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138604. 8,
  138605. };
  138606. static float _vq_quantthresh__44un1__p2_0[] = {
  138607. -0.5, 0.5,
  138608. };
  138609. static long _vq_quantmap__44un1__p2_0[] = {
  138610. 1, 0, 2,
  138611. };
  138612. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138613. _vq_quantthresh__44un1__p2_0,
  138614. _vq_quantmap__44un1__p2_0,
  138615. 3,
  138616. 3
  138617. };
  138618. static static_codebook _44un1__p2_0 = {
  138619. 4, 81,
  138620. _vq_lengthlist__44un1__p2_0,
  138621. 1, -535822336, 1611661312, 2, 0,
  138622. _vq_quantlist__44un1__p2_0,
  138623. NULL,
  138624. &_vq_auxt__44un1__p2_0,
  138625. NULL,
  138626. 0
  138627. };
  138628. static long _vq_quantlist__44un1__p3_0[] = {
  138629. 2,
  138630. 1,
  138631. 3,
  138632. 0,
  138633. 4,
  138634. };
  138635. static long _vq_lengthlist__44un1__p3_0[] = {
  138636. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138637. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138638. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138639. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138640. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138641. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138642. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138643. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138644. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138645. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138646. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138647. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138648. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138649. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138650. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138651. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138652. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138653. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138654. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138655. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138656. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138657. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138658. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138659. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138660. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138661. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138662. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138663. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138664. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138665. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138666. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138667. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138668. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138669. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138670. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138671. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138672. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138673. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138674. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138675. 17,
  138676. };
  138677. static float _vq_quantthresh__44un1__p3_0[] = {
  138678. -1.5, -0.5, 0.5, 1.5,
  138679. };
  138680. static long _vq_quantmap__44un1__p3_0[] = {
  138681. 3, 1, 0, 2, 4,
  138682. };
  138683. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138684. _vq_quantthresh__44un1__p3_0,
  138685. _vq_quantmap__44un1__p3_0,
  138686. 5,
  138687. 5
  138688. };
  138689. static static_codebook _44un1__p3_0 = {
  138690. 4, 625,
  138691. _vq_lengthlist__44un1__p3_0,
  138692. 1, -533725184, 1611661312, 3, 0,
  138693. _vq_quantlist__44un1__p3_0,
  138694. NULL,
  138695. &_vq_auxt__44un1__p3_0,
  138696. NULL,
  138697. 0
  138698. };
  138699. static long _vq_quantlist__44un1__p4_0[] = {
  138700. 2,
  138701. 1,
  138702. 3,
  138703. 0,
  138704. 4,
  138705. };
  138706. static long _vq_lengthlist__44un1__p4_0[] = {
  138707. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138708. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138709. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138710. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138711. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138712. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138713. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138714. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138715. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138716. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138717. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138718. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138719. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138720. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138721. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138722. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138723. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138724. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138725. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138726. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138727. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138728. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138729. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138730. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138731. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138732. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138733. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138734. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138735. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138736. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138737. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138738. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138739. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138740. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138741. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138742. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138743. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138744. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138745. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138746. 12,
  138747. };
  138748. static float _vq_quantthresh__44un1__p4_0[] = {
  138749. -1.5, -0.5, 0.5, 1.5,
  138750. };
  138751. static long _vq_quantmap__44un1__p4_0[] = {
  138752. 3, 1, 0, 2, 4,
  138753. };
  138754. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138755. _vq_quantthresh__44un1__p4_0,
  138756. _vq_quantmap__44un1__p4_0,
  138757. 5,
  138758. 5
  138759. };
  138760. static static_codebook _44un1__p4_0 = {
  138761. 4, 625,
  138762. _vq_lengthlist__44un1__p4_0,
  138763. 1, -533725184, 1611661312, 3, 0,
  138764. _vq_quantlist__44un1__p4_0,
  138765. NULL,
  138766. &_vq_auxt__44un1__p4_0,
  138767. NULL,
  138768. 0
  138769. };
  138770. static long _vq_quantlist__44un1__p5_0[] = {
  138771. 4,
  138772. 3,
  138773. 5,
  138774. 2,
  138775. 6,
  138776. 1,
  138777. 7,
  138778. 0,
  138779. 8,
  138780. };
  138781. static long _vq_lengthlist__44un1__p5_0[] = {
  138782. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138783. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138784. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138785. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138786. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138787. 12,
  138788. };
  138789. static float _vq_quantthresh__44un1__p5_0[] = {
  138790. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138791. };
  138792. static long _vq_quantmap__44un1__p5_0[] = {
  138793. 7, 5, 3, 1, 0, 2, 4, 6,
  138794. 8,
  138795. };
  138796. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138797. _vq_quantthresh__44un1__p5_0,
  138798. _vq_quantmap__44un1__p5_0,
  138799. 9,
  138800. 9
  138801. };
  138802. static static_codebook _44un1__p5_0 = {
  138803. 2, 81,
  138804. _vq_lengthlist__44un1__p5_0,
  138805. 1, -531628032, 1611661312, 4, 0,
  138806. _vq_quantlist__44un1__p5_0,
  138807. NULL,
  138808. &_vq_auxt__44un1__p5_0,
  138809. NULL,
  138810. 0
  138811. };
  138812. static long _vq_quantlist__44un1__p6_0[] = {
  138813. 6,
  138814. 5,
  138815. 7,
  138816. 4,
  138817. 8,
  138818. 3,
  138819. 9,
  138820. 2,
  138821. 10,
  138822. 1,
  138823. 11,
  138824. 0,
  138825. 12,
  138826. };
  138827. static long _vq_lengthlist__44un1__p6_0[] = {
  138828. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138829. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138830. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138831. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138832. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138833. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138834. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138835. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138836. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138837. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138838. 16, 0,15,18,18, 0,16, 0, 0,
  138839. };
  138840. static float _vq_quantthresh__44un1__p6_0[] = {
  138841. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138842. 12.5, 17.5, 22.5, 27.5,
  138843. };
  138844. static long _vq_quantmap__44un1__p6_0[] = {
  138845. 11, 9, 7, 5, 3, 1, 0, 2,
  138846. 4, 6, 8, 10, 12,
  138847. };
  138848. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138849. _vq_quantthresh__44un1__p6_0,
  138850. _vq_quantmap__44un1__p6_0,
  138851. 13,
  138852. 13
  138853. };
  138854. static static_codebook _44un1__p6_0 = {
  138855. 2, 169,
  138856. _vq_lengthlist__44un1__p6_0,
  138857. 1, -526516224, 1616117760, 4, 0,
  138858. _vq_quantlist__44un1__p6_0,
  138859. NULL,
  138860. &_vq_auxt__44un1__p6_0,
  138861. NULL,
  138862. 0
  138863. };
  138864. static long _vq_quantlist__44un1__p6_1[] = {
  138865. 2,
  138866. 1,
  138867. 3,
  138868. 0,
  138869. 4,
  138870. };
  138871. static long _vq_lengthlist__44un1__p6_1[] = {
  138872. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138873. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138874. };
  138875. static float _vq_quantthresh__44un1__p6_1[] = {
  138876. -1.5, -0.5, 0.5, 1.5,
  138877. };
  138878. static long _vq_quantmap__44un1__p6_1[] = {
  138879. 3, 1, 0, 2, 4,
  138880. };
  138881. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138882. _vq_quantthresh__44un1__p6_1,
  138883. _vq_quantmap__44un1__p6_1,
  138884. 5,
  138885. 5
  138886. };
  138887. static static_codebook _44un1__p6_1 = {
  138888. 2, 25,
  138889. _vq_lengthlist__44un1__p6_1,
  138890. 1, -533725184, 1611661312, 3, 0,
  138891. _vq_quantlist__44un1__p6_1,
  138892. NULL,
  138893. &_vq_auxt__44un1__p6_1,
  138894. NULL,
  138895. 0
  138896. };
  138897. static long _vq_quantlist__44un1__p7_0[] = {
  138898. 2,
  138899. 1,
  138900. 3,
  138901. 0,
  138902. 4,
  138903. };
  138904. static long _vq_lengthlist__44un1__p7_0[] = {
  138905. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138906. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138907. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138908. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138909. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138910. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138911. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138912. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138913. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138914. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138915. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138916. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138917. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138918. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138919. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138920. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138921. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138922. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138923. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138924. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138925. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138926. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138927. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138928. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138929. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138930. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138931. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138932. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138933. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138934. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138935. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138936. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138937. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138938. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138939. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138940. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138941. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138942. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138943. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138944. 10,
  138945. };
  138946. static float _vq_quantthresh__44un1__p7_0[] = {
  138947. -253.5, -84.5, 84.5, 253.5,
  138948. };
  138949. static long _vq_quantmap__44un1__p7_0[] = {
  138950. 3, 1, 0, 2, 4,
  138951. };
  138952. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138953. _vq_quantthresh__44un1__p7_0,
  138954. _vq_quantmap__44un1__p7_0,
  138955. 5,
  138956. 5
  138957. };
  138958. static static_codebook _44un1__p7_0 = {
  138959. 4, 625,
  138960. _vq_lengthlist__44un1__p7_0,
  138961. 1, -518709248, 1626677248, 3, 0,
  138962. _vq_quantlist__44un1__p7_0,
  138963. NULL,
  138964. &_vq_auxt__44un1__p7_0,
  138965. NULL,
  138966. 0
  138967. };
  138968. static long _vq_quantlist__44un1__p7_1[] = {
  138969. 6,
  138970. 5,
  138971. 7,
  138972. 4,
  138973. 8,
  138974. 3,
  138975. 9,
  138976. 2,
  138977. 10,
  138978. 1,
  138979. 11,
  138980. 0,
  138981. 12,
  138982. };
  138983. static long _vq_lengthlist__44un1__p7_1[] = {
  138984. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138985. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138986. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138987. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138988. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138989. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138990. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138991. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138992. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138993. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138994. 12,13,13,12,13,13,14,14,14,
  138995. };
  138996. static float _vq_quantthresh__44un1__p7_1[] = {
  138997. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138998. 32.5, 45.5, 58.5, 71.5,
  138999. };
  139000. static long _vq_quantmap__44un1__p7_1[] = {
  139001. 11, 9, 7, 5, 3, 1, 0, 2,
  139002. 4, 6, 8, 10, 12,
  139003. };
  139004. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  139005. _vq_quantthresh__44un1__p7_1,
  139006. _vq_quantmap__44un1__p7_1,
  139007. 13,
  139008. 13
  139009. };
  139010. static static_codebook _44un1__p7_1 = {
  139011. 2, 169,
  139012. _vq_lengthlist__44un1__p7_1,
  139013. 1, -523010048, 1618608128, 4, 0,
  139014. _vq_quantlist__44un1__p7_1,
  139015. NULL,
  139016. &_vq_auxt__44un1__p7_1,
  139017. NULL,
  139018. 0
  139019. };
  139020. static long _vq_quantlist__44un1__p7_2[] = {
  139021. 6,
  139022. 5,
  139023. 7,
  139024. 4,
  139025. 8,
  139026. 3,
  139027. 9,
  139028. 2,
  139029. 10,
  139030. 1,
  139031. 11,
  139032. 0,
  139033. 12,
  139034. };
  139035. static long _vq_lengthlist__44un1__p7_2[] = {
  139036. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  139037. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  139038. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  139039. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  139040. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  139041. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  139042. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  139043. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  139044. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  139045. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  139046. 9, 9, 9,10,10,10,10,10,10,
  139047. };
  139048. static float _vq_quantthresh__44un1__p7_2[] = {
  139049. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  139050. 2.5, 3.5, 4.5, 5.5,
  139051. };
  139052. static long _vq_quantmap__44un1__p7_2[] = {
  139053. 11, 9, 7, 5, 3, 1, 0, 2,
  139054. 4, 6, 8, 10, 12,
  139055. };
  139056. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  139057. _vq_quantthresh__44un1__p7_2,
  139058. _vq_quantmap__44un1__p7_2,
  139059. 13,
  139060. 13
  139061. };
  139062. static static_codebook _44un1__p7_2 = {
  139063. 2, 169,
  139064. _vq_lengthlist__44un1__p7_2,
  139065. 1, -531103744, 1611661312, 4, 0,
  139066. _vq_quantlist__44un1__p7_2,
  139067. NULL,
  139068. &_vq_auxt__44un1__p7_2,
  139069. NULL,
  139070. 0
  139071. };
  139072. static long _huff_lengthlist__44un1__short[] = {
  139073. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  139074. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  139075. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  139076. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  139077. };
  139078. static static_codebook _huff_book__44un1__short = {
  139079. 2, 64,
  139080. _huff_lengthlist__44un1__short,
  139081. 0, 0, 0, 0, 0,
  139082. NULL,
  139083. NULL,
  139084. NULL,
  139085. NULL,
  139086. 0
  139087. };
  139088. /*** End of inlined file: res_books_uncoupled.h ***/
  139089. static vorbis_info_residue0 _residue_44_low_un={
  139090. 0,-1, -1, 8,-1,
  139091. {0},
  139092. {-1},
  139093. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  139094. { -1, 25, -1, 45, -1, -1, -1}
  139095. };
  139096. static vorbis_info_residue0 _residue_44_mid_un={
  139097. 0,-1, -1, 10,-1,
  139098. {0},
  139099. {-1},
  139100. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  139101. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  139102. };
  139103. static vorbis_info_residue0 _residue_44_hi_un={
  139104. 0,-1, -1, 10,-1,
  139105. {0},
  139106. {-1},
  139107. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  139108. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  139109. };
  139110. static vorbis_info_mapping0 _map_nominal_u[2]={
  139111. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  139112. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  139113. };
  139114. static static_bookblock _resbook_44u_n1={
  139115. {
  139116. {0},
  139117. {0,0,&_44un1__p1_0},
  139118. {0,0,&_44un1__p2_0},
  139119. {0,0,&_44un1__p3_0},
  139120. {0,0,&_44un1__p4_0},
  139121. {0,0,&_44un1__p5_0},
  139122. {&_44un1__p6_0,&_44un1__p6_1},
  139123. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  139124. }
  139125. };
  139126. static static_bookblock _resbook_44u_0={
  139127. {
  139128. {0},
  139129. {0,0,&_44u0__p1_0},
  139130. {0,0,&_44u0__p2_0},
  139131. {0,0,&_44u0__p3_0},
  139132. {0,0,&_44u0__p4_0},
  139133. {0,0,&_44u0__p5_0},
  139134. {&_44u0__p6_0,&_44u0__p6_1},
  139135. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  139136. }
  139137. };
  139138. static static_bookblock _resbook_44u_1={
  139139. {
  139140. {0},
  139141. {0,0,&_44u1__p1_0},
  139142. {0,0,&_44u1__p2_0},
  139143. {0,0,&_44u1__p3_0},
  139144. {0,0,&_44u1__p4_0},
  139145. {0,0,&_44u1__p5_0},
  139146. {&_44u1__p6_0,&_44u1__p6_1},
  139147. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  139148. }
  139149. };
  139150. static static_bookblock _resbook_44u_2={
  139151. {
  139152. {0},
  139153. {0,0,&_44u2__p1_0},
  139154. {0,0,&_44u2__p2_0},
  139155. {0,0,&_44u2__p3_0},
  139156. {0,0,&_44u2__p4_0},
  139157. {0,0,&_44u2__p5_0},
  139158. {&_44u2__p6_0,&_44u2__p6_1},
  139159. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  139160. }
  139161. };
  139162. static static_bookblock _resbook_44u_3={
  139163. {
  139164. {0},
  139165. {0,0,&_44u3__p1_0},
  139166. {0,0,&_44u3__p2_0},
  139167. {0,0,&_44u3__p3_0},
  139168. {0,0,&_44u3__p4_0},
  139169. {0,0,&_44u3__p5_0},
  139170. {&_44u3__p6_0,&_44u3__p6_1},
  139171. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  139172. }
  139173. };
  139174. static static_bookblock _resbook_44u_4={
  139175. {
  139176. {0},
  139177. {0,0,&_44u4__p1_0},
  139178. {0,0,&_44u4__p2_0},
  139179. {0,0,&_44u4__p3_0},
  139180. {0,0,&_44u4__p4_0},
  139181. {0,0,&_44u4__p5_0},
  139182. {&_44u4__p6_0,&_44u4__p6_1},
  139183. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  139184. }
  139185. };
  139186. static static_bookblock _resbook_44u_5={
  139187. {
  139188. {0},
  139189. {0,0,&_44u5__p1_0},
  139190. {0,0,&_44u5__p2_0},
  139191. {0,0,&_44u5__p3_0},
  139192. {0,0,&_44u5__p4_0},
  139193. {0,0,&_44u5__p5_0},
  139194. {0,0,&_44u5__p6_0},
  139195. {&_44u5__p7_0,&_44u5__p7_1},
  139196. {&_44u5__p8_0,&_44u5__p8_1},
  139197. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  139198. }
  139199. };
  139200. static static_bookblock _resbook_44u_6={
  139201. {
  139202. {0},
  139203. {0,0,&_44u6__p1_0},
  139204. {0,0,&_44u6__p2_0},
  139205. {0,0,&_44u6__p3_0},
  139206. {0,0,&_44u6__p4_0},
  139207. {0,0,&_44u6__p5_0},
  139208. {0,0,&_44u6__p6_0},
  139209. {&_44u6__p7_0,&_44u6__p7_1},
  139210. {&_44u6__p8_0,&_44u6__p8_1},
  139211. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  139212. }
  139213. };
  139214. static static_bookblock _resbook_44u_7={
  139215. {
  139216. {0},
  139217. {0,0,&_44u7__p1_0},
  139218. {0,0,&_44u7__p2_0},
  139219. {0,0,&_44u7__p3_0},
  139220. {0,0,&_44u7__p4_0},
  139221. {0,0,&_44u7__p5_0},
  139222. {0,0,&_44u7__p6_0},
  139223. {&_44u7__p7_0,&_44u7__p7_1},
  139224. {&_44u7__p8_0,&_44u7__p8_1},
  139225. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  139226. }
  139227. };
  139228. static static_bookblock _resbook_44u_8={
  139229. {
  139230. {0},
  139231. {0,0,&_44u8_p1_0},
  139232. {0,0,&_44u8_p2_0},
  139233. {0,0,&_44u8_p3_0},
  139234. {0,0,&_44u8_p4_0},
  139235. {&_44u8_p5_0,&_44u8_p5_1},
  139236. {&_44u8_p6_0,&_44u8_p6_1},
  139237. {&_44u8_p7_0,&_44u8_p7_1},
  139238. {&_44u8_p8_0,&_44u8_p8_1},
  139239. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  139240. }
  139241. };
  139242. static static_bookblock _resbook_44u_9={
  139243. {
  139244. {0},
  139245. {0,0,&_44u9_p1_0},
  139246. {0,0,&_44u9_p2_0},
  139247. {0,0,&_44u9_p3_0},
  139248. {0,0,&_44u9_p4_0},
  139249. {&_44u9_p5_0,&_44u9_p5_1},
  139250. {&_44u9_p6_0,&_44u9_p6_1},
  139251. {&_44u9_p7_0,&_44u9_p7_1},
  139252. {&_44u9_p8_0,&_44u9_p8_1},
  139253. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  139254. }
  139255. };
  139256. static vorbis_residue_template _res_44u_n1[]={
  139257. {1,0, &_residue_44_low_un,
  139258. &_huff_book__44un1__short,&_huff_book__44un1__short,
  139259. &_resbook_44u_n1,&_resbook_44u_n1},
  139260. {1,0, &_residue_44_low_un,
  139261. &_huff_book__44un1__long,&_huff_book__44un1__long,
  139262. &_resbook_44u_n1,&_resbook_44u_n1}
  139263. };
  139264. static vorbis_residue_template _res_44u_0[]={
  139265. {1,0, &_residue_44_low_un,
  139266. &_huff_book__44u0__short,&_huff_book__44u0__short,
  139267. &_resbook_44u_0,&_resbook_44u_0},
  139268. {1,0, &_residue_44_low_un,
  139269. &_huff_book__44u0__long,&_huff_book__44u0__long,
  139270. &_resbook_44u_0,&_resbook_44u_0}
  139271. };
  139272. static vorbis_residue_template _res_44u_1[]={
  139273. {1,0, &_residue_44_low_un,
  139274. &_huff_book__44u1__short,&_huff_book__44u1__short,
  139275. &_resbook_44u_1,&_resbook_44u_1},
  139276. {1,0, &_residue_44_low_un,
  139277. &_huff_book__44u1__long,&_huff_book__44u1__long,
  139278. &_resbook_44u_1,&_resbook_44u_1}
  139279. };
  139280. static vorbis_residue_template _res_44u_2[]={
  139281. {1,0, &_residue_44_low_un,
  139282. &_huff_book__44u2__short,&_huff_book__44u2__short,
  139283. &_resbook_44u_2,&_resbook_44u_2},
  139284. {1,0, &_residue_44_low_un,
  139285. &_huff_book__44u2__long,&_huff_book__44u2__long,
  139286. &_resbook_44u_2,&_resbook_44u_2}
  139287. };
  139288. static vorbis_residue_template _res_44u_3[]={
  139289. {1,0, &_residue_44_low_un,
  139290. &_huff_book__44u3__short,&_huff_book__44u3__short,
  139291. &_resbook_44u_3,&_resbook_44u_3},
  139292. {1,0, &_residue_44_low_un,
  139293. &_huff_book__44u3__long,&_huff_book__44u3__long,
  139294. &_resbook_44u_3,&_resbook_44u_3}
  139295. };
  139296. static vorbis_residue_template _res_44u_4[]={
  139297. {1,0, &_residue_44_low_un,
  139298. &_huff_book__44u4__short,&_huff_book__44u4__short,
  139299. &_resbook_44u_4,&_resbook_44u_4},
  139300. {1,0, &_residue_44_low_un,
  139301. &_huff_book__44u4__long,&_huff_book__44u4__long,
  139302. &_resbook_44u_4,&_resbook_44u_4}
  139303. };
  139304. static vorbis_residue_template _res_44u_5[]={
  139305. {1,0, &_residue_44_mid_un,
  139306. &_huff_book__44u5__short,&_huff_book__44u5__short,
  139307. &_resbook_44u_5,&_resbook_44u_5},
  139308. {1,0, &_residue_44_mid_un,
  139309. &_huff_book__44u5__long,&_huff_book__44u5__long,
  139310. &_resbook_44u_5,&_resbook_44u_5}
  139311. };
  139312. static vorbis_residue_template _res_44u_6[]={
  139313. {1,0, &_residue_44_mid_un,
  139314. &_huff_book__44u6__short,&_huff_book__44u6__short,
  139315. &_resbook_44u_6,&_resbook_44u_6},
  139316. {1,0, &_residue_44_mid_un,
  139317. &_huff_book__44u6__long,&_huff_book__44u6__long,
  139318. &_resbook_44u_6,&_resbook_44u_6}
  139319. };
  139320. static vorbis_residue_template _res_44u_7[]={
  139321. {1,0, &_residue_44_mid_un,
  139322. &_huff_book__44u7__short,&_huff_book__44u7__short,
  139323. &_resbook_44u_7,&_resbook_44u_7},
  139324. {1,0, &_residue_44_mid_un,
  139325. &_huff_book__44u7__long,&_huff_book__44u7__long,
  139326. &_resbook_44u_7,&_resbook_44u_7}
  139327. };
  139328. static vorbis_residue_template _res_44u_8[]={
  139329. {1,0, &_residue_44_hi_un,
  139330. &_huff_book__44u8__short,&_huff_book__44u8__short,
  139331. &_resbook_44u_8,&_resbook_44u_8},
  139332. {1,0, &_residue_44_hi_un,
  139333. &_huff_book__44u8__long,&_huff_book__44u8__long,
  139334. &_resbook_44u_8,&_resbook_44u_8}
  139335. };
  139336. static vorbis_residue_template _res_44u_9[]={
  139337. {1,0, &_residue_44_hi_un,
  139338. &_huff_book__44u9__short,&_huff_book__44u9__short,
  139339. &_resbook_44u_9,&_resbook_44u_9},
  139340. {1,0, &_residue_44_hi_un,
  139341. &_huff_book__44u9__long,&_huff_book__44u9__long,
  139342. &_resbook_44u_9,&_resbook_44u_9}
  139343. };
  139344. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  139345. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  139346. { _map_nominal_u, _res_44u_0 }, /* 0 */
  139347. { _map_nominal_u, _res_44u_1 }, /* 1 */
  139348. { _map_nominal_u, _res_44u_2 }, /* 2 */
  139349. { _map_nominal_u, _res_44u_3 }, /* 3 */
  139350. { _map_nominal_u, _res_44u_4 }, /* 4 */
  139351. { _map_nominal_u, _res_44u_5 }, /* 5 */
  139352. { _map_nominal_u, _res_44u_6 }, /* 6 */
  139353. { _map_nominal_u, _res_44u_7 }, /* 7 */
  139354. { _map_nominal_u, _res_44u_8 }, /* 8 */
  139355. { _map_nominal_u, _res_44u_9 }, /* 9 */
  139356. };
  139357. /*** End of inlined file: residue_44u.h ***/
  139358. static double rate_mapping_44_un[12]={
  139359. 32000.,48000.,60000.,70000.,80000.,86000.,
  139360. 96000.,110000.,120000.,140000.,160000.,240001.
  139361. };
  139362. ve_setup_data_template ve_setup_44_uncoupled={
  139363. 11,
  139364. rate_mapping_44_un,
  139365. quality_mapping_44,
  139366. -1,
  139367. 40000,
  139368. 50000,
  139369. blocksize_short_44,
  139370. blocksize_long_44,
  139371. _psy_tone_masteratt_44,
  139372. _psy_tone_0dB,
  139373. _psy_tone_suppress,
  139374. _vp_tonemask_adj_otherblock,
  139375. _vp_tonemask_adj_longblock,
  139376. _vp_tonemask_adj_otherblock,
  139377. _psy_noiseguards_44,
  139378. _psy_noisebias_impulse,
  139379. _psy_noisebias_padding,
  139380. _psy_noisebias_trans,
  139381. _psy_noisebias_long,
  139382. _psy_noise_suppress,
  139383. _psy_compand_44,
  139384. _psy_compand_short_mapping,
  139385. _psy_compand_long_mapping,
  139386. {_noise_start_short_44,_noise_start_long_44},
  139387. {_noise_part_short_44,_noise_part_long_44},
  139388. _noise_thresh_44,
  139389. _psy_ath_floater,
  139390. _psy_ath_abs,
  139391. _psy_lowpass_44,
  139392. _psy_global_44,
  139393. _global_mapping_44,
  139394. NULL,
  139395. _floor_books,
  139396. _floor,
  139397. _floor_short_mapping_44,
  139398. _floor_long_mapping_44,
  139399. _mapres_template_44_uncoupled
  139400. };
  139401. /*** End of inlined file: setup_44u.h ***/
  139402. /*** Start of inlined file: setup_32.h ***/
  139403. static double rate_mapping_32[12]={
  139404. 18000.,28000.,35000.,45000.,56000.,60000.,
  139405. 75000.,90000.,100000.,115000.,150000.,190000.,
  139406. };
  139407. static double rate_mapping_32_un[12]={
  139408. 30000.,42000.,52000.,64000.,72000.,78000.,
  139409. 86000.,92000.,110000.,120000.,140000.,190000.,
  139410. };
  139411. static double _psy_lowpass_32[12]={
  139412. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  139413. };
  139414. ve_setup_data_template ve_setup_32_stereo={
  139415. 11,
  139416. rate_mapping_32,
  139417. quality_mapping_44,
  139418. 2,
  139419. 26000,
  139420. 40000,
  139421. blocksize_short_44,
  139422. blocksize_long_44,
  139423. _psy_tone_masteratt_44,
  139424. _psy_tone_0dB,
  139425. _psy_tone_suppress,
  139426. _vp_tonemask_adj_otherblock,
  139427. _vp_tonemask_adj_longblock,
  139428. _vp_tonemask_adj_otherblock,
  139429. _psy_noiseguards_44,
  139430. _psy_noisebias_impulse,
  139431. _psy_noisebias_padding,
  139432. _psy_noisebias_trans,
  139433. _psy_noisebias_long,
  139434. _psy_noise_suppress,
  139435. _psy_compand_44,
  139436. _psy_compand_short_mapping,
  139437. _psy_compand_long_mapping,
  139438. {_noise_start_short_44,_noise_start_long_44},
  139439. {_noise_part_short_44,_noise_part_long_44},
  139440. _noise_thresh_44,
  139441. _psy_ath_floater,
  139442. _psy_ath_abs,
  139443. _psy_lowpass_32,
  139444. _psy_global_44,
  139445. _global_mapping_44,
  139446. _psy_stereo_modes_44,
  139447. _floor_books,
  139448. _floor,
  139449. _floor_short_mapping_44,
  139450. _floor_long_mapping_44,
  139451. _mapres_template_44_stereo
  139452. };
  139453. ve_setup_data_template ve_setup_32_uncoupled={
  139454. 11,
  139455. rate_mapping_32_un,
  139456. quality_mapping_44,
  139457. -1,
  139458. 26000,
  139459. 40000,
  139460. blocksize_short_44,
  139461. blocksize_long_44,
  139462. _psy_tone_masteratt_44,
  139463. _psy_tone_0dB,
  139464. _psy_tone_suppress,
  139465. _vp_tonemask_adj_otherblock,
  139466. _vp_tonemask_adj_longblock,
  139467. _vp_tonemask_adj_otherblock,
  139468. _psy_noiseguards_44,
  139469. _psy_noisebias_impulse,
  139470. _psy_noisebias_padding,
  139471. _psy_noisebias_trans,
  139472. _psy_noisebias_long,
  139473. _psy_noise_suppress,
  139474. _psy_compand_44,
  139475. _psy_compand_short_mapping,
  139476. _psy_compand_long_mapping,
  139477. {_noise_start_short_44,_noise_start_long_44},
  139478. {_noise_part_short_44,_noise_part_long_44},
  139479. _noise_thresh_44,
  139480. _psy_ath_floater,
  139481. _psy_ath_abs,
  139482. _psy_lowpass_32,
  139483. _psy_global_44,
  139484. _global_mapping_44,
  139485. NULL,
  139486. _floor_books,
  139487. _floor,
  139488. _floor_short_mapping_44,
  139489. _floor_long_mapping_44,
  139490. _mapres_template_44_uncoupled
  139491. };
  139492. /*** End of inlined file: setup_32.h ***/
  139493. /*** Start of inlined file: setup_8.h ***/
  139494. /*** Start of inlined file: psych_8.h ***/
  139495. static att3 _psy_tone_masteratt_8[3]={
  139496. {{ 32, 25, 12}, 0, 0}, /* 0 */
  139497. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139498. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139499. };
  139500. static vp_adjblock _vp_tonemask_adj_8[3]={
  139501. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139502. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139503. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  139504. };
  139505. static noise3 _psy_noisebias_8[3]={
  139506. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139507. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  139508. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139509. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139510. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139511. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139512. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139513. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139514. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139515. };
  139516. static adj_stereo _psy_stereo_modes_8[3]={
  139517. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139518. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139519. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139520. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139521. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139522. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139523. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139524. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139525. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139526. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139527. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139528. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139529. };
  139530. static noiseguard _psy_noiseguards_8[2]={
  139531. {10,10,-1},
  139532. {10,10,-1},
  139533. };
  139534. static compandblock _psy_compand_8[2]={
  139535. {{
  139536. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139537. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139538. 12,12,13,13,14,14,15, 15, /* 23dB */
  139539. 16,16,17,17,17,18,18, 19, /* 31dB */
  139540. 19,19,20,21,22,23,24, 25, /* 39dB */
  139541. }},
  139542. {{
  139543. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139544. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139545. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139546. 9,10,11,12,13,14,15, 16, /* 31dB */
  139547. 17,18,19,20,21,22,23, 24, /* 39dB */
  139548. }},
  139549. };
  139550. static double _psy_lowpass_8[3]={3.,4.,4.};
  139551. static int _noise_start_8[2]={
  139552. 64,64,
  139553. };
  139554. static int _noise_part_8[2]={
  139555. 8,8,
  139556. };
  139557. static int _psy_ath_floater_8[3]={
  139558. -100,-100,-105,
  139559. };
  139560. static int _psy_ath_abs_8[3]={
  139561. -130,-130,-140,
  139562. };
  139563. /*** End of inlined file: psych_8.h ***/
  139564. /*** Start of inlined file: residue_8.h ***/
  139565. static static_bookblock _resbook_8s_0={
  139566. {
  139567. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139568. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139569. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139570. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139571. }
  139572. };
  139573. static static_bookblock _resbook_8s_1={
  139574. {
  139575. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139576. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139577. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139578. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139579. }
  139580. };
  139581. static vorbis_residue_template _res_8s_0[]={
  139582. {2,0, &_residue_44_mid,
  139583. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139584. &_resbook_8s_0,&_resbook_8s_0},
  139585. };
  139586. static vorbis_residue_template _res_8s_1[]={
  139587. {2,0, &_residue_44_mid,
  139588. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139589. &_resbook_8s_1,&_resbook_8s_1},
  139590. };
  139591. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139592. { _map_nominal, _res_8s_0 }, /* 0 */
  139593. { _map_nominal, _res_8s_1 }, /* 1 */
  139594. };
  139595. static static_bookblock _resbook_8u_0={
  139596. {
  139597. {0},
  139598. {0,0,&_8u0__p1_0},
  139599. {0,0,&_8u0__p2_0},
  139600. {0,0,&_8u0__p3_0},
  139601. {0,0,&_8u0__p4_0},
  139602. {0,0,&_8u0__p5_0},
  139603. {&_8u0__p6_0,&_8u0__p6_1},
  139604. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139605. }
  139606. };
  139607. static static_bookblock _resbook_8u_1={
  139608. {
  139609. {0},
  139610. {0,0,&_8u1__p1_0},
  139611. {0,0,&_8u1__p2_0},
  139612. {0,0,&_8u1__p3_0},
  139613. {0,0,&_8u1__p4_0},
  139614. {0,0,&_8u1__p5_0},
  139615. {0,0,&_8u1__p6_0},
  139616. {&_8u1__p7_0,&_8u1__p7_1},
  139617. {&_8u1__p8_0,&_8u1__p8_1},
  139618. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139619. }
  139620. };
  139621. static vorbis_residue_template _res_8u_0[]={
  139622. {1,0, &_residue_44_low_un,
  139623. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139624. &_resbook_8u_0,&_resbook_8u_0},
  139625. };
  139626. static vorbis_residue_template _res_8u_1[]={
  139627. {1,0, &_residue_44_mid_un,
  139628. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139629. &_resbook_8u_1,&_resbook_8u_1},
  139630. };
  139631. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139632. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139633. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139634. };
  139635. /*** End of inlined file: residue_8.h ***/
  139636. static int blocksize_8[2]={
  139637. 512,512
  139638. };
  139639. static int _floor_mapping_8[2]={
  139640. 6,6,
  139641. };
  139642. static double rate_mapping_8[3]={
  139643. 6000.,9000.,32000.,
  139644. };
  139645. static double rate_mapping_8_uncoupled[3]={
  139646. 8000.,14000.,42000.,
  139647. };
  139648. static double quality_mapping_8[3]={
  139649. -.1,.0,1.
  139650. };
  139651. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139652. static double _global_mapping_8[3]={ 1., 2., 3. };
  139653. ve_setup_data_template ve_setup_8_stereo={
  139654. 2,
  139655. rate_mapping_8,
  139656. quality_mapping_8,
  139657. 2,
  139658. 8000,
  139659. 9000,
  139660. blocksize_8,
  139661. blocksize_8,
  139662. _psy_tone_masteratt_8,
  139663. _psy_tone_0dB,
  139664. _psy_tone_suppress,
  139665. _vp_tonemask_adj_8,
  139666. NULL,
  139667. _vp_tonemask_adj_8,
  139668. _psy_noiseguards_8,
  139669. _psy_noisebias_8,
  139670. _psy_noisebias_8,
  139671. NULL,
  139672. NULL,
  139673. _psy_noise_suppress,
  139674. _psy_compand_8,
  139675. _psy_compand_8_mapping,
  139676. NULL,
  139677. {_noise_start_8,_noise_start_8},
  139678. {_noise_part_8,_noise_part_8},
  139679. _noise_thresh_5only,
  139680. _psy_ath_floater_8,
  139681. _psy_ath_abs_8,
  139682. _psy_lowpass_8,
  139683. _psy_global_44,
  139684. _global_mapping_8,
  139685. _psy_stereo_modes_8,
  139686. _floor_books,
  139687. _floor,
  139688. _floor_mapping_8,
  139689. NULL,
  139690. _mapres_template_8_stereo
  139691. };
  139692. ve_setup_data_template ve_setup_8_uncoupled={
  139693. 2,
  139694. rate_mapping_8_uncoupled,
  139695. quality_mapping_8,
  139696. -1,
  139697. 8000,
  139698. 9000,
  139699. blocksize_8,
  139700. blocksize_8,
  139701. _psy_tone_masteratt_8,
  139702. _psy_tone_0dB,
  139703. _psy_tone_suppress,
  139704. _vp_tonemask_adj_8,
  139705. NULL,
  139706. _vp_tonemask_adj_8,
  139707. _psy_noiseguards_8,
  139708. _psy_noisebias_8,
  139709. _psy_noisebias_8,
  139710. NULL,
  139711. NULL,
  139712. _psy_noise_suppress,
  139713. _psy_compand_8,
  139714. _psy_compand_8_mapping,
  139715. NULL,
  139716. {_noise_start_8,_noise_start_8},
  139717. {_noise_part_8,_noise_part_8},
  139718. _noise_thresh_5only,
  139719. _psy_ath_floater_8,
  139720. _psy_ath_abs_8,
  139721. _psy_lowpass_8,
  139722. _psy_global_44,
  139723. _global_mapping_8,
  139724. _psy_stereo_modes_8,
  139725. _floor_books,
  139726. _floor,
  139727. _floor_mapping_8,
  139728. NULL,
  139729. _mapres_template_8_uncoupled
  139730. };
  139731. /*** End of inlined file: setup_8.h ***/
  139732. /*** Start of inlined file: setup_11.h ***/
  139733. /*** Start of inlined file: psych_11.h ***/
  139734. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139735. static att3 _psy_tone_masteratt_11[3]={
  139736. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139737. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139738. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139739. };
  139740. static vp_adjblock _vp_tonemask_adj_11[3]={
  139741. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139742. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139743. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139744. };
  139745. static noise3 _psy_noisebias_11[3]={
  139746. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139747. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139748. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139749. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139750. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139751. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139752. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139753. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139754. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139755. };
  139756. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139757. /*** End of inlined file: psych_11.h ***/
  139758. static int blocksize_11[2]={
  139759. 512,512
  139760. };
  139761. static int _floor_mapping_11[2]={
  139762. 6,6,
  139763. };
  139764. static double rate_mapping_11[3]={
  139765. 8000.,13000.,44000.,
  139766. };
  139767. static double rate_mapping_11_uncoupled[3]={
  139768. 12000.,20000.,50000.,
  139769. };
  139770. static double quality_mapping_11[3]={
  139771. -.1,.0,1.
  139772. };
  139773. ve_setup_data_template ve_setup_11_stereo={
  139774. 2,
  139775. rate_mapping_11,
  139776. quality_mapping_11,
  139777. 2,
  139778. 9000,
  139779. 15000,
  139780. blocksize_11,
  139781. blocksize_11,
  139782. _psy_tone_masteratt_11,
  139783. _psy_tone_0dB,
  139784. _psy_tone_suppress,
  139785. _vp_tonemask_adj_11,
  139786. NULL,
  139787. _vp_tonemask_adj_11,
  139788. _psy_noiseguards_8,
  139789. _psy_noisebias_11,
  139790. _psy_noisebias_11,
  139791. NULL,
  139792. NULL,
  139793. _psy_noise_suppress,
  139794. _psy_compand_8,
  139795. _psy_compand_8_mapping,
  139796. NULL,
  139797. {_noise_start_8,_noise_start_8},
  139798. {_noise_part_8,_noise_part_8},
  139799. _noise_thresh_11,
  139800. _psy_ath_floater_8,
  139801. _psy_ath_abs_8,
  139802. _psy_lowpass_11,
  139803. _psy_global_44,
  139804. _global_mapping_8,
  139805. _psy_stereo_modes_8,
  139806. _floor_books,
  139807. _floor,
  139808. _floor_mapping_11,
  139809. NULL,
  139810. _mapres_template_8_stereo
  139811. };
  139812. ve_setup_data_template ve_setup_11_uncoupled={
  139813. 2,
  139814. rate_mapping_11_uncoupled,
  139815. quality_mapping_11,
  139816. -1,
  139817. 9000,
  139818. 15000,
  139819. blocksize_11,
  139820. blocksize_11,
  139821. _psy_tone_masteratt_11,
  139822. _psy_tone_0dB,
  139823. _psy_tone_suppress,
  139824. _vp_tonemask_adj_11,
  139825. NULL,
  139826. _vp_tonemask_adj_11,
  139827. _psy_noiseguards_8,
  139828. _psy_noisebias_11,
  139829. _psy_noisebias_11,
  139830. NULL,
  139831. NULL,
  139832. _psy_noise_suppress,
  139833. _psy_compand_8,
  139834. _psy_compand_8_mapping,
  139835. NULL,
  139836. {_noise_start_8,_noise_start_8},
  139837. {_noise_part_8,_noise_part_8},
  139838. _noise_thresh_11,
  139839. _psy_ath_floater_8,
  139840. _psy_ath_abs_8,
  139841. _psy_lowpass_11,
  139842. _psy_global_44,
  139843. _global_mapping_8,
  139844. _psy_stereo_modes_8,
  139845. _floor_books,
  139846. _floor,
  139847. _floor_mapping_11,
  139848. NULL,
  139849. _mapres_template_8_uncoupled
  139850. };
  139851. /*** End of inlined file: setup_11.h ***/
  139852. /*** Start of inlined file: setup_16.h ***/
  139853. /*** Start of inlined file: psych_16.h ***/
  139854. static adj_stereo _psy_stereo_modes_16[4]={
  139855. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139856. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139857. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139858. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139859. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139860. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139861. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139862. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139863. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139864. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139865. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139866. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139867. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139868. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139869. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139870. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139871. };
  139872. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139873. static att3 _psy_tone_masteratt_16[4]={
  139874. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139875. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139876. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139877. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139878. };
  139879. static vp_adjblock _vp_tonemask_adj_16[4]={
  139880. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139881. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139882. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139883. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139884. };
  139885. static noise3 _psy_noisebias_16_short[4]={
  139886. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139887. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139888. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139889. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139890. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139891. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139892. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139893. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139894. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139895. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139896. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139897. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139898. };
  139899. static noise3 _psy_noisebias_16_impulse[4]={
  139900. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139901. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139902. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139903. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139904. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139905. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139906. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139907. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139908. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139909. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139910. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139911. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139912. };
  139913. static noise3 _psy_noisebias_16[4]={
  139914. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139915. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139916. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139917. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139918. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139919. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139920. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139921. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139922. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139923. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139924. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139925. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139926. };
  139927. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139928. static int _noise_start_16[3]={ 256,256,9999 };
  139929. static int _noise_part_16[4]={ 8,8,8,8 };
  139930. static int _psy_ath_floater_16[4]={
  139931. -100,-100,-100,-105,
  139932. };
  139933. static int _psy_ath_abs_16[4]={
  139934. -130,-130,-130,-140,
  139935. };
  139936. /*** End of inlined file: psych_16.h ***/
  139937. /*** Start of inlined file: residue_16.h ***/
  139938. static static_bookblock _resbook_16s_0={
  139939. {
  139940. {0},
  139941. {0,0,&_16c0_s_p1_0},
  139942. {0,0,&_16c0_s_p2_0},
  139943. {0,0,&_16c0_s_p3_0},
  139944. {0,0,&_16c0_s_p4_0},
  139945. {0,0,&_16c0_s_p5_0},
  139946. {0,0,&_16c0_s_p6_0},
  139947. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139948. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139949. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139950. }
  139951. };
  139952. static static_bookblock _resbook_16s_1={
  139953. {
  139954. {0},
  139955. {0,0,&_16c1_s_p1_0},
  139956. {0,0,&_16c1_s_p2_0},
  139957. {0,0,&_16c1_s_p3_0},
  139958. {0,0,&_16c1_s_p4_0},
  139959. {0,0,&_16c1_s_p5_0},
  139960. {0,0,&_16c1_s_p6_0},
  139961. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139962. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139963. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139964. }
  139965. };
  139966. static static_bookblock _resbook_16s_2={
  139967. {
  139968. {0},
  139969. {0,0,&_16c2_s_p1_0},
  139970. {0,0,&_16c2_s_p2_0},
  139971. {0,0,&_16c2_s_p3_0},
  139972. {0,0,&_16c2_s_p4_0},
  139973. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139974. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139975. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139976. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139977. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139978. }
  139979. };
  139980. static vorbis_residue_template _res_16s_0[]={
  139981. {2,0, &_residue_44_mid,
  139982. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139983. &_resbook_16s_0,&_resbook_16s_0},
  139984. };
  139985. static vorbis_residue_template _res_16s_1[]={
  139986. {2,0, &_residue_44_mid,
  139987. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139988. &_resbook_16s_1,&_resbook_16s_1},
  139989. {2,0, &_residue_44_mid,
  139990. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139991. &_resbook_16s_1,&_resbook_16s_1}
  139992. };
  139993. static vorbis_residue_template _res_16s_2[]={
  139994. {2,0, &_residue_44_high,
  139995. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139996. &_resbook_16s_2,&_resbook_16s_2},
  139997. {2,0, &_residue_44_high,
  139998. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139999. &_resbook_16s_2,&_resbook_16s_2}
  140000. };
  140001. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  140002. { _map_nominal, _res_16s_0 }, /* 0 */
  140003. { _map_nominal, _res_16s_1 }, /* 1 */
  140004. { _map_nominal, _res_16s_2 }, /* 2 */
  140005. };
  140006. static static_bookblock _resbook_16u_0={
  140007. {
  140008. {0},
  140009. {0,0,&_16u0__p1_0},
  140010. {0,0,&_16u0__p2_0},
  140011. {0,0,&_16u0__p3_0},
  140012. {0,0,&_16u0__p4_0},
  140013. {0,0,&_16u0__p5_0},
  140014. {&_16u0__p6_0,&_16u0__p6_1},
  140015. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  140016. }
  140017. };
  140018. static static_bookblock _resbook_16u_1={
  140019. {
  140020. {0},
  140021. {0,0,&_16u1__p1_0},
  140022. {0,0,&_16u1__p2_0},
  140023. {0,0,&_16u1__p3_0},
  140024. {0,0,&_16u1__p4_0},
  140025. {0,0,&_16u1__p5_0},
  140026. {0,0,&_16u1__p6_0},
  140027. {&_16u1__p7_0,&_16u1__p7_1},
  140028. {&_16u1__p8_0,&_16u1__p8_1},
  140029. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  140030. }
  140031. };
  140032. static static_bookblock _resbook_16u_2={
  140033. {
  140034. {0},
  140035. {0,0,&_16u2_p1_0},
  140036. {0,0,&_16u2_p2_0},
  140037. {0,0,&_16u2_p3_0},
  140038. {0,0,&_16u2_p4_0},
  140039. {&_16u2_p5_0,&_16u2_p5_1},
  140040. {&_16u2_p6_0,&_16u2_p6_1},
  140041. {&_16u2_p7_0,&_16u2_p7_1},
  140042. {&_16u2_p8_0,&_16u2_p8_1},
  140043. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  140044. }
  140045. };
  140046. static vorbis_residue_template _res_16u_0[]={
  140047. {1,0, &_residue_44_low_un,
  140048. &_huff_book__16u0__single,&_huff_book__16u0__single,
  140049. &_resbook_16u_0,&_resbook_16u_0},
  140050. };
  140051. static vorbis_residue_template _res_16u_1[]={
  140052. {1,0, &_residue_44_mid_un,
  140053. &_huff_book__16u1__short,&_huff_book__16u1__short,
  140054. &_resbook_16u_1,&_resbook_16u_1},
  140055. {1,0, &_residue_44_mid_un,
  140056. &_huff_book__16u1__long,&_huff_book__16u1__long,
  140057. &_resbook_16u_1,&_resbook_16u_1}
  140058. };
  140059. static vorbis_residue_template _res_16u_2[]={
  140060. {1,0, &_residue_44_hi_un,
  140061. &_huff_book__16u2__short,&_huff_book__16u2__short,
  140062. &_resbook_16u_2,&_resbook_16u_2},
  140063. {1,0, &_residue_44_hi_un,
  140064. &_huff_book__16u2__long,&_huff_book__16u2__long,
  140065. &_resbook_16u_2,&_resbook_16u_2}
  140066. };
  140067. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  140068. { _map_nominal_u, _res_16u_0 }, /* 0 */
  140069. { _map_nominal_u, _res_16u_1 }, /* 1 */
  140070. { _map_nominal_u, _res_16u_2 }, /* 2 */
  140071. };
  140072. /*** End of inlined file: residue_16.h ***/
  140073. static int blocksize_16_short[3]={
  140074. 1024,512,512
  140075. };
  140076. static int blocksize_16_long[3]={
  140077. 1024,1024,1024
  140078. };
  140079. static int _floor_mapping_16_short[3]={
  140080. 9,3,3
  140081. };
  140082. static int _floor_mapping_16[3]={
  140083. 9,9,9
  140084. };
  140085. static double rate_mapping_16[4]={
  140086. 12000.,20000.,44000.,86000.
  140087. };
  140088. static double rate_mapping_16_uncoupled[4]={
  140089. 16000.,28000.,64000.,100000.
  140090. };
  140091. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  140092. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  140093. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  140094. ve_setup_data_template ve_setup_16_stereo={
  140095. 3,
  140096. rate_mapping_16,
  140097. quality_mapping_16,
  140098. 2,
  140099. 15000,
  140100. 19000,
  140101. blocksize_16_short,
  140102. blocksize_16_long,
  140103. _psy_tone_masteratt_16,
  140104. _psy_tone_0dB,
  140105. _psy_tone_suppress,
  140106. _vp_tonemask_adj_16,
  140107. _vp_tonemask_adj_16,
  140108. _vp_tonemask_adj_16,
  140109. _psy_noiseguards_8,
  140110. _psy_noisebias_16_impulse,
  140111. _psy_noisebias_16_short,
  140112. _psy_noisebias_16_short,
  140113. _psy_noisebias_16,
  140114. _psy_noise_suppress,
  140115. _psy_compand_8,
  140116. _psy_compand_16_mapping,
  140117. _psy_compand_16_mapping,
  140118. {_noise_start_16,_noise_start_16},
  140119. { _noise_part_16, _noise_part_16},
  140120. _noise_thresh_16,
  140121. _psy_ath_floater_16,
  140122. _psy_ath_abs_16,
  140123. _psy_lowpass_16,
  140124. _psy_global_44,
  140125. _global_mapping_16,
  140126. _psy_stereo_modes_16,
  140127. _floor_books,
  140128. _floor,
  140129. _floor_mapping_16_short,
  140130. _floor_mapping_16,
  140131. _mapres_template_16_stereo
  140132. };
  140133. ve_setup_data_template ve_setup_16_uncoupled={
  140134. 3,
  140135. rate_mapping_16_uncoupled,
  140136. quality_mapping_16,
  140137. -1,
  140138. 15000,
  140139. 19000,
  140140. blocksize_16_short,
  140141. blocksize_16_long,
  140142. _psy_tone_masteratt_16,
  140143. _psy_tone_0dB,
  140144. _psy_tone_suppress,
  140145. _vp_tonemask_adj_16,
  140146. _vp_tonemask_adj_16,
  140147. _vp_tonemask_adj_16,
  140148. _psy_noiseguards_8,
  140149. _psy_noisebias_16_impulse,
  140150. _psy_noisebias_16_short,
  140151. _psy_noisebias_16_short,
  140152. _psy_noisebias_16,
  140153. _psy_noise_suppress,
  140154. _psy_compand_8,
  140155. _psy_compand_16_mapping,
  140156. _psy_compand_16_mapping,
  140157. {_noise_start_16,_noise_start_16},
  140158. { _noise_part_16, _noise_part_16},
  140159. _noise_thresh_16,
  140160. _psy_ath_floater_16,
  140161. _psy_ath_abs_16,
  140162. _psy_lowpass_16,
  140163. _psy_global_44,
  140164. _global_mapping_16,
  140165. _psy_stereo_modes_16,
  140166. _floor_books,
  140167. _floor,
  140168. _floor_mapping_16_short,
  140169. _floor_mapping_16,
  140170. _mapres_template_16_uncoupled
  140171. };
  140172. /*** End of inlined file: setup_16.h ***/
  140173. /*** Start of inlined file: setup_22.h ***/
  140174. static double rate_mapping_22[4]={
  140175. 15000.,20000.,44000.,86000.
  140176. };
  140177. static double rate_mapping_22_uncoupled[4]={
  140178. 16000.,28000.,50000.,90000.
  140179. };
  140180. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  140181. ve_setup_data_template ve_setup_22_stereo={
  140182. 3,
  140183. rate_mapping_22,
  140184. quality_mapping_16,
  140185. 2,
  140186. 19000,
  140187. 26000,
  140188. blocksize_16_short,
  140189. blocksize_16_long,
  140190. _psy_tone_masteratt_16,
  140191. _psy_tone_0dB,
  140192. _psy_tone_suppress,
  140193. _vp_tonemask_adj_16,
  140194. _vp_tonemask_adj_16,
  140195. _vp_tonemask_adj_16,
  140196. _psy_noiseguards_8,
  140197. _psy_noisebias_16_impulse,
  140198. _psy_noisebias_16_short,
  140199. _psy_noisebias_16_short,
  140200. _psy_noisebias_16,
  140201. _psy_noise_suppress,
  140202. _psy_compand_8,
  140203. _psy_compand_8_mapping,
  140204. _psy_compand_8_mapping,
  140205. {_noise_start_16,_noise_start_16},
  140206. { _noise_part_16, _noise_part_16},
  140207. _noise_thresh_16,
  140208. _psy_ath_floater_16,
  140209. _psy_ath_abs_16,
  140210. _psy_lowpass_22,
  140211. _psy_global_44,
  140212. _global_mapping_16,
  140213. _psy_stereo_modes_16,
  140214. _floor_books,
  140215. _floor,
  140216. _floor_mapping_16_short,
  140217. _floor_mapping_16,
  140218. _mapres_template_16_stereo
  140219. };
  140220. ve_setup_data_template ve_setup_22_uncoupled={
  140221. 3,
  140222. rate_mapping_22_uncoupled,
  140223. quality_mapping_16,
  140224. -1,
  140225. 19000,
  140226. 26000,
  140227. blocksize_16_short,
  140228. blocksize_16_long,
  140229. _psy_tone_masteratt_16,
  140230. _psy_tone_0dB,
  140231. _psy_tone_suppress,
  140232. _vp_tonemask_adj_16,
  140233. _vp_tonemask_adj_16,
  140234. _vp_tonemask_adj_16,
  140235. _psy_noiseguards_8,
  140236. _psy_noisebias_16_impulse,
  140237. _psy_noisebias_16_short,
  140238. _psy_noisebias_16_short,
  140239. _psy_noisebias_16,
  140240. _psy_noise_suppress,
  140241. _psy_compand_8,
  140242. _psy_compand_8_mapping,
  140243. _psy_compand_8_mapping,
  140244. {_noise_start_16,_noise_start_16},
  140245. { _noise_part_16, _noise_part_16},
  140246. _noise_thresh_16,
  140247. _psy_ath_floater_16,
  140248. _psy_ath_abs_16,
  140249. _psy_lowpass_22,
  140250. _psy_global_44,
  140251. _global_mapping_16,
  140252. _psy_stereo_modes_16,
  140253. _floor_books,
  140254. _floor,
  140255. _floor_mapping_16_short,
  140256. _floor_mapping_16,
  140257. _mapres_template_16_uncoupled
  140258. };
  140259. /*** End of inlined file: setup_22.h ***/
  140260. /*** Start of inlined file: setup_X.h ***/
  140261. static double rate_mapping_X[12]={
  140262. -1.,-1.,-1.,-1.,-1.,-1.,
  140263. -1.,-1.,-1.,-1.,-1.,-1.
  140264. };
  140265. ve_setup_data_template ve_setup_X_stereo={
  140266. 11,
  140267. rate_mapping_X,
  140268. quality_mapping_44,
  140269. 2,
  140270. 50000,
  140271. 200000,
  140272. blocksize_short_44,
  140273. blocksize_long_44,
  140274. _psy_tone_masteratt_44,
  140275. _psy_tone_0dB,
  140276. _psy_tone_suppress,
  140277. _vp_tonemask_adj_otherblock,
  140278. _vp_tonemask_adj_longblock,
  140279. _vp_tonemask_adj_otherblock,
  140280. _psy_noiseguards_44,
  140281. _psy_noisebias_impulse,
  140282. _psy_noisebias_padding,
  140283. _psy_noisebias_trans,
  140284. _psy_noisebias_long,
  140285. _psy_noise_suppress,
  140286. _psy_compand_44,
  140287. _psy_compand_short_mapping,
  140288. _psy_compand_long_mapping,
  140289. {_noise_start_short_44,_noise_start_long_44},
  140290. {_noise_part_short_44,_noise_part_long_44},
  140291. _noise_thresh_44,
  140292. _psy_ath_floater,
  140293. _psy_ath_abs,
  140294. _psy_lowpass_44,
  140295. _psy_global_44,
  140296. _global_mapping_44,
  140297. _psy_stereo_modes_44,
  140298. _floor_books,
  140299. _floor,
  140300. _floor_short_mapping_44,
  140301. _floor_long_mapping_44,
  140302. _mapres_template_44_stereo
  140303. };
  140304. ve_setup_data_template ve_setup_X_uncoupled={
  140305. 11,
  140306. rate_mapping_X,
  140307. quality_mapping_44,
  140308. -1,
  140309. 50000,
  140310. 200000,
  140311. blocksize_short_44,
  140312. blocksize_long_44,
  140313. _psy_tone_masteratt_44,
  140314. _psy_tone_0dB,
  140315. _psy_tone_suppress,
  140316. _vp_tonemask_adj_otherblock,
  140317. _vp_tonemask_adj_longblock,
  140318. _vp_tonemask_adj_otherblock,
  140319. _psy_noiseguards_44,
  140320. _psy_noisebias_impulse,
  140321. _psy_noisebias_padding,
  140322. _psy_noisebias_trans,
  140323. _psy_noisebias_long,
  140324. _psy_noise_suppress,
  140325. _psy_compand_44,
  140326. _psy_compand_short_mapping,
  140327. _psy_compand_long_mapping,
  140328. {_noise_start_short_44,_noise_start_long_44},
  140329. {_noise_part_short_44,_noise_part_long_44},
  140330. _noise_thresh_44,
  140331. _psy_ath_floater,
  140332. _psy_ath_abs,
  140333. _psy_lowpass_44,
  140334. _psy_global_44,
  140335. _global_mapping_44,
  140336. NULL,
  140337. _floor_books,
  140338. _floor,
  140339. _floor_short_mapping_44,
  140340. _floor_long_mapping_44,
  140341. _mapres_template_44_uncoupled
  140342. };
  140343. ve_setup_data_template ve_setup_XX_stereo={
  140344. 2,
  140345. rate_mapping_X,
  140346. quality_mapping_8,
  140347. 2,
  140348. 0,
  140349. 8000,
  140350. blocksize_8,
  140351. blocksize_8,
  140352. _psy_tone_masteratt_8,
  140353. _psy_tone_0dB,
  140354. _psy_tone_suppress,
  140355. _vp_tonemask_adj_8,
  140356. NULL,
  140357. _vp_tonemask_adj_8,
  140358. _psy_noiseguards_8,
  140359. _psy_noisebias_8,
  140360. _psy_noisebias_8,
  140361. NULL,
  140362. NULL,
  140363. _psy_noise_suppress,
  140364. _psy_compand_8,
  140365. _psy_compand_8_mapping,
  140366. NULL,
  140367. {_noise_start_8,_noise_start_8},
  140368. {_noise_part_8,_noise_part_8},
  140369. _noise_thresh_5only,
  140370. _psy_ath_floater_8,
  140371. _psy_ath_abs_8,
  140372. _psy_lowpass_8,
  140373. _psy_global_44,
  140374. _global_mapping_8,
  140375. _psy_stereo_modes_8,
  140376. _floor_books,
  140377. _floor,
  140378. _floor_mapping_8,
  140379. NULL,
  140380. _mapres_template_8_stereo
  140381. };
  140382. ve_setup_data_template ve_setup_XX_uncoupled={
  140383. 2,
  140384. rate_mapping_X,
  140385. quality_mapping_8,
  140386. -1,
  140387. 0,
  140388. 8000,
  140389. blocksize_8,
  140390. blocksize_8,
  140391. _psy_tone_masteratt_8,
  140392. _psy_tone_0dB,
  140393. _psy_tone_suppress,
  140394. _vp_tonemask_adj_8,
  140395. NULL,
  140396. _vp_tonemask_adj_8,
  140397. _psy_noiseguards_8,
  140398. _psy_noisebias_8,
  140399. _psy_noisebias_8,
  140400. NULL,
  140401. NULL,
  140402. _psy_noise_suppress,
  140403. _psy_compand_8,
  140404. _psy_compand_8_mapping,
  140405. NULL,
  140406. {_noise_start_8,_noise_start_8},
  140407. {_noise_part_8,_noise_part_8},
  140408. _noise_thresh_5only,
  140409. _psy_ath_floater_8,
  140410. _psy_ath_abs_8,
  140411. _psy_lowpass_8,
  140412. _psy_global_44,
  140413. _global_mapping_8,
  140414. _psy_stereo_modes_8,
  140415. _floor_books,
  140416. _floor,
  140417. _floor_mapping_8,
  140418. NULL,
  140419. _mapres_template_8_uncoupled
  140420. };
  140421. /*** End of inlined file: setup_X.h ***/
  140422. static ve_setup_data_template *setup_list[]={
  140423. &ve_setup_44_stereo,
  140424. &ve_setup_44_uncoupled,
  140425. &ve_setup_32_stereo,
  140426. &ve_setup_32_uncoupled,
  140427. &ve_setup_22_stereo,
  140428. &ve_setup_22_uncoupled,
  140429. &ve_setup_16_stereo,
  140430. &ve_setup_16_uncoupled,
  140431. &ve_setup_11_stereo,
  140432. &ve_setup_11_uncoupled,
  140433. &ve_setup_8_stereo,
  140434. &ve_setup_8_uncoupled,
  140435. &ve_setup_X_stereo,
  140436. &ve_setup_X_uncoupled,
  140437. &ve_setup_XX_stereo,
  140438. &ve_setup_XX_uncoupled,
  140439. 0
  140440. };
  140441. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  140442. if(vi && vi->codec_setup){
  140443. vi->version=0;
  140444. vi->channels=ch;
  140445. vi->rate=rate;
  140446. return(0);
  140447. }
  140448. return(OV_EINVAL);
  140449. }
  140450. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  140451. static_codebook ***books,
  140452. vorbis_info_floor1 *in,
  140453. int *x){
  140454. int i,k,is=s;
  140455. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  140456. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140457. memcpy(f,in+x[is],sizeof(*f));
  140458. f->n=ci->blocksizes[block]>>1;
  140459. {
  140460. int partitions=f->partitions;
  140461. int maxclass=-1;
  140462. int maxbook=-1;
  140463. for(i=0;i<partitions;i++)
  140464. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  140465. for(i=0;i<=maxclass;i++){
  140466. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  140467. f->class_book[i]+=ci->books;
  140468. for(k=0;k<(1<<f->class_subs[i]);k++){
  140469. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  140470. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  140471. }
  140472. }
  140473. for(i=0;i<=maxbook;i++)
  140474. ci->book_param[ci->books++]=books[x[is]][i];
  140475. }
  140476. ci->floor_type[ci->floors]=1;
  140477. ci->floor_param[ci->floors]=f;
  140478. ci->floors++;
  140479. return;
  140480. }
  140481. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  140482. vorbis_info_psy_global *in,
  140483. double *x){
  140484. int i,is=s;
  140485. double ds=s-is;
  140486. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140487. vorbis_info_psy_global *g=&ci->psy_g_param;
  140488. memcpy(g,in+(int)x[is],sizeof(*g));
  140489. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140490. is=(int)ds;
  140491. ds-=is;
  140492. if(ds==0 && is>0){
  140493. is--;
  140494. ds=1.;
  140495. }
  140496. for(i=0;i<4;i++){
  140497. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  140498. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  140499. }
  140500. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  140501. return;
  140502. }
  140503. static void vorbis_encode_global_stereo(vorbis_info *vi,
  140504. highlevel_encode_setup *hi,
  140505. adj_stereo *p){
  140506. float s=hi->stereo_point_setting;
  140507. int i,is=s;
  140508. double ds=s-is;
  140509. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140510. vorbis_info_psy_global *g=&ci->psy_g_param;
  140511. if(p){
  140512. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  140513. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  140514. if(hi->managed){
  140515. for(i=0;i<PACKETBLOBS;i++){
  140516. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  140517. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140518. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140519. g->coupling_pkHz[i]=kHz;
  140520. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  140521. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140522. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140523. }
  140524. }else{
  140525. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140526. for(i=0;i<PACKETBLOBS;i++){
  140527. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140528. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140529. g->coupling_pkHz[i]=kHz;
  140530. }
  140531. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140532. for(i=0;i<PACKETBLOBS;i++){
  140533. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140534. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140535. }
  140536. }
  140537. }else{
  140538. for(i=0;i<PACKETBLOBS;i++){
  140539. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140540. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140541. }
  140542. }
  140543. return;
  140544. }
  140545. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140546. int *nn_start,
  140547. int *nn_partition,
  140548. double *nn_thresh,
  140549. int block){
  140550. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140551. vorbis_info_psy *p=ci->psy_param[block];
  140552. highlevel_encode_setup *hi=&ci->hi;
  140553. int is=s;
  140554. if(block>=ci->psys)
  140555. ci->psys=block+1;
  140556. if(!p){
  140557. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140558. ci->psy_param[block]=p;
  140559. }
  140560. memcpy(p,&_psy_info_template,sizeof(*p));
  140561. p->blockflag=block>>1;
  140562. if(hi->noise_normalize_p){
  140563. p->normal_channel_p=1;
  140564. p->normal_point_p=1;
  140565. p->normal_start=nn_start[is];
  140566. p->normal_partition=nn_partition[is];
  140567. p->normal_thresh=nn_thresh[is];
  140568. }
  140569. return;
  140570. }
  140571. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140572. att3 *att,
  140573. int *max,
  140574. vp_adjblock *in){
  140575. int i,is=s;
  140576. double ds=s-is;
  140577. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140578. vorbis_info_psy *p=ci->psy_param[block];
  140579. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140580. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140581. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140582. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140583. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140584. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140585. for(i=0;i<P_BANDS;i++)
  140586. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140587. return;
  140588. }
  140589. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140590. compandblock *in, double *x){
  140591. int i,is=s;
  140592. double ds=s-is;
  140593. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140594. vorbis_info_psy *p=ci->psy_param[block];
  140595. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140596. is=(int)ds;
  140597. ds-=is;
  140598. if(ds==0 && is>0){
  140599. is--;
  140600. ds=1.;
  140601. }
  140602. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140603. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140604. return;
  140605. }
  140606. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140607. int *suppress){
  140608. int is=s;
  140609. double ds=s-is;
  140610. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140611. vorbis_info_psy *p=ci->psy_param[block];
  140612. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140613. return;
  140614. }
  140615. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140616. int *suppress,
  140617. noise3 *in,
  140618. noiseguard *guard,
  140619. double userbias){
  140620. int i,is=s,j;
  140621. double ds=s-is;
  140622. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140623. vorbis_info_psy *p=ci->psy_param[block];
  140624. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140625. p->noisewindowlomin=guard[block].lo;
  140626. p->noisewindowhimin=guard[block].hi;
  140627. p->noisewindowfixed=guard[block].fixed;
  140628. for(j=0;j<P_NOISECURVES;j++)
  140629. for(i=0;i<P_BANDS;i++)
  140630. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140631. for(j=0;j<P_NOISECURVES;j++){
  140632. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140633. for(i=0;i<P_BANDS;i++){
  140634. p->noiseoff[j][i]+=userbias;
  140635. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140636. }
  140637. }
  140638. return;
  140639. }
  140640. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140641. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140642. vorbis_info_psy *p=ci->psy_param[block];
  140643. p->ath_adjatt=ci->hi.ath_floating_dB;
  140644. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140645. return;
  140646. }
  140647. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140648. int i;
  140649. for(i=0;i<ci->books;i++)
  140650. if(ci->book_param[i]==book)return(i);
  140651. return(ci->books++);
  140652. }
  140653. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140654. int *shortb,int *longb){
  140655. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140656. int is=s;
  140657. int blockshort=shortb[is];
  140658. int blocklong=longb[is];
  140659. ci->blocksizes[0]=blockshort;
  140660. ci->blocksizes[1]=blocklong;
  140661. }
  140662. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140663. int number, int block,
  140664. vorbis_residue_template *res){
  140665. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140666. int i,n;
  140667. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140668. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140669. memcpy(r,res->res,sizeof(*r));
  140670. if(ci->residues<=number)ci->residues=number+1;
  140671. switch(ci->blocksizes[block]){
  140672. case 64:case 128:case 256:
  140673. r->grouping=16;
  140674. break;
  140675. default:
  140676. r->grouping=32;
  140677. break;
  140678. }
  140679. ci->residue_type[number]=res->res_type;
  140680. n=r->end=ci->blocksizes[block]>>1;
  140681. if(res->res_type==2)
  140682. n=r->end*=vi->channels;
  140683. {
  140684. int booklist=0,k;
  140685. if(ci->hi.managed){
  140686. for(i=0;i<r->partitions;i++)
  140687. for(k=0;k<3;k++)
  140688. if(res->books_base_managed->books[i][k])
  140689. r->secondstages[i]|=(1<<k);
  140690. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140691. ci->book_param[r->groupbook]=res->book_aux_managed;
  140692. for(i=0;i<r->partitions;i++){
  140693. for(k=0;k<3;k++){
  140694. if(res->books_base_managed->books[i][k]){
  140695. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140696. r->booklist[booklist++]=bookid;
  140697. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140698. }
  140699. }
  140700. }
  140701. }else{
  140702. for(i=0;i<r->partitions;i++)
  140703. for(k=0;k<3;k++)
  140704. if(res->books_base->books[i][k])
  140705. r->secondstages[i]|=(1<<k);
  140706. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140707. ci->book_param[r->groupbook]=res->book_aux;
  140708. for(i=0;i<r->partitions;i++){
  140709. for(k=0;k<3;k++){
  140710. if(res->books_base->books[i][k]){
  140711. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140712. r->booklist[booklist++]=bookid;
  140713. ci->book_param[bookid]=res->books_base->books[i][k];
  140714. }
  140715. }
  140716. }
  140717. }
  140718. }
  140719. {
  140720. double freq=ci->hi.lowpass_kHz*1000.;
  140721. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140722. double nyq=vi->rate/2.;
  140723. long blocksize=ci->blocksizes[block]>>1;
  140724. if(freq>nyq)freq=nyq;
  140725. f->n=freq/nyq*blocksize;
  140726. if(res->limit_type){
  140727. if(ci->hi.managed)
  140728. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140729. else
  140730. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140731. if(freq>nyq)freq=nyq;
  140732. }
  140733. if(ci->residue_type[block]==2)
  140734. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140735. r->grouping;
  140736. else
  140737. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140738. r->grouping;
  140739. }
  140740. }
  140741. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140742. vorbis_mapping_template *maps){
  140743. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140744. int i,j,is=s,modes=2;
  140745. vorbis_info_mapping0 *map=maps[is].map;
  140746. vorbis_info_mode *mode=_mode_template;
  140747. vorbis_residue_template *res=maps[is].res;
  140748. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140749. for(i=0;i<modes;i++){
  140750. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140751. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140752. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140753. if(i>=ci->modes)ci->modes=i+1;
  140754. ci->map_type[i]=0;
  140755. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140756. if(i>=ci->maps)ci->maps=i+1;
  140757. for(j=0;j<map[i].submaps;j++)
  140758. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140759. ,res+map[i].residuesubmap[j]);
  140760. }
  140761. }
  140762. static double setting_to_approx_bitrate(vorbis_info *vi){
  140763. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140764. highlevel_encode_setup *hi=&ci->hi;
  140765. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140766. int is=hi->base_setting;
  140767. double ds=hi->base_setting-is;
  140768. int ch=vi->channels;
  140769. double *r=setup->rate_mapping;
  140770. if(r==NULL)
  140771. return(-1);
  140772. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140773. }
  140774. static void get_setup_template(vorbis_info *vi,
  140775. long ch,long srate,
  140776. double req,int q_or_bitrate){
  140777. int i=0,j;
  140778. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140779. highlevel_encode_setup *hi=&ci->hi;
  140780. if(q_or_bitrate)req/=ch;
  140781. while(setup_list[i]){
  140782. if(setup_list[i]->coupling_restriction==-1 ||
  140783. setup_list[i]->coupling_restriction==ch){
  140784. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140785. srate<=setup_list[i]->samplerate_max_restriction){
  140786. int mappings=setup_list[i]->mappings;
  140787. double *map=(q_or_bitrate?
  140788. setup_list[i]->rate_mapping:
  140789. setup_list[i]->quality_mapping);
  140790. if(req<map[0]){++i;continue;}
  140791. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140792. for(j=0;j<mappings;j++)
  140793. if(req>=map[j] && req<map[j+1])break;
  140794. hi->setup=setup_list[i];
  140795. if(j==mappings)
  140796. hi->base_setting=j-.001;
  140797. else{
  140798. float low=map[j];
  140799. float high=map[j+1];
  140800. float del=(req-low)/(high-low);
  140801. hi->base_setting=j+del;
  140802. }
  140803. return;
  140804. }
  140805. }
  140806. i++;
  140807. }
  140808. hi->setup=NULL;
  140809. }
  140810. int vorbis_encode_setup_init(vorbis_info *vi){
  140811. int i0=0,singleblock=0;
  140812. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140813. ve_setup_data_template *setup=NULL;
  140814. highlevel_encode_setup *hi=&ci->hi;
  140815. if(ci==NULL)return(OV_EINVAL);
  140816. if(!hi->impulse_block_p)i0=1;
  140817. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140818. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140819. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140820. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140821. setup=(ve_setup_data_template *)hi->setup;
  140822. if(setup==NULL)return(OV_EINVAL);
  140823. hi->set_in_stone=1;
  140824. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140825. setup->blocksize_short,
  140826. setup->blocksize_long);
  140827. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140828. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140829. setup->floor_books,
  140830. setup->floor_params,
  140831. setup->floor_short_mapping);
  140832. if(!singleblock)
  140833. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140834. setup->floor_books,
  140835. setup->floor_params,
  140836. setup->floor_long_mapping);
  140837. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140838. setup->global_params,
  140839. setup->global_mapping);
  140840. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140841. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140842. setup->psy_noise_normal_start[0],
  140843. setup->psy_noise_normal_partition[0],
  140844. setup->psy_noise_normal_thresh,
  140845. 0);
  140846. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140847. setup->psy_noise_normal_start[0],
  140848. setup->psy_noise_normal_partition[0],
  140849. setup->psy_noise_normal_thresh,
  140850. 1);
  140851. if(!singleblock){
  140852. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140853. setup->psy_noise_normal_start[1],
  140854. setup->psy_noise_normal_partition[1],
  140855. setup->psy_noise_normal_thresh,
  140856. 2);
  140857. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140858. setup->psy_noise_normal_start[1],
  140859. setup->psy_noise_normal_partition[1],
  140860. setup->psy_noise_normal_thresh,
  140861. 3);
  140862. }
  140863. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140864. setup->psy_tone_masteratt,
  140865. setup->psy_tone_0dB,
  140866. setup->psy_tone_adj_impulse);
  140867. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140868. setup->psy_tone_masteratt,
  140869. setup->psy_tone_0dB,
  140870. setup->psy_tone_adj_other);
  140871. if(!singleblock){
  140872. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140873. setup->psy_tone_masteratt,
  140874. setup->psy_tone_0dB,
  140875. setup->psy_tone_adj_other);
  140876. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140877. setup->psy_tone_masteratt,
  140878. setup->psy_tone_0dB,
  140879. setup->psy_tone_adj_long);
  140880. }
  140881. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140882. setup->psy_noise_compand,
  140883. setup->psy_noise_compand_short_mapping);
  140884. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140885. setup->psy_noise_compand,
  140886. setup->psy_noise_compand_short_mapping);
  140887. if(!singleblock){
  140888. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140889. setup->psy_noise_compand,
  140890. setup->psy_noise_compand_long_mapping);
  140891. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140892. setup->psy_noise_compand,
  140893. setup->psy_noise_compand_long_mapping);
  140894. }
  140895. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140896. setup->psy_tone_dBsuppress);
  140897. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140898. setup->psy_tone_dBsuppress);
  140899. if(!singleblock){
  140900. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140901. setup->psy_tone_dBsuppress);
  140902. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140903. setup->psy_tone_dBsuppress);
  140904. }
  140905. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140906. setup->psy_noise_dBsuppress,
  140907. setup->psy_noise_bias_impulse,
  140908. setup->psy_noiseguards,
  140909. (i0==0?hi->impulse_noisetune:0.));
  140910. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140911. setup->psy_noise_dBsuppress,
  140912. setup->psy_noise_bias_padding,
  140913. setup->psy_noiseguards,0.);
  140914. if(!singleblock){
  140915. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140916. setup->psy_noise_dBsuppress,
  140917. setup->psy_noise_bias_trans,
  140918. setup->psy_noiseguards,0.);
  140919. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140920. setup->psy_noise_dBsuppress,
  140921. setup->psy_noise_bias_long,
  140922. setup->psy_noiseguards,0.);
  140923. }
  140924. vorbis_encode_ath_setup(vi,0);
  140925. vorbis_encode_ath_setup(vi,1);
  140926. if(!singleblock){
  140927. vorbis_encode_ath_setup(vi,2);
  140928. vorbis_encode_ath_setup(vi,3);
  140929. }
  140930. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140931. if(hi->bitrate_av>0)
  140932. vi->bitrate_nominal=hi->bitrate_av;
  140933. else{
  140934. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140935. }
  140936. vi->bitrate_lower=hi->bitrate_min;
  140937. vi->bitrate_upper=hi->bitrate_max;
  140938. if(hi->bitrate_av)
  140939. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140940. else
  140941. vi->bitrate_window=0.;
  140942. if(hi->managed){
  140943. ci->bi.avg_rate=hi->bitrate_av;
  140944. ci->bi.min_rate=hi->bitrate_min;
  140945. ci->bi.max_rate=hi->bitrate_max;
  140946. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140947. ci->bi.reservoir_bias=
  140948. hi->bitrate_reservoir_bias;
  140949. ci->bi.slew_damp=hi->bitrate_av_damp;
  140950. }
  140951. return(0);
  140952. }
  140953. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140954. long channels,
  140955. long rate){
  140956. int ret=0,i,is;
  140957. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140958. highlevel_encode_setup *hi=&ci->hi;
  140959. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140960. double ds;
  140961. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140962. if(ret)return(ret);
  140963. is=hi->base_setting;
  140964. ds=hi->base_setting-is;
  140965. hi->short_setting=hi->base_setting;
  140966. hi->long_setting=hi->base_setting;
  140967. hi->managed=0;
  140968. hi->impulse_block_p=1;
  140969. hi->noise_normalize_p=1;
  140970. hi->stereo_point_setting=hi->base_setting;
  140971. hi->lowpass_kHz=
  140972. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140973. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140974. setup->psy_ath_float[is+1]*ds;
  140975. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140976. setup->psy_ath_abs[is+1]*ds;
  140977. hi->amplitude_track_dBpersec=-6.;
  140978. hi->trigger_setting=hi->base_setting;
  140979. for(i=0;i<4;i++){
  140980. hi->block[i].tone_mask_setting=hi->base_setting;
  140981. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140982. hi->block[i].noise_bias_setting=hi->base_setting;
  140983. hi->block[i].noise_compand_setting=hi->base_setting;
  140984. }
  140985. return(ret);
  140986. }
  140987. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140988. long channels,
  140989. long rate,
  140990. float quality){
  140991. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140992. highlevel_encode_setup *hi=&ci->hi;
  140993. quality+=.0000001;
  140994. if(quality>=1.)quality=.9999;
  140995. get_setup_template(vi,channels,rate,quality,0);
  140996. if(!hi->setup)return OV_EIMPL;
  140997. return vorbis_encode_setup_setting(vi,channels,rate);
  140998. }
  140999. int vorbis_encode_init_vbr(vorbis_info *vi,
  141000. long channels,
  141001. long rate,
  141002. float base_quality /* 0. to 1. */
  141003. ){
  141004. int ret=0;
  141005. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  141006. if(ret){
  141007. vorbis_info_clear(vi);
  141008. return ret;
  141009. }
  141010. ret=vorbis_encode_setup_init(vi);
  141011. if(ret)
  141012. vorbis_info_clear(vi);
  141013. return(ret);
  141014. }
  141015. int vorbis_encode_setup_managed(vorbis_info *vi,
  141016. long channels,
  141017. long rate,
  141018. long max_bitrate,
  141019. long nominal_bitrate,
  141020. long min_bitrate){
  141021. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141022. highlevel_encode_setup *hi=&ci->hi;
  141023. double tnominal=nominal_bitrate;
  141024. int ret=0;
  141025. if(nominal_bitrate<=0.){
  141026. if(max_bitrate>0.){
  141027. if(min_bitrate>0.)
  141028. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  141029. else
  141030. nominal_bitrate=max_bitrate*.875;
  141031. }else{
  141032. if(min_bitrate>0.){
  141033. nominal_bitrate=min_bitrate;
  141034. }else{
  141035. return(OV_EINVAL);
  141036. }
  141037. }
  141038. }
  141039. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  141040. if(!hi->setup)return OV_EIMPL;
  141041. ret=vorbis_encode_setup_setting(vi,channels,rate);
  141042. if(ret){
  141043. vorbis_info_clear(vi);
  141044. return ret;
  141045. }
  141046. hi->managed=1;
  141047. hi->bitrate_min=min_bitrate;
  141048. hi->bitrate_max=max_bitrate;
  141049. hi->bitrate_av=tnominal;
  141050. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  141051. hi->bitrate_reservoir=nominal_bitrate*2;
  141052. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  141053. return(ret);
  141054. }
  141055. int vorbis_encode_init(vorbis_info *vi,
  141056. long channels,
  141057. long rate,
  141058. long max_bitrate,
  141059. long nominal_bitrate,
  141060. long min_bitrate){
  141061. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  141062. max_bitrate,
  141063. nominal_bitrate,
  141064. min_bitrate);
  141065. if(ret){
  141066. vorbis_info_clear(vi);
  141067. return(ret);
  141068. }
  141069. ret=vorbis_encode_setup_init(vi);
  141070. if(ret)
  141071. vorbis_info_clear(vi);
  141072. return(ret);
  141073. }
  141074. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  141075. if(vi){
  141076. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141077. highlevel_encode_setup *hi=&ci->hi;
  141078. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  141079. if(setp && hi->set_in_stone)return(OV_EINVAL);
  141080. switch(number){
  141081. case OV_ECTL_RATEMANAGE_GET:
  141082. {
  141083. struct ovectl_ratemanage_arg *ai=
  141084. (struct ovectl_ratemanage_arg *)arg;
  141085. ai->management_active=hi->managed;
  141086. ai->bitrate_hard_window=ai->bitrate_av_window=
  141087. (double)hi->bitrate_reservoir/vi->rate;
  141088. ai->bitrate_av_window_center=1.;
  141089. ai->bitrate_hard_min=hi->bitrate_min;
  141090. ai->bitrate_hard_max=hi->bitrate_max;
  141091. ai->bitrate_av_lo=hi->bitrate_av;
  141092. ai->bitrate_av_hi=hi->bitrate_av;
  141093. }
  141094. return(0);
  141095. case OV_ECTL_RATEMANAGE_SET:
  141096. {
  141097. struct ovectl_ratemanage_arg *ai=
  141098. (struct ovectl_ratemanage_arg *)arg;
  141099. if(ai==NULL){
  141100. hi->managed=0;
  141101. }else{
  141102. hi->managed=ai->management_active;
  141103. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  141104. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  141105. }
  141106. }
  141107. return 0;
  141108. case OV_ECTL_RATEMANAGE_AVG:
  141109. {
  141110. struct ovectl_ratemanage_arg *ai=
  141111. (struct ovectl_ratemanage_arg *)arg;
  141112. if(ai==NULL){
  141113. hi->bitrate_av=0;
  141114. }else{
  141115. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  141116. }
  141117. }
  141118. return(0);
  141119. case OV_ECTL_RATEMANAGE_HARD:
  141120. {
  141121. struct ovectl_ratemanage_arg *ai=
  141122. (struct ovectl_ratemanage_arg *)arg;
  141123. if(ai==NULL){
  141124. hi->bitrate_min=0;
  141125. hi->bitrate_max=0;
  141126. }else{
  141127. hi->bitrate_min=ai->bitrate_hard_min;
  141128. hi->bitrate_max=ai->bitrate_hard_max;
  141129. hi->bitrate_reservoir=ai->bitrate_hard_window*
  141130. (hi->bitrate_max+hi->bitrate_min)*.5;
  141131. }
  141132. if(hi->bitrate_reservoir<128.)
  141133. hi->bitrate_reservoir=128.;
  141134. }
  141135. return(0);
  141136. case OV_ECTL_RATEMANAGE2_GET:
  141137. {
  141138. struct ovectl_ratemanage2_arg *ai=
  141139. (struct ovectl_ratemanage2_arg *)arg;
  141140. if(ai==NULL)return OV_EINVAL;
  141141. ai->management_active=hi->managed;
  141142. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  141143. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  141144. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  141145. ai->bitrate_average_damping=hi->bitrate_av_damp;
  141146. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  141147. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  141148. }
  141149. return (0);
  141150. case OV_ECTL_RATEMANAGE2_SET:
  141151. {
  141152. struct ovectl_ratemanage2_arg *ai=
  141153. (struct ovectl_ratemanage2_arg *)arg;
  141154. if(ai==NULL){
  141155. hi->managed=0;
  141156. }else{
  141157. if(ai->bitrate_limit_min_kbps>0 &&
  141158. ai->bitrate_average_kbps>0 &&
  141159. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  141160. return OV_EINVAL;
  141161. if(ai->bitrate_limit_max_kbps>0 &&
  141162. ai->bitrate_average_kbps>0 &&
  141163. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  141164. return OV_EINVAL;
  141165. if(ai->bitrate_limit_min_kbps>0 &&
  141166. ai->bitrate_limit_max_kbps>0 &&
  141167. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  141168. return OV_EINVAL;
  141169. if(ai->bitrate_average_damping <= 0.)
  141170. return OV_EINVAL;
  141171. if(ai->bitrate_limit_reservoir_bits < 0)
  141172. return OV_EINVAL;
  141173. if(ai->bitrate_limit_reservoir_bias < 0.)
  141174. return OV_EINVAL;
  141175. if(ai->bitrate_limit_reservoir_bias > 1.)
  141176. return OV_EINVAL;
  141177. hi->managed=ai->management_active;
  141178. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  141179. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  141180. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  141181. hi->bitrate_av_damp=ai->bitrate_average_damping;
  141182. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  141183. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  141184. }
  141185. }
  141186. return 0;
  141187. case OV_ECTL_LOWPASS_GET:
  141188. {
  141189. double *farg=(double *)arg;
  141190. *farg=hi->lowpass_kHz;
  141191. }
  141192. return(0);
  141193. case OV_ECTL_LOWPASS_SET:
  141194. {
  141195. double *farg=(double *)arg;
  141196. hi->lowpass_kHz=*farg;
  141197. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  141198. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  141199. }
  141200. return(0);
  141201. case OV_ECTL_IBLOCK_GET:
  141202. {
  141203. double *farg=(double *)arg;
  141204. *farg=hi->impulse_noisetune;
  141205. }
  141206. return(0);
  141207. case OV_ECTL_IBLOCK_SET:
  141208. {
  141209. double *farg=(double *)arg;
  141210. hi->impulse_noisetune=*farg;
  141211. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  141212. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  141213. }
  141214. return(0);
  141215. }
  141216. return(OV_EIMPL);
  141217. }
  141218. return(OV_EINVAL);
  141219. }
  141220. #endif
  141221. /*** End of inlined file: vorbisenc.c ***/
  141222. /*** Start of inlined file: vorbisfile.c ***/
  141223. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  141224. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  141225. // tasks..
  141226. #if JUCE_MSVC
  141227. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  141228. #endif
  141229. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  141230. #if JUCE_USE_OGGVORBIS
  141231. #include <stdlib.h>
  141232. #include <stdio.h>
  141233. #include <errno.h>
  141234. #include <string.h>
  141235. #include <math.h>
  141236. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  141237. over 8k gets what they deserve */
  141238. static long _get_data(OggVorbis_File *vf){
  141239. errno=0;
  141240. if(vf->datasource){
  141241. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  141242. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  141243. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  141244. if(bytes==0 && errno)return(-1);
  141245. return(bytes);
  141246. }else
  141247. return(0);
  141248. }
  141249. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  141250. if(vf->datasource){
  141251. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  141252. vf->offset=offset;
  141253. ogg_sync_reset(&vf->oy);
  141254. }else{
  141255. return;
  141256. }
  141257. }
  141258. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  141259. ogg_int64_t boundary){
  141260. if(boundary>0)boundary+=vf->offset;
  141261. while(1){
  141262. long more;
  141263. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  141264. more=ogg_sync_pageseek(&vf->oy,og);
  141265. if(more<0){
  141266. vf->offset-=more;
  141267. }else{
  141268. if(more==0){
  141269. if(!boundary)return(OV_FALSE);
  141270. {
  141271. long ret=_get_data(vf);
  141272. if(ret==0)return(OV_EOF);
  141273. if(ret<0)return(OV_EREAD);
  141274. }
  141275. }else{
  141276. ogg_int64_t ret=vf->offset;
  141277. vf->offset+=more;
  141278. return(ret);
  141279. }
  141280. }
  141281. }
  141282. }
  141283. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  141284. ogg_int64_t begin=vf->offset;
  141285. ogg_int64_t end=begin;
  141286. ogg_int64_t ret;
  141287. ogg_int64_t offset=-1;
  141288. while(offset==-1){
  141289. begin-=CHUNKSIZE;
  141290. if(begin<0)
  141291. begin=0;
  141292. _seek_helper(vf,begin);
  141293. while(vf->offset<end){
  141294. ret=_get_next_page(vf,og,end-vf->offset);
  141295. if(ret==OV_EREAD)return(OV_EREAD);
  141296. if(ret<0){
  141297. break;
  141298. }else{
  141299. offset=ret;
  141300. }
  141301. }
  141302. }
  141303. _seek_helper(vf,offset);
  141304. ret=_get_next_page(vf,og,CHUNKSIZE);
  141305. if(ret<0)
  141306. return(OV_EFAULT);
  141307. return(offset);
  141308. }
  141309. static int _bisect_forward_serialno(OggVorbis_File *vf,
  141310. ogg_int64_t begin,
  141311. ogg_int64_t searched,
  141312. ogg_int64_t end,
  141313. long currentno,
  141314. long m){
  141315. ogg_int64_t endsearched=end;
  141316. ogg_int64_t next=end;
  141317. ogg_page og;
  141318. ogg_int64_t ret;
  141319. while(searched<endsearched){
  141320. ogg_int64_t bisect;
  141321. if(endsearched-searched<CHUNKSIZE){
  141322. bisect=searched;
  141323. }else{
  141324. bisect=(searched+endsearched)/2;
  141325. }
  141326. _seek_helper(vf,bisect);
  141327. ret=_get_next_page(vf,&og,-1);
  141328. if(ret==OV_EREAD)return(OV_EREAD);
  141329. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  141330. endsearched=bisect;
  141331. if(ret>=0)next=ret;
  141332. }else{
  141333. searched=ret+og.header_len+og.body_len;
  141334. }
  141335. }
  141336. _seek_helper(vf,next);
  141337. ret=_get_next_page(vf,&og,-1);
  141338. if(ret==OV_EREAD)return(OV_EREAD);
  141339. if(searched>=end || ret<0){
  141340. vf->links=m+1;
  141341. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  141342. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  141343. vf->offsets[m+1]=searched;
  141344. }else{
  141345. ret=_bisect_forward_serialno(vf,next,vf->offset,
  141346. end,ogg_page_serialno(&og),m+1);
  141347. if(ret==OV_EREAD)return(OV_EREAD);
  141348. }
  141349. vf->offsets[m]=begin;
  141350. vf->serialnos[m]=currentno;
  141351. return(0);
  141352. }
  141353. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  141354. long *serialno,ogg_page *og_ptr){
  141355. ogg_page og;
  141356. ogg_packet op;
  141357. int i,ret;
  141358. if(!og_ptr){
  141359. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  141360. if(llret==OV_EREAD)return(OV_EREAD);
  141361. if(llret<0)return OV_ENOTVORBIS;
  141362. og_ptr=&og;
  141363. }
  141364. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  141365. if(serialno)*serialno=vf->os.serialno;
  141366. vf->ready_state=STREAMSET;
  141367. vorbis_info_init(vi);
  141368. vorbis_comment_init(vc);
  141369. i=0;
  141370. while(i<3){
  141371. ogg_stream_pagein(&vf->os,og_ptr);
  141372. while(i<3){
  141373. int result=ogg_stream_packetout(&vf->os,&op);
  141374. if(result==0)break;
  141375. if(result==-1){
  141376. ret=OV_EBADHEADER;
  141377. goto bail_header;
  141378. }
  141379. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  141380. goto bail_header;
  141381. }
  141382. i++;
  141383. }
  141384. if(i<3)
  141385. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  141386. ret=OV_EBADHEADER;
  141387. goto bail_header;
  141388. }
  141389. }
  141390. return 0;
  141391. bail_header:
  141392. vorbis_info_clear(vi);
  141393. vorbis_comment_clear(vc);
  141394. vf->ready_state=OPENED;
  141395. return ret;
  141396. }
  141397. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  141398. ogg_page og;
  141399. int i;
  141400. ogg_int64_t ret;
  141401. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  141402. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  141403. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  141404. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  141405. for(i=0;i<vf->links;i++){
  141406. if(i==0){
  141407. vf->dataoffsets[i]=dataoffset;
  141408. _seek_helper(vf,dataoffset);
  141409. }else{
  141410. _seek_helper(vf,vf->offsets[i]);
  141411. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  141412. vf->dataoffsets[i]=-1;
  141413. }else{
  141414. vf->dataoffsets[i]=vf->offset;
  141415. }
  141416. }
  141417. if(vf->dataoffsets[i]!=-1){
  141418. ogg_int64_t accumulated=0;
  141419. long lastblock=-1;
  141420. int result;
  141421. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  141422. while(1){
  141423. ogg_packet op;
  141424. ret=_get_next_page(vf,&og,-1);
  141425. if(ret<0)
  141426. break;
  141427. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  141428. break;
  141429. ogg_stream_pagein(&vf->os,&og);
  141430. while((result=ogg_stream_packetout(&vf->os,&op))){
  141431. if(result>0){ /* ignore holes */
  141432. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  141433. if(lastblock!=-1)
  141434. accumulated+=(lastblock+thisblock)>>2;
  141435. lastblock=thisblock;
  141436. }
  141437. }
  141438. if(ogg_page_granulepos(&og)!=-1){
  141439. accumulated= ogg_page_granulepos(&og)-accumulated;
  141440. break;
  141441. }
  141442. }
  141443. if(accumulated<0)accumulated=0;
  141444. vf->pcmlengths[i*2]=accumulated;
  141445. }
  141446. {
  141447. ogg_int64_t end=vf->offsets[i+1];
  141448. _seek_helper(vf,end);
  141449. while(1){
  141450. ret=_get_prev_page(vf,&og);
  141451. if(ret<0){
  141452. vorbis_info_clear(vf->vi+i);
  141453. vorbis_comment_clear(vf->vc+i);
  141454. break;
  141455. }
  141456. if(ogg_page_granulepos(&og)!=-1){
  141457. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  141458. break;
  141459. }
  141460. vf->offset=ret;
  141461. }
  141462. }
  141463. }
  141464. }
  141465. static int _make_decode_ready(OggVorbis_File *vf){
  141466. if(vf->ready_state>STREAMSET)return 0;
  141467. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  141468. if(vf->seekable){
  141469. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  141470. return OV_EBADLINK;
  141471. }else{
  141472. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  141473. return OV_EBADLINK;
  141474. }
  141475. vorbis_block_init(&vf->vd,&vf->vb);
  141476. vf->ready_state=INITSET;
  141477. vf->bittrack=0.f;
  141478. vf->samptrack=0.f;
  141479. return 0;
  141480. }
  141481. static int _open_seekable2(OggVorbis_File *vf){
  141482. long serialno=vf->current_serialno;
  141483. ogg_int64_t dataoffset=vf->offset, end;
  141484. ogg_page og;
  141485. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  141486. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  141487. end=_get_prev_page(vf,&og);
  141488. if(end<0)return(end);
  141489. if(ogg_page_serialno(&og)!=serialno){
  141490. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  141491. }else{
  141492. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  141493. }
  141494. _prefetch_all_headers(vf,dataoffset);
  141495. return(ov_raw_seek(vf,0));
  141496. }
  141497. static void _decode_clear(OggVorbis_File *vf){
  141498. vorbis_dsp_clear(&vf->vd);
  141499. vorbis_block_clear(&vf->vb);
  141500. vf->ready_state=OPENED;
  141501. }
  141502. static int _fetch_and_process_packet(OggVorbis_File *vf,
  141503. ogg_packet *op_in,
  141504. int readp,
  141505. int spanp){
  141506. ogg_page og;
  141507. while(1){
  141508. if(vf->ready_state==INITSET){
  141509. while(1) {
  141510. ogg_packet op;
  141511. ogg_packet *op_ptr=(op_in?op_in:&op);
  141512. int result=ogg_stream_packetout(&vf->os,op_ptr);
  141513. ogg_int64_t granulepos;
  141514. op_in=NULL;
  141515. if(result==-1)return(OV_HOLE); /* hole in the data. */
  141516. if(result>0){
  141517. granulepos=op_ptr->granulepos;
  141518. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  141519. header handling. The
  141520. header packets aren't
  141521. audio, so if/when we
  141522. submit them,
  141523. vorbis_synthesis will
  141524. reject them */
  141525. {
  141526. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141527. if(oldsamples)return(OV_EFAULT);
  141528. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141529. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141530. vf->bittrack+=op_ptr->bytes*8;
  141531. }
  141532. if(granulepos!=-1 && !op_ptr->e_o_s){
  141533. int link=(vf->seekable?vf->current_link:0);
  141534. int i,samples;
  141535. if(vf->seekable && link>0)
  141536. granulepos-=vf->pcmlengths[link*2];
  141537. if(granulepos<0)granulepos=0; /* actually, this
  141538. shouldn't be possible
  141539. here unless the stream
  141540. is very broken */
  141541. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141542. granulepos-=samples;
  141543. for(i=0;i<link;i++)
  141544. granulepos+=vf->pcmlengths[i*2+1];
  141545. vf->pcm_offset=granulepos;
  141546. }
  141547. return(1);
  141548. }
  141549. }
  141550. else
  141551. break;
  141552. }
  141553. }
  141554. if(vf->ready_state>=OPENED){
  141555. ogg_int64_t ret;
  141556. if(!readp)return(0);
  141557. if((ret=_get_next_page(vf,&og,-1))<0){
  141558. return(OV_EOF); /* eof.
  141559. leave unitialized */
  141560. }
  141561. vf->bittrack+=og.header_len*8;
  141562. if(vf->ready_state==INITSET){
  141563. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141564. if(!spanp)
  141565. return(OV_EOF);
  141566. _decode_clear(vf);
  141567. if(!vf->seekable){
  141568. vorbis_info_clear(vf->vi);
  141569. vorbis_comment_clear(vf->vc);
  141570. }
  141571. }
  141572. }
  141573. }
  141574. if(vf->ready_state!=INITSET){
  141575. int link;
  141576. if(vf->ready_state<STREAMSET){
  141577. if(vf->seekable){
  141578. vf->current_serialno=ogg_page_serialno(&og);
  141579. for(link=0;link<vf->links;link++)
  141580. if(vf->serialnos[link]==vf->current_serialno)break;
  141581. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141582. stream. error out,
  141583. leave machine
  141584. uninitialized */
  141585. vf->current_link=link;
  141586. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141587. vf->ready_state=STREAMSET;
  141588. }else{
  141589. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141590. if(ret)return(ret);
  141591. vf->current_link++;
  141592. link=0;
  141593. }
  141594. }
  141595. {
  141596. int ret=_make_decode_ready(vf);
  141597. if(ret<0)return ret;
  141598. }
  141599. }
  141600. ogg_stream_pagein(&vf->os,&og);
  141601. }
  141602. }
  141603. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141604. if(f==NULL)return(-1);
  141605. return fseek(f,off,whence);
  141606. }
  141607. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141608. long ibytes, ov_callbacks callbacks){
  141609. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141610. int ret;
  141611. memset(vf,0,sizeof(*vf));
  141612. vf->datasource=f;
  141613. vf->callbacks = callbacks;
  141614. ogg_sync_init(&vf->oy);
  141615. if(initial){
  141616. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141617. memcpy(buffer,initial,ibytes);
  141618. ogg_sync_wrote(&vf->oy,ibytes);
  141619. }
  141620. if(offsettest!=-1)vf->seekable=1;
  141621. vf->links=1;
  141622. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141623. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141624. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141625. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141626. vf->datasource=NULL;
  141627. ov_clear(vf);
  141628. }else
  141629. vf->ready_state=PARTOPEN;
  141630. return(ret);
  141631. }
  141632. static int _ov_open2(OggVorbis_File *vf){
  141633. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141634. vf->ready_state=OPENED;
  141635. if(vf->seekable){
  141636. int ret=_open_seekable2(vf);
  141637. if(ret){
  141638. vf->datasource=NULL;
  141639. ov_clear(vf);
  141640. }
  141641. return(ret);
  141642. }else
  141643. vf->ready_state=STREAMSET;
  141644. return 0;
  141645. }
  141646. int ov_clear(OggVorbis_File *vf){
  141647. if(vf){
  141648. vorbis_block_clear(&vf->vb);
  141649. vorbis_dsp_clear(&vf->vd);
  141650. ogg_stream_clear(&vf->os);
  141651. if(vf->vi && vf->links){
  141652. int i;
  141653. for(i=0;i<vf->links;i++){
  141654. vorbis_info_clear(vf->vi+i);
  141655. vorbis_comment_clear(vf->vc+i);
  141656. }
  141657. _ogg_free(vf->vi);
  141658. _ogg_free(vf->vc);
  141659. }
  141660. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141661. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141662. if(vf->serialnos)_ogg_free(vf->serialnos);
  141663. if(vf->offsets)_ogg_free(vf->offsets);
  141664. ogg_sync_clear(&vf->oy);
  141665. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141666. memset(vf,0,sizeof(*vf));
  141667. }
  141668. #ifdef DEBUG_LEAKS
  141669. _VDBG_dump();
  141670. #endif
  141671. return(0);
  141672. }
  141673. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141674. ov_callbacks callbacks){
  141675. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141676. if(ret)return ret;
  141677. return _ov_open2(vf);
  141678. }
  141679. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141680. ov_callbacks callbacks = {
  141681. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141682. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141683. (int (*)(void *)) fclose,
  141684. (long (*)(void *)) ftell
  141685. };
  141686. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141687. }
  141688. int ov_halfrate(OggVorbis_File *vf,int flag){
  141689. int i;
  141690. if(vf->vi==NULL)return OV_EINVAL;
  141691. if(!vf->seekable)return OV_EINVAL;
  141692. if(vf->ready_state>=STREAMSET)
  141693. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141694. will be able to swap this on the fly, but
  141695. for now dumping the decode machine is needed
  141696. to reinit the MDCT lookups. 1.1 libvorbis
  141697. is planned to be able to switch on the fly */
  141698. for(i=0;i<vf->links;i++){
  141699. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141700. ov_halfrate(vf,0);
  141701. return OV_EINVAL;
  141702. }
  141703. }
  141704. return 0;
  141705. }
  141706. int ov_halfrate_p(OggVorbis_File *vf){
  141707. if(vf->vi==NULL)return OV_EINVAL;
  141708. return vorbis_synthesis_halfrate_p(vf->vi);
  141709. }
  141710. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141711. ov_callbacks callbacks)
  141712. {
  141713. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141714. }
  141715. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141716. ov_callbacks callbacks = {
  141717. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141718. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141719. (int (*)(void *)) fclose,
  141720. (long (*)(void *)) ftell
  141721. };
  141722. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141723. }
  141724. int ov_test_open(OggVorbis_File *vf){
  141725. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141726. return _ov_open2(vf);
  141727. }
  141728. long ov_streams(OggVorbis_File *vf){
  141729. return vf->links;
  141730. }
  141731. long ov_seekable(OggVorbis_File *vf){
  141732. return vf->seekable;
  141733. }
  141734. long ov_bitrate(OggVorbis_File *vf,int i){
  141735. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141736. if(i>=vf->links)return(OV_EINVAL);
  141737. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141738. if(i<0){
  141739. ogg_int64_t bits=0;
  141740. int i;
  141741. float br;
  141742. for(i=0;i<vf->links;i++)
  141743. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141744. br = bits/ov_time_total(vf,-1);
  141745. return(rint(br));
  141746. }else{
  141747. if(vf->seekable){
  141748. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141749. }else{
  141750. if(vf->vi[i].bitrate_nominal>0){
  141751. return vf->vi[i].bitrate_nominal;
  141752. }else{
  141753. if(vf->vi[i].bitrate_upper>0){
  141754. if(vf->vi[i].bitrate_lower>0){
  141755. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141756. }else{
  141757. return vf->vi[i].bitrate_upper;
  141758. }
  141759. }
  141760. return(OV_FALSE);
  141761. }
  141762. }
  141763. }
  141764. }
  141765. long ov_bitrate_instant(OggVorbis_File *vf){
  141766. int link=(vf->seekable?vf->current_link:0);
  141767. long ret;
  141768. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141769. if(vf->samptrack==0)return(OV_FALSE);
  141770. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141771. vf->bittrack=0.f;
  141772. vf->samptrack=0.f;
  141773. return(ret);
  141774. }
  141775. long ov_serialnumber(OggVorbis_File *vf,int i){
  141776. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141777. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141778. if(i<0){
  141779. return(vf->current_serialno);
  141780. }else{
  141781. return(vf->serialnos[i]);
  141782. }
  141783. }
  141784. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141785. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141786. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141787. if(i<0){
  141788. ogg_int64_t acc=0;
  141789. int i;
  141790. for(i=0;i<vf->links;i++)
  141791. acc+=ov_raw_total(vf,i);
  141792. return(acc);
  141793. }else{
  141794. return(vf->offsets[i+1]-vf->offsets[i]);
  141795. }
  141796. }
  141797. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141798. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141799. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141800. if(i<0){
  141801. ogg_int64_t acc=0;
  141802. int i;
  141803. for(i=0;i<vf->links;i++)
  141804. acc+=ov_pcm_total(vf,i);
  141805. return(acc);
  141806. }else{
  141807. return(vf->pcmlengths[i*2+1]);
  141808. }
  141809. }
  141810. double ov_time_total(OggVorbis_File *vf,int i){
  141811. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141812. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141813. if(i<0){
  141814. double acc=0;
  141815. int i;
  141816. for(i=0;i<vf->links;i++)
  141817. acc+=ov_time_total(vf,i);
  141818. return(acc);
  141819. }else{
  141820. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141821. }
  141822. }
  141823. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141824. ogg_stream_state work_os;
  141825. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141826. if(!vf->seekable)
  141827. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141828. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141829. vf->pcm_offset=-1;
  141830. ogg_stream_reset_serialno(&vf->os,
  141831. vf->current_serialno); /* must set serialno */
  141832. vorbis_synthesis_restart(&vf->vd);
  141833. _seek_helper(vf,pos);
  141834. {
  141835. ogg_page og;
  141836. ogg_packet op;
  141837. int lastblock=0;
  141838. int accblock=0;
  141839. int thisblock;
  141840. int eosflag;
  141841. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141842. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141843. return from not necessarily
  141844. starting from the beginning */
  141845. while(1){
  141846. if(vf->ready_state>=STREAMSET){
  141847. int result=ogg_stream_packetout(&work_os,&op);
  141848. if(result>0){
  141849. if(vf->vi[vf->current_link].codec_setup){
  141850. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141851. if(thisblock<0){
  141852. ogg_stream_packetout(&vf->os,NULL);
  141853. thisblock=0;
  141854. }else{
  141855. if(eosflag)
  141856. ogg_stream_packetout(&vf->os,NULL);
  141857. else
  141858. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141859. }
  141860. if(op.granulepos!=-1){
  141861. int i,link=vf->current_link;
  141862. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141863. if(granulepos<0)granulepos=0;
  141864. for(i=0;i<link;i++)
  141865. granulepos+=vf->pcmlengths[i*2+1];
  141866. vf->pcm_offset=granulepos-accblock;
  141867. break;
  141868. }
  141869. lastblock=thisblock;
  141870. continue;
  141871. }else
  141872. ogg_stream_packetout(&vf->os,NULL);
  141873. }
  141874. }
  141875. if(!lastblock){
  141876. if(_get_next_page(vf,&og,-1)<0){
  141877. vf->pcm_offset=ov_pcm_total(vf,-1);
  141878. break;
  141879. }
  141880. }else{
  141881. vf->pcm_offset=-1;
  141882. break;
  141883. }
  141884. if(vf->ready_state>=STREAMSET)
  141885. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141886. _decode_clear(vf); /* clear out stream state */
  141887. ogg_stream_clear(&work_os);
  141888. }
  141889. if(vf->ready_state<STREAMSET){
  141890. int link;
  141891. vf->current_serialno=ogg_page_serialno(&og);
  141892. for(link=0;link<vf->links;link++)
  141893. if(vf->serialnos[link]==vf->current_serialno)break;
  141894. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141895. error out, leave
  141896. machine uninitialized */
  141897. vf->current_link=link;
  141898. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141899. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141900. vf->ready_state=STREAMSET;
  141901. }
  141902. ogg_stream_pagein(&vf->os,&og);
  141903. ogg_stream_pagein(&work_os,&og);
  141904. eosflag=ogg_page_eos(&og);
  141905. }
  141906. }
  141907. ogg_stream_clear(&work_os);
  141908. vf->bittrack=0.f;
  141909. vf->samptrack=0.f;
  141910. return(0);
  141911. seek_error:
  141912. vf->pcm_offset=-1;
  141913. ogg_stream_clear(&work_os);
  141914. _decode_clear(vf);
  141915. return OV_EBADLINK;
  141916. }
  141917. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141918. int link=-1;
  141919. ogg_int64_t result=0;
  141920. ogg_int64_t total=ov_pcm_total(vf,-1);
  141921. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141922. if(!vf->seekable)return(OV_ENOSEEK);
  141923. if(pos<0 || pos>total)return(OV_EINVAL);
  141924. for(link=vf->links-1;link>=0;link--){
  141925. total-=vf->pcmlengths[link*2+1];
  141926. if(pos>=total)break;
  141927. }
  141928. {
  141929. ogg_int64_t end=vf->offsets[link+1];
  141930. ogg_int64_t begin=vf->offsets[link];
  141931. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141932. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141933. ogg_int64_t target=pos-total+begintime;
  141934. ogg_int64_t best=begin;
  141935. ogg_page og;
  141936. while(begin<end){
  141937. ogg_int64_t bisect;
  141938. if(end-begin<CHUNKSIZE){
  141939. bisect=begin;
  141940. }else{
  141941. bisect=begin +
  141942. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141943. if(bisect<=begin)
  141944. bisect=begin+1;
  141945. }
  141946. _seek_helper(vf,bisect);
  141947. while(begin<end){
  141948. result=_get_next_page(vf,&og,end-vf->offset);
  141949. if(result==OV_EREAD) goto seek_error;
  141950. if(result<0){
  141951. if(bisect<=begin+1)
  141952. end=begin; /* found it */
  141953. else{
  141954. if(bisect==0) goto seek_error;
  141955. bisect-=CHUNKSIZE;
  141956. if(bisect<=begin)bisect=begin+1;
  141957. _seek_helper(vf,bisect);
  141958. }
  141959. }else{
  141960. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141961. if(granulepos==-1)continue;
  141962. if(granulepos<target){
  141963. best=result; /* raw offset of packet with granulepos */
  141964. begin=vf->offset; /* raw offset of next page */
  141965. begintime=granulepos;
  141966. if(target-begintime>44100)break;
  141967. bisect=begin; /* *not* begin + 1 */
  141968. }else{
  141969. if(bisect<=begin+1)
  141970. end=begin; /* found it */
  141971. else{
  141972. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141973. end=result;
  141974. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141975. if(bisect<=begin)bisect=begin+1;
  141976. _seek_helper(vf,bisect);
  141977. }else{
  141978. end=result;
  141979. endtime=granulepos;
  141980. break;
  141981. }
  141982. }
  141983. }
  141984. }
  141985. }
  141986. }
  141987. {
  141988. ogg_page og;
  141989. ogg_packet op;
  141990. _seek_helper(vf,best);
  141991. vf->pcm_offset=-1;
  141992. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141993. if(link!=vf->current_link){
  141994. _decode_clear(vf);
  141995. vf->current_link=link;
  141996. vf->current_serialno=ogg_page_serialno(&og);
  141997. vf->ready_state=STREAMSET;
  141998. }else{
  141999. vorbis_synthesis_restart(&vf->vd);
  142000. }
  142001. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  142002. ogg_stream_pagein(&vf->os,&og);
  142003. while(1){
  142004. result=ogg_stream_packetpeek(&vf->os,&op);
  142005. if(result==0){
  142006. _seek_helper(vf,best);
  142007. while(1){
  142008. result=_get_prev_page(vf,&og);
  142009. if(result<0) goto seek_error;
  142010. if(ogg_page_granulepos(&og)>-1 ||
  142011. !ogg_page_continued(&og)){
  142012. return ov_raw_seek(vf,result);
  142013. }
  142014. vf->offset=result;
  142015. }
  142016. }
  142017. if(result<0){
  142018. result = OV_EBADPACKET;
  142019. goto seek_error;
  142020. }
  142021. if(op.granulepos!=-1){
  142022. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  142023. if(vf->pcm_offset<0)vf->pcm_offset=0;
  142024. vf->pcm_offset+=total;
  142025. break;
  142026. }else
  142027. result=ogg_stream_packetout(&vf->os,NULL);
  142028. }
  142029. }
  142030. }
  142031. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  142032. result=OV_EFAULT;
  142033. goto seek_error;
  142034. }
  142035. vf->bittrack=0.f;
  142036. vf->samptrack=0.f;
  142037. return(0);
  142038. seek_error:
  142039. vf->pcm_offset=-1;
  142040. _decode_clear(vf);
  142041. return (int)result;
  142042. }
  142043. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  142044. int thisblock,lastblock=0;
  142045. int ret=ov_pcm_seek_page(vf,pos);
  142046. if(ret<0)return(ret);
  142047. if((ret=_make_decode_ready(vf)))return ret;
  142048. while(1){
  142049. ogg_packet op;
  142050. ogg_page og;
  142051. int ret=ogg_stream_packetpeek(&vf->os,&op);
  142052. if(ret>0){
  142053. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  142054. if(thisblock<0){
  142055. ogg_stream_packetout(&vf->os,NULL);
  142056. continue; /* non audio packet */
  142057. }
  142058. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  142059. if(vf->pcm_offset+((thisblock+
  142060. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  142061. ogg_stream_packetout(&vf->os,NULL);
  142062. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  142063. only tracking, no
  142064. pcm_decode */
  142065. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  142066. if(op.granulepos>-1){
  142067. int i;
  142068. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  142069. if(vf->pcm_offset<0)vf->pcm_offset=0;
  142070. for(i=0;i<vf->current_link;i++)
  142071. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  142072. }
  142073. lastblock=thisblock;
  142074. }else{
  142075. if(ret<0 && ret!=OV_HOLE)break;
  142076. if(_get_next_page(vf,&og,-1)<0)break;
  142077. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  142078. if(vf->ready_state<STREAMSET){
  142079. int link;
  142080. vf->current_serialno=ogg_page_serialno(&og);
  142081. for(link=0;link<vf->links;link++)
  142082. if(vf->serialnos[link]==vf->current_serialno)break;
  142083. if(link==vf->links)return(OV_EBADLINK);
  142084. vf->current_link=link;
  142085. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  142086. vf->ready_state=STREAMSET;
  142087. ret=_make_decode_ready(vf);
  142088. if(ret)return ret;
  142089. lastblock=0;
  142090. }
  142091. ogg_stream_pagein(&vf->os,&og);
  142092. }
  142093. }
  142094. vf->bittrack=0.f;
  142095. vf->samptrack=0.f;
  142096. while(vf->pcm_offset<pos){
  142097. ogg_int64_t target=pos-vf->pcm_offset;
  142098. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  142099. if(samples>target)samples=target;
  142100. vorbis_synthesis_read(&vf->vd,samples);
  142101. vf->pcm_offset+=samples;
  142102. if(samples<target)
  142103. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  142104. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  142105. }
  142106. return 0;
  142107. }
  142108. int ov_time_seek(OggVorbis_File *vf,double seconds){
  142109. int link=-1;
  142110. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  142111. double time_total=ov_time_total(vf,-1);
  142112. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142113. if(!vf->seekable)return(OV_ENOSEEK);
  142114. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  142115. for(link=vf->links-1;link>=0;link--){
  142116. pcm_total-=vf->pcmlengths[link*2+1];
  142117. time_total-=ov_time_total(vf,link);
  142118. if(seconds>=time_total)break;
  142119. }
  142120. {
  142121. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142122. return(ov_pcm_seek(vf,target));
  142123. }
  142124. }
  142125. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  142126. int link=-1;
  142127. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  142128. double time_total=ov_time_total(vf,-1);
  142129. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142130. if(!vf->seekable)return(OV_ENOSEEK);
  142131. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  142132. for(link=vf->links-1;link>=0;link--){
  142133. pcm_total-=vf->pcmlengths[link*2+1];
  142134. time_total-=ov_time_total(vf,link);
  142135. if(seconds>=time_total)break;
  142136. }
  142137. {
  142138. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142139. return(ov_pcm_seek_page(vf,target));
  142140. }
  142141. }
  142142. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  142143. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142144. return(vf->offset);
  142145. }
  142146. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  142147. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142148. return(vf->pcm_offset);
  142149. }
  142150. double ov_time_tell(OggVorbis_File *vf){
  142151. int link=0;
  142152. ogg_int64_t pcm_total=0;
  142153. double time_total=0.f;
  142154. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142155. if(vf->seekable){
  142156. pcm_total=ov_pcm_total(vf,-1);
  142157. time_total=ov_time_total(vf,-1);
  142158. for(link=vf->links-1;link>=0;link--){
  142159. pcm_total-=vf->pcmlengths[link*2+1];
  142160. time_total-=ov_time_total(vf,link);
  142161. if(vf->pcm_offset>=pcm_total)break;
  142162. }
  142163. }
  142164. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  142165. }
  142166. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  142167. if(vf->seekable){
  142168. if(link<0)
  142169. if(vf->ready_state>=STREAMSET)
  142170. return vf->vi+vf->current_link;
  142171. else
  142172. return vf->vi;
  142173. else
  142174. if(link>=vf->links)
  142175. return NULL;
  142176. else
  142177. return vf->vi+link;
  142178. }else{
  142179. return vf->vi;
  142180. }
  142181. }
  142182. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  142183. if(vf->seekable){
  142184. if(link<0)
  142185. if(vf->ready_state>=STREAMSET)
  142186. return vf->vc+vf->current_link;
  142187. else
  142188. return vf->vc;
  142189. else
  142190. if(link>=vf->links)
  142191. return NULL;
  142192. else
  142193. return vf->vc+link;
  142194. }else{
  142195. return vf->vc;
  142196. }
  142197. }
  142198. static int host_is_big_endian() {
  142199. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  142200. unsigned char *bytewise = (unsigned char *)&pattern;
  142201. if (bytewise[0] == 0xfe) return 1;
  142202. return 0;
  142203. }
  142204. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  142205. int bigendianp,int word,int sgned,int *bitstream){
  142206. int i,j;
  142207. int host_endian = host_is_big_endian();
  142208. float **pcm;
  142209. long samples;
  142210. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142211. while(1){
  142212. if(vf->ready_state==INITSET){
  142213. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142214. if(samples)break;
  142215. }
  142216. {
  142217. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142218. if(ret==OV_EOF)
  142219. return(0);
  142220. if(ret<=0)
  142221. return(ret);
  142222. }
  142223. }
  142224. if(samples>0){
  142225. long channels=ov_info(vf,-1)->channels;
  142226. long bytespersample=word * channels;
  142227. vorbis_fpu_control fpu;
  142228. (void) fpu; // (to avoid a warning about it being unused)
  142229. if(samples>length/bytespersample)samples=length/bytespersample;
  142230. if(samples <= 0)
  142231. return OV_EINVAL;
  142232. {
  142233. int val;
  142234. if(word==1){
  142235. int off=(sgned?0:128);
  142236. vorbis_fpu_setround(&fpu);
  142237. for(j=0;j<samples;j++)
  142238. for(i=0;i<channels;i++){
  142239. val=vorbis_ftoi(pcm[i][j]*128.f);
  142240. if(val>127)val=127;
  142241. else if(val<-128)val=-128;
  142242. *buffer++=val+off;
  142243. }
  142244. vorbis_fpu_restore(fpu);
  142245. }else{
  142246. int off=(sgned?0:32768);
  142247. if(host_endian==bigendianp){
  142248. if(sgned){
  142249. vorbis_fpu_setround(&fpu);
  142250. for(i=0;i<channels;i++) { /* It's faster in this order */
  142251. float *src=pcm[i];
  142252. short *dest=((short *)buffer)+i;
  142253. for(j=0;j<samples;j++) {
  142254. val=vorbis_ftoi(src[j]*32768.f);
  142255. if(val>32767)val=32767;
  142256. else if(val<-32768)val=-32768;
  142257. *dest=val;
  142258. dest+=channels;
  142259. }
  142260. }
  142261. vorbis_fpu_restore(fpu);
  142262. }else{
  142263. vorbis_fpu_setround(&fpu);
  142264. for(i=0;i<channels;i++) {
  142265. float *src=pcm[i];
  142266. short *dest=((short *)buffer)+i;
  142267. for(j=0;j<samples;j++) {
  142268. val=vorbis_ftoi(src[j]*32768.f);
  142269. if(val>32767)val=32767;
  142270. else if(val<-32768)val=-32768;
  142271. *dest=val+off;
  142272. dest+=channels;
  142273. }
  142274. }
  142275. vorbis_fpu_restore(fpu);
  142276. }
  142277. }else if(bigendianp){
  142278. vorbis_fpu_setround(&fpu);
  142279. for(j=0;j<samples;j++)
  142280. for(i=0;i<channels;i++){
  142281. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142282. if(val>32767)val=32767;
  142283. else if(val<-32768)val=-32768;
  142284. val+=off;
  142285. *buffer++=(val>>8);
  142286. *buffer++=(val&0xff);
  142287. }
  142288. vorbis_fpu_restore(fpu);
  142289. }else{
  142290. int val;
  142291. vorbis_fpu_setround(&fpu);
  142292. for(j=0;j<samples;j++)
  142293. for(i=0;i<channels;i++){
  142294. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142295. if(val>32767)val=32767;
  142296. else if(val<-32768)val=-32768;
  142297. val+=off;
  142298. *buffer++=(val&0xff);
  142299. *buffer++=(val>>8);
  142300. }
  142301. vorbis_fpu_restore(fpu);
  142302. }
  142303. }
  142304. }
  142305. vorbis_synthesis_read(&vf->vd,samples);
  142306. vf->pcm_offset+=samples;
  142307. if(bitstream)*bitstream=vf->current_link;
  142308. return(samples*bytespersample);
  142309. }else{
  142310. return(samples);
  142311. }
  142312. }
  142313. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  142314. int *bitstream){
  142315. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142316. while(1){
  142317. if(vf->ready_state==INITSET){
  142318. float **pcm;
  142319. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142320. if(samples){
  142321. if(pcm_channels)*pcm_channels=pcm;
  142322. if(samples>length)samples=length;
  142323. vorbis_synthesis_read(&vf->vd,samples);
  142324. vf->pcm_offset+=samples;
  142325. if(bitstream)*bitstream=vf->current_link;
  142326. return samples;
  142327. }
  142328. }
  142329. {
  142330. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142331. if(ret==OV_EOF)return(0);
  142332. if(ret<=0)return(ret);
  142333. }
  142334. }
  142335. }
  142336. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  142337. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  142338. ogg_int64_t off);
  142339. static void _ov_splice(float **pcm,float **lappcm,
  142340. int n1, int n2,
  142341. int ch1, int ch2,
  142342. float *w1, float *w2){
  142343. int i,j;
  142344. float *w=w1;
  142345. int n=n1;
  142346. if(n1>n2){
  142347. n=n2;
  142348. w=w2;
  142349. }
  142350. for(j=0;j<ch1 && j<ch2;j++){
  142351. float *s=lappcm[j];
  142352. float *d=pcm[j];
  142353. for(i=0;i<n;i++){
  142354. float wd=w[i]*w[i];
  142355. float ws=1.-wd;
  142356. d[i]=d[i]*wd + s[i]*ws;
  142357. }
  142358. }
  142359. for(;j<ch2;j++){
  142360. float *d=pcm[j];
  142361. for(i=0;i<n;i++){
  142362. float wd=w[i]*w[i];
  142363. d[i]=d[i]*wd;
  142364. }
  142365. }
  142366. }
  142367. static int _ov_initset(OggVorbis_File *vf){
  142368. while(1){
  142369. if(vf->ready_state==INITSET)break;
  142370. {
  142371. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142372. if(ret<0 && ret!=OV_HOLE)return(ret);
  142373. }
  142374. }
  142375. return 0;
  142376. }
  142377. static int _ov_initprime(OggVorbis_File *vf){
  142378. vorbis_dsp_state *vd=&vf->vd;
  142379. while(1){
  142380. if(vf->ready_state==INITSET)
  142381. if(vorbis_synthesis_pcmout(vd,NULL))break;
  142382. {
  142383. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142384. if(ret<0 && ret!=OV_HOLE)return(ret);
  142385. }
  142386. }
  142387. return 0;
  142388. }
  142389. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  142390. float **lappcm,int lapsize){
  142391. int lapcount=0,i;
  142392. float **pcm;
  142393. while(lapcount<lapsize){
  142394. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  142395. if(samples){
  142396. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142397. for(i=0;i<vi->channels;i++)
  142398. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142399. lapcount+=samples;
  142400. vorbis_synthesis_read(vd,samples);
  142401. }else{
  142402. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  142403. if(ret==OV_EOF)break;
  142404. }
  142405. }
  142406. if(lapcount<lapsize){
  142407. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  142408. if(samples==0){
  142409. for(i=0;i<vi->channels;i++)
  142410. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  142411. lapcount=lapsize;
  142412. }else{
  142413. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142414. for(i=0;i<vi->channels;i++)
  142415. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142416. lapcount+=samples;
  142417. }
  142418. }
  142419. }
  142420. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  142421. vorbis_info *vi1,*vi2;
  142422. float **lappcm;
  142423. float **pcm;
  142424. float *w1,*w2;
  142425. int n1,n2,i,ret,hs1,hs2;
  142426. if(vf1==vf2)return(0); /* degenerate case */
  142427. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  142428. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  142429. ret=_ov_initset(vf1);
  142430. if(ret)return(ret);
  142431. ret=_ov_initprime(vf2);
  142432. if(ret)return(ret);
  142433. vi1=ov_info(vf1,-1);
  142434. vi2=ov_info(vf2,-1);
  142435. hs1=ov_halfrate_p(vf1);
  142436. hs2=ov_halfrate_p(vf2);
  142437. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  142438. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  142439. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  142440. w1=vorbis_window(&vf1->vd,0);
  142441. w2=vorbis_window(&vf2->vd,0);
  142442. for(i=0;i<vi1->channels;i++)
  142443. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142444. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  142445. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  142446. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  142447. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  142448. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  142449. return(0);
  142450. }
  142451. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  142452. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  142453. vorbis_info *vi;
  142454. float **lappcm;
  142455. float **pcm;
  142456. float *w1,*w2;
  142457. int n1,n2,ch1,ch2,hs;
  142458. int i,ret;
  142459. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142460. ret=_ov_initset(vf);
  142461. if(ret)return(ret);
  142462. vi=ov_info(vf,-1);
  142463. hs=ov_halfrate_p(vf);
  142464. ch1=vi->channels;
  142465. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142466. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142467. persistent; even if the decode state
  142468. from this link gets dumped, this
  142469. window array continues to exist */
  142470. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142471. for(i=0;i<ch1;i++)
  142472. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142473. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142474. ret=localseek(vf,pos);
  142475. if(ret)return ret;
  142476. ret=_ov_initprime(vf);
  142477. if(ret)return(ret);
  142478. vi=ov_info(vf,-1);
  142479. ch2=vi->channels;
  142480. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142481. w2=vorbis_window(&vf->vd,0);
  142482. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142483. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142484. return(0);
  142485. }
  142486. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142487. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  142488. }
  142489. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142490. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  142491. }
  142492. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142493. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  142494. }
  142495. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  142496. int (*localseek)(OggVorbis_File *,double)){
  142497. vorbis_info *vi;
  142498. float **lappcm;
  142499. float **pcm;
  142500. float *w1,*w2;
  142501. int n1,n2,ch1,ch2,hs;
  142502. int i,ret;
  142503. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142504. ret=_ov_initset(vf);
  142505. if(ret)return(ret);
  142506. vi=ov_info(vf,-1);
  142507. hs=ov_halfrate_p(vf);
  142508. ch1=vi->channels;
  142509. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142510. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142511. persistent; even if the decode state
  142512. from this link gets dumped, this
  142513. window array continues to exist */
  142514. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142515. for(i=0;i<ch1;i++)
  142516. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142517. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142518. ret=localseek(vf,pos);
  142519. if(ret)return ret;
  142520. ret=_ov_initprime(vf);
  142521. if(ret)return(ret);
  142522. vi=ov_info(vf,-1);
  142523. ch2=vi->channels;
  142524. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142525. w2=vorbis_window(&vf->vd,0);
  142526. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142527. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142528. return(0);
  142529. }
  142530. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142531. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142532. }
  142533. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142534. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142535. }
  142536. #endif
  142537. /*** End of inlined file: vorbisfile.c ***/
  142538. /*** Start of inlined file: window.c ***/
  142539. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  142540. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142541. // tasks..
  142542. #if JUCE_MSVC
  142543. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142544. #endif
  142545. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  142546. #if JUCE_USE_OGGVORBIS
  142547. #include <stdlib.h>
  142548. #include <math.h>
  142549. static float vwin64[32] = {
  142550. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142551. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142552. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142553. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142554. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142555. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142556. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142557. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142558. };
  142559. static float vwin128[64] = {
  142560. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142561. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142562. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142563. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142564. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142565. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142566. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142567. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142568. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142569. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142570. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142571. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142572. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142573. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142574. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142575. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142576. };
  142577. static float vwin256[128] = {
  142578. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142579. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142580. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142581. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142582. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142583. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142584. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142585. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142586. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142587. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142588. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142589. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142590. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142591. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142592. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142593. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142594. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142595. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142596. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142597. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142598. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142599. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142600. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142601. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142602. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142603. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142604. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142605. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142606. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142607. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142608. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142609. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142610. };
  142611. static float vwin512[256] = {
  142612. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142613. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142614. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142615. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142616. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142617. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142618. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142619. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142620. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142621. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142622. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142623. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142624. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142625. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142626. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142627. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142628. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142629. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142630. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142631. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142632. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142633. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142634. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142635. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142636. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142637. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142638. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142639. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142640. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142641. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142642. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142643. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142644. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142645. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142646. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142647. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142648. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142649. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142650. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142651. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142652. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142653. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142654. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142655. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142656. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142657. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142658. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142659. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142660. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142661. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142662. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142663. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142664. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142665. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142666. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142667. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142668. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142669. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142670. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142671. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142672. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142673. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142674. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142675. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142676. };
  142677. static float vwin1024[512] = {
  142678. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142679. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142680. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142681. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142682. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142683. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142684. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142685. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142686. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142687. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142688. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142689. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142690. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142691. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142692. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142693. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142694. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142695. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142696. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142697. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142698. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142699. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142700. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142701. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142702. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142703. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142704. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142705. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142706. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142707. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142708. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142709. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142710. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142711. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142712. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142713. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142714. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142715. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142716. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142717. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142718. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142719. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142720. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142721. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142722. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142723. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142724. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142725. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142726. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142727. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142728. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142729. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142730. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142731. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142732. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142733. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142734. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142735. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142736. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142737. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142738. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142739. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142740. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142741. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142742. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142743. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142744. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142745. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142746. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142747. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142748. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142749. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142750. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142751. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142752. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142753. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142754. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142755. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142756. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142757. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142758. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142759. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142760. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142761. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142762. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142763. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142764. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142765. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142766. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142767. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142768. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142769. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142770. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142771. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142772. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142773. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142774. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142775. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142776. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142777. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142778. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142779. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142780. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142781. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142782. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142783. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142784. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142785. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142786. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142787. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142788. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142789. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142790. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142791. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142792. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142793. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142794. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142795. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142796. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142797. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142798. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142799. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142800. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142801. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142802. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142803. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142804. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142805. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142806. };
  142807. static float vwin2048[1024] = {
  142808. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142809. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142810. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142811. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142812. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142813. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142814. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142815. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142816. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142817. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142818. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142819. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142820. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142821. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142822. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142823. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142824. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142825. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142826. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142827. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142828. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142829. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142830. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142831. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142832. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142833. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142834. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142835. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142836. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142837. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142838. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142839. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142840. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142841. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142842. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142843. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142844. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142845. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142846. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142847. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142848. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142849. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142850. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142851. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142852. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142853. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142854. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142855. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142856. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142857. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142858. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142859. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142860. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142861. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142862. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142863. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142864. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142865. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142866. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142867. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142868. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142869. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142870. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142871. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142872. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142873. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142874. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142875. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142876. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142877. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142878. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142879. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142880. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142881. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142882. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142883. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142884. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142885. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142886. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142887. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142888. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142889. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142890. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142891. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142892. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142893. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142894. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142895. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142896. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142897. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142898. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142899. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142900. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142901. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142902. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142903. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142904. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142905. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142906. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142907. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142908. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142909. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142910. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142911. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142912. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142913. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142914. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142915. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142916. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142917. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142918. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142919. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142920. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142921. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142922. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142923. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142924. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142925. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142926. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142927. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142928. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142929. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142930. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142931. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142932. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142933. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142934. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142935. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142936. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142937. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142938. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142939. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142940. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142941. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142942. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142943. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142944. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142945. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142946. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142947. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142948. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142949. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142950. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142951. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142952. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142953. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142954. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142955. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142956. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142957. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142958. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142959. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142960. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142961. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142962. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142963. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142964. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142965. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142966. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142967. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142968. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142969. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142970. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142971. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142972. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142973. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142974. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142975. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142976. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142977. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142978. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142979. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142980. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142981. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142982. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142983. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142984. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142985. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142986. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142987. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142988. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142989. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142990. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142991. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142992. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142993. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142994. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142995. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142996. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142997. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142998. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142999. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  143000. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  143001. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  143002. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  143003. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  143004. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  143005. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  143006. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  143007. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  143008. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  143009. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  143010. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  143011. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  143012. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  143013. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  143014. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  143015. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  143016. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  143017. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  143018. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  143019. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  143020. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  143021. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  143022. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  143023. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  143024. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  143025. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  143026. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  143027. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  143028. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  143029. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  143030. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  143031. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  143032. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  143033. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  143034. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  143035. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  143036. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  143037. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  143038. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  143039. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  143040. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  143041. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  143042. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  143043. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  143044. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  143045. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  143046. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  143047. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  143048. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  143049. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  143050. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  143051. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  143052. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  143053. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  143054. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  143055. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  143056. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  143057. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  143058. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  143059. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  143060. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  143061. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  143062. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  143063. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  143064. };
  143065. static float vwin4096[2048] = {
  143066. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  143067. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  143068. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  143069. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  143070. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  143071. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  143072. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  143073. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  143074. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  143075. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  143076. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  143077. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  143078. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  143079. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  143080. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  143081. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  143082. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  143083. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  143084. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  143085. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  143086. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  143087. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  143088. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  143089. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  143090. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  143091. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  143092. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  143093. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  143094. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  143095. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  143096. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  143097. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  143098. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  143099. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  143100. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  143101. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  143102. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  143103. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  143104. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  143105. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  143106. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  143107. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  143108. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  143109. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  143110. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  143111. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  143112. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  143113. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  143114. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  143115. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  143116. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  143117. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  143118. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  143119. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  143120. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  143121. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  143122. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  143123. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  143124. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  143125. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  143126. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  143127. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  143128. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  143129. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  143130. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  143131. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  143132. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  143133. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  143134. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  143135. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  143136. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  143137. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  143138. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  143139. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  143140. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  143141. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  143142. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  143143. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  143144. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  143145. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  143146. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  143147. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  143148. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  143149. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  143150. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  143151. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  143152. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  143153. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  143154. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  143155. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  143156. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  143157. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  143158. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  143159. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  143160. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  143161. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  143162. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  143163. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  143164. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  143165. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  143166. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  143167. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  143168. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  143169. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  143170. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  143171. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  143172. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  143173. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  143174. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  143175. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  143176. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  143177. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  143178. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  143179. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  143180. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  143181. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  143182. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  143183. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  143184. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  143185. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  143186. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  143187. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  143188. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  143189. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  143190. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  143191. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  143192. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  143193. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  143194. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  143195. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  143196. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  143197. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  143198. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  143199. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  143200. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  143201. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  143202. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  143203. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  143204. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  143205. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  143206. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  143207. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  143208. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  143209. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  143210. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  143211. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  143212. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  143213. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  143214. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  143215. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  143216. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  143217. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  143218. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  143219. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  143220. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  143221. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  143222. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  143223. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  143224. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  143225. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  143226. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  143227. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  143228. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  143229. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  143230. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  143231. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  143232. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  143233. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  143234. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  143235. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  143236. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  143237. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  143238. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  143239. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  143240. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  143241. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  143242. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  143243. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  143244. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  143245. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  143246. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  143247. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  143248. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  143249. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  143250. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  143251. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  143252. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  143253. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  143254. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  143255. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  143256. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  143257. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  143258. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  143259. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  143260. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  143261. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  143262. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  143263. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  143264. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  143265. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  143266. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  143267. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  143268. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  143269. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  143270. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  143271. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  143272. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  143273. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  143274. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  143275. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  143276. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  143277. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  143278. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  143279. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  143280. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  143281. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  143282. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  143283. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  143284. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  143285. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  143286. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  143287. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  143288. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  143289. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  143290. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  143291. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  143292. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  143293. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  143294. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  143295. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  143296. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  143297. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  143298. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  143299. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  143300. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  143301. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  143302. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  143303. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  143304. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  143305. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  143306. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  143307. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  143308. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  143309. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  143310. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  143311. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  143312. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  143313. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  143314. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  143315. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  143316. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  143317. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  143318. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  143319. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  143320. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  143321. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  143322. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  143323. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  143324. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  143325. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  143326. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  143327. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  143328. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  143329. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  143330. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  143331. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  143332. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  143333. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  143334. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  143335. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  143336. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  143337. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  143338. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  143339. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  143340. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  143341. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  143342. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  143343. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  143344. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  143345. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  143346. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  143347. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  143348. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  143349. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  143350. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  143351. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  143352. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  143353. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  143354. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  143355. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  143356. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  143357. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  143358. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  143359. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  143360. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  143361. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  143362. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  143363. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  143364. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  143365. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  143366. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  143367. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  143368. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  143369. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  143370. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  143371. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  143372. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  143373. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  143374. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  143375. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  143376. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  143377. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  143378. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  143379. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  143380. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  143381. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  143382. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  143383. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  143384. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  143385. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  143386. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  143387. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  143388. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  143389. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  143390. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  143391. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  143392. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  143393. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  143394. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  143395. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  143396. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  143397. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  143398. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  143399. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  143400. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  143401. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  143402. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  143403. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  143404. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  143405. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  143406. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  143407. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  143408. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  143409. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  143410. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  143411. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  143412. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  143413. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  143414. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  143415. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  143416. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  143417. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  143418. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  143419. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  143420. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  143421. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  143422. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  143423. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  143424. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  143425. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  143426. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  143427. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  143428. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  143429. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  143430. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  143431. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  143432. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  143433. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  143434. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  143435. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  143436. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  143437. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  143438. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  143439. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  143440. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  143441. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  143442. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  143443. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  143444. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  143445. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  143446. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  143447. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  143448. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  143449. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  143450. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  143451. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  143452. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  143453. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  143454. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  143455. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  143456. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  143457. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  143458. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  143459. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  143460. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  143461. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  143462. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  143463. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  143464. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  143465. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  143466. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  143467. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  143468. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  143469. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  143470. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  143471. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  143472. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  143473. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  143474. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  143475. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  143476. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  143477. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  143478. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  143479. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  143480. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  143481. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  143482. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  143483. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  143484. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  143485. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  143486. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  143487. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  143488. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  143489. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  143490. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  143491. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  143492. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  143493. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  143494. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  143495. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  143496. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  143497. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  143498. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  143499. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  143500. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  143501. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  143502. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  143503. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  143504. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  143505. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  143506. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  143507. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  143508. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  143509. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  143510. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  143511. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  143512. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  143513. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  143514. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  143515. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  143516. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  143517. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  143518. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  143519. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  143520. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  143521. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  143522. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  143523. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  143524. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  143525. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143526. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143527. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143528. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143529. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143530. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143531. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143532. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143533. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143534. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143535. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143536. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143537. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143538. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143539. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143540. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143541. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143542. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143543. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143544. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143545. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143546. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143547. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143548. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143549. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143550. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143551. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143552. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143553. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143554. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143555. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143556. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143557. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143558. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143559. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143560. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143561. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143562. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143563. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143564. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143565. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143566. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143567. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143568. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143569. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143570. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143571. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143572. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143573. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143574. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143575. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143576. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143577. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143578. };
  143579. static float vwin8192[4096] = {
  143580. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143581. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143582. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143583. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143584. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143585. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143586. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143587. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143588. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143589. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143590. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143591. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143592. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143593. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143594. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143595. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143596. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143597. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143598. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143599. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143600. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143601. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143602. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143603. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143604. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143605. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143606. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143607. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143608. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143609. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143610. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143611. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143612. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143613. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143614. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143615. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143616. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143617. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143618. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143619. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143620. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143621. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143622. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143623. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143624. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143625. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143626. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143627. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143628. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143629. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143630. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143631. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143632. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143633. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143634. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143635. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143636. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143637. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143638. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143639. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143640. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143641. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143642. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143643. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143644. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143645. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143646. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143647. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143648. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143649. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143650. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143651. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143652. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143653. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143654. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143655. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143656. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143657. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143658. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143659. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143660. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143661. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143662. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143663. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143664. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143665. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143666. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143667. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143668. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143669. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143670. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143671. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143672. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143673. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143674. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143675. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143676. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143677. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143678. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143679. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143680. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143681. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143682. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143683. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143684. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143685. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143686. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143687. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143688. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143689. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143690. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143691. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143692. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143693. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143694. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143695. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143696. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143697. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143698. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143699. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143700. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143701. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143702. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143703. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143704. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143705. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143706. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143707. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143708. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143709. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143710. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143711. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143712. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143713. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143714. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143715. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143716. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143717. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143718. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143719. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143720. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143721. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143722. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143723. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143724. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143725. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143726. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143727. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143728. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143729. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143730. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143731. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143732. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143733. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143734. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143735. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143736. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143737. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143738. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143739. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143740. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143741. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143742. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143743. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143744. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143745. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143746. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143747. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143748. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143749. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143750. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143751. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143752. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143753. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143754. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143755. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143756. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143757. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143758. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143759. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143760. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143761. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143762. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143763. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143764. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143765. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143766. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143767. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143768. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143769. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143770. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143771. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143772. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143773. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143774. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143775. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143776. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143777. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143778. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143779. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143780. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143781. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143782. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143783. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143784. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143785. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143786. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143787. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143788. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143789. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143790. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143791. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143792. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143793. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143794. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143795. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143796. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143797. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143798. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143799. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143800. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143801. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143802. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143803. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143804. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143805. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143806. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143807. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143808. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143809. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143810. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143811. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143812. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143813. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143814. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143815. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143816. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143817. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143818. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143819. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143820. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143821. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143822. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143823. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143824. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143825. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143826. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143827. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143828. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143829. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143830. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143831. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143832. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143833. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143834. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143835. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143836. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143837. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143838. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143839. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143840. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143841. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143842. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143843. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143844. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143845. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143846. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143847. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143848. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143849. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143850. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143851. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143852. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143853. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143854. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143855. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143856. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143857. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143858. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143859. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143860. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143861. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143862. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143863. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143864. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143865. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143866. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143867. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143868. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143869. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143870. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143871. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143872. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143873. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143874. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143875. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143876. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143877. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143878. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143879. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143880. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143881. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143882. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143883. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143884. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143885. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143886. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143887. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143888. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143889. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143890. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143891. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143892. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143893. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143894. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143895. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143896. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143897. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143898. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143899. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143900. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143901. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143902. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143903. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143904. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143905. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143906. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143907. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143908. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143909. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143910. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143911. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143912. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143913. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143914. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143915. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143916. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143917. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143918. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143919. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143920. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143921. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143922. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143923. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143924. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143925. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143926. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143927. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143928. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143929. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143930. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143931. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143932. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143933. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143934. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143935. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143936. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143937. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143938. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143939. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143940. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143941. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143942. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143943. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143944. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143945. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143946. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143947. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143948. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143949. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143950. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143951. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143952. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143953. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143954. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143955. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143956. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143957. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143958. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143959. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143960. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143961. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143962. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143963. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143964. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143965. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143966. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143967. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143968. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143969. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143970. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143971. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143972. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143973. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143974. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143975. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143976. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143977. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143978. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143979. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143980. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143981. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143982. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143983. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143984. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143985. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143986. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143987. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143988. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143989. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143990. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143991. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143992. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143993. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143994. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143995. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143996. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143997. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143998. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143999. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  144000. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  144001. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  144002. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  144003. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  144004. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  144005. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  144006. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  144007. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  144008. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  144009. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  144010. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  144011. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  144012. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  144013. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  144014. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  144015. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  144016. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  144017. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  144018. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  144019. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  144020. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  144021. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  144022. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  144023. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  144024. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  144025. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  144026. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  144027. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  144028. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  144029. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  144030. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  144031. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  144032. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  144033. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  144034. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  144035. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  144036. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  144037. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  144038. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  144039. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  144040. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  144041. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  144042. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  144043. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  144044. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  144045. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  144046. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  144047. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  144048. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  144049. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  144050. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  144051. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  144052. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  144053. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  144054. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  144055. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  144056. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  144057. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  144058. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  144059. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  144060. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  144061. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  144062. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  144063. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  144064. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  144065. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  144066. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  144067. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  144068. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  144069. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  144070. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  144071. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  144072. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  144073. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  144074. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  144075. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  144076. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  144077. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  144078. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  144079. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  144080. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  144081. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  144082. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  144083. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  144084. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  144085. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  144086. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  144087. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  144088. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  144089. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  144090. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  144091. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  144092. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  144093. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  144094. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  144095. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  144096. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  144097. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  144098. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  144099. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  144100. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  144101. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  144102. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  144103. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  144104. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  144105. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  144106. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  144107. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  144108. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  144109. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  144110. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  144111. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  144112. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  144113. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  144114. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  144115. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  144116. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  144117. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  144118. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  144119. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  144120. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  144121. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  144122. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  144123. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  144124. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  144125. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  144126. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  144127. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  144128. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  144129. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  144130. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  144131. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  144132. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  144133. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  144134. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  144135. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  144136. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  144137. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  144138. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  144139. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  144140. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  144141. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  144142. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  144143. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  144144. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  144145. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  144146. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  144147. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  144148. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  144149. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  144150. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  144151. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  144152. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  144153. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  144154. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  144155. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  144156. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  144157. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  144158. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  144159. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  144160. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  144161. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  144162. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  144163. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  144164. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  144165. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  144166. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  144167. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  144168. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  144169. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  144170. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  144171. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  144172. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  144173. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  144174. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  144175. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  144176. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  144177. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  144178. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  144179. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  144180. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  144181. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  144182. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  144183. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  144184. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  144185. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  144186. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  144187. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  144188. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  144189. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  144190. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  144191. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  144192. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  144193. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  144194. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  144195. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  144196. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  144197. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  144198. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  144199. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  144200. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  144201. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  144202. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  144203. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  144204. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  144205. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  144206. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  144207. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  144208. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  144209. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  144210. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  144211. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  144212. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  144213. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  144214. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  144215. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  144216. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  144217. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  144218. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  144219. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  144220. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  144221. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  144222. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  144223. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  144224. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  144225. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  144226. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  144227. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  144228. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  144229. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  144230. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  144231. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  144232. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  144233. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  144234. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  144235. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  144236. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  144237. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  144238. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  144239. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  144240. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  144241. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  144242. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  144243. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  144244. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  144245. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  144246. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  144247. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  144248. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  144249. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  144250. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  144251. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  144252. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  144253. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  144254. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  144255. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  144256. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  144257. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  144258. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  144259. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  144260. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  144261. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  144262. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  144263. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  144264. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  144265. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  144266. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  144267. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  144268. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  144269. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  144270. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  144271. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  144272. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  144273. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  144274. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  144275. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  144276. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  144277. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  144278. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  144279. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  144280. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  144281. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  144282. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  144283. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  144284. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  144285. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  144286. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  144287. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  144288. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  144289. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  144290. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  144291. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  144292. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  144293. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  144294. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  144295. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  144296. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  144297. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  144298. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  144299. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  144300. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  144301. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  144302. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  144303. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  144304. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  144305. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  144306. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  144307. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  144308. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  144309. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  144310. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  144311. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  144312. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  144313. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  144314. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  144315. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  144316. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  144317. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  144318. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  144319. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  144320. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  144321. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  144322. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  144323. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  144324. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  144325. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  144326. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  144327. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  144328. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  144329. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  144330. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  144331. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  144332. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  144333. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  144334. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  144335. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  144336. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  144337. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  144338. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  144339. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  144340. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  144341. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  144342. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  144343. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  144344. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  144345. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  144346. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  144347. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  144348. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  144349. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  144350. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  144351. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  144352. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  144353. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  144354. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  144355. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  144356. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  144357. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  144358. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  144359. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  144360. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  144361. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  144362. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  144363. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  144364. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  144365. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  144366. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  144367. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  144368. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  144369. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  144370. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  144371. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  144372. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  144373. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  144374. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  144375. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  144376. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  144377. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  144378. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  144379. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  144380. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  144381. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  144382. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  144383. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  144384. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  144385. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  144386. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  144387. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  144388. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  144389. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  144390. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  144391. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  144392. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  144393. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  144394. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  144395. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  144396. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  144397. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  144398. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  144399. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  144400. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  144401. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  144402. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  144403. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  144404. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  144405. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  144406. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  144407. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  144408. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  144409. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  144410. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  144411. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  144412. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  144413. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  144414. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  144415. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  144416. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  144417. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  144418. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  144419. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  144420. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  144421. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  144422. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  144423. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  144424. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  144425. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  144426. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  144427. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  144428. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  144429. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  144430. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  144431. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  144432. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  144433. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  144434. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  144435. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  144436. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  144437. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  144438. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  144439. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  144440. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  144441. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  144442. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  144443. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  144444. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  144445. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  144446. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  144447. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  144448. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  144449. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  144450. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  144451. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  144452. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  144453. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  144454. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  144455. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  144456. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  144457. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  144458. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  144459. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  144460. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  144461. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  144462. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  144463. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  144464. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  144465. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  144466. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  144467. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  144468. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  144469. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  144470. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  144471. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  144472. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  144473. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  144474. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  144475. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  144476. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  144477. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  144478. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  144479. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  144480. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  144481. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  144482. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  144483. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  144484. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  144485. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  144486. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  144487. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  144488. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  144489. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  144490. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  144491. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  144492. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  144493. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  144494. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  144495. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  144496. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  144497. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  144498. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  144499. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  144500. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  144501. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  144502. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  144503. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  144504. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  144505. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  144506. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  144507. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  144508. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  144509. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  144510. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  144511. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  144512. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  144513. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  144514. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  144515. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  144516. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  144517. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  144518. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  144519. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  144520. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  144521. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  144522. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  144523. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  144524. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  144525. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144526. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144527. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144528. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144529. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144530. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144531. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144532. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144533. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144534. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144535. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144536. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144537. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144538. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144539. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144540. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144541. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144542. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144543. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144544. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144545. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144546. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144547. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144548. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144549. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144550. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144551. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144552. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144553. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144554. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144555. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144556. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144557. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144558. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144559. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144560. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144561. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144562. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144563. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144564. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144565. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144566. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144567. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144568. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144569. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144570. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144571. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144572. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144573. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144574. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144575. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144576. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144577. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144578. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144579. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144580. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144581. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144582. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144583. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144584. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144585. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144586. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144587. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144588. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144589. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144590. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144591. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144592. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144593. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144594. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144595. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144596. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144597. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144598. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144599. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144600. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144601. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144602. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144603. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144604. };
  144605. static float *vwin[8] = {
  144606. vwin64,
  144607. vwin128,
  144608. vwin256,
  144609. vwin512,
  144610. vwin1024,
  144611. vwin2048,
  144612. vwin4096,
  144613. vwin8192,
  144614. };
  144615. float *_vorbis_window_get(int n){
  144616. return vwin[n];
  144617. }
  144618. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144619. int lW,int W,int nW){
  144620. lW=(W?lW:0);
  144621. nW=(W?nW:0);
  144622. {
  144623. float *windowLW=vwin[winno[lW]];
  144624. float *windowNW=vwin[winno[nW]];
  144625. long n=blocksizes[W];
  144626. long ln=blocksizes[lW];
  144627. long rn=blocksizes[nW];
  144628. long leftbegin=n/4-ln/4;
  144629. long leftend=leftbegin+ln/2;
  144630. long rightbegin=n/2+n/4-rn/4;
  144631. long rightend=rightbegin+rn/2;
  144632. int i,p;
  144633. for(i=0;i<leftbegin;i++)
  144634. d[i]=0.f;
  144635. for(p=0;i<leftend;i++,p++)
  144636. d[i]*=windowLW[p];
  144637. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144638. d[i]*=windowNW[p];
  144639. for(;i<n;i++)
  144640. d[i]=0.f;
  144641. }
  144642. }
  144643. #endif
  144644. /*** End of inlined file: window.c ***/
  144645. #else
  144646. #include <vorbis/vorbisenc.h>
  144647. #include <vorbis/codec.h>
  144648. #include <vorbis/vorbisfile.h>
  144649. #endif
  144650. }
  144651. BEGIN_JUCE_NAMESPACE
  144652. using namespace OggVorbisNamespace;
  144653. static const char* const oggFormatName = "Ogg-Vorbis file";
  144654. static const tchar* const oggExtensions[] = { T(".ogg"), 0 };
  144655. class OggReader : public AudioFormatReader
  144656. {
  144657. OggVorbis_File ovFile;
  144658. ov_callbacks callbacks;
  144659. AudioSampleBuffer reservoir;
  144660. int reservoirStart, samplesInReservoir;
  144661. public:
  144662. OggReader (InputStream* const inp)
  144663. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144664. reservoir (2, 4096),
  144665. reservoirStart (0),
  144666. samplesInReservoir (0)
  144667. {
  144668. sampleRate = 0;
  144669. usesFloatingPointData = true;
  144670. callbacks.read_func = &oggReadCallback;
  144671. callbacks.seek_func = &oggSeekCallback;
  144672. callbacks.close_func = &oggCloseCallback;
  144673. callbacks.tell_func = &oggTellCallback;
  144674. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144675. if (err == 0)
  144676. {
  144677. vorbis_info* info = ov_info (&ovFile, -1);
  144678. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144679. numChannels = info->channels;
  144680. bitsPerSample = 16;
  144681. sampleRate = info->rate;
  144682. reservoir.setSize (numChannels,
  144683. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144684. }
  144685. }
  144686. ~OggReader()
  144687. {
  144688. ov_clear (&ovFile);
  144689. }
  144690. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144691. int64 startSampleInFile, int numSamples)
  144692. {
  144693. while (numSamples > 0)
  144694. {
  144695. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144696. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144697. {
  144698. // got a few samples overlapping, so use them before seeking..
  144699. const int numToUse = jmin (numSamples, numAvailable);
  144700. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144701. if (destSamples[i] != 0)
  144702. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144703. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144704. sizeof (float) * numToUse);
  144705. startSampleInFile += numToUse;
  144706. numSamples -= numToUse;
  144707. startOffsetInDestBuffer += numToUse;
  144708. if (numSamples == 0)
  144709. break;
  144710. }
  144711. if (startSampleInFile < reservoirStart
  144712. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144713. {
  144714. // buffer miss, so refill the reservoir
  144715. int bitStream = 0;
  144716. reservoirStart = jmax (0, (int) startSampleInFile);
  144717. samplesInReservoir = reservoir.getNumSamples();
  144718. if (reservoirStart != (int) ov_pcm_tell (&ovFile))
  144719. ov_pcm_seek (&ovFile, reservoirStart);
  144720. int offset = 0;
  144721. int numToRead = samplesInReservoir;
  144722. while (numToRead > 0)
  144723. {
  144724. float** dataIn = 0;
  144725. const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144726. if (samps <= 0)
  144727. break;
  144728. jassert (samps <= numToRead);
  144729. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144730. {
  144731. memcpy (reservoir.getSampleData (i, offset),
  144732. dataIn[i],
  144733. sizeof (float) * samps);
  144734. }
  144735. numToRead -= samps;
  144736. offset += samps;
  144737. }
  144738. if (numToRead > 0)
  144739. reservoir.clear (offset, numToRead);
  144740. }
  144741. }
  144742. if (numSamples > 0)
  144743. {
  144744. for (int i = numDestChannels; --i >= 0;)
  144745. if (destSamples[i] != 0)
  144746. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144747. sizeof (int) * numSamples);
  144748. }
  144749. return true;
  144750. }
  144751. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144752. {
  144753. return (size_t) (((InputStream*) datasource)->read (ptr, (int) (size * nmemb)) / size);
  144754. }
  144755. static int oggSeekCallback (void* datasource, ogg_int64_t offset, int whence)
  144756. {
  144757. InputStream* const in = (InputStream*) datasource;
  144758. if (whence == SEEK_CUR)
  144759. offset += in->getPosition();
  144760. else if (whence == SEEK_END)
  144761. offset += in->getTotalLength();
  144762. in->setPosition (offset);
  144763. return 0;
  144764. }
  144765. static int oggCloseCallback (void*)
  144766. {
  144767. return 0;
  144768. }
  144769. static long oggTellCallback (void* datasource)
  144770. {
  144771. return (long) ((InputStream*) datasource)->getPosition();
  144772. }
  144773. juce_UseDebuggingNewOperator
  144774. };
  144775. class OggWriter : public AudioFormatWriter
  144776. {
  144777. ogg_stream_state os;
  144778. ogg_page og;
  144779. ogg_packet op;
  144780. vorbis_info vi;
  144781. vorbis_comment vc;
  144782. vorbis_dsp_state vd;
  144783. vorbis_block vb;
  144784. public:
  144785. bool ok;
  144786. OggWriter (OutputStream* const out,
  144787. const double sampleRate,
  144788. const int numChannels,
  144789. const int bitsPerSample,
  144790. const int qualityIndex)
  144791. : AudioFormatWriter (out, TRANS (oggFormatName),
  144792. sampleRate,
  144793. numChannels,
  144794. bitsPerSample)
  144795. {
  144796. ok = false;
  144797. vorbis_info_init (&vi);
  144798. if (vorbis_encode_init_vbr (&vi,
  144799. numChannels,
  144800. (int) sampleRate,
  144801. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144802. {
  144803. vorbis_comment_init (&vc);
  144804. if (JUCEApplication::getInstance() != 0)
  144805. vorbis_comment_add_tag (&vc, "ENCODER",
  144806. (char*) (const char*) JUCEApplication::getInstance()->getApplicationName());
  144807. vorbis_analysis_init (&vd, &vi);
  144808. vorbis_block_init (&vd, &vb);
  144809. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144810. ogg_packet header;
  144811. ogg_packet header_comm;
  144812. ogg_packet header_code;
  144813. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144814. ogg_stream_packetin (&os, &header);
  144815. ogg_stream_packetin (&os, &header_comm);
  144816. ogg_stream_packetin (&os, &header_code);
  144817. for (;;)
  144818. {
  144819. if (ogg_stream_flush (&os, &og) == 0)
  144820. break;
  144821. output->write (og.header, og.header_len);
  144822. output->write (og.body, og.body_len);
  144823. }
  144824. ok = true;
  144825. }
  144826. }
  144827. ~OggWriter()
  144828. {
  144829. if (ok)
  144830. {
  144831. // write a zero-length packet to show ogg that we're finished..
  144832. write (0, 0);
  144833. ogg_stream_clear (&os);
  144834. vorbis_block_clear (&vb);
  144835. vorbis_dsp_clear (&vd);
  144836. vorbis_comment_clear (&vc);
  144837. vorbis_info_clear (&vi);
  144838. output->flush();
  144839. }
  144840. else
  144841. {
  144842. vorbis_info_clear (&vi);
  144843. output = 0; // to stop the base class deleting this, as it needs to be returned
  144844. // to the caller of createWriter()
  144845. }
  144846. }
  144847. bool write (const int** samplesToWrite, int numSamples)
  144848. {
  144849. if (! ok)
  144850. return false;
  144851. if (numSamples > 0)
  144852. {
  144853. const double gain = 1.0 / 0x80000000u;
  144854. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144855. for (int i = numChannels; --i >= 0;)
  144856. {
  144857. float* const dst = vorbisBuffer[i];
  144858. const int* const src = samplesToWrite [i];
  144859. if (src != 0 && dst != 0)
  144860. {
  144861. for (int j = 0; j < numSamples; ++j)
  144862. dst[j] = (float) (src[j] * gain);
  144863. }
  144864. }
  144865. }
  144866. vorbis_analysis_wrote (&vd, numSamples);
  144867. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144868. {
  144869. vorbis_analysis (&vb, 0);
  144870. vorbis_bitrate_addblock (&vb);
  144871. while (vorbis_bitrate_flushpacket (&vd, &op))
  144872. {
  144873. ogg_stream_packetin (&os, &op);
  144874. for (;;)
  144875. {
  144876. if (ogg_stream_pageout (&os, &og) == 0)
  144877. break;
  144878. output->write (og.header, og.header_len);
  144879. output->write (og.body, og.body_len);
  144880. if (ogg_page_eos (&og))
  144881. break;
  144882. }
  144883. }
  144884. }
  144885. return true;
  144886. }
  144887. juce_UseDebuggingNewOperator
  144888. };
  144889. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144890. : AudioFormat (TRANS (oggFormatName), (const tchar**) oggExtensions)
  144891. {
  144892. }
  144893. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144894. {
  144895. }
  144896. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144897. {
  144898. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144899. return Array <int> (rates);
  144900. }
  144901. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144902. {
  144903. Array <int> depths;
  144904. depths.add (32);
  144905. return depths;
  144906. }
  144907. bool OggVorbisAudioFormat::canDoStereo()
  144908. {
  144909. return true;
  144910. }
  144911. bool OggVorbisAudioFormat::canDoMono()
  144912. {
  144913. return true;
  144914. }
  144915. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144916. const bool deleteStreamIfOpeningFails)
  144917. {
  144918. ScopedPointer <OggReader> r (new OggReader (in));
  144919. if (r->sampleRate != 0)
  144920. return r.release();
  144921. if (! deleteStreamIfOpeningFails)
  144922. r->input = 0;
  144923. return 0;
  144924. }
  144925. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144926. double sampleRate,
  144927. unsigned int numChannels,
  144928. int bitsPerSample,
  144929. const StringPairArray& /*metadataValues*/,
  144930. int qualityOptionIndex)
  144931. {
  144932. ScopedPointer <OggWriter> w (new OggWriter (out,
  144933. sampleRate,
  144934. numChannels,
  144935. bitsPerSample,
  144936. qualityOptionIndex));
  144937. return w->ok ? w.release() : 0;
  144938. }
  144939. bool OggVorbisAudioFormat::isCompressed()
  144940. {
  144941. return true;
  144942. }
  144943. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144944. {
  144945. StringArray s;
  144946. s.add ("Low Quality");
  144947. s.add ("Medium Quality");
  144948. s.add ("High Quality");
  144949. return s;
  144950. }
  144951. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144952. {
  144953. FileInputStream* const in = source.createInputStream();
  144954. if (in != 0)
  144955. {
  144956. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144957. if (r != 0)
  144958. {
  144959. const int64 numSamps = r->lengthInSamples;
  144960. r = 0;
  144961. const int64 fileNumSamps = source.getSize() / 4;
  144962. const double ratio = numSamps / (double) fileNumSamps;
  144963. if (ratio > 12.0)
  144964. return 0;
  144965. else if (ratio > 6.0)
  144966. return 1;
  144967. else
  144968. return 2;
  144969. }
  144970. }
  144971. return 1;
  144972. }
  144973. END_JUCE_NAMESPACE
  144974. #endif
  144975. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144976. #endif
  144977. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144978. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144979. #if JUCE_MSVC
  144980. #pragma warning (push)
  144981. #endif
  144982. namespace jpeglibNamespace
  144983. {
  144984. #if JUCE_INCLUDE_JPEGLIB_CODE
  144985. #if JUCE_MINGW
  144986. typedef unsigned char boolean;
  144987. #endif
  144988. extern "C"
  144989. {
  144990. #define JPEG_INTERNALS
  144991. #undef FAR
  144992. /*** Start of inlined file: jpeglib.h ***/
  144993. #ifndef JPEGLIB_H
  144994. #define JPEGLIB_H
  144995. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144996. /*** Start of inlined file: jconfig.h ***/
  144997. // disable all the warnings under MSVC
  144998. #ifdef _MSC_VER
  144999. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  145000. #endif
  145001. #ifdef __BORLANDC__
  145002. #pragma warn -8057
  145003. #pragma warn -8019
  145004. #pragma warn -8004
  145005. #pragma warn -8008
  145006. #endif
  145007. #define HAVE_PROTOTYPES
  145008. #define HAVE_UNSIGNED_CHAR
  145009. #define HAVE_UNSIGNED_SHORT
  145010. #undef CHAR_IS_UNSIGNED
  145011. #define HAVE_STDDEF_H
  145012. #define HAVE_STDLIB_H
  145013. #undef NEED_BSD_STRINGS
  145014. #undef NEED_SYS_TYPES_H
  145015. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145016. #undef NEED_SHORT_EXTERNAL_NAMES
  145017. #undef INCOMPLETE_TYPES_BROKEN
  145018. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145019. typedef unsigned char boolean;
  145020. #endif
  145021. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145022. #ifdef JPEG_INTERNALS
  145023. #undef RIGHT_SHIFT_IS_UNSIGNED
  145024. #endif /* JPEG_INTERNALS */
  145025. #ifdef JPEG_CJPEG_DJPEG
  145026. #define BMP_SUPPORTED /* BMP image file format */
  145027. #define GIF_SUPPORTED /* GIF image file format */
  145028. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145029. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145030. #define TARGA_SUPPORTED /* Targa image file format */
  145031. #define TWO_FILE_COMMANDLINE /* optional */
  145032. #define USE_SETMODE /* Microsoft has setmode() */
  145033. #undef NEED_SIGNAL_CATCHER
  145034. #undef DONT_USE_B_MODE
  145035. #undef PROGRESS_REPORT /* optional */
  145036. #endif /* JPEG_CJPEG_DJPEG */
  145037. /*** End of inlined file: jconfig.h ***/
  145038. /* widely used configuration options */
  145039. #endif
  145040. /*** Start of inlined file: jmorecfg.h ***/
  145041. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  145042. #define MAX_COMPONENTS 10 /* maximum number of image components */
  145043. #if BITS_IN_JSAMPLE == 8
  145044. #ifdef HAVE_UNSIGNED_CHAR
  145045. typedef unsigned char JSAMPLE;
  145046. #define GETJSAMPLE(value) ((int) (value))
  145047. #else /* not HAVE_UNSIGNED_CHAR */
  145048. typedef char JSAMPLE;
  145049. #ifdef CHAR_IS_UNSIGNED
  145050. #define GETJSAMPLE(value) ((int) (value))
  145051. #else
  145052. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  145053. #endif /* CHAR_IS_UNSIGNED */
  145054. #endif /* HAVE_UNSIGNED_CHAR */
  145055. #define MAXJSAMPLE 255
  145056. #define CENTERJSAMPLE 128
  145057. #endif /* BITS_IN_JSAMPLE == 8 */
  145058. #if BITS_IN_JSAMPLE == 12
  145059. typedef short JSAMPLE;
  145060. #define GETJSAMPLE(value) ((int) (value))
  145061. #define MAXJSAMPLE 4095
  145062. #define CENTERJSAMPLE 2048
  145063. #endif /* BITS_IN_JSAMPLE == 12 */
  145064. typedef short JCOEF;
  145065. #ifdef HAVE_UNSIGNED_CHAR
  145066. typedef unsigned char JOCTET;
  145067. #define GETJOCTET(value) (value)
  145068. #else /* not HAVE_UNSIGNED_CHAR */
  145069. typedef char JOCTET;
  145070. #ifdef CHAR_IS_UNSIGNED
  145071. #define GETJOCTET(value) (value)
  145072. #else
  145073. #define GETJOCTET(value) ((value) & 0xFF)
  145074. #endif /* CHAR_IS_UNSIGNED */
  145075. #endif /* HAVE_UNSIGNED_CHAR */
  145076. #ifdef HAVE_UNSIGNED_CHAR
  145077. typedef unsigned char UINT8;
  145078. #else /* not HAVE_UNSIGNED_CHAR */
  145079. #ifdef CHAR_IS_UNSIGNED
  145080. typedef char UINT8;
  145081. #else /* not CHAR_IS_UNSIGNED */
  145082. typedef short UINT8;
  145083. #endif /* CHAR_IS_UNSIGNED */
  145084. #endif /* HAVE_UNSIGNED_CHAR */
  145085. #ifdef HAVE_UNSIGNED_SHORT
  145086. typedef unsigned short UINT16;
  145087. #else /* not HAVE_UNSIGNED_SHORT */
  145088. typedef unsigned int UINT16;
  145089. #endif /* HAVE_UNSIGNED_SHORT */
  145090. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  145091. typedef short INT16;
  145092. #endif
  145093. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  145094. typedef long INT32;
  145095. #endif
  145096. typedef unsigned int JDIMENSION;
  145097. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  145098. #define METHODDEF(type) static type
  145099. #define LOCAL(type) static type
  145100. #define GLOBAL(type) type
  145101. #define EXTERN(type) extern type
  145102. #ifdef HAVE_PROTOTYPES
  145103. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  145104. #else
  145105. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  145106. #endif
  145107. #ifdef NEED_FAR_POINTERS
  145108. #define FAR far
  145109. #else
  145110. #define FAR
  145111. #endif
  145112. #ifndef HAVE_BOOLEAN
  145113. typedef int boolean;
  145114. #endif
  145115. #ifndef FALSE /* in case these macros already exist */
  145116. #define FALSE 0 /* values of boolean */
  145117. #endif
  145118. #ifndef TRUE
  145119. #define TRUE 1
  145120. #endif
  145121. #ifdef JPEG_INTERNALS
  145122. #define JPEG_INTERNAL_OPTIONS
  145123. #endif
  145124. #ifdef JPEG_INTERNAL_OPTIONS
  145125. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  145126. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  145127. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  145128. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145129. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145130. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145131. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  145132. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  145133. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145134. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145135. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145136. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  145137. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  145138. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  145139. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  145140. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  145141. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  145142. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  145143. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  145144. #define RGB_GREEN 1 /* Offset of Green */
  145145. #define RGB_BLUE 2 /* Offset of Blue */
  145146. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  145147. #ifndef INLINE
  145148. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  145149. #define INLINE __inline__
  145150. #endif
  145151. #ifndef INLINE
  145152. #define INLINE /* default is to define it as empty */
  145153. #endif
  145154. #endif
  145155. #ifndef MULTIPLIER
  145156. #define MULTIPLIER int /* type for fastest integer multiply */
  145157. #endif
  145158. #ifndef FAST_FLOAT
  145159. #ifdef HAVE_PROTOTYPES
  145160. #define FAST_FLOAT float
  145161. #else
  145162. #define FAST_FLOAT double
  145163. #endif
  145164. #endif
  145165. #endif /* JPEG_INTERNAL_OPTIONS */
  145166. /*** End of inlined file: jmorecfg.h ***/
  145167. /* seldom changed options */
  145168. #define JPEG_LIB_VERSION 62 /* Version 6b */
  145169. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  145170. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  145171. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  145172. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  145173. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  145174. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  145175. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  145176. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  145177. #ifndef D_MAX_BLOCKS_IN_MCU
  145178. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  145179. #endif
  145180. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  145181. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  145182. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  145183. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  145184. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  145185. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  145186. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  145187. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  145188. typedef struct {
  145189. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  145190. boolean sent_table; /* TRUE when table has been output */
  145191. } JQUANT_TBL;
  145192. typedef struct {
  145193. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  145194. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  145195. boolean sent_table; /* TRUE when table has been output */
  145196. } JHUFF_TBL;
  145197. typedef struct {
  145198. int component_id; /* identifier for this component (0..255) */
  145199. int component_index; /* its index in SOF or cinfo->comp_info[] */
  145200. int h_samp_factor; /* horizontal sampling factor (1..4) */
  145201. int v_samp_factor; /* vertical sampling factor (1..4) */
  145202. int quant_tbl_no; /* quantization table selector (0..3) */
  145203. int dc_tbl_no; /* DC entropy table selector (0..3) */
  145204. int ac_tbl_no; /* AC entropy table selector (0..3) */
  145205. JDIMENSION width_in_blocks;
  145206. JDIMENSION height_in_blocks;
  145207. int DCT_scaled_size;
  145208. JDIMENSION downsampled_width; /* actual width in samples */
  145209. JDIMENSION downsampled_height; /* actual height in samples */
  145210. boolean component_needed; /* do we need the value of this component? */
  145211. int MCU_width; /* number of blocks per MCU, horizontally */
  145212. int MCU_height; /* number of blocks per MCU, vertically */
  145213. int MCU_blocks; /* MCU_width * MCU_height */
  145214. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  145215. int last_col_width; /* # of non-dummy blocks across in last MCU */
  145216. int last_row_height; /* # of non-dummy blocks down in last MCU */
  145217. JQUANT_TBL * quant_table;
  145218. void * dct_table;
  145219. } jpeg_component_info;
  145220. typedef struct {
  145221. int comps_in_scan; /* number of components encoded in this scan */
  145222. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  145223. int Ss, Se; /* progressive JPEG spectral selection parms */
  145224. int Ah, Al; /* progressive JPEG successive approx. parms */
  145225. } jpeg_scan_info;
  145226. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  145227. struct jpeg_marker_struct {
  145228. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  145229. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  145230. unsigned int original_length; /* # bytes of data in the file */
  145231. unsigned int data_length; /* # bytes of data saved at data[] */
  145232. JOCTET FAR * data; /* the data contained in the marker */
  145233. };
  145234. typedef enum {
  145235. JCS_UNKNOWN, /* error/unspecified */
  145236. JCS_GRAYSCALE, /* monochrome */
  145237. JCS_RGB, /* red/green/blue */
  145238. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  145239. JCS_CMYK, /* C/M/Y/K */
  145240. JCS_YCCK /* Y/Cb/Cr/K */
  145241. } J_COLOR_SPACE;
  145242. typedef enum {
  145243. JDCT_ISLOW, /* slow but accurate integer algorithm */
  145244. JDCT_IFAST, /* faster, less accurate integer method */
  145245. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  145246. } J_DCT_METHOD;
  145247. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  145248. #define JDCT_DEFAULT JDCT_ISLOW
  145249. #endif
  145250. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  145251. #define JDCT_FASTEST JDCT_IFAST
  145252. #endif
  145253. typedef enum {
  145254. JDITHER_NONE, /* no dithering */
  145255. JDITHER_ORDERED, /* simple ordered dither */
  145256. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  145257. } J_DITHER_MODE;
  145258. #define jpeg_common_fields \
  145259. struct jpeg_error_mgr * err; /* Error handler module */\
  145260. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  145261. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  145262. void * client_data; /* Available for use by application */\
  145263. boolean is_decompressor; /* So common code can tell which is which */\
  145264. int global_state /* For checking call sequence validity */
  145265. struct jpeg_common_struct {
  145266. jpeg_common_fields; /* Fields common to both master struct types */
  145267. };
  145268. typedef struct jpeg_common_struct * j_common_ptr;
  145269. typedef struct jpeg_compress_struct * j_compress_ptr;
  145270. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  145271. struct jpeg_compress_struct {
  145272. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  145273. struct jpeg_destination_mgr * dest;
  145274. JDIMENSION image_width; /* input image width */
  145275. JDIMENSION image_height; /* input image height */
  145276. int input_components; /* # of color components in input image */
  145277. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  145278. double input_gamma; /* image gamma of input image */
  145279. int data_precision; /* bits of precision in image data */
  145280. int num_components; /* # of color components in JPEG image */
  145281. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145282. jpeg_component_info * comp_info;
  145283. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145284. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145285. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145286. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145287. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145288. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145289. int num_scans; /* # of entries in scan_info array */
  145290. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  145291. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  145292. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145293. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  145294. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145295. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  145296. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  145297. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  145298. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  145299. boolean write_JFIF_header; /* should a JFIF marker be written? */
  145300. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  145301. UINT8 JFIF_minor_version;
  145302. UINT8 density_unit; /* JFIF code for pixel size units */
  145303. UINT16 X_density; /* Horizontal pixel density */
  145304. UINT16 Y_density; /* Vertical pixel density */
  145305. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  145306. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  145307. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  145308. int max_h_samp_factor; /* largest h_samp_factor */
  145309. int max_v_samp_factor; /* largest v_samp_factor */
  145310. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  145311. int comps_in_scan; /* # of JPEG components in this scan */
  145312. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145313. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145314. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145315. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145316. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  145317. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145318. struct jpeg_comp_master * master;
  145319. struct jpeg_c_main_controller * main;
  145320. struct jpeg_c_prep_controller * prep;
  145321. struct jpeg_c_coef_controller * coef;
  145322. struct jpeg_marker_writer * marker;
  145323. struct jpeg_color_converter * cconvert;
  145324. struct jpeg_downsampler * downsample;
  145325. struct jpeg_forward_dct * fdct;
  145326. struct jpeg_entropy_encoder * entropy;
  145327. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  145328. int script_space_size;
  145329. };
  145330. struct jpeg_decompress_struct {
  145331. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  145332. struct jpeg_source_mgr * src;
  145333. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  145334. JDIMENSION image_height; /* nominal image height */
  145335. int num_components; /* # of color components in JPEG image */
  145336. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145337. J_COLOR_SPACE out_color_space; /* colorspace for output */
  145338. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  145339. double output_gamma; /* image gamma wanted in output */
  145340. boolean buffered_image; /* TRUE=multiple output passes */
  145341. boolean raw_data_out; /* TRUE=downsampled data wanted */
  145342. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  145343. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  145344. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  145345. boolean quantize_colors; /* TRUE=colormapped output wanted */
  145346. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  145347. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  145348. int desired_number_of_colors; /* max # colors to use in created colormap */
  145349. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  145350. boolean enable_external_quant;/* enable future use of external colormap */
  145351. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  145352. JDIMENSION output_width; /* scaled image width */
  145353. JDIMENSION output_height; /* scaled image height */
  145354. int out_color_components; /* # of color components in out_color_space */
  145355. int output_components; /* # of color components returned */
  145356. int rec_outbuf_height; /* min recommended height of scanline buffer */
  145357. int actual_number_of_colors; /* number of entries in use */
  145358. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  145359. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  145360. int input_scan_number; /* Number of SOS markers seen so far */
  145361. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  145362. int output_scan_number; /* Nominal scan number being displayed */
  145363. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  145364. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  145365. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145366. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145367. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145368. int data_precision; /* bits of precision in image data */
  145369. jpeg_component_info * comp_info;
  145370. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  145371. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145372. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145373. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145374. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145375. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  145376. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  145377. UINT8 JFIF_major_version; /* JFIF version number */
  145378. UINT8 JFIF_minor_version;
  145379. UINT8 density_unit; /* JFIF code for pixel size units */
  145380. UINT16 X_density; /* Horizontal pixel density */
  145381. UINT16 Y_density; /* Vertical pixel density */
  145382. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  145383. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  145384. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145385. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  145386. int max_h_samp_factor; /* largest h_samp_factor */
  145387. int max_v_samp_factor; /* largest v_samp_factor */
  145388. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  145389. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  145390. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  145391. int comps_in_scan; /* # of JPEG components in this scan */
  145392. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145393. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145394. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145395. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145396. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  145397. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145398. int unread_marker;
  145399. struct jpeg_decomp_master * master;
  145400. struct jpeg_d_main_controller * main;
  145401. struct jpeg_d_coef_controller * coef;
  145402. struct jpeg_d_post_controller * post;
  145403. struct jpeg_input_controller * inputctl;
  145404. struct jpeg_marker_reader * marker;
  145405. struct jpeg_entropy_decoder * entropy;
  145406. struct jpeg_inverse_dct * idct;
  145407. struct jpeg_upsampler * upsample;
  145408. struct jpeg_color_deconverter * cconvert;
  145409. struct jpeg_color_quantizer * cquantize;
  145410. };
  145411. struct jpeg_error_mgr {
  145412. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  145413. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  145414. JMETHOD(void, output_message, (j_common_ptr cinfo));
  145415. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  145416. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  145417. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  145418. int msg_code;
  145419. #define JMSG_STR_PARM_MAX 80
  145420. union {
  145421. int i[8];
  145422. char s[JMSG_STR_PARM_MAX];
  145423. } msg_parm;
  145424. int trace_level; /* max msg_level that will be displayed */
  145425. long num_warnings; /* number of corrupt-data warnings */
  145426. const char * const * jpeg_message_table; /* Library errors */
  145427. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  145428. const char * const * addon_message_table; /* Non-library errors */
  145429. int first_addon_message; /* code for first string in addon table */
  145430. int last_addon_message; /* code for last string in addon table */
  145431. };
  145432. struct jpeg_progress_mgr {
  145433. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  145434. long pass_counter; /* work units completed in this pass */
  145435. long pass_limit; /* total number of work units in this pass */
  145436. int completed_passes; /* passes completed so far */
  145437. int total_passes; /* total number of passes expected */
  145438. };
  145439. struct jpeg_destination_mgr {
  145440. JOCTET * next_output_byte; /* => next byte to write in buffer */
  145441. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  145442. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  145443. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  145444. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  145445. };
  145446. struct jpeg_source_mgr {
  145447. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  145448. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  145449. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  145450. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  145451. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  145452. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  145453. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  145454. };
  145455. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  145456. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  145457. #define JPOOL_NUMPOOLS 2
  145458. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  145459. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  145460. struct jpeg_memory_mgr {
  145461. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  145462. size_t sizeofobject));
  145463. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  145464. size_t sizeofobject));
  145465. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  145466. JDIMENSION samplesperrow,
  145467. JDIMENSION numrows));
  145468. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  145469. JDIMENSION blocksperrow,
  145470. JDIMENSION numrows));
  145471. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  145472. int pool_id,
  145473. boolean pre_zero,
  145474. JDIMENSION samplesperrow,
  145475. JDIMENSION numrows,
  145476. JDIMENSION maxaccess));
  145477. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  145478. int pool_id,
  145479. boolean pre_zero,
  145480. JDIMENSION blocksperrow,
  145481. JDIMENSION numrows,
  145482. JDIMENSION maxaccess));
  145483. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  145484. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  145485. jvirt_sarray_ptr ptr,
  145486. JDIMENSION start_row,
  145487. JDIMENSION num_rows,
  145488. boolean writable));
  145489. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  145490. jvirt_barray_ptr ptr,
  145491. JDIMENSION start_row,
  145492. JDIMENSION num_rows,
  145493. boolean writable));
  145494. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  145495. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  145496. long max_memory_to_use;
  145497. long max_alloc_chunk;
  145498. };
  145499. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  145500. #ifdef HAVE_PROTOTYPES
  145501. #define JPP(arglist) arglist
  145502. #else
  145503. #define JPP(arglist) ()
  145504. #endif
  145505. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145506. #define jpeg_std_error jStdError
  145507. #define jpeg_CreateCompress jCreaCompress
  145508. #define jpeg_CreateDecompress jCreaDecompress
  145509. #define jpeg_destroy_compress jDestCompress
  145510. #define jpeg_destroy_decompress jDestDecompress
  145511. #define jpeg_stdio_dest jStdDest
  145512. #define jpeg_stdio_src jStdSrc
  145513. #define jpeg_set_defaults jSetDefaults
  145514. #define jpeg_set_colorspace jSetColorspace
  145515. #define jpeg_default_colorspace jDefColorspace
  145516. #define jpeg_set_quality jSetQuality
  145517. #define jpeg_set_linear_quality jSetLQuality
  145518. #define jpeg_add_quant_table jAddQuantTable
  145519. #define jpeg_quality_scaling jQualityScaling
  145520. #define jpeg_simple_progression jSimProgress
  145521. #define jpeg_suppress_tables jSuppressTables
  145522. #define jpeg_alloc_quant_table jAlcQTable
  145523. #define jpeg_alloc_huff_table jAlcHTable
  145524. #define jpeg_start_compress jStrtCompress
  145525. #define jpeg_write_scanlines jWrtScanlines
  145526. #define jpeg_finish_compress jFinCompress
  145527. #define jpeg_write_raw_data jWrtRawData
  145528. #define jpeg_write_marker jWrtMarker
  145529. #define jpeg_write_m_header jWrtMHeader
  145530. #define jpeg_write_m_byte jWrtMByte
  145531. #define jpeg_write_tables jWrtTables
  145532. #define jpeg_read_header jReadHeader
  145533. #define jpeg_start_decompress jStrtDecompress
  145534. #define jpeg_read_scanlines jReadScanlines
  145535. #define jpeg_finish_decompress jFinDecompress
  145536. #define jpeg_read_raw_data jReadRawData
  145537. #define jpeg_has_multiple_scans jHasMultScn
  145538. #define jpeg_start_output jStrtOutput
  145539. #define jpeg_finish_output jFinOutput
  145540. #define jpeg_input_complete jInComplete
  145541. #define jpeg_new_colormap jNewCMap
  145542. #define jpeg_consume_input jConsumeInput
  145543. #define jpeg_calc_output_dimensions jCalcDimensions
  145544. #define jpeg_save_markers jSaveMarkers
  145545. #define jpeg_set_marker_processor jSetMarker
  145546. #define jpeg_read_coefficients jReadCoefs
  145547. #define jpeg_write_coefficients jWrtCoefs
  145548. #define jpeg_copy_critical_parameters jCopyCrit
  145549. #define jpeg_abort_compress jAbrtCompress
  145550. #define jpeg_abort_decompress jAbrtDecompress
  145551. #define jpeg_abort jAbort
  145552. #define jpeg_destroy jDestroy
  145553. #define jpeg_resync_to_restart jResyncRestart
  145554. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145555. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145556. JPP((struct jpeg_error_mgr * err));
  145557. #define jpeg_create_compress(cinfo) \
  145558. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145559. (size_t) sizeof(struct jpeg_compress_struct))
  145560. #define jpeg_create_decompress(cinfo) \
  145561. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145562. (size_t) sizeof(struct jpeg_decompress_struct))
  145563. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145564. int version, size_t structsize));
  145565. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145566. int version, size_t structsize));
  145567. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145568. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145569. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145570. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145571. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145572. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145573. J_COLOR_SPACE colorspace));
  145574. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145575. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145576. boolean force_baseline));
  145577. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145578. int scale_factor,
  145579. boolean force_baseline));
  145580. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145581. const unsigned int *basic_table,
  145582. int scale_factor,
  145583. boolean force_baseline));
  145584. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145585. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145586. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145587. boolean suppress));
  145588. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145589. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145590. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145591. boolean write_all_tables));
  145592. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145593. JSAMPARRAY scanlines,
  145594. JDIMENSION num_lines));
  145595. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145596. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145597. JSAMPIMAGE data,
  145598. JDIMENSION num_lines));
  145599. EXTERN(void) jpeg_write_marker
  145600. JPP((j_compress_ptr cinfo, int marker,
  145601. const JOCTET * dataptr, unsigned int datalen));
  145602. EXTERN(void) jpeg_write_m_header
  145603. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145604. EXTERN(void) jpeg_write_m_byte
  145605. JPP((j_compress_ptr cinfo, int val));
  145606. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145607. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145608. boolean require_image));
  145609. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145610. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145611. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145612. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145613. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145614. JSAMPARRAY scanlines,
  145615. JDIMENSION max_lines));
  145616. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145617. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145618. JSAMPIMAGE data,
  145619. JDIMENSION max_lines));
  145620. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145621. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145622. int scan_number));
  145623. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145624. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145625. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145626. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145627. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145628. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145629. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145630. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145631. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145632. EXTERN(void) jpeg_save_markers
  145633. JPP((j_decompress_ptr cinfo, int marker_code,
  145634. unsigned int length_limit));
  145635. EXTERN(void) jpeg_set_marker_processor
  145636. JPP((j_decompress_ptr cinfo, int marker_code,
  145637. jpeg_marker_parser_method routine));
  145638. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145639. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145640. jvirt_barray_ptr * coef_arrays));
  145641. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145642. j_compress_ptr dstinfo));
  145643. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145644. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145645. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145646. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145647. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145648. int desired));
  145649. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145650. #define JPEG_EOI 0xD9 /* EOI marker code */
  145651. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145652. #define JPEG_COM 0xFE /* COM marker code */
  145653. #ifdef INCOMPLETE_TYPES_BROKEN
  145654. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145655. struct jvirt_sarray_control { long dummy; };
  145656. struct jvirt_barray_control { long dummy; };
  145657. struct jpeg_comp_master { long dummy; };
  145658. struct jpeg_c_main_controller { long dummy; };
  145659. struct jpeg_c_prep_controller { long dummy; };
  145660. struct jpeg_c_coef_controller { long dummy; };
  145661. struct jpeg_marker_writer { long dummy; };
  145662. struct jpeg_color_converter { long dummy; };
  145663. struct jpeg_downsampler { long dummy; };
  145664. struct jpeg_forward_dct { long dummy; };
  145665. struct jpeg_entropy_encoder { long dummy; };
  145666. struct jpeg_decomp_master { long dummy; };
  145667. struct jpeg_d_main_controller { long dummy; };
  145668. struct jpeg_d_coef_controller { long dummy; };
  145669. struct jpeg_d_post_controller { long dummy; };
  145670. struct jpeg_input_controller { long dummy; };
  145671. struct jpeg_marker_reader { long dummy; };
  145672. struct jpeg_entropy_decoder { long dummy; };
  145673. struct jpeg_inverse_dct { long dummy; };
  145674. struct jpeg_upsampler { long dummy; };
  145675. struct jpeg_color_deconverter { long dummy; };
  145676. struct jpeg_color_quantizer { long dummy; };
  145677. #endif /* JPEG_INTERNALS */
  145678. #endif /* INCOMPLETE_TYPES_BROKEN */
  145679. #ifdef JPEG_INTERNALS
  145680. /*** Start of inlined file: jpegint.h ***/
  145681. typedef enum { /* Operating modes for buffer controllers */
  145682. JBUF_PASS_THRU, /* Plain stripwise operation */
  145683. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145684. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145685. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145686. } J_BUF_MODE;
  145687. #define CSTATE_START 100 /* after create_compress */
  145688. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145689. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145690. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145691. #define DSTATE_START 200 /* after create_decompress */
  145692. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145693. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145694. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145695. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145696. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145697. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145698. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145699. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145700. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145701. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145702. struct jpeg_comp_master {
  145703. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145704. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145705. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145706. boolean call_pass_startup; /* True if pass_startup must be called */
  145707. boolean is_last_pass; /* True during last pass */
  145708. };
  145709. struct jpeg_c_main_controller {
  145710. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145711. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145712. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145713. JDIMENSION in_rows_avail));
  145714. };
  145715. struct jpeg_c_prep_controller {
  145716. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145717. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145718. JSAMPARRAY input_buf,
  145719. JDIMENSION *in_row_ctr,
  145720. JDIMENSION in_rows_avail,
  145721. JSAMPIMAGE output_buf,
  145722. JDIMENSION *out_row_group_ctr,
  145723. JDIMENSION out_row_groups_avail));
  145724. };
  145725. struct jpeg_c_coef_controller {
  145726. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145727. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145728. JSAMPIMAGE input_buf));
  145729. };
  145730. struct jpeg_color_converter {
  145731. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145732. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145733. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145734. JDIMENSION output_row, int num_rows));
  145735. };
  145736. struct jpeg_downsampler {
  145737. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145738. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145739. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145740. JSAMPIMAGE output_buf,
  145741. JDIMENSION out_row_group_index));
  145742. boolean need_context_rows; /* TRUE if need rows above & below */
  145743. };
  145744. struct jpeg_forward_dct {
  145745. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145746. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145747. jpeg_component_info * compptr,
  145748. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145749. JDIMENSION start_row, JDIMENSION start_col,
  145750. JDIMENSION num_blocks));
  145751. };
  145752. struct jpeg_entropy_encoder {
  145753. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145754. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145755. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145756. };
  145757. struct jpeg_marker_writer {
  145758. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145759. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145760. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145761. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145762. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145763. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145764. unsigned int datalen));
  145765. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145766. };
  145767. struct jpeg_decomp_master {
  145768. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145769. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145770. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145771. };
  145772. struct jpeg_input_controller {
  145773. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145774. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145775. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145776. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145777. boolean has_multiple_scans; /* True if file has multiple scans */
  145778. boolean eoi_reached; /* True when EOI has been consumed */
  145779. };
  145780. struct jpeg_d_main_controller {
  145781. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145782. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145783. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145784. JDIMENSION out_rows_avail));
  145785. };
  145786. struct jpeg_d_coef_controller {
  145787. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145788. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145789. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145790. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145791. JSAMPIMAGE output_buf));
  145792. jvirt_barray_ptr *coef_arrays;
  145793. };
  145794. struct jpeg_d_post_controller {
  145795. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145796. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145797. JSAMPIMAGE input_buf,
  145798. JDIMENSION *in_row_group_ctr,
  145799. JDIMENSION in_row_groups_avail,
  145800. JSAMPARRAY output_buf,
  145801. JDIMENSION *out_row_ctr,
  145802. JDIMENSION out_rows_avail));
  145803. };
  145804. struct jpeg_marker_reader {
  145805. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145806. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145807. jpeg_marker_parser_method read_restart_marker;
  145808. boolean saw_SOI; /* found SOI? */
  145809. boolean saw_SOF; /* found SOF? */
  145810. int next_restart_num; /* next restart number expected (0-7) */
  145811. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145812. };
  145813. struct jpeg_entropy_decoder {
  145814. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145815. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145816. JBLOCKROW *MCU_data));
  145817. boolean insufficient_data; /* set TRUE after emitting warning */
  145818. };
  145819. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145820. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145821. JCOEFPTR coef_block,
  145822. JSAMPARRAY output_buf, JDIMENSION output_col));
  145823. struct jpeg_inverse_dct {
  145824. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145825. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145826. };
  145827. struct jpeg_upsampler {
  145828. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145829. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145830. JSAMPIMAGE input_buf,
  145831. JDIMENSION *in_row_group_ctr,
  145832. JDIMENSION in_row_groups_avail,
  145833. JSAMPARRAY output_buf,
  145834. JDIMENSION *out_row_ctr,
  145835. JDIMENSION out_rows_avail));
  145836. boolean need_context_rows; /* TRUE if need rows above & below */
  145837. };
  145838. struct jpeg_color_deconverter {
  145839. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145840. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145841. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145842. JSAMPARRAY output_buf, int num_rows));
  145843. };
  145844. struct jpeg_color_quantizer {
  145845. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145846. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145847. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145848. int num_rows));
  145849. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145850. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145851. };
  145852. #undef MAX
  145853. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145854. #undef MIN
  145855. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145856. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145857. #define SHIFT_TEMPS INT32 shift_temp;
  145858. #define RIGHT_SHIFT(x,shft) \
  145859. ((shift_temp = (x)) < 0 ? \
  145860. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145861. (shift_temp >> (shft)))
  145862. #else
  145863. #define SHIFT_TEMPS
  145864. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145865. #endif
  145866. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145867. #define jinit_compress_master jICompress
  145868. #define jinit_c_master_control jICMaster
  145869. #define jinit_c_main_controller jICMainC
  145870. #define jinit_c_prep_controller jICPrepC
  145871. #define jinit_c_coef_controller jICCoefC
  145872. #define jinit_color_converter jICColor
  145873. #define jinit_downsampler jIDownsampler
  145874. #define jinit_forward_dct jIFDCT
  145875. #define jinit_huff_encoder jIHEncoder
  145876. #define jinit_phuff_encoder jIPHEncoder
  145877. #define jinit_marker_writer jIMWriter
  145878. #define jinit_master_decompress jIDMaster
  145879. #define jinit_d_main_controller jIDMainC
  145880. #define jinit_d_coef_controller jIDCoefC
  145881. #define jinit_d_post_controller jIDPostC
  145882. #define jinit_input_controller jIInCtlr
  145883. #define jinit_marker_reader jIMReader
  145884. #define jinit_huff_decoder jIHDecoder
  145885. #define jinit_phuff_decoder jIPHDecoder
  145886. #define jinit_inverse_dct jIIDCT
  145887. #define jinit_upsampler jIUpsampler
  145888. #define jinit_color_deconverter jIDColor
  145889. #define jinit_1pass_quantizer jI1Quant
  145890. #define jinit_2pass_quantizer jI2Quant
  145891. #define jinit_merged_upsampler jIMUpsampler
  145892. #define jinit_memory_mgr jIMemMgr
  145893. #define jdiv_round_up jDivRound
  145894. #define jround_up jRound
  145895. #define jcopy_sample_rows jCopySamples
  145896. #define jcopy_block_row jCopyBlocks
  145897. #define jzero_far jZeroFar
  145898. #define jpeg_zigzag_order jZIGTable
  145899. #define jpeg_natural_order jZAGTable
  145900. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145901. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145902. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145903. boolean transcode_only));
  145904. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145905. boolean need_full_buffer));
  145906. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145907. boolean need_full_buffer));
  145908. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145909. boolean need_full_buffer));
  145910. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145911. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145912. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145913. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145914. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145915. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145916. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145917. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145918. boolean need_full_buffer));
  145919. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145920. boolean need_full_buffer));
  145921. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145922. boolean need_full_buffer));
  145923. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145924. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145925. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145926. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145927. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145928. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145929. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145930. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145931. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145932. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145933. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145934. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145935. EXTERN(long) jround_up JPP((long a, long b));
  145936. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145937. JSAMPARRAY output_array, int dest_row,
  145938. int num_rows, JDIMENSION num_cols));
  145939. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145940. JDIMENSION num_blocks));
  145941. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145942. #if 0 /* This table is not actually needed in v6a */
  145943. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145944. #endif
  145945. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145946. #ifdef INCOMPLETE_TYPES_BROKEN
  145947. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145948. struct jvirt_sarray_control { long dummy; };
  145949. struct jvirt_barray_control { long dummy; };
  145950. #endif
  145951. #endif /* INCOMPLETE_TYPES_BROKEN */
  145952. /*** End of inlined file: jpegint.h ***/
  145953. /* fetch private declarations */
  145954. /*** Start of inlined file: jerror.h ***/
  145955. #ifndef JMESSAGE
  145956. #ifndef JERROR_H
  145957. #define JMAKE_ENUM_LIST
  145958. #else
  145959. #define JMESSAGE(code,string)
  145960. #endif /* JERROR_H */
  145961. #endif /* JMESSAGE */
  145962. #ifdef JMAKE_ENUM_LIST
  145963. typedef enum {
  145964. #define JMESSAGE(code,string) code ,
  145965. #endif /* JMAKE_ENUM_LIST */
  145966. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145967. JMESSAGE(JERR_ARITH_NOTIMPL,
  145968. "Sorry, there are legal restrictions on arithmetic coding")
  145969. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145970. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145971. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145972. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145973. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145974. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145975. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145976. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145977. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145978. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145979. JMESSAGE(JERR_BAD_LIB_VERSION,
  145980. "Wrong JPEG library version: library is %d, caller expects %d")
  145981. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145982. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145983. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145984. JMESSAGE(JERR_BAD_PROGRESSION,
  145985. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145986. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145987. "Invalid progressive parameters at scan script entry %d")
  145988. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145989. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145990. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145991. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145992. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145993. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145994. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145995. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145996. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145997. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145998. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145999. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  146000. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  146001. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  146002. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  146003. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  146004. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  146005. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  146006. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  146007. JMESSAGE(JERR_FILE_READ, "Input file read error")
  146008. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  146009. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  146010. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  146011. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  146012. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  146013. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  146014. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  146015. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  146016. "Cannot transcode due to multiple use of quantization table %d")
  146017. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  146018. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  146019. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  146020. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  146021. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  146022. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  146023. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  146024. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  146025. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  146026. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  146027. JMESSAGE(JERR_QUANT_COMPONENTS,
  146028. "Cannot quantize more than %d color components")
  146029. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  146030. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  146031. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  146032. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  146033. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  146034. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  146035. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  146036. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  146037. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  146038. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  146039. JMESSAGE(JERR_TFILE_WRITE,
  146040. "Write failed on temporary file --- out of disk space?")
  146041. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  146042. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  146043. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  146044. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  146045. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  146046. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  146047. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  146048. JMESSAGE(JMSG_VERSION, JVERSION)
  146049. JMESSAGE(JTRC_16BIT_TABLES,
  146050. "Caution: quantization tables are too coarse for baseline JPEG")
  146051. JMESSAGE(JTRC_ADOBE,
  146052. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  146053. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  146054. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  146055. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  146056. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  146057. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  146058. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  146059. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  146060. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  146061. JMESSAGE(JTRC_EOI, "End Of Image")
  146062. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  146063. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  146064. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  146065. "Warning: thumbnail image size does not match data length %u")
  146066. JMESSAGE(JTRC_JFIF_EXTENSION,
  146067. "JFIF extension marker: type 0x%02x, length %u")
  146068. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  146069. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  146070. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  146071. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  146072. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  146073. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  146074. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  146075. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  146076. JMESSAGE(JTRC_RST, "RST%d")
  146077. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  146078. "Smoothing not supported with nonstandard sampling ratios")
  146079. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  146080. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  146081. JMESSAGE(JTRC_SOI, "Start of Image")
  146082. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  146083. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  146084. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  146085. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  146086. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  146087. JMESSAGE(JTRC_THUMB_JPEG,
  146088. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  146089. JMESSAGE(JTRC_THUMB_PALETTE,
  146090. "JFIF extension marker: palette thumbnail image, length %u")
  146091. JMESSAGE(JTRC_THUMB_RGB,
  146092. "JFIF extension marker: RGB thumbnail image, length %u")
  146093. JMESSAGE(JTRC_UNKNOWN_IDS,
  146094. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  146095. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  146096. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  146097. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  146098. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  146099. "Inconsistent progression sequence for component %d coefficient %d")
  146100. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  146101. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  146102. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  146103. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  146104. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  146105. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  146106. JMESSAGE(JWRN_MUST_RESYNC,
  146107. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  146108. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  146109. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  146110. #ifdef JMAKE_ENUM_LIST
  146111. JMSG_LASTMSGCODE
  146112. } J_MESSAGE_CODE;
  146113. #undef JMAKE_ENUM_LIST
  146114. #endif /* JMAKE_ENUM_LIST */
  146115. #undef JMESSAGE
  146116. #ifndef JERROR_H
  146117. #define JERROR_H
  146118. #define ERREXIT(cinfo,code) \
  146119. ((cinfo)->err->msg_code = (code), \
  146120. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146121. #define ERREXIT1(cinfo,code,p1) \
  146122. ((cinfo)->err->msg_code = (code), \
  146123. (cinfo)->err->msg_parm.i[0] = (p1), \
  146124. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146125. #define ERREXIT2(cinfo,code,p1,p2) \
  146126. ((cinfo)->err->msg_code = (code), \
  146127. (cinfo)->err->msg_parm.i[0] = (p1), \
  146128. (cinfo)->err->msg_parm.i[1] = (p2), \
  146129. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146130. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  146131. ((cinfo)->err->msg_code = (code), \
  146132. (cinfo)->err->msg_parm.i[0] = (p1), \
  146133. (cinfo)->err->msg_parm.i[1] = (p2), \
  146134. (cinfo)->err->msg_parm.i[2] = (p3), \
  146135. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146136. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  146137. ((cinfo)->err->msg_code = (code), \
  146138. (cinfo)->err->msg_parm.i[0] = (p1), \
  146139. (cinfo)->err->msg_parm.i[1] = (p2), \
  146140. (cinfo)->err->msg_parm.i[2] = (p3), \
  146141. (cinfo)->err->msg_parm.i[3] = (p4), \
  146142. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146143. #define ERREXITS(cinfo,code,str) \
  146144. ((cinfo)->err->msg_code = (code), \
  146145. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146146. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146147. #define MAKESTMT(stuff) do { stuff } while (0)
  146148. #define WARNMS(cinfo,code) \
  146149. ((cinfo)->err->msg_code = (code), \
  146150. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146151. #define WARNMS1(cinfo,code,p1) \
  146152. ((cinfo)->err->msg_code = (code), \
  146153. (cinfo)->err->msg_parm.i[0] = (p1), \
  146154. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146155. #define WARNMS2(cinfo,code,p1,p2) \
  146156. ((cinfo)->err->msg_code = (code), \
  146157. (cinfo)->err->msg_parm.i[0] = (p1), \
  146158. (cinfo)->err->msg_parm.i[1] = (p2), \
  146159. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146160. #define TRACEMS(cinfo,lvl,code) \
  146161. ((cinfo)->err->msg_code = (code), \
  146162. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146163. #define TRACEMS1(cinfo,lvl,code,p1) \
  146164. ((cinfo)->err->msg_code = (code), \
  146165. (cinfo)->err->msg_parm.i[0] = (p1), \
  146166. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146167. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  146168. ((cinfo)->err->msg_code = (code), \
  146169. (cinfo)->err->msg_parm.i[0] = (p1), \
  146170. (cinfo)->err->msg_parm.i[1] = (p2), \
  146171. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146172. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  146173. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146174. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  146175. (cinfo)->err->msg_code = (code); \
  146176. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146177. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  146178. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146179. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146180. (cinfo)->err->msg_code = (code); \
  146181. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146182. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  146183. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146184. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146185. _mp[4] = (p5); \
  146186. (cinfo)->err->msg_code = (code); \
  146187. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146188. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  146189. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146190. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146191. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  146192. (cinfo)->err->msg_code = (code); \
  146193. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146194. #define TRACEMSS(cinfo,lvl,code,str) \
  146195. ((cinfo)->err->msg_code = (code), \
  146196. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146197. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146198. #endif /* JERROR_H */
  146199. /*** End of inlined file: jerror.h ***/
  146200. /* fetch error codes too */
  146201. #endif
  146202. #endif /* JPEGLIB_H */
  146203. /*** End of inlined file: jpeglib.h ***/
  146204. /*** Start of inlined file: jcapimin.c ***/
  146205. #define JPEG_INTERNALS
  146206. /*** Start of inlined file: jinclude.h ***/
  146207. #ifndef __jinclude_h__
  146208. #define __jinclude_h__
  146209. /*** Start of inlined file: jconfig.h ***/
  146210. // disable all the warnings under MSVC
  146211. #ifdef _MSC_VER
  146212. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  146213. #endif
  146214. #ifdef __BORLANDC__
  146215. #pragma warn -8057
  146216. #pragma warn -8019
  146217. #pragma warn -8004
  146218. #pragma warn -8008
  146219. #endif
  146220. #define HAVE_PROTOTYPES
  146221. #define HAVE_UNSIGNED_CHAR
  146222. #define HAVE_UNSIGNED_SHORT
  146223. #undef CHAR_IS_UNSIGNED
  146224. #define HAVE_STDDEF_H
  146225. #define HAVE_STDLIB_H
  146226. #undef NEED_BSD_STRINGS
  146227. #undef NEED_SYS_TYPES_H
  146228. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  146229. #undef NEED_SHORT_EXTERNAL_NAMES
  146230. #undef INCOMPLETE_TYPES_BROKEN
  146231. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  146232. typedef unsigned char boolean;
  146233. #endif
  146234. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  146235. #ifdef JPEG_INTERNALS
  146236. #undef RIGHT_SHIFT_IS_UNSIGNED
  146237. #endif /* JPEG_INTERNALS */
  146238. #ifdef JPEG_CJPEG_DJPEG
  146239. #define BMP_SUPPORTED /* BMP image file format */
  146240. #define GIF_SUPPORTED /* GIF image file format */
  146241. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  146242. #undef RLE_SUPPORTED /* Utah RLE image file format */
  146243. #define TARGA_SUPPORTED /* Targa image file format */
  146244. #define TWO_FILE_COMMANDLINE /* optional */
  146245. #define USE_SETMODE /* Microsoft has setmode() */
  146246. #undef NEED_SIGNAL_CATCHER
  146247. #undef DONT_USE_B_MODE
  146248. #undef PROGRESS_REPORT /* optional */
  146249. #endif /* JPEG_CJPEG_DJPEG */
  146250. /*** End of inlined file: jconfig.h ***/
  146251. /* auto configuration options */
  146252. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  146253. #ifdef HAVE_STDDEF_H
  146254. #include <stddef.h>
  146255. #endif
  146256. #ifdef HAVE_STDLIB_H
  146257. #include <stdlib.h>
  146258. #endif
  146259. #ifdef NEED_SYS_TYPES_H
  146260. #include <sys/types.h>
  146261. #endif
  146262. #include <stdio.h>
  146263. #ifdef NEED_BSD_STRINGS
  146264. #include <strings.h>
  146265. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  146266. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  146267. #else /* not BSD, assume ANSI/SysV string lib */
  146268. #include <string.h>
  146269. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  146270. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  146271. #endif
  146272. #define SIZEOF(object) ((size_t) sizeof(object))
  146273. #define JFREAD(file,buf,sizeofbuf) \
  146274. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146275. #define JFWRITE(file,buf,sizeofbuf) \
  146276. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146277. typedef enum { /* JPEG marker codes */
  146278. M_SOF0 = 0xc0,
  146279. M_SOF1 = 0xc1,
  146280. M_SOF2 = 0xc2,
  146281. M_SOF3 = 0xc3,
  146282. M_SOF5 = 0xc5,
  146283. M_SOF6 = 0xc6,
  146284. M_SOF7 = 0xc7,
  146285. M_JPG = 0xc8,
  146286. M_SOF9 = 0xc9,
  146287. M_SOF10 = 0xca,
  146288. M_SOF11 = 0xcb,
  146289. M_SOF13 = 0xcd,
  146290. M_SOF14 = 0xce,
  146291. M_SOF15 = 0xcf,
  146292. M_DHT = 0xc4,
  146293. M_DAC = 0xcc,
  146294. M_RST0 = 0xd0,
  146295. M_RST1 = 0xd1,
  146296. M_RST2 = 0xd2,
  146297. M_RST3 = 0xd3,
  146298. M_RST4 = 0xd4,
  146299. M_RST5 = 0xd5,
  146300. M_RST6 = 0xd6,
  146301. M_RST7 = 0xd7,
  146302. M_SOI = 0xd8,
  146303. M_EOI = 0xd9,
  146304. M_SOS = 0xda,
  146305. M_DQT = 0xdb,
  146306. M_DNL = 0xdc,
  146307. M_DRI = 0xdd,
  146308. M_DHP = 0xde,
  146309. M_EXP = 0xdf,
  146310. M_APP0 = 0xe0,
  146311. M_APP1 = 0xe1,
  146312. M_APP2 = 0xe2,
  146313. M_APP3 = 0xe3,
  146314. M_APP4 = 0xe4,
  146315. M_APP5 = 0xe5,
  146316. M_APP6 = 0xe6,
  146317. M_APP7 = 0xe7,
  146318. M_APP8 = 0xe8,
  146319. M_APP9 = 0xe9,
  146320. M_APP10 = 0xea,
  146321. M_APP11 = 0xeb,
  146322. M_APP12 = 0xec,
  146323. M_APP13 = 0xed,
  146324. M_APP14 = 0xee,
  146325. M_APP15 = 0xef,
  146326. M_JPG0 = 0xf0,
  146327. M_JPG13 = 0xfd,
  146328. M_COM = 0xfe,
  146329. M_TEM = 0x01,
  146330. M_ERROR = 0x100
  146331. } JPEG_MARKER;
  146332. #ifdef AVOID_TABLES
  146333. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  146334. #else
  146335. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  146336. static const int extend_test[16] = /* entry n is 2**(n-1) */
  146337. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  146338. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  146339. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  146340. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  146341. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  146342. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  146343. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  146344. #endif /* AVOID_TABLES */
  146345. #endif
  146346. /*** End of inlined file: jinclude.h ***/
  146347. GLOBAL(void)
  146348. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  146349. {
  146350. int i;
  146351. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  146352. if (version != JPEG_LIB_VERSION)
  146353. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  146354. if (structsize != SIZEOF(struct jpeg_compress_struct))
  146355. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  146356. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  146357. {
  146358. struct jpeg_error_mgr * err = cinfo->err;
  146359. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  146360. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  146361. cinfo->err = err;
  146362. cinfo->client_data = client_data;
  146363. }
  146364. cinfo->is_decompressor = FALSE;
  146365. jinit_memory_mgr((j_common_ptr) cinfo);
  146366. cinfo->progress = NULL;
  146367. cinfo->dest = NULL;
  146368. cinfo->comp_info = NULL;
  146369. for (i = 0; i < NUM_QUANT_TBLS; i++)
  146370. cinfo->quant_tbl_ptrs[i] = NULL;
  146371. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146372. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  146373. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  146374. }
  146375. cinfo->script_space = NULL;
  146376. cinfo->input_gamma = 1.0; /* in case application forgets */
  146377. cinfo->global_state = CSTATE_START;
  146378. }
  146379. GLOBAL(void)
  146380. jpeg_destroy_compress (j_compress_ptr cinfo)
  146381. {
  146382. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  146383. }
  146384. GLOBAL(void)
  146385. jpeg_abort_compress (j_compress_ptr cinfo)
  146386. {
  146387. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  146388. }
  146389. GLOBAL(void)
  146390. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  146391. {
  146392. int i;
  146393. JQUANT_TBL * qtbl;
  146394. JHUFF_TBL * htbl;
  146395. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146396. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  146397. qtbl->sent_table = suppress;
  146398. }
  146399. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146400. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  146401. htbl->sent_table = suppress;
  146402. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  146403. htbl->sent_table = suppress;
  146404. }
  146405. }
  146406. GLOBAL(void)
  146407. jpeg_finish_compress (j_compress_ptr cinfo)
  146408. {
  146409. JDIMENSION iMCU_row;
  146410. if (cinfo->global_state == CSTATE_SCANNING ||
  146411. cinfo->global_state == CSTATE_RAW_OK) {
  146412. if (cinfo->next_scanline < cinfo->image_height)
  146413. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  146414. (*cinfo->master->finish_pass) (cinfo);
  146415. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  146416. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146417. while (! cinfo->master->is_last_pass) {
  146418. (*cinfo->master->prepare_for_pass) (cinfo);
  146419. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  146420. if (cinfo->progress != NULL) {
  146421. cinfo->progress->pass_counter = (long) iMCU_row;
  146422. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  146423. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146424. }
  146425. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  146426. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  146427. }
  146428. (*cinfo->master->finish_pass) (cinfo);
  146429. }
  146430. (*cinfo->marker->write_file_trailer) (cinfo);
  146431. (*cinfo->dest->term_destination) (cinfo);
  146432. jpeg_abort((j_common_ptr) cinfo);
  146433. }
  146434. GLOBAL(void)
  146435. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  146436. const JOCTET *dataptr, unsigned int datalen)
  146437. {
  146438. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  146439. if (cinfo->next_scanline != 0 ||
  146440. (cinfo->global_state != CSTATE_SCANNING &&
  146441. cinfo->global_state != CSTATE_RAW_OK &&
  146442. cinfo->global_state != CSTATE_WRCOEFS))
  146443. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146444. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146445. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  146446. while (datalen--) {
  146447. (*write_marker_byte) (cinfo, *dataptr);
  146448. dataptr++;
  146449. }
  146450. }
  146451. GLOBAL(void)
  146452. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  146453. {
  146454. if (cinfo->next_scanline != 0 ||
  146455. (cinfo->global_state != CSTATE_SCANNING &&
  146456. cinfo->global_state != CSTATE_RAW_OK &&
  146457. cinfo->global_state != CSTATE_WRCOEFS))
  146458. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146459. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146460. }
  146461. GLOBAL(void)
  146462. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  146463. {
  146464. (*cinfo->marker->write_marker_byte) (cinfo, val);
  146465. }
  146466. GLOBAL(void)
  146467. jpeg_write_tables (j_compress_ptr cinfo)
  146468. {
  146469. if (cinfo->global_state != CSTATE_START)
  146470. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146471. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146472. (*cinfo->dest->init_destination) (cinfo);
  146473. jinit_marker_writer(cinfo);
  146474. (*cinfo->marker->write_tables_only) (cinfo);
  146475. (*cinfo->dest->term_destination) (cinfo);
  146476. }
  146477. /*** End of inlined file: jcapimin.c ***/
  146478. /*** Start of inlined file: jcapistd.c ***/
  146479. #define JPEG_INTERNALS
  146480. GLOBAL(void)
  146481. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  146482. {
  146483. if (cinfo->global_state != CSTATE_START)
  146484. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146485. if (write_all_tables)
  146486. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  146487. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146488. (*cinfo->dest->init_destination) (cinfo);
  146489. jinit_compress_master(cinfo);
  146490. (*cinfo->master->prepare_for_pass) (cinfo);
  146491. cinfo->next_scanline = 0;
  146492. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  146493. }
  146494. GLOBAL(JDIMENSION)
  146495. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  146496. JDIMENSION num_lines)
  146497. {
  146498. JDIMENSION row_ctr, rows_left;
  146499. if (cinfo->global_state != CSTATE_SCANNING)
  146500. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146501. if (cinfo->next_scanline >= cinfo->image_height)
  146502. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146503. if (cinfo->progress != NULL) {
  146504. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146505. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146506. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146507. }
  146508. if (cinfo->master->call_pass_startup)
  146509. (*cinfo->master->pass_startup) (cinfo);
  146510. rows_left = cinfo->image_height - cinfo->next_scanline;
  146511. if (num_lines > rows_left)
  146512. num_lines = rows_left;
  146513. row_ctr = 0;
  146514. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  146515. cinfo->next_scanline += row_ctr;
  146516. return row_ctr;
  146517. }
  146518. GLOBAL(JDIMENSION)
  146519. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  146520. JDIMENSION num_lines)
  146521. {
  146522. JDIMENSION lines_per_iMCU_row;
  146523. if (cinfo->global_state != CSTATE_RAW_OK)
  146524. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146525. if (cinfo->next_scanline >= cinfo->image_height) {
  146526. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146527. return 0;
  146528. }
  146529. if (cinfo->progress != NULL) {
  146530. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146531. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146532. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146533. }
  146534. if (cinfo->master->call_pass_startup)
  146535. (*cinfo->master->pass_startup) (cinfo);
  146536. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146537. if (num_lines < lines_per_iMCU_row)
  146538. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146539. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146540. return 0;
  146541. }
  146542. cinfo->next_scanline += lines_per_iMCU_row;
  146543. return lines_per_iMCU_row;
  146544. }
  146545. /*** End of inlined file: jcapistd.c ***/
  146546. /*** Start of inlined file: jccoefct.c ***/
  146547. #define JPEG_INTERNALS
  146548. #ifdef ENTROPY_OPT_SUPPORTED
  146549. #define FULL_COEF_BUFFER_SUPPORTED
  146550. #else
  146551. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146552. #define FULL_COEF_BUFFER_SUPPORTED
  146553. #endif
  146554. #endif
  146555. typedef struct {
  146556. struct jpeg_c_coef_controller pub; /* public fields */
  146557. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146558. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146559. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146560. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146561. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146562. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146563. } my_coef_controller;
  146564. typedef my_coef_controller * my_coef_ptr;
  146565. METHODDEF(boolean) compress_data
  146566. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146567. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146568. METHODDEF(boolean) compress_first_pass
  146569. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146570. METHODDEF(boolean) compress_output
  146571. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146572. #endif
  146573. LOCAL(void)
  146574. start_iMCU_row (j_compress_ptr cinfo)
  146575. {
  146576. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146577. if (cinfo->comps_in_scan > 1) {
  146578. coef->MCU_rows_per_iMCU_row = 1;
  146579. } else {
  146580. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146581. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146582. else
  146583. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146584. }
  146585. coef->mcu_ctr = 0;
  146586. coef->MCU_vert_offset = 0;
  146587. }
  146588. METHODDEF(void)
  146589. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146590. {
  146591. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146592. coef->iMCU_row_num = 0;
  146593. start_iMCU_row(cinfo);
  146594. switch (pass_mode) {
  146595. case JBUF_PASS_THRU:
  146596. if (coef->whole_image[0] != NULL)
  146597. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146598. coef->pub.compress_data = compress_data;
  146599. break;
  146600. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146601. case JBUF_SAVE_AND_PASS:
  146602. if (coef->whole_image[0] == NULL)
  146603. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146604. coef->pub.compress_data = compress_first_pass;
  146605. break;
  146606. case JBUF_CRANK_DEST:
  146607. if (coef->whole_image[0] == NULL)
  146608. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146609. coef->pub.compress_data = compress_output;
  146610. break;
  146611. #endif
  146612. default:
  146613. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146614. break;
  146615. }
  146616. }
  146617. METHODDEF(boolean)
  146618. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146619. {
  146620. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146621. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146622. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146623. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146624. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146625. JDIMENSION ypos, xpos;
  146626. jpeg_component_info *compptr;
  146627. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146628. yoffset++) {
  146629. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146630. MCU_col_num++) {
  146631. blkn = 0;
  146632. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146633. compptr = cinfo->cur_comp_info[ci];
  146634. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146635. : compptr->last_col_width;
  146636. xpos = MCU_col_num * compptr->MCU_sample_width;
  146637. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146638. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146639. if (coef->iMCU_row_num < last_iMCU_row ||
  146640. yoffset+yindex < compptr->last_row_height) {
  146641. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146642. input_buf[compptr->component_index],
  146643. coef->MCU_buffer[blkn],
  146644. ypos, xpos, (JDIMENSION) blockcnt);
  146645. if (blockcnt < compptr->MCU_width) {
  146646. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146647. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146648. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146649. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146650. }
  146651. }
  146652. } else {
  146653. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146654. compptr->MCU_width * SIZEOF(JBLOCK));
  146655. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146656. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146657. }
  146658. }
  146659. blkn += compptr->MCU_width;
  146660. ypos += DCTSIZE;
  146661. }
  146662. }
  146663. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146664. coef->MCU_vert_offset = yoffset;
  146665. coef->mcu_ctr = MCU_col_num;
  146666. return FALSE;
  146667. }
  146668. }
  146669. coef->mcu_ctr = 0;
  146670. }
  146671. coef->iMCU_row_num++;
  146672. start_iMCU_row(cinfo);
  146673. return TRUE;
  146674. }
  146675. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146676. METHODDEF(boolean)
  146677. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146678. {
  146679. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146680. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146681. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146682. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146683. JCOEF lastDC;
  146684. jpeg_component_info *compptr;
  146685. JBLOCKARRAY buffer;
  146686. JBLOCKROW thisblockrow, lastblockrow;
  146687. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146688. ci++, compptr++) {
  146689. buffer = (*cinfo->mem->access_virt_barray)
  146690. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146691. coef->iMCU_row_num * compptr->v_samp_factor,
  146692. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146693. if (coef->iMCU_row_num < last_iMCU_row)
  146694. block_rows = compptr->v_samp_factor;
  146695. else {
  146696. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146697. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146698. }
  146699. blocks_across = compptr->width_in_blocks;
  146700. h_samp_factor = compptr->h_samp_factor;
  146701. ndummy = (int) (blocks_across % h_samp_factor);
  146702. if (ndummy > 0)
  146703. ndummy = h_samp_factor - ndummy;
  146704. for (block_row = 0; block_row < block_rows; block_row++) {
  146705. thisblockrow = buffer[block_row];
  146706. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146707. input_buf[ci], thisblockrow,
  146708. (JDIMENSION) (block_row * DCTSIZE),
  146709. (JDIMENSION) 0, blocks_across);
  146710. if (ndummy > 0) {
  146711. thisblockrow += blocks_across; /* => first dummy block */
  146712. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146713. lastDC = thisblockrow[-1][0];
  146714. for (bi = 0; bi < ndummy; bi++) {
  146715. thisblockrow[bi][0] = lastDC;
  146716. }
  146717. }
  146718. }
  146719. if (coef->iMCU_row_num == last_iMCU_row) {
  146720. blocks_across += ndummy; /* include lower right corner */
  146721. MCUs_across = blocks_across / h_samp_factor;
  146722. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146723. block_row++) {
  146724. thisblockrow = buffer[block_row];
  146725. lastblockrow = buffer[block_row-1];
  146726. jzero_far((void FAR *) thisblockrow,
  146727. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146728. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146729. lastDC = lastblockrow[h_samp_factor-1][0];
  146730. for (bi = 0; bi < h_samp_factor; bi++) {
  146731. thisblockrow[bi][0] = lastDC;
  146732. }
  146733. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146734. lastblockrow += h_samp_factor;
  146735. }
  146736. }
  146737. }
  146738. }
  146739. return compress_output(cinfo, input_buf);
  146740. }
  146741. METHODDEF(boolean)
  146742. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146743. {
  146744. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146745. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146746. int blkn, ci, xindex, yindex, yoffset;
  146747. JDIMENSION start_col;
  146748. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146749. JBLOCKROW buffer_ptr;
  146750. jpeg_component_info *compptr;
  146751. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146752. compptr = cinfo->cur_comp_info[ci];
  146753. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146754. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146755. coef->iMCU_row_num * compptr->v_samp_factor,
  146756. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146757. }
  146758. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146759. yoffset++) {
  146760. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146761. MCU_col_num++) {
  146762. blkn = 0; /* index of current DCT block within MCU */
  146763. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146764. compptr = cinfo->cur_comp_info[ci];
  146765. start_col = MCU_col_num * compptr->MCU_width;
  146766. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146767. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146768. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146769. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146770. }
  146771. }
  146772. }
  146773. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146774. coef->MCU_vert_offset = yoffset;
  146775. coef->mcu_ctr = MCU_col_num;
  146776. return FALSE;
  146777. }
  146778. }
  146779. coef->mcu_ctr = 0;
  146780. }
  146781. coef->iMCU_row_num++;
  146782. start_iMCU_row(cinfo);
  146783. return TRUE;
  146784. }
  146785. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146786. GLOBAL(void)
  146787. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146788. {
  146789. my_coef_ptr coef;
  146790. coef = (my_coef_ptr)
  146791. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146792. SIZEOF(my_coef_controller));
  146793. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146794. coef->pub.start_pass = start_pass_coef;
  146795. if (need_full_buffer) {
  146796. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146797. int ci;
  146798. jpeg_component_info *compptr;
  146799. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146800. ci++, compptr++) {
  146801. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146802. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146803. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146804. (long) compptr->h_samp_factor),
  146805. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146806. (long) compptr->v_samp_factor),
  146807. (JDIMENSION) compptr->v_samp_factor);
  146808. }
  146809. #else
  146810. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146811. #endif
  146812. } else {
  146813. JBLOCKROW buffer;
  146814. int i;
  146815. buffer = (JBLOCKROW)
  146816. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146817. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146818. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146819. coef->MCU_buffer[i] = buffer + i;
  146820. }
  146821. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146822. }
  146823. }
  146824. /*** End of inlined file: jccoefct.c ***/
  146825. /*** Start of inlined file: jccolor.c ***/
  146826. #define JPEG_INTERNALS
  146827. typedef struct {
  146828. struct jpeg_color_converter pub; /* public fields */
  146829. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146830. } my_color_converter;
  146831. typedef my_color_converter * my_cconvert_ptr;
  146832. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146833. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146834. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146835. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146836. #define R_Y_OFF 0 /* offset to R => Y section */
  146837. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146838. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146839. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146840. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146841. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146842. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146843. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146844. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146845. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146846. METHODDEF(void)
  146847. rgb_ycc_start (j_compress_ptr cinfo)
  146848. {
  146849. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146850. INT32 * rgb_ycc_tab;
  146851. INT32 i;
  146852. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146853. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146854. (TABLE_SIZE * SIZEOF(INT32)));
  146855. for (i = 0; i <= MAXJSAMPLE; i++) {
  146856. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146857. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146858. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146859. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146860. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146861. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146862. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146863. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146864. }
  146865. }
  146866. METHODDEF(void)
  146867. rgb_ycc_convert (j_compress_ptr cinfo,
  146868. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146869. JDIMENSION output_row, int num_rows)
  146870. {
  146871. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146872. register int r, g, b;
  146873. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146874. register JSAMPROW inptr;
  146875. register JSAMPROW outptr0, outptr1, outptr2;
  146876. register JDIMENSION col;
  146877. JDIMENSION num_cols = cinfo->image_width;
  146878. while (--num_rows >= 0) {
  146879. inptr = *input_buf++;
  146880. outptr0 = output_buf[0][output_row];
  146881. outptr1 = output_buf[1][output_row];
  146882. outptr2 = output_buf[2][output_row];
  146883. output_row++;
  146884. for (col = 0; col < num_cols; col++) {
  146885. r = GETJSAMPLE(inptr[RGB_RED]);
  146886. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146887. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146888. inptr += RGB_PIXELSIZE;
  146889. outptr0[col] = (JSAMPLE)
  146890. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146891. >> SCALEBITS);
  146892. outptr1[col] = (JSAMPLE)
  146893. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146894. >> SCALEBITS);
  146895. outptr2[col] = (JSAMPLE)
  146896. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146897. >> SCALEBITS);
  146898. }
  146899. }
  146900. }
  146901. METHODDEF(void)
  146902. rgb_gray_convert (j_compress_ptr cinfo,
  146903. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146904. JDIMENSION output_row, int num_rows)
  146905. {
  146906. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146907. register int r, g, b;
  146908. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146909. register JSAMPROW inptr;
  146910. register JSAMPROW outptr;
  146911. register JDIMENSION col;
  146912. JDIMENSION num_cols = cinfo->image_width;
  146913. while (--num_rows >= 0) {
  146914. inptr = *input_buf++;
  146915. outptr = output_buf[0][output_row];
  146916. output_row++;
  146917. for (col = 0; col < num_cols; col++) {
  146918. r = GETJSAMPLE(inptr[RGB_RED]);
  146919. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146920. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146921. inptr += RGB_PIXELSIZE;
  146922. outptr[col] = (JSAMPLE)
  146923. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146924. >> SCALEBITS);
  146925. }
  146926. }
  146927. }
  146928. METHODDEF(void)
  146929. cmyk_ycck_convert (j_compress_ptr cinfo,
  146930. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146931. JDIMENSION output_row, int num_rows)
  146932. {
  146933. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146934. register int r, g, b;
  146935. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146936. register JSAMPROW inptr;
  146937. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146938. register JDIMENSION col;
  146939. JDIMENSION num_cols = cinfo->image_width;
  146940. while (--num_rows >= 0) {
  146941. inptr = *input_buf++;
  146942. outptr0 = output_buf[0][output_row];
  146943. outptr1 = output_buf[1][output_row];
  146944. outptr2 = output_buf[2][output_row];
  146945. outptr3 = output_buf[3][output_row];
  146946. output_row++;
  146947. for (col = 0; col < num_cols; col++) {
  146948. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146949. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146950. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146951. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146952. inptr += 4;
  146953. outptr0[col] = (JSAMPLE)
  146954. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146955. >> SCALEBITS);
  146956. outptr1[col] = (JSAMPLE)
  146957. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146958. >> SCALEBITS);
  146959. outptr2[col] = (JSAMPLE)
  146960. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146961. >> SCALEBITS);
  146962. }
  146963. }
  146964. }
  146965. METHODDEF(void)
  146966. grayscale_convert (j_compress_ptr cinfo,
  146967. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146968. JDIMENSION output_row, int num_rows)
  146969. {
  146970. register JSAMPROW inptr;
  146971. register JSAMPROW outptr;
  146972. register JDIMENSION col;
  146973. JDIMENSION num_cols = cinfo->image_width;
  146974. int instride = cinfo->input_components;
  146975. while (--num_rows >= 0) {
  146976. inptr = *input_buf++;
  146977. outptr = output_buf[0][output_row];
  146978. output_row++;
  146979. for (col = 0; col < num_cols; col++) {
  146980. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146981. inptr += instride;
  146982. }
  146983. }
  146984. }
  146985. METHODDEF(void)
  146986. null_convert (j_compress_ptr cinfo,
  146987. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146988. JDIMENSION output_row, int num_rows)
  146989. {
  146990. register JSAMPROW inptr;
  146991. register JSAMPROW outptr;
  146992. register JDIMENSION col;
  146993. register int ci;
  146994. int nc = cinfo->num_components;
  146995. JDIMENSION num_cols = cinfo->image_width;
  146996. while (--num_rows >= 0) {
  146997. for (ci = 0; ci < nc; ci++) {
  146998. inptr = *input_buf;
  146999. outptr = output_buf[ci][output_row];
  147000. for (col = 0; col < num_cols; col++) {
  147001. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  147002. inptr += nc;
  147003. }
  147004. }
  147005. input_buf++;
  147006. output_row++;
  147007. }
  147008. }
  147009. METHODDEF(void)
  147010. null_method (j_compress_ptr cinfo)
  147011. {
  147012. }
  147013. GLOBAL(void)
  147014. jinit_color_converter (j_compress_ptr cinfo)
  147015. {
  147016. my_cconvert_ptr cconvert;
  147017. cconvert = (my_cconvert_ptr)
  147018. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147019. SIZEOF(my_color_converter));
  147020. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  147021. cconvert->pub.start_pass = null_method;
  147022. switch (cinfo->in_color_space) {
  147023. case JCS_GRAYSCALE:
  147024. if (cinfo->input_components != 1)
  147025. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147026. break;
  147027. case JCS_RGB:
  147028. #if RGB_PIXELSIZE != 3
  147029. if (cinfo->input_components != RGB_PIXELSIZE)
  147030. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147031. break;
  147032. #endif /* else share code with YCbCr */
  147033. case JCS_YCbCr:
  147034. if (cinfo->input_components != 3)
  147035. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147036. break;
  147037. case JCS_CMYK:
  147038. case JCS_YCCK:
  147039. if (cinfo->input_components != 4)
  147040. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147041. break;
  147042. default: /* JCS_UNKNOWN can be anything */
  147043. if (cinfo->input_components < 1)
  147044. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147045. break;
  147046. }
  147047. switch (cinfo->jpeg_color_space) {
  147048. case JCS_GRAYSCALE:
  147049. if (cinfo->num_components != 1)
  147050. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147051. if (cinfo->in_color_space == JCS_GRAYSCALE)
  147052. cconvert->pub.color_convert = grayscale_convert;
  147053. else if (cinfo->in_color_space == JCS_RGB) {
  147054. cconvert->pub.start_pass = rgb_ycc_start;
  147055. cconvert->pub.color_convert = rgb_gray_convert;
  147056. } else if (cinfo->in_color_space == JCS_YCbCr)
  147057. cconvert->pub.color_convert = grayscale_convert;
  147058. else
  147059. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147060. break;
  147061. case JCS_RGB:
  147062. if (cinfo->num_components != 3)
  147063. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147064. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  147065. cconvert->pub.color_convert = null_convert;
  147066. else
  147067. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147068. break;
  147069. case JCS_YCbCr:
  147070. if (cinfo->num_components != 3)
  147071. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147072. if (cinfo->in_color_space == JCS_RGB) {
  147073. cconvert->pub.start_pass = rgb_ycc_start;
  147074. cconvert->pub.color_convert = rgb_ycc_convert;
  147075. } else if (cinfo->in_color_space == JCS_YCbCr)
  147076. cconvert->pub.color_convert = null_convert;
  147077. else
  147078. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147079. break;
  147080. case JCS_CMYK:
  147081. if (cinfo->num_components != 4)
  147082. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147083. if (cinfo->in_color_space == JCS_CMYK)
  147084. cconvert->pub.color_convert = null_convert;
  147085. else
  147086. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147087. break;
  147088. case JCS_YCCK:
  147089. if (cinfo->num_components != 4)
  147090. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147091. if (cinfo->in_color_space == JCS_CMYK) {
  147092. cconvert->pub.start_pass = rgb_ycc_start;
  147093. cconvert->pub.color_convert = cmyk_ycck_convert;
  147094. } else if (cinfo->in_color_space == JCS_YCCK)
  147095. cconvert->pub.color_convert = null_convert;
  147096. else
  147097. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147098. break;
  147099. default: /* allow null conversion of JCS_UNKNOWN */
  147100. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  147101. cinfo->num_components != cinfo->input_components)
  147102. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147103. cconvert->pub.color_convert = null_convert;
  147104. break;
  147105. }
  147106. }
  147107. /*** End of inlined file: jccolor.c ***/
  147108. #undef FIX
  147109. /*** Start of inlined file: jcdctmgr.c ***/
  147110. #define JPEG_INTERNALS
  147111. /*** Start of inlined file: jdct.h ***/
  147112. #ifndef __jdct_h__
  147113. #define __jdct_h__
  147114. #if BITS_IN_JSAMPLE == 8
  147115. typedef int DCTELEM; /* 16 or 32 bits is fine */
  147116. #else
  147117. typedef INT32 DCTELEM; /* must have 32 bits */
  147118. #endif
  147119. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  147120. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  147121. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  147122. #if BITS_IN_JSAMPLE == 8
  147123. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  147124. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  147125. #else
  147126. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  147127. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  147128. #endif
  147129. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  147130. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  147131. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  147132. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147133. #define jpeg_fdct_islow jFDislow
  147134. #define jpeg_fdct_ifast jFDifast
  147135. #define jpeg_fdct_float jFDfloat
  147136. #define jpeg_idct_islow jRDislow
  147137. #define jpeg_idct_ifast jRDifast
  147138. #define jpeg_idct_float jRDfloat
  147139. #define jpeg_idct_4x4 jRD4x4
  147140. #define jpeg_idct_2x2 jRD2x2
  147141. #define jpeg_idct_1x1 jRD1x1
  147142. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147143. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  147144. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  147145. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  147146. EXTERN(void) jpeg_idct_islow
  147147. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147148. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147149. EXTERN(void) jpeg_idct_ifast
  147150. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147151. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147152. EXTERN(void) jpeg_idct_float
  147153. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147154. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147155. EXTERN(void) jpeg_idct_4x4
  147156. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147157. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147158. EXTERN(void) jpeg_idct_2x2
  147159. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147160. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147161. EXTERN(void) jpeg_idct_1x1
  147162. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147163. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147164. #define ONE ((INT32) 1)
  147165. #define CONST_SCALE (ONE << CONST_BITS)
  147166. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  147167. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  147168. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147169. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  147170. #endif
  147171. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  147172. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  147173. #endif
  147174. #ifndef MULTIPLY16C16 /* default definition */
  147175. #define MULTIPLY16C16(var,const) ((var) * (const))
  147176. #endif
  147177. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147178. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  147179. #endif
  147180. #ifndef MULTIPLY16V16 /* default definition */
  147181. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  147182. #endif
  147183. #endif
  147184. /*** End of inlined file: jdct.h ***/
  147185. /* Private declarations for DCT subsystem */
  147186. typedef struct {
  147187. struct jpeg_forward_dct pub; /* public fields */
  147188. forward_DCT_method_ptr do_dct;
  147189. DCTELEM * divisors[NUM_QUANT_TBLS];
  147190. #ifdef DCT_FLOAT_SUPPORTED
  147191. float_DCT_method_ptr do_float_dct;
  147192. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  147193. #endif
  147194. } my_fdct_controller;
  147195. typedef my_fdct_controller * my_fdct_ptr;
  147196. METHODDEF(void)
  147197. start_pass_fdctmgr (j_compress_ptr cinfo)
  147198. {
  147199. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147200. int ci, qtblno, i;
  147201. jpeg_component_info *compptr;
  147202. JQUANT_TBL * qtbl;
  147203. DCTELEM * dtbl;
  147204. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147205. ci++, compptr++) {
  147206. qtblno = compptr->quant_tbl_no;
  147207. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  147208. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  147209. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  147210. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  147211. switch (cinfo->dct_method) {
  147212. #ifdef DCT_ISLOW_SUPPORTED
  147213. case JDCT_ISLOW:
  147214. if (fdct->divisors[qtblno] == NULL) {
  147215. fdct->divisors[qtblno] = (DCTELEM *)
  147216. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147217. DCTSIZE2 * SIZEOF(DCTELEM));
  147218. }
  147219. dtbl = fdct->divisors[qtblno];
  147220. for (i = 0; i < DCTSIZE2; i++) {
  147221. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  147222. }
  147223. break;
  147224. #endif
  147225. #ifdef DCT_IFAST_SUPPORTED
  147226. case JDCT_IFAST:
  147227. {
  147228. #define CONST_BITS 14
  147229. static const INT16 aanscales[DCTSIZE2] = {
  147230. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147231. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  147232. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  147233. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  147234. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147235. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  147236. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  147237. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  147238. };
  147239. SHIFT_TEMPS
  147240. if (fdct->divisors[qtblno] == NULL) {
  147241. fdct->divisors[qtblno] = (DCTELEM *)
  147242. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147243. DCTSIZE2 * SIZEOF(DCTELEM));
  147244. }
  147245. dtbl = fdct->divisors[qtblno];
  147246. for (i = 0; i < DCTSIZE2; i++) {
  147247. dtbl[i] = (DCTELEM)
  147248. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  147249. (INT32) aanscales[i]),
  147250. CONST_BITS-3);
  147251. }
  147252. }
  147253. break;
  147254. #endif
  147255. #ifdef DCT_FLOAT_SUPPORTED
  147256. case JDCT_FLOAT:
  147257. {
  147258. FAST_FLOAT * fdtbl;
  147259. int row, col;
  147260. static const double aanscalefactor[DCTSIZE] = {
  147261. 1.0, 1.387039845, 1.306562965, 1.175875602,
  147262. 1.0, 0.785694958, 0.541196100, 0.275899379
  147263. };
  147264. if (fdct->float_divisors[qtblno] == NULL) {
  147265. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  147266. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147267. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  147268. }
  147269. fdtbl = fdct->float_divisors[qtblno];
  147270. i = 0;
  147271. for (row = 0; row < DCTSIZE; row++) {
  147272. for (col = 0; col < DCTSIZE; col++) {
  147273. fdtbl[i] = (FAST_FLOAT)
  147274. (1.0 / (((double) qtbl->quantval[i] *
  147275. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  147276. i++;
  147277. }
  147278. }
  147279. }
  147280. break;
  147281. #endif
  147282. default:
  147283. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147284. break;
  147285. }
  147286. }
  147287. }
  147288. METHODDEF(void)
  147289. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147290. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147291. JDIMENSION start_row, JDIMENSION start_col,
  147292. JDIMENSION num_blocks)
  147293. {
  147294. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147295. forward_DCT_method_ptr do_dct = fdct->do_dct;
  147296. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  147297. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147298. JDIMENSION bi;
  147299. sample_data += start_row; /* fold in the vertical offset once */
  147300. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147301. { register DCTELEM *workspaceptr;
  147302. register JSAMPROW elemptr;
  147303. register int elemr;
  147304. workspaceptr = workspace;
  147305. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147306. elemptr = sample_data[elemr] + start_col;
  147307. #if DCTSIZE == 8 /* unroll the inner loop */
  147308. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147309. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147310. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147311. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147312. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147313. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147314. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147315. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147316. #else
  147317. { register int elemc;
  147318. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147319. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147320. }
  147321. }
  147322. #endif
  147323. }
  147324. }
  147325. (*do_dct) (workspace);
  147326. { register DCTELEM temp, qval;
  147327. register int i;
  147328. register JCOEFPTR output_ptr = coef_blocks[bi];
  147329. for (i = 0; i < DCTSIZE2; i++) {
  147330. qval = divisors[i];
  147331. temp = workspace[i];
  147332. #ifdef FAST_DIVIDE
  147333. #define DIVIDE_BY(a,b) a /= b
  147334. #else
  147335. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  147336. #endif
  147337. if (temp < 0) {
  147338. temp = -temp;
  147339. temp += qval>>1; /* for rounding */
  147340. DIVIDE_BY(temp, qval);
  147341. temp = -temp;
  147342. } else {
  147343. temp += qval>>1; /* for rounding */
  147344. DIVIDE_BY(temp, qval);
  147345. }
  147346. output_ptr[i] = (JCOEF) temp;
  147347. }
  147348. }
  147349. }
  147350. }
  147351. #ifdef DCT_FLOAT_SUPPORTED
  147352. METHODDEF(void)
  147353. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147354. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147355. JDIMENSION start_row, JDIMENSION start_col,
  147356. JDIMENSION num_blocks)
  147357. {
  147358. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147359. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  147360. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  147361. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147362. JDIMENSION bi;
  147363. sample_data += start_row; /* fold in the vertical offset once */
  147364. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147365. { register FAST_FLOAT *workspaceptr;
  147366. register JSAMPROW elemptr;
  147367. register int elemr;
  147368. workspaceptr = workspace;
  147369. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147370. elemptr = sample_data[elemr] + start_col;
  147371. #if DCTSIZE == 8 /* unroll the inner loop */
  147372. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147373. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147374. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147375. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147376. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147377. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147378. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147379. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147380. #else
  147381. { register int elemc;
  147382. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147383. *workspaceptr++ = (FAST_FLOAT)
  147384. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147385. }
  147386. }
  147387. #endif
  147388. }
  147389. }
  147390. (*do_dct) (workspace);
  147391. { register FAST_FLOAT temp;
  147392. register int i;
  147393. register JCOEFPTR output_ptr = coef_blocks[bi];
  147394. for (i = 0; i < DCTSIZE2; i++) {
  147395. temp = workspace[i] * divisors[i];
  147396. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  147397. }
  147398. }
  147399. }
  147400. }
  147401. #endif /* DCT_FLOAT_SUPPORTED */
  147402. GLOBAL(void)
  147403. jinit_forward_dct (j_compress_ptr cinfo)
  147404. {
  147405. my_fdct_ptr fdct;
  147406. int i;
  147407. fdct = (my_fdct_ptr)
  147408. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147409. SIZEOF(my_fdct_controller));
  147410. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  147411. fdct->pub.start_pass = start_pass_fdctmgr;
  147412. switch (cinfo->dct_method) {
  147413. #ifdef DCT_ISLOW_SUPPORTED
  147414. case JDCT_ISLOW:
  147415. fdct->pub.forward_DCT = forward_DCT;
  147416. fdct->do_dct = jpeg_fdct_islow;
  147417. break;
  147418. #endif
  147419. #ifdef DCT_IFAST_SUPPORTED
  147420. case JDCT_IFAST:
  147421. fdct->pub.forward_DCT = forward_DCT;
  147422. fdct->do_dct = jpeg_fdct_ifast;
  147423. break;
  147424. #endif
  147425. #ifdef DCT_FLOAT_SUPPORTED
  147426. case JDCT_FLOAT:
  147427. fdct->pub.forward_DCT = forward_DCT_float;
  147428. fdct->do_float_dct = jpeg_fdct_float;
  147429. break;
  147430. #endif
  147431. default:
  147432. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147433. break;
  147434. }
  147435. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147436. fdct->divisors[i] = NULL;
  147437. #ifdef DCT_FLOAT_SUPPORTED
  147438. fdct->float_divisors[i] = NULL;
  147439. #endif
  147440. }
  147441. }
  147442. /*** End of inlined file: jcdctmgr.c ***/
  147443. #undef CONST_BITS
  147444. /*** Start of inlined file: jchuff.c ***/
  147445. #define JPEG_INTERNALS
  147446. /*** Start of inlined file: jchuff.h ***/
  147447. #ifndef _jchuff_h_
  147448. #define _jchuff_h_
  147449. #if BITS_IN_JSAMPLE == 8
  147450. #define MAX_COEF_BITS 10
  147451. #else
  147452. #define MAX_COEF_BITS 14
  147453. #endif
  147454. typedef struct {
  147455. unsigned int ehufco[256]; /* code for each symbol */
  147456. char ehufsi[256]; /* length of code for each symbol */
  147457. } c_derived_tbl;
  147458. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147459. #define jpeg_make_c_derived_tbl jMkCDerived
  147460. #define jpeg_gen_optimal_table jGenOptTbl
  147461. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147462. EXTERN(void) jpeg_make_c_derived_tbl
  147463. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  147464. c_derived_tbl ** pdtbl));
  147465. EXTERN(void) jpeg_gen_optimal_table
  147466. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  147467. #endif
  147468. /*** End of inlined file: jchuff.h ***/
  147469. /* Declarations shared with jcphuff.c */
  147470. typedef struct {
  147471. INT32 put_buffer; /* current bit-accumulation buffer */
  147472. int put_bits; /* # of bits now in it */
  147473. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  147474. } savable_state;
  147475. #ifndef NO_STRUCT_ASSIGN
  147476. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  147477. #else
  147478. #if MAX_COMPS_IN_SCAN == 4
  147479. #define ASSIGN_STATE(dest,src) \
  147480. ((dest).put_buffer = (src).put_buffer, \
  147481. (dest).put_bits = (src).put_bits, \
  147482. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  147483. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  147484. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  147485. (dest).last_dc_val[3] = (src).last_dc_val[3])
  147486. #endif
  147487. #endif
  147488. typedef struct {
  147489. struct jpeg_entropy_encoder pub; /* public fields */
  147490. savable_state saved; /* Bit buffer & DC state at start of MCU */
  147491. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  147492. int next_restart_num; /* next restart number to write (0-7) */
  147493. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  147494. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  147495. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  147496. long * dc_count_ptrs[NUM_HUFF_TBLS];
  147497. long * ac_count_ptrs[NUM_HUFF_TBLS];
  147498. #endif
  147499. } huff_entropy_encoder;
  147500. typedef huff_entropy_encoder * huff_entropy_ptr;
  147501. typedef struct {
  147502. JOCTET * next_output_byte; /* => next byte to write in buffer */
  147503. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  147504. savable_state cur; /* Current bit buffer & DC state */
  147505. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  147506. } working_state;
  147507. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  147508. JBLOCKROW *MCU_data));
  147509. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  147510. #ifdef ENTROPY_OPT_SUPPORTED
  147511. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  147512. JBLOCKROW *MCU_data));
  147513. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  147514. #endif
  147515. METHODDEF(void)
  147516. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  147517. {
  147518. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147519. int ci, dctbl, actbl;
  147520. jpeg_component_info * compptr;
  147521. if (gather_statistics) {
  147522. #ifdef ENTROPY_OPT_SUPPORTED
  147523. entropy->pub.encode_mcu = encode_mcu_gather;
  147524. entropy->pub.finish_pass = finish_pass_gather;
  147525. #else
  147526. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147527. #endif
  147528. } else {
  147529. entropy->pub.encode_mcu = encode_mcu_huff;
  147530. entropy->pub.finish_pass = finish_pass_huff;
  147531. }
  147532. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147533. compptr = cinfo->cur_comp_info[ci];
  147534. dctbl = compptr->dc_tbl_no;
  147535. actbl = compptr->ac_tbl_no;
  147536. if (gather_statistics) {
  147537. #ifdef ENTROPY_OPT_SUPPORTED
  147538. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147539. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147540. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147541. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147542. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147543. entropy->dc_count_ptrs[dctbl] = (long *)
  147544. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147545. 257 * SIZEOF(long));
  147546. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147547. if (entropy->ac_count_ptrs[actbl] == NULL)
  147548. entropy->ac_count_ptrs[actbl] = (long *)
  147549. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147550. 257 * SIZEOF(long));
  147551. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147552. #endif
  147553. } else {
  147554. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147555. & entropy->dc_derived_tbls[dctbl]);
  147556. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147557. & entropy->ac_derived_tbls[actbl]);
  147558. }
  147559. entropy->saved.last_dc_val[ci] = 0;
  147560. }
  147561. entropy->saved.put_buffer = 0;
  147562. entropy->saved.put_bits = 0;
  147563. entropy->restarts_to_go = cinfo->restart_interval;
  147564. entropy->next_restart_num = 0;
  147565. }
  147566. GLOBAL(void)
  147567. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147568. c_derived_tbl ** pdtbl)
  147569. {
  147570. JHUFF_TBL *htbl;
  147571. c_derived_tbl *dtbl;
  147572. int p, i, l, lastp, si, maxsymbol;
  147573. char huffsize[257];
  147574. unsigned int huffcode[257];
  147575. unsigned int code;
  147576. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147577. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147578. htbl =
  147579. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147580. if (htbl == NULL)
  147581. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147582. if (*pdtbl == NULL)
  147583. *pdtbl = (c_derived_tbl *)
  147584. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147585. SIZEOF(c_derived_tbl));
  147586. dtbl = *pdtbl;
  147587. p = 0;
  147588. for (l = 1; l <= 16; l++) {
  147589. i = (int) htbl->bits[l];
  147590. if (i < 0 || p + i > 256) /* protect against table overrun */
  147591. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147592. while (i--)
  147593. huffsize[p++] = (char) l;
  147594. }
  147595. huffsize[p] = 0;
  147596. lastp = p;
  147597. code = 0;
  147598. si = huffsize[0];
  147599. p = 0;
  147600. while (huffsize[p]) {
  147601. while (((int) huffsize[p]) == si) {
  147602. huffcode[p++] = code;
  147603. code++;
  147604. }
  147605. if (((INT32) code) >= (((INT32) 1) << si))
  147606. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147607. code <<= 1;
  147608. si++;
  147609. }
  147610. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147611. maxsymbol = isDC ? 15 : 255;
  147612. for (p = 0; p < lastp; p++) {
  147613. i = htbl->huffval[p];
  147614. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147615. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147616. dtbl->ehufco[i] = huffcode[p];
  147617. dtbl->ehufsi[i] = huffsize[p];
  147618. }
  147619. }
  147620. #define emit_byte(state,val,action) \
  147621. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147622. if (--(state)->free_in_buffer == 0) \
  147623. if (! dump_buffer(state)) \
  147624. { action; } }
  147625. LOCAL(boolean)
  147626. dump_buffer (working_state * state)
  147627. {
  147628. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147629. if (! (*dest->empty_output_buffer) (state->cinfo))
  147630. return FALSE;
  147631. state->next_output_byte = dest->next_output_byte;
  147632. state->free_in_buffer = dest->free_in_buffer;
  147633. return TRUE;
  147634. }
  147635. INLINE
  147636. LOCAL(boolean)
  147637. emit_bits (working_state * state, unsigned int code, int size)
  147638. {
  147639. register INT32 put_buffer = (INT32) code;
  147640. register int put_bits = state->cur.put_bits;
  147641. if (size == 0)
  147642. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147643. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147644. put_bits += size; /* new number of bits in buffer */
  147645. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147646. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147647. while (put_bits >= 8) {
  147648. int c = (int) ((put_buffer >> 16) & 0xFF);
  147649. emit_byte(state, c, return FALSE);
  147650. if (c == 0xFF) { /* need to stuff a zero byte? */
  147651. emit_byte(state, 0, return FALSE);
  147652. }
  147653. put_buffer <<= 8;
  147654. put_bits -= 8;
  147655. }
  147656. state->cur.put_buffer = put_buffer; /* update state variables */
  147657. state->cur.put_bits = put_bits;
  147658. return TRUE;
  147659. }
  147660. LOCAL(boolean)
  147661. flush_bits (working_state * state)
  147662. {
  147663. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147664. return FALSE;
  147665. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147666. state->cur.put_bits = 0;
  147667. return TRUE;
  147668. }
  147669. LOCAL(boolean)
  147670. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147671. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147672. {
  147673. register int temp, temp2;
  147674. register int nbits;
  147675. register int k, r, i;
  147676. temp = temp2 = block[0] - last_dc_val;
  147677. if (temp < 0) {
  147678. temp = -temp; /* temp is abs value of input */
  147679. temp2--;
  147680. }
  147681. nbits = 0;
  147682. while (temp) {
  147683. nbits++;
  147684. temp >>= 1;
  147685. }
  147686. if (nbits > MAX_COEF_BITS+1)
  147687. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147688. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147689. return FALSE;
  147690. if (nbits) /* emit_bits rejects calls with size 0 */
  147691. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147692. return FALSE;
  147693. r = 0; /* r = run length of zeros */
  147694. for (k = 1; k < DCTSIZE2; k++) {
  147695. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147696. r++;
  147697. } else {
  147698. while (r > 15) {
  147699. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147700. return FALSE;
  147701. r -= 16;
  147702. }
  147703. temp2 = temp;
  147704. if (temp < 0) {
  147705. temp = -temp; /* temp is abs value of input */
  147706. temp2--;
  147707. }
  147708. nbits = 1; /* there must be at least one 1 bit */
  147709. while ((temp >>= 1))
  147710. nbits++;
  147711. if (nbits > MAX_COEF_BITS)
  147712. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147713. i = (r << 4) + nbits;
  147714. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147715. return FALSE;
  147716. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147717. return FALSE;
  147718. r = 0;
  147719. }
  147720. }
  147721. if (r > 0)
  147722. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147723. return FALSE;
  147724. return TRUE;
  147725. }
  147726. LOCAL(boolean)
  147727. emit_restart (working_state * state, int restart_num)
  147728. {
  147729. int ci;
  147730. if (! flush_bits(state))
  147731. return FALSE;
  147732. emit_byte(state, 0xFF, return FALSE);
  147733. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147734. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147735. state->cur.last_dc_val[ci] = 0;
  147736. return TRUE;
  147737. }
  147738. METHODDEF(boolean)
  147739. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147740. {
  147741. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147742. working_state state;
  147743. int blkn, ci;
  147744. jpeg_component_info * compptr;
  147745. state.next_output_byte = cinfo->dest->next_output_byte;
  147746. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147747. ASSIGN_STATE(state.cur, entropy->saved);
  147748. state.cinfo = cinfo;
  147749. if (cinfo->restart_interval) {
  147750. if (entropy->restarts_to_go == 0)
  147751. if (! emit_restart(&state, entropy->next_restart_num))
  147752. return FALSE;
  147753. }
  147754. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147755. ci = cinfo->MCU_membership[blkn];
  147756. compptr = cinfo->cur_comp_info[ci];
  147757. if (! encode_one_block(&state,
  147758. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147759. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147760. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147761. return FALSE;
  147762. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147763. }
  147764. cinfo->dest->next_output_byte = state.next_output_byte;
  147765. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147766. ASSIGN_STATE(entropy->saved, state.cur);
  147767. if (cinfo->restart_interval) {
  147768. if (entropy->restarts_to_go == 0) {
  147769. entropy->restarts_to_go = cinfo->restart_interval;
  147770. entropy->next_restart_num++;
  147771. entropy->next_restart_num &= 7;
  147772. }
  147773. entropy->restarts_to_go--;
  147774. }
  147775. return TRUE;
  147776. }
  147777. METHODDEF(void)
  147778. finish_pass_huff (j_compress_ptr cinfo)
  147779. {
  147780. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147781. working_state state;
  147782. state.next_output_byte = cinfo->dest->next_output_byte;
  147783. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147784. ASSIGN_STATE(state.cur, entropy->saved);
  147785. state.cinfo = cinfo;
  147786. if (! flush_bits(&state))
  147787. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147788. cinfo->dest->next_output_byte = state.next_output_byte;
  147789. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147790. ASSIGN_STATE(entropy->saved, state.cur);
  147791. }
  147792. #ifdef ENTROPY_OPT_SUPPORTED
  147793. LOCAL(void)
  147794. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147795. long dc_counts[], long ac_counts[])
  147796. {
  147797. register int temp;
  147798. register int nbits;
  147799. register int k, r;
  147800. temp = block[0] - last_dc_val;
  147801. if (temp < 0)
  147802. temp = -temp;
  147803. nbits = 0;
  147804. while (temp) {
  147805. nbits++;
  147806. temp >>= 1;
  147807. }
  147808. if (nbits > MAX_COEF_BITS+1)
  147809. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147810. dc_counts[nbits]++;
  147811. r = 0; /* r = run length of zeros */
  147812. for (k = 1; k < DCTSIZE2; k++) {
  147813. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147814. r++;
  147815. } else {
  147816. while (r > 15) {
  147817. ac_counts[0xF0]++;
  147818. r -= 16;
  147819. }
  147820. if (temp < 0)
  147821. temp = -temp;
  147822. nbits = 1; /* there must be at least one 1 bit */
  147823. while ((temp >>= 1))
  147824. nbits++;
  147825. if (nbits > MAX_COEF_BITS)
  147826. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147827. ac_counts[(r << 4) + nbits]++;
  147828. r = 0;
  147829. }
  147830. }
  147831. if (r > 0)
  147832. ac_counts[0]++;
  147833. }
  147834. METHODDEF(boolean)
  147835. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147836. {
  147837. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147838. int blkn, ci;
  147839. jpeg_component_info * compptr;
  147840. if (cinfo->restart_interval) {
  147841. if (entropy->restarts_to_go == 0) {
  147842. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147843. entropy->saved.last_dc_val[ci] = 0;
  147844. entropy->restarts_to_go = cinfo->restart_interval;
  147845. }
  147846. entropy->restarts_to_go--;
  147847. }
  147848. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147849. ci = cinfo->MCU_membership[blkn];
  147850. compptr = cinfo->cur_comp_info[ci];
  147851. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147852. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147853. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147854. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147855. }
  147856. return TRUE;
  147857. }
  147858. GLOBAL(void)
  147859. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147860. {
  147861. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147862. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147863. int codesize[257]; /* codesize[k] = code length of symbol k */
  147864. int others[257]; /* next symbol in current branch of tree */
  147865. int c1, c2;
  147866. int p, i, j;
  147867. long v;
  147868. MEMZERO(bits, SIZEOF(bits));
  147869. MEMZERO(codesize, SIZEOF(codesize));
  147870. for (i = 0; i < 257; i++)
  147871. others[i] = -1; /* init links to empty */
  147872. freq[256] = 1; /* make sure 256 has a nonzero count */
  147873. for (;;) {
  147874. c1 = -1;
  147875. v = 1000000000L;
  147876. for (i = 0; i <= 256; i++) {
  147877. if (freq[i] && freq[i] <= v) {
  147878. v = freq[i];
  147879. c1 = i;
  147880. }
  147881. }
  147882. c2 = -1;
  147883. v = 1000000000L;
  147884. for (i = 0; i <= 256; i++) {
  147885. if (freq[i] && freq[i] <= v && i != c1) {
  147886. v = freq[i];
  147887. c2 = i;
  147888. }
  147889. }
  147890. if (c2 < 0)
  147891. break;
  147892. freq[c1] += freq[c2];
  147893. freq[c2] = 0;
  147894. codesize[c1]++;
  147895. while (others[c1] >= 0) {
  147896. c1 = others[c1];
  147897. codesize[c1]++;
  147898. }
  147899. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147900. codesize[c2]++;
  147901. while (others[c2] >= 0) {
  147902. c2 = others[c2];
  147903. codesize[c2]++;
  147904. }
  147905. }
  147906. for (i = 0; i <= 256; i++) {
  147907. if (codesize[i]) {
  147908. if (codesize[i] > MAX_CLEN)
  147909. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147910. bits[codesize[i]]++;
  147911. }
  147912. }
  147913. for (i = MAX_CLEN; i > 16; i--) {
  147914. while (bits[i] > 0) {
  147915. j = i - 2; /* find length of new prefix to be used */
  147916. while (bits[j] == 0)
  147917. j--;
  147918. bits[i] -= 2; /* remove two symbols */
  147919. bits[i-1]++; /* one goes in this length */
  147920. bits[j+1] += 2; /* two new symbols in this length */
  147921. bits[j]--; /* symbol of this length is now a prefix */
  147922. }
  147923. }
  147924. while (bits[i] == 0) /* find largest codelength still in use */
  147925. i--;
  147926. bits[i]--;
  147927. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147928. p = 0;
  147929. for (i = 1; i <= MAX_CLEN; i++) {
  147930. for (j = 0; j <= 255; j++) {
  147931. if (codesize[j] == i) {
  147932. htbl->huffval[p] = (UINT8) j;
  147933. p++;
  147934. }
  147935. }
  147936. }
  147937. htbl->sent_table = FALSE;
  147938. }
  147939. METHODDEF(void)
  147940. finish_pass_gather (j_compress_ptr cinfo)
  147941. {
  147942. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147943. int ci, dctbl, actbl;
  147944. jpeg_component_info * compptr;
  147945. JHUFF_TBL **htblptr;
  147946. boolean did_dc[NUM_HUFF_TBLS];
  147947. boolean did_ac[NUM_HUFF_TBLS];
  147948. MEMZERO(did_dc, SIZEOF(did_dc));
  147949. MEMZERO(did_ac, SIZEOF(did_ac));
  147950. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147951. compptr = cinfo->cur_comp_info[ci];
  147952. dctbl = compptr->dc_tbl_no;
  147953. actbl = compptr->ac_tbl_no;
  147954. if (! did_dc[dctbl]) {
  147955. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147956. if (*htblptr == NULL)
  147957. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147958. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147959. did_dc[dctbl] = TRUE;
  147960. }
  147961. if (! did_ac[actbl]) {
  147962. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147963. if (*htblptr == NULL)
  147964. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147965. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147966. did_ac[actbl] = TRUE;
  147967. }
  147968. }
  147969. }
  147970. #endif /* ENTROPY_OPT_SUPPORTED */
  147971. GLOBAL(void)
  147972. jinit_huff_encoder (j_compress_ptr cinfo)
  147973. {
  147974. huff_entropy_ptr entropy;
  147975. int i;
  147976. entropy = (huff_entropy_ptr)
  147977. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147978. SIZEOF(huff_entropy_encoder));
  147979. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147980. entropy->pub.start_pass = start_pass_huff;
  147981. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147982. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147983. #ifdef ENTROPY_OPT_SUPPORTED
  147984. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147985. #endif
  147986. }
  147987. }
  147988. /*** End of inlined file: jchuff.c ***/
  147989. #undef emit_byte
  147990. /*** Start of inlined file: jcinit.c ***/
  147991. #define JPEG_INTERNALS
  147992. GLOBAL(void)
  147993. jinit_compress_master (j_compress_ptr cinfo)
  147994. {
  147995. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147996. if (! cinfo->raw_data_in) {
  147997. jinit_color_converter(cinfo);
  147998. jinit_downsampler(cinfo);
  147999. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  148000. }
  148001. jinit_forward_dct(cinfo);
  148002. if (cinfo->arith_code) {
  148003. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  148004. } else {
  148005. if (cinfo->progressive_mode) {
  148006. #ifdef C_PROGRESSIVE_SUPPORTED
  148007. jinit_phuff_encoder(cinfo);
  148008. #else
  148009. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148010. #endif
  148011. } else
  148012. jinit_huff_encoder(cinfo);
  148013. }
  148014. jinit_c_coef_controller(cinfo,
  148015. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  148016. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  148017. jinit_marker_writer(cinfo);
  148018. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  148019. (*cinfo->marker->write_file_header) (cinfo);
  148020. }
  148021. /*** End of inlined file: jcinit.c ***/
  148022. /*** Start of inlined file: jcmainct.c ***/
  148023. #define JPEG_INTERNALS
  148024. #undef FULL_MAIN_BUFFER_SUPPORTED
  148025. typedef struct {
  148026. struct jpeg_c_main_controller pub; /* public fields */
  148027. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  148028. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  148029. boolean suspended; /* remember if we suspended output */
  148030. J_BUF_MODE pass_mode; /* current operating mode */
  148031. JSAMPARRAY buffer[MAX_COMPONENTS];
  148032. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148033. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  148034. #endif
  148035. } my_main_controller;
  148036. typedef my_main_controller * my_main_ptr;
  148037. METHODDEF(void) process_data_simple_main
  148038. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  148039. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  148040. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148041. METHODDEF(void) process_data_buffer_main
  148042. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  148043. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  148044. #endif
  148045. METHODDEF(void)
  148046. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  148047. {
  148048. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  148049. if (cinfo->raw_data_in)
  148050. return;
  148051. main_->cur_iMCU_row = 0; /* initialize counters */
  148052. main_->rowgroup_ctr = 0;
  148053. main_->suspended = FALSE;
  148054. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  148055. switch (pass_mode) {
  148056. case JBUF_PASS_THRU:
  148057. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148058. if (main_->whole_image[0] != NULL)
  148059. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148060. #endif
  148061. main_->pub.process_data = process_data_simple_main;
  148062. break;
  148063. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148064. case JBUF_SAVE_SOURCE:
  148065. case JBUF_CRANK_DEST:
  148066. case JBUF_SAVE_AND_PASS:
  148067. if (main_->whole_image[0] == NULL)
  148068. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148069. main_->pub.process_data = process_data_buffer_main;
  148070. break;
  148071. #endif
  148072. default:
  148073. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148074. break;
  148075. }
  148076. }
  148077. METHODDEF(void)
  148078. process_data_simple_main (j_compress_ptr cinfo,
  148079. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  148080. JDIMENSION in_rows_avail)
  148081. {
  148082. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  148083. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  148084. if (main_->rowgroup_ctr < DCTSIZE)
  148085. (*cinfo->prep->pre_process_data) (cinfo,
  148086. input_buf, in_row_ctr, in_rows_avail,
  148087. main_->buffer, &main_->rowgroup_ctr,
  148088. (JDIMENSION) DCTSIZE);
  148089. if (main_->rowgroup_ctr != DCTSIZE)
  148090. return;
  148091. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  148092. if (! main_->suspended) {
  148093. (*in_row_ctr)--;
  148094. main_->suspended = TRUE;
  148095. }
  148096. return;
  148097. }
  148098. if (main_->suspended) {
  148099. (*in_row_ctr)++;
  148100. main_->suspended = FALSE;
  148101. }
  148102. main_->rowgroup_ctr = 0;
  148103. main_->cur_iMCU_row++;
  148104. }
  148105. }
  148106. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148107. METHODDEF(void)
  148108. process_data_buffer_main (j_compress_ptr cinfo,
  148109. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  148110. JDIMENSION in_rows_avail)
  148111. {
  148112. my_main_ptr main = (my_main_ptr) cinfo->main;
  148113. int ci;
  148114. jpeg_component_info *compptr;
  148115. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  148116. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  148117. if (main->rowgroup_ctr == 0) {
  148118. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148119. ci++, compptr++) {
  148120. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  148121. ((j_common_ptr) cinfo, main->whole_image[ci],
  148122. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  148123. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  148124. }
  148125. if (! writing) {
  148126. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  148127. main->rowgroup_ctr = DCTSIZE;
  148128. }
  148129. }
  148130. if (writing) {
  148131. (*cinfo->prep->pre_process_data) (cinfo,
  148132. input_buf, in_row_ctr, in_rows_avail,
  148133. main->buffer, &main->rowgroup_ctr,
  148134. (JDIMENSION) DCTSIZE);
  148135. if (main->rowgroup_ctr < DCTSIZE)
  148136. return;
  148137. }
  148138. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  148139. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  148140. if (! main->suspended) {
  148141. (*in_row_ctr)--;
  148142. main->suspended = TRUE;
  148143. }
  148144. return;
  148145. }
  148146. if (main->suspended) {
  148147. (*in_row_ctr)++;
  148148. main->suspended = FALSE;
  148149. }
  148150. }
  148151. main->rowgroup_ctr = 0;
  148152. main->cur_iMCU_row++;
  148153. }
  148154. }
  148155. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  148156. GLOBAL(void)
  148157. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  148158. {
  148159. my_main_ptr main_;
  148160. int ci;
  148161. jpeg_component_info *compptr;
  148162. main_ = (my_main_ptr)
  148163. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148164. SIZEOF(my_main_controller));
  148165. cinfo->main = (struct jpeg_c_main_controller *) main_;
  148166. main_->pub.start_pass = start_pass_main;
  148167. if (cinfo->raw_data_in)
  148168. return;
  148169. if (need_full_buffer) {
  148170. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148171. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148172. ci++, compptr++) {
  148173. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  148174. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  148175. compptr->width_in_blocks * DCTSIZE,
  148176. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  148177. (long) compptr->v_samp_factor) * DCTSIZE,
  148178. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148179. }
  148180. #else
  148181. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148182. #endif
  148183. } else {
  148184. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148185. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  148186. #endif
  148187. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148188. ci++, compptr++) {
  148189. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  148190. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148191. compptr->width_in_blocks * DCTSIZE,
  148192. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148193. }
  148194. }
  148195. }
  148196. /*** End of inlined file: jcmainct.c ***/
  148197. /*** Start of inlined file: jcmarker.c ***/
  148198. #define JPEG_INTERNALS
  148199. typedef struct {
  148200. struct jpeg_marker_writer pub; /* public fields */
  148201. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  148202. } my_marker_writer;
  148203. typedef my_marker_writer * my_marker_ptr;
  148204. LOCAL(void)
  148205. emit_byte (j_compress_ptr cinfo, int val)
  148206. {
  148207. struct jpeg_destination_mgr * dest = cinfo->dest;
  148208. *(dest->next_output_byte)++ = (JOCTET) val;
  148209. if (--dest->free_in_buffer == 0) {
  148210. if (! (*dest->empty_output_buffer) (cinfo))
  148211. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  148212. }
  148213. }
  148214. LOCAL(void)
  148215. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  148216. {
  148217. emit_byte(cinfo, 0xFF);
  148218. emit_byte(cinfo, (int) mark);
  148219. }
  148220. LOCAL(void)
  148221. emit_2bytes (j_compress_ptr cinfo, int value)
  148222. {
  148223. emit_byte(cinfo, (value >> 8) & 0xFF);
  148224. emit_byte(cinfo, value & 0xFF);
  148225. }
  148226. LOCAL(int)
  148227. emit_dqt (j_compress_ptr cinfo, int index)
  148228. {
  148229. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  148230. int prec;
  148231. int i;
  148232. if (qtbl == NULL)
  148233. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  148234. prec = 0;
  148235. for (i = 0; i < DCTSIZE2; i++) {
  148236. if (qtbl->quantval[i] > 255)
  148237. prec = 1;
  148238. }
  148239. if (! qtbl->sent_table) {
  148240. emit_marker(cinfo, M_DQT);
  148241. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  148242. emit_byte(cinfo, index + (prec<<4));
  148243. for (i = 0; i < DCTSIZE2; i++) {
  148244. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  148245. if (prec)
  148246. emit_byte(cinfo, (int) (qval >> 8));
  148247. emit_byte(cinfo, (int) (qval & 0xFF));
  148248. }
  148249. qtbl->sent_table = TRUE;
  148250. }
  148251. return prec;
  148252. }
  148253. LOCAL(void)
  148254. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  148255. {
  148256. JHUFF_TBL * htbl;
  148257. int length, i;
  148258. if (is_ac) {
  148259. htbl = cinfo->ac_huff_tbl_ptrs[index];
  148260. index += 0x10; /* output index has AC bit set */
  148261. } else {
  148262. htbl = cinfo->dc_huff_tbl_ptrs[index];
  148263. }
  148264. if (htbl == NULL)
  148265. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  148266. if (! htbl->sent_table) {
  148267. emit_marker(cinfo, M_DHT);
  148268. length = 0;
  148269. for (i = 1; i <= 16; i++)
  148270. length += htbl->bits[i];
  148271. emit_2bytes(cinfo, length + 2 + 1 + 16);
  148272. emit_byte(cinfo, index);
  148273. for (i = 1; i <= 16; i++)
  148274. emit_byte(cinfo, htbl->bits[i]);
  148275. for (i = 0; i < length; i++)
  148276. emit_byte(cinfo, htbl->huffval[i]);
  148277. htbl->sent_table = TRUE;
  148278. }
  148279. }
  148280. LOCAL(void)
  148281. emit_dac (j_compress_ptr cinfo)
  148282. {
  148283. #ifdef C_ARITH_CODING_SUPPORTED
  148284. char dc_in_use[NUM_ARITH_TBLS];
  148285. char ac_in_use[NUM_ARITH_TBLS];
  148286. int length, i;
  148287. jpeg_component_info *compptr;
  148288. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148289. dc_in_use[i] = ac_in_use[i] = 0;
  148290. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148291. compptr = cinfo->cur_comp_info[i];
  148292. dc_in_use[compptr->dc_tbl_no] = 1;
  148293. ac_in_use[compptr->ac_tbl_no] = 1;
  148294. }
  148295. length = 0;
  148296. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148297. length += dc_in_use[i] + ac_in_use[i];
  148298. emit_marker(cinfo, M_DAC);
  148299. emit_2bytes(cinfo, length*2 + 2);
  148300. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148301. if (dc_in_use[i]) {
  148302. emit_byte(cinfo, i);
  148303. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  148304. }
  148305. if (ac_in_use[i]) {
  148306. emit_byte(cinfo, i + 0x10);
  148307. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  148308. }
  148309. }
  148310. #endif /* C_ARITH_CODING_SUPPORTED */
  148311. }
  148312. LOCAL(void)
  148313. emit_dri (j_compress_ptr cinfo)
  148314. {
  148315. emit_marker(cinfo, M_DRI);
  148316. emit_2bytes(cinfo, 4); /* fixed length */
  148317. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  148318. }
  148319. LOCAL(void)
  148320. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  148321. {
  148322. int ci;
  148323. jpeg_component_info *compptr;
  148324. emit_marker(cinfo, code);
  148325. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  148326. if ((long) cinfo->image_height > 65535L ||
  148327. (long) cinfo->image_width > 65535L)
  148328. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  148329. emit_byte(cinfo, cinfo->data_precision);
  148330. emit_2bytes(cinfo, (int) cinfo->image_height);
  148331. emit_2bytes(cinfo, (int) cinfo->image_width);
  148332. emit_byte(cinfo, cinfo->num_components);
  148333. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148334. ci++, compptr++) {
  148335. emit_byte(cinfo, compptr->component_id);
  148336. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  148337. emit_byte(cinfo, compptr->quant_tbl_no);
  148338. }
  148339. }
  148340. LOCAL(void)
  148341. emit_sos (j_compress_ptr cinfo)
  148342. {
  148343. int i, td, ta;
  148344. jpeg_component_info *compptr;
  148345. emit_marker(cinfo, M_SOS);
  148346. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  148347. emit_byte(cinfo, cinfo->comps_in_scan);
  148348. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148349. compptr = cinfo->cur_comp_info[i];
  148350. emit_byte(cinfo, compptr->component_id);
  148351. td = compptr->dc_tbl_no;
  148352. ta = compptr->ac_tbl_no;
  148353. if (cinfo->progressive_mode) {
  148354. if (cinfo->Ss == 0) {
  148355. ta = 0; /* DC scan */
  148356. if (cinfo->Ah != 0 && !cinfo->arith_code)
  148357. td = 0; /* no DC table either */
  148358. } else {
  148359. td = 0; /* AC scan */
  148360. }
  148361. }
  148362. emit_byte(cinfo, (td << 4) + ta);
  148363. }
  148364. emit_byte(cinfo, cinfo->Ss);
  148365. emit_byte(cinfo, cinfo->Se);
  148366. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  148367. }
  148368. LOCAL(void)
  148369. emit_jfif_app0 (j_compress_ptr cinfo)
  148370. {
  148371. emit_marker(cinfo, M_APP0);
  148372. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  148373. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  148374. emit_byte(cinfo, 0x46);
  148375. emit_byte(cinfo, 0x49);
  148376. emit_byte(cinfo, 0x46);
  148377. emit_byte(cinfo, 0);
  148378. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  148379. emit_byte(cinfo, cinfo->JFIF_minor_version);
  148380. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  148381. emit_2bytes(cinfo, (int) cinfo->X_density);
  148382. emit_2bytes(cinfo, (int) cinfo->Y_density);
  148383. emit_byte(cinfo, 0); /* No thumbnail image */
  148384. emit_byte(cinfo, 0);
  148385. }
  148386. LOCAL(void)
  148387. emit_adobe_app14 (j_compress_ptr cinfo)
  148388. {
  148389. emit_marker(cinfo, M_APP14);
  148390. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  148391. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  148392. emit_byte(cinfo, 0x64);
  148393. emit_byte(cinfo, 0x6F);
  148394. emit_byte(cinfo, 0x62);
  148395. emit_byte(cinfo, 0x65);
  148396. emit_2bytes(cinfo, 100); /* Version */
  148397. emit_2bytes(cinfo, 0); /* Flags0 */
  148398. emit_2bytes(cinfo, 0); /* Flags1 */
  148399. switch (cinfo->jpeg_color_space) {
  148400. case JCS_YCbCr:
  148401. emit_byte(cinfo, 1); /* Color transform = 1 */
  148402. break;
  148403. case JCS_YCCK:
  148404. emit_byte(cinfo, 2); /* Color transform = 2 */
  148405. break;
  148406. default:
  148407. emit_byte(cinfo, 0); /* Color transform = 0 */
  148408. break;
  148409. }
  148410. }
  148411. METHODDEF(void)
  148412. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  148413. {
  148414. if (datalen > (unsigned int) 65533) /* safety check */
  148415. ERREXIT(cinfo, JERR_BAD_LENGTH);
  148416. emit_marker(cinfo, (JPEG_MARKER) marker);
  148417. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  148418. }
  148419. METHODDEF(void)
  148420. write_marker_byte (j_compress_ptr cinfo, int val)
  148421. {
  148422. emit_byte(cinfo, val);
  148423. }
  148424. METHODDEF(void)
  148425. write_file_header (j_compress_ptr cinfo)
  148426. {
  148427. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148428. emit_marker(cinfo, M_SOI); /* first the SOI */
  148429. marker->last_restart_interval = 0;
  148430. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  148431. emit_jfif_app0(cinfo);
  148432. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  148433. emit_adobe_app14(cinfo);
  148434. }
  148435. METHODDEF(void)
  148436. write_frame_header (j_compress_ptr cinfo)
  148437. {
  148438. int ci, prec;
  148439. boolean is_baseline;
  148440. jpeg_component_info *compptr;
  148441. prec = 0;
  148442. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148443. ci++, compptr++) {
  148444. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  148445. }
  148446. if (cinfo->arith_code || cinfo->progressive_mode ||
  148447. cinfo->data_precision != 8) {
  148448. is_baseline = FALSE;
  148449. } else {
  148450. is_baseline = TRUE;
  148451. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148452. ci++, compptr++) {
  148453. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  148454. is_baseline = FALSE;
  148455. }
  148456. if (prec && is_baseline) {
  148457. is_baseline = FALSE;
  148458. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  148459. }
  148460. }
  148461. if (cinfo->arith_code) {
  148462. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  148463. } else {
  148464. if (cinfo->progressive_mode)
  148465. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  148466. else if (is_baseline)
  148467. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  148468. else
  148469. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  148470. }
  148471. }
  148472. METHODDEF(void)
  148473. write_scan_header (j_compress_ptr cinfo)
  148474. {
  148475. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148476. int i;
  148477. jpeg_component_info *compptr;
  148478. if (cinfo->arith_code) {
  148479. emit_dac(cinfo);
  148480. } else {
  148481. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148482. compptr = cinfo->cur_comp_info[i];
  148483. if (cinfo->progressive_mode) {
  148484. if (cinfo->Ss == 0) {
  148485. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  148486. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148487. } else {
  148488. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148489. }
  148490. } else {
  148491. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148492. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148493. }
  148494. }
  148495. }
  148496. if (cinfo->restart_interval != marker->last_restart_interval) {
  148497. emit_dri(cinfo);
  148498. marker->last_restart_interval = cinfo->restart_interval;
  148499. }
  148500. emit_sos(cinfo);
  148501. }
  148502. METHODDEF(void)
  148503. write_file_trailer (j_compress_ptr cinfo)
  148504. {
  148505. emit_marker(cinfo, M_EOI);
  148506. }
  148507. METHODDEF(void)
  148508. write_tables_only (j_compress_ptr cinfo)
  148509. {
  148510. int i;
  148511. emit_marker(cinfo, M_SOI);
  148512. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  148513. if (cinfo->quant_tbl_ptrs[i] != NULL)
  148514. (void) emit_dqt(cinfo, i);
  148515. }
  148516. if (! cinfo->arith_code) {
  148517. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148518. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  148519. emit_dht(cinfo, i, FALSE);
  148520. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  148521. emit_dht(cinfo, i, TRUE);
  148522. }
  148523. }
  148524. emit_marker(cinfo, M_EOI);
  148525. }
  148526. GLOBAL(void)
  148527. jinit_marker_writer (j_compress_ptr cinfo)
  148528. {
  148529. my_marker_ptr marker;
  148530. marker = (my_marker_ptr)
  148531. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148532. SIZEOF(my_marker_writer));
  148533. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148534. marker->pub.write_file_header = write_file_header;
  148535. marker->pub.write_frame_header = write_frame_header;
  148536. marker->pub.write_scan_header = write_scan_header;
  148537. marker->pub.write_file_trailer = write_file_trailer;
  148538. marker->pub.write_tables_only = write_tables_only;
  148539. marker->pub.write_marker_header = write_marker_header;
  148540. marker->pub.write_marker_byte = write_marker_byte;
  148541. marker->last_restart_interval = 0;
  148542. }
  148543. /*** End of inlined file: jcmarker.c ***/
  148544. /*** Start of inlined file: jcmaster.c ***/
  148545. #define JPEG_INTERNALS
  148546. typedef enum {
  148547. main_pass, /* input data, also do first output step */
  148548. huff_opt_pass, /* Huffman code optimization pass */
  148549. output_pass /* data output pass */
  148550. } c_pass_type;
  148551. typedef struct {
  148552. struct jpeg_comp_master pub; /* public fields */
  148553. c_pass_type pass_type; /* the type of the current pass */
  148554. int pass_number; /* # of passes completed */
  148555. int total_passes; /* total # of passes needed */
  148556. int scan_number; /* current index in scan_info[] */
  148557. } my_comp_master;
  148558. typedef my_comp_master * my_master_ptr;
  148559. LOCAL(void)
  148560. initial_setup (j_compress_ptr cinfo)
  148561. {
  148562. int ci;
  148563. jpeg_component_info *compptr;
  148564. long samplesperrow;
  148565. JDIMENSION jd_samplesperrow;
  148566. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148567. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148568. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148569. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148570. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148571. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148572. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148573. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148574. if ((long) jd_samplesperrow != samplesperrow)
  148575. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148576. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148577. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148578. if (cinfo->num_components > MAX_COMPONENTS)
  148579. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148580. MAX_COMPONENTS);
  148581. cinfo->max_h_samp_factor = 1;
  148582. cinfo->max_v_samp_factor = 1;
  148583. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148584. ci++, compptr++) {
  148585. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148586. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148587. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148588. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148589. compptr->h_samp_factor);
  148590. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148591. compptr->v_samp_factor);
  148592. }
  148593. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148594. ci++, compptr++) {
  148595. compptr->component_index = ci;
  148596. compptr->DCT_scaled_size = DCTSIZE;
  148597. compptr->width_in_blocks = (JDIMENSION)
  148598. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148599. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148600. compptr->height_in_blocks = (JDIMENSION)
  148601. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148602. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148603. compptr->downsampled_width = (JDIMENSION)
  148604. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148605. (long) cinfo->max_h_samp_factor);
  148606. compptr->downsampled_height = (JDIMENSION)
  148607. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148608. (long) cinfo->max_v_samp_factor);
  148609. compptr->component_needed = TRUE;
  148610. }
  148611. cinfo->total_iMCU_rows = (JDIMENSION)
  148612. jdiv_round_up((long) cinfo->image_height,
  148613. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148614. }
  148615. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148616. LOCAL(void)
  148617. validate_script (j_compress_ptr cinfo)
  148618. {
  148619. const jpeg_scan_info * scanptr;
  148620. int scanno, ncomps, ci, coefi, thisi;
  148621. int Ss, Se, Ah, Al;
  148622. boolean component_sent[MAX_COMPONENTS];
  148623. #ifdef C_PROGRESSIVE_SUPPORTED
  148624. int * last_bitpos_ptr;
  148625. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148626. #endif
  148627. if (cinfo->num_scans <= 0)
  148628. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148629. scanptr = cinfo->scan_info;
  148630. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148631. #ifdef C_PROGRESSIVE_SUPPORTED
  148632. cinfo->progressive_mode = TRUE;
  148633. last_bitpos_ptr = & last_bitpos[0][0];
  148634. for (ci = 0; ci < cinfo->num_components; ci++)
  148635. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148636. *last_bitpos_ptr++ = -1;
  148637. #else
  148638. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148639. #endif
  148640. } else {
  148641. cinfo->progressive_mode = FALSE;
  148642. for (ci = 0; ci < cinfo->num_components; ci++)
  148643. component_sent[ci] = FALSE;
  148644. }
  148645. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148646. ncomps = scanptr->comps_in_scan;
  148647. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148648. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148649. for (ci = 0; ci < ncomps; ci++) {
  148650. thisi = scanptr->component_index[ci];
  148651. if (thisi < 0 || thisi >= cinfo->num_components)
  148652. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148653. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148654. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148655. }
  148656. Ss = scanptr->Ss;
  148657. Se = scanptr->Se;
  148658. Ah = scanptr->Ah;
  148659. Al = scanptr->Al;
  148660. if (cinfo->progressive_mode) {
  148661. #ifdef C_PROGRESSIVE_SUPPORTED
  148662. #if BITS_IN_JSAMPLE == 8
  148663. #define MAX_AH_AL 10
  148664. #else
  148665. #define MAX_AH_AL 13
  148666. #endif
  148667. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148668. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148669. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148670. if (Ss == 0) {
  148671. if (Se != 0) /* DC and AC together not OK */
  148672. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148673. } else {
  148674. if (ncomps != 1) /* AC scans must be for only one component */
  148675. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148676. }
  148677. for (ci = 0; ci < ncomps; ci++) {
  148678. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148679. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148680. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148681. for (coefi = Ss; coefi <= Se; coefi++) {
  148682. if (last_bitpos_ptr[coefi] < 0) {
  148683. if (Ah != 0)
  148684. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148685. } else {
  148686. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148687. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148688. }
  148689. last_bitpos_ptr[coefi] = Al;
  148690. }
  148691. }
  148692. #endif
  148693. } else {
  148694. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148695. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148696. for (ci = 0; ci < ncomps; ci++) {
  148697. thisi = scanptr->component_index[ci];
  148698. if (component_sent[thisi])
  148699. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148700. component_sent[thisi] = TRUE;
  148701. }
  148702. }
  148703. }
  148704. if (cinfo->progressive_mode) {
  148705. #ifdef C_PROGRESSIVE_SUPPORTED
  148706. for (ci = 0; ci < cinfo->num_components; ci++) {
  148707. if (last_bitpos[ci][0] < 0)
  148708. ERREXIT(cinfo, JERR_MISSING_DATA);
  148709. }
  148710. #endif
  148711. } else {
  148712. for (ci = 0; ci < cinfo->num_components; ci++) {
  148713. if (! component_sent[ci])
  148714. ERREXIT(cinfo, JERR_MISSING_DATA);
  148715. }
  148716. }
  148717. }
  148718. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148719. LOCAL(void)
  148720. select_scan_parameters (j_compress_ptr cinfo)
  148721. {
  148722. int ci;
  148723. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148724. if (cinfo->scan_info != NULL) {
  148725. my_master_ptr master = (my_master_ptr) cinfo->master;
  148726. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148727. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148728. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148729. cinfo->cur_comp_info[ci] =
  148730. &cinfo->comp_info[scanptr->component_index[ci]];
  148731. }
  148732. cinfo->Ss = scanptr->Ss;
  148733. cinfo->Se = scanptr->Se;
  148734. cinfo->Ah = scanptr->Ah;
  148735. cinfo->Al = scanptr->Al;
  148736. }
  148737. else
  148738. #endif
  148739. {
  148740. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148741. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148742. MAX_COMPS_IN_SCAN);
  148743. cinfo->comps_in_scan = cinfo->num_components;
  148744. for (ci = 0; ci < cinfo->num_components; ci++) {
  148745. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148746. }
  148747. cinfo->Ss = 0;
  148748. cinfo->Se = DCTSIZE2-1;
  148749. cinfo->Ah = 0;
  148750. cinfo->Al = 0;
  148751. }
  148752. }
  148753. LOCAL(void)
  148754. per_scan_setup (j_compress_ptr cinfo)
  148755. {
  148756. int ci, mcublks, tmp;
  148757. jpeg_component_info *compptr;
  148758. if (cinfo->comps_in_scan == 1) {
  148759. compptr = cinfo->cur_comp_info[0];
  148760. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148761. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148762. compptr->MCU_width = 1;
  148763. compptr->MCU_height = 1;
  148764. compptr->MCU_blocks = 1;
  148765. compptr->MCU_sample_width = DCTSIZE;
  148766. compptr->last_col_width = 1;
  148767. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148768. if (tmp == 0) tmp = compptr->v_samp_factor;
  148769. compptr->last_row_height = tmp;
  148770. cinfo->blocks_in_MCU = 1;
  148771. cinfo->MCU_membership[0] = 0;
  148772. } else {
  148773. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148774. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148775. MAX_COMPS_IN_SCAN);
  148776. cinfo->MCUs_per_row = (JDIMENSION)
  148777. jdiv_round_up((long) cinfo->image_width,
  148778. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148779. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148780. jdiv_round_up((long) cinfo->image_height,
  148781. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148782. cinfo->blocks_in_MCU = 0;
  148783. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148784. compptr = cinfo->cur_comp_info[ci];
  148785. compptr->MCU_width = compptr->h_samp_factor;
  148786. compptr->MCU_height = compptr->v_samp_factor;
  148787. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148788. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148789. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148790. if (tmp == 0) tmp = compptr->MCU_width;
  148791. compptr->last_col_width = tmp;
  148792. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148793. if (tmp == 0) tmp = compptr->MCU_height;
  148794. compptr->last_row_height = tmp;
  148795. mcublks = compptr->MCU_blocks;
  148796. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148797. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148798. while (mcublks-- > 0) {
  148799. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148800. }
  148801. }
  148802. }
  148803. if (cinfo->restart_in_rows > 0) {
  148804. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148805. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148806. }
  148807. }
  148808. METHODDEF(void)
  148809. prepare_for_pass (j_compress_ptr cinfo)
  148810. {
  148811. my_master_ptr master = (my_master_ptr) cinfo->master;
  148812. switch (master->pass_type) {
  148813. case main_pass:
  148814. select_scan_parameters(cinfo);
  148815. per_scan_setup(cinfo);
  148816. if (! cinfo->raw_data_in) {
  148817. (*cinfo->cconvert->start_pass) (cinfo);
  148818. (*cinfo->downsample->start_pass) (cinfo);
  148819. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148820. }
  148821. (*cinfo->fdct->start_pass) (cinfo);
  148822. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148823. (*cinfo->coef->start_pass) (cinfo,
  148824. (master->total_passes > 1 ?
  148825. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148826. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148827. if (cinfo->optimize_coding) {
  148828. master->pub.call_pass_startup = FALSE;
  148829. } else {
  148830. master->pub.call_pass_startup = TRUE;
  148831. }
  148832. break;
  148833. #ifdef ENTROPY_OPT_SUPPORTED
  148834. case huff_opt_pass:
  148835. select_scan_parameters(cinfo);
  148836. per_scan_setup(cinfo);
  148837. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148838. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148839. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148840. master->pub.call_pass_startup = FALSE;
  148841. break;
  148842. }
  148843. master->pass_type = output_pass;
  148844. master->pass_number++;
  148845. #endif
  148846. case output_pass:
  148847. if (! cinfo->optimize_coding) {
  148848. select_scan_parameters(cinfo);
  148849. per_scan_setup(cinfo);
  148850. }
  148851. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148852. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148853. if (master->scan_number == 0)
  148854. (*cinfo->marker->write_frame_header) (cinfo);
  148855. (*cinfo->marker->write_scan_header) (cinfo);
  148856. master->pub.call_pass_startup = FALSE;
  148857. break;
  148858. default:
  148859. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148860. }
  148861. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148862. if (cinfo->progress != NULL) {
  148863. cinfo->progress->completed_passes = master->pass_number;
  148864. cinfo->progress->total_passes = master->total_passes;
  148865. }
  148866. }
  148867. METHODDEF(void)
  148868. pass_startup (j_compress_ptr cinfo)
  148869. {
  148870. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148871. (*cinfo->marker->write_frame_header) (cinfo);
  148872. (*cinfo->marker->write_scan_header) (cinfo);
  148873. }
  148874. METHODDEF(void)
  148875. finish_pass_master (j_compress_ptr cinfo)
  148876. {
  148877. my_master_ptr master = (my_master_ptr) cinfo->master;
  148878. (*cinfo->entropy->finish_pass) (cinfo);
  148879. switch (master->pass_type) {
  148880. case main_pass:
  148881. master->pass_type = output_pass;
  148882. if (! cinfo->optimize_coding)
  148883. master->scan_number++;
  148884. break;
  148885. case huff_opt_pass:
  148886. master->pass_type = output_pass;
  148887. break;
  148888. case output_pass:
  148889. if (cinfo->optimize_coding)
  148890. master->pass_type = huff_opt_pass;
  148891. master->scan_number++;
  148892. break;
  148893. }
  148894. master->pass_number++;
  148895. }
  148896. GLOBAL(void)
  148897. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148898. {
  148899. my_master_ptr master;
  148900. master = (my_master_ptr)
  148901. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148902. SIZEOF(my_comp_master));
  148903. cinfo->master = (struct jpeg_comp_master *) master;
  148904. master->pub.prepare_for_pass = prepare_for_pass;
  148905. master->pub.pass_startup = pass_startup;
  148906. master->pub.finish_pass = finish_pass_master;
  148907. master->pub.is_last_pass = FALSE;
  148908. initial_setup(cinfo);
  148909. if (cinfo->scan_info != NULL) {
  148910. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148911. validate_script(cinfo);
  148912. #else
  148913. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148914. #endif
  148915. } else {
  148916. cinfo->progressive_mode = FALSE;
  148917. cinfo->num_scans = 1;
  148918. }
  148919. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148920. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148921. if (transcode_only) {
  148922. if (cinfo->optimize_coding)
  148923. master->pass_type = huff_opt_pass;
  148924. else
  148925. master->pass_type = output_pass;
  148926. } else {
  148927. master->pass_type = main_pass;
  148928. }
  148929. master->scan_number = 0;
  148930. master->pass_number = 0;
  148931. if (cinfo->optimize_coding)
  148932. master->total_passes = cinfo->num_scans * 2;
  148933. else
  148934. master->total_passes = cinfo->num_scans;
  148935. }
  148936. /*** End of inlined file: jcmaster.c ***/
  148937. /*** Start of inlined file: jcomapi.c ***/
  148938. #define JPEG_INTERNALS
  148939. GLOBAL(void)
  148940. jpeg_abort (j_common_ptr cinfo)
  148941. {
  148942. int pool;
  148943. if (cinfo->mem == NULL)
  148944. return;
  148945. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148946. (*cinfo->mem->free_pool) (cinfo, pool);
  148947. }
  148948. if (cinfo->is_decompressor) {
  148949. cinfo->global_state = DSTATE_START;
  148950. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148951. } else {
  148952. cinfo->global_state = CSTATE_START;
  148953. }
  148954. }
  148955. GLOBAL(void)
  148956. jpeg_destroy (j_common_ptr cinfo)
  148957. {
  148958. if (cinfo->mem != NULL)
  148959. (*cinfo->mem->self_destruct) (cinfo);
  148960. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148961. cinfo->global_state = 0; /* mark it destroyed */
  148962. }
  148963. GLOBAL(JQUANT_TBL *)
  148964. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148965. {
  148966. JQUANT_TBL *tbl;
  148967. tbl = (JQUANT_TBL *)
  148968. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148969. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148970. return tbl;
  148971. }
  148972. GLOBAL(JHUFF_TBL *)
  148973. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148974. {
  148975. JHUFF_TBL *tbl;
  148976. tbl = (JHUFF_TBL *)
  148977. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148978. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148979. return tbl;
  148980. }
  148981. /*** End of inlined file: jcomapi.c ***/
  148982. /*** Start of inlined file: jcparam.c ***/
  148983. #define JPEG_INTERNALS
  148984. GLOBAL(void)
  148985. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148986. const unsigned int *basic_table,
  148987. int scale_factor, boolean force_baseline)
  148988. {
  148989. JQUANT_TBL ** qtblptr;
  148990. int i;
  148991. long temp;
  148992. if (cinfo->global_state != CSTATE_START)
  148993. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148994. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148995. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148996. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148997. if (*qtblptr == NULL)
  148998. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148999. for (i = 0; i < DCTSIZE2; i++) {
  149000. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  149001. if (temp <= 0L) temp = 1L;
  149002. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  149003. if (force_baseline && temp > 255L)
  149004. temp = 255L; /* limit to baseline range if requested */
  149005. (*qtblptr)->quantval[i] = (UINT16) temp;
  149006. }
  149007. (*qtblptr)->sent_table = FALSE;
  149008. }
  149009. GLOBAL(void)
  149010. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  149011. boolean force_baseline)
  149012. {
  149013. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  149014. 16, 11, 10, 16, 24, 40, 51, 61,
  149015. 12, 12, 14, 19, 26, 58, 60, 55,
  149016. 14, 13, 16, 24, 40, 57, 69, 56,
  149017. 14, 17, 22, 29, 51, 87, 80, 62,
  149018. 18, 22, 37, 56, 68, 109, 103, 77,
  149019. 24, 35, 55, 64, 81, 104, 113, 92,
  149020. 49, 64, 78, 87, 103, 121, 120, 101,
  149021. 72, 92, 95, 98, 112, 100, 103, 99
  149022. };
  149023. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  149024. 17, 18, 24, 47, 99, 99, 99, 99,
  149025. 18, 21, 26, 66, 99, 99, 99, 99,
  149026. 24, 26, 56, 99, 99, 99, 99, 99,
  149027. 47, 66, 99, 99, 99, 99, 99, 99,
  149028. 99, 99, 99, 99, 99, 99, 99, 99,
  149029. 99, 99, 99, 99, 99, 99, 99, 99,
  149030. 99, 99, 99, 99, 99, 99, 99, 99,
  149031. 99, 99, 99, 99, 99, 99, 99, 99
  149032. };
  149033. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  149034. scale_factor, force_baseline);
  149035. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  149036. scale_factor, force_baseline);
  149037. }
  149038. GLOBAL(int)
  149039. jpeg_quality_scaling (int quality)
  149040. {
  149041. if (quality <= 0) quality = 1;
  149042. if (quality > 100) quality = 100;
  149043. if (quality < 50)
  149044. quality = 5000 / quality;
  149045. else
  149046. quality = 200 - quality*2;
  149047. return quality;
  149048. }
  149049. GLOBAL(void)
  149050. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  149051. {
  149052. quality = jpeg_quality_scaling(quality);
  149053. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  149054. }
  149055. LOCAL(void)
  149056. add_huff_table (j_compress_ptr cinfo,
  149057. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  149058. {
  149059. int nsymbols, len;
  149060. if (*htblptr == NULL)
  149061. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149062. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  149063. nsymbols = 0;
  149064. for (len = 1; len <= 16; len++)
  149065. nsymbols += bits[len];
  149066. if (nsymbols < 1 || nsymbols > 256)
  149067. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  149068. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  149069. (*htblptr)->sent_table = FALSE;
  149070. }
  149071. LOCAL(void)
  149072. std_huff_tables (j_compress_ptr cinfo)
  149073. {
  149074. static const UINT8 bits_dc_luminance[17] =
  149075. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  149076. static const UINT8 val_dc_luminance[] =
  149077. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  149078. static const UINT8 bits_dc_chrominance[17] =
  149079. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  149080. static const UINT8 val_dc_chrominance[] =
  149081. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  149082. static const UINT8 bits_ac_luminance[17] =
  149083. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  149084. static const UINT8 val_ac_luminance[] =
  149085. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  149086. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  149087. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  149088. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  149089. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  149090. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  149091. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  149092. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  149093. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  149094. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  149095. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  149096. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  149097. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  149098. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  149099. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  149100. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  149101. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  149102. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  149103. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  149104. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  149105. 0xf9, 0xfa };
  149106. static const UINT8 bits_ac_chrominance[17] =
  149107. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  149108. static const UINT8 val_ac_chrominance[] =
  149109. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  149110. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  149111. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  149112. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  149113. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  149114. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  149115. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  149116. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  149117. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  149118. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  149119. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  149120. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  149121. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  149122. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  149123. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  149124. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  149125. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  149126. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  149127. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  149128. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  149129. 0xf9, 0xfa };
  149130. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  149131. bits_dc_luminance, val_dc_luminance);
  149132. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  149133. bits_ac_luminance, val_ac_luminance);
  149134. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  149135. bits_dc_chrominance, val_dc_chrominance);
  149136. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  149137. bits_ac_chrominance, val_ac_chrominance);
  149138. }
  149139. GLOBAL(void)
  149140. jpeg_set_defaults (j_compress_ptr cinfo)
  149141. {
  149142. int i;
  149143. if (cinfo->global_state != CSTATE_START)
  149144. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149145. if (cinfo->comp_info == NULL)
  149146. cinfo->comp_info = (jpeg_component_info *)
  149147. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149148. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  149149. cinfo->data_precision = BITS_IN_JSAMPLE;
  149150. jpeg_set_quality(cinfo, 75, TRUE);
  149151. std_huff_tables(cinfo);
  149152. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  149153. cinfo->arith_dc_L[i] = 0;
  149154. cinfo->arith_dc_U[i] = 1;
  149155. cinfo->arith_ac_K[i] = 5;
  149156. }
  149157. cinfo->scan_info = NULL;
  149158. cinfo->num_scans = 0;
  149159. cinfo->raw_data_in = FALSE;
  149160. cinfo->arith_code = FALSE;
  149161. cinfo->optimize_coding = FALSE;
  149162. if (cinfo->data_precision > 8)
  149163. cinfo->optimize_coding = TRUE;
  149164. cinfo->CCIR601_sampling = FALSE;
  149165. cinfo->smoothing_factor = 0;
  149166. cinfo->dct_method = JDCT_DEFAULT;
  149167. cinfo->restart_interval = 0;
  149168. cinfo->restart_in_rows = 0;
  149169. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  149170. cinfo->JFIF_minor_version = 1;
  149171. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  149172. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  149173. cinfo->Y_density = 1;
  149174. jpeg_default_colorspace(cinfo);
  149175. }
  149176. GLOBAL(void)
  149177. jpeg_default_colorspace (j_compress_ptr cinfo)
  149178. {
  149179. switch (cinfo->in_color_space) {
  149180. case JCS_GRAYSCALE:
  149181. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  149182. break;
  149183. case JCS_RGB:
  149184. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149185. break;
  149186. case JCS_YCbCr:
  149187. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149188. break;
  149189. case JCS_CMYK:
  149190. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  149191. break;
  149192. case JCS_YCCK:
  149193. jpeg_set_colorspace(cinfo, JCS_YCCK);
  149194. break;
  149195. case JCS_UNKNOWN:
  149196. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  149197. break;
  149198. default:
  149199. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  149200. }
  149201. }
  149202. GLOBAL(void)
  149203. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  149204. {
  149205. jpeg_component_info * compptr;
  149206. int ci;
  149207. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  149208. (compptr = &cinfo->comp_info[index], \
  149209. compptr->component_id = (id), \
  149210. compptr->h_samp_factor = (hsamp), \
  149211. compptr->v_samp_factor = (vsamp), \
  149212. compptr->quant_tbl_no = (quant), \
  149213. compptr->dc_tbl_no = (dctbl), \
  149214. compptr->ac_tbl_no = (actbl) )
  149215. if (cinfo->global_state != CSTATE_START)
  149216. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149217. cinfo->jpeg_color_space = colorspace;
  149218. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  149219. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  149220. switch (colorspace) {
  149221. case JCS_GRAYSCALE:
  149222. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149223. cinfo->num_components = 1;
  149224. SET_COMP(0, 1, 1,1, 0, 0,0);
  149225. break;
  149226. case JCS_RGB:
  149227. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  149228. cinfo->num_components = 3;
  149229. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  149230. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  149231. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  149232. break;
  149233. case JCS_YCbCr:
  149234. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149235. cinfo->num_components = 3;
  149236. SET_COMP(0, 1, 2,2, 0, 0,0);
  149237. SET_COMP(1, 2, 1,1, 1, 1,1);
  149238. SET_COMP(2, 3, 1,1, 1, 1,1);
  149239. break;
  149240. case JCS_CMYK:
  149241. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  149242. cinfo->num_components = 4;
  149243. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  149244. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  149245. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  149246. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  149247. break;
  149248. case JCS_YCCK:
  149249. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  149250. cinfo->num_components = 4;
  149251. SET_COMP(0, 1, 2,2, 0, 0,0);
  149252. SET_COMP(1, 2, 1,1, 1, 1,1);
  149253. SET_COMP(2, 3, 1,1, 1, 1,1);
  149254. SET_COMP(3, 4, 2,2, 0, 0,0);
  149255. break;
  149256. case JCS_UNKNOWN:
  149257. cinfo->num_components = cinfo->input_components;
  149258. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  149259. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  149260. MAX_COMPONENTS);
  149261. for (ci = 0; ci < cinfo->num_components; ci++) {
  149262. SET_COMP(ci, ci, 1,1, 0, 0,0);
  149263. }
  149264. break;
  149265. default:
  149266. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  149267. }
  149268. }
  149269. #ifdef C_PROGRESSIVE_SUPPORTED
  149270. LOCAL(jpeg_scan_info *)
  149271. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  149272. int Ss, int Se, int Ah, int Al)
  149273. {
  149274. scanptr->comps_in_scan = 1;
  149275. scanptr->component_index[0] = ci;
  149276. scanptr->Ss = Ss;
  149277. scanptr->Se = Se;
  149278. scanptr->Ah = Ah;
  149279. scanptr->Al = Al;
  149280. scanptr++;
  149281. return scanptr;
  149282. }
  149283. LOCAL(jpeg_scan_info *)
  149284. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  149285. int Ss, int Se, int Ah, int Al)
  149286. {
  149287. int ci;
  149288. for (ci = 0; ci < ncomps; ci++) {
  149289. scanptr->comps_in_scan = 1;
  149290. scanptr->component_index[0] = ci;
  149291. scanptr->Ss = Ss;
  149292. scanptr->Se = Se;
  149293. scanptr->Ah = Ah;
  149294. scanptr->Al = Al;
  149295. scanptr++;
  149296. }
  149297. return scanptr;
  149298. }
  149299. LOCAL(jpeg_scan_info *)
  149300. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  149301. {
  149302. int ci;
  149303. if (ncomps <= MAX_COMPS_IN_SCAN) {
  149304. scanptr->comps_in_scan = ncomps;
  149305. for (ci = 0; ci < ncomps; ci++)
  149306. scanptr->component_index[ci] = ci;
  149307. scanptr->Ss = scanptr->Se = 0;
  149308. scanptr->Ah = Ah;
  149309. scanptr->Al = Al;
  149310. scanptr++;
  149311. } else {
  149312. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  149313. }
  149314. return scanptr;
  149315. }
  149316. GLOBAL(void)
  149317. jpeg_simple_progression (j_compress_ptr cinfo)
  149318. {
  149319. int ncomps = cinfo->num_components;
  149320. int nscans;
  149321. jpeg_scan_info * scanptr;
  149322. if (cinfo->global_state != CSTATE_START)
  149323. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149324. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149325. nscans = 10;
  149326. } else {
  149327. if (ncomps > MAX_COMPS_IN_SCAN)
  149328. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  149329. else
  149330. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  149331. }
  149332. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  149333. cinfo->script_space_size = MAX(nscans, 10);
  149334. cinfo->script_space = (jpeg_scan_info *)
  149335. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149336. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  149337. }
  149338. scanptr = cinfo->script_space;
  149339. cinfo->scan_info = scanptr;
  149340. cinfo->num_scans = nscans;
  149341. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149342. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149343. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  149344. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  149345. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  149346. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  149347. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  149348. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149349. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  149350. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  149351. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  149352. } else {
  149353. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149354. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  149355. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  149356. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  149357. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149358. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  149359. }
  149360. }
  149361. #endif /* C_PROGRESSIVE_SUPPORTED */
  149362. /*** End of inlined file: jcparam.c ***/
  149363. /*** Start of inlined file: jcphuff.c ***/
  149364. #define JPEG_INTERNALS
  149365. #ifdef C_PROGRESSIVE_SUPPORTED
  149366. typedef struct {
  149367. struct jpeg_entropy_encoder pub; /* public fields */
  149368. boolean gather_statistics;
  149369. JOCTET * next_output_byte; /* => next byte to write in buffer */
  149370. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  149371. INT32 put_buffer; /* current bit-accumulation buffer */
  149372. int put_bits; /* # of bits now in it */
  149373. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  149374. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  149375. int ac_tbl_no; /* the table number of the single component */
  149376. unsigned int EOBRUN; /* run length of EOBs */
  149377. unsigned int BE; /* # of buffered correction bits before MCU */
  149378. char * bit_buffer; /* buffer for correction bits (1 per char) */
  149379. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  149380. int next_restart_num; /* next restart number to write (0-7) */
  149381. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  149382. long * count_ptrs[NUM_HUFF_TBLS];
  149383. } phuff_entropy_encoder;
  149384. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  149385. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  149386. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  149387. #define ISHIFT_TEMPS int ishift_temp;
  149388. #define IRIGHT_SHIFT(x,shft) \
  149389. ((ishift_temp = (x)) < 0 ? \
  149390. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  149391. (ishift_temp >> (shft)))
  149392. #else
  149393. #define ISHIFT_TEMPS
  149394. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  149395. #endif
  149396. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  149397. JBLOCKROW *MCU_data));
  149398. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  149399. JBLOCKROW *MCU_data));
  149400. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  149401. JBLOCKROW *MCU_data));
  149402. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  149403. JBLOCKROW *MCU_data));
  149404. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  149405. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  149406. METHODDEF(void)
  149407. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  149408. {
  149409. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149410. boolean is_DC_band;
  149411. int ci, tbl;
  149412. jpeg_component_info * compptr;
  149413. entropy->cinfo = cinfo;
  149414. entropy->gather_statistics = gather_statistics;
  149415. is_DC_band = (cinfo->Ss == 0);
  149416. if (cinfo->Ah == 0) {
  149417. if (is_DC_band)
  149418. entropy->pub.encode_mcu = encode_mcu_DC_first;
  149419. else
  149420. entropy->pub.encode_mcu = encode_mcu_AC_first;
  149421. } else {
  149422. if (is_DC_band)
  149423. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  149424. else {
  149425. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  149426. if (entropy->bit_buffer == NULL)
  149427. entropy->bit_buffer = (char *)
  149428. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149429. MAX_CORR_BITS * SIZEOF(char));
  149430. }
  149431. }
  149432. if (gather_statistics)
  149433. entropy->pub.finish_pass = finish_pass_gather_phuff;
  149434. else
  149435. entropy->pub.finish_pass = finish_pass_phuff;
  149436. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149437. compptr = cinfo->cur_comp_info[ci];
  149438. entropy->last_dc_val[ci] = 0;
  149439. if (is_DC_band) {
  149440. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149441. continue;
  149442. tbl = compptr->dc_tbl_no;
  149443. } else {
  149444. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  149445. }
  149446. if (gather_statistics) {
  149447. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  149448. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  149449. if (entropy->count_ptrs[tbl] == NULL)
  149450. entropy->count_ptrs[tbl] = (long *)
  149451. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149452. 257 * SIZEOF(long));
  149453. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  149454. } else {
  149455. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  149456. & entropy->derived_tbls[tbl]);
  149457. }
  149458. }
  149459. entropy->EOBRUN = 0;
  149460. entropy->BE = 0;
  149461. entropy->put_buffer = 0;
  149462. entropy->put_bits = 0;
  149463. entropy->restarts_to_go = cinfo->restart_interval;
  149464. entropy->next_restart_num = 0;
  149465. }
  149466. #define emit_byte(entropy,val) \
  149467. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  149468. if (--(entropy)->free_in_buffer == 0) \
  149469. dump_buffer_p(entropy); }
  149470. LOCAL(void)
  149471. dump_buffer_p (phuff_entropy_ptr entropy)
  149472. {
  149473. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  149474. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  149475. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  149476. entropy->next_output_byte = dest->next_output_byte;
  149477. entropy->free_in_buffer = dest->free_in_buffer;
  149478. }
  149479. INLINE
  149480. LOCAL(void)
  149481. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  149482. {
  149483. register INT32 put_buffer = (INT32) code;
  149484. register int put_bits = entropy->put_bits;
  149485. if (size == 0)
  149486. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149487. if (entropy->gather_statistics)
  149488. return; /* do nothing if we're only getting stats */
  149489. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  149490. put_bits += size; /* new number of bits in buffer */
  149491. put_buffer <<= 24 - put_bits; /* align incoming bits */
  149492. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  149493. while (put_bits >= 8) {
  149494. int c = (int) ((put_buffer >> 16) & 0xFF);
  149495. emit_byte(entropy, c);
  149496. if (c == 0xFF) { /* need to stuff a zero byte? */
  149497. emit_byte(entropy, 0);
  149498. }
  149499. put_buffer <<= 8;
  149500. put_bits -= 8;
  149501. }
  149502. entropy->put_buffer = put_buffer; /* update variables */
  149503. entropy->put_bits = put_bits;
  149504. }
  149505. LOCAL(void)
  149506. flush_bits_p (phuff_entropy_ptr entropy)
  149507. {
  149508. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  149509. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  149510. entropy->put_bits = 0;
  149511. }
  149512. INLINE
  149513. LOCAL(void)
  149514. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  149515. {
  149516. if (entropy->gather_statistics)
  149517. entropy->count_ptrs[tbl_no][symbol]++;
  149518. else {
  149519. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  149520. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  149521. }
  149522. }
  149523. LOCAL(void)
  149524. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149525. unsigned int nbits)
  149526. {
  149527. if (entropy->gather_statistics)
  149528. return; /* no real work */
  149529. while (nbits > 0) {
  149530. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149531. bufstart++;
  149532. nbits--;
  149533. }
  149534. }
  149535. LOCAL(void)
  149536. emit_eobrun (phuff_entropy_ptr entropy)
  149537. {
  149538. register int temp, nbits;
  149539. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149540. temp = entropy->EOBRUN;
  149541. nbits = 0;
  149542. while ((temp >>= 1))
  149543. nbits++;
  149544. if (nbits > 14)
  149545. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149546. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149547. if (nbits)
  149548. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149549. entropy->EOBRUN = 0;
  149550. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149551. entropy->BE = 0;
  149552. }
  149553. }
  149554. LOCAL(void)
  149555. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149556. {
  149557. int ci;
  149558. emit_eobrun(entropy);
  149559. if (! entropy->gather_statistics) {
  149560. flush_bits_p(entropy);
  149561. emit_byte(entropy, 0xFF);
  149562. emit_byte(entropy, JPEG_RST0 + restart_num);
  149563. }
  149564. if (entropy->cinfo->Ss == 0) {
  149565. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149566. entropy->last_dc_val[ci] = 0;
  149567. } else {
  149568. entropy->EOBRUN = 0;
  149569. entropy->BE = 0;
  149570. }
  149571. }
  149572. METHODDEF(boolean)
  149573. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149574. {
  149575. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149576. register int temp, temp2;
  149577. register int nbits;
  149578. int blkn, ci;
  149579. int Al = cinfo->Al;
  149580. JBLOCKROW block;
  149581. jpeg_component_info * compptr;
  149582. ISHIFT_TEMPS
  149583. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149584. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149585. if (cinfo->restart_interval)
  149586. if (entropy->restarts_to_go == 0)
  149587. emit_restart_p(entropy, entropy->next_restart_num);
  149588. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149589. block = MCU_data[blkn];
  149590. ci = cinfo->MCU_membership[blkn];
  149591. compptr = cinfo->cur_comp_info[ci];
  149592. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149593. temp = temp2 - entropy->last_dc_val[ci];
  149594. entropy->last_dc_val[ci] = temp2;
  149595. temp2 = temp;
  149596. if (temp < 0) {
  149597. temp = -temp; /* temp is abs value of input */
  149598. temp2--;
  149599. }
  149600. nbits = 0;
  149601. while (temp) {
  149602. nbits++;
  149603. temp >>= 1;
  149604. }
  149605. if (nbits > MAX_COEF_BITS+1)
  149606. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149607. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149608. if (nbits) /* emit_bits rejects calls with size 0 */
  149609. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149610. }
  149611. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149612. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149613. if (cinfo->restart_interval) {
  149614. if (entropy->restarts_to_go == 0) {
  149615. entropy->restarts_to_go = cinfo->restart_interval;
  149616. entropy->next_restart_num++;
  149617. entropy->next_restart_num &= 7;
  149618. }
  149619. entropy->restarts_to_go--;
  149620. }
  149621. return TRUE;
  149622. }
  149623. METHODDEF(boolean)
  149624. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149625. {
  149626. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149627. register int temp, temp2;
  149628. register int nbits;
  149629. register int r, k;
  149630. int Se = cinfo->Se;
  149631. int Al = cinfo->Al;
  149632. JBLOCKROW block;
  149633. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149634. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149635. if (cinfo->restart_interval)
  149636. if (entropy->restarts_to_go == 0)
  149637. emit_restart_p(entropy, entropy->next_restart_num);
  149638. block = MCU_data[0];
  149639. r = 0; /* r = run length of zeros */
  149640. for (k = cinfo->Ss; k <= Se; k++) {
  149641. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149642. r++;
  149643. continue;
  149644. }
  149645. if (temp < 0) {
  149646. temp = -temp; /* temp is abs value of input */
  149647. temp >>= Al; /* apply the point transform */
  149648. temp2 = ~temp;
  149649. } else {
  149650. temp >>= Al; /* apply the point transform */
  149651. temp2 = temp;
  149652. }
  149653. if (temp == 0) {
  149654. r++;
  149655. continue;
  149656. }
  149657. if (entropy->EOBRUN > 0)
  149658. emit_eobrun(entropy);
  149659. while (r > 15) {
  149660. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149661. r -= 16;
  149662. }
  149663. nbits = 1; /* there must be at least one 1 bit */
  149664. while ((temp >>= 1))
  149665. nbits++;
  149666. if (nbits > MAX_COEF_BITS)
  149667. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149668. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149669. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149670. r = 0; /* reset zero run length */
  149671. }
  149672. if (r > 0) { /* If there are trailing zeroes, */
  149673. entropy->EOBRUN++; /* count an EOB */
  149674. if (entropy->EOBRUN == 0x7FFF)
  149675. emit_eobrun(entropy); /* force it out to avoid overflow */
  149676. }
  149677. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149678. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149679. if (cinfo->restart_interval) {
  149680. if (entropy->restarts_to_go == 0) {
  149681. entropy->restarts_to_go = cinfo->restart_interval;
  149682. entropy->next_restart_num++;
  149683. entropy->next_restart_num &= 7;
  149684. }
  149685. entropy->restarts_to_go--;
  149686. }
  149687. return TRUE;
  149688. }
  149689. METHODDEF(boolean)
  149690. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149691. {
  149692. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149693. register int temp;
  149694. int blkn;
  149695. int Al = cinfo->Al;
  149696. JBLOCKROW block;
  149697. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149698. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149699. if (cinfo->restart_interval)
  149700. if (entropy->restarts_to_go == 0)
  149701. emit_restart_p(entropy, entropy->next_restart_num);
  149702. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149703. block = MCU_data[blkn];
  149704. temp = (*block)[0];
  149705. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149706. }
  149707. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149708. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149709. if (cinfo->restart_interval) {
  149710. if (entropy->restarts_to_go == 0) {
  149711. entropy->restarts_to_go = cinfo->restart_interval;
  149712. entropy->next_restart_num++;
  149713. entropy->next_restart_num &= 7;
  149714. }
  149715. entropy->restarts_to_go--;
  149716. }
  149717. return TRUE;
  149718. }
  149719. METHODDEF(boolean)
  149720. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149721. {
  149722. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149723. register int temp;
  149724. register int r, k;
  149725. int EOB;
  149726. char *BR_buffer;
  149727. unsigned int BR;
  149728. int Se = cinfo->Se;
  149729. int Al = cinfo->Al;
  149730. JBLOCKROW block;
  149731. int absvalues[DCTSIZE2];
  149732. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149733. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149734. if (cinfo->restart_interval)
  149735. if (entropy->restarts_to_go == 0)
  149736. emit_restart_p(entropy, entropy->next_restart_num);
  149737. block = MCU_data[0];
  149738. EOB = 0;
  149739. for (k = cinfo->Ss; k <= Se; k++) {
  149740. temp = (*block)[jpeg_natural_order[k]];
  149741. if (temp < 0)
  149742. temp = -temp; /* temp is abs value of input */
  149743. temp >>= Al; /* apply the point transform */
  149744. absvalues[k] = temp; /* save abs value for main pass */
  149745. if (temp == 1)
  149746. EOB = k; /* EOB = index of last newly-nonzero coef */
  149747. }
  149748. r = 0; /* r = run length of zeros */
  149749. BR = 0; /* BR = count of buffered bits added now */
  149750. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149751. for (k = cinfo->Ss; k <= Se; k++) {
  149752. if ((temp = absvalues[k]) == 0) {
  149753. r++;
  149754. continue;
  149755. }
  149756. while (r > 15 && k <= EOB) {
  149757. emit_eobrun(entropy);
  149758. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149759. r -= 16;
  149760. emit_buffered_bits(entropy, BR_buffer, BR);
  149761. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149762. BR = 0;
  149763. }
  149764. if (temp > 1) {
  149765. BR_buffer[BR++] = (char) (temp & 1);
  149766. continue;
  149767. }
  149768. emit_eobrun(entropy);
  149769. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149770. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149771. emit_bits_p(entropy, (unsigned int) temp, 1);
  149772. emit_buffered_bits(entropy, BR_buffer, BR);
  149773. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149774. BR = 0;
  149775. r = 0; /* reset zero run length */
  149776. }
  149777. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149778. entropy->EOBRUN++; /* count an EOB */
  149779. entropy->BE += BR; /* concat my correction bits to older ones */
  149780. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149781. emit_eobrun(entropy);
  149782. }
  149783. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149784. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149785. if (cinfo->restart_interval) {
  149786. if (entropy->restarts_to_go == 0) {
  149787. entropy->restarts_to_go = cinfo->restart_interval;
  149788. entropy->next_restart_num++;
  149789. entropy->next_restart_num &= 7;
  149790. }
  149791. entropy->restarts_to_go--;
  149792. }
  149793. return TRUE;
  149794. }
  149795. METHODDEF(void)
  149796. finish_pass_phuff (j_compress_ptr cinfo)
  149797. {
  149798. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149799. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149800. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149801. emit_eobrun(entropy);
  149802. flush_bits_p(entropy);
  149803. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149804. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149805. }
  149806. METHODDEF(void)
  149807. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149808. {
  149809. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149810. boolean is_DC_band;
  149811. int ci, tbl;
  149812. jpeg_component_info * compptr;
  149813. JHUFF_TBL **htblptr;
  149814. boolean did[NUM_HUFF_TBLS];
  149815. emit_eobrun(entropy);
  149816. is_DC_band = (cinfo->Ss == 0);
  149817. MEMZERO(did, SIZEOF(did));
  149818. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149819. compptr = cinfo->cur_comp_info[ci];
  149820. if (is_DC_band) {
  149821. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149822. continue;
  149823. tbl = compptr->dc_tbl_no;
  149824. } else {
  149825. tbl = compptr->ac_tbl_no;
  149826. }
  149827. if (! did[tbl]) {
  149828. if (is_DC_band)
  149829. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149830. else
  149831. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149832. if (*htblptr == NULL)
  149833. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149834. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149835. did[tbl] = TRUE;
  149836. }
  149837. }
  149838. }
  149839. GLOBAL(void)
  149840. jinit_phuff_encoder (j_compress_ptr cinfo)
  149841. {
  149842. phuff_entropy_ptr entropy;
  149843. int i;
  149844. entropy = (phuff_entropy_ptr)
  149845. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149846. SIZEOF(phuff_entropy_encoder));
  149847. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149848. entropy->pub.start_pass = start_pass_phuff;
  149849. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149850. entropy->derived_tbls[i] = NULL;
  149851. entropy->count_ptrs[i] = NULL;
  149852. }
  149853. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149854. }
  149855. #endif /* C_PROGRESSIVE_SUPPORTED */
  149856. /*** End of inlined file: jcphuff.c ***/
  149857. /*** Start of inlined file: jcprepct.c ***/
  149858. #define JPEG_INTERNALS
  149859. #ifdef INPUT_SMOOTHING_SUPPORTED
  149860. #define CONTEXT_ROWS_SUPPORTED
  149861. #endif
  149862. typedef struct {
  149863. struct jpeg_c_prep_controller pub; /* public fields */
  149864. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149865. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149866. int next_buf_row; /* index of next row to store in color_buf */
  149867. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149868. int this_row_group; /* starting row index of group to process */
  149869. int next_buf_stop; /* downsample when we reach this index */
  149870. #endif
  149871. } my_prep_controller;
  149872. typedef my_prep_controller * my_prep_ptr;
  149873. METHODDEF(void)
  149874. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149875. {
  149876. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149877. if (pass_mode != JBUF_PASS_THRU)
  149878. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149879. prep->rows_to_go = cinfo->image_height;
  149880. prep->next_buf_row = 0;
  149881. #ifdef CONTEXT_ROWS_SUPPORTED
  149882. prep->this_row_group = 0;
  149883. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149884. #endif
  149885. }
  149886. LOCAL(void)
  149887. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149888. int input_rows, int output_rows)
  149889. {
  149890. register int row;
  149891. for (row = input_rows; row < output_rows; row++) {
  149892. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149893. 1, num_cols);
  149894. }
  149895. }
  149896. METHODDEF(void)
  149897. pre_process_data (j_compress_ptr cinfo,
  149898. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149899. JDIMENSION in_rows_avail,
  149900. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149901. JDIMENSION out_row_groups_avail)
  149902. {
  149903. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149904. int numrows, ci;
  149905. JDIMENSION inrows;
  149906. jpeg_component_info * compptr;
  149907. while (*in_row_ctr < in_rows_avail &&
  149908. *out_row_group_ctr < out_row_groups_avail) {
  149909. inrows = in_rows_avail - *in_row_ctr;
  149910. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149911. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149912. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149913. prep->color_buf,
  149914. (JDIMENSION) prep->next_buf_row,
  149915. numrows);
  149916. *in_row_ctr += numrows;
  149917. prep->next_buf_row += numrows;
  149918. prep->rows_to_go -= numrows;
  149919. if (prep->rows_to_go == 0 &&
  149920. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149921. for (ci = 0; ci < cinfo->num_components; ci++) {
  149922. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149923. prep->next_buf_row, cinfo->max_v_samp_factor);
  149924. }
  149925. prep->next_buf_row = cinfo->max_v_samp_factor;
  149926. }
  149927. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149928. (*cinfo->downsample->downsample) (cinfo,
  149929. prep->color_buf, (JDIMENSION) 0,
  149930. output_buf, *out_row_group_ctr);
  149931. prep->next_buf_row = 0;
  149932. (*out_row_group_ctr)++;
  149933. }
  149934. if (prep->rows_to_go == 0 &&
  149935. *out_row_group_ctr < out_row_groups_avail) {
  149936. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149937. ci++, compptr++) {
  149938. expand_bottom_edge(output_buf[ci],
  149939. compptr->width_in_blocks * DCTSIZE,
  149940. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149941. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149942. }
  149943. *out_row_group_ctr = out_row_groups_avail;
  149944. break; /* can exit outer loop without test */
  149945. }
  149946. }
  149947. }
  149948. #ifdef CONTEXT_ROWS_SUPPORTED
  149949. METHODDEF(void)
  149950. pre_process_context (j_compress_ptr cinfo,
  149951. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149952. JDIMENSION in_rows_avail,
  149953. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149954. JDIMENSION out_row_groups_avail)
  149955. {
  149956. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149957. int numrows, ci;
  149958. int buf_height = cinfo->max_v_samp_factor * 3;
  149959. JDIMENSION inrows;
  149960. while (*out_row_group_ctr < out_row_groups_avail) {
  149961. if (*in_row_ctr < in_rows_avail) {
  149962. inrows = in_rows_avail - *in_row_ctr;
  149963. numrows = prep->next_buf_stop - prep->next_buf_row;
  149964. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149965. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149966. prep->color_buf,
  149967. (JDIMENSION) prep->next_buf_row,
  149968. numrows);
  149969. if (prep->rows_to_go == cinfo->image_height) {
  149970. for (ci = 0; ci < cinfo->num_components; ci++) {
  149971. int row;
  149972. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149973. jcopy_sample_rows(prep->color_buf[ci], 0,
  149974. prep->color_buf[ci], -row,
  149975. 1, cinfo->image_width);
  149976. }
  149977. }
  149978. }
  149979. *in_row_ctr += numrows;
  149980. prep->next_buf_row += numrows;
  149981. prep->rows_to_go -= numrows;
  149982. } else {
  149983. if (prep->rows_to_go != 0)
  149984. break;
  149985. if (prep->next_buf_row < prep->next_buf_stop) {
  149986. for (ci = 0; ci < cinfo->num_components; ci++) {
  149987. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149988. prep->next_buf_row, prep->next_buf_stop);
  149989. }
  149990. prep->next_buf_row = prep->next_buf_stop;
  149991. }
  149992. }
  149993. if (prep->next_buf_row == prep->next_buf_stop) {
  149994. (*cinfo->downsample->downsample) (cinfo,
  149995. prep->color_buf,
  149996. (JDIMENSION) prep->this_row_group,
  149997. output_buf, *out_row_group_ctr);
  149998. (*out_row_group_ctr)++;
  149999. prep->this_row_group += cinfo->max_v_samp_factor;
  150000. if (prep->this_row_group >= buf_height)
  150001. prep->this_row_group = 0;
  150002. if (prep->next_buf_row >= buf_height)
  150003. prep->next_buf_row = 0;
  150004. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  150005. }
  150006. }
  150007. }
  150008. LOCAL(void)
  150009. create_context_buffer (j_compress_ptr cinfo)
  150010. {
  150011. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  150012. int rgroup_height = cinfo->max_v_samp_factor;
  150013. int ci, i;
  150014. jpeg_component_info * compptr;
  150015. JSAMPARRAY true_buffer, fake_buffer;
  150016. fake_buffer = (JSAMPARRAY)
  150017. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150018. (cinfo->num_components * 5 * rgroup_height) *
  150019. SIZEOF(JSAMPROW));
  150020. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150021. ci++, compptr++) {
  150022. true_buffer = (*cinfo->mem->alloc_sarray)
  150023. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150024. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  150025. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  150026. (JDIMENSION) (3 * rgroup_height));
  150027. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  150028. 3 * rgroup_height * SIZEOF(JSAMPROW));
  150029. for (i = 0; i < rgroup_height; i++) {
  150030. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  150031. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  150032. }
  150033. prep->color_buf[ci] = fake_buffer + rgroup_height;
  150034. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  150035. }
  150036. }
  150037. #endif /* CONTEXT_ROWS_SUPPORTED */
  150038. GLOBAL(void)
  150039. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  150040. {
  150041. my_prep_ptr prep;
  150042. int ci;
  150043. jpeg_component_info * compptr;
  150044. if (need_full_buffer) /* safety check */
  150045. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150046. prep = (my_prep_ptr)
  150047. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150048. SIZEOF(my_prep_controller));
  150049. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  150050. prep->pub.start_pass = start_pass_prep;
  150051. if (cinfo->downsample->need_context_rows) {
  150052. #ifdef CONTEXT_ROWS_SUPPORTED
  150053. prep->pub.pre_process_data = pre_process_context;
  150054. create_context_buffer(cinfo);
  150055. #else
  150056. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150057. #endif
  150058. } else {
  150059. prep->pub.pre_process_data = pre_process_data;
  150060. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150061. ci++, compptr++) {
  150062. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  150063. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150064. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  150065. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  150066. (JDIMENSION) cinfo->max_v_samp_factor);
  150067. }
  150068. }
  150069. }
  150070. /*** End of inlined file: jcprepct.c ***/
  150071. /*** Start of inlined file: jcsample.c ***/
  150072. #define JPEG_INTERNALS
  150073. typedef JMETHOD(void, downsample1_ptr,
  150074. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150075. JSAMPARRAY input_data, JSAMPARRAY output_data));
  150076. typedef struct {
  150077. struct jpeg_downsampler pub; /* public fields */
  150078. downsample1_ptr methods[MAX_COMPONENTS];
  150079. } my_downsampler;
  150080. typedef my_downsampler * my_downsample_ptr;
  150081. METHODDEF(void)
  150082. start_pass_downsample (j_compress_ptr cinfo)
  150083. {
  150084. }
  150085. LOCAL(void)
  150086. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  150087. JDIMENSION input_cols, JDIMENSION output_cols)
  150088. {
  150089. register JSAMPROW ptr;
  150090. register JSAMPLE pixval;
  150091. register int count;
  150092. int row;
  150093. int numcols = (int) (output_cols - input_cols);
  150094. if (numcols > 0) {
  150095. for (row = 0; row < num_rows; row++) {
  150096. ptr = image_data[row] + input_cols;
  150097. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  150098. for (count = numcols; count > 0; count--)
  150099. *ptr++ = pixval;
  150100. }
  150101. }
  150102. }
  150103. METHODDEF(void)
  150104. sep_downsample (j_compress_ptr cinfo,
  150105. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  150106. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  150107. {
  150108. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  150109. int ci;
  150110. jpeg_component_info * compptr;
  150111. JSAMPARRAY in_ptr, out_ptr;
  150112. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150113. ci++, compptr++) {
  150114. in_ptr = input_buf[ci] + in_row_index;
  150115. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  150116. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  150117. }
  150118. }
  150119. METHODDEF(void)
  150120. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150121. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150122. {
  150123. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  150124. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  150125. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150126. JSAMPROW inptr, outptr;
  150127. INT32 outvalue;
  150128. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  150129. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  150130. numpix = h_expand * v_expand;
  150131. numpix2 = numpix/2;
  150132. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150133. cinfo->image_width, output_cols * h_expand);
  150134. inrow = 0;
  150135. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150136. outptr = output_data[outrow];
  150137. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  150138. outcol++, outcol_h += h_expand) {
  150139. outvalue = 0;
  150140. for (v = 0; v < v_expand; v++) {
  150141. inptr = input_data[inrow+v] + outcol_h;
  150142. for (h = 0; h < h_expand; h++) {
  150143. outvalue += (INT32) GETJSAMPLE(*inptr++);
  150144. }
  150145. }
  150146. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  150147. }
  150148. inrow += v_expand;
  150149. }
  150150. }
  150151. METHODDEF(void)
  150152. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150153. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150154. {
  150155. jcopy_sample_rows(input_data, 0, output_data, 0,
  150156. cinfo->max_v_samp_factor, cinfo->image_width);
  150157. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  150158. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  150159. }
  150160. METHODDEF(void)
  150161. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150162. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150163. {
  150164. int outrow;
  150165. JDIMENSION outcol;
  150166. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150167. register JSAMPROW inptr, outptr;
  150168. register int bias;
  150169. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150170. cinfo->image_width, output_cols * 2);
  150171. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150172. outptr = output_data[outrow];
  150173. inptr = input_data[outrow];
  150174. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  150175. for (outcol = 0; outcol < output_cols; outcol++) {
  150176. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  150177. + bias) >> 1);
  150178. bias ^= 1; /* 0=>1, 1=>0 */
  150179. inptr += 2;
  150180. }
  150181. }
  150182. }
  150183. METHODDEF(void)
  150184. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150185. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150186. {
  150187. int inrow, outrow;
  150188. JDIMENSION outcol;
  150189. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150190. register JSAMPROW inptr0, inptr1, outptr;
  150191. register int bias;
  150192. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150193. cinfo->image_width, output_cols * 2);
  150194. inrow = 0;
  150195. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150196. outptr = output_data[outrow];
  150197. inptr0 = input_data[inrow];
  150198. inptr1 = input_data[inrow+1];
  150199. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  150200. for (outcol = 0; outcol < output_cols; outcol++) {
  150201. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150202. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  150203. + bias) >> 2);
  150204. bias ^= 3; /* 1=>2, 2=>1 */
  150205. inptr0 += 2; inptr1 += 2;
  150206. }
  150207. inrow += 2;
  150208. }
  150209. }
  150210. #ifdef INPUT_SMOOTHING_SUPPORTED
  150211. METHODDEF(void)
  150212. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150213. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150214. {
  150215. int inrow, outrow;
  150216. JDIMENSION colctr;
  150217. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150218. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  150219. INT32 membersum, neighsum, memberscale, neighscale;
  150220. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150221. cinfo->image_width, output_cols * 2);
  150222. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  150223. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  150224. inrow = 0;
  150225. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150226. outptr = output_data[outrow];
  150227. inptr0 = input_data[inrow];
  150228. inptr1 = input_data[inrow+1];
  150229. above_ptr = input_data[inrow-1];
  150230. below_ptr = input_data[inrow+2];
  150231. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150232. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150233. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150234. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150235. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  150236. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  150237. neighsum += neighsum;
  150238. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  150239. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  150240. membersum = membersum * memberscale + neighsum * neighscale;
  150241. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150242. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150243. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150244. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150245. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150246. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150247. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150248. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  150249. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  150250. neighsum += neighsum;
  150251. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  150252. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  150253. membersum = membersum * memberscale + neighsum * neighscale;
  150254. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150255. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150256. }
  150257. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150258. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150259. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150260. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150261. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  150262. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  150263. neighsum += neighsum;
  150264. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  150265. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  150266. membersum = membersum * memberscale + neighsum * neighscale;
  150267. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150268. inrow += 2;
  150269. }
  150270. }
  150271. METHODDEF(void)
  150272. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  150273. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150274. {
  150275. int outrow;
  150276. JDIMENSION colctr;
  150277. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150278. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  150279. INT32 membersum, neighsum, memberscale, neighscale;
  150280. int colsum, lastcolsum, nextcolsum;
  150281. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150282. cinfo->image_width, output_cols);
  150283. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  150284. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  150285. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150286. outptr = output_data[outrow];
  150287. inptr = input_data[outrow];
  150288. above_ptr = input_data[outrow-1];
  150289. below_ptr = input_data[outrow+1];
  150290. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  150291. GETJSAMPLE(*inptr);
  150292. membersum = GETJSAMPLE(*inptr++);
  150293. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150294. GETJSAMPLE(*inptr);
  150295. neighsum = colsum + (colsum - membersum) + nextcolsum;
  150296. membersum = membersum * memberscale + neighsum * neighscale;
  150297. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150298. lastcolsum = colsum; colsum = nextcolsum;
  150299. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150300. membersum = GETJSAMPLE(*inptr++);
  150301. above_ptr++; below_ptr++;
  150302. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150303. GETJSAMPLE(*inptr);
  150304. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  150305. membersum = membersum * memberscale + neighsum * neighscale;
  150306. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150307. lastcolsum = colsum; colsum = nextcolsum;
  150308. }
  150309. membersum = GETJSAMPLE(*inptr);
  150310. neighsum = lastcolsum + (colsum - membersum) + colsum;
  150311. membersum = membersum * memberscale + neighsum * neighscale;
  150312. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150313. }
  150314. }
  150315. #endif /* INPUT_SMOOTHING_SUPPORTED */
  150316. GLOBAL(void)
  150317. jinit_downsampler (j_compress_ptr cinfo)
  150318. {
  150319. my_downsample_ptr downsample;
  150320. int ci;
  150321. jpeg_component_info * compptr;
  150322. boolean smoothok = TRUE;
  150323. downsample = (my_downsample_ptr)
  150324. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150325. SIZEOF(my_downsampler));
  150326. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  150327. downsample->pub.start_pass = start_pass_downsample;
  150328. downsample->pub.downsample = sep_downsample;
  150329. downsample->pub.need_context_rows = FALSE;
  150330. if (cinfo->CCIR601_sampling)
  150331. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  150332. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150333. ci++, compptr++) {
  150334. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  150335. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150336. #ifdef INPUT_SMOOTHING_SUPPORTED
  150337. if (cinfo->smoothing_factor) {
  150338. downsample->methods[ci] = fullsize_smooth_downsample;
  150339. downsample->pub.need_context_rows = TRUE;
  150340. } else
  150341. #endif
  150342. downsample->methods[ci] = fullsize_downsample;
  150343. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150344. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150345. smoothok = FALSE;
  150346. downsample->methods[ci] = h2v1_downsample;
  150347. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150348. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  150349. #ifdef INPUT_SMOOTHING_SUPPORTED
  150350. if (cinfo->smoothing_factor) {
  150351. downsample->methods[ci] = h2v2_smooth_downsample;
  150352. downsample->pub.need_context_rows = TRUE;
  150353. } else
  150354. #endif
  150355. downsample->methods[ci] = h2v2_downsample;
  150356. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  150357. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  150358. smoothok = FALSE;
  150359. downsample->methods[ci] = int_downsample;
  150360. } else
  150361. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  150362. }
  150363. #ifdef INPUT_SMOOTHING_SUPPORTED
  150364. if (cinfo->smoothing_factor && !smoothok)
  150365. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  150366. #endif
  150367. }
  150368. /*** End of inlined file: jcsample.c ***/
  150369. /*** Start of inlined file: jctrans.c ***/
  150370. #define JPEG_INTERNALS
  150371. LOCAL(void) transencode_master_selection
  150372. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150373. LOCAL(void) transencode_coef_controller
  150374. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150375. GLOBAL(void)
  150376. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  150377. {
  150378. if (cinfo->global_state != CSTATE_START)
  150379. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150380. jpeg_suppress_tables(cinfo, FALSE);
  150381. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  150382. (*cinfo->dest->init_destination) (cinfo);
  150383. transencode_master_selection(cinfo, coef_arrays);
  150384. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  150385. cinfo->global_state = CSTATE_WRCOEFS;
  150386. }
  150387. GLOBAL(void)
  150388. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  150389. j_compress_ptr dstinfo)
  150390. {
  150391. JQUANT_TBL ** qtblptr;
  150392. jpeg_component_info *incomp, *outcomp;
  150393. JQUANT_TBL *c_quant, *slot_quant;
  150394. int tblno, ci, coefi;
  150395. if (dstinfo->global_state != CSTATE_START)
  150396. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  150397. dstinfo->image_width = srcinfo->image_width;
  150398. dstinfo->image_height = srcinfo->image_height;
  150399. dstinfo->input_components = srcinfo->num_components;
  150400. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  150401. jpeg_set_defaults(dstinfo);
  150402. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  150403. dstinfo->data_precision = srcinfo->data_precision;
  150404. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  150405. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  150406. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  150407. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  150408. if (*qtblptr == NULL)
  150409. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  150410. MEMCOPY((*qtblptr)->quantval,
  150411. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  150412. SIZEOF((*qtblptr)->quantval));
  150413. (*qtblptr)->sent_table = FALSE;
  150414. }
  150415. }
  150416. dstinfo->num_components = srcinfo->num_components;
  150417. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  150418. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  150419. MAX_COMPONENTS);
  150420. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  150421. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  150422. outcomp->component_id = incomp->component_id;
  150423. outcomp->h_samp_factor = incomp->h_samp_factor;
  150424. outcomp->v_samp_factor = incomp->v_samp_factor;
  150425. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  150426. tblno = outcomp->quant_tbl_no;
  150427. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  150428. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  150429. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  150430. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  150431. c_quant = incomp->quant_table;
  150432. if (c_quant != NULL) {
  150433. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  150434. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  150435. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  150436. }
  150437. }
  150438. }
  150439. if (srcinfo->saw_JFIF_marker) {
  150440. if (srcinfo->JFIF_major_version == 1) {
  150441. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  150442. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  150443. }
  150444. dstinfo->density_unit = srcinfo->density_unit;
  150445. dstinfo->X_density = srcinfo->X_density;
  150446. dstinfo->Y_density = srcinfo->Y_density;
  150447. }
  150448. }
  150449. LOCAL(void)
  150450. transencode_master_selection (j_compress_ptr cinfo,
  150451. jvirt_barray_ptr * coef_arrays)
  150452. {
  150453. cinfo->input_components = 1;
  150454. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  150455. if (cinfo->arith_code) {
  150456. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  150457. } else {
  150458. if (cinfo->progressive_mode) {
  150459. #ifdef C_PROGRESSIVE_SUPPORTED
  150460. jinit_phuff_encoder(cinfo);
  150461. #else
  150462. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150463. #endif
  150464. } else
  150465. jinit_huff_encoder(cinfo);
  150466. }
  150467. transencode_coef_controller(cinfo, coef_arrays);
  150468. jinit_marker_writer(cinfo);
  150469. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  150470. (*cinfo->marker->write_file_header) (cinfo);
  150471. }
  150472. typedef struct {
  150473. struct jpeg_c_coef_controller pub; /* public fields */
  150474. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  150475. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  150476. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150477. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150478. jvirt_barray_ptr * whole_image;
  150479. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  150480. } my_coef_controller2;
  150481. typedef my_coef_controller2 * my_coef_ptr2;
  150482. LOCAL(void)
  150483. start_iMCU_row2 (j_compress_ptr cinfo)
  150484. {
  150485. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150486. if (cinfo->comps_in_scan > 1) {
  150487. coef->MCU_rows_per_iMCU_row = 1;
  150488. } else {
  150489. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  150490. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150491. else
  150492. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150493. }
  150494. coef->mcu_ctr = 0;
  150495. coef->MCU_vert_offset = 0;
  150496. }
  150497. METHODDEF(void)
  150498. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150499. {
  150500. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150501. if (pass_mode != JBUF_CRANK_DEST)
  150502. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150503. coef->iMCU_row_num = 0;
  150504. start_iMCU_row2(cinfo);
  150505. }
  150506. METHODDEF(boolean)
  150507. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  150508. {
  150509. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150510. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150511. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150512. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150513. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  150514. JDIMENSION start_col;
  150515. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150516. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  150517. JBLOCKROW buffer_ptr;
  150518. jpeg_component_info *compptr;
  150519. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150520. compptr = cinfo->cur_comp_info[ci];
  150521. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150522. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150523. coef->iMCU_row_num * compptr->v_samp_factor,
  150524. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150525. }
  150526. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150527. yoffset++) {
  150528. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150529. MCU_col_num++) {
  150530. blkn = 0; /* index of current DCT block within MCU */
  150531. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150532. compptr = cinfo->cur_comp_info[ci];
  150533. start_col = MCU_col_num * compptr->MCU_width;
  150534. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150535. : compptr->last_col_width;
  150536. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150537. if (coef->iMCU_row_num < last_iMCU_row ||
  150538. yindex+yoffset < compptr->last_row_height) {
  150539. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150540. for (xindex = 0; xindex < blockcnt; xindex++)
  150541. MCU_buffer[blkn++] = buffer_ptr++;
  150542. } else {
  150543. xindex = 0;
  150544. }
  150545. for (; xindex < compptr->MCU_width; xindex++) {
  150546. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150547. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150548. blkn++;
  150549. }
  150550. }
  150551. }
  150552. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150553. coef->MCU_vert_offset = yoffset;
  150554. coef->mcu_ctr = MCU_col_num;
  150555. return FALSE;
  150556. }
  150557. }
  150558. coef->mcu_ctr = 0;
  150559. }
  150560. coef->iMCU_row_num++;
  150561. start_iMCU_row2(cinfo);
  150562. return TRUE;
  150563. }
  150564. LOCAL(void)
  150565. transencode_coef_controller (j_compress_ptr cinfo,
  150566. jvirt_barray_ptr * coef_arrays)
  150567. {
  150568. my_coef_ptr2 coef;
  150569. JBLOCKROW buffer;
  150570. int i;
  150571. coef = (my_coef_ptr2)
  150572. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150573. SIZEOF(my_coef_controller2));
  150574. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150575. coef->pub.start_pass = start_pass_coef2;
  150576. coef->pub.compress_data = compress_output2;
  150577. coef->whole_image = coef_arrays;
  150578. buffer = (JBLOCKROW)
  150579. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150580. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150581. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150582. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150583. coef->dummy_buffer[i] = buffer + i;
  150584. }
  150585. }
  150586. /*** End of inlined file: jctrans.c ***/
  150587. /*** Start of inlined file: jdapistd.c ***/
  150588. #define JPEG_INTERNALS
  150589. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150590. GLOBAL(boolean)
  150591. jpeg_start_decompress (j_decompress_ptr cinfo)
  150592. {
  150593. if (cinfo->global_state == DSTATE_READY) {
  150594. jinit_master_decompress(cinfo);
  150595. if (cinfo->buffered_image) {
  150596. cinfo->global_state = DSTATE_BUFIMAGE;
  150597. return TRUE;
  150598. }
  150599. cinfo->global_state = DSTATE_PRELOAD;
  150600. }
  150601. if (cinfo->global_state == DSTATE_PRELOAD) {
  150602. if (cinfo->inputctl->has_multiple_scans) {
  150603. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150604. for (;;) {
  150605. int retcode;
  150606. if (cinfo->progress != NULL)
  150607. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150608. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150609. if (retcode == JPEG_SUSPENDED)
  150610. return FALSE;
  150611. if (retcode == JPEG_REACHED_EOI)
  150612. break;
  150613. if (cinfo->progress != NULL &&
  150614. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150615. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150616. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150617. }
  150618. }
  150619. }
  150620. #else
  150621. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150622. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150623. }
  150624. cinfo->output_scan_number = cinfo->input_scan_number;
  150625. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150626. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150627. return output_pass_setup(cinfo);
  150628. }
  150629. LOCAL(boolean)
  150630. output_pass_setup (j_decompress_ptr cinfo)
  150631. {
  150632. if (cinfo->global_state != DSTATE_PRESCAN) {
  150633. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150634. cinfo->output_scanline = 0;
  150635. cinfo->global_state = DSTATE_PRESCAN;
  150636. }
  150637. while (cinfo->master->is_dummy_pass) {
  150638. #ifdef QUANT_2PASS_SUPPORTED
  150639. while (cinfo->output_scanline < cinfo->output_height) {
  150640. JDIMENSION last_scanline;
  150641. if (cinfo->progress != NULL) {
  150642. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150643. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150644. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150645. }
  150646. last_scanline = cinfo->output_scanline;
  150647. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150648. &cinfo->output_scanline, (JDIMENSION) 0);
  150649. if (cinfo->output_scanline == last_scanline)
  150650. return FALSE; /* No progress made, must suspend */
  150651. }
  150652. (*cinfo->master->finish_output_pass) (cinfo);
  150653. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150654. cinfo->output_scanline = 0;
  150655. #else
  150656. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150657. #endif /* QUANT_2PASS_SUPPORTED */
  150658. }
  150659. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150660. return TRUE;
  150661. }
  150662. GLOBAL(JDIMENSION)
  150663. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150664. JDIMENSION max_lines)
  150665. {
  150666. JDIMENSION row_ctr;
  150667. if (cinfo->global_state != DSTATE_SCANNING)
  150668. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150669. if (cinfo->output_scanline >= cinfo->output_height) {
  150670. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150671. return 0;
  150672. }
  150673. if (cinfo->progress != NULL) {
  150674. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150675. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150676. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150677. }
  150678. row_ctr = 0;
  150679. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150680. cinfo->output_scanline += row_ctr;
  150681. return row_ctr;
  150682. }
  150683. GLOBAL(JDIMENSION)
  150684. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150685. JDIMENSION max_lines)
  150686. {
  150687. JDIMENSION lines_per_iMCU_row;
  150688. if (cinfo->global_state != DSTATE_RAW_OK)
  150689. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150690. if (cinfo->output_scanline >= cinfo->output_height) {
  150691. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150692. return 0;
  150693. }
  150694. if (cinfo->progress != NULL) {
  150695. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150696. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150697. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150698. }
  150699. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150700. if (max_lines < lines_per_iMCU_row)
  150701. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150702. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150703. return 0; /* suspension forced, can do nothing more */
  150704. cinfo->output_scanline += lines_per_iMCU_row;
  150705. return lines_per_iMCU_row;
  150706. }
  150707. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150708. GLOBAL(boolean)
  150709. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150710. {
  150711. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150712. cinfo->global_state != DSTATE_PRESCAN)
  150713. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150714. if (scan_number <= 0)
  150715. scan_number = 1;
  150716. if (cinfo->inputctl->eoi_reached &&
  150717. scan_number > cinfo->input_scan_number)
  150718. scan_number = cinfo->input_scan_number;
  150719. cinfo->output_scan_number = scan_number;
  150720. return output_pass_setup(cinfo);
  150721. }
  150722. GLOBAL(boolean)
  150723. jpeg_finish_output (j_decompress_ptr cinfo)
  150724. {
  150725. if ((cinfo->global_state == DSTATE_SCANNING ||
  150726. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150727. (*cinfo->master->finish_output_pass) (cinfo);
  150728. cinfo->global_state = DSTATE_BUFPOST;
  150729. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150730. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150731. }
  150732. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150733. ! cinfo->inputctl->eoi_reached) {
  150734. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150735. return FALSE; /* Suspend, come back later */
  150736. }
  150737. cinfo->global_state = DSTATE_BUFIMAGE;
  150738. return TRUE;
  150739. }
  150740. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150741. /*** End of inlined file: jdapistd.c ***/
  150742. /*** Start of inlined file: jdapimin.c ***/
  150743. #define JPEG_INTERNALS
  150744. GLOBAL(void)
  150745. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150746. {
  150747. int i;
  150748. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150749. if (version != JPEG_LIB_VERSION)
  150750. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150751. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150752. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150753. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150754. {
  150755. struct jpeg_error_mgr * err = cinfo->err;
  150756. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150757. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150758. cinfo->err = err;
  150759. cinfo->client_data = client_data;
  150760. }
  150761. cinfo->is_decompressor = TRUE;
  150762. jinit_memory_mgr((j_common_ptr) cinfo);
  150763. cinfo->progress = NULL;
  150764. cinfo->src = NULL;
  150765. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150766. cinfo->quant_tbl_ptrs[i] = NULL;
  150767. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150768. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150769. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150770. }
  150771. cinfo->marker_list = NULL;
  150772. jinit_marker_reader(cinfo);
  150773. jinit_input_controller(cinfo);
  150774. cinfo->global_state = DSTATE_START;
  150775. }
  150776. GLOBAL(void)
  150777. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150778. {
  150779. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150780. }
  150781. GLOBAL(void)
  150782. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150783. {
  150784. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150785. }
  150786. LOCAL(void)
  150787. default_decompress_parms (j_decompress_ptr cinfo)
  150788. {
  150789. switch (cinfo->num_components) {
  150790. case 1:
  150791. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150792. cinfo->out_color_space = JCS_GRAYSCALE;
  150793. break;
  150794. case 3:
  150795. if (cinfo->saw_JFIF_marker) {
  150796. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150797. } else if (cinfo->saw_Adobe_marker) {
  150798. switch (cinfo->Adobe_transform) {
  150799. case 0:
  150800. cinfo->jpeg_color_space = JCS_RGB;
  150801. break;
  150802. case 1:
  150803. cinfo->jpeg_color_space = JCS_YCbCr;
  150804. break;
  150805. default:
  150806. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150807. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150808. break;
  150809. }
  150810. } else {
  150811. int cid0 = cinfo->comp_info[0].component_id;
  150812. int cid1 = cinfo->comp_info[1].component_id;
  150813. int cid2 = cinfo->comp_info[2].component_id;
  150814. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150815. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150816. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150817. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150818. else {
  150819. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150820. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150821. }
  150822. }
  150823. cinfo->out_color_space = JCS_RGB;
  150824. break;
  150825. case 4:
  150826. if (cinfo->saw_Adobe_marker) {
  150827. switch (cinfo->Adobe_transform) {
  150828. case 0:
  150829. cinfo->jpeg_color_space = JCS_CMYK;
  150830. break;
  150831. case 2:
  150832. cinfo->jpeg_color_space = JCS_YCCK;
  150833. break;
  150834. default:
  150835. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150836. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150837. break;
  150838. }
  150839. } else {
  150840. cinfo->jpeg_color_space = JCS_CMYK;
  150841. }
  150842. cinfo->out_color_space = JCS_CMYK;
  150843. break;
  150844. default:
  150845. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150846. cinfo->out_color_space = JCS_UNKNOWN;
  150847. break;
  150848. }
  150849. cinfo->scale_num = 1; /* 1:1 scaling */
  150850. cinfo->scale_denom = 1;
  150851. cinfo->output_gamma = 1.0;
  150852. cinfo->buffered_image = FALSE;
  150853. cinfo->raw_data_out = FALSE;
  150854. cinfo->dct_method = JDCT_DEFAULT;
  150855. cinfo->do_fancy_upsampling = TRUE;
  150856. cinfo->do_block_smoothing = TRUE;
  150857. cinfo->quantize_colors = FALSE;
  150858. cinfo->dither_mode = JDITHER_FS;
  150859. #ifdef QUANT_2PASS_SUPPORTED
  150860. cinfo->two_pass_quantize = TRUE;
  150861. #else
  150862. cinfo->two_pass_quantize = FALSE;
  150863. #endif
  150864. cinfo->desired_number_of_colors = 256;
  150865. cinfo->colormap = NULL;
  150866. cinfo->enable_1pass_quant = FALSE;
  150867. cinfo->enable_external_quant = FALSE;
  150868. cinfo->enable_2pass_quant = FALSE;
  150869. }
  150870. GLOBAL(int)
  150871. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150872. {
  150873. int retcode;
  150874. if (cinfo->global_state != DSTATE_START &&
  150875. cinfo->global_state != DSTATE_INHEADER)
  150876. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150877. retcode = jpeg_consume_input(cinfo);
  150878. switch (retcode) {
  150879. case JPEG_REACHED_SOS:
  150880. retcode = JPEG_HEADER_OK;
  150881. break;
  150882. case JPEG_REACHED_EOI:
  150883. if (require_image) /* Complain if application wanted an image */
  150884. ERREXIT(cinfo, JERR_NO_IMAGE);
  150885. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150886. retcode = JPEG_HEADER_TABLES_ONLY;
  150887. break;
  150888. case JPEG_SUSPENDED:
  150889. break;
  150890. }
  150891. return retcode;
  150892. }
  150893. GLOBAL(int)
  150894. jpeg_consume_input (j_decompress_ptr cinfo)
  150895. {
  150896. int retcode = JPEG_SUSPENDED;
  150897. switch (cinfo->global_state) {
  150898. case DSTATE_START:
  150899. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150900. (*cinfo->src->init_source) (cinfo);
  150901. cinfo->global_state = DSTATE_INHEADER;
  150902. case DSTATE_INHEADER:
  150903. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150904. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150905. default_decompress_parms(cinfo);
  150906. cinfo->global_state = DSTATE_READY;
  150907. }
  150908. break;
  150909. case DSTATE_READY:
  150910. retcode = JPEG_REACHED_SOS;
  150911. break;
  150912. case DSTATE_PRELOAD:
  150913. case DSTATE_PRESCAN:
  150914. case DSTATE_SCANNING:
  150915. case DSTATE_RAW_OK:
  150916. case DSTATE_BUFIMAGE:
  150917. case DSTATE_BUFPOST:
  150918. case DSTATE_STOPPING:
  150919. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150920. break;
  150921. default:
  150922. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150923. }
  150924. return retcode;
  150925. }
  150926. GLOBAL(boolean)
  150927. jpeg_input_complete (j_decompress_ptr cinfo)
  150928. {
  150929. if (cinfo->global_state < DSTATE_START ||
  150930. cinfo->global_state > DSTATE_STOPPING)
  150931. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150932. return cinfo->inputctl->eoi_reached;
  150933. }
  150934. GLOBAL(boolean)
  150935. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150936. {
  150937. if (cinfo->global_state < DSTATE_READY ||
  150938. cinfo->global_state > DSTATE_STOPPING)
  150939. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150940. return cinfo->inputctl->has_multiple_scans;
  150941. }
  150942. GLOBAL(boolean)
  150943. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150944. {
  150945. if ((cinfo->global_state == DSTATE_SCANNING ||
  150946. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150947. if (cinfo->output_scanline < cinfo->output_height)
  150948. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150949. (*cinfo->master->finish_output_pass) (cinfo);
  150950. cinfo->global_state = DSTATE_STOPPING;
  150951. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150952. cinfo->global_state = DSTATE_STOPPING;
  150953. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150954. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150955. }
  150956. while (! cinfo->inputctl->eoi_reached) {
  150957. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150958. return FALSE; /* Suspend, come back later */
  150959. }
  150960. (*cinfo->src->term_source) (cinfo);
  150961. jpeg_abort((j_common_ptr) cinfo);
  150962. return TRUE;
  150963. }
  150964. /*** End of inlined file: jdapimin.c ***/
  150965. /*** Start of inlined file: jdatasrc.c ***/
  150966. /*** Start of inlined file: jerror.h ***/
  150967. #ifndef JMESSAGE
  150968. #ifndef JERROR_H
  150969. #define JMAKE_ENUM_LIST
  150970. #else
  150971. #define JMESSAGE(code,string)
  150972. #endif /* JERROR_H */
  150973. #endif /* JMESSAGE */
  150974. #ifdef JMAKE_ENUM_LIST
  150975. typedef enum {
  150976. #define JMESSAGE(code,string) code ,
  150977. #endif /* JMAKE_ENUM_LIST */
  150978. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150979. JMESSAGE(JERR_ARITH_NOTIMPL,
  150980. "Sorry, there are legal restrictions on arithmetic coding")
  150981. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150982. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150983. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150984. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150985. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150986. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150987. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150988. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150989. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150990. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150991. JMESSAGE(JERR_BAD_LIB_VERSION,
  150992. "Wrong JPEG library version: library is %d, caller expects %d")
  150993. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150994. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150995. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150996. JMESSAGE(JERR_BAD_PROGRESSION,
  150997. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150998. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150999. "Invalid progressive parameters at scan script entry %d")
  151000. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  151001. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  151002. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  151003. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  151004. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  151005. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  151006. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  151007. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  151008. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  151009. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  151010. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  151011. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  151012. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  151013. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  151014. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  151015. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  151016. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  151017. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  151018. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  151019. JMESSAGE(JERR_FILE_READ, "Input file read error")
  151020. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  151021. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  151022. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  151023. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  151024. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  151025. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  151026. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  151027. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  151028. "Cannot transcode due to multiple use of quantization table %d")
  151029. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  151030. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  151031. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  151032. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  151033. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  151034. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  151035. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  151036. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  151037. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  151038. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  151039. JMESSAGE(JERR_QUANT_COMPONENTS,
  151040. "Cannot quantize more than %d color components")
  151041. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  151042. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  151043. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  151044. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  151045. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  151046. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  151047. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  151048. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  151049. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  151050. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  151051. JMESSAGE(JERR_TFILE_WRITE,
  151052. "Write failed on temporary file --- out of disk space?")
  151053. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  151054. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  151055. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  151056. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  151057. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  151058. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  151059. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  151060. JMESSAGE(JMSG_VERSION, JVERSION)
  151061. JMESSAGE(JTRC_16BIT_TABLES,
  151062. "Caution: quantization tables are too coarse for baseline JPEG")
  151063. JMESSAGE(JTRC_ADOBE,
  151064. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  151065. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  151066. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  151067. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  151068. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  151069. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  151070. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  151071. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  151072. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  151073. JMESSAGE(JTRC_EOI, "End Of Image")
  151074. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  151075. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  151076. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  151077. "Warning: thumbnail image size does not match data length %u")
  151078. JMESSAGE(JTRC_JFIF_EXTENSION,
  151079. "JFIF extension marker: type 0x%02x, length %u")
  151080. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  151081. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  151082. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  151083. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  151084. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  151085. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  151086. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  151087. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  151088. JMESSAGE(JTRC_RST, "RST%d")
  151089. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  151090. "Smoothing not supported with nonstandard sampling ratios")
  151091. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  151092. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  151093. JMESSAGE(JTRC_SOI, "Start of Image")
  151094. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  151095. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  151096. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  151097. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  151098. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  151099. JMESSAGE(JTRC_THUMB_JPEG,
  151100. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  151101. JMESSAGE(JTRC_THUMB_PALETTE,
  151102. "JFIF extension marker: palette thumbnail image, length %u")
  151103. JMESSAGE(JTRC_THUMB_RGB,
  151104. "JFIF extension marker: RGB thumbnail image, length %u")
  151105. JMESSAGE(JTRC_UNKNOWN_IDS,
  151106. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  151107. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  151108. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  151109. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  151110. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  151111. "Inconsistent progression sequence for component %d coefficient %d")
  151112. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  151113. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  151114. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  151115. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  151116. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  151117. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  151118. JMESSAGE(JWRN_MUST_RESYNC,
  151119. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  151120. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  151121. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  151122. #ifdef JMAKE_ENUM_LIST
  151123. JMSG_LASTMSGCODE
  151124. } J_MESSAGE_CODE;
  151125. #undef JMAKE_ENUM_LIST
  151126. #endif /* JMAKE_ENUM_LIST */
  151127. #undef JMESSAGE
  151128. #ifndef JERROR_H
  151129. #define JERROR_H
  151130. #define ERREXIT(cinfo,code) \
  151131. ((cinfo)->err->msg_code = (code), \
  151132. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151133. #define ERREXIT1(cinfo,code,p1) \
  151134. ((cinfo)->err->msg_code = (code), \
  151135. (cinfo)->err->msg_parm.i[0] = (p1), \
  151136. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151137. #define ERREXIT2(cinfo,code,p1,p2) \
  151138. ((cinfo)->err->msg_code = (code), \
  151139. (cinfo)->err->msg_parm.i[0] = (p1), \
  151140. (cinfo)->err->msg_parm.i[1] = (p2), \
  151141. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151142. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  151143. ((cinfo)->err->msg_code = (code), \
  151144. (cinfo)->err->msg_parm.i[0] = (p1), \
  151145. (cinfo)->err->msg_parm.i[1] = (p2), \
  151146. (cinfo)->err->msg_parm.i[2] = (p3), \
  151147. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151148. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  151149. ((cinfo)->err->msg_code = (code), \
  151150. (cinfo)->err->msg_parm.i[0] = (p1), \
  151151. (cinfo)->err->msg_parm.i[1] = (p2), \
  151152. (cinfo)->err->msg_parm.i[2] = (p3), \
  151153. (cinfo)->err->msg_parm.i[3] = (p4), \
  151154. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151155. #define ERREXITS(cinfo,code,str) \
  151156. ((cinfo)->err->msg_code = (code), \
  151157. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151158. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151159. #define MAKESTMT(stuff) do { stuff } while (0)
  151160. #define WARNMS(cinfo,code) \
  151161. ((cinfo)->err->msg_code = (code), \
  151162. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151163. #define WARNMS1(cinfo,code,p1) \
  151164. ((cinfo)->err->msg_code = (code), \
  151165. (cinfo)->err->msg_parm.i[0] = (p1), \
  151166. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151167. #define WARNMS2(cinfo,code,p1,p2) \
  151168. ((cinfo)->err->msg_code = (code), \
  151169. (cinfo)->err->msg_parm.i[0] = (p1), \
  151170. (cinfo)->err->msg_parm.i[1] = (p2), \
  151171. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151172. #define TRACEMS(cinfo,lvl,code) \
  151173. ((cinfo)->err->msg_code = (code), \
  151174. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151175. #define TRACEMS1(cinfo,lvl,code,p1) \
  151176. ((cinfo)->err->msg_code = (code), \
  151177. (cinfo)->err->msg_parm.i[0] = (p1), \
  151178. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151179. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  151180. ((cinfo)->err->msg_code = (code), \
  151181. (cinfo)->err->msg_parm.i[0] = (p1), \
  151182. (cinfo)->err->msg_parm.i[1] = (p2), \
  151183. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151184. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  151185. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151186. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  151187. (cinfo)->err->msg_code = (code); \
  151188. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151189. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  151190. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151191. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151192. (cinfo)->err->msg_code = (code); \
  151193. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151194. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  151195. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151196. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151197. _mp[4] = (p5); \
  151198. (cinfo)->err->msg_code = (code); \
  151199. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151200. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  151201. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151202. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151203. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  151204. (cinfo)->err->msg_code = (code); \
  151205. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151206. #define TRACEMSS(cinfo,lvl,code,str) \
  151207. ((cinfo)->err->msg_code = (code), \
  151208. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151209. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151210. #endif /* JERROR_H */
  151211. /*** End of inlined file: jerror.h ***/
  151212. typedef struct {
  151213. struct jpeg_source_mgr pub; /* public fields */
  151214. FILE * infile; /* source stream */
  151215. JOCTET * buffer; /* start of buffer */
  151216. boolean start_of_file; /* have we gotten any data yet? */
  151217. } my_source_mgr;
  151218. typedef my_source_mgr * my_src_ptr;
  151219. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  151220. METHODDEF(void)
  151221. init_source (j_decompress_ptr cinfo)
  151222. {
  151223. my_src_ptr src = (my_src_ptr) cinfo->src;
  151224. src->start_of_file = TRUE;
  151225. }
  151226. METHODDEF(boolean)
  151227. fill_input_buffer (j_decompress_ptr cinfo)
  151228. {
  151229. my_src_ptr src = (my_src_ptr) cinfo->src;
  151230. size_t nbytes;
  151231. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  151232. if (nbytes <= 0) {
  151233. if (src->start_of_file) /* Treat empty input file as fatal error */
  151234. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  151235. WARNMS(cinfo, JWRN_JPEG_EOF);
  151236. src->buffer[0] = (JOCTET) 0xFF;
  151237. src->buffer[1] = (JOCTET) JPEG_EOI;
  151238. nbytes = 2;
  151239. }
  151240. src->pub.next_input_byte = src->buffer;
  151241. src->pub.bytes_in_buffer = nbytes;
  151242. src->start_of_file = FALSE;
  151243. return TRUE;
  151244. }
  151245. METHODDEF(void)
  151246. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  151247. {
  151248. my_src_ptr src = (my_src_ptr) cinfo->src;
  151249. if (num_bytes > 0) {
  151250. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  151251. num_bytes -= (long) src->pub.bytes_in_buffer;
  151252. (void) fill_input_buffer(cinfo);
  151253. }
  151254. src->pub.next_input_byte += (size_t) num_bytes;
  151255. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  151256. }
  151257. }
  151258. METHODDEF(void)
  151259. term_source (j_decompress_ptr cinfo)
  151260. {
  151261. }
  151262. GLOBAL(void)
  151263. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  151264. {
  151265. my_src_ptr src;
  151266. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  151267. cinfo->src = (struct jpeg_source_mgr *)
  151268. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151269. SIZEOF(my_source_mgr));
  151270. src = (my_src_ptr) cinfo->src;
  151271. src->buffer = (JOCTET *)
  151272. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151273. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  151274. }
  151275. src = (my_src_ptr) cinfo->src;
  151276. src->pub.init_source = init_source;
  151277. src->pub.fill_input_buffer = fill_input_buffer;
  151278. src->pub.skip_input_data = skip_input_data;
  151279. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  151280. src->pub.term_source = term_source;
  151281. src->infile = infile;
  151282. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  151283. src->pub.next_input_byte = NULL; /* until buffer loaded */
  151284. }
  151285. /*** End of inlined file: jdatasrc.c ***/
  151286. /*** Start of inlined file: jdcoefct.c ***/
  151287. #define JPEG_INTERNALS
  151288. #ifndef D_PROGRESSIVE_SUPPORTED
  151289. #undef BLOCK_SMOOTHING_SUPPORTED
  151290. #endif
  151291. typedef struct {
  151292. struct jpeg_d_coef_controller pub; /* public fields */
  151293. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  151294. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  151295. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  151296. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  151297. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151298. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  151299. #endif
  151300. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151301. int * coef_bits_latch;
  151302. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  151303. #endif
  151304. } my_coef_controller3;
  151305. typedef my_coef_controller3 * my_coef_ptr3;
  151306. METHODDEF(int) decompress_onepass
  151307. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151308. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151309. METHODDEF(int) decompress_data
  151310. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151311. #endif
  151312. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151313. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  151314. METHODDEF(int) decompress_smooth_data
  151315. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151316. #endif
  151317. LOCAL(void)
  151318. start_iMCU_row3 (j_decompress_ptr cinfo)
  151319. {
  151320. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151321. if (cinfo->comps_in_scan > 1) {
  151322. coef->MCU_rows_per_iMCU_row = 1;
  151323. } else {
  151324. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  151325. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  151326. else
  151327. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  151328. }
  151329. coef->MCU_ctr = 0;
  151330. coef->MCU_vert_offset = 0;
  151331. }
  151332. METHODDEF(void)
  151333. start_input_pass (j_decompress_ptr cinfo)
  151334. {
  151335. cinfo->input_iMCU_row = 0;
  151336. start_iMCU_row3(cinfo);
  151337. }
  151338. METHODDEF(void)
  151339. start_output_pass (j_decompress_ptr cinfo)
  151340. {
  151341. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151342. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151343. if (coef->pub.coef_arrays != NULL) {
  151344. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  151345. coef->pub.decompress_data = decompress_smooth_data;
  151346. else
  151347. coef->pub.decompress_data = decompress_data;
  151348. }
  151349. #endif
  151350. cinfo->output_iMCU_row = 0;
  151351. }
  151352. METHODDEF(int)
  151353. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151354. {
  151355. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151356. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151357. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  151358. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151359. int blkn, ci, xindex, yindex, yoffset, useful_width;
  151360. JSAMPARRAY output_ptr;
  151361. JDIMENSION start_col, output_col;
  151362. jpeg_component_info *compptr;
  151363. inverse_DCT_method_ptr inverse_DCT;
  151364. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151365. yoffset++) {
  151366. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  151367. MCU_col_num++) {
  151368. jzero_far((void FAR *) coef->MCU_buffer[0],
  151369. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  151370. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151371. coef->MCU_vert_offset = yoffset;
  151372. coef->MCU_ctr = MCU_col_num;
  151373. return JPEG_SUSPENDED;
  151374. }
  151375. blkn = 0; /* index of current DCT block within MCU */
  151376. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151377. compptr = cinfo->cur_comp_info[ci];
  151378. if (! compptr->component_needed) {
  151379. blkn += compptr->MCU_blocks;
  151380. continue;
  151381. }
  151382. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  151383. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  151384. : compptr->last_col_width;
  151385. output_ptr = output_buf[compptr->component_index] +
  151386. yoffset * compptr->DCT_scaled_size;
  151387. start_col = MCU_col_num * compptr->MCU_sample_width;
  151388. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151389. if (cinfo->input_iMCU_row < last_iMCU_row ||
  151390. yoffset+yindex < compptr->last_row_height) {
  151391. output_col = start_col;
  151392. for (xindex = 0; xindex < useful_width; xindex++) {
  151393. (*inverse_DCT) (cinfo, compptr,
  151394. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  151395. output_ptr, output_col);
  151396. output_col += compptr->DCT_scaled_size;
  151397. }
  151398. }
  151399. blkn += compptr->MCU_width;
  151400. output_ptr += compptr->DCT_scaled_size;
  151401. }
  151402. }
  151403. }
  151404. coef->MCU_ctr = 0;
  151405. }
  151406. cinfo->output_iMCU_row++;
  151407. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151408. start_iMCU_row3(cinfo);
  151409. return JPEG_ROW_COMPLETED;
  151410. }
  151411. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151412. return JPEG_SCAN_COMPLETED;
  151413. }
  151414. METHODDEF(int)
  151415. dummy_consume_data (j_decompress_ptr cinfo)
  151416. {
  151417. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  151418. }
  151419. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151420. METHODDEF(int)
  151421. consume_data (j_decompress_ptr cinfo)
  151422. {
  151423. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151424. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151425. int blkn, ci, xindex, yindex, yoffset;
  151426. JDIMENSION start_col;
  151427. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  151428. JBLOCKROW buffer_ptr;
  151429. jpeg_component_info *compptr;
  151430. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151431. compptr = cinfo->cur_comp_info[ci];
  151432. buffer[ci] = (*cinfo->mem->access_virt_barray)
  151433. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  151434. cinfo->input_iMCU_row * compptr->v_samp_factor,
  151435. (JDIMENSION) compptr->v_samp_factor, TRUE);
  151436. }
  151437. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151438. yoffset++) {
  151439. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  151440. MCU_col_num++) {
  151441. blkn = 0; /* index of current DCT block within MCU */
  151442. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151443. compptr = cinfo->cur_comp_info[ci];
  151444. start_col = MCU_col_num * compptr->MCU_width;
  151445. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151446. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  151447. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  151448. coef->MCU_buffer[blkn++] = buffer_ptr++;
  151449. }
  151450. }
  151451. }
  151452. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151453. coef->MCU_vert_offset = yoffset;
  151454. coef->MCU_ctr = MCU_col_num;
  151455. return JPEG_SUSPENDED;
  151456. }
  151457. }
  151458. coef->MCU_ctr = 0;
  151459. }
  151460. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151461. start_iMCU_row3(cinfo);
  151462. return JPEG_ROW_COMPLETED;
  151463. }
  151464. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151465. return JPEG_SCAN_COMPLETED;
  151466. }
  151467. METHODDEF(int)
  151468. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151469. {
  151470. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151471. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151472. JDIMENSION block_num;
  151473. int ci, block_row, block_rows;
  151474. JBLOCKARRAY buffer;
  151475. JBLOCKROW buffer_ptr;
  151476. JSAMPARRAY output_ptr;
  151477. JDIMENSION output_col;
  151478. jpeg_component_info *compptr;
  151479. inverse_DCT_method_ptr inverse_DCT;
  151480. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  151481. (cinfo->input_scan_number == cinfo->output_scan_number &&
  151482. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  151483. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151484. return JPEG_SUSPENDED;
  151485. }
  151486. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151487. ci++, compptr++) {
  151488. if (! compptr->component_needed)
  151489. continue;
  151490. buffer = (*cinfo->mem->access_virt_barray)
  151491. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151492. cinfo->output_iMCU_row * compptr->v_samp_factor,
  151493. (JDIMENSION) compptr->v_samp_factor, FALSE);
  151494. if (cinfo->output_iMCU_row < last_iMCU_row)
  151495. block_rows = compptr->v_samp_factor;
  151496. else {
  151497. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151498. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151499. }
  151500. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151501. output_ptr = output_buf[ci];
  151502. for (block_row = 0; block_row < block_rows; block_row++) {
  151503. buffer_ptr = buffer[block_row];
  151504. output_col = 0;
  151505. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  151506. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  151507. output_ptr, output_col);
  151508. buffer_ptr++;
  151509. output_col += compptr->DCT_scaled_size;
  151510. }
  151511. output_ptr += compptr->DCT_scaled_size;
  151512. }
  151513. }
  151514. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151515. return JPEG_ROW_COMPLETED;
  151516. return JPEG_SCAN_COMPLETED;
  151517. }
  151518. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151519. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151520. #define Q01_POS 1
  151521. #define Q10_POS 8
  151522. #define Q20_POS 16
  151523. #define Q11_POS 9
  151524. #define Q02_POS 2
  151525. LOCAL(boolean)
  151526. smoothing_ok (j_decompress_ptr cinfo)
  151527. {
  151528. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151529. boolean smoothing_useful = FALSE;
  151530. int ci, coefi;
  151531. jpeg_component_info *compptr;
  151532. JQUANT_TBL * qtable;
  151533. int * coef_bits;
  151534. int * coef_bits_latch;
  151535. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151536. return FALSE;
  151537. if (coef->coef_bits_latch == NULL)
  151538. coef->coef_bits_latch = (int *)
  151539. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151540. cinfo->num_components *
  151541. (SAVED_COEFS * SIZEOF(int)));
  151542. coef_bits_latch = coef->coef_bits_latch;
  151543. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151544. ci++, compptr++) {
  151545. if ((qtable = compptr->quant_table) == NULL)
  151546. return FALSE;
  151547. if (qtable->quantval[0] == 0 ||
  151548. qtable->quantval[Q01_POS] == 0 ||
  151549. qtable->quantval[Q10_POS] == 0 ||
  151550. qtable->quantval[Q20_POS] == 0 ||
  151551. qtable->quantval[Q11_POS] == 0 ||
  151552. qtable->quantval[Q02_POS] == 0)
  151553. return FALSE;
  151554. coef_bits = cinfo->coef_bits[ci];
  151555. if (coef_bits[0] < 0)
  151556. return FALSE;
  151557. for (coefi = 1; coefi <= 5; coefi++) {
  151558. coef_bits_latch[coefi] = coef_bits[coefi];
  151559. if (coef_bits[coefi] != 0)
  151560. smoothing_useful = TRUE;
  151561. }
  151562. coef_bits_latch += SAVED_COEFS;
  151563. }
  151564. return smoothing_useful;
  151565. }
  151566. METHODDEF(int)
  151567. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151568. {
  151569. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151570. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151571. JDIMENSION block_num, last_block_column;
  151572. int ci, block_row, block_rows, access_rows;
  151573. JBLOCKARRAY buffer;
  151574. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151575. JSAMPARRAY output_ptr;
  151576. JDIMENSION output_col;
  151577. jpeg_component_info *compptr;
  151578. inverse_DCT_method_ptr inverse_DCT;
  151579. boolean first_row, last_row;
  151580. JBLOCK workspace;
  151581. int *coef_bits;
  151582. JQUANT_TBL *quanttbl;
  151583. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151584. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151585. int Al, pred;
  151586. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151587. ! cinfo->inputctl->eoi_reached) {
  151588. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151589. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151590. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151591. break;
  151592. }
  151593. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151594. return JPEG_SUSPENDED;
  151595. }
  151596. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151597. ci++, compptr++) {
  151598. if (! compptr->component_needed)
  151599. continue;
  151600. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151601. block_rows = compptr->v_samp_factor;
  151602. access_rows = block_rows * 2; /* this and next iMCU row */
  151603. last_row = FALSE;
  151604. } else {
  151605. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151606. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151607. access_rows = block_rows; /* this iMCU row only */
  151608. last_row = TRUE;
  151609. }
  151610. if (cinfo->output_iMCU_row > 0) {
  151611. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151612. buffer = (*cinfo->mem->access_virt_barray)
  151613. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151614. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151615. (JDIMENSION) access_rows, FALSE);
  151616. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151617. first_row = FALSE;
  151618. } else {
  151619. buffer = (*cinfo->mem->access_virt_barray)
  151620. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151621. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151622. first_row = TRUE;
  151623. }
  151624. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151625. quanttbl = compptr->quant_table;
  151626. Q00 = quanttbl->quantval[0];
  151627. Q01 = quanttbl->quantval[Q01_POS];
  151628. Q10 = quanttbl->quantval[Q10_POS];
  151629. Q20 = quanttbl->quantval[Q20_POS];
  151630. Q11 = quanttbl->quantval[Q11_POS];
  151631. Q02 = quanttbl->quantval[Q02_POS];
  151632. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151633. output_ptr = output_buf[ci];
  151634. for (block_row = 0; block_row < block_rows; block_row++) {
  151635. buffer_ptr = buffer[block_row];
  151636. if (first_row && block_row == 0)
  151637. prev_block_row = buffer_ptr;
  151638. else
  151639. prev_block_row = buffer[block_row-1];
  151640. if (last_row && block_row == block_rows-1)
  151641. next_block_row = buffer_ptr;
  151642. else
  151643. next_block_row = buffer[block_row+1];
  151644. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151645. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151646. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151647. output_col = 0;
  151648. last_block_column = compptr->width_in_blocks - 1;
  151649. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151650. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151651. if (block_num < last_block_column) {
  151652. DC3 = (int) prev_block_row[1][0];
  151653. DC6 = (int) buffer_ptr[1][0];
  151654. DC9 = (int) next_block_row[1][0];
  151655. }
  151656. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151657. num = 36 * Q00 * (DC4 - DC6);
  151658. if (num >= 0) {
  151659. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151660. if (Al > 0 && pred >= (1<<Al))
  151661. pred = (1<<Al)-1;
  151662. } else {
  151663. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151664. if (Al > 0 && pred >= (1<<Al))
  151665. pred = (1<<Al)-1;
  151666. pred = -pred;
  151667. }
  151668. workspace[1] = (JCOEF) pred;
  151669. }
  151670. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151671. num = 36 * Q00 * (DC2 - DC8);
  151672. if (num >= 0) {
  151673. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151674. if (Al > 0 && pred >= (1<<Al))
  151675. pred = (1<<Al)-1;
  151676. } else {
  151677. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151678. if (Al > 0 && pred >= (1<<Al))
  151679. pred = (1<<Al)-1;
  151680. pred = -pred;
  151681. }
  151682. workspace[8] = (JCOEF) pred;
  151683. }
  151684. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151685. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151686. if (num >= 0) {
  151687. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151688. if (Al > 0 && pred >= (1<<Al))
  151689. pred = (1<<Al)-1;
  151690. } else {
  151691. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151692. if (Al > 0 && pred >= (1<<Al))
  151693. pred = (1<<Al)-1;
  151694. pred = -pred;
  151695. }
  151696. workspace[16] = (JCOEF) pred;
  151697. }
  151698. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151699. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151700. if (num >= 0) {
  151701. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151702. if (Al > 0 && pred >= (1<<Al))
  151703. pred = (1<<Al)-1;
  151704. } else {
  151705. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151706. if (Al > 0 && pred >= (1<<Al))
  151707. pred = (1<<Al)-1;
  151708. pred = -pred;
  151709. }
  151710. workspace[9] = (JCOEF) pred;
  151711. }
  151712. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151713. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151714. if (num >= 0) {
  151715. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151716. if (Al > 0 && pred >= (1<<Al))
  151717. pred = (1<<Al)-1;
  151718. } else {
  151719. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151720. if (Al > 0 && pred >= (1<<Al))
  151721. pred = (1<<Al)-1;
  151722. pred = -pred;
  151723. }
  151724. workspace[2] = (JCOEF) pred;
  151725. }
  151726. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151727. output_ptr, output_col);
  151728. DC1 = DC2; DC2 = DC3;
  151729. DC4 = DC5; DC5 = DC6;
  151730. DC7 = DC8; DC8 = DC9;
  151731. buffer_ptr++, prev_block_row++, next_block_row++;
  151732. output_col += compptr->DCT_scaled_size;
  151733. }
  151734. output_ptr += compptr->DCT_scaled_size;
  151735. }
  151736. }
  151737. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151738. return JPEG_ROW_COMPLETED;
  151739. return JPEG_SCAN_COMPLETED;
  151740. }
  151741. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151742. GLOBAL(void)
  151743. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151744. {
  151745. my_coef_ptr3 coef;
  151746. coef = (my_coef_ptr3)
  151747. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151748. SIZEOF(my_coef_controller3));
  151749. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151750. coef->pub.start_input_pass = start_input_pass;
  151751. coef->pub.start_output_pass = start_output_pass;
  151752. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151753. coef->coef_bits_latch = NULL;
  151754. #endif
  151755. if (need_full_buffer) {
  151756. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151757. int ci, access_rows;
  151758. jpeg_component_info *compptr;
  151759. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151760. ci++, compptr++) {
  151761. access_rows = compptr->v_samp_factor;
  151762. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151763. if (cinfo->progressive_mode)
  151764. access_rows *= 3;
  151765. #endif
  151766. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151767. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151768. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151769. (long) compptr->h_samp_factor),
  151770. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151771. (long) compptr->v_samp_factor),
  151772. (JDIMENSION) access_rows);
  151773. }
  151774. coef->pub.consume_data = consume_data;
  151775. coef->pub.decompress_data = decompress_data;
  151776. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151777. #else
  151778. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151779. #endif
  151780. } else {
  151781. JBLOCKROW buffer;
  151782. int i;
  151783. buffer = (JBLOCKROW)
  151784. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151785. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151786. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151787. coef->MCU_buffer[i] = buffer + i;
  151788. }
  151789. coef->pub.consume_data = dummy_consume_data;
  151790. coef->pub.decompress_data = decompress_onepass;
  151791. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151792. }
  151793. }
  151794. /*** End of inlined file: jdcoefct.c ***/
  151795. #undef FIX
  151796. /*** Start of inlined file: jdcolor.c ***/
  151797. #define JPEG_INTERNALS
  151798. typedef struct {
  151799. struct jpeg_color_deconverter pub; /* public fields */
  151800. int * Cr_r_tab; /* => table for Cr to R conversion */
  151801. int * Cb_b_tab; /* => table for Cb to B conversion */
  151802. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151803. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151804. } my_color_deconverter2;
  151805. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151806. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151807. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151808. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151809. LOCAL(void)
  151810. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151811. {
  151812. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151813. int i;
  151814. INT32 x;
  151815. SHIFT_TEMPS
  151816. cconvert->Cr_r_tab = (int *)
  151817. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151818. (MAXJSAMPLE+1) * SIZEOF(int));
  151819. cconvert->Cb_b_tab = (int *)
  151820. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151821. (MAXJSAMPLE+1) * SIZEOF(int));
  151822. cconvert->Cr_g_tab = (INT32 *)
  151823. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151824. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151825. cconvert->Cb_g_tab = (INT32 *)
  151826. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151827. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151828. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151829. cconvert->Cr_r_tab[i] = (int)
  151830. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151831. cconvert->Cb_b_tab[i] = (int)
  151832. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151833. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151834. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151835. }
  151836. }
  151837. METHODDEF(void)
  151838. ycc_rgb_convert (j_decompress_ptr cinfo,
  151839. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151840. JSAMPARRAY output_buf, int num_rows)
  151841. {
  151842. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151843. register int y, cb, cr;
  151844. register JSAMPROW outptr;
  151845. register JSAMPROW inptr0, inptr1, inptr2;
  151846. register JDIMENSION col;
  151847. JDIMENSION num_cols = cinfo->output_width;
  151848. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151849. register int * Crrtab = cconvert->Cr_r_tab;
  151850. register int * Cbbtab = cconvert->Cb_b_tab;
  151851. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151852. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151853. SHIFT_TEMPS
  151854. while (--num_rows >= 0) {
  151855. inptr0 = input_buf[0][input_row];
  151856. inptr1 = input_buf[1][input_row];
  151857. inptr2 = input_buf[2][input_row];
  151858. input_row++;
  151859. outptr = *output_buf++;
  151860. for (col = 0; col < num_cols; col++) {
  151861. y = GETJSAMPLE(inptr0[col]);
  151862. cb = GETJSAMPLE(inptr1[col]);
  151863. cr = GETJSAMPLE(inptr2[col]);
  151864. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151865. outptr[RGB_GREEN] = range_limit[y +
  151866. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151867. SCALEBITS))];
  151868. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151869. outptr += RGB_PIXELSIZE;
  151870. }
  151871. }
  151872. }
  151873. METHODDEF(void)
  151874. null_convert2 (j_decompress_ptr cinfo,
  151875. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151876. JSAMPARRAY output_buf, int num_rows)
  151877. {
  151878. register JSAMPROW inptr, outptr;
  151879. register JDIMENSION count;
  151880. register int num_components = cinfo->num_components;
  151881. JDIMENSION num_cols = cinfo->output_width;
  151882. int ci;
  151883. while (--num_rows >= 0) {
  151884. for (ci = 0; ci < num_components; ci++) {
  151885. inptr = input_buf[ci][input_row];
  151886. outptr = output_buf[0] + ci;
  151887. for (count = num_cols; count > 0; count--) {
  151888. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151889. outptr += num_components;
  151890. }
  151891. }
  151892. input_row++;
  151893. output_buf++;
  151894. }
  151895. }
  151896. METHODDEF(void)
  151897. grayscale_convert2 (j_decompress_ptr cinfo,
  151898. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151899. JSAMPARRAY output_buf, int num_rows)
  151900. {
  151901. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151902. num_rows, cinfo->output_width);
  151903. }
  151904. METHODDEF(void)
  151905. gray_rgb_convert (j_decompress_ptr cinfo,
  151906. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151907. JSAMPARRAY output_buf, int num_rows)
  151908. {
  151909. register JSAMPROW inptr, outptr;
  151910. register JDIMENSION col;
  151911. JDIMENSION num_cols = cinfo->output_width;
  151912. while (--num_rows >= 0) {
  151913. inptr = input_buf[0][input_row++];
  151914. outptr = *output_buf++;
  151915. for (col = 0; col < num_cols; col++) {
  151916. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151917. outptr += RGB_PIXELSIZE;
  151918. }
  151919. }
  151920. }
  151921. METHODDEF(void)
  151922. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151923. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151924. JSAMPARRAY output_buf, int num_rows)
  151925. {
  151926. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151927. register int y, cb, cr;
  151928. register JSAMPROW outptr;
  151929. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151930. register JDIMENSION col;
  151931. JDIMENSION num_cols = cinfo->output_width;
  151932. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151933. register int * Crrtab = cconvert->Cr_r_tab;
  151934. register int * Cbbtab = cconvert->Cb_b_tab;
  151935. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151936. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151937. SHIFT_TEMPS
  151938. while (--num_rows >= 0) {
  151939. inptr0 = input_buf[0][input_row];
  151940. inptr1 = input_buf[1][input_row];
  151941. inptr2 = input_buf[2][input_row];
  151942. inptr3 = input_buf[3][input_row];
  151943. input_row++;
  151944. outptr = *output_buf++;
  151945. for (col = 0; col < num_cols; col++) {
  151946. y = GETJSAMPLE(inptr0[col]);
  151947. cb = GETJSAMPLE(inptr1[col]);
  151948. cr = GETJSAMPLE(inptr2[col]);
  151949. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151950. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151951. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151952. SCALEBITS)))];
  151953. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151954. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151955. outptr += 4;
  151956. }
  151957. }
  151958. }
  151959. METHODDEF(void)
  151960. start_pass_dcolor (j_decompress_ptr cinfo)
  151961. {
  151962. }
  151963. GLOBAL(void)
  151964. jinit_color_deconverter (j_decompress_ptr cinfo)
  151965. {
  151966. my_cconvert_ptr2 cconvert;
  151967. int ci;
  151968. cconvert = (my_cconvert_ptr2)
  151969. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151970. SIZEOF(my_color_deconverter2));
  151971. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151972. cconvert->pub.start_pass = start_pass_dcolor;
  151973. switch (cinfo->jpeg_color_space) {
  151974. case JCS_GRAYSCALE:
  151975. if (cinfo->num_components != 1)
  151976. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151977. break;
  151978. case JCS_RGB:
  151979. case JCS_YCbCr:
  151980. if (cinfo->num_components != 3)
  151981. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151982. break;
  151983. case JCS_CMYK:
  151984. case JCS_YCCK:
  151985. if (cinfo->num_components != 4)
  151986. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151987. break;
  151988. default: /* JCS_UNKNOWN can be anything */
  151989. if (cinfo->num_components < 1)
  151990. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151991. break;
  151992. }
  151993. switch (cinfo->out_color_space) {
  151994. case JCS_GRAYSCALE:
  151995. cinfo->out_color_components = 1;
  151996. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151997. cinfo->jpeg_color_space == JCS_YCbCr) {
  151998. cconvert->pub.color_convert = grayscale_convert2;
  151999. for (ci = 1; ci < cinfo->num_components; ci++)
  152000. cinfo->comp_info[ci].component_needed = FALSE;
  152001. } else
  152002. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152003. break;
  152004. case JCS_RGB:
  152005. cinfo->out_color_components = RGB_PIXELSIZE;
  152006. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  152007. cconvert->pub.color_convert = ycc_rgb_convert;
  152008. build_ycc_rgb_table(cinfo);
  152009. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  152010. cconvert->pub.color_convert = gray_rgb_convert;
  152011. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  152012. cconvert->pub.color_convert = null_convert2;
  152013. } else
  152014. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152015. break;
  152016. case JCS_CMYK:
  152017. cinfo->out_color_components = 4;
  152018. if (cinfo->jpeg_color_space == JCS_YCCK) {
  152019. cconvert->pub.color_convert = ycck_cmyk_convert;
  152020. build_ycc_rgb_table(cinfo);
  152021. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  152022. cconvert->pub.color_convert = null_convert2;
  152023. } else
  152024. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152025. break;
  152026. default:
  152027. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  152028. cinfo->out_color_components = cinfo->num_components;
  152029. cconvert->pub.color_convert = null_convert2;
  152030. } else /* unsupported non-null conversion */
  152031. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152032. break;
  152033. }
  152034. if (cinfo->quantize_colors)
  152035. cinfo->output_components = 1; /* single colormapped output component */
  152036. else
  152037. cinfo->output_components = cinfo->out_color_components;
  152038. }
  152039. /*** End of inlined file: jdcolor.c ***/
  152040. #undef FIX
  152041. /*** Start of inlined file: jddctmgr.c ***/
  152042. #define JPEG_INTERNALS
  152043. typedef struct {
  152044. struct jpeg_inverse_dct pub; /* public fields */
  152045. int cur_method[MAX_COMPONENTS];
  152046. } my_idct_controller;
  152047. typedef my_idct_controller * my_idct_ptr;
  152048. typedef union {
  152049. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  152050. #ifdef DCT_IFAST_SUPPORTED
  152051. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  152052. #endif
  152053. #ifdef DCT_FLOAT_SUPPORTED
  152054. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  152055. #endif
  152056. } multiplier_table;
  152057. #ifdef DCT_ISLOW_SUPPORTED
  152058. #define PROVIDE_ISLOW_TABLES
  152059. #else
  152060. #ifdef IDCT_SCALING_SUPPORTED
  152061. #define PROVIDE_ISLOW_TABLES
  152062. #endif
  152063. #endif
  152064. METHODDEF(void)
  152065. start_pass (j_decompress_ptr cinfo)
  152066. {
  152067. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  152068. int ci, i;
  152069. jpeg_component_info *compptr;
  152070. int method = 0;
  152071. inverse_DCT_method_ptr method_ptr = NULL;
  152072. JQUANT_TBL * qtbl;
  152073. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152074. ci++, compptr++) {
  152075. switch (compptr->DCT_scaled_size) {
  152076. #ifdef IDCT_SCALING_SUPPORTED
  152077. case 1:
  152078. method_ptr = jpeg_idct_1x1;
  152079. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152080. break;
  152081. case 2:
  152082. method_ptr = jpeg_idct_2x2;
  152083. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152084. break;
  152085. case 4:
  152086. method_ptr = jpeg_idct_4x4;
  152087. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152088. break;
  152089. #endif
  152090. case DCTSIZE:
  152091. switch (cinfo->dct_method) {
  152092. #ifdef DCT_ISLOW_SUPPORTED
  152093. case JDCT_ISLOW:
  152094. method_ptr = jpeg_idct_islow;
  152095. method = JDCT_ISLOW;
  152096. break;
  152097. #endif
  152098. #ifdef DCT_IFAST_SUPPORTED
  152099. case JDCT_IFAST:
  152100. method_ptr = jpeg_idct_ifast;
  152101. method = JDCT_IFAST;
  152102. break;
  152103. #endif
  152104. #ifdef DCT_FLOAT_SUPPORTED
  152105. case JDCT_FLOAT:
  152106. method_ptr = jpeg_idct_float;
  152107. method = JDCT_FLOAT;
  152108. break;
  152109. #endif
  152110. default:
  152111. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152112. break;
  152113. }
  152114. break;
  152115. default:
  152116. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  152117. break;
  152118. }
  152119. idct->pub.inverse_DCT[ci] = method_ptr;
  152120. if (! compptr->component_needed || idct->cur_method[ci] == method)
  152121. continue;
  152122. qtbl = compptr->quant_table;
  152123. if (qtbl == NULL) /* happens if no data yet for component */
  152124. continue;
  152125. idct->cur_method[ci] = method;
  152126. switch (method) {
  152127. #ifdef PROVIDE_ISLOW_TABLES
  152128. case JDCT_ISLOW:
  152129. {
  152130. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  152131. for (i = 0; i < DCTSIZE2; i++) {
  152132. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  152133. }
  152134. }
  152135. break;
  152136. #endif
  152137. #ifdef DCT_IFAST_SUPPORTED
  152138. case JDCT_IFAST:
  152139. {
  152140. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  152141. #define CONST_BITS 14
  152142. static const INT16 aanscales[DCTSIZE2] = {
  152143. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152144. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  152145. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  152146. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  152147. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152148. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  152149. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  152150. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  152151. };
  152152. SHIFT_TEMPS
  152153. for (i = 0; i < DCTSIZE2; i++) {
  152154. ifmtbl[i] = (IFAST_MULT_TYPE)
  152155. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  152156. (INT32) aanscales[i]),
  152157. CONST_BITS-IFAST_SCALE_BITS);
  152158. }
  152159. }
  152160. break;
  152161. #endif
  152162. #ifdef DCT_FLOAT_SUPPORTED
  152163. case JDCT_FLOAT:
  152164. {
  152165. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  152166. int row, col;
  152167. static const double aanscalefactor[DCTSIZE] = {
  152168. 1.0, 1.387039845, 1.306562965, 1.175875602,
  152169. 1.0, 0.785694958, 0.541196100, 0.275899379
  152170. };
  152171. i = 0;
  152172. for (row = 0; row < DCTSIZE; row++) {
  152173. for (col = 0; col < DCTSIZE; col++) {
  152174. fmtbl[i] = (FLOAT_MULT_TYPE)
  152175. ((double) qtbl->quantval[i] *
  152176. aanscalefactor[row] * aanscalefactor[col]);
  152177. i++;
  152178. }
  152179. }
  152180. }
  152181. break;
  152182. #endif
  152183. default:
  152184. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152185. break;
  152186. }
  152187. }
  152188. }
  152189. GLOBAL(void)
  152190. jinit_inverse_dct (j_decompress_ptr cinfo)
  152191. {
  152192. my_idct_ptr idct;
  152193. int ci;
  152194. jpeg_component_info *compptr;
  152195. idct = (my_idct_ptr)
  152196. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152197. SIZEOF(my_idct_controller));
  152198. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  152199. idct->pub.start_pass = start_pass;
  152200. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152201. ci++, compptr++) {
  152202. compptr->dct_table =
  152203. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152204. SIZEOF(multiplier_table));
  152205. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  152206. idct->cur_method[ci] = -1;
  152207. }
  152208. }
  152209. /*** End of inlined file: jddctmgr.c ***/
  152210. #undef CONST_BITS
  152211. #undef ASSIGN_STATE
  152212. /*** Start of inlined file: jdhuff.c ***/
  152213. #define JPEG_INTERNALS
  152214. /*** Start of inlined file: jdhuff.h ***/
  152215. #ifndef __jdhuff_h__
  152216. #define __jdhuff_h__
  152217. #ifdef NEED_SHORT_EXTERNAL_NAMES
  152218. #define jpeg_make_d_derived_tbl jMkDDerived
  152219. #define jpeg_fill_bit_buffer jFilBitBuf
  152220. #define jpeg_huff_decode jHufDecode
  152221. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  152222. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  152223. typedef struct {
  152224. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  152225. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  152226. JHUFF_TBL *pub;
  152227. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  152228. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  152229. } d_derived_tbl;
  152230. EXTERN(void) jpeg_make_d_derived_tbl
  152231. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  152232. d_derived_tbl ** pdtbl));
  152233. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  152234. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  152235. typedef struct { /* Bitreading state saved across MCUs */
  152236. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152237. int bits_left; /* # of unused bits in it */
  152238. } bitread_perm_state;
  152239. typedef struct { /* Bitreading working state within an MCU */
  152240. const JOCTET * next_input_byte; /* => next byte to read from source */
  152241. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  152242. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152243. int bits_left; /* # of unused bits in it */
  152244. j_decompress_ptr cinfo; /* back link to decompress master record */
  152245. } bitread_working_state;
  152246. #define BITREAD_STATE_VARS \
  152247. register bit_buf_type get_buffer; \
  152248. register int bits_left; \
  152249. bitread_working_state br_state
  152250. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  152251. br_state.cinfo = cinfop; \
  152252. br_state.next_input_byte = cinfop->src->next_input_byte; \
  152253. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  152254. get_buffer = permstate.get_buffer; \
  152255. bits_left = permstate.bits_left;
  152256. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  152257. cinfop->src->next_input_byte = br_state.next_input_byte; \
  152258. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  152259. permstate.get_buffer = get_buffer; \
  152260. permstate.bits_left = bits_left
  152261. #define CHECK_BIT_BUFFER(state,nbits,action) \
  152262. { if (bits_left < (nbits)) { \
  152263. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  152264. { action; } \
  152265. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  152266. #define GET_BITS(nbits) \
  152267. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  152268. #define PEEK_BITS(nbits) \
  152269. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  152270. #define DROP_BITS(nbits) \
  152271. (bits_left -= (nbits))
  152272. EXTERN(boolean) jpeg_fill_bit_buffer
  152273. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152274. register int bits_left, int nbits));
  152275. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  152276. { register int nb, look; \
  152277. if (bits_left < HUFF_LOOKAHEAD) { \
  152278. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  152279. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152280. if (bits_left < HUFF_LOOKAHEAD) { \
  152281. nb = 1; goto slowlabel; \
  152282. } \
  152283. } \
  152284. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  152285. if ((nb = htbl->look_nbits[look]) != 0) { \
  152286. DROP_BITS(nb); \
  152287. result = htbl->look_sym[look]; \
  152288. } else { \
  152289. nb = HUFF_LOOKAHEAD+1; \
  152290. slowlabel: \
  152291. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  152292. { failaction; } \
  152293. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152294. } \
  152295. }
  152296. EXTERN(int) jpeg_huff_decode
  152297. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152298. register int bits_left, d_derived_tbl * htbl, int min_bits));
  152299. #endif
  152300. /*** End of inlined file: jdhuff.h ***/
  152301. /* Declarations shared with jdphuff.c */
  152302. typedef struct {
  152303. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  152304. } savable_state2;
  152305. #ifndef NO_STRUCT_ASSIGN
  152306. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  152307. #else
  152308. #if MAX_COMPS_IN_SCAN == 4
  152309. #define ASSIGN_STATE(dest,src) \
  152310. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  152311. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  152312. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  152313. (dest).last_dc_val[3] = (src).last_dc_val[3])
  152314. #endif
  152315. #endif
  152316. typedef struct {
  152317. struct jpeg_entropy_decoder pub; /* public fields */
  152318. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  152319. savable_state2 saved; /* Other state at start of MCU */
  152320. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  152321. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  152322. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  152323. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152324. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152325. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  152326. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  152327. } huff_entropy_decoder2;
  152328. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  152329. METHODDEF(void)
  152330. start_pass_huff_decoder (j_decompress_ptr cinfo)
  152331. {
  152332. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152333. int ci, blkn, dctbl, actbl;
  152334. jpeg_component_info * compptr;
  152335. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  152336. cinfo->Ah != 0 || cinfo->Al != 0)
  152337. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  152338. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152339. compptr = cinfo->cur_comp_info[ci];
  152340. dctbl = compptr->dc_tbl_no;
  152341. actbl = compptr->ac_tbl_no;
  152342. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  152343. & entropy->dc_derived_tbls[dctbl]);
  152344. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  152345. & entropy->ac_derived_tbls[actbl]);
  152346. entropy->saved.last_dc_val[ci] = 0;
  152347. }
  152348. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152349. ci = cinfo->MCU_membership[blkn];
  152350. compptr = cinfo->cur_comp_info[ci];
  152351. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  152352. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  152353. if (compptr->component_needed) {
  152354. entropy->dc_needed[blkn] = TRUE;
  152355. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  152356. } else {
  152357. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  152358. }
  152359. }
  152360. entropy->bitstate.bits_left = 0;
  152361. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  152362. entropy->pub.insufficient_data = FALSE;
  152363. entropy->restarts_to_go = cinfo->restart_interval;
  152364. }
  152365. GLOBAL(void)
  152366. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  152367. d_derived_tbl ** pdtbl)
  152368. {
  152369. JHUFF_TBL *htbl;
  152370. d_derived_tbl *dtbl;
  152371. int p, i, l, si, numsymbols;
  152372. int lookbits, ctr;
  152373. char huffsize[257];
  152374. unsigned int huffcode[257];
  152375. unsigned int code;
  152376. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  152377. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152378. htbl =
  152379. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  152380. if (htbl == NULL)
  152381. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152382. if (*pdtbl == NULL)
  152383. *pdtbl = (d_derived_tbl *)
  152384. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152385. SIZEOF(d_derived_tbl));
  152386. dtbl = *pdtbl;
  152387. dtbl->pub = htbl; /* fill in back link */
  152388. p = 0;
  152389. for (l = 1; l <= 16; l++) {
  152390. i = (int) htbl->bits[l];
  152391. if (i < 0 || p + i > 256) /* protect against table overrun */
  152392. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152393. while (i--)
  152394. huffsize[p++] = (char) l;
  152395. }
  152396. huffsize[p] = 0;
  152397. numsymbols = p;
  152398. code = 0;
  152399. si = huffsize[0];
  152400. p = 0;
  152401. while (huffsize[p]) {
  152402. while (((int) huffsize[p]) == si) {
  152403. huffcode[p++] = code;
  152404. code++;
  152405. }
  152406. if (((INT32) code) >= (((INT32) 1) << si))
  152407. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152408. code <<= 1;
  152409. si++;
  152410. }
  152411. p = 0;
  152412. for (l = 1; l <= 16; l++) {
  152413. if (htbl->bits[l]) {
  152414. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  152415. p += htbl->bits[l];
  152416. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  152417. } else {
  152418. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  152419. }
  152420. }
  152421. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  152422. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  152423. p = 0;
  152424. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  152425. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  152426. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  152427. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  152428. dtbl->look_nbits[lookbits] = l;
  152429. dtbl->look_sym[lookbits] = htbl->huffval[p];
  152430. lookbits++;
  152431. }
  152432. }
  152433. }
  152434. if (isDC) {
  152435. for (i = 0; i < numsymbols; i++) {
  152436. int sym = htbl->huffval[i];
  152437. if (sym < 0 || sym > 15)
  152438. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152439. }
  152440. }
  152441. }
  152442. #ifdef SLOW_SHIFT_32
  152443. #define MIN_GET_BITS 15 /* minimum allowable value */
  152444. #else
  152445. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  152446. #endif
  152447. GLOBAL(boolean)
  152448. jpeg_fill_bit_buffer (bitread_working_state * state,
  152449. register bit_buf_type get_buffer, register int bits_left,
  152450. int nbits)
  152451. {
  152452. register const JOCTET * next_input_byte = state->next_input_byte;
  152453. register size_t bytes_in_buffer = state->bytes_in_buffer;
  152454. j_decompress_ptr cinfo = state->cinfo;
  152455. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  152456. while (bits_left < MIN_GET_BITS) {
  152457. register int c;
  152458. if (bytes_in_buffer == 0) {
  152459. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152460. return FALSE;
  152461. next_input_byte = cinfo->src->next_input_byte;
  152462. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152463. }
  152464. bytes_in_buffer--;
  152465. c = GETJOCTET(*next_input_byte++);
  152466. if (c == 0xFF) {
  152467. do {
  152468. if (bytes_in_buffer == 0) {
  152469. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152470. return FALSE;
  152471. next_input_byte = cinfo->src->next_input_byte;
  152472. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152473. }
  152474. bytes_in_buffer--;
  152475. c = GETJOCTET(*next_input_byte++);
  152476. } while (c == 0xFF);
  152477. if (c == 0) {
  152478. c = 0xFF;
  152479. } else {
  152480. cinfo->unread_marker = c;
  152481. goto no_more_bytes;
  152482. }
  152483. }
  152484. get_buffer = (get_buffer << 8) | c;
  152485. bits_left += 8;
  152486. } /* end while */
  152487. } else {
  152488. no_more_bytes:
  152489. if (nbits > bits_left) {
  152490. if (! cinfo->entropy->insufficient_data) {
  152491. WARNMS(cinfo, JWRN_HIT_MARKER);
  152492. cinfo->entropy->insufficient_data = TRUE;
  152493. }
  152494. get_buffer <<= MIN_GET_BITS - bits_left;
  152495. bits_left = MIN_GET_BITS;
  152496. }
  152497. }
  152498. state->next_input_byte = next_input_byte;
  152499. state->bytes_in_buffer = bytes_in_buffer;
  152500. state->get_buffer = get_buffer;
  152501. state->bits_left = bits_left;
  152502. return TRUE;
  152503. }
  152504. GLOBAL(int)
  152505. jpeg_huff_decode (bitread_working_state * state,
  152506. register bit_buf_type get_buffer, register int bits_left,
  152507. d_derived_tbl * htbl, int min_bits)
  152508. {
  152509. register int l = min_bits;
  152510. register INT32 code;
  152511. CHECK_BIT_BUFFER(*state, l, return -1);
  152512. code = GET_BITS(l);
  152513. while (code > htbl->maxcode[l]) {
  152514. code <<= 1;
  152515. CHECK_BIT_BUFFER(*state, 1, return -1);
  152516. code |= GET_BITS(1);
  152517. l++;
  152518. }
  152519. state->get_buffer = get_buffer;
  152520. state->bits_left = bits_left;
  152521. if (l > 16) {
  152522. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152523. return 0; /* fake a zero as the safest result */
  152524. }
  152525. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152526. }
  152527. LOCAL(boolean)
  152528. process_restart (j_decompress_ptr cinfo)
  152529. {
  152530. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152531. int ci;
  152532. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152533. entropy->bitstate.bits_left = 0;
  152534. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152535. return FALSE;
  152536. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152537. entropy->saved.last_dc_val[ci] = 0;
  152538. entropy->restarts_to_go = cinfo->restart_interval;
  152539. if (cinfo->unread_marker == 0)
  152540. entropy->pub.insufficient_data = FALSE;
  152541. return TRUE;
  152542. }
  152543. METHODDEF(boolean)
  152544. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152545. {
  152546. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152547. int blkn;
  152548. BITREAD_STATE_VARS;
  152549. savable_state2 state;
  152550. if (cinfo->restart_interval) {
  152551. if (entropy->restarts_to_go == 0)
  152552. if (! process_restart(cinfo))
  152553. return FALSE;
  152554. }
  152555. if (! entropy->pub.insufficient_data) {
  152556. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152557. ASSIGN_STATE(state, entropy->saved);
  152558. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152559. JBLOCKROW block = MCU_data[blkn];
  152560. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152561. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152562. register int s, k, r;
  152563. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152564. if (s) {
  152565. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152566. r = GET_BITS(s);
  152567. s = HUFF_EXTEND(r, s);
  152568. }
  152569. if (entropy->dc_needed[blkn]) {
  152570. int ci = cinfo->MCU_membership[blkn];
  152571. s += state.last_dc_val[ci];
  152572. state.last_dc_val[ci] = s;
  152573. (*block)[0] = (JCOEF) s;
  152574. }
  152575. if (entropy->ac_needed[blkn]) {
  152576. for (k = 1; k < DCTSIZE2; k++) {
  152577. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152578. r = s >> 4;
  152579. s &= 15;
  152580. if (s) {
  152581. k += r;
  152582. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152583. r = GET_BITS(s);
  152584. s = HUFF_EXTEND(r, s);
  152585. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152586. } else {
  152587. if (r != 15)
  152588. break;
  152589. k += 15;
  152590. }
  152591. }
  152592. } else {
  152593. for (k = 1; k < DCTSIZE2; k++) {
  152594. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152595. r = s >> 4;
  152596. s &= 15;
  152597. if (s) {
  152598. k += r;
  152599. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152600. DROP_BITS(s);
  152601. } else {
  152602. if (r != 15)
  152603. break;
  152604. k += 15;
  152605. }
  152606. }
  152607. }
  152608. }
  152609. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152610. ASSIGN_STATE(entropy->saved, state);
  152611. }
  152612. entropy->restarts_to_go--;
  152613. return TRUE;
  152614. }
  152615. GLOBAL(void)
  152616. jinit_huff_decoder (j_decompress_ptr cinfo)
  152617. {
  152618. huff_entropy_ptr2 entropy;
  152619. int i;
  152620. entropy = (huff_entropy_ptr2)
  152621. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152622. SIZEOF(huff_entropy_decoder2));
  152623. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152624. entropy->pub.start_pass = start_pass_huff_decoder;
  152625. entropy->pub.decode_mcu = decode_mcu;
  152626. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152627. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152628. }
  152629. }
  152630. /*** End of inlined file: jdhuff.c ***/
  152631. /*** Start of inlined file: jdinput.c ***/
  152632. #define JPEG_INTERNALS
  152633. typedef struct {
  152634. struct jpeg_input_controller pub; /* public fields */
  152635. boolean inheaders; /* TRUE until first SOS is reached */
  152636. } my_input_controller;
  152637. typedef my_input_controller * my_inputctl_ptr;
  152638. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152639. LOCAL(void)
  152640. initial_setup2 (j_decompress_ptr cinfo)
  152641. {
  152642. int ci;
  152643. jpeg_component_info *compptr;
  152644. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152645. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152646. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152647. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152648. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152649. if (cinfo->num_components > MAX_COMPONENTS)
  152650. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152651. MAX_COMPONENTS);
  152652. cinfo->max_h_samp_factor = 1;
  152653. cinfo->max_v_samp_factor = 1;
  152654. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152655. ci++, compptr++) {
  152656. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152657. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152658. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152659. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152660. compptr->h_samp_factor);
  152661. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152662. compptr->v_samp_factor);
  152663. }
  152664. cinfo->min_DCT_scaled_size = DCTSIZE;
  152665. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152666. ci++, compptr++) {
  152667. compptr->DCT_scaled_size = DCTSIZE;
  152668. compptr->width_in_blocks = (JDIMENSION)
  152669. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152670. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152671. compptr->height_in_blocks = (JDIMENSION)
  152672. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152673. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152674. compptr->downsampled_width = (JDIMENSION)
  152675. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152676. (long) cinfo->max_h_samp_factor);
  152677. compptr->downsampled_height = (JDIMENSION)
  152678. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152679. (long) cinfo->max_v_samp_factor);
  152680. compptr->component_needed = TRUE;
  152681. compptr->quant_table = NULL;
  152682. }
  152683. cinfo->total_iMCU_rows = (JDIMENSION)
  152684. jdiv_round_up((long) cinfo->image_height,
  152685. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152686. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152687. cinfo->inputctl->has_multiple_scans = TRUE;
  152688. else
  152689. cinfo->inputctl->has_multiple_scans = FALSE;
  152690. }
  152691. LOCAL(void)
  152692. per_scan_setup2 (j_decompress_ptr cinfo)
  152693. {
  152694. int ci, mcublks, tmp;
  152695. jpeg_component_info *compptr;
  152696. if (cinfo->comps_in_scan == 1) {
  152697. compptr = cinfo->cur_comp_info[0];
  152698. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152699. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152700. compptr->MCU_width = 1;
  152701. compptr->MCU_height = 1;
  152702. compptr->MCU_blocks = 1;
  152703. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152704. compptr->last_col_width = 1;
  152705. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152706. if (tmp == 0) tmp = compptr->v_samp_factor;
  152707. compptr->last_row_height = tmp;
  152708. cinfo->blocks_in_MCU = 1;
  152709. cinfo->MCU_membership[0] = 0;
  152710. } else {
  152711. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152712. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152713. MAX_COMPS_IN_SCAN);
  152714. cinfo->MCUs_per_row = (JDIMENSION)
  152715. jdiv_round_up((long) cinfo->image_width,
  152716. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152717. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152718. jdiv_round_up((long) cinfo->image_height,
  152719. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152720. cinfo->blocks_in_MCU = 0;
  152721. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152722. compptr = cinfo->cur_comp_info[ci];
  152723. compptr->MCU_width = compptr->h_samp_factor;
  152724. compptr->MCU_height = compptr->v_samp_factor;
  152725. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152726. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152727. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152728. if (tmp == 0) tmp = compptr->MCU_width;
  152729. compptr->last_col_width = tmp;
  152730. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152731. if (tmp == 0) tmp = compptr->MCU_height;
  152732. compptr->last_row_height = tmp;
  152733. mcublks = compptr->MCU_blocks;
  152734. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152735. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152736. while (mcublks-- > 0) {
  152737. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152738. }
  152739. }
  152740. }
  152741. }
  152742. LOCAL(void)
  152743. latch_quant_tables (j_decompress_ptr cinfo)
  152744. {
  152745. int ci, qtblno;
  152746. jpeg_component_info *compptr;
  152747. JQUANT_TBL * qtbl;
  152748. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152749. compptr = cinfo->cur_comp_info[ci];
  152750. if (compptr->quant_table != NULL)
  152751. continue;
  152752. qtblno = compptr->quant_tbl_no;
  152753. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152754. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152755. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152756. qtbl = (JQUANT_TBL *)
  152757. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152758. SIZEOF(JQUANT_TBL));
  152759. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152760. compptr->quant_table = qtbl;
  152761. }
  152762. }
  152763. METHODDEF(void)
  152764. start_input_pass2 (j_decompress_ptr cinfo)
  152765. {
  152766. per_scan_setup2(cinfo);
  152767. latch_quant_tables(cinfo);
  152768. (*cinfo->entropy->start_pass) (cinfo);
  152769. (*cinfo->coef->start_input_pass) (cinfo);
  152770. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152771. }
  152772. METHODDEF(void)
  152773. finish_input_pass (j_decompress_ptr cinfo)
  152774. {
  152775. cinfo->inputctl->consume_input = consume_markers;
  152776. }
  152777. METHODDEF(int)
  152778. consume_markers (j_decompress_ptr cinfo)
  152779. {
  152780. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152781. int val;
  152782. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152783. return JPEG_REACHED_EOI;
  152784. val = (*cinfo->marker->read_markers) (cinfo);
  152785. switch (val) {
  152786. case JPEG_REACHED_SOS: /* Found SOS */
  152787. if (inputctl->inheaders) { /* 1st SOS */
  152788. initial_setup2(cinfo);
  152789. inputctl->inheaders = FALSE;
  152790. } else { /* 2nd or later SOS marker */
  152791. if (! inputctl->pub.has_multiple_scans)
  152792. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152793. start_input_pass2(cinfo);
  152794. }
  152795. break;
  152796. case JPEG_REACHED_EOI: /* Found EOI */
  152797. inputctl->pub.eoi_reached = TRUE;
  152798. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152799. if (cinfo->marker->saw_SOF)
  152800. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152801. } else {
  152802. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152803. cinfo->output_scan_number = cinfo->input_scan_number;
  152804. }
  152805. break;
  152806. case JPEG_SUSPENDED:
  152807. break;
  152808. }
  152809. return val;
  152810. }
  152811. METHODDEF(void)
  152812. reset_input_controller (j_decompress_ptr cinfo)
  152813. {
  152814. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152815. inputctl->pub.consume_input = consume_markers;
  152816. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152817. inputctl->pub.eoi_reached = FALSE;
  152818. inputctl->inheaders = TRUE;
  152819. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152820. (*cinfo->marker->reset_marker_reader) (cinfo);
  152821. cinfo->coef_bits = NULL;
  152822. }
  152823. GLOBAL(void)
  152824. jinit_input_controller (j_decompress_ptr cinfo)
  152825. {
  152826. my_inputctl_ptr inputctl;
  152827. inputctl = (my_inputctl_ptr)
  152828. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152829. SIZEOF(my_input_controller));
  152830. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152831. inputctl->pub.consume_input = consume_markers;
  152832. inputctl->pub.reset_input_controller = reset_input_controller;
  152833. inputctl->pub.start_input_pass = start_input_pass2;
  152834. inputctl->pub.finish_input_pass = finish_input_pass;
  152835. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152836. inputctl->pub.eoi_reached = FALSE;
  152837. inputctl->inheaders = TRUE;
  152838. }
  152839. /*** End of inlined file: jdinput.c ***/
  152840. /*** Start of inlined file: jdmainct.c ***/
  152841. #define JPEG_INTERNALS
  152842. typedef struct {
  152843. struct jpeg_d_main_controller pub; /* public fields */
  152844. JSAMPARRAY buffer[MAX_COMPONENTS];
  152845. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152846. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152847. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152848. int whichptr; /* indicates which pointer set is now in use */
  152849. int context_state; /* process_data state machine status */
  152850. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152851. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152852. } my_main_controller4;
  152853. typedef my_main_controller4 * my_main_ptr4;
  152854. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152855. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152856. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152857. METHODDEF(void) process_data_simple_main2
  152858. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152859. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152860. METHODDEF(void) process_data_context_main
  152861. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152862. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152863. #ifdef QUANT_2PASS_SUPPORTED
  152864. METHODDEF(void) process_data_crank_post
  152865. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152866. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152867. #endif
  152868. LOCAL(void)
  152869. alloc_funny_pointers (j_decompress_ptr cinfo)
  152870. {
  152871. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152872. int ci, rgroup;
  152873. int M = cinfo->min_DCT_scaled_size;
  152874. jpeg_component_info *compptr;
  152875. JSAMPARRAY xbuf;
  152876. main_->xbuffer[0] = (JSAMPIMAGE)
  152877. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152878. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152879. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152880. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152881. ci++, compptr++) {
  152882. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152883. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152884. xbuf = (JSAMPARRAY)
  152885. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152886. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152887. xbuf += rgroup; /* want one row group at negative offsets */
  152888. main_->xbuffer[0][ci] = xbuf;
  152889. xbuf += rgroup * (M + 4);
  152890. main_->xbuffer[1][ci] = xbuf;
  152891. }
  152892. }
  152893. LOCAL(void)
  152894. make_funny_pointers (j_decompress_ptr cinfo)
  152895. {
  152896. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152897. int ci, i, rgroup;
  152898. int M = cinfo->min_DCT_scaled_size;
  152899. jpeg_component_info *compptr;
  152900. JSAMPARRAY buf, xbuf0, xbuf1;
  152901. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152902. ci++, compptr++) {
  152903. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152904. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152905. xbuf0 = main_->xbuffer[0][ci];
  152906. xbuf1 = main_->xbuffer[1][ci];
  152907. buf = main_->buffer[ci];
  152908. for (i = 0; i < rgroup * (M + 2); i++) {
  152909. xbuf0[i] = xbuf1[i] = buf[i];
  152910. }
  152911. for (i = 0; i < rgroup * 2; i++) {
  152912. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152913. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152914. }
  152915. for (i = 0; i < rgroup; i++) {
  152916. xbuf0[i - rgroup] = xbuf0[0];
  152917. }
  152918. }
  152919. }
  152920. LOCAL(void)
  152921. set_wraparound_pointers (j_decompress_ptr cinfo)
  152922. {
  152923. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152924. int ci, i, rgroup;
  152925. int M = cinfo->min_DCT_scaled_size;
  152926. jpeg_component_info *compptr;
  152927. JSAMPARRAY xbuf0, xbuf1;
  152928. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152929. ci++, compptr++) {
  152930. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152931. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152932. xbuf0 = main_->xbuffer[0][ci];
  152933. xbuf1 = main_->xbuffer[1][ci];
  152934. for (i = 0; i < rgroup; i++) {
  152935. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152936. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152937. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152938. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152939. }
  152940. }
  152941. }
  152942. LOCAL(void)
  152943. set_bottom_pointers (j_decompress_ptr cinfo)
  152944. {
  152945. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152946. int ci, i, rgroup, iMCUheight, rows_left;
  152947. jpeg_component_info *compptr;
  152948. JSAMPARRAY xbuf;
  152949. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152950. ci++, compptr++) {
  152951. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152952. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152953. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152954. if (rows_left == 0) rows_left = iMCUheight;
  152955. if (ci == 0) {
  152956. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152957. }
  152958. xbuf = main_->xbuffer[main_->whichptr][ci];
  152959. for (i = 0; i < rgroup * 2; i++) {
  152960. xbuf[rows_left + i] = xbuf[rows_left-1];
  152961. }
  152962. }
  152963. }
  152964. METHODDEF(void)
  152965. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152966. {
  152967. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152968. switch (pass_mode) {
  152969. case JBUF_PASS_THRU:
  152970. if (cinfo->upsample->need_context_rows) {
  152971. main_->pub.process_data = process_data_context_main;
  152972. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152973. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152974. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152975. main_->iMCU_row_ctr = 0;
  152976. } else {
  152977. main_->pub.process_data = process_data_simple_main2;
  152978. }
  152979. main_->buffer_full = FALSE; /* Mark buffer empty */
  152980. main_->rowgroup_ctr = 0;
  152981. break;
  152982. #ifdef QUANT_2PASS_SUPPORTED
  152983. case JBUF_CRANK_DEST:
  152984. main_->pub.process_data = process_data_crank_post;
  152985. break;
  152986. #endif
  152987. default:
  152988. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152989. break;
  152990. }
  152991. }
  152992. METHODDEF(void)
  152993. process_data_simple_main2 (j_decompress_ptr cinfo,
  152994. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152995. JDIMENSION out_rows_avail)
  152996. {
  152997. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152998. JDIMENSION rowgroups_avail;
  152999. if (! main_->buffer_full) {
  153000. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  153001. return; /* suspension forced, can do nothing more */
  153002. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  153003. }
  153004. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  153005. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  153006. &main_->rowgroup_ctr, rowgroups_avail,
  153007. output_buf, out_row_ctr, out_rows_avail);
  153008. if (main_->rowgroup_ctr >= rowgroups_avail) {
  153009. main_->buffer_full = FALSE;
  153010. main_->rowgroup_ctr = 0;
  153011. }
  153012. }
  153013. METHODDEF(void)
  153014. process_data_context_main (j_decompress_ptr cinfo,
  153015. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153016. JDIMENSION out_rows_avail)
  153017. {
  153018. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153019. if (! main_->buffer_full) {
  153020. if (! (*cinfo->coef->decompress_data) (cinfo,
  153021. main_->xbuffer[main_->whichptr]))
  153022. return; /* suspension forced, can do nothing more */
  153023. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  153024. main_->iMCU_row_ctr++; /* count rows received */
  153025. }
  153026. switch (main_->context_state) {
  153027. case CTX_POSTPONED_ROW:
  153028. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  153029. &main_->rowgroup_ctr, main_->rowgroups_avail,
  153030. output_buf, out_row_ctr, out_rows_avail);
  153031. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  153032. return; /* Need to suspend */
  153033. main_->context_state = CTX_PREPARE_FOR_IMCU;
  153034. if (*out_row_ctr >= out_rows_avail)
  153035. return; /* Postprocessor exactly filled output buf */
  153036. case CTX_PREPARE_FOR_IMCU:
  153037. main_->rowgroup_ctr = 0;
  153038. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  153039. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  153040. set_bottom_pointers(cinfo);
  153041. main_->context_state = CTX_PROCESS_IMCU;
  153042. case CTX_PROCESS_IMCU:
  153043. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  153044. &main_->rowgroup_ctr, main_->rowgroups_avail,
  153045. output_buf, out_row_ctr, out_rows_avail);
  153046. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  153047. return; /* Need to suspend */
  153048. if (main_->iMCU_row_ctr == 1)
  153049. set_wraparound_pointers(cinfo);
  153050. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  153051. main_->buffer_full = FALSE;
  153052. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  153053. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  153054. main_->context_state = CTX_POSTPONED_ROW;
  153055. }
  153056. }
  153057. #ifdef QUANT_2PASS_SUPPORTED
  153058. METHODDEF(void)
  153059. process_data_crank_post (j_decompress_ptr cinfo,
  153060. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153061. JDIMENSION out_rows_avail)
  153062. {
  153063. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  153064. (JDIMENSION *) NULL, (JDIMENSION) 0,
  153065. output_buf, out_row_ctr, out_rows_avail);
  153066. }
  153067. #endif /* QUANT_2PASS_SUPPORTED */
  153068. GLOBAL(void)
  153069. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  153070. {
  153071. my_main_ptr4 main_;
  153072. int ci, rgroup, ngroups;
  153073. jpeg_component_info *compptr;
  153074. main_ = (my_main_ptr4)
  153075. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153076. SIZEOF(my_main_controller4));
  153077. cinfo->main = (struct jpeg_d_main_controller *) main_;
  153078. main_->pub.start_pass = start_pass_main2;
  153079. if (need_full_buffer) /* shouldn't happen */
  153080. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  153081. if (cinfo->upsample->need_context_rows) {
  153082. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  153083. ERREXIT(cinfo, JERR_NOTIMPL);
  153084. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  153085. ngroups = cinfo->min_DCT_scaled_size + 2;
  153086. } else {
  153087. ngroups = cinfo->min_DCT_scaled_size;
  153088. }
  153089. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153090. ci++, compptr++) {
  153091. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  153092. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  153093. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  153094. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153095. compptr->width_in_blocks * compptr->DCT_scaled_size,
  153096. (JDIMENSION) (rgroup * ngroups));
  153097. }
  153098. }
  153099. /*** End of inlined file: jdmainct.c ***/
  153100. /*** Start of inlined file: jdmarker.c ***/
  153101. #define JPEG_INTERNALS
  153102. typedef struct {
  153103. struct jpeg_marker_reader pub; /* public fields */
  153104. jpeg_marker_parser_method process_COM;
  153105. jpeg_marker_parser_method process_APPn[16];
  153106. unsigned int length_limit_COM;
  153107. unsigned int length_limit_APPn[16];
  153108. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  153109. unsigned int bytes_read; /* data bytes read so far in marker */
  153110. } my_marker_reader;
  153111. typedef my_marker_reader * my_marker_ptr2;
  153112. #define INPUT_VARS(cinfo) \
  153113. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  153114. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  153115. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  153116. #define INPUT_SYNC(cinfo) \
  153117. ( datasrc->next_input_byte = next_input_byte, \
  153118. datasrc->bytes_in_buffer = bytes_in_buffer )
  153119. #define INPUT_RELOAD(cinfo) \
  153120. ( next_input_byte = datasrc->next_input_byte, \
  153121. bytes_in_buffer = datasrc->bytes_in_buffer )
  153122. #define MAKE_BYTE_AVAIL(cinfo,action) \
  153123. if (bytes_in_buffer == 0) { \
  153124. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  153125. { action; } \
  153126. INPUT_RELOAD(cinfo); \
  153127. }
  153128. #define INPUT_BYTE(cinfo,V,action) \
  153129. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153130. bytes_in_buffer--; \
  153131. V = GETJOCTET(*next_input_byte++); )
  153132. #define INPUT_2BYTES(cinfo,V,action) \
  153133. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153134. bytes_in_buffer--; \
  153135. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  153136. MAKE_BYTE_AVAIL(cinfo,action); \
  153137. bytes_in_buffer--; \
  153138. V += GETJOCTET(*next_input_byte++); )
  153139. LOCAL(boolean)
  153140. get_soi (j_decompress_ptr cinfo)
  153141. {
  153142. int i;
  153143. TRACEMS(cinfo, 1, JTRC_SOI);
  153144. if (cinfo->marker->saw_SOI)
  153145. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  153146. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  153147. cinfo->arith_dc_L[i] = 0;
  153148. cinfo->arith_dc_U[i] = 1;
  153149. cinfo->arith_ac_K[i] = 5;
  153150. }
  153151. cinfo->restart_interval = 0;
  153152. cinfo->jpeg_color_space = JCS_UNKNOWN;
  153153. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  153154. cinfo->saw_JFIF_marker = FALSE;
  153155. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  153156. cinfo->JFIF_minor_version = 1;
  153157. cinfo->density_unit = 0;
  153158. cinfo->X_density = 1;
  153159. cinfo->Y_density = 1;
  153160. cinfo->saw_Adobe_marker = FALSE;
  153161. cinfo->Adobe_transform = 0;
  153162. cinfo->marker->saw_SOI = TRUE;
  153163. return TRUE;
  153164. }
  153165. LOCAL(boolean)
  153166. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  153167. {
  153168. INT32 length;
  153169. int c, ci;
  153170. jpeg_component_info * compptr;
  153171. INPUT_VARS(cinfo);
  153172. cinfo->progressive_mode = is_prog;
  153173. cinfo->arith_code = is_arith;
  153174. INPUT_2BYTES(cinfo, length, return FALSE);
  153175. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  153176. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  153177. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  153178. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  153179. length -= 8;
  153180. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  153181. (int) cinfo->image_width, (int) cinfo->image_height,
  153182. cinfo->num_components);
  153183. if (cinfo->marker->saw_SOF)
  153184. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  153185. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  153186. || cinfo->num_components <= 0)
  153187. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  153188. if (length != (cinfo->num_components * 3))
  153189. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153190. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  153191. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  153192. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153193. cinfo->num_components * SIZEOF(jpeg_component_info));
  153194. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153195. ci++, compptr++) {
  153196. compptr->component_index = ci;
  153197. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  153198. INPUT_BYTE(cinfo, c, return FALSE);
  153199. compptr->h_samp_factor = (c >> 4) & 15;
  153200. compptr->v_samp_factor = (c ) & 15;
  153201. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  153202. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  153203. compptr->component_id, compptr->h_samp_factor,
  153204. compptr->v_samp_factor, compptr->quant_tbl_no);
  153205. }
  153206. cinfo->marker->saw_SOF = TRUE;
  153207. INPUT_SYNC(cinfo);
  153208. return TRUE;
  153209. }
  153210. LOCAL(boolean)
  153211. get_sos (j_decompress_ptr cinfo)
  153212. {
  153213. INT32 length;
  153214. int i, ci, n, c, cc;
  153215. jpeg_component_info * compptr;
  153216. INPUT_VARS(cinfo);
  153217. if (! cinfo->marker->saw_SOF)
  153218. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  153219. INPUT_2BYTES(cinfo, length, return FALSE);
  153220. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  153221. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  153222. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  153223. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153224. cinfo->comps_in_scan = n;
  153225. for (i = 0; i < n; i++) {
  153226. INPUT_BYTE(cinfo, cc, return FALSE);
  153227. INPUT_BYTE(cinfo, c, return FALSE);
  153228. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153229. ci++, compptr++) {
  153230. if (cc == compptr->component_id)
  153231. goto id_found;
  153232. }
  153233. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  153234. id_found:
  153235. cinfo->cur_comp_info[i] = compptr;
  153236. compptr->dc_tbl_no = (c >> 4) & 15;
  153237. compptr->ac_tbl_no = (c ) & 15;
  153238. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  153239. compptr->dc_tbl_no, compptr->ac_tbl_no);
  153240. }
  153241. INPUT_BYTE(cinfo, c, return FALSE);
  153242. cinfo->Ss = c;
  153243. INPUT_BYTE(cinfo, c, return FALSE);
  153244. cinfo->Se = c;
  153245. INPUT_BYTE(cinfo, c, return FALSE);
  153246. cinfo->Ah = (c >> 4) & 15;
  153247. cinfo->Al = (c ) & 15;
  153248. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  153249. cinfo->Ah, cinfo->Al);
  153250. cinfo->marker->next_restart_num = 0;
  153251. cinfo->input_scan_number++;
  153252. INPUT_SYNC(cinfo);
  153253. return TRUE;
  153254. }
  153255. #ifdef D_ARITH_CODING_SUPPORTED
  153256. LOCAL(boolean)
  153257. get_dac (j_decompress_ptr cinfo)
  153258. {
  153259. INT32 length;
  153260. int index, val;
  153261. INPUT_VARS(cinfo);
  153262. INPUT_2BYTES(cinfo, length, return FALSE);
  153263. length -= 2;
  153264. while (length > 0) {
  153265. INPUT_BYTE(cinfo, index, return FALSE);
  153266. INPUT_BYTE(cinfo, val, return FALSE);
  153267. length -= 2;
  153268. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  153269. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  153270. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  153271. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  153272. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  153273. } else { /* define DC table */
  153274. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  153275. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  153276. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  153277. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  153278. }
  153279. }
  153280. if (length != 0)
  153281. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153282. INPUT_SYNC(cinfo);
  153283. return TRUE;
  153284. }
  153285. #else /* ! D_ARITH_CODING_SUPPORTED */
  153286. #define get_dac(cinfo) skip_variable(cinfo)
  153287. #endif /* D_ARITH_CODING_SUPPORTED */
  153288. LOCAL(boolean)
  153289. get_dht (j_decompress_ptr cinfo)
  153290. {
  153291. INT32 length;
  153292. UINT8 bits[17];
  153293. UINT8 huffval[256];
  153294. int i, index, count;
  153295. JHUFF_TBL **htblptr;
  153296. INPUT_VARS(cinfo);
  153297. INPUT_2BYTES(cinfo, length, return FALSE);
  153298. length -= 2;
  153299. while (length > 16) {
  153300. INPUT_BYTE(cinfo, index, return FALSE);
  153301. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  153302. bits[0] = 0;
  153303. count = 0;
  153304. for (i = 1; i <= 16; i++) {
  153305. INPUT_BYTE(cinfo, bits[i], return FALSE);
  153306. count += bits[i];
  153307. }
  153308. length -= 1 + 16;
  153309. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153310. bits[1], bits[2], bits[3], bits[4],
  153311. bits[5], bits[6], bits[7], bits[8]);
  153312. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153313. bits[9], bits[10], bits[11], bits[12],
  153314. bits[13], bits[14], bits[15], bits[16]);
  153315. if (count > 256 || ((INT32) count) > length)
  153316. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  153317. for (i = 0; i < count; i++)
  153318. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  153319. length -= count;
  153320. if (index & 0x10) { /* AC table definition */
  153321. index -= 0x10;
  153322. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  153323. } else { /* DC table definition */
  153324. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  153325. }
  153326. if (index < 0 || index >= NUM_HUFF_TBLS)
  153327. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  153328. if (*htblptr == NULL)
  153329. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  153330. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  153331. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  153332. }
  153333. if (length != 0)
  153334. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153335. INPUT_SYNC(cinfo);
  153336. return TRUE;
  153337. }
  153338. LOCAL(boolean)
  153339. get_dqt (j_decompress_ptr cinfo)
  153340. {
  153341. INT32 length;
  153342. int n, i, prec;
  153343. unsigned int tmp;
  153344. JQUANT_TBL *quant_ptr;
  153345. INPUT_VARS(cinfo);
  153346. INPUT_2BYTES(cinfo, length, return FALSE);
  153347. length -= 2;
  153348. while (length > 0) {
  153349. INPUT_BYTE(cinfo, n, return FALSE);
  153350. prec = n >> 4;
  153351. n &= 0x0F;
  153352. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  153353. if (n >= NUM_QUANT_TBLS)
  153354. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  153355. if (cinfo->quant_tbl_ptrs[n] == NULL)
  153356. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  153357. quant_ptr = cinfo->quant_tbl_ptrs[n];
  153358. for (i = 0; i < DCTSIZE2; i++) {
  153359. if (prec)
  153360. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153361. else
  153362. INPUT_BYTE(cinfo, tmp, return FALSE);
  153363. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  153364. }
  153365. if (cinfo->err->trace_level >= 2) {
  153366. for (i = 0; i < DCTSIZE2; i += 8) {
  153367. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  153368. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  153369. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  153370. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  153371. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  153372. }
  153373. }
  153374. length -= DCTSIZE2+1;
  153375. if (prec) length -= DCTSIZE2;
  153376. }
  153377. if (length != 0)
  153378. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153379. INPUT_SYNC(cinfo);
  153380. return TRUE;
  153381. }
  153382. LOCAL(boolean)
  153383. get_dri (j_decompress_ptr cinfo)
  153384. {
  153385. INT32 length;
  153386. unsigned int tmp;
  153387. INPUT_VARS(cinfo);
  153388. INPUT_2BYTES(cinfo, length, return FALSE);
  153389. if (length != 4)
  153390. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153391. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153392. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  153393. cinfo->restart_interval = tmp;
  153394. INPUT_SYNC(cinfo);
  153395. return TRUE;
  153396. }
  153397. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  153398. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  153399. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  153400. LOCAL(void)
  153401. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153402. unsigned int datalen, INT32 remaining)
  153403. {
  153404. INT32 totallen = (INT32) datalen + remaining;
  153405. if (datalen >= APP0_DATA_LEN &&
  153406. GETJOCTET(data[0]) == 0x4A &&
  153407. GETJOCTET(data[1]) == 0x46 &&
  153408. GETJOCTET(data[2]) == 0x49 &&
  153409. GETJOCTET(data[3]) == 0x46 &&
  153410. GETJOCTET(data[4]) == 0) {
  153411. cinfo->saw_JFIF_marker = TRUE;
  153412. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  153413. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  153414. cinfo->density_unit = GETJOCTET(data[7]);
  153415. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  153416. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  153417. if (cinfo->JFIF_major_version != 1)
  153418. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  153419. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  153420. TRACEMS5(cinfo, 1, JTRC_JFIF,
  153421. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  153422. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  153423. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  153424. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  153425. GETJOCTET(data[12]), GETJOCTET(data[13]));
  153426. totallen -= APP0_DATA_LEN;
  153427. if (totallen !=
  153428. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  153429. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  153430. } else if (datalen >= 6 &&
  153431. GETJOCTET(data[0]) == 0x4A &&
  153432. GETJOCTET(data[1]) == 0x46 &&
  153433. GETJOCTET(data[2]) == 0x58 &&
  153434. GETJOCTET(data[3]) == 0x58 &&
  153435. GETJOCTET(data[4]) == 0) {
  153436. switch (GETJOCTET(data[5])) {
  153437. case 0x10:
  153438. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  153439. break;
  153440. case 0x11:
  153441. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  153442. break;
  153443. case 0x13:
  153444. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  153445. break;
  153446. default:
  153447. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  153448. GETJOCTET(data[5]), (int) totallen);
  153449. break;
  153450. }
  153451. } else {
  153452. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  153453. }
  153454. }
  153455. LOCAL(void)
  153456. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153457. unsigned int datalen, INT32 remaining)
  153458. {
  153459. unsigned int version, flags0, flags1, transform;
  153460. if (datalen >= APP14_DATA_LEN &&
  153461. GETJOCTET(data[0]) == 0x41 &&
  153462. GETJOCTET(data[1]) == 0x64 &&
  153463. GETJOCTET(data[2]) == 0x6F &&
  153464. GETJOCTET(data[3]) == 0x62 &&
  153465. GETJOCTET(data[4]) == 0x65) {
  153466. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  153467. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  153468. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  153469. transform = GETJOCTET(data[11]);
  153470. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  153471. cinfo->saw_Adobe_marker = TRUE;
  153472. cinfo->Adobe_transform = (UINT8) transform;
  153473. } else {
  153474. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  153475. }
  153476. }
  153477. METHODDEF(boolean)
  153478. get_interesting_appn (j_decompress_ptr cinfo)
  153479. {
  153480. INT32 length;
  153481. JOCTET b[APPN_DATA_LEN];
  153482. unsigned int i, numtoread;
  153483. INPUT_VARS(cinfo);
  153484. INPUT_2BYTES(cinfo, length, return FALSE);
  153485. length -= 2;
  153486. if (length >= APPN_DATA_LEN)
  153487. numtoread = APPN_DATA_LEN;
  153488. else if (length > 0)
  153489. numtoread = (unsigned int) length;
  153490. else
  153491. numtoread = 0;
  153492. for (i = 0; i < numtoread; i++)
  153493. INPUT_BYTE(cinfo, b[i], return FALSE);
  153494. length -= numtoread;
  153495. switch (cinfo->unread_marker) {
  153496. case M_APP0:
  153497. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  153498. break;
  153499. case M_APP14:
  153500. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  153501. break;
  153502. default:
  153503. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153504. break;
  153505. }
  153506. INPUT_SYNC(cinfo);
  153507. if (length > 0)
  153508. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153509. return TRUE;
  153510. }
  153511. #ifdef SAVE_MARKERS_SUPPORTED
  153512. METHODDEF(boolean)
  153513. save_marker (j_decompress_ptr cinfo)
  153514. {
  153515. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153516. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  153517. unsigned int bytes_read, data_length;
  153518. JOCTET FAR * data;
  153519. INT32 length = 0;
  153520. INPUT_VARS(cinfo);
  153521. if (cur_marker == NULL) {
  153522. INPUT_2BYTES(cinfo, length, return FALSE);
  153523. length -= 2;
  153524. if (length >= 0) { /* watch out for bogus length word */
  153525. unsigned int limit;
  153526. if (cinfo->unread_marker == (int) M_COM)
  153527. limit = marker->length_limit_COM;
  153528. else
  153529. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153530. if ((unsigned int) length < limit)
  153531. limit = (unsigned int) length;
  153532. cur_marker = (jpeg_saved_marker_ptr)
  153533. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153534. SIZEOF(struct jpeg_marker_struct) + limit);
  153535. cur_marker->next = NULL;
  153536. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153537. cur_marker->original_length = (unsigned int) length;
  153538. cur_marker->data_length = limit;
  153539. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153540. marker->cur_marker = cur_marker;
  153541. marker->bytes_read = 0;
  153542. bytes_read = 0;
  153543. data_length = limit;
  153544. } else {
  153545. bytes_read = data_length = 0;
  153546. data = NULL;
  153547. }
  153548. } else {
  153549. bytes_read = marker->bytes_read;
  153550. data_length = cur_marker->data_length;
  153551. data = cur_marker->data + bytes_read;
  153552. }
  153553. while (bytes_read < data_length) {
  153554. INPUT_SYNC(cinfo); /* move the restart point to here */
  153555. marker->bytes_read = bytes_read;
  153556. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153557. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153558. *data++ = *next_input_byte++;
  153559. bytes_in_buffer--;
  153560. bytes_read++;
  153561. }
  153562. }
  153563. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153564. if (cinfo->marker_list == NULL) {
  153565. cinfo->marker_list = cur_marker;
  153566. } else {
  153567. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153568. while (prev->next != NULL)
  153569. prev = prev->next;
  153570. prev->next = cur_marker;
  153571. }
  153572. data = cur_marker->data;
  153573. length = cur_marker->original_length - data_length;
  153574. }
  153575. marker->cur_marker = NULL;
  153576. switch (cinfo->unread_marker) {
  153577. case M_APP0:
  153578. examine_app0(cinfo, data, data_length, length);
  153579. break;
  153580. case M_APP14:
  153581. examine_app14(cinfo, data, data_length, length);
  153582. break;
  153583. default:
  153584. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153585. (int) (data_length + length));
  153586. break;
  153587. }
  153588. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153589. if (length > 0)
  153590. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153591. return TRUE;
  153592. }
  153593. #endif /* SAVE_MARKERS_SUPPORTED */
  153594. METHODDEF(boolean)
  153595. skip_variable (j_decompress_ptr cinfo)
  153596. {
  153597. INT32 length;
  153598. INPUT_VARS(cinfo);
  153599. INPUT_2BYTES(cinfo, length, return FALSE);
  153600. length -= 2;
  153601. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153602. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153603. if (length > 0)
  153604. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153605. return TRUE;
  153606. }
  153607. LOCAL(boolean)
  153608. next_marker (j_decompress_ptr cinfo)
  153609. {
  153610. int c;
  153611. INPUT_VARS(cinfo);
  153612. for (;;) {
  153613. INPUT_BYTE(cinfo, c, return FALSE);
  153614. while (c != 0xFF) {
  153615. cinfo->marker->discarded_bytes++;
  153616. INPUT_SYNC(cinfo);
  153617. INPUT_BYTE(cinfo, c, return FALSE);
  153618. }
  153619. do {
  153620. INPUT_BYTE(cinfo, c, return FALSE);
  153621. } while (c == 0xFF);
  153622. if (c != 0)
  153623. break; /* found a valid marker, exit loop */
  153624. cinfo->marker->discarded_bytes += 2;
  153625. INPUT_SYNC(cinfo);
  153626. }
  153627. if (cinfo->marker->discarded_bytes != 0) {
  153628. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153629. cinfo->marker->discarded_bytes = 0;
  153630. }
  153631. cinfo->unread_marker = c;
  153632. INPUT_SYNC(cinfo);
  153633. return TRUE;
  153634. }
  153635. LOCAL(boolean)
  153636. first_marker (j_decompress_ptr cinfo)
  153637. {
  153638. int c, c2;
  153639. INPUT_VARS(cinfo);
  153640. INPUT_BYTE(cinfo, c, return FALSE);
  153641. INPUT_BYTE(cinfo, c2, return FALSE);
  153642. if (c != 0xFF || c2 != (int) M_SOI)
  153643. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153644. cinfo->unread_marker = c2;
  153645. INPUT_SYNC(cinfo);
  153646. return TRUE;
  153647. }
  153648. METHODDEF(int)
  153649. read_markers (j_decompress_ptr cinfo)
  153650. {
  153651. for (;;) {
  153652. if (cinfo->unread_marker == 0) {
  153653. if (! cinfo->marker->saw_SOI) {
  153654. if (! first_marker(cinfo))
  153655. return JPEG_SUSPENDED;
  153656. } else {
  153657. if (! next_marker(cinfo))
  153658. return JPEG_SUSPENDED;
  153659. }
  153660. }
  153661. switch (cinfo->unread_marker) {
  153662. case M_SOI:
  153663. if (! get_soi(cinfo))
  153664. return JPEG_SUSPENDED;
  153665. break;
  153666. case M_SOF0: /* Baseline */
  153667. case M_SOF1: /* Extended sequential, Huffman */
  153668. if (! get_sof(cinfo, FALSE, FALSE))
  153669. return JPEG_SUSPENDED;
  153670. break;
  153671. case M_SOF2: /* Progressive, Huffman */
  153672. if (! get_sof(cinfo, TRUE, FALSE))
  153673. return JPEG_SUSPENDED;
  153674. break;
  153675. case M_SOF9: /* Extended sequential, arithmetic */
  153676. if (! get_sof(cinfo, FALSE, TRUE))
  153677. return JPEG_SUSPENDED;
  153678. break;
  153679. case M_SOF10: /* Progressive, arithmetic */
  153680. if (! get_sof(cinfo, TRUE, TRUE))
  153681. return JPEG_SUSPENDED;
  153682. break;
  153683. case M_SOF3: /* Lossless, Huffman */
  153684. case M_SOF5: /* Differential sequential, Huffman */
  153685. case M_SOF6: /* Differential progressive, Huffman */
  153686. case M_SOF7: /* Differential lossless, Huffman */
  153687. case M_JPG: /* Reserved for JPEG extensions */
  153688. case M_SOF11: /* Lossless, arithmetic */
  153689. case M_SOF13: /* Differential sequential, arithmetic */
  153690. case M_SOF14: /* Differential progressive, arithmetic */
  153691. case M_SOF15: /* Differential lossless, arithmetic */
  153692. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153693. break;
  153694. case M_SOS:
  153695. if (! get_sos(cinfo))
  153696. return JPEG_SUSPENDED;
  153697. cinfo->unread_marker = 0; /* processed the marker */
  153698. return JPEG_REACHED_SOS;
  153699. case M_EOI:
  153700. TRACEMS(cinfo, 1, JTRC_EOI);
  153701. cinfo->unread_marker = 0; /* processed the marker */
  153702. return JPEG_REACHED_EOI;
  153703. case M_DAC:
  153704. if (! get_dac(cinfo))
  153705. return JPEG_SUSPENDED;
  153706. break;
  153707. case M_DHT:
  153708. if (! get_dht(cinfo))
  153709. return JPEG_SUSPENDED;
  153710. break;
  153711. case M_DQT:
  153712. if (! get_dqt(cinfo))
  153713. return JPEG_SUSPENDED;
  153714. break;
  153715. case M_DRI:
  153716. if (! get_dri(cinfo))
  153717. return JPEG_SUSPENDED;
  153718. break;
  153719. case M_APP0:
  153720. case M_APP1:
  153721. case M_APP2:
  153722. case M_APP3:
  153723. case M_APP4:
  153724. case M_APP5:
  153725. case M_APP6:
  153726. case M_APP7:
  153727. case M_APP8:
  153728. case M_APP9:
  153729. case M_APP10:
  153730. case M_APP11:
  153731. case M_APP12:
  153732. case M_APP13:
  153733. case M_APP14:
  153734. case M_APP15:
  153735. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153736. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153737. return JPEG_SUSPENDED;
  153738. break;
  153739. case M_COM:
  153740. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153741. return JPEG_SUSPENDED;
  153742. break;
  153743. case M_RST0: /* these are all parameterless */
  153744. case M_RST1:
  153745. case M_RST2:
  153746. case M_RST3:
  153747. case M_RST4:
  153748. case M_RST5:
  153749. case M_RST6:
  153750. case M_RST7:
  153751. case M_TEM:
  153752. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153753. break;
  153754. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153755. if (! skip_variable(cinfo))
  153756. return JPEG_SUSPENDED;
  153757. break;
  153758. default: /* must be DHP, EXP, JPGn, or RESn */
  153759. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153760. break;
  153761. }
  153762. cinfo->unread_marker = 0;
  153763. } /* end loop */
  153764. }
  153765. METHODDEF(boolean)
  153766. read_restart_marker (j_decompress_ptr cinfo)
  153767. {
  153768. if (cinfo->unread_marker == 0) {
  153769. if (! next_marker(cinfo))
  153770. return FALSE;
  153771. }
  153772. if (cinfo->unread_marker ==
  153773. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153774. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153775. cinfo->unread_marker = 0;
  153776. } else {
  153777. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153778. cinfo->marker->next_restart_num))
  153779. return FALSE;
  153780. }
  153781. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153782. return TRUE;
  153783. }
  153784. GLOBAL(boolean)
  153785. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153786. {
  153787. int marker = cinfo->unread_marker;
  153788. int action = 1;
  153789. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153790. for (;;) {
  153791. if (marker < (int) M_SOF0)
  153792. action = 2; /* invalid marker */
  153793. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153794. action = 3; /* valid non-restart marker */
  153795. else {
  153796. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153797. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153798. action = 3; /* one of the next two expected restarts */
  153799. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153800. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153801. action = 2; /* a prior restart, so advance */
  153802. else
  153803. action = 1; /* desired restart or too far away */
  153804. }
  153805. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153806. switch (action) {
  153807. case 1:
  153808. cinfo->unread_marker = 0;
  153809. return TRUE;
  153810. case 2:
  153811. if (! next_marker(cinfo))
  153812. return FALSE;
  153813. marker = cinfo->unread_marker;
  153814. break;
  153815. case 3:
  153816. return TRUE;
  153817. }
  153818. } /* end loop */
  153819. }
  153820. METHODDEF(void)
  153821. reset_marker_reader (j_decompress_ptr cinfo)
  153822. {
  153823. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153824. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153825. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153826. cinfo->unread_marker = 0; /* no pending marker */
  153827. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153828. marker->pub.saw_SOF = FALSE;
  153829. marker->pub.discarded_bytes = 0;
  153830. marker->cur_marker = NULL;
  153831. }
  153832. GLOBAL(void)
  153833. jinit_marker_reader (j_decompress_ptr cinfo)
  153834. {
  153835. my_marker_ptr2 marker;
  153836. int i;
  153837. marker = (my_marker_ptr2)
  153838. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153839. SIZEOF(my_marker_reader));
  153840. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153841. marker->pub.reset_marker_reader = reset_marker_reader;
  153842. marker->pub.read_markers = read_markers;
  153843. marker->pub.read_restart_marker = read_restart_marker;
  153844. marker->process_COM = skip_variable;
  153845. marker->length_limit_COM = 0;
  153846. for (i = 0; i < 16; i++) {
  153847. marker->process_APPn[i] = skip_variable;
  153848. marker->length_limit_APPn[i] = 0;
  153849. }
  153850. marker->process_APPn[0] = get_interesting_appn;
  153851. marker->process_APPn[14] = get_interesting_appn;
  153852. reset_marker_reader(cinfo);
  153853. }
  153854. #ifdef SAVE_MARKERS_SUPPORTED
  153855. GLOBAL(void)
  153856. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153857. unsigned int length_limit)
  153858. {
  153859. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153860. long maxlength;
  153861. jpeg_marker_parser_method processor;
  153862. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153863. if (((long) length_limit) > maxlength)
  153864. length_limit = (unsigned int) maxlength;
  153865. if (length_limit) {
  153866. processor = save_marker;
  153867. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153868. length_limit = APP0_DATA_LEN;
  153869. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153870. length_limit = APP14_DATA_LEN;
  153871. } else {
  153872. processor = skip_variable;
  153873. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153874. processor = get_interesting_appn;
  153875. }
  153876. if (marker_code == (int) M_COM) {
  153877. marker->process_COM = processor;
  153878. marker->length_limit_COM = length_limit;
  153879. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153880. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153881. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153882. } else
  153883. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153884. }
  153885. #endif /* SAVE_MARKERS_SUPPORTED */
  153886. GLOBAL(void)
  153887. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153888. jpeg_marker_parser_method routine)
  153889. {
  153890. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153891. if (marker_code == (int) M_COM)
  153892. marker->process_COM = routine;
  153893. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153894. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153895. else
  153896. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153897. }
  153898. /*** End of inlined file: jdmarker.c ***/
  153899. /*** Start of inlined file: jdmaster.c ***/
  153900. #define JPEG_INTERNALS
  153901. typedef struct {
  153902. struct jpeg_decomp_master pub; /* public fields */
  153903. int pass_number; /* # of passes completed */
  153904. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153905. struct jpeg_color_quantizer * quantizer_1pass;
  153906. struct jpeg_color_quantizer * quantizer_2pass;
  153907. } my_decomp_master;
  153908. typedef my_decomp_master * my_master_ptr6;
  153909. LOCAL(boolean)
  153910. use_merged_upsample (j_decompress_ptr cinfo)
  153911. {
  153912. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153913. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153914. return FALSE;
  153915. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153916. cinfo->out_color_space != JCS_RGB ||
  153917. cinfo->out_color_components != RGB_PIXELSIZE)
  153918. return FALSE;
  153919. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153920. cinfo->comp_info[1].h_samp_factor != 1 ||
  153921. cinfo->comp_info[2].h_samp_factor != 1 ||
  153922. cinfo->comp_info[0].v_samp_factor > 2 ||
  153923. cinfo->comp_info[1].v_samp_factor != 1 ||
  153924. cinfo->comp_info[2].v_samp_factor != 1)
  153925. return FALSE;
  153926. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153927. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153928. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153929. return FALSE;
  153930. return TRUE; /* by golly, it'll work... */
  153931. #else
  153932. return FALSE;
  153933. #endif
  153934. }
  153935. GLOBAL(void)
  153936. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153937. {
  153938. #ifdef IDCT_SCALING_SUPPORTED
  153939. int ci;
  153940. jpeg_component_info *compptr;
  153941. #endif
  153942. if (cinfo->global_state != DSTATE_READY)
  153943. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153944. #ifdef IDCT_SCALING_SUPPORTED
  153945. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153946. cinfo->output_width = (JDIMENSION)
  153947. jdiv_round_up((long) cinfo->image_width, 8L);
  153948. cinfo->output_height = (JDIMENSION)
  153949. jdiv_round_up((long) cinfo->image_height, 8L);
  153950. cinfo->min_DCT_scaled_size = 1;
  153951. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153952. cinfo->output_width = (JDIMENSION)
  153953. jdiv_round_up((long) cinfo->image_width, 4L);
  153954. cinfo->output_height = (JDIMENSION)
  153955. jdiv_round_up((long) cinfo->image_height, 4L);
  153956. cinfo->min_DCT_scaled_size = 2;
  153957. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153958. cinfo->output_width = (JDIMENSION)
  153959. jdiv_round_up((long) cinfo->image_width, 2L);
  153960. cinfo->output_height = (JDIMENSION)
  153961. jdiv_round_up((long) cinfo->image_height, 2L);
  153962. cinfo->min_DCT_scaled_size = 4;
  153963. } else {
  153964. cinfo->output_width = cinfo->image_width;
  153965. cinfo->output_height = cinfo->image_height;
  153966. cinfo->min_DCT_scaled_size = DCTSIZE;
  153967. }
  153968. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153969. ci++, compptr++) {
  153970. int ssize = cinfo->min_DCT_scaled_size;
  153971. while (ssize < DCTSIZE &&
  153972. (compptr->h_samp_factor * ssize * 2 <=
  153973. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153974. (compptr->v_samp_factor * ssize * 2 <=
  153975. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153976. ssize = ssize * 2;
  153977. }
  153978. compptr->DCT_scaled_size = ssize;
  153979. }
  153980. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153981. ci++, compptr++) {
  153982. compptr->downsampled_width = (JDIMENSION)
  153983. jdiv_round_up((long) cinfo->image_width *
  153984. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153985. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153986. compptr->downsampled_height = (JDIMENSION)
  153987. jdiv_round_up((long) cinfo->image_height *
  153988. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153989. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153990. }
  153991. #else /* !IDCT_SCALING_SUPPORTED */
  153992. cinfo->output_width = cinfo->image_width;
  153993. cinfo->output_height = cinfo->image_height;
  153994. #endif /* IDCT_SCALING_SUPPORTED */
  153995. switch (cinfo->out_color_space) {
  153996. case JCS_GRAYSCALE:
  153997. cinfo->out_color_components = 1;
  153998. break;
  153999. case JCS_RGB:
  154000. #if RGB_PIXELSIZE != 3
  154001. cinfo->out_color_components = RGB_PIXELSIZE;
  154002. break;
  154003. #endif /* else share code with YCbCr */
  154004. case JCS_YCbCr:
  154005. cinfo->out_color_components = 3;
  154006. break;
  154007. case JCS_CMYK:
  154008. case JCS_YCCK:
  154009. cinfo->out_color_components = 4;
  154010. break;
  154011. default: /* else must be same colorspace as in file */
  154012. cinfo->out_color_components = cinfo->num_components;
  154013. break;
  154014. }
  154015. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  154016. cinfo->out_color_components);
  154017. if (use_merged_upsample(cinfo))
  154018. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  154019. else
  154020. cinfo->rec_outbuf_height = 1;
  154021. }
  154022. LOCAL(void)
  154023. prepare_range_limit_table (j_decompress_ptr cinfo)
  154024. {
  154025. JSAMPLE * table;
  154026. int i;
  154027. table = (JSAMPLE *)
  154028. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154029. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  154030. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  154031. cinfo->sample_range_limit = table;
  154032. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  154033. for (i = 0; i <= MAXJSAMPLE; i++)
  154034. table[i] = (JSAMPLE) i;
  154035. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  154036. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  154037. table[i] = MAXJSAMPLE;
  154038. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  154039. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  154040. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  154041. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  154042. }
  154043. LOCAL(void)
  154044. master_selection (j_decompress_ptr cinfo)
  154045. {
  154046. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154047. boolean use_c_buffer;
  154048. long samplesperrow;
  154049. JDIMENSION jd_samplesperrow;
  154050. jpeg_calc_output_dimensions(cinfo);
  154051. prepare_range_limit_table(cinfo);
  154052. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  154053. jd_samplesperrow = (JDIMENSION) samplesperrow;
  154054. if ((long) jd_samplesperrow != samplesperrow)
  154055. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  154056. master->pass_number = 0;
  154057. master->using_merged_upsample = use_merged_upsample(cinfo);
  154058. master->quantizer_1pass = NULL;
  154059. master->quantizer_2pass = NULL;
  154060. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  154061. cinfo->enable_1pass_quant = FALSE;
  154062. cinfo->enable_external_quant = FALSE;
  154063. cinfo->enable_2pass_quant = FALSE;
  154064. }
  154065. if (cinfo->quantize_colors) {
  154066. if (cinfo->raw_data_out)
  154067. ERREXIT(cinfo, JERR_NOTIMPL);
  154068. if (cinfo->out_color_components != 3) {
  154069. cinfo->enable_1pass_quant = TRUE;
  154070. cinfo->enable_external_quant = FALSE;
  154071. cinfo->enable_2pass_quant = FALSE;
  154072. cinfo->colormap = NULL;
  154073. } else if (cinfo->colormap != NULL) {
  154074. cinfo->enable_external_quant = TRUE;
  154075. } else if (cinfo->two_pass_quantize) {
  154076. cinfo->enable_2pass_quant = TRUE;
  154077. } else {
  154078. cinfo->enable_1pass_quant = TRUE;
  154079. }
  154080. if (cinfo->enable_1pass_quant) {
  154081. #ifdef QUANT_1PASS_SUPPORTED
  154082. jinit_1pass_quantizer(cinfo);
  154083. master->quantizer_1pass = cinfo->cquantize;
  154084. #else
  154085. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154086. #endif
  154087. }
  154088. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  154089. #ifdef QUANT_2PASS_SUPPORTED
  154090. jinit_2pass_quantizer(cinfo);
  154091. master->quantizer_2pass = cinfo->cquantize;
  154092. #else
  154093. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154094. #endif
  154095. }
  154096. }
  154097. if (! cinfo->raw_data_out) {
  154098. if (master->using_merged_upsample) {
  154099. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154100. jinit_merged_upsampler(cinfo); /* does color conversion too */
  154101. #else
  154102. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154103. #endif
  154104. } else {
  154105. jinit_color_deconverter(cinfo);
  154106. jinit_upsampler(cinfo);
  154107. }
  154108. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  154109. }
  154110. jinit_inverse_dct(cinfo);
  154111. if (cinfo->arith_code) {
  154112. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154113. } else {
  154114. if (cinfo->progressive_mode) {
  154115. #ifdef D_PROGRESSIVE_SUPPORTED
  154116. jinit_phuff_decoder(cinfo);
  154117. #else
  154118. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154119. #endif
  154120. } else
  154121. jinit_huff_decoder(cinfo);
  154122. }
  154123. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  154124. jinit_d_coef_controller(cinfo, use_c_buffer);
  154125. if (! cinfo->raw_data_out)
  154126. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  154127. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154128. (*cinfo->inputctl->start_input_pass) (cinfo);
  154129. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154130. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  154131. cinfo->inputctl->has_multiple_scans) {
  154132. int nscans;
  154133. if (cinfo->progressive_mode) {
  154134. nscans = 2 + 3 * cinfo->num_components;
  154135. } else {
  154136. nscans = cinfo->num_components;
  154137. }
  154138. cinfo->progress->pass_counter = 0L;
  154139. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154140. cinfo->progress->completed_passes = 0;
  154141. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  154142. master->pass_number++;
  154143. }
  154144. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154145. }
  154146. METHODDEF(void)
  154147. prepare_for_output_pass (j_decompress_ptr cinfo)
  154148. {
  154149. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154150. if (master->pub.is_dummy_pass) {
  154151. #ifdef QUANT_2PASS_SUPPORTED
  154152. master->pub.is_dummy_pass = FALSE;
  154153. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  154154. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  154155. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  154156. #else
  154157. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154158. #endif /* QUANT_2PASS_SUPPORTED */
  154159. } else {
  154160. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  154161. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  154162. cinfo->cquantize = master->quantizer_2pass;
  154163. master->pub.is_dummy_pass = TRUE;
  154164. } else if (cinfo->enable_1pass_quant) {
  154165. cinfo->cquantize = master->quantizer_1pass;
  154166. } else {
  154167. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154168. }
  154169. }
  154170. (*cinfo->idct->start_pass) (cinfo);
  154171. (*cinfo->coef->start_output_pass) (cinfo);
  154172. if (! cinfo->raw_data_out) {
  154173. if (! master->using_merged_upsample)
  154174. (*cinfo->cconvert->start_pass) (cinfo);
  154175. (*cinfo->upsample->start_pass) (cinfo);
  154176. if (cinfo->quantize_colors)
  154177. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  154178. (*cinfo->post->start_pass) (cinfo,
  154179. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  154180. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  154181. }
  154182. }
  154183. if (cinfo->progress != NULL) {
  154184. cinfo->progress->completed_passes = master->pass_number;
  154185. cinfo->progress->total_passes = master->pass_number +
  154186. (master->pub.is_dummy_pass ? 2 : 1);
  154187. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  154188. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  154189. }
  154190. }
  154191. }
  154192. METHODDEF(void)
  154193. finish_output_pass (j_decompress_ptr cinfo)
  154194. {
  154195. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154196. if (cinfo->quantize_colors)
  154197. (*cinfo->cquantize->finish_pass) (cinfo);
  154198. master->pass_number++;
  154199. }
  154200. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154201. GLOBAL(void)
  154202. jpeg_new_colormap (j_decompress_ptr cinfo)
  154203. {
  154204. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154205. if (cinfo->global_state != DSTATE_BUFIMAGE)
  154206. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154207. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  154208. cinfo->colormap != NULL) {
  154209. cinfo->cquantize = master->quantizer_2pass;
  154210. (*cinfo->cquantize->new_color_map) (cinfo);
  154211. master->pub.is_dummy_pass = FALSE; /* just in case */
  154212. } else
  154213. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154214. }
  154215. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154216. GLOBAL(void)
  154217. jinit_master_decompress (j_decompress_ptr cinfo)
  154218. {
  154219. my_master_ptr6 master;
  154220. master = (my_master_ptr6)
  154221. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154222. SIZEOF(my_decomp_master));
  154223. cinfo->master = (struct jpeg_decomp_master *) master;
  154224. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  154225. master->pub.finish_output_pass = finish_output_pass;
  154226. master->pub.is_dummy_pass = FALSE;
  154227. master_selection(cinfo);
  154228. }
  154229. /*** End of inlined file: jdmaster.c ***/
  154230. #undef FIX
  154231. /*** Start of inlined file: jdmerge.c ***/
  154232. #define JPEG_INTERNALS
  154233. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154234. typedef struct {
  154235. struct jpeg_upsampler pub; /* public fields */
  154236. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  154237. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154238. JSAMPARRAY output_buf));
  154239. int * Cr_r_tab; /* => table for Cr to R conversion */
  154240. int * Cb_b_tab; /* => table for Cb to B conversion */
  154241. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  154242. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  154243. JSAMPROW spare_row;
  154244. boolean spare_full; /* T if spare buffer is occupied */
  154245. JDIMENSION out_row_width; /* samples per output row */
  154246. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154247. } my_upsampler;
  154248. typedef my_upsampler * my_upsample_ptr;
  154249. #define SCALEBITS 16 /* speediest right-shift on some machines */
  154250. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  154251. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  154252. LOCAL(void)
  154253. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  154254. {
  154255. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154256. int i;
  154257. INT32 x;
  154258. SHIFT_TEMPS
  154259. upsample->Cr_r_tab = (int *)
  154260. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154261. (MAXJSAMPLE+1) * SIZEOF(int));
  154262. upsample->Cb_b_tab = (int *)
  154263. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154264. (MAXJSAMPLE+1) * SIZEOF(int));
  154265. upsample->Cr_g_tab = (INT32 *)
  154266. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154267. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154268. upsample->Cb_g_tab = (INT32 *)
  154269. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154270. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154271. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  154272. upsample->Cr_r_tab[i] = (int)
  154273. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  154274. upsample->Cb_b_tab[i] = (int)
  154275. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  154276. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  154277. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  154278. }
  154279. }
  154280. METHODDEF(void)
  154281. start_pass_merged_upsample (j_decompress_ptr cinfo)
  154282. {
  154283. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154284. upsample->spare_full = FALSE;
  154285. upsample->rows_to_go = cinfo->output_height;
  154286. }
  154287. METHODDEF(void)
  154288. merged_2v_upsample (j_decompress_ptr cinfo,
  154289. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154290. JDIMENSION in_row_groups_avail,
  154291. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154292. JDIMENSION out_rows_avail)
  154293. {
  154294. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154295. JSAMPROW work_ptrs[2];
  154296. JDIMENSION num_rows; /* number of rows returned to caller */
  154297. if (upsample->spare_full) {
  154298. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  154299. 1, upsample->out_row_width);
  154300. num_rows = 1;
  154301. upsample->spare_full = FALSE;
  154302. } else {
  154303. num_rows = 2;
  154304. if (num_rows > upsample->rows_to_go)
  154305. num_rows = upsample->rows_to_go;
  154306. out_rows_avail -= *out_row_ctr;
  154307. if (num_rows > out_rows_avail)
  154308. num_rows = out_rows_avail;
  154309. work_ptrs[0] = output_buf[*out_row_ctr];
  154310. if (num_rows > 1) {
  154311. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  154312. } else {
  154313. work_ptrs[1] = upsample->spare_row;
  154314. upsample->spare_full = TRUE;
  154315. }
  154316. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  154317. }
  154318. *out_row_ctr += num_rows;
  154319. upsample->rows_to_go -= num_rows;
  154320. if (! upsample->spare_full)
  154321. (*in_row_group_ctr)++;
  154322. }
  154323. METHODDEF(void)
  154324. merged_1v_upsample (j_decompress_ptr cinfo,
  154325. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154326. JDIMENSION in_row_groups_avail,
  154327. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154328. JDIMENSION out_rows_avail)
  154329. {
  154330. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154331. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  154332. output_buf + *out_row_ctr);
  154333. (*out_row_ctr)++;
  154334. (*in_row_group_ctr)++;
  154335. }
  154336. METHODDEF(void)
  154337. h2v1_merged_upsample (j_decompress_ptr cinfo,
  154338. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154339. JSAMPARRAY output_buf)
  154340. {
  154341. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154342. register int y, cred, cgreen, cblue;
  154343. int cb, cr;
  154344. register JSAMPROW outptr;
  154345. JSAMPROW inptr0, inptr1, inptr2;
  154346. JDIMENSION col;
  154347. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154348. int * Crrtab = upsample->Cr_r_tab;
  154349. int * Cbbtab = upsample->Cb_b_tab;
  154350. INT32 * Crgtab = upsample->Cr_g_tab;
  154351. INT32 * Cbgtab = upsample->Cb_g_tab;
  154352. SHIFT_TEMPS
  154353. inptr0 = input_buf[0][in_row_group_ctr];
  154354. inptr1 = input_buf[1][in_row_group_ctr];
  154355. inptr2 = input_buf[2][in_row_group_ctr];
  154356. outptr = output_buf[0];
  154357. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154358. cb = GETJSAMPLE(*inptr1++);
  154359. cr = GETJSAMPLE(*inptr2++);
  154360. cred = Crrtab[cr];
  154361. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154362. cblue = Cbbtab[cb];
  154363. y = GETJSAMPLE(*inptr0++);
  154364. outptr[RGB_RED] = range_limit[y + cred];
  154365. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154366. outptr[RGB_BLUE] = range_limit[y + cblue];
  154367. outptr += RGB_PIXELSIZE;
  154368. y = GETJSAMPLE(*inptr0++);
  154369. outptr[RGB_RED] = range_limit[y + cred];
  154370. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154371. outptr[RGB_BLUE] = range_limit[y + cblue];
  154372. outptr += RGB_PIXELSIZE;
  154373. }
  154374. if (cinfo->output_width & 1) {
  154375. cb = GETJSAMPLE(*inptr1);
  154376. cr = GETJSAMPLE(*inptr2);
  154377. cred = Crrtab[cr];
  154378. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154379. cblue = Cbbtab[cb];
  154380. y = GETJSAMPLE(*inptr0);
  154381. outptr[RGB_RED] = range_limit[y + cred];
  154382. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154383. outptr[RGB_BLUE] = range_limit[y + cblue];
  154384. }
  154385. }
  154386. METHODDEF(void)
  154387. h2v2_merged_upsample (j_decompress_ptr cinfo,
  154388. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154389. JSAMPARRAY output_buf)
  154390. {
  154391. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154392. register int y, cred, cgreen, cblue;
  154393. int cb, cr;
  154394. register JSAMPROW outptr0, outptr1;
  154395. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  154396. JDIMENSION col;
  154397. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154398. int * Crrtab = upsample->Cr_r_tab;
  154399. int * Cbbtab = upsample->Cb_b_tab;
  154400. INT32 * Crgtab = upsample->Cr_g_tab;
  154401. INT32 * Cbgtab = upsample->Cb_g_tab;
  154402. SHIFT_TEMPS
  154403. inptr00 = input_buf[0][in_row_group_ctr*2];
  154404. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  154405. inptr1 = input_buf[1][in_row_group_ctr];
  154406. inptr2 = input_buf[2][in_row_group_ctr];
  154407. outptr0 = output_buf[0];
  154408. outptr1 = output_buf[1];
  154409. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154410. cb = GETJSAMPLE(*inptr1++);
  154411. cr = GETJSAMPLE(*inptr2++);
  154412. cred = Crrtab[cr];
  154413. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154414. cblue = Cbbtab[cb];
  154415. y = GETJSAMPLE(*inptr00++);
  154416. outptr0[RGB_RED] = range_limit[y + cred];
  154417. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154418. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154419. outptr0 += RGB_PIXELSIZE;
  154420. y = GETJSAMPLE(*inptr00++);
  154421. outptr0[RGB_RED] = range_limit[y + cred];
  154422. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154423. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154424. outptr0 += RGB_PIXELSIZE;
  154425. y = GETJSAMPLE(*inptr01++);
  154426. outptr1[RGB_RED] = range_limit[y + cred];
  154427. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154428. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154429. outptr1 += RGB_PIXELSIZE;
  154430. y = GETJSAMPLE(*inptr01++);
  154431. outptr1[RGB_RED] = range_limit[y + cred];
  154432. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154433. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154434. outptr1 += RGB_PIXELSIZE;
  154435. }
  154436. if (cinfo->output_width & 1) {
  154437. cb = GETJSAMPLE(*inptr1);
  154438. cr = GETJSAMPLE(*inptr2);
  154439. cred = Crrtab[cr];
  154440. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154441. cblue = Cbbtab[cb];
  154442. y = GETJSAMPLE(*inptr00);
  154443. outptr0[RGB_RED] = range_limit[y + cred];
  154444. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154445. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154446. y = GETJSAMPLE(*inptr01);
  154447. outptr1[RGB_RED] = range_limit[y + cred];
  154448. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154449. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154450. }
  154451. }
  154452. GLOBAL(void)
  154453. jinit_merged_upsampler (j_decompress_ptr cinfo)
  154454. {
  154455. my_upsample_ptr upsample;
  154456. upsample = (my_upsample_ptr)
  154457. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154458. SIZEOF(my_upsampler));
  154459. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154460. upsample->pub.start_pass = start_pass_merged_upsample;
  154461. upsample->pub.need_context_rows = FALSE;
  154462. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  154463. if (cinfo->max_v_samp_factor == 2) {
  154464. upsample->pub.upsample = merged_2v_upsample;
  154465. upsample->upmethod = h2v2_merged_upsample;
  154466. upsample->spare_row = (JSAMPROW)
  154467. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154468. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  154469. } else {
  154470. upsample->pub.upsample = merged_1v_upsample;
  154471. upsample->upmethod = h2v1_merged_upsample;
  154472. upsample->spare_row = NULL;
  154473. }
  154474. build_ycc_rgb_table2(cinfo);
  154475. }
  154476. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  154477. /*** End of inlined file: jdmerge.c ***/
  154478. #undef ASSIGN_STATE
  154479. /*** Start of inlined file: jdphuff.c ***/
  154480. #define JPEG_INTERNALS
  154481. #ifdef D_PROGRESSIVE_SUPPORTED
  154482. typedef struct {
  154483. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  154484. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  154485. } savable_state3;
  154486. #ifndef NO_STRUCT_ASSIGN
  154487. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  154488. #else
  154489. #if MAX_COMPS_IN_SCAN == 4
  154490. #define ASSIGN_STATE(dest,src) \
  154491. ((dest).EOBRUN = (src).EOBRUN, \
  154492. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  154493. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  154494. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  154495. (dest).last_dc_val[3] = (src).last_dc_val[3])
  154496. #endif
  154497. #endif
  154498. typedef struct {
  154499. struct jpeg_entropy_decoder pub; /* public fields */
  154500. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  154501. savable_state3 saved; /* Other state at start of MCU */
  154502. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  154503. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  154504. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  154505. } phuff_entropy_decoder;
  154506. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  154507. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  154508. JBLOCKROW *MCU_data));
  154509. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  154510. JBLOCKROW *MCU_data));
  154511. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  154512. JBLOCKROW *MCU_data));
  154513. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  154514. JBLOCKROW *MCU_data));
  154515. METHODDEF(void)
  154516. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  154517. {
  154518. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154519. boolean is_DC_band, bad;
  154520. int ci, coefi, tbl;
  154521. int *coef_bit_ptr;
  154522. jpeg_component_info * compptr;
  154523. is_DC_band = (cinfo->Ss == 0);
  154524. bad = FALSE;
  154525. if (is_DC_band) {
  154526. if (cinfo->Se != 0)
  154527. bad = TRUE;
  154528. } else {
  154529. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154530. bad = TRUE;
  154531. if (cinfo->comps_in_scan != 1)
  154532. bad = TRUE;
  154533. }
  154534. if (cinfo->Ah != 0) {
  154535. if (cinfo->Al != cinfo->Ah-1)
  154536. bad = TRUE;
  154537. }
  154538. if (cinfo->Al > 13) /* need not check for < 0 */
  154539. bad = TRUE;
  154540. if (bad)
  154541. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154542. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154543. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154544. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154545. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154546. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154547. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154548. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154549. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154550. if (cinfo->Ah != expected)
  154551. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154552. coef_bit_ptr[coefi] = cinfo->Al;
  154553. }
  154554. }
  154555. if (cinfo->Ah == 0) {
  154556. if (is_DC_band)
  154557. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154558. else
  154559. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154560. } else {
  154561. if (is_DC_band)
  154562. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154563. else
  154564. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154565. }
  154566. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154567. compptr = cinfo->cur_comp_info[ci];
  154568. if (is_DC_band) {
  154569. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154570. tbl = compptr->dc_tbl_no;
  154571. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154572. & entropy->derived_tbls[tbl]);
  154573. }
  154574. } else {
  154575. tbl = compptr->ac_tbl_no;
  154576. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154577. & entropy->derived_tbls[tbl]);
  154578. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154579. }
  154580. entropy->saved.last_dc_val[ci] = 0;
  154581. }
  154582. entropy->bitstate.bits_left = 0;
  154583. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154584. entropy->pub.insufficient_data = FALSE;
  154585. entropy->saved.EOBRUN = 0;
  154586. entropy->restarts_to_go = cinfo->restart_interval;
  154587. }
  154588. LOCAL(boolean)
  154589. process_restartp (j_decompress_ptr cinfo)
  154590. {
  154591. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154592. int ci;
  154593. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154594. entropy->bitstate.bits_left = 0;
  154595. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154596. return FALSE;
  154597. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154598. entropy->saved.last_dc_val[ci] = 0;
  154599. entropy->saved.EOBRUN = 0;
  154600. entropy->restarts_to_go = cinfo->restart_interval;
  154601. if (cinfo->unread_marker == 0)
  154602. entropy->pub.insufficient_data = FALSE;
  154603. return TRUE;
  154604. }
  154605. METHODDEF(boolean)
  154606. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154607. {
  154608. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154609. int Al = cinfo->Al;
  154610. register int s, r;
  154611. int blkn, ci;
  154612. JBLOCKROW block;
  154613. BITREAD_STATE_VARS;
  154614. savable_state3 state;
  154615. d_derived_tbl * tbl;
  154616. jpeg_component_info * compptr;
  154617. if (cinfo->restart_interval) {
  154618. if (entropy->restarts_to_go == 0)
  154619. if (! process_restartp(cinfo))
  154620. return FALSE;
  154621. }
  154622. if (! entropy->pub.insufficient_data) {
  154623. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154624. ASSIGN_STATE(state, entropy->saved);
  154625. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154626. block = MCU_data[blkn];
  154627. ci = cinfo->MCU_membership[blkn];
  154628. compptr = cinfo->cur_comp_info[ci];
  154629. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154630. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154631. if (s) {
  154632. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154633. r = GET_BITS(s);
  154634. s = HUFF_EXTEND(r, s);
  154635. }
  154636. s += state.last_dc_val[ci];
  154637. state.last_dc_val[ci] = s;
  154638. (*block)[0] = (JCOEF) (s << Al);
  154639. }
  154640. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154641. ASSIGN_STATE(entropy->saved, state);
  154642. }
  154643. entropy->restarts_to_go--;
  154644. return TRUE;
  154645. }
  154646. METHODDEF(boolean)
  154647. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154648. {
  154649. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154650. int Se = cinfo->Se;
  154651. int Al = cinfo->Al;
  154652. register int s, k, r;
  154653. unsigned int EOBRUN;
  154654. JBLOCKROW block;
  154655. BITREAD_STATE_VARS;
  154656. d_derived_tbl * tbl;
  154657. if (cinfo->restart_interval) {
  154658. if (entropy->restarts_to_go == 0)
  154659. if (! process_restartp(cinfo))
  154660. return FALSE;
  154661. }
  154662. if (! entropy->pub.insufficient_data) {
  154663. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154664. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154665. EOBRUN--; /* ...process it now (we do nothing) */
  154666. else {
  154667. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154668. block = MCU_data[0];
  154669. tbl = entropy->ac_derived_tbl;
  154670. for (k = cinfo->Ss; k <= Se; k++) {
  154671. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154672. r = s >> 4;
  154673. s &= 15;
  154674. if (s) {
  154675. k += r;
  154676. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154677. r = GET_BITS(s);
  154678. s = HUFF_EXTEND(r, s);
  154679. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154680. } else {
  154681. if (r == 15) { /* ZRL */
  154682. k += 15; /* skip 15 zeroes in band */
  154683. } else { /* EOBr, run length is 2^r + appended bits */
  154684. EOBRUN = 1 << r;
  154685. if (r) { /* EOBr, r > 0 */
  154686. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154687. r = GET_BITS(r);
  154688. EOBRUN += r;
  154689. }
  154690. EOBRUN--; /* this band is processed at this moment */
  154691. break; /* force end-of-band */
  154692. }
  154693. }
  154694. }
  154695. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154696. }
  154697. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154698. }
  154699. entropy->restarts_to_go--;
  154700. return TRUE;
  154701. }
  154702. METHODDEF(boolean)
  154703. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154704. {
  154705. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154706. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154707. int blkn;
  154708. JBLOCKROW block;
  154709. BITREAD_STATE_VARS;
  154710. if (cinfo->restart_interval) {
  154711. if (entropy->restarts_to_go == 0)
  154712. if (! process_restartp(cinfo))
  154713. return FALSE;
  154714. }
  154715. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154716. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154717. block = MCU_data[blkn];
  154718. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154719. if (GET_BITS(1))
  154720. (*block)[0] |= p1;
  154721. }
  154722. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154723. entropy->restarts_to_go--;
  154724. return TRUE;
  154725. }
  154726. METHODDEF(boolean)
  154727. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154728. {
  154729. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154730. int Se = cinfo->Se;
  154731. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154732. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154733. register int s, k, r;
  154734. unsigned int EOBRUN;
  154735. JBLOCKROW block;
  154736. JCOEFPTR thiscoef;
  154737. BITREAD_STATE_VARS;
  154738. d_derived_tbl * tbl;
  154739. int num_newnz;
  154740. int newnz_pos[DCTSIZE2];
  154741. if (cinfo->restart_interval) {
  154742. if (entropy->restarts_to_go == 0)
  154743. if (! process_restartp(cinfo))
  154744. return FALSE;
  154745. }
  154746. if (! entropy->pub.insufficient_data) {
  154747. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154748. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154749. block = MCU_data[0];
  154750. tbl = entropy->ac_derived_tbl;
  154751. num_newnz = 0;
  154752. k = cinfo->Ss;
  154753. if (EOBRUN == 0) {
  154754. for (; k <= Se; k++) {
  154755. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154756. r = s >> 4;
  154757. s &= 15;
  154758. if (s) {
  154759. if (s != 1) /* size of new coef should always be 1 */
  154760. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154761. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154762. if (GET_BITS(1))
  154763. s = p1; /* newly nonzero coef is positive */
  154764. else
  154765. s = m1; /* newly nonzero coef is negative */
  154766. } else {
  154767. if (r != 15) {
  154768. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154769. if (r) {
  154770. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154771. r = GET_BITS(r);
  154772. EOBRUN += r;
  154773. }
  154774. break; /* rest of block is handled by EOB logic */
  154775. }
  154776. }
  154777. do {
  154778. thiscoef = *block + jpeg_natural_order[k];
  154779. if (*thiscoef != 0) {
  154780. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154781. if (GET_BITS(1)) {
  154782. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154783. if (*thiscoef >= 0)
  154784. *thiscoef += p1;
  154785. else
  154786. *thiscoef += m1;
  154787. }
  154788. }
  154789. } else {
  154790. if (--r < 0)
  154791. break; /* reached target zero coefficient */
  154792. }
  154793. k++;
  154794. } while (k <= Se);
  154795. if (s) {
  154796. int pos = jpeg_natural_order[k];
  154797. (*block)[pos] = (JCOEF) s;
  154798. newnz_pos[num_newnz++] = pos;
  154799. }
  154800. }
  154801. }
  154802. if (EOBRUN > 0) {
  154803. for (; k <= Se; k++) {
  154804. thiscoef = *block + jpeg_natural_order[k];
  154805. if (*thiscoef != 0) {
  154806. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154807. if (GET_BITS(1)) {
  154808. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154809. if (*thiscoef >= 0)
  154810. *thiscoef += p1;
  154811. else
  154812. *thiscoef += m1;
  154813. }
  154814. }
  154815. }
  154816. }
  154817. EOBRUN--;
  154818. }
  154819. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154820. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154821. }
  154822. entropy->restarts_to_go--;
  154823. return TRUE;
  154824. undoit:
  154825. while (num_newnz > 0)
  154826. (*block)[newnz_pos[--num_newnz]] = 0;
  154827. return FALSE;
  154828. }
  154829. GLOBAL(void)
  154830. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154831. {
  154832. phuff_entropy_ptr2 entropy;
  154833. int *coef_bit_ptr;
  154834. int ci, i;
  154835. entropy = (phuff_entropy_ptr2)
  154836. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154837. SIZEOF(phuff_entropy_decoder));
  154838. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154839. entropy->pub.start_pass = start_pass_phuff_decoder;
  154840. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154841. entropy->derived_tbls[i] = NULL;
  154842. }
  154843. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154844. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154845. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154846. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154847. for (ci = 0; ci < cinfo->num_components; ci++)
  154848. for (i = 0; i < DCTSIZE2; i++)
  154849. *coef_bit_ptr++ = -1;
  154850. }
  154851. #endif /* D_PROGRESSIVE_SUPPORTED */
  154852. /*** End of inlined file: jdphuff.c ***/
  154853. /*** Start of inlined file: jdpostct.c ***/
  154854. #define JPEG_INTERNALS
  154855. typedef struct {
  154856. struct jpeg_d_post_controller pub; /* public fields */
  154857. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154858. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154859. JDIMENSION strip_height; /* buffer size in rows */
  154860. JDIMENSION starting_row; /* row # of first row in current strip */
  154861. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154862. } my_post_controller;
  154863. typedef my_post_controller * my_post_ptr;
  154864. METHODDEF(void) post_process_1pass
  154865. JPP((j_decompress_ptr cinfo,
  154866. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154867. JDIMENSION in_row_groups_avail,
  154868. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154869. JDIMENSION out_rows_avail));
  154870. #ifdef QUANT_2PASS_SUPPORTED
  154871. METHODDEF(void) post_process_prepass
  154872. JPP((j_decompress_ptr cinfo,
  154873. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154874. JDIMENSION in_row_groups_avail,
  154875. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154876. JDIMENSION out_rows_avail));
  154877. METHODDEF(void) post_process_2pass
  154878. JPP((j_decompress_ptr cinfo,
  154879. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154880. JDIMENSION in_row_groups_avail,
  154881. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154882. JDIMENSION out_rows_avail));
  154883. #endif
  154884. METHODDEF(void)
  154885. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154886. {
  154887. my_post_ptr post = (my_post_ptr) cinfo->post;
  154888. switch (pass_mode) {
  154889. case JBUF_PASS_THRU:
  154890. if (cinfo->quantize_colors) {
  154891. post->pub.post_process_data = post_process_1pass;
  154892. if (post->buffer == NULL) {
  154893. post->buffer = (*cinfo->mem->access_virt_sarray)
  154894. ((j_common_ptr) cinfo, post->whole_image,
  154895. (JDIMENSION) 0, post->strip_height, TRUE);
  154896. }
  154897. } else {
  154898. post->pub.post_process_data = cinfo->upsample->upsample;
  154899. }
  154900. break;
  154901. #ifdef QUANT_2PASS_SUPPORTED
  154902. case JBUF_SAVE_AND_PASS:
  154903. if (post->whole_image == NULL)
  154904. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154905. post->pub.post_process_data = post_process_prepass;
  154906. break;
  154907. case JBUF_CRANK_DEST:
  154908. if (post->whole_image == NULL)
  154909. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154910. post->pub.post_process_data = post_process_2pass;
  154911. break;
  154912. #endif /* QUANT_2PASS_SUPPORTED */
  154913. default:
  154914. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154915. break;
  154916. }
  154917. post->starting_row = post->next_row = 0;
  154918. }
  154919. METHODDEF(void)
  154920. post_process_1pass (j_decompress_ptr cinfo,
  154921. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154922. JDIMENSION in_row_groups_avail,
  154923. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154924. JDIMENSION out_rows_avail)
  154925. {
  154926. my_post_ptr post = (my_post_ptr) cinfo->post;
  154927. JDIMENSION num_rows, max_rows;
  154928. max_rows = out_rows_avail - *out_row_ctr;
  154929. if (max_rows > post->strip_height)
  154930. max_rows = post->strip_height;
  154931. num_rows = 0;
  154932. (*cinfo->upsample->upsample) (cinfo,
  154933. input_buf, in_row_group_ctr, in_row_groups_avail,
  154934. post->buffer, &num_rows, max_rows);
  154935. (*cinfo->cquantize->color_quantize) (cinfo,
  154936. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154937. *out_row_ctr += num_rows;
  154938. }
  154939. #ifdef QUANT_2PASS_SUPPORTED
  154940. METHODDEF(void)
  154941. post_process_prepass (j_decompress_ptr cinfo,
  154942. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154943. JDIMENSION in_row_groups_avail,
  154944. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154945. JDIMENSION out_rows_avail)
  154946. {
  154947. my_post_ptr post = (my_post_ptr) cinfo->post;
  154948. JDIMENSION old_next_row, num_rows;
  154949. if (post->next_row == 0) {
  154950. post->buffer = (*cinfo->mem->access_virt_sarray)
  154951. ((j_common_ptr) cinfo, post->whole_image,
  154952. post->starting_row, post->strip_height, TRUE);
  154953. }
  154954. old_next_row = post->next_row;
  154955. (*cinfo->upsample->upsample) (cinfo,
  154956. input_buf, in_row_group_ctr, in_row_groups_avail,
  154957. post->buffer, &post->next_row, post->strip_height);
  154958. if (post->next_row > old_next_row) {
  154959. num_rows = post->next_row - old_next_row;
  154960. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154961. (JSAMPARRAY) NULL, (int) num_rows);
  154962. *out_row_ctr += num_rows;
  154963. }
  154964. if (post->next_row >= post->strip_height) {
  154965. post->starting_row += post->strip_height;
  154966. post->next_row = 0;
  154967. }
  154968. }
  154969. METHODDEF(void)
  154970. post_process_2pass (j_decompress_ptr cinfo,
  154971. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154972. JDIMENSION in_row_groups_avail,
  154973. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154974. JDIMENSION out_rows_avail)
  154975. {
  154976. my_post_ptr post = (my_post_ptr) cinfo->post;
  154977. JDIMENSION num_rows, max_rows;
  154978. if (post->next_row == 0) {
  154979. post->buffer = (*cinfo->mem->access_virt_sarray)
  154980. ((j_common_ptr) cinfo, post->whole_image,
  154981. post->starting_row, post->strip_height, FALSE);
  154982. }
  154983. num_rows = post->strip_height - post->next_row; /* available in strip */
  154984. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154985. if (num_rows > max_rows)
  154986. num_rows = max_rows;
  154987. max_rows = cinfo->output_height - post->starting_row;
  154988. if (num_rows > max_rows)
  154989. num_rows = max_rows;
  154990. (*cinfo->cquantize->color_quantize) (cinfo,
  154991. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154992. (int) num_rows);
  154993. *out_row_ctr += num_rows;
  154994. post->next_row += num_rows;
  154995. if (post->next_row >= post->strip_height) {
  154996. post->starting_row += post->strip_height;
  154997. post->next_row = 0;
  154998. }
  154999. }
  155000. #endif /* QUANT_2PASS_SUPPORTED */
  155001. GLOBAL(void)
  155002. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  155003. {
  155004. my_post_ptr post;
  155005. post = (my_post_ptr)
  155006. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155007. SIZEOF(my_post_controller));
  155008. cinfo->post = (struct jpeg_d_post_controller *) post;
  155009. post->pub.start_pass = start_pass_dpost;
  155010. post->whole_image = NULL; /* flag for no virtual arrays */
  155011. post->buffer = NULL; /* flag for no strip buffer */
  155012. if (cinfo->quantize_colors) {
  155013. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  155014. if (need_full_buffer) {
  155015. #ifdef QUANT_2PASS_SUPPORTED
  155016. post->whole_image = (*cinfo->mem->request_virt_sarray)
  155017. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  155018. cinfo->output_width * cinfo->out_color_components,
  155019. (JDIMENSION) jround_up((long) cinfo->output_height,
  155020. (long) post->strip_height),
  155021. post->strip_height);
  155022. #else
  155023. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  155024. #endif /* QUANT_2PASS_SUPPORTED */
  155025. } else {
  155026. post->buffer = (*cinfo->mem->alloc_sarray)
  155027. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155028. cinfo->output_width * cinfo->out_color_components,
  155029. post->strip_height);
  155030. }
  155031. }
  155032. }
  155033. /*** End of inlined file: jdpostct.c ***/
  155034. #undef FIX
  155035. /*** Start of inlined file: jdsample.c ***/
  155036. #define JPEG_INTERNALS
  155037. typedef JMETHOD(void, upsample1_ptr,
  155038. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155039. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  155040. typedef struct {
  155041. struct jpeg_upsampler pub; /* public fields */
  155042. JSAMPARRAY color_buf[MAX_COMPONENTS];
  155043. upsample1_ptr methods[MAX_COMPONENTS];
  155044. int next_row_out; /* counts rows emitted from color_buf */
  155045. JDIMENSION rows_to_go; /* counts rows remaining in image */
  155046. int rowgroup_height[MAX_COMPONENTS];
  155047. UINT8 h_expand[MAX_COMPONENTS];
  155048. UINT8 v_expand[MAX_COMPONENTS];
  155049. } my_upsampler2;
  155050. typedef my_upsampler2 * my_upsample_ptr2;
  155051. METHODDEF(void)
  155052. start_pass_upsample (j_decompress_ptr cinfo)
  155053. {
  155054. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155055. upsample->next_row_out = cinfo->max_v_samp_factor;
  155056. upsample->rows_to_go = cinfo->output_height;
  155057. }
  155058. METHODDEF(void)
  155059. sep_upsample (j_decompress_ptr cinfo,
  155060. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155061. JDIMENSION in_row_groups_avail,
  155062. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155063. JDIMENSION out_rows_avail)
  155064. {
  155065. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155066. int ci;
  155067. jpeg_component_info * compptr;
  155068. JDIMENSION num_rows;
  155069. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  155070. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  155071. ci++, compptr++) {
  155072. (*upsample->methods[ci]) (cinfo, compptr,
  155073. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  155074. upsample->color_buf + ci);
  155075. }
  155076. upsample->next_row_out = 0;
  155077. }
  155078. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  155079. if (num_rows > upsample->rows_to_go)
  155080. num_rows = upsample->rows_to_go;
  155081. out_rows_avail -= *out_row_ctr;
  155082. if (num_rows > out_rows_avail)
  155083. num_rows = out_rows_avail;
  155084. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  155085. (JDIMENSION) upsample->next_row_out,
  155086. output_buf + *out_row_ctr,
  155087. (int) num_rows);
  155088. *out_row_ctr += num_rows;
  155089. upsample->rows_to_go -= num_rows;
  155090. upsample->next_row_out += num_rows;
  155091. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  155092. (*in_row_group_ctr)++;
  155093. }
  155094. METHODDEF(void)
  155095. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155096. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155097. {
  155098. *output_data_ptr = input_data;
  155099. }
  155100. METHODDEF(void)
  155101. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155102. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155103. {
  155104. *output_data_ptr = NULL; /* safety check */
  155105. }
  155106. METHODDEF(void)
  155107. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155108. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155109. {
  155110. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155111. JSAMPARRAY output_data = *output_data_ptr;
  155112. register JSAMPROW inptr, outptr;
  155113. register JSAMPLE invalue;
  155114. register int h;
  155115. JSAMPROW outend;
  155116. int h_expand, v_expand;
  155117. int inrow, outrow;
  155118. h_expand = upsample->h_expand[compptr->component_index];
  155119. v_expand = upsample->v_expand[compptr->component_index];
  155120. inrow = outrow = 0;
  155121. while (outrow < cinfo->max_v_samp_factor) {
  155122. inptr = input_data[inrow];
  155123. outptr = output_data[outrow];
  155124. outend = outptr + cinfo->output_width;
  155125. while (outptr < outend) {
  155126. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155127. for (h = h_expand; h > 0; h--) {
  155128. *outptr++ = invalue;
  155129. }
  155130. }
  155131. if (v_expand > 1) {
  155132. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155133. v_expand-1, cinfo->output_width);
  155134. }
  155135. inrow++;
  155136. outrow += v_expand;
  155137. }
  155138. }
  155139. METHODDEF(void)
  155140. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155141. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155142. {
  155143. JSAMPARRAY output_data = *output_data_ptr;
  155144. register JSAMPROW inptr, outptr;
  155145. register JSAMPLE invalue;
  155146. JSAMPROW outend;
  155147. int inrow;
  155148. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155149. inptr = input_data[inrow];
  155150. outptr = output_data[inrow];
  155151. outend = outptr + cinfo->output_width;
  155152. while (outptr < outend) {
  155153. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155154. *outptr++ = invalue;
  155155. *outptr++ = invalue;
  155156. }
  155157. }
  155158. }
  155159. METHODDEF(void)
  155160. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155161. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155162. {
  155163. JSAMPARRAY output_data = *output_data_ptr;
  155164. register JSAMPROW inptr, outptr;
  155165. register JSAMPLE invalue;
  155166. JSAMPROW outend;
  155167. int inrow, outrow;
  155168. inrow = outrow = 0;
  155169. while (outrow < cinfo->max_v_samp_factor) {
  155170. inptr = input_data[inrow];
  155171. outptr = output_data[outrow];
  155172. outend = outptr + cinfo->output_width;
  155173. while (outptr < outend) {
  155174. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155175. *outptr++ = invalue;
  155176. *outptr++ = invalue;
  155177. }
  155178. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155179. 1, cinfo->output_width);
  155180. inrow++;
  155181. outrow += 2;
  155182. }
  155183. }
  155184. METHODDEF(void)
  155185. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155186. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155187. {
  155188. JSAMPARRAY output_data = *output_data_ptr;
  155189. register JSAMPROW inptr, outptr;
  155190. register int invalue;
  155191. register JDIMENSION colctr;
  155192. int inrow;
  155193. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155194. inptr = input_data[inrow];
  155195. outptr = output_data[inrow];
  155196. invalue = GETJSAMPLE(*inptr++);
  155197. *outptr++ = (JSAMPLE) invalue;
  155198. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  155199. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155200. invalue = GETJSAMPLE(*inptr++) * 3;
  155201. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  155202. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  155203. }
  155204. invalue = GETJSAMPLE(*inptr);
  155205. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  155206. *outptr++ = (JSAMPLE) invalue;
  155207. }
  155208. }
  155209. METHODDEF(void)
  155210. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155211. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155212. {
  155213. JSAMPARRAY output_data = *output_data_ptr;
  155214. register JSAMPROW inptr0, inptr1, outptr;
  155215. #if BITS_IN_JSAMPLE == 8
  155216. register int thiscolsum, lastcolsum, nextcolsum;
  155217. #else
  155218. register INT32 thiscolsum, lastcolsum, nextcolsum;
  155219. #endif
  155220. register JDIMENSION colctr;
  155221. int inrow, outrow, v;
  155222. inrow = outrow = 0;
  155223. while (outrow < cinfo->max_v_samp_factor) {
  155224. for (v = 0; v < 2; v++) {
  155225. inptr0 = input_data[inrow];
  155226. if (v == 0) /* next nearest is row above */
  155227. inptr1 = input_data[inrow-1];
  155228. else /* next nearest is row below */
  155229. inptr1 = input_data[inrow+1];
  155230. outptr = output_data[outrow++];
  155231. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155232. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155233. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  155234. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155235. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155236. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155237. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155238. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155239. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155240. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155241. }
  155242. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155243. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  155244. }
  155245. inrow++;
  155246. }
  155247. }
  155248. GLOBAL(void)
  155249. jinit_upsampler (j_decompress_ptr cinfo)
  155250. {
  155251. my_upsample_ptr2 upsample;
  155252. int ci;
  155253. jpeg_component_info * compptr;
  155254. boolean need_buffer, do_fancy;
  155255. int h_in_group, v_in_group, h_out_group, v_out_group;
  155256. upsample = (my_upsample_ptr2)
  155257. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155258. SIZEOF(my_upsampler2));
  155259. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  155260. upsample->pub.start_pass = start_pass_upsample;
  155261. upsample->pub.upsample = sep_upsample;
  155262. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  155263. if (cinfo->CCIR601_sampling) /* this isn't supported */
  155264. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  155265. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  155266. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  155267. ci++, compptr++) {
  155268. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  155269. cinfo->min_DCT_scaled_size;
  155270. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  155271. cinfo->min_DCT_scaled_size;
  155272. h_out_group = cinfo->max_h_samp_factor;
  155273. v_out_group = cinfo->max_v_samp_factor;
  155274. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  155275. need_buffer = TRUE;
  155276. if (! compptr->component_needed) {
  155277. upsample->methods[ci] = noop_upsample;
  155278. need_buffer = FALSE;
  155279. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  155280. upsample->methods[ci] = fullsize_upsample;
  155281. need_buffer = FALSE;
  155282. } else if (h_in_group * 2 == h_out_group &&
  155283. v_in_group == v_out_group) {
  155284. if (do_fancy && compptr->downsampled_width > 2)
  155285. upsample->methods[ci] = h2v1_fancy_upsample;
  155286. else
  155287. upsample->methods[ci] = h2v1_upsample;
  155288. } else if (h_in_group * 2 == h_out_group &&
  155289. v_in_group * 2 == v_out_group) {
  155290. if (do_fancy && compptr->downsampled_width > 2) {
  155291. upsample->methods[ci] = h2v2_fancy_upsample;
  155292. upsample->pub.need_context_rows = TRUE;
  155293. } else
  155294. upsample->methods[ci] = h2v2_upsample;
  155295. } else if ((h_out_group % h_in_group) == 0 &&
  155296. (v_out_group % v_in_group) == 0) {
  155297. upsample->methods[ci] = int_upsample;
  155298. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  155299. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  155300. } else
  155301. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  155302. if (need_buffer) {
  155303. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  155304. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155305. (JDIMENSION) jround_up((long) cinfo->output_width,
  155306. (long) cinfo->max_h_samp_factor),
  155307. (JDIMENSION) cinfo->max_v_samp_factor);
  155308. }
  155309. }
  155310. }
  155311. /*** End of inlined file: jdsample.c ***/
  155312. /*** Start of inlined file: jdtrans.c ***/
  155313. #define JPEG_INTERNALS
  155314. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  155315. GLOBAL(jvirt_barray_ptr *)
  155316. jpeg_read_coefficients (j_decompress_ptr cinfo)
  155317. {
  155318. if (cinfo->global_state == DSTATE_READY) {
  155319. transdecode_master_selection(cinfo);
  155320. cinfo->global_state = DSTATE_RDCOEFS;
  155321. }
  155322. if (cinfo->global_state == DSTATE_RDCOEFS) {
  155323. for (;;) {
  155324. int retcode;
  155325. if (cinfo->progress != NULL)
  155326. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  155327. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  155328. if (retcode == JPEG_SUSPENDED)
  155329. return NULL;
  155330. if (retcode == JPEG_REACHED_EOI)
  155331. break;
  155332. if (cinfo->progress != NULL &&
  155333. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  155334. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  155335. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  155336. }
  155337. }
  155338. }
  155339. cinfo->global_state = DSTATE_STOPPING;
  155340. }
  155341. if ((cinfo->global_state == DSTATE_STOPPING ||
  155342. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  155343. return cinfo->coef->coef_arrays;
  155344. }
  155345. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  155346. return NULL; /* keep compiler happy */
  155347. }
  155348. LOCAL(void)
  155349. transdecode_master_selection (j_decompress_ptr cinfo)
  155350. {
  155351. cinfo->buffered_image = TRUE;
  155352. if (cinfo->arith_code) {
  155353. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  155354. } else {
  155355. if (cinfo->progressive_mode) {
  155356. #ifdef D_PROGRESSIVE_SUPPORTED
  155357. jinit_phuff_decoder(cinfo);
  155358. #else
  155359. ERREXIT(cinfo, JERR_NOT_COMPILED);
  155360. #endif
  155361. } else
  155362. jinit_huff_decoder(cinfo);
  155363. }
  155364. jinit_d_coef_controller(cinfo, TRUE);
  155365. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  155366. (*cinfo->inputctl->start_input_pass) (cinfo);
  155367. if (cinfo->progress != NULL) {
  155368. int nscans;
  155369. if (cinfo->progressive_mode) {
  155370. nscans = 2 + 3 * cinfo->num_components;
  155371. } else if (cinfo->inputctl->has_multiple_scans) {
  155372. nscans = cinfo->num_components;
  155373. } else {
  155374. nscans = 1;
  155375. }
  155376. cinfo->progress->pass_counter = 0L;
  155377. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  155378. cinfo->progress->completed_passes = 0;
  155379. cinfo->progress->total_passes = 1;
  155380. }
  155381. }
  155382. /*** End of inlined file: jdtrans.c ***/
  155383. /*** Start of inlined file: jfdctflt.c ***/
  155384. #define JPEG_INTERNALS
  155385. #ifdef DCT_FLOAT_SUPPORTED
  155386. #if DCTSIZE != 8
  155387. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155388. #endif
  155389. GLOBAL(void)
  155390. jpeg_fdct_float (FAST_FLOAT * data)
  155391. {
  155392. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155393. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155394. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  155395. FAST_FLOAT *dataptr;
  155396. int ctr;
  155397. dataptr = data;
  155398. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155399. tmp0 = dataptr[0] + dataptr[7];
  155400. tmp7 = dataptr[0] - dataptr[7];
  155401. tmp1 = dataptr[1] + dataptr[6];
  155402. tmp6 = dataptr[1] - dataptr[6];
  155403. tmp2 = dataptr[2] + dataptr[5];
  155404. tmp5 = dataptr[2] - dataptr[5];
  155405. tmp3 = dataptr[3] + dataptr[4];
  155406. tmp4 = dataptr[3] - dataptr[4];
  155407. tmp10 = tmp0 + tmp3; /* phase 2 */
  155408. tmp13 = tmp0 - tmp3;
  155409. tmp11 = tmp1 + tmp2;
  155410. tmp12 = tmp1 - tmp2;
  155411. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155412. dataptr[4] = tmp10 - tmp11;
  155413. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155414. dataptr[2] = tmp13 + z1; /* phase 5 */
  155415. dataptr[6] = tmp13 - z1;
  155416. tmp10 = tmp4 + tmp5; /* phase 2 */
  155417. tmp11 = tmp5 + tmp6;
  155418. tmp12 = tmp6 + tmp7;
  155419. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155420. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155421. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155422. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155423. z11 = tmp7 + z3; /* phase 5 */
  155424. z13 = tmp7 - z3;
  155425. dataptr[5] = z13 + z2; /* phase 6 */
  155426. dataptr[3] = z13 - z2;
  155427. dataptr[1] = z11 + z4;
  155428. dataptr[7] = z11 - z4;
  155429. dataptr += DCTSIZE; /* advance pointer to next row */
  155430. }
  155431. dataptr = data;
  155432. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155433. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155434. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155435. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155436. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155437. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155438. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155439. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155440. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155441. tmp10 = tmp0 + tmp3; /* phase 2 */
  155442. tmp13 = tmp0 - tmp3;
  155443. tmp11 = tmp1 + tmp2;
  155444. tmp12 = tmp1 - tmp2;
  155445. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155446. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155447. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155448. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155449. dataptr[DCTSIZE*6] = tmp13 - z1;
  155450. tmp10 = tmp4 + tmp5; /* phase 2 */
  155451. tmp11 = tmp5 + tmp6;
  155452. tmp12 = tmp6 + tmp7;
  155453. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155454. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155455. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155456. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155457. z11 = tmp7 + z3; /* phase 5 */
  155458. z13 = tmp7 - z3;
  155459. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155460. dataptr[DCTSIZE*3] = z13 - z2;
  155461. dataptr[DCTSIZE*1] = z11 + z4;
  155462. dataptr[DCTSIZE*7] = z11 - z4;
  155463. dataptr++; /* advance pointer to next column */
  155464. }
  155465. }
  155466. #endif /* DCT_FLOAT_SUPPORTED */
  155467. /*** End of inlined file: jfdctflt.c ***/
  155468. /*** Start of inlined file: jfdctint.c ***/
  155469. #define JPEG_INTERNALS
  155470. #ifdef DCT_ISLOW_SUPPORTED
  155471. #if DCTSIZE != 8
  155472. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155473. #endif
  155474. #if BITS_IN_JSAMPLE == 8
  155475. #define CONST_BITS 13
  155476. #define PASS1_BITS 2
  155477. #else
  155478. #define CONST_BITS 13
  155479. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155480. #endif
  155481. #if CONST_BITS == 13
  155482. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155483. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155484. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155485. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155486. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155487. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155488. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155489. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155490. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155491. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155492. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155493. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155494. #else
  155495. #define FIX_0_298631336 FIX(0.298631336)
  155496. #define FIX_0_390180644 FIX(0.390180644)
  155497. #define FIX_0_541196100 FIX(0.541196100)
  155498. #define FIX_0_765366865 FIX(0.765366865)
  155499. #define FIX_0_899976223 FIX(0.899976223)
  155500. #define FIX_1_175875602 FIX(1.175875602)
  155501. #define FIX_1_501321110 FIX(1.501321110)
  155502. #define FIX_1_847759065 FIX(1.847759065)
  155503. #define FIX_1_961570560 FIX(1.961570560)
  155504. #define FIX_2_053119869 FIX(2.053119869)
  155505. #define FIX_2_562915447 FIX(2.562915447)
  155506. #define FIX_3_072711026 FIX(3.072711026)
  155507. #endif
  155508. #if BITS_IN_JSAMPLE == 8
  155509. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155510. #else
  155511. #define MULTIPLY(var,const) ((var) * (const))
  155512. #endif
  155513. GLOBAL(void)
  155514. jpeg_fdct_islow (DCTELEM * data)
  155515. {
  155516. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155517. INT32 tmp10, tmp11, tmp12, tmp13;
  155518. INT32 z1, z2, z3, z4, z5;
  155519. DCTELEM *dataptr;
  155520. int ctr;
  155521. SHIFT_TEMPS
  155522. dataptr = data;
  155523. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155524. tmp0 = dataptr[0] + dataptr[7];
  155525. tmp7 = dataptr[0] - dataptr[7];
  155526. tmp1 = dataptr[1] + dataptr[6];
  155527. tmp6 = dataptr[1] - dataptr[6];
  155528. tmp2 = dataptr[2] + dataptr[5];
  155529. tmp5 = dataptr[2] - dataptr[5];
  155530. tmp3 = dataptr[3] + dataptr[4];
  155531. tmp4 = dataptr[3] - dataptr[4];
  155532. tmp10 = tmp0 + tmp3;
  155533. tmp13 = tmp0 - tmp3;
  155534. tmp11 = tmp1 + tmp2;
  155535. tmp12 = tmp1 - tmp2;
  155536. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155537. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155538. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155539. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155540. CONST_BITS-PASS1_BITS);
  155541. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155542. CONST_BITS-PASS1_BITS);
  155543. z1 = tmp4 + tmp7;
  155544. z2 = tmp5 + tmp6;
  155545. z3 = tmp4 + tmp6;
  155546. z4 = tmp5 + tmp7;
  155547. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155548. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155549. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155550. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155551. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155552. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155553. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155554. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155555. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155556. z3 += z5;
  155557. z4 += z5;
  155558. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155559. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155560. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155561. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155562. dataptr += DCTSIZE; /* advance pointer to next row */
  155563. }
  155564. dataptr = data;
  155565. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155566. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155567. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155568. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155569. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155570. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155571. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155572. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155573. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155574. tmp10 = tmp0 + tmp3;
  155575. tmp13 = tmp0 - tmp3;
  155576. tmp11 = tmp1 + tmp2;
  155577. tmp12 = tmp1 - tmp2;
  155578. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155579. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155580. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155581. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155582. CONST_BITS+PASS1_BITS);
  155583. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155584. CONST_BITS+PASS1_BITS);
  155585. z1 = tmp4 + tmp7;
  155586. z2 = tmp5 + tmp6;
  155587. z3 = tmp4 + tmp6;
  155588. z4 = tmp5 + tmp7;
  155589. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155590. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155591. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155592. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155593. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155594. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155595. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155596. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155597. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155598. z3 += z5;
  155599. z4 += z5;
  155600. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155601. CONST_BITS+PASS1_BITS);
  155602. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155603. CONST_BITS+PASS1_BITS);
  155604. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155605. CONST_BITS+PASS1_BITS);
  155606. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155607. CONST_BITS+PASS1_BITS);
  155608. dataptr++; /* advance pointer to next column */
  155609. }
  155610. }
  155611. #endif /* DCT_ISLOW_SUPPORTED */
  155612. /*** End of inlined file: jfdctint.c ***/
  155613. #undef CONST_BITS
  155614. #undef MULTIPLY
  155615. #undef FIX_0_541196100
  155616. /*** Start of inlined file: jfdctfst.c ***/
  155617. #define JPEG_INTERNALS
  155618. #ifdef DCT_IFAST_SUPPORTED
  155619. #if DCTSIZE != 8
  155620. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155621. #endif
  155622. #define CONST_BITS 8
  155623. #if CONST_BITS == 8
  155624. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155625. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155626. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155627. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155628. #else
  155629. #define FIX_0_382683433 FIX(0.382683433)
  155630. #define FIX_0_541196100 FIX(0.541196100)
  155631. #define FIX_0_707106781 FIX(0.707106781)
  155632. #define FIX_1_306562965 FIX(1.306562965)
  155633. #endif
  155634. #ifndef USE_ACCURATE_ROUNDING
  155635. #undef DESCALE
  155636. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155637. #endif
  155638. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155639. GLOBAL(void)
  155640. jpeg_fdct_ifast (DCTELEM * data)
  155641. {
  155642. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155643. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155644. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155645. DCTELEM *dataptr;
  155646. int ctr;
  155647. SHIFT_TEMPS
  155648. dataptr = data;
  155649. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155650. tmp0 = dataptr[0] + dataptr[7];
  155651. tmp7 = dataptr[0] - dataptr[7];
  155652. tmp1 = dataptr[1] + dataptr[6];
  155653. tmp6 = dataptr[1] - dataptr[6];
  155654. tmp2 = dataptr[2] + dataptr[5];
  155655. tmp5 = dataptr[2] - dataptr[5];
  155656. tmp3 = dataptr[3] + dataptr[4];
  155657. tmp4 = dataptr[3] - dataptr[4];
  155658. tmp10 = tmp0 + tmp3; /* phase 2 */
  155659. tmp13 = tmp0 - tmp3;
  155660. tmp11 = tmp1 + tmp2;
  155661. tmp12 = tmp1 - tmp2;
  155662. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155663. dataptr[4] = tmp10 - tmp11;
  155664. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155665. dataptr[2] = tmp13 + z1; /* phase 5 */
  155666. dataptr[6] = tmp13 - z1;
  155667. tmp10 = tmp4 + tmp5; /* phase 2 */
  155668. tmp11 = tmp5 + tmp6;
  155669. tmp12 = tmp6 + tmp7;
  155670. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155671. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155672. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155673. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155674. z11 = tmp7 + z3; /* phase 5 */
  155675. z13 = tmp7 - z3;
  155676. dataptr[5] = z13 + z2; /* phase 6 */
  155677. dataptr[3] = z13 - z2;
  155678. dataptr[1] = z11 + z4;
  155679. dataptr[7] = z11 - z4;
  155680. dataptr += DCTSIZE; /* advance pointer to next row */
  155681. }
  155682. dataptr = data;
  155683. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155684. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155685. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155686. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155687. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155688. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155689. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155690. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155691. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155692. tmp10 = tmp0 + tmp3; /* phase 2 */
  155693. tmp13 = tmp0 - tmp3;
  155694. tmp11 = tmp1 + tmp2;
  155695. tmp12 = tmp1 - tmp2;
  155696. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155697. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155698. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155699. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155700. dataptr[DCTSIZE*6] = tmp13 - z1;
  155701. tmp10 = tmp4 + tmp5; /* phase 2 */
  155702. tmp11 = tmp5 + tmp6;
  155703. tmp12 = tmp6 + tmp7;
  155704. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155705. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155706. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155707. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155708. z11 = tmp7 + z3; /* phase 5 */
  155709. z13 = tmp7 - z3;
  155710. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155711. dataptr[DCTSIZE*3] = z13 - z2;
  155712. dataptr[DCTSIZE*1] = z11 + z4;
  155713. dataptr[DCTSIZE*7] = z11 - z4;
  155714. dataptr++; /* advance pointer to next column */
  155715. }
  155716. }
  155717. #endif /* DCT_IFAST_SUPPORTED */
  155718. /*** End of inlined file: jfdctfst.c ***/
  155719. #undef FIX_0_541196100
  155720. /*** Start of inlined file: jidctflt.c ***/
  155721. #define JPEG_INTERNALS
  155722. #ifdef DCT_FLOAT_SUPPORTED
  155723. #if DCTSIZE != 8
  155724. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155725. #endif
  155726. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155727. GLOBAL(void)
  155728. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155729. JCOEFPTR coef_block,
  155730. JSAMPARRAY output_buf, JDIMENSION output_col)
  155731. {
  155732. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155733. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155734. FAST_FLOAT z5, z10, z11, z12, z13;
  155735. JCOEFPTR inptr;
  155736. FLOAT_MULT_TYPE * quantptr;
  155737. FAST_FLOAT * wsptr;
  155738. JSAMPROW outptr;
  155739. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155740. int ctr;
  155741. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155742. SHIFT_TEMPS
  155743. inptr = coef_block;
  155744. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155745. wsptr = workspace;
  155746. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155747. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155748. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155749. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155750. inptr[DCTSIZE*7] == 0) {
  155751. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155752. wsptr[DCTSIZE*0] = dcval;
  155753. wsptr[DCTSIZE*1] = dcval;
  155754. wsptr[DCTSIZE*2] = dcval;
  155755. wsptr[DCTSIZE*3] = dcval;
  155756. wsptr[DCTSIZE*4] = dcval;
  155757. wsptr[DCTSIZE*5] = dcval;
  155758. wsptr[DCTSIZE*6] = dcval;
  155759. wsptr[DCTSIZE*7] = dcval;
  155760. inptr++; /* advance pointers to next column */
  155761. quantptr++;
  155762. wsptr++;
  155763. continue;
  155764. }
  155765. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155766. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155767. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155768. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155769. tmp10 = tmp0 + tmp2; /* phase 3 */
  155770. tmp11 = tmp0 - tmp2;
  155771. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155772. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155773. tmp0 = tmp10 + tmp13; /* phase 2 */
  155774. tmp3 = tmp10 - tmp13;
  155775. tmp1 = tmp11 + tmp12;
  155776. tmp2 = tmp11 - tmp12;
  155777. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155778. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155779. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155780. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155781. z13 = tmp6 + tmp5; /* phase 6 */
  155782. z10 = tmp6 - tmp5;
  155783. z11 = tmp4 + tmp7;
  155784. z12 = tmp4 - tmp7;
  155785. tmp7 = z11 + z13; /* phase 5 */
  155786. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155787. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155788. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155789. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155790. tmp6 = tmp12 - tmp7; /* phase 2 */
  155791. tmp5 = tmp11 - tmp6;
  155792. tmp4 = tmp10 + tmp5;
  155793. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155794. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155795. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155796. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155797. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155798. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155799. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155800. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155801. inptr++; /* advance pointers to next column */
  155802. quantptr++;
  155803. wsptr++;
  155804. }
  155805. wsptr = workspace;
  155806. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155807. outptr = output_buf[ctr] + output_col;
  155808. tmp10 = wsptr[0] + wsptr[4];
  155809. tmp11 = wsptr[0] - wsptr[4];
  155810. tmp13 = wsptr[2] + wsptr[6];
  155811. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155812. tmp0 = tmp10 + tmp13;
  155813. tmp3 = tmp10 - tmp13;
  155814. tmp1 = tmp11 + tmp12;
  155815. tmp2 = tmp11 - tmp12;
  155816. z13 = wsptr[5] + wsptr[3];
  155817. z10 = wsptr[5] - wsptr[3];
  155818. z11 = wsptr[1] + wsptr[7];
  155819. z12 = wsptr[1] - wsptr[7];
  155820. tmp7 = z11 + z13;
  155821. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155822. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155823. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155824. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155825. tmp6 = tmp12 - tmp7;
  155826. tmp5 = tmp11 - tmp6;
  155827. tmp4 = tmp10 + tmp5;
  155828. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155829. & RANGE_MASK];
  155830. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155831. & RANGE_MASK];
  155832. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155833. & RANGE_MASK];
  155834. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155835. & RANGE_MASK];
  155836. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155837. & RANGE_MASK];
  155838. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155839. & RANGE_MASK];
  155840. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155841. & RANGE_MASK];
  155842. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155843. & RANGE_MASK];
  155844. wsptr += DCTSIZE; /* advance pointer to next row */
  155845. }
  155846. }
  155847. #endif /* DCT_FLOAT_SUPPORTED */
  155848. /*** End of inlined file: jidctflt.c ***/
  155849. #undef CONST_BITS
  155850. #undef FIX_1_847759065
  155851. #undef MULTIPLY
  155852. #undef DEQUANTIZE
  155853. #undef DESCALE
  155854. /*** Start of inlined file: jidctfst.c ***/
  155855. #define JPEG_INTERNALS
  155856. #ifdef DCT_IFAST_SUPPORTED
  155857. #if DCTSIZE != 8
  155858. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155859. #endif
  155860. #if BITS_IN_JSAMPLE == 8
  155861. #define CONST_BITS 8
  155862. #define PASS1_BITS 2
  155863. #else
  155864. #define CONST_BITS 8
  155865. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155866. #endif
  155867. #if CONST_BITS == 8
  155868. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155869. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155870. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155871. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155872. #else
  155873. #define FIX_1_082392200 FIX(1.082392200)
  155874. #define FIX_1_414213562 FIX(1.414213562)
  155875. #define FIX_1_847759065 FIX(1.847759065)
  155876. #define FIX_2_613125930 FIX(2.613125930)
  155877. #endif
  155878. #ifndef USE_ACCURATE_ROUNDING
  155879. #undef DESCALE
  155880. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155881. #endif
  155882. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155883. #if BITS_IN_JSAMPLE == 8
  155884. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155885. #else
  155886. #define DEQUANTIZE(coef,quantval) \
  155887. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155888. #endif
  155889. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155890. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155891. #if BITS_IN_JSAMPLE == 8
  155892. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155893. #else
  155894. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155895. #endif
  155896. #define IRIGHT_SHIFT(x,shft) \
  155897. ((ishift_temp = (x)) < 0 ? \
  155898. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155899. (ishift_temp >> (shft)))
  155900. #else
  155901. #define ISHIFT_TEMPS
  155902. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155903. #endif
  155904. #ifdef USE_ACCURATE_ROUNDING
  155905. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155906. #else
  155907. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155908. #endif
  155909. GLOBAL(void)
  155910. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155911. JCOEFPTR coef_block,
  155912. JSAMPARRAY output_buf, JDIMENSION output_col)
  155913. {
  155914. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155915. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155916. DCTELEM z5, z10, z11, z12, z13;
  155917. JCOEFPTR inptr;
  155918. IFAST_MULT_TYPE * quantptr;
  155919. int * wsptr;
  155920. JSAMPROW outptr;
  155921. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155922. int ctr;
  155923. int workspace[DCTSIZE2]; /* buffers data between passes */
  155924. SHIFT_TEMPS /* for DESCALE */
  155925. ISHIFT_TEMPS /* for IDESCALE */
  155926. inptr = coef_block;
  155927. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155928. wsptr = workspace;
  155929. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155930. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155931. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155932. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155933. inptr[DCTSIZE*7] == 0) {
  155934. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155935. wsptr[DCTSIZE*0] = dcval;
  155936. wsptr[DCTSIZE*1] = dcval;
  155937. wsptr[DCTSIZE*2] = dcval;
  155938. wsptr[DCTSIZE*3] = dcval;
  155939. wsptr[DCTSIZE*4] = dcval;
  155940. wsptr[DCTSIZE*5] = dcval;
  155941. wsptr[DCTSIZE*6] = dcval;
  155942. wsptr[DCTSIZE*7] = dcval;
  155943. inptr++; /* advance pointers to next column */
  155944. quantptr++;
  155945. wsptr++;
  155946. continue;
  155947. }
  155948. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155949. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155950. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155951. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155952. tmp10 = tmp0 + tmp2; /* phase 3 */
  155953. tmp11 = tmp0 - tmp2;
  155954. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155955. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155956. tmp0 = tmp10 + tmp13; /* phase 2 */
  155957. tmp3 = tmp10 - tmp13;
  155958. tmp1 = tmp11 + tmp12;
  155959. tmp2 = tmp11 - tmp12;
  155960. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155961. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155962. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155963. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155964. z13 = tmp6 + tmp5; /* phase 6 */
  155965. z10 = tmp6 - tmp5;
  155966. z11 = tmp4 + tmp7;
  155967. z12 = tmp4 - tmp7;
  155968. tmp7 = z11 + z13; /* phase 5 */
  155969. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155970. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155971. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155972. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155973. tmp6 = tmp12 - tmp7; /* phase 2 */
  155974. tmp5 = tmp11 - tmp6;
  155975. tmp4 = tmp10 + tmp5;
  155976. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155977. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155978. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155979. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155980. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155981. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155982. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155983. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155984. inptr++; /* advance pointers to next column */
  155985. quantptr++;
  155986. wsptr++;
  155987. }
  155988. wsptr = workspace;
  155989. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155990. outptr = output_buf[ctr] + output_col;
  155991. #ifndef NO_ZERO_ROW_TEST
  155992. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155993. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155994. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155995. & RANGE_MASK];
  155996. outptr[0] = dcval;
  155997. outptr[1] = dcval;
  155998. outptr[2] = dcval;
  155999. outptr[3] = dcval;
  156000. outptr[4] = dcval;
  156001. outptr[5] = dcval;
  156002. outptr[6] = dcval;
  156003. outptr[7] = dcval;
  156004. wsptr += DCTSIZE; /* advance pointer to next row */
  156005. continue;
  156006. }
  156007. #endif
  156008. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  156009. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  156010. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  156011. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  156012. - tmp13;
  156013. tmp0 = tmp10 + tmp13;
  156014. tmp3 = tmp10 - tmp13;
  156015. tmp1 = tmp11 + tmp12;
  156016. tmp2 = tmp11 - tmp12;
  156017. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  156018. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  156019. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  156020. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  156021. tmp7 = z11 + z13; /* phase 5 */
  156022. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  156023. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  156024. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  156025. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  156026. tmp6 = tmp12 - tmp7; /* phase 2 */
  156027. tmp5 = tmp11 - tmp6;
  156028. tmp4 = tmp10 + tmp5;
  156029. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  156030. & RANGE_MASK];
  156031. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  156032. & RANGE_MASK];
  156033. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  156034. & RANGE_MASK];
  156035. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  156036. & RANGE_MASK];
  156037. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  156038. & RANGE_MASK];
  156039. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  156040. & RANGE_MASK];
  156041. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  156042. & RANGE_MASK];
  156043. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  156044. & RANGE_MASK];
  156045. wsptr += DCTSIZE; /* advance pointer to next row */
  156046. }
  156047. }
  156048. #endif /* DCT_IFAST_SUPPORTED */
  156049. /*** End of inlined file: jidctfst.c ***/
  156050. #undef CONST_BITS
  156051. #undef FIX_1_847759065
  156052. #undef MULTIPLY
  156053. #undef DEQUANTIZE
  156054. /*** Start of inlined file: jidctint.c ***/
  156055. #define JPEG_INTERNALS
  156056. #ifdef DCT_ISLOW_SUPPORTED
  156057. #if DCTSIZE != 8
  156058. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156059. #endif
  156060. #if BITS_IN_JSAMPLE == 8
  156061. #define CONST_BITS 13
  156062. #define PASS1_BITS 2
  156063. #else
  156064. #define CONST_BITS 13
  156065. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156066. #endif
  156067. #if CONST_BITS == 13
  156068. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  156069. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  156070. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  156071. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  156072. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  156073. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  156074. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  156075. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  156076. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  156077. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  156078. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  156079. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  156080. #else
  156081. #define FIX_0_298631336 FIX(0.298631336)
  156082. #define FIX_0_390180644 FIX(0.390180644)
  156083. #define FIX_0_541196100 FIX(0.541196100)
  156084. #define FIX_0_765366865 FIX(0.765366865)
  156085. #define FIX_0_899976223 FIX(0.899976223)
  156086. #define FIX_1_175875602 FIX(1.175875602)
  156087. #define FIX_1_501321110 FIX(1.501321110)
  156088. #define FIX_1_847759065 FIX(1.847759065)
  156089. #define FIX_1_961570560 FIX(1.961570560)
  156090. #define FIX_2_053119869 FIX(2.053119869)
  156091. #define FIX_2_562915447 FIX(2.562915447)
  156092. #define FIX_3_072711026 FIX(3.072711026)
  156093. #endif
  156094. #if BITS_IN_JSAMPLE == 8
  156095. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  156096. #else
  156097. #define MULTIPLY(var,const) ((var) * (const))
  156098. #endif
  156099. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  156100. GLOBAL(void)
  156101. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156102. JCOEFPTR coef_block,
  156103. JSAMPARRAY output_buf, JDIMENSION output_col)
  156104. {
  156105. INT32 tmp0, tmp1, tmp2, tmp3;
  156106. INT32 tmp10, tmp11, tmp12, tmp13;
  156107. INT32 z1, z2, z3, z4, z5;
  156108. JCOEFPTR inptr;
  156109. ISLOW_MULT_TYPE * quantptr;
  156110. int * wsptr;
  156111. JSAMPROW outptr;
  156112. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156113. int ctr;
  156114. int workspace[DCTSIZE2]; /* buffers data between passes */
  156115. SHIFT_TEMPS
  156116. inptr = coef_block;
  156117. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156118. wsptr = workspace;
  156119. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  156120. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156121. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  156122. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  156123. inptr[DCTSIZE*7] == 0) {
  156124. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156125. wsptr[DCTSIZE*0] = dcval;
  156126. wsptr[DCTSIZE*1] = dcval;
  156127. wsptr[DCTSIZE*2] = dcval;
  156128. wsptr[DCTSIZE*3] = dcval;
  156129. wsptr[DCTSIZE*4] = dcval;
  156130. wsptr[DCTSIZE*5] = dcval;
  156131. wsptr[DCTSIZE*6] = dcval;
  156132. wsptr[DCTSIZE*7] = dcval;
  156133. inptr++; /* advance pointers to next column */
  156134. quantptr++;
  156135. wsptr++;
  156136. continue;
  156137. }
  156138. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156139. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156140. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156141. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156142. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156143. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156144. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  156145. tmp0 = (z2 + z3) << CONST_BITS;
  156146. tmp1 = (z2 - z3) << CONST_BITS;
  156147. tmp10 = tmp0 + tmp3;
  156148. tmp13 = tmp0 - tmp3;
  156149. tmp11 = tmp1 + tmp2;
  156150. tmp12 = tmp1 - tmp2;
  156151. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156152. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156153. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156154. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156155. z1 = tmp0 + tmp3;
  156156. z2 = tmp1 + tmp2;
  156157. z3 = tmp0 + tmp2;
  156158. z4 = tmp1 + tmp3;
  156159. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156160. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156161. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156162. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156163. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156164. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156165. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156166. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156167. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156168. z3 += z5;
  156169. z4 += z5;
  156170. tmp0 += z1 + z3;
  156171. tmp1 += z2 + z4;
  156172. tmp2 += z2 + z3;
  156173. tmp3 += z1 + z4;
  156174. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  156175. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  156176. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  156177. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  156178. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  156179. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  156180. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  156181. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  156182. inptr++; /* advance pointers to next column */
  156183. quantptr++;
  156184. wsptr++;
  156185. }
  156186. wsptr = workspace;
  156187. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  156188. outptr = output_buf[ctr] + output_col;
  156189. #ifndef NO_ZERO_ROW_TEST
  156190. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  156191. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156192. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156193. & RANGE_MASK];
  156194. outptr[0] = dcval;
  156195. outptr[1] = dcval;
  156196. outptr[2] = dcval;
  156197. outptr[3] = dcval;
  156198. outptr[4] = dcval;
  156199. outptr[5] = dcval;
  156200. outptr[6] = dcval;
  156201. outptr[7] = dcval;
  156202. wsptr += DCTSIZE; /* advance pointer to next row */
  156203. continue;
  156204. }
  156205. #endif
  156206. z2 = (INT32) wsptr[2];
  156207. z3 = (INT32) wsptr[6];
  156208. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156209. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156210. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156211. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  156212. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  156213. tmp10 = tmp0 + tmp3;
  156214. tmp13 = tmp0 - tmp3;
  156215. tmp11 = tmp1 + tmp2;
  156216. tmp12 = tmp1 - tmp2;
  156217. tmp0 = (INT32) wsptr[7];
  156218. tmp1 = (INT32) wsptr[5];
  156219. tmp2 = (INT32) wsptr[3];
  156220. tmp3 = (INT32) wsptr[1];
  156221. z1 = tmp0 + tmp3;
  156222. z2 = tmp1 + tmp2;
  156223. z3 = tmp0 + tmp2;
  156224. z4 = tmp1 + tmp3;
  156225. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156226. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156227. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156228. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156229. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156230. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156231. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156232. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156233. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156234. z3 += z5;
  156235. z4 += z5;
  156236. tmp0 += z1 + z3;
  156237. tmp1 += z2 + z4;
  156238. tmp2 += z2 + z3;
  156239. tmp3 += z1 + z4;
  156240. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  156241. CONST_BITS+PASS1_BITS+3)
  156242. & RANGE_MASK];
  156243. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  156244. CONST_BITS+PASS1_BITS+3)
  156245. & RANGE_MASK];
  156246. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  156247. CONST_BITS+PASS1_BITS+3)
  156248. & RANGE_MASK];
  156249. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  156250. CONST_BITS+PASS1_BITS+3)
  156251. & RANGE_MASK];
  156252. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  156253. CONST_BITS+PASS1_BITS+3)
  156254. & RANGE_MASK];
  156255. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  156256. CONST_BITS+PASS1_BITS+3)
  156257. & RANGE_MASK];
  156258. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  156259. CONST_BITS+PASS1_BITS+3)
  156260. & RANGE_MASK];
  156261. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  156262. CONST_BITS+PASS1_BITS+3)
  156263. & RANGE_MASK];
  156264. wsptr += DCTSIZE; /* advance pointer to next row */
  156265. }
  156266. }
  156267. #endif /* DCT_ISLOW_SUPPORTED */
  156268. /*** End of inlined file: jidctint.c ***/
  156269. /*** Start of inlined file: jidctred.c ***/
  156270. #define JPEG_INTERNALS
  156271. #ifdef IDCT_SCALING_SUPPORTED
  156272. #if DCTSIZE != 8
  156273. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156274. #endif
  156275. #if BITS_IN_JSAMPLE == 8
  156276. #define CONST_BITS 13
  156277. #define PASS1_BITS 2
  156278. #else
  156279. #define CONST_BITS 13
  156280. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156281. #endif
  156282. #if CONST_BITS == 13
  156283. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  156284. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  156285. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  156286. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  156287. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  156288. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  156289. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  156290. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  156291. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  156292. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  156293. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  156294. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  156295. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  156296. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  156297. #else
  156298. #define FIX_0_211164243 FIX(0.211164243)
  156299. #define FIX_0_509795579 FIX(0.509795579)
  156300. #define FIX_0_601344887 FIX(0.601344887)
  156301. #define FIX_0_720959822 FIX(0.720959822)
  156302. #define FIX_0_765366865 FIX(0.765366865)
  156303. #define FIX_0_850430095 FIX(0.850430095)
  156304. #define FIX_0_899976223 FIX(0.899976223)
  156305. #define FIX_1_061594337 FIX(1.061594337)
  156306. #define FIX_1_272758580 FIX(1.272758580)
  156307. #define FIX_1_451774981 FIX(1.451774981)
  156308. #define FIX_1_847759065 FIX(1.847759065)
  156309. #define FIX_2_172734803 FIX(2.172734803)
  156310. #define FIX_2_562915447 FIX(2.562915447)
  156311. #define FIX_3_624509785 FIX(3.624509785)
  156312. #endif
  156313. #if BITS_IN_JSAMPLE == 8
  156314. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  156315. #else
  156316. #define MULTIPLY(var,const) ((var) * (const))
  156317. #endif
  156318. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  156319. GLOBAL(void)
  156320. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156321. JCOEFPTR coef_block,
  156322. JSAMPARRAY output_buf, JDIMENSION output_col)
  156323. {
  156324. INT32 tmp0, tmp2, tmp10, tmp12;
  156325. INT32 z1, z2, z3, z4;
  156326. JCOEFPTR inptr;
  156327. ISLOW_MULT_TYPE * quantptr;
  156328. int * wsptr;
  156329. JSAMPROW outptr;
  156330. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156331. int ctr;
  156332. int workspace[DCTSIZE*4]; /* buffers data between passes */
  156333. SHIFT_TEMPS
  156334. inptr = coef_block;
  156335. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156336. wsptr = workspace;
  156337. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156338. if (ctr == DCTSIZE-4)
  156339. continue;
  156340. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156341. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  156342. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  156343. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156344. wsptr[DCTSIZE*0] = dcval;
  156345. wsptr[DCTSIZE*1] = dcval;
  156346. wsptr[DCTSIZE*2] = dcval;
  156347. wsptr[DCTSIZE*3] = dcval;
  156348. continue;
  156349. }
  156350. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156351. tmp0 <<= (CONST_BITS+1);
  156352. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156353. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156354. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  156355. tmp10 = tmp0 + tmp2;
  156356. tmp12 = tmp0 - tmp2;
  156357. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156358. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156359. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156360. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156361. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156362. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156363. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156364. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156365. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156366. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156367. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156368. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156369. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  156370. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  156371. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  156372. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  156373. }
  156374. wsptr = workspace;
  156375. for (ctr = 0; ctr < 4; ctr++) {
  156376. outptr = output_buf[ctr] + output_col;
  156377. #ifndef NO_ZERO_ROW_TEST
  156378. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  156379. wsptr[5] == 0 && wsptr[6] == 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. outptr[2] = dcval;
  156385. outptr[3] = dcval;
  156386. wsptr += DCTSIZE; /* advance pointer to next row */
  156387. continue;
  156388. }
  156389. #endif
  156390. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  156391. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  156392. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  156393. tmp10 = tmp0 + tmp2;
  156394. tmp12 = tmp0 - tmp2;
  156395. z1 = (INT32) wsptr[7];
  156396. z2 = (INT32) wsptr[5];
  156397. z3 = (INT32) wsptr[3];
  156398. z4 = (INT32) wsptr[1];
  156399. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156400. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156401. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156402. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156403. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156404. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156405. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156406. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156407. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  156408. CONST_BITS+PASS1_BITS+3+1)
  156409. & RANGE_MASK];
  156410. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  156411. CONST_BITS+PASS1_BITS+3+1)
  156412. & RANGE_MASK];
  156413. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  156414. CONST_BITS+PASS1_BITS+3+1)
  156415. & RANGE_MASK];
  156416. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  156417. CONST_BITS+PASS1_BITS+3+1)
  156418. & RANGE_MASK];
  156419. wsptr += DCTSIZE; /* advance pointer to next row */
  156420. }
  156421. }
  156422. GLOBAL(void)
  156423. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156424. JCOEFPTR coef_block,
  156425. JSAMPARRAY output_buf, JDIMENSION output_col)
  156426. {
  156427. INT32 tmp0, tmp10, z1;
  156428. JCOEFPTR inptr;
  156429. ISLOW_MULT_TYPE * quantptr;
  156430. int * wsptr;
  156431. JSAMPROW outptr;
  156432. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156433. int ctr;
  156434. int workspace[DCTSIZE*2]; /* buffers data between passes */
  156435. SHIFT_TEMPS
  156436. inptr = coef_block;
  156437. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156438. wsptr = workspace;
  156439. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156440. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  156441. continue;
  156442. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  156443. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  156444. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156445. wsptr[DCTSIZE*0] = dcval;
  156446. wsptr[DCTSIZE*1] = dcval;
  156447. continue;
  156448. }
  156449. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156450. tmp10 = z1 << (CONST_BITS+2);
  156451. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156452. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  156453. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156454. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  156455. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156456. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  156457. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156458. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156459. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  156460. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  156461. }
  156462. wsptr = workspace;
  156463. for (ctr = 0; ctr < 2; ctr++) {
  156464. outptr = output_buf[ctr] + output_col;
  156465. #ifndef NO_ZERO_ROW_TEST
  156466. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  156467. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156468. & RANGE_MASK];
  156469. outptr[0] = dcval;
  156470. outptr[1] = dcval;
  156471. wsptr += DCTSIZE; /* advance pointer to next row */
  156472. continue;
  156473. }
  156474. #endif
  156475. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  156476. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  156477. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  156478. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  156479. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156480. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  156481. CONST_BITS+PASS1_BITS+3+2)
  156482. & RANGE_MASK];
  156483. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  156484. CONST_BITS+PASS1_BITS+3+2)
  156485. & RANGE_MASK];
  156486. wsptr += DCTSIZE; /* advance pointer to next row */
  156487. }
  156488. }
  156489. GLOBAL(void)
  156490. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156491. JCOEFPTR coef_block,
  156492. JSAMPARRAY output_buf, JDIMENSION output_col)
  156493. {
  156494. int dcval;
  156495. ISLOW_MULT_TYPE * quantptr;
  156496. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156497. SHIFT_TEMPS
  156498. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156499. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  156500. dcval = (int) DESCALE((INT32) dcval, 3);
  156501. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  156502. }
  156503. #endif /* IDCT_SCALING_SUPPORTED */
  156504. /*** End of inlined file: jidctred.c ***/
  156505. /*** Start of inlined file: jmemmgr.c ***/
  156506. #define JPEG_INTERNALS
  156507. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  156508. /*** Start of inlined file: jmemsys.h ***/
  156509. #ifndef __jmemsys_h__
  156510. #define __jmemsys_h__
  156511. #ifdef NEED_SHORT_EXTERNAL_NAMES
  156512. #define jpeg_get_small jGetSmall
  156513. #define jpeg_free_small jFreeSmall
  156514. #define jpeg_get_large jGetLarge
  156515. #define jpeg_free_large jFreeLarge
  156516. #define jpeg_mem_available jMemAvail
  156517. #define jpeg_open_backing_store jOpenBackStore
  156518. #define jpeg_mem_init jMemInit
  156519. #define jpeg_mem_term jMemTerm
  156520. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  156521. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156522. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156523. size_t sizeofobject));
  156524. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156525. size_t sizeofobject));
  156526. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156527. size_t sizeofobject));
  156528. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156529. #define MAX_ALLOC_CHUNK 1000000000L
  156530. #endif
  156531. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156532. long min_bytes_needed,
  156533. long max_bytes_needed,
  156534. long already_allocated));
  156535. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156536. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156537. typedef unsigned short XMSH; /* type of extended-memory handles */
  156538. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156539. typedef union {
  156540. short file_handle; /* DOS file handle if it's a temp file */
  156541. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156542. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156543. } handle_union;
  156544. #endif /* USE_MSDOS_MEMMGR */
  156545. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156546. #include <Files.h>
  156547. #endif /* USE_MAC_MEMMGR */
  156548. //typedef struct backing_store_struct * backing_store_ptr;
  156549. typedef struct backing_store_struct {
  156550. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156551. struct backing_store_struct *info,
  156552. void FAR * buffer_address,
  156553. long file_offset, long byte_count));
  156554. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156555. struct backing_store_struct *info,
  156556. void FAR * buffer_address,
  156557. long file_offset, long byte_count));
  156558. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156559. struct backing_store_struct *info));
  156560. #ifdef USE_MSDOS_MEMMGR
  156561. handle_union handle; /* reference to backing-store storage object */
  156562. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156563. #else
  156564. #ifdef USE_MAC_MEMMGR
  156565. short temp_file; /* file reference number to temp file */
  156566. FSSpec tempSpec; /* the FSSpec for the temp file */
  156567. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156568. #else
  156569. FILE * temp_file; /* stdio reference to temp file */
  156570. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156571. #endif
  156572. #endif
  156573. } backing_store_info;
  156574. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156575. struct backing_store_struct *info,
  156576. long total_bytes_needed));
  156577. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156578. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156579. #endif
  156580. /*** End of inlined file: jmemsys.h ***/
  156581. /* import the system-dependent declarations */
  156582. #ifndef NO_GETENV
  156583. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156584. extern char * getenv JPP((const char * name));
  156585. #endif
  156586. #endif
  156587. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156588. #define ALIGN_TYPE double
  156589. #endif
  156590. typedef union small_pool_struct * small_pool_ptr;
  156591. typedef union small_pool_struct {
  156592. struct {
  156593. small_pool_ptr next; /* next in list of pools */
  156594. size_t bytes_used; /* how many bytes already used within pool */
  156595. size_t bytes_left; /* bytes still available in this pool */
  156596. } hdr;
  156597. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156598. } small_pool_hdr;
  156599. typedef union large_pool_struct FAR * large_pool_ptr;
  156600. typedef union large_pool_struct {
  156601. struct {
  156602. large_pool_ptr next; /* next in list of pools */
  156603. size_t bytes_used; /* how many bytes already used within pool */
  156604. size_t bytes_left; /* bytes still available in this pool */
  156605. } hdr;
  156606. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156607. } large_pool_hdr;
  156608. typedef struct {
  156609. struct jpeg_memory_mgr pub; /* public fields */
  156610. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156611. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156612. jvirt_sarray_ptr virt_sarray_list;
  156613. jvirt_barray_ptr virt_barray_list;
  156614. long total_space_allocated;
  156615. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156616. } my_memory_mgr;
  156617. typedef my_memory_mgr * my_mem_ptr;
  156618. struct jvirt_sarray_control {
  156619. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156620. JDIMENSION rows_in_array; /* total virtual array height */
  156621. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156622. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156623. JDIMENSION rows_in_mem; /* height of memory buffer */
  156624. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156625. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156626. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156627. boolean pre_zero; /* pre-zero mode requested? */
  156628. boolean dirty; /* do current buffer contents need written? */
  156629. boolean b_s_open; /* is backing-store data valid? */
  156630. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156631. backing_store_info b_s_info; /* System-dependent control info */
  156632. };
  156633. struct jvirt_barray_control {
  156634. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156635. JDIMENSION rows_in_array; /* total virtual array height */
  156636. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156637. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156638. JDIMENSION rows_in_mem; /* height of memory buffer */
  156639. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156640. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156641. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156642. boolean pre_zero; /* pre-zero mode requested? */
  156643. boolean dirty; /* do current buffer contents need written? */
  156644. boolean b_s_open; /* is backing-store data valid? */
  156645. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156646. backing_store_info b_s_info; /* System-dependent control info */
  156647. };
  156648. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156649. LOCAL(void)
  156650. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156651. {
  156652. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156653. small_pool_ptr shdr_ptr;
  156654. large_pool_ptr lhdr_ptr;
  156655. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156656. pool_id, mem->total_space_allocated);
  156657. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156658. lhdr_ptr = lhdr_ptr->hdr.next) {
  156659. fprintf(stderr, " Large chunk used %ld\n",
  156660. (long) lhdr_ptr->hdr.bytes_used);
  156661. }
  156662. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156663. shdr_ptr = shdr_ptr->hdr.next) {
  156664. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156665. (long) shdr_ptr->hdr.bytes_used,
  156666. (long) shdr_ptr->hdr.bytes_left);
  156667. }
  156668. }
  156669. #endif /* MEM_STATS */
  156670. LOCAL(void)
  156671. out_of_memory (j_common_ptr cinfo, int which)
  156672. {
  156673. #ifdef MEM_STATS
  156674. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156675. #endif
  156676. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156677. }
  156678. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156679. {
  156680. 1600, /* first PERMANENT pool */
  156681. 16000 /* first IMAGE pool */
  156682. };
  156683. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156684. {
  156685. 0, /* additional PERMANENT pools */
  156686. 5000 /* additional IMAGE pools */
  156687. };
  156688. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156689. METHODDEF(void *)
  156690. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156691. {
  156692. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156693. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156694. char * data_ptr;
  156695. size_t odd_bytes, min_request, slop;
  156696. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156697. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156698. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156699. if (odd_bytes > 0)
  156700. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156701. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156702. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156703. prev_hdr_ptr = NULL;
  156704. hdr_ptr = mem->small_list[pool_id];
  156705. while (hdr_ptr != NULL) {
  156706. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156707. break; /* found pool with enough space */
  156708. prev_hdr_ptr = hdr_ptr;
  156709. hdr_ptr = hdr_ptr->hdr.next;
  156710. }
  156711. if (hdr_ptr == NULL) {
  156712. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156713. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156714. slop = first_pool_slop[pool_id];
  156715. else
  156716. slop = extra_pool_slop[pool_id];
  156717. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156718. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156719. for (;;) {
  156720. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156721. if (hdr_ptr != NULL)
  156722. break;
  156723. slop /= 2;
  156724. if (slop < MIN_SLOP) /* give up when it gets real small */
  156725. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156726. }
  156727. mem->total_space_allocated += min_request + slop;
  156728. hdr_ptr->hdr.next = NULL;
  156729. hdr_ptr->hdr.bytes_used = 0;
  156730. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156731. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156732. mem->small_list[pool_id] = hdr_ptr;
  156733. else
  156734. prev_hdr_ptr->hdr.next = hdr_ptr;
  156735. }
  156736. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156737. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156738. hdr_ptr->hdr.bytes_used += sizeofobject;
  156739. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156740. return (void *) data_ptr;
  156741. }
  156742. METHODDEF(void FAR *)
  156743. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156744. {
  156745. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156746. large_pool_ptr hdr_ptr;
  156747. size_t odd_bytes;
  156748. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156749. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156750. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156751. if (odd_bytes > 0)
  156752. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156753. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156754. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156755. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156756. SIZEOF(large_pool_hdr));
  156757. if (hdr_ptr == NULL)
  156758. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156759. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156760. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156761. hdr_ptr->hdr.bytes_used = sizeofobject;
  156762. hdr_ptr->hdr.bytes_left = 0;
  156763. mem->large_list[pool_id] = hdr_ptr;
  156764. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156765. }
  156766. METHODDEF(JSAMPARRAY)
  156767. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156768. JDIMENSION samplesperrow, JDIMENSION numrows)
  156769. {
  156770. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156771. JSAMPARRAY result;
  156772. JSAMPROW workspace;
  156773. JDIMENSION rowsperchunk, currow, i;
  156774. long ltemp;
  156775. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156776. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156777. if (ltemp <= 0)
  156778. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156779. if (ltemp < (long) numrows)
  156780. rowsperchunk = (JDIMENSION) ltemp;
  156781. else
  156782. rowsperchunk = numrows;
  156783. mem->last_rowsperchunk = rowsperchunk;
  156784. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156785. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156786. currow = 0;
  156787. while (currow < numrows) {
  156788. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156789. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156790. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156791. * SIZEOF(JSAMPLE)));
  156792. for (i = rowsperchunk; i > 0; i--) {
  156793. result[currow++] = workspace;
  156794. workspace += samplesperrow;
  156795. }
  156796. }
  156797. return result;
  156798. }
  156799. METHODDEF(JBLOCKARRAY)
  156800. alloc_barray (j_common_ptr cinfo, int pool_id,
  156801. JDIMENSION blocksperrow, JDIMENSION numrows)
  156802. {
  156803. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156804. JBLOCKARRAY result;
  156805. JBLOCKROW workspace;
  156806. JDIMENSION rowsperchunk, currow, i;
  156807. long ltemp;
  156808. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156809. ((long) blocksperrow * SIZEOF(JBLOCK));
  156810. if (ltemp <= 0)
  156811. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156812. if (ltemp < (long) numrows)
  156813. rowsperchunk = (JDIMENSION) ltemp;
  156814. else
  156815. rowsperchunk = numrows;
  156816. mem->last_rowsperchunk = rowsperchunk;
  156817. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156818. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156819. currow = 0;
  156820. while (currow < numrows) {
  156821. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156822. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156823. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156824. * SIZEOF(JBLOCK)));
  156825. for (i = rowsperchunk; i > 0; i--) {
  156826. result[currow++] = workspace;
  156827. workspace += blocksperrow;
  156828. }
  156829. }
  156830. return result;
  156831. }
  156832. METHODDEF(jvirt_sarray_ptr)
  156833. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156834. JDIMENSION samplesperrow, JDIMENSION numrows,
  156835. JDIMENSION maxaccess)
  156836. {
  156837. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156838. jvirt_sarray_ptr result;
  156839. if (pool_id != JPOOL_IMAGE)
  156840. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156841. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156842. SIZEOF(struct jvirt_sarray_control));
  156843. result->mem_buffer = NULL; /* marks array not yet realized */
  156844. result->rows_in_array = numrows;
  156845. result->samplesperrow = samplesperrow;
  156846. result->maxaccess = maxaccess;
  156847. result->pre_zero = pre_zero;
  156848. result->b_s_open = FALSE; /* no associated backing-store object */
  156849. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156850. mem->virt_sarray_list = result;
  156851. return result;
  156852. }
  156853. METHODDEF(jvirt_barray_ptr)
  156854. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156855. JDIMENSION blocksperrow, JDIMENSION numrows,
  156856. JDIMENSION maxaccess)
  156857. {
  156858. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156859. jvirt_barray_ptr result;
  156860. if (pool_id != JPOOL_IMAGE)
  156861. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156862. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156863. SIZEOF(struct jvirt_barray_control));
  156864. result->mem_buffer = NULL; /* marks array not yet realized */
  156865. result->rows_in_array = numrows;
  156866. result->blocksperrow = blocksperrow;
  156867. result->maxaccess = maxaccess;
  156868. result->pre_zero = pre_zero;
  156869. result->b_s_open = FALSE; /* no associated backing-store object */
  156870. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156871. mem->virt_barray_list = result;
  156872. return result;
  156873. }
  156874. METHODDEF(void)
  156875. realize_virt_arrays (j_common_ptr cinfo)
  156876. {
  156877. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156878. long space_per_minheight, maximum_space, avail_mem;
  156879. long minheights, max_minheights;
  156880. jvirt_sarray_ptr sptr;
  156881. jvirt_barray_ptr bptr;
  156882. space_per_minheight = 0;
  156883. maximum_space = 0;
  156884. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156885. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156886. space_per_minheight += (long) sptr->maxaccess *
  156887. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156888. maximum_space += (long) sptr->rows_in_array *
  156889. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156890. }
  156891. }
  156892. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156893. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156894. space_per_minheight += (long) bptr->maxaccess *
  156895. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156896. maximum_space += (long) bptr->rows_in_array *
  156897. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156898. }
  156899. }
  156900. if (space_per_minheight <= 0)
  156901. return; /* no unrealized arrays, no work */
  156902. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156903. mem->total_space_allocated);
  156904. if (avail_mem >= maximum_space)
  156905. max_minheights = 1000000000L;
  156906. else {
  156907. max_minheights = avail_mem / space_per_minheight;
  156908. if (max_minheights <= 0)
  156909. max_minheights = 1;
  156910. }
  156911. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156912. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156913. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156914. if (minheights <= max_minheights) {
  156915. sptr->rows_in_mem = sptr->rows_in_array;
  156916. } else {
  156917. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156918. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156919. (long) sptr->rows_in_array *
  156920. (long) sptr->samplesperrow *
  156921. (long) SIZEOF(JSAMPLE));
  156922. sptr->b_s_open = TRUE;
  156923. }
  156924. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156925. sptr->samplesperrow, sptr->rows_in_mem);
  156926. sptr->rowsperchunk = mem->last_rowsperchunk;
  156927. sptr->cur_start_row = 0;
  156928. sptr->first_undef_row = 0;
  156929. sptr->dirty = FALSE;
  156930. }
  156931. }
  156932. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156933. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156934. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156935. if (minheights <= max_minheights) {
  156936. bptr->rows_in_mem = bptr->rows_in_array;
  156937. } else {
  156938. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156939. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156940. (long) bptr->rows_in_array *
  156941. (long) bptr->blocksperrow *
  156942. (long) SIZEOF(JBLOCK));
  156943. bptr->b_s_open = TRUE;
  156944. }
  156945. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156946. bptr->blocksperrow, bptr->rows_in_mem);
  156947. bptr->rowsperchunk = mem->last_rowsperchunk;
  156948. bptr->cur_start_row = 0;
  156949. bptr->first_undef_row = 0;
  156950. bptr->dirty = FALSE;
  156951. }
  156952. }
  156953. }
  156954. LOCAL(void)
  156955. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156956. {
  156957. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156958. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156959. file_offset = ptr->cur_start_row * bytesperrow;
  156960. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156961. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156962. thisrow = (long) ptr->cur_start_row + i;
  156963. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156964. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156965. if (rows <= 0) /* this chunk might be past end of file! */
  156966. break;
  156967. byte_count = rows * bytesperrow;
  156968. if (writing)
  156969. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156970. (void FAR *) ptr->mem_buffer[i],
  156971. file_offset, byte_count);
  156972. else
  156973. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156974. (void FAR *) ptr->mem_buffer[i],
  156975. file_offset, byte_count);
  156976. file_offset += byte_count;
  156977. }
  156978. }
  156979. LOCAL(void)
  156980. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156981. {
  156982. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156983. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156984. file_offset = ptr->cur_start_row * bytesperrow;
  156985. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156986. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156987. thisrow = (long) ptr->cur_start_row + i;
  156988. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156989. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156990. if (rows <= 0) /* this chunk might be past end of file! */
  156991. break;
  156992. byte_count = rows * bytesperrow;
  156993. if (writing)
  156994. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156995. (void FAR *) ptr->mem_buffer[i],
  156996. file_offset, byte_count);
  156997. else
  156998. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156999. (void FAR *) ptr->mem_buffer[i],
  157000. file_offset, byte_count);
  157001. file_offset += byte_count;
  157002. }
  157003. }
  157004. METHODDEF(JSAMPARRAY)
  157005. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  157006. JDIMENSION start_row, JDIMENSION num_rows,
  157007. boolean writable)
  157008. {
  157009. JDIMENSION end_row = start_row + num_rows;
  157010. JDIMENSION undef_row;
  157011. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  157012. ptr->mem_buffer == NULL)
  157013. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157014. if (start_row < ptr->cur_start_row ||
  157015. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  157016. if (! ptr->b_s_open)
  157017. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  157018. if (ptr->dirty) {
  157019. do_sarray_io(cinfo, ptr, TRUE);
  157020. ptr->dirty = FALSE;
  157021. }
  157022. if (start_row > ptr->cur_start_row) {
  157023. ptr->cur_start_row = start_row;
  157024. } else {
  157025. long ltemp;
  157026. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  157027. if (ltemp < 0)
  157028. ltemp = 0; /* don't fall off front end of file */
  157029. ptr->cur_start_row = (JDIMENSION) ltemp;
  157030. }
  157031. do_sarray_io(cinfo, ptr, FALSE);
  157032. }
  157033. if (ptr->first_undef_row < end_row) {
  157034. if (ptr->first_undef_row < start_row) {
  157035. if (writable) /* writer skipped over a section of array */
  157036. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157037. undef_row = start_row; /* but reader is allowed to read ahead */
  157038. } else {
  157039. undef_row = ptr->first_undef_row;
  157040. }
  157041. if (writable)
  157042. ptr->first_undef_row = end_row;
  157043. if (ptr->pre_zero) {
  157044. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  157045. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  157046. end_row -= ptr->cur_start_row;
  157047. while (undef_row < end_row) {
  157048. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  157049. undef_row++;
  157050. }
  157051. } else {
  157052. if (! writable) /* reader looking at undefined data */
  157053. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157054. }
  157055. }
  157056. if (writable)
  157057. ptr->dirty = TRUE;
  157058. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  157059. }
  157060. METHODDEF(JBLOCKARRAY)
  157061. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  157062. JDIMENSION start_row, JDIMENSION num_rows,
  157063. boolean writable)
  157064. {
  157065. JDIMENSION end_row = start_row + num_rows;
  157066. JDIMENSION undef_row;
  157067. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  157068. ptr->mem_buffer == NULL)
  157069. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157070. if (start_row < ptr->cur_start_row ||
  157071. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  157072. if (! ptr->b_s_open)
  157073. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  157074. if (ptr->dirty) {
  157075. do_barray_io(cinfo, ptr, TRUE);
  157076. ptr->dirty = FALSE;
  157077. }
  157078. if (start_row > ptr->cur_start_row) {
  157079. ptr->cur_start_row = start_row;
  157080. } else {
  157081. long ltemp;
  157082. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  157083. if (ltemp < 0)
  157084. ltemp = 0; /* don't fall off front end of file */
  157085. ptr->cur_start_row = (JDIMENSION) ltemp;
  157086. }
  157087. do_barray_io(cinfo, ptr, FALSE);
  157088. }
  157089. if (ptr->first_undef_row < end_row) {
  157090. if (ptr->first_undef_row < start_row) {
  157091. if (writable) /* writer skipped over a section of array */
  157092. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157093. undef_row = start_row; /* but reader is allowed to read ahead */
  157094. } else {
  157095. undef_row = ptr->first_undef_row;
  157096. }
  157097. if (writable)
  157098. ptr->first_undef_row = end_row;
  157099. if (ptr->pre_zero) {
  157100. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  157101. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  157102. end_row -= ptr->cur_start_row;
  157103. while (undef_row < end_row) {
  157104. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  157105. undef_row++;
  157106. }
  157107. } else {
  157108. if (! writable) /* reader looking at undefined data */
  157109. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157110. }
  157111. }
  157112. if (writable)
  157113. ptr->dirty = TRUE;
  157114. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  157115. }
  157116. METHODDEF(void)
  157117. free_pool (j_common_ptr cinfo, int pool_id)
  157118. {
  157119. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157120. small_pool_ptr shdr_ptr;
  157121. large_pool_ptr lhdr_ptr;
  157122. size_t space_freed;
  157123. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  157124. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  157125. #ifdef MEM_STATS
  157126. if (cinfo->err->trace_level > 1)
  157127. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  157128. #endif
  157129. if (pool_id == JPOOL_IMAGE) {
  157130. jvirt_sarray_ptr sptr;
  157131. jvirt_barray_ptr bptr;
  157132. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  157133. if (sptr->b_s_open) { /* there may be no backing store */
  157134. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  157135. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  157136. }
  157137. }
  157138. mem->virt_sarray_list = NULL;
  157139. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  157140. if (bptr->b_s_open) { /* there may be no backing store */
  157141. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  157142. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  157143. }
  157144. }
  157145. mem->virt_barray_list = NULL;
  157146. }
  157147. lhdr_ptr = mem->large_list[pool_id];
  157148. mem->large_list[pool_id] = NULL;
  157149. while (lhdr_ptr != NULL) {
  157150. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  157151. space_freed = lhdr_ptr->hdr.bytes_used +
  157152. lhdr_ptr->hdr.bytes_left +
  157153. SIZEOF(large_pool_hdr);
  157154. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  157155. mem->total_space_allocated -= space_freed;
  157156. lhdr_ptr = next_lhdr_ptr;
  157157. }
  157158. shdr_ptr = mem->small_list[pool_id];
  157159. mem->small_list[pool_id] = NULL;
  157160. while (shdr_ptr != NULL) {
  157161. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  157162. space_freed = shdr_ptr->hdr.bytes_used +
  157163. shdr_ptr->hdr.bytes_left +
  157164. SIZEOF(small_pool_hdr);
  157165. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  157166. mem->total_space_allocated -= space_freed;
  157167. shdr_ptr = next_shdr_ptr;
  157168. }
  157169. }
  157170. METHODDEF(void)
  157171. self_destruct (j_common_ptr cinfo)
  157172. {
  157173. int pool;
  157174. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157175. free_pool(cinfo, pool);
  157176. }
  157177. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  157178. cinfo->mem = NULL; /* ensures I will be called only once */
  157179. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157180. }
  157181. GLOBAL(void)
  157182. jinit_memory_mgr (j_common_ptr cinfo)
  157183. {
  157184. my_mem_ptr mem;
  157185. long max_to_use;
  157186. int pool;
  157187. size_t test_mac;
  157188. cinfo->mem = NULL; /* for safety if init fails */
  157189. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  157190. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  157191. test_mac = (size_t) MAX_ALLOC_CHUNK;
  157192. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  157193. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  157194. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  157195. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  157196. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  157197. if (mem == NULL) {
  157198. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157199. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  157200. }
  157201. mem->pub.alloc_small = alloc_small;
  157202. mem->pub.alloc_large = alloc_large;
  157203. mem->pub.alloc_sarray = alloc_sarray;
  157204. mem->pub.alloc_barray = alloc_barray;
  157205. mem->pub.request_virt_sarray = request_virt_sarray;
  157206. mem->pub.request_virt_barray = request_virt_barray;
  157207. mem->pub.realize_virt_arrays = realize_virt_arrays;
  157208. mem->pub.access_virt_sarray = access_virt_sarray;
  157209. mem->pub.access_virt_barray = access_virt_barray;
  157210. mem->pub.free_pool = free_pool;
  157211. mem->pub.self_destruct = self_destruct;
  157212. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  157213. mem->pub.max_memory_to_use = max_to_use;
  157214. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157215. mem->small_list[pool] = NULL;
  157216. mem->large_list[pool] = NULL;
  157217. }
  157218. mem->virt_sarray_list = NULL;
  157219. mem->virt_barray_list = NULL;
  157220. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  157221. cinfo->mem = & mem->pub;
  157222. #ifndef NO_GETENV
  157223. { char * memenv;
  157224. if ((memenv = getenv("JPEGMEM")) != NULL) {
  157225. char ch = 'x';
  157226. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  157227. if (ch == 'm' || ch == 'M')
  157228. max_to_use *= 1000L;
  157229. mem->pub.max_memory_to_use = max_to_use * 1000L;
  157230. }
  157231. }
  157232. }
  157233. #endif
  157234. }
  157235. /*** End of inlined file: jmemmgr.c ***/
  157236. /*** Start of inlined file: jmemnobs.c ***/
  157237. #define JPEG_INTERNALS
  157238. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  157239. extern void * malloc JPP((size_t size));
  157240. extern void free JPP((void *ptr));
  157241. #endif
  157242. GLOBAL(void *)
  157243. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  157244. {
  157245. return (void *) malloc(sizeofobject);
  157246. }
  157247. GLOBAL(void)
  157248. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  157249. {
  157250. free(object);
  157251. }
  157252. GLOBAL(void FAR *)
  157253. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  157254. {
  157255. return (void FAR *) malloc(sizeofobject);
  157256. }
  157257. GLOBAL(void)
  157258. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  157259. {
  157260. free(object);
  157261. }
  157262. GLOBAL(long)
  157263. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  157264. long max_bytes_needed, long already_allocated)
  157265. {
  157266. return max_bytes_needed;
  157267. }
  157268. GLOBAL(void)
  157269. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  157270. long total_bytes_needed)
  157271. {
  157272. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  157273. }
  157274. GLOBAL(long)
  157275. jpeg_mem_init (j_common_ptr cinfo)
  157276. {
  157277. return 0; /* just set max_memory_to_use to 0 */
  157278. }
  157279. GLOBAL(void)
  157280. jpeg_mem_term (j_common_ptr cinfo)
  157281. {
  157282. }
  157283. /*** End of inlined file: jmemnobs.c ***/
  157284. /*** Start of inlined file: jquant1.c ***/
  157285. #define JPEG_INTERNALS
  157286. #ifdef QUANT_1PASS_SUPPORTED
  157287. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  157288. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  157289. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  157290. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  157291. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  157292. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  157293. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  157294. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  157295. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  157296. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  157297. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  157298. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  157299. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  157300. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  157301. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  157302. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  157303. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  157304. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  157305. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  157306. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  157307. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  157308. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  157309. };
  157310. #if BITS_IN_JSAMPLE == 8
  157311. typedef INT16 FSERROR; /* 16 bits should be enough */
  157312. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157313. #else
  157314. typedef INT32 FSERROR; /* may need more than 16 bits */
  157315. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157316. #endif
  157317. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157318. #define MAX_Q_COMPS 4 /* max components I can handle */
  157319. typedef struct {
  157320. struct jpeg_color_quantizer pub; /* public fields */
  157321. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  157322. int sv_actual; /* number of entries in use */
  157323. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  157324. boolean is_padded; /* is the colorindex padded for odither? */
  157325. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  157326. int row_index; /* cur row's vertical index in dither matrix */
  157327. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  157328. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  157329. boolean on_odd_row; /* flag to remember which row we are on */
  157330. } my_cquantizer;
  157331. typedef my_cquantizer * my_cquantize_ptr;
  157332. LOCAL(int)
  157333. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  157334. {
  157335. int nc = cinfo->out_color_components; /* number of color components */
  157336. int max_colors = cinfo->desired_number_of_colors;
  157337. int total_colors, iroot, i, j;
  157338. boolean changed;
  157339. long temp;
  157340. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  157341. iroot = 1;
  157342. do {
  157343. iroot++;
  157344. temp = iroot; /* set temp = iroot ** nc */
  157345. for (i = 1; i < nc; i++)
  157346. temp *= iroot;
  157347. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  157348. iroot--; /* now iroot = floor(root) */
  157349. if (iroot < 2)
  157350. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  157351. total_colors = 1;
  157352. for (i = 0; i < nc; i++) {
  157353. Ncolors[i] = iroot;
  157354. total_colors *= iroot;
  157355. }
  157356. do {
  157357. changed = FALSE;
  157358. for (i = 0; i < nc; i++) {
  157359. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  157360. temp = total_colors / Ncolors[j];
  157361. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  157362. if (temp > (long) max_colors)
  157363. break; /* won't fit, done with this pass */
  157364. Ncolors[j]++; /* OK, apply the increment */
  157365. total_colors = (int) temp;
  157366. changed = TRUE;
  157367. }
  157368. } while (changed);
  157369. return total_colors;
  157370. }
  157371. LOCAL(int)
  157372. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157373. {
  157374. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  157375. }
  157376. LOCAL(int)
  157377. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157378. {
  157379. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  157380. }
  157381. LOCAL(void)
  157382. create_colormap (j_decompress_ptr cinfo)
  157383. {
  157384. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157385. JSAMPARRAY colormap; /* Created colormap */
  157386. int total_colors; /* Number of distinct output colors */
  157387. int i,j,k, nci, blksize, blkdist, ptr, val;
  157388. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  157389. if (cinfo->out_color_components == 3)
  157390. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  157391. total_colors, cquantize->Ncolors[0],
  157392. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  157393. else
  157394. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  157395. colormap = (*cinfo->mem->alloc_sarray)
  157396. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157397. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  157398. blkdist = total_colors;
  157399. for (i = 0; i < cinfo->out_color_components; i++) {
  157400. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157401. blksize = blkdist / nci;
  157402. for (j = 0; j < nci; j++) {
  157403. val = output_value(cinfo, i, j, nci-1);
  157404. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  157405. for (k = 0; k < blksize; k++)
  157406. colormap[i][ptr+k] = (JSAMPLE) val;
  157407. }
  157408. }
  157409. blkdist = blksize; /* blksize of this color is blkdist of next */
  157410. }
  157411. cquantize->sv_colormap = colormap;
  157412. cquantize->sv_actual = total_colors;
  157413. }
  157414. LOCAL(void)
  157415. create_colorindex (j_decompress_ptr cinfo)
  157416. {
  157417. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157418. JSAMPROW indexptr;
  157419. int i,j,k, nci, blksize, val, pad;
  157420. if (cinfo->dither_mode == JDITHER_ORDERED) {
  157421. pad = MAXJSAMPLE*2;
  157422. cquantize->is_padded = TRUE;
  157423. } else {
  157424. pad = 0;
  157425. cquantize->is_padded = FALSE;
  157426. }
  157427. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  157428. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157429. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  157430. (JDIMENSION) cinfo->out_color_components);
  157431. blksize = cquantize->sv_actual;
  157432. for (i = 0; i < cinfo->out_color_components; i++) {
  157433. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157434. blksize = blksize / nci;
  157435. if (pad)
  157436. cquantize->colorindex[i] += MAXJSAMPLE;
  157437. indexptr = cquantize->colorindex[i];
  157438. val = 0;
  157439. k = largest_input_value(cinfo, i, 0, nci-1);
  157440. for (j = 0; j <= MAXJSAMPLE; j++) {
  157441. while (j > k) /* advance val if past boundary */
  157442. k = largest_input_value(cinfo, i, ++val, nci-1);
  157443. indexptr[j] = (JSAMPLE) (val * blksize);
  157444. }
  157445. if (pad)
  157446. for (j = 1; j <= MAXJSAMPLE; j++) {
  157447. indexptr[-j] = indexptr[0];
  157448. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  157449. }
  157450. }
  157451. }
  157452. LOCAL(ODITHER_MATRIX_PTR)
  157453. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  157454. {
  157455. ODITHER_MATRIX_PTR odither;
  157456. int j,k;
  157457. INT32 num,den;
  157458. odither = (ODITHER_MATRIX_PTR)
  157459. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157460. SIZEOF(ODITHER_MATRIX));
  157461. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  157462. for (j = 0; j < ODITHER_SIZE; j++) {
  157463. for (k = 0; k < ODITHER_SIZE; k++) {
  157464. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  157465. * MAXJSAMPLE;
  157466. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  157467. }
  157468. }
  157469. return odither;
  157470. }
  157471. LOCAL(void)
  157472. create_odither_tables (j_decompress_ptr cinfo)
  157473. {
  157474. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157475. ODITHER_MATRIX_PTR odither;
  157476. int i, j, nci;
  157477. for (i = 0; i < cinfo->out_color_components; i++) {
  157478. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157479. odither = NULL; /* search for matching prior component */
  157480. for (j = 0; j < i; j++) {
  157481. if (nci == cquantize->Ncolors[j]) {
  157482. odither = cquantize->odither[j];
  157483. break;
  157484. }
  157485. }
  157486. if (odither == NULL) /* need a new table? */
  157487. odither = make_odither_array(cinfo, nci);
  157488. cquantize->odither[i] = odither;
  157489. }
  157490. }
  157491. METHODDEF(void)
  157492. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157493. JSAMPARRAY output_buf, int num_rows)
  157494. {
  157495. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157496. JSAMPARRAY colorindex = cquantize->colorindex;
  157497. register int pixcode, ci;
  157498. register JSAMPROW ptrin, ptrout;
  157499. int row;
  157500. JDIMENSION col;
  157501. JDIMENSION width = cinfo->output_width;
  157502. register int nc = cinfo->out_color_components;
  157503. for (row = 0; row < num_rows; row++) {
  157504. ptrin = input_buf[row];
  157505. ptrout = output_buf[row];
  157506. for (col = width; col > 0; col--) {
  157507. pixcode = 0;
  157508. for (ci = 0; ci < nc; ci++) {
  157509. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  157510. }
  157511. *ptrout++ = (JSAMPLE) pixcode;
  157512. }
  157513. }
  157514. }
  157515. METHODDEF(void)
  157516. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157517. JSAMPARRAY output_buf, int num_rows)
  157518. {
  157519. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157520. register int pixcode;
  157521. register JSAMPROW ptrin, ptrout;
  157522. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157523. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157524. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157525. int row;
  157526. JDIMENSION col;
  157527. JDIMENSION width = cinfo->output_width;
  157528. for (row = 0; row < num_rows; row++) {
  157529. ptrin = input_buf[row];
  157530. ptrout = output_buf[row];
  157531. for (col = width; col > 0; col--) {
  157532. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157533. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157534. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157535. *ptrout++ = (JSAMPLE) pixcode;
  157536. }
  157537. }
  157538. }
  157539. METHODDEF(void)
  157540. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157541. JSAMPARRAY output_buf, int num_rows)
  157542. {
  157543. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157544. register JSAMPROW input_ptr;
  157545. register JSAMPROW output_ptr;
  157546. JSAMPROW colorindex_ci;
  157547. int * dither; /* points to active row of dither matrix */
  157548. int row_index, col_index; /* current indexes into dither matrix */
  157549. int nc = cinfo->out_color_components;
  157550. int ci;
  157551. int row;
  157552. JDIMENSION col;
  157553. JDIMENSION width = cinfo->output_width;
  157554. for (row = 0; row < num_rows; row++) {
  157555. jzero_far((void FAR *) output_buf[row],
  157556. (size_t) (width * SIZEOF(JSAMPLE)));
  157557. row_index = cquantize->row_index;
  157558. for (ci = 0; ci < nc; ci++) {
  157559. input_ptr = input_buf[row] + ci;
  157560. output_ptr = output_buf[row];
  157561. colorindex_ci = cquantize->colorindex[ci];
  157562. dither = cquantize->odither[ci][row_index];
  157563. col_index = 0;
  157564. for (col = width; col > 0; col--) {
  157565. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157566. input_ptr += nc;
  157567. output_ptr++;
  157568. col_index = (col_index + 1) & ODITHER_MASK;
  157569. }
  157570. }
  157571. row_index = (row_index + 1) & ODITHER_MASK;
  157572. cquantize->row_index = row_index;
  157573. }
  157574. }
  157575. METHODDEF(void)
  157576. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157577. JSAMPARRAY output_buf, int num_rows)
  157578. {
  157579. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157580. register int pixcode;
  157581. register JSAMPROW input_ptr;
  157582. register JSAMPROW output_ptr;
  157583. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157584. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157585. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157586. int * dither0; /* points to active row of dither matrix */
  157587. int * dither1;
  157588. int * dither2;
  157589. int row_index, col_index; /* current indexes into dither matrix */
  157590. int row;
  157591. JDIMENSION col;
  157592. JDIMENSION width = cinfo->output_width;
  157593. for (row = 0; row < num_rows; row++) {
  157594. row_index = cquantize->row_index;
  157595. input_ptr = input_buf[row];
  157596. output_ptr = output_buf[row];
  157597. dither0 = cquantize->odither[0][row_index];
  157598. dither1 = cquantize->odither[1][row_index];
  157599. dither2 = cquantize->odither[2][row_index];
  157600. col_index = 0;
  157601. for (col = width; col > 0; col--) {
  157602. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157603. dither0[col_index]]);
  157604. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157605. dither1[col_index]]);
  157606. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157607. dither2[col_index]]);
  157608. *output_ptr++ = (JSAMPLE) pixcode;
  157609. col_index = (col_index + 1) & ODITHER_MASK;
  157610. }
  157611. row_index = (row_index + 1) & ODITHER_MASK;
  157612. cquantize->row_index = row_index;
  157613. }
  157614. }
  157615. METHODDEF(void)
  157616. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157617. JSAMPARRAY output_buf, int num_rows)
  157618. {
  157619. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157620. register LOCFSERROR cur; /* current error or pixel value */
  157621. LOCFSERROR belowerr; /* error for pixel below cur */
  157622. LOCFSERROR bpreverr; /* error for below/prev col */
  157623. LOCFSERROR bnexterr; /* error for below/next col */
  157624. LOCFSERROR delta;
  157625. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157626. register JSAMPROW input_ptr;
  157627. register JSAMPROW output_ptr;
  157628. JSAMPROW colorindex_ci;
  157629. JSAMPROW colormap_ci;
  157630. int pixcode;
  157631. int nc = cinfo->out_color_components;
  157632. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157633. int dirnc; /* dir * nc */
  157634. int ci;
  157635. int row;
  157636. JDIMENSION col;
  157637. JDIMENSION width = cinfo->output_width;
  157638. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157639. SHIFT_TEMPS
  157640. for (row = 0; row < num_rows; row++) {
  157641. jzero_far((void FAR *) output_buf[row],
  157642. (size_t) (width * SIZEOF(JSAMPLE)));
  157643. for (ci = 0; ci < nc; ci++) {
  157644. input_ptr = input_buf[row] + ci;
  157645. output_ptr = output_buf[row];
  157646. if (cquantize->on_odd_row) {
  157647. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157648. output_ptr += width-1;
  157649. dir = -1;
  157650. dirnc = -nc;
  157651. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157652. } else {
  157653. dir = 1;
  157654. dirnc = nc;
  157655. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157656. }
  157657. colorindex_ci = cquantize->colorindex[ci];
  157658. colormap_ci = cquantize->sv_colormap[ci];
  157659. cur = 0;
  157660. belowerr = bpreverr = 0;
  157661. for (col = width; col > 0; col--) {
  157662. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157663. cur += GETJSAMPLE(*input_ptr);
  157664. cur = GETJSAMPLE(range_limit[cur]);
  157665. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157666. *output_ptr += (JSAMPLE) pixcode;
  157667. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157668. bnexterr = cur;
  157669. delta = cur * 2;
  157670. cur += delta; /* form error * 3 */
  157671. errorptr[0] = (FSERROR) (bpreverr + cur);
  157672. cur += delta; /* form error * 5 */
  157673. bpreverr = belowerr + cur;
  157674. belowerr = bnexterr;
  157675. cur += delta; /* form error * 7 */
  157676. input_ptr += dirnc; /* advance input ptr to next column */
  157677. output_ptr += dir; /* advance output ptr to next column */
  157678. errorptr += dir; /* advance errorptr to current column */
  157679. }
  157680. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157681. }
  157682. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157683. }
  157684. }
  157685. LOCAL(void)
  157686. alloc_fs_workspace (j_decompress_ptr cinfo)
  157687. {
  157688. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157689. size_t arraysize;
  157690. int i;
  157691. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157692. for (i = 0; i < cinfo->out_color_components; i++) {
  157693. cquantize->fserrors[i] = (FSERRPTR)
  157694. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157695. }
  157696. }
  157697. METHODDEF(void)
  157698. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157699. {
  157700. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157701. size_t arraysize;
  157702. int i;
  157703. cinfo->colormap = cquantize->sv_colormap;
  157704. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157705. switch (cinfo->dither_mode) {
  157706. case JDITHER_NONE:
  157707. if (cinfo->out_color_components == 3)
  157708. cquantize->pub.color_quantize = color_quantize3;
  157709. else
  157710. cquantize->pub.color_quantize = color_quantize;
  157711. break;
  157712. case JDITHER_ORDERED:
  157713. if (cinfo->out_color_components == 3)
  157714. cquantize->pub.color_quantize = quantize3_ord_dither;
  157715. else
  157716. cquantize->pub.color_quantize = quantize_ord_dither;
  157717. cquantize->row_index = 0; /* initialize state for ordered dither */
  157718. if (! cquantize->is_padded)
  157719. create_colorindex(cinfo);
  157720. if (cquantize->odither[0] == NULL)
  157721. create_odither_tables(cinfo);
  157722. break;
  157723. case JDITHER_FS:
  157724. cquantize->pub.color_quantize = quantize_fs_dither;
  157725. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157726. if (cquantize->fserrors[0] == NULL)
  157727. alloc_fs_workspace(cinfo);
  157728. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157729. for (i = 0; i < cinfo->out_color_components; i++)
  157730. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157731. break;
  157732. default:
  157733. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157734. break;
  157735. }
  157736. }
  157737. METHODDEF(void)
  157738. finish_pass_1_quant (j_decompress_ptr cinfo)
  157739. {
  157740. }
  157741. METHODDEF(void)
  157742. new_color_map_1_quant (j_decompress_ptr cinfo)
  157743. {
  157744. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157745. }
  157746. GLOBAL(void)
  157747. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157748. {
  157749. my_cquantize_ptr cquantize;
  157750. cquantize = (my_cquantize_ptr)
  157751. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157752. SIZEOF(my_cquantizer));
  157753. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157754. cquantize->pub.start_pass = start_pass_1_quant;
  157755. cquantize->pub.finish_pass = finish_pass_1_quant;
  157756. cquantize->pub.new_color_map = new_color_map_1_quant;
  157757. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157758. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157759. if (cinfo->out_color_components > MAX_Q_COMPS)
  157760. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157761. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157762. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157763. create_colormap(cinfo);
  157764. create_colorindex(cinfo);
  157765. if (cinfo->dither_mode == JDITHER_FS)
  157766. alloc_fs_workspace(cinfo);
  157767. }
  157768. #endif /* QUANT_1PASS_SUPPORTED */
  157769. /*** End of inlined file: jquant1.c ***/
  157770. /*** Start of inlined file: jquant2.c ***/
  157771. #define JPEG_INTERNALS
  157772. #ifdef QUANT_2PASS_SUPPORTED
  157773. #define R_SCALE 2 /* scale R distances by this much */
  157774. #define G_SCALE 3 /* scale G distances by this much */
  157775. #define B_SCALE 1 /* and B by this much */
  157776. #if RGB_RED == 0
  157777. #define C0_SCALE R_SCALE
  157778. #endif
  157779. #if RGB_BLUE == 0
  157780. #define C0_SCALE B_SCALE
  157781. #endif
  157782. #if RGB_GREEN == 1
  157783. #define C1_SCALE G_SCALE
  157784. #endif
  157785. #if RGB_RED == 2
  157786. #define C2_SCALE R_SCALE
  157787. #endif
  157788. #if RGB_BLUE == 2
  157789. #define C2_SCALE B_SCALE
  157790. #endif
  157791. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157792. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157793. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157794. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157795. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157796. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157797. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157798. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157799. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157800. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157801. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157802. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157803. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157804. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157805. typedef hist2d * hist3d; /* type for top-level pointer */
  157806. #if BITS_IN_JSAMPLE == 8
  157807. typedef INT16 FSERROR; /* 16 bits should be enough */
  157808. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157809. #else
  157810. typedef INT32 FSERROR; /* may need more than 16 bits */
  157811. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157812. #endif
  157813. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157814. typedef struct {
  157815. struct jpeg_color_quantizer pub; /* public fields */
  157816. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157817. int desired; /* desired # of colors = size of colormap */
  157818. hist3d histogram; /* pointer to the histogram */
  157819. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157820. FSERRPTR fserrors; /* accumulated errors */
  157821. boolean on_odd_row; /* flag to remember which row we are on */
  157822. int * error_limiter; /* table for clamping the applied error */
  157823. } my_cquantizer2;
  157824. typedef my_cquantizer2 * my_cquantize_ptr2;
  157825. METHODDEF(void)
  157826. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157827. JSAMPARRAY output_buf, int num_rows)
  157828. {
  157829. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157830. register JSAMPROW ptr;
  157831. register histptr histp;
  157832. register hist3d histogram = cquantize->histogram;
  157833. int row;
  157834. JDIMENSION col;
  157835. JDIMENSION width = cinfo->output_width;
  157836. for (row = 0; row < num_rows; row++) {
  157837. ptr = input_buf[row];
  157838. for (col = width; col > 0; col--) {
  157839. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157840. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157841. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157842. if (++(*histp) <= 0)
  157843. (*histp)--;
  157844. ptr += 3;
  157845. }
  157846. }
  157847. }
  157848. typedef struct {
  157849. int c0min, c0max;
  157850. int c1min, c1max;
  157851. int c2min, c2max;
  157852. INT32 volume;
  157853. long colorcount;
  157854. } box;
  157855. typedef box * boxptr;
  157856. LOCAL(boxptr)
  157857. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157858. {
  157859. register boxptr boxp;
  157860. register int i;
  157861. register long maxc = 0;
  157862. boxptr which = NULL;
  157863. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157864. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157865. which = boxp;
  157866. maxc = boxp->colorcount;
  157867. }
  157868. }
  157869. return which;
  157870. }
  157871. LOCAL(boxptr)
  157872. find_biggest_volume (boxptr boxlist, int numboxes)
  157873. {
  157874. register boxptr boxp;
  157875. register int i;
  157876. register INT32 maxv = 0;
  157877. boxptr which = NULL;
  157878. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157879. if (boxp->volume > maxv) {
  157880. which = boxp;
  157881. maxv = boxp->volume;
  157882. }
  157883. }
  157884. return which;
  157885. }
  157886. LOCAL(void)
  157887. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157888. {
  157889. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157890. hist3d histogram = cquantize->histogram;
  157891. histptr histp;
  157892. int c0,c1,c2;
  157893. int c0min,c0max,c1min,c1max,c2min,c2max;
  157894. INT32 dist0,dist1,dist2;
  157895. long ccount;
  157896. c0min = boxp->c0min; c0max = boxp->c0max;
  157897. c1min = boxp->c1min; c1max = boxp->c1max;
  157898. c2min = boxp->c2min; c2max = boxp->c2max;
  157899. if (c0max > c0min)
  157900. for (c0 = c0min; c0 <= c0max; c0++)
  157901. for (c1 = c1min; c1 <= c1max; c1++) {
  157902. histp = & histogram[c0][c1][c2min];
  157903. for (c2 = c2min; c2 <= c2max; c2++)
  157904. if (*histp++ != 0) {
  157905. boxp->c0min = c0min = c0;
  157906. goto have_c0min;
  157907. }
  157908. }
  157909. have_c0min:
  157910. if (c0max > c0min)
  157911. for (c0 = c0max; c0 >= c0min; c0--)
  157912. for (c1 = c1min; c1 <= c1max; c1++) {
  157913. histp = & histogram[c0][c1][c2min];
  157914. for (c2 = c2min; c2 <= c2max; c2++)
  157915. if (*histp++ != 0) {
  157916. boxp->c0max = c0max = c0;
  157917. goto have_c0max;
  157918. }
  157919. }
  157920. have_c0max:
  157921. if (c1max > c1min)
  157922. for (c1 = c1min; c1 <= c1max; c1++)
  157923. for (c0 = c0min; c0 <= c0max; c0++) {
  157924. histp = & histogram[c0][c1][c2min];
  157925. for (c2 = c2min; c2 <= c2max; c2++)
  157926. if (*histp++ != 0) {
  157927. boxp->c1min = c1min = c1;
  157928. goto have_c1min;
  157929. }
  157930. }
  157931. have_c1min:
  157932. if (c1max > c1min)
  157933. for (c1 = c1max; c1 >= c1min; c1--)
  157934. for (c0 = c0min; c0 <= c0max; c0++) {
  157935. histp = & histogram[c0][c1][c2min];
  157936. for (c2 = c2min; c2 <= c2max; c2++)
  157937. if (*histp++ != 0) {
  157938. boxp->c1max = c1max = c1;
  157939. goto have_c1max;
  157940. }
  157941. }
  157942. have_c1max:
  157943. if (c2max > c2min)
  157944. for (c2 = c2min; c2 <= c2max; c2++)
  157945. for (c0 = c0min; c0 <= c0max; c0++) {
  157946. histp = & histogram[c0][c1min][c2];
  157947. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157948. if (*histp != 0) {
  157949. boxp->c2min = c2min = c2;
  157950. goto have_c2min;
  157951. }
  157952. }
  157953. have_c2min:
  157954. if (c2max > c2min)
  157955. for (c2 = c2max; c2 >= c2min; c2--)
  157956. for (c0 = c0min; c0 <= c0max; c0++) {
  157957. histp = & histogram[c0][c1min][c2];
  157958. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157959. if (*histp != 0) {
  157960. boxp->c2max = c2max = c2;
  157961. goto have_c2max;
  157962. }
  157963. }
  157964. have_c2max:
  157965. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157966. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157967. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157968. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157969. ccount = 0;
  157970. for (c0 = c0min; c0 <= c0max; c0++)
  157971. for (c1 = c1min; c1 <= c1max; c1++) {
  157972. histp = & histogram[c0][c1][c2min];
  157973. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157974. if (*histp != 0) {
  157975. ccount++;
  157976. }
  157977. }
  157978. boxp->colorcount = ccount;
  157979. }
  157980. LOCAL(int)
  157981. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157982. int desired_colors)
  157983. {
  157984. int n,lb;
  157985. int c0,c1,c2,cmax;
  157986. register boxptr b1,b2;
  157987. while (numboxes < desired_colors) {
  157988. if (numboxes*2 <= desired_colors) {
  157989. b1 = find_biggest_color_pop(boxlist, numboxes);
  157990. } else {
  157991. b1 = find_biggest_volume(boxlist, numboxes);
  157992. }
  157993. if (b1 == NULL) /* no splittable boxes left! */
  157994. break;
  157995. b2 = &boxlist[numboxes]; /* where new box will go */
  157996. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157997. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157998. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157999. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  158000. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  158001. #if RGB_RED == 0
  158002. cmax = c1; n = 1;
  158003. if (c0 > cmax) { cmax = c0; n = 0; }
  158004. if (c2 > cmax) { n = 2; }
  158005. #else
  158006. cmax = c1; n = 1;
  158007. if (c2 > cmax) { cmax = c2; n = 2; }
  158008. if (c0 > cmax) { n = 0; }
  158009. #endif
  158010. switch (n) {
  158011. case 0:
  158012. lb = (b1->c0max + b1->c0min) / 2;
  158013. b1->c0max = lb;
  158014. b2->c0min = lb+1;
  158015. break;
  158016. case 1:
  158017. lb = (b1->c1max + b1->c1min) / 2;
  158018. b1->c1max = lb;
  158019. b2->c1min = lb+1;
  158020. break;
  158021. case 2:
  158022. lb = (b1->c2max + b1->c2min) / 2;
  158023. b1->c2max = lb;
  158024. b2->c2min = lb+1;
  158025. break;
  158026. }
  158027. update_box(cinfo, b1);
  158028. update_box(cinfo, b2);
  158029. numboxes++;
  158030. }
  158031. return numboxes;
  158032. }
  158033. LOCAL(void)
  158034. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  158035. {
  158036. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158037. hist3d histogram = cquantize->histogram;
  158038. histptr histp;
  158039. int c0,c1,c2;
  158040. int c0min,c0max,c1min,c1max,c2min,c2max;
  158041. long count;
  158042. long total = 0;
  158043. long c0total = 0;
  158044. long c1total = 0;
  158045. long c2total = 0;
  158046. c0min = boxp->c0min; c0max = boxp->c0max;
  158047. c1min = boxp->c1min; c1max = boxp->c1max;
  158048. c2min = boxp->c2min; c2max = boxp->c2max;
  158049. for (c0 = c0min; c0 <= c0max; c0++)
  158050. for (c1 = c1min; c1 <= c1max; c1++) {
  158051. histp = & histogram[c0][c1][c2min];
  158052. for (c2 = c2min; c2 <= c2max; c2++) {
  158053. if ((count = *histp++) != 0) {
  158054. total += count;
  158055. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  158056. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  158057. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  158058. }
  158059. }
  158060. }
  158061. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  158062. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  158063. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  158064. }
  158065. LOCAL(void)
  158066. select_colors (j_decompress_ptr cinfo, int desired_colors)
  158067. {
  158068. boxptr boxlist;
  158069. int numboxes;
  158070. int i;
  158071. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  158072. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  158073. numboxes = 1;
  158074. boxlist[0].c0min = 0;
  158075. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  158076. boxlist[0].c1min = 0;
  158077. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  158078. boxlist[0].c2min = 0;
  158079. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  158080. update_box(cinfo, & boxlist[0]);
  158081. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  158082. for (i = 0; i < numboxes; i++)
  158083. compute_color(cinfo, & boxlist[i], i);
  158084. cinfo->actual_number_of_colors = numboxes;
  158085. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  158086. }
  158087. #define BOX_C0_LOG (HIST_C0_BITS-3)
  158088. #define BOX_C1_LOG (HIST_C1_BITS-3)
  158089. #define BOX_C2_LOG (HIST_C2_BITS-3)
  158090. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  158091. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  158092. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  158093. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  158094. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  158095. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  158096. LOCAL(int)
  158097. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  158098. JSAMPLE colorlist[])
  158099. {
  158100. int numcolors = cinfo->actual_number_of_colors;
  158101. int maxc0, maxc1, maxc2;
  158102. int centerc0, centerc1, centerc2;
  158103. int i, x, ncolors;
  158104. INT32 minmaxdist, min_dist, max_dist, tdist;
  158105. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  158106. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  158107. centerc0 = (minc0 + maxc0) >> 1;
  158108. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  158109. centerc1 = (minc1 + maxc1) >> 1;
  158110. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  158111. centerc2 = (minc2 + maxc2) >> 1;
  158112. minmaxdist = 0x7FFFFFFFL;
  158113. for (i = 0; i < numcolors; i++) {
  158114. x = GETJSAMPLE(cinfo->colormap[0][i]);
  158115. if (x < minc0) {
  158116. tdist = (x - minc0) * C0_SCALE;
  158117. min_dist = tdist*tdist;
  158118. tdist = (x - maxc0) * C0_SCALE;
  158119. max_dist = tdist*tdist;
  158120. } else if (x > maxc0) {
  158121. tdist = (x - maxc0) * C0_SCALE;
  158122. min_dist = tdist*tdist;
  158123. tdist = (x - minc0) * C0_SCALE;
  158124. max_dist = tdist*tdist;
  158125. } else {
  158126. min_dist = 0;
  158127. if (x <= centerc0) {
  158128. tdist = (x - maxc0) * C0_SCALE;
  158129. max_dist = tdist*tdist;
  158130. } else {
  158131. tdist = (x - minc0) * C0_SCALE;
  158132. max_dist = tdist*tdist;
  158133. }
  158134. }
  158135. x = GETJSAMPLE(cinfo->colormap[1][i]);
  158136. if (x < minc1) {
  158137. tdist = (x - minc1) * C1_SCALE;
  158138. min_dist += tdist*tdist;
  158139. tdist = (x - maxc1) * C1_SCALE;
  158140. max_dist += tdist*tdist;
  158141. } else if (x > maxc1) {
  158142. tdist = (x - maxc1) * C1_SCALE;
  158143. min_dist += tdist*tdist;
  158144. tdist = (x - minc1) * C1_SCALE;
  158145. max_dist += tdist*tdist;
  158146. } else {
  158147. if (x <= centerc1) {
  158148. tdist = (x - maxc1) * C1_SCALE;
  158149. max_dist += tdist*tdist;
  158150. } else {
  158151. tdist = (x - minc1) * C1_SCALE;
  158152. max_dist += tdist*tdist;
  158153. }
  158154. }
  158155. x = GETJSAMPLE(cinfo->colormap[2][i]);
  158156. if (x < minc2) {
  158157. tdist = (x - minc2) * C2_SCALE;
  158158. min_dist += tdist*tdist;
  158159. tdist = (x - maxc2) * C2_SCALE;
  158160. max_dist += tdist*tdist;
  158161. } else if (x > maxc2) {
  158162. tdist = (x - maxc2) * C2_SCALE;
  158163. min_dist += tdist*tdist;
  158164. tdist = (x - minc2) * C2_SCALE;
  158165. max_dist += tdist*tdist;
  158166. } else {
  158167. if (x <= centerc2) {
  158168. tdist = (x - maxc2) * C2_SCALE;
  158169. max_dist += tdist*tdist;
  158170. } else {
  158171. tdist = (x - minc2) * C2_SCALE;
  158172. max_dist += tdist*tdist;
  158173. }
  158174. }
  158175. mindist[i] = min_dist; /* save away the results */
  158176. if (max_dist < minmaxdist)
  158177. minmaxdist = max_dist;
  158178. }
  158179. ncolors = 0;
  158180. for (i = 0; i < numcolors; i++) {
  158181. if (mindist[i] <= minmaxdist)
  158182. colorlist[ncolors++] = (JSAMPLE) i;
  158183. }
  158184. return ncolors;
  158185. }
  158186. LOCAL(void)
  158187. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  158188. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  158189. {
  158190. int ic0, ic1, ic2;
  158191. int i, icolor;
  158192. register INT32 * bptr; /* pointer into bestdist[] array */
  158193. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158194. INT32 dist0, dist1; /* initial distance values */
  158195. register INT32 dist2; /* current distance in inner loop */
  158196. INT32 xx0, xx1; /* distance increments */
  158197. register INT32 xx2;
  158198. INT32 inc0, inc1, inc2; /* initial values for increments */
  158199. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158200. bptr = bestdist;
  158201. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  158202. *bptr++ = 0x7FFFFFFFL;
  158203. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  158204. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  158205. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  158206. for (i = 0; i < numcolors; i++) {
  158207. icolor = GETJSAMPLE(colorlist[i]);
  158208. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  158209. dist0 = inc0*inc0;
  158210. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  158211. dist0 += inc1*inc1;
  158212. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  158213. dist0 += inc2*inc2;
  158214. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  158215. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  158216. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  158217. bptr = bestdist;
  158218. cptr = bestcolor;
  158219. xx0 = inc0;
  158220. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  158221. dist1 = dist0;
  158222. xx1 = inc1;
  158223. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  158224. dist2 = dist1;
  158225. xx2 = inc2;
  158226. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  158227. if (dist2 < *bptr) {
  158228. *bptr = dist2;
  158229. *cptr = (JSAMPLE) icolor;
  158230. }
  158231. dist2 += xx2;
  158232. xx2 += 2 * STEP_C2 * STEP_C2;
  158233. bptr++;
  158234. cptr++;
  158235. }
  158236. dist1 += xx1;
  158237. xx1 += 2 * STEP_C1 * STEP_C1;
  158238. }
  158239. dist0 += xx0;
  158240. xx0 += 2 * STEP_C0 * STEP_C0;
  158241. }
  158242. }
  158243. }
  158244. LOCAL(void)
  158245. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  158246. {
  158247. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158248. hist3d histogram = cquantize->histogram;
  158249. int minc0, minc1, minc2; /* lower left corner of update box */
  158250. int ic0, ic1, ic2;
  158251. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158252. register histptr cachep; /* pointer into main cache array */
  158253. JSAMPLE colorlist[MAXNUMCOLORS];
  158254. int numcolors; /* number of candidate colors */
  158255. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158256. c0 >>= BOX_C0_LOG;
  158257. c1 >>= BOX_C1_LOG;
  158258. c2 >>= BOX_C2_LOG;
  158259. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  158260. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  158261. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  158262. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  158263. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  158264. bestcolor);
  158265. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  158266. c1 <<= BOX_C1_LOG;
  158267. c2 <<= BOX_C2_LOG;
  158268. cptr = bestcolor;
  158269. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  158270. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  158271. cachep = & histogram[c0+ic0][c1+ic1][c2];
  158272. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  158273. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  158274. }
  158275. }
  158276. }
  158277. }
  158278. METHODDEF(void)
  158279. pass2_no_dither (j_decompress_ptr cinfo,
  158280. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158281. {
  158282. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158283. hist3d histogram = cquantize->histogram;
  158284. register JSAMPROW inptr, outptr;
  158285. register histptr cachep;
  158286. register int c0, c1, c2;
  158287. int row;
  158288. JDIMENSION col;
  158289. JDIMENSION width = cinfo->output_width;
  158290. for (row = 0; row < num_rows; row++) {
  158291. inptr = input_buf[row];
  158292. outptr = output_buf[row];
  158293. for (col = width; col > 0; col--) {
  158294. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  158295. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  158296. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  158297. cachep = & histogram[c0][c1][c2];
  158298. if (*cachep == 0)
  158299. fill_inverse_cmap(cinfo, c0,c1,c2);
  158300. *outptr++ = (JSAMPLE) (*cachep - 1);
  158301. }
  158302. }
  158303. }
  158304. METHODDEF(void)
  158305. pass2_fs_dither (j_decompress_ptr cinfo,
  158306. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158307. {
  158308. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158309. hist3d histogram = cquantize->histogram;
  158310. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  158311. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  158312. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  158313. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  158314. JSAMPROW inptr; /* => current input pixel */
  158315. JSAMPROW outptr; /* => current output pixel */
  158316. histptr cachep;
  158317. int dir; /* +1 or -1 depending on direction */
  158318. int dir3; /* 3*dir, for advancing inptr & errorptr */
  158319. int row;
  158320. JDIMENSION col;
  158321. JDIMENSION width = cinfo->output_width;
  158322. JSAMPLE *range_limit = cinfo->sample_range_limit;
  158323. int *error_limit = cquantize->error_limiter;
  158324. JSAMPROW colormap0 = cinfo->colormap[0];
  158325. JSAMPROW colormap1 = cinfo->colormap[1];
  158326. JSAMPROW colormap2 = cinfo->colormap[2];
  158327. SHIFT_TEMPS
  158328. for (row = 0; row < num_rows; row++) {
  158329. inptr = input_buf[row];
  158330. outptr = output_buf[row];
  158331. if (cquantize->on_odd_row) {
  158332. inptr += (width-1) * 3; /* so point to rightmost pixel */
  158333. outptr += width-1;
  158334. dir = -1;
  158335. dir3 = -3;
  158336. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  158337. cquantize->on_odd_row = FALSE; /* flip for next time */
  158338. } else {
  158339. dir = 1;
  158340. dir3 = 3;
  158341. errorptr = cquantize->fserrors; /* => entry before first real column */
  158342. cquantize->on_odd_row = TRUE; /* flip for next time */
  158343. }
  158344. cur0 = cur1 = cur2 = 0;
  158345. belowerr0 = belowerr1 = belowerr2 = 0;
  158346. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  158347. for (col = width; col > 0; col--) {
  158348. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  158349. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  158350. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  158351. cur0 = error_limit[cur0];
  158352. cur1 = error_limit[cur1];
  158353. cur2 = error_limit[cur2];
  158354. cur0 += GETJSAMPLE(inptr[0]);
  158355. cur1 += GETJSAMPLE(inptr[1]);
  158356. cur2 += GETJSAMPLE(inptr[2]);
  158357. cur0 = GETJSAMPLE(range_limit[cur0]);
  158358. cur1 = GETJSAMPLE(range_limit[cur1]);
  158359. cur2 = GETJSAMPLE(range_limit[cur2]);
  158360. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  158361. if (*cachep == 0)
  158362. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  158363. { register int pixcode = *cachep - 1;
  158364. *outptr = (JSAMPLE) pixcode;
  158365. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  158366. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  158367. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  158368. }
  158369. { register LOCFSERROR bnexterr, delta;
  158370. bnexterr = cur0; /* Process component 0 */
  158371. delta = cur0 * 2;
  158372. cur0 += delta; /* form error * 3 */
  158373. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  158374. cur0 += delta; /* form error * 5 */
  158375. bpreverr0 = belowerr0 + cur0;
  158376. belowerr0 = bnexterr;
  158377. cur0 += delta; /* form error * 7 */
  158378. bnexterr = cur1; /* Process component 1 */
  158379. delta = cur1 * 2;
  158380. cur1 += delta; /* form error * 3 */
  158381. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  158382. cur1 += delta; /* form error * 5 */
  158383. bpreverr1 = belowerr1 + cur1;
  158384. belowerr1 = bnexterr;
  158385. cur1 += delta; /* form error * 7 */
  158386. bnexterr = cur2; /* Process component 2 */
  158387. delta = cur2 * 2;
  158388. cur2 += delta; /* form error * 3 */
  158389. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  158390. cur2 += delta; /* form error * 5 */
  158391. bpreverr2 = belowerr2 + cur2;
  158392. belowerr2 = bnexterr;
  158393. cur2 += delta; /* form error * 7 */
  158394. }
  158395. inptr += dir3; /* Advance pixel pointers to next column */
  158396. outptr += dir;
  158397. errorptr += dir3; /* advance errorptr to current column */
  158398. }
  158399. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  158400. errorptr[1] = (FSERROR) bpreverr1;
  158401. errorptr[2] = (FSERROR) bpreverr2;
  158402. }
  158403. }
  158404. LOCAL(void)
  158405. init_error_limit (j_decompress_ptr cinfo)
  158406. {
  158407. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158408. int * table;
  158409. int in, out;
  158410. table = (int *) (*cinfo->mem->alloc_small)
  158411. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  158412. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  158413. cquantize->error_limiter = table;
  158414. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  158415. out = 0;
  158416. for (in = 0; in < STEPSIZE; in++, out++) {
  158417. table[in] = out; table[-in] = -out;
  158418. }
  158419. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  158420. table[in] = out; table[-in] = -out;
  158421. }
  158422. for (; in <= MAXJSAMPLE; in++) {
  158423. table[in] = out; table[-in] = -out;
  158424. }
  158425. #undef STEPSIZE
  158426. }
  158427. METHODDEF(void)
  158428. finish_pass1 (j_decompress_ptr cinfo)
  158429. {
  158430. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158431. cinfo->colormap = cquantize->sv_colormap;
  158432. select_colors(cinfo, cquantize->desired);
  158433. cquantize->needs_zeroed = TRUE;
  158434. }
  158435. METHODDEF(void)
  158436. finish_pass2 (j_decompress_ptr cinfo)
  158437. {
  158438. }
  158439. METHODDEF(void)
  158440. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  158441. {
  158442. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158443. hist3d histogram = cquantize->histogram;
  158444. int i;
  158445. if (cinfo->dither_mode != JDITHER_NONE)
  158446. cinfo->dither_mode = JDITHER_FS;
  158447. if (is_pre_scan) {
  158448. cquantize->pub.color_quantize = prescan_quantize;
  158449. cquantize->pub.finish_pass = finish_pass1;
  158450. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  158451. } else {
  158452. if (cinfo->dither_mode == JDITHER_FS)
  158453. cquantize->pub.color_quantize = pass2_fs_dither;
  158454. else
  158455. cquantize->pub.color_quantize = pass2_no_dither;
  158456. cquantize->pub.finish_pass = finish_pass2;
  158457. i = cinfo->actual_number_of_colors;
  158458. if (i < 1)
  158459. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  158460. if (i > MAXNUMCOLORS)
  158461. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158462. if (cinfo->dither_mode == JDITHER_FS) {
  158463. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  158464. (3 * SIZEOF(FSERROR)));
  158465. if (cquantize->fserrors == NULL)
  158466. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158467. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  158468. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  158469. if (cquantize->error_limiter == NULL)
  158470. init_error_limit(cinfo);
  158471. cquantize->on_odd_row = FALSE;
  158472. }
  158473. }
  158474. if (cquantize->needs_zeroed) {
  158475. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158476. jzero_far((void FAR *) histogram[i],
  158477. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158478. }
  158479. cquantize->needs_zeroed = FALSE;
  158480. }
  158481. }
  158482. METHODDEF(void)
  158483. new_color_map_2_quant (j_decompress_ptr cinfo)
  158484. {
  158485. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158486. cquantize->needs_zeroed = TRUE;
  158487. }
  158488. GLOBAL(void)
  158489. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  158490. {
  158491. my_cquantize_ptr2 cquantize;
  158492. int i;
  158493. cquantize = (my_cquantize_ptr2)
  158494. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158495. SIZEOF(my_cquantizer2));
  158496. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158497. cquantize->pub.start_pass = start_pass_2_quant;
  158498. cquantize->pub.new_color_map = new_color_map_2_quant;
  158499. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  158500. cquantize->error_limiter = NULL;
  158501. if (cinfo->out_color_components != 3)
  158502. ERREXIT(cinfo, JERR_NOTIMPL);
  158503. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  158504. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  158505. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158506. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  158507. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158508. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158509. }
  158510. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  158511. if (cinfo->enable_2pass_quant) {
  158512. int desired = cinfo->desired_number_of_colors;
  158513. if (desired < 8)
  158514. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  158515. if (desired > MAXNUMCOLORS)
  158516. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158517. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  158518. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  158519. cquantize->desired = desired;
  158520. } else
  158521. cquantize->sv_colormap = NULL;
  158522. if (cinfo->dither_mode != JDITHER_NONE)
  158523. cinfo->dither_mode = JDITHER_FS;
  158524. if (cinfo->dither_mode == JDITHER_FS) {
  158525. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158526. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158527. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158528. init_error_limit(cinfo);
  158529. }
  158530. }
  158531. #endif /* QUANT_2PASS_SUPPORTED */
  158532. /*** End of inlined file: jquant2.c ***/
  158533. /*** Start of inlined file: jutils.c ***/
  158534. #define JPEG_INTERNALS
  158535. #if 0 /* This table is not actually needed in v6a */
  158536. const int jpeg_zigzag_order[DCTSIZE2] = {
  158537. 0, 1, 5, 6, 14, 15, 27, 28,
  158538. 2, 4, 7, 13, 16, 26, 29, 42,
  158539. 3, 8, 12, 17, 25, 30, 41, 43,
  158540. 9, 11, 18, 24, 31, 40, 44, 53,
  158541. 10, 19, 23, 32, 39, 45, 52, 54,
  158542. 20, 22, 33, 38, 46, 51, 55, 60,
  158543. 21, 34, 37, 47, 50, 56, 59, 61,
  158544. 35, 36, 48, 49, 57, 58, 62, 63
  158545. };
  158546. #endif
  158547. const int jpeg_natural_order[DCTSIZE2+16] = {
  158548. 0, 1, 8, 16, 9, 2, 3, 10,
  158549. 17, 24, 32, 25, 18, 11, 4, 5,
  158550. 12, 19, 26, 33, 40, 48, 41, 34,
  158551. 27, 20, 13, 6, 7, 14, 21, 28,
  158552. 35, 42, 49, 56, 57, 50, 43, 36,
  158553. 29, 22, 15, 23, 30, 37, 44, 51,
  158554. 58, 59, 52, 45, 38, 31, 39, 46,
  158555. 53, 60, 61, 54, 47, 55, 62, 63,
  158556. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158557. 63, 63, 63, 63, 63, 63, 63, 63
  158558. };
  158559. GLOBAL(long)
  158560. jdiv_round_up (long a, long b)
  158561. {
  158562. return (a + b - 1L) / b;
  158563. }
  158564. GLOBAL(long)
  158565. jround_up (long a, long b)
  158566. {
  158567. a += b - 1L;
  158568. return a - (a % b);
  158569. }
  158570. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158571. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158572. #define FMEMZERO(target,size) MEMZERO(target,size)
  158573. #else /* 80x86 case, define if we can */
  158574. #ifdef USE_FMEM
  158575. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158576. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158577. #endif
  158578. #endif
  158579. GLOBAL(void)
  158580. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158581. JSAMPARRAY output_array, int dest_row,
  158582. int num_rows, JDIMENSION num_cols)
  158583. {
  158584. register JSAMPROW inptr, outptr;
  158585. #ifdef FMEMCOPY
  158586. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158587. #else
  158588. register JDIMENSION count;
  158589. #endif
  158590. register int row;
  158591. input_array += source_row;
  158592. output_array += dest_row;
  158593. for (row = num_rows; row > 0; row--) {
  158594. inptr = *input_array++;
  158595. outptr = *output_array++;
  158596. #ifdef FMEMCOPY
  158597. FMEMCOPY(outptr, inptr, count);
  158598. #else
  158599. for (count = num_cols; count > 0; count--)
  158600. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158601. #endif
  158602. }
  158603. }
  158604. GLOBAL(void)
  158605. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158606. JDIMENSION num_blocks)
  158607. {
  158608. #ifdef FMEMCOPY
  158609. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158610. #else
  158611. register JCOEFPTR inptr, outptr;
  158612. register long count;
  158613. inptr = (JCOEFPTR) input_row;
  158614. outptr = (JCOEFPTR) output_row;
  158615. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158616. *outptr++ = *inptr++;
  158617. }
  158618. #endif
  158619. }
  158620. GLOBAL(void)
  158621. jzero_far (void FAR * target, size_t bytestozero)
  158622. {
  158623. #ifdef FMEMZERO
  158624. FMEMZERO(target, bytestozero);
  158625. #else
  158626. register char FAR * ptr = (char FAR *) target;
  158627. register size_t count;
  158628. for (count = bytestozero; count > 0; count--) {
  158629. *ptr++ = 0;
  158630. }
  158631. #endif
  158632. }
  158633. /*** End of inlined file: jutils.c ***/
  158634. /*** Start of inlined file: transupp.c ***/
  158635. #define JPEG_INTERNALS
  158636. /*** Start of inlined file: transupp.h ***/
  158637. #ifndef TRANSFORMS_SUPPORTED
  158638. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158639. #endif
  158640. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158641. #define jtransform_request_workspace jTrRequest
  158642. #define jtransform_adjust_parameters jTrAdjust
  158643. #define jtransform_execute_transformation jTrExec
  158644. #define jcopy_markers_setup jCMrkSetup
  158645. #define jcopy_markers_execute jCMrkExec
  158646. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158647. typedef enum {
  158648. JXFORM_NONE, /* no transformation */
  158649. JXFORM_FLIP_H, /* horizontal flip */
  158650. JXFORM_FLIP_V, /* vertical flip */
  158651. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158652. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158653. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158654. JXFORM_ROT_180, /* 180-degree rotation */
  158655. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158656. } JXFORM_CODE;
  158657. typedef struct {
  158658. JXFORM_CODE transform; /* image transform operator */
  158659. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158660. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158661. int num_components; /* # of components in workspace */
  158662. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158663. } jpeg_transform_info;
  158664. #if TRANSFORMS_SUPPORTED
  158665. EXTERN(void) jtransform_request_workspace
  158666. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158667. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158668. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158669. jvirt_barray_ptr *src_coef_arrays,
  158670. jpeg_transform_info *info));
  158671. EXTERN(void) jtransform_execute_transformation
  158672. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158673. jvirt_barray_ptr *src_coef_arrays,
  158674. jpeg_transform_info *info));
  158675. #endif /* TRANSFORMS_SUPPORTED */
  158676. typedef enum {
  158677. JCOPYOPT_NONE, /* copy no optional markers */
  158678. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158679. JCOPYOPT_ALL /* copy all optional markers */
  158680. } JCOPY_OPTION;
  158681. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158682. EXTERN(void) jcopy_markers_setup
  158683. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158684. EXTERN(void) jcopy_markers_execute
  158685. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158686. JCOPY_OPTION option));
  158687. /*** End of inlined file: transupp.h ***/
  158688. /* My own external interface */
  158689. #if TRANSFORMS_SUPPORTED
  158690. LOCAL(void)
  158691. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158692. jvirt_barray_ptr *src_coef_arrays)
  158693. {
  158694. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158695. int ci, k, offset_y;
  158696. JBLOCKARRAY buffer;
  158697. JCOEFPTR ptr1, ptr2;
  158698. JCOEF temp1, temp2;
  158699. jpeg_component_info *compptr;
  158700. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158701. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158702. compptr = dstinfo->comp_info + ci;
  158703. comp_width = MCU_cols * compptr->h_samp_factor;
  158704. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158705. blk_y += compptr->v_samp_factor) {
  158706. buffer = (*srcinfo->mem->access_virt_barray)
  158707. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158708. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158709. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158710. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158711. ptr1 = buffer[offset_y][blk_x];
  158712. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158713. for (k = 0; k < DCTSIZE2; k += 2) {
  158714. temp1 = *ptr1; /* swap even column */
  158715. temp2 = *ptr2;
  158716. *ptr1++ = temp2;
  158717. *ptr2++ = temp1;
  158718. temp1 = *ptr1; /* swap odd column with sign change */
  158719. temp2 = *ptr2;
  158720. *ptr1++ = -temp2;
  158721. *ptr2++ = -temp1;
  158722. }
  158723. }
  158724. }
  158725. }
  158726. }
  158727. }
  158728. LOCAL(void)
  158729. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158730. jvirt_barray_ptr *src_coef_arrays,
  158731. jvirt_barray_ptr *dst_coef_arrays)
  158732. {
  158733. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158734. int ci, i, j, offset_y;
  158735. JBLOCKARRAY src_buffer, dst_buffer;
  158736. JBLOCKROW src_row_ptr, dst_row_ptr;
  158737. JCOEFPTR src_ptr, dst_ptr;
  158738. jpeg_component_info *compptr;
  158739. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158740. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158741. compptr = dstinfo->comp_info + ci;
  158742. comp_height = MCU_rows * compptr->v_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. if (dst_blk_y < comp_height) {
  158749. src_buffer = (*srcinfo->mem->access_virt_barray)
  158750. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158751. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158752. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158753. } else {
  158754. src_buffer = (*srcinfo->mem->access_virt_barray)
  158755. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158756. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158757. }
  158758. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158759. if (dst_blk_y < comp_height) {
  158760. dst_row_ptr = dst_buffer[offset_y];
  158761. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158762. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158763. dst_blk_x++) {
  158764. dst_ptr = dst_row_ptr[dst_blk_x];
  158765. src_ptr = src_row_ptr[dst_blk_x];
  158766. for (i = 0; i < DCTSIZE; i += 2) {
  158767. for (j = 0; j < DCTSIZE; j++)
  158768. *dst_ptr++ = *src_ptr++;
  158769. for (j = 0; j < DCTSIZE; j++)
  158770. *dst_ptr++ = - *src_ptr++;
  158771. }
  158772. }
  158773. } else {
  158774. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158775. compptr->width_in_blocks);
  158776. }
  158777. }
  158778. }
  158779. }
  158780. }
  158781. LOCAL(void)
  158782. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158783. jvirt_barray_ptr *src_coef_arrays,
  158784. jvirt_barray_ptr *dst_coef_arrays)
  158785. {
  158786. JDIMENSION dst_blk_x, dst_blk_y;
  158787. int ci, i, j, offset_x, offset_y;
  158788. JBLOCKARRAY src_buffer, dst_buffer;
  158789. JCOEFPTR src_ptr, dst_ptr;
  158790. jpeg_component_info *compptr;
  158791. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158792. compptr = dstinfo->comp_info + ci;
  158793. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158794. dst_blk_y += compptr->v_samp_factor) {
  158795. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158796. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158797. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158798. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158799. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158800. dst_blk_x += compptr->h_samp_factor) {
  158801. src_buffer = (*srcinfo->mem->access_virt_barray)
  158802. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158803. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158804. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158805. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158806. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158807. for (i = 0; i < DCTSIZE; i++)
  158808. for (j = 0; j < DCTSIZE; j++)
  158809. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158810. }
  158811. }
  158812. }
  158813. }
  158814. }
  158815. }
  158816. LOCAL(void)
  158817. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158818. jvirt_barray_ptr *src_coef_arrays,
  158819. jvirt_barray_ptr *dst_coef_arrays)
  158820. {
  158821. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158822. int ci, i, j, offset_x, offset_y;
  158823. JBLOCKARRAY src_buffer, dst_buffer;
  158824. JCOEFPTR src_ptr, dst_ptr;
  158825. jpeg_component_info *compptr;
  158826. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158827. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158828. compptr = dstinfo->comp_info + ci;
  158829. comp_width = MCU_cols * compptr->h_samp_factor;
  158830. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158831. dst_blk_y += compptr->v_samp_factor) {
  158832. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158833. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158834. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158835. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158836. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158837. dst_blk_x += compptr->h_samp_factor) {
  158838. src_buffer = (*srcinfo->mem->access_virt_barray)
  158839. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158840. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158841. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158842. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158843. if (dst_blk_x < comp_width) {
  158844. dst_ptr = dst_buffer[offset_y]
  158845. [comp_width - dst_blk_x - offset_x - 1];
  158846. for (i = 0; i < DCTSIZE; i++) {
  158847. for (j = 0; j < DCTSIZE; j++)
  158848. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158849. i++;
  158850. for (j = 0; j < DCTSIZE; j++)
  158851. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158852. }
  158853. } else {
  158854. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158855. for (i = 0; i < DCTSIZE; i++)
  158856. for (j = 0; j < DCTSIZE; j++)
  158857. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158858. }
  158859. }
  158860. }
  158861. }
  158862. }
  158863. }
  158864. }
  158865. LOCAL(void)
  158866. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158867. jvirt_barray_ptr *src_coef_arrays,
  158868. jvirt_barray_ptr *dst_coef_arrays)
  158869. {
  158870. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158871. int ci, i, j, offset_x, offset_y;
  158872. JBLOCKARRAY src_buffer, dst_buffer;
  158873. JCOEFPTR src_ptr, dst_ptr;
  158874. jpeg_component_info *compptr;
  158875. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158876. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158877. compptr = dstinfo->comp_info + ci;
  158878. comp_height = MCU_rows * compptr->v_samp_factor;
  158879. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158880. dst_blk_y += compptr->v_samp_factor) {
  158881. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158882. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158883. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158884. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158885. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158886. dst_blk_x += compptr->h_samp_factor) {
  158887. src_buffer = (*srcinfo->mem->access_virt_barray)
  158888. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158889. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158890. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158891. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158892. if (dst_blk_y < comp_height) {
  158893. src_ptr = src_buffer[offset_x]
  158894. [comp_height - dst_blk_y - offset_y - 1];
  158895. for (i = 0; i < DCTSIZE; i++) {
  158896. for (j = 0; j < DCTSIZE; j++) {
  158897. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158898. j++;
  158899. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158900. }
  158901. }
  158902. } else {
  158903. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158904. for (i = 0; i < DCTSIZE; i++)
  158905. for (j = 0; j < DCTSIZE; j++)
  158906. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158907. }
  158908. }
  158909. }
  158910. }
  158911. }
  158912. }
  158913. }
  158914. LOCAL(void)
  158915. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158916. jvirt_barray_ptr *src_coef_arrays,
  158917. jvirt_barray_ptr *dst_coef_arrays)
  158918. {
  158919. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158920. int ci, i, j, offset_y;
  158921. JBLOCKARRAY src_buffer, dst_buffer;
  158922. JBLOCKROW src_row_ptr, dst_row_ptr;
  158923. JCOEFPTR src_ptr, dst_ptr;
  158924. jpeg_component_info *compptr;
  158925. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158926. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158927. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158928. compptr = dstinfo->comp_info + ci;
  158929. comp_width = MCU_cols * compptr->h_samp_factor;
  158930. comp_height = MCU_rows * compptr->v_samp_factor;
  158931. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158932. dst_blk_y += compptr->v_samp_factor) {
  158933. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158934. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158935. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158936. if (dst_blk_y < comp_height) {
  158937. src_buffer = (*srcinfo->mem->access_virt_barray)
  158938. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158939. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158940. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158941. } else {
  158942. src_buffer = (*srcinfo->mem->access_virt_barray)
  158943. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158944. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158945. }
  158946. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158947. if (dst_blk_y < comp_height) {
  158948. dst_row_ptr = dst_buffer[offset_y];
  158949. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158950. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158951. dst_ptr = dst_row_ptr[dst_blk_x];
  158952. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158953. for (i = 0; i < DCTSIZE; i += 2) {
  158954. for (j = 0; j < DCTSIZE; j += 2) {
  158955. *dst_ptr++ = *src_ptr++;
  158956. *dst_ptr++ = - *src_ptr++;
  158957. }
  158958. for (j = 0; j < DCTSIZE; j += 2) {
  158959. *dst_ptr++ = - *src_ptr++;
  158960. *dst_ptr++ = *src_ptr++;
  158961. }
  158962. }
  158963. }
  158964. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158965. dst_ptr = dst_row_ptr[dst_blk_x];
  158966. src_ptr = src_row_ptr[dst_blk_x];
  158967. for (i = 0; i < DCTSIZE; i += 2) {
  158968. for (j = 0; j < DCTSIZE; j++)
  158969. *dst_ptr++ = *src_ptr++;
  158970. for (j = 0; j < DCTSIZE; j++)
  158971. *dst_ptr++ = - *src_ptr++;
  158972. }
  158973. }
  158974. } else {
  158975. dst_row_ptr = dst_buffer[offset_y];
  158976. src_row_ptr = src_buffer[offset_y];
  158977. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158978. dst_ptr = dst_row_ptr[dst_blk_x];
  158979. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158980. for (i = 0; i < DCTSIZE2; i += 2) {
  158981. *dst_ptr++ = *src_ptr++;
  158982. *dst_ptr++ = - *src_ptr++;
  158983. }
  158984. }
  158985. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158986. dst_ptr = dst_row_ptr[dst_blk_x];
  158987. src_ptr = src_row_ptr[dst_blk_x];
  158988. for (i = 0; i < DCTSIZE2; i++)
  158989. *dst_ptr++ = *src_ptr++;
  158990. }
  158991. }
  158992. }
  158993. }
  158994. }
  158995. }
  158996. LOCAL(void)
  158997. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158998. jvirt_barray_ptr *src_coef_arrays,
  158999. jvirt_barray_ptr *dst_coef_arrays)
  159000. {
  159001. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  159002. int ci, i, j, offset_x, offset_y;
  159003. JBLOCKARRAY src_buffer, dst_buffer;
  159004. JCOEFPTR src_ptr, dst_ptr;
  159005. jpeg_component_info *compptr;
  159006. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  159007. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  159008. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159009. compptr = dstinfo->comp_info + ci;
  159010. comp_width = MCU_cols * compptr->h_samp_factor;
  159011. comp_height = MCU_rows * compptr->v_samp_factor;
  159012. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  159013. dst_blk_y += compptr->v_samp_factor) {
  159014. dst_buffer = (*srcinfo->mem->access_virt_barray)
  159015. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  159016. (JDIMENSION) compptr->v_samp_factor, TRUE);
  159017. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  159018. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  159019. dst_blk_x += compptr->h_samp_factor) {
  159020. src_buffer = (*srcinfo->mem->access_virt_barray)
  159021. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  159022. (JDIMENSION) compptr->h_samp_factor, FALSE);
  159023. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  159024. if (dst_blk_y < comp_height) {
  159025. src_ptr = src_buffer[offset_x]
  159026. [comp_height - dst_blk_y - offset_y - 1];
  159027. if (dst_blk_x < comp_width) {
  159028. dst_ptr = dst_buffer[offset_y]
  159029. [comp_width - dst_blk_x - offset_x - 1];
  159030. for (i = 0; i < DCTSIZE; i++) {
  159031. for (j = 0; j < DCTSIZE; j++) {
  159032. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159033. j++;
  159034. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159035. }
  159036. i++;
  159037. for (j = 0; j < DCTSIZE; j++) {
  159038. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159039. j++;
  159040. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159041. }
  159042. }
  159043. } else {
  159044. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159045. for (i = 0; i < DCTSIZE; i++) {
  159046. for (j = 0; j < DCTSIZE; j++) {
  159047. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159048. j++;
  159049. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159050. }
  159051. }
  159052. }
  159053. } else {
  159054. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  159055. if (dst_blk_x < comp_width) {
  159056. dst_ptr = dst_buffer[offset_y]
  159057. [comp_width - dst_blk_x - offset_x - 1];
  159058. for (i = 0; i < DCTSIZE; i++) {
  159059. for (j = 0; j < DCTSIZE; j++)
  159060. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159061. i++;
  159062. for (j = 0; j < DCTSIZE; j++)
  159063. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159064. }
  159065. } else {
  159066. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159067. for (i = 0; i < DCTSIZE; i++)
  159068. for (j = 0; j < DCTSIZE; j++)
  159069. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159070. }
  159071. }
  159072. }
  159073. }
  159074. }
  159075. }
  159076. }
  159077. }
  159078. GLOBAL(void)
  159079. jtransform_request_workspace (j_decompress_ptr srcinfo,
  159080. jpeg_transform_info *info)
  159081. {
  159082. jvirt_barray_ptr *coef_arrays = NULL;
  159083. jpeg_component_info *compptr;
  159084. int ci;
  159085. if (info->force_grayscale &&
  159086. srcinfo->jpeg_color_space == JCS_YCbCr &&
  159087. srcinfo->num_components == 3) {
  159088. info->num_components = 1;
  159089. } else {
  159090. info->num_components = srcinfo->num_components;
  159091. }
  159092. switch (info->transform) {
  159093. case JXFORM_NONE:
  159094. case JXFORM_FLIP_H:
  159095. break;
  159096. case JXFORM_FLIP_V:
  159097. case JXFORM_ROT_180:
  159098. coef_arrays = (jvirt_barray_ptr *)
  159099. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  159100. SIZEOF(jvirt_barray_ptr) * info->num_components);
  159101. for (ci = 0; ci < info->num_components; ci++) {
  159102. compptr = srcinfo->comp_info + ci;
  159103. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  159104. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  159105. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  159106. (long) compptr->h_samp_factor),
  159107. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  159108. (long) compptr->v_samp_factor),
  159109. (JDIMENSION) compptr->v_samp_factor);
  159110. }
  159111. break;
  159112. case JXFORM_TRANSPOSE:
  159113. case JXFORM_TRANSVERSE:
  159114. case JXFORM_ROT_90:
  159115. case JXFORM_ROT_270:
  159116. coef_arrays = (jvirt_barray_ptr *)
  159117. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  159118. SIZEOF(jvirt_barray_ptr) * info->num_components);
  159119. for (ci = 0; ci < info->num_components; ci++) {
  159120. compptr = srcinfo->comp_info + ci;
  159121. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  159122. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  159123. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  159124. (long) compptr->v_samp_factor),
  159125. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  159126. (long) compptr->h_samp_factor),
  159127. (JDIMENSION) compptr->h_samp_factor);
  159128. }
  159129. break;
  159130. }
  159131. info->workspace_coef_arrays = coef_arrays;
  159132. }
  159133. LOCAL(void)
  159134. transpose_critical_parameters (j_compress_ptr dstinfo)
  159135. {
  159136. int tblno, i, j, ci, itemp;
  159137. jpeg_component_info *compptr;
  159138. JQUANT_TBL *qtblptr;
  159139. JDIMENSION dtemp;
  159140. UINT16 qtemp;
  159141. dtemp = dstinfo->image_width;
  159142. dstinfo->image_width = dstinfo->image_height;
  159143. dstinfo->image_height = dtemp;
  159144. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159145. compptr = dstinfo->comp_info + ci;
  159146. itemp = compptr->h_samp_factor;
  159147. compptr->h_samp_factor = compptr->v_samp_factor;
  159148. compptr->v_samp_factor = itemp;
  159149. }
  159150. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  159151. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  159152. if (qtblptr != NULL) {
  159153. for (i = 0; i < DCTSIZE; i++) {
  159154. for (j = 0; j < i; j++) {
  159155. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  159156. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  159157. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  159158. }
  159159. }
  159160. }
  159161. }
  159162. }
  159163. LOCAL(void)
  159164. trim_right_edge (j_compress_ptr dstinfo)
  159165. {
  159166. int ci, max_h_samp_factor;
  159167. JDIMENSION MCU_cols;
  159168. max_h_samp_factor = 1;
  159169. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159170. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  159171. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  159172. }
  159173. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  159174. if (MCU_cols > 0) /* can't trim to 0 pixels */
  159175. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  159176. }
  159177. LOCAL(void)
  159178. trim_bottom_edge (j_compress_ptr dstinfo)
  159179. {
  159180. int ci, max_v_samp_factor;
  159181. JDIMENSION MCU_rows;
  159182. max_v_samp_factor = 1;
  159183. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159184. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  159185. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  159186. }
  159187. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  159188. if (MCU_rows > 0) /* can't trim to 0 pixels */
  159189. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  159190. }
  159191. GLOBAL(jvirt_barray_ptr *)
  159192. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  159193. j_compress_ptr dstinfo,
  159194. jvirt_barray_ptr *src_coef_arrays,
  159195. jpeg_transform_info *info)
  159196. {
  159197. if (info->force_grayscale) {
  159198. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  159199. dstinfo->num_components == 3) ||
  159200. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  159201. dstinfo->num_components == 1)) {
  159202. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  159203. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  159204. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  159205. } else {
  159206. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  159207. }
  159208. }
  159209. switch (info->transform) {
  159210. case JXFORM_NONE:
  159211. break;
  159212. case JXFORM_FLIP_H:
  159213. if (info->trim)
  159214. trim_right_edge(dstinfo);
  159215. break;
  159216. case JXFORM_FLIP_V:
  159217. if (info->trim)
  159218. trim_bottom_edge(dstinfo);
  159219. break;
  159220. case JXFORM_TRANSPOSE:
  159221. transpose_critical_parameters(dstinfo);
  159222. break;
  159223. case JXFORM_TRANSVERSE:
  159224. transpose_critical_parameters(dstinfo);
  159225. if (info->trim) {
  159226. trim_right_edge(dstinfo);
  159227. trim_bottom_edge(dstinfo);
  159228. }
  159229. break;
  159230. case JXFORM_ROT_90:
  159231. transpose_critical_parameters(dstinfo);
  159232. if (info->trim)
  159233. trim_right_edge(dstinfo);
  159234. break;
  159235. case JXFORM_ROT_180:
  159236. if (info->trim) {
  159237. trim_right_edge(dstinfo);
  159238. trim_bottom_edge(dstinfo);
  159239. }
  159240. break;
  159241. case JXFORM_ROT_270:
  159242. transpose_critical_parameters(dstinfo);
  159243. if (info->trim)
  159244. trim_bottom_edge(dstinfo);
  159245. break;
  159246. }
  159247. if (info->workspace_coef_arrays != NULL)
  159248. return info->workspace_coef_arrays;
  159249. return src_coef_arrays;
  159250. }
  159251. GLOBAL(void)
  159252. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  159253. j_compress_ptr dstinfo,
  159254. jvirt_barray_ptr *src_coef_arrays,
  159255. jpeg_transform_info *info)
  159256. {
  159257. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  159258. switch (info->transform) {
  159259. case JXFORM_NONE:
  159260. break;
  159261. case JXFORM_FLIP_H:
  159262. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  159263. break;
  159264. case JXFORM_FLIP_V:
  159265. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159266. break;
  159267. case JXFORM_TRANSPOSE:
  159268. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159269. break;
  159270. case JXFORM_TRANSVERSE:
  159271. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159272. break;
  159273. case JXFORM_ROT_90:
  159274. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159275. break;
  159276. case JXFORM_ROT_180:
  159277. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159278. break;
  159279. case JXFORM_ROT_270:
  159280. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159281. break;
  159282. }
  159283. }
  159284. #endif /* TRANSFORMS_SUPPORTED */
  159285. GLOBAL(void)
  159286. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  159287. {
  159288. #ifdef SAVE_MARKERS_SUPPORTED
  159289. int m;
  159290. if (option != JCOPYOPT_NONE) {
  159291. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  159292. }
  159293. if (option == JCOPYOPT_ALL) {
  159294. for (m = 0; m < 16; m++)
  159295. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  159296. }
  159297. #endif /* SAVE_MARKERS_SUPPORTED */
  159298. }
  159299. GLOBAL(void)
  159300. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159301. JCOPY_OPTION option)
  159302. {
  159303. jpeg_saved_marker_ptr marker;
  159304. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  159305. if (dstinfo->write_JFIF_header &&
  159306. marker->marker == JPEG_APP0 &&
  159307. marker->data_length >= 5 &&
  159308. GETJOCTET(marker->data[0]) == 0x4A &&
  159309. GETJOCTET(marker->data[1]) == 0x46 &&
  159310. GETJOCTET(marker->data[2]) == 0x49 &&
  159311. GETJOCTET(marker->data[3]) == 0x46 &&
  159312. GETJOCTET(marker->data[4]) == 0)
  159313. continue; /* reject duplicate JFIF */
  159314. if (dstinfo->write_Adobe_marker &&
  159315. marker->marker == JPEG_APP0+14 &&
  159316. marker->data_length >= 5 &&
  159317. GETJOCTET(marker->data[0]) == 0x41 &&
  159318. GETJOCTET(marker->data[1]) == 0x64 &&
  159319. GETJOCTET(marker->data[2]) == 0x6F &&
  159320. GETJOCTET(marker->data[3]) == 0x62 &&
  159321. GETJOCTET(marker->data[4]) == 0x65)
  159322. continue; /* reject duplicate Adobe */
  159323. #ifdef NEED_FAR_POINTERS
  159324. {
  159325. unsigned int i;
  159326. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  159327. for (i = 0; i < marker->data_length; i++)
  159328. jpeg_write_m_byte(dstinfo, marker->data[i]);
  159329. }
  159330. #else
  159331. jpeg_write_marker(dstinfo, marker->marker,
  159332. marker->data, marker->data_length);
  159333. #endif
  159334. }
  159335. }
  159336. /*** End of inlined file: transupp.c ***/
  159337. }
  159338. #else
  159339. #define JPEG_INTERNALS
  159340. #undef FAR
  159341. #include <jpeglib.h>
  159342. #endif
  159343. }
  159344. #if JUCE_MSVC
  159345. #pragma warning (pop)
  159346. #endif
  159347. BEGIN_JUCE_NAMESPACE
  159348. using namespace jpeglibNamespace;
  159349. #if ! JUCE_MSVC
  159350. using jpeglibNamespace::boolean;
  159351. #endif
  159352. struct JPEGDecodingFailure {};
  159353. static void fatalErrorHandler (j_common_ptr)
  159354. {
  159355. throw JPEGDecodingFailure();
  159356. }
  159357. static void silentErrorCallback1 (j_common_ptr) {}
  159358. static void silentErrorCallback2 (j_common_ptr, int) {}
  159359. static void silentErrorCallback3 (j_common_ptr, char*) {}
  159360. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  159361. {
  159362. zerostruct (err);
  159363. err.error_exit = fatalErrorHandler;
  159364. err.emit_message = silentErrorCallback2;
  159365. err.output_message = silentErrorCallback1;
  159366. err.format_message = silentErrorCallback3;
  159367. err.reset_error_mgr = silentErrorCallback1;
  159368. }
  159369. static void dummyCallback1 (j_decompress_ptr)
  159370. {
  159371. }
  159372. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  159373. {
  159374. decompStruct->src->next_input_byte += num;
  159375. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  159376. decompStruct->src->bytes_in_buffer -= num;
  159377. }
  159378. static boolean jpegFill (j_decompress_ptr)
  159379. {
  159380. return 0;
  159381. }
  159382. Image* juce_loadJPEGImageFromStream (InputStream& in)
  159383. {
  159384. MemoryBlock mb;
  159385. in.readIntoMemoryBlock (mb);
  159386. Image* image = 0;
  159387. if (mb.getSize() > 16)
  159388. {
  159389. struct jpeg_decompress_struct jpegDecompStruct;
  159390. struct jpeg_error_mgr jerr;
  159391. setupSilentErrorHandler (jerr);
  159392. jpegDecompStruct.err = &jerr;
  159393. jpeg_create_decompress (&jpegDecompStruct);
  159394. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  159395. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  159396. jpegDecompStruct.src->init_source = dummyCallback1;
  159397. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  159398. jpegDecompStruct.src->skip_input_data = jpegSkip;
  159399. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  159400. jpegDecompStruct.src->term_source = dummyCallback1;
  159401. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  159402. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  159403. try
  159404. {
  159405. jpeg_read_header (&jpegDecompStruct, TRUE);
  159406. jpeg_calc_output_dimensions (&jpegDecompStruct);
  159407. const int width = jpegDecompStruct.output_width;
  159408. const int height = jpegDecompStruct.output_height;
  159409. jpegDecompStruct.out_color_space = JCS_RGB;
  159410. JSAMPARRAY buffer
  159411. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  159412. JPOOL_IMAGE,
  159413. width * 3, 1);
  159414. if (jpeg_start_decompress (&jpegDecompStruct))
  159415. {
  159416. image = Image::createNativeImage (Image::RGB, width, height, false);
  159417. const bool hasAlphaChan = image->hasAlphaChannel();
  159418. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  159419. for (int y = 0; y < height; ++y)
  159420. {
  159421. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  159422. const uint8* src = *buffer;
  159423. uint8* dest = destData.getLinePointer (y);
  159424. if (hasAlphaChan)
  159425. {
  159426. for (int i = width; --i >= 0;)
  159427. {
  159428. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159429. ((PixelARGB*) dest)->premultiply();
  159430. dest += destData.pixelStride;
  159431. src += 3;
  159432. }
  159433. }
  159434. else
  159435. {
  159436. for (int i = width; --i >= 0;)
  159437. {
  159438. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159439. dest += destData.pixelStride;
  159440. src += 3;
  159441. }
  159442. }
  159443. }
  159444. jpeg_finish_decompress (&jpegDecompStruct);
  159445. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  159446. }
  159447. jpeg_destroy_decompress (&jpegDecompStruct);
  159448. }
  159449. catch (...)
  159450. {}
  159451. }
  159452. return image;
  159453. }
  159454. static const int jpegBufferSize = 512;
  159455. struct JuceJpegDest : public jpeg_destination_mgr
  159456. {
  159457. OutputStream* output;
  159458. char* buffer;
  159459. };
  159460. static void jpegWriteInit (j_compress_ptr)
  159461. {
  159462. }
  159463. static void jpegWriteTerminate (j_compress_ptr cinfo)
  159464. {
  159465. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159466. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  159467. dest->output->write (dest->buffer, (int) numToWrite);
  159468. }
  159469. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  159470. {
  159471. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159472. const int numToWrite = jpegBufferSize;
  159473. dest->next_output_byte = (JOCTET*) dest->buffer;
  159474. dest->free_in_buffer = jpegBufferSize;
  159475. return dest->output->write (dest->buffer, numToWrite);
  159476. }
  159477. bool juce_writeJPEGImageToStream (const Image& image,
  159478. OutputStream& out,
  159479. float quality)
  159480. {
  159481. if (image.hasAlphaChannel())
  159482. {
  159483. // this method could fill the background in white and still save the image..
  159484. jassertfalse
  159485. return true;
  159486. }
  159487. struct jpeg_compress_struct jpegCompStruct;
  159488. struct jpeg_error_mgr jerr;
  159489. setupSilentErrorHandler (jerr);
  159490. jpegCompStruct.err = &jerr;
  159491. jpeg_create_compress (&jpegCompStruct);
  159492. JuceJpegDest dest;
  159493. jpegCompStruct.dest = &dest;
  159494. dest.output = &out;
  159495. HeapBlock <char> tempBuffer (jpegBufferSize);
  159496. dest.buffer = (char*) tempBuffer;
  159497. dest.next_output_byte = (JOCTET*) dest.buffer;
  159498. dest.free_in_buffer = jpegBufferSize;
  159499. dest.init_destination = jpegWriteInit;
  159500. dest.empty_output_buffer = jpegWriteFlush;
  159501. dest.term_destination = jpegWriteTerminate;
  159502. jpegCompStruct.image_width = image.getWidth();
  159503. jpegCompStruct.image_height = image.getHeight();
  159504. jpegCompStruct.input_components = 3;
  159505. jpegCompStruct.in_color_space = JCS_RGB;
  159506. jpegCompStruct.write_JFIF_header = 1;
  159507. jpegCompStruct.X_density = 72;
  159508. jpegCompStruct.Y_density = 72;
  159509. jpeg_set_defaults (&jpegCompStruct);
  159510. jpegCompStruct.dct_method = JDCT_FLOAT;
  159511. jpegCompStruct.optimize_coding = 1;
  159512. // jpegCompStruct.smoothing_factor = 10;
  159513. if (quality < 0.0f)
  159514. quality = 0.85f;
  159515. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159516. jpeg_start_compress (&jpegCompStruct, TRUE);
  159517. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159518. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159519. JPOOL_IMAGE,
  159520. strideBytes, 1);
  159521. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159522. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159523. {
  159524. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159525. uint8* dst = *buffer;
  159526. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159527. {
  159528. *dst++ = ((const PixelRGB*) src)->getRed();
  159529. *dst++ = ((const PixelRGB*) src)->getGreen();
  159530. *dst++ = ((const PixelRGB*) src)->getBlue();
  159531. src += srcData.pixelStride;
  159532. }
  159533. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159534. }
  159535. jpeg_finish_compress (&jpegCompStruct);
  159536. jpeg_destroy_compress (&jpegCompStruct);
  159537. out.flush();
  159538. return true;
  159539. }
  159540. END_JUCE_NAMESPACE
  159541. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  159542. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  159543. #ifdef _MSC_VER
  159544. #pragma warning (push)
  159545. #pragma warning (disable: 4390 4611)
  159546. #endif
  159547. namespace zlibNamespace
  159548. {
  159549. #if JUCE_INCLUDE_ZLIB_CODE
  159550. #undef OS_CODE
  159551. #undef fdopen
  159552. #undef OS_CODE
  159553. #else
  159554. #include <zlib.h>
  159555. #endif
  159556. }
  159557. namespace pnglibNamespace
  159558. {
  159559. using namespace zlibNamespace;
  159560. #if JUCE_INCLUDE_PNGLIB_CODE
  159561. #if _MSC_VER != 1310
  159562. using ::calloc; // (causes conflict in VS.NET 2003)
  159563. using ::malloc;
  159564. using ::free;
  159565. #endif
  159566. extern "C"
  159567. {
  159568. using ::abs;
  159569. #define PNG_INTERNAL
  159570. #define NO_DUMMY_DECL
  159571. #define PNG_SETJMP_NOT_SUPPORTED
  159572. /*** Start of inlined file: png.h ***/
  159573. #ifndef PNG_H
  159574. #define PNG_H
  159575. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159576. #define PNG_HEADER_VERSION_STRING \
  159577. " libpng version 1.2.21 - October 4, 2007\n"
  159578. #define PNG_LIBPNG_VER_SONUM 0
  159579. #define PNG_LIBPNG_VER_DLLNUM 13
  159580. #define PNG_LIBPNG_VER_MAJOR 1
  159581. #define PNG_LIBPNG_VER_MINOR 2
  159582. #define PNG_LIBPNG_VER_RELEASE 21
  159583. #define PNG_LIBPNG_VER_BUILD 0
  159584. #define PNG_LIBPNG_BUILD_ALPHA 1
  159585. #define PNG_LIBPNG_BUILD_BETA 2
  159586. #define PNG_LIBPNG_BUILD_RC 3
  159587. #define PNG_LIBPNG_BUILD_STABLE 4
  159588. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159589. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159590. PNG_LIBPNG_BUILD_STABLE only */
  159591. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159592. PNG_LIBPNG_BUILD_SPECIAL */
  159593. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159594. PNG_LIBPNG_BUILD_PRIVATE */
  159595. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159596. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159597. #ifndef PNG_VERSION_INFO_ONLY
  159598. #endif
  159599. /*** Start of inlined file: pngconf.h ***/
  159600. #ifndef PNGCONF_H
  159601. #define PNGCONF_H
  159602. #define PNG_1_2_X
  159603. // These are some Juce config settings that should remove any unnecessary code bloat..
  159604. #define PNG_NO_STDIO 1
  159605. #define PNG_DEBUG 0
  159606. #define PNG_NO_WARNINGS 1
  159607. #define PNG_NO_ERROR_TEXT 1
  159608. #define PNG_NO_ERROR_NUMBERS 1
  159609. #define PNG_NO_USER_MEM 1
  159610. #define PNG_NO_READ_iCCP 1
  159611. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159612. #define PNG_NO_READ_USER_CHUNKS 1
  159613. #define PNG_NO_READ_iTXt 1
  159614. #define PNG_NO_READ_sCAL 1
  159615. #define PNG_NO_READ_sPLT 1
  159616. #define png_error(a, b) png_err(a)
  159617. #define png_warning(a, b)
  159618. #define png_chunk_error(a, b) png_err(a)
  159619. #define png_chunk_warning(a, b)
  159620. #ifdef PNG_USER_CONFIG
  159621. # ifndef PNG_USER_PRIVATEBUILD
  159622. # define PNG_USER_PRIVATEBUILD
  159623. # endif
  159624. #include "pngusr.h"
  159625. #endif
  159626. #ifdef PNG_CONFIGURE_LIBPNG
  159627. #ifdef HAVE_CONFIG_H
  159628. #include "config.h"
  159629. #endif
  159630. #endif
  159631. #ifdef __STDC__
  159632. #ifdef SPECIALBUILD
  159633. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159634. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159635. #endif
  159636. #ifdef PRIVATEBUILD
  159637. # pragma message("PRIVATEBUILD is deprecated.\
  159638. Use PNG_USER_PRIVATEBUILD instead.")
  159639. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159640. #endif
  159641. #endif /* __STDC__ */
  159642. #ifndef PNG_VERSION_INFO_ONLY
  159643. # define PNG_WARN_UNINITIALIZED_ROW 1
  159644. #ifndef PNG_ZBUF_SIZE
  159645. # define PNG_ZBUF_SIZE 8192
  159646. #endif
  159647. #ifndef PNG_NO_READ_SUPPORTED
  159648. # define PNG_READ_SUPPORTED
  159649. #endif
  159650. #ifndef PNG_NO_WRITE_SUPPORTED
  159651. # define PNG_WRITE_SUPPORTED
  159652. #endif
  159653. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159654. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159655. # define PNG_MNG_FEATURES_SUPPORTED
  159656. # endif
  159657. #endif
  159658. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159659. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159660. # define PNG_FLOATING_POINT_SUPPORTED
  159661. # endif
  159662. #endif
  159663. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159664. # define PNG_MAX_MALLOC_64K
  159665. #endif
  159666. #if defined(__CYGWIN__)
  159667. # if defined(ALL_STATIC)
  159668. # if defined(PNG_BUILD_DLL)
  159669. # undef PNG_BUILD_DLL
  159670. # endif
  159671. # if defined(PNG_USE_DLL)
  159672. # undef PNG_USE_DLL
  159673. # endif
  159674. # if defined(PNG_DLL)
  159675. # undef PNG_DLL
  159676. # endif
  159677. # if !defined(PNG_STATIC)
  159678. # define PNG_STATIC
  159679. # endif
  159680. # else
  159681. # if defined (PNG_BUILD_DLL)
  159682. # if defined(PNG_STATIC)
  159683. # undef PNG_STATIC
  159684. # endif
  159685. # if defined(PNG_USE_DLL)
  159686. # undef PNG_USE_DLL
  159687. # endif
  159688. # if !defined(PNG_DLL)
  159689. # define PNG_DLL
  159690. # endif
  159691. # else
  159692. # if defined(PNG_STATIC)
  159693. # if defined(PNG_USE_DLL)
  159694. # undef PNG_USE_DLL
  159695. # endif
  159696. # if defined(PNG_DLL)
  159697. # undef PNG_DLL
  159698. # endif
  159699. # else
  159700. # if !defined(PNG_USE_DLL)
  159701. # define PNG_USE_DLL
  159702. # endif
  159703. # if !defined(PNG_DLL)
  159704. # define PNG_DLL
  159705. # endif
  159706. # endif
  159707. # endif
  159708. # endif
  159709. #endif
  159710. #if defined(_WIN32_WCE)
  159711. # include <windows.h>
  159712. # define PNG_NO_CONSOLE_IO
  159713. # ifdef PNG_DEBUG
  159714. # undef PNG_DEBUG
  159715. # endif
  159716. #endif
  159717. #ifdef PNG_BUILD_DLL
  159718. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159719. # ifndef PNG_NO_CONSOLE_IO
  159720. # define PNG_NO_CONSOLE_IO
  159721. # endif
  159722. # endif
  159723. #endif
  159724. # ifdef PNG_NO_STDIO
  159725. # ifndef PNG_NO_CONSOLE_IO
  159726. # define PNG_NO_CONSOLE_IO
  159727. # endif
  159728. # ifdef PNG_DEBUG
  159729. # if (PNG_DEBUG > 0)
  159730. # include <stdio.h>
  159731. # endif
  159732. # endif
  159733. # else
  159734. # if !defined(_WIN32_WCE)
  159735. # include <stdio.h>
  159736. # endif
  159737. # endif
  159738. #ifndef PNGARG
  159739. #ifdef OF /* zlib prototype munger */
  159740. # define PNGARG(arglist) OF(arglist)
  159741. #else
  159742. #ifdef _NO_PROTO
  159743. # define PNGARG(arglist) ()
  159744. # ifndef PNG_TYPECAST_NULL
  159745. # define PNG_TYPECAST_NULL
  159746. # endif
  159747. #else
  159748. # define PNGARG(arglist) arglist
  159749. #endif /* _NO_PROTO */
  159750. #endif /* OF */
  159751. #endif /* PNGARG */
  159752. #ifndef MACOS
  159753. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159754. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159755. # define MACOS
  159756. # endif
  159757. #endif
  159758. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159759. # include <sys/types.h>
  159760. #endif
  159761. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159762. # define PNG_SETJMP_SUPPORTED
  159763. #endif
  159764. #ifdef PNG_SETJMP_SUPPORTED
  159765. # ifdef __linux__
  159766. # ifdef _BSD_SOURCE
  159767. # define PNG_SAVE_BSD_SOURCE
  159768. # undef _BSD_SOURCE
  159769. # endif
  159770. # ifdef _SETJMP_H
  159771. __png.h__ already includes setjmp.h;
  159772. __dont__ include it again.;
  159773. # endif
  159774. # endif /* __linux__ */
  159775. # include <setjmp.h>
  159776. # ifdef __linux__
  159777. # ifdef PNG_SAVE_BSD_SOURCE
  159778. # define _BSD_SOURCE
  159779. # undef PNG_SAVE_BSD_SOURCE
  159780. # endif
  159781. # endif /* __linux__ */
  159782. #endif /* PNG_SETJMP_SUPPORTED */
  159783. #ifdef BSD
  159784. #if ! JUCE_MAC
  159785. # include <strings.h>
  159786. #endif
  159787. #else
  159788. # include <string.h>
  159789. #endif
  159790. #ifdef PNG_INTERNAL
  159791. #include <stdlib.h>
  159792. #define PNG_EXTERN
  159793. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159794. # if defined(MACOS)
  159795. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159796. # include <fp.h>
  159797. # endif
  159798. # else
  159799. # include <math.h>
  159800. # endif
  159801. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159802. # include <m68881.h>
  159803. # endif
  159804. #endif
  159805. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159806. # define PNG_ALWAYS_EXTERN
  159807. #endif
  159808. #if defined(__TURBOC__) && defined(__MSDOS__)
  159809. # include <mem.h>
  159810. # include <alloc.h>
  159811. #endif
  159812. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159813. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159814. # include <malloc.h>
  159815. #endif
  159816. #ifndef PNG_DITHER_RED_BITS
  159817. # define PNG_DITHER_RED_BITS 5
  159818. #endif
  159819. #ifndef PNG_DITHER_GREEN_BITS
  159820. # define PNG_DITHER_GREEN_BITS 5
  159821. #endif
  159822. #ifndef PNG_DITHER_BLUE_BITS
  159823. # define PNG_DITHER_BLUE_BITS 5
  159824. #endif
  159825. #ifndef PNG_MAX_GAMMA_8
  159826. # define PNG_MAX_GAMMA_8 11
  159827. #endif
  159828. #ifndef PNG_GAMMA_THRESHOLD
  159829. # define PNG_GAMMA_THRESHOLD 0.05
  159830. #endif
  159831. #endif /* PNG_INTERNAL */
  159832. #ifndef PNG_NO_CONST
  159833. # define PNG_CONST const
  159834. #else
  159835. # define PNG_CONST
  159836. #endif
  159837. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159838. # ifndef PNG_NO_iTXt_SUPPORTED
  159839. # define PNG_NO_iTXt_SUPPORTED
  159840. # endif
  159841. # ifndef PNG_NO_READ_iTXt
  159842. # define PNG_NO_READ_iTXt
  159843. # endif
  159844. # ifndef PNG_NO_WRITE_iTXt
  159845. # define PNG_NO_WRITE_iTXt
  159846. # endif
  159847. #endif
  159848. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159849. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159850. # define PNG_READ_iTXt
  159851. # endif
  159852. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159853. # define PNG_WRITE_iTXt
  159854. # endif
  159855. #endif
  159856. #ifdef PNG_LEGACY_SUPPORTED
  159857. # define PNG_NO_FREE_ME
  159858. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159859. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159860. # define PNG_NO_READ_USER_CHUNKS
  159861. # define PNG_NO_READ_iCCP
  159862. # define PNG_NO_WRITE_iCCP
  159863. # define PNG_NO_READ_iTXt
  159864. # define PNG_NO_WRITE_iTXt
  159865. # define PNG_NO_READ_sCAL
  159866. # define PNG_NO_WRITE_sCAL
  159867. # define PNG_NO_READ_sPLT
  159868. # define PNG_NO_WRITE_sPLT
  159869. # define PNG_NO_INFO_IMAGE
  159870. # define PNG_NO_READ_RGB_TO_GRAY
  159871. # define PNG_NO_READ_USER_TRANSFORM
  159872. # define PNG_NO_WRITE_USER_TRANSFORM
  159873. # define PNG_NO_USER_MEM
  159874. # define PNG_NO_READ_EMPTY_PLTE
  159875. # define PNG_NO_MNG_FEATURES
  159876. # define PNG_NO_FIXED_POINT_SUPPORTED
  159877. #endif
  159878. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159879. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159880. # define PNG_FIXED_POINT_SUPPORTED
  159881. #endif
  159882. #ifndef PNG_NO_FREE_ME
  159883. # define PNG_FREE_ME_SUPPORTED
  159884. #endif
  159885. #if defined(PNG_READ_SUPPORTED)
  159886. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159887. !defined(PNG_NO_READ_TRANSFORMS)
  159888. # define PNG_READ_TRANSFORMS_SUPPORTED
  159889. #endif
  159890. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159891. # ifndef PNG_NO_READ_EXPAND
  159892. # define PNG_READ_EXPAND_SUPPORTED
  159893. # endif
  159894. # ifndef PNG_NO_READ_SHIFT
  159895. # define PNG_READ_SHIFT_SUPPORTED
  159896. # endif
  159897. # ifndef PNG_NO_READ_PACK
  159898. # define PNG_READ_PACK_SUPPORTED
  159899. # endif
  159900. # ifndef PNG_NO_READ_BGR
  159901. # define PNG_READ_BGR_SUPPORTED
  159902. # endif
  159903. # ifndef PNG_NO_READ_SWAP
  159904. # define PNG_READ_SWAP_SUPPORTED
  159905. # endif
  159906. # ifndef PNG_NO_READ_PACKSWAP
  159907. # define PNG_READ_PACKSWAP_SUPPORTED
  159908. # endif
  159909. # ifndef PNG_NO_READ_INVERT
  159910. # define PNG_READ_INVERT_SUPPORTED
  159911. # endif
  159912. # ifndef PNG_NO_READ_DITHER
  159913. # define PNG_READ_DITHER_SUPPORTED
  159914. # endif
  159915. # ifndef PNG_NO_READ_BACKGROUND
  159916. # define PNG_READ_BACKGROUND_SUPPORTED
  159917. # endif
  159918. # ifndef PNG_NO_READ_16_TO_8
  159919. # define PNG_READ_16_TO_8_SUPPORTED
  159920. # endif
  159921. # ifndef PNG_NO_READ_FILLER
  159922. # define PNG_READ_FILLER_SUPPORTED
  159923. # endif
  159924. # ifndef PNG_NO_READ_GAMMA
  159925. # define PNG_READ_GAMMA_SUPPORTED
  159926. # endif
  159927. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159928. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159929. # endif
  159930. # ifndef PNG_NO_READ_SWAP_ALPHA
  159931. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159932. # endif
  159933. # ifndef PNG_NO_READ_INVERT_ALPHA
  159934. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159935. # endif
  159936. # ifndef PNG_NO_READ_STRIP_ALPHA
  159937. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159938. # endif
  159939. # ifndef PNG_NO_READ_USER_TRANSFORM
  159940. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159941. # endif
  159942. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159943. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159944. # endif
  159945. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159946. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159947. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159948. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159949. #endif /* about interlacing capability! You'll */
  159950. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159951. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159952. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159953. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159954. # endif
  159955. #endif
  159956. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159957. #ifndef PNG_NO_READ_EMPTY_PLTE
  159958. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159959. #endif
  159960. #endif
  159961. #endif /* PNG_READ_SUPPORTED */
  159962. #if defined(PNG_WRITE_SUPPORTED)
  159963. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159964. !defined(PNG_NO_WRITE_TRANSFORMS)
  159965. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159966. #endif
  159967. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159968. # ifndef PNG_NO_WRITE_SHIFT
  159969. # define PNG_WRITE_SHIFT_SUPPORTED
  159970. # endif
  159971. # ifndef PNG_NO_WRITE_PACK
  159972. # define PNG_WRITE_PACK_SUPPORTED
  159973. # endif
  159974. # ifndef PNG_NO_WRITE_BGR
  159975. # define PNG_WRITE_BGR_SUPPORTED
  159976. # endif
  159977. # ifndef PNG_NO_WRITE_SWAP
  159978. # define PNG_WRITE_SWAP_SUPPORTED
  159979. # endif
  159980. # ifndef PNG_NO_WRITE_PACKSWAP
  159981. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159982. # endif
  159983. # ifndef PNG_NO_WRITE_INVERT
  159984. # define PNG_WRITE_INVERT_SUPPORTED
  159985. # endif
  159986. # ifndef PNG_NO_WRITE_FILLER
  159987. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159988. # endif
  159989. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159990. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159991. # endif
  159992. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159993. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159994. # endif
  159995. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159996. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159997. # endif
  159998. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159999. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  160000. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  160001. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  160002. encoders, but can cause trouble
  160003. if left undefined */
  160004. #endif
  160005. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  160006. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  160007. defined(PNG_FLOATING_POINT_SUPPORTED)
  160008. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  160009. #endif
  160010. #ifndef PNG_NO_WRITE_FLUSH
  160011. # define PNG_WRITE_FLUSH_SUPPORTED
  160012. #endif
  160013. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160014. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  160015. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  160016. #endif
  160017. #endif
  160018. #endif /* PNG_WRITE_SUPPORTED */
  160019. #ifndef PNG_1_0_X
  160020. # ifndef PNG_NO_ERROR_NUMBERS
  160021. # define PNG_ERROR_NUMBERS_SUPPORTED
  160022. # endif
  160023. #endif /* PNG_1_0_X */
  160024. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160025. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160026. # ifndef PNG_NO_USER_TRANSFORM_PTR
  160027. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  160028. # endif
  160029. #endif
  160030. #ifndef PNG_NO_STDIO
  160031. # define PNG_TIME_RFC1123_SUPPORTED
  160032. #endif
  160033. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  160034. # define PNG_EASY_ACCESS_SUPPORTED
  160035. #endif
  160036. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  160037. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  160038. # define PNG_OPTIMIZED_CODE_SUPPORTED
  160039. # endif
  160040. #endif
  160041. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  160042. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  160043. # define PNG_ASSEMBLER_CODE_SUPPORTED
  160044. # endif
  160045. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  160046. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160047. # define PNG_NO_MMX_CODE
  160048. # endif
  160049. # endif
  160050. # if defined(__APPLE__)
  160051. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160052. # define PNG_NO_MMX_CODE
  160053. # endif
  160054. # endif
  160055. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  160056. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160057. # define PNG_NO_MMX_CODE
  160058. # endif
  160059. # endif
  160060. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160061. # define PNG_MMX_CODE_SUPPORTED
  160062. # endif
  160063. #endif
  160064. #if !defined(PNG_1_0_X)
  160065. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  160066. # define PNG_USER_MEM_SUPPORTED
  160067. #endif
  160068. #endif /* PNG_1_0_X */
  160069. #if !defined(PNG_1_0_X)
  160070. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  160071. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  160072. # define PNG_SET_USER_LIMITS_SUPPORTED
  160073. #endif
  160074. #endif
  160075. #endif /* PNG_1_0_X */
  160076. #ifndef PNG_USER_WIDTH_MAX
  160077. # define PNG_USER_WIDTH_MAX 1000000L
  160078. #endif
  160079. #ifndef PNG_USER_HEIGHT_MAX
  160080. # define PNG_USER_HEIGHT_MAX 1000000L
  160081. #endif
  160082. #if defined(PNG_READ_SUPPORTED) && \
  160083. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  160084. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  160085. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  160086. #endif
  160087. #if defined(PNG_WRITE_SUPPORTED) && \
  160088. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  160089. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  160090. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  160091. #endif
  160092. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  160093. #ifdef PNG_NO_READ_TEXT
  160094. # define PNG_NO_READ_iTXt
  160095. # define PNG_NO_READ_tEXt
  160096. # define PNG_NO_READ_zTXt
  160097. #endif
  160098. #ifndef PNG_NO_READ_bKGD
  160099. # define PNG_READ_bKGD_SUPPORTED
  160100. # define PNG_bKGD_SUPPORTED
  160101. #endif
  160102. #ifndef PNG_NO_READ_cHRM
  160103. # define PNG_READ_cHRM_SUPPORTED
  160104. # define PNG_cHRM_SUPPORTED
  160105. #endif
  160106. #ifndef PNG_NO_READ_gAMA
  160107. # define PNG_READ_gAMA_SUPPORTED
  160108. # define PNG_gAMA_SUPPORTED
  160109. #endif
  160110. #ifndef PNG_NO_READ_hIST
  160111. # define PNG_READ_hIST_SUPPORTED
  160112. # define PNG_hIST_SUPPORTED
  160113. #endif
  160114. #ifndef PNG_NO_READ_iCCP
  160115. # define PNG_READ_iCCP_SUPPORTED
  160116. # define PNG_iCCP_SUPPORTED
  160117. #endif
  160118. #ifndef PNG_NO_READ_iTXt
  160119. # ifndef PNG_READ_iTXt_SUPPORTED
  160120. # define PNG_READ_iTXt_SUPPORTED
  160121. # endif
  160122. # ifndef PNG_iTXt_SUPPORTED
  160123. # define PNG_iTXt_SUPPORTED
  160124. # endif
  160125. #endif
  160126. #ifndef PNG_NO_READ_oFFs
  160127. # define PNG_READ_oFFs_SUPPORTED
  160128. # define PNG_oFFs_SUPPORTED
  160129. #endif
  160130. #ifndef PNG_NO_READ_pCAL
  160131. # define PNG_READ_pCAL_SUPPORTED
  160132. # define PNG_pCAL_SUPPORTED
  160133. #endif
  160134. #ifndef PNG_NO_READ_sCAL
  160135. # define PNG_READ_sCAL_SUPPORTED
  160136. # define PNG_sCAL_SUPPORTED
  160137. #endif
  160138. #ifndef PNG_NO_READ_pHYs
  160139. # define PNG_READ_pHYs_SUPPORTED
  160140. # define PNG_pHYs_SUPPORTED
  160141. #endif
  160142. #ifndef PNG_NO_READ_sBIT
  160143. # define PNG_READ_sBIT_SUPPORTED
  160144. # define PNG_sBIT_SUPPORTED
  160145. #endif
  160146. #ifndef PNG_NO_READ_sPLT
  160147. # define PNG_READ_sPLT_SUPPORTED
  160148. # define PNG_sPLT_SUPPORTED
  160149. #endif
  160150. #ifndef PNG_NO_READ_sRGB
  160151. # define PNG_READ_sRGB_SUPPORTED
  160152. # define PNG_sRGB_SUPPORTED
  160153. #endif
  160154. #ifndef PNG_NO_READ_tEXt
  160155. # define PNG_READ_tEXt_SUPPORTED
  160156. # define PNG_tEXt_SUPPORTED
  160157. #endif
  160158. #ifndef PNG_NO_READ_tIME
  160159. # define PNG_READ_tIME_SUPPORTED
  160160. # define PNG_tIME_SUPPORTED
  160161. #endif
  160162. #ifndef PNG_NO_READ_tRNS
  160163. # define PNG_READ_tRNS_SUPPORTED
  160164. # define PNG_tRNS_SUPPORTED
  160165. #endif
  160166. #ifndef PNG_NO_READ_zTXt
  160167. # define PNG_READ_zTXt_SUPPORTED
  160168. # define PNG_zTXt_SUPPORTED
  160169. #endif
  160170. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  160171. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  160172. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160173. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160174. # endif
  160175. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160176. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160177. # endif
  160178. #endif
  160179. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  160180. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  160181. # define PNG_READ_USER_CHUNKS_SUPPORTED
  160182. # define PNG_USER_CHUNKS_SUPPORTED
  160183. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  160184. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  160185. # endif
  160186. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  160187. # undef PNG_NO_HANDLE_AS_UNKNOWN
  160188. # endif
  160189. #endif
  160190. #ifndef PNG_NO_READ_OPT_PLTE
  160191. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  160192. #endif /* optional PLTE chunk in RGB and RGBA images */
  160193. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  160194. defined(PNG_READ_zTXt_SUPPORTED)
  160195. # define PNG_READ_TEXT_SUPPORTED
  160196. # define PNG_TEXT_SUPPORTED
  160197. #endif
  160198. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  160199. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  160200. #ifdef PNG_NO_WRITE_TEXT
  160201. # define PNG_NO_WRITE_iTXt
  160202. # define PNG_NO_WRITE_tEXt
  160203. # define PNG_NO_WRITE_zTXt
  160204. #endif
  160205. #ifndef PNG_NO_WRITE_bKGD
  160206. # define PNG_WRITE_bKGD_SUPPORTED
  160207. # ifndef PNG_bKGD_SUPPORTED
  160208. # define PNG_bKGD_SUPPORTED
  160209. # endif
  160210. #endif
  160211. #ifndef PNG_NO_WRITE_cHRM
  160212. # define PNG_WRITE_cHRM_SUPPORTED
  160213. # ifndef PNG_cHRM_SUPPORTED
  160214. # define PNG_cHRM_SUPPORTED
  160215. # endif
  160216. #endif
  160217. #ifndef PNG_NO_WRITE_gAMA
  160218. # define PNG_WRITE_gAMA_SUPPORTED
  160219. # ifndef PNG_gAMA_SUPPORTED
  160220. # define PNG_gAMA_SUPPORTED
  160221. # endif
  160222. #endif
  160223. #ifndef PNG_NO_WRITE_hIST
  160224. # define PNG_WRITE_hIST_SUPPORTED
  160225. # ifndef PNG_hIST_SUPPORTED
  160226. # define PNG_hIST_SUPPORTED
  160227. # endif
  160228. #endif
  160229. #ifndef PNG_NO_WRITE_iCCP
  160230. # define PNG_WRITE_iCCP_SUPPORTED
  160231. # ifndef PNG_iCCP_SUPPORTED
  160232. # define PNG_iCCP_SUPPORTED
  160233. # endif
  160234. #endif
  160235. #ifndef PNG_NO_WRITE_iTXt
  160236. # ifndef PNG_WRITE_iTXt_SUPPORTED
  160237. # define PNG_WRITE_iTXt_SUPPORTED
  160238. # endif
  160239. # ifndef PNG_iTXt_SUPPORTED
  160240. # define PNG_iTXt_SUPPORTED
  160241. # endif
  160242. #endif
  160243. #ifndef PNG_NO_WRITE_oFFs
  160244. # define PNG_WRITE_oFFs_SUPPORTED
  160245. # ifndef PNG_oFFs_SUPPORTED
  160246. # define PNG_oFFs_SUPPORTED
  160247. # endif
  160248. #endif
  160249. #ifndef PNG_NO_WRITE_pCAL
  160250. # define PNG_WRITE_pCAL_SUPPORTED
  160251. # ifndef PNG_pCAL_SUPPORTED
  160252. # define PNG_pCAL_SUPPORTED
  160253. # endif
  160254. #endif
  160255. #ifndef PNG_NO_WRITE_sCAL
  160256. # define PNG_WRITE_sCAL_SUPPORTED
  160257. # ifndef PNG_sCAL_SUPPORTED
  160258. # define PNG_sCAL_SUPPORTED
  160259. # endif
  160260. #endif
  160261. #ifndef PNG_NO_WRITE_pHYs
  160262. # define PNG_WRITE_pHYs_SUPPORTED
  160263. # ifndef PNG_pHYs_SUPPORTED
  160264. # define PNG_pHYs_SUPPORTED
  160265. # endif
  160266. #endif
  160267. #ifndef PNG_NO_WRITE_sBIT
  160268. # define PNG_WRITE_sBIT_SUPPORTED
  160269. # ifndef PNG_sBIT_SUPPORTED
  160270. # define PNG_sBIT_SUPPORTED
  160271. # endif
  160272. #endif
  160273. #ifndef PNG_NO_WRITE_sPLT
  160274. # define PNG_WRITE_sPLT_SUPPORTED
  160275. # ifndef PNG_sPLT_SUPPORTED
  160276. # define PNG_sPLT_SUPPORTED
  160277. # endif
  160278. #endif
  160279. #ifndef PNG_NO_WRITE_sRGB
  160280. # define PNG_WRITE_sRGB_SUPPORTED
  160281. # ifndef PNG_sRGB_SUPPORTED
  160282. # define PNG_sRGB_SUPPORTED
  160283. # endif
  160284. #endif
  160285. #ifndef PNG_NO_WRITE_tEXt
  160286. # define PNG_WRITE_tEXt_SUPPORTED
  160287. # ifndef PNG_tEXt_SUPPORTED
  160288. # define PNG_tEXt_SUPPORTED
  160289. # endif
  160290. #endif
  160291. #ifndef PNG_NO_WRITE_tIME
  160292. # define PNG_WRITE_tIME_SUPPORTED
  160293. # ifndef PNG_tIME_SUPPORTED
  160294. # define PNG_tIME_SUPPORTED
  160295. # endif
  160296. #endif
  160297. #ifndef PNG_NO_WRITE_tRNS
  160298. # define PNG_WRITE_tRNS_SUPPORTED
  160299. # ifndef PNG_tRNS_SUPPORTED
  160300. # define PNG_tRNS_SUPPORTED
  160301. # endif
  160302. #endif
  160303. #ifndef PNG_NO_WRITE_zTXt
  160304. # define PNG_WRITE_zTXt_SUPPORTED
  160305. # ifndef PNG_zTXt_SUPPORTED
  160306. # define PNG_zTXt_SUPPORTED
  160307. # endif
  160308. #endif
  160309. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  160310. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  160311. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160312. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160313. # endif
  160314. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160315. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160316. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160317. # endif
  160318. # endif
  160319. #endif
  160320. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  160321. defined(PNG_WRITE_zTXt_SUPPORTED)
  160322. # define PNG_WRITE_TEXT_SUPPORTED
  160323. # ifndef PNG_TEXT_SUPPORTED
  160324. # define PNG_TEXT_SUPPORTED
  160325. # endif
  160326. #endif
  160327. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  160328. #ifndef PNG_NO_INFO_IMAGE
  160329. # define PNG_INFO_IMAGE_SUPPORTED
  160330. #endif
  160331. #if defined(PNG_tIME_SUPPORTED)
  160332. # if !defined(_WIN32_WCE)
  160333. # include <time.h>
  160334. # endif
  160335. #endif
  160336. typedef unsigned long png_uint_32;
  160337. typedef long png_int_32;
  160338. typedef unsigned short png_uint_16;
  160339. typedef short png_int_16;
  160340. typedef unsigned char png_byte;
  160341. #ifdef PNG_SIZE_T
  160342. typedef PNG_SIZE_T png_size_t;
  160343. # define png_sizeof(x) png_convert_size(sizeof (x))
  160344. #else
  160345. typedef size_t png_size_t;
  160346. # define png_sizeof(x) sizeof (x)
  160347. #endif
  160348. #ifdef __BORLANDC__
  160349. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  160350. # define LDATA 1
  160351. # else
  160352. # define LDATA 0
  160353. # endif
  160354. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  160355. # define PNG_MAX_MALLOC_64K
  160356. # if (LDATA != 1)
  160357. # ifndef FAR
  160358. # define FAR __far
  160359. # endif
  160360. # define USE_FAR_KEYWORD
  160361. # endif /* LDATA != 1 */
  160362. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  160363. #endif /* __BORLANDC__ */
  160364. #if defined(FAR)
  160365. # if defined(M_I86MM)
  160366. # define USE_FAR_KEYWORD
  160367. # define FARDATA FAR
  160368. # include <dos.h>
  160369. # endif
  160370. #endif
  160371. #ifndef FAR
  160372. # define FAR
  160373. #endif
  160374. #ifndef FARDATA
  160375. # define FARDATA
  160376. #endif
  160377. typedef png_int_32 png_fixed_point;
  160378. typedef void FAR * png_voidp;
  160379. typedef png_byte FAR * png_bytep;
  160380. typedef png_uint_32 FAR * png_uint_32p;
  160381. typedef png_int_32 FAR * png_int_32p;
  160382. typedef png_uint_16 FAR * png_uint_16p;
  160383. typedef png_int_16 FAR * png_int_16p;
  160384. typedef PNG_CONST char FAR * png_const_charp;
  160385. typedef char FAR * png_charp;
  160386. typedef png_fixed_point FAR * png_fixed_point_p;
  160387. #ifndef PNG_NO_STDIO
  160388. #if defined(_WIN32_WCE)
  160389. typedef HANDLE png_FILE_p;
  160390. #else
  160391. typedef FILE * png_FILE_p;
  160392. #endif
  160393. #endif
  160394. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160395. typedef double FAR * png_doublep;
  160396. #endif
  160397. typedef png_byte FAR * FAR * png_bytepp;
  160398. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  160399. typedef png_int_32 FAR * FAR * png_int_32pp;
  160400. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  160401. typedef png_int_16 FAR * FAR * png_int_16pp;
  160402. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  160403. typedef char FAR * FAR * png_charpp;
  160404. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  160405. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160406. typedef double FAR * FAR * png_doublepp;
  160407. #endif
  160408. typedef char FAR * FAR * FAR * png_charppp;
  160409. #if 0
  160410. typedef charf * png_zcharp;
  160411. typedef charf * FAR * png_zcharpp;
  160412. typedef z_stream FAR * png_zstreamp;
  160413. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  160414. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  160415. # define PNG_DLL
  160416. #endif
  160417. #if defined(__CYGWIN__)
  160418. # if !defined(PNG_STATIC)
  160419. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160420. # undef PNG_USE_GLOBAL_ARRAYS
  160421. # endif
  160422. # if !defined(PNG_USE_LOCAL_ARRAYS)
  160423. # define PNG_USE_LOCAL_ARRAYS
  160424. # endif
  160425. # else
  160426. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  160427. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160428. # undef PNG_USE_GLOBAL_ARRAYS
  160429. # endif
  160430. # endif
  160431. # endif
  160432. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160433. # define PNG_USE_LOCAL_ARRAYS
  160434. # endif
  160435. #endif
  160436. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160437. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  160438. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  160439. # define PNG_USE_LOCAL_ARRAYS
  160440. # else
  160441. # define PNG_USE_GLOBAL_ARRAYS
  160442. # endif
  160443. #endif
  160444. #if defined(__CYGWIN__)
  160445. # undef PNGAPI
  160446. # define PNGAPI __cdecl
  160447. # undef PNG_IMPEXP
  160448. # define PNG_IMPEXP
  160449. #endif
  160450. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  160451. # ifndef PNG_NO_MODULEDEF
  160452. # define PNG_NO_MODULEDEF
  160453. # endif
  160454. #endif
  160455. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  160456. # define PNG_IMPEXP
  160457. #endif
  160458. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  160459. (( defined(_Windows) || defined(_WINDOWS) || \
  160460. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  160461. # ifndef PNGAPI
  160462. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  160463. # define PNGAPI __cdecl
  160464. # else
  160465. # define PNGAPI _cdecl
  160466. # endif
  160467. # endif
  160468. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  160469. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  160470. # define PNG_IMPEXP
  160471. # endif
  160472. # if !defined(PNG_IMPEXP)
  160473. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160474. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  160475. # if defined(_MSC_VER) || defined(__BORLANDC__)
  160476. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  160477. # define PNG_EXPORT PNG_EXPORT_TYPE1
  160478. # else
  160479. # define PNG_EXPORT PNG_EXPORT_TYPE2
  160480. # if defined(PNG_BUILD_DLL)
  160481. # define PNG_IMPEXP __export
  160482. # else
  160483. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  160484. VC++ */
  160485. # endif /* Exists in Borland C++ for
  160486. C++ classes (== huge) */
  160487. # endif
  160488. # endif
  160489. # if !defined(PNG_IMPEXP)
  160490. # if defined(PNG_BUILD_DLL)
  160491. # define PNG_IMPEXP __declspec(dllexport)
  160492. # else
  160493. # define PNG_IMPEXP __declspec(dllimport)
  160494. # endif
  160495. # endif
  160496. # endif /* PNG_IMPEXP */
  160497. #else /* !(DLL || non-cygwin WINDOWS) */
  160498. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  160499. # ifndef PNGAPI
  160500. # define PNGAPI _System
  160501. # endif
  160502. # else
  160503. # if 0 /* ... other platforms, with other meanings */
  160504. # endif
  160505. # endif
  160506. #endif
  160507. #ifndef PNGAPI
  160508. # define PNGAPI
  160509. #endif
  160510. #ifndef PNG_IMPEXP
  160511. # define PNG_IMPEXP
  160512. #endif
  160513. #ifdef PNG_BUILDSYMS
  160514. # ifndef PNG_EXPORT
  160515. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160516. # endif
  160517. # ifdef PNG_USE_GLOBAL_ARRAYS
  160518. # ifndef PNG_EXPORT_VAR
  160519. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160520. # endif
  160521. # endif
  160522. #endif
  160523. #ifndef PNG_EXPORT
  160524. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160525. #endif
  160526. #ifdef PNG_USE_GLOBAL_ARRAYS
  160527. # ifndef PNG_EXPORT_VAR
  160528. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160529. # endif
  160530. #endif
  160531. #ifndef PNG_ABORT
  160532. # define PNG_ABORT() abort()
  160533. #endif
  160534. #ifdef PNG_SETJMP_SUPPORTED
  160535. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160536. #else
  160537. # define png_jmpbuf(png_ptr) \
  160538. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160539. #endif
  160540. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160541. # define CHECK 1
  160542. # define NOCHECK 0
  160543. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160544. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160545. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160546. # define png_strcpy _fstrcpy
  160547. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160548. # define png_strlen _fstrlen
  160549. # define png_memcmp _fmemcmp /* SJT: added */
  160550. # define png_memcpy _fmemcpy
  160551. # define png_memset _fmemset
  160552. #else /* use the usual functions */
  160553. # define CVT_PTR(ptr) (ptr)
  160554. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160555. # ifndef PNG_NO_SNPRINTF
  160556. # ifdef _MSC_VER
  160557. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160558. # define png_snprintf2 _snprintf
  160559. # define png_snprintf6 _snprintf
  160560. # else
  160561. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160562. # define png_snprintf2 snprintf
  160563. # define png_snprintf6 snprintf
  160564. # endif
  160565. # else
  160566. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160567. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160568. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160569. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160570. # endif
  160571. # define png_strcpy strcpy
  160572. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160573. # define png_strlen strlen
  160574. # define png_memcmp memcmp /* SJT: added */
  160575. # define png_memcpy memcpy
  160576. # define png_memset memset
  160577. #endif
  160578. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160579. # undef PNG_ZBUF_SIZE
  160580. # define PNG_ZBUF_SIZE 65536L
  160581. #endif
  160582. #endif /* PNG_VERSION_INFO_ONLY */
  160583. #endif /* PNGCONF_H */
  160584. /*** End of inlined file: pngconf.h ***/
  160585. #ifdef _MSC_VER
  160586. #pragma warning (disable: 4996 4100)
  160587. #endif
  160588. #if defined(PNG_USER_PRIVATEBUILD)
  160589. # define PNG_LIBPNG_BUILD_TYPE \
  160590. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160591. #else
  160592. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160593. # define PNG_LIBPNG_BUILD_TYPE \
  160594. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160595. # else
  160596. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160597. # endif
  160598. #endif
  160599. #ifndef PNG_VERSION_INFO_ONLY
  160600. #ifdef __cplusplus
  160601. extern "C" {
  160602. #endif /* __cplusplus */
  160603. #ifndef PNG_NO_TYPECAST_NULL
  160604. #define int_p_NULL (int *)NULL
  160605. #define png_bytep_NULL (png_bytep)NULL
  160606. #define png_bytepp_NULL (png_bytepp)NULL
  160607. #define png_doublep_NULL (png_doublep)NULL
  160608. #define png_error_ptr_NULL (png_error_ptr)NULL
  160609. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160610. #define png_free_ptr_NULL (png_free_ptr)NULL
  160611. #define png_infopp_NULL (png_infopp)NULL
  160612. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160613. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160614. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160615. #define png_structp_NULL (png_structp)NULL
  160616. #define png_uint_16p_NULL (png_uint_16p)NULL
  160617. #define png_voidp_NULL (png_voidp)NULL
  160618. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160619. #else
  160620. #define int_p_NULL NULL
  160621. #define png_bytep_NULL NULL
  160622. #define png_bytepp_NULL NULL
  160623. #define png_doublep_NULL NULL
  160624. #define png_error_ptr_NULL NULL
  160625. #define png_flush_ptr_NULL NULL
  160626. #define png_free_ptr_NULL NULL
  160627. #define png_infopp_NULL NULL
  160628. #define png_malloc_ptr_NULL NULL
  160629. #define png_read_status_ptr_NULL NULL
  160630. #define png_rw_ptr_NULL NULL
  160631. #define png_structp_NULL NULL
  160632. #define png_uint_16p_NULL NULL
  160633. #define png_voidp_NULL NULL
  160634. #define png_write_status_ptr_NULL NULL
  160635. #endif
  160636. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160637. #ifdef PNG_USE_GLOBAL_ARRAYS
  160638. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160639. #else
  160640. #define png_libpng_ver png_get_header_ver(NULL)
  160641. #endif
  160642. #ifdef PNG_USE_GLOBAL_ARRAYS
  160643. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160644. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160645. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160646. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160647. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160648. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160649. #endif
  160650. #endif /* PNG_NO_EXTERN */
  160651. typedef struct png_color_struct
  160652. {
  160653. png_byte red;
  160654. png_byte green;
  160655. png_byte blue;
  160656. } png_color;
  160657. typedef png_color FAR * png_colorp;
  160658. typedef png_color FAR * FAR * png_colorpp;
  160659. typedef struct png_color_16_struct
  160660. {
  160661. png_byte index; /* used for palette files */
  160662. png_uint_16 red; /* for use in red green blue files */
  160663. png_uint_16 green;
  160664. png_uint_16 blue;
  160665. png_uint_16 gray; /* for use in grayscale files */
  160666. } png_color_16;
  160667. typedef png_color_16 FAR * png_color_16p;
  160668. typedef png_color_16 FAR * FAR * png_color_16pp;
  160669. typedef struct png_color_8_struct
  160670. {
  160671. png_byte red; /* for use in red green blue files */
  160672. png_byte green;
  160673. png_byte blue;
  160674. png_byte gray; /* for use in grayscale files */
  160675. png_byte alpha; /* for alpha channel files */
  160676. } png_color_8;
  160677. typedef png_color_8 FAR * png_color_8p;
  160678. typedef png_color_8 FAR * FAR * png_color_8pp;
  160679. typedef struct png_sPLT_entry_struct
  160680. {
  160681. png_uint_16 red;
  160682. png_uint_16 green;
  160683. png_uint_16 blue;
  160684. png_uint_16 alpha;
  160685. png_uint_16 frequency;
  160686. } png_sPLT_entry;
  160687. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160688. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160689. typedef struct png_sPLT_struct
  160690. {
  160691. png_charp name; /* palette name */
  160692. png_byte depth; /* depth of palette samples */
  160693. png_sPLT_entryp entries; /* palette entries */
  160694. png_int_32 nentries; /* number of palette entries */
  160695. } png_sPLT_t;
  160696. typedef png_sPLT_t FAR * png_sPLT_tp;
  160697. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160698. #ifdef PNG_TEXT_SUPPORTED
  160699. typedef struct png_text_struct
  160700. {
  160701. int compression; /* compression value:
  160702. -1: tEXt, none
  160703. 0: zTXt, deflate
  160704. 1: iTXt, none
  160705. 2: iTXt, deflate */
  160706. png_charp key; /* keyword, 1-79 character description of "text" */
  160707. png_charp text; /* comment, may be an empty string (ie "")
  160708. or a NULL pointer */
  160709. png_size_t text_length; /* length of the text string */
  160710. #ifdef PNG_iTXt_SUPPORTED
  160711. png_size_t itxt_length; /* length of the itxt string */
  160712. png_charp lang; /* language code, 0-79 characters
  160713. or a NULL pointer */
  160714. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160715. chars or a NULL pointer */
  160716. #endif
  160717. } png_text;
  160718. typedef png_text FAR * png_textp;
  160719. typedef png_text FAR * FAR * png_textpp;
  160720. #endif
  160721. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160722. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160723. #define PNG_TEXT_COMPRESSION_NONE -1
  160724. #define PNG_TEXT_COMPRESSION_zTXt 0
  160725. #define PNG_ITXT_COMPRESSION_NONE 1
  160726. #define PNG_ITXT_COMPRESSION_zTXt 2
  160727. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160728. typedef struct png_time_struct
  160729. {
  160730. png_uint_16 year; /* full year, as in, 1995 */
  160731. png_byte month; /* month of year, 1 - 12 */
  160732. png_byte day; /* day of month, 1 - 31 */
  160733. png_byte hour; /* hour of day, 0 - 23 */
  160734. png_byte minute; /* minute of hour, 0 - 59 */
  160735. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160736. } png_time;
  160737. typedef png_time FAR * png_timep;
  160738. typedef png_time FAR * FAR * png_timepp;
  160739. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160740. typedef struct png_unknown_chunk_t
  160741. {
  160742. png_byte name[5];
  160743. png_byte *data;
  160744. png_size_t size;
  160745. png_byte location; /* mode of operation at read time */
  160746. }
  160747. png_unknown_chunk;
  160748. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160749. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160750. #endif
  160751. typedef struct png_info_struct
  160752. {
  160753. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160754. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160755. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160756. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160757. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160758. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160759. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160760. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160761. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160762. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160763. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160764. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160765. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160766. png_byte pixel_depth; /* number of bits per pixel */
  160767. png_byte spare_byte; /* to align the data, and for future use */
  160768. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160769. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160770. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160771. #endif
  160772. #if defined(PNG_sRGB_SUPPORTED)
  160773. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160774. #endif
  160775. #if defined(PNG_TEXT_SUPPORTED)
  160776. int num_text; /* number of comments read/to write */
  160777. int max_text; /* current size of text array */
  160778. png_textp text; /* array of comments read/to write */
  160779. #endif /* PNG_TEXT_SUPPORTED */
  160780. #if defined(PNG_tIME_SUPPORTED)
  160781. png_time mod_time;
  160782. #endif
  160783. #if defined(PNG_sBIT_SUPPORTED)
  160784. png_color_8 sig_bit; /* significant bits in color channels */
  160785. #endif
  160786. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160787. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160788. png_bytep trans; /* transparent values for paletted image */
  160789. png_color_16 trans_values; /* transparent color for non-palette image */
  160790. #endif
  160791. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160792. png_color_16 background;
  160793. #endif
  160794. #if defined(PNG_oFFs_SUPPORTED)
  160795. png_int_32 x_offset; /* x offset on page */
  160796. png_int_32 y_offset; /* y offset on page */
  160797. png_byte offset_unit_type; /* offset units type */
  160798. #endif
  160799. #if defined(PNG_pHYs_SUPPORTED)
  160800. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160801. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160802. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160803. #endif
  160804. #if defined(PNG_hIST_SUPPORTED)
  160805. png_uint_16p hist;
  160806. #endif
  160807. #ifdef PNG_cHRM_SUPPORTED
  160808. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160809. float x_white;
  160810. float y_white;
  160811. float x_red;
  160812. float y_red;
  160813. float x_green;
  160814. float y_green;
  160815. float x_blue;
  160816. float y_blue;
  160817. #endif
  160818. #endif
  160819. #if defined(PNG_pCAL_SUPPORTED)
  160820. png_charp pcal_purpose; /* pCAL chunk description string */
  160821. png_int_32 pcal_X0; /* minimum value */
  160822. png_int_32 pcal_X1; /* maximum value */
  160823. png_charp pcal_units; /* Latin-1 string giving physical units */
  160824. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160825. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160826. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160827. #endif
  160828. #ifdef PNG_FREE_ME_SUPPORTED
  160829. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160830. #endif
  160831. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160832. png_unknown_chunkp unknown_chunks;
  160833. png_size_t unknown_chunks_num;
  160834. #endif
  160835. #if defined(PNG_iCCP_SUPPORTED)
  160836. png_charp iccp_name; /* profile name */
  160837. png_charp iccp_profile; /* International Color Consortium profile data */
  160838. png_uint_32 iccp_proflen; /* ICC profile data length */
  160839. png_byte iccp_compression; /* Always zero */
  160840. #endif
  160841. #if defined(PNG_sPLT_SUPPORTED)
  160842. png_sPLT_tp splt_palettes;
  160843. png_uint_32 splt_palettes_num;
  160844. #endif
  160845. #if defined(PNG_sCAL_SUPPORTED)
  160846. png_byte scal_unit; /* unit of physical scale */
  160847. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160848. double scal_pixel_width; /* width of one pixel */
  160849. double scal_pixel_height; /* height of one pixel */
  160850. #endif
  160851. #ifdef PNG_FIXED_POINT_SUPPORTED
  160852. png_charp scal_s_width; /* string containing height */
  160853. png_charp scal_s_height; /* string containing width */
  160854. #endif
  160855. #endif
  160856. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160857. png_bytepp row_pointers; /* the image bits */
  160858. #endif
  160859. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160860. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160861. #endif
  160862. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160863. png_fixed_point int_x_white;
  160864. png_fixed_point int_y_white;
  160865. png_fixed_point int_x_red;
  160866. png_fixed_point int_y_red;
  160867. png_fixed_point int_x_green;
  160868. png_fixed_point int_y_green;
  160869. png_fixed_point int_x_blue;
  160870. png_fixed_point int_y_blue;
  160871. #endif
  160872. } png_info;
  160873. typedef png_info FAR * png_infop;
  160874. typedef png_info FAR * FAR * png_infopp;
  160875. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160876. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160877. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160878. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160879. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160880. #endif
  160881. #define PNG_COLOR_MASK_PALETTE 1
  160882. #define PNG_COLOR_MASK_COLOR 2
  160883. #define PNG_COLOR_MASK_ALPHA 4
  160884. #define PNG_COLOR_TYPE_GRAY 0
  160885. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160886. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160887. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160888. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160889. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160890. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160891. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160892. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160893. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160894. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160895. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160896. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160897. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160898. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160899. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160900. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160901. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160902. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160903. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160904. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160905. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160906. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160907. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160908. #define PNG_SCALE_METER 1 /* meters per pixel */
  160909. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160910. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160911. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160912. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160913. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160914. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160915. #define PNG_sRGB_INTENT_RELATIVE 1
  160916. #define PNG_sRGB_INTENT_SATURATION 2
  160917. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160918. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160919. #define PNG_KEYWORD_MAX_LENGTH 79
  160920. #define PNG_MAX_PALETTE_LENGTH 256
  160921. #define PNG_INFO_gAMA 0x0001
  160922. #define PNG_INFO_sBIT 0x0002
  160923. #define PNG_INFO_cHRM 0x0004
  160924. #define PNG_INFO_PLTE 0x0008
  160925. #define PNG_INFO_tRNS 0x0010
  160926. #define PNG_INFO_bKGD 0x0020
  160927. #define PNG_INFO_hIST 0x0040
  160928. #define PNG_INFO_pHYs 0x0080
  160929. #define PNG_INFO_oFFs 0x0100
  160930. #define PNG_INFO_tIME 0x0200
  160931. #define PNG_INFO_pCAL 0x0400
  160932. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160933. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160934. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160935. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160936. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160937. typedef struct png_row_info_struct
  160938. {
  160939. png_uint_32 width; /* width of row */
  160940. png_uint_32 rowbytes; /* number of bytes in row */
  160941. png_byte color_type; /* color type of row */
  160942. png_byte bit_depth; /* bit depth of row */
  160943. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160944. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160945. } png_row_info;
  160946. typedef png_row_info FAR * png_row_infop;
  160947. typedef png_row_info FAR * FAR * png_row_infopp;
  160948. typedef struct png_struct_def png_struct;
  160949. typedef png_struct FAR * png_structp;
  160950. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160951. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160952. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160953. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160954. int));
  160955. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160956. int));
  160957. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160958. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160959. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160960. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160961. png_uint_32, int));
  160962. #endif
  160963. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160964. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160965. defined(PNG_LEGACY_SUPPORTED)
  160966. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160967. png_row_infop, png_bytep));
  160968. #endif
  160969. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160970. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160971. #endif
  160972. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160973. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160974. #endif
  160975. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160976. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160977. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160978. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160979. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160980. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160981. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160982. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160983. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160984. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160985. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160986. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160987. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160988. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160989. #define PNG_FLAG_MNG_FILTER_64 0x04
  160990. #define PNG_ALL_MNG_FEATURES 0x05
  160991. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160992. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160993. struct png_struct_def
  160994. {
  160995. #ifdef PNG_SETJMP_SUPPORTED
  160996. jmp_buf jmpbuf; /* used in png_error */
  160997. #endif
  160998. png_error_ptr error_fn; /* function for printing errors and aborting */
  160999. png_error_ptr warning_fn; /* function for printing warnings */
  161000. png_voidp error_ptr; /* user supplied struct for error functions */
  161001. png_rw_ptr write_data_fn; /* function for writing output data */
  161002. png_rw_ptr read_data_fn; /* function for reading input data */
  161003. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  161004. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  161005. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  161006. #endif
  161007. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  161008. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  161009. #endif
  161010. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  161011. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161012. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  161013. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  161014. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  161015. png_byte user_transform_channels; /* channels in user transformed pixels */
  161016. #endif
  161017. #endif
  161018. png_uint_32 mode; /* tells us where we are in the PNG file */
  161019. png_uint_32 flags; /* flags indicating various things to libpng */
  161020. png_uint_32 transformations; /* which transformations to perform */
  161021. z_stream zstream; /* pointer to decompression structure (below) */
  161022. png_bytep zbuf; /* buffer for zlib */
  161023. png_size_t zbuf_size; /* size of zbuf */
  161024. int zlib_level; /* holds zlib compression level */
  161025. int zlib_method; /* holds zlib compression method */
  161026. int zlib_window_bits; /* holds zlib compression window bits */
  161027. int zlib_mem_level; /* holds zlib compression memory level */
  161028. int zlib_strategy; /* holds zlib compression strategy */
  161029. png_uint_32 width; /* width of image in pixels */
  161030. png_uint_32 height; /* height of image in pixels */
  161031. png_uint_32 num_rows; /* number of rows in current pass */
  161032. png_uint_32 usr_width; /* width of row at start of write */
  161033. png_uint_32 rowbytes; /* size of row in bytes */
  161034. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  161035. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  161036. png_uint_32 row_number; /* current row in interlace pass */
  161037. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  161038. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  161039. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  161040. png_bytep up_row; /* buffer to save "up" row when filtering */
  161041. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  161042. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  161043. png_row_info row_info; /* used for transformation routines */
  161044. png_uint_32 idat_size; /* current IDAT size for read */
  161045. png_uint_32 crc; /* current chunk CRC value */
  161046. png_colorp palette; /* palette from the input file */
  161047. png_uint_16 num_palette; /* number of color entries in palette */
  161048. png_uint_16 num_trans; /* number of transparency values */
  161049. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  161050. png_byte compression; /* file compression type (always 0) */
  161051. png_byte filter; /* file filter type (always 0) */
  161052. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  161053. png_byte pass; /* current interlace pass (0 - 6) */
  161054. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  161055. png_byte color_type; /* color type of file */
  161056. png_byte bit_depth; /* bit depth of file */
  161057. png_byte usr_bit_depth; /* bit depth of users row */
  161058. png_byte pixel_depth; /* number of bits per pixel */
  161059. png_byte channels; /* number of channels in file */
  161060. png_byte usr_channels; /* channels at start of write */
  161061. png_byte sig_bytes; /* magic bytes read/written from start of file */
  161062. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  161063. #ifdef PNG_LEGACY_SUPPORTED
  161064. png_byte filler; /* filler byte for pixel expansion */
  161065. #else
  161066. png_uint_16 filler; /* filler bytes for pixel expansion */
  161067. #endif
  161068. #endif
  161069. #if defined(PNG_bKGD_SUPPORTED)
  161070. png_byte background_gamma_type;
  161071. # ifdef PNG_FLOATING_POINT_SUPPORTED
  161072. float background_gamma;
  161073. # endif
  161074. png_color_16 background; /* background color in screen gamma space */
  161075. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161076. png_color_16 background_1; /* background normalized to gamma 1.0 */
  161077. #endif
  161078. #endif /* PNG_bKGD_SUPPORTED */
  161079. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161080. png_flush_ptr output_flush_fn;/* Function for flushing output */
  161081. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  161082. png_uint_32 flush_rows; /* number of rows written since last flush */
  161083. #endif
  161084. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161085. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  161086. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161087. float gamma; /* file gamma value */
  161088. float screen_gamma; /* screen gamma value (display_exponent) */
  161089. #endif
  161090. #endif
  161091. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161092. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  161093. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  161094. png_bytep gamma_to_1; /* converts from file to 1.0 */
  161095. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  161096. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  161097. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  161098. #endif
  161099. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  161100. png_color_8 sig_bit; /* significant bits in each available channel */
  161101. #endif
  161102. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161103. png_color_8 shift; /* shift for significant bit tranformation */
  161104. #endif
  161105. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  161106. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161107. png_bytep trans; /* transparency values for paletted files */
  161108. png_color_16 trans_values; /* transparency values for non-paletted files */
  161109. #endif
  161110. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  161111. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  161112. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161113. png_progressive_info_ptr info_fn; /* called after header data fully read */
  161114. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  161115. png_progressive_end_ptr end_fn; /* called after image is complete */
  161116. png_bytep save_buffer_ptr; /* current location in save_buffer */
  161117. png_bytep save_buffer; /* buffer for previously read data */
  161118. png_bytep current_buffer_ptr; /* current location in current_buffer */
  161119. png_bytep current_buffer; /* buffer for recently used data */
  161120. png_uint_32 push_length; /* size of current input chunk */
  161121. png_uint_32 skip_length; /* bytes to skip in input data */
  161122. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  161123. png_size_t save_buffer_max; /* total size of save_buffer */
  161124. png_size_t buffer_size; /* total amount of available input data */
  161125. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  161126. int process_mode; /* what push library is currently doing */
  161127. int cur_palette; /* current push library palette index */
  161128. # if defined(PNG_TEXT_SUPPORTED)
  161129. png_size_t current_text_size; /* current size of text input data */
  161130. png_size_t current_text_left; /* how much text left to read in input */
  161131. png_charp current_text; /* current text chunk buffer */
  161132. png_charp current_text_ptr; /* current location in current_text */
  161133. # endif /* PNG_TEXT_SUPPORTED */
  161134. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161135. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  161136. png_bytepp offset_table_ptr;
  161137. png_bytep offset_table;
  161138. png_uint_16 offset_table_number;
  161139. png_uint_16 offset_table_count;
  161140. png_uint_16 offset_table_count_free;
  161141. #endif
  161142. #if defined(PNG_READ_DITHER_SUPPORTED)
  161143. png_bytep palette_lookup; /* lookup table for dithering */
  161144. png_bytep dither_index; /* index translation for palette files */
  161145. #endif
  161146. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  161147. png_uint_16p hist; /* histogram */
  161148. #endif
  161149. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  161150. png_byte heuristic_method; /* heuristic for row filter selection */
  161151. png_byte num_prev_filters; /* number of weights for previous rows */
  161152. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  161153. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  161154. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  161155. png_uint_16p filter_costs; /* relative filter calculation cost */
  161156. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  161157. #endif
  161158. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161159. png_charp time_buffer; /* String to hold RFC 1123 time text */
  161160. #endif
  161161. #ifdef PNG_FREE_ME_SUPPORTED
  161162. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  161163. #endif
  161164. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  161165. png_voidp user_chunk_ptr;
  161166. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  161167. #endif
  161168. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161169. int num_chunk_list;
  161170. png_bytep chunk_list;
  161171. #endif
  161172. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161173. png_byte rgb_to_gray_status;
  161174. png_uint_16 rgb_to_gray_red_coeff;
  161175. png_uint_16 rgb_to_gray_green_coeff;
  161176. png_uint_16 rgb_to_gray_blue_coeff;
  161177. #endif
  161178. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  161179. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161180. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161181. #ifdef PNG_1_0_X
  161182. png_byte mng_features_permitted;
  161183. #else
  161184. png_uint_32 mng_features_permitted;
  161185. #endif /* PNG_1_0_X */
  161186. #endif
  161187. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161188. png_fixed_point int_gamma;
  161189. #endif
  161190. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  161191. png_byte filter_type;
  161192. #endif
  161193. #if defined(PNG_1_0_X)
  161194. png_uint_32 row_buf_size;
  161195. #endif
  161196. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161197. # if !defined(PNG_1_0_X)
  161198. # if defined(PNG_MMX_CODE_SUPPORTED)
  161199. png_byte mmx_bitdepth_threshold;
  161200. png_uint_32 mmx_rowbytes_threshold;
  161201. # endif
  161202. png_uint_32 asm_flags;
  161203. # endif
  161204. #endif
  161205. #ifdef PNG_USER_MEM_SUPPORTED
  161206. png_voidp mem_ptr; /* user supplied struct for mem functions */
  161207. png_malloc_ptr malloc_fn; /* function for allocating memory */
  161208. png_free_ptr free_fn; /* function for freeing memory */
  161209. #endif
  161210. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  161211. #if defined(PNG_READ_DITHER_SUPPORTED)
  161212. png_bytep dither_sort; /* working sort array */
  161213. png_bytep index_to_palette; /* where the original index currently is */
  161214. png_bytep palette_to_index; /* which original index points to this */
  161215. #endif
  161216. png_byte compression_type;
  161217. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161218. png_uint_32 user_width_max;
  161219. png_uint_32 user_height_max;
  161220. #endif
  161221. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161222. png_unknown_chunk unknown_chunk;
  161223. #endif
  161224. };
  161225. typedef png_structp version_1_2_21;
  161226. typedef png_struct FAR * FAR * png_structpp;
  161227. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  161228. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  161229. int num_bytes));
  161230. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  161231. png_size_t num_to_check));
  161232. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  161233. extern PNG_EXPORT(png_structp,png_create_read_struct)
  161234. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161235. png_error_ptr error_fn, png_error_ptr warn_fn));
  161236. extern PNG_EXPORT(png_structp,png_create_write_struct)
  161237. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161238. png_error_ptr error_fn, png_error_ptr warn_fn));
  161239. #ifdef PNG_WRITE_SUPPORTED
  161240. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  161241. PNGARG((png_structp png_ptr));
  161242. #endif
  161243. #ifdef PNG_WRITE_SUPPORTED
  161244. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  161245. PNGARG((png_structp png_ptr, png_uint_32 size));
  161246. #endif
  161247. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  161248. #ifdef PNG_USER_MEM_SUPPORTED
  161249. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  161250. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161251. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161252. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161253. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  161254. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161255. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161256. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161257. #endif
  161258. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  161259. png_bytep chunk_name, png_bytep data, png_size_t length));
  161260. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  161261. png_bytep chunk_name, png_uint_32 length));
  161262. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  161263. png_bytep data, png_size_t length));
  161264. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  161265. extern PNG_EXPORT(png_infop,png_create_info_struct)
  161266. PNGARG((png_structp png_ptr));
  161267. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161268. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  161269. #undef png_info_init
  161270. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  161271. png_sizeof(png_info));
  161272. #endif
  161273. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  161274. png_size_t png_info_struct_size));
  161275. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  161276. png_infop info_ptr));
  161277. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  161278. png_infop info_ptr));
  161279. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161280. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  161281. png_infop info_ptr));
  161282. #endif
  161283. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161284. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  161285. PNGARG((png_structp png_ptr, png_timep ptime));
  161286. #endif
  161287. #if !defined(_WIN32_WCE)
  161288. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161289. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  161290. struct tm FAR * ttime));
  161291. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  161292. time_t ttime));
  161293. #endif /* PNG_WRITE_tIME_SUPPORTED */
  161294. #endif /* _WIN32_WCE */
  161295. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161296. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  161297. #if !defined(PNG_1_0_X)
  161298. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  161299. png_ptr));
  161300. #endif
  161301. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  161302. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  161303. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161304. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  161305. #endif
  161306. #endif
  161307. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161308. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  161309. #endif
  161310. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161311. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  161312. #endif
  161313. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161314. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161315. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  161316. int error_action, double red, double green ));
  161317. #endif
  161318. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  161319. int error_action, png_fixed_point red, png_fixed_point green ));
  161320. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  161321. png_ptr));
  161322. #endif
  161323. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  161324. png_colorp palette));
  161325. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161326. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  161327. #endif
  161328. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  161329. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161330. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  161331. #endif
  161332. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  161333. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161334. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  161335. #endif
  161336. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  161337. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  161338. png_uint_32 filler, int flags));
  161339. #define PNG_FILLER_BEFORE 0
  161340. #define PNG_FILLER_AFTER 1
  161341. #if !defined(PNG_1_0_X)
  161342. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  161343. png_uint_32 filler, int flags));
  161344. #endif
  161345. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  161346. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161347. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  161348. #endif
  161349. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  161350. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  161351. #endif
  161352. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161353. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  161354. #endif
  161355. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161356. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  161357. png_color_8p true_bits));
  161358. #endif
  161359. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  161360. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161361. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  161362. #endif
  161363. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161364. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  161365. #endif
  161366. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161367. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161368. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  161369. png_color_16p background_color, int background_gamma_code,
  161370. int need_expand, double background_gamma));
  161371. #endif
  161372. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  161373. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  161374. #define PNG_BACKGROUND_GAMMA_FILE 2
  161375. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  161376. #endif
  161377. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161378. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  161379. #endif
  161380. #if defined(PNG_READ_DITHER_SUPPORTED)
  161381. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  161382. png_colorp palette, int num_palette, int maximum_colors,
  161383. png_uint_16p histogram, int full_dither));
  161384. #endif
  161385. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161386. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161387. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  161388. double screen_gamma, double default_file_gamma));
  161389. #endif
  161390. #endif
  161391. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161392. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161393. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161394. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  161395. int empty_plte_permitted));
  161396. #endif
  161397. #endif
  161398. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161399. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  161400. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  161401. #endif
  161402. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  161403. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  161404. png_infop info_ptr));
  161405. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161406. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  161407. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  161408. #endif
  161409. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161410. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  161411. png_bytep row,
  161412. png_bytep display_row));
  161413. #endif
  161414. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161415. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  161416. png_bytepp image));
  161417. #endif
  161418. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  161419. png_bytep row));
  161420. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  161421. png_bytepp row, png_uint_32 num_rows));
  161422. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  161423. png_bytepp image));
  161424. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  161425. png_infop info_ptr));
  161426. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161427. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  161428. png_infop info_ptr));
  161429. #endif
  161430. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  161431. png_infopp info_ptr_ptr));
  161432. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  161433. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  161434. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  161435. png_infop end_info_ptr));
  161436. extern PNG_EXPORT(void,png_destroy_write_struct)
  161437. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  161438. extern void png_write_destroy PNGARG((png_structp png_ptr));
  161439. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  161440. int crit_action, int ancil_action));
  161441. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  161442. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  161443. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  161444. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  161445. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  161446. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  161447. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  161448. int filters));
  161449. #define PNG_NO_FILTERS 0x00
  161450. #define PNG_FILTER_NONE 0x08
  161451. #define PNG_FILTER_SUB 0x10
  161452. #define PNG_FILTER_UP 0x20
  161453. #define PNG_FILTER_AVG 0x40
  161454. #define PNG_FILTER_PAETH 0x80
  161455. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  161456. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  161457. #define PNG_FILTER_VALUE_NONE 0
  161458. #define PNG_FILTER_VALUE_SUB 1
  161459. #define PNG_FILTER_VALUE_UP 2
  161460. #define PNG_FILTER_VALUE_AVG 3
  161461. #define PNG_FILTER_VALUE_PAETH 4
  161462. #define PNG_FILTER_VALUE_LAST 5
  161463. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  161464. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161465. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  161466. int heuristic_method, int num_weights, png_doublep filter_weights,
  161467. png_doublep filter_costs));
  161468. #endif
  161469. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  161470. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  161471. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  161472. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  161473. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  161474. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  161475. int level));
  161476. extern PNG_EXPORT(void,png_set_compression_mem_level)
  161477. PNGARG((png_structp png_ptr, int mem_level));
  161478. extern PNG_EXPORT(void,png_set_compression_strategy)
  161479. PNGARG((png_structp png_ptr, int strategy));
  161480. extern PNG_EXPORT(void,png_set_compression_window_bits)
  161481. PNGARG((png_structp png_ptr, int window_bits));
  161482. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  161483. int method));
  161484. #if !defined(PNG_NO_STDIO)
  161485. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  161486. #endif
  161487. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  161488. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  161489. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  161490. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  161491. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  161492. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  161493. png_voidp io_ptr, png_rw_ptr read_data_fn));
  161494. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  161495. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  161496. png_read_status_ptr read_row_fn));
  161497. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  161498. png_write_status_ptr write_row_fn));
  161499. #ifdef PNG_USER_MEM_SUPPORTED
  161500. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  161501. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161502. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  161503. #endif
  161504. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161505. defined(PNG_LEGACY_SUPPORTED)
  161506. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  161507. png_ptr, png_user_transform_ptr read_user_transform_fn));
  161508. #endif
  161509. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161510. defined(PNG_LEGACY_SUPPORTED)
  161511. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  161512. png_ptr, png_user_transform_ptr write_user_transform_fn));
  161513. #endif
  161514. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161515. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161516. defined(PNG_LEGACY_SUPPORTED)
  161517. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161518. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161519. int user_transform_channels));
  161520. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161521. PNGARG((png_structp png_ptr));
  161522. #endif
  161523. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161524. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161525. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161526. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161527. png_ptr));
  161528. #endif
  161529. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161530. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161531. png_voidp progressive_ptr,
  161532. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161533. png_progressive_end_ptr end_fn));
  161534. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161535. PNGARG((png_structp png_ptr));
  161536. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161537. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161538. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161539. png_bytep old_row, png_bytep new_row));
  161540. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161541. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161542. png_uint_32 size));
  161543. #if defined(PNG_1_0_X)
  161544. # define png_malloc_warn png_malloc
  161545. #else
  161546. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161547. png_uint_32 size));
  161548. #endif
  161549. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161550. #if defined(PNG_1_0_X)
  161551. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161552. uInt size));
  161553. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161554. #endif
  161555. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161556. png_infop info_ptr, png_uint_32 free_me, int num));
  161557. #ifdef PNG_FREE_ME_SUPPORTED
  161558. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161559. png_infop info_ptr, int freer, png_uint_32 mask));
  161560. #endif
  161561. #define PNG_DESTROY_WILL_FREE_DATA 1
  161562. #define PNG_SET_WILL_FREE_DATA 1
  161563. #define PNG_USER_WILL_FREE_DATA 2
  161564. #define PNG_FREE_HIST 0x0008
  161565. #define PNG_FREE_ICCP 0x0010
  161566. #define PNG_FREE_SPLT 0x0020
  161567. #define PNG_FREE_ROWS 0x0040
  161568. #define PNG_FREE_PCAL 0x0080
  161569. #define PNG_FREE_SCAL 0x0100
  161570. #define PNG_FREE_UNKN 0x0200
  161571. #define PNG_FREE_LIST 0x0400
  161572. #define PNG_FREE_PLTE 0x1000
  161573. #define PNG_FREE_TRNS 0x2000
  161574. #define PNG_FREE_TEXT 0x4000
  161575. #define PNG_FREE_ALL 0x7fff
  161576. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161577. #ifdef PNG_USER_MEM_SUPPORTED
  161578. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161579. png_uint_32 size));
  161580. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161581. png_voidp ptr));
  161582. #endif
  161583. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161584. png_voidp s1, png_voidp s2, png_uint_32 size));
  161585. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161586. png_voidp s1, int value, png_uint_32 size));
  161587. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161588. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161589. int check));
  161590. #endif /* USE_FAR_KEYWORD */
  161591. #ifndef PNG_NO_ERROR_TEXT
  161592. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161593. png_const_charp error_message));
  161594. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161595. png_const_charp error_message));
  161596. #else
  161597. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161598. #endif
  161599. #ifndef PNG_NO_WARNINGS
  161600. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161601. png_const_charp warning_message));
  161602. #ifdef PNG_READ_SUPPORTED
  161603. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161604. png_const_charp warning_message));
  161605. #endif /* PNG_READ_SUPPORTED */
  161606. #endif /* PNG_NO_WARNINGS */
  161607. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161608. png_infop info_ptr, png_uint_32 flag));
  161609. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161610. png_infop info_ptr));
  161611. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161612. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161613. png_infop info_ptr));
  161614. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161615. png_infop info_ptr, png_bytepp row_pointers));
  161616. #endif
  161617. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161618. png_infop info_ptr));
  161619. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161620. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161621. png_ptr, png_infop info_ptr));
  161622. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161623. png_ptr, png_infop info_ptr));
  161624. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161625. png_ptr, png_infop info_ptr));
  161626. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161627. png_ptr, png_infop info_ptr));
  161628. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161629. png_ptr, png_infop info_ptr));
  161630. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161631. png_ptr, png_infop info_ptr));
  161632. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161633. png_ptr, png_infop info_ptr));
  161634. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161635. png_ptr, png_infop info_ptr));
  161636. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161637. png_ptr, png_infop info_ptr));
  161638. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161639. png_ptr, png_infop info_ptr));
  161640. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161641. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161642. png_ptr, png_infop info_ptr));
  161643. #endif
  161644. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161645. png_ptr, png_infop info_ptr));
  161646. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161647. png_ptr, png_infop info_ptr));
  161648. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161649. png_ptr, png_infop info_ptr));
  161650. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161651. png_ptr, png_infop info_ptr));
  161652. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161653. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161654. png_infop info_ptr));
  161655. #if defined(PNG_bKGD_SUPPORTED)
  161656. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161657. png_infop info_ptr, png_color_16p *background));
  161658. #endif
  161659. #if defined(PNG_bKGD_SUPPORTED)
  161660. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161661. png_infop info_ptr, png_color_16p background));
  161662. #endif
  161663. #if defined(PNG_cHRM_SUPPORTED)
  161664. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161665. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161666. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161667. double *red_y, double *green_x, double *green_y, double *blue_x,
  161668. double *blue_y));
  161669. #endif
  161670. #ifdef PNG_FIXED_POINT_SUPPORTED
  161671. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161672. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161673. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161674. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161675. *int_blue_x, png_fixed_point *int_blue_y));
  161676. #endif
  161677. #endif
  161678. #if defined(PNG_cHRM_SUPPORTED)
  161679. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161680. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161681. png_infop info_ptr, double white_x, double white_y, double red_x,
  161682. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161683. #endif
  161684. #ifdef PNG_FIXED_POINT_SUPPORTED
  161685. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161686. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161687. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161688. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161689. png_fixed_point int_blue_y));
  161690. #endif
  161691. #endif
  161692. #if defined(PNG_gAMA_SUPPORTED)
  161693. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161694. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161695. png_infop info_ptr, double *file_gamma));
  161696. #endif
  161697. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161698. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161699. #endif
  161700. #if defined(PNG_gAMA_SUPPORTED)
  161701. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161702. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161703. png_infop info_ptr, double file_gamma));
  161704. #endif
  161705. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161706. png_infop info_ptr, png_fixed_point int_file_gamma));
  161707. #endif
  161708. #if defined(PNG_hIST_SUPPORTED)
  161709. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161710. png_infop info_ptr, png_uint_16p *hist));
  161711. #endif
  161712. #if defined(PNG_hIST_SUPPORTED)
  161713. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161714. png_infop info_ptr, png_uint_16p hist));
  161715. #endif
  161716. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161717. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161718. int *bit_depth, int *color_type, int *interlace_method,
  161719. int *compression_method, int *filter_method));
  161720. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161721. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161722. int color_type, int interlace_method, int compression_method,
  161723. int filter_method));
  161724. #if defined(PNG_oFFs_SUPPORTED)
  161725. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161726. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161727. int *unit_type));
  161728. #endif
  161729. #if defined(PNG_oFFs_SUPPORTED)
  161730. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161731. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161732. int unit_type));
  161733. #endif
  161734. #if defined(PNG_pCAL_SUPPORTED)
  161735. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161736. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161737. int *type, int *nparams, png_charp *units, png_charpp *params));
  161738. #endif
  161739. #if defined(PNG_pCAL_SUPPORTED)
  161740. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161741. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161742. int type, int nparams, png_charp units, png_charpp params));
  161743. #endif
  161744. #if defined(PNG_pHYs_SUPPORTED)
  161745. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161746. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161747. #endif
  161748. #if defined(PNG_pHYs_SUPPORTED)
  161749. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161750. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161751. #endif
  161752. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161753. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161754. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161755. png_infop info_ptr, png_colorp palette, int num_palette));
  161756. #if defined(PNG_sBIT_SUPPORTED)
  161757. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161758. png_infop info_ptr, png_color_8p *sig_bit));
  161759. #endif
  161760. #if defined(PNG_sBIT_SUPPORTED)
  161761. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161762. png_infop info_ptr, png_color_8p sig_bit));
  161763. #endif
  161764. #if defined(PNG_sRGB_SUPPORTED)
  161765. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161766. png_infop info_ptr, int *intent));
  161767. #endif
  161768. #if defined(PNG_sRGB_SUPPORTED)
  161769. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161770. png_infop info_ptr, int intent));
  161771. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161772. png_infop info_ptr, int intent));
  161773. #endif
  161774. #if defined(PNG_iCCP_SUPPORTED)
  161775. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161776. png_infop info_ptr, png_charpp name, int *compression_type,
  161777. png_charpp profile, png_uint_32 *proflen));
  161778. #endif
  161779. #if defined(PNG_iCCP_SUPPORTED)
  161780. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161781. png_infop info_ptr, png_charp name, int compression_type,
  161782. png_charp profile, png_uint_32 proflen));
  161783. #endif
  161784. #if defined(PNG_sPLT_SUPPORTED)
  161785. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161786. png_infop info_ptr, png_sPLT_tpp entries));
  161787. #endif
  161788. #if defined(PNG_sPLT_SUPPORTED)
  161789. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161790. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161791. #endif
  161792. #if defined(PNG_TEXT_SUPPORTED)
  161793. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161794. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161795. #endif
  161796. #if defined(PNG_TEXT_SUPPORTED)
  161797. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161798. png_infop info_ptr, png_textp text_ptr, int num_text));
  161799. #endif
  161800. #if defined(PNG_tIME_SUPPORTED)
  161801. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161802. png_infop info_ptr, png_timep *mod_time));
  161803. #endif
  161804. #if defined(PNG_tIME_SUPPORTED)
  161805. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161806. png_infop info_ptr, png_timep mod_time));
  161807. #endif
  161808. #if defined(PNG_tRNS_SUPPORTED)
  161809. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161810. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161811. png_color_16p *trans_values));
  161812. #endif
  161813. #if defined(PNG_tRNS_SUPPORTED)
  161814. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161815. png_infop info_ptr, png_bytep trans, int num_trans,
  161816. png_color_16p trans_values));
  161817. #endif
  161818. #if defined(PNG_tRNS_SUPPORTED)
  161819. #endif
  161820. #if defined(PNG_sCAL_SUPPORTED)
  161821. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161822. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161823. png_infop info_ptr, int *unit, double *width, double *height));
  161824. #else
  161825. #ifdef PNG_FIXED_POINT_SUPPORTED
  161826. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161827. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161828. #endif
  161829. #endif
  161830. #endif /* PNG_sCAL_SUPPORTED */
  161831. #if defined(PNG_sCAL_SUPPORTED)
  161832. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161833. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161834. png_infop info_ptr, int unit, double width, double height));
  161835. #else
  161836. #ifdef PNG_FIXED_POINT_SUPPORTED
  161837. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161838. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161839. #endif
  161840. #endif
  161841. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161842. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161843. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161844. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161845. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161846. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161847. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161848. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161849. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161850. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161851. #endif
  161852. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161853. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161854. chunk_name));
  161855. #endif
  161856. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161857. png_infop info_ptr, int mask));
  161858. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161859. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161860. png_infop info_ptr,
  161861. int transforms,
  161862. png_voidp params));
  161863. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161864. png_infop info_ptr,
  161865. int transforms,
  161866. png_voidp params));
  161867. #endif
  161868. #ifdef PNG_DEBUG
  161869. #if (PNG_DEBUG > 0)
  161870. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161871. #include <crtdbg.h>
  161872. #if (PNG_DEBUG > 1)
  161873. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161874. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161875. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161876. #endif
  161877. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161878. #ifndef PNG_DEBUG_FILE
  161879. #define PNG_DEBUG_FILE stderr
  161880. #endif /* PNG_DEBUG_FILE */
  161881. #if (PNG_DEBUG > 1)
  161882. #define png_debug(l,m) \
  161883. { \
  161884. int num_tabs=l; \
  161885. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161886. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161887. }
  161888. #define png_debug1(l,m,p1) \
  161889. { \
  161890. int num_tabs=l; \
  161891. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161892. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161893. }
  161894. #define png_debug2(l,m,p1,p2) \
  161895. { \
  161896. int num_tabs=l; \
  161897. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161898. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161899. }
  161900. #endif /* (PNG_DEBUG > 1) */
  161901. #endif /* _MSC_VER */
  161902. #endif /* (PNG_DEBUG > 0) */
  161903. #endif /* PNG_DEBUG */
  161904. #ifndef png_debug
  161905. #define png_debug(l, m)
  161906. #endif
  161907. #ifndef png_debug1
  161908. #define png_debug1(l, m, p1)
  161909. #endif
  161910. #ifndef png_debug2
  161911. #define png_debug2(l, m, p1, p2)
  161912. #endif
  161913. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161914. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161915. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161916. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161917. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161918. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161919. png_ptr, png_uint_32 mng_features_permitted));
  161920. #endif
  161921. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161922. #define PNG_HANDLE_CHUNK_NEVER 1
  161923. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161924. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161925. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161926. #if defined(PNG_MMX_CODE_SUPPORTED)
  161927. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161928. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161929. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161930. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161931. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161932. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161933. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161934. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161935. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161936. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161937. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161938. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161939. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161940. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161941. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161942. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161943. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161944. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161945. | PNG_MMX_READ_FLAGS \
  161946. | PNG_MMX_WRITE_FLAGS )
  161947. #define PNG_SELECT_READ 1
  161948. #define PNG_SELECT_WRITE 2
  161949. #endif /* PNG_MMX_CODE_SUPPORTED */
  161950. #if !defined(PNG_1_0_X)
  161951. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161952. PNGARG((int flag_select, int *compilerID));
  161953. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161954. PNGARG((int flag_select));
  161955. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161956. PNGARG((png_structp png_ptr));
  161957. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161958. PNGARG((png_structp png_ptr));
  161959. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161960. PNGARG((png_structp png_ptr));
  161961. extern PNG_EXPORT(void,png_set_asm_flags)
  161962. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161963. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161964. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161965. png_uint_32 mmx_rowbytes_threshold));
  161966. #endif /* PNG_1_0_X */
  161967. #if !defined(PNG_1_0_X)
  161968. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161969. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161970. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161971. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161972. png_ptr, png_uint_32 strip_mode));
  161973. #endif
  161974. #endif /* PNG_1_0_X */
  161975. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161976. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161977. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161978. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161979. png_ptr));
  161980. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161981. png_ptr));
  161982. #endif
  161983. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161984. # define png_composite(composite, fg, alpha, bg) \
  161985. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161986. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161987. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161988. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161989. # define png_composite_16(composite, fg, alpha, bg) \
  161990. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161991. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161992. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161993. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161994. #else /* standard method using integer division */
  161995. # define png_composite(composite, fg, alpha, bg) \
  161996. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161997. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161998. (png_uint_16)127) / 255)
  161999. # define png_composite_16(composite, fg, alpha, bg) \
  162000. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  162001. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  162002. (png_uint_32)32767) / (png_uint_32)65535L)
  162003. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  162004. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  162005. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  162006. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  162007. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  162008. #else
  162009. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  162010. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  162011. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  162012. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  162013. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  162014. PNGARG((png_structp png_ptr, png_bytep buf));
  162015. extern PNG_EXPORT(void,png_save_uint_32)
  162016. PNGARG((png_bytep buf, png_uint_32 i));
  162017. extern PNG_EXPORT(void,png_save_int_32)
  162018. PNGARG((png_bytep buf, png_int_32 i));
  162019. extern PNG_EXPORT(void,png_save_uint_16)
  162020. PNGARG((png_bytep buf, unsigned int i));
  162021. #define PNG_HAVE_IHDR 0x01
  162022. #define PNG_HAVE_PLTE 0x02
  162023. #define PNG_HAVE_IDAT 0x04
  162024. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  162025. #define PNG_HAVE_IEND 0x10
  162026. #if defined(PNG_INTERNAL)
  162027. #define PNG_HAVE_gAMA 0x20
  162028. #define PNG_HAVE_cHRM 0x40
  162029. #define PNG_HAVE_sRGB 0x80
  162030. #define PNG_HAVE_CHUNK_HEADER 0x100
  162031. #define PNG_WROTE_tIME 0x200
  162032. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  162033. #define PNG_BACKGROUND_IS_GRAY 0x800
  162034. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  162035. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  162036. #define PNG_BGR 0x0001
  162037. #define PNG_INTERLACE 0x0002
  162038. #define PNG_PACK 0x0004
  162039. #define PNG_SHIFT 0x0008
  162040. #define PNG_SWAP_BYTES 0x0010
  162041. #define PNG_INVERT_MONO 0x0020
  162042. #define PNG_DITHER 0x0040
  162043. #define PNG_BACKGROUND 0x0080
  162044. #define PNG_BACKGROUND_EXPAND 0x0100
  162045. #define PNG_16_TO_8 0x0400
  162046. #define PNG_RGBA 0x0800
  162047. #define PNG_EXPAND 0x1000
  162048. #define PNG_GAMMA 0x2000
  162049. #define PNG_GRAY_TO_RGB 0x4000
  162050. #define PNG_FILLER 0x8000L
  162051. #define PNG_PACKSWAP 0x10000L
  162052. #define PNG_SWAP_ALPHA 0x20000L
  162053. #define PNG_STRIP_ALPHA 0x40000L
  162054. #define PNG_INVERT_ALPHA 0x80000L
  162055. #define PNG_USER_TRANSFORM 0x100000L
  162056. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  162057. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  162058. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  162059. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  162060. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  162061. #define PNG_STRUCT_PNG 0x0001
  162062. #define PNG_STRUCT_INFO 0x0002
  162063. #define PNG_WEIGHT_SHIFT 8
  162064. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  162065. #define PNG_COST_SHIFT 3
  162066. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  162067. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  162068. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  162069. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  162070. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  162071. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  162072. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  162073. #define PNG_FLAG_ROW_INIT 0x0040
  162074. #define PNG_FLAG_FILLER_AFTER 0x0080
  162075. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  162076. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  162077. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  162078. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  162079. #define PNG_FLAG_FREE_PLTE 0x1000
  162080. #define PNG_FLAG_FREE_TRNS 0x2000
  162081. #define PNG_FLAG_FREE_HIST 0x4000
  162082. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  162083. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  162084. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  162085. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  162086. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  162087. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  162088. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  162089. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  162090. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  162091. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  162092. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  162093. PNG_FLAG_CRC_CRITICAL_IGNORE)
  162094. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  162095. PNG_FLAG_CRC_CRITICAL_MASK)
  162096. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  162097. abs((int)((c1).green) - (int)((c2).green)) + \
  162098. abs((int)((c1).blue) - (int)((c2).blue)))
  162099. #define PNG_ROWBYTES(pixel_bits, width) \
  162100. ((pixel_bits) >= 8 ? \
  162101. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  162102. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  162103. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  162104. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  162105. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  162106. #ifdef PNG_USE_GLOBAL_ARRAYS
  162107. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  162108. #else
  162109. #endif
  162110. #endif /* PNG_NO_EXTERN */
  162111. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  162112. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  162113. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  162114. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  162115. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  162116. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  162117. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  162118. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  162119. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  162120. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  162121. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  162122. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  162123. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  162124. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  162125. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  162126. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  162127. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  162128. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  162129. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  162130. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  162131. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  162132. #ifdef PNG_USE_GLOBAL_ARRAYS
  162133. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  162134. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  162135. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  162136. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  162137. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  162138. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  162139. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  162140. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  162141. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  162142. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  162143. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  162144. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  162145. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  162146. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  162147. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  162148. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  162149. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  162150. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  162151. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  162152. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  162153. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  162154. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162155. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162156. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  162157. #undef png_read_init
  162158. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  162159. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162160. #endif
  162161. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  162162. png_const_charp user_png_ver, png_size_t png_struct_size));
  162163. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162164. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  162165. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162166. png_info_size));
  162167. #endif
  162168. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162169. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  162170. #undef png_write_init
  162171. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  162172. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162173. #endif
  162174. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  162175. png_const_charp user_png_ver, png_size_t png_struct_size));
  162176. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  162177. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162178. png_info_size));
  162179. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  162180. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  162181. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  162182. malloc_fn, png_voidp mem_ptr));
  162183. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  162184. png_free_ptr free_fn, png_voidp mem_ptr));
  162185. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  162186. png_infop info_ptr));
  162187. #ifndef PNG_1_0_X
  162188. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  162189. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  162190. #ifdef PNG_SIZE_T
  162191. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162192. #endif
  162193. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  162194. png_bytep data, png_size_t length));
  162195. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162196. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  162197. png_bytep buffer, png_size_t length));
  162198. #endif
  162199. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  162200. png_bytep data, png_size_t length));
  162201. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162202. #if !defined(PNG_NO_STDIO)
  162203. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  162204. #endif
  162205. #endif
  162206. #else /* PNG_1_0_X */
  162207. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162208. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  162209. png_bytep buffer, png_size_t length));
  162210. #endif
  162211. #endif /* PNG_1_0_X */
  162212. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  162213. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  162214. png_size_t length));
  162215. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  162216. png_size_t length));
  162217. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  162218. png_size_t length));
  162219. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  162220. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  162221. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  162222. int comp_type, png_charp chunkdata, png_size_t chunklength,
  162223. png_size_t prefix_length, png_size_t *data_length));
  162224. #endif
  162225. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  162226. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  162227. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  162228. png_size_t length));
  162229. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162230. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  162231. #endif
  162232. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  162233. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  162234. png_uint_32 height,
  162235. int bit_depth, int color_type, int compression_method, int filter_method,
  162236. int interlace_method));
  162237. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  162238. png_uint_32 num_pal));
  162239. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  162240. png_size_t length));
  162241. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  162242. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  162243. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162244. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  162245. #endif
  162246. #ifdef PNG_FIXED_POINT_SUPPORTED
  162247. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  162248. file_gamma));
  162249. #endif
  162250. #endif
  162251. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  162252. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  162253. int color_type));
  162254. #endif
  162255. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  162256. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162257. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  162258. double white_x, double white_y,
  162259. double red_x, double red_y, double green_x, double green_y,
  162260. double blue_x, double blue_y));
  162261. #endif
  162262. #ifdef PNG_FIXED_POINT_SUPPORTED
  162263. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  162264. png_fixed_point int_white_x, png_fixed_point int_white_y,
  162265. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  162266. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  162267. png_fixed_point int_blue_y));
  162268. #endif
  162269. #endif
  162270. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  162271. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  162272. int intent));
  162273. #endif
  162274. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  162275. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  162276. png_charp name, int compression_type,
  162277. png_charp profile, int proflen));
  162278. #endif
  162279. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  162280. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  162281. png_sPLT_tp palette));
  162282. #endif
  162283. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  162284. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  162285. png_color_16p values, int number, int color_type));
  162286. #endif
  162287. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  162288. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  162289. png_color_16p values, int color_type));
  162290. #endif
  162291. #if defined(PNG_WRITE_hIST_SUPPORTED)
  162292. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  162293. int num_hist));
  162294. #endif
  162295. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  162296. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  162297. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  162298. png_charp key, png_charpp new_key));
  162299. #endif
  162300. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  162301. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  162302. png_charp text, png_size_t text_len));
  162303. #endif
  162304. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  162305. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  162306. png_charp text, png_size_t text_len, int compression));
  162307. #endif
  162308. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  162309. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  162310. int compression, png_charp key, png_charp lang, png_charp lang_key,
  162311. png_charp text));
  162312. #endif
  162313. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  162314. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  162315. png_infop info_ptr, png_textp text_ptr, int num_text));
  162316. #endif
  162317. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  162318. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  162319. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  162320. #endif
  162321. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  162322. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  162323. png_int_32 X0, png_int_32 X1, int type, int nparams,
  162324. png_charp units, png_charpp params));
  162325. #endif
  162326. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  162327. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  162328. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  162329. int unit_type));
  162330. #endif
  162331. #if defined(PNG_WRITE_tIME_SUPPORTED)
  162332. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  162333. png_timep mod_time));
  162334. #endif
  162335. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  162336. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  162337. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  162338. int unit, double width, double height));
  162339. #else
  162340. #ifdef PNG_FIXED_POINT_SUPPORTED
  162341. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  162342. int unit, png_charp width, png_charp height));
  162343. #endif
  162344. #endif
  162345. #endif
  162346. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  162347. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  162348. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162349. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  162350. #endif
  162351. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  162352. int mask));
  162353. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  162354. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  162355. #endif
  162356. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  162357. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  162358. png_bytep row, int pass));
  162359. #endif
  162360. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  162361. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  162362. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  162363. png_row_infop row_info));
  162364. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  162365. png_bytep filtered_row));
  162366. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  162367. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  162368. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  162369. png_infop info_ptr));
  162370. #if defined(PNG_READ_FILLER_SUPPORTED)
  162371. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  162372. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  162373. #endif
  162374. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  162375. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  162376. png_bytep row));
  162377. #endif
  162378. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  162379. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  162380. png_bytep row));
  162381. #endif
  162382. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  162383. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  162384. png_bytep row));
  162385. #endif
  162386. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  162387. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  162388. png_bytep row));
  162389. #endif
  162390. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  162391. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  162392. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  162393. png_bytep row, png_uint_32 flags));
  162394. #endif
  162395. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  162396. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  162397. #endif
  162398. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  162399. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  162400. #endif
  162401. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  162402. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  162403. row_info, png_bytep row));
  162404. #endif
  162405. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  162406. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  162407. png_bytep row));
  162408. #endif
  162409. #if defined(PNG_READ_PACK_SUPPORTED)
  162410. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  162411. #endif
  162412. #if defined(PNG_READ_SHIFT_SUPPORTED)
  162413. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  162414. png_color_8p sig_bits));
  162415. #endif
  162416. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  162417. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  162418. #endif
  162419. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  162420. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  162421. #endif
  162422. #if defined(PNG_READ_DITHER_SUPPORTED)
  162423. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  162424. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  162425. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  162426. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  162427. png_colorp palette, int num_palette));
  162428. # endif
  162429. #endif
  162430. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  162431. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  162432. #endif
  162433. #if defined(PNG_WRITE_PACK_SUPPORTED)
  162434. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  162435. png_bytep row, png_uint_32 bit_depth));
  162436. #endif
  162437. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  162438. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  162439. png_color_8p bit_depth));
  162440. #endif
  162441. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  162442. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162443. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162444. png_color_16p trans_values, png_color_16p background,
  162445. png_color_16p background_1,
  162446. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  162447. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  162448. png_uint_16pp gamma_16_to_1, int gamma_shift));
  162449. #else
  162450. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162451. png_color_16p trans_values, png_color_16p background));
  162452. #endif
  162453. #endif
  162454. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162455. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  162456. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  162457. int gamma_shift));
  162458. #endif
  162459. #if defined(PNG_READ_EXPAND_SUPPORTED)
  162460. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  162461. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  162462. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  162463. png_bytep row, png_color_16p trans_value));
  162464. #endif
  162465. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  162466. png_uint_32 length));
  162467. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  162468. png_uint_32 length));
  162469. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  162470. png_uint_32 length));
  162471. #if defined(PNG_READ_bKGD_SUPPORTED)
  162472. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  162473. png_uint_32 length));
  162474. #endif
  162475. #if defined(PNG_READ_cHRM_SUPPORTED)
  162476. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  162477. png_uint_32 length));
  162478. #endif
  162479. #if defined(PNG_READ_gAMA_SUPPORTED)
  162480. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  162481. png_uint_32 length));
  162482. #endif
  162483. #if defined(PNG_READ_hIST_SUPPORTED)
  162484. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  162485. png_uint_32 length));
  162486. #endif
  162487. #if defined(PNG_READ_iCCP_SUPPORTED)
  162488. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  162489. png_uint_32 length));
  162490. #endif /* PNG_READ_iCCP_SUPPORTED */
  162491. #if defined(PNG_READ_iTXt_SUPPORTED)
  162492. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162493. png_uint_32 length));
  162494. #endif
  162495. #if defined(PNG_READ_oFFs_SUPPORTED)
  162496. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162497. png_uint_32 length));
  162498. #endif
  162499. #if defined(PNG_READ_pCAL_SUPPORTED)
  162500. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162501. png_uint_32 length));
  162502. #endif
  162503. #if defined(PNG_READ_pHYs_SUPPORTED)
  162504. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162505. png_uint_32 length));
  162506. #endif
  162507. #if defined(PNG_READ_sBIT_SUPPORTED)
  162508. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162509. png_uint_32 length));
  162510. #endif
  162511. #if defined(PNG_READ_sCAL_SUPPORTED)
  162512. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162513. png_uint_32 length));
  162514. #endif
  162515. #if defined(PNG_READ_sPLT_SUPPORTED)
  162516. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162517. png_uint_32 length));
  162518. #endif /* PNG_READ_sPLT_SUPPORTED */
  162519. #if defined(PNG_READ_sRGB_SUPPORTED)
  162520. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162521. png_uint_32 length));
  162522. #endif
  162523. #if defined(PNG_READ_tEXt_SUPPORTED)
  162524. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162525. png_uint_32 length));
  162526. #endif
  162527. #if defined(PNG_READ_tIME_SUPPORTED)
  162528. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162529. png_uint_32 length));
  162530. #endif
  162531. #if defined(PNG_READ_tRNS_SUPPORTED)
  162532. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162533. png_uint_32 length));
  162534. #endif
  162535. #if defined(PNG_READ_zTXt_SUPPORTED)
  162536. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162537. png_uint_32 length));
  162538. #endif
  162539. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162540. png_infop info_ptr, png_uint_32 length));
  162541. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162542. png_bytep chunk_name));
  162543. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162544. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162545. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162546. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162547. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162548. png_infop info_ptr));
  162549. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162550. png_infop info_ptr));
  162551. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162552. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162553. png_uint_32 length));
  162554. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162555. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162556. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162557. png_bytep buffer, png_size_t buffer_length));
  162558. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162559. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162560. png_bytep buffer, png_size_t buffer_length));
  162561. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162562. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162563. png_infop info_ptr, png_uint_32 length));
  162564. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162565. png_infop info_ptr));
  162566. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162567. png_infop info_ptr));
  162568. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162569. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162570. png_infop info_ptr));
  162571. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162572. png_infop info_ptr));
  162573. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162574. #if defined(PNG_READ_tEXt_SUPPORTED)
  162575. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162576. png_infop info_ptr, png_uint_32 length));
  162577. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162578. png_infop info_ptr));
  162579. #endif
  162580. #if defined(PNG_READ_zTXt_SUPPORTED)
  162581. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162582. png_infop info_ptr, png_uint_32 length));
  162583. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162584. png_infop info_ptr));
  162585. #endif
  162586. #if defined(PNG_READ_iTXt_SUPPORTED)
  162587. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162588. png_infop info_ptr, png_uint_32 length));
  162589. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162590. png_infop info_ptr));
  162591. #endif
  162592. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162593. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162594. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162595. png_bytep row));
  162596. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162597. png_bytep row));
  162598. #endif
  162599. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162600. #if defined(PNG_MMX_CODE_SUPPORTED)
  162601. /* PRIVATE */
  162602. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162603. #endif
  162604. #endif
  162605. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162606. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162607. png_infop info_ptr));
  162608. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162609. png_infop info_ptr));
  162610. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162611. png_infop info_ptr));
  162612. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162613. png_infop info_ptr));
  162614. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162615. png_infop info_ptr));
  162616. #if defined(PNG_pHYs_SUPPORTED)
  162617. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162618. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162619. #endif /* PNG_pHYs_SUPPORTED */
  162620. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162621. #endif /* PNG_INTERNAL */
  162622. #ifdef __cplusplus
  162623. }
  162624. #endif
  162625. #endif /* PNG_VERSION_INFO_ONLY */
  162626. #endif /* PNG_H */
  162627. /*** End of inlined file: png.h ***/
  162628. #define PNG_NO_EXTERN
  162629. /*** Start of inlined file: png.c ***/
  162630. #define PNG_INTERNAL
  162631. #define PNG_NO_EXTERN
  162632. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162633. #ifdef PNG_USE_GLOBAL_ARRAYS
  162634. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162635. #ifdef PNG_READ_SUPPORTED
  162636. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162637. #endif /* PNG_READ_SUPPORTED */
  162638. PNG_IHDR;
  162639. PNG_IDAT;
  162640. PNG_IEND;
  162641. PNG_PLTE;
  162642. PNG_bKGD;
  162643. PNG_cHRM;
  162644. PNG_gAMA;
  162645. PNG_hIST;
  162646. PNG_iCCP;
  162647. PNG_iTXt;
  162648. PNG_oFFs;
  162649. PNG_pCAL;
  162650. PNG_sCAL;
  162651. PNG_pHYs;
  162652. PNG_sBIT;
  162653. PNG_sPLT;
  162654. PNG_sRGB;
  162655. PNG_tEXt;
  162656. PNG_tIME;
  162657. PNG_tRNS;
  162658. PNG_zTXt;
  162659. #ifdef PNG_READ_SUPPORTED
  162660. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162661. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162662. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162663. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162664. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162665. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162666. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162667. #endif /* PNG_READ_SUPPORTED */
  162668. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162669. #ifdef PNG_READ_SUPPORTED
  162670. void PNGAPI
  162671. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162672. {
  162673. if(png_ptr == NULL) return;
  162674. png_debug(1, "in png_set_sig_bytes\n");
  162675. if (num_bytes > 8)
  162676. png_error(png_ptr, "Too many bytes for PNG signature.");
  162677. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162678. }
  162679. int PNGAPI
  162680. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162681. {
  162682. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162683. if (num_to_check > 8)
  162684. num_to_check = 8;
  162685. else if (num_to_check < 1)
  162686. return (-1);
  162687. if (start > 7)
  162688. return (-1);
  162689. if (start + num_to_check > 8)
  162690. num_to_check = 8 - start;
  162691. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162692. }
  162693. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162694. int PNGAPI
  162695. png_check_sig(png_bytep sig, int num)
  162696. {
  162697. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162698. }
  162699. #endif
  162700. #endif /* PNG_READ_SUPPORTED */
  162701. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162702. #ifdef PNG_1_0_X
  162703. voidpf PNGAPI
  162704. #else
  162705. voidpf /* private */
  162706. #endif
  162707. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162708. {
  162709. png_voidp ptr;
  162710. png_structp p=(png_structp)png_ptr;
  162711. png_uint_32 save_flags=p->flags;
  162712. png_uint_32 num_bytes;
  162713. if(png_ptr == NULL) return (NULL);
  162714. if (items > PNG_UINT_32_MAX/size)
  162715. {
  162716. png_warning (p, "Potential overflow in png_zalloc()");
  162717. return (NULL);
  162718. }
  162719. num_bytes = (png_uint_32)items * size;
  162720. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162721. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162722. p->flags=save_flags;
  162723. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162724. if (ptr == NULL)
  162725. return ((voidpf)ptr);
  162726. if (num_bytes > (png_uint_32)0x8000L)
  162727. {
  162728. png_memset(ptr, 0, (png_size_t)0x8000L);
  162729. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162730. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162731. }
  162732. else
  162733. {
  162734. png_memset(ptr, 0, (png_size_t)num_bytes);
  162735. }
  162736. #endif
  162737. return ((voidpf)ptr);
  162738. }
  162739. #ifdef PNG_1_0_X
  162740. void PNGAPI
  162741. #else
  162742. void /* private */
  162743. #endif
  162744. png_zfree(voidpf png_ptr, voidpf ptr)
  162745. {
  162746. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162747. }
  162748. void /* PRIVATE */
  162749. png_reset_crc(png_structp png_ptr)
  162750. {
  162751. png_ptr->crc = crc32(0, Z_NULL, 0);
  162752. }
  162753. void /* PRIVATE */
  162754. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162755. {
  162756. int need_crc = 1;
  162757. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162758. {
  162759. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162760. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162761. need_crc = 0;
  162762. }
  162763. else /* critical */
  162764. {
  162765. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162766. need_crc = 0;
  162767. }
  162768. if (need_crc)
  162769. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162770. }
  162771. png_infop PNGAPI
  162772. png_create_info_struct(png_structp png_ptr)
  162773. {
  162774. png_infop info_ptr;
  162775. png_debug(1, "in png_create_info_struct\n");
  162776. if(png_ptr == NULL) return (NULL);
  162777. #ifdef PNG_USER_MEM_SUPPORTED
  162778. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162779. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162780. #else
  162781. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162782. #endif
  162783. if (info_ptr != NULL)
  162784. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162785. return (info_ptr);
  162786. }
  162787. void PNGAPI
  162788. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162789. {
  162790. png_infop info_ptr = NULL;
  162791. if(png_ptr == NULL) return;
  162792. png_debug(1, "in png_destroy_info_struct\n");
  162793. if (info_ptr_ptr != NULL)
  162794. info_ptr = *info_ptr_ptr;
  162795. if (info_ptr != NULL)
  162796. {
  162797. png_info_destroy(png_ptr, info_ptr);
  162798. #ifdef PNG_USER_MEM_SUPPORTED
  162799. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162800. png_ptr->mem_ptr);
  162801. #else
  162802. png_destroy_struct((png_voidp)info_ptr);
  162803. #endif
  162804. *info_ptr_ptr = NULL;
  162805. }
  162806. }
  162807. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162808. #undef png_info_init
  162809. void PNGAPI
  162810. png_info_init(png_infop info_ptr)
  162811. {
  162812. png_info_init_3(&info_ptr, 0);
  162813. }
  162814. #endif
  162815. void PNGAPI
  162816. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162817. {
  162818. png_infop info_ptr = *ptr_ptr;
  162819. if(info_ptr == NULL) return;
  162820. png_debug(1, "in png_info_init_3\n");
  162821. if(png_sizeof(png_info) > png_info_struct_size)
  162822. {
  162823. png_destroy_struct(info_ptr);
  162824. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162825. *ptr_ptr = info_ptr;
  162826. }
  162827. png_memset(info_ptr, 0, png_sizeof (png_info));
  162828. }
  162829. #ifdef PNG_FREE_ME_SUPPORTED
  162830. void PNGAPI
  162831. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162832. int freer, png_uint_32 mask)
  162833. {
  162834. png_debug(1, "in png_data_freer\n");
  162835. if (png_ptr == NULL || info_ptr == NULL)
  162836. return;
  162837. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162838. info_ptr->free_me |= mask;
  162839. else if(freer == PNG_USER_WILL_FREE_DATA)
  162840. info_ptr->free_me &= ~mask;
  162841. else
  162842. png_warning(png_ptr,
  162843. "Unknown freer parameter in png_data_freer.");
  162844. }
  162845. #endif
  162846. void PNGAPI
  162847. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162848. int num)
  162849. {
  162850. png_debug(1, "in png_free_data\n");
  162851. if (png_ptr == NULL || info_ptr == NULL)
  162852. return;
  162853. #if defined(PNG_TEXT_SUPPORTED)
  162854. #ifdef PNG_FREE_ME_SUPPORTED
  162855. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162856. #else
  162857. if (mask & PNG_FREE_TEXT)
  162858. #endif
  162859. {
  162860. if (num != -1)
  162861. {
  162862. if (info_ptr->text && info_ptr->text[num].key)
  162863. {
  162864. png_free(png_ptr, info_ptr->text[num].key);
  162865. info_ptr->text[num].key = NULL;
  162866. }
  162867. }
  162868. else
  162869. {
  162870. int i;
  162871. for (i = 0; i < info_ptr->num_text; i++)
  162872. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162873. png_free(png_ptr, info_ptr->text);
  162874. info_ptr->text = NULL;
  162875. info_ptr->num_text=0;
  162876. }
  162877. }
  162878. #endif
  162879. #if defined(PNG_tRNS_SUPPORTED)
  162880. #ifdef PNG_FREE_ME_SUPPORTED
  162881. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162882. #else
  162883. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162884. #endif
  162885. {
  162886. png_free(png_ptr, info_ptr->trans);
  162887. info_ptr->valid &= ~PNG_INFO_tRNS;
  162888. #ifndef PNG_FREE_ME_SUPPORTED
  162889. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162890. #endif
  162891. info_ptr->trans = NULL;
  162892. }
  162893. #endif
  162894. #if defined(PNG_sCAL_SUPPORTED)
  162895. #ifdef PNG_FREE_ME_SUPPORTED
  162896. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162897. #else
  162898. if (mask & PNG_FREE_SCAL)
  162899. #endif
  162900. {
  162901. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162902. png_free(png_ptr, info_ptr->scal_s_width);
  162903. png_free(png_ptr, info_ptr->scal_s_height);
  162904. info_ptr->scal_s_width = NULL;
  162905. info_ptr->scal_s_height = NULL;
  162906. #endif
  162907. info_ptr->valid &= ~PNG_INFO_sCAL;
  162908. }
  162909. #endif
  162910. #if defined(PNG_pCAL_SUPPORTED)
  162911. #ifdef PNG_FREE_ME_SUPPORTED
  162912. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162913. #else
  162914. if (mask & PNG_FREE_PCAL)
  162915. #endif
  162916. {
  162917. png_free(png_ptr, info_ptr->pcal_purpose);
  162918. png_free(png_ptr, info_ptr->pcal_units);
  162919. info_ptr->pcal_purpose = NULL;
  162920. info_ptr->pcal_units = NULL;
  162921. if (info_ptr->pcal_params != NULL)
  162922. {
  162923. int i;
  162924. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162925. {
  162926. png_free(png_ptr, info_ptr->pcal_params[i]);
  162927. info_ptr->pcal_params[i]=NULL;
  162928. }
  162929. png_free(png_ptr, info_ptr->pcal_params);
  162930. info_ptr->pcal_params = NULL;
  162931. }
  162932. info_ptr->valid &= ~PNG_INFO_pCAL;
  162933. }
  162934. #endif
  162935. #if defined(PNG_iCCP_SUPPORTED)
  162936. #ifdef PNG_FREE_ME_SUPPORTED
  162937. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162938. #else
  162939. if (mask & PNG_FREE_ICCP)
  162940. #endif
  162941. {
  162942. png_free(png_ptr, info_ptr->iccp_name);
  162943. png_free(png_ptr, info_ptr->iccp_profile);
  162944. info_ptr->iccp_name = NULL;
  162945. info_ptr->iccp_profile = NULL;
  162946. info_ptr->valid &= ~PNG_INFO_iCCP;
  162947. }
  162948. #endif
  162949. #if defined(PNG_sPLT_SUPPORTED)
  162950. #ifdef PNG_FREE_ME_SUPPORTED
  162951. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162952. #else
  162953. if (mask & PNG_FREE_SPLT)
  162954. #endif
  162955. {
  162956. if (num != -1)
  162957. {
  162958. if(info_ptr->splt_palettes)
  162959. {
  162960. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162961. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162962. info_ptr->splt_palettes[num].name = NULL;
  162963. info_ptr->splt_palettes[num].entries = NULL;
  162964. }
  162965. }
  162966. else
  162967. {
  162968. if(info_ptr->splt_palettes_num)
  162969. {
  162970. int i;
  162971. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162972. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162973. png_free(png_ptr, info_ptr->splt_palettes);
  162974. info_ptr->splt_palettes = NULL;
  162975. info_ptr->splt_palettes_num = 0;
  162976. }
  162977. info_ptr->valid &= ~PNG_INFO_sPLT;
  162978. }
  162979. }
  162980. #endif
  162981. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162982. if(png_ptr->unknown_chunk.data)
  162983. {
  162984. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162985. png_ptr->unknown_chunk.data = NULL;
  162986. }
  162987. #ifdef PNG_FREE_ME_SUPPORTED
  162988. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162989. #else
  162990. if (mask & PNG_FREE_UNKN)
  162991. #endif
  162992. {
  162993. if (num != -1)
  162994. {
  162995. if(info_ptr->unknown_chunks)
  162996. {
  162997. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162998. info_ptr->unknown_chunks[num].data = NULL;
  162999. }
  163000. }
  163001. else
  163002. {
  163003. int i;
  163004. if(info_ptr->unknown_chunks_num)
  163005. {
  163006. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  163007. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  163008. png_free(png_ptr, info_ptr->unknown_chunks);
  163009. info_ptr->unknown_chunks = NULL;
  163010. info_ptr->unknown_chunks_num = 0;
  163011. }
  163012. }
  163013. }
  163014. #endif
  163015. #if defined(PNG_hIST_SUPPORTED)
  163016. #ifdef PNG_FREE_ME_SUPPORTED
  163017. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  163018. #else
  163019. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  163020. #endif
  163021. {
  163022. png_free(png_ptr, info_ptr->hist);
  163023. info_ptr->hist = NULL;
  163024. info_ptr->valid &= ~PNG_INFO_hIST;
  163025. #ifndef PNG_FREE_ME_SUPPORTED
  163026. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  163027. #endif
  163028. }
  163029. #endif
  163030. #ifdef PNG_FREE_ME_SUPPORTED
  163031. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  163032. #else
  163033. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  163034. #endif
  163035. {
  163036. png_zfree(png_ptr, info_ptr->palette);
  163037. info_ptr->palette = NULL;
  163038. info_ptr->valid &= ~PNG_INFO_PLTE;
  163039. #ifndef PNG_FREE_ME_SUPPORTED
  163040. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  163041. #endif
  163042. info_ptr->num_palette = 0;
  163043. }
  163044. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163045. #ifdef PNG_FREE_ME_SUPPORTED
  163046. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  163047. #else
  163048. if (mask & PNG_FREE_ROWS)
  163049. #endif
  163050. {
  163051. if(info_ptr->row_pointers)
  163052. {
  163053. int row;
  163054. for (row = 0; row < (int)info_ptr->height; row++)
  163055. {
  163056. png_free(png_ptr, info_ptr->row_pointers[row]);
  163057. info_ptr->row_pointers[row]=NULL;
  163058. }
  163059. png_free(png_ptr, info_ptr->row_pointers);
  163060. info_ptr->row_pointers=NULL;
  163061. }
  163062. info_ptr->valid &= ~PNG_INFO_IDAT;
  163063. }
  163064. #endif
  163065. #ifdef PNG_FREE_ME_SUPPORTED
  163066. if(num == -1)
  163067. info_ptr->free_me &= ~mask;
  163068. else
  163069. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  163070. #endif
  163071. }
  163072. void /* PRIVATE */
  163073. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  163074. {
  163075. png_debug(1, "in png_info_destroy\n");
  163076. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  163077. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163078. if (png_ptr->num_chunk_list)
  163079. {
  163080. png_free(png_ptr, png_ptr->chunk_list);
  163081. png_ptr->chunk_list=NULL;
  163082. png_ptr->num_chunk_list=0;
  163083. }
  163084. #endif
  163085. png_info_init_3(&info_ptr, png_sizeof(png_info));
  163086. }
  163087. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163088. png_voidp PNGAPI
  163089. png_get_io_ptr(png_structp png_ptr)
  163090. {
  163091. if(png_ptr == NULL) return (NULL);
  163092. return (png_ptr->io_ptr);
  163093. }
  163094. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163095. #if !defined(PNG_NO_STDIO)
  163096. void PNGAPI
  163097. png_init_io(png_structp png_ptr, png_FILE_p fp)
  163098. {
  163099. png_debug(1, "in png_init_io\n");
  163100. if(png_ptr == NULL) return;
  163101. png_ptr->io_ptr = (png_voidp)fp;
  163102. }
  163103. #endif
  163104. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  163105. png_charp PNGAPI
  163106. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  163107. {
  163108. static PNG_CONST char short_months[12][4] =
  163109. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  163110. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  163111. if(png_ptr == NULL) return (NULL);
  163112. if (png_ptr->time_buffer == NULL)
  163113. {
  163114. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  163115. png_sizeof(char)));
  163116. }
  163117. #if defined(_WIN32_WCE)
  163118. {
  163119. wchar_t time_buf[29];
  163120. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  163121. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163122. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163123. ptime->second % 61);
  163124. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  163125. NULL, NULL);
  163126. }
  163127. #else
  163128. #ifdef USE_FAR_KEYWORD
  163129. {
  163130. char near_time_buf[29];
  163131. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  163132. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163133. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163134. ptime->second % 61);
  163135. png_memcpy(png_ptr->time_buffer, near_time_buf,
  163136. 29*png_sizeof(char));
  163137. }
  163138. #else
  163139. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  163140. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163141. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163142. ptime->second % 61);
  163143. #endif
  163144. #endif /* _WIN32_WCE */
  163145. return ((png_charp)png_ptr->time_buffer);
  163146. }
  163147. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  163148. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163149. png_charp PNGAPI
  163150. png_get_copyright(png_structp png_ptr)
  163151. {
  163152. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163153. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  163154. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  163155. Copyright (c) 1996-1997 Andreas Dilger\n\
  163156. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  163157. }
  163158. png_charp PNGAPI
  163159. png_get_libpng_ver(png_structp png_ptr)
  163160. {
  163161. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163162. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163163. }
  163164. png_charp PNGAPI
  163165. png_get_header_ver(png_structp png_ptr)
  163166. {
  163167. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163168. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163169. }
  163170. png_charp PNGAPI
  163171. png_get_header_version(png_structp png_ptr)
  163172. {
  163173. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163174. return ((png_charp) PNG_HEADER_VERSION_STRING
  163175. #ifndef PNG_READ_SUPPORTED
  163176. " (NO READ SUPPORT)"
  163177. #endif
  163178. "\n");
  163179. }
  163180. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163181. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  163182. int PNGAPI
  163183. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  163184. {
  163185. int i;
  163186. png_bytep p;
  163187. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  163188. return 0;
  163189. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  163190. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  163191. if (!png_memcmp(chunk_name, p, 4))
  163192. return ((int)*(p+4));
  163193. return 0;
  163194. }
  163195. #endif
  163196. int PNGAPI
  163197. png_reset_zstream(png_structp png_ptr)
  163198. {
  163199. if (png_ptr == NULL) return Z_STREAM_ERROR;
  163200. return (inflateReset(&png_ptr->zstream));
  163201. }
  163202. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163203. png_uint_32 PNGAPI
  163204. png_access_version_number(void)
  163205. {
  163206. return((png_uint_32) PNG_LIBPNG_VER);
  163207. }
  163208. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  163209. #if !defined(PNG_1_0_X)
  163210. int PNGAPI
  163211. png_mmx_support(void)
  163212. {
  163213. return -1;
  163214. }
  163215. #endif /* PNG_1_0_X */
  163216. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  163217. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163218. #ifdef PNG_SIZE_T
  163219. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  163220. png_size_t PNGAPI
  163221. png_convert_size(size_t size)
  163222. {
  163223. if (size > (png_size_t)-1)
  163224. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  163225. return ((png_size_t)size);
  163226. }
  163227. #endif /* PNG_SIZE_T */
  163228. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163229. /*** End of inlined file: png.c ***/
  163230. /*** Start of inlined file: pngerror.c ***/
  163231. #define PNG_INTERNAL
  163232. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163233. static void /* PRIVATE */
  163234. png_default_error PNGARG((png_structp png_ptr,
  163235. png_const_charp error_message));
  163236. #ifndef PNG_NO_WARNINGS
  163237. static void /* PRIVATE */
  163238. png_default_warning PNGARG((png_structp png_ptr,
  163239. png_const_charp warning_message));
  163240. #endif /* PNG_NO_WARNINGS */
  163241. #ifndef PNG_NO_ERROR_TEXT
  163242. void PNGAPI
  163243. png_error(png_structp png_ptr, png_const_charp error_message)
  163244. {
  163245. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163246. char msg[16];
  163247. if (png_ptr != NULL)
  163248. {
  163249. if (png_ptr->flags&
  163250. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163251. {
  163252. if (*error_message == '#')
  163253. {
  163254. int offset;
  163255. for (offset=1; offset<15; offset++)
  163256. if (*(error_message+offset) == ' ')
  163257. break;
  163258. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163259. {
  163260. int i;
  163261. for (i=0; i<offset-1; i++)
  163262. msg[i]=error_message[i+1];
  163263. msg[i]='\0';
  163264. error_message=msg;
  163265. }
  163266. else
  163267. error_message+=offset;
  163268. }
  163269. else
  163270. {
  163271. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163272. {
  163273. msg[0]='0';
  163274. msg[1]='\0';
  163275. error_message=msg;
  163276. }
  163277. }
  163278. }
  163279. }
  163280. #endif
  163281. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163282. (*(png_ptr->error_fn))(png_ptr, error_message);
  163283. png_default_error(png_ptr, error_message);
  163284. }
  163285. #else
  163286. void PNGAPI
  163287. png_err(png_structp png_ptr)
  163288. {
  163289. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163290. (*(png_ptr->error_fn))(png_ptr, '\0');
  163291. png_default_error(png_ptr, '\0');
  163292. }
  163293. #endif /* PNG_NO_ERROR_TEXT */
  163294. #ifndef PNG_NO_WARNINGS
  163295. void PNGAPI
  163296. png_warning(png_structp png_ptr, png_const_charp warning_message)
  163297. {
  163298. int offset = 0;
  163299. if (png_ptr != NULL)
  163300. {
  163301. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163302. if (png_ptr->flags&
  163303. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163304. #endif
  163305. {
  163306. if (*warning_message == '#')
  163307. {
  163308. for (offset=1; offset<15; offset++)
  163309. if (*(warning_message+offset) == ' ')
  163310. break;
  163311. }
  163312. }
  163313. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  163314. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  163315. }
  163316. else
  163317. png_default_warning(png_ptr, warning_message+offset);
  163318. }
  163319. #endif /* PNG_NO_WARNINGS */
  163320. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  163321. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  163322. static void /* PRIVATE */
  163323. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  163324. error_message)
  163325. {
  163326. int iout = 0, iin = 0;
  163327. while (iin < 4)
  163328. {
  163329. int c = png_ptr->chunk_name[iin++];
  163330. if (isnonalpha(c))
  163331. {
  163332. buffer[iout++] = '[';
  163333. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  163334. buffer[iout++] = png_digit[c & 0x0f];
  163335. buffer[iout++] = ']';
  163336. }
  163337. else
  163338. {
  163339. buffer[iout++] = (png_byte)c;
  163340. }
  163341. }
  163342. if (error_message == NULL)
  163343. buffer[iout] = 0;
  163344. else
  163345. {
  163346. buffer[iout++] = ':';
  163347. buffer[iout++] = ' ';
  163348. png_strncpy(buffer+iout, error_message, 63);
  163349. buffer[iout+63] = 0;
  163350. }
  163351. }
  163352. #ifdef PNG_READ_SUPPORTED
  163353. void PNGAPI
  163354. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  163355. {
  163356. char msg[18+64];
  163357. if (png_ptr == NULL)
  163358. png_error(png_ptr, error_message);
  163359. else
  163360. {
  163361. png_format_buffer(png_ptr, msg, error_message);
  163362. png_error(png_ptr, msg);
  163363. }
  163364. }
  163365. #endif /* PNG_READ_SUPPORTED */
  163366. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  163367. #ifndef PNG_NO_WARNINGS
  163368. void PNGAPI
  163369. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  163370. {
  163371. char msg[18+64];
  163372. if (png_ptr == NULL)
  163373. png_warning(png_ptr, warning_message);
  163374. else
  163375. {
  163376. png_format_buffer(png_ptr, msg, warning_message);
  163377. png_warning(png_ptr, msg);
  163378. }
  163379. }
  163380. #endif /* PNG_NO_WARNINGS */
  163381. static void /* PRIVATE */
  163382. png_default_error(png_structp png_ptr, png_const_charp error_message)
  163383. {
  163384. #ifndef PNG_NO_CONSOLE_IO
  163385. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163386. if (*error_message == '#')
  163387. {
  163388. int offset;
  163389. char error_number[16];
  163390. for (offset=0; offset<15; offset++)
  163391. {
  163392. error_number[offset] = *(error_message+offset+1);
  163393. if (*(error_message+offset) == ' ')
  163394. break;
  163395. }
  163396. if((offset > 1) && (offset < 15))
  163397. {
  163398. error_number[offset-1]='\0';
  163399. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  163400. error_message+offset);
  163401. }
  163402. else
  163403. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  163404. }
  163405. else
  163406. #endif
  163407. fprintf(stderr, "libpng error: %s\n", error_message);
  163408. #endif
  163409. #ifdef PNG_SETJMP_SUPPORTED
  163410. if (png_ptr)
  163411. {
  163412. # ifdef USE_FAR_KEYWORD
  163413. {
  163414. jmp_buf jmpbuf;
  163415. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  163416. longjmp(jmpbuf, 1);
  163417. }
  163418. # else
  163419. longjmp(png_ptr->jmpbuf, 1);
  163420. # endif
  163421. }
  163422. #else
  163423. PNG_ABORT();
  163424. #endif
  163425. #ifdef PNG_NO_CONSOLE_IO
  163426. error_message = error_message; /* make compiler happy */
  163427. #endif
  163428. }
  163429. #ifndef PNG_NO_WARNINGS
  163430. static void /* PRIVATE */
  163431. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  163432. {
  163433. #ifndef PNG_NO_CONSOLE_IO
  163434. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163435. if (*warning_message == '#')
  163436. {
  163437. int offset;
  163438. char warning_number[16];
  163439. for (offset=0; offset<15; offset++)
  163440. {
  163441. warning_number[offset]=*(warning_message+offset+1);
  163442. if (*(warning_message+offset) == ' ')
  163443. break;
  163444. }
  163445. if((offset > 1) && (offset < 15))
  163446. {
  163447. warning_number[offset-1]='\0';
  163448. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  163449. warning_message+offset);
  163450. }
  163451. else
  163452. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163453. }
  163454. else
  163455. # endif
  163456. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163457. #else
  163458. warning_message = warning_message; /* make compiler happy */
  163459. #endif
  163460. png_ptr = png_ptr; /* make compiler happy */
  163461. }
  163462. #endif /* PNG_NO_WARNINGS */
  163463. void PNGAPI
  163464. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  163465. png_error_ptr error_fn, png_error_ptr warning_fn)
  163466. {
  163467. if (png_ptr == NULL)
  163468. return;
  163469. png_ptr->error_ptr = error_ptr;
  163470. png_ptr->error_fn = error_fn;
  163471. png_ptr->warning_fn = warning_fn;
  163472. }
  163473. png_voidp PNGAPI
  163474. png_get_error_ptr(png_structp png_ptr)
  163475. {
  163476. if (png_ptr == NULL)
  163477. return NULL;
  163478. return ((png_voidp)png_ptr->error_ptr);
  163479. }
  163480. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163481. void PNGAPI
  163482. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  163483. {
  163484. if(png_ptr != NULL)
  163485. {
  163486. png_ptr->flags &=
  163487. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  163488. }
  163489. }
  163490. #endif
  163491. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163492. /*** End of inlined file: pngerror.c ***/
  163493. /*** Start of inlined file: pngget.c ***/
  163494. #define PNG_INTERNAL
  163495. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163496. png_uint_32 PNGAPI
  163497. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  163498. {
  163499. if (png_ptr != NULL && info_ptr != NULL)
  163500. return(info_ptr->valid & flag);
  163501. else
  163502. return(0);
  163503. }
  163504. png_uint_32 PNGAPI
  163505. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  163506. {
  163507. if (png_ptr != NULL && info_ptr != NULL)
  163508. return(info_ptr->rowbytes);
  163509. else
  163510. return(0);
  163511. }
  163512. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163513. png_bytepp PNGAPI
  163514. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163515. {
  163516. if (png_ptr != NULL && info_ptr != NULL)
  163517. return(info_ptr->row_pointers);
  163518. else
  163519. return(0);
  163520. }
  163521. #endif
  163522. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163523. png_uint_32 PNGAPI
  163524. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163525. {
  163526. if (png_ptr != NULL && info_ptr != NULL)
  163527. {
  163528. return info_ptr->width;
  163529. }
  163530. return (0);
  163531. }
  163532. png_uint_32 PNGAPI
  163533. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163534. {
  163535. if (png_ptr != NULL && info_ptr != NULL)
  163536. {
  163537. return info_ptr->height;
  163538. }
  163539. return (0);
  163540. }
  163541. png_byte PNGAPI
  163542. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163543. {
  163544. if (png_ptr != NULL && info_ptr != NULL)
  163545. {
  163546. return info_ptr->bit_depth;
  163547. }
  163548. return (0);
  163549. }
  163550. png_byte PNGAPI
  163551. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163552. {
  163553. if (png_ptr != NULL && info_ptr != NULL)
  163554. {
  163555. return info_ptr->color_type;
  163556. }
  163557. return (0);
  163558. }
  163559. png_byte PNGAPI
  163560. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163561. {
  163562. if (png_ptr != NULL && info_ptr != NULL)
  163563. {
  163564. return info_ptr->filter_type;
  163565. }
  163566. return (0);
  163567. }
  163568. png_byte PNGAPI
  163569. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163570. {
  163571. if (png_ptr != NULL && info_ptr != NULL)
  163572. {
  163573. return info_ptr->interlace_type;
  163574. }
  163575. return (0);
  163576. }
  163577. png_byte PNGAPI
  163578. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163579. {
  163580. if (png_ptr != NULL && info_ptr != NULL)
  163581. {
  163582. return info_ptr->compression_type;
  163583. }
  163584. return (0);
  163585. }
  163586. png_uint_32 PNGAPI
  163587. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163588. {
  163589. if (png_ptr != NULL && info_ptr != NULL)
  163590. #if defined(PNG_pHYs_SUPPORTED)
  163591. if (info_ptr->valid & PNG_INFO_pHYs)
  163592. {
  163593. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163594. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163595. return (0);
  163596. else return (info_ptr->x_pixels_per_unit);
  163597. }
  163598. #else
  163599. return (0);
  163600. #endif
  163601. return (0);
  163602. }
  163603. png_uint_32 PNGAPI
  163604. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163605. {
  163606. if (png_ptr != NULL && info_ptr != NULL)
  163607. #if defined(PNG_pHYs_SUPPORTED)
  163608. if (info_ptr->valid & PNG_INFO_pHYs)
  163609. {
  163610. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163611. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163612. return (0);
  163613. else return (info_ptr->y_pixels_per_unit);
  163614. }
  163615. #else
  163616. return (0);
  163617. #endif
  163618. return (0);
  163619. }
  163620. png_uint_32 PNGAPI
  163621. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163622. {
  163623. if (png_ptr != NULL && info_ptr != NULL)
  163624. #if defined(PNG_pHYs_SUPPORTED)
  163625. if (info_ptr->valid & PNG_INFO_pHYs)
  163626. {
  163627. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163628. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163629. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163630. return (0);
  163631. else return (info_ptr->x_pixels_per_unit);
  163632. }
  163633. #else
  163634. return (0);
  163635. #endif
  163636. return (0);
  163637. }
  163638. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163639. float PNGAPI
  163640. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163641. {
  163642. if (png_ptr != NULL && info_ptr != NULL)
  163643. #if defined(PNG_pHYs_SUPPORTED)
  163644. if (info_ptr->valid & PNG_INFO_pHYs)
  163645. {
  163646. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163647. if (info_ptr->x_pixels_per_unit == 0)
  163648. return ((float)0.0);
  163649. else
  163650. return ((float)((float)info_ptr->y_pixels_per_unit
  163651. /(float)info_ptr->x_pixels_per_unit));
  163652. }
  163653. #else
  163654. return (0.0);
  163655. #endif
  163656. return ((float)0.0);
  163657. }
  163658. #endif
  163659. png_int_32 PNGAPI
  163660. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163661. {
  163662. if (png_ptr != NULL && info_ptr != NULL)
  163663. #if defined(PNG_oFFs_SUPPORTED)
  163664. if (info_ptr->valid & PNG_INFO_oFFs)
  163665. {
  163666. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163667. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163668. return (0);
  163669. else return (info_ptr->x_offset);
  163670. }
  163671. #else
  163672. return (0);
  163673. #endif
  163674. return (0);
  163675. }
  163676. png_int_32 PNGAPI
  163677. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163678. {
  163679. if (png_ptr != NULL && info_ptr != NULL)
  163680. #if defined(PNG_oFFs_SUPPORTED)
  163681. if (info_ptr->valid & PNG_INFO_oFFs)
  163682. {
  163683. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163684. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163685. return (0);
  163686. else return (info_ptr->y_offset);
  163687. }
  163688. #else
  163689. return (0);
  163690. #endif
  163691. return (0);
  163692. }
  163693. png_int_32 PNGAPI
  163694. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163695. {
  163696. if (png_ptr != NULL && info_ptr != NULL)
  163697. #if defined(PNG_oFFs_SUPPORTED)
  163698. if (info_ptr->valid & PNG_INFO_oFFs)
  163699. {
  163700. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163701. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163702. return (0);
  163703. else return (info_ptr->x_offset);
  163704. }
  163705. #else
  163706. return (0);
  163707. #endif
  163708. return (0);
  163709. }
  163710. png_int_32 PNGAPI
  163711. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163712. {
  163713. if (png_ptr != NULL && info_ptr != NULL)
  163714. #if defined(PNG_oFFs_SUPPORTED)
  163715. if (info_ptr->valid & PNG_INFO_oFFs)
  163716. {
  163717. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163718. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163719. return (0);
  163720. else return (info_ptr->y_offset);
  163721. }
  163722. #else
  163723. return (0);
  163724. #endif
  163725. return (0);
  163726. }
  163727. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163728. png_uint_32 PNGAPI
  163729. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163730. {
  163731. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163732. *.0254 +.5));
  163733. }
  163734. png_uint_32 PNGAPI
  163735. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163736. {
  163737. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163738. *.0254 +.5));
  163739. }
  163740. png_uint_32 PNGAPI
  163741. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163742. {
  163743. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163744. *.0254 +.5));
  163745. }
  163746. float PNGAPI
  163747. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163748. {
  163749. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163750. *.00003937);
  163751. }
  163752. float PNGAPI
  163753. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163754. {
  163755. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163756. *.00003937);
  163757. }
  163758. #if defined(PNG_pHYs_SUPPORTED)
  163759. png_uint_32 PNGAPI
  163760. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163761. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163762. {
  163763. png_uint_32 retval = 0;
  163764. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163765. {
  163766. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163767. if (res_x != NULL)
  163768. {
  163769. *res_x = info_ptr->x_pixels_per_unit;
  163770. retval |= PNG_INFO_pHYs;
  163771. }
  163772. if (res_y != NULL)
  163773. {
  163774. *res_y = info_ptr->y_pixels_per_unit;
  163775. retval |= PNG_INFO_pHYs;
  163776. }
  163777. if (unit_type != NULL)
  163778. {
  163779. *unit_type = (int)info_ptr->phys_unit_type;
  163780. retval |= PNG_INFO_pHYs;
  163781. if(*unit_type == 1)
  163782. {
  163783. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163784. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163785. }
  163786. }
  163787. }
  163788. return (retval);
  163789. }
  163790. #endif /* PNG_pHYs_SUPPORTED */
  163791. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163792. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163793. png_byte PNGAPI
  163794. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163795. {
  163796. if (png_ptr != NULL && info_ptr != NULL)
  163797. return(info_ptr->channels);
  163798. else
  163799. return (0);
  163800. }
  163801. png_bytep PNGAPI
  163802. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163803. {
  163804. if (png_ptr != NULL && info_ptr != NULL)
  163805. return(info_ptr->signature);
  163806. else
  163807. return (NULL);
  163808. }
  163809. #if defined(PNG_bKGD_SUPPORTED)
  163810. png_uint_32 PNGAPI
  163811. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163812. png_color_16p *background)
  163813. {
  163814. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163815. && background != NULL)
  163816. {
  163817. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163818. *background = &(info_ptr->background);
  163819. return (PNG_INFO_bKGD);
  163820. }
  163821. return (0);
  163822. }
  163823. #endif
  163824. #if defined(PNG_cHRM_SUPPORTED)
  163825. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163826. png_uint_32 PNGAPI
  163827. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163828. double *white_x, double *white_y, double *red_x, double *red_y,
  163829. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163830. {
  163831. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163832. {
  163833. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163834. if (white_x != NULL)
  163835. *white_x = (double)info_ptr->x_white;
  163836. if (white_y != NULL)
  163837. *white_y = (double)info_ptr->y_white;
  163838. if (red_x != NULL)
  163839. *red_x = (double)info_ptr->x_red;
  163840. if (red_y != NULL)
  163841. *red_y = (double)info_ptr->y_red;
  163842. if (green_x != NULL)
  163843. *green_x = (double)info_ptr->x_green;
  163844. if (green_y != NULL)
  163845. *green_y = (double)info_ptr->y_green;
  163846. if (blue_x != NULL)
  163847. *blue_x = (double)info_ptr->x_blue;
  163848. if (blue_y != NULL)
  163849. *blue_y = (double)info_ptr->y_blue;
  163850. return (PNG_INFO_cHRM);
  163851. }
  163852. return (0);
  163853. }
  163854. #endif
  163855. #ifdef PNG_FIXED_POINT_SUPPORTED
  163856. png_uint_32 PNGAPI
  163857. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163858. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163859. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163860. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163861. {
  163862. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163863. {
  163864. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163865. if (white_x != NULL)
  163866. *white_x = info_ptr->int_x_white;
  163867. if (white_y != NULL)
  163868. *white_y = info_ptr->int_y_white;
  163869. if (red_x != NULL)
  163870. *red_x = info_ptr->int_x_red;
  163871. if (red_y != NULL)
  163872. *red_y = info_ptr->int_y_red;
  163873. if (green_x != NULL)
  163874. *green_x = info_ptr->int_x_green;
  163875. if (green_y != NULL)
  163876. *green_y = info_ptr->int_y_green;
  163877. if (blue_x != NULL)
  163878. *blue_x = info_ptr->int_x_blue;
  163879. if (blue_y != NULL)
  163880. *blue_y = info_ptr->int_y_blue;
  163881. return (PNG_INFO_cHRM);
  163882. }
  163883. return (0);
  163884. }
  163885. #endif
  163886. #endif
  163887. #if defined(PNG_gAMA_SUPPORTED)
  163888. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163889. png_uint_32 PNGAPI
  163890. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163891. {
  163892. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163893. && file_gamma != NULL)
  163894. {
  163895. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163896. *file_gamma = (double)info_ptr->gamma;
  163897. return (PNG_INFO_gAMA);
  163898. }
  163899. return (0);
  163900. }
  163901. #endif
  163902. #ifdef PNG_FIXED_POINT_SUPPORTED
  163903. png_uint_32 PNGAPI
  163904. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163905. png_fixed_point *int_file_gamma)
  163906. {
  163907. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163908. && int_file_gamma != NULL)
  163909. {
  163910. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163911. *int_file_gamma = info_ptr->int_gamma;
  163912. return (PNG_INFO_gAMA);
  163913. }
  163914. return (0);
  163915. }
  163916. #endif
  163917. #endif
  163918. #if defined(PNG_sRGB_SUPPORTED)
  163919. png_uint_32 PNGAPI
  163920. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163921. {
  163922. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163923. && file_srgb_intent != NULL)
  163924. {
  163925. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163926. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163927. return (PNG_INFO_sRGB);
  163928. }
  163929. return (0);
  163930. }
  163931. #endif
  163932. #if defined(PNG_iCCP_SUPPORTED)
  163933. png_uint_32 PNGAPI
  163934. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163935. png_charpp name, int *compression_type,
  163936. png_charpp profile, png_uint_32 *proflen)
  163937. {
  163938. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163939. && name != NULL && profile != NULL && proflen != NULL)
  163940. {
  163941. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163942. *name = info_ptr->iccp_name;
  163943. *profile = info_ptr->iccp_profile;
  163944. *proflen = (int)info_ptr->iccp_proflen;
  163945. *compression_type = (int)info_ptr->iccp_compression;
  163946. return (PNG_INFO_iCCP);
  163947. }
  163948. return (0);
  163949. }
  163950. #endif
  163951. #if defined(PNG_sPLT_SUPPORTED)
  163952. png_uint_32 PNGAPI
  163953. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163954. png_sPLT_tpp spalettes)
  163955. {
  163956. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163957. {
  163958. *spalettes = info_ptr->splt_palettes;
  163959. return ((png_uint_32)info_ptr->splt_palettes_num);
  163960. }
  163961. return (0);
  163962. }
  163963. #endif
  163964. #if defined(PNG_hIST_SUPPORTED)
  163965. png_uint_32 PNGAPI
  163966. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163967. {
  163968. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163969. && hist != NULL)
  163970. {
  163971. png_debug1(1, "in %s retrieval function\n", "hIST");
  163972. *hist = info_ptr->hist;
  163973. return (PNG_INFO_hIST);
  163974. }
  163975. return (0);
  163976. }
  163977. #endif
  163978. png_uint_32 PNGAPI
  163979. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163980. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163981. int *color_type, int *interlace_type, int *compression_type,
  163982. int *filter_type)
  163983. {
  163984. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163985. bit_depth != NULL && color_type != NULL)
  163986. {
  163987. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163988. *width = info_ptr->width;
  163989. *height = info_ptr->height;
  163990. *bit_depth = info_ptr->bit_depth;
  163991. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163992. png_error(png_ptr, "Invalid bit depth");
  163993. *color_type = info_ptr->color_type;
  163994. if (info_ptr->color_type > 6)
  163995. png_error(png_ptr, "Invalid color type");
  163996. if (compression_type != NULL)
  163997. *compression_type = info_ptr->compression_type;
  163998. if (filter_type != NULL)
  163999. *filter_type = info_ptr->filter_type;
  164000. if (interlace_type != NULL)
  164001. *interlace_type = info_ptr->interlace_type;
  164002. if (*width == 0 || *width > PNG_UINT_31_MAX)
  164003. png_error(png_ptr, "Invalid image width");
  164004. if (*height == 0 || *height > PNG_UINT_31_MAX)
  164005. png_error(png_ptr, "Invalid image height");
  164006. if (info_ptr->width > (PNG_UINT_32_MAX
  164007. >> 3) /* 8-byte RGBA pixels */
  164008. - 64 /* bigrowbuf hack */
  164009. - 1 /* filter byte */
  164010. - 7*8 /* rounding of width to multiple of 8 pixels */
  164011. - 8) /* extra max_pixel_depth pad */
  164012. {
  164013. png_warning(png_ptr,
  164014. "Width too large for libpng to process image data.");
  164015. }
  164016. return (1);
  164017. }
  164018. return (0);
  164019. }
  164020. #if defined(PNG_oFFs_SUPPORTED)
  164021. png_uint_32 PNGAPI
  164022. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  164023. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  164024. {
  164025. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  164026. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  164027. {
  164028. png_debug1(1, "in %s retrieval function\n", "oFFs");
  164029. *offset_x = info_ptr->x_offset;
  164030. *offset_y = info_ptr->y_offset;
  164031. *unit_type = (int)info_ptr->offset_unit_type;
  164032. return (PNG_INFO_oFFs);
  164033. }
  164034. return (0);
  164035. }
  164036. #endif
  164037. #if defined(PNG_pCAL_SUPPORTED)
  164038. png_uint_32 PNGAPI
  164039. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  164040. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  164041. png_charp *units, png_charpp *params)
  164042. {
  164043. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  164044. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  164045. nparams != NULL && units != NULL && params != NULL)
  164046. {
  164047. png_debug1(1, "in %s retrieval function\n", "pCAL");
  164048. *purpose = info_ptr->pcal_purpose;
  164049. *X0 = info_ptr->pcal_X0;
  164050. *X1 = info_ptr->pcal_X1;
  164051. *type = (int)info_ptr->pcal_type;
  164052. *nparams = (int)info_ptr->pcal_nparams;
  164053. *units = info_ptr->pcal_units;
  164054. *params = info_ptr->pcal_params;
  164055. return (PNG_INFO_pCAL);
  164056. }
  164057. return (0);
  164058. }
  164059. #endif
  164060. #if defined(PNG_sCAL_SUPPORTED)
  164061. #ifdef PNG_FLOATING_POINT_SUPPORTED
  164062. png_uint_32 PNGAPI
  164063. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  164064. int *unit, double *width, double *height)
  164065. {
  164066. if (png_ptr != NULL && info_ptr != NULL &&
  164067. (info_ptr->valid & PNG_INFO_sCAL))
  164068. {
  164069. *unit = info_ptr->scal_unit;
  164070. *width = info_ptr->scal_pixel_width;
  164071. *height = info_ptr->scal_pixel_height;
  164072. return (PNG_INFO_sCAL);
  164073. }
  164074. return(0);
  164075. }
  164076. #else
  164077. #ifdef PNG_FIXED_POINT_SUPPORTED
  164078. png_uint_32 PNGAPI
  164079. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  164080. int *unit, png_charpp width, png_charpp height)
  164081. {
  164082. if (png_ptr != NULL && info_ptr != NULL &&
  164083. (info_ptr->valid & PNG_INFO_sCAL))
  164084. {
  164085. *unit = info_ptr->scal_unit;
  164086. *width = info_ptr->scal_s_width;
  164087. *height = info_ptr->scal_s_height;
  164088. return (PNG_INFO_sCAL);
  164089. }
  164090. return(0);
  164091. }
  164092. #endif
  164093. #endif
  164094. #endif
  164095. #if defined(PNG_pHYs_SUPPORTED)
  164096. png_uint_32 PNGAPI
  164097. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  164098. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  164099. {
  164100. png_uint_32 retval = 0;
  164101. if (png_ptr != NULL && info_ptr != NULL &&
  164102. (info_ptr->valid & PNG_INFO_pHYs))
  164103. {
  164104. png_debug1(1, "in %s retrieval function\n", "pHYs");
  164105. if (res_x != NULL)
  164106. {
  164107. *res_x = info_ptr->x_pixels_per_unit;
  164108. retval |= PNG_INFO_pHYs;
  164109. }
  164110. if (res_y != NULL)
  164111. {
  164112. *res_y = info_ptr->y_pixels_per_unit;
  164113. retval |= PNG_INFO_pHYs;
  164114. }
  164115. if (unit_type != NULL)
  164116. {
  164117. *unit_type = (int)info_ptr->phys_unit_type;
  164118. retval |= PNG_INFO_pHYs;
  164119. }
  164120. }
  164121. return (retval);
  164122. }
  164123. #endif
  164124. png_uint_32 PNGAPI
  164125. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  164126. int *num_palette)
  164127. {
  164128. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  164129. && palette != NULL)
  164130. {
  164131. png_debug1(1, "in %s retrieval function\n", "PLTE");
  164132. *palette = info_ptr->palette;
  164133. *num_palette = info_ptr->num_palette;
  164134. png_debug1(3, "num_palette = %d\n", *num_palette);
  164135. return (PNG_INFO_PLTE);
  164136. }
  164137. return (0);
  164138. }
  164139. #if defined(PNG_sBIT_SUPPORTED)
  164140. png_uint_32 PNGAPI
  164141. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  164142. {
  164143. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  164144. && sig_bit != NULL)
  164145. {
  164146. png_debug1(1, "in %s retrieval function\n", "sBIT");
  164147. *sig_bit = &(info_ptr->sig_bit);
  164148. return (PNG_INFO_sBIT);
  164149. }
  164150. return (0);
  164151. }
  164152. #endif
  164153. #if defined(PNG_TEXT_SUPPORTED)
  164154. png_uint_32 PNGAPI
  164155. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  164156. int *num_text)
  164157. {
  164158. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  164159. {
  164160. png_debug1(1, "in %s retrieval function\n",
  164161. (png_ptr->chunk_name[0] == '\0' ? "text"
  164162. : (png_const_charp)png_ptr->chunk_name));
  164163. if (text_ptr != NULL)
  164164. *text_ptr = info_ptr->text;
  164165. if (num_text != NULL)
  164166. *num_text = info_ptr->num_text;
  164167. return ((png_uint_32)info_ptr->num_text);
  164168. }
  164169. if (num_text != NULL)
  164170. *num_text = 0;
  164171. return(0);
  164172. }
  164173. #endif
  164174. #if defined(PNG_tIME_SUPPORTED)
  164175. png_uint_32 PNGAPI
  164176. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  164177. {
  164178. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  164179. && mod_time != NULL)
  164180. {
  164181. png_debug1(1, "in %s retrieval function\n", "tIME");
  164182. *mod_time = &(info_ptr->mod_time);
  164183. return (PNG_INFO_tIME);
  164184. }
  164185. return (0);
  164186. }
  164187. #endif
  164188. #if defined(PNG_tRNS_SUPPORTED)
  164189. png_uint_32 PNGAPI
  164190. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  164191. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  164192. {
  164193. png_uint_32 retval = 0;
  164194. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  164195. {
  164196. png_debug1(1, "in %s retrieval function\n", "tRNS");
  164197. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  164198. {
  164199. if (trans != NULL)
  164200. {
  164201. *trans = info_ptr->trans;
  164202. retval |= PNG_INFO_tRNS;
  164203. }
  164204. if (trans_values != NULL)
  164205. *trans_values = &(info_ptr->trans_values);
  164206. }
  164207. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  164208. {
  164209. if (trans_values != NULL)
  164210. {
  164211. *trans_values = &(info_ptr->trans_values);
  164212. retval |= PNG_INFO_tRNS;
  164213. }
  164214. if(trans != NULL)
  164215. *trans = NULL;
  164216. }
  164217. if(num_trans != NULL)
  164218. {
  164219. *num_trans = info_ptr->num_trans;
  164220. retval |= PNG_INFO_tRNS;
  164221. }
  164222. }
  164223. return (retval);
  164224. }
  164225. #endif
  164226. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  164227. png_uint_32 PNGAPI
  164228. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  164229. png_unknown_chunkpp unknowns)
  164230. {
  164231. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  164232. {
  164233. *unknowns = info_ptr->unknown_chunks;
  164234. return ((png_uint_32)info_ptr->unknown_chunks_num);
  164235. }
  164236. return (0);
  164237. }
  164238. #endif
  164239. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  164240. png_byte PNGAPI
  164241. png_get_rgb_to_gray_status (png_structp png_ptr)
  164242. {
  164243. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  164244. }
  164245. #endif
  164246. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  164247. png_voidp PNGAPI
  164248. png_get_user_chunk_ptr(png_structp png_ptr)
  164249. {
  164250. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  164251. }
  164252. #endif
  164253. #ifdef PNG_WRITE_SUPPORTED
  164254. png_uint_32 PNGAPI
  164255. png_get_compression_buffer_size(png_structp png_ptr)
  164256. {
  164257. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  164258. }
  164259. #endif
  164260. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  164261. #ifndef PNG_1_0_X
  164262. png_uint_32 PNGAPI
  164263. png_get_asm_flags (png_structp png_ptr)
  164264. {
  164265. return (png_ptr? 0L: 0L);
  164266. }
  164267. png_uint_32 PNGAPI
  164268. png_get_asm_flagmask (int flag_select)
  164269. {
  164270. flag_select=flag_select;
  164271. return 0L;
  164272. }
  164273. png_uint_32 PNGAPI
  164274. png_get_mmx_flagmask (int flag_select, int *compilerID)
  164275. {
  164276. flag_select=flag_select;
  164277. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  164278. return 0L;
  164279. }
  164280. png_byte PNGAPI
  164281. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  164282. {
  164283. return (png_ptr? 0: 0);
  164284. }
  164285. png_uint_32 PNGAPI
  164286. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  164287. {
  164288. return (png_ptr? 0L: 0L);
  164289. }
  164290. #endif /* ?PNG_1_0_X */
  164291. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  164292. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164293. png_uint_32 PNGAPI
  164294. png_get_user_width_max (png_structp png_ptr)
  164295. {
  164296. return (png_ptr? png_ptr->user_width_max : 0);
  164297. }
  164298. png_uint_32 PNGAPI
  164299. png_get_user_height_max (png_structp png_ptr)
  164300. {
  164301. return (png_ptr? png_ptr->user_height_max : 0);
  164302. }
  164303. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  164304. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164305. /*** End of inlined file: pngget.c ***/
  164306. /*** Start of inlined file: pngmem.c ***/
  164307. #define PNG_INTERNAL
  164308. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  164309. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  164310. png_voidp /* PRIVATE */
  164311. png_create_struct(int type)
  164312. {
  164313. #ifdef PNG_USER_MEM_SUPPORTED
  164314. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164315. }
  164316. png_voidp /* PRIVATE */
  164317. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164318. {
  164319. #endif /* PNG_USER_MEM_SUPPORTED */
  164320. png_size_t size;
  164321. png_voidp struct_ptr;
  164322. if (type == PNG_STRUCT_INFO)
  164323. size = png_sizeof(png_info);
  164324. else if (type == PNG_STRUCT_PNG)
  164325. size = png_sizeof(png_struct);
  164326. else
  164327. return (png_get_copyright(NULL));
  164328. #ifdef PNG_USER_MEM_SUPPORTED
  164329. if(malloc_fn != NULL)
  164330. {
  164331. png_struct dummy_struct;
  164332. png_structp png_ptr = &dummy_struct;
  164333. png_ptr->mem_ptr=mem_ptr;
  164334. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  164335. }
  164336. else
  164337. #endif /* PNG_USER_MEM_SUPPORTED */
  164338. struct_ptr = (png_voidp)farmalloc(size);
  164339. if (struct_ptr != NULL)
  164340. png_memset(struct_ptr, 0, size);
  164341. return (struct_ptr);
  164342. }
  164343. void /* PRIVATE */
  164344. png_destroy_struct(png_voidp struct_ptr)
  164345. {
  164346. #ifdef PNG_USER_MEM_SUPPORTED
  164347. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164348. }
  164349. void /* PRIVATE */
  164350. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164351. png_voidp mem_ptr)
  164352. {
  164353. #endif
  164354. if (struct_ptr != NULL)
  164355. {
  164356. #ifdef PNG_USER_MEM_SUPPORTED
  164357. if(free_fn != NULL)
  164358. {
  164359. png_struct dummy_struct;
  164360. png_structp png_ptr = &dummy_struct;
  164361. png_ptr->mem_ptr=mem_ptr;
  164362. (*(free_fn))(png_ptr, struct_ptr);
  164363. return;
  164364. }
  164365. #endif /* PNG_USER_MEM_SUPPORTED */
  164366. farfree (struct_ptr);
  164367. }
  164368. }
  164369. png_voidp PNGAPI
  164370. png_malloc(png_structp png_ptr, png_uint_32 size)
  164371. {
  164372. png_voidp ret;
  164373. if (png_ptr == NULL || size == 0)
  164374. return (NULL);
  164375. #ifdef PNG_USER_MEM_SUPPORTED
  164376. if(png_ptr->malloc_fn != NULL)
  164377. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164378. else
  164379. ret = (png_malloc_default(png_ptr, size));
  164380. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164381. png_error(png_ptr, "Out of memory!");
  164382. return (ret);
  164383. }
  164384. png_voidp PNGAPI
  164385. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164386. {
  164387. png_voidp ret;
  164388. #endif /* PNG_USER_MEM_SUPPORTED */
  164389. if (png_ptr == NULL || size == 0)
  164390. return (NULL);
  164391. #ifdef PNG_MAX_MALLOC_64K
  164392. if (size > (png_uint_32)65536L)
  164393. {
  164394. png_warning(png_ptr, "Cannot Allocate > 64K");
  164395. ret = NULL;
  164396. }
  164397. else
  164398. #endif
  164399. if (size != (size_t)size)
  164400. ret = NULL;
  164401. else if (size == (png_uint_32)65536L)
  164402. {
  164403. if (png_ptr->offset_table == NULL)
  164404. {
  164405. ret = farmalloc(size);
  164406. if (ret == NULL || ((png_size_t)ret & 0xffff))
  164407. {
  164408. int num_blocks;
  164409. png_uint_32 total_size;
  164410. png_bytep table;
  164411. int i;
  164412. png_byte huge * hptr;
  164413. if (ret != NULL)
  164414. {
  164415. farfree(ret);
  164416. ret = NULL;
  164417. }
  164418. if(png_ptr->zlib_window_bits > 14)
  164419. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  164420. else
  164421. num_blocks = 1;
  164422. if (png_ptr->zlib_mem_level >= 7)
  164423. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  164424. else
  164425. num_blocks++;
  164426. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  164427. table = farmalloc(total_size);
  164428. if (table == NULL)
  164429. {
  164430. #ifndef PNG_USER_MEM_SUPPORTED
  164431. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164432. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  164433. else
  164434. png_warning(png_ptr, "Out Of Memory.");
  164435. #endif
  164436. return (NULL);
  164437. }
  164438. if ((png_size_t)table & 0xfff0)
  164439. {
  164440. #ifndef PNG_USER_MEM_SUPPORTED
  164441. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164442. png_error(png_ptr,
  164443. "Farmalloc didn't return normalized pointer");
  164444. else
  164445. png_warning(png_ptr,
  164446. "Farmalloc didn't return normalized pointer");
  164447. #endif
  164448. return (NULL);
  164449. }
  164450. png_ptr->offset_table = table;
  164451. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  164452. png_sizeof (png_bytep));
  164453. if (png_ptr->offset_table_ptr == NULL)
  164454. {
  164455. #ifndef PNG_USER_MEM_SUPPORTED
  164456. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164457. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  164458. else
  164459. png_warning(png_ptr, "Out Of memory.");
  164460. #endif
  164461. return (NULL);
  164462. }
  164463. hptr = (png_byte huge *)table;
  164464. if ((png_size_t)hptr & 0xf)
  164465. {
  164466. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  164467. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  164468. }
  164469. for (i = 0; i < num_blocks; i++)
  164470. {
  164471. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  164472. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  164473. }
  164474. png_ptr->offset_table_number = num_blocks;
  164475. png_ptr->offset_table_count = 0;
  164476. png_ptr->offset_table_count_free = 0;
  164477. }
  164478. }
  164479. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  164480. {
  164481. #ifndef PNG_USER_MEM_SUPPORTED
  164482. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164483. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  164484. else
  164485. png_warning(png_ptr, "Out of Memory.");
  164486. #endif
  164487. return (NULL);
  164488. }
  164489. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  164490. }
  164491. else
  164492. ret = farmalloc(size);
  164493. #ifndef PNG_USER_MEM_SUPPORTED
  164494. if (ret == NULL)
  164495. {
  164496. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164497. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164498. else
  164499. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164500. }
  164501. #endif
  164502. return (ret);
  164503. }
  164504. void PNGAPI
  164505. png_free(png_structp png_ptr, png_voidp ptr)
  164506. {
  164507. if (png_ptr == NULL || ptr == NULL)
  164508. return;
  164509. #ifdef PNG_USER_MEM_SUPPORTED
  164510. if (png_ptr->free_fn != NULL)
  164511. {
  164512. (*(png_ptr->free_fn))(png_ptr, ptr);
  164513. return;
  164514. }
  164515. else png_free_default(png_ptr, ptr);
  164516. }
  164517. void PNGAPI
  164518. png_free_default(png_structp png_ptr, png_voidp ptr)
  164519. {
  164520. #endif /* PNG_USER_MEM_SUPPORTED */
  164521. if(png_ptr == NULL) return;
  164522. if (png_ptr->offset_table != NULL)
  164523. {
  164524. int i;
  164525. for (i = 0; i < png_ptr->offset_table_count; i++)
  164526. {
  164527. if (ptr == png_ptr->offset_table_ptr[i])
  164528. {
  164529. ptr = NULL;
  164530. png_ptr->offset_table_count_free++;
  164531. break;
  164532. }
  164533. }
  164534. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164535. {
  164536. farfree(png_ptr->offset_table);
  164537. farfree(png_ptr->offset_table_ptr);
  164538. png_ptr->offset_table = NULL;
  164539. png_ptr->offset_table_ptr = NULL;
  164540. }
  164541. }
  164542. if (ptr != NULL)
  164543. {
  164544. farfree(ptr);
  164545. }
  164546. }
  164547. #else /* Not the Borland DOS special memory handler */
  164548. png_voidp /* PRIVATE */
  164549. png_create_struct(int type)
  164550. {
  164551. #ifdef PNG_USER_MEM_SUPPORTED
  164552. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164553. }
  164554. png_voidp /* PRIVATE */
  164555. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164556. {
  164557. #endif /* PNG_USER_MEM_SUPPORTED */
  164558. png_size_t size;
  164559. png_voidp struct_ptr;
  164560. if (type == PNG_STRUCT_INFO)
  164561. size = png_sizeof(png_info);
  164562. else if (type == PNG_STRUCT_PNG)
  164563. size = png_sizeof(png_struct);
  164564. else
  164565. return (NULL);
  164566. #ifdef PNG_USER_MEM_SUPPORTED
  164567. if(malloc_fn != NULL)
  164568. {
  164569. png_struct dummy_struct;
  164570. png_structp png_ptr = &dummy_struct;
  164571. png_ptr->mem_ptr=mem_ptr;
  164572. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164573. if (struct_ptr != NULL)
  164574. png_memset(struct_ptr, 0, size);
  164575. return (struct_ptr);
  164576. }
  164577. #endif /* PNG_USER_MEM_SUPPORTED */
  164578. #if defined(__TURBOC__) && !defined(__FLAT__)
  164579. struct_ptr = (png_voidp)farmalloc(size);
  164580. #else
  164581. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164582. struct_ptr = (png_voidp)halloc(size,1);
  164583. # else
  164584. struct_ptr = (png_voidp)malloc(size);
  164585. # endif
  164586. #endif
  164587. if (struct_ptr != NULL)
  164588. png_memset(struct_ptr, 0, size);
  164589. return (struct_ptr);
  164590. }
  164591. void /* PRIVATE */
  164592. png_destroy_struct(png_voidp struct_ptr)
  164593. {
  164594. #ifdef PNG_USER_MEM_SUPPORTED
  164595. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164596. }
  164597. void /* PRIVATE */
  164598. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164599. png_voidp mem_ptr)
  164600. {
  164601. #endif /* PNG_USER_MEM_SUPPORTED */
  164602. if (struct_ptr != NULL)
  164603. {
  164604. #ifdef PNG_USER_MEM_SUPPORTED
  164605. if(free_fn != NULL)
  164606. {
  164607. png_struct dummy_struct;
  164608. png_structp png_ptr = &dummy_struct;
  164609. png_ptr->mem_ptr=mem_ptr;
  164610. (*(free_fn))(png_ptr, struct_ptr);
  164611. return;
  164612. }
  164613. #endif /* PNG_USER_MEM_SUPPORTED */
  164614. #if defined(__TURBOC__) && !defined(__FLAT__)
  164615. farfree(struct_ptr);
  164616. #else
  164617. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164618. hfree(struct_ptr);
  164619. # else
  164620. free(struct_ptr);
  164621. # endif
  164622. #endif
  164623. }
  164624. }
  164625. png_voidp PNGAPI
  164626. png_malloc(png_structp png_ptr, png_uint_32 size)
  164627. {
  164628. png_voidp ret;
  164629. #ifdef PNG_USER_MEM_SUPPORTED
  164630. if (png_ptr == NULL || size == 0)
  164631. return (NULL);
  164632. if(png_ptr->malloc_fn != NULL)
  164633. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164634. else
  164635. ret = (png_malloc_default(png_ptr, size));
  164636. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164637. png_error(png_ptr, "Out of Memory!");
  164638. return (ret);
  164639. }
  164640. png_voidp PNGAPI
  164641. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164642. {
  164643. png_voidp ret;
  164644. #endif /* PNG_USER_MEM_SUPPORTED */
  164645. if (png_ptr == NULL || size == 0)
  164646. return (NULL);
  164647. #ifdef PNG_MAX_MALLOC_64K
  164648. if (size > (png_uint_32)65536L)
  164649. {
  164650. #ifndef PNG_USER_MEM_SUPPORTED
  164651. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164652. png_error(png_ptr, "Cannot Allocate > 64K");
  164653. else
  164654. #endif
  164655. return NULL;
  164656. }
  164657. #endif
  164658. #if defined(__TURBOC__) && !defined(__FLAT__)
  164659. if (size != (unsigned long)size)
  164660. ret = NULL;
  164661. else
  164662. ret = farmalloc(size);
  164663. #else
  164664. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164665. if (size != (unsigned long)size)
  164666. ret = NULL;
  164667. else
  164668. ret = halloc(size, 1);
  164669. # else
  164670. if (size != (size_t)size)
  164671. ret = NULL;
  164672. else
  164673. ret = malloc((size_t)size);
  164674. # endif
  164675. #endif
  164676. #ifndef PNG_USER_MEM_SUPPORTED
  164677. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164678. png_error(png_ptr, "Out of Memory");
  164679. #endif
  164680. return (ret);
  164681. }
  164682. void PNGAPI
  164683. png_free(png_structp png_ptr, png_voidp ptr)
  164684. {
  164685. if (png_ptr == NULL || ptr == NULL)
  164686. return;
  164687. #ifdef PNG_USER_MEM_SUPPORTED
  164688. if (png_ptr->free_fn != NULL)
  164689. {
  164690. (*(png_ptr->free_fn))(png_ptr, ptr);
  164691. return;
  164692. }
  164693. else png_free_default(png_ptr, ptr);
  164694. }
  164695. void PNGAPI
  164696. png_free_default(png_structp png_ptr, png_voidp ptr)
  164697. {
  164698. if (png_ptr == NULL || ptr == NULL)
  164699. return;
  164700. #endif /* PNG_USER_MEM_SUPPORTED */
  164701. #if defined(__TURBOC__) && !defined(__FLAT__)
  164702. farfree(ptr);
  164703. #else
  164704. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164705. hfree(ptr);
  164706. # else
  164707. free(ptr);
  164708. # endif
  164709. #endif
  164710. }
  164711. #endif /* Not Borland DOS special memory handler */
  164712. #if defined(PNG_1_0_X)
  164713. # define png_malloc_warn png_malloc
  164714. #else
  164715. png_voidp PNGAPI
  164716. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164717. {
  164718. png_voidp ptr;
  164719. png_uint_32 save_flags;
  164720. if(png_ptr == NULL) return (NULL);
  164721. save_flags=png_ptr->flags;
  164722. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164723. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164724. png_ptr->flags=save_flags;
  164725. return(ptr);
  164726. }
  164727. #endif
  164728. png_voidp PNGAPI
  164729. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164730. png_uint_32 length)
  164731. {
  164732. png_size_t size;
  164733. size = (png_size_t)length;
  164734. if ((png_uint_32)size != length)
  164735. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164736. return(png_memcpy (s1, s2, size));
  164737. }
  164738. png_voidp PNGAPI
  164739. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164740. png_uint_32 length)
  164741. {
  164742. png_size_t size;
  164743. size = (png_size_t)length;
  164744. if ((png_uint_32)size != length)
  164745. png_error(png_ptr,"Overflow in png_memset_check.");
  164746. return (png_memset (s1, value, size));
  164747. }
  164748. #ifdef PNG_USER_MEM_SUPPORTED
  164749. void PNGAPI
  164750. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164751. malloc_fn, png_free_ptr free_fn)
  164752. {
  164753. if(png_ptr != NULL) {
  164754. png_ptr->mem_ptr = mem_ptr;
  164755. png_ptr->malloc_fn = malloc_fn;
  164756. png_ptr->free_fn = free_fn;
  164757. }
  164758. }
  164759. png_voidp PNGAPI
  164760. png_get_mem_ptr(png_structp png_ptr)
  164761. {
  164762. if(png_ptr == NULL) return (NULL);
  164763. return ((png_voidp)png_ptr->mem_ptr);
  164764. }
  164765. #endif /* PNG_USER_MEM_SUPPORTED */
  164766. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164767. /*** End of inlined file: pngmem.c ***/
  164768. /*** Start of inlined file: pngread.c ***/
  164769. #define PNG_INTERNAL
  164770. #if defined(PNG_READ_SUPPORTED)
  164771. png_structp PNGAPI
  164772. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164773. png_error_ptr error_fn, png_error_ptr warn_fn)
  164774. {
  164775. #ifdef PNG_USER_MEM_SUPPORTED
  164776. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164777. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164778. }
  164779. png_structp PNGAPI
  164780. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164781. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164782. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164783. {
  164784. #endif /* PNG_USER_MEM_SUPPORTED */
  164785. png_structp png_ptr;
  164786. #ifdef PNG_SETJMP_SUPPORTED
  164787. #ifdef USE_FAR_KEYWORD
  164788. jmp_buf jmpbuf;
  164789. #endif
  164790. #endif
  164791. int i;
  164792. png_debug(1, "in png_create_read_struct\n");
  164793. #ifdef PNG_USER_MEM_SUPPORTED
  164794. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164795. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164796. #else
  164797. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164798. #endif
  164799. if (png_ptr == NULL)
  164800. return (NULL);
  164801. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164802. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164803. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164804. #endif
  164805. #ifdef PNG_SETJMP_SUPPORTED
  164806. #ifdef USE_FAR_KEYWORD
  164807. if (setjmp(jmpbuf))
  164808. #else
  164809. if (setjmp(png_ptr->jmpbuf))
  164810. #endif
  164811. {
  164812. png_free(png_ptr, png_ptr->zbuf);
  164813. png_ptr->zbuf=NULL;
  164814. #ifdef PNG_USER_MEM_SUPPORTED
  164815. png_destroy_struct_2((png_voidp)png_ptr,
  164816. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164817. #else
  164818. png_destroy_struct((png_voidp)png_ptr);
  164819. #endif
  164820. return (NULL);
  164821. }
  164822. #ifdef USE_FAR_KEYWORD
  164823. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164824. #endif
  164825. #endif
  164826. #ifdef PNG_USER_MEM_SUPPORTED
  164827. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164828. #endif
  164829. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164830. i=0;
  164831. do
  164832. {
  164833. if(user_png_ver[i] != png_libpng_ver[i])
  164834. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164835. } while (png_libpng_ver[i++]);
  164836. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164837. {
  164838. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164839. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164840. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164841. {
  164842. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164843. char msg[80];
  164844. if (user_png_ver)
  164845. {
  164846. png_snprintf(msg, 80,
  164847. "Application was compiled with png.h from libpng-%.20s",
  164848. user_png_ver);
  164849. png_warning(png_ptr, msg);
  164850. }
  164851. png_snprintf(msg, 80,
  164852. "Application is running with png.c from libpng-%.20s",
  164853. png_libpng_ver);
  164854. png_warning(png_ptr, msg);
  164855. #endif
  164856. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164857. png_ptr->flags=0;
  164858. #endif
  164859. png_error(png_ptr,
  164860. "Incompatible libpng version in application and library");
  164861. }
  164862. }
  164863. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164864. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164865. (png_uint_32)png_ptr->zbuf_size);
  164866. png_ptr->zstream.zalloc = png_zalloc;
  164867. png_ptr->zstream.zfree = png_zfree;
  164868. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164869. switch (inflateInit(&png_ptr->zstream))
  164870. {
  164871. case Z_OK: /* Do nothing */ break;
  164872. case Z_MEM_ERROR:
  164873. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164874. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164875. default: png_error(png_ptr, "Unknown zlib error");
  164876. }
  164877. png_ptr->zstream.next_out = png_ptr->zbuf;
  164878. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164879. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164880. #ifdef PNG_SETJMP_SUPPORTED
  164881. #ifdef USE_FAR_KEYWORD
  164882. if (setjmp(jmpbuf))
  164883. PNG_ABORT();
  164884. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164885. #else
  164886. if (setjmp(png_ptr->jmpbuf))
  164887. PNG_ABORT();
  164888. #endif
  164889. #endif
  164890. return (png_ptr);
  164891. }
  164892. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164893. #undef png_read_init
  164894. void PNGAPI
  164895. png_read_init(png_structp png_ptr)
  164896. {
  164897. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164898. }
  164899. void PNGAPI
  164900. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164901. png_size_t png_struct_size, png_size_t png_info_size)
  164902. {
  164903. if(png_ptr == NULL) return;
  164904. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164905. if(png_sizeof(png_struct) > png_struct_size ||
  164906. png_sizeof(png_info) > png_info_size)
  164907. {
  164908. char msg[80];
  164909. png_ptr->warning_fn=NULL;
  164910. if (user_png_ver)
  164911. {
  164912. png_snprintf(msg, 80,
  164913. "Application was compiled with png.h from libpng-%.20s",
  164914. user_png_ver);
  164915. png_warning(png_ptr, msg);
  164916. }
  164917. png_snprintf(msg, 80,
  164918. "Application is running with png.c from libpng-%.20s",
  164919. png_libpng_ver);
  164920. png_warning(png_ptr, msg);
  164921. }
  164922. #endif
  164923. if(png_sizeof(png_struct) > png_struct_size)
  164924. {
  164925. png_ptr->error_fn=NULL;
  164926. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164927. png_ptr->flags=0;
  164928. #endif
  164929. png_error(png_ptr,
  164930. "The png struct allocated by the application for reading is too small.");
  164931. }
  164932. if(png_sizeof(png_info) > png_info_size)
  164933. {
  164934. png_ptr->error_fn=NULL;
  164935. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164936. png_ptr->flags=0;
  164937. #endif
  164938. png_error(png_ptr,
  164939. "The info struct allocated by application for reading is too small.");
  164940. }
  164941. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164942. }
  164943. #endif /* PNG_1_0_X || PNG_1_2_X */
  164944. void PNGAPI
  164945. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164946. png_size_t png_struct_size)
  164947. {
  164948. #ifdef PNG_SETJMP_SUPPORTED
  164949. jmp_buf tmp_jmp; /* to save current jump buffer */
  164950. #endif
  164951. int i=0;
  164952. png_structp png_ptr=*ptr_ptr;
  164953. if(png_ptr == NULL) return;
  164954. do
  164955. {
  164956. if(user_png_ver[i] != png_libpng_ver[i])
  164957. {
  164958. #ifdef PNG_LEGACY_SUPPORTED
  164959. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164960. #else
  164961. png_ptr->warning_fn=NULL;
  164962. png_warning(png_ptr,
  164963. "Application uses deprecated png_read_init() and should be recompiled.");
  164964. break;
  164965. #endif
  164966. }
  164967. } while (png_libpng_ver[i++]);
  164968. png_debug(1, "in png_read_init_3\n");
  164969. #ifdef PNG_SETJMP_SUPPORTED
  164970. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164971. #endif
  164972. if(png_sizeof(png_struct) > png_struct_size)
  164973. {
  164974. png_destroy_struct(png_ptr);
  164975. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164976. png_ptr = *ptr_ptr;
  164977. }
  164978. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164979. #ifdef PNG_SETJMP_SUPPORTED
  164980. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164981. #endif
  164982. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164983. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164984. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164985. #endif
  164986. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164987. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164988. (png_uint_32)png_ptr->zbuf_size);
  164989. png_ptr->zstream.zalloc = png_zalloc;
  164990. png_ptr->zstream.zfree = png_zfree;
  164991. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164992. switch (inflateInit(&png_ptr->zstream))
  164993. {
  164994. case Z_OK: /* Do nothing */ break;
  164995. case Z_MEM_ERROR:
  164996. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164997. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164998. default: png_error(png_ptr, "Unknown zlib error");
  164999. }
  165000. png_ptr->zstream.next_out = png_ptr->zbuf;
  165001. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  165002. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  165003. }
  165004. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165005. void PNGAPI
  165006. png_read_info(png_structp png_ptr, png_infop info_ptr)
  165007. {
  165008. if(png_ptr == NULL) return;
  165009. png_debug(1, "in png_read_info\n");
  165010. if (png_ptr->sig_bytes < 8)
  165011. {
  165012. png_size_t num_checked = png_ptr->sig_bytes,
  165013. num_to_check = 8 - num_checked;
  165014. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  165015. png_ptr->sig_bytes = 8;
  165016. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165017. {
  165018. if (num_checked < 4 &&
  165019. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165020. png_error(png_ptr, "Not a PNG file");
  165021. else
  165022. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165023. }
  165024. if (num_checked < 3)
  165025. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  165026. }
  165027. for(;;)
  165028. {
  165029. #ifdef PNG_USE_LOCAL_ARRAYS
  165030. PNG_CONST PNG_IHDR;
  165031. PNG_CONST PNG_IDAT;
  165032. PNG_CONST PNG_IEND;
  165033. PNG_CONST PNG_PLTE;
  165034. #if defined(PNG_READ_bKGD_SUPPORTED)
  165035. PNG_CONST PNG_bKGD;
  165036. #endif
  165037. #if defined(PNG_READ_cHRM_SUPPORTED)
  165038. PNG_CONST PNG_cHRM;
  165039. #endif
  165040. #if defined(PNG_READ_gAMA_SUPPORTED)
  165041. PNG_CONST PNG_gAMA;
  165042. #endif
  165043. #if defined(PNG_READ_hIST_SUPPORTED)
  165044. PNG_CONST PNG_hIST;
  165045. #endif
  165046. #if defined(PNG_READ_iCCP_SUPPORTED)
  165047. PNG_CONST PNG_iCCP;
  165048. #endif
  165049. #if defined(PNG_READ_iTXt_SUPPORTED)
  165050. PNG_CONST PNG_iTXt;
  165051. #endif
  165052. #if defined(PNG_READ_oFFs_SUPPORTED)
  165053. PNG_CONST PNG_oFFs;
  165054. #endif
  165055. #if defined(PNG_READ_pCAL_SUPPORTED)
  165056. PNG_CONST PNG_pCAL;
  165057. #endif
  165058. #if defined(PNG_READ_pHYs_SUPPORTED)
  165059. PNG_CONST PNG_pHYs;
  165060. #endif
  165061. #if defined(PNG_READ_sBIT_SUPPORTED)
  165062. PNG_CONST PNG_sBIT;
  165063. #endif
  165064. #if defined(PNG_READ_sCAL_SUPPORTED)
  165065. PNG_CONST PNG_sCAL;
  165066. #endif
  165067. #if defined(PNG_READ_sPLT_SUPPORTED)
  165068. PNG_CONST PNG_sPLT;
  165069. #endif
  165070. #if defined(PNG_READ_sRGB_SUPPORTED)
  165071. PNG_CONST PNG_sRGB;
  165072. #endif
  165073. #if defined(PNG_READ_tEXt_SUPPORTED)
  165074. PNG_CONST PNG_tEXt;
  165075. #endif
  165076. #if defined(PNG_READ_tIME_SUPPORTED)
  165077. PNG_CONST PNG_tIME;
  165078. #endif
  165079. #if defined(PNG_READ_tRNS_SUPPORTED)
  165080. PNG_CONST PNG_tRNS;
  165081. #endif
  165082. #if defined(PNG_READ_zTXt_SUPPORTED)
  165083. PNG_CONST PNG_zTXt;
  165084. #endif
  165085. #endif /* PNG_USE_LOCAL_ARRAYS */
  165086. png_byte chunk_length[4];
  165087. png_uint_32 length;
  165088. png_read_data(png_ptr, chunk_length, 4);
  165089. length = png_get_uint_31(png_ptr,chunk_length);
  165090. png_reset_crc(png_ptr);
  165091. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165092. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  165093. length);
  165094. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165095. if(png_ptr->mode & PNG_AFTER_IDAT)
  165096. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165097. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165098. png_handle_IHDR(png_ptr, info_ptr, length);
  165099. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165100. png_handle_IEND(png_ptr, info_ptr, length);
  165101. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165102. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165103. {
  165104. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165105. png_ptr->mode |= PNG_HAVE_IDAT;
  165106. png_handle_unknown(png_ptr, info_ptr, length);
  165107. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165108. png_ptr->mode |= PNG_HAVE_PLTE;
  165109. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165110. {
  165111. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165112. png_error(png_ptr, "Missing IHDR before IDAT");
  165113. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165114. !(png_ptr->mode & PNG_HAVE_PLTE))
  165115. png_error(png_ptr, "Missing PLTE before IDAT");
  165116. break;
  165117. }
  165118. }
  165119. #endif
  165120. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165121. png_handle_PLTE(png_ptr, info_ptr, length);
  165122. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165123. {
  165124. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165125. png_error(png_ptr, "Missing IHDR before IDAT");
  165126. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165127. !(png_ptr->mode & PNG_HAVE_PLTE))
  165128. png_error(png_ptr, "Missing PLTE before IDAT");
  165129. png_ptr->idat_size = length;
  165130. png_ptr->mode |= PNG_HAVE_IDAT;
  165131. break;
  165132. }
  165133. #if defined(PNG_READ_bKGD_SUPPORTED)
  165134. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165135. png_handle_bKGD(png_ptr, info_ptr, length);
  165136. #endif
  165137. #if defined(PNG_READ_cHRM_SUPPORTED)
  165138. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165139. png_handle_cHRM(png_ptr, info_ptr, length);
  165140. #endif
  165141. #if defined(PNG_READ_gAMA_SUPPORTED)
  165142. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165143. png_handle_gAMA(png_ptr, info_ptr, length);
  165144. #endif
  165145. #if defined(PNG_READ_hIST_SUPPORTED)
  165146. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165147. png_handle_hIST(png_ptr, info_ptr, length);
  165148. #endif
  165149. #if defined(PNG_READ_oFFs_SUPPORTED)
  165150. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165151. png_handle_oFFs(png_ptr, info_ptr, length);
  165152. #endif
  165153. #if defined(PNG_READ_pCAL_SUPPORTED)
  165154. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165155. png_handle_pCAL(png_ptr, info_ptr, length);
  165156. #endif
  165157. #if defined(PNG_READ_sCAL_SUPPORTED)
  165158. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165159. png_handle_sCAL(png_ptr, info_ptr, length);
  165160. #endif
  165161. #if defined(PNG_READ_pHYs_SUPPORTED)
  165162. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165163. png_handle_pHYs(png_ptr, info_ptr, length);
  165164. #endif
  165165. #if defined(PNG_READ_sBIT_SUPPORTED)
  165166. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165167. png_handle_sBIT(png_ptr, info_ptr, length);
  165168. #endif
  165169. #if defined(PNG_READ_sRGB_SUPPORTED)
  165170. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165171. png_handle_sRGB(png_ptr, info_ptr, length);
  165172. #endif
  165173. #if defined(PNG_READ_iCCP_SUPPORTED)
  165174. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165175. png_handle_iCCP(png_ptr, info_ptr, length);
  165176. #endif
  165177. #if defined(PNG_READ_sPLT_SUPPORTED)
  165178. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165179. png_handle_sPLT(png_ptr, info_ptr, length);
  165180. #endif
  165181. #if defined(PNG_READ_tEXt_SUPPORTED)
  165182. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165183. png_handle_tEXt(png_ptr, info_ptr, length);
  165184. #endif
  165185. #if defined(PNG_READ_tIME_SUPPORTED)
  165186. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165187. png_handle_tIME(png_ptr, info_ptr, length);
  165188. #endif
  165189. #if defined(PNG_READ_tRNS_SUPPORTED)
  165190. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165191. png_handle_tRNS(png_ptr, info_ptr, length);
  165192. #endif
  165193. #if defined(PNG_READ_zTXt_SUPPORTED)
  165194. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165195. png_handle_zTXt(png_ptr, info_ptr, length);
  165196. #endif
  165197. #if defined(PNG_READ_iTXt_SUPPORTED)
  165198. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165199. png_handle_iTXt(png_ptr, info_ptr, length);
  165200. #endif
  165201. else
  165202. png_handle_unknown(png_ptr, info_ptr, length);
  165203. }
  165204. }
  165205. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165206. void PNGAPI
  165207. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  165208. {
  165209. png_debug(1, "in png_read_update_info\n");
  165210. if(png_ptr == NULL) return;
  165211. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165212. png_read_start_row(png_ptr);
  165213. else
  165214. png_warning(png_ptr,
  165215. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  165216. png_read_transform_info(png_ptr, info_ptr);
  165217. }
  165218. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165219. void PNGAPI
  165220. png_start_read_image(png_structp png_ptr)
  165221. {
  165222. png_debug(1, "in png_start_read_image\n");
  165223. if(png_ptr == NULL) return;
  165224. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165225. png_read_start_row(png_ptr);
  165226. }
  165227. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165228. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165229. void PNGAPI
  165230. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  165231. {
  165232. #ifdef PNG_USE_LOCAL_ARRAYS
  165233. PNG_CONST PNG_IDAT;
  165234. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  165235. 0xff};
  165236. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  165237. #endif
  165238. int ret;
  165239. if(png_ptr == NULL) return;
  165240. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  165241. png_ptr->row_number, png_ptr->pass);
  165242. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165243. png_read_start_row(png_ptr);
  165244. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  165245. {
  165246. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  165247. if (png_ptr->transformations & PNG_INVERT_MONO)
  165248. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  165249. #endif
  165250. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  165251. if (png_ptr->transformations & PNG_FILLER)
  165252. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  165253. #endif
  165254. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  165255. if (png_ptr->transformations & PNG_PACKSWAP)
  165256. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  165257. #endif
  165258. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  165259. if (png_ptr->transformations & PNG_PACK)
  165260. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  165261. #endif
  165262. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  165263. if (png_ptr->transformations & PNG_SHIFT)
  165264. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  165265. #endif
  165266. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  165267. if (png_ptr->transformations & PNG_BGR)
  165268. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  165269. #endif
  165270. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  165271. if (png_ptr->transformations & PNG_SWAP_BYTES)
  165272. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  165273. #endif
  165274. }
  165275. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165276. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  165277. {
  165278. switch (png_ptr->pass)
  165279. {
  165280. case 0:
  165281. if (png_ptr->row_number & 0x07)
  165282. {
  165283. if (dsp_row != NULL)
  165284. png_combine_row(png_ptr, dsp_row,
  165285. png_pass_dsp_mask[png_ptr->pass]);
  165286. png_read_finish_row(png_ptr);
  165287. return;
  165288. }
  165289. break;
  165290. case 1:
  165291. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  165292. {
  165293. if (dsp_row != NULL)
  165294. png_combine_row(png_ptr, dsp_row,
  165295. png_pass_dsp_mask[png_ptr->pass]);
  165296. png_read_finish_row(png_ptr);
  165297. return;
  165298. }
  165299. break;
  165300. case 2:
  165301. if ((png_ptr->row_number & 0x07) != 4)
  165302. {
  165303. if (dsp_row != NULL && (png_ptr->row_number & 4))
  165304. png_combine_row(png_ptr, dsp_row,
  165305. png_pass_dsp_mask[png_ptr->pass]);
  165306. png_read_finish_row(png_ptr);
  165307. return;
  165308. }
  165309. break;
  165310. case 3:
  165311. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  165312. {
  165313. if (dsp_row != NULL)
  165314. png_combine_row(png_ptr, dsp_row,
  165315. png_pass_dsp_mask[png_ptr->pass]);
  165316. png_read_finish_row(png_ptr);
  165317. return;
  165318. }
  165319. break;
  165320. case 4:
  165321. if ((png_ptr->row_number & 3) != 2)
  165322. {
  165323. if (dsp_row != NULL && (png_ptr->row_number & 2))
  165324. png_combine_row(png_ptr, dsp_row,
  165325. png_pass_dsp_mask[png_ptr->pass]);
  165326. png_read_finish_row(png_ptr);
  165327. return;
  165328. }
  165329. break;
  165330. case 5:
  165331. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  165332. {
  165333. if (dsp_row != NULL)
  165334. png_combine_row(png_ptr, dsp_row,
  165335. png_pass_dsp_mask[png_ptr->pass]);
  165336. png_read_finish_row(png_ptr);
  165337. return;
  165338. }
  165339. break;
  165340. case 6:
  165341. if (!(png_ptr->row_number & 1))
  165342. {
  165343. png_read_finish_row(png_ptr);
  165344. return;
  165345. }
  165346. break;
  165347. }
  165348. }
  165349. #endif
  165350. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  165351. png_error(png_ptr, "Invalid attempt to read row data");
  165352. png_ptr->zstream.next_out = png_ptr->row_buf;
  165353. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165354. do
  165355. {
  165356. if (!(png_ptr->zstream.avail_in))
  165357. {
  165358. while (!png_ptr->idat_size)
  165359. {
  165360. png_byte chunk_length[4];
  165361. png_crc_finish(png_ptr, 0);
  165362. png_read_data(png_ptr, chunk_length, 4);
  165363. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  165364. png_reset_crc(png_ptr);
  165365. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165366. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165367. png_error(png_ptr, "Not enough image data");
  165368. }
  165369. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  165370. png_ptr->zstream.next_in = png_ptr->zbuf;
  165371. if (png_ptr->zbuf_size > png_ptr->idat_size)
  165372. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  165373. png_crc_read(png_ptr, png_ptr->zbuf,
  165374. (png_size_t)png_ptr->zstream.avail_in);
  165375. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  165376. }
  165377. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  165378. if (ret == Z_STREAM_END)
  165379. {
  165380. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  165381. png_ptr->idat_size)
  165382. png_error(png_ptr, "Extra compressed data");
  165383. png_ptr->mode |= PNG_AFTER_IDAT;
  165384. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  165385. break;
  165386. }
  165387. if (ret != Z_OK)
  165388. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  165389. "Decompression error");
  165390. } while (png_ptr->zstream.avail_out);
  165391. png_ptr->row_info.color_type = png_ptr->color_type;
  165392. png_ptr->row_info.width = png_ptr->iwidth;
  165393. png_ptr->row_info.channels = png_ptr->channels;
  165394. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  165395. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  165396. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  165397. png_ptr->row_info.width);
  165398. if(png_ptr->row_buf[0])
  165399. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  165400. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  165401. (int)(png_ptr->row_buf[0]));
  165402. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  165403. png_ptr->rowbytes + 1);
  165404. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  165405. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  165406. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  165407. {
  165408. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  165409. }
  165410. #endif
  165411. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  165412. png_do_read_transformations(png_ptr);
  165413. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165414. if (png_ptr->interlaced &&
  165415. (png_ptr->transformations & PNG_INTERLACE))
  165416. {
  165417. if (png_ptr->pass < 6)
  165418. png_do_read_interlace(png_ptr);
  165419. if (dsp_row != NULL)
  165420. png_combine_row(png_ptr, dsp_row,
  165421. png_pass_dsp_mask[png_ptr->pass]);
  165422. if (row != NULL)
  165423. png_combine_row(png_ptr, row,
  165424. png_pass_mask[png_ptr->pass]);
  165425. }
  165426. else
  165427. #endif
  165428. {
  165429. if (row != NULL)
  165430. png_combine_row(png_ptr, row, 0xff);
  165431. if (dsp_row != NULL)
  165432. png_combine_row(png_ptr, dsp_row, 0xff);
  165433. }
  165434. png_read_finish_row(png_ptr);
  165435. if (png_ptr->read_row_fn != NULL)
  165436. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  165437. }
  165438. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165439. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165440. void PNGAPI
  165441. png_read_rows(png_structp png_ptr, png_bytepp row,
  165442. png_bytepp display_row, png_uint_32 num_rows)
  165443. {
  165444. png_uint_32 i;
  165445. png_bytepp rp;
  165446. png_bytepp dp;
  165447. png_debug(1, "in png_read_rows\n");
  165448. if(png_ptr == NULL) return;
  165449. rp = row;
  165450. dp = display_row;
  165451. if (rp != NULL && dp != NULL)
  165452. for (i = 0; i < num_rows; i++)
  165453. {
  165454. png_bytep rptr = *rp++;
  165455. png_bytep dptr = *dp++;
  165456. png_read_row(png_ptr, rptr, dptr);
  165457. }
  165458. else if(rp != NULL)
  165459. for (i = 0; i < num_rows; i++)
  165460. {
  165461. png_bytep rptr = *rp;
  165462. png_read_row(png_ptr, rptr, png_bytep_NULL);
  165463. rp++;
  165464. }
  165465. else if(dp != NULL)
  165466. for (i = 0; i < num_rows; i++)
  165467. {
  165468. png_bytep dptr = *dp;
  165469. png_read_row(png_ptr, png_bytep_NULL, dptr);
  165470. dp++;
  165471. }
  165472. }
  165473. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165474. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165475. void PNGAPI
  165476. png_read_image(png_structp png_ptr, png_bytepp image)
  165477. {
  165478. png_uint_32 i,image_height;
  165479. int pass, j;
  165480. png_bytepp rp;
  165481. png_debug(1, "in png_read_image\n");
  165482. if(png_ptr == NULL) return;
  165483. #ifdef PNG_READ_INTERLACING_SUPPORTED
  165484. pass = png_set_interlace_handling(png_ptr);
  165485. #else
  165486. if (png_ptr->interlaced)
  165487. png_error(png_ptr,
  165488. "Cannot read interlaced image -- interlace handler disabled.");
  165489. pass = 1;
  165490. #endif
  165491. image_height=png_ptr->height;
  165492. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  165493. for (j = 0; j < pass; j++)
  165494. {
  165495. rp = image;
  165496. for (i = 0; i < image_height; i++)
  165497. {
  165498. png_read_row(png_ptr, *rp, png_bytep_NULL);
  165499. rp++;
  165500. }
  165501. }
  165502. }
  165503. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165504. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165505. void PNGAPI
  165506. png_read_end(png_structp png_ptr, png_infop info_ptr)
  165507. {
  165508. png_byte chunk_length[4];
  165509. png_uint_32 length;
  165510. png_debug(1, "in png_read_end\n");
  165511. if(png_ptr == NULL) return;
  165512. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  165513. do
  165514. {
  165515. #ifdef PNG_USE_LOCAL_ARRAYS
  165516. PNG_CONST PNG_IHDR;
  165517. PNG_CONST PNG_IDAT;
  165518. PNG_CONST PNG_IEND;
  165519. PNG_CONST PNG_PLTE;
  165520. #if defined(PNG_READ_bKGD_SUPPORTED)
  165521. PNG_CONST PNG_bKGD;
  165522. #endif
  165523. #if defined(PNG_READ_cHRM_SUPPORTED)
  165524. PNG_CONST PNG_cHRM;
  165525. #endif
  165526. #if defined(PNG_READ_gAMA_SUPPORTED)
  165527. PNG_CONST PNG_gAMA;
  165528. #endif
  165529. #if defined(PNG_READ_hIST_SUPPORTED)
  165530. PNG_CONST PNG_hIST;
  165531. #endif
  165532. #if defined(PNG_READ_iCCP_SUPPORTED)
  165533. PNG_CONST PNG_iCCP;
  165534. #endif
  165535. #if defined(PNG_READ_iTXt_SUPPORTED)
  165536. PNG_CONST PNG_iTXt;
  165537. #endif
  165538. #if defined(PNG_READ_oFFs_SUPPORTED)
  165539. PNG_CONST PNG_oFFs;
  165540. #endif
  165541. #if defined(PNG_READ_pCAL_SUPPORTED)
  165542. PNG_CONST PNG_pCAL;
  165543. #endif
  165544. #if defined(PNG_READ_pHYs_SUPPORTED)
  165545. PNG_CONST PNG_pHYs;
  165546. #endif
  165547. #if defined(PNG_READ_sBIT_SUPPORTED)
  165548. PNG_CONST PNG_sBIT;
  165549. #endif
  165550. #if defined(PNG_READ_sCAL_SUPPORTED)
  165551. PNG_CONST PNG_sCAL;
  165552. #endif
  165553. #if defined(PNG_READ_sPLT_SUPPORTED)
  165554. PNG_CONST PNG_sPLT;
  165555. #endif
  165556. #if defined(PNG_READ_sRGB_SUPPORTED)
  165557. PNG_CONST PNG_sRGB;
  165558. #endif
  165559. #if defined(PNG_READ_tEXt_SUPPORTED)
  165560. PNG_CONST PNG_tEXt;
  165561. #endif
  165562. #if defined(PNG_READ_tIME_SUPPORTED)
  165563. PNG_CONST PNG_tIME;
  165564. #endif
  165565. #if defined(PNG_READ_tRNS_SUPPORTED)
  165566. PNG_CONST PNG_tRNS;
  165567. #endif
  165568. #if defined(PNG_READ_zTXt_SUPPORTED)
  165569. PNG_CONST PNG_zTXt;
  165570. #endif
  165571. #endif /* PNG_USE_LOCAL_ARRAYS */
  165572. png_read_data(png_ptr, chunk_length, 4);
  165573. length = png_get_uint_31(png_ptr,chunk_length);
  165574. png_reset_crc(png_ptr);
  165575. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165576. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165577. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165578. png_handle_IHDR(png_ptr, info_ptr, length);
  165579. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165580. png_handle_IEND(png_ptr, info_ptr, length);
  165581. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165582. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165583. {
  165584. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165585. {
  165586. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165587. png_error(png_ptr, "Too many IDAT's found");
  165588. }
  165589. png_handle_unknown(png_ptr, info_ptr, length);
  165590. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165591. png_ptr->mode |= PNG_HAVE_PLTE;
  165592. }
  165593. #endif
  165594. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165595. {
  165596. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165597. png_error(png_ptr, "Too many IDAT's found");
  165598. png_crc_finish(png_ptr, length);
  165599. }
  165600. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165601. png_handle_PLTE(png_ptr, info_ptr, length);
  165602. #if defined(PNG_READ_bKGD_SUPPORTED)
  165603. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165604. png_handle_bKGD(png_ptr, info_ptr, length);
  165605. #endif
  165606. #if defined(PNG_READ_cHRM_SUPPORTED)
  165607. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165608. png_handle_cHRM(png_ptr, info_ptr, length);
  165609. #endif
  165610. #if defined(PNG_READ_gAMA_SUPPORTED)
  165611. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165612. png_handle_gAMA(png_ptr, info_ptr, length);
  165613. #endif
  165614. #if defined(PNG_READ_hIST_SUPPORTED)
  165615. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165616. png_handle_hIST(png_ptr, info_ptr, length);
  165617. #endif
  165618. #if defined(PNG_READ_oFFs_SUPPORTED)
  165619. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165620. png_handle_oFFs(png_ptr, info_ptr, length);
  165621. #endif
  165622. #if defined(PNG_READ_pCAL_SUPPORTED)
  165623. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165624. png_handle_pCAL(png_ptr, info_ptr, length);
  165625. #endif
  165626. #if defined(PNG_READ_sCAL_SUPPORTED)
  165627. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165628. png_handle_sCAL(png_ptr, info_ptr, length);
  165629. #endif
  165630. #if defined(PNG_READ_pHYs_SUPPORTED)
  165631. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165632. png_handle_pHYs(png_ptr, info_ptr, length);
  165633. #endif
  165634. #if defined(PNG_READ_sBIT_SUPPORTED)
  165635. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165636. png_handle_sBIT(png_ptr, info_ptr, length);
  165637. #endif
  165638. #if defined(PNG_READ_sRGB_SUPPORTED)
  165639. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165640. png_handle_sRGB(png_ptr, info_ptr, length);
  165641. #endif
  165642. #if defined(PNG_READ_iCCP_SUPPORTED)
  165643. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165644. png_handle_iCCP(png_ptr, info_ptr, length);
  165645. #endif
  165646. #if defined(PNG_READ_sPLT_SUPPORTED)
  165647. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165648. png_handle_sPLT(png_ptr, info_ptr, length);
  165649. #endif
  165650. #if defined(PNG_READ_tEXt_SUPPORTED)
  165651. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165652. png_handle_tEXt(png_ptr, info_ptr, length);
  165653. #endif
  165654. #if defined(PNG_READ_tIME_SUPPORTED)
  165655. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165656. png_handle_tIME(png_ptr, info_ptr, length);
  165657. #endif
  165658. #if defined(PNG_READ_tRNS_SUPPORTED)
  165659. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165660. png_handle_tRNS(png_ptr, info_ptr, length);
  165661. #endif
  165662. #if defined(PNG_READ_zTXt_SUPPORTED)
  165663. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165664. png_handle_zTXt(png_ptr, info_ptr, length);
  165665. #endif
  165666. #if defined(PNG_READ_iTXt_SUPPORTED)
  165667. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165668. png_handle_iTXt(png_ptr, info_ptr, length);
  165669. #endif
  165670. else
  165671. png_handle_unknown(png_ptr, info_ptr, length);
  165672. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165673. }
  165674. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165675. void PNGAPI
  165676. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165677. png_infopp end_info_ptr_ptr)
  165678. {
  165679. png_structp png_ptr = NULL;
  165680. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165681. #ifdef PNG_USER_MEM_SUPPORTED
  165682. png_free_ptr free_fn;
  165683. png_voidp mem_ptr;
  165684. #endif
  165685. png_debug(1, "in png_destroy_read_struct\n");
  165686. if (png_ptr_ptr != NULL)
  165687. png_ptr = *png_ptr_ptr;
  165688. if (info_ptr_ptr != NULL)
  165689. info_ptr = *info_ptr_ptr;
  165690. if (end_info_ptr_ptr != NULL)
  165691. end_info_ptr = *end_info_ptr_ptr;
  165692. #ifdef PNG_USER_MEM_SUPPORTED
  165693. free_fn = png_ptr->free_fn;
  165694. mem_ptr = png_ptr->mem_ptr;
  165695. #endif
  165696. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165697. if (info_ptr != NULL)
  165698. {
  165699. #if defined(PNG_TEXT_SUPPORTED)
  165700. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165701. #endif
  165702. #ifdef PNG_USER_MEM_SUPPORTED
  165703. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165704. (png_voidp)mem_ptr);
  165705. #else
  165706. png_destroy_struct((png_voidp)info_ptr);
  165707. #endif
  165708. *info_ptr_ptr = NULL;
  165709. }
  165710. if (end_info_ptr != NULL)
  165711. {
  165712. #if defined(PNG_READ_TEXT_SUPPORTED)
  165713. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165714. #endif
  165715. #ifdef PNG_USER_MEM_SUPPORTED
  165716. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165717. (png_voidp)mem_ptr);
  165718. #else
  165719. png_destroy_struct((png_voidp)end_info_ptr);
  165720. #endif
  165721. *end_info_ptr_ptr = NULL;
  165722. }
  165723. if (png_ptr != NULL)
  165724. {
  165725. #ifdef PNG_USER_MEM_SUPPORTED
  165726. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165727. (png_voidp)mem_ptr);
  165728. #else
  165729. png_destroy_struct((png_voidp)png_ptr);
  165730. #endif
  165731. *png_ptr_ptr = NULL;
  165732. }
  165733. }
  165734. void /* PRIVATE */
  165735. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165736. {
  165737. #ifdef PNG_SETJMP_SUPPORTED
  165738. jmp_buf tmp_jmp;
  165739. #endif
  165740. png_error_ptr error_fn;
  165741. png_error_ptr warning_fn;
  165742. png_voidp error_ptr;
  165743. #ifdef PNG_USER_MEM_SUPPORTED
  165744. png_free_ptr free_fn;
  165745. #endif
  165746. png_debug(1, "in png_read_destroy\n");
  165747. if (info_ptr != NULL)
  165748. png_info_destroy(png_ptr, info_ptr);
  165749. if (end_info_ptr != NULL)
  165750. png_info_destroy(png_ptr, end_info_ptr);
  165751. png_free(png_ptr, png_ptr->zbuf);
  165752. png_free(png_ptr, png_ptr->big_row_buf);
  165753. png_free(png_ptr, png_ptr->prev_row);
  165754. #if defined(PNG_READ_DITHER_SUPPORTED)
  165755. png_free(png_ptr, png_ptr->palette_lookup);
  165756. png_free(png_ptr, png_ptr->dither_index);
  165757. #endif
  165758. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165759. png_free(png_ptr, png_ptr->gamma_table);
  165760. #endif
  165761. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165762. png_free(png_ptr, png_ptr->gamma_from_1);
  165763. png_free(png_ptr, png_ptr->gamma_to_1);
  165764. #endif
  165765. #ifdef PNG_FREE_ME_SUPPORTED
  165766. if (png_ptr->free_me & PNG_FREE_PLTE)
  165767. png_zfree(png_ptr, png_ptr->palette);
  165768. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165769. #else
  165770. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165771. png_zfree(png_ptr, png_ptr->palette);
  165772. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165773. #endif
  165774. #if defined(PNG_tRNS_SUPPORTED) || \
  165775. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165776. #ifdef PNG_FREE_ME_SUPPORTED
  165777. if (png_ptr->free_me & PNG_FREE_TRNS)
  165778. png_free(png_ptr, png_ptr->trans);
  165779. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165780. #else
  165781. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165782. png_free(png_ptr, png_ptr->trans);
  165783. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165784. #endif
  165785. #endif
  165786. #if defined(PNG_READ_hIST_SUPPORTED)
  165787. #ifdef PNG_FREE_ME_SUPPORTED
  165788. if (png_ptr->free_me & PNG_FREE_HIST)
  165789. png_free(png_ptr, png_ptr->hist);
  165790. png_ptr->free_me &= ~PNG_FREE_HIST;
  165791. #else
  165792. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165793. png_free(png_ptr, png_ptr->hist);
  165794. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165795. #endif
  165796. #endif
  165797. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165798. if (png_ptr->gamma_16_table != NULL)
  165799. {
  165800. int i;
  165801. int istop = (1 << (8 - png_ptr->gamma_shift));
  165802. for (i = 0; i < istop; i++)
  165803. {
  165804. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165805. }
  165806. png_free(png_ptr, png_ptr->gamma_16_table);
  165807. }
  165808. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165809. if (png_ptr->gamma_16_from_1 != NULL)
  165810. {
  165811. int i;
  165812. int istop = (1 << (8 - png_ptr->gamma_shift));
  165813. for (i = 0; i < istop; i++)
  165814. {
  165815. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165816. }
  165817. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165818. }
  165819. if (png_ptr->gamma_16_to_1 != NULL)
  165820. {
  165821. int i;
  165822. int istop = (1 << (8 - png_ptr->gamma_shift));
  165823. for (i = 0; i < istop; i++)
  165824. {
  165825. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165826. }
  165827. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165828. }
  165829. #endif
  165830. #endif
  165831. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165832. png_free(png_ptr, png_ptr->time_buffer);
  165833. #endif
  165834. inflateEnd(&png_ptr->zstream);
  165835. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165836. png_free(png_ptr, png_ptr->save_buffer);
  165837. #endif
  165838. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165839. #ifdef PNG_TEXT_SUPPORTED
  165840. png_free(png_ptr, png_ptr->current_text);
  165841. #endif /* PNG_TEXT_SUPPORTED */
  165842. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165843. #ifdef PNG_SETJMP_SUPPORTED
  165844. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165845. #endif
  165846. error_fn = png_ptr->error_fn;
  165847. warning_fn = png_ptr->warning_fn;
  165848. error_ptr = png_ptr->error_ptr;
  165849. #ifdef PNG_USER_MEM_SUPPORTED
  165850. free_fn = png_ptr->free_fn;
  165851. #endif
  165852. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165853. png_ptr->error_fn = error_fn;
  165854. png_ptr->warning_fn = warning_fn;
  165855. png_ptr->error_ptr = error_ptr;
  165856. #ifdef PNG_USER_MEM_SUPPORTED
  165857. png_ptr->free_fn = free_fn;
  165858. #endif
  165859. #ifdef PNG_SETJMP_SUPPORTED
  165860. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165861. #endif
  165862. }
  165863. void PNGAPI
  165864. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165865. {
  165866. if(png_ptr == NULL) return;
  165867. png_ptr->read_row_fn = read_row_fn;
  165868. }
  165869. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165870. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165871. void PNGAPI
  165872. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165873. int transforms,
  165874. voidp params)
  165875. {
  165876. int row;
  165877. if(png_ptr == NULL) return;
  165878. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165879. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165880. png_set_invert_alpha(png_ptr);
  165881. #endif
  165882. png_read_info(png_ptr, info_ptr);
  165883. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165884. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165885. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165886. if (transforms & PNG_TRANSFORM_STRIP_16)
  165887. png_set_strip_16(png_ptr);
  165888. #endif
  165889. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165890. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165891. png_set_strip_alpha(png_ptr);
  165892. #endif
  165893. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165894. if (transforms & PNG_TRANSFORM_PACKING)
  165895. png_set_packing(png_ptr);
  165896. #endif
  165897. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165898. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165899. png_set_packswap(png_ptr);
  165900. #endif
  165901. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165902. if (transforms & PNG_TRANSFORM_EXPAND)
  165903. if ((png_ptr->bit_depth < 8) ||
  165904. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165905. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165906. png_set_expand(png_ptr);
  165907. #endif
  165908. #if defined(PNG_READ_INVERT_SUPPORTED)
  165909. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165910. png_set_invert_mono(png_ptr);
  165911. #endif
  165912. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165913. if ((transforms & PNG_TRANSFORM_SHIFT)
  165914. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165915. {
  165916. png_color_8p sig_bit;
  165917. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165918. png_set_shift(png_ptr, sig_bit);
  165919. }
  165920. #endif
  165921. #if defined(PNG_READ_BGR_SUPPORTED)
  165922. if (transforms & PNG_TRANSFORM_BGR)
  165923. png_set_bgr(png_ptr);
  165924. #endif
  165925. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165926. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165927. png_set_swap_alpha(png_ptr);
  165928. #endif
  165929. #if defined(PNG_READ_SWAP_SUPPORTED)
  165930. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165931. png_set_swap(png_ptr);
  165932. #endif
  165933. png_read_update_info(png_ptr, info_ptr);
  165934. #ifdef PNG_FREE_ME_SUPPORTED
  165935. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165936. #endif
  165937. if(info_ptr->row_pointers == NULL)
  165938. {
  165939. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165940. info_ptr->height * png_sizeof(png_bytep));
  165941. #ifdef PNG_FREE_ME_SUPPORTED
  165942. info_ptr->free_me |= PNG_FREE_ROWS;
  165943. #endif
  165944. for (row = 0; row < (int)info_ptr->height; row++)
  165945. {
  165946. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165947. png_get_rowbytes(png_ptr, info_ptr));
  165948. }
  165949. }
  165950. png_read_image(png_ptr, info_ptr->row_pointers);
  165951. info_ptr->valid |= PNG_INFO_IDAT;
  165952. png_read_end(png_ptr, info_ptr);
  165953. transforms = transforms; /* quiet compiler warnings */
  165954. params = params;
  165955. }
  165956. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165957. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165958. #endif /* PNG_READ_SUPPORTED */
  165959. /*** End of inlined file: pngread.c ***/
  165960. /*** Start of inlined file: pngpread.c ***/
  165961. #define PNG_INTERNAL
  165962. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165963. #define PNG_READ_SIG_MODE 0
  165964. #define PNG_READ_CHUNK_MODE 1
  165965. #define PNG_READ_IDAT_MODE 2
  165966. #define PNG_SKIP_MODE 3
  165967. #define PNG_READ_tEXt_MODE 4
  165968. #define PNG_READ_zTXt_MODE 5
  165969. #define PNG_READ_DONE_MODE 6
  165970. #define PNG_READ_iTXt_MODE 7
  165971. #define PNG_ERROR_MODE 8
  165972. void PNGAPI
  165973. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165974. png_bytep buffer, png_size_t buffer_size)
  165975. {
  165976. if(png_ptr == NULL) return;
  165977. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165978. while (png_ptr->buffer_size)
  165979. {
  165980. png_process_some_data(png_ptr, info_ptr);
  165981. }
  165982. }
  165983. void /* PRIVATE */
  165984. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165985. {
  165986. if(png_ptr == NULL) return;
  165987. switch (png_ptr->process_mode)
  165988. {
  165989. case PNG_READ_SIG_MODE:
  165990. {
  165991. png_push_read_sig(png_ptr, info_ptr);
  165992. break;
  165993. }
  165994. case PNG_READ_CHUNK_MODE:
  165995. {
  165996. png_push_read_chunk(png_ptr, info_ptr);
  165997. break;
  165998. }
  165999. case PNG_READ_IDAT_MODE:
  166000. {
  166001. png_push_read_IDAT(png_ptr);
  166002. break;
  166003. }
  166004. #if defined(PNG_READ_tEXt_SUPPORTED)
  166005. case PNG_READ_tEXt_MODE:
  166006. {
  166007. png_push_read_tEXt(png_ptr, info_ptr);
  166008. break;
  166009. }
  166010. #endif
  166011. #if defined(PNG_READ_zTXt_SUPPORTED)
  166012. case PNG_READ_zTXt_MODE:
  166013. {
  166014. png_push_read_zTXt(png_ptr, info_ptr);
  166015. break;
  166016. }
  166017. #endif
  166018. #if defined(PNG_READ_iTXt_SUPPORTED)
  166019. case PNG_READ_iTXt_MODE:
  166020. {
  166021. png_push_read_iTXt(png_ptr, info_ptr);
  166022. break;
  166023. }
  166024. #endif
  166025. case PNG_SKIP_MODE:
  166026. {
  166027. png_push_crc_finish(png_ptr);
  166028. break;
  166029. }
  166030. default:
  166031. {
  166032. png_ptr->buffer_size = 0;
  166033. break;
  166034. }
  166035. }
  166036. }
  166037. void /* PRIVATE */
  166038. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  166039. {
  166040. png_size_t num_checked = png_ptr->sig_bytes,
  166041. num_to_check = 8 - num_checked;
  166042. if (png_ptr->buffer_size < num_to_check)
  166043. {
  166044. num_to_check = png_ptr->buffer_size;
  166045. }
  166046. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  166047. num_to_check);
  166048. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  166049. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  166050. {
  166051. if (num_checked < 4 &&
  166052. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  166053. png_error(png_ptr, "Not a PNG file");
  166054. else
  166055. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  166056. }
  166057. else
  166058. {
  166059. if (png_ptr->sig_bytes >= 8)
  166060. {
  166061. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166062. }
  166063. }
  166064. }
  166065. void /* PRIVATE */
  166066. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  166067. {
  166068. #ifdef PNG_USE_LOCAL_ARRAYS
  166069. PNG_CONST PNG_IHDR;
  166070. PNG_CONST PNG_IDAT;
  166071. PNG_CONST PNG_IEND;
  166072. PNG_CONST PNG_PLTE;
  166073. #if defined(PNG_READ_bKGD_SUPPORTED)
  166074. PNG_CONST PNG_bKGD;
  166075. #endif
  166076. #if defined(PNG_READ_cHRM_SUPPORTED)
  166077. PNG_CONST PNG_cHRM;
  166078. #endif
  166079. #if defined(PNG_READ_gAMA_SUPPORTED)
  166080. PNG_CONST PNG_gAMA;
  166081. #endif
  166082. #if defined(PNG_READ_hIST_SUPPORTED)
  166083. PNG_CONST PNG_hIST;
  166084. #endif
  166085. #if defined(PNG_READ_iCCP_SUPPORTED)
  166086. PNG_CONST PNG_iCCP;
  166087. #endif
  166088. #if defined(PNG_READ_iTXt_SUPPORTED)
  166089. PNG_CONST PNG_iTXt;
  166090. #endif
  166091. #if defined(PNG_READ_oFFs_SUPPORTED)
  166092. PNG_CONST PNG_oFFs;
  166093. #endif
  166094. #if defined(PNG_READ_pCAL_SUPPORTED)
  166095. PNG_CONST PNG_pCAL;
  166096. #endif
  166097. #if defined(PNG_READ_pHYs_SUPPORTED)
  166098. PNG_CONST PNG_pHYs;
  166099. #endif
  166100. #if defined(PNG_READ_sBIT_SUPPORTED)
  166101. PNG_CONST PNG_sBIT;
  166102. #endif
  166103. #if defined(PNG_READ_sCAL_SUPPORTED)
  166104. PNG_CONST PNG_sCAL;
  166105. #endif
  166106. #if defined(PNG_READ_sRGB_SUPPORTED)
  166107. PNG_CONST PNG_sRGB;
  166108. #endif
  166109. #if defined(PNG_READ_sPLT_SUPPORTED)
  166110. PNG_CONST PNG_sPLT;
  166111. #endif
  166112. #if defined(PNG_READ_tEXt_SUPPORTED)
  166113. PNG_CONST PNG_tEXt;
  166114. #endif
  166115. #if defined(PNG_READ_tIME_SUPPORTED)
  166116. PNG_CONST PNG_tIME;
  166117. #endif
  166118. #if defined(PNG_READ_tRNS_SUPPORTED)
  166119. PNG_CONST PNG_tRNS;
  166120. #endif
  166121. #if defined(PNG_READ_zTXt_SUPPORTED)
  166122. PNG_CONST PNG_zTXt;
  166123. #endif
  166124. #endif /* PNG_USE_LOCAL_ARRAYS */
  166125. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166126. {
  166127. png_byte chunk_length[4];
  166128. if (png_ptr->buffer_size < 8)
  166129. {
  166130. png_push_save_buffer(png_ptr);
  166131. return;
  166132. }
  166133. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166134. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166135. png_reset_crc(png_ptr);
  166136. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166137. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166138. }
  166139. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166140. if(png_ptr->mode & PNG_AFTER_IDAT)
  166141. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  166142. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 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_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  166150. }
  166151. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  166152. {
  166153. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166154. {
  166155. png_push_save_buffer(png_ptr);
  166156. return;
  166157. }
  166158. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  166159. png_ptr->process_mode = PNG_READ_DONE_MODE;
  166160. png_push_have_end(png_ptr, info_ptr);
  166161. }
  166162. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  166163. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  166164. {
  166165. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166166. {
  166167. png_push_save_buffer(png_ptr);
  166168. return;
  166169. }
  166170. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166171. png_ptr->mode |= PNG_HAVE_IDAT;
  166172. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166173. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166174. png_ptr->mode |= PNG_HAVE_PLTE;
  166175. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166176. {
  166177. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166178. png_error(png_ptr, "Missing IHDR before IDAT");
  166179. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166180. !(png_ptr->mode & PNG_HAVE_PLTE))
  166181. png_error(png_ptr, "Missing PLTE before IDAT");
  166182. }
  166183. }
  166184. #endif
  166185. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166186. {
  166187. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166188. {
  166189. png_push_save_buffer(png_ptr);
  166190. return;
  166191. }
  166192. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  166193. }
  166194. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166195. {
  166196. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166197. png_error(png_ptr, "Missing IHDR before IDAT");
  166198. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166199. !(png_ptr->mode & PNG_HAVE_PLTE))
  166200. png_error(png_ptr, "Missing PLTE before IDAT");
  166201. if (png_ptr->mode & PNG_HAVE_IDAT)
  166202. {
  166203. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  166204. if (png_ptr->push_length == 0)
  166205. return;
  166206. if (png_ptr->mode & PNG_AFTER_IDAT)
  166207. png_error(png_ptr, "Too many IDAT's found");
  166208. }
  166209. png_ptr->idat_size = png_ptr->push_length;
  166210. png_ptr->mode |= PNG_HAVE_IDAT;
  166211. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  166212. png_push_have_info(png_ptr, info_ptr);
  166213. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166214. png_ptr->zstream.next_out = png_ptr->row_buf;
  166215. return;
  166216. }
  166217. #if defined(PNG_READ_gAMA_SUPPORTED)
  166218. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  166219. {
  166220. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166221. {
  166222. png_push_save_buffer(png_ptr);
  166223. return;
  166224. }
  166225. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  166226. }
  166227. #endif
  166228. #if defined(PNG_READ_sBIT_SUPPORTED)
  166229. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  166230. {
  166231. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166232. {
  166233. png_push_save_buffer(png_ptr);
  166234. return;
  166235. }
  166236. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  166237. }
  166238. #endif
  166239. #if defined(PNG_READ_cHRM_SUPPORTED)
  166240. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  166241. {
  166242. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166243. {
  166244. png_push_save_buffer(png_ptr);
  166245. return;
  166246. }
  166247. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  166248. }
  166249. #endif
  166250. #if defined(PNG_READ_sRGB_SUPPORTED)
  166251. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  166252. {
  166253. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166254. {
  166255. png_push_save_buffer(png_ptr);
  166256. return;
  166257. }
  166258. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  166259. }
  166260. #endif
  166261. #if defined(PNG_READ_iCCP_SUPPORTED)
  166262. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  166263. {
  166264. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166265. {
  166266. png_push_save_buffer(png_ptr);
  166267. return;
  166268. }
  166269. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  166270. }
  166271. #endif
  166272. #if defined(PNG_READ_sPLT_SUPPORTED)
  166273. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  166274. {
  166275. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166276. {
  166277. png_push_save_buffer(png_ptr);
  166278. return;
  166279. }
  166280. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  166281. }
  166282. #endif
  166283. #if defined(PNG_READ_tRNS_SUPPORTED)
  166284. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  166285. {
  166286. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166287. {
  166288. png_push_save_buffer(png_ptr);
  166289. return;
  166290. }
  166291. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  166292. }
  166293. #endif
  166294. #if defined(PNG_READ_bKGD_SUPPORTED)
  166295. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  166296. {
  166297. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166298. {
  166299. png_push_save_buffer(png_ptr);
  166300. return;
  166301. }
  166302. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  166303. }
  166304. #endif
  166305. #if defined(PNG_READ_hIST_SUPPORTED)
  166306. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  166307. {
  166308. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166309. {
  166310. png_push_save_buffer(png_ptr);
  166311. return;
  166312. }
  166313. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  166314. }
  166315. #endif
  166316. #if defined(PNG_READ_pHYs_SUPPORTED)
  166317. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  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_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  166325. }
  166326. #endif
  166327. #if defined(PNG_READ_oFFs_SUPPORTED)
  166328. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  166329. {
  166330. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166331. {
  166332. png_push_save_buffer(png_ptr);
  166333. return;
  166334. }
  166335. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  166336. }
  166337. #endif
  166338. #if defined(PNG_READ_pCAL_SUPPORTED)
  166339. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  166340. {
  166341. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166342. {
  166343. png_push_save_buffer(png_ptr);
  166344. return;
  166345. }
  166346. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  166347. }
  166348. #endif
  166349. #if defined(PNG_READ_sCAL_SUPPORTED)
  166350. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  166351. {
  166352. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166353. {
  166354. png_push_save_buffer(png_ptr);
  166355. return;
  166356. }
  166357. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  166358. }
  166359. #endif
  166360. #if defined(PNG_READ_tIME_SUPPORTED)
  166361. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  166362. {
  166363. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166364. {
  166365. png_push_save_buffer(png_ptr);
  166366. return;
  166367. }
  166368. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  166369. }
  166370. #endif
  166371. #if defined(PNG_READ_tEXt_SUPPORTED)
  166372. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  166373. {
  166374. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166375. {
  166376. png_push_save_buffer(png_ptr);
  166377. return;
  166378. }
  166379. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  166380. }
  166381. #endif
  166382. #if defined(PNG_READ_zTXt_SUPPORTED)
  166383. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  166384. {
  166385. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166386. {
  166387. png_push_save_buffer(png_ptr);
  166388. return;
  166389. }
  166390. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  166391. }
  166392. #endif
  166393. #if defined(PNG_READ_iTXt_SUPPORTED)
  166394. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  166395. {
  166396. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166397. {
  166398. png_push_save_buffer(png_ptr);
  166399. return;
  166400. }
  166401. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  166402. }
  166403. #endif
  166404. else
  166405. {
  166406. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166407. {
  166408. png_push_save_buffer(png_ptr);
  166409. return;
  166410. }
  166411. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166412. }
  166413. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166414. }
  166415. void /* PRIVATE */
  166416. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  166417. {
  166418. png_ptr->process_mode = PNG_SKIP_MODE;
  166419. png_ptr->skip_length = skip;
  166420. }
  166421. void /* PRIVATE */
  166422. png_push_crc_finish(png_structp png_ptr)
  166423. {
  166424. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  166425. {
  166426. png_size_t save_size;
  166427. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  166428. save_size = (png_size_t)png_ptr->skip_length;
  166429. else
  166430. save_size = png_ptr->save_buffer_size;
  166431. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166432. png_ptr->skip_length -= save_size;
  166433. png_ptr->buffer_size -= save_size;
  166434. png_ptr->save_buffer_size -= save_size;
  166435. png_ptr->save_buffer_ptr += save_size;
  166436. }
  166437. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  166438. {
  166439. png_size_t save_size;
  166440. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  166441. save_size = (png_size_t)png_ptr->skip_length;
  166442. else
  166443. save_size = png_ptr->current_buffer_size;
  166444. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166445. png_ptr->skip_length -= save_size;
  166446. png_ptr->buffer_size -= save_size;
  166447. png_ptr->current_buffer_size -= save_size;
  166448. png_ptr->current_buffer_ptr += save_size;
  166449. }
  166450. if (!png_ptr->skip_length)
  166451. {
  166452. if (png_ptr->buffer_size < 4)
  166453. {
  166454. png_push_save_buffer(png_ptr);
  166455. return;
  166456. }
  166457. png_crc_finish(png_ptr, 0);
  166458. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166459. }
  166460. }
  166461. void PNGAPI
  166462. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  166463. {
  166464. png_bytep ptr;
  166465. if(png_ptr == NULL) return;
  166466. ptr = buffer;
  166467. if (png_ptr->save_buffer_size)
  166468. {
  166469. png_size_t save_size;
  166470. if (length < png_ptr->save_buffer_size)
  166471. save_size = length;
  166472. else
  166473. save_size = png_ptr->save_buffer_size;
  166474. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  166475. length -= save_size;
  166476. ptr += save_size;
  166477. png_ptr->buffer_size -= save_size;
  166478. png_ptr->save_buffer_size -= save_size;
  166479. png_ptr->save_buffer_ptr += save_size;
  166480. }
  166481. if (length && png_ptr->current_buffer_size)
  166482. {
  166483. png_size_t save_size;
  166484. if (length < png_ptr->current_buffer_size)
  166485. save_size = length;
  166486. else
  166487. save_size = png_ptr->current_buffer_size;
  166488. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  166489. png_ptr->buffer_size -= save_size;
  166490. png_ptr->current_buffer_size -= save_size;
  166491. png_ptr->current_buffer_ptr += save_size;
  166492. }
  166493. }
  166494. void /* PRIVATE */
  166495. png_push_save_buffer(png_structp png_ptr)
  166496. {
  166497. if (png_ptr->save_buffer_size)
  166498. {
  166499. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  166500. {
  166501. png_size_t i,istop;
  166502. png_bytep sp;
  166503. png_bytep dp;
  166504. istop = png_ptr->save_buffer_size;
  166505. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  166506. i < istop; i++, sp++, dp++)
  166507. {
  166508. *dp = *sp;
  166509. }
  166510. }
  166511. }
  166512. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  166513. png_ptr->save_buffer_max)
  166514. {
  166515. png_size_t new_max;
  166516. png_bytep old_buffer;
  166517. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166518. (png_ptr->current_buffer_size + 256))
  166519. {
  166520. png_error(png_ptr, "Potential overflow of save_buffer");
  166521. }
  166522. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166523. old_buffer = png_ptr->save_buffer;
  166524. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166525. (png_uint_32)new_max);
  166526. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166527. png_free(png_ptr, old_buffer);
  166528. png_ptr->save_buffer_max = new_max;
  166529. }
  166530. if (png_ptr->current_buffer_size)
  166531. {
  166532. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166533. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166534. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166535. png_ptr->current_buffer_size = 0;
  166536. }
  166537. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166538. png_ptr->buffer_size = 0;
  166539. }
  166540. void /* PRIVATE */
  166541. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166542. png_size_t buffer_length)
  166543. {
  166544. png_ptr->current_buffer = buffer;
  166545. png_ptr->current_buffer_size = buffer_length;
  166546. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166547. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166548. }
  166549. void /* PRIVATE */
  166550. png_push_read_IDAT(png_structp png_ptr)
  166551. {
  166552. #ifdef PNG_USE_LOCAL_ARRAYS
  166553. PNG_CONST PNG_IDAT;
  166554. #endif
  166555. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166556. {
  166557. png_byte chunk_length[4];
  166558. if (png_ptr->buffer_size < 8)
  166559. {
  166560. png_push_save_buffer(png_ptr);
  166561. return;
  166562. }
  166563. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166564. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166565. png_reset_crc(png_ptr);
  166566. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166567. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166568. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166569. {
  166570. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166571. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166572. png_error(png_ptr, "Not enough compressed data");
  166573. return;
  166574. }
  166575. png_ptr->idat_size = png_ptr->push_length;
  166576. }
  166577. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166578. {
  166579. png_size_t save_size;
  166580. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166581. {
  166582. save_size = (png_size_t)png_ptr->idat_size;
  166583. if((png_uint_32)save_size != png_ptr->idat_size)
  166584. png_error(png_ptr, "save_size overflowed in pngpread");
  166585. }
  166586. else
  166587. save_size = png_ptr->save_buffer_size;
  166588. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166589. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166590. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166591. png_ptr->idat_size -= save_size;
  166592. png_ptr->buffer_size -= save_size;
  166593. png_ptr->save_buffer_size -= save_size;
  166594. png_ptr->save_buffer_ptr += save_size;
  166595. }
  166596. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166597. {
  166598. png_size_t save_size;
  166599. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166600. {
  166601. save_size = (png_size_t)png_ptr->idat_size;
  166602. if((png_uint_32)save_size != png_ptr->idat_size)
  166603. png_error(png_ptr, "save_size overflowed in pngpread");
  166604. }
  166605. else
  166606. save_size = png_ptr->current_buffer_size;
  166607. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166608. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166609. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166610. png_ptr->idat_size -= save_size;
  166611. png_ptr->buffer_size -= save_size;
  166612. png_ptr->current_buffer_size -= save_size;
  166613. png_ptr->current_buffer_ptr += save_size;
  166614. }
  166615. if (!png_ptr->idat_size)
  166616. {
  166617. if (png_ptr->buffer_size < 4)
  166618. {
  166619. png_push_save_buffer(png_ptr);
  166620. return;
  166621. }
  166622. png_crc_finish(png_ptr, 0);
  166623. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166624. png_ptr->mode |= PNG_AFTER_IDAT;
  166625. }
  166626. }
  166627. void /* PRIVATE */
  166628. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166629. png_size_t buffer_length)
  166630. {
  166631. int ret;
  166632. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166633. png_error(png_ptr, "Extra compression data");
  166634. png_ptr->zstream.next_in = buffer;
  166635. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166636. for(;;)
  166637. {
  166638. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166639. if (ret != Z_OK)
  166640. {
  166641. if (ret == Z_STREAM_END)
  166642. {
  166643. if (png_ptr->zstream.avail_in)
  166644. png_error(png_ptr, "Extra compressed data");
  166645. if (!(png_ptr->zstream.avail_out))
  166646. {
  166647. png_push_process_row(png_ptr);
  166648. }
  166649. png_ptr->mode |= PNG_AFTER_IDAT;
  166650. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166651. break;
  166652. }
  166653. else if (ret == Z_BUF_ERROR)
  166654. break;
  166655. else
  166656. png_error(png_ptr, "Decompression Error");
  166657. }
  166658. if (!(png_ptr->zstream.avail_out))
  166659. {
  166660. if ((
  166661. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166662. png_ptr->interlaced && png_ptr->pass > 6) ||
  166663. (!png_ptr->interlaced &&
  166664. #endif
  166665. png_ptr->row_number == png_ptr->num_rows))
  166666. {
  166667. if (png_ptr->zstream.avail_in)
  166668. {
  166669. png_warning(png_ptr, "Too much data in IDAT chunks");
  166670. }
  166671. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166672. break;
  166673. }
  166674. png_push_process_row(png_ptr);
  166675. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166676. png_ptr->zstream.next_out = png_ptr->row_buf;
  166677. }
  166678. else
  166679. break;
  166680. }
  166681. }
  166682. void /* PRIVATE */
  166683. png_push_process_row(png_structp png_ptr)
  166684. {
  166685. png_ptr->row_info.color_type = png_ptr->color_type;
  166686. png_ptr->row_info.width = png_ptr->iwidth;
  166687. png_ptr->row_info.channels = png_ptr->channels;
  166688. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166689. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166690. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166691. png_ptr->row_info.width);
  166692. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166693. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166694. (int)(png_ptr->row_buf[0]));
  166695. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166696. png_ptr->rowbytes + 1);
  166697. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166698. png_do_read_transformations(png_ptr);
  166699. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166700. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166701. {
  166702. if (png_ptr->pass < 6)
  166703. png_do_read_interlace(png_ptr);
  166704. switch (png_ptr->pass)
  166705. {
  166706. case 0:
  166707. {
  166708. int i;
  166709. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166710. {
  166711. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166712. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166713. }
  166714. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166715. {
  166716. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166717. {
  166718. png_push_have_row(png_ptr, png_bytep_NULL);
  166719. png_read_push_finish_row(png_ptr);
  166720. }
  166721. }
  166722. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166723. {
  166724. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166725. {
  166726. png_push_have_row(png_ptr, png_bytep_NULL);
  166727. png_read_push_finish_row(png_ptr);
  166728. }
  166729. }
  166730. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166731. {
  166732. png_push_have_row(png_ptr, png_bytep_NULL);
  166733. png_read_push_finish_row(png_ptr);
  166734. }
  166735. break;
  166736. }
  166737. case 1:
  166738. {
  166739. int i;
  166740. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166741. {
  166742. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166743. png_read_push_finish_row(png_ptr);
  166744. }
  166745. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166746. {
  166747. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166748. {
  166749. png_push_have_row(png_ptr, png_bytep_NULL);
  166750. png_read_push_finish_row(png_ptr);
  166751. }
  166752. }
  166753. break;
  166754. }
  166755. case 2:
  166756. {
  166757. int i;
  166758. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166759. {
  166760. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166761. png_read_push_finish_row(png_ptr);
  166762. }
  166763. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166764. {
  166765. png_push_have_row(png_ptr, png_bytep_NULL);
  166766. png_read_push_finish_row(png_ptr);
  166767. }
  166768. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166769. {
  166770. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166771. {
  166772. png_push_have_row(png_ptr, png_bytep_NULL);
  166773. png_read_push_finish_row(png_ptr);
  166774. }
  166775. }
  166776. break;
  166777. }
  166778. case 3:
  166779. {
  166780. int i;
  166781. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166782. {
  166783. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166784. png_read_push_finish_row(png_ptr);
  166785. }
  166786. if (png_ptr->pass == 4) /* skip top two generated rows */
  166787. {
  166788. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166789. {
  166790. png_push_have_row(png_ptr, png_bytep_NULL);
  166791. png_read_push_finish_row(png_ptr);
  166792. }
  166793. }
  166794. break;
  166795. }
  166796. case 4:
  166797. {
  166798. int i;
  166799. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166800. {
  166801. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166802. png_read_push_finish_row(png_ptr);
  166803. }
  166804. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166805. {
  166806. png_push_have_row(png_ptr, png_bytep_NULL);
  166807. png_read_push_finish_row(png_ptr);
  166808. }
  166809. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166810. {
  166811. png_push_have_row(png_ptr, png_bytep_NULL);
  166812. png_read_push_finish_row(png_ptr);
  166813. }
  166814. break;
  166815. }
  166816. case 5:
  166817. {
  166818. int i;
  166819. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166820. {
  166821. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166822. png_read_push_finish_row(png_ptr);
  166823. }
  166824. if (png_ptr->pass == 6) /* skip top generated row */
  166825. {
  166826. png_push_have_row(png_ptr, png_bytep_NULL);
  166827. png_read_push_finish_row(png_ptr);
  166828. }
  166829. break;
  166830. }
  166831. case 6:
  166832. {
  166833. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166834. png_read_push_finish_row(png_ptr);
  166835. if (png_ptr->pass != 6)
  166836. break;
  166837. png_push_have_row(png_ptr, png_bytep_NULL);
  166838. png_read_push_finish_row(png_ptr);
  166839. }
  166840. }
  166841. }
  166842. else
  166843. #endif
  166844. {
  166845. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166846. png_read_push_finish_row(png_ptr);
  166847. }
  166848. }
  166849. void /* PRIVATE */
  166850. png_read_push_finish_row(png_structp png_ptr)
  166851. {
  166852. #ifdef PNG_USE_LOCAL_ARRAYS
  166853. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166854. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166855. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166856. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166857. #endif
  166858. png_ptr->row_number++;
  166859. if (png_ptr->row_number < png_ptr->num_rows)
  166860. return;
  166861. if (png_ptr->interlaced)
  166862. {
  166863. png_ptr->row_number = 0;
  166864. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166865. png_ptr->rowbytes + 1);
  166866. do
  166867. {
  166868. png_ptr->pass++;
  166869. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166870. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166871. (png_ptr->pass == 5 && png_ptr->width < 2))
  166872. png_ptr->pass++;
  166873. if (png_ptr->pass > 7)
  166874. png_ptr->pass--;
  166875. if (png_ptr->pass >= 7)
  166876. break;
  166877. png_ptr->iwidth = (png_ptr->width +
  166878. png_pass_inc[png_ptr->pass] - 1 -
  166879. png_pass_start[png_ptr->pass]) /
  166880. png_pass_inc[png_ptr->pass];
  166881. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166882. png_ptr->iwidth) + 1;
  166883. if (png_ptr->transformations & PNG_INTERLACE)
  166884. break;
  166885. png_ptr->num_rows = (png_ptr->height +
  166886. png_pass_yinc[png_ptr->pass] - 1 -
  166887. png_pass_ystart[png_ptr->pass]) /
  166888. png_pass_yinc[png_ptr->pass];
  166889. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166890. }
  166891. }
  166892. #if defined(PNG_READ_tEXt_SUPPORTED)
  166893. void /* PRIVATE */
  166894. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166895. length)
  166896. {
  166897. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166898. {
  166899. png_error(png_ptr, "Out of place tEXt");
  166900. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166901. }
  166902. #ifdef PNG_MAX_MALLOC_64K
  166903. png_ptr->skip_length = 0; /* This may not be necessary */
  166904. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166905. {
  166906. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166907. png_ptr->skip_length = length - (png_uint_32)65535L;
  166908. length = (png_uint_32)65535L;
  166909. }
  166910. #endif
  166911. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166912. (png_uint_32)(length+1));
  166913. png_ptr->current_text[length] = '\0';
  166914. png_ptr->current_text_ptr = png_ptr->current_text;
  166915. png_ptr->current_text_size = (png_size_t)length;
  166916. png_ptr->current_text_left = (png_size_t)length;
  166917. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166918. }
  166919. void /* PRIVATE */
  166920. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166921. {
  166922. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166923. {
  166924. png_size_t text_size;
  166925. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166926. text_size = png_ptr->buffer_size;
  166927. else
  166928. text_size = png_ptr->current_text_left;
  166929. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166930. png_ptr->current_text_left -= text_size;
  166931. png_ptr->current_text_ptr += text_size;
  166932. }
  166933. if (!(png_ptr->current_text_left))
  166934. {
  166935. png_textp text_ptr;
  166936. png_charp text;
  166937. png_charp key;
  166938. int ret;
  166939. if (png_ptr->buffer_size < 4)
  166940. {
  166941. png_push_save_buffer(png_ptr);
  166942. return;
  166943. }
  166944. png_push_crc_finish(png_ptr);
  166945. #if defined(PNG_MAX_MALLOC_64K)
  166946. if (png_ptr->skip_length)
  166947. return;
  166948. #endif
  166949. key = png_ptr->current_text;
  166950. for (text = key; *text; text++)
  166951. ;
  166952. if (text < key + png_ptr->current_text_size)
  166953. text++;
  166954. text_ptr = (png_textp)png_malloc(png_ptr,
  166955. (png_uint_32)png_sizeof(png_text));
  166956. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166957. text_ptr->key = key;
  166958. #ifdef PNG_iTXt_SUPPORTED
  166959. text_ptr->lang = NULL;
  166960. text_ptr->lang_key = NULL;
  166961. #endif
  166962. text_ptr->text = text;
  166963. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166964. png_free(png_ptr, key);
  166965. png_free(png_ptr, text_ptr);
  166966. png_ptr->current_text = NULL;
  166967. if (ret)
  166968. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166969. }
  166970. }
  166971. #endif
  166972. #if defined(PNG_READ_zTXt_SUPPORTED)
  166973. void /* PRIVATE */
  166974. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166975. length)
  166976. {
  166977. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166978. {
  166979. png_error(png_ptr, "Out of place zTXt");
  166980. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166981. }
  166982. #ifdef PNG_MAX_MALLOC_64K
  166983. if (length > (png_uint_32)65535L)
  166984. {
  166985. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166986. png_push_crc_skip(png_ptr, length);
  166987. return;
  166988. }
  166989. #endif
  166990. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166991. (png_uint_32)(length+1));
  166992. png_ptr->current_text[length] = '\0';
  166993. png_ptr->current_text_ptr = png_ptr->current_text;
  166994. png_ptr->current_text_size = (png_size_t)length;
  166995. png_ptr->current_text_left = (png_size_t)length;
  166996. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166997. }
  166998. void /* PRIVATE */
  166999. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  167000. {
  167001. if (png_ptr->buffer_size && png_ptr->current_text_left)
  167002. {
  167003. png_size_t text_size;
  167004. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  167005. text_size = png_ptr->buffer_size;
  167006. else
  167007. text_size = png_ptr->current_text_left;
  167008. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  167009. png_ptr->current_text_left -= text_size;
  167010. png_ptr->current_text_ptr += text_size;
  167011. }
  167012. if (!(png_ptr->current_text_left))
  167013. {
  167014. png_textp text_ptr;
  167015. png_charp text;
  167016. png_charp key;
  167017. int ret;
  167018. png_size_t text_size, key_size;
  167019. if (png_ptr->buffer_size < 4)
  167020. {
  167021. png_push_save_buffer(png_ptr);
  167022. return;
  167023. }
  167024. png_push_crc_finish(png_ptr);
  167025. key = png_ptr->current_text;
  167026. for (text = key; *text; text++)
  167027. ;
  167028. if (text >= key + png_ptr->current_text_size)
  167029. {
  167030. png_ptr->current_text = NULL;
  167031. png_free(png_ptr, key);
  167032. return;
  167033. }
  167034. text++;
  167035. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  167036. {
  167037. png_ptr->current_text = NULL;
  167038. png_free(png_ptr, key);
  167039. return;
  167040. }
  167041. text++;
  167042. png_ptr->zstream.next_in = (png_bytep )text;
  167043. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  167044. (text - key));
  167045. png_ptr->zstream.next_out = png_ptr->zbuf;
  167046. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  167047. key_size = text - key;
  167048. text_size = 0;
  167049. text = NULL;
  167050. ret = Z_STREAM_END;
  167051. while (png_ptr->zstream.avail_in)
  167052. {
  167053. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  167054. if (ret != Z_OK && ret != Z_STREAM_END)
  167055. {
  167056. inflateReset(&png_ptr->zstream);
  167057. png_ptr->zstream.avail_in = 0;
  167058. png_ptr->current_text = NULL;
  167059. png_free(png_ptr, key);
  167060. png_free(png_ptr, text);
  167061. return;
  167062. }
  167063. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  167064. {
  167065. if (text == NULL)
  167066. {
  167067. text = (png_charp)png_malloc(png_ptr,
  167068. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  167069. + key_size + 1));
  167070. png_memcpy(text + key_size, png_ptr->zbuf,
  167071. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  167072. png_memcpy(text, key, key_size);
  167073. text_size = key_size + png_ptr->zbuf_size -
  167074. png_ptr->zstream.avail_out;
  167075. *(text + text_size) = '\0';
  167076. }
  167077. else
  167078. {
  167079. png_charp tmp;
  167080. tmp = text;
  167081. text = (png_charp)png_malloc(png_ptr, text_size +
  167082. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  167083. + 1));
  167084. png_memcpy(text, tmp, text_size);
  167085. png_free(png_ptr, tmp);
  167086. png_memcpy(text + text_size, png_ptr->zbuf,
  167087. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  167088. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  167089. *(text + text_size) = '\0';
  167090. }
  167091. if (ret != Z_STREAM_END)
  167092. {
  167093. png_ptr->zstream.next_out = png_ptr->zbuf;
  167094. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  167095. }
  167096. }
  167097. else
  167098. {
  167099. break;
  167100. }
  167101. if (ret == Z_STREAM_END)
  167102. break;
  167103. }
  167104. inflateReset(&png_ptr->zstream);
  167105. png_ptr->zstream.avail_in = 0;
  167106. if (ret != Z_STREAM_END)
  167107. {
  167108. png_ptr->current_text = NULL;
  167109. png_free(png_ptr, key);
  167110. png_free(png_ptr, text);
  167111. return;
  167112. }
  167113. png_ptr->current_text = NULL;
  167114. png_free(png_ptr, key);
  167115. key = text;
  167116. text += key_size;
  167117. text_ptr = (png_textp)png_malloc(png_ptr,
  167118. (png_uint_32)png_sizeof(png_text));
  167119. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  167120. text_ptr->key = key;
  167121. #ifdef PNG_iTXt_SUPPORTED
  167122. text_ptr->lang = NULL;
  167123. text_ptr->lang_key = NULL;
  167124. #endif
  167125. text_ptr->text = text;
  167126. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167127. png_free(png_ptr, key);
  167128. png_free(png_ptr, text_ptr);
  167129. if (ret)
  167130. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  167131. }
  167132. }
  167133. #endif
  167134. #if defined(PNG_READ_iTXt_SUPPORTED)
  167135. void /* PRIVATE */
  167136. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167137. length)
  167138. {
  167139. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  167140. {
  167141. png_error(png_ptr, "Out of place iTXt");
  167142. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167143. }
  167144. #ifdef PNG_MAX_MALLOC_64K
  167145. png_ptr->skip_length = 0; /* This may not be necessary */
  167146. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  167147. {
  167148. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  167149. png_ptr->skip_length = length - (png_uint_32)65535L;
  167150. length = (png_uint_32)65535L;
  167151. }
  167152. #endif
  167153. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  167154. (png_uint_32)(length+1));
  167155. png_ptr->current_text[length] = '\0';
  167156. png_ptr->current_text_ptr = png_ptr->current_text;
  167157. png_ptr->current_text_size = (png_size_t)length;
  167158. png_ptr->current_text_left = (png_size_t)length;
  167159. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  167160. }
  167161. void /* PRIVATE */
  167162. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  167163. {
  167164. if (png_ptr->buffer_size && png_ptr->current_text_left)
  167165. {
  167166. png_size_t text_size;
  167167. if (png_ptr->buffer_size < png_ptr->current_text_left)
  167168. text_size = png_ptr->buffer_size;
  167169. else
  167170. text_size = png_ptr->current_text_left;
  167171. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  167172. png_ptr->current_text_left -= text_size;
  167173. png_ptr->current_text_ptr += text_size;
  167174. }
  167175. if (!(png_ptr->current_text_left))
  167176. {
  167177. png_textp text_ptr;
  167178. png_charp key;
  167179. int comp_flag;
  167180. png_charp lang;
  167181. png_charp lang_key;
  167182. png_charp text;
  167183. int ret;
  167184. if (png_ptr->buffer_size < 4)
  167185. {
  167186. png_push_save_buffer(png_ptr);
  167187. return;
  167188. }
  167189. png_push_crc_finish(png_ptr);
  167190. #if defined(PNG_MAX_MALLOC_64K)
  167191. if (png_ptr->skip_length)
  167192. return;
  167193. #endif
  167194. key = png_ptr->current_text;
  167195. for (lang = key; *lang; lang++)
  167196. ;
  167197. if (lang < key + png_ptr->current_text_size - 3)
  167198. lang++;
  167199. comp_flag = *lang++;
  167200. lang++; /* skip comp_type, always zero */
  167201. for (lang_key = lang; *lang_key; lang_key++)
  167202. ;
  167203. lang_key++; /* skip NUL separator */
  167204. text=lang_key;
  167205. if (lang_key < key + png_ptr->current_text_size - 1)
  167206. {
  167207. for (; *text; text++)
  167208. ;
  167209. }
  167210. if (text < key + png_ptr->current_text_size)
  167211. text++;
  167212. text_ptr = (png_textp)png_malloc(png_ptr,
  167213. (png_uint_32)png_sizeof(png_text));
  167214. text_ptr->compression = comp_flag + 2;
  167215. text_ptr->key = key;
  167216. text_ptr->lang = lang;
  167217. text_ptr->lang_key = lang_key;
  167218. text_ptr->text = text;
  167219. text_ptr->text_length = 0;
  167220. text_ptr->itxt_length = png_strlen(text);
  167221. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167222. png_ptr->current_text = NULL;
  167223. png_free(png_ptr, text_ptr);
  167224. if (ret)
  167225. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  167226. }
  167227. }
  167228. #endif
  167229. void /* PRIVATE */
  167230. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167231. length)
  167232. {
  167233. png_uint_32 skip=0;
  167234. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  167235. if (!(png_ptr->chunk_name[0] & 0x20))
  167236. {
  167237. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167238. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167239. PNG_HANDLE_CHUNK_ALWAYS
  167240. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167241. && png_ptr->read_user_chunk_fn == NULL
  167242. #endif
  167243. )
  167244. #endif
  167245. png_chunk_error(png_ptr, "unknown critical chunk");
  167246. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167247. }
  167248. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167249. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  167250. {
  167251. #ifdef PNG_MAX_MALLOC_64K
  167252. if (length > (png_uint_32)65535L)
  167253. {
  167254. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  167255. skip = length - (png_uint_32)65535L;
  167256. length = (png_uint_32)65535L;
  167257. }
  167258. #endif
  167259. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  167260. (png_charp)png_ptr->chunk_name, 5);
  167261. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  167262. png_ptr->unknown_chunk.size = (png_size_t)length;
  167263. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  167264. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167265. if(png_ptr->read_user_chunk_fn != NULL)
  167266. {
  167267. int ret;
  167268. ret = (*(png_ptr->read_user_chunk_fn))
  167269. (png_ptr, &png_ptr->unknown_chunk);
  167270. if (ret < 0)
  167271. png_chunk_error(png_ptr, "error in user chunk");
  167272. if (ret == 0)
  167273. {
  167274. if (!(png_ptr->chunk_name[0] & 0x20))
  167275. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167276. PNG_HANDLE_CHUNK_ALWAYS)
  167277. png_chunk_error(png_ptr, "unknown critical chunk");
  167278. png_set_unknown_chunks(png_ptr, info_ptr,
  167279. &png_ptr->unknown_chunk, 1);
  167280. }
  167281. }
  167282. #else
  167283. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  167284. #endif
  167285. png_free(png_ptr, png_ptr->unknown_chunk.data);
  167286. png_ptr->unknown_chunk.data = NULL;
  167287. }
  167288. else
  167289. #endif
  167290. skip=length;
  167291. png_push_crc_skip(png_ptr, skip);
  167292. }
  167293. void /* PRIVATE */
  167294. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  167295. {
  167296. if (png_ptr->info_fn != NULL)
  167297. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  167298. }
  167299. void /* PRIVATE */
  167300. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  167301. {
  167302. if (png_ptr->end_fn != NULL)
  167303. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  167304. }
  167305. void /* PRIVATE */
  167306. png_push_have_row(png_structp png_ptr, png_bytep row)
  167307. {
  167308. if (png_ptr->row_fn != NULL)
  167309. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  167310. (int)png_ptr->pass);
  167311. }
  167312. void PNGAPI
  167313. png_progressive_combine_row (png_structp png_ptr,
  167314. png_bytep old_row, png_bytep new_row)
  167315. {
  167316. #ifdef PNG_USE_LOCAL_ARRAYS
  167317. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  167318. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  167319. #endif
  167320. if(png_ptr == NULL) return;
  167321. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  167322. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  167323. }
  167324. void PNGAPI
  167325. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  167326. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  167327. png_progressive_end_ptr end_fn)
  167328. {
  167329. if(png_ptr == NULL) return;
  167330. png_ptr->info_fn = info_fn;
  167331. png_ptr->row_fn = row_fn;
  167332. png_ptr->end_fn = end_fn;
  167333. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  167334. }
  167335. png_voidp PNGAPI
  167336. png_get_progressive_ptr(png_structp png_ptr)
  167337. {
  167338. if(png_ptr == NULL) return (NULL);
  167339. return png_ptr->io_ptr;
  167340. }
  167341. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  167342. /*** End of inlined file: pngpread.c ***/
  167343. /*** Start of inlined file: pngrio.c ***/
  167344. #define PNG_INTERNAL
  167345. #if defined(PNG_READ_SUPPORTED)
  167346. void /* PRIVATE */
  167347. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167348. {
  167349. png_debug1(4,"reading %d bytes\n", (int)length);
  167350. if (png_ptr->read_data_fn != NULL)
  167351. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  167352. else
  167353. png_error(png_ptr, "Call to NULL read function");
  167354. }
  167355. #if !defined(PNG_NO_STDIO)
  167356. #ifndef USE_FAR_KEYWORD
  167357. void PNGAPI
  167358. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167359. {
  167360. png_size_t check;
  167361. if(png_ptr == NULL) return;
  167362. #if defined(_WIN32_WCE)
  167363. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167364. check = 0;
  167365. #else
  167366. check = (png_size_t)fread(data, (png_size_t)1, length,
  167367. (png_FILE_p)png_ptr->io_ptr);
  167368. #endif
  167369. if (check != length)
  167370. png_error(png_ptr, "Read Error");
  167371. }
  167372. #else
  167373. #define NEAR_BUF_SIZE 1024
  167374. #define MIN(a,b) (a <= b ? a : b)
  167375. static void PNGAPI
  167376. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167377. {
  167378. int check;
  167379. png_byte *n_data;
  167380. png_FILE_p io_ptr;
  167381. if(png_ptr == NULL) return;
  167382. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  167383. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  167384. if ((png_bytep)n_data == data)
  167385. {
  167386. #if defined(_WIN32_WCE)
  167387. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167388. check = 0;
  167389. #else
  167390. check = fread(n_data, 1, length, io_ptr);
  167391. #endif
  167392. }
  167393. else
  167394. {
  167395. png_byte buf[NEAR_BUF_SIZE];
  167396. png_size_t read, remaining, err;
  167397. check = 0;
  167398. remaining = length;
  167399. do
  167400. {
  167401. read = MIN(NEAR_BUF_SIZE, remaining);
  167402. #if defined(_WIN32_WCE)
  167403. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  167404. err = 0;
  167405. #else
  167406. err = fread(buf, (png_size_t)1, read, io_ptr);
  167407. #endif
  167408. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  167409. if(err != read)
  167410. break;
  167411. else
  167412. check += err;
  167413. data += read;
  167414. remaining -= read;
  167415. }
  167416. while (remaining != 0);
  167417. }
  167418. if ((png_uint_32)check != (png_uint_32)length)
  167419. png_error(png_ptr, "read Error");
  167420. }
  167421. #endif
  167422. #endif
  167423. void PNGAPI
  167424. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  167425. png_rw_ptr read_data_fn)
  167426. {
  167427. if(png_ptr == NULL) return;
  167428. png_ptr->io_ptr = io_ptr;
  167429. #if !defined(PNG_NO_STDIO)
  167430. if (read_data_fn != NULL)
  167431. png_ptr->read_data_fn = read_data_fn;
  167432. else
  167433. png_ptr->read_data_fn = png_default_read_data;
  167434. #else
  167435. png_ptr->read_data_fn = read_data_fn;
  167436. #endif
  167437. if (png_ptr->write_data_fn != NULL)
  167438. {
  167439. png_ptr->write_data_fn = NULL;
  167440. png_warning(png_ptr,
  167441. "It's an error to set both read_data_fn and write_data_fn in the ");
  167442. png_warning(png_ptr,
  167443. "same structure. Resetting write_data_fn to NULL.");
  167444. }
  167445. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  167446. png_ptr->output_flush_fn = NULL;
  167447. #endif
  167448. }
  167449. #endif /* PNG_READ_SUPPORTED */
  167450. /*** End of inlined file: pngrio.c ***/
  167451. /*** Start of inlined file: pngrtran.c ***/
  167452. #define PNG_INTERNAL
  167453. #if defined(PNG_READ_SUPPORTED)
  167454. void PNGAPI
  167455. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  167456. {
  167457. png_debug(1, "in png_set_crc_action\n");
  167458. if(png_ptr == NULL) return;
  167459. switch (crit_action)
  167460. {
  167461. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167462. break;
  167463. case PNG_CRC_WARN_USE: /* warn/use data */
  167464. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167465. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  167466. break;
  167467. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167468. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167469. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  167470. PNG_FLAG_CRC_CRITICAL_IGNORE;
  167471. break;
  167472. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  167473. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  167474. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167475. case PNG_CRC_DEFAULT:
  167476. default:
  167477. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167478. break;
  167479. }
  167480. switch (ancil_action)
  167481. {
  167482. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167483. break;
  167484. case PNG_CRC_WARN_USE: /* warn/use data */
  167485. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167486. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  167487. break;
  167488. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167489. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167490. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  167491. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167492. break;
  167493. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167494. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167495. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167496. break;
  167497. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  167498. case PNG_CRC_DEFAULT:
  167499. default:
  167500. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167501. break;
  167502. }
  167503. }
  167504. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  167505. defined(PNG_FLOATING_POINT_SUPPORTED)
  167506. void PNGAPI
  167507. png_set_background(png_structp png_ptr,
  167508. png_color_16p background_color, int background_gamma_code,
  167509. int need_expand, double background_gamma)
  167510. {
  167511. png_debug(1, "in png_set_background\n");
  167512. if(png_ptr == NULL) return;
  167513. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167514. {
  167515. png_warning(png_ptr, "Application must supply a known background gamma");
  167516. return;
  167517. }
  167518. png_ptr->transformations |= PNG_BACKGROUND;
  167519. png_memcpy(&(png_ptr->background), background_color,
  167520. png_sizeof(png_color_16));
  167521. png_ptr->background_gamma = (float)background_gamma;
  167522. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167523. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167524. }
  167525. #endif
  167526. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167527. void PNGAPI
  167528. png_set_strip_16(png_structp png_ptr)
  167529. {
  167530. png_debug(1, "in png_set_strip_16\n");
  167531. if(png_ptr == NULL) return;
  167532. png_ptr->transformations |= PNG_16_TO_8;
  167533. }
  167534. #endif
  167535. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167536. void PNGAPI
  167537. png_set_strip_alpha(png_structp png_ptr)
  167538. {
  167539. png_debug(1, "in png_set_strip_alpha\n");
  167540. if(png_ptr == NULL) return;
  167541. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167542. }
  167543. #endif
  167544. #if defined(PNG_READ_DITHER_SUPPORTED)
  167545. typedef struct png_dsort_struct
  167546. {
  167547. struct png_dsort_struct FAR * next;
  167548. png_byte left;
  167549. png_byte right;
  167550. } png_dsort;
  167551. typedef png_dsort FAR * png_dsortp;
  167552. typedef png_dsort FAR * FAR * png_dsortpp;
  167553. void PNGAPI
  167554. png_set_dither(png_structp png_ptr, png_colorp palette,
  167555. int num_palette, int maximum_colors, png_uint_16p histogram,
  167556. int full_dither)
  167557. {
  167558. png_debug(1, "in png_set_dither\n");
  167559. if(png_ptr == NULL) return;
  167560. png_ptr->transformations |= PNG_DITHER;
  167561. if (!full_dither)
  167562. {
  167563. int i;
  167564. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167565. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167566. for (i = 0; i < num_palette; i++)
  167567. png_ptr->dither_index[i] = (png_byte)i;
  167568. }
  167569. if (num_palette > maximum_colors)
  167570. {
  167571. if (histogram != NULL)
  167572. {
  167573. int i;
  167574. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167575. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167576. for (i = 0; i < num_palette; i++)
  167577. png_ptr->dither_sort[i] = (png_byte)i;
  167578. for (i = num_palette - 1; i >= maximum_colors; i--)
  167579. {
  167580. int done; /* to stop early if the list is pre-sorted */
  167581. int j;
  167582. done = 1;
  167583. for (j = 0; j < i; j++)
  167584. {
  167585. if (histogram[png_ptr->dither_sort[j]]
  167586. < histogram[png_ptr->dither_sort[j + 1]])
  167587. {
  167588. png_byte t;
  167589. t = png_ptr->dither_sort[j];
  167590. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167591. png_ptr->dither_sort[j + 1] = t;
  167592. done = 0;
  167593. }
  167594. }
  167595. if (done)
  167596. break;
  167597. }
  167598. if (full_dither)
  167599. {
  167600. int j = num_palette;
  167601. for (i = 0; i < maximum_colors; i++)
  167602. {
  167603. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167604. {
  167605. do
  167606. j--;
  167607. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167608. palette[i] = palette[j];
  167609. }
  167610. }
  167611. }
  167612. else
  167613. {
  167614. int j = num_palette;
  167615. for (i = 0; i < maximum_colors; i++)
  167616. {
  167617. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167618. {
  167619. png_color tmp_color;
  167620. do
  167621. j--;
  167622. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167623. tmp_color = palette[j];
  167624. palette[j] = palette[i];
  167625. palette[i] = tmp_color;
  167626. png_ptr->dither_index[j] = (png_byte)i;
  167627. png_ptr->dither_index[i] = (png_byte)j;
  167628. }
  167629. }
  167630. for (i = 0; i < num_palette; i++)
  167631. {
  167632. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167633. {
  167634. int min_d, k, min_k, d_index;
  167635. d_index = png_ptr->dither_index[i];
  167636. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167637. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167638. {
  167639. int d;
  167640. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167641. if (d < min_d)
  167642. {
  167643. min_d = d;
  167644. min_k = k;
  167645. }
  167646. }
  167647. png_ptr->dither_index[i] = (png_byte)min_k;
  167648. }
  167649. }
  167650. }
  167651. png_free(png_ptr, png_ptr->dither_sort);
  167652. png_ptr->dither_sort=NULL;
  167653. }
  167654. else
  167655. {
  167656. int i;
  167657. int max_d;
  167658. int num_new_palette;
  167659. png_dsortp t;
  167660. png_dsortpp hash;
  167661. t=NULL;
  167662. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167663. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167664. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167665. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167666. for (i = 0; i < num_palette; i++)
  167667. {
  167668. png_ptr->index_to_palette[i] = (png_byte)i;
  167669. png_ptr->palette_to_index[i] = (png_byte)i;
  167670. }
  167671. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167672. png_sizeof (png_dsortp)));
  167673. for (i = 0; i < 769; i++)
  167674. hash[i] = NULL;
  167675. num_new_palette = num_palette;
  167676. max_d = 96;
  167677. while (num_new_palette > maximum_colors)
  167678. {
  167679. for (i = 0; i < num_new_palette - 1; i++)
  167680. {
  167681. int j;
  167682. for (j = i + 1; j < num_new_palette; j++)
  167683. {
  167684. int d;
  167685. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167686. if (d <= max_d)
  167687. {
  167688. t = (png_dsortp)png_malloc_warn(png_ptr,
  167689. (png_uint_32)(png_sizeof(png_dsort)));
  167690. if (t == NULL)
  167691. break;
  167692. t->next = hash[d];
  167693. t->left = (png_byte)i;
  167694. t->right = (png_byte)j;
  167695. hash[d] = t;
  167696. }
  167697. }
  167698. if (t == NULL)
  167699. break;
  167700. }
  167701. if (t != NULL)
  167702. for (i = 0; i <= max_d; i++)
  167703. {
  167704. if (hash[i] != NULL)
  167705. {
  167706. png_dsortp p;
  167707. for (p = hash[i]; p; p = p->next)
  167708. {
  167709. if ((int)png_ptr->index_to_palette[p->left]
  167710. < num_new_palette &&
  167711. (int)png_ptr->index_to_palette[p->right]
  167712. < num_new_palette)
  167713. {
  167714. int j, next_j;
  167715. if (num_new_palette & 0x01)
  167716. {
  167717. j = p->left;
  167718. next_j = p->right;
  167719. }
  167720. else
  167721. {
  167722. j = p->right;
  167723. next_j = p->left;
  167724. }
  167725. num_new_palette--;
  167726. palette[png_ptr->index_to_palette[j]]
  167727. = palette[num_new_palette];
  167728. if (!full_dither)
  167729. {
  167730. int k;
  167731. for (k = 0; k < num_palette; k++)
  167732. {
  167733. if (png_ptr->dither_index[k] ==
  167734. png_ptr->index_to_palette[j])
  167735. png_ptr->dither_index[k] =
  167736. png_ptr->index_to_palette[next_j];
  167737. if ((int)png_ptr->dither_index[k] ==
  167738. num_new_palette)
  167739. png_ptr->dither_index[k] =
  167740. png_ptr->index_to_palette[j];
  167741. }
  167742. }
  167743. png_ptr->index_to_palette[png_ptr->palette_to_index
  167744. [num_new_palette]] = png_ptr->index_to_palette[j];
  167745. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167746. = png_ptr->palette_to_index[num_new_palette];
  167747. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167748. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167749. }
  167750. if (num_new_palette <= maximum_colors)
  167751. break;
  167752. }
  167753. if (num_new_palette <= maximum_colors)
  167754. break;
  167755. }
  167756. }
  167757. for (i = 0; i < 769; i++)
  167758. {
  167759. if (hash[i] != NULL)
  167760. {
  167761. png_dsortp p = hash[i];
  167762. while (p)
  167763. {
  167764. t = p->next;
  167765. png_free(png_ptr, p);
  167766. p = t;
  167767. }
  167768. }
  167769. hash[i] = 0;
  167770. }
  167771. max_d += 96;
  167772. }
  167773. png_free(png_ptr, hash);
  167774. png_free(png_ptr, png_ptr->palette_to_index);
  167775. png_free(png_ptr, png_ptr->index_to_palette);
  167776. png_ptr->palette_to_index=NULL;
  167777. png_ptr->index_to_palette=NULL;
  167778. }
  167779. num_palette = maximum_colors;
  167780. }
  167781. if (png_ptr->palette == NULL)
  167782. {
  167783. png_ptr->palette = palette;
  167784. }
  167785. png_ptr->num_palette = (png_uint_16)num_palette;
  167786. if (full_dither)
  167787. {
  167788. int i;
  167789. png_bytep distance;
  167790. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167791. PNG_DITHER_BLUE_BITS;
  167792. int num_red = (1 << PNG_DITHER_RED_BITS);
  167793. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167794. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167795. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167796. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167797. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167798. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167799. png_sizeof (png_byte));
  167800. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167801. png_sizeof(png_byte)));
  167802. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167803. for (i = 0; i < num_palette; i++)
  167804. {
  167805. int ir, ig, ib;
  167806. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167807. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167808. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167809. for (ir = 0; ir < num_red; ir++)
  167810. {
  167811. int dr = ((ir > r) ? ir - r : r - ir);
  167812. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167813. for (ig = 0; ig < num_green; ig++)
  167814. {
  167815. int dg = ((ig > g) ? ig - g : g - ig);
  167816. int dt = dr + dg;
  167817. int dm = ((dr > dg) ? dr : dg);
  167818. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167819. for (ib = 0; ib < num_blue; ib++)
  167820. {
  167821. int d_index = index_g | ib;
  167822. int db = ((ib > b) ? ib - b : b - ib);
  167823. int dmax = ((dm > db) ? dm : db);
  167824. int d = dmax + dt + db;
  167825. if (d < (int)distance[d_index])
  167826. {
  167827. distance[d_index] = (png_byte)d;
  167828. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167829. }
  167830. }
  167831. }
  167832. }
  167833. }
  167834. png_free(png_ptr, distance);
  167835. }
  167836. }
  167837. #endif
  167838. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167839. void PNGAPI
  167840. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167841. {
  167842. png_debug(1, "in png_set_gamma\n");
  167843. if(png_ptr == NULL) return;
  167844. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167845. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167846. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167847. png_ptr->transformations |= PNG_GAMMA;
  167848. png_ptr->gamma = (float)file_gamma;
  167849. png_ptr->screen_gamma = (float)scrn_gamma;
  167850. }
  167851. #endif
  167852. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167853. void PNGAPI
  167854. png_set_expand(png_structp png_ptr)
  167855. {
  167856. png_debug(1, "in png_set_expand\n");
  167857. if(png_ptr == NULL) return;
  167858. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167859. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167860. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167861. #endif
  167862. }
  167863. void PNGAPI
  167864. png_set_palette_to_rgb(png_structp png_ptr)
  167865. {
  167866. png_debug(1, "in png_set_palette_to_rgb\n");
  167867. if(png_ptr == NULL) return;
  167868. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167869. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167870. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167871. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167872. #endif
  167873. }
  167874. #if !defined(PNG_1_0_X)
  167875. void PNGAPI
  167876. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167877. {
  167878. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167879. if(png_ptr == NULL) return;
  167880. png_ptr->transformations |= PNG_EXPAND;
  167881. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167882. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167883. #endif
  167884. }
  167885. #endif
  167886. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167887. void PNGAPI
  167888. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167889. {
  167890. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167891. if(png_ptr == NULL) return;
  167892. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167893. }
  167894. #endif
  167895. void PNGAPI
  167896. png_set_tRNS_to_alpha(png_structp png_ptr)
  167897. {
  167898. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167899. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167900. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167901. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167902. #endif
  167903. }
  167904. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167905. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167906. void PNGAPI
  167907. png_set_gray_to_rgb(png_structp png_ptr)
  167908. {
  167909. png_debug(1, "in png_set_gray_to_rgb\n");
  167910. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167911. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167912. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167913. #endif
  167914. }
  167915. #endif
  167916. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167917. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167918. void PNGAPI
  167919. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167920. double green)
  167921. {
  167922. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167923. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167924. if(png_ptr == NULL) return;
  167925. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167926. }
  167927. #endif
  167928. void PNGAPI
  167929. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167930. png_fixed_point red, png_fixed_point green)
  167931. {
  167932. png_debug(1, "in png_set_rgb_to_gray\n");
  167933. if(png_ptr == NULL) return;
  167934. switch(error_action)
  167935. {
  167936. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167937. break;
  167938. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167939. break;
  167940. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167941. }
  167942. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167943. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167944. png_ptr->transformations |= PNG_EXPAND;
  167945. #else
  167946. {
  167947. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167948. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167949. }
  167950. #endif
  167951. {
  167952. png_uint_16 red_int, green_int;
  167953. if(red < 0 || green < 0)
  167954. {
  167955. red_int = 6968; /* .212671 * 32768 + .5 */
  167956. green_int = 23434; /* .715160 * 32768 + .5 */
  167957. }
  167958. else if(red + green < 100000L)
  167959. {
  167960. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167961. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167962. }
  167963. else
  167964. {
  167965. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167966. red_int = 6968;
  167967. green_int = 23434;
  167968. }
  167969. png_ptr->rgb_to_gray_red_coeff = red_int;
  167970. png_ptr->rgb_to_gray_green_coeff = green_int;
  167971. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167972. }
  167973. }
  167974. #endif
  167975. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167976. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167977. defined(PNG_LEGACY_SUPPORTED)
  167978. void PNGAPI
  167979. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167980. read_user_transform_fn)
  167981. {
  167982. png_debug(1, "in png_set_read_user_transform_fn\n");
  167983. if(png_ptr == NULL) return;
  167984. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167985. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167986. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167987. #endif
  167988. #ifdef PNG_LEGACY_SUPPORTED
  167989. if(read_user_transform_fn)
  167990. png_warning(png_ptr,
  167991. "This version of libpng does not support user transforms");
  167992. #endif
  167993. }
  167994. #endif
  167995. void /* PRIVATE */
  167996. png_init_read_transformations(png_structp png_ptr)
  167997. {
  167998. png_debug(1, "in png_init_read_transformations\n");
  167999. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168000. if(png_ptr != NULL)
  168001. #endif
  168002. {
  168003. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  168004. || defined(PNG_READ_GAMMA_SUPPORTED)
  168005. int color_type = png_ptr->color_type;
  168006. #endif
  168007. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  168008. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168009. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  168010. !(color_type & PNG_COLOR_MASK_COLOR))
  168011. {
  168012. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  168013. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168014. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  168015. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168016. png_ptr->background.red == png_ptr->background.green &&
  168017. png_ptr->background.red == png_ptr->background.blue)
  168018. {
  168019. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  168020. png_ptr->background.gray = png_ptr->background.red;
  168021. }
  168022. #endif
  168023. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  168024. (png_ptr->transformations & PNG_EXPAND))
  168025. {
  168026. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  168027. {
  168028. switch (png_ptr->bit_depth)
  168029. {
  168030. case 1:
  168031. png_ptr->background.gray *= (png_uint_16)0xff;
  168032. png_ptr->background.red = png_ptr->background.green
  168033. = png_ptr->background.blue = png_ptr->background.gray;
  168034. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168035. {
  168036. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  168037. png_ptr->trans_values.red = png_ptr->trans_values.green
  168038. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168039. }
  168040. break;
  168041. case 2:
  168042. png_ptr->background.gray *= (png_uint_16)0x55;
  168043. png_ptr->background.red = png_ptr->background.green
  168044. = png_ptr->background.blue = png_ptr->background.gray;
  168045. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168046. {
  168047. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  168048. png_ptr->trans_values.red = png_ptr->trans_values.green
  168049. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168050. }
  168051. break;
  168052. case 4:
  168053. png_ptr->background.gray *= (png_uint_16)0x11;
  168054. png_ptr->background.red = png_ptr->background.green
  168055. = png_ptr->background.blue = png_ptr->background.gray;
  168056. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168057. {
  168058. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  168059. png_ptr->trans_values.red = png_ptr->trans_values.green
  168060. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168061. }
  168062. break;
  168063. case 8:
  168064. case 16:
  168065. png_ptr->background.red = png_ptr->background.green
  168066. = png_ptr->background.blue = png_ptr->background.gray;
  168067. break;
  168068. }
  168069. }
  168070. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  168071. {
  168072. png_ptr->background.red =
  168073. png_ptr->palette[png_ptr->background.index].red;
  168074. png_ptr->background.green =
  168075. png_ptr->palette[png_ptr->background.index].green;
  168076. png_ptr->background.blue =
  168077. png_ptr->palette[png_ptr->background.index].blue;
  168078. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168079. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168080. {
  168081. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168082. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168083. #endif
  168084. {
  168085. int i,istop;
  168086. istop=(int)png_ptr->num_trans;
  168087. for (i=0; i<istop; i++)
  168088. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  168089. }
  168090. }
  168091. #endif
  168092. }
  168093. }
  168094. #endif
  168095. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  168096. png_ptr->background_1 = png_ptr->background;
  168097. #endif
  168098. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  168099. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  168100. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  168101. < PNG_GAMMA_THRESHOLD))
  168102. {
  168103. int i,k;
  168104. k=0;
  168105. for (i=0; i<png_ptr->num_trans; i++)
  168106. {
  168107. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  168108. k=1; /* partial transparency is present */
  168109. }
  168110. if (k == 0)
  168111. png_ptr->transformations &= (~PNG_GAMMA);
  168112. }
  168113. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  168114. png_ptr->gamma != 0.0)
  168115. {
  168116. png_build_gamma_table(png_ptr);
  168117. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168118. if (png_ptr->transformations & PNG_BACKGROUND)
  168119. {
  168120. if (color_type == PNG_COLOR_TYPE_PALETTE)
  168121. {
  168122. png_color back, back_1;
  168123. png_colorp palette = png_ptr->palette;
  168124. int num_palette = png_ptr->num_palette;
  168125. int i;
  168126. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  168127. {
  168128. back.red = png_ptr->gamma_table[png_ptr->background.red];
  168129. back.green = png_ptr->gamma_table[png_ptr->background.green];
  168130. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  168131. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  168132. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  168133. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  168134. }
  168135. else
  168136. {
  168137. double g, gs;
  168138. switch (png_ptr->background_gamma_type)
  168139. {
  168140. case PNG_BACKGROUND_GAMMA_SCREEN:
  168141. g = (png_ptr->screen_gamma);
  168142. gs = 1.0;
  168143. break;
  168144. case PNG_BACKGROUND_GAMMA_FILE:
  168145. g = 1.0 / (png_ptr->gamma);
  168146. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168147. break;
  168148. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168149. g = 1.0 / (png_ptr->background_gamma);
  168150. gs = 1.0 / (png_ptr->background_gamma *
  168151. png_ptr->screen_gamma);
  168152. break;
  168153. default:
  168154. g = 1.0; /* back_1 */
  168155. gs = 1.0; /* back */
  168156. }
  168157. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  168158. {
  168159. back.red = (png_byte)png_ptr->background.red;
  168160. back.green = (png_byte)png_ptr->background.green;
  168161. back.blue = (png_byte)png_ptr->background.blue;
  168162. }
  168163. else
  168164. {
  168165. back.red = (png_byte)(pow(
  168166. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  168167. back.green = (png_byte)(pow(
  168168. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  168169. back.blue = (png_byte)(pow(
  168170. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  168171. }
  168172. back_1.red = (png_byte)(pow(
  168173. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  168174. back_1.green = (png_byte)(pow(
  168175. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  168176. back_1.blue = (png_byte)(pow(
  168177. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  168178. }
  168179. for (i = 0; i < num_palette; i++)
  168180. {
  168181. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  168182. {
  168183. if (png_ptr->trans[i] == 0)
  168184. {
  168185. palette[i] = back;
  168186. }
  168187. else /* if (png_ptr->trans[i] != 0xff) */
  168188. {
  168189. png_byte v, w;
  168190. v = png_ptr->gamma_to_1[palette[i].red];
  168191. png_composite(w, v, png_ptr->trans[i], back_1.red);
  168192. palette[i].red = png_ptr->gamma_from_1[w];
  168193. v = png_ptr->gamma_to_1[palette[i].green];
  168194. png_composite(w, v, png_ptr->trans[i], back_1.green);
  168195. palette[i].green = png_ptr->gamma_from_1[w];
  168196. v = png_ptr->gamma_to_1[palette[i].blue];
  168197. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  168198. palette[i].blue = png_ptr->gamma_from_1[w];
  168199. }
  168200. }
  168201. else
  168202. {
  168203. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168204. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168205. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168206. }
  168207. }
  168208. }
  168209. else
  168210. {
  168211. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  168212. double g = 1.0;
  168213. double gs = 1.0;
  168214. switch (png_ptr->background_gamma_type)
  168215. {
  168216. case PNG_BACKGROUND_GAMMA_SCREEN:
  168217. g = (png_ptr->screen_gamma);
  168218. gs = 1.0;
  168219. break;
  168220. case PNG_BACKGROUND_GAMMA_FILE:
  168221. g = 1.0 / (png_ptr->gamma);
  168222. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168223. break;
  168224. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168225. g = 1.0 / (png_ptr->background_gamma);
  168226. gs = 1.0 / (png_ptr->background_gamma *
  168227. png_ptr->screen_gamma);
  168228. break;
  168229. }
  168230. png_ptr->background_1.gray = (png_uint_16)(pow(
  168231. (double)png_ptr->background.gray / m, g) * m + .5);
  168232. png_ptr->background.gray = (png_uint_16)(pow(
  168233. (double)png_ptr->background.gray / m, gs) * m + .5);
  168234. if ((png_ptr->background.red != png_ptr->background.green) ||
  168235. (png_ptr->background.red != png_ptr->background.blue) ||
  168236. (png_ptr->background.red != png_ptr->background.gray))
  168237. {
  168238. png_ptr->background_1.red = (png_uint_16)(pow(
  168239. (double)png_ptr->background.red / m, g) * m + .5);
  168240. png_ptr->background_1.green = (png_uint_16)(pow(
  168241. (double)png_ptr->background.green / m, g) * m + .5);
  168242. png_ptr->background_1.blue = (png_uint_16)(pow(
  168243. (double)png_ptr->background.blue / m, g) * m + .5);
  168244. png_ptr->background.red = (png_uint_16)(pow(
  168245. (double)png_ptr->background.red / m, gs) * m + .5);
  168246. png_ptr->background.green = (png_uint_16)(pow(
  168247. (double)png_ptr->background.green / m, gs) * m + .5);
  168248. png_ptr->background.blue = (png_uint_16)(pow(
  168249. (double)png_ptr->background.blue / m, gs) * m + .5);
  168250. }
  168251. else
  168252. {
  168253. png_ptr->background_1.red = png_ptr->background_1.green
  168254. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  168255. png_ptr->background.red = png_ptr->background.green
  168256. = png_ptr->background.blue = png_ptr->background.gray;
  168257. }
  168258. }
  168259. }
  168260. else
  168261. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168262. if (color_type == PNG_COLOR_TYPE_PALETTE)
  168263. {
  168264. png_colorp palette = png_ptr->palette;
  168265. int num_palette = png_ptr->num_palette;
  168266. int i;
  168267. for (i = 0; i < num_palette; i++)
  168268. {
  168269. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168270. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168271. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168272. }
  168273. }
  168274. }
  168275. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168276. else
  168277. #endif
  168278. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  168279. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168280. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168281. (color_type == PNG_COLOR_TYPE_PALETTE))
  168282. {
  168283. int i;
  168284. int istop = (int)png_ptr->num_trans;
  168285. png_color back;
  168286. png_colorp palette = png_ptr->palette;
  168287. back.red = (png_byte)png_ptr->background.red;
  168288. back.green = (png_byte)png_ptr->background.green;
  168289. back.blue = (png_byte)png_ptr->background.blue;
  168290. for (i = 0; i < istop; i++)
  168291. {
  168292. if (png_ptr->trans[i] == 0)
  168293. {
  168294. palette[i] = back;
  168295. }
  168296. else if (png_ptr->trans[i] != 0xff)
  168297. {
  168298. png_composite(palette[i].red, palette[i].red,
  168299. png_ptr->trans[i], back.red);
  168300. png_composite(palette[i].green, palette[i].green,
  168301. png_ptr->trans[i], back.green);
  168302. png_composite(palette[i].blue, palette[i].blue,
  168303. png_ptr->trans[i], back.blue);
  168304. }
  168305. }
  168306. }
  168307. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168308. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168309. if ((png_ptr->transformations & PNG_SHIFT) &&
  168310. (color_type == PNG_COLOR_TYPE_PALETTE))
  168311. {
  168312. png_uint_16 i;
  168313. png_uint_16 istop = png_ptr->num_palette;
  168314. int sr = 8 - png_ptr->sig_bit.red;
  168315. int sg = 8 - png_ptr->sig_bit.green;
  168316. int sb = 8 - png_ptr->sig_bit.blue;
  168317. if (sr < 0 || sr > 8)
  168318. sr = 0;
  168319. if (sg < 0 || sg > 8)
  168320. sg = 0;
  168321. if (sb < 0 || sb > 8)
  168322. sb = 0;
  168323. for (i = 0; i < istop; i++)
  168324. {
  168325. png_ptr->palette[i].red >>= sr;
  168326. png_ptr->palette[i].green >>= sg;
  168327. png_ptr->palette[i].blue >>= sb;
  168328. }
  168329. }
  168330. #endif /* PNG_READ_SHIFT_SUPPORTED */
  168331. }
  168332. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  168333. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  168334. if(png_ptr)
  168335. return;
  168336. #endif
  168337. }
  168338. void /* PRIVATE */
  168339. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  168340. {
  168341. png_debug(1, "in png_read_transform_info\n");
  168342. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168343. if (png_ptr->transformations & PNG_EXPAND)
  168344. {
  168345. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168346. {
  168347. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  168348. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  168349. else
  168350. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  168351. info_ptr->bit_depth = 8;
  168352. info_ptr->num_trans = 0;
  168353. }
  168354. else
  168355. {
  168356. if (png_ptr->num_trans)
  168357. {
  168358. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  168359. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168360. else
  168361. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168362. }
  168363. if (info_ptr->bit_depth < 8)
  168364. info_ptr->bit_depth = 8;
  168365. info_ptr->num_trans = 0;
  168366. }
  168367. }
  168368. #endif
  168369. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168370. if (png_ptr->transformations & PNG_BACKGROUND)
  168371. {
  168372. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168373. info_ptr->num_trans = 0;
  168374. info_ptr->background = png_ptr->background;
  168375. }
  168376. #endif
  168377. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168378. if (png_ptr->transformations & PNG_GAMMA)
  168379. {
  168380. #ifdef PNG_FLOATING_POINT_SUPPORTED
  168381. info_ptr->gamma = png_ptr->gamma;
  168382. #endif
  168383. #ifdef PNG_FIXED_POINT_SUPPORTED
  168384. info_ptr->int_gamma = png_ptr->int_gamma;
  168385. #endif
  168386. }
  168387. #endif
  168388. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168389. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  168390. info_ptr->bit_depth = 8;
  168391. #endif
  168392. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168393. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  168394. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168395. #endif
  168396. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168397. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168398. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  168399. #endif
  168400. #if defined(PNG_READ_DITHER_SUPPORTED)
  168401. if (png_ptr->transformations & PNG_DITHER)
  168402. {
  168403. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168404. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  168405. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  168406. {
  168407. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  168408. }
  168409. }
  168410. #endif
  168411. #if defined(PNG_READ_PACK_SUPPORTED)
  168412. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  168413. info_ptr->bit_depth = 8;
  168414. #endif
  168415. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168416. info_ptr->channels = 1;
  168417. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  168418. info_ptr->channels = 3;
  168419. else
  168420. info_ptr->channels = 1;
  168421. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168422. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168423. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168424. #endif
  168425. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  168426. info_ptr->channels++;
  168427. #if defined(PNG_READ_FILLER_SUPPORTED)
  168428. if ((png_ptr->transformations & PNG_FILLER) &&
  168429. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168430. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  168431. {
  168432. info_ptr->channels++;
  168433. #if !defined(PNG_1_0_X)
  168434. if (png_ptr->transformations & PNG_ADD_ALPHA)
  168435. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168436. #endif
  168437. }
  168438. #endif
  168439. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  168440. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168441. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  168442. {
  168443. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  168444. info_ptr->bit_depth = png_ptr->user_transform_depth;
  168445. if(info_ptr->channels < png_ptr->user_transform_channels)
  168446. info_ptr->channels = png_ptr->user_transform_channels;
  168447. }
  168448. #endif
  168449. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  168450. info_ptr->bit_depth);
  168451. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  168452. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  168453. if(png_ptr)
  168454. return;
  168455. #endif
  168456. }
  168457. void /* PRIVATE */
  168458. png_do_read_transformations(png_structp png_ptr)
  168459. {
  168460. png_debug(1, "in png_do_read_transformations\n");
  168461. if (png_ptr->row_buf == NULL)
  168462. {
  168463. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  168464. char msg[50];
  168465. png_snprintf2(msg, 50,
  168466. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  168467. png_ptr->pass);
  168468. png_error(png_ptr, msg);
  168469. #else
  168470. png_error(png_ptr, "NULL row buffer");
  168471. #endif
  168472. }
  168473. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168474. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  168475. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  168476. png_error(png_ptr, "Uninitialized row");
  168477. #else
  168478. png_warning(png_ptr, "Uninitialized row");
  168479. #endif
  168480. #endif
  168481. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168482. if (png_ptr->transformations & PNG_EXPAND)
  168483. {
  168484. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  168485. {
  168486. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168487. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  168488. }
  168489. else
  168490. {
  168491. if (png_ptr->num_trans &&
  168492. (png_ptr->transformations & PNG_EXPAND_tRNS))
  168493. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168494. &(png_ptr->trans_values));
  168495. else
  168496. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168497. NULL);
  168498. }
  168499. }
  168500. #endif
  168501. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168502. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168503. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168504. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  168505. #endif
  168506. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168507. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168508. {
  168509. int rgb_error =
  168510. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  168511. if(rgb_error)
  168512. {
  168513. png_ptr->rgb_to_gray_status=1;
  168514. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168515. PNG_RGB_TO_GRAY_WARN)
  168516. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168517. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168518. PNG_RGB_TO_GRAY_ERR)
  168519. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168520. }
  168521. }
  168522. #endif
  168523. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168524. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168525. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168526. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168527. #endif
  168528. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168529. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168530. ((png_ptr->num_trans != 0 ) ||
  168531. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168532. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168533. &(png_ptr->trans_values), &(png_ptr->background)
  168534. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168535. , &(png_ptr->background_1),
  168536. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168537. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168538. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168539. png_ptr->gamma_shift
  168540. #endif
  168541. );
  168542. #endif
  168543. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168544. if ((png_ptr->transformations & PNG_GAMMA) &&
  168545. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168546. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168547. ((png_ptr->num_trans != 0) ||
  168548. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168549. #endif
  168550. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168551. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168552. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168553. png_ptr->gamma_shift);
  168554. #endif
  168555. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168556. if (png_ptr->transformations & PNG_16_TO_8)
  168557. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168558. #endif
  168559. #if defined(PNG_READ_DITHER_SUPPORTED)
  168560. if (png_ptr->transformations & PNG_DITHER)
  168561. {
  168562. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168563. png_ptr->palette_lookup, png_ptr->dither_index);
  168564. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168565. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168566. }
  168567. #endif
  168568. #if defined(PNG_READ_INVERT_SUPPORTED)
  168569. if (png_ptr->transformations & PNG_INVERT_MONO)
  168570. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168571. #endif
  168572. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168573. if (png_ptr->transformations & PNG_SHIFT)
  168574. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168575. &(png_ptr->shift));
  168576. #endif
  168577. #if defined(PNG_READ_PACK_SUPPORTED)
  168578. if (png_ptr->transformations & PNG_PACK)
  168579. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168580. #endif
  168581. #if defined(PNG_READ_BGR_SUPPORTED)
  168582. if (png_ptr->transformations & PNG_BGR)
  168583. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168584. #endif
  168585. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168586. if (png_ptr->transformations & PNG_PACKSWAP)
  168587. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168588. #endif
  168589. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168590. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168591. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168592. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168593. #endif
  168594. #if defined(PNG_READ_FILLER_SUPPORTED)
  168595. if (png_ptr->transformations & PNG_FILLER)
  168596. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168597. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168598. #endif
  168599. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168600. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168601. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168602. #endif
  168603. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168604. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168605. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168606. #endif
  168607. #if defined(PNG_READ_SWAP_SUPPORTED)
  168608. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168609. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168610. #endif
  168611. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168612. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168613. {
  168614. if(png_ptr->read_user_transform_fn != NULL)
  168615. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168616. (png_ptr, /* png_ptr */
  168617. &(png_ptr->row_info), /* row_info: */
  168618. png_ptr->row_buf + 1); /* start of pixel data for row */
  168619. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168620. if(png_ptr->user_transform_depth)
  168621. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168622. if(png_ptr->user_transform_channels)
  168623. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168624. #endif
  168625. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168626. png_ptr->row_info.channels);
  168627. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168628. png_ptr->row_info.width);
  168629. }
  168630. #endif
  168631. }
  168632. #if defined(PNG_READ_PACK_SUPPORTED)
  168633. void /* PRIVATE */
  168634. png_do_unpack(png_row_infop row_info, png_bytep row)
  168635. {
  168636. png_debug(1, "in png_do_unpack\n");
  168637. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168638. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168639. #else
  168640. if (row_info->bit_depth < 8)
  168641. #endif
  168642. {
  168643. png_uint_32 i;
  168644. png_uint_32 row_width=row_info->width;
  168645. switch (row_info->bit_depth)
  168646. {
  168647. case 1:
  168648. {
  168649. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168650. png_bytep dp = row + (png_size_t)row_width - 1;
  168651. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168652. for (i = 0; i < row_width; i++)
  168653. {
  168654. *dp = (png_byte)((*sp >> shift) & 0x01);
  168655. if (shift == 7)
  168656. {
  168657. shift = 0;
  168658. sp--;
  168659. }
  168660. else
  168661. shift++;
  168662. dp--;
  168663. }
  168664. break;
  168665. }
  168666. case 2:
  168667. {
  168668. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168669. png_bytep dp = row + (png_size_t)row_width - 1;
  168670. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168671. for (i = 0; i < row_width; i++)
  168672. {
  168673. *dp = (png_byte)((*sp >> shift) & 0x03);
  168674. if (shift == 6)
  168675. {
  168676. shift = 0;
  168677. sp--;
  168678. }
  168679. else
  168680. shift += 2;
  168681. dp--;
  168682. }
  168683. break;
  168684. }
  168685. case 4:
  168686. {
  168687. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168688. png_bytep dp = row + (png_size_t)row_width - 1;
  168689. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168690. for (i = 0; i < row_width; i++)
  168691. {
  168692. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168693. if (shift == 4)
  168694. {
  168695. shift = 0;
  168696. sp--;
  168697. }
  168698. else
  168699. shift = 4;
  168700. dp--;
  168701. }
  168702. break;
  168703. }
  168704. }
  168705. row_info->bit_depth = 8;
  168706. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168707. row_info->rowbytes = row_width * row_info->channels;
  168708. }
  168709. }
  168710. #endif
  168711. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168712. void /* PRIVATE */
  168713. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168714. {
  168715. png_debug(1, "in png_do_unshift\n");
  168716. if (
  168717. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168718. row != NULL && row_info != NULL && sig_bits != NULL &&
  168719. #endif
  168720. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168721. {
  168722. int shift[4];
  168723. int channels = 0;
  168724. int c;
  168725. png_uint_16 value = 0;
  168726. png_uint_32 row_width = row_info->width;
  168727. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168728. {
  168729. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168730. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168731. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168732. }
  168733. else
  168734. {
  168735. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168736. }
  168737. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168738. {
  168739. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168740. }
  168741. for (c = 0; c < channels; c++)
  168742. {
  168743. if (shift[c] <= 0)
  168744. shift[c] = 0;
  168745. else
  168746. value = 1;
  168747. }
  168748. if (!value)
  168749. return;
  168750. switch (row_info->bit_depth)
  168751. {
  168752. case 2:
  168753. {
  168754. png_bytep bp;
  168755. png_uint_32 i;
  168756. png_uint_32 istop = row_info->rowbytes;
  168757. for (bp = row, i = 0; i < istop; i++)
  168758. {
  168759. *bp >>= 1;
  168760. *bp++ &= 0x55;
  168761. }
  168762. break;
  168763. }
  168764. case 4:
  168765. {
  168766. png_bytep bp = row;
  168767. png_uint_32 i;
  168768. png_uint_32 istop = row_info->rowbytes;
  168769. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168770. (png_byte)((int)0xf >> shift[0]));
  168771. for (i = 0; i < istop; i++)
  168772. {
  168773. *bp >>= shift[0];
  168774. *bp++ &= mask;
  168775. }
  168776. break;
  168777. }
  168778. case 8:
  168779. {
  168780. png_bytep bp = row;
  168781. png_uint_32 i;
  168782. png_uint_32 istop = row_width * channels;
  168783. for (i = 0; i < istop; i++)
  168784. {
  168785. *bp++ >>= shift[i%channels];
  168786. }
  168787. break;
  168788. }
  168789. case 16:
  168790. {
  168791. png_bytep bp = row;
  168792. png_uint_32 i;
  168793. png_uint_32 istop = channels * row_width;
  168794. for (i = 0; i < istop; i++)
  168795. {
  168796. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168797. value >>= shift[i%channels];
  168798. *bp++ = (png_byte)(value >> 8);
  168799. *bp++ = (png_byte)(value & 0xff);
  168800. }
  168801. break;
  168802. }
  168803. }
  168804. }
  168805. }
  168806. #endif
  168807. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168808. void /* PRIVATE */
  168809. png_do_chop(png_row_infop row_info, png_bytep row)
  168810. {
  168811. png_debug(1, "in png_do_chop\n");
  168812. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168813. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168814. #else
  168815. if (row_info->bit_depth == 16)
  168816. #endif
  168817. {
  168818. png_bytep sp = row;
  168819. png_bytep dp = row;
  168820. png_uint_32 i;
  168821. png_uint_32 istop = row_info->width * row_info->channels;
  168822. for (i = 0; i<istop; i++, sp += 2, dp++)
  168823. {
  168824. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168825. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168826. #else
  168827. *dp = *sp;
  168828. #endif
  168829. }
  168830. row_info->bit_depth = 8;
  168831. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168832. row_info->rowbytes = row_info->width * row_info->channels;
  168833. }
  168834. }
  168835. #endif
  168836. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168837. void /* PRIVATE */
  168838. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168839. {
  168840. png_debug(1, "in png_do_read_swap_alpha\n");
  168841. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168842. if (row != NULL && row_info != NULL)
  168843. #endif
  168844. {
  168845. png_uint_32 row_width = row_info->width;
  168846. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168847. {
  168848. if (row_info->bit_depth == 8)
  168849. {
  168850. png_bytep sp = row + row_info->rowbytes;
  168851. png_bytep dp = sp;
  168852. png_byte save;
  168853. png_uint_32 i;
  168854. for (i = 0; i < row_width; i++)
  168855. {
  168856. save = *(--sp);
  168857. *(--dp) = *(--sp);
  168858. *(--dp) = *(--sp);
  168859. *(--dp) = *(--sp);
  168860. *(--dp) = save;
  168861. }
  168862. }
  168863. else
  168864. {
  168865. png_bytep sp = row + row_info->rowbytes;
  168866. png_bytep dp = sp;
  168867. png_byte save[2];
  168868. png_uint_32 i;
  168869. for (i = 0; i < row_width; i++)
  168870. {
  168871. save[0] = *(--sp);
  168872. save[1] = *(--sp);
  168873. *(--dp) = *(--sp);
  168874. *(--dp) = *(--sp);
  168875. *(--dp) = *(--sp);
  168876. *(--dp) = *(--sp);
  168877. *(--dp) = *(--sp);
  168878. *(--dp) = *(--sp);
  168879. *(--dp) = save[0];
  168880. *(--dp) = save[1];
  168881. }
  168882. }
  168883. }
  168884. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168885. {
  168886. if (row_info->bit_depth == 8)
  168887. {
  168888. png_bytep sp = row + row_info->rowbytes;
  168889. png_bytep dp = sp;
  168890. png_byte save;
  168891. png_uint_32 i;
  168892. for (i = 0; i < row_width; i++)
  168893. {
  168894. save = *(--sp);
  168895. *(--dp) = *(--sp);
  168896. *(--dp) = save;
  168897. }
  168898. }
  168899. else
  168900. {
  168901. png_bytep sp = row + row_info->rowbytes;
  168902. png_bytep dp = sp;
  168903. png_byte save[2];
  168904. png_uint_32 i;
  168905. for (i = 0; i < row_width; i++)
  168906. {
  168907. save[0] = *(--sp);
  168908. save[1] = *(--sp);
  168909. *(--dp) = *(--sp);
  168910. *(--dp) = *(--sp);
  168911. *(--dp) = save[0];
  168912. *(--dp) = save[1];
  168913. }
  168914. }
  168915. }
  168916. }
  168917. }
  168918. #endif
  168919. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168920. void /* PRIVATE */
  168921. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168922. {
  168923. png_debug(1, "in png_do_read_invert_alpha\n");
  168924. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168925. if (row != NULL && row_info != NULL)
  168926. #endif
  168927. {
  168928. png_uint_32 row_width = row_info->width;
  168929. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168930. {
  168931. if (row_info->bit_depth == 8)
  168932. {
  168933. png_bytep sp = row + row_info->rowbytes;
  168934. png_bytep dp = sp;
  168935. png_uint_32 i;
  168936. for (i = 0; i < row_width; i++)
  168937. {
  168938. *(--dp) = (png_byte)(255 - *(--sp));
  168939. sp-=3;
  168940. dp=sp;
  168941. }
  168942. }
  168943. else
  168944. {
  168945. png_bytep sp = row + row_info->rowbytes;
  168946. png_bytep dp = sp;
  168947. png_uint_32 i;
  168948. for (i = 0; i < row_width; i++)
  168949. {
  168950. *(--dp) = (png_byte)(255 - *(--sp));
  168951. *(--dp) = (png_byte)(255 - *(--sp));
  168952. sp-=6;
  168953. dp=sp;
  168954. }
  168955. }
  168956. }
  168957. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168958. {
  168959. if (row_info->bit_depth == 8)
  168960. {
  168961. png_bytep sp = row + row_info->rowbytes;
  168962. png_bytep dp = sp;
  168963. png_uint_32 i;
  168964. for (i = 0; i < row_width; i++)
  168965. {
  168966. *(--dp) = (png_byte)(255 - *(--sp));
  168967. *(--dp) = *(--sp);
  168968. }
  168969. }
  168970. else
  168971. {
  168972. png_bytep sp = row + row_info->rowbytes;
  168973. png_bytep dp = sp;
  168974. png_uint_32 i;
  168975. for (i = 0; i < row_width; i++)
  168976. {
  168977. *(--dp) = (png_byte)(255 - *(--sp));
  168978. *(--dp) = (png_byte)(255 - *(--sp));
  168979. sp-=2;
  168980. dp=sp;
  168981. }
  168982. }
  168983. }
  168984. }
  168985. }
  168986. #endif
  168987. #if defined(PNG_READ_FILLER_SUPPORTED)
  168988. void /* PRIVATE */
  168989. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168990. png_uint_32 filler, png_uint_32 flags)
  168991. {
  168992. png_uint_32 i;
  168993. png_uint_32 row_width = row_info->width;
  168994. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168995. png_byte lo_filler = (png_byte)(filler & 0xff);
  168996. png_debug(1, "in png_do_read_filler\n");
  168997. if (
  168998. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168999. row != NULL && row_info != NULL &&
  169000. #endif
  169001. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  169002. {
  169003. if(row_info->bit_depth == 8)
  169004. {
  169005. if (flags & PNG_FLAG_FILLER_AFTER)
  169006. {
  169007. png_bytep sp = row + (png_size_t)row_width;
  169008. png_bytep dp = sp + (png_size_t)row_width;
  169009. for (i = 1; i < row_width; i++)
  169010. {
  169011. *(--dp) = lo_filler;
  169012. *(--dp) = *(--sp);
  169013. }
  169014. *(--dp) = lo_filler;
  169015. row_info->channels = 2;
  169016. row_info->pixel_depth = 16;
  169017. row_info->rowbytes = row_width * 2;
  169018. }
  169019. else
  169020. {
  169021. png_bytep sp = row + (png_size_t)row_width;
  169022. png_bytep dp = sp + (png_size_t)row_width;
  169023. for (i = 0; i < row_width; i++)
  169024. {
  169025. *(--dp) = *(--sp);
  169026. *(--dp) = lo_filler;
  169027. }
  169028. row_info->channels = 2;
  169029. row_info->pixel_depth = 16;
  169030. row_info->rowbytes = row_width * 2;
  169031. }
  169032. }
  169033. else if(row_info->bit_depth == 16)
  169034. {
  169035. if (flags & PNG_FLAG_FILLER_AFTER)
  169036. {
  169037. png_bytep sp = row + (png_size_t)row_width * 2;
  169038. png_bytep dp = sp + (png_size_t)row_width * 2;
  169039. for (i = 1; i < row_width; i++)
  169040. {
  169041. *(--dp) = hi_filler;
  169042. *(--dp) = lo_filler;
  169043. *(--dp) = *(--sp);
  169044. *(--dp) = *(--sp);
  169045. }
  169046. *(--dp) = hi_filler;
  169047. *(--dp) = lo_filler;
  169048. row_info->channels = 2;
  169049. row_info->pixel_depth = 32;
  169050. row_info->rowbytes = row_width * 4;
  169051. }
  169052. else
  169053. {
  169054. png_bytep sp = row + (png_size_t)row_width * 2;
  169055. png_bytep dp = sp + (png_size_t)row_width * 2;
  169056. for (i = 0; i < row_width; i++)
  169057. {
  169058. *(--dp) = *(--sp);
  169059. *(--dp) = *(--sp);
  169060. *(--dp) = hi_filler;
  169061. *(--dp) = lo_filler;
  169062. }
  169063. row_info->channels = 2;
  169064. row_info->pixel_depth = 32;
  169065. row_info->rowbytes = row_width * 4;
  169066. }
  169067. }
  169068. } /* COLOR_TYPE == GRAY */
  169069. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  169070. {
  169071. if(row_info->bit_depth == 8)
  169072. {
  169073. if (flags & PNG_FLAG_FILLER_AFTER)
  169074. {
  169075. png_bytep sp = row + (png_size_t)row_width * 3;
  169076. png_bytep dp = sp + (png_size_t)row_width;
  169077. for (i = 1; i < row_width; i++)
  169078. {
  169079. *(--dp) = lo_filler;
  169080. *(--dp) = *(--sp);
  169081. *(--dp) = *(--sp);
  169082. *(--dp) = *(--sp);
  169083. }
  169084. *(--dp) = lo_filler;
  169085. row_info->channels = 4;
  169086. row_info->pixel_depth = 32;
  169087. row_info->rowbytes = row_width * 4;
  169088. }
  169089. else
  169090. {
  169091. png_bytep sp = row + (png_size_t)row_width * 3;
  169092. png_bytep dp = sp + (png_size_t)row_width;
  169093. for (i = 0; i < row_width; i++)
  169094. {
  169095. *(--dp) = *(--sp);
  169096. *(--dp) = *(--sp);
  169097. *(--dp) = *(--sp);
  169098. *(--dp) = lo_filler;
  169099. }
  169100. row_info->channels = 4;
  169101. row_info->pixel_depth = 32;
  169102. row_info->rowbytes = row_width * 4;
  169103. }
  169104. }
  169105. else if(row_info->bit_depth == 16)
  169106. {
  169107. if (flags & PNG_FLAG_FILLER_AFTER)
  169108. {
  169109. png_bytep sp = row + (png_size_t)row_width * 6;
  169110. png_bytep dp = sp + (png_size_t)row_width * 2;
  169111. for (i = 1; i < row_width; i++)
  169112. {
  169113. *(--dp) = hi_filler;
  169114. *(--dp) = lo_filler;
  169115. *(--dp) = *(--sp);
  169116. *(--dp) = *(--sp);
  169117. *(--dp) = *(--sp);
  169118. *(--dp) = *(--sp);
  169119. *(--dp) = *(--sp);
  169120. *(--dp) = *(--sp);
  169121. }
  169122. *(--dp) = hi_filler;
  169123. *(--dp) = lo_filler;
  169124. row_info->channels = 4;
  169125. row_info->pixel_depth = 64;
  169126. row_info->rowbytes = row_width * 8;
  169127. }
  169128. else
  169129. {
  169130. png_bytep sp = row + (png_size_t)row_width * 6;
  169131. png_bytep dp = sp + (png_size_t)row_width * 2;
  169132. for (i = 0; i < row_width; i++)
  169133. {
  169134. *(--dp) = *(--sp);
  169135. *(--dp) = *(--sp);
  169136. *(--dp) = *(--sp);
  169137. *(--dp) = *(--sp);
  169138. *(--dp) = *(--sp);
  169139. *(--dp) = *(--sp);
  169140. *(--dp) = hi_filler;
  169141. *(--dp) = lo_filler;
  169142. }
  169143. row_info->channels = 4;
  169144. row_info->pixel_depth = 64;
  169145. row_info->rowbytes = row_width * 8;
  169146. }
  169147. }
  169148. } /* COLOR_TYPE == RGB */
  169149. }
  169150. #endif
  169151. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  169152. void /* PRIVATE */
  169153. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  169154. {
  169155. png_uint_32 i;
  169156. png_uint_32 row_width = row_info->width;
  169157. png_debug(1, "in png_do_gray_to_rgb\n");
  169158. if (row_info->bit_depth >= 8 &&
  169159. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169160. row != NULL && row_info != NULL &&
  169161. #endif
  169162. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  169163. {
  169164. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  169165. {
  169166. if (row_info->bit_depth == 8)
  169167. {
  169168. png_bytep sp = row + (png_size_t)row_width - 1;
  169169. png_bytep dp = sp + (png_size_t)row_width * 2;
  169170. for (i = 0; i < row_width; i++)
  169171. {
  169172. *(dp--) = *sp;
  169173. *(dp--) = *sp;
  169174. *(dp--) = *(sp--);
  169175. }
  169176. }
  169177. else
  169178. {
  169179. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169180. png_bytep dp = sp + (png_size_t)row_width * 4;
  169181. for (i = 0; i < row_width; i++)
  169182. {
  169183. *(dp--) = *sp;
  169184. *(dp--) = *(sp - 1);
  169185. *(dp--) = *sp;
  169186. *(dp--) = *(sp - 1);
  169187. *(dp--) = *(sp--);
  169188. *(dp--) = *(sp--);
  169189. }
  169190. }
  169191. }
  169192. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  169193. {
  169194. if (row_info->bit_depth == 8)
  169195. {
  169196. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169197. png_bytep dp = sp + (png_size_t)row_width * 2;
  169198. for (i = 0; i < row_width; i++)
  169199. {
  169200. *(dp--) = *(sp--);
  169201. *(dp--) = *sp;
  169202. *(dp--) = *sp;
  169203. *(dp--) = *(sp--);
  169204. }
  169205. }
  169206. else
  169207. {
  169208. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  169209. png_bytep dp = sp + (png_size_t)row_width * 4;
  169210. for (i = 0; i < row_width; i++)
  169211. {
  169212. *(dp--) = *(sp--);
  169213. *(dp--) = *(sp--);
  169214. *(dp--) = *sp;
  169215. *(dp--) = *(sp - 1);
  169216. *(dp--) = *sp;
  169217. *(dp--) = *(sp - 1);
  169218. *(dp--) = *(sp--);
  169219. *(dp--) = *(sp--);
  169220. }
  169221. }
  169222. }
  169223. row_info->channels += (png_byte)2;
  169224. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  169225. row_info->pixel_depth = (png_byte)(row_info->channels *
  169226. row_info->bit_depth);
  169227. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169228. }
  169229. }
  169230. #endif
  169231. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  169232. int /* PRIVATE */
  169233. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  169234. {
  169235. png_uint_32 i;
  169236. png_uint_32 row_width = row_info->width;
  169237. int rgb_error = 0;
  169238. png_debug(1, "in png_do_rgb_to_gray\n");
  169239. if (
  169240. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169241. row != NULL && row_info != NULL &&
  169242. #endif
  169243. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  169244. {
  169245. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  169246. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  169247. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  169248. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  169249. {
  169250. if (row_info->bit_depth == 8)
  169251. {
  169252. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169253. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169254. {
  169255. png_bytep sp = row;
  169256. png_bytep dp = row;
  169257. for (i = 0; i < row_width; i++)
  169258. {
  169259. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169260. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169261. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169262. if(red != green || red != blue)
  169263. {
  169264. rgb_error |= 1;
  169265. *(dp++) = png_ptr->gamma_from_1[
  169266. (rc*red+gc*green+bc*blue)>>15];
  169267. }
  169268. else
  169269. *(dp++) = *(sp-1);
  169270. }
  169271. }
  169272. else
  169273. #endif
  169274. {
  169275. png_bytep sp = row;
  169276. png_bytep dp = row;
  169277. for (i = 0; i < row_width; i++)
  169278. {
  169279. png_byte red = *(sp++);
  169280. png_byte green = *(sp++);
  169281. png_byte blue = *(sp++);
  169282. if(red != green || red != blue)
  169283. {
  169284. rgb_error |= 1;
  169285. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  169286. }
  169287. else
  169288. *(dp++) = *(sp-1);
  169289. }
  169290. }
  169291. }
  169292. else /* RGB bit_depth == 16 */
  169293. {
  169294. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169295. if (png_ptr->gamma_16_to_1 != NULL &&
  169296. png_ptr->gamma_16_from_1 != NULL)
  169297. {
  169298. png_bytep sp = row;
  169299. png_bytep dp = row;
  169300. for (i = 0; i < row_width; i++)
  169301. {
  169302. png_uint_16 red, green, blue, w;
  169303. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169304. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169305. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169306. if(red == green && red == blue)
  169307. w = red;
  169308. else
  169309. {
  169310. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169311. png_ptr->gamma_shift][red>>8];
  169312. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169313. png_ptr->gamma_shift][green>>8];
  169314. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169315. png_ptr->gamma_shift][blue>>8];
  169316. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  169317. + bc*blue_1)>>15);
  169318. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169319. png_ptr->gamma_shift][gray16 >> 8];
  169320. rgb_error |= 1;
  169321. }
  169322. *(dp++) = (png_byte)((w>>8) & 0xff);
  169323. *(dp++) = (png_byte)(w & 0xff);
  169324. }
  169325. }
  169326. else
  169327. #endif
  169328. {
  169329. png_bytep sp = row;
  169330. png_bytep dp = row;
  169331. for (i = 0; i < row_width; i++)
  169332. {
  169333. png_uint_16 red, green, blue, gray16;
  169334. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169335. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169336. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169337. if(red != green || red != blue)
  169338. rgb_error |= 1;
  169339. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169340. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169341. *(dp++) = (png_byte)(gray16 & 0xff);
  169342. }
  169343. }
  169344. }
  169345. }
  169346. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  169347. {
  169348. if (row_info->bit_depth == 8)
  169349. {
  169350. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169351. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169352. {
  169353. png_bytep sp = row;
  169354. png_bytep dp = row;
  169355. for (i = 0; i < row_width; i++)
  169356. {
  169357. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169358. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169359. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169360. if(red != green || red != blue)
  169361. rgb_error |= 1;
  169362. *(dp++) = png_ptr->gamma_from_1
  169363. [(rc*red + gc*green + bc*blue)>>15];
  169364. *(dp++) = *(sp++); /* alpha */
  169365. }
  169366. }
  169367. else
  169368. #endif
  169369. {
  169370. png_bytep sp = row;
  169371. png_bytep dp = row;
  169372. for (i = 0; i < row_width; i++)
  169373. {
  169374. png_byte red = *(sp++);
  169375. png_byte green = *(sp++);
  169376. png_byte blue = *(sp++);
  169377. if(red != green || red != blue)
  169378. rgb_error |= 1;
  169379. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  169380. *(dp++) = *(sp++); /* alpha */
  169381. }
  169382. }
  169383. }
  169384. else /* RGBA bit_depth == 16 */
  169385. {
  169386. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169387. if (png_ptr->gamma_16_to_1 != NULL &&
  169388. png_ptr->gamma_16_from_1 != NULL)
  169389. {
  169390. png_bytep sp = row;
  169391. png_bytep dp = row;
  169392. for (i = 0; i < row_width; i++)
  169393. {
  169394. png_uint_16 red, green, blue, w;
  169395. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169396. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169397. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169398. if(red == green && red == blue)
  169399. w = red;
  169400. else
  169401. {
  169402. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169403. png_ptr->gamma_shift][red>>8];
  169404. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169405. png_ptr->gamma_shift][green>>8];
  169406. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169407. png_ptr->gamma_shift][blue>>8];
  169408. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  169409. + gc * green_1 + bc * blue_1)>>15);
  169410. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169411. png_ptr->gamma_shift][gray16 >> 8];
  169412. rgb_error |= 1;
  169413. }
  169414. *(dp++) = (png_byte)((w>>8) & 0xff);
  169415. *(dp++) = (png_byte)(w & 0xff);
  169416. *(dp++) = *(sp++); /* alpha */
  169417. *(dp++) = *(sp++);
  169418. }
  169419. }
  169420. else
  169421. #endif
  169422. {
  169423. png_bytep sp = row;
  169424. png_bytep dp = row;
  169425. for (i = 0; i < row_width; i++)
  169426. {
  169427. png_uint_16 red, green, blue, gray16;
  169428. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169429. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169430. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169431. if(red != green || red != blue)
  169432. rgb_error |= 1;
  169433. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169434. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169435. *(dp++) = (png_byte)(gray16 & 0xff);
  169436. *(dp++) = *(sp++); /* alpha */
  169437. *(dp++) = *(sp++);
  169438. }
  169439. }
  169440. }
  169441. }
  169442. row_info->channels -= (png_byte)2;
  169443. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  169444. row_info->pixel_depth = (png_byte)(row_info->channels *
  169445. row_info->bit_depth);
  169446. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169447. }
  169448. return rgb_error;
  169449. }
  169450. #endif
  169451. void PNGAPI
  169452. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  169453. {
  169454. int num_palette;
  169455. int color_inc;
  169456. int i;
  169457. int v;
  169458. png_debug(1, "in png_do_build_grayscale_palette\n");
  169459. if (palette == NULL)
  169460. return;
  169461. switch (bit_depth)
  169462. {
  169463. case 1:
  169464. num_palette = 2;
  169465. color_inc = 0xff;
  169466. break;
  169467. case 2:
  169468. num_palette = 4;
  169469. color_inc = 0x55;
  169470. break;
  169471. case 4:
  169472. num_palette = 16;
  169473. color_inc = 0x11;
  169474. break;
  169475. case 8:
  169476. num_palette = 256;
  169477. color_inc = 1;
  169478. break;
  169479. default:
  169480. num_palette = 0;
  169481. color_inc = 0;
  169482. break;
  169483. }
  169484. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  169485. {
  169486. palette[i].red = (png_byte)v;
  169487. palette[i].green = (png_byte)v;
  169488. palette[i].blue = (png_byte)v;
  169489. }
  169490. }
  169491. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  169492. void /* PRIVATE */
  169493. png_correct_palette(png_structp png_ptr, png_colorp palette,
  169494. int num_palette)
  169495. {
  169496. png_debug(1, "in png_correct_palette\n");
  169497. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  169498. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  169499. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  169500. {
  169501. png_color back, back_1;
  169502. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  169503. {
  169504. back.red = png_ptr->gamma_table[png_ptr->background.red];
  169505. back.green = png_ptr->gamma_table[png_ptr->background.green];
  169506. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  169507. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  169508. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  169509. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  169510. }
  169511. else
  169512. {
  169513. double g;
  169514. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169515. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169516. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169517. {
  169518. back.red = png_ptr->background.red;
  169519. back.green = png_ptr->background.green;
  169520. back.blue = png_ptr->background.blue;
  169521. }
  169522. else
  169523. {
  169524. back.red =
  169525. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169526. 255.0 + 0.5);
  169527. back.green =
  169528. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169529. 255.0 + 0.5);
  169530. back.blue =
  169531. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169532. 255.0 + 0.5);
  169533. }
  169534. g = 1.0 / png_ptr->background_gamma;
  169535. back_1.red =
  169536. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169537. 255.0 + 0.5);
  169538. back_1.green =
  169539. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169540. 255.0 + 0.5);
  169541. back_1.blue =
  169542. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169543. 255.0 + 0.5);
  169544. }
  169545. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169546. {
  169547. png_uint_32 i;
  169548. for (i = 0; i < (png_uint_32)num_palette; i++)
  169549. {
  169550. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169551. {
  169552. palette[i] = back;
  169553. }
  169554. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169555. {
  169556. png_byte v, w;
  169557. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169558. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169559. palette[i].red = png_ptr->gamma_from_1[w];
  169560. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169561. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169562. palette[i].green = png_ptr->gamma_from_1[w];
  169563. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169564. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169565. palette[i].blue = png_ptr->gamma_from_1[w];
  169566. }
  169567. else
  169568. {
  169569. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169570. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169571. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169572. }
  169573. }
  169574. }
  169575. else
  169576. {
  169577. int i;
  169578. for (i = 0; i < num_palette; i++)
  169579. {
  169580. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169581. {
  169582. palette[i] = back;
  169583. }
  169584. else
  169585. {
  169586. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169587. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169588. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169589. }
  169590. }
  169591. }
  169592. }
  169593. else
  169594. #endif
  169595. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169596. if (png_ptr->transformations & PNG_GAMMA)
  169597. {
  169598. int i;
  169599. for (i = 0; i < num_palette; i++)
  169600. {
  169601. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169602. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169603. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169604. }
  169605. }
  169606. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169607. else
  169608. #endif
  169609. #endif
  169610. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169611. if (png_ptr->transformations & PNG_BACKGROUND)
  169612. {
  169613. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169614. {
  169615. png_color back;
  169616. back.red = (png_byte)png_ptr->background.red;
  169617. back.green = (png_byte)png_ptr->background.green;
  169618. back.blue = (png_byte)png_ptr->background.blue;
  169619. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169620. {
  169621. if (png_ptr->trans[i] == 0)
  169622. {
  169623. palette[i].red = back.red;
  169624. palette[i].green = back.green;
  169625. palette[i].blue = back.blue;
  169626. }
  169627. else if (png_ptr->trans[i] != 0xff)
  169628. {
  169629. png_composite(palette[i].red, png_ptr->palette[i].red,
  169630. png_ptr->trans[i], back.red);
  169631. png_composite(palette[i].green, png_ptr->palette[i].green,
  169632. png_ptr->trans[i], back.green);
  169633. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169634. png_ptr->trans[i], back.blue);
  169635. }
  169636. }
  169637. }
  169638. else /* assume grayscale palette (what else could it be?) */
  169639. {
  169640. int i;
  169641. for (i = 0; i < num_palette; i++)
  169642. {
  169643. if (i == (png_byte)png_ptr->trans_values.gray)
  169644. {
  169645. palette[i].red = (png_byte)png_ptr->background.red;
  169646. palette[i].green = (png_byte)png_ptr->background.green;
  169647. palette[i].blue = (png_byte)png_ptr->background.blue;
  169648. }
  169649. }
  169650. }
  169651. }
  169652. #endif
  169653. }
  169654. #endif
  169655. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169656. void /* PRIVATE */
  169657. png_do_background(png_row_infop row_info, png_bytep row,
  169658. png_color_16p trans_values, png_color_16p background
  169659. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169660. , png_color_16p background_1,
  169661. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169662. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169663. png_uint_16pp gamma_16_to_1, int gamma_shift
  169664. #endif
  169665. )
  169666. {
  169667. png_bytep sp, dp;
  169668. png_uint_32 i;
  169669. png_uint_32 row_width=row_info->width;
  169670. int shift;
  169671. png_debug(1, "in png_do_background\n");
  169672. if (background != NULL &&
  169673. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169674. row != NULL && row_info != NULL &&
  169675. #endif
  169676. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169677. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169678. {
  169679. switch (row_info->color_type)
  169680. {
  169681. case PNG_COLOR_TYPE_GRAY:
  169682. {
  169683. switch (row_info->bit_depth)
  169684. {
  169685. case 1:
  169686. {
  169687. sp = row;
  169688. shift = 7;
  169689. for (i = 0; i < row_width; i++)
  169690. {
  169691. if ((png_uint_16)((*sp >> shift) & 0x01)
  169692. == trans_values->gray)
  169693. {
  169694. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169695. *sp |= (png_byte)(background->gray << shift);
  169696. }
  169697. if (!shift)
  169698. {
  169699. shift = 7;
  169700. sp++;
  169701. }
  169702. else
  169703. shift--;
  169704. }
  169705. break;
  169706. }
  169707. case 2:
  169708. {
  169709. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169710. if (gamma_table != NULL)
  169711. {
  169712. sp = row;
  169713. shift = 6;
  169714. for (i = 0; i < row_width; i++)
  169715. {
  169716. if ((png_uint_16)((*sp >> shift) & 0x03)
  169717. == trans_values->gray)
  169718. {
  169719. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169720. *sp |= (png_byte)(background->gray << shift);
  169721. }
  169722. else
  169723. {
  169724. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169725. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169726. (p << 4) | (p << 6)] >> 6) & 0x03);
  169727. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169728. *sp |= (png_byte)(g << shift);
  169729. }
  169730. if (!shift)
  169731. {
  169732. shift = 6;
  169733. sp++;
  169734. }
  169735. else
  169736. shift -= 2;
  169737. }
  169738. }
  169739. else
  169740. #endif
  169741. {
  169742. sp = row;
  169743. shift = 6;
  169744. for (i = 0; i < row_width; i++)
  169745. {
  169746. if ((png_uint_16)((*sp >> shift) & 0x03)
  169747. == trans_values->gray)
  169748. {
  169749. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169750. *sp |= (png_byte)(background->gray << shift);
  169751. }
  169752. if (!shift)
  169753. {
  169754. shift = 6;
  169755. sp++;
  169756. }
  169757. else
  169758. shift -= 2;
  169759. }
  169760. }
  169761. break;
  169762. }
  169763. case 4:
  169764. {
  169765. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169766. if (gamma_table != NULL)
  169767. {
  169768. sp = row;
  169769. shift = 4;
  169770. for (i = 0; i < row_width; i++)
  169771. {
  169772. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169773. == trans_values->gray)
  169774. {
  169775. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169776. *sp |= (png_byte)(background->gray << shift);
  169777. }
  169778. else
  169779. {
  169780. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169781. png_byte g = (png_byte)((gamma_table[p |
  169782. (p << 4)] >> 4) & 0x0f);
  169783. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169784. *sp |= (png_byte)(g << shift);
  169785. }
  169786. if (!shift)
  169787. {
  169788. shift = 4;
  169789. sp++;
  169790. }
  169791. else
  169792. shift -= 4;
  169793. }
  169794. }
  169795. else
  169796. #endif
  169797. {
  169798. sp = row;
  169799. shift = 4;
  169800. for (i = 0; i < row_width; i++)
  169801. {
  169802. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169803. == trans_values->gray)
  169804. {
  169805. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169806. *sp |= (png_byte)(background->gray << shift);
  169807. }
  169808. if (!shift)
  169809. {
  169810. shift = 4;
  169811. sp++;
  169812. }
  169813. else
  169814. shift -= 4;
  169815. }
  169816. }
  169817. break;
  169818. }
  169819. case 8:
  169820. {
  169821. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169822. if (gamma_table != NULL)
  169823. {
  169824. sp = row;
  169825. for (i = 0; i < row_width; i++, sp++)
  169826. {
  169827. if (*sp == trans_values->gray)
  169828. {
  169829. *sp = (png_byte)background->gray;
  169830. }
  169831. else
  169832. {
  169833. *sp = gamma_table[*sp];
  169834. }
  169835. }
  169836. }
  169837. else
  169838. #endif
  169839. {
  169840. sp = row;
  169841. for (i = 0; i < row_width; i++, sp++)
  169842. {
  169843. if (*sp == trans_values->gray)
  169844. {
  169845. *sp = (png_byte)background->gray;
  169846. }
  169847. }
  169848. }
  169849. break;
  169850. }
  169851. case 16:
  169852. {
  169853. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169854. if (gamma_16 != NULL)
  169855. {
  169856. sp = row;
  169857. for (i = 0; i < row_width; i++, sp += 2)
  169858. {
  169859. png_uint_16 v;
  169860. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169861. if (v == trans_values->gray)
  169862. {
  169863. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169864. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169865. }
  169866. else
  169867. {
  169868. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169869. *sp = (png_byte)((v >> 8) & 0xff);
  169870. *(sp + 1) = (png_byte)(v & 0xff);
  169871. }
  169872. }
  169873. }
  169874. else
  169875. #endif
  169876. {
  169877. sp = row;
  169878. for (i = 0; i < row_width; i++, sp += 2)
  169879. {
  169880. png_uint_16 v;
  169881. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169882. if (v == trans_values->gray)
  169883. {
  169884. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169885. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169886. }
  169887. }
  169888. }
  169889. break;
  169890. }
  169891. }
  169892. break;
  169893. }
  169894. case PNG_COLOR_TYPE_RGB:
  169895. {
  169896. if (row_info->bit_depth == 8)
  169897. {
  169898. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169899. if (gamma_table != NULL)
  169900. {
  169901. sp = row;
  169902. for (i = 0; i < row_width; i++, sp += 3)
  169903. {
  169904. if (*sp == trans_values->red &&
  169905. *(sp + 1) == trans_values->green &&
  169906. *(sp + 2) == trans_values->blue)
  169907. {
  169908. *sp = (png_byte)background->red;
  169909. *(sp + 1) = (png_byte)background->green;
  169910. *(sp + 2) = (png_byte)background->blue;
  169911. }
  169912. else
  169913. {
  169914. *sp = gamma_table[*sp];
  169915. *(sp + 1) = gamma_table[*(sp + 1)];
  169916. *(sp + 2) = gamma_table[*(sp + 2)];
  169917. }
  169918. }
  169919. }
  169920. else
  169921. #endif
  169922. {
  169923. sp = row;
  169924. for (i = 0; i < row_width; i++, sp += 3)
  169925. {
  169926. if (*sp == trans_values->red &&
  169927. *(sp + 1) == trans_values->green &&
  169928. *(sp + 2) == trans_values->blue)
  169929. {
  169930. *sp = (png_byte)background->red;
  169931. *(sp + 1) = (png_byte)background->green;
  169932. *(sp + 2) = (png_byte)background->blue;
  169933. }
  169934. }
  169935. }
  169936. }
  169937. else /* if (row_info->bit_depth == 16) */
  169938. {
  169939. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169940. if (gamma_16 != NULL)
  169941. {
  169942. sp = row;
  169943. for (i = 0; i < row_width; i++, sp += 6)
  169944. {
  169945. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169946. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169947. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169948. if (r == trans_values->red && g == trans_values->green &&
  169949. b == trans_values->blue)
  169950. {
  169951. *sp = (png_byte)((background->red >> 8) & 0xff);
  169952. *(sp + 1) = (png_byte)(background->red & 0xff);
  169953. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169954. *(sp + 3) = (png_byte)(background->green & 0xff);
  169955. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169956. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169957. }
  169958. else
  169959. {
  169960. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169961. *sp = (png_byte)((v >> 8) & 0xff);
  169962. *(sp + 1) = (png_byte)(v & 0xff);
  169963. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169964. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169965. *(sp + 3) = (png_byte)(v & 0xff);
  169966. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169967. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169968. *(sp + 5) = (png_byte)(v & 0xff);
  169969. }
  169970. }
  169971. }
  169972. else
  169973. #endif
  169974. {
  169975. sp = row;
  169976. for (i = 0; i < row_width; i++, sp += 6)
  169977. {
  169978. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169979. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169980. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169981. if (r == trans_values->red && g == trans_values->green &&
  169982. b == trans_values->blue)
  169983. {
  169984. *sp = (png_byte)((background->red >> 8) & 0xff);
  169985. *(sp + 1) = (png_byte)(background->red & 0xff);
  169986. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169987. *(sp + 3) = (png_byte)(background->green & 0xff);
  169988. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169989. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169990. }
  169991. }
  169992. }
  169993. }
  169994. break;
  169995. }
  169996. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169997. {
  169998. if (row_info->bit_depth == 8)
  169999. {
  170000. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170001. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  170002. gamma_table != NULL)
  170003. {
  170004. sp = row;
  170005. dp = row;
  170006. for (i = 0; i < row_width; i++, sp += 2, dp++)
  170007. {
  170008. png_uint_16 a = *(sp + 1);
  170009. if (a == 0xff)
  170010. {
  170011. *dp = gamma_table[*sp];
  170012. }
  170013. else if (a == 0)
  170014. {
  170015. *dp = (png_byte)background->gray;
  170016. }
  170017. else
  170018. {
  170019. png_byte v, w;
  170020. v = gamma_to_1[*sp];
  170021. png_composite(w, v, a, background_1->gray);
  170022. *dp = gamma_from_1[w];
  170023. }
  170024. }
  170025. }
  170026. else
  170027. #endif
  170028. {
  170029. sp = row;
  170030. dp = row;
  170031. for (i = 0; i < row_width; i++, sp += 2, dp++)
  170032. {
  170033. png_byte a = *(sp + 1);
  170034. if (a == 0xff)
  170035. {
  170036. *dp = *sp;
  170037. }
  170038. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170039. else if (a == 0)
  170040. {
  170041. *dp = (png_byte)background->gray;
  170042. }
  170043. else
  170044. {
  170045. png_composite(*dp, *sp, a, background_1->gray);
  170046. }
  170047. #else
  170048. *dp = (png_byte)background->gray;
  170049. #endif
  170050. }
  170051. }
  170052. }
  170053. else /* if (png_ptr->bit_depth == 16) */
  170054. {
  170055. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170056. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  170057. gamma_16_to_1 != NULL)
  170058. {
  170059. sp = row;
  170060. dp = row;
  170061. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  170062. {
  170063. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170064. if (a == (png_uint_16)0xffff)
  170065. {
  170066. png_uint_16 v;
  170067. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170068. *dp = (png_byte)((v >> 8) & 0xff);
  170069. *(dp + 1) = (png_byte)(v & 0xff);
  170070. }
  170071. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170072. else if (a == 0)
  170073. #else
  170074. else
  170075. #endif
  170076. {
  170077. *dp = (png_byte)((background->gray >> 8) & 0xff);
  170078. *(dp + 1) = (png_byte)(background->gray & 0xff);
  170079. }
  170080. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170081. else
  170082. {
  170083. png_uint_16 g, v, w;
  170084. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  170085. png_composite_16(v, g, a, background_1->gray);
  170086. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  170087. *dp = (png_byte)((w >> 8) & 0xff);
  170088. *(dp + 1) = (png_byte)(w & 0xff);
  170089. }
  170090. #endif
  170091. }
  170092. }
  170093. else
  170094. #endif
  170095. {
  170096. sp = row;
  170097. dp = row;
  170098. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  170099. {
  170100. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170101. if (a == (png_uint_16)0xffff)
  170102. {
  170103. png_memcpy(dp, sp, 2);
  170104. }
  170105. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170106. else if (a == 0)
  170107. #else
  170108. else
  170109. #endif
  170110. {
  170111. *dp = (png_byte)((background->gray >> 8) & 0xff);
  170112. *(dp + 1) = (png_byte)(background->gray & 0xff);
  170113. }
  170114. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170115. else
  170116. {
  170117. png_uint_16 g, v;
  170118. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170119. png_composite_16(v, g, a, background_1->gray);
  170120. *dp = (png_byte)((v >> 8) & 0xff);
  170121. *(dp + 1) = (png_byte)(v & 0xff);
  170122. }
  170123. #endif
  170124. }
  170125. }
  170126. }
  170127. break;
  170128. }
  170129. case PNG_COLOR_TYPE_RGB_ALPHA:
  170130. {
  170131. if (row_info->bit_depth == 8)
  170132. {
  170133. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170134. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  170135. gamma_table != NULL)
  170136. {
  170137. sp = row;
  170138. dp = row;
  170139. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170140. {
  170141. png_byte a = *(sp + 3);
  170142. if (a == 0xff)
  170143. {
  170144. *dp = gamma_table[*sp];
  170145. *(dp + 1) = gamma_table[*(sp + 1)];
  170146. *(dp + 2) = gamma_table[*(sp + 2)];
  170147. }
  170148. else if (a == 0)
  170149. {
  170150. *dp = (png_byte)background->red;
  170151. *(dp + 1) = (png_byte)background->green;
  170152. *(dp + 2) = (png_byte)background->blue;
  170153. }
  170154. else
  170155. {
  170156. png_byte v, w;
  170157. v = gamma_to_1[*sp];
  170158. png_composite(w, v, a, background_1->red);
  170159. *dp = gamma_from_1[w];
  170160. v = gamma_to_1[*(sp + 1)];
  170161. png_composite(w, v, a, background_1->green);
  170162. *(dp + 1) = gamma_from_1[w];
  170163. v = gamma_to_1[*(sp + 2)];
  170164. png_composite(w, v, a, background_1->blue);
  170165. *(dp + 2) = gamma_from_1[w];
  170166. }
  170167. }
  170168. }
  170169. else
  170170. #endif
  170171. {
  170172. sp = row;
  170173. dp = row;
  170174. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170175. {
  170176. png_byte a = *(sp + 3);
  170177. if (a == 0xff)
  170178. {
  170179. *dp = *sp;
  170180. *(dp + 1) = *(sp + 1);
  170181. *(dp + 2) = *(sp + 2);
  170182. }
  170183. else if (a == 0)
  170184. {
  170185. *dp = (png_byte)background->red;
  170186. *(dp + 1) = (png_byte)background->green;
  170187. *(dp + 2) = (png_byte)background->blue;
  170188. }
  170189. else
  170190. {
  170191. png_composite(*dp, *sp, a, background->red);
  170192. png_composite(*(dp + 1), *(sp + 1), a,
  170193. background->green);
  170194. png_composite(*(dp + 2), *(sp + 2), a,
  170195. background->blue);
  170196. }
  170197. }
  170198. }
  170199. }
  170200. else /* if (row_info->bit_depth == 16) */
  170201. {
  170202. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170203. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  170204. gamma_16_to_1 != NULL)
  170205. {
  170206. sp = row;
  170207. dp = row;
  170208. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170209. {
  170210. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170211. << 8) + (png_uint_16)(*(sp + 7)));
  170212. if (a == (png_uint_16)0xffff)
  170213. {
  170214. png_uint_16 v;
  170215. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170216. *dp = (png_byte)((v >> 8) & 0xff);
  170217. *(dp + 1) = (png_byte)(v & 0xff);
  170218. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170219. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170220. *(dp + 3) = (png_byte)(v & 0xff);
  170221. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170222. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170223. *(dp + 5) = (png_byte)(v & 0xff);
  170224. }
  170225. else if (a == 0)
  170226. {
  170227. *dp = (png_byte)((background->red >> 8) & 0xff);
  170228. *(dp + 1) = (png_byte)(background->red & 0xff);
  170229. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170230. *(dp + 3) = (png_byte)(background->green & 0xff);
  170231. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170232. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170233. }
  170234. else
  170235. {
  170236. png_uint_16 v, w, x;
  170237. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  170238. png_composite_16(w, v, a, background_1->red);
  170239. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170240. *dp = (png_byte)((x >> 8) & 0xff);
  170241. *(dp + 1) = (png_byte)(x & 0xff);
  170242. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170243. png_composite_16(w, v, a, background_1->green);
  170244. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170245. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  170246. *(dp + 3) = (png_byte)(x & 0xff);
  170247. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170248. png_composite_16(w, v, a, background_1->blue);
  170249. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  170250. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  170251. *(dp + 5) = (png_byte)(x & 0xff);
  170252. }
  170253. }
  170254. }
  170255. else
  170256. #endif
  170257. {
  170258. sp = row;
  170259. dp = row;
  170260. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170261. {
  170262. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170263. << 8) + (png_uint_16)(*(sp + 7)));
  170264. if (a == (png_uint_16)0xffff)
  170265. {
  170266. png_memcpy(dp, sp, 6);
  170267. }
  170268. else if (a == 0)
  170269. {
  170270. *dp = (png_byte)((background->red >> 8) & 0xff);
  170271. *(dp + 1) = (png_byte)(background->red & 0xff);
  170272. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170273. *(dp + 3) = (png_byte)(background->green & 0xff);
  170274. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170275. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170276. }
  170277. else
  170278. {
  170279. png_uint_16 v;
  170280. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170281. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  170282. + *(sp + 3));
  170283. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  170284. + *(sp + 5));
  170285. png_composite_16(v, r, a, background->red);
  170286. *dp = (png_byte)((v >> 8) & 0xff);
  170287. *(dp + 1) = (png_byte)(v & 0xff);
  170288. png_composite_16(v, g, a, background->green);
  170289. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170290. *(dp + 3) = (png_byte)(v & 0xff);
  170291. png_composite_16(v, b, a, background->blue);
  170292. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170293. *(dp + 5) = (png_byte)(v & 0xff);
  170294. }
  170295. }
  170296. }
  170297. }
  170298. break;
  170299. }
  170300. }
  170301. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  170302. {
  170303. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  170304. row_info->channels--;
  170305. row_info->pixel_depth = (png_byte)(row_info->channels *
  170306. row_info->bit_depth);
  170307. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170308. }
  170309. }
  170310. }
  170311. #endif
  170312. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170313. void /* PRIVATE */
  170314. png_do_gamma(png_row_infop row_info, png_bytep row,
  170315. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  170316. int gamma_shift)
  170317. {
  170318. png_bytep sp;
  170319. png_uint_32 i;
  170320. png_uint_32 row_width=row_info->width;
  170321. png_debug(1, "in png_do_gamma\n");
  170322. if (
  170323. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170324. row != NULL && row_info != NULL &&
  170325. #endif
  170326. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  170327. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  170328. {
  170329. switch (row_info->color_type)
  170330. {
  170331. case PNG_COLOR_TYPE_RGB:
  170332. {
  170333. if (row_info->bit_depth == 8)
  170334. {
  170335. sp = row;
  170336. for (i = 0; i < row_width; i++)
  170337. {
  170338. *sp = gamma_table[*sp];
  170339. sp++;
  170340. *sp = gamma_table[*sp];
  170341. sp++;
  170342. *sp = gamma_table[*sp];
  170343. sp++;
  170344. }
  170345. }
  170346. else /* if (row_info->bit_depth == 16) */
  170347. {
  170348. sp = row;
  170349. for (i = 0; i < row_width; i++)
  170350. {
  170351. png_uint_16 v;
  170352. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170353. *sp = (png_byte)((v >> 8) & 0xff);
  170354. *(sp + 1) = (png_byte)(v & 0xff);
  170355. sp += 2;
  170356. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170357. *sp = (png_byte)((v >> 8) & 0xff);
  170358. *(sp + 1) = (png_byte)(v & 0xff);
  170359. sp += 2;
  170360. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170361. *sp = (png_byte)((v >> 8) & 0xff);
  170362. *(sp + 1) = (png_byte)(v & 0xff);
  170363. sp += 2;
  170364. }
  170365. }
  170366. break;
  170367. }
  170368. case PNG_COLOR_TYPE_RGB_ALPHA:
  170369. {
  170370. if (row_info->bit_depth == 8)
  170371. {
  170372. sp = row;
  170373. for (i = 0; i < row_width; i++)
  170374. {
  170375. *sp = gamma_table[*sp];
  170376. sp++;
  170377. *sp = gamma_table[*sp];
  170378. sp++;
  170379. *sp = gamma_table[*sp];
  170380. sp++;
  170381. sp++;
  170382. }
  170383. }
  170384. else /* if (row_info->bit_depth == 16) */
  170385. {
  170386. sp = row;
  170387. for (i = 0; i < row_width; i++)
  170388. {
  170389. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170390. *sp = (png_byte)((v >> 8) & 0xff);
  170391. *(sp + 1) = (png_byte)(v & 0xff);
  170392. sp += 2;
  170393. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170394. *sp = (png_byte)((v >> 8) & 0xff);
  170395. *(sp + 1) = (png_byte)(v & 0xff);
  170396. sp += 2;
  170397. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170398. *sp = (png_byte)((v >> 8) & 0xff);
  170399. *(sp + 1) = (png_byte)(v & 0xff);
  170400. sp += 4;
  170401. }
  170402. }
  170403. break;
  170404. }
  170405. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170406. {
  170407. if (row_info->bit_depth == 8)
  170408. {
  170409. sp = row;
  170410. for (i = 0; i < row_width; i++)
  170411. {
  170412. *sp = gamma_table[*sp];
  170413. sp += 2;
  170414. }
  170415. }
  170416. else /* if (row_info->bit_depth == 16) */
  170417. {
  170418. sp = row;
  170419. for (i = 0; i < row_width; i++)
  170420. {
  170421. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170422. *sp = (png_byte)((v >> 8) & 0xff);
  170423. *(sp + 1) = (png_byte)(v & 0xff);
  170424. sp += 4;
  170425. }
  170426. }
  170427. break;
  170428. }
  170429. case PNG_COLOR_TYPE_GRAY:
  170430. {
  170431. if (row_info->bit_depth == 2)
  170432. {
  170433. sp = row;
  170434. for (i = 0; i < row_width; i += 4)
  170435. {
  170436. int a = *sp & 0xc0;
  170437. int b = *sp & 0x30;
  170438. int c = *sp & 0x0c;
  170439. int d = *sp & 0x03;
  170440. *sp = (png_byte)(
  170441. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  170442. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  170443. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  170444. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  170445. sp++;
  170446. }
  170447. }
  170448. if (row_info->bit_depth == 4)
  170449. {
  170450. sp = row;
  170451. for (i = 0; i < row_width; i += 2)
  170452. {
  170453. int msb = *sp & 0xf0;
  170454. int lsb = *sp & 0x0f;
  170455. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  170456. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  170457. sp++;
  170458. }
  170459. }
  170460. else if (row_info->bit_depth == 8)
  170461. {
  170462. sp = row;
  170463. for (i = 0; i < row_width; i++)
  170464. {
  170465. *sp = gamma_table[*sp];
  170466. sp++;
  170467. }
  170468. }
  170469. else if (row_info->bit_depth == 16)
  170470. {
  170471. sp = row;
  170472. for (i = 0; i < row_width; i++)
  170473. {
  170474. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170475. *sp = (png_byte)((v >> 8) & 0xff);
  170476. *(sp + 1) = (png_byte)(v & 0xff);
  170477. sp += 2;
  170478. }
  170479. }
  170480. break;
  170481. }
  170482. }
  170483. }
  170484. }
  170485. #endif
  170486. #if defined(PNG_READ_EXPAND_SUPPORTED)
  170487. void /* PRIVATE */
  170488. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  170489. png_colorp palette, png_bytep trans, int num_trans)
  170490. {
  170491. int shift, value;
  170492. png_bytep sp, dp;
  170493. png_uint_32 i;
  170494. png_uint_32 row_width=row_info->width;
  170495. png_debug(1, "in png_do_expand_palette\n");
  170496. if (
  170497. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170498. row != NULL && row_info != NULL &&
  170499. #endif
  170500. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  170501. {
  170502. if (row_info->bit_depth < 8)
  170503. {
  170504. switch (row_info->bit_depth)
  170505. {
  170506. case 1:
  170507. {
  170508. sp = row + (png_size_t)((row_width - 1) >> 3);
  170509. dp = row + (png_size_t)row_width - 1;
  170510. shift = 7 - (int)((row_width + 7) & 0x07);
  170511. for (i = 0; i < row_width; i++)
  170512. {
  170513. if ((*sp >> shift) & 0x01)
  170514. *dp = 1;
  170515. else
  170516. *dp = 0;
  170517. if (shift == 7)
  170518. {
  170519. shift = 0;
  170520. sp--;
  170521. }
  170522. else
  170523. shift++;
  170524. dp--;
  170525. }
  170526. break;
  170527. }
  170528. case 2:
  170529. {
  170530. sp = row + (png_size_t)((row_width - 1) >> 2);
  170531. dp = row + (png_size_t)row_width - 1;
  170532. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170533. for (i = 0; i < row_width; i++)
  170534. {
  170535. value = (*sp >> shift) & 0x03;
  170536. *dp = (png_byte)value;
  170537. if (shift == 6)
  170538. {
  170539. shift = 0;
  170540. sp--;
  170541. }
  170542. else
  170543. shift += 2;
  170544. dp--;
  170545. }
  170546. break;
  170547. }
  170548. case 4:
  170549. {
  170550. sp = row + (png_size_t)((row_width - 1) >> 1);
  170551. dp = row + (png_size_t)row_width - 1;
  170552. shift = (int)((row_width & 0x01) << 2);
  170553. for (i = 0; i < row_width; i++)
  170554. {
  170555. value = (*sp >> shift) & 0x0f;
  170556. *dp = (png_byte)value;
  170557. if (shift == 4)
  170558. {
  170559. shift = 0;
  170560. sp--;
  170561. }
  170562. else
  170563. shift += 4;
  170564. dp--;
  170565. }
  170566. break;
  170567. }
  170568. }
  170569. row_info->bit_depth = 8;
  170570. row_info->pixel_depth = 8;
  170571. row_info->rowbytes = row_width;
  170572. }
  170573. switch (row_info->bit_depth)
  170574. {
  170575. case 8:
  170576. {
  170577. if (trans != NULL)
  170578. {
  170579. sp = row + (png_size_t)row_width - 1;
  170580. dp = row + (png_size_t)(row_width << 2) - 1;
  170581. for (i = 0; i < row_width; i++)
  170582. {
  170583. if ((int)(*sp) >= num_trans)
  170584. *dp-- = 0xff;
  170585. else
  170586. *dp-- = trans[*sp];
  170587. *dp-- = palette[*sp].blue;
  170588. *dp-- = palette[*sp].green;
  170589. *dp-- = palette[*sp].red;
  170590. sp--;
  170591. }
  170592. row_info->bit_depth = 8;
  170593. row_info->pixel_depth = 32;
  170594. row_info->rowbytes = row_width * 4;
  170595. row_info->color_type = 6;
  170596. row_info->channels = 4;
  170597. }
  170598. else
  170599. {
  170600. sp = row + (png_size_t)row_width - 1;
  170601. dp = row + (png_size_t)(row_width * 3) - 1;
  170602. for (i = 0; i < row_width; i++)
  170603. {
  170604. *dp-- = palette[*sp].blue;
  170605. *dp-- = palette[*sp].green;
  170606. *dp-- = palette[*sp].red;
  170607. sp--;
  170608. }
  170609. row_info->bit_depth = 8;
  170610. row_info->pixel_depth = 24;
  170611. row_info->rowbytes = row_width * 3;
  170612. row_info->color_type = 2;
  170613. row_info->channels = 3;
  170614. }
  170615. break;
  170616. }
  170617. }
  170618. }
  170619. }
  170620. void /* PRIVATE */
  170621. png_do_expand(png_row_infop row_info, png_bytep row,
  170622. png_color_16p trans_value)
  170623. {
  170624. int shift, value;
  170625. png_bytep sp, dp;
  170626. png_uint_32 i;
  170627. png_uint_32 row_width=row_info->width;
  170628. png_debug(1, "in png_do_expand\n");
  170629. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170630. if (row != NULL && row_info != NULL)
  170631. #endif
  170632. {
  170633. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170634. {
  170635. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170636. if (row_info->bit_depth < 8)
  170637. {
  170638. switch (row_info->bit_depth)
  170639. {
  170640. case 1:
  170641. {
  170642. gray = (png_uint_16)((gray&0x01)*0xff);
  170643. sp = row + (png_size_t)((row_width - 1) >> 3);
  170644. dp = row + (png_size_t)row_width - 1;
  170645. shift = 7 - (int)((row_width + 7) & 0x07);
  170646. for (i = 0; i < row_width; i++)
  170647. {
  170648. if ((*sp >> shift) & 0x01)
  170649. *dp = 0xff;
  170650. else
  170651. *dp = 0;
  170652. if (shift == 7)
  170653. {
  170654. shift = 0;
  170655. sp--;
  170656. }
  170657. else
  170658. shift++;
  170659. dp--;
  170660. }
  170661. break;
  170662. }
  170663. case 2:
  170664. {
  170665. gray = (png_uint_16)((gray&0x03)*0x55);
  170666. sp = row + (png_size_t)((row_width - 1) >> 2);
  170667. dp = row + (png_size_t)row_width - 1;
  170668. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170669. for (i = 0; i < row_width; i++)
  170670. {
  170671. value = (*sp >> shift) & 0x03;
  170672. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170673. (value << 6));
  170674. if (shift == 6)
  170675. {
  170676. shift = 0;
  170677. sp--;
  170678. }
  170679. else
  170680. shift += 2;
  170681. dp--;
  170682. }
  170683. break;
  170684. }
  170685. case 4:
  170686. {
  170687. gray = (png_uint_16)((gray&0x0f)*0x11);
  170688. sp = row + (png_size_t)((row_width - 1) >> 1);
  170689. dp = row + (png_size_t)row_width - 1;
  170690. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170691. for (i = 0; i < row_width; i++)
  170692. {
  170693. value = (*sp >> shift) & 0x0f;
  170694. *dp = (png_byte)(value | (value << 4));
  170695. if (shift == 4)
  170696. {
  170697. shift = 0;
  170698. sp--;
  170699. }
  170700. else
  170701. shift = 4;
  170702. dp--;
  170703. }
  170704. break;
  170705. }
  170706. }
  170707. row_info->bit_depth = 8;
  170708. row_info->pixel_depth = 8;
  170709. row_info->rowbytes = row_width;
  170710. }
  170711. if (trans_value != NULL)
  170712. {
  170713. if (row_info->bit_depth == 8)
  170714. {
  170715. gray = gray & 0xff;
  170716. sp = row + (png_size_t)row_width - 1;
  170717. dp = row + (png_size_t)(row_width << 1) - 1;
  170718. for (i = 0; i < row_width; i++)
  170719. {
  170720. if (*sp == gray)
  170721. *dp-- = 0;
  170722. else
  170723. *dp-- = 0xff;
  170724. *dp-- = *sp--;
  170725. }
  170726. }
  170727. else if (row_info->bit_depth == 16)
  170728. {
  170729. png_byte gray_high = (gray >> 8) & 0xff;
  170730. png_byte gray_low = gray & 0xff;
  170731. sp = row + row_info->rowbytes - 1;
  170732. dp = row + (row_info->rowbytes << 1) - 1;
  170733. for (i = 0; i < row_width; i++)
  170734. {
  170735. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170736. {
  170737. *dp-- = 0;
  170738. *dp-- = 0;
  170739. }
  170740. else
  170741. {
  170742. *dp-- = 0xff;
  170743. *dp-- = 0xff;
  170744. }
  170745. *dp-- = *sp--;
  170746. *dp-- = *sp--;
  170747. }
  170748. }
  170749. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170750. row_info->channels = 2;
  170751. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170752. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170753. row_width);
  170754. }
  170755. }
  170756. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170757. {
  170758. if (row_info->bit_depth == 8)
  170759. {
  170760. png_byte red = trans_value->red & 0xff;
  170761. png_byte green = trans_value->green & 0xff;
  170762. png_byte blue = trans_value->blue & 0xff;
  170763. sp = row + (png_size_t)row_info->rowbytes - 1;
  170764. dp = row + (png_size_t)(row_width << 2) - 1;
  170765. for (i = 0; i < row_width; i++)
  170766. {
  170767. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170768. *dp-- = 0;
  170769. else
  170770. *dp-- = 0xff;
  170771. *dp-- = *sp--;
  170772. *dp-- = *sp--;
  170773. *dp-- = *sp--;
  170774. }
  170775. }
  170776. else if (row_info->bit_depth == 16)
  170777. {
  170778. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170779. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170780. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170781. png_byte red_low = trans_value->red & 0xff;
  170782. png_byte green_low = trans_value->green & 0xff;
  170783. png_byte blue_low = trans_value->blue & 0xff;
  170784. sp = row + row_info->rowbytes - 1;
  170785. dp = row + (png_size_t)(row_width << 3) - 1;
  170786. for (i = 0; i < row_width; i++)
  170787. {
  170788. if (*(sp - 5) == red_high &&
  170789. *(sp - 4) == red_low &&
  170790. *(sp - 3) == green_high &&
  170791. *(sp - 2) == green_low &&
  170792. *(sp - 1) == blue_high &&
  170793. *(sp ) == blue_low)
  170794. {
  170795. *dp-- = 0;
  170796. *dp-- = 0;
  170797. }
  170798. else
  170799. {
  170800. *dp-- = 0xff;
  170801. *dp-- = 0xff;
  170802. }
  170803. *dp-- = *sp--;
  170804. *dp-- = *sp--;
  170805. *dp-- = *sp--;
  170806. *dp-- = *sp--;
  170807. *dp-- = *sp--;
  170808. *dp-- = *sp--;
  170809. }
  170810. }
  170811. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170812. row_info->channels = 4;
  170813. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170814. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170815. }
  170816. }
  170817. }
  170818. #endif
  170819. #if defined(PNG_READ_DITHER_SUPPORTED)
  170820. void /* PRIVATE */
  170821. png_do_dither(png_row_infop row_info, png_bytep row,
  170822. png_bytep palette_lookup, png_bytep dither_lookup)
  170823. {
  170824. png_bytep sp, dp;
  170825. png_uint_32 i;
  170826. png_uint_32 row_width=row_info->width;
  170827. png_debug(1, "in png_do_dither\n");
  170828. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170829. if (row != NULL && row_info != NULL)
  170830. #endif
  170831. {
  170832. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170833. palette_lookup && row_info->bit_depth == 8)
  170834. {
  170835. int r, g, b, p;
  170836. sp = row;
  170837. dp = row;
  170838. for (i = 0; i < row_width; i++)
  170839. {
  170840. r = *sp++;
  170841. g = *sp++;
  170842. b = *sp++;
  170843. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170844. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170845. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170846. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170847. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170848. (PNG_DITHER_BLUE_BITS)) |
  170849. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170850. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170851. *dp++ = palette_lookup[p];
  170852. }
  170853. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170854. row_info->channels = 1;
  170855. row_info->pixel_depth = row_info->bit_depth;
  170856. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170857. }
  170858. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170859. palette_lookup != NULL && row_info->bit_depth == 8)
  170860. {
  170861. int r, g, b, p;
  170862. sp = row;
  170863. dp = row;
  170864. for (i = 0; i < row_width; i++)
  170865. {
  170866. r = *sp++;
  170867. g = *sp++;
  170868. b = *sp++;
  170869. sp++;
  170870. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170871. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170872. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170873. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170874. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170875. (PNG_DITHER_BLUE_BITS)) |
  170876. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170877. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170878. *dp++ = palette_lookup[p];
  170879. }
  170880. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170881. row_info->channels = 1;
  170882. row_info->pixel_depth = row_info->bit_depth;
  170883. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170884. }
  170885. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170886. dither_lookup && row_info->bit_depth == 8)
  170887. {
  170888. sp = row;
  170889. for (i = 0; i < row_width; i++, sp++)
  170890. {
  170891. *sp = dither_lookup[*sp];
  170892. }
  170893. }
  170894. }
  170895. }
  170896. #endif
  170897. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170898. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170899. static PNG_CONST int png_gamma_shift[] =
  170900. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170901. void /* PRIVATE */
  170902. png_build_gamma_table(png_structp png_ptr)
  170903. {
  170904. png_debug(1, "in png_build_gamma_table\n");
  170905. if (png_ptr->bit_depth <= 8)
  170906. {
  170907. int i;
  170908. double g;
  170909. if (png_ptr->screen_gamma > .000001)
  170910. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170911. else
  170912. g = 1.0;
  170913. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170914. (png_uint_32)256);
  170915. for (i = 0; i < 256; i++)
  170916. {
  170917. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170918. g) * 255.0 + .5);
  170919. }
  170920. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170921. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170922. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170923. {
  170924. g = 1.0 / (png_ptr->gamma);
  170925. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170926. (png_uint_32)256);
  170927. for (i = 0; i < 256; i++)
  170928. {
  170929. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170930. g) * 255.0 + .5);
  170931. }
  170932. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170933. (png_uint_32)256);
  170934. if(png_ptr->screen_gamma > 0.000001)
  170935. g = 1.0 / png_ptr->screen_gamma;
  170936. else
  170937. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170938. for (i = 0; i < 256; i++)
  170939. {
  170940. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170941. g) * 255.0 + .5);
  170942. }
  170943. }
  170944. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170945. }
  170946. else
  170947. {
  170948. double g;
  170949. int i, j, shift, num;
  170950. int sig_bit;
  170951. png_uint_32 ig;
  170952. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170953. {
  170954. sig_bit = (int)png_ptr->sig_bit.red;
  170955. if ((int)png_ptr->sig_bit.green > sig_bit)
  170956. sig_bit = png_ptr->sig_bit.green;
  170957. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170958. sig_bit = png_ptr->sig_bit.blue;
  170959. }
  170960. else
  170961. {
  170962. sig_bit = (int)png_ptr->sig_bit.gray;
  170963. }
  170964. if (sig_bit > 0)
  170965. shift = 16 - sig_bit;
  170966. else
  170967. shift = 0;
  170968. if (png_ptr->transformations & PNG_16_TO_8)
  170969. {
  170970. if (shift < (16 - PNG_MAX_GAMMA_8))
  170971. shift = (16 - PNG_MAX_GAMMA_8);
  170972. }
  170973. if (shift > 8)
  170974. shift = 8;
  170975. if (shift < 0)
  170976. shift = 0;
  170977. png_ptr->gamma_shift = (png_byte)shift;
  170978. num = (1 << (8 - shift));
  170979. if (png_ptr->screen_gamma > .000001)
  170980. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170981. else
  170982. g = 1.0;
  170983. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170984. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170985. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170986. {
  170987. double fin, fout;
  170988. png_uint_32 last, max;
  170989. for (i = 0; i < num; i++)
  170990. {
  170991. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170992. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170993. }
  170994. g = 1.0 / g;
  170995. last = 0;
  170996. for (i = 0; i < 256; i++)
  170997. {
  170998. fout = ((double)i + 0.5) / 256.0;
  170999. fin = pow(fout, g);
  171000. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  171001. while (last <= max)
  171002. {
  171003. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  171004. [(int)(last >> (8 - shift))] = (png_uint_16)(
  171005. (png_uint_16)i | ((png_uint_16)i << 8));
  171006. last++;
  171007. }
  171008. }
  171009. while (last < ((png_uint_32)num << 8))
  171010. {
  171011. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  171012. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  171013. last++;
  171014. }
  171015. }
  171016. else
  171017. {
  171018. for (i = 0; i < num; i++)
  171019. {
  171020. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  171021. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171022. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  171023. for (j = 0; j < 256; j++)
  171024. {
  171025. png_ptr->gamma_16_table[i][j] =
  171026. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171027. 65535.0, g) * 65535.0 + .5);
  171028. }
  171029. }
  171030. }
  171031. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  171032. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  171033. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  171034. {
  171035. g = 1.0 / (png_ptr->gamma);
  171036. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  171037. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  171038. for (i = 0; i < num; i++)
  171039. {
  171040. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  171041. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171042. ig = (((png_uint_32)i *
  171043. (png_uint_32)png_gamma_shift[shift]) >> 4);
  171044. for (j = 0; j < 256; j++)
  171045. {
  171046. png_ptr->gamma_16_to_1[i][j] =
  171047. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171048. 65535.0, g) * 65535.0 + .5);
  171049. }
  171050. }
  171051. if(png_ptr->screen_gamma > 0.000001)
  171052. g = 1.0 / png_ptr->screen_gamma;
  171053. else
  171054. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  171055. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  171056. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  171057. for (i = 0; i < num; i++)
  171058. {
  171059. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  171060. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171061. ig = (((png_uint_32)i *
  171062. (png_uint_32)png_gamma_shift[shift]) >> 4);
  171063. for (j = 0; j < 256; j++)
  171064. {
  171065. png_ptr->gamma_16_from_1[i][j] =
  171066. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171067. 65535.0, g) * 65535.0 + .5);
  171068. }
  171069. }
  171070. }
  171071. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  171072. }
  171073. }
  171074. #endif
  171075. #endif
  171076. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171077. void /* PRIVATE */
  171078. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  171079. {
  171080. png_debug(1, "in png_do_read_intrapixel\n");
  171081. if (
  171082. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  171083. row != NULL && row_info != NULL &&
  171084. #endif
  171085. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  171086. {
  171087. int bytes_per_pixel;
  171088. png_uint_32 row_width = row_info->width;
  171089. if (row_info->bit_depth == 8)
  171090. {
  171091. png_bytep rp;
  171092. png_uint_32 i;
  171093. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  171094. bytes_per_pixel = 3;
  171095. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  171096. bytes_per_pixel = 4;
  171097. else
  171098. return;
  171099. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  171100. {
  171101. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  171102. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  171103. }
  171104. }
  171105. else if (row_info->bit_depth == 16)
  171106. {
  171107. png_bytep rp;
  171108. png_uint_32 i;
  171109. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  171110. bytes_per_pixel = 6;
  171111. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  171112. bytes_per_pixel = 8;
  171113. else
  171114. return;
  171115. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  171116. {
  171117. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  171118. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  171119. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  171120. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  171121. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  171122. *(rp ) = (png_byte)((red >> 8) & 0xff);
  171123. *(rp+1) = (png_byte)(red & 0xff);
  171124. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  171125. *(rp+5) = (png_byte)(blue & 0xff);
  171126. }
  171127. }
  171128. }
  171129. }
  171130. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  171131. #endif /* PNG_READ_SUPPORTED */
  171132. /*** End of inlined file: pngrtran.c ***/
  171133. /*** Start of inlined file: pngrutil.c ***/
  171134. #define PNG_INTERNAL
  171135. #if defined(PNG_READ_SUPPORTED)
  171136. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  171137. # define WIN32_WCE_OLD
  171138. #endif
  171139. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171140. # if defined(WIN32_WCE_OLD)
  171141. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  171142. {
  171143. double result = 0;
  171144. int len;
  171145. wchar_t *str, *end;
  171146. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  171147. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  171148. if ( NULL != str )
  171149. {
  171150. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  171151. result = wcstod(str, &end);
  171152. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  171153. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  171154. png_free(png_ptr, str);
  171155. }
  171156. return result;
  171157. }
  171158. # else
  171159. # define png_strtod(p,a,b) strtod(a,b)
  171160. # endif
  171161. #endif
  171162. png_uint_32 PNGAPI
  171163. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  171164. {
  171165. png_uint_32 i = png_get_uint_32(buf);
  171166. if (i > PNG_UINT_31_MAX)
  171167. png_error(png_ptr, "PNG unsigned integer out of range.");
  171168. return (i);
  171169. }
  171170. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  171171. png_uint_32 PNGAPI
  171172. png_get_uint_32(png_bytep buf)
  171173. {
  171174. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  171175. ((png_uint_32)(*(buf + 1)) << 16) +
  171176. ((png_uint_32)(*(buf + 2)) << 8) +
  171177. (png_uint_32)(*(buf + 3));
  171178. return (i);
  171179. }
  171180. png_int_32 PNGAPI
  171181. png_get_int_32(png_bytep buf)
  171182. {
  171183. png_int_32 i = ((png_int_32)(*buf) << 24) +
  171184. ((png_int_32)(*(buf + 1)) << 16) +
  171185. ((png_int_32)(*(buf + 2)) << 8) +
  171186. (png_int_32)(*(buf + 3));
  171187. return (i);
  171188. }
  171189. png_uint_16 PNGAPI
  171190. png_get_uint_16(png_bytep buf)
  171191. {
  171192. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  171193. (png_uint_16)(*(buf + 1)));
  171194. return (i);
  171195. }
  171196. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  171197. void /* PRIVATE */
  171198. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  171199. {
  171200. if(png_ptr == NULL) return;
  171201. png_read_data(png_ptr, buf, length);
  171202. png_calculate_crc(png_ptr, buf, length);
  171203. }
  171204. int /* PRIVATE */
  171205. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  171206. {
  171207. png_size_t i;
  171208. png_size_t istop = png_ptr->zbuf_size;
  171209. for (i = (png_size_t)skip; i > istop; i -= istop)
  171210. {
  171211. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  171212. }
  171213. if (i)
  171214. {
  171215. png_crc_read(png_ptr, png_ptr->zbuf, i);
  171216. }
  171217. if (png_crc_error(png_ptr))
  171218. {
  171219. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  171220. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  171221. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  171222. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  171223. {
  171224. png_chunk_warning(png_ptr, "CRC error");
  171225. }
  171226. else
  171227. {
  171228. png_chunk_error(png_ptr, "CRC error");
  171229. }
  171230. return (1);
  171231. }
  171232. return (0);
  171233. }
  171234. int /* PRIVATE */
  171235. png_crc_error(png_structp png_ptr)
  171236. {
  171237. png_byte crc_bytes[4];
  171238. png_uint_32 crc;
  171239. int need_crc = 1;
  171240. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  171241. {
  171242. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  171243. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171244. need_crc = 0;
  171245. }
  171246. else /* critical */
  171247. {
  171248. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  171249. need_crc = 0;
  171250. }
  171251. png_read_data(png_ptr, crc_bytes, 4);
  171252. if (need_crc)
  171253. {
  171254. crc = png_get_uint_32(crc_bytes);
  171255. return ((int)(crc != png_ptr->crc));
  171256. }
  171257. else
  171258. return (0);
  171259. }
  171260. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  171261. defined(PNG_READ_iCCP_SUPPORTED)
  171262. png_charp /* PRIVATE */
  171263. png_decompress_chunk(png_structp png_ptr, int comp_type,
  171264. png_charp chunkdata, png_size_t chunklength,
  171265. png_size_t prefix_size, png_size_t *newlength)
  171266. {
  171267. static PNG_CONST char msg[] = "Error decoding compressed text";
  171268. png_charp text;
  171269. png_size_t text_size;
  171270. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  171271. {
  171272. int ret = Z_OK;
  171273. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  171274. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  171275. png_ptr->zstream.next_out = png_ptr->zbuf;
  171276. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171277. text_size = 0;
  171278. text = NULL;
  171279. while (png_ptr->zstream.avail_in)
  171280. {
  171281. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  171282. if (ret != Z_OK && ret != Z_STREAM_END)
  171283. {
  171284. if (png_ptr->zstream.msg != NULL)
  171285. png_warning(png_ptr, png_ptr->zstream.msg);
  171286. else
  171287. png_warning(png_ptr, msg);
  171288. inflateReset(&png_ptr->zstream);
  171289. png_ptr->zstream.avail_in = 0;
  171290. if (text == NULL)
  171291. {
  171292. text_size = prefix_size + png_sizeof(msg) + 1;
  171293. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  171294. if (text == NULL)
  171295. {
  171296. png_free(png_ptr,chunkdata);
  171297. png_error(png_ptr,"Not enough memory to decompress chunk");
  171298. }
  171299. png_memcpy(text, chunkdata, prefix_size);
  171300. }
  171301. text[text_size - 1] = 0x00;
  171302. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  171303. text_size = png_sizeof(msg) > text_size ? text_size :
  171304. png_sizeof(msg);
  171305. png_memcpy(text + prefix_size, msg, text_size + 1);
  171306. break;
  171307. }
  171308. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  171309. {
  171310. if (text == NULL)
  171311. {
  171312. text_size = prefix_size +
  171313. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171314. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  171315. if (text == NULL)
  171316. {
  171317. png_free(png_ptr,chunkdata);
  171318. png_error(png_ptr,"Not enough memory to decompress chunk.");
  171319. }
  171320. png_memcpy(text + prefix_size, png_ptr->zbuf,
  171321. text_size - prefix_size);
  171322. png_memcpy(text, chunkdata, prefix_size);
  171323. *(text + text_size) = 0x00;
  171324. }
  171325. else
  171326. {
  171327. png_charp tmp;
  171328. tmp = text;
  171329. text = (png_charp)png_malloc_warn(png_ptr,
  171330. (png_uint_32)(text_size +
  171331. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  171332. if (text == NULL)
  171333. {
  171334. png_free(png_ptr, tmp);
  171335. png_free(png_ptr, chunkdata);
  171336. png_error(png_ptr,"Not enough memory to decompress chunk..");
  171337. }
  171338. png_memcpy(text, tmp, text_size);
  171339. png_free(png_ptr, tmp);
  171340. png_memcpy(text + text_size, png_ptr->zbuf,
  171341. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  171342. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171343. *(text + text_size) = 0x00;
  171344. }
  171345. if (ret == Z_STREAM_END)
  171346. break;
  171347. else
  171348. {
  171349. png_ptr->zstream.next_out = png_ptr->zbuf;
  171350. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171351. }
  171352. }
  171353. }
  171354. if (ret != Z_STREAM_END)
  171355. {
  171356. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171357. char umsg[52];
  171358. if (ret == Z_BUF_ERROR)
  171359. png_snprintf(umsg, 52,
  171360. "Buffer error in compressed datastream in %s chunk",
  171361. png_ptr->chunk_name);
  171362. else if (ret == Z_DATA_ERROR)
  171363. png_snprintf(umsg, 52,
  171364. "Data error in compressed datastream in %s chunk",
  171365. png_ptr->chunk_name);
  171366. else
  171367. png_snprintf(umsg, 52,
  171368. "Incomplete compressed datastream in %s chunk",
  171369. png_ptr->chunk_name);
  171370. png_warning(png_ptr, umsg);
  171371. #else
  171372. png_warning(png_ptr,
  171373. "Incomplete compressed datastream in chunk other than IDAT");
  171374. #endif
  171375. text_size=prefix_size;
  171376. if (text == NULL)
  171377. {
  171378. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  171379. if (text == NULL)
  171380. {
  171381. png_free(png_ptr, chunkdata);
  171382. png_error(png_ptr,"Not enough memory for text.");
  171383. }
  171384. png_memcpy(text, chunkdata, prefix_size);
  171385. }
  171386. *(text + text_size) = 0x00;
  171387. }
  171388. inflateReset(&png_ptr->zstream);
  171389. png_ptr->zstream.avail_in = 0;
  171390. png_free(png_ptr, chunkdata);
  171391. chunkdata = text;
  171392. *newlength=text_size;
  171393. }
  171394. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  171395. {
  171396. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171397. char umsg[50];
  171398. png_snprintf(umsg, 50,
  171399. "Unknown zTXt compression type %d", comp_type);
  171400. png_warning(png_ptr, umsg);
  171401. #else
  171402. png_warning(png_ptr, "Unknown zTXt compression type");
  171403. #endif
  171404. *(chunkdata + prefix_size) = 0x00;
  171405. *newlength=prefix_size;
  171406. }
  171407. return chunkdata;
  171408. }
  171409. #endif
  171410. void /* PRIVATE */
  171411. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171412. {
  171413. png_byte buf[13];
  171414. png_uint_32 width, height;
  171415. int bit_depth, color_type, compression_type, filter_type;
  171416. int interlace_type;
  171417. png_debug(1, "in png_handle_IHDR\n");
  171418. if (png_ptr->mode & PNG_HAVE_IHDR)
  171419. png_error(png_ptr, "Out of place IHDR");
  171420. if (length != 13)
  171421. png_error(png_ptr, "Invalid IHDR chunk");
  171422. png_ptr->mode |= PNG_HAVE_IHDR;
  171423. png_crc_read(png_ptr, buf, 13);
  171424. png_crc_finish(png_ptr, 0);
  171425. width = png_get_uint_31(png_ptr, buf);
  171426. height = png_get_uint_31(png_ptr, buf + 4);
  171427. bit_depth = buf[8];
  171428. color_type = buf[9];
  171429. compression_type = buf[10];
  171430. filter_type = buf[11];
  171431. interlace_type = buf[12];
  171432. png_ptr->width = width;
  171433. png_ptr->height = height;
  171434. png_ptr->bit_depth = (png_byte)bit_depth;
  171435. png_ptr->interlaced = (png_byte)interlace_type;
  171436. png_ptr->color_type = (png_byte)color_type;
  171437. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171438. png_ptr->filter_type = (png_byte)filter_type;
  171439. #endif
  171440. png_ptr->compression_type = (png_byte)compression_type;
  171441. switch (png_ptr->color_type)
  171442. {
  171443. case PNG_COLOR_TYPE_GRAY:
  171444. case PNG_COLOR_TYPE_PALETTE:
  171445. png_ptr->channels = 1;
  171446. break;
  171447. case PNG_COLOR_TYPE_RGB:
  171448. png_ptr->channels = 3;
  171449. break;
  171450. case PNG_COLOR_TYPE_GRAY_ALPHA:
  171451. png_ptr->channels = 2;
  171452. break;
  171453. case PNG_COLOR_TYPE_RGB_ALPHA:
  171454. png_ptr->channels = 4;
  171455. break;
  171456. }
  171457. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  171458. png_ptr->channels);
  171459. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  171460. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  171461. png_debug1(3,"channels = %d\n", png_ptr->channels);
  171462. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  171463. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  171464. color_type, interlace_type, compression_type, filter_type);
  171465. }
  171466. void /* PRIVATE */
  171467. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171468. {
  171469. png_color palette[PNG_MAX_PALETTE_LENGTH];
  171470. int num, i;
  171471. #ifndef PNG_NO_POINTER_INDEXING
  171472. png_colorp pal_ptr;
  171473. #endif
  171474. png_debug(1, "in png_handle_PLTE\n");
  171475. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171476. png_error(png_ptr, "Missing IHDR before PLTE");
  171477. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171478. {
  171479. png_warning(png_ptr, "Invalid PLTE after IDAT");
  171480. png_crc_finish(png_ptr, length);
  171481. return;
  171482. }
  171483. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171484. png_error(png_ptr, "Duplicate PLTE chunk");
  171485. png_ptr->mode |= PNG_HAVE_PLTE;
  171486. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  171487. {
  171488. png_warning(png_ptr,
  171489. "Ignoring PLTE chunk in grayscale PNG");
  171490. png_crc_finish(png_ptr, length);
  171491. return;
  171492. }
  171493. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171494. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171495. {
  171496. png_crc_finish(png_ptr, length);
  171497. return;
  171498. }
  171499. #endif
  171500. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  171501. {
  171502. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171503. {
  171504. png_warning(png_ptr, "Invalid palette chunk");
  171505. png_crc_finish(png_ptr, length);
  171506. return;
  171507. }
  171508. else
  171509. {
  171510. png_error(png_ptr, "Invalid palette chunk");
  171511. }
  171512. }
  171513. num = (int)length / 3;
  171514. #ifndef PNG_NO_POINTER_INDEXING
  171515. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171516. {
  171517. png_byte buf[3];
  171518. png_crc_read(png_ptr, buf, 3);
  171519. pal_ptr->red = buf[0];
  171520. pal_ptr->green = buf[1];
  171521. pal_ptr->blue = buf[2];
  171522. }
  171523. #else
  171524. for (i = 0; i < num; i++)
  171525. {
  171526. png_byte buf[3];
  171527. png_crc_read(png_ptr, buf, 3);
  171528. palette[i].red = buf[0];
  171529. palette[i].green = buf[1];
  171530. palette[i].blue = buf[2];
  171531. }
  171532. #endif
  171533. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171534. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171535. #endif
  171536. {
  171537. png_crc_finish(png_ptr, 0);
  171538. }
  171539. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171540. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171541. {
  171542. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171543. {
  171544. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171545. {
  171546. png_chunk_error(png_ptr, "CRC error");
  171547. }
  171548. else
  171549. {
  171550. png_chunk_warning(png_ptr, "CRC error");
  171551. return;
  171552. }
  171553. }
  171554. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171555. {
  171556. png_chunk_warning(png_ptr, "CRC error");
  171557. }
  171558. }
  171559. #endif
  171560. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171561. #if defined(PNG_READ_tRNS_SUPPORTED)
  171562. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171563. {
  171564. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171565. {
  171566. if (png_ptr->num_trans > (png_uint_16)num)
  171567. {
  171568. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171569. png_ptr->num_trans = (png_uint_16)num;
  171570. }
  171571. if (info_ptr->num_trans > (png_uint_16)num)
  171572. {
  171573. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171574. info_ptr->num_trans = (png_uint_16)num;
  171575. }
  171576. }
  171577. }
  171578. #endif
  171579. }
  171580. void /* PRIVATE */
  171581. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171582. {
  171583. png_debug(1, "in png_handle_IEND\n");
  171584. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171585. {
  171586. png_error(png_ptr, "No image in file");
  171587. }
  171588. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171589. if (length != 0)
  171590. {
  171591. png_warning(png_ptr, "Incorrect IEND chunk length");
  171592. }
  171593. png_crc_finish(png_ptr, length);
  171594. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171595. }
  171596. #if defined(PNG_READ_gAMA_SUPPORTED)
  171597. void /* PRIVATE */
  171598. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171599. {
  171600. png_fixed_point igamma;
  171601. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171602. float file_gamma;
  171603. #endif
  171604. png_byte buf[4];
  171605. png_debug(1, "in png_handle_gAMA\n");
  171606. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171607. png_error(png_ptr, "Missing IHDR before gAMA");
  171608. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171609. {
  171610. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171611. png_crc_finish(png_ptr, length);
  171612. return;
  171613. }
  171614. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171615. png_warning(png_ptr, "Out of place gAMA chunk");
  171616. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171617. #if defined(PNG_READ_sRGB_SUPPORTED)
  171618. && !(info_ptr->valid & PNG_INFO_sRGB)
  171619. #endif
  171620. )
  171621. {
  171622. png_warning(png_ptr, "Duplicate gAMA chunk");
  171623. png_crc_finish(png_ptr, length);
  171624. return;
  171625. }
  171626. if (length != 4)
  171627. {
  171628. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171629. png_crc_finish(png_ptr, length);
  171630. return;
  171631. }
  171632. png_crc_read(png_ptr, buf, 4);
  171633. if (png_crc_finish(png_ptr, 0))
  171634. return;
  171635. igamma = (png_fixed_point)png_get_uint_32(buf);
  171636. if (igamma == 0)
  171637. {
  171638. png_warning(png_ptr,
  171639. "Ignoring gAMA chunk with gamma=0");
  171640. return;
  171641. }
  171642. #if defined(PNG_READ_sRGB_SUPPORTED)
  171643. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171644. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171645. {
  171646. png_warning(png_ptr,
  171647. "Ignoring incorrect gAMA value when sRGB is also present");
  171648. #ifndef PNG_NO_CONSOLE_IO
  171649. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171650. #endif
  171651. return;
  171652. }
  171653. #endif /* PNG_READ_sRGB_SUPPORTED */
  171654. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171655. file_gamma = (float)igamma / (float)100000.0;
  171656. # ifdef PNG_READ_GAMMA_SUPPORTED
  171657. png_ptr->gamma = file_gamma;
  171658. # endif
  171659. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171660. #endif
  171661. #ifdef PNG_FIXED_POINT_SUPPORTED
  171662. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171663. #endif
  171664. }
  171665. #endif
  171666. #if defined(PNG_READ_sBIT_SUPPORTED)
  171667. void /* PRIVATE */
  171668. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171669. {
  171670. png_size_t truelen;
  171671. png_byte buf[4];
  171672. png_debug(1, "in png_handle_sBIT\n");
  171673. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171674. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171675. png_error(png_ptr, "Missing IHDR before sBIT");
  171676. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171677. {
  171678. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171679. png_crc_finish(png_ptr, length);
  171680. return;
  171681. }
  171682. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171683. {
  171684. png_warning(png_ptr, "Out of place sBIT chunk");
  171685. }
  171686. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171687. {
  171688. png_warning(png_ptr, "Duplicate sBIT chunk");
  171689. png_crc_finish(png_ptr, length);
  171690. return;
  171691. }
  171692. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171693. truelen = 3;
  171694. else
  171695. truelen = (png_size_t)png_ptr->channels;
  171696. if (length != truelen || length > 4)
  171697. {
  171698. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171699. png_crc_finish(png_ptr, length);
  171700. return;
  171701. }
  171702. png_crc_read(png_ptr, buf, truelen);
  171703. if (png_crc_finish(png_ptr, 0))
  171704. return;
  171705. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171706. {
  171707. png_ptr->sig_bit.red = buf[0];
  171708. png_ptr->sig_bit.green = buf[1];
  171709. png_ptr->sig_bit.blue = buf[2];
  171710. png_ptr->sig_bit.alpha = buf[3];
  171711. }
  171712. else
  171713. {
  171714. png_ptr->sig_bit.gray = buf[0];
  171715. png_ptr->sig_bit.red = buf[0];
  171716. png_ptr->sig_bit.green = buf[0];
  171717. png_ptr->sig_bit.blue = buf[0];
  171718. png_ptr->sig_bit.alpha = buf[1];
  171719. }
  171720. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171721. }
  171722. #endif
  171723. #if defined(PNG_READ_cHRM_SUPPORTED)
  171724. void /* PRIVATE */
  171725. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171726. {
  171727. png_byte buf[4];
  171728. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171729. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171730. #endif
  171731. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171732. int_y_green, int_x_blue, int_y_blue;
  171733. png_uint_32 uint_x, uint_y;
  171734. png_debug(1, "in png_handle_cHRM\n");
  171735. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171736. png_error(png_ptr, "Missing IHDR before cHRM");
  171737. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171738. {
  171739. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171740. png_crc_finish(png_ptr, length);
  171741. return;
  171742. }
  171743. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171744. png_warning(png_ptr, "Missing PLTE before cHRM");
  171745. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171746. #if defined(PNG_READ_sRGB_SUPPORTED)
  171747. && !(info_ptr->valid & PNG_INFO_sRGB)
  171748. #endif
  171749. )
  171750. {
  171751. png_warning(png_ptr, "Duplicate cHRM chunk");
  171752. png_crc_finish(png_ptr, length);
  171753. return;
  171754. }
  171755. if (length != 32)
  171756. {
  171757. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171758. png_crc_finish(png_ptr, length);
  171759. return;
  171760. }
  171761. png_crc_read(png_ptr, buf, 4);
  171762. uint_x = png_get_uint_32(buf);
  171763. png_crc_read(png_ptr, buf, 4);
  171764. uint_y = png_get_uint_32(buf);
  171765. if (uint_x > 80000L || uint_y > 80000L ||
  171766. uint_x + uint_y > 100000L)
  171767. {
  171768. png_warning(png_ptr, "Invalid cHRM white point");
  171769. png_crc_finish(png_ptr, 24);
  171770. return;
  171771. }
  171772. int_x_white = (png_fixed_point)uint_x;
  171773. int_y_white = (png_fixed_point)uint_y;
  171774. png_crc_read(png_ptr, buf, 4);
  171775. uint_x = png_get_uint_32(buf);
  171776. png_crc_read(png_ptr, buf, 4);
  171777. uint_y = png_get_uint_32(buf);
  171778. if (uint_x + uint_y > 100000L)
  171779. {
  171780. png_warning(png_ptr, "Invalid cHRM red point");
  171781. png_crc_finish(png_ptr, 16);
  171782. return;
  171783. }
  171784. int_x_red = (png_fixed_point)uint_x;
  171785. int_y_red = (png_fixed_point)uint_y;
  171786. png_crc_read(png_ptr, buf, 4);
  171787. uint_x = png_get_uint_32(buf);
  171788. png_crc_read(png_ptr, buf, 4);
  171789. uint_y = png_get_uint_32(buf);
  171790. if (uint_x + uint_y > 100000L)
  171791. {
  171792. png_warning(png_ptr, "Invalid cHRM green point");
  171793. png_crc_finish(png_ptr, 8);
  171794. return;
  171795. }
  171796. int_x_green = (png_fixed_point)uint_x;
  171797. int_y_green = (png_fixed_point)uint_y;
  171798. png_crc_read(png_ptr, buf, 4);
  171799. uint_x = png_get_uint_32(buf);
  171800. png_crc_read(png_ptr, buf, 4);
  171801. uint_y = png_get_uint_32(buf);
  171802. if (uint_x + uint_y > 100000L)
  171803. {
  171804. png_warning(png_ptr, "Invalid cHRM blue point");
  171805. png_crc_finish(png_ptr, 0);
  171806. return;
  171807. }
  171808. int_x_blue = (png_fixed_point)uint_x;
  171809. int_y_blue = (png_fixed_point)uint_y;
  171810. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171811. white_x = (float)int_x_white / (float)100000.0;
  171812. white_y = (float)int_y_white / (float)100000.0;
  171813. red_x = (float)int_x_red / (float)100000.0;
  171814. red_y = (float)int_y_red / (float)100000.0;
  171815. green_x = (float)int_x_green / (float)100000.0;
  171816. green_y = (float)int_y_green / (float)100000.0;
  171817. blue_x = (float)int_x_blue / (float)100000.0;
  171818. blue_y = (float)int_y_blue / (float)100000.0;
  171819. #endif
  171820. #if defined(PNG_READ_sRGB_SUPPORTED)
  171821. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171822. {
  171823. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171824. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171825. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171826. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171827. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171828. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171829. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171830. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171831. {
  171832. png_warning(png_ptr,
  171833. "Ignoring incorrect cHRM value when sRGB is also present");
  171834. #ifndef PNG_NO_CONSOLE_IO
  171835. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171836. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171837. white_x, white_y, red_x, red_y);
  171838. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171839. green_x, green_y, blue_x, blue_y);
  171840. #else
  171841. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171842. int_x_white, int_y_white, int_x_red, int_y_red);
  171843. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171844. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171845. #endif
  171846. #endif /* PNG_NO_CONSOLE_IO */
  171847. }
  171848. png_crc_finish(png_ptr, 0);
  171849. return;
  171850. }
  171851. #endif /* PNG_READ_sRGB_SUPPORTED */
  171852. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171853. png_set_cHRM(png_ptr, info_ptr,
  171854. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171855. #endif
  171856. #ifdef PNG_FIXED_POINT_SUPPORTED
  171857. png_set_cHRM_fixed(png_ptr, info_ptr,
  171858. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171859. int_y_green, int_x_blue, int_y_blue);
  171860. #endif
  171861. if (png_crc_finish(png_ptr, 0))
  171862. return;
  171863. }
  171864. #endif
  171865. #if defined(PNG_READ_sRGB_SUPPORTED)
  171866. void /* PRIVATE */
  171867. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171868. {
  171869. int intent;
  171870. png_byte buf[1];
  171871. png_debug(1, "in png_handle_sRGB\n");
  171872. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171873. png_error(png_ptr, "Missing IHDR before sRGB");
  171874. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171875. {
  171876. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171877. png_crc_finish(png_ptr, length);
  171878. return;
  171879. }
  171880. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171881. png_warning(png_ptr, "Out of place sRGB chunk");
  171882. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171883. {
  171884. png_warning(png_ptr, "Duplicate sRGB chunk");
  171885. png_crc_finish(png_ptr, length);
  171886. return;
  171887. }
  171888. if (length != 1)
  171889. {
  171890. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171891. png_crc_finish(png_ptr, length);
  171892. return;
  171893. }
  171894. png_crc_read(png_ptr, buf, 1);
  171895. if (png_crc_finish(png_ptr, 0))
  171896. return;
  171897. intent = buf[0];
  171898. if (intent >= PNG_sRGB_INTENT_LAST)
  171899. {
  171900. png_warning(png_ptr, "Unknown sRGB intent");
  171901. return;
  171902. }
  171903. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171904. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171905. {
  171906. png_fixed_point igamma;
  171907. #ifdef PNG_FIXED_POINT_SUPPORTED
  171908. igamma=info_ptr->int_gamma;
  171909. #else
  171910. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171911. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171912. # endif
  171913. #endif
  171914. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171915. {
  171916. png_warning(png_ptr,
  171917. "Ignoring incorrect gAMA value when sRGB is also present");
  171918. #ifndef PNG_NO_CONSOLE_IO
  171919. # ifdef PNG_FIXED_POINT_SUPPORTED
  171920. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171921. # else
  171922. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171923. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171924. # endif
  171925. # endif
  171926. #endif
  171927. }
  171928. }
  171929. #endif /* PNG_READ_gAMA_SUPPORTED */
  171930. #ifdef PNG_READ_cHRM_SUPPORTED
  171931. #ifdef PNG_FIXED_POINT_SUPPORTED
  171932. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171933. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171934. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171935. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171936. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171937. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171938. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171939. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171940. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171941. {
  171942. png_warning(png_ptr,
  171943. "Ignoring incorrect cHRM value when sRGB is also present");
  171944. }
  171945. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171946. #endif /* PNG_READ_cHRM_SUPPORTED */
  171947. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171948. }
  171949. #endif /* PNG_READ_sRGB_SUPPORTED */
  171950. #if defined(PNG_READ_iCCP_SUPPORTED)
  171951. void /* PRIVATE */
  171952. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171953. {
  171954. png_charp chunkdata;
  171955. png_byte compression_type;
  171956. png_bytep pC;
  171957. png_charp profile;
  171958. png_uint_32 skip = 0;
  171959. png_uint_32 profile_size, profile_length;
  171960. png_size_t slength, prefix_length, data_length;
  171961. png_debug(1, "in png_handle_iCCP\n");
  171962. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171963. png_error(png_ptr, "Missing IHDR before iCCP");
  171964. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171965. {
  171966. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171967. png_crc_finish(png_ptr, length);
  171968. return;
  171969. }
  171970. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171971. png_warning(png_ptr, "Out of place iCCP chunk");
  171972. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171973. {
  171974. png_warning(png_ptr, "Duplicate iCCP chunk");
  171975. png_crc_finish(png_ptr, length);
  171976. return;
  171977. }
  171978. #ifdef PNG_MAX_MALLOC_64K
  171979. if (length > (png_uint_32)65535L)
  171980. {
  171981. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171982. skip = length - (png_uint_32)65535L;
  171983. length = (png_uint_32)65535L;
  171984. }
  171985. #endif
  171986. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171987. slength = (png_size_t)length;
  171988. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171989. if (png_crc_finish(png_ptr, skip))
  171990. {
  171991. png_free(png_ptr, chunkdata);
  171992. return;
  171993. }
  171994. chunkdata[slength] = 0x00;
  171995. for (profile = chunkdata; *profile; profile++)
  171996. ;
  171997. ++profile;
  171998. if ( profile >= chunkdata + slength - 1)
  171999. {
  172000. png_free(png_ptr, chunkdata);
  172001. png_warning(png_ptr, "Malformed iCCP chunk");
  172002. return;
  172003. }
  172004. compression_type = *profile++;
  172005. if (compression_type)
  172006. {
  172007. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  172008. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  172009. wrote nonzero) */
  172010. }
  172011. prefix_length = profile - chunkdata;
  172012. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  172013. slength, prefix_length, &data_length);
  172014. profile_length = data_length - prefix_length;
  172015. if ( prefix_length > data_length || profile_length < 4)
  172016. {
  172017. png_free(png_ptr, chunkdata);
  172018. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  172019. return;
  172020. }
  172021. pC = (png_bytep)(chunkdata+prefix_length);
  172022. profile_size = ((*(pC ))<<24) |
  172023. ((*(pC+1))<<16) |
  172024. ((*(pC+2))<< 8) |
  172025. ((*(pC+3)) );
  172026. if(profile_size < profile_length)
  172027. profile_length = profile_size;
  172028. if(profile_size > profile_length)
  172029. {
  172030. png_free(png_ptr, chunkdata);
  172031. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  172032. return;
  172033. }
  172034. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  172035. chunkdata + prefix_length, profile_length);
  172036. png_free(png_ptr, chunkdata);
  172037. }
  172038. #endif /* PNG_READ_iCCP_SUPPORTED */
  172039. #if defined(PNG_READ_sPLT_SUPPORTED)
  172040. void /* PRIVATE */
  172041. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172042. {
  172043. png_bytep chunkdata;
  172044. png_bytep entry_start;
  172045. png_sPLT_t new_palette;
  172046. #ifdef PNG_NO_POINTER_INDEXING
  172047. png_sPLT_entryp pp;
  172048. #endif
  172049. int data_length, entry_size, i;
  172050. png_uint_32 skip = 0;
  172051. png_size_t slength;
  172052. png_debug(1, "in png_handle_sPLT\n");
  172053. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172054. png_error(png_ptr, "Missing IHDR before sPLT");
  172055. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172056. {
  172057. png_warning(png_ptr, "Invalid sPLT after IDAT");
  172058. png_crc_finish(png_ptr, length);
  172059. return;
  172060. }
  172061. #ifdef PNG_MAX_MALLOC_64K
  172062. if (length > (png_uint_32)65535L)
  172063. {
  172064. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  172065. skip = length - (png_uint_32)65535L;
  172066. length = (png_uint_32)65535L;
  172067. }
  172068. #endif
  172069. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  172070. slength = (png_size_t)length;
  172071. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172072. if (png_crc_finish(png_ptr, skip))
  172073. {
  172074. png_free(png_ptr, chunkdata);
  172075. return;
  172076. }
  172077. chunkdata[slength] = 0x00;
  172078. for (entry_start = chunkdata; *entry_start; entry_start++)
  172079. ;
  172080. ++entry_start;
  172081. if (entry_start > chunkdata + slength - 2)
  172082. {
  172083. png_free(png_ptr, chunkdata);
  172084. png_warning(png_ptr, "malformed sPLT chunk");
  172085. return;
  172086. }
  172087. new_palette.depth = *entry_start++;
  172088. entry_size = (new_palette.depth == 8 ? 6 : 10);
  172089. data_length = (slength - (entry_start - chunkdata));
  172090. if (data_length % entry_size)
  172091. {
  172092. png_free(png_ptr, chunkdata);
  172093. png_warning(png_ptr, "sPLT chunk has bad length");
  172094. return;
  172095. }
  172096. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  172097. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  172098. png_sizeof(png_sPLT_entry)))
  172099. {
  172100. png_warning(png_ptr, "sPLT chunk too long");
  172101. return;
  172102. }
  172103. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  172104. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  172105. if (new_palette.entries == NULL)
  172106. {
  172107. png_warning(png_ptr, "sPLT chunk requires too much memory");
  172108. return;
  172109. }
  172110. #ifndef PNG_NO_POINTER_INDEXING
  172111. for (i = 0; i < new_palette.nentries; i++)
  172112. {
  172113. png_sPLT_entryp pp = new_palette.entries + i;
  172114. if (new_palette.depth == 8)
  172115. {
  172116. pp->red = *entry_start++;
  172117. pp->green = *entry_start++;
  172118. pp->blue = *entry_start++;
  172119. pp->alpha = *entry_start++;
  172120. }
  172121. else
  172122. {
  172123. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  172124. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  172125. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  172126. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  172127. }
  172128. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172129. }
  172130. #else
  172131. pp = new_palette.entries;
  172132. for (i = 0; i < new_palette.nentries; i++)
  172133. {
  172134. if (new_palette.depth == 8)
  172135. {
  172136. pp[i].red = *entry_start++;
  172137. pp[i].green = *entry_start++;
  172138. pp[i].blue = *entry_start++;
  172139. pp[i].alpha = *entry_start++;
  172140. }
  172141. else
  172142. {
  172143. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  172144. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  172145. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  172146. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  172147. }
  172148. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172149. }
  172150. #endif
  172151. new_palette.name = (png_charp)chunkdata;
  172152. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  172153. png_free(png_ptr, chunkdata);
  172154. png_free(png_ptr, new_palette.entries);
  172155. }
  172156. #endif /* PNG_READ_sPLT_SUPPORTED */
  172157. #if defined(PNG_READ_tRNS_SUPPORTED)
  172158. void /* PRIVATE */
  172159. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172160. {
  172161. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  172162. int bit_mask;
  172163. png_debug(1, "in png_handle_tRNS\n");
  172164. bit_mask = (1 << png_ptr->bit_depth) - 1;
  172165. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172166. png_error(png_ptr, "Missing IHDR before tRNS");
  172167. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172168. {
  172169. png_warning(png_ptr, "Invalid tRNS after IDAT");
  172170. png_crc_finish(png_ptr, length);
  172171. return;
  172172. }
  172173. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  172174. {
  172175. png_warning(png_ptr, "Duplicate tRNS chunk");
  172176. png_crc_finish(png_ptr, length);
  172177. return;
  172178. }
  172179. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  172180. {
  172181. png_byte buf[2];
  172182. if (length != 2)
  172183. {
  172184. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172185. png_crc_finish(png_ptr, length);
  172186. return;
  172187. }
  172188. png_crc_read(png_ptr, buf, 2);
  172189. png_ptr->num_trans = 1;
  172190. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  172191. }
  172192. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  172193. {
  172194. png_byte buf[6];
  172195. if (length != 6)
  172196. {
  172197. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172198. png_crc_finish(png_ptr, length);
  172199. return;
  172200. }
  172201. png_crc_read(png_ptr, buf, (png_size_t)length);
  172202. png_ptr->num_trans = 1;
  172203. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  172204. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  172205. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  172206. }
  172207. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172208. {
  172209. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172210. {
  172211. png_warning(png_ptr, "Missing PLTE before tRNS");
  172212. }
  172213. if (length > (png_uint_32)png_ptr->num_palette ||
  172214. length > PNG_MAX_PALETTE_LENGTH)
  172215. {
  172216. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172217. png_crc_finish(png_ptr, length);
  172218. return;
  172219. }
  172220. if (length == 0)
  172221. {
  172222. png_warning(png_ptr, "Zero length tRNS chunk");
  172223. png_crc_finish(png_ptr, length);
  172224. return;
  172225. }
  172226. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  172227. png_ptr->num_trans = (png_uint_16)length;
  172228. }
  172229. else
  172230. {
  172231. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  172232. png_crc_finish(png_ptr, length);
  172233. return;
  172234. }
  172235. if (png_crc_finish(png_ptr, 0))
  172236. {
  172237. png_ptr->num_trans = 0;
  172238. return;
  172239. }
  172240. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  172241. &(png_ptr->trans_values));
  172242. }
  172243. #endif
  172244. #if defined(PNG_READ_bKGD_SUPPORTED)
  172245. void /* PRIVATE */
  172246. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172247. {
  172248. png_size_t truelen;
  172249. png_byte buf[6];
  172250. png_debug(1, "in png_handle_bKGD\n");
  172251. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172252. png_error(png_ptr, "Missing IHDR before bKGD");
  172253. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172254. {
  172255. png_warning(png_ptr, "Invalid bKGD after IDAT");
  172256. png_crc_finish(png_ptr, length);
  172257. return;
  172258. }
  172259. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  172260. !(png_ptr->mode & PNG_HAVE_PLTE))
  172261. {
  172262. png_warning(png_ptr, "Missing PLTE before bKGD");
  172263. png_crc_finish(png_ptr, length);
  172264. return;
  172265. }
  172266. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  172267. {
  172268. png_warning(png_ptr, "Duplicate bKGD chunk");
  172269. png_crc_finish(png_ptr, length);
  172270. return;
  172271. }
  172272. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172273. truelen = 1;
  172274. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  172275. truelen = 6;
  172276. else
  172277. truelen = 2;
  172278. if (length != truelen)
  172279. {
  172280. png_warning(png_ptr, "Incorrect bKGD chunk length");
  172281. png_crc_finish(png_ptr, length);
  172282. return;
  172283. }
  172284. png_crc_read(png_ptr, buf, truelen);
  172285. if (png_crc_finish(png_ptr, 0))
  172286. return;
  172287. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172288. {
  172289. png_ptr->background.index = buf[0];
  172290. if(info_ptr->num_palette)
  172291. {
  172292. if(buf[0] > info_ptr->num_palette)
  172293. {
  172294. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  172295. return;
  172296. }
  172297. png_ptr->background.red =
  172298. (png_uint_16)png_ptr->palette[buf[0]].red;
  172299. png_ptr->background.green =
  172300. (png_uint_16)png_ptr->palette[buf[0]].green;
  172301. png_ptr->background.blue =
  172302. (png_uint_16)png_ptr->palette[buf[0]].blue;
  172303. }
  172304. }
  172305. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  172306. {
  172307. png_ptr->background.red =
  172308. png_ptr->background.green =
  172309. png_ptr->background.blue =
  172310. png_ptr->background.gray = png_get_uint_16(buf);
  172311. }
  172312. else
  172313. {
  172314. png_ptr->background.red = png_get_uint_16(buf);
  172315. png_ptr->background.green = png_get_uint_16(buf + 2);
  172316. png_ptr->background.blue = png_get_uint_16(buf + 4);
  172317. }
  172318. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  172319. }
  172320. #endif
  172321. #if defined(PNG_READ_hIST_SUPPORTED)
  172322. void /* PRIVATE */
  172323. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172324. {
  172325. unsigned int num, i;
  172326. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  172327. png_debug(1, "in png_handle_hIST\n");
  172328. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172329. png_error(png_ptr, "Missing IHDR before hIST");
  172330. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172331. {
  172332. png_warning(png_ptr, "Invalid hIST after IDAT");
  172333. png_crc_finish(png_ptr, length);
  172334. return;
  172335. }
  172336. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172337. {
  172338. png_warning(png_ptr, "Missing PLTE before hIST");
  172339. png_crc_finish(png_ptr, length);
  172340. return;
  172341. }
  172342. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  172343. {
  172344. png_warning(png_ptr, "Duplicate hIST chunk");
  172345. png_crc_finish(png_ptr, length);
  172346. return;
  172347. }
  172348. num = length / 2 ;
  172349. if (num != (unsigned int) png_ptr->num_palette || num >
  172350. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  172351. {
  172352. png_warning(png_ptr, "Incorrect hIST chunk length");
  172353. png_crc_finish(png_ptr, length);
  172354. return;
  172355. }
  172356. for (i = 0; i < num; i++)
  172357. {
  172358. png_byte buf[2];
  172359. png_crc_read(png_ptr, buf, 2);
  172360. readbuf[i] = png_get_uint_16(buf);
  172361. }
  172362. if (png_crc_finish(png_ptr, 0))
  172363. return;
  172364. png_set_hIST(png_ptr, info_ptr, readbuf);
  172365. }
  172366. #endif
  172367. #if defined(PNG_READ_pHYs_SUPPORTED)
  172368. void /* PRIVATE */
  172369. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172370. {
  172371. png_byte buf[9];
  172372. png_uint_32 res_x, res_y;
  172373. int unit_type;
  172374. png_debug(1, "in png_handle_pHYs\n");
  172375. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172376. png_error(png_ptr, "Missing IHDR before pHYs");
  172377. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172378. {
  172379. png_warning(png_ptr, "Invalid pHYs after IDAT");
  172380. png_crc_finish(png_ptr, length);
  172381. return;
  172382. }
  172383. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  172384. {
  172385. png_warning(png_ptr, "Duplicate pHYs chunk");
  172386. png_crc_finish(png_ptr, length);
  172387. return;
  172388. }
  172389. if (length != 9)
  172390. {
  172391. png_warning(png_ptr, "Incorrect pHYs chunk length");
  172392. png_crc_finish(png_ptr, length);
  172393. return;
  172394. }
  172395. png_crc_read(png_ptr, buf, 9);
  172396. if (png_crc_finish(png_ptr, 0))
  172397. return;
  172398. res_x = png_get_uint_32(buf);
  172399. res_y = png_get_uint_32(buf + 4);
  172400. unit_type = buf[8];
  172401. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  172402. }
  172403. #endif
  172404. #if defined(PNG_READ_oFFs_SUPPORTED)
  172405. void /* PRIVATE */
  172406. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172407. {
  172408. png_byte buf[9];
  172409. png_int_32 offset_x, offset_y;
  172410. int unit_type;
  172411. png_debug(1, "in png_handle_oFFs\n");
  172412. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172413. png_error(png_ptr, "Missing IHDR before oFFs");
  172414. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172415. {
  172416. png_warning(png_ptr, "Invalid oFFs after IDAT");
  172417. png_crc_finish(png_ptr, length);
  172418. return;
  172419. }
  172420. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  172421. {
  172422. png_warning(png_ptr, "Duplicate oFFs chunk");
  172423. png_crc_finish(png_ptr, length);
  172424. return;
  172425. }
  172426. if (length != 9)
  172427. {
  172428. png_warning(png_ptr, "Incorrect oFFs chunk length");
  172429. png_crc_finish(png_ptr, length);
  172430. return;
  172431. }
  172432. png_crc_read(png_ptr, buf, 9);
  172433. if (png_crc_finish(png_ptr, 0))
  172434. return;
  172435. offset_x = png_get_int_32(buf);
  172436. offset_y = png_get_int_32(buf + 4);
  172437. unit_type = buf[8];
  172438. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  172439. }
  172440. #endif
  172441. #if defined(PNG_READ_pCAL_SUPPORTED)
  172442. void /* PRIVATE */
  172443. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172444. {
  172445. png_charp purpose;
  172446. png_int_32 X0, X1;
  172447. png_byte type, nparams;
  172448. png_charp buf, units, endptr;
  172449. png_charpp params;
  172450. png_size_t slength;
  172451. int i;
  172452. png_debug(1, "in png_handle_pCAL\n");
  172453. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172454. png_error(png_ptr, "Missing IHDR before pCAL");
  172455. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172456. {
  172457. png_warning(png_ptr, "Invalid pCAL after IDAT");
  172458. png_crc_finish(png_ptr, length);
  172459. return;
  172460. }
  172461. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  172462. {
  172463. png_warning(png_ptr, "Duplicate pCAL chunk");
  172464. png_crc_finish(png_ptr, length);
  172465. return;
  172466. }
  172467. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  172468. length + 1);
  172469. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172470. if (purpose == NULL)
  172471. {
  172472. png_warning(png_ptr, "No memory for pCAL purpose.");
  172473. return;
  172474. }
  172475. slength = (png_size_t)length;
  172476. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  172477. if (png_crc_finish(png_ptr, 0))
  172478. {
  172479. png_free(png_ptr, purpose);
  172480. return;
  172481. }
  172482. purpose[slength] = 0x00; /* null terminate the last string */
  172483. png_debug(3, "Finding end of pCAL purpose string\n");
  172484. for (buf = purpose; *buf; buf++)
  172485. ;
  172486. endptr = purpose + slength;
  172487. if (endptr <= buf + 12)
  172488. {
  172489. png_warning(png_ptr, "Invalid pCAL data");
  172490. png_free(png_ptr, purpose);
  172491. return;
  172492. }
  172493. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  172494. X0 = png_get_int_32((png_bytep)buf+1);
  172495. X1 = png_get_int_32((png_bytep)buf+5);
  172496. type = buf[9];
  172497. nparams = buf[10];
  172498. units = buf + 11;
  172499. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  172500. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  172501. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  172502. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  172503. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  172504. {
  172505. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  172506. png_free(png_ptr, purpose);
  172507. return;
  172508. }
  172509. else if (type >= PNG_EQUATION_LAST)
  172510. {
  172511. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  172512. }
  172513. for (buf = units; *buf; buf++)
  172514. ;
  172515. png_debug(3, "Allocating pCAL parameters array\n");
  172516. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172517. *png_sizeof(png_charp))) ;
  172518. if (params == NULL)
  172519. {
  172520. png_free(png_ptr, purpose);
  172521. png_warning(png_ptr, "No memory for pCAL params.");
  172522. return;
  172523. }
  172524. for (i = 0; i < (int)nparams; i++)
  172525. {
  172526. buf++; /* Skip the null string terminator from previous parameter. */
  172527. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172528. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172529. ;
  172530. if (buf > endptr)
  172531. {
  172532. png_warning(png_ptr, "Invalid pCAL data");
  172533. png_free(png_ptr, purpose);
  172534. png_free(png_ptr, params);
  172535. return;
  172536. }
  172537. }
  172538. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172539. units, params);
  172540. png_free(png_ptr, purpose);
  172541. png_free(png_ptr, params);
  172542. }
  172543. #endif
  172544. #if defined(PNG_READ_sCAL_SUPPORTED)
  172545. void /* PRIVATE */
  172546. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172547. {
  172548. png_charp buffer, ep;
  172549. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172550. double width, height;
  172551. png_charp vp;
  172552. #else
  172553. #ifdef PNG_FIXED_POINT_SUPPORTED
  172554. png_charp swidth, sheight;
  172555. #endif
  172556. #endif
  172557. png_size_t slength;
  172558. png_debug(1, "in png_handle_sCAL\n");
  172559. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172560. png_error(png_ptr, "Missing IHDR before sCAL");
  172561. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172562. {
  172563. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172564. png_crc_finish(png_ptr, length);
  172565. return;
  172566. }
  172567. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172568. {
  172569. png_warning(png_ptr, "Duplicate sCAL chunk");
  172570. png_crc_finish(png_ptr, length);
  172571. return;
  172572. }
  172573. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172574. length + 1);
  172575. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172576. if (buffer == NULL)
  172577. {
  172578. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172579. return;
  172580. }
  172581. slength = (png_size_t)length;
  172582. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172583. if (png_crc_finish(png_ptr, 0))
  172584. {
  172585. png_free(png_ptr, buffer);
  172586. return;
  172587. }
  172588. buffer[slength] = 0x00; /* null terminate the last string */
  172589. ep = buffer + 1; /* skip unit byte */
  172590. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172591. width = png_strtod(png_ptr, ep, &vp);
  172592. if (*vp)
  172593. {
  172594. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172595. return;
  172596. }
  172597. #else
  172598. #ifdef PNG_FIXED_POINT_SUPPORTED
  172599. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172600. if (swidth == NULL)
  172601. {
  172602. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172603. return;
  172604. }
  172605. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172606. #endif
  172607. #endif
  172608. for (ep = buffer; *ep; ep++)
  172609. ;
  172610. ep++;
  172611. if (buffer + slength < ep)
  172612. {
  172613. png_warning(png_ptr, "Truncated sCAL chunk");
  172614. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172615. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172616. png_free(png_ptr, swidth);
  172617. #endif
  172618. png_free(png_ptr, buffer);
  172619. return;
  172620. }
  172621. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172622. height = png_strtod(png_ptr, ep, &vp);
  172623. if (*vp)
  172624. {
  172625. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172626. return;
  172627. }
  172628. #else
  172629. #ifdef PNG_FIXED_POINT_SUPPORTED
  172630. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172631. if (swidth == NULL)
  172632. {
  172633. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172634. return;
  172635. }
  172636. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172637. #endif
  172638. #endif
  172639. if (buffer + slength < ep
  172640. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172641. || width <= 0. || height <= 0.
  172642. #endif
  172643. )
  172644. {
  172645. png_warning(png_ptr, "Invalid sCAL data");
  172646. png_free(png_ptr, buffer);
  172647. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172648. png_free(png_ptr, swidth);
  172649. png_free(png_ptr, sheight);
  172650. #endif
  172651. return;
  172652. }
  172653. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172654. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172655. #else
  172656. #ifdef PNG_FIXED_POINT_SUPPORTED
  172657. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172658. #endif
  172659. #endif
  172660. png_free(png_ptr, buffer);
  172661. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172662. png_free(png_ptr, swidth);
  172663. png_free(png_ptr, sheight);
  172664. #endif
  172665. }
  172666. #endif
  172667. #if defined(PNG_READ_tIME_SUPPORTED)
  172668. void /* PRIVATE */
  172669. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172670. {
  172671. png_byte buf[7];
  172672. png_time mod_time;
  172673. png_debug(1, "in png_handle_tIME\n");
  172674. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172675. png_error(png_ptr, "Out of place tIME chunk");
  172676. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172677. {
  172678. png_warning(png_ptr, "Duplicate tIME chunk");
  172679. png_crc_finish(png_ptr, length);
  172680. return;
  172681. }
  172682. if (png_ptr->mode & PNG_HAVE_IDAT)
  172683. png_ptr->mode |= PNG_AFTER_IDAT;
  172684. if (length != 7)
  172685. {
  172686. png_warning(png_ptr, "Incorrect tIME chunk length");
  172687. png_crc_finish(png_ptr, length);
  172688. return;
  172689. }
  172690. png_crc_read(png_ptr, buf, 7);
  172691. if (png_crc_finish(png_ptr, 0))
  172692. return;
  172693. mod_time.second = buf[6];
  172694. mod_time.minute = buf[5];
  172695. mod_time.hour = buf[4];
  172696. mod_time.day = buf[3];
  172697. mod_time.month = buf[2];
  172698. mod_time.year = png_get_uint_16(buf);
  172699. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172700. }
  172701. #endif
  172702. #if defined(PNG_READ_tEXt_SUPPORTED)
  172703. void /* PRIVATE */
  172704. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172705. {
  172706. png_textp text_ptr;
  172707. png_charp key;
  172708. png_charp text;
  172709. png_uint_32 skip = 0;
  172710. png_size_t slength;
  172711. int ret;
  172712. png_debug(1, "in png_handle_tEXt\n");
  172713. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172714. png_error(png_ptr, "Missing IHDR before tEXt");
  172715. if (png_ptr->mode & PNG_HAVE_IDAT)
  172716. png_ptr->mode |= PNG_AFTER_IDAT;
  172717. #ifdef PNG_MAX_MALLOC_64K
  172718. if (length > (png_uint_32)65535L)
  172719. {
  172720. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172721. skip = length - (png_uint_32)65535L;
  172722. length = (png_uint_32)65535L;
  172723. }
  172724. #endif
  172725. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172726. if (key == NULL)
  172727. {
  172728. png_warning(png_ptr, "No memory to process text chunk.");
  172729. return;
  172730. }
  172731. slength = (png_size_t)length;
  172732. png_crc_read(png_ptr, (png_bytep)key, slength);
  172733. if (png_crc_finish(png_ptr, skip))
  172734. {
  172735. png_free(png_ptr, key);
  172736. return;
  172737. }
  172738. key[slength] = 0x00;
  172739. for (text = key; *text; text++)
  172740. ;
  172741. if (text != key + slength)
  172742. text++;
  172743. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172744. (png_uint_32)png_sizeof(png_text));
  172745. if (text_ptr == NULL)
  172746. {
  172747. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172748. png_free(png_ptr, key);
  172749. return;
  172750. }
  172751. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172752. text_ptr->key = key;
  172753. #ifdef PNG_iTXt_SUPPORTED
  172754. text_ptr->lang = NULL;
  172755. text_ptr->lang_key = NULL;
  172756. text_ptr->itxt_length = 0;
  172757. #endif
  172758. text_ptr->text = text;
  172759. text_ptr->text_length = png_strlen(text);
  172760. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172761. png_free(png_ptr, key);
  172762. png_free(png_ptr, text_ptr);
  172763. if (ret)
  172764. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172765. }
  172766. #endif
  172767. #if defined(PNG_READ_zTXt_SUPPORTED)
  172768. void /* PRIVATE */
  172769. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172770. {
  172771. png_textp text_ptr;
  172772. png_charp chunkdata;
  172773. png_charp text;
  172774. int comp_type;
  172775. int ret;
  172776. png_size_t slength, prefix_len, data_len;
  172777. png_debug(1, "in png_handle_zTXt\n");
  172778. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172779. png_error(png_ptr, "Missing IHDR before zTXt");
  172780. if (png_ptr->mode & PNG_HAVE_IDAT)
  172781. png_ptr->mode |= PNG_AFTER_IDAT;
  172782. #ifdef PNG_MAX_MALLOC_64K
  172783. if (length > (png_uint_32)65535L)
  172784. {
  172785. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172786. png_crc_finish(png_ptr, length);
  172787. return;
  172788. }
  172789. #endif
  172790. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172791. if (chunkdata == NULL)
  172792. {
  172793. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172794. return;
  172795. }
  172796. slength = (png_size_t)length;
  172797. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172798. if (png_crc_finish(png_ptr, 0))
  172799. {
  172800. png_free(png_ptr, chunkdata);
  172801. return;
  172802. }
  172803. chunkdata[slength] = 0x00;
  172804. for (text = chunkdata; *text; text++)
  172805. ;
  172806. if (text >= chunkdata + slength - 2)
  172807. {
  172808. png_warning(png_ptr, "Truncated zTXt chunk");
  172809. png_free(png_ptr, chunkdata);
  172810. return;
  172811. }
  172812. else
  172813. {
  172814. comp_type = *(++text);
  172815. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172816. {
  172817. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172818. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172819. }
  172820. text++; /* skip the compression_method byte */
  172821. }
  172822. prefix_len = text - chunkdata;
  172823. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172824. (png_size_t)length, prefix_len, &data_len);
  172825. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172826. (png_uint_32)png_sizeof(png_text));
  172827. if (text_ptr == NULL)
  172828. {
  172829. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172830. png_free(png_ptr, chunkdata);
  172831. return;
  172832. }
  172833. text_ptr->compression = comp_type;
  172834. text_ptr->key = chunkdata;
  172835. #ifdef PNG_iTXt_SUPPORTED
  172836. text_ptr->lang = NULL;
  172837. text_ptr->lang_key = NULL;
  172838. text_ptr->itxt_length = 0;
  172839. #endif
  172840. text_ptr->text = chunkdata + prefix_len;
  172841. text_ptr->text_length = data_len;
  172842. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172843. png_free(png_ptr, text_ptr);
  172844. png_free(png_ptr, chunkdata);
  172845. if (ret)
  172846. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172847. }
  172848. #endif
  172849. #if defined(PNG_READ_iTXt_SUPPORTED)
  172850. void /* PRIVATE */
  172851. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172852. {
  172853. png_textp text_ptr;
  172854. png_charp chunkdata;
  172855. png_charp key, lang, text, lang_key;
  172856. int comp_flag;
  172857. int comp_type = 0;
  172858. int ret;
  172859. png_size_t slength, prefix_len, data_len;
  172860. png_debug(1, "in png_handle_iTXt\n");
  172861. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172862. png_error(png_ptr, "Missing IHDR before iTXt");
  172863. if (png_ptr->mode & PNG_HAVE_IDAT)
  172864. png_ptr->mode |= PNG_AFTER_IDAT;
  172865. #ifdef PNG_MAX_MALLOC_64K
  172866. if (length > (png_uint_32)65535L)
  172867. {
  172868. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172869. png_crc_finish(png_ptr, length);
  172870. return;
  172871. }
  172872. #endif
  172873. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172874. if (chunkdata == NULL)
  172875. {
  172876. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172877. return;
  172878. }
  172879. slength = (png_size_t)length;
  172880. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172881. if (png_crc_finish(png_ptr, 0))
  172882. {
  172883. png_free(png_ptr, chunkdata);
  172884. return;
  172885. }
  172886. chunkdata[slength] = 0x00;
  172887. for (lang = chunkdata; *lang; lang++)
  172888. ;
  172889. lang++; /* skip NUL separator */
  172890. if (lang >= chunkdata + slength - 3)
  172891. {
  172892. png_warning(png_ptr, "Truncated iTXt chunk");
  172893. png_free(png_ptr, chunkdata);
  172894. return;
  172895. }
  172896. else
  172897. {
  172898. comp_flag = *lang++;
  172899. comp_type = *lang++;
  172900. }
  172901. for (lang_key = lang; *lang_key; lang_key++)
  172902. ;
  172903. lang_key++; /* skip NUL separator */
  172904. if (lang_key >= chunkdata + slength)
  172905. {
  172906. png_warning(png_ptr, "Truncated iTXt chunk");
  172907. png_free(png_ptr, chunkdata);
  172908. return;
  172909. }
  172910. for (text = lang_key; *text; text++)
  172911. ;
  172912. text++; /* skip NUL separator */
  172913. if (text >= chunkdata + slength)
  172914. {
  172915. png_warning(png_ptr, "Malformed iTXt chunk");
  172916. png_free(png_ptr, chunkdata);
  172917. return;
  172918. }
  172919. prefix_len = text - chunkdata;
  172920. key=chunkdata;
  172921. if (comp_flag)
  172922. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172923. (size_t)length, prefix_len, &data_len);
  172924. else
  172925. data_len=png_strlen(chunkdata + prefix_len);
  172926. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172927. (png_uint_32)png_sizeof(png_text));
  172928. if (text_ptr == NULL)
  172929. {
  172930. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172931. png_free(png_ptr, chunkdata);
  172932. return;
  172933. }
  172934. text_ptr->compression = (int)comp_flag + 1;
  172935. text_ptr->lang_key = chunkdata+(lang_key-key);
  172936. text_ptr->lang = chunkdata+(lang-key);
  172937. text_ptr->itxt_length = data_len;
  172938. text_ptr->text_length = 0;
  172939. text_ptr->key = chunkdata;
  172940. text_ptr->text = chunkdata + prefix_len;
  172941. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172942. png_free(png_ptr, text_ptr);
  172943. png_free(png_ptr, chunkdata);
  172944. if (ret)
  172945. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172946. }
  172947. #endif
  172948. void /* PRIVATE */
  172949. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172950. {
  172951. png_uint_32 skip = 0;
  172952. png_debug(1, "in png_handle_unknown\n");
  172953. if (png_ptr->mode & PNG_HAVE_IDAT)
  172954. {
  172955. #ifdef PNG_USE_LOCAL_ARRAYS
  172956. PNG_CONST PNG_IDAT;
  172957. #endif
  172958. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172959. png_ptr->mode |= PNG_AFTER_IDAT;
  172960. }
  172961. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172962. if (!(png_ptr->chunk_name[0] & 0x20))
  172963. {
  172964. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172965. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172966. PNG_HANDLE_CHUNK_ALWAYS
  172967. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172968. && png_ptr->read_user_chunk_fn == NULL
  172969. #endif
  172970. )
  172971. #endif
  172972. png_chunk_error(png_ptr, "unknown critical chunk");
  172973. }
  172974. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172975. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172976. (png_ptr->read_user_chunk_fn != NULL))
  172977. {
  172978. #ifdef PNG_MAX_MALLOC_64K
  172979. if (length > (png_uint_32)65535L)
  172980. {
  172981. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172982. skip = length - (png_uint_32)65535L;
  172983. length = (png_uint_32)65535L;
  172984. }
  172985. #endif
  172986. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172987. (png_charp)png_ptr->chunk_name, 5);
  172988. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172989. png_ptr->unknown_chunk.size = (png_size_t)length;
  172990. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172991. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172992. if(png_ptr->read_user_chunk_fn != NULL)
  172993. {
  172994. int ret;
  172995. ret = (*(png_ptr->read_user_chunk_fn))
  172996. (png_ptr, &png_ptr->unknown_chunk);
  172997. if (ret < 0)
  172998. png_chunk_error(png_ptr, "error in user chunk");
  172999. if (ret == 0)
  173000. {
  173001. if (!(png_ptr->chunk_name[0] & 0x20))
  173002. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  173003. PNG_HANDLE_CHUNK_ALWAYS)
  173004. png_chunk_error(png_ptr, "unknown critical chunk");
  173005. png_set_unknown_chunks(png_ptr, info_ptr,
  173006. &png_ptr->unknown_chunk, 1);
  173007. }
  173008. }
  173009. #else
  173010. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  173011. #endif
  173012. png_free(png_ptr, png_ptr->unknown_chunk.data);
  173013. png_ptr->unknown_chunk.data = NULL;
  173014. }
  173015. else
  173016. #endif
  173017. skip = length;
  173018. png_crc_finish(png_ptr, skip);
  173019. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  173020. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  173021. #endif
  173022. }
  173023. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  173024. void /* PRIVATE */
  173025. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  173026. {
  173027. png_debug(1, "in png_check_chunk_name\n");
  173028. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  173029. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  173030. {
  173031. png_chunk_error(png_ptr, "invalid chunk type");
  173032. }
  173033. }
  173034. void /* PRIVATE */
  173035. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  173036. {
  173037. png_debug(1,"in png_combine_row\n");
  173038. if (mask == 0xff)
  173039. {
  173040. png_memcpy(row, png_ptr->row_buf + 1,
  173041. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  173042. }
  173043. else
  173044. {
  173045. switch (png_ptr->row_info.pixel_depth)
  173046. {
  173047. case 1:
  173048. {
  173049. png_bytep sp = png_ptr->row_buf + 1;
  173050. png_bytep dp = row;
  173051. int s_inc, s_start, s_end;
  173052. int m = 0x80;
  173053. int shift;
  173054. png_uint_32 i;
  173055. png_uint_32 row_width = png_ptr->width;
  173056. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173057. if (png_ptr->transformations & PNG_PACKSWAP)
  173058. {
  173059. s_start = 0;
  173060. s_end = 7;
  173061. s_inc = 1;
  173062. }
  173063. else
  173064. #endif
  173065. {
  173066. s_start = 7;
  173067. s_end = 0;
  173068. s_inc = -1;
  173069. }
  173070. shift = s_start;
  173071. for (i = 0; i < row_width; i++)
  173072. {
  173073. if (m & mask)
  173074. {
  173075. int value;
  173076. value = (*sp >> shift) & 0x01;
  173077. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  173078. *dp |= (png_byte)(value << shift);
  173079. }
  173080. if (shift == s_end)
  173081. {
  173082. shift = s_start;
  173083. sp++;
  173084. dp++;
  173085. }
  173086. else
  173087. shift += s_inc;
  173088. if (m == 1)
  173089. m = 0x80;
  173090. else
  173091. m >>= 1;
  173092. }
  173093. break;
  173094. }
  173095. case 2:
  173096. {
  173097. png_bytep sp = png_ptr->row_buf + 1;
  173098. png_bytep dp = row;
  173099. int s_start, s_end, s_inc;
  173100. int m = 0x80;
  173101. int shift;
  173102. png_uint_32 i;
  173103. png_uint_32 row_width = png_ptr->width;
  173104. int value;
  173105. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173106. if (png_ptr->transformations & PNG_PACKSWAP)
  173107. {
  173108. s_start = 0;
  173109. s_end = 6;
  173110. s_inc = 2;
  173111. }
  173112. else
  173113. #endif
  173114. {
  173115. s_start = 6;
  173116. s_end = 0;
  173117. s_inc = -2;
  173118. }
  173119. shift = s_start;
  173120. for (i = 0; i < row_width; i++)
  173121. {
  173122. if (m & mask)
  173123. {
  173124. value = (*sp >> shift) & 0x03;
  173125. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  173126. *dp |= (png_byte)(value << shift);
  173127. }
  173128. if (shift == s_end)
  173129. {
  173130. shift = s_start;
  173131. sp++;
  173132. dp++;
  173133. }
  173134. else
  173135. shift += s_inc;
  173136. if (m == 1)
  173137. m = 0x80;
  173138. else
  173139. m >>= 1;
  173140. }
  173141. break;
  173142. }
  173143. case 4:
  173144. {
  173145. png_bytep sp = png_ptr->row_buf + 1;
  173146. png_bytep dp = row;
  173147. int s_start, s_end, s_inc;
  173148. int m = 0x80;
  173149. int shift;
  173150. png_uint_32 i;
  173151. png_uint_32 row_width = png_ptr->width;
  173152. int value;
  173153. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173154. if (png_ptr->transformations & PNG_PACKSWAP)
  173155. {
  173156. s_start = 0;
  173157. s_end = 4;
  173158. s_inc = 4;
  173159. }
  173160. else
  173161. #endif
  173162. {
  173163. s_start = 4;
  173164. s_end = 0;
  173165. s_inc = -4;
  173166. }
  173167. shift = s_start;
  173168. for (i = 0; i < row_width; i++)
  173169. {
  173170. if (m & mask)
  173171. {
  173172. value = (*sp >> shift) & 0xf;
  173173. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  173174. *dp |= (png_byte)(value << shift);
  173175. }
  173176. if (shift == s_end)
  173177. {
  173178. shift = s_start;
  173179. sp++;
  173180. dp++;
  173181. }
  173182. else
  173183. shift += s_inc;
  173184. if (m == 1)
  173185. m = 0x80;
  173186. else
  173187. m >>= 1;
  173188. }
  173189. break;
  173190. }
  173191. default:
  173192. {
  173193. png_bytep sp = png_ptr->row_buf + 1;
  173194. png_bytep dp = row;
  173195. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  173196. png_uint_32 i;
  173197. png_uint_32 row_width = png_ptr->width;
  173198. png_byte m = 0x80;
  173199. for (i = 0; i < row_width; i++)
  173200. {
  173201. if (m & mask)
  173202. {
  173203. png_memcpy(dp, sp, pixel_bytes);
  173204. }
  173205. sp += pixel_bytes;
  173206. dp += pixel_bytes;
  173207. if (m == 1)
  173208. m = 0x80;
  173209. else
  173210. m >>= 1;
  173211. }
  173212. break;
  173213. }
  173214. }
  173215. }
  173216. }
  173217. #ifdef PNG_READ_INTERLACING_SUPPORTED
  173218. void /* PRIVATE */
  173219. png_do_read_interlace(png_structp png_ptr)
  173220. {
  173221. png_row_infop row_info = &(png_ptr->row_info);
  173222. png_bytep row = png_ptr->row_buf + 1;
  173223. int pass = png_ptr->pass;
  173224. png_uint_32 transformations = png_ptr->transformations;
  173225. #ifdef PNG_USE_LOCAL_ARRAYS
  173226. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173227. #endif
  173228. png_debug(1,"in png_do_read_interlace\n");
  173229. if (row != NULL && row_info != NULL)
  173230. {
  173231. png_uint_32 final_width;
  173232. final_width = row_info->width * png_pass_inc[pass];
  173233. switch (row_info->pixel_depth)
  173234. {
  173235. case 1:
  173236. {
  173237. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  173238. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  173239. int sshift, dshift;
  173240. int s_start, s_end, s_inc;
  173241. int jstop = png_pass_inc[pass];
  173242. png_byte v;
  173243. png_uint_32 i;
  173244. int j;
  173245. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173246. if (transformations & PNG_PACKSWAP)
  173247. {
  173248. sshift = (int)((row_info->width + 7) & 0x07);
  173249. dshift = (int)((final_width + 7) & 0x07);
  173250. s_start = 7;
  173251. s_end = 0;
  173252. s_inc = -1;
  173253. }
  173254. else
  173255. #endif
  173256. {
  173257. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  173258. dshift = 7 - (int)((final_width + 7) & 0x07);
  173259. s_start = 0;
  173260. s_end = 7;
  173261. s_inc = 1;
  173262. }
  173263. for (i = 0; i < row_info->width; i++)
  173264. {
  173265. v = (png_byte)((*sp >> sshift) & 0x01);
  173266. for (j = 0; j < jstop; j++)
  173267. {
  173268. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  173269. *dp |= (png_byte)(v << dshift);
  173270. if (dshift == s_end)
  173271. {
  173272. dshift = s_start;
  173273. dp--;
  173274. }
  173275. else
  173276. dshift += s_inc;
  173277. }
  173278. if (sshift == s_end)
  173279. {
  173280. sshift = s_start;
  173281. sp--;
  173282. }
  173283. else
  173284. sshift += s_inc;
  173285. }
  173286. break;
  173287. }
  173288. case 2:
  173289. {
  173290. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  173291. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  173292. int sshift, dshift;
  173293. int s_start, s_end, s_inc;
  173294. int jstop = png_pass_inc[pass];
  173295. png_uint_32 i;
  173296. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173297. if (transformations & PNG_PACKSWAP)
  173298. {
  173299. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  173300. dshift = (int)(((final_width + 3) & 0x03) << 1);
  173301. s_start = 6;
  173302. s_end = 0;
  173303. s_inc = -2;
  173304. }
  173305. else
  173306. #endif
  173307. {
  173308. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  173309. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  173310. s_start = 0;
  173311. s_end = 6;
  173312. s_inc = 2;
  173313. }
  173314. for (i = 0; i < row_info->width; i++)
  173315. {
  173316. png_byte v;
  173317. int j;
  173318. v = (png_byte)((*sp >> sshift) & 0x03);
  173319. for (j = 0; j < jstop; j++)
  173320. {
  173321. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  173322. *dp |= (png_byte)(v << dshift);
  173323. if (dshift == s_end)
  173324. {
  173325. dshift = s_start;
  173326. dp--;
  173327. }
  173328. else
  173329. dshift += s_inc;
  173330. }
  173331. if (sshift == s_end)
  173332. {
  173333. sshift = s_start;
  173334. sp--;
  173335. }
  173336. else
  173337. sshift += s_inc;
  173338. }
  173339. break;
  173340. }
  173341. case 4:
  173342. {
  173343. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  173344. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  173345. int sshift, dshift;
  173346. int s_start, s_end, s_inc;
  173347. png_uint_32 i;
  173348. int jstop = png_pass_inc[pass];
  173349. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173350. if (transformations & PNG_PACKSWAP)
  173351. {
  173352. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  173353. dshift = (int)(((final_width + 1) & 0x01) << 2);
  173354. s_start = 4;
  173355. s_end = 0;
  173356. s_inc = -4;
  173357. }
  173358. else
  173359. #endif
  173360. {
  173361. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  173362. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  173363. s_start = 0;
  173364. s_end = 4;
  173365. s_inc = 4;
  173366. }
  173367. for (i = 0; i < row_info->width; i++)
  173368. {
  173369. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  173370. int j;
  173371. for (j = 0; j < jstop; j++)
  173372. {
  173373. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  173374. *dp |= (png_byte)(v << dshift);
  173375. if (dshift == s_end)
  173376. {
  173377. dshift = s_start;
  173378. dp--;
  173379. }
  173380. else
  173381. dshift += s_inc;
  173382. }
  173383. if (sshift == s_end)
  173384. {
  173385. sshift = s_start;
  173386. sp--;
  173387. }
  173388. else
  173389. sshift += s_inc;
  173390. }
  173391. break;
  173392. }
  173393. default:
  173394. {
  173395. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  173396. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  173397. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  173398. int jstop = png_pass_inc[pass];
  173399. png_uint_32 i;
  173400. for (i = 0; i < row_info->width; i++)
  173401. {
  173402. png_byte v[8];
  173403. int j;
  173404. png_memcpy(v, sp, pixel_bytes);
  173405. for (j = 0; j < jstop; j++)
  173406. {
  173407. png_memcpy(dp, v, pixel_bytes);
  173408. dp -= pixel_bytes;
  173409. }
  173410. sp -= pixel_bytes;
  173411. }
  173412. break;
  173413. }
  173414. }
  173415. row_info->width = final_width;
  173416. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  173417. }
  173418. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  173419. transformations = transformations; /* silence compiler warning */
  173420. #endif
  173421. }
  173422. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  173423. void /* PRIVATE */
  173424. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  173425. png_bytep prev_row, int filter)
  173426. {
  173427. png_debug(1, "in png_read_filter_row\n");
  173428. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  173429. switch (filter)
  173430. {
  173431. case PNG_FILTER_VALUE_NONE:
  173432. break;
  173433. case PNG_FILTER_VALUE_SUB:
  173434. {
  173435. png_uint_32 i;
  173436. png_uint_32 istop = row_info->rowbytes;
  173437. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173438. png_bytep rp = row + bpp;
  173439. png_bytep lp = row;
  173440. for (i = bpp; i < istop; i++)
  173441. {
  173442. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  173443. rp++;
  173444. }
  173445. break;
  173446. }
  173447. case PNG_FILTER_VALUE_UP:
  173448. {
  173449. png_uint_32 i;
  173450. png_uint_32 istop = row_info->rowbytes;
  173451. png_bytep rp = row;
  173452. png_bytep pp = prev_row;
  173453. for (i = 0; i < istop; i++)
  173454. {
  173455. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173456. rp++;
  173457. }
  173458. break;
  173459. }
  173460. case PNG_FILTER_VALUE_AVG:
  173461. {
  173462. png_uint_32 i;
  173463. png_bytep rp = row;
  173464. png_bytep pp = prev_row;
  173465. png_bytep lp = row;
  173466. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173467. png_uint_32 istop = row_info->rowbytes - bpp;
  173468. for (i = 0; i < bpp; i++)
  173469. {
  173470. *rp = (png_byte)(((int)(*rp) +
  173471. ((int)(*pp++) / 2 )) & 0xff);
  173472. rp++;
  173473. }
  173474. for (i = 0; i < istop; i++)
  173475. {
  173476. *rp = (png_byte)(((int)(*rp) +
  173477. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  173478. rp++;
  173479. }
  173480. break;
  173481. }
  173482. case PNG_FILTER_VALUE_PAETH:
  173483. {
  173484. png_uint_32 i;
  173485. png_bytep rp = row;
  173486. png_bytep pp = prev_row;
  173487. png_bytep lp = row;
  173488. png_bytep cp = prev_row;
  173489. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173490. png_uint_32 istop=row_info->rowbytes - bpp;
  173491. for (i = 0; i < bpp; i++)
  173492. {
  173493. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173494. rp++;
  173495. }
  173496. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  173497. {
  173498. int a, b, c, pa, pb, pc, p;
  173499. a = *lp++;
  173500. b = *pp++;
  173501. c = *cp++;
  173502. p = b - c;
  173503. pc = a - c;
  173504. #ifdef PNG_USE_ABS
  173505. pa = abs(p);
  173506. pb = abs(pc);
  173507. pc = abs(p + pc);
  173508. #else
  173509. pa = p < 0 ? -p : p;
  173510. pb = pc < 0 ? -pc : pc;
  173511. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  173512. #endif
  173513. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173514. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173515. rp++;
  173516. }
  173517. break;
  173518. }
  173519. default:
  173520. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173521. *row=0;
  173522. break;
  173523. }
  173524. }
  173525. void /* PRIVATE */
  173526. png_read_finish_row(png_structp png_ptr)
  173527. {
  173528. #ifdef PNG_USE_LOCAL_ARRAYS
  173529. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173530. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173531. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173532. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173533. #endif
  173534. png_debug(1, "in png_read_finish_row\n");
  173535. png_ptr->row_number++;
  173536. if (png_ptr->row_number < png_ptr->num_rows)
  173537. return;
  173538. if (png_ptr->interlaced)
  173539. {
  173540. png_ptr->row_number = 0;
  173541. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173542. png_ptr->rowbytes + 1);
  173543. do
  173544. {
  173545. png_ptr->pass++;
  173546. if (png_ptr->pass >= 7)
  173547. break;
  173548. png_ptr->iwidth = (png_ptr->width +
  173549. png_pass_inc[png_ptr->pass] - 1 -
  173550. png_pass_start[png_ptr->pass]) /
  173551. png_pass_inc[png_ptr->pass];
  173552. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173553. png_ptr->iwidth) + 1;
  173554. if (!(png_ptr->transformations & PNG_INTERLACE))
  173555. {
  173556. png_ptr->num_rows = (png_ptr->height +
  173557. png_pass_yinc[png_ptr->pass] - 1 -
  173558. png_pass_ystart[png_ptr->pass]) /
  173559. png_pass_yinc[png_ptr->pass];
  173560. if (!(png_ptr->num_rows))
  173561. continue;
  173562. }
  173563. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173564. break;
  173565. } while (png_ptr->iwidth == 0);
  173566. if (png_ptr->pass < 7)
  173567. return;
  173568. }
  173569. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173570. {
  173571. #ifdef PNG_USE_LOCAL_ARRAYS
  173572. PNG_CONST PNG_IDAT;
  173573. #endif
  173574. char extra;
  173575. int ret;
  173576. png_ptr->zstream.next_out = (Bytef *)&extra;
  173577. png_ptr->zstream.avail_out = (uInt)1;
  173578. for(;;)
  173579. {
  173580. if (!(png_ptr->zstream.avail_in))
  173581. {
  173582. while (!png_ptr->idat_size)
  173583. {
  173584. png_byte chunk_length[4];
  173585. png_crc_finish(png_ptr, 0);
  173586. png_read_data(png_ptr, chunk_length, 4);
  173587. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173588. png_reset_crc(png_ptr);
  173589. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173590. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173591. png_error(png_ptr, "Not enough image data");
  173592. }
  173593. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173594. png_ptr->zstream.next_in = png_ptr->zbuf;
  173595. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173596. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173597. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173598. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173599. }
  173600. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173601. if (ret == Z_STREAM_END)
  173602. {
  173603. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173604. png_ptr->idat_size)
  173605. png_warning(png_ptr, "Extra compressed data");
  173606. png_ptr->mode |= PNG_AFTER_IDAT;
  173607. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173608. break;
  173609. }
  173610. if (ret != Z_OK)
  173611. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173612. "Decompression Error");
  173613. if (!(png_ptr->zstream.avail_out))
  173614. {
  173615. png_warning(png_ptr, "Extra compressed data.");
  173616. png_ptr->mode |= PNG_AFTER_IDAT;
  173617. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173618. break;
  173619. }
  173620. }
  173621. png_ptr->zstream.avail_out = 0;
  173622. }
  173623. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173624. png_warning(png_ptr, "Extra compression data");
  173625. inflateReset(&png_ptr->zstream);
  173626. png_ptr->mode |= PNG_AFTER_IDAT;
  173627. }
  173628. void /* PRIVATE */
  173629. png_read_start_row(png_structp png_ptr)
  173630. {
  173631. #ifdef PNG_USE_LOCAL_ARRAYS
  173632. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173633. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173634. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173635. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173636. #endif
  173637. int max_pixel_depth;
  173638. png_uint_32 row_bytes;
  173639. png_debug(1, "in png_read_start_row\n");
  173640. png_ptr->zstream.avail_in = 0;
  173641. png_init_read_transformations(png_ptr);
  173642. if (png_ptr->interlaced)
  173643. {
  173644. if (!(png_ptr->transformations & PNG_INTERLACE))
  173645. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173646. png_pass_ystart[0]) / png_pass_yinc[0];
  173647. else
  173648. png_ptr->num_rows = png_ptr->height;
  173649. png_ptr->iwidth = (png_ptr->width +
  173650. png_pass_inc[png_ptr->pass] - 1 -
  173651. png_pass_start[png_ptr->pass]) /
  173652. png_pass_inc[png_ptr->pass];
  173653. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173654. png_ptr->irowbytes = (png_size_t)row_bytes;
  173655. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173656. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173657. }
  173658. else
  173659. {
  173660. png_ptr->num_rows = png_ptr->height;
  173661. png_ptr->iwidth = png_ptr->width;
  173662. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173663. }
  173664. max_pixel_depth = png_ptr->pixel_depth;
  173665. #if defined(PNG_READ_PACK_SUPPORTED)
  173666. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173667. max_pixel_depth = 8;
  173668. #endif
  173669. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173670. if (png_ptr->transformations & PNG_EXPAND)
  173671. {
  173672. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173673. {
  173674. if (png_ptr->num_trans)
  173675. max_pixel_depth = 32;
  173676. else
  173677. max_pixel_depth = 24;
  173678. }
  173679. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173680. {
  173681. if (max_pixel_depth < 8)
  173682. max_pixel_depth = 8;
  173683. if (png_ptr->num_trans)
  173684. max_pixel_depth *= 2;
  173685. }
  173686. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173687. {
  173688. if (png_ptr->num_trans)
  173689. {
  173690. max_pixel_depth *= 4;
  173691. max_pixel_depth /= 3;
  173692. }
  173693. }
  173694. }
  173695. #endif
  173696. #if defined(PNG_READ_FILLER_SUPPORTED)
  173697. if (png_ptr->transformations & (PNG_FILLER))
  173698. {
  173699. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173700. max_pixel_depth = 32;
  173701. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173702. {
  173703. if (max_pixel_depth <= 8)
  173704. max_pixel_depth = 16;
  173705. else
  173706. max_pixel_depth = 32;
  173707. }
  173708. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173709. {
  173710. if (max_pixel_depth <= 32)
  173711. max_pixel_depth = 32;
  173712. else
  173713. max_pixel_depth = 64;
  173714. }
  173715. }
  173716. #endif
  173717. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173718. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173719. {
  173720. if (
  173721. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173722. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173723. #endif
  173724. #if defined(PNG_READ_FILLER_SUPPORTED)
  173725. (png_ptr->transformations & (PNG_FILLER)) ||
  173726. #endif
  173727. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173728. {
  173729. if (max_pixel_depth <= 16)
  173730. max_pixel_depth = 32;
  173731. else
  173732. max_pixel_depth = 64;
  173733. }
  173734. else
  173735. {
  173736. if (max_pixel_depth <= 8)
  173737. {
  173738. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173739. max_pixel_depth = 32;
  173740. else
  173741. max_pixel_depth = 24;
  173742. }
  173743. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173744. max_pixel_depth = 64;
  173745. else
  173746. max_pixel_depth = 48;
  173747. }
  173748. }
  173749. #endif
  173750. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173751. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173752. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173753. {
  173754. int user_pixel_depth=png_ptr->user_transform_depth*
  173755. png_ptr->user_transform_channels;
  173756. if(user_pixel_depth > max_pixel_depth)
  173757. max_pixel_depth=user_pixel_depth;
  173758. }
  173759. #endif
  173760. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173761. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173762. 1 + ((max_pixel_depth + 7) >> 3);
  173763. #ifdef PNG_MAX_MALLOC_64K
  173764. if (row_bytes > (png_uint_32)65536L)
  173765. png_error(png_ptr, "This image requires a row greater than 64KB");
  173766. #endif
  173767. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173768. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173769. #ifdef PNG_MAX_MALLOC_64K
  173770. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173771. png_error(png_ptr, "This image requires a row greater than 64KB");
  173772. #endif
  173773. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173774. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173775. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173776. png_ptr->rowbytes + 1));
  173777. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173778. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173779. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173780. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173781. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173782. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173783. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173784. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173785. }
  173786. #endif /* PNG_READ_SUPPORTED */
  173787. /*** End of inlined file: pngrutil.c ***/
  173788. /*** Start of inlined file: pngset.c ***/
  173789. #define PNG_INTERNAL
  173790. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173791. #if defined(PNG_bKGD_SUPPORTED)
  173792. void PNGAPI
  173793. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173794. {
  173795. png_debug1(1, "in %s storage function\n", "bKGD");
  173796. if (png_ptr == NULL || info_ptr == NULL)
  173797. return;
  173798. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173799. info_ptr->valid |= PNG_INFO_bKGD;
  173800. }
  173801. #endif
  173802. #if defined(PNG_cHRM_SUPPORTED)
  173803. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173804. void PNGAPI
  173805. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173806. double white_x, double white_y, double red_x, double red_y,
  173807. double green_x, double green_y, double blue_x, double blue_y)
  173808. {
  173809. png_debug1(1, "in %s storage function\n", "cHRM");
  173810. if (png_ptr == NULL || info_ptr == NULL)
  173811. return;
  173812. if (white_x < 0.0 || white_y < 0.0 ||
  173813. red_x < 0.0 || red_y < 0.0 ||
  173814. green_x < 0.0 || green_y < 0.0 ||
  173815. blue_x < 0.0 || blue_y < 0.0)
  173816. {
  173817. png_warning(png_ptr,
  173818. "Ignoring attempt to set negative chromaticity value");
  173819. return;
  173820. }
  173821. if (white_x > 21474.83 || white_y > 21474.83 ||
  173822. red_x > 21474.83 || red_y > 21474.83 ||
  173823. green_x > 21474.83 || green_y > 21474.83 ||
  173824. blue_x > 21474.83 || blue_y > 21474.83)
  173825. {
  173826. png_warning(png_ptr,
  173827. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173828. return;
  173829. }
  173830. info_ptr->x_white = (float)white_x;
  173831. info_ptr->y_white = (float)white_y;
  173832. info_ptr->x_red = (float)red_x;
  173833. info_ptr->y_red = (float)red_y;
  173834. info_ptr->x_green = (float)green_x;
  173835. info_ptr->y_green = (float)green_y;
  173836. info_ptr->x_blue = (float)blue_x;
  173837. info_ptr->y_blue = (float)blue_y;
  173838. #ifdef PNG_FIXED_POINT_SUPPORTED
  173839. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173840. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173841. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173842. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173843. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173844. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173845. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173846. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173847. #endif
  173848. info_ptr->valid |= PNG_INFO_cHRM;
  173849. }
  173850. #endif
  173851. #ifdef PNG_FIXED_POINT_SUPPORTED
  173852. void PNGAPI
  173853. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173854. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173855. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173856. png_fixed_point blue_x, png_fixed_point blue_y)
  173857. {
  173858. png_debug1(1, "in %s storage function\n", "cHRM");
  173859. if (png_ptr == NULL || info_ptr == NULL)
  173860. return;
  173861. if (white_x < 0 || white_y < 0 ||
  173862. red_x < 0 || red_y < 0 ||
  173863. green_x < 0 || green_y < 0 ||
  173864. blue_x < 0 || blue_y < 0)
  173865. {
  173866. png_warning(png_ptr,
  173867. "Ignoring attempt to set negative chromaticity value");
  173868. return;
  173869. }
  173870. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173871. if (white_x > (double) PNG_UINT_31_MAX ||
  173872. white_y > (double) PNG_UINT_31_MAX ||
  173873. red_x > (double) PNG_UINT_31_MAX ||
  173874. red_y > (double) PNG_UINT_31_MAX ||
  173875. green_x > (double) PNG_UINT_31_MAX ||
  173876. green_y > (double) PNG_UINT_31_MAX ||
  173877. blue_x > (double) PNG_UINT_31_MAX ||
  173878. blue_y > (double) PNG_UINT_31_MAX)
  173879. #else
  173880. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173881. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173882. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173883. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173884. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173885. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173886. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173887. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173888. #endif
  173889. {
  173890. png_warning(png_ptr,
  173891. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173892. return;
  173893. }
  173894. info_ptr->int_x_white = white_x;
  173895. info_ptr->int_y_white = white_y;
  173896. info_ptr->int_x_red = red_x;
  173897. info_ptr->int_y_red = red_y;
  173898. info_ptr->int_x_green = green_x;
  173899. info_ptr->int_y_green = green_y;
  173900. info_ptr->int_x_blue = blue_x;
  173901. info_ptr->int_y_blue = blue_y;
  173902. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173903. info_ptr->x_white = (float)(white_x/100000.);
  173904. info_ptr->y_white = (float)(white_y/100000.);
  173905. info_ptr->x_red = (float)( red_x/100000.);
  173906. info_ptr->y_red = (float)( red_y/100000.);
  173907. info_ptr->x_green = (float)(green_x/100000.);
  173908. info_ptr->y_green = (float)(green_y/100000.);
  173909. info_ptr->x_blue = (float)( blue_x/100000.);
  173910. info_ptr->y_blue = (float)( blue_y/100000.);
  173911. #endif
  173912. info_ptr->valid |= PNG_INFO_cHRM;
  173913. }
  173914. #endif
  173915. #endif
  173916. #if defined(PNG_gAMA_SUPPORTED)
  173917. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173918. void PNGAPI
  173919. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173920. {
  173921. double gamma;
  173922. png_debug1(1, "in %s storage function\n", "gAMA");
  173923. if (png_ptr == NULL || info_ptr == NULL)
  173924. return;
  173925. if (file_gamma > 21474.83)
  173926. {
  173927. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173928. gamma=21474.83;
  173929. }
  173930. else
  173931. gamma=file_gamma;
  173932. info_ptr->gamma = (float)gamma;
  173933. #ifdef PNG_FIXED_POINT_SUPPORTED
  173934. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173935. #endif
  173936. info_ptr->valid |= PNG_INFO_gAMA;
  173937. if(gamma == 0.0)
  173938. png_warning(png_ptr, "Setting gamma=0");
  173939. }
  173940. #endif
  173941. void PNGAPI
  173942. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173943. int_gamma)
  173944. {
  173945. png_fixed_point gamma;
  173946. png_debug1(1, "in %s storage function\n", "gAMA");
  173947. if (png_ptr == NULL || info_ptr == NULL)
  173948. return;
  173949. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173950. {
  173951. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173952. gamma=PNG_UINT_31_MAX;
  173953. }
  173954. else
  173955. {
  173956. if (int_gamma < 0)
  173957. {
  173958. png_warning(png_ptr, "Setting negative gamma to zero");
  173959. gamma=0;
  173960. }
  173961. else
  173962. gamma=int_gamma;
  173963. }
  173964. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173965. info_ptr->gamma = (float)(gamma/100000.);
  173966. #endif
  173967. #ifdef PNG_FIXED_POINT_SUPPORTED
  173968. info_ptr->int_gamma = gamma;
  173969. #endif
  173970. info_ptr->valid |= PNG_INFO_gAMA;
  173971. if(gamma == 0)
  173972. png_warning(png_ptr, "Setting gamma=0");
  173973. }
  173974. #endif
  173975. #if defined(PNG_hIST_SUPPORTED)
  173976. void PNGAPI
  173977. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173978. {
  173979. int i;
  173980. png_debug1(1, "in %s storage function\n", "hIST");
  173981. if (png_ptr == NULL || info_ptr == NULL)
  173982. return;
  173983. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173984. > PNG_MAX_PALETTE_LENGTH)
  173985. {
  173986. png_warning(png_ptr,
  173987. "Invalid palette size, hIST allocation skipped.");
  173988. return;
  173989. }
  173990. #ifdef PNG_FREE_ME_SUPPORTED
  173991. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173992. #endif
  173993. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173994. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173995. if (png_ptr->hist == NULL)
  173996. {
  173997. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173998. return;
  173999. }
  174000. for (i = 0; i < info_ptr->num_palette; i++)
  174001. png_ptr->hist[i] = hist[i];
  174002. info_ptr->hist = png_ptr->hist;
  174003. info_ptr->valid |= PNG_INFO_hIST;
  174004. #ifdef PNG_FREE_ME_SUPPORTED
  174005. info_ptr->free_me |= PNG_FREE_HIST;
  174006. #else
  174007. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  174008. #endif
  174009. }
  174010. #endif
  174011. void PNGAPI
  174012. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  174013. png_uint_32 width, png_uint_32 height, int bit_depth,
  174014. int color_type, int interlace_type, int compression_type,
  174015. int filter_type)
  174016. {
  174017. png_debug1(1, "in %s storage function\n", "IHDR");
  174018. if (png_ptr == NULL || info_ptr == NULL)
  174019. return;
  174020. if (width == 0 || height == 0)
  174021. png_error(png_ptr, "Image width or height is zero in IHDR");
  174022. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174023. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  174024. png_error(png_ptr, "image size exceeds user limits in IHDR");
  174025. #else
  174026. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  174027. png_error(png_ptr, "image size exceeds user limits in IHDR");
  174028. #endif
  174029. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  174030. png_error(png_ptr, "Invalid image size in IHDR");
  174031. if ( width > (PNG_UINT_32_MAX
  174032. >> 3) /* 8-byte RGBA pixels */
  174033. - 64 /* bigrowbuf hack */
  174034. - 1 /* filter byte */
  174035. - 7*8 /* rounding of width to multiple of 8 pixels */
  174036. - 8) /* extra max_pixel_depth pad */
  174037. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  174038. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  174039. bit_depth != 8 && bit_depth != 16)
  174040. png_error(png_ptr, "Invalid bit depth in IHDR");
  174041. if (color_type < 0 || color_type == 1 ||
  174042. color_type == 5 || color_type > 6)
  174043. png_error(png_ptr, "Invalid color type in IHDR");
  174044. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  174045. ((color_type == PNG_COLOR_TYPE_RGB ||
  174046. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  174047. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  174048. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  174049. if (interlace_type >= PNG_INTERLACE_LAST)
  174050. png_error(png_ptr, "Unknown interlace method in IHDR");
  174051. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  174052. png_error(png_ptr, "Unknown compression method in IHDR");
  174053. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174054. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  174055. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  174056. if(filter_type != PNG_FILTER_TYPE_BASE)
  174057. {
  174058. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  174059. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  174060. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  174061. (color_type == PNG_COLOR_TYPE_RGB ||
  174062. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  174063. png_error(png_ptr, "Unknown filter method in IHDR");
  174064. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  174065. png_warning(png_ptr, "Invalid filter method in IHDR");
  174066. }
  174067. #else
  174068. if(filter_type != PNG_FILTER_TYPE_BASE)
  174069. png_error(png_ptr, "Unknown filter method in IHDR");
  174070. #endif
  174071. info_ptr->width = width;
  174072. info_ptr->height = height;
  174073. info_ptr->bit_depth = (png_byte)bit_depth;
  174074. info_ptr->color_type =(png_byte) color_type;
  174075. info_ptr->compression_type = (png_byte)compression_type;
  174076. info_ptr->filter_type = (png_byte)filter_type;
  174077. info_ptr->interlace_type = (png_byte)interlace_type;
  174078. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174079. info_ptr->channels = 1;
  174080. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  174081. info_ptr->channels = 3;
  174082. else
  174083. info_ptr->channels = 1;
  174084. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  174085. info_ptr->channels++;
  174086. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  174087. if (width > (PNG_UINT_32_MAX
  174088. >> 3) /* 8-byte RGBA pixels */
  174089. - 64 /* bigrowbuf hack */
  174090. - 1 /* filter byte */
  174091. - 7*8 /* rounding of width to multiple of 8 pixels */
  174092. - 8) /* extra max_pixel_depth pad */
  174093. info_ptr->rowbytes = (png_size_t)0;
  174094. else
  174095. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  174096. }
  174097. #if defined(PNG_oFFs_SUPPORTED)
  174098. void PNGAPI
  174099. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  174100. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  174101. {
  174102. png_debug1(1, "in %s storage function\n", "oFFs");
  174103. if (png_ptr == NULL || info_ptr == NULL)
  174104. return;
  174105. info_ptr->x_offset = offset_x;
  174106. info_ptr->y_offset = offset_y;
  174107. info_ptr->offset_unit_type = (png_byte)unit_type;
  174108. info_ptr->valid |= PNG_INFO_oFFs;
  174109. }
  174110. #endif
  174111. #if defined(PNG_pCAL_SUPPORTED)
  174112. void PNGAPI
  174113. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  174114. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  174115. png_charp units, png_charpp params)
  174116. {
  174117. png_uint_32 length;
  174118. int i;
  174119. png_debug1(1, "in %s storage function\n", "pCAL");
  174120. if (png_ptr == NULL || info_ptr == NULL)
  174121. return;
  174122. length = png_strlen(purpose) + 1;
  174123. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  174124. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  174125. if (info_ptr->pcal_purpose == NULL)
  174126. {
  174127. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  174128. return;
  174129. }
  174130. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  174131. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  174132. info_ptr->pcal_X0 = X0;
  174133. info_ptr->pcal_X1 = X1;
  174134. info_ptr->pcal_type = (png_byte)type;
  174135. info_ptr->pcal_nparams = (png_byte)nparams;
  174136. length = png_strlen(units) + 1;
  174137. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  174138. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  174139. if (info_ptr->pcal_units == NULL)
  174140. {
  174141. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  174142. return;
  174143. }
  174144. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  174145. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  174146. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  174147. if (info_ptr->pcal_params == NULL)
  174148. {
  174149. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  174150. return;
  174151. }
  174152. info_ptr->pcal_params[nparams] = NULL;
  174153. for (i = 0; i < nparams; i++)
  174154. {
  174155. length = png_strlen(params[i]) + 1;
  174156. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  174157. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  174158. if (info_ptr->pcal_params[i] == NULL)
  174159. {
  174160. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  174161. return;
  174162. }
  174163. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  174164. }
  174165. info_ptr->valid |= PNG_INFO_pCAL;
  174166. #ifdef PNG_FREE_ME_SUPPORTED
  174167. info_ptr->free_me |= PNG_FREE_PCAL;
  174168. #endif
  174169. }
  174170. #endif
  174171. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  174172. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174173. void PNGAPI
  174174. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  174175. int unit, double width, double height)
  174176. {
  174177. png_debug1(1, "in %s storage function\n", "sCAL");
  174178. if (png_ptr == NULL || info_ptr == NULL)
  174179. return;
  174180. info_ptr->scal_unit = (png_byte)unit;
  174181. info_ptr->scal_pixel_width = width;
  174182. info_ptr->scal_pixel_height = height;
  174183. info_ptr->valid |= PNG_INFO_sCAL;
  174184. }
  174185. #else
  174186. #ifdef PNG_FIXED_POINT_SUPPORTED
  174187. void PNGAPI
  174188. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  174189. int unit, png_charp swidth, png_charp sheight)
  174190. {
  174191. png_uint_32 length;
  174192. png_debug1(1, "in %s storage function\n", "sCAL");
  174193. if (png_ptr == NULL || info_ptr == NULL)
  174194. return;
  174195. info_ptr->scal_unit = (png_byte)unit;
  174196. length = png_strlen(swidth) + 1;
  174197. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174198. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  174199. if (info_ptr->scal_s_width == NULL)
  174200. {
  174201. png_warning(png_ptr,
  174202. "Memory allocation failed while processing sCAL.");
  174203. }
  174204. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  174205. length = png_strlen(sheight) + 1;
  174206. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174207. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  174208. if (info_ptr->scal_s_height == NULL)
  174209. {
  174210. png_free (png_ptr, info_ptr->scal_s_width);
  174211. png_warning(png_ptr,
  174212. "Memory allocation failed while processing sCAL.");
  174213. }
  174214. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  174215. info_ptr->valid |= PNG_INFO_sCAL;
  174216. #ifdef PNG_FREE_ME_SUPPORTED
  174217. info_ptr->free_me |= PNG_FREE_SCAL;
  174218. #endif
  174219. }
  174220. #endif
  174221. #endif
  174222. #endif
  174223. #if defined(PNG_pHYs_SUPPORTED)
  174224. void PNGAPI
  174225. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  174226. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  174227. {
  174228. png_debug1(1, "in %s storage function\n", "pHYs");
  174229. if (png_ptr == NULL || info_ptr == NULL)
  174230. return;
  174231. info_ptr->x_pixels_per_unit = res_x;
  174232. info_ptr->y_pixels_per_unit = res_y;
  174233. info_ptr->phys_unit_type = (png_byte)unit_type;
  174234. info_ptr->valid |= PNG_INFO_pHYs;
  174235. }
  174236. #endif
  174237. void PNGAPI
  174238. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  174239. png_colorp palette, int num_palette)
  174240. {
  174241. png_debug1(1, "in %s storage function\n", "PLTE");
  174242. if (png_ptr == NULL || info_ptr == NULL)
  174243. return;
  174244. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  174245. {
  174246. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174247. png_error(png_ptr, "Invalid palette length");
  174248. else
  174249. {
  174250. png_warning(png_ptr, "Invalid palette length");
  174251. return;
  174252. }
  174253. }
  174254. #ifdef PNG_FREE_ME_SUPPORTED
  174255. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  174256. #endif
  174257. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  174258. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  174259. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  174260. png_sizeof(png_color));
  174261. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  174262. info_ptr->palette = png_ptr->palette;
  174263. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  174264. #ifdef PNG_FREE_ME_SUPPORTED
  174265. info_ptr->free_me |= PNG_FREE_PLTE;
  174266. #else
  174267. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  174268. #endif
  174269. info_ptr->valid |= PNG_INFO_PLTE;
  174270. }
  174271. #if defined(PNG_sBIT_SUPPORTED)
  174272. void PNGAPI
  174273. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  174274. png_color_8p sig_bit)
  174275. {
  174276. png_debug1(1, "in %s storage function\n", "sBIT");
  174277. if (png_ptr == NULL || info_ptr == NULL)
  174278. return;
  174279. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  174280. info_ptr->valid |= PNG_INFO_sBIT;
  174281. }
  174282. #endif
  174283. #if defined(PNG_sRGB_SUPPORTED)
  174284. void PNGAPI
  174285. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  174286. {
  174287. png_debug1(1, "in %s storage function\n", "sRGB");
  174288. if (png_ptr == NULL || info_ptr == NULL)
  174289. return;
  174290. info_ptr->srgb_intent = (png_byte)intent;
  174291. info_ptr->valid |= PNG_INFO_sRGB;
  174292. }
  174293. void PNGAPI
  174294. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  174295. int intent)
  174296. {
  174297. #if defined(PNG_gAMA_SUPPORTED)
  174298. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174299. float file_gamma;
  174300. #endif
  174301. #ifdef PNG_FIXED_POINT_SUPPORTED
  174302. png_fixed_point int_file_gamma;
  174303. #endif
  174304. #endif
  174305. #if defined(PNG_cHRM_SUPPORTED)
  174306. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174307. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  174308. #endif
  174309. #ifdef PNG_FIXED_POINT_SUPPORTED
  174310. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  174311. int_green_y, int_blue_x, int_blue_y;
  174312. #endif
  174313. #endif
  174314. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  174315. if (png_ptr == NULL || info_ptr == NULL)
  174316. return;
  174317. png_set_sRGB(png_ptr, info_ptr, intent);
  174318. #if defined(PNG_gAMA_SUPPORTED)
  174319. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174320. file_gamma = (float).45455;
  174321. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  174322. #endif
  174323. #ifdef PNG_FIXED_POINT_SUPPORTED
  174324. int_file_gamma = 45455L;
  174325. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  174326. #endif
  174327. #endif
  174328. #if defined(PNG_cHRM_SUPPORTED)
  174329. #ifdef PNG_FIXED_POINT_SUPPORTED
  174330. int_white_x = 31270L;
  174331. int_white_y = 32900L;
  174332. int_red_x = 64000L;
  174333. int_red_y = 33000L;
  174334. int_green_x = 30000L;
  174335. int_green_y = 60000L;
  174336. int_blue_x = 15000L;
  174337. int_blue_y = 6000L;
  174338. png_set_cHRM_fixed(png_ptr, info_ptr,
  174339. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  174340. int_blue_x, int_blue_y);
  174341. #endif
  174342. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174343. white_x = (float).3127;
  174344. white_y = (float).3290;
  174345. red_x = (float).64;
  174346. red_y = (float).33;
  174347. green_x = (float).30;
  174348. green_y = (float).60;
  174349. blue_x = (float).15;
  174350. blue_y = (float).06;
  174351. png_set_cHRM(png_ptr, info_ptr,
  174352. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  174353. #endif
  174354. #endif
  174355. }
  174356. #endif
  174357. #if defined(PNG_iCCP_SUPPORTED)
  174358. void PNGAPI
  174359. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  174360. png_charp name, int compression_type,
  174361. png_charp profile, png_uint_32 proflen)
  174362. {
  174363. png_charp new_iccp_name;
  174364. png_charp new_iccp_profile;
  174365. png_debug1(1, "in %s storage function\n", "iCCP");
  174366. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  174367. return;
  174368. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  174369. if (new_iccp_name == NULL)
  174370. {
  174371. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  174372. return;
  174373. }
  174374. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  174375. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  174376. if (new_iccp_profile == NULL)
  174377. {
  174378. png_free (png_ptr, new_iccp_name);
  174379. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  174380. return;
  174381. }
  174382. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  174383. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  174384. info_ptr->iccp_proflen = proflen;
  174385. info_ptr->iccp_name = new_iccp_name;
  174386. info_ptr->iccp_profile = new_iccp_profile;
  174387. info_ptr->iccp_compression = (png_byte)compression_type;
  174388. #ifdef PNG_FREE_ME_SUPPORTED
  174389. info_ptr->free_me |= PNG_FREE_ICCP;
  174390. #endif
  174391. info_ptr->valid |= PNG_INFO_iCCP;
  174392. }
  174393. #endif
  174394. #if defined(PNG_TEXT_SUPPORTED)
  174395. void PNGAPI
  174396. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174397. int num_text)
  174398. {
  174399. int ret;
  174400. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  174401. if (ret)
  174402. png_error(png_ptr, "Insufficient memory to store text");
  174403. }
  174404. int /* PRIVATE */
  174405. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174406. int num_text)
  174407. {
  174408. int i;
  174409. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  174410. "text" : (png_const_charp)png_ptr->chunk_name));
  174411. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  174412. return(0);
  174413. if (info_ptr->num_text + num_text > info_ptr->max_text)
  174414. {
  174415. if (info_ptr->text != NULL)
  174416. {
  174417. png_textp old_text;
  174418. int old_max;
  174419. old_max = info_ptr->max_text;
  174420. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  174421. old_text = info_ptr->text;
  174422. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174423. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174424. if (info_ptr->text == NULL)
  174425. {
  174426. png_free(png_ptr, old_text);
  174427. return(1);
  174428. }
  174429. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  174430. png_sizeof(png_text)));
  174431. png_free(png_ptr, old_text);
  174432. }
  174433. else
  174434. {
  174435. info_ptr->max_text = num_text + 8;
  174436. info_ptr->num_text = 0;
  174437. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174438. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174439. if (info_ptr->text == NULL)
  174440. return(1);
  174441. #ifdef PNG_FREE_ME_SUPPORTED
  174442. info_ptr->free_me |= PNG_FREE_TEXT;
  174443. #endif
  174444. }
  174445. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  174446. info_ptr->max_text);
  174447. }
  174448. for (i = 0; i < num_text; i++)
  174449. {
  174450. png_size_t text_length,key_len;
  174451. png_size_t lang_len,lang_key_len;
  174452. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  174453. if (text_ptr[i].key == NULL)
  174454. continue;
  174455. key_len = png_strlen(text_ptr[i].key);
  174456. if(text_ptr[i].compression <= 0)
  174457. {
  174458. lang_len = 0;
  174459. lang_key_len = 0;
  174460. }
  174461. else
  174462. #ifdef PNG_iTXt_SUPPORTED
  174463. {
  174464. if (text_ptr[i].lang != NULL)
  174465. lang_len = png_strlen(text_ptr[i].lang);
  174466. else
  174467. lang_len = 0;
  174468. if (text_ptr[i].lang_key != NULL)
  174469. lang_key_len = png_strlen(text_ptr[i].lang_key);
  174470. else
  174471. lang_key_len = 0;
  174472. }
  174473. #else
  174474. {
  174475. png_warning(png_ptr, "iTXt chunk not supported.");
  174476. continue;
  174477. }
  174478. #endif
  174479. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  174480. {
  174481. text_length = 0;
  174482. #ifdef PNG_iTXt_SUPPORTED
  174483. if(text_ptr[i].compression > 0)
  174484. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  174485. else
  174486. #endif
  174487. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  174488. }
  174489. else
  174490. {
  174491. text_length = png_strlen(text_ptr[i].text);
  174492. textp->compression = text_ptr[i].compression;
  174493. }
  174494. textp->key = (png_charp)png_malloc_warn(png_ptr,
  174495. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  174496. if (textp->key == NULL)
  174497. return(1);
  174498. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  174499. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  174500. (int)textp->key);
  174501. png_memcpy(textp->key, text_ptr[i].key,
  174502. (png_size_t)(key_len));
  174503. *(textp->key+key_len) = '\0';
  174504. #ifdef PNG_iTXt_SUPPORTED
  174505. if (text_ptr[i].compression > 0)
  174506. {
  174507. textp->lang=textp->key + key_len + 1;
  174508. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  174509. *(textp->lang+lang_len) = '\0';
  174510. textp->lang_key=textp->lang + lang_len + 1;
  174511. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  174512. *(textp->lang_key+lang_key_len) = '\0';
  174513. textp->text=textp->lang_key + lang_key_len + 1;
  174514. }
  174515. else
  174516. #endif
  174517. {
  174518. #ifdef PNG_iTXt_SUPPORTED
  174519. textp->lang=NULL;
  174520. textp->lang_key=NULL;
  174521. #endif
  174522. textp->text=textp->key + key_len + 1;
  174523. }
  174524. if(text_length)
  174525. png_memcpy(textp->text, text_ptr[i].text,
  174526. (png_size_t)(text_length));
  174527. *(textp->text+text_length) = '\0';
  174528. #ifdef PNG_iTXt_SUPPORTED
  174529. if(textp->compression > 0)
  174530. {
  174531. textp->text_length = 0;
  174532. textp->itxt_length = text_length;
  174533. }
  174534. else
  174535. #endif
  174536. {
  174537. textp->text_length = text_length;
  174538. #ifdef PNG_iTXt_SUPPORTED
  174539. textp->itxt_length = 0;
  174540. #endif
  174541. }
  174542. info_ptr->num_text++;
  174543. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174544. }
  174545. return(0);
  174546. }
  174547. #endif
  174548. #if defined(PNG_tIME_SUPPORTED)
  174549. void PNGAPI
  174550. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174551. {
  174552. png_debug1(1, "in %s storage function\n", "tIME");
  174553. if (png_ptr == NULL || info_ptr == NULL ||
  174554. (png_ptr->mode & PNG_WROTE_tIME))
  174555. return;
  174556. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174557. info_ptr->valid |= PNG_INFO_tIME;
  174558. }
  174559. #endif
  174560. #if defined(PNG_tRNS_SUPPORTED)
  174561. void PNGAPI
  174562. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174563. png_bytep trans, int num_trans, png_color_16p trans_values)
  174564. {
  174565. png_debug1(1, "in %s storage function\n", "tRNS");
  174566. if (png_ptr == NULL || info_ptr == NULL)
  174567. return;
  174568. if (trans != NULL)
  174569. {
  174570. #ifdef PNG_FREE_ME_SUPPORTED
  174571. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174572. #endif
  174573. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174574. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174575. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174576. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174577. #ifdef PNG_FREE_ME_SUPPORTED
  174578. info_ptr->free_me |= PNG_FREE_TRNS;
  174579. #else
  174580. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174581. #endif
  174582. }
  174583. if (trans_values != NULL)
  174584. {
  174585. png_memcpy(&(info_ptr->trans_values), trans_values,
  174586. png_sizeof(png_color_16));
  174587. if (num_trans == 0)
  174588. num_trans = 1;
  174589. }
  174590. info_ptr->num_trans = (png_uint_16)num_trans;
  174591. info_ptr->valid |= PNG_INFO_tRNS;
  174592. }
  174593. #endif
  174594. #if defined(PNG_sPLT_SUPPORTED)
  174595. void PNGAPI
  174596. png_set_sPLT(png_structp png_ptr,
  174597. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174598. {
  174599. png_sPLT_tp np;
  174600. int i;
  174601. if (png_ptr == NULL || info_ptr == NULL)
  174602. return;
  174603. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174604. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174605. if (np == NULL)
  174606. {
  174607. png_warning(png_ptr, "No memory for sPLT palettes.");
  174608. return;
  174609. }
  174610. png_memcpy(np, info_ptr->splt_palettes,
  174611. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174612. png_free(png_ptr, info_ptr->splt_palettes);
  174613. info_ptr->splt_palettes=NULL;
  174614. for (i = 0; i < nentries; i++)
  174615. {
  174616. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174617. png_sPLT_tp from = entries + i;
  174618. to->name = (png_charp)png_malloc_warn(png_ptr,
  174619. png_strlen(from->name) + 1);
  174620. if (to->name == NULL)
  174621. {
  174622. png_warning(png_ptr,
  174623. "Out of memory while processing sPLT chunk");
  174624. }
  174625. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174626. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174627. from->nentries * png_sizeof(png_sPLT_entry));
  174628. png_memcpy(to->entries, from->entries,
  174629. from->nentries * png_sizeof(png_sPLT_entry));
  174630. if (to->entries == NULL)
  174631. {
  174632. png_warning(png_ptr,
  174633. "Out of memory while processing sPLT chunk");
  174634. png_free(png_ptr,to->name);
  174635. to->name = NULL;
  174636. }
  174637. to->nentries = from->nentries;
  174638. to->depth = from->depth;
  174639. }
  174640. info_ptr->splt_palettes = np;
  174641. info_ptr->splt_palettes_num += nentries;
  174642. info_ptr->valid |= PNG_INFO_sPLT;
  174643. #ifdef PNG_FREE_ME_SUPPORTED
  174644. info_ptr->free_me |= PNG_FREE_SPLT;
  174645. #endif
  174646. }
  174647. #endif /* PNG_sPLT_SUPPORTED */
  174648. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174649. void PNGAPI
  174650. png_set_unknown_chunks(png_structp png_ptr,
  174651. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174652. {
  174653. png_unknown_chunkp np;
  174654. int i;
  174655. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174656. return;
  174657. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174658. (info_ptr->unknown_chunks_num + num_unknowns) *
  174659. png_sizeof(png_unknown_chunk));
  174660. if (np == NULL)
  174661. {
  174662. png_warning(png_ptr,
  174663. "Out of memory while processing unknown chunk.");
  174664. return;
  174665. }
  174666. png_memcpy(np, info_ptr->unknown_chunks,
  174667. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174668. png_free(png_ptr, info_ptr->unknown_chunks);
  174669. info_ptr->unknown_chunks=NULL;
  174670. for (i = 0; i < num_unknowns; i++)
  174671. {
  174672. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174673. png_unknown_chunkp from = unknowns + i;
  174674. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174675. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174676. if (to->data == NULL)
  174677. {
  174678. png_warning(png_ptr,
  174679. "Out of memory while processing unknown chunk.");
  174680. }
  174681. else
  174682. {
  174683. png_memcpy(to->data, from->data, from->size);
  174684. to->size = from->size;
  174685. to->location = (png_byte)(png_ptr->mode & 0xff);
  174686. }
  174687. }
  174688. info_ptr->unknown_chunks = np;
  174689. info_ptr->unknown_chunks_num += num_unknowns;
  174690. #ifdef PNG_FREE_ME_SUPPORTED
  174691. info_ptr->free_me |= PNG_FREE_UNKN;
  174692. #endif
  174693. }
  174694. void PNGAPI
  174695. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174696. int chunk, int location)
  174697. {
  174698. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174699. (int)info_ptr->unknown_chunks_num)
  174700. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174701. }
  174702. #endif
  174703. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174704. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174705. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174706. void PNGAPI
  174707. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174708. {
  174709. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174710. if (png_ptr == NULL)
  174711. return;
  174712. png_ptr->mng_features_permitted = (png_byte)
  174713. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174714. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174715. }
  174716. #endif
  174717. #endif
  174718. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174719. png_uint_32 PNGAPI
  174720. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174721. {
  174722. png_debug(1, "in png_permit_mng_features\n");
  174723. if (png_ptr == NULL)
  174724. return (png_uint_32)0;
  174725. png_ptr->mng_features_permitted =
  174726. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174727. return (png_uint_32)png_ptr->mng_features_permitted;
  174728. }
  174729. #endif
  174730. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174731. void PNGAPI
  174732. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174733. chunk_list, int num_chunks)
  174734. {
  174735. png_bytep new_list, p;
  174736. int i, old_num_chunks;
  174737. if (png_ptr == NULL)
  174738. return;
  174739. if (num_chunks == 0)
  174740. {
  174741. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174742. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174743. else
  174744. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174745. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174746. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174747. else
  174748. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174749. return;
  174750. }
  174751. if (chunk_list == NULL)
  174752. return;
  174753. old_num_chunks=png_ptr->num_chunk_list;
  174754. new_list=(png_bytep)png_malloc(png_ptr,
  174755. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174756. if(png_ptr->chunk_list != NULL)
  174757. {
  174758. png_memcpy(new_list, png_ptr->chunk_list,
  174759. (png_size_t)(5*old_num_chunks));
  174760. png_free(png_ptr, png_ptr->chunk_list);
  174761. png_ptr->chunk_list=NULL;
  174762. }
  174763. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174764. (png_size_t)(5*num_chunks));
  174765. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174766. *p=(png_byte)keep;
  174767. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174768. png_ptr->chunk_list=new_list;
  174769. #ifdef PNG_FREE_ME_SUPPORTED
  174770. png_ptr->free_me |= PNG_FREE_LIST;
  174771. #endif
  174772. }
  174773. #endif
  174774. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174775. void PNGAPI
  174776. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174777. png_user_chunk_ptr read_user_chunk_fn)
  174778. {
  174779. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174780. if (png_ptr == NULL)
  174781. return;
  174782. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174783. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174784. }
  174785. #endif
  174786. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174787. void PNGAPI
  174788. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174789. {
  174790. png_debug1(1, "in %s storage function\n", "rows");
  174791. if (png_ptr == NULL || info_ptr == NULL)
  174792. return;
  174793. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174794. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174795. info_ptr->row_pointers = row_pointers;
  174796. if(row_pointers)
  174797. info_ptr->valid |= PNG_INFO_IDAT;
  174798. }
  174799. #endif
  174800. #ifdef PNG_WRITE_SUPPORTED
  174801. void PNGAPI
  174802. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174803. {
  174804. if (png_ptr == NULL)
  174805. return;
  174806. if(png_ptr->zbuf)
  174807. png_free(png_ptr, png_ptr->zbuf);
  174808. png_ptr->zbuf_size = (png_size_t)size;
  174809. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174810. png_ptr->zstream.next_out = png_ptr->zbuf;
  174811. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174812. }
  174813. #endif
  174814. void PNGAPI
  174815. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174816. {
  174817. if (png_ptr && info_ptr)
  174818. info_ptr->valid &= ~(mask);
  174819. }
  174820. #ifndef PNG_1_0_X
  174821. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174822. void PNGAPI
  174823. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174824. {
  174825. if (png_ptr != NULL)
  174826. png_ptr->asm_flags = 0;
  174827. }
  174828. void PNGAPI
  174829. png_set_mmx_thresholds (png_structp png_ptr,
  174830. png_byte mmx_bitdepth_threshold,
  174831. png_uint_32 mmx_rowbytes_threshold)
  174832. {
  174833. if (png_ptr == NULL)
  174834. return;
  174835. }
  174836. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174837. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174838. void PNGAPI
  174839. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174840. png_uint_32 user_height_max)
  174841. {
  174842. if(png_ptr == NULL) return;
  174843. png_ptr->user_width_max = user_width_max;
  174844. png_ptr->user_height_max = user_height_max;
  174845. }
  174846. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174847. #endif /* ?PNG_1_0_X */
  174848. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174849. /*** End of inlined file: pngset.c ***/
  174850. /*** Start of inlined file: pngtrans.c ***/
  174851. #define PNG_INTERNAL
  174852. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174853. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174854. void PNGAPI
  174855. png_set_bgr(png_structp png_ptr)
  174856. {
  174857. png_debug(1, "in png_set_bgr\n");
  174858. if(png_ptr == NULL) return;
  174859. png_ptr->transformations |= PNG_BGR;
  174860. }
  174861. #endif
  174862. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174863. void PNGAPI
  174864. png_set_swap(png_structp png_ptr)
  174865. {
  174866. png_debug(1, "in png_set_swap\n");
  174867. if(png_ptr == NULL) return;
  174868. if (png_ptr->bit_depth == 16)
  174869. png_ptr->transformations |= PNG_SWAP_BYTES;
  174870. }
  174871. #endif
  174872. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174873. void PNGAPI
  174874. png_set_packing(png_structp png_ptr)
  174875. {
  174876. png_debug(1, "in png_set_packing\n");
  174877. if(png_ptr == NULL) return;
  174878. if (png_ptr->bit_depth < 8)
  174879. {
  174880. png_ptr->transformations |= PNG_PACK;
  174881. png_ptr->usr_bit_depth = 8;
  174882. }
  174883. }
  174884. #endif
  174885. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174886. void PNGAPI
  174887. png_set_packswap(png_structp png_ptr)
  174888. {
  174889. png_debug(1, "in png_set_packswap\n");
  174890. if(png_ptr == NULL) return;
  174891. if (png_ptr->bit_depth < 8)
  174892. png_ptr->transformations |= PNG_PACKSWAP;
  174893. }
  174894. #endif
  174895. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174896. void PNGAPI
  174897. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174898. {
  174899. png_debug(1, "in png_set_shift\n");
  174900. if(png_ptr == NULL) return;
  174901. png_ptr->transformations |= PNG_SHIFT;
  174902. png_ptr->shift = *true_bits;
  174903. }
  174904. #endif
  174905. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174906. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174907. int PNGAPI
  174908. png_set_interlace_handling(png_structp png_ptr)
  174909. {
  174910. png_debug(1, "in png_set_interlace handling\n");
  174911. if (png_ptr && png_ptr->interlaced)
  174912. {
  174913. png_ptr->transformations |= PNG_INTERLACE;
  174914. return (7);
  174915. }
  174916. return (1);
  174917. }
  174918. #endif
  174919. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174920. void PNGAPI
  174921. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174922. {
  174923. png_debug(1, "in png_set_filler\n");
  174924. if(png_ptr == NULL) return;
  174925. png_ptr->transformations |= PNG_FILLER;
  174926. png_ptr->filler = (png_byte)filler;
  174927. if (filler_loc == PNG_FILLER_AFTER)
  174928. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174929. else
  174930. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174931. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174932. {
  174933. png_ptr->usr_channels = 4;
  174934. }
  174935. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174936. {
  174937. png_ptr->usr_channels = 2;
  174938. }
  174939. }
  174940. #if !defined(PNG_1_0_X)
  174941. void PNGAPI
  174942. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174943. {
  174944. png_debug(1, "in png_set_add_alpha\n");
  174945. if(png_ptr == NULL) return;
  174946. png_set_filler(png_ptr, filler, filler_loc);
  174947. png_ptr->transformations |= PNG_ADD_ALPHA;
  174948. }
  174949. #endif
  174950. #endif
  174951. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174952. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174953. void PNGAPI
  174954. png_set_swap_alpha(png_structp png_ptr)
  174955. {
  174956. png_debug(1, "in png_set_swap_alpha\n");
  174957. if(png_ptr == NULL) return;
  174958. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174959. }
  174960. #endif
  174961. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174962. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174963. void PNGAPI
  174964. png_set_invert_alpha(png_structp png_ptr)
  174965. {
  174966. png_debug(1, "in png_set_invert_alpha\n");
  174967. if(png_ptr == NULL) return;
  174968. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174969. }
  174970. #endif
  174971. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174972. void PNGAPI
  174973. png_set_invert_mono(png_structp png_ptr)
  174974. {
  174975. png_debug(1, "in png_set_invert_mono\n");
  174976. if(png_ptr == NULL) return;
  174977. png_ptr->transformations |= PNG_INVERT_MONO;
  174978. }
  174979. void /* PRIVATE */
  174980. png_do_invert(png_row_infop row_info, png_bytep row)
  174981. {
  174982. png_debug(1, "in png_do_invert\n");
  174983. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174984. if (row == NULL || row_info == NULL)
  174985. return;
  174986. #endif
  174987. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174988. {
  174989. png_bytep rp = row;
  174990. png_uint_32 i;
  174991. png_uint_32 istop = row_info->rowbytes;
  174992. for (i = 0; i < istop; i++)
  174993. {
  174994. *rp = (png_byte)(~(*rp));
  174995. rp++;
  174996. }
  174997. }
  174998. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174999. row_info->bit_depth == 8)
  175000. {
  175001. png_bytep rp = row;
  175002. png_uint_32 i;
  175003. png_uint_32 istop = row_info->rowbytes;
  175004. for (i = 0; i < istop; i+=2)
  175005. {
  175006. *rp = (png_byte)(~(*rp));
  175007. rp+=2;
  175008. }
  175009. }
  175010. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  175011. row_info->bit_depth == 16)
  175012. {
  175013. png_bytep rp = row;
  175014. png_uint_32 i;
  175015. png_uint_32 istop = row_info->rowbytes;
  175016. for (i = 0; i < istop; i+=4)
  175017. {
  175018. *rp = (png_byte)(~(*rp));
  175019. *(rp+1) = (png_byte)(~(*(rp+1)));
  175020. rp+=4;
  175021. }
  175022. }
  175023. }
  175024. #endif
  175025. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  175026. void /* PRIVATE */
  175027. png_do_swap(png_row_infop row_info, png_bytep row)
  175028. {
  175029. png_debug(1, "in png_do_swap\n");
  175030. if (
  175031. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175032. row != NULL && row_info != NULL &&
  175033. #endif
  175034. row_info->bit_depth == 16)
  175035. {
  175036. png_bytep rp = row;
  175037. png_uint_32 i;
  175038. png_uint_32 istop= row_info->width * row_info->channels;
  175039. for (i = 0; i < istop; i++, rp += 2)
  175040. {
  175041. png_byte t = *rp;
  175042. *rp = *(rp + 1);
  175043. *(rp + 1) = t;
  175044. }
  175045. }
  175046. }
  175047. #endif
  175048. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  175049. static PNG_CONST png_byte onebppswaptable[256] = {
  175050. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  175051. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  175052. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  175053. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  175054. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  175055. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  175056. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  175057. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  175058. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  175059. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  175060. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  175061. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  175062. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  175063. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  175064. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  175065. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  175066. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  175067. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  175068. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  175069. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  175070. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  175071. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  175072. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  175073. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  175074. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  175075. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  175076. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  175077. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  175078. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  175079. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  175080. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  175081. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  175082. };
  175083. static PNG_CONST png_byte twobppswaptable[256] = {
  175084. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  175085. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  175086. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  175087. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  175088. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  175089. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  175090. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  175091. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  175092. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  175093. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  175094. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  175095. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  175096. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  175097. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  175098. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  175099. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  175100. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  175101. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  175102. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  175103. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  175104. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  175105. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  175106. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  175107. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  175108. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  175109. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  175110. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  175111. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  175112. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  175113. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  175114. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  175115. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  175116. };
  175117. static PNG_CONST png_byte fourbppswaptable[256] = {
  175118. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  175119. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  175120. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  175121. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  175122. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  175123. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  175124. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  175125. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  175126. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  175127. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  175128. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  175129. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  175130. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  175131. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  175132. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  175133. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  175134. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  175135. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  175136. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  175137. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  175138. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  175139. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  175140. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  175141. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  175142. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  175143. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  175144. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  175145. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  175146. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  175147. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  175148. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  175149. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  175150. };
  175151. void /* PRIVATE */
  175152. png_do_packswap(png_row_infop row_info, png_bytep row)
  175153. {
  175154. png_debug(1, "in png_do_packswap\n");
  175155. if (
  175156. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175157. row != NULL && row_info != NULL &&
  175158. #endif
  175159. row_info->bit_depth < 8)
  175160. {
  175161. png_bytep rp, end, table;
  175162. end = row + row_info->rowbytes;
  175163. if (row_info->bit_depth == 1)
  175164. table = (png_bytep)onebppswaptable;
  175165. else if (row_info->bit_depth == 2)
  175166. table = (png_bytep)twobppswaptable;
  175167. else if (row_info->bit_depth == 4)
  175168. table = (png_bytep)fourbppswaptable;
  175169. else
  175170. return;
  175171. for (rp = row; rp < end; rp++)
  175172. *rp = table[*rp];
  175173. }
  175174. }
  175175. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  175176. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  175177. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  175178. void /* PRIVATE */
  175179. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  175180. {
  175181. png_debug(1, "in png_do_strip_filler\n");
  175182. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175183. if (row != NULL && row_info != NULL)
  175184. #endif
  175185. {
  175186. png_bytep sp=row;
  175187. png_bytep dp=row;
  175188. png_uint_32 row_width=row_info->width;
  175189. png_uint_32 i;
  175190. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  175191. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  175192. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175193. row_info->channels == 4)
  175194. {
  175195. if (row_info->bit_depth == 8)
  175196. {
  175197. if (flags & PNG_FLAG_FILLER_AFTER)
  175198. {
  175199. dp+=3; sp+=4;
  175200. for (i = 1; i < row_width; i++)
  175201. {
  175202. *dp++ = *sp++;
  175203. *dp++ = *sp++;
  175204. *dp++ = *sp++;
  175205. sp++;
  175206. }
  175207. }
  175208. else
  175209. {
  175210. for (i = 0; i < row_width; i++)
  175211. {
  175212. sp++;
  175213. *dp++ = *sp++;
  175214. *dp++ = *sp++;
  175215. *dp++ = *sp++;
  175216. }
  175217. }
  175218. row_info->pixel_depth = 24;
  175219. row_info->rowbytes = row_width * 3;
  175220. }
  175221. else /* if (row_info->bit_depth == 16) */
  175222. {
  175223. if (flags & PNG_FLAG_FILLER_AFTER)
  175224. {
  175225. sp += 8; dp += 6;
  175226. for (i = 1; i < row_width; i++)
  175227. {
  175228. *dp++ = *sp++;
  175229. *dp++ = *sp++;
  175230. *dp++ = *sp++;
  175231. *dp++ = *sp++;
  175232. *dp++ = *sp++;
  175233. *dp++ = *sp++;
  175234. sp += 2;
  175235. }
  175236. }
  175237. else
  175238. {
  175239. for (i = 0; i < row_width; i++)
  175240. {
  175241. sp+=2;
  175242. *dp++ = *sp++;
  175243. *dp++ = *sp++;
  175244. *dp++ = *sp++;
  175245. *dp++ = *sp++;
  175246. *dp++ = *sp++;
  175247. *dp++ = *sp++;
  175248. }
  175249. }
  175250. row_info->pixel_depth = 48;
  175251. row_info->rowbytes = row_width * 6;
  175252. }
  175253. row_info->channels = 3;
  175254. }
  175255. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  175256. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  175257. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175258. row_info->channels == 2)
  175259. {
  175260. if (row_info->bit_depth == 8)
  175261. {
  175262. if (flags & PNG_FLAG_FILLER_AFTER)
  175263. {
  175264. for (i = 0; i < row_width; i++)
  175265. {
  175266. *dp++ = *sp++;
  175267. sp++;
  175268. }
  175269. }
  175270. else
  175271. {
  175272. for (i = 0; i < row_width; i++)
  175273. {
  175274. sp++;
  175275. *dp++ = *sp++;
  175276. }
  175277. }
  175278. row_info->pixel_depth = 8;
  175279. row_info->rowbytes = row_width;
  175280. }
  175281. else /* if (row_info->bit_depth == 16) */
  175282. {
  175283. if (flags & PNG_FLAG_FILLER_AFTER)
  175284. {
  175285. sp += 4; dp += 2;
  175286. for (i = 1; i < row_width; i++)
  175287. {
  175288. *dp++ = *sp++;
  175289. *dp++ = *sp++;
  175290. sp += 2;
  175291. }
  175292. }
  175293. else
  175294. {
  175295. for (i = 0; i < row_width; i++)
  175296. {
  175297. sp += 2;
  175298. *dp++ = *sp++;
  175299. *dp++ = *sp++;
  175300. }
  175301. }
  175302. row_info->pixel_depth = 16;
  175303. row_info->rowbytes = row_width * 2;
  175304. }
  175305. row_info->channels = 1;
  175306. }
  175307. if (flags & PNG_FLAG_STRIP_ALPHA)
  175308. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  175309. }
  175310. }
  175311. #endif
  175312. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  175313. void /* PRIVATE */
  175314. png_do_bgr(png_row_infop row_info, png_bytep row)
  175315. {
  175316. png_debug(1, "in png_do_bgr\n");
  175317. if (
  175318. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175319. row != NULL && row_info != NULL &&
  175320. #endif
  175321. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  175322. {
  175323. png_uint_32 row_width = row_info->width;
  175324. if (row_info->bit_depth == 8)
  175325. {
  175326. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175327. {
  175328. png_bytep rp;
  175329. png_uint_32 i;
  175330. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  175331. {
  175332. png_byte save = *rp;
  175333. *rp = *(rp + 2);
  175334. *(rp + 2) = save;
  175335. }
  175336. }
  175337. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175338. {
  175339. png_bytep rp;
  175340. png_uint_32 i;
  175341. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  175342. {
  175343. png_byte save = *rp;
  175344. *rp = *(rp + 2);
  175345. *(rp + 2) = save;
  175346. }
  175347. }
  175348. }
  175349. else if (row_info->bit_depth == 16)
  175350. {
  175351. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175352. {
  175353. png_bytep rp;
  175354. png_uint_32 i;
  175355. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  175356. {
  175357. png_byte save = *rp;
  175358. *rp = *(rp + 4);
  175359. *(rp + 4) = save;
  175360. save = *(rp + 1);
  175361. *(rp + 1) = *(rp + 5);
  175362. *(rp + 5) = save;
  175363. }
  175364. }
  175365. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175366. {
  175367. png_bytep rp;
  175368. png_uint_32 i;
  175369. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  175370. {
  175371. png_byte save = *rp;
  175372. *rp = *(rp + 4);
  175373. *(rp + 4) = save;
  175374. save = *(rp + 1);
  175375. *(rp + 1) = *(rp + 5);
  175376. *(rp + 5) = save;
  175377. }
  175378. }
  175379. }
  175380. }
  175381. }
  175382. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  175383. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  175384. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  175385. defined(PNG_LEGACY_SUPPORTED)
  175386. void PNGAPI
  175387. png_set_user_transform_info(png_structp png_ptr, png_voidp
  175388. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  175389. {
  175390. png_debug(1, "in png_set_user_transform_info\n");
  175391. if(png_ptr == NULL) return;
  175392. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175393. png_ptr->user_transform_ptr = user_transform_ptr;
  175394. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  175395. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  175396. #else
  175397. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  175398. png_warning(png_ptr,
  175399. "This version of libpng does not support user transform info");
  175400. #endif
  175401. }
  175402. #endif
  175403. png_voidp PNGAPI
  175404. png_get_user_transform_ptr(png_structp png_ptr)
  175405. {
  175406. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175407. if (png_ptr == NULL) return (NULL);
  175408. return ((png_voidp)png_ptr->user_transform_ptr);
  175409. #else
  175410. return (NULL);
  175411. #endif
  175412. }
  175413. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  175414. /*** End of inlined file: pngtrans.c ***/
  175415. /*** Start of inlined file: pngwio.c ***/
  175416. #define PNG_INTERNAL
  175417. #ifdef PNG_WRITE_SUPPORTED
  175418. void /* PRIVATE */
  175419. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175420. {
  175421. if (png_ptr->write_data_fn != NULL )
  175422. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  175423. else
  175424. png_error(png_ptr, "Call to NULL write function");
  175425. }
  175426. #if !defined(PNG_NO_STDIO)
  175427. #ifndef USE_FAR_KEYWORD
  175428. void PNGAPI
  175429. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175430. {
  175431. png_uint_32 check;
  175432. if(png_ptr == NULL) return;
  175433. #if defined(_WIN32_WCE)
  175434. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  175435. check = 0;
  175436. #else
  175437. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  175438. #endif
  175439. if (check != length)
  175440. png_error(png_ptr, "Write Error");
  175441. }
  175442. #else
  175443. #define NEAR_BUF_SIZE 1024
  175444. #define MIN(a,b) (a <= b ? a : b)
  175445. void PNGAPI
  175446. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175447. {
  175448. png_uint_32 check;
  175449. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  175450. png_FILE_p io_ptr;
  175451. if(png_ptr == NULL) return;
  175452. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  175453. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  175454. if ((png_bytep)near_data == data)
  175455. {
  175456. #if defined(_WIN32_WCE)
  175457. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  175458. check = 0;
  175459. #else
  175460. check = fwrite(near_data, 1, length, io_ptr);
  175461. #endif
  175462. }
  175463. else
  175464. {
  175465. png_byte buf[NEAR_BUF_SIZE];
  175466. png_size_t written, remaining, err;
  175467. check = 0;
  175468. remaining = length;
  175469. do
  175470. {
  175471. written = MIN(NEAR_BUF_SIZE, remaining);
  175472. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  175473. #if defined(_WIN32_WCE)
  175474. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  175475. err = 0;
  175476. #else
  175477. err = fwrite(buf, 1, written, io_ptr);
  175478. #endif
  175479. if (err != written)
  175480. break;
  175481. else
  175482. check += err;
  175483. data += written;
  175484. remaining -= written;
  175485. }
  175486. while (remaining != 0);
  175487. }
  175488. if (check != length)
  175489. png_error(png_ptr, "Write Error");
  175490. }
  175491. #endif
  175492. #endif
  175493. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175494. void /* PRIVATE */
  175495. png_flush(png_structp png_ptr)
  175496. {
  175497. if (png_ptr->output_flush_fn != NULL)
  175498. (*(png_ptr->output_flush_fn))(png_ptr);
  175499. }
  175500. #if !defined(PNG_NO_STDIO)
  175501. void PNGAPI
  175502. png_default_flush(png_structp png_ptr)
  175503. {
  175504. #if !defined(_WIN32_WCE)
  175505. png_FILE_p io_ptr;
  175506. #endif
  175507. if(png_ptr == NULL) return;
  175508. #if !defined(_WIN32_WCE)
  175509. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  175510. if (io_ptr != NULL)
  175511. fflush(io_ptr);
  175512. #endif
  175513. }
  175514. #endif
  175515. #endif
  175516. void PNGAPI
  175517. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175518. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175519. {
  175520. if(png_ptr == NULL) return;
  175521. png_ptr->io_ptr = io_ptr;
  175522. #if !defined(PNG_NO_STDIO)
  175523. if (write_data_fn != NULL)
  175524. png_ptr->write_data_fn = write_data_fn;
  175525. else
  175526. png_ptr->write_data_fn = png_default_write_data;
  175527. #else
  175528. png_ptr->write_data_fn = write_data_fn;
  175529. #endif
  175530. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175531. #if !defined(PNG_NO_STDIO)
  175532. if (output_flush_fn != NULL)
  175533. png_ptr->output_flush_fn = output_flush_fn;
  175534. else
  175535. png_ptr->output_flush_fn = png_default_flush;
  175536. #else
  175537. png_ptr->output_flush_fn = output_flush_fn;
  175538. #endif
  175539. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175540. if (png_ptr->read_data_fn != NULL)
  175541. {
  175542. png_ptr->read_data_fn = NULL;
  175543. png_warning(png_ptr,
  175544. "Attempted to set both read_data_fn and write_data_fn in");
  175545. png_warning(png_ptr,
  175546. "the same structure. Resetting read_data_fn to NULL.");
  175547. }
  175548. }
  175549. #if defined(USE_FAR_KEYWORD)
  175550. #if defined(_MSC_VER)
  175551. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175552. {
  175553. void *near_ptr;
  175554. void FAR *far_ptr;
  175555. FP_OFF(near_ptr) = FP_OFF(ptr);
  175556. far_ptr = (void FAR *)near_ptr;
  175557. if(check != 0)
  175558. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175559. png_error(png_ptr,"segment lost in conversion");
  175560. return(near_ptr);
  175561. }
  175562. # else
  175563. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175564. {
  175565. void *near_ptr;
  175566. void FAR *far_ptr;
  175567. near_ptr = (void FAR *)ptr;
  175568. far_ptr = (void FAR *)near_ptr;
  175569. if(check != 0)
  175570. if(far_ptr != ptr)
  175571. png_error(png_ptr,"segment lost in conversion");
  175572. return(near_ptr);
  175573. }
  175574. # endif
  175575. # endif
  175576. #endif /* PNG_WRITE_SUPPORTED */
  175577. /*** End of inlined file: pngwio.c ***/
  175578. /*** Start of inlined file: pngwrite.c ***/
  175579. #define PNG_INTERNAL
  175580. #ifdef PNG_WRITE_SUPPORTED
  175581. void PNGAPI
  175582. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175583. {
  175584. png_debug(1, "in png_write_info_before_PLTE\n");
  175585. if (png_ptr == NULL || info_ptr == NULL)
  175586. return;
  175587. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175588. {
  175589. png_write_sig(png_ptr); /* write PNG signature */
  175590. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175591. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175592. {
  175593. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175594. png_ptr->mng_features_permitted=0;
  175595. }
  175596. #endif
  175597. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175598. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175599. info_ptr->filter_type,
  175600. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175601. info_ptr->interlace_type);
  175602. #else
  175603. 0);
  175604. #endif
  175605. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175606. if (info_ptr->valid & PNG_INFO_gAMA)
  175607. {
  175608. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175609. png_write_gAMA(png_ptr, info_ptr->gamma);
  175610. #else
  175611. #ifdef PNG_FIXED_POINT_SUPPORTED
  175612. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175613. # endif
  175614. #endif
  175615. }
  175616. #endif
  175617. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175618. if (info_ptr->valid & PNG_INFO_sRGB)
  175619. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175620. #endif
  175621. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175622. if (info_ptr->valid & PNG_INFO_iCCP)
  175623. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175624. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175625. #endif
  175626. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175627. if (info_ptr->valid & PNG_INFO_sBIT)
  175628. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175629. #endif
  175630. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175631. if (info_ptr->valid & PNG_INFO_cHRM)
  175632. {
  175633. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175634. png_write_cHRM(png_ptr,
  175635. info_ptr->x_white, info_ptr->y_white,
  175636. info_ptr->x_red, info_ptr->y_red,
  175637. info_ptr->x_green, info_ptr->y_green,
  175638. info_ptr->x_blue, info_ptr->y_blue);
  175639. #else
  175640. # ifdef PNG_FIXED_POINT_SUPPORTED
  175641. png_write_cHRM_fixed(png_ptr,
  175642. info_ptr->int_x_white, info_ptr->int_y_white,
  175643. info_ptr->int_x_red, info_ptr->int_y_red,
  175644. info_ptr->int_x_green, info_ptr->int_y_green,
  175645. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175646. # endif
  175647. #endif
  175648. }
  175649. #endif
  175650. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175651. if (info_ptr->unknown_chunks_num)
  175652. {
  175653. png_unknown_chunk *up;
  175654. png_debug(5, "writing extra chunks\n");
  175655. for (up = info_ptr->unknown_chunks;
  175656. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175657. up++)
  175658. {
  175659. int keep=png_handle_as_unknown(png_ptr, up->name);
  175660. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175661. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175662. !(up->location & PNG_HAVE_IDAT) &&
  175663. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175664. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175665. {
  175666. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175667. }
  175668. }
  175669. }
  175670. #endif
  175671. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175672. }
  175673. }
  175674. void PNGAPI
  175675. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175676. {
  175677. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175678. int i;
  175679. #endif
  175680. png_debug(1, "in png_write_info\n");
  175681. if (png_ptr == NULL || info_ptr == NULL)
  175682. return;
  175683. png_write_info_before_PLTE(png_ptr, info_ptr);
  175684. if (info_ptr->valid & PNG_INFO_PLTE)
  175685. png_write_PLTE(png_ptr, info_ptr->palette,
  175686. (png_uint_32)info_ptr->num_palette);
  175687. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175688. png_error(png_ptr, "Valid palette required for paletted images");
  175689. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175690. if (info_ptr->valid & PNG_INFO_tRNS)
  175691. {
  175692. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175693. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175694. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175695. {
  175696. int j;
  175697. for (j=0; j<(int)info_ptr->num_trans; j++)
  175698. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175699. }
  175700. #endif
  175701. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175702. info_ptr->num_trans, info_ptr->color_type);
  175703. }
  175704. #endif
  175705. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175706. if (info_ptr->valid & PNG_INFO_bKGD)
  175707. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175708. #endif
  175709. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175710. if (info_ptr->valid & PNG_INFO_hIST)
  175711. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175712. #endif
  175713. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175714. if (info_ptr->valid & PNG_INFO_oFFs)
  175715. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175716. info_ptr->offset_unit_type);
  175717. #endif
  175718. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175719. if (info_ptr->valid & PNG_INFO_pCAL)
  175720. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175721. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175722. info_ptr->pcal_units, info_ptr->pcal_params);
  175723. #endif
  175724. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175725. if (info_ptr->valid & PNG_INFO_sCAL)
  175726. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175727. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175728. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175729. #else
  175730. #ifdef PNG_FIXED_POINT_SUPPORTED
  175731. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175732. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175733. #else
  175734. png_warning(png_ptr,
  175735. "png_write_sCAL not supported; sCAL chunk not written.");
  175736. #endif
  175737. #endif
  175738. #endif
  175739. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175740. if (info_ptr->valid & PNG_INFO_pHYs)
  175741. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175742. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175743. #endif
  175744. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175745. if (info_ptr->valid & PNG_INFO_tIME)
  175746. {
  175747. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175748. png_ptr->mode |= PNG_WROTE_tIME;
  175749. }
  175750. #endif
  175751. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175752. if (info_ptr->valid & PNG_INFO_sPLT)
  175753. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175754. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175755. #endif
  175756. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175757. for (i = 0; i < info_ptr->num_text; i++)
  175758. {
  175759. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175760. info_ptr->text[i].compression);
  175761. if (info_ptr->text[i].compression > 0)
  175762. {
  175763. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175764. png_write_iTXt(png_ptr,
  175765. info_ptr->text[i].compression,
  175766. info_ptr->text[i].key,
  175767. info_ptr->text[i].lang,
  175768. info_ptr->text[i].lang_key,
  175769. info_ptr->text[i].text);
  175770. #else
  175771. png_warning(png_ptr, "Unable to write international text");
  175772. #endif
  175773. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175774. }
  175775. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175776. {
  175777. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175778. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175779. info_ptr->text[i].text, 0,
  175780. info_ptr->text[i].compression);
  175781. #else
  175782. png_warning(png_ptr, "Unable to write compressed text");
  175783. #endif
  175784. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175785. }
  175786. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175787. {
  175788. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175789. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175790. info_ptr->text[i].text,
  175791. 0);
  175792. #else
  175793. png_warning(png_ptr, "Unable to write uncompressed text");
  175794. #endif
  175795. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175796. }
  175797. }
  175798. #endif
  175799. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175800. if (info_ptr->unknown_chunks_num)
  175801. {
  175802. png_unknown_chunk *up;
  175803. png_debug(5, "writing extra chunks\n");
  175804. for (up = info_ptr->unknown_chunks;
  175805. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175806. up++)
  175807. {
  175808. int keep=png_handle_as_unknown(png_ptr, up->name);
  175809. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175810. up->location && (up->location & PNG_HAVE_PLTE) &&
  175811. !(up->location & PNG_HAVE_IDAT) &&
  175812. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175813. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175814. {
  175815. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175816. }
  175817. }
  175818. }
  175819. #endif
  175820. }
  175821. void PNGAPI
  175822. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175823. {
  175824. png_debug(1, "in png_write_end\n");
  175825. if (png_ptr == NULL)
  175826. return;
  175827. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175828. png_error(png_ptr, "No IDATs written into file");
  175829. if (info_ptr != NULL)
  175830. {
  175831. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175832. int i; /* local index variable */
  175833. #endif
  175834. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175835. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175836. !(png_ptr->mode & PNG_WROTE_tIME))
  175837. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175838. #endif
  175839. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175840. for (i = 0; i < info_ptr->num_text; i++)
  175841. {
  175842. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175843. info_ptr->text[i].compression);
  175844. if (info_ptr->text[i].compression > 0)
  175845. {
  175846. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175847. png_write_iTXt(png_ptr,
  175848. info_ptr->text[i].compression,
  175849. info_ptr->text[i].key,
  175850. info_ptr->text[i].lang,
  175851. info_ptr->text[i].lang_key,
  175852. info_ptr->text[i].text);
  175853. #else
  175854. png_warning(png_ptr, "Unable to write international text");
  175855. #endif
  175856. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175857. }
  175858. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175859. {
  175860. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175861. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175862. info_ptr->text[i].text, 0,
  175863. info_ptr->text[i].compression);
  175864. #else
  175865. png_warning(png_ptr, "Unable to write compressed text");
  175866. #endif
  175867. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175868. }
  175869. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175870. {
  175871. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175872. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175873. info_ptr->text[i].text, 0);
  175874. #else
  175875. png_warning(png_ptr, "Unable to write uncompressed text");
  175876. #endif
  175877. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175878. }
  175879. }
  175880. #endif
  175881. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175882. if (info_ptr->unknown_chunks_num)
  175883. {
  175884. png_unknown_chunk *up;
  175885. png_debug(5, "writing extra chunks\n");
  175886. for (up = info_ptr->unknown_chunks;
  175887. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175888. up++)
  175889. {
  175890. int keep=png_handle_as_unknown(png_ptr, up->name);
  175891. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175892. up->location && (up->location & PNG_AFTER_IDAT) &&
  175893. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175894. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175895. {
  175896. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175897. }
  175898. }
  175899. }
  175900. #endif
  175901. }
  175902. png_ptr->mode |= PNG_AFTER_IDAT;
  175903. png_write_IEND(png_ptr);
  175904. }
  175905. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175906. #if !defined(_WIN32_WCE)
  175907. void PNGAPI
  175908. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175909. {
  175910. png_debug(1, "in png_convert_from_struct_tm\n");
  175911. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175912. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175913. ptime->day = (png_byte)ttime->tm_mday;
  175914. ptime->hour = (png_byte)ttime->tm_hour;
  175915. ptime->minute = (png_byte)ttime->tm_min;
  175916. ptime->second = (png_byte)ttime->tm_sec;
  175917. }
  175918. void PNGAPI
  175919. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175920. {
  175921. struct tm *tbuf;
  175922. png_debug(1, "in png_convert_from_time_t\n");
  175923. tbuf = gmtime(&ttime);
  175924. png_convert_from_struct_tm(ptime, tbuf);
  175925. }
  175926. #endif
  175927. #endif
  175928. png_structp PNGAPI
  175929. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175930. png_error_ptr error_fn, png_error_ptr warn_fn)
  175931. {
  175932. #ifdef PNG_USER_MEM_SUPPORTED
  175933. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175934. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175935. }
  175936. png_structp PNGAPI
  175937. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175938. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175939. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175940. {
  175941. #endif /* PNG_USER_MEM_SUPPORTED */
  175942. png_structp png_ptr;
  175943. #ifdef PNG_SETJMP_SUPPORTED
  175944. #ifdef USE_FAR_KEYWORD
  175945. jmp_buf jmpbuf;
  175946. #endif
  175947. #endif
  175948. int i;
  175949. png_debug(1, "in png_create_write_struct\n");
  175950. #ifdef PNG_USER_MEM_SUPPORTED
  175951. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175952. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175953. #else
  175954. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175955. #endif /* PNG_USER_MEM_SUPPORTED */
  175956. if (png_ptr == NULL)
  175957. return (NULL);
  175958. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175959. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175960. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175961. #endif
  175962. #ifdef PNG_SETJMP_SUPPORTED
  175963. #ifdef USE_FAR_KEYWORD
  175964. if (setjmp(jmpbuf))
  175965. #else
  175966. if (setjmp(png_ptr->jmpbuf))
  175967. #endif
  175968. {
  175969. png_free(png_ptr, png_ptr->zbuf);
  175970. png_ptr->zbuf=NULL;
  175971. png_destroy_struct(png_ptr);
  175972. return (NULL);
  175973. }
  175974. #ifdef USE_FAR_KEYWORD
  175975. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175976. #endif
  175977. #endif
  175978. #ifdef PNG_USER_MEM_SUPPORTED
  175979. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175980. #endif /* PNG_USER_MEM_SUPPORTED */
  175981. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175982. i=0;
  175983. do
  175984. {
  175985. if(user_png_ver[i] != png_libpng_ver[i])
  175986. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175987. } while (png_libpng_ver[i++]);
  175988. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175989. {
  175990. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175991. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175992. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175993. {
  175994. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175995. char msg[80];
  175996. if (user_png_ver)
  175997. {
  175998. png_snprintf(msg, 80,
  175999. "Application was compiled with png.h from libpng-%.20s",
  176000. user_png_ver);
  176001. png_warning(png_ptr, msg);
  176002. }
  176003. png_snprintf(msg, 80,
  176004. "Application is running with png.c from libpng-%.20s",
  176005. png_libpng_ver);
  176006. png_warning(png_ptr, msg);
  176007. #endif
  176008. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176009. png_ptr->flags=0;
  176010. #endif
  176011. png_error(png_ptr,
  176012. "Incompatible libpng version in application and library");
  176013. }
  176014. }
  176015. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  176016. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  176017. (png_uint_32)png_ptr->zbuf_size);
  176018. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  176019. png_flush_ptr_NULL);
  176020. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176021. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  176022. 1, png_doublep_NULL, png_doublep_NULL);
  176023. #endif
  176024. #ifdef PNG_SETJMP_SUPPORTED
  176025. #ifdef USE_FAR_KEYWORD
  176026. if (setjmp(jmpbuf))
  176027. PNG_ABORT();
  176028. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  176029. #else
  176030. if (setjmp(png_ptr->jmpbuf))
  176031. PNG_ABORT();
  176032. #endif
  176033. #endif
  176034. return (png_ptr);
  176035. }
  176036. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  176037. #undef png_write_init
  176038. void PNGAPI
  176039. png_write_init(png_structp png_ptr)
  176040. {
  176041. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  176042. }
  176043. void PNGAPI
  176044. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  176045. png_size_t png_struct_size, png_size_t png_info_size)
  176046. {
  176047. if(png_ptr == NULL) return;
  176048. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176049. if(png_sizeof(png_struct) > png_struct_size ||
  176050. png_sizeof(png_info) > png_info_size)
  176051. {
  176052. char msg[80];
  176053. png_ptr->warning_fn=NULL;
  176054. if (user_png_ver)
  176055. {
  176056. png_snprintf(msg, 80,
  176057. "Application was compiled with png.h from libpng-%.20s",
  176058. user_png_ver);
  176059. png_warning(png_ptr, msg);
  176060. }
  176061. png_snprintf(msg, 80,
  176062. "Application is running with png.c from libpng-%.20s",
  176063. png_libpng_ver);
  176064. png_warning(png_ptr, msg);
  176065. }
  176066. #endif
  176067. if(png_sizeof(png_struct) > png_struct_size)
  176068. {
  176069. png_ptr->error_fn=NULL;
  176070. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176071. png_ptr->flags=0;
  176072. #endif
  176073. png_error(png_ptr,
  176074. "The png struct allocated by the application for writing is too small.");
  176075. }
  176076. if(png_sizeof(png_info) > png_info_size)
  176077. {
  176078. png_ptr->error_fn=NULL;
  176079. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176080. png_ptr->flags=0;
  176081. #endif
  176082. png_error(png_ptr,
  176083. "The info struct allocated by the application for writing is too small.");
  176084. }
  176085. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  176086. }
  176087. #endif /* PNG_1_0_X || PNG_1_2_X */
  176088. void PNGAPI
  176089. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  176090. png_size_t png_struct_size)
  176091. {
  176092. png_structp png_ptr=*ptr_ptr;
  176093. #ifdef PNG_SETJMP_SUPPORTED
  176094. jmp_buf tmp_jmp; /* to save current jump buffer */
  176095. #endif
  176096. int i = 0;
  176097. if (png_ptr == NULL)
  176098. return;
  176099. do
  176100. {
  176101. if (user_png_ver[i] != png_libpng_ver[i])
  176102. {
  176103. #ifdef PNG_LEGACY_SUPPORTED
  176104. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  176105. #else
  176106. png_ptr->warning_fn=NULL;
  176107. png_warning(png_ptr,
  176108. "Application uses deprecated png_write_init() and should be recompiled.");
  176109. break;
  176110. #endif
  176111. }
  176112. } while (png_libpng_ver[i++]);
  176113. png_debug(1, "in png_write_init_3\n");
  176114. #ifdef PNG_SETJMP_SUPPORTED
  176115. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176116. #endif
  176117. if (png_sizeof(png_struct) > png_struct_size)
  176118. {
  176119. png_destroy_struct(png_ptr);
  176120. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  176121. *ptr_ptr = png_ptr;
  176122. }
  176123. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176124. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  176125. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  176126. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  176127. #endif
  176128. #ifdef PNG_SETJMP_SUPPORTED
  176129. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176130. #endif
  176131. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  176132. png_flush_ptr_NULL);
  176133. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  176134. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  176135. (png_uint_32)png_ptr->zbuf_size);
  176136. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176137. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  176138. 1, png_doublep_NULL, png_doublep_NULL);
  176139. #endif
  176140. }
  176141. void PNGAPI
  176142. png_write_rows(png_structp png_ptr, png_bytepp row,
  176143. png_uint_32 num_rows)
  176144. {
  176145. png_uint_32 i; /* row counter */
  176146. png_bytepp rp; /* row pointer */
  176147. png_debug(1, "in png_write_rows\n");
  176148. if (png_ptr == NULL)
  176149. return;
  176150. for (i = 0, rp = row; i < num_rows; i++, rp++)
  176151. {
  176152. png_write_row(png_ptr, *rp);
  176153. }
  176154. }
  176155. void PNGAPI
  176156. png_write_image(png_structp png_ptr, png_bytepp image)
  176157. {
  176158. png_uint_32 i; /* row index */
  176159. int pass, num_pass; /* pass variables */
  176160. png_bytepp rp; /* points to current row */
  176161. if (png_ptr == NULL)
  176162. return;
  176163. png_debug(1, "in png_write_image\n");
  176164. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176165. num_pass = png_set_interlace_handling(png_ptr);
  176166. #else
  176167. num_pass = 1;
  176168. #endif
  176169. for (pass = 0; pass < num_pass; pass++)
  176170. {
  176171. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  176172. {
  176173. png_write_row(png_ptr, *rp);
  176174. }
  176175. }
  176176. }
  176177. void PNGAPI
  176178. png_write_row(png_structp png_ptr, png_bytep row)
  176179. {
  176180. if (png_ptr == NULL)
  176181. return;
  176182. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  176183. png_ptr->row_number, png_ptr->pass);
  176184. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  176185. {
  176186. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  176187. png_error(png_ptr,
  176188. "png_write_info was never called before png_write_row.");
  176189. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  176190. if (png_ptr->transformations & PNG_INVERT_MONO)
  176191. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  176192. #endif
  176193. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  176194. if (png_ptr->transformations & PNG_FILLER)
  176195. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  176196. #endif
  176197. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  176198. if (png_ptr->transformations & PNG_PACKSWAP)
  176199. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  176200. #endif
  176201. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  176202. if (png_ptr->transformations & PNG_PACK)
  176203. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  176204. #endif
  176205. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  176206. if (png_ptr->transformations & PNG_SHIFT)
  176207. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  176208. #endif
  176209. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  176210. if (png_ptr->transformations & PNG_BGR)
  176211. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  176212. #endif
  176213. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  176214. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176215. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  176216. #endif
  176217. png_write_start_row(png_ptr);
  176218. }
  176219. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176220. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  176221. {
  176222. switch (png_ptr->pass)
  176223. {
  176224. case 0:
  176225. if (png_ptr->row_number & 0x07)
  176226. {
  176227. png_write_finish_row(png_ptr);
  176228. return;
  176229. }
  176230. break;
  176231. case 1:
  176232. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  176233. {
  176234. png_write_finish_row(png_ptr);
  176235. return;
  176236. }
  176237. break;
  176238. case 2:
  176239. if ((png_ptr->row_number & 0x07) != 4)
  176240. {
  176241. png_write_finish_row(png_ptr);
  176242. return;
  176243. }
  176244. break;
  176245. case 3:
  176246. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  176247. {
  176248. png_write_finish_row(png_ptr);
  176249. return;
  176250. }
  176251. break;
  176252. case 4:
  176253. if ((png_ptr->row_number & 0x03) != 2)
  176254. {
  176255. png_write_finish_row(png_ptr);
  176256. return;
  176257. }
  176258. break;
  176259. case 5:
  176260. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  176261. {
  176262. png_write_finish_row(png_ptr);
  176263. return;
  176264. }
  176265. break;
  176266. case 6:
  176267. if (!(png_ptr->row_number & 0x01))
  176268. {
  176269. png_write_finish_row(png_ptr);
  176270. return;
  176271. }
  176272. break;
  176273. }
  176274. }
  176275. #endif
  176276. png_ptr->row_info.color_type = png_ptr->color_type;
  176277. png_ptr->row_info.width = png_ptr->usr_width;
  176278. png_ptr->row_info.channels = png_ptr->usr_channels;
  176279. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  176280. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  176281. png_ptr->row_info.channels);
  176282. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  176283. png_ptr->row_info.width);
  176284. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  176285. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  176286. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  176287. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  176288. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  176289. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  176290. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  176291. png_ptr->row_info.rowbytes);
  176292. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176293. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  176294. (png_ptr->transformations & PNG_INTERLACE))
  176295. {
  176296. png_do_write_interlace(&(png_ptr->row_info),
  176297. png_ptr->row_buf + 1, png_ptr->pass);
  176298. if (!(png_ptr->row_info.width))
  176299. {
  176300. png_write_finish_row(png_ptr);
  176301. return;
  176302. }
  176303. }
  176304. #endif
  176305. if (png_ptr->transformations)
  176306. png_do_write_transformations(png_ptr);
  176307. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176308. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176309. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  176310. {
  176311. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176312. }
  176313. #endif
  176314. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  176315. if (png_ptr->write_row_fn != NULL)
  176316. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  176317. }
  176318. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  176319. void PNGAPI
  176320. png_set_flush(png_structp png_ptr, int nrows)
  176321. {
  176322. png_debug(1, "in png_set_flush\n");
  176323. if (png_ptr == NULL)
  176324. return;
  176325. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  176326. }
  176327. void PNGAPI
  176328. png_write_flush(png_structp png_ptr)
  176329. {
  176330. int wrote_IDAT;
  176331. png_debug(1, "in png_write_flush\n");
  176332. if (png_ptr == NULL)
  176333. return;
  176334. if (png_ptr->row_number >= png_ptr->num_rows)
  176335. return;
  176336. do
  176337. {
  176338. int ret;
  176339. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  176340. wrote_IDAT = 0;
  176341. if (ret != Z_OK)
  176342. {
  176343. if (png_ptr->zstream.msg != NULL)
  176344. png_error(png_ptr, png_ptr->zstream.msg);
  176345. else
  176346. png_error(png_ptr, "zlib error");
  176347. }
  176348. if (!(png_ptr->zstream.avail_out))
  176349. {
  176350. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176351. png_ptr->zbuf_size);
  176352. png_ptr->zstream.next_out = png_ptr->zbuf;
  176353. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176354. wrote_IDAT = 1;
  176355. }
  176356. } while(wrote_IDAT == 1);
  176357. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  176358. {
  176359. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176360. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  176361. png_ptr->zstream.next_out = png_ptr->zbuf;
  176362. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176363. }
  176364. png_ptr->flush_rows = 0;
  176365. png_flush(png_ptr);
  176366. }
  176367. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  176368. void PNGAPI
  176369. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  176370. {
  176371. png_structp png_ptr = NULL;
  176372. png_infop info_ptr = NULL;
  176373. #ifdef PNG_USER_MEM_SUPPORTED
  176374. png_free_ptr free_fn = NULL;
  176375. png_voidp mem_ptr = NULL;
  176376. #endif
  176377. png_debug(1, "in png_destroy_write_struct\n");
  176378. if (png_ptr_ptr != NULL)
  176379. {
  176380. png_ptr = *png_ptr_ptr;
  176381. #ifdef PNG_USER_MEM_SUPPORTED
  176382. free_fn = png_ptr->free_fn;
  176383. mem_ptr = png_ptr->mem_ptr;
  176384. #endif
  176385. }
  176386. if (info_ptr_ptr != NULL)
  176387. info_ptr = *info_ptr_ptr;
  176388. if (info_ptr != NULL)
  176389. {
  176390. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  176391. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  176392. if (png_ptr->num_chunk_list)
  176393. {
  176394. png_free(png_ptr, png_ptr->chunk_list);
  176395. png_ptr->chunk_list=NULL;
  176396. png_ptr->num_chunk_list=0;
  176397. }
  176398. #endif
  176399. #ifdef PNG_USER_MEM_SUPPORTED
  176400. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  176401. (png_voidp)mem_ptr);
  176402. #else
  176403. png_destroy_struct((png_voidp)info_ptr);
  176404. #endif
  176405. *info_ptr_ptr = NULL;
  176406. }
  176407. if (png_ptr != NULL)
  176408. {
  176409. png_write_destroy(png_ptr);
  176410. #ifdef PNG_USER_MEM_SUPPORTED
  176411. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  176412. (png_voidp)mem_ptr);
  176413. #else
  176414. png_destroy_struct((png_voidp)png_ptr);
  176415. #endif
  176416. *png_ptr_ptr = NULL;
  176417. }
  176418. }
  176419. void /* PRIVATE */
  176420. png_write_destroy(png_structp png_ptr)
  176421. {
  176422. #ifdef PNG_SETJMP_SUPPORTED
  176423. jmp_buf tmp_jmp; /* save jump buffer */
  176424. #endif
  176425. png_error_ptr error_fn;
  176426. png_error_ptr warning_fn;
  176427. png_voidp error_ptr;
  176428. #ifdef PNG_USER_MEM_SUPPORTED
  176429. png_free_ptr free_fn;
  176430. #endif
  176431. png_debug(1, "in png_write_destroy\n");
  176432. deflateEnd(&png_ptr->zstream);
  176433. png_free(png_ptr, png_ptr->zbuf);
  176434. png_free(png_ptr, png_ptr->row_buf);
  176435. png_free(png_ptr, png_ptr->prev_row);
  176436. png_free(png_ptr, png_ptr->sub_row);
  176437. png_free(png_ptr, png_ptr->up_row);
  176438. png_free(png_ptr, png_ptr->avg_row);
  176439. png_free(png_ptr, png_ptr->paeth_row);
  176440. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  176441. png_free(png_ptr, png_ptr->time_buffer);
  176442. #endif
  176443. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176444. png_free(png_ptr, png_ptr->prev_filters);
  176445. png_free(png_ptr, png_ptr->filter_weights);
  176446. png_free(png_ptr, png_ptr->inv_filter_weights);
  176447. png_free(png_ptr, png_ptr->filter_costs);
  176448. png_free(png_ptr, png_ptr->inv_filter_costs);
  176449. #endif
  176450. #ifdef PNG_SETJMP_SUPPORTED
  176451. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176452. #endif
  176453. error_fn = png_ptr->error_fn;
  176454. warning_fn = png_ptr->warning_fn;
  176455. error_ptr = png_ptr->error_ptr;
  176456. #ifdef PNG_USER_MEM_SUPPORTED
  176457. free_fn = png_ptr->free_fn;
  176458. #endif
  176459. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176460. png_ptr->error_fn = error_fn;
  176461. png_ptr->warning_fn = warning_fn;
  176462. png_ptr->error_ptr = error_ptr;
  176463. #ifdef PNG_USER_MEM_SUPPORTED
  176464. png_ptr->free_fn = free_fn;
  176465. #endif
  176466. #ifdef PNG_SETJMP_SUPPORTED
  176467. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176468. #endif
  176469. }
  176470. void PNGAPI
  176471. png_set_filter(png_structp png_ptr, int method, int filters)
  176472. {
  176473. png_debug(1, "in png_set_filter\n");
  176474. if (png_ptr == NULL)
  176475. return;
  176476. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176477. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176478. (method == PNG_INTRAPIXEL_DIFFERENCING))
  176479. method = PNG_FILTER_TYPE_BASE;
  176480. #endif
  176481. if (method == PNG_FILTER_TYPE_BASE)
  176482. {
  176483. switch (filters & (PNG_ALL_FILTERS | 0x07))
  176484. {
  176485. #ifndef PNG_NO_WRITE_FILTER
  176486. case 5:
  176487. case 6:
  176488. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  176489. #endif /* PNG_NO_WRITE_FILTER */
  176490. case PNG_FILTER_VALUE_NONE:
  176491. png_ptr->do_filter=PNG_FILTER_NONE; break;
  176492. #ifndef PNG_NO_WRITE_FILTER
  176493. case PNG_FILTER_VALUE_SUB:
  176494. png_ptr->do_filter=PNG_FILTER_SUB; break;
  176495. case PNG_FILTER_VALUE_UP:
  176496. png_ptr->do_filter=PNG_FILTER_UP; break;
  176497. case PNG_FILTER_VALUE_AVG:
  176498. png_ptr->do_filter=PNG_FILTER_AVG; break;
  176499. case PNG_FILTER_VALUE_PAETH:
  176500. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  176501. default: png_ptr->do_filter = (png_byte)filters; break;
  176502. #else
  176503. default: png_warning(png_ptr, "Unknown row filter for method 0");
  176504. #endif /* PNG_NO_WRITE_FILTER */
  176505. }
  176506. if (png_ptr->row_buf != NULL)
  176507. {
  176508. #ifndef PNG_NO_WRITE_FILTER
  176509. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  176510. {
  176511. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  176512. (png_ptr->rowbytes + 1));
  176513. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176514. }
  176515. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176516. {
  176517. if (png_ptr->prev_row == NULL)
  176518. {
  176519. png_warning(png_ptr, "Can't add Up filter after starting");
  176520. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176521. }
  176522. else
  176523. {
  176524. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176525. (png_ptr->rowbytes + 1));
  176526. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176527. }
  176528. }
  176529. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176530. {
  176531. if (png_ptr->prev_row == NULL)
  176532. {
  176533. png_warning(png_ptr, "Can't add Average filter after starting");
  176534. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176535. }
  176536. else
  176537. {
  176538. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176539. (png_ptr->rowbytes + 1));
  176540. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176541. }
  176542. }
  176543. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176544. png_ptr->paeth_row == NULL)
  176545. {
  176546. if (png_ptr->prev_row == NULL)
  176547. {
  176548. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176549. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176550. }
  176551. else
  176552. {
  176553. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176554. (png_ptr->rowbytes + 1));
  176555. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176556. }
  176557. }
  176558. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176559. #endif /* PNG_NO_WRITE_FILTER */
  176560. png_ptr->do_filter = PNG_FILTER_NONE;
  176561. }
  176562. }
  176563. else
  176564. png_error(png_ptr, "Unknown custom filter method");
  176565. }
  176566. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176567. void PNGAPI
  176568. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176569. int num_weights, png_doublep filter_weights,
  176570. png_doublep filter_costs)
  176571. {
  176572. int i;
  176573. png_debug(1, "in png_set_filter_heuristics\n");
  176574. if (png_ptr == NULL)
  176575. return;
  176576. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176577. {
  176578. png_warning(png_ptr, "Unknown filter heuristic method");
  176579. return;
  176580. }
  176581. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176582. {
  176583. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176584. }
  176585. if (num_weights < 0 || filter_weights == NULL ||
  176586. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176587. {
  176588. num_weights = 0;
  176589. }
  176590. png_ptr->num_prev_filters = (png_byte)num_weights;
  176591. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176592. if (num_weights > 0)
  176593. {
  176594. if (png_ptr->prev_filters == NULL)
  176595. {
  176596. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176597. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176598. for (i = 0; i < num_weights; i++)
  176599. {
  176600. png_ptr->prev_filters[i] = 255;
  176601. }
  176602. }
  176603. if (png_ptr->filter_weights == NULL)
  176604. {
  176605. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176606. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176607. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176608. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176609. for (i = 0; i < num_weights; i++)
  176610. {
  176611. png_ptr->inv_filter_weights[i] =
  176612. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176613. }
  176614. }
  176615. for (i = 0; i < num_weights; i++)
  176616. {
  176617. if (filter_weights[i] < 0.0)
  176618. {
  176619. png_ptr->inv_filter_weights[i] =
  176620. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176621. }
  176622. else
  176623. {
  176624. png_ptr->inv_filter_weights[i] =
  176625. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176626. png_ptr->filter_weights[i] =
  176627. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176628. }
  176629. }
  176630. }
  176631. if (png_ptr->filter_costs == NULL)
  176632. {
  176633. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176634. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176635. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176636. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176637. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176638. {
  176639. png_ptr->inv_filter_costs[i] =
  176640. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176641. }
  176642. }
  176643. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176644. {
  176645. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176646. {
  176647. png_ptr->inv_filter_costs[i] =
  176648. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176649. }
  176650. else if (filter_costs[i] >= 1.0)
  176651. {
  176652. png_ptr->inv_filter_costs[i] =
  176653. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176654. png_ptr->filter_costs[i] =
  176655. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176656. }
  176657. }
  176658. }
  176659. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176660. void PNGAPI
  176661. png_set_compression_level(png_structp png_ptr, int level)
  176662. {
  176663. png_debug(1, "in png_set_compression_level\n");
  176664. if (png_ptr == NULL)
  176665. return;
  176666. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176667. png_ptr->zlib_level = level;
  176668. }
  176669. void PNGAPI
  176670. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176671. {
  176672. png_debug(1, "in png_set_compression_mem_level\n");
  176673. if (png_ptr == NULL)
  176674. return;
  176675. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176676. png_ptr->zlib_mem_level = mem_level;
  176677. }
  176678. void PNGAPI
  176679. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176680. {
  176681. png_debug(1, "in png_set_compression_strategy\n");
  176682. if (png_ptr == NULL)
  176683. return;
  176684. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176685. png_ptr->zlib_strategy = strategy;
  176686. }
  176687. void PNGAPI
  176688. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176689. {
  176690. if (png_ptr == NULL)
  176691. return;
  176692. if (window_bits > 15)
  176693. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176694. else if (window_bits < 8)
  176695. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176696. #ifndef WBITS_8_OK
  176697. if (window_bits == 8)
  176698. {
  176699. png_warning(png_ptr, "Compression window is being reset to 512");
  176700. window_bits=9;
  176701. }
  176702. #endif
  176703. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176704. png_ptr->zlib_window_bits = window_bits;
  176705. }
  176706. void PNGAPI
  176707. png_set_compression_method(png_structp png_ptr, int method)
  176708. {
  176709. png_debug(1, "in png_set_compression_method\n");
  176710. if (png_ptr == NULL)
  176711. return;
  176712. if (method != 8)
  176713. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176714. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176715. png_ptr->zlib_method = method;
  176716. }
  176717. void PNGAPI
  176718. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176719. {
  176720. if (png_ptr == NULL)
  176721. return;
  176722. png_ptr->write_row_fn = write_row_fn;
  176723. }
  176724. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176725. void PNGAPI
  176726. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176727. write_user_transform_fn)
  176728. {
  176729. png_debug(1, "in png_set_write_user_transform_fn\n");
  176730. if (png_ptr == NULL)
  176731. return;
  176732. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176733. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176734. }
  176735. #endif
  176736. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176737. void PNGAPI
  176738. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176739. int transforms, voidp params)
  176740. {
  176741. if (png_ptr == NULL || info_ptr == NULL)
  176742. return;
  176743. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176744. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176745. png_set_invert_alpha(png_ptr);
  176746. #endif
  176747. png_write_info(png_ptr, info_ptr);
  176748. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176749. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176750. png_set_invert_mono(png_ptr);
  176751. #endif
  176752. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176753. if ((transforms & PNG_TRANSFORM_SHIFT)
  176754. && (info_ptr->valid & PNG_INFO_sBIT))
  176755. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176756. #endif
  176757. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176758. if (transforms & PNG_TRANSFORM_PACKING)
  176759. png_set_packing(png_ptr);
  176760. #endif
  176761. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176762. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176763. png_set_swap_alpha(png_ptr);
  176764. #endif
  176765. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176766. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176767. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176768. #endif
  176769. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176770. if (transforms & PNG_TRANSFORM_BGR)
  176771. png_set_bgr(png_ptr);
  176772. #endif
  176773. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176774. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176775. png_set_swap(png_ptr);
  176776. #endif
  176777. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176778. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176779. png_set_packswap(png_ptr);
  176780. #endif
  176781. if (info_ptr->valid & PNG_INFO_IDAT)
  176782. png_write_image(png_ptr, info_ptr->row_pointers);
  176783. png_write_end(png_ptr, info_ptr);
  176784. transforms = transforms; /* quiet compiler warnings */
  176785. params = params;
  176786. }
  176787. #endif
  176788. #endif /* PNG_WRITE_SUPPORTED */
  176789. /*** End of inlined file: pngwrite.c ***/
  176790. /*** Start of inlined file: pngwtran.c ***/
  176791. #define PNG_INTERNAL
  176792. #ifdef PNG_WRITE_SUPPORTED
  176793. void /* PRIVATE */
  176794. png_do_write_transformations(png_structp png_ptr)
  176795. {
  176796. png_debug(1, "in png_do_write_transformations\n");
  176797. if (png_ptr == NULL)
  176798. return;
  176799. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176800. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176801. if(png_ptr->write_user_transform_fn != NULL)
  176802. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176803. (png_ptr, /* png_ptr */
  176804. &(png_ptr->row_info), /* row_info: */
  176805. png_ptr->row_buf + 1); /* start of pixel data for row */
  176806. #endif
  176807. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176808. if (png_ptr->transformations & PNG_FILLER)
  176809. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176810. png_ptr->flags);
  176811. #endif
  176812. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176813. if (png_ptr->transformations & PNG_PACKSWAP)
  176814. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176815. #endif
  176816. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176817. if (png_ptr->transformations & PNG_PACK)
  176818. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176819. (png_uint_32)png_ptr->bit_depth);
  176820. #endif
  176821. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176822. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176823. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176824. #endif
  176825. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176826. if (png_ptr->transformations & PNG_SHIFT)
  176827. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176828. &(png_ptr->shift));
  176829. #endif
  176830. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176831. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176832. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176833. #endif
  176834. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176835. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176836. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176837. #endif
  176838. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176839. if (png_ptr->transformations & PNG_BGR)
  176840. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176841. #endif
  176842. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176843. if (png_ptr->transformations & PNG_INVERT_MONO)
  176844. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176845. #endif
  176846. }
  176847. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176848. void /* PRIVATE */
  176849. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176850. {
  176851. png_debug(1, "in png_do_pack\n");
  176852. if (row_info->bit_depth == 8 &&
  176853. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176854. row != NULL && row_info != NULL &&
  176855. #endif
  176856. row_info->channels == 1)
  176857. {
  176858. switch ((int)bit_depth)
  176859. {
  176860. case 1:
  176861. {
  176862. png_bytep sp, dp;
  176863. int mask, v;
  176864. png_uint_32 i;
  176865. png_uint_32 row_width = row_info->width;
  176866. sp = row;
  176867. dp = row;
  176868. mask = 0x80;
  176869. v = 0;
  176870. for (i = 0; i < row_width; i++)
  176871. {
  176872. if (*sp != 0)
  176873. v |= mask;
  176874. sp++;
  176875. if (mask > 1)
  176876. mask >>= 1;
  176877. else
  176878. {
  176879. mask = 0x80;
  176880. *dp = (png_byte)v;
  176881. dp++;
  176882. v = 0;
  176883. }
  176884. }
  176885. if (mask != 0x80)
  176886. *dp = (png_byte)v;
  176887. break;
  176888. }
  176889. case 2:
  176890. {
  176891. png_bytep sp, dp;
  176892. int shift, v;
  176893. png_uint_32 i;
  176894. png_uint_32 row_width = row_info->width;
  176895. sp = row;
  176896. dp = row;
  176897. shift = 6;
  176898. v = 0;
  176899. for (i = 0; i < row_width; i++)
  176900. {
  176901. png_byte value;
  176902. value = (png_byte)(*sp & 0x03);
  176903. v |= (value << shift);
  176904. if (shift == 0)
  176905. {
  176906. shift = 6;
  176907. *dp = (png_byte)v;
  176908. dp++;
  176909. v = 0;
  176910. }
  176911. else
  176912. shift -= 2;
  176913. sp++;
  176914. }
  176915. if (shift != 6)
  176916. *dp = (png_byte)v;
  176917. break;
  176918. }
  176919. case 4:
  176920. {
  176921. png_bytep sp, dp;
  176922. int shift, v;
  176923. png_uint_32 i;
  176924. png_uint_32 row_width = row_info->width;
  176925. sp = row;
  176926. dp = row;
  176927. shift = 4;
  176928. v = 0;
  176929. for (i = 0; i < row_width; i++)
  176930. {
  176931. png_byte value;
  176932. value = (png_byte)(*sp & 0x0f);
  176933. v |= (value << shift);
  176934. if (shift == 0)
  176935. {
  176936. shift = 4;
  176937. *dp = (png_byte)v;
  176938. dp++;
  176939. v = 0;
  176940. }
  176941. else
  176942. shift -= 4;
  176943. sp++;
  176944. }
  176945. if (shift != 4)
  176946. *dp = (png_byte)v;
  176947. break;
  176948. }
  176949. }
  176950. row_info->bit_depth = (png_byte)bit_depth;
  176951. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176952. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176953. row_info->width);
  176954. }
  176955. }
  176956. #endif
  176957. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176958. void /* PRIVATE */
  176959. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176960. {
  176961. png_debug(1, "in png_do_shift\n");
  176962. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176963. if (row != NULL && row_info != NULL &&
  176964. #else
  176965. if (
  176966. #endif
  176967. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176968. {
  176969. int shift_start[4], shift_dec[4];
  176970. int channels = 0;
  176971. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176972. {
  176973. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176974. shift_dec[channels] = bit_depth->red;
  176975. channels++;
  176976. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176977. shift_dec[channels] = bit_depth->green;
  176978. channels++;
  176979. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176980. shift_dec[channels] = bit_depth->blue;
  176981. channels++;
  176982. }
  176983. else
  176984. {
  176985. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176986. shift_dec[channels] = bit_depth->gray;
  176987. channels++;
  176988. }
  176989. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176990. {
  176991. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176992. shift_dec[channels] = bit_depth->alpha;
  176993. channels++;
  176994. }
  176995. if (row_info->bit_depth < 8)
  176996. {
  176997. png_bytep bp = row;
  176998. png_uint_32 i;
  176999. png_byte mask;
  177000. png_uint_32 row_bytes = row_info->rowbytes;
  177001. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  177002. mask = 0x55;
  177003. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  177004. mask = 0x11;
  177005. else
  177006. mask = 0xff;
  177007. for (i = 0; i < row_bytes; i++, bp++)
  177008. {
  177009. png_uint_16 v;
  177010. int j;
  177011. v = *bp;
  177012. *bp = 0;
  177013. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  177014. {
  177015. if (j > 0)
  177016. *bp |= (png_byte)((v << j) & 0xff);
  177017. else
  177018. *bp |= (png_byte)((v >> (-j)) & mask);
  177019. }
  177020. }
  177021. }
  177022. else if (row_info->bit_depth == 8)
  177023. {
  177024. png_bytep bp = row;
  177025. png_uint_32 i;
  177026. png_uint_32 istop = channels * row_info->width;
  177027. for (i = 0; i < istop; i++, bp++)
  177028. {
  177029. png_uint_16 v;
  177030. int j;
  177031. int c = (int)(i%channels);
  177032. v = *bp;
  177033. *bp = 0;
  177034. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  177035. {
  177036. if (j > 0)
  177037. *bp |= (png_byte)((v << j) & 0xff);
  177038. else
  177039. *bp |= (png_byte)((v >> (-j)) & 0xff);
  177040. }
  177041. }
  177042. }
  177043. else
  177044. {
  177045. png_bytep bp;
  177046. png_uint_32 i;
  177047. png_uint_32 istop = channels * row_info->width;
  177048. for (bp = row, i = 0; i < istop; i++)
  177049. {
  177050. int c = (int)(i%channels);
  177051. png_uint_16 value, v;
  177052. int j;
  177053. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  177054. value = 0;
  177055. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  177056. {
  177057. if (j > 0)
  177058. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  177059. else
  177060. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  177061. }
  177062. *bp++ = (png_byte)(value >> 8);
  177063. *bp++ = (png_byte)(value & 0xff);
  177064. }
  177065. }
  177066. }
  177067. }
  177068. #endif
  177069. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  177070. void /* PRIVATE */
  177071. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  177072. {
  177073. png_debug(1, "in png_do_write_swap_alpha\n");
  177074. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177075. if (row != NULL && row_info != NULL)
  177076. #endif
  177077. {
  177078. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177079. {
  177080. if (row_info->bit_depth == 8)
  177081. {
  177082. png_bytep sp, dp;
  177083. png_uint_32 i;
  177084. png_uint_32 row_width = row_info->width;
  177085. for (i = 0, sp = dp = row; i < row_width; i++)
  177086. {
  177087. png_byte save = *(sp++);
  177088. *(dp++) = *(sp++);
  177089. *(dp++) = *(sp++);
  177090. *(dp++) = *(sp++);
  177091. *(dp++) = save;
  177092. }
  177093. }
  177094. else
  177095. {
  177096. png_bytep sp, dp;
  177097. png_uint_32 i;
  177098. png_uint_32 row_width = row_info->width;
  177099. for (i = 0, sp = dp = row; i < row_width; i++)
  177100. {
  177101. png_byte save[2];
  177102. save[0] = *(sp++);
  177103. save[1] = *(sp++);
  177104. *(dp++) = *(sp++);
  177105. *(dp++) = *(sp++);
  177106. *(dp++) = *(sp++);
  177107. *(dp++) = *(sp++);
  177108. *(dp++) = *(sp++);
  177109. *(dp++) = *(sp++);
  177110. *(dp++) = save[0];
  177111. *(dp++) = save[1];
  177112. }
  177113. }
  177114. }
  177115. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  177116. {
  177117. if (row_info->bit_depth == 8)
  177118. {
  177119. png_bytep sp, dp;
  177120. png_uint_32 i;
  177121. png_uint_32 row_width = row_info->width;
  177122. for (i = 0, sp = dp = row; i < row_width; i++)
  177123. {
  177124. png_byte save = *(sp++);
  177125. *(dp++) = *(sp++);
  177126. *(dp++) = save;
  177127. }
  177128. }
  177129. else
  177130. {
  177131. png_bytep sp, dp;
  177132. png_uint_32 i;
  177133. png_uint_32 row_width = row_info->width;
  177134. for (i = 0, sp = dp = row; i < row_width; i++)
  177135. {
  177136. png_byte save[2];
  177137. save[0] = *(sp++);
  177138. save[1] = *(sp++);
  177139. *(dp++) = *(sp++);
  177140. *(dp++) = *(sp++);
  177141. *(dp++) = save[0];
  177142. *(dp++) = save[1];
  177143. }
  177144. }
  177145. }
  177146. }
  177147. }
  177148. #endif
  177149. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  177150. void /* PRIVATE */
  177151. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  177152. {
  177153. png_debug(1, "in png_do_write_invert_alpha\n");
  177154. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177155. if (row != NULL && row_info != NULL)
  177156. #endif
  177157. {
  177158. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177159. {
  177160. if (row_info->bit_depth == 8)
  177161. {
  177162. png_bytep sp, dp;
  177163. png_uint_32 i;
  177164. png_uint_32 row_width = row_info->width;
  177165. for (i = 0, sp = dp = row; i < row_width; i++)
  177166. {
  177167. sp+=3; dp = sp;
  177168. *(dp++) = (png_byte)(255 - *(sp++));
  177169. }
  177170. }
  177171. else
  177172. {
  177173. png_bytep sp, dp;
  177174. png_uint_32 i;
  177175. png_uint_32 row_width = row_info->width;
  177176. for (i = 0, sp = dp = row; i < row_width; i++)
  177177. {
  177178. sp+=6; dp = sp;
  177179. *(dp++) = (png_byte)(255 - *(sp++));
  177180. *(dp++) = (png_byte)(255 - *(sp++));
  177181. }
  177182. }
  177183. }
  177184. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  177185. {
  177186. if (row_info->bit_depth == 8)
  177187. {
  177188. png_bytep sp, dp;
  177189. png_uint_32 i;
  177190. png_uint_32 row_width = row_info->width;
  177191. for (i = 0, sp = dp = row; i < row_width; i++)
  177192. {
  177193. *(dp++) = *(sp++);
  177194. *(dp++) = (png_byte)(255 - *(sp++));
  177195. }
  177196. }
  177197. else
  177198. {
  177199. png_bytep sp, dp;
  177200. png_uint_32 i;
  177201. png_uint_32 row_width = row_info->width;
  177202. for (i = 0, sp = dp = row; i < row_width; i++)
  177203. {
  177204. sp+=2; dp = sp;
  177205. *(dp++) = (png_byte)(255 - *(sp++));
  177206. *(dp++) = (png_byte)(255 - *(sp++));
  177207. }
  177208. }
  177209. }
  177210. }
  177211. }
  177212. #endif
  177213. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177214. void /* PRIVATE */
  177215. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  177216. {
  177217. png_debug(1, "in png_do_write_intrapixel\n");
  177218. if (
  177219. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177220. row != NULL && row_info != NULL &&
  177221. #endif
  177222. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  177223. {
  177224. int bytes_per_pixel;
  177225. png_uint_32 row_width = row_info->width;
  177226. if (row_info->bit_depth == 8)
  177227. {
  177228. png_bytep rp;
  177229. png_uint_32 i;
  177230. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177231. bytes_per_pixel = 3;
  177232. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177233. bytes_per_pixel = 4;
  177234. else
  177235. return;
  177236. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177237. {
  177238. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  177239. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  177240. }
  177241. }
  177242. else if (row_info->bit_depth == 16)
  177243. {
  177244. png_bytep rp;
  177245. png_uint_32 i;
  177246. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177247. bytes_per_pixel = 6;
  177248. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177249. bytes_per_pixel = 8;
  177250. else
  177251. return;
  177252. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177253. {
  177254. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  177255. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  177256. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  177257. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  177258. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  177259. *(rp ) = (png_byte)((red >> 8) & 0xff);
  177260. *(rp+1) = (png_byte)(red & 0xff);
  177261. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  177262. *(rp+5) = (png_byte)(blue & 0xff);
  177263. }
  177264. }
  177265. }
  177266. }
  177267. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  177268. #endif /* PNG_WRITE_SUPPORTED */
  177269. /*** End of inlined file: pngwtran.c ***/
  177270. /*** Start of inlined file: pngwutil.c ***/
  177271. #define PNG_INTERNAL
  177272. #ifdef PNG_WRITE_SUPPORTED
  177273. void PNGAPI
  177274. png_save_uint_32(png_bytep buf, png_uint_32 i)
  177275. {
  177276. buf[0] = (png_byte)((i >> 24) & 0xff);
  177277. buf[1] = (png_byte)((i >> 16) & 0xff);
  177278. buf[2] = (png_byte)((i >> 8) & 0xff);
  177279. buf[3] = (png_byte)(i & 0xff);
  177280. }
  177281. void PNGAPI
  177282. png_save_int_32(png_bytep buf, png_int_32 i)
  177283. {
  177284. buf[0] = (png_byte)((i >> 24) & 0xff);
  177285. buf[1] = (png_byte)((i >> 16) & 0xff);
  177286. buf[2] = (png_byte)((i >> 8) & 0xff);
  177287. buf[3] = (png_byte)(i & 0xff);
  177288. }
  177289. void PNGAPI
  177290. png_save_uint_16(png_bytep buf, unsigned int i)
  177291. {
  177292. buf[0] = (png_byte)((i >> 8) & 0xff);
  177293. buf[1] = (png_byte)(i & 0xff);
  177294. }
  177295. void PNGAPI
  177296. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  177297. png_bytep data, png_size_t length)
  177298. {
  177299. if(png_ptr == NULL) return;
  177300. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  177301. png_write_chunk_data(png_ptr, data, length);
  177302. png_write_chunk_end(png_ptr);
  177303. }
  177304. void PNGAPI
  177305. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  177306. png_uint_32 length)
  177307. {
  177308. png_byte buf[4];
  177309. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  177310. if(png_ptr == NULL) return;
  177311. png_save_uint_32(buf, length);
  177312. png_write_data(png_ptr, buf, (png_size_t)4);
  177313. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  177314. png_reset_crc(png_ptr);
  177315. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  177316. }
  177317. void PNGAPI
  177318. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  177319. {
  177320. if(png_ptr == NULL) return;
  177321. if (data != NULL && length > 0)
  177322. {
  177323. png_calculate_crc(png_ptr, data, length);
  177324. png_write_data(png_ptr, data, length);
  177325. }
  177326. }
  177327. void PNGAPI
  177328. png_write_chunk_end(png_structp png_ptr)
  177329. {
  177330. png_byte buf[4];
  177331. if(png_ptr == NULL) return;
  177332. png_save_uint_32(buf, png_ptr->crc);
  177333. png_write_data(png_ptr, buf, (png_size_t)4);
  177334. }
  177335. void /* PRIVATE */
  177336. png_write_sig(png_structp png_ptr)
  177337. {
  177338. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  177339. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  177340. (png_size_t)8 - png_ptr->sig_bytes);
  177341. if(png_ptr->sig_bytes < 3)
  177342. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  177343. }
  177344. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  177345. typedef struct
  177346. {
  177347. char *input; /* the uncompressed input data */
  177348. int input_len; /* its length */
  177349. int num_output_ptr; /* number of output pointers used */
  177350. int max_output_ptr; /* size of output_ptr */
  177351. png_charpp output_ptr; /* array of pointers to output */
  177352. } compression_state;
  177353. static int /* PRIVATE */
  177354. png_text_compress(png_structp png_ptr,
  177355. png_charp text, png_size_t text_len, int compression,
  177356. compression_state *comp)
  177357. {
  177358. int ret;
  177359. comp->num_output_ptr = 0;
  177360. comp->max_output_ptr = 0;
  177361. comp->output_ptr = NULL;
  177362. comp->input = NULL;
  177363. comp->input_len = 0;
  177364. if (compression == PNG_TEXT_COMPRESSION_NONE)
  177365. {
  177366. comp->input = text;
  177367. comp->input_len = text_len;
  177368. return((int)text_len);
  177369. }
  177370. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  177371. {
  177372. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177373. char msg[50];
  177374. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  177375. png_warning(png_ptr, msg);
  177376. #else
  177377. png_warning(png_ptr, "Unknown compression type");
  177378. #endif
  177379. }
  177380. png_ptr->zstream.avail_in = (uInt)text_len;
  177381. png_ptr->zstream.next_in = (Bytef *)text;
  177382. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177383. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  177384. do
  177385. {
  177386. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  177387. if (ret != Z_OK)
  177388. {
  177389. if (png_ptr->zstream.msg != NULL)
  177390. png_error(png_ptr, png_ptr->zstream.msg);
  177391. else
  177392. png_error(png_ptr, "zlib error");
  177393. }
  177394. if (!(png_ptr->zstream.avail_out))
  177395. {
  177396. if (comp->num_output_ptr >= comp->max_output_ptr)
  177397. {
  177398. int old_max;
  177399. old_max = comp->max_output_ptr;
  177400. comp->max_output_ptr = comp->num_output_ptr + 4;
  177401. if (comp->output_ptr != NULL)
  177402. {
  177403. png_charpp old_ptr;
  177404. old_ptr = comp->output_ptr;
  177405. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177406. (png_uint_32)(comp->max_output_ptr *
  177407. png_sizeof (png_charpp)));
  177408. png_memcpy(comp->output_ptr, old_ptr, old_max
  177409. * png_sizeof (png_charp));
  177410. png_free(png_ptr, old_ptr);
  177411. }
  177412. else
  177413. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177414. (png_uint_32)(comp->max_output_ptr *
  177415. png_sizeof (png_charp)));
  177416. }
  177417. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  177418. (png_uint_32)png_ptr->zbuf_size);
  177419. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177420. png_ptr->zbuf_size);
  177421. comp->num_output_ptr++;
  177422. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177423. png_ptr->zstream.next_out = png_ptr->zbuf;
  177424. }
  177425. } while (png_ptr->zstream.avail_in);
  177426. do
  177427. {
  177428. ret = deflate(&png_ptr->zstream, Z_FINISH);
  177429. if (ret == Z_OK)
  177430. {
  177431. if (!(png_ptr->zstream.avail_out))
  177432. {
  177433. if (comp->num_output_ptr >= comp->max_output_ptr)
  177434. {
  177435. int old_max;
  177436. old_max = comp->max_output_ptr;
  177437. comp->max_output_ptr = comp->num_output_ptr + 4;
  177438. if (comp->output_ptr != NULL)
  177439. {
  177440. png_charpp old_ptr;
  177441. old_ptr = comp->output_ptr;
  177442. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177443. (png_uint_32)(comp->max_output_ptr *
  177444. png_sizeof (png_charpp)));
  177445. png_memcpy(comp->output_ptr, old_ptr,
  177446. old_max * png_sizeof (png_charp));
  177447. png_free(png_ptr, old_ptr);
  177448. }
  177449. else
  177450. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177451. (png_uint_32)(comp->max_output_ptr *
  177452. png_sizeof (png_charp)));
  177453. }
  177454. comp->output_ptr[comp->num_output_ptr] =
  177455. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  177456. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177457. png_ptr->zbuf_size);
  177458. comp->num_output_ptr++;
  177459. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177460. png_ptr->zstream.next_out = png_ptr->zbuf;
  177461. }
  177462. }
  177463. else if (ret != Z_STREAM_END)
  177464. {
  177465. if (png_ptr->zstream.msg != NULL)
  177466. png_error(png_ptr, png_ptr->zstream.msg);
  177467. else
  177468. png_error(png_ptr, "zlib error");
  177469. }
  177470. } while (ret != Z_STREAM_END);
  177471. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  177472. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  177473. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  177474. return((int)text_len);
  177475. }
  177476. static void /* PRIVATE */
  177477. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  177478. {
  177479. int i;
  177480. if (comp->input)
  177481. {
  177482. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  177483. (png_size_t)comp->input_len);
  177484. return;
  177485. }
  177486. for (i = 0; i < comp->num_output_ptr; i++)
  177487. {
  177488. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  177489. png_ptr->zbuf_size);
  177490. png_free(png_ptr, comp->output_ptr[i]);
  177491. comp->output_ptr[i]=NULL;
  177492. }
  177493. if (comp->max_output_ptr != 0)
  177494. png_free(png_ptr, comp->output_ptr);
  177495. comp->output_ptr=NULL;
  177496. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  177497. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  177498. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  177499. deflateReset(&png_ptr->zstream);
  177500. png_ptr->zstream.data_type = Z_BINARY;
  177501. }
  177502. #endif
  177503. void /* PRIVATE */
  177504. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  177505. int bit_depth, int color_type, int compression_type, int filter_type,
  177506. int interlace_type)
  177507. {
  177508. #ifdef PNG_USE_LOCAL_ARRAYS
  177509. PNG_IHDR;
  177510. #endif
  177511. png_byte buf[13]; /* buffer to store the IHDR info */
  177512. png_debug(1, "in png_write_IHDR\n");
  177513. switch (color_type)
  177514. {
  177515. case PNG_COLOR_TYPE_GRAY:
  177516. switch (bit_depth)
  177517. {
  177518. case 1:
  177519. case 2:
  177520. case 4:
  177521. case 8:
  177522. case 16: png_ptr->channels = 1; break;
  177523. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177524. }
  177525. break;
  177526. case PNG_COLOR_TYPE_RGB:
  177527. if (bit_depth != 8 && bit_depth != 16)
  177528. png_error(png_ptr, "Invalid bit depth for RGB image");
  177529. png_ptr->channels = 3;
  177530. break;
  177531. case PNG_COLOR_TYPE_PALETTE:
  177532. switch (bit_depth)
  177533. {
  177534. case 1:
  177535. case 2:
  177536. case 4:
  177537. case 8: png_ptr->channels = 1; break;
  177538. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177539. }
  177540. break;
  177541. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177542. if (bit_depth != 8 && bit_depth != 16)
  177543. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177544. png_ptr->channels = 2;
  177545. break;
  177546. case PNG_COLOR_TYPE_RGB_ALPHA:
  177547. if (bit_depth != 8 && bit_depth != 16)
  177548. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177549. png_ptr->channels = 4;
  177550. break;
  177551. default:
  177552. png_error(png_ptr, "Invalid image color type specified");
  177553. }
  177554. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177555. {
  177556. png_warning(png_ptr, "Invalid compression type specified");
  177557. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177558. }
  177559. if (
  177560. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177561. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177562. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177563. (color_type == PNG_COLOR_TYPE_RGB ||
  177564. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177565. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177566. #endif
  177567. filter_type != PNG_FILTER_TYPE_BASE)
  177568. {
  177569. png_warning(png_ptr, "Invalid filter type specified");
  177570. filter_type = PNG_FILTER_TYPE_BASE;
  177571. }
  177572. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177573. if (interlace_type != PNG_INTERLACE_NONE &&
  177574. interlace_type != PNG_INTERLACE_ADAM7)
  177575. {
  177576. png_warning(png_ptr, "Invalid interlace type specified");
  177577. interlace_type = PNG_INTERLACE_ADAM7;
  177578. }
  177579. #else
  177580. interlace_type=PNG_INTERLACE_NONE;
  177581. #endif
  177582. png_ptr->bit_depth = (png_byte)bit_depth;
  177583. png_ptr->color_type = (png_byte)color_type;
  177584. png_ptr->interlaced = (png_byte)interlace_type;
  177585. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177586. png_ptr->filter_type = (png_byte)filter_type;
  177587. #endif
  177588. png_ptr->compression_type = (png_byte)compression_type;
  177589. png_ptr->width = width;
  177590. png_ptr->height = height;
  177591. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177592. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177593. png_ptr->usr_width = png_ptr->width;
  177594. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177595. png_ptr->usr_channels = png_ptr->channels;
  177596. png_save_uint_32(buf, width);
  177597. png_save_uint_32(buf + 4, height);
  177598. buf[8] = (png_byte)bit_depth;
  177599. buf[9] = (png_byte)color_type;
  177600. buf[10] = (png_byte)compression_type;
  177601. buf[11] = (png_byte)filter_type;
  177602. buf[12] = (png_byte)interlace_type;
  177603. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177604. png_ptr->zstream.zalloc = png_zalloc;
  177605. png_ptr->zstream.zfree = png_zfree;
  177606. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177607. if (!(png_ptr->do_filter))
  177608. {
  177609. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177610. png_ptr->bit_depth < 8)
  177611. png_ptr->do_filter = PNG_FILTER_NONE;
  177612. else
  177613. png_ptr->do_filter = PNG_ALL_FILTERS;
  177614. }
  177615. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177616. {
  177617. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177618. png_ptr->zlib_strategy = Z_FILTERED;
  177619. else
  177620. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177621. }
  177622. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177623. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177624. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177625. png_ptr->zlib_mem_level = 8;
  177626. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177627. png_ptr->zlib_window_bits = 15;
  177628. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177629. png_ptr->zlib_method = 8;
  177630. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177631. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177632. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177633. png_error(png_ptr, "zlib failed to initialize compressor");
  177634. png_ptr->zstream.next_out = png_ptr->zbuf;
  177635. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177636. png_ptr->zstream.data_type = Z_BINARY;
  177637. png_ptr->mode = PNG_HAVE_IHDR;
  177638. }
  177639. void /* PRIVATE */
  177640. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177641. {
  177642. #ifdef PNG_USE_LOCAL_ARRAYS
  177643. PNG_PLTE;
  177644. #endif
  177645. png_uint_32 i;
  177646. png_colorp pal_ptr;
  177647. png_byte buf[3];
  177648. png_debug(1, "in png_write_PLTE\n");
  177649. if ((
  177650. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177651. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177652. #endif
  177653. num_pal == 0) || num_pal > 256)
  177654. {
  177655. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177656. {
  177657. png_error(png_ptr, "Invalid number of colors in palette");
  177658. }
  177659. else
  177660. {
  177661. png_warning(png_ptr, "Invalid number of colors in palette");
  177662. return;
  177663. }
  177664. }
  177665. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177666. {
  177667. png_warning(png_ptr,
  177668. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177669. return;
  177670. }
  177671. png_ptr->num_palette = (png_uint_16)num_pal;
  177672. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177673. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177674. #ifndef PNG_NO_POINTER_INDEXING
  177675. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177676. {
  177677. buf[0] = pal_ptr->red;
  177678. buf[1] = pal_ptr->green;
  177679. buf[2] = pal_ptr->blue;
  177680. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177681. }
  177682. #else
  177683. pal_ptr=palette;
  177684. for (i = 0; i < num_pal; i++)
  177685. {
  177686. buf[0] = pal_ptr[i].red;
  177687. buf[1] = pal_ptr[i].green;
  177688. buf[2] = pal_ptr[i].blue;
  177689. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177690. }
  177691. #endif
  177692. png_write_chunk_end(png_ptr);
  177693. png_ptr->mode |= PNG_HAVE_PLTE;
  177694. }
  177695. void /* PRIVATE */
  177696. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177697. {
  177698. #ifdef PNG_USE_LOCAL_ARRAYS
  177699. PNG_IDAT;
  177700. #endif
  177701. png_debug(1, "in png_write_IDAT\n");
  177702. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177703. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177704. {
  177705. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177706. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177707. {
  177708. if (length >= 2 &&
  177709. png_ptr->height < 16384 && png_ptr->width < 16384)
  177710. {
  177711. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177712. ((png_ptr->width *
  177713. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177714. unsigned int z_cinfo = z_cmf >> 4;
  177715. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177716. while (uncompressed_idat_size <= half_z_window_size &&
  177717. half_z_window_size >= 256)
  177718. {
  177719. z_cinfo--;
  177720. half_z_window_size >>= 1;
  177721. }
  177722. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177723. if (data[0] != (png_byte)z_cmf)
  177724. {
  177725. data[0] = (png_byte)z_cmf;
  177726. data[1] &= 0xe0;
  177727. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177728. }
  177729. }
  177730. }
  177731. else
  177732. png_error(png_ptr,
  177733. "Invalid zlib compression method or flags in IDAT");
  177734. }
  177735. png_write_chunk(png_ptr, png_IDAT, data, length);
  177736. png_ptr->mode |= PNG_HAVE_IDAT;
  177737. }
  177738. void /* PRIVATE */
  177739. png_write_IEND(png_structp png_ptr)
  177740. {
  177741. #ifdef PNG_USE_LOCAL_ARRAYS
  177742. PNG_IEND;
  177743. #endif
  177744. png_debug(1, "in png_write_IEND\n");
  177745. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177746. (png_size_t)0);
  177747. png_ptr->mode |= PNG_HAVE_IEND;
  177748. }
  177749. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177750. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177751. void /* PRIVATE */
  177752. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177753. {
  177754. #ifdef PNG_USE_LOCAL_ARRAYS
  177755. PNG_gAMA;
  177756. #endif
  177757. png_uint_32 igamma;
  177758. png_byte buf[4];
  177759. png_debug(1, "in png_write_gAMA\n");
  177760. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177761. png_save_uint_32(buf, igamma);
  177762. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177763. }
  177764. #endif
  177765. #ifdef PNG_FIXED_POINT_SUPPORTED
  177766. void /* PRIVATE */
  177767. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177768. {
  177769. #ifdef PNG_USE_LOCAL_ARRAYS
  177770. PNG_gAMA;
  177771. #endif
  177772. png_byte buf[4];
  177773. png_debug(1, "in png_write_gAMA\n");
  177774. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177775. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177776. }
  177777. #endif
  177778. #endif
  177779. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177780. void /* PRIVATE */
  177781. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177782. {
  177783. #ifdef PNG_USE_LOCAL_ARRAYS
  177784. PNG_sRGB;
  177785. #endif
  177786. png_byte buf[1];
  177787. png_debug(1, "in png_write_sRGB\n");
  177788. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177789. png_warning(png_ptr,
  177790. "Invalid sRGB rendering intent specified");
  177791. buf[0]=(png_byte)srgb_intent;
  177792. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177793. }
  177794. #endif
  177795. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177796. void /* PRIVATE */
  177797. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177798. png_charp profile, int profile_len)
  177799. {
  177800. #ifdef PNG_USE_LOCAL_ARRAYS
  177801. PNG_iCCP;
  177802. #endif
  177803. png_size_t name_len;
  177804. png_charp new_name;
  177805. compression_state comp;
  177806. int embedded_profile_len = 0;
  177807. png_debug(1, "in png_write_iCCP\n");
  177808. comp.num_output_ptr = 0;
  177809. comp.max_output_ptr = 0;
  177810. comp.output_ptr = NULL;
  177811. comp.input = NULL;
  177812. comp.input_len = 0;
  177813. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177814. &new_name)) == 0)
  177815. {
  177816. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177817. return;
  177818. }
  177819. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177820. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177821. if (profile == NULL)
  177822. profile_len = 0;
  177823. if (profile_len > 3)
  177824. embedded_profile_len =
  177825. ((*( (png_bytep)profile ))<<24) |
  177826. ((*( (png_bytep)profile+1))<<16) |
  177827. ((*( (png_bytep)profile+2))<< 8) |
  177828. ((*( (png_bytep)profile+3)) );
  177829. if (profile_len < embedded_profile_len)
  177830. {
  177831. png_warning(png_ptr,
  177832. "Embedded profile length too large in iCCP chunk");
  177833. return;
  177834. }
  177835. if (profile_len > embedded_profile_len)
  177836. {
  177837. png_warning(png_ptr,
  177838. "Truncating profile to actual length in iCCP chunk");
  177839. profile_len = embedded_profile_len;
  177840. }
  177841. if (profile_len)
  177842. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177843. PNG_COMPRESSION_TYPE_BASE, &comp);
  177844. png_write_chunk_start(png_ptr, png_iCCP,
  177845. (png_uint_32)name_len+profile_len+2);
  177846. new_name[name_len+1]=0x00;
  177847. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177848. if (profile_len)
  177849. png_write_compressed_data_out(png_ptr, &comp);
  177850. png_write_chunk_end(png_ptr);
  177851. png_free(png_ptr, new_name);
  177852. }
  177853. #endif
  177854. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177855. void /* PRIVATE */
  177856. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177857. {
  177858. #ifdef PNG_USE_LOCAL_ARRAYS
  177859. PNG_sPLT;
  177860. #endif
  177861. png_size_t name_len;
  177862. png_charp new_name;
  177863. png_byte entrybuf[10];
  177864. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177865. int palette_size = entry_size * spalette->nentries;
  177866. png_sPLT_entryp ep;
  177867. #ifdef PNG_NO_POINTER_INDEXING
  177868. int i;
  177869. #endif
  177870. png_debug(1, "in png_write_sPLT\n");
  177871. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177872. spalette->name, &new_name))==0)
  177873. {
  177874. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177875. return;
  177876. }
  177877. png_write_chunk_start(png_ptr, png_sPLT,
  177878. (png_uint_32)(name_len + 2 + palette_size));
  177879. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177880. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177881. #ifndef PNG_NO_POINTER_INDEXING
  177882. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177883. {
  177884. if (spalette->depth == 8)
  177885. {
  177886. entrybuf[0] = (png_byte)ep->red;
  177887. entrybuf[1] = (png_byte)ep->green;
  177888. entrybuf[2] = (png_byte)ep->blue;
  177889. entrybuf[3] = (png_byte)ep->alpha;
  177890. png_save_uint_16(entrybuf + 4, ep->frequency);
  177891. }
  177892. else
  177893. {
  177894. png_save_uint_16(entrybuf + 0, ep->red);
  177895. png_save_uint_16(entrybuf + 2, ep->green);
  177896. png_save_uint_16(entrybuf + 4, ep->blue);
  177897. png_save_uint_16(entrybuf + 6, ep->alpha);
  177898. png_save_uint_16(entrybuf + 8, ep->frequency);
  177899. }
  177900. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177901. }
  177902. #else
  177903. ep=spalette->entries;
  177904. for (i=0; i>spalette->nentries; i++)
  177905. {
  177906. if (spalette->depth == 8)
  177907. {
  177908. entrybuf[0] = (png_byte)ep[i].red;
  177909. entrybuf[1] = (png_byte)ep[i].green;
  177910. entrybuf[2] = (png_byte)ep[i].blue;
  177911. entrybuf[3] = (png_byte)ep[i].alpha;
  177912. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177913. }
  177914. else
  177915. {
  177916. png_save_uint_16(entrybuf + 0, ep[i].red);
  177917. png_save_uint_16(entrybuf + 2, ep[i].green);
  177918. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177919. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177920. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177921. }
  177922. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177923. }
  177924. #endif
  177925. png_write_chunk_end(png_ptr);
  177926. png_free(png_ptr, new_name);
  177927. }
  177928. #endif
  177929. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177930. void /* PRIVATE */
  177931. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177932. {
  177933. #ifdef PNG_USE_LOCAL_ARRAYS
  177934. PNG_sBIT;
  177935. #endif
  177936. png_byte buf[4];
  177937. png_size_t size;
  177938. png_debug(1, "in png_write_sBIT\n");
  177939. if (color_type & PNG_COLOR_MASK_COLOR)
  177940. {
  177941. png_byte maxbits;
  177942. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177943. png_ptr->usr_bit_depth);
  177944. if (sbit->red == 0 || sbit->red > maxbits ||
  177945. sbit->green == 0 || sbit->green > maxbits ||
  177946. sbit->blue == 0 || sbit->blue > maxbits)
  177947. {
  177948. png_warning(png_ptr, "Invalid sBIT depth specified");
  177949. return;
  177950. }
  177951. buf[0] = sbit->red;
  177952. buf[1] = sbit->green;
  177953. buf[2] = sbit->blue;
  177954. size = 3;
  177955. }
  177956. else
  177957. {
  177958. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177959. {
  177960. png_warning(png_ptr, "Invalid sBIT depth specified");
  177961. return;
  177962. }
  177963. buf[0] = sbit->gray;
  177964. size = 1;
  177965. }
  177966. if (color_type & PNG_COLOR_MASK_ALPHA)
  177967. {
  177968. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177969. {
  177970. png_warning(png_ptr, "Invalid sBIT depth specified");
  177971. return;
  177972. }
  177973. buf[size++] = sbit->alpha;
  177974. }
  177975. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177976. }
  177977. #endif
  177978. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177979. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177980. void /* PRIVATE */
  177981. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177982. double red_x, double red_y, double green_x, double green_y,
  177983. double blue_x, double blue_y)
  177984. {
  177985. #ifdef PNG_USE_LOCAL_ARRAYS
  177986. PNG_cHRM;
  177987. #endif
  177988. png_byte buf[32];
  177989. png_uint_32 itemp;
  177990. png_debug(1, "in png_write_cHRM\n");
  177991. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177992. white_x + white_y > 1.0)
  177993. {
  177994. png_warning(png_ptr, "Invalid cHRM white point specified");
  177995. #if !defined(PNG_NO_CONSOLE_IO)
  177996. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177997. #endif
  177998. return;
  177999. }
  178000. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  178001. png_save_uint_32(buf, itemp);
  178002. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  178003. png_save_uint_32(buf + 4, itemp);
  178004. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  178005. {
  178006. png_warning(png_ptr, "Invalid cHRM red point specified");
  178007. return;
  178008. }
  178009. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  178010. png_save_uint_32(buf + 8, itemp);
  178011. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  178012. png_save_uint_32(buf + 12, itemp);
  178013. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  178014. {
  178015. png_warning(png_ptr, "Invalid cHRM green point specified");
  178016. return;
  178017. }
  178018. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  178019. png_save_uint_32(buf + 16, itemp);
  178020. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  178021. png_save_uint_32(buf + 20, itemp);
  178022. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  178023. {
  178024. png_warning(png_ptr, "Invalid cHRM blue point specified");
  178025. return;
  178026. }
  178027. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  178028. png_save_uint_32(buf + 24, itemp);
  178029. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  178030. png_save_uint_32(buf + 28, itemp);
  178031. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  178032. }
  178033. #endif
  178034. #ifdef PNG_FIXED_POINT_SUPPORTED
  178035. void /* PRIVATE */
  178036. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  178037. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  178038. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  178039. png_fixed_point blue_y)
  178040. {
  178041. #ifdef PNG_USE_LOCAL_ARRAYS
  178042. PNG_cHRM;
  178043. #endif
  178044. png_byte buf[32];
  178045. png_debug(1, "in png_write_cHRM\n");
  178046. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  178047. {
  178048. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  178049. #if !defined(PNG_NO_CONSOLE_IO)
  178050. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  178051. #endif
  178052. return;
  178053. }
  178054. png_save_uint_32(buf, (png_uint_32)white_x);
  178055. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  178056. if (red_x + red_y > 100000L)
  178057. {
  178058. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  178059. return;
  178060. }
  178061. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  178062. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  178063. if (green_x + green_y > 100000L)
  178064. {
  178065. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  178066. return;
  178067. }
  178068. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  178069. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  178070. if (blue_x + blue_y > 100000L)
  178071. {
  178072. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  178073. return;
  178074. }
  178075. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  178076. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  178077. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  178078. }
  178079. #endif
  178080. #endif
  178081. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  178082. void /* PRIVATE */
  178083. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  178084. int num_trans, int color_type)
  178085. {
  178086. #ifdef PNG_USE_LOCAL_ARRAYS
  178087. PNG_tRNS;
  178088. #endif
  178089. png_byte buf[6];
  178090. png_debug(1, "in png_write_tRNS\n");
  178091. if (color_type == PNG_COLOR_TYPE_PALETTE)
  178092. {
  178093. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  178094. {
  178095. png_warning(png_ptr,"Invalid number of transparent colors specified");
  178096. return;
  178097. }
  178098. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  178099. }
  178100. else if (color_type == PNG_COLOR_TYPE_GRAY)
  178101. {
  178102. if(tran->gray >= (1 << png_ptr->bit_depth))
  178103. {
  178104. png_warning(png_ptr,
  178105. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  178106. return;
  178107. }
  178108. png_save_uint_16(buf, tran->gray);
  178109. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  178110. }
  178111. else if (color_type == PNG_COLOR_TYPE_RGB)
  178112. {
  178113. png_save_uint_16(buf, tran->red);
  178114. png_save_uint_16(buf + 2, tran->green);
  178115. png_save_uint_16(buf + 4, tran->blue);
  178116. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  178117. {
  178118. png_warning(png_ptr,
  178119. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  178120. return;
  178121. }
  178122. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  178123. }
  178124. else
  178125. {
  178126. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  178127. }
  178128. }
  178129. #endif
  178130. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  178131. void /* PRIVATE */
  178132. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  178133. {
  178134. #ifdef PNG_USE_LOCAL_ARRAYS
  178135. PNG_bKGD;
  178136. #endif
  178137. png_byte buf[6];
  178138. png_debug(1, "in png_write_bKGD\n");
  178139. if (color_type == PNG_COLOR_TYPE_PALETTE)
  178140. {
  178141. if (
  178142. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  178143. (png_ptr->num_palette ||
  178144. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  178145. #endif
  178146. back->index > png_ptr->num_palette)
  178147. {
  178148. png_warning(png_ptr, "Invalid background palette index");
  178149. return;
  178150. }
  178151. buf[0] = back->index;
  178152. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  178153. }
  178154. else if (color_type & PNG_COLOR_MASK_COLOR)
  178155. {
  178156. png_save_uint_16(buf, back->red);
  178157. png_save_uint_16(buf + 2, back->green);
  178158. png_save_uint_16(buf + 4, back->blue);
  178159. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  178160. {
  178161. png_warning(png_ptr,
  178162. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  178163. return;
  178164. }
  178165. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  178166. }
  178167. else
  178168. {
  178169. if(back->gray >= (1 << png_ptr->bit_depth))
  178170. {
  178171. png_warning(png_ptr,
  178172. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  178173. return;
  178174. }
  178175. png_save_uint_16(buf, back->gray);
  178176. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  178177. }
  178178. }
  178179. #endif
  178180. #if defined(PNG_WRITE_hIST_SUPPORTED)
  178181. void /* PRIVATE */
  178182. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  178183. {
  178184. #ifdef PNG_USE_LOCAL_ARRAYS
  178185. PNG_hIST;
  178186. #endif
  178187. int i;
  178188. png_byte buf[3];
  178189. png_debug(1, "in png_write_hIST\n");
  178190. if (num_hist > (int)png_ptr->num_palette)
  178191. {
  178192. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  178193. png_ptr->num_palette);
  178194. png_warning(png_ptr, "Invalid number of histogram entries specified");
  178195. return;
  178196. }
  178197. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  178198. for (i = 0; i < num_hist; i++)
  178199. {
  178200. png_save_uint_16(buf, hist[i]);
  178201. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  178202. }
  178203. png_write_chunk_end(png_ptr);
  178204. }
  178205. #endif
  178206. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  178207. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  178208. png_size_t /* PRIVATE */
  178209. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  178210. {
  178211. png_size_t key_len;
  178212. png_charp kp, dp;
  178213. int kflag;
  178214. int kwarn=0;
  178215. png_debug(1, "in png_check_keyword\n");
  178216. *new_key = NULL;
  178217. if (key == NULL || (key_len = png_strlen(key)) == 0)
  178218. {
  178219. png_warning(png_ptr, "zero length keyword");
  178220. return ((png_size_t)0);
  178221. }
  178222. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  178223. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  178224. if (*new_key == NULL)
  178225. {
  178226. png_warning(png_ptr, "Out of memory while procesing keyword");
  178227. return ((png_size_t)0);
  178228. }
  178229. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  178230. {
  178231. if ((png_byte)*kp < 0x20 ||
  178232. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  178233. {
  178234. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  178235. char msg[40];
  178236. png_snprintf(msg, 40,
  178237. "invalid keyword character 0x%02X", (png_byte)*kp);
  178238. png_warning(png_ptr, msg);
  178239. #else
  178240. png_warning(png_ptr, "invalid character in keyword");
  178241. #endif
  178242. *dp = ' ';
  178243. }
  178244. else
  178245. {
  178246. *dp = *kp;
  178247. }
  178248. }
  178249. *dp = '\0';
  178250. kp = *new_key + key_len - 1;
  178251. if (*kp == ' ')
  178252. {
  178253. png_warning(png_ptr, "trailing spaces removed from keyword");
  178254. while (*kp == ' ')
  178255. {
  178256. *(kp--) = '\0';
  178257. key_len--;
  178258. }
  178259. }
  178260. kp = *new_key;
  178261. if (*kp == ' ')
  178262. {
  178263. png_warning(png_ptr, "leading spaces removed from keyword");
  178264. while (*kp == ' ')
  178265. {
  178266. kp++;
  178267. key_len--;
  178268. }
  178269. }
  178270. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  178271. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  178272. {
  178273. if (*kp == ' ' && kflag == 0)
  178274. {
  178275. *(dp++) = *kp;
  178276. kflag = 1;
  178277. }
  178278. else if (*kp == ' ')
  178279. {
  178280. key_len--;
  178281. kwarn=1;
  178282. }
  178283. else
  178284. {
  178285. *(dp++) = *kp;
  178286. kflag = 0;
  178287. }
  178288. }
  178289. *dp = '\0';
  178290. if(kwarn)
  178291. png_warning(png_ptr, "extra interior spaces removed from keyword");
  178292. if (key_len == 0)
  178293. {
  178294. png_free(png_ptr, *new_key);
  178295. *new_key=NULL;
  178296. png_warning(png_ptr, "Zero length keyword");
  178297. }
  178298. if (key_len > 79)
  178299. {
  178300. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  178301. new_key[79] = '\0';
  178302. key_len = 79;
  178303. }
  178304. return (key_len);
  178305. }
  178306. #endif
  178307. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  178308. void /* PRIVATE */
  178309. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  178310. png_size_t text_len)
  178311. {
  178312. #ifdef PNG_USE_LOCAL_ARRAYS
  178313. PNG_tEXt;
  178314. #endif
  178315. png_size_t key_len;
  178316. png_charp new_key;
  178317. png_debug(1, "in png_write_tEXt\n");
  178318. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178319. {
  178320. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  178321. return;
  178322. }
  178323. if (text == NULL || *text == '\0')
  178324. text_len = 0;
  178325. else
  178326. text_len = png_strlen(text);
  178327. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  178328. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178329. if (text_len)
  178330. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  178331. png_write_chunk_end(png_ptr);
  178332. png_free(png_ptr, new_key);
  178333. }
  178334. #endif
  178335. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  178336. void /* PRIVATE */
  178337. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  178338. png_size_t text_len, int compression)
  178339. {
  178340. #ifdef PNG_USE_LOCAL_ARRAYS
  178341. PNG_zTXt;
  178342. #endif
  178343. png_size_t key_len;
  178344. char buf[1];
  178345. png_charp new_key;
  178346. compression_state comp;
  178347. png_debug(1, "in png_write_zTXt\n");
  178348. comp.num_output_ptr = 0;
  178349. comp.max_output_ptr = 0;
  178350. comp.output_ptr = NULL;
  178351. comp.input = NULL;
  178352. comp.input_len = 0;
  178353. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178354. {
  178355. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  178356. return;
  178357. }
  178358. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  178359. {
  178360. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  178361. png_free(png_ptr, new_key);
  178362. return;
  178363. }
  178364. text_len = png_strlen(text);
  178365. text_len = png_text_compress(png_ptr, text, text_len, compression,
  178366. &comp);
  178367. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  178368. (key_len+text_len+2));
  178369. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178370. png_free(png_ptr, new_key);
  178371. buf[0] = (png_byte)compression;
  178372. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  178373. png_write_compressed_data_out(png_ptr, &comp);
  178374. png_write_chunk_end(png_ptr);
  178375. }
  178376. #endif
  178377. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  178378. void /* PRIVATE */
  178379. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  178380. png_charp lang, png_charp lang_key, png_charp text)
  178381. {
  178382. #ifdef PNG_USE_LOCAL_ARRAYS
  178383. PNG_iTXt;
  178384. #endif
  178385. png_size_t lang_len, key_len, lang_key_len, text_len;
  178386. png_charp new_lang, new_key;
  178387. png_byte cbuf[2];
  178388. compression_state comp;
  178389. png_debug(1, "in png_write_iTXt\n");
  178390. comp.num_output_ptr = 0;
  178391. comp.max_output_ptr = 0;
  178392. comp.output_ptr = NULL;
  178393. comp.input = NULL;
  178394. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178395. {
  178396. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  178397. return;
  178398. }
  178399. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  178400. {
  178401. png_warning(png_ptr, "Empty language field in iTXt chunk");
  178402. new_lang = NULL;
  178403. lang_len = 0;
  178404. }
  178405. if (lang_key == NULL)
  178406. lang_key_len = 0;
  178407. else
  178408. lang_key_len = png_strlen(lang_key);
  178409. if (text == NULL)
  178410. text_len = 0;
  178411. else
  178412. text_len = png_strlen(text);
  178413. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  178414. &comp);
  178415. png_write_chunk_start(png_ptr, png_iTXt,
  178416. (png_uint_32)(
  178417. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  178418. + key_len
  178419. + lang_len
  178420. + lang_key_len
  178421. + text_len));
  178422. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178423. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  178424. compression == PNG_TEXT_COMPRESSION_NONE)
  178425. cbuf[0] = 0;
  178426. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  178427. cbuf[0] = 1;
  178428. cbuf[1] = 0;
  178429. png_write_chunk_data(png_ptr, cbuf, 2);
  178430. cbuf[0] = 0;
  178431. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  178432. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  178433. png_write_compressed_data_out(png_ptr, &comp);
  178434. png_write_chunk_end(png_ptr);
  178435. png_free(png_ptr, new_key);
  178436. if (new_lang)
  178437. png_free(png_ptr, new_lang);
  178438. }
  178439. #endif
  178440. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  178441. void /* PRIVATE */
  178442. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  178443. int unit_type)
  178444. {
  178445. #ifdef PNG_USE_LOCAL_ARRAYS
  178446. PNG_oFFs;
  178447. #endif
  178448. png_byte buf[9];
  178449. png_debug(1, "in png_write_oFFs\n");
  178450. if (unit_type >= PNG_OFFSET_LAST)
  178451. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  178452. png_save_int_32(buf, x_offset);
  178453. png_save_int_32(buf + 4, y_offset);
  178454. buf[8] = (png_byte)unit_type;
  178455. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  178456. }
  178457. #endif
  178458. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  178459. void /* PRIVATE */
  178460. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  178461. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  178462. {
  178463. #ifdef PNG_USE_LOCAL_ARRAYS
  178464. PNG_pCAL;
  178465. #endif
  178466. png_size_t purpose_len, units_len, total_len;
  178467. png_uint_32p params_len;
  178468. png_byte buf[10];
  178469. png_charp new_purpose;
  178470. int i;
  178471. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  178472. if (type >= PNG_EQUATION_LAST)
  178473. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  178474. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  178475. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  178476. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  178477. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  178478. total_len = purpose_len + units_len + 10;
  178479. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  178480. *png_sizeof(png_uint_32)));
  178481. for (i = 0; i < nparams; i++)
  178482. {
  178483. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  178484. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  178485. total_len += (png_size_t)params_len[i];
  178486. }
  178487. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  178488. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  178489. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  178490. png_save_int_32(buf, X0);
  178491. png_save_int_32(buf + 4, X1);
  178492. buf[8] = (png_byte)type;
  178493. buf[9] = (png_byte)nparams;
  178494. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  178495. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  178496. png_free(png_ptr, new_purpose);
  178497. for (i = 0; i < nparams; i++)
  178498. {
  178499. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  178500. (png_size_t)params_len[i]);
  178501. }
  178502. png_free(png_ptr, params_len);
  178503. png_write_chunk_end(png_ptr);
  178504. }
  178505. #endif
  178506. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  178507. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  178508. void /* PRIVATE */
  178509. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  178510. {
  178511. #ifdef PNG_USE_LOCAL_ARRAYS
  178512. PNG_sCAL;
  178513. #endif
  178514. char buf[64];
  178515. png_size_t total_len;
  178516. png_debug(1, "in png_write_sCAL\n");
  178517. buf[0] = (char)unit;
  178518. #if defined(_WIN32_WCE)
  178519. {
  178520. wchar_t wc_buf[32];
  178521. size_t wc_len;
  178522. swprintf(wc_buf, TEXT("%12.12e"), width);
  178523. wc_len = wcslen(wc_buf);
  178524. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178525. total_len = wc_len + 2;
  178526. swprintf(wc_buf, TEXT("%12.12e"), height);
  178527. wc_len = wcslen(wc_buf);
  178528. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178529. NULL, NULL);
  178530. total_len += wc_len;
  178531. }
  178532. #else
  178533. png_snprintf(buf + 1, 63, "%12.12e", width);
  178534. total_len = 1 + png_strlen(buf + 1) + 1;
  178535. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178536. total_len += png_strlen(buf + total_len);
  178537. #endif
  178538. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178539. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178540. }
  178541. #else
  178542. #ifdef PNG_FIXED_POINT_SUPPORTED
  178543. void /* PRIVATE */
  178544. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178545. png_charp height)
  178546. {
  178547. #ifdef PNG_USE_LOCAL_ARRAYS
  178548. PNG_sCAL;
  178549. #endif
  178550. png_byte buf[64];
  178551. png_size_t wlen, hlen, total_len;
  178552. png_debug(1, "in png_write_sCAL_s\n");
  178553. wlen = png_strlen(width);
  178554. hlen = png_strlen(height);
  178555. total_len = wlen + hlen + 2;
  178556. if (total_len > 64)
  178557. {
  178558. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178559. return;
  178560. }
  178561. buf[0] = (png_byte)unit;
  178562. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178563. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178564. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178565. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178566. }
  178567. #endif
  178568. #endif
  178569. #endif
  178570. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178571. void /* PRIVATE */
  178572. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178573. png_uint_32 y_pixels_per_unit,
  178574. int unit_type)
  178575. {
  178576. #ifdef PNG_USE_LOCAL_ARRAYS
  178577. PNG_pHYs;
  178578. #endif
  178579. png_byte buf[9];
  178580. png_debug(1, "in png_write_pHYs\n");
  178581. if (unit_type >= PNG_RESOLUTION_LAST)
  178582. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178583. png_save_uint_32(buf, x_pixels_per_unit);
  178584. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178585. buf[8] = (png_byte)unit_type;
  178586. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178587. }
  178588. #endif
  178589. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178590. void /* PRIVATE */
  178591. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178592. {
  178593. #ifdef PNG_USE_LOCAL_ARRAYS
  178594. PNG_tIME;
  178595. #endif
  178596. png_byte buf[7];
  178597. png_debug(1, "in png_write_tIME\n");
  178598. if (mod_time->month > 12 || mod_time->month < 1 ||
  178599. mod_time->day > 31 || mod_time->day < 1 ||
  178600. mod_time->hour > 23 || mod_time->second > 60)
  178601. {
  178602. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178603. return;
  178604. }
  178605. png_save_uint_16(buf, mod_time->year);
  178606. buf[2] = mod_time->month;
  178607. buf[3] = mod_time->day;
  178608. buf[4] = mod_time->hour;
  178609. buf[5] = mod_time->minute;
  178610. buf[6] = mod_time->second;
  178611. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178612. }
  178613. #endif
  178614. void /* PRIVATE */
  178615. png_write_start_row(png_structp png_ptr)
  178616. {
  178617. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178618. #ifdef PNG_USE_LOCAL_ARRAYS
  178619. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178620. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178621. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178622. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178623. #endif
  178624. #endif
  178625. png_size_t buf_size;
  178626. png_debug(1, "in png_write_start_row\n");
  178627. buf_size = (png_size_t)(PNG_ROWBYTES(
  178628. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178629. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178630. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178631. #ifndef PNG_NO_WRITE_FILTERING
  178632. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178633. {
  178634. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178635. (png_ptr->rowbytes + 1));
  178636. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178637. }
  178638. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178639. {
  178640. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178641. png_memset(png_ptr->prev_row, 0, buf_size);
  178642. if (png_ptr->do_filter & PNG_FILTER_UP)
  178643. {
  178644. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178645. (png_ptr->rowbytes + 1));
  178646. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178647. }
  178648. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178649. {
  178650. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178651. (png_ptr->rowbytes + 1));
  178652. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178653. }
  178654. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178655. {
  178656. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178657. (png_ptr->rowbytes + 1));
  178658. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178659. }
  178660. #endif /* PNG_NO_WRITE_FILTERING */
  178661. }
  178662. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178663. if (png_ptr->interlaced)
  178664. {
  178665. if (!(png_ptr->transformations & PNG_INTERLACE))
  178666. {
  178667. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178668. png_pass_ystart[0]) / png_pass_yinc[0];
  178669. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178670. png_pass_start[0]) / png_pass_inc[0];
  178671. }
  178672. else
  178673. {
  178674. png_ptr->num_rows = png_ptr->height;
  178675. png_ptr->usr_width = png_ptr->width;
  178676. }
  178677. }
  178678. else
  178679. #endif
  178680. {
  178681. png_ptr->num_rows = png_ptr->height;
  178682. png_ptr->usr_width = png_ptr->width;
  178683. }
  178684. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178685. png_ptr->zstream.next_out = png_ptr->zbuf;
  178686. }
  178687. void /* PRIVATE */
  178688. png_write_finish_row(png_structp png_ptr)
  178689. {
  178690. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178691. #ifdef PNG_USE_LOCAL_ARRAYS
  178692. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178693. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178694. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178695. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178696. #endif
  178697. #endif
  178698. int ret;
  178699. png_debug(1, "in png_write_finish_row\n");
  178700. png_ptr->row_number++;
  178701. if (png_ptr->row_number < png_ptr->num_rows)
  178702. return;
  178703. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178704. if (png_ptr->interlaced)
  178705. {
  178706. png_ptr->row_number = 0;
  178707. if (png_ptr->transformations & PNG_INTERLACE)
  178708. {
  178709. png_ptr->pass++;
  178710. }
  178711. else
  178712. {
  178713. do
  178714. {
  178715. png_ptr->pass++;
  178716. if (png_ptr->pass >= 7)
  178717. break;
  178718. png_ptr->usr_width = (png_ptr->width +
  178719. png_pass_inc[png_ptr->pass] - 1 -
  178720. png_pass_start[png_ptr->pass]) /
  178721. png_pass_inc[png_ptr->pass];
  178722. png_ptr->num_rows = (png_ptr->height +
  178723. png_pass_yinc[png_ptr->pass] - 1 -
  178724. png_pass_ystart[png_ptr->pass]) /
  178725. png_pass_yinc[png_ptr->pass];
  178726. if (png_ptr->transformations & PNG_INTERLACE)
  178727. break;
  178728. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178729. }
  178730. if (png_ptr->pass < 7)
  178731. {
  178732. if (png_ptr->prev_row != NULL)
  178733. png_memset(png_ptr->prev_row, 0,
  178734. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178735. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178736. return;
  178737. }
  178738. }
  178739. #endif
  178740. do
  178741. {
  178742. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178743. if (ret == Z_OK)
  178744. {
  178745. if (!(png_ptr->zstream.avail_out))
  178746. {
  178747. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178748. png_ptr->zstream.next_out = png_ptr->zbuf;
  178749. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178750. }
  178751. }
  178752. else if (ret != Z_STREAM_END)
  178753. {
  178754. if (png_ptr->zstream.msg != NULL)
  178755. png_error(png_ptr, png_ptr->zstream.msg);
  178756. else
  178757. png_error(png_ptr, "zlib error");
  178758. }
  178759. } while (ret != Z_STREAM_END);
  178760. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178761. {
  178762. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178763. png_ptr->zstream.avail_out);
  178764. }
  178765. deflateReset(&png_ptr->zstream);
  178766. png_ptr->zstream.data_type = Z_BINARY;
  178767. }
  178768. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178769. void /* PRIVATE */
  178770. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178771. {
  178772. #ifdef PNG_USE_LOCAL_ARRAYS
  178773. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178774. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178775. #endif
  178776. png_debug(1, "in png_do_write_interlace\n");
  178777. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178778. if (row != NULL && row_info != NULL && pass < 6)
  178779. #else
  178780. if (pass < 6)
  178781. #endif
  178782. {
  178783. switch (row_info->pixel_depth)
  178784. {
  178785. case 1:
  178786. {
  178787. png_bytep sp;
  178788. png_bytep dp;
  178789. int shift;
  178790. int d;
  178791. int value;
  178792. png_uint_32 i;
  178793. png_uint_32 row_width = row_info->width;
  178794. dp = row;
  178795. d = 0;
  178796. shift = 7;
  178797. for (i = png_pass_start[pass]; i < row_width;
  178798. i += png_pass_inc[pass])
  178799. {
  178800. sp = row + (png_size_t)(i >> 3);
  178801. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178802. d |= (value << shift);
  178803. if (shift == 0)
  178804. {
  178805. shift = 7;
  178806. *dp++ = (png_byte)d;
  178807. d = 0;
  178808. }
  178809. else
  178810. shift--;
  178811. }
  178812. if (shift != 7)
  178813. *dp = (png_byte)d;
  178814. break;
  178815. }
  178816. case 2:
  178817. {
  178818. png_bytep sp;
  178819. png_bytep dp;
  178820. int shift;
  178821. int d;
  178822. int value;
  178823. png_uint_32 i;
  178824. png_uint_32 row_width = row_info->width;
  178825. dp = row;
  178826. shift = 6;
  178827. d = 0;
  178828. for (i = png_pass_start[pass]; i < row_width;
  178829. i += png_pass_inc[pass])
  178830. {
  178831. sp = row + (png_size_t)(i >> 2);
  178832. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178833. d |= (value << shift);
  178834. if (shift == 0)
  178835. {
  178836. shift = 6;
  178837. *dp++ = (png_byte)d;
  178838. d = 0;
  178839. }
  178840. else
  178841. shift -= 2;
  178842. }
  178843. if (shift != 6)
  178844. *dp = (png_byte)d;
  178845. break;
  178846. }
  178847. case 4:
  178848. {
  178849. png_bytep sp;
  178850. png_bytep dp;
  178851. int shift;
  178852. int d;
  178853. int value;
  178854. png_uint_32 i;
  178855. png_uint_32 row_width = row_info->width;
  178856. dp = row;
  178857. shift = 4;
  178858. d = 0;
  178859. for (i = png_pass_start[pass]; i < row_width;
  178860. i += png_pass_inc[pass])
  178861. {
  178862. sp = row + (png_size_t)(i >> 1);
  178863. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178864. d |= (value << shift);
  178865. if (shift == 0)
  178866. {
  178867. shift = 4;
  178868. *dp++ = (png_byte)d;
  178869. d = 0;
  178870. }
  178871. else
  178872. shift -= 4;
  178873. }
  178874. if (shift != 4)
  178875. *dp = (png_byte)d;
  178876. break;
  178877. }
  178878. default:
  178879. {
  178880. png_bytep sp;
  178881. png_bytep dp;
  178882. png_uint_32 i;
  178883. png_uint_32 row_width = row_info->width;
  178884. png_size_t pixel_bytes;
  178885. dp = row;
  178886. pixel_bytes = (row_info->pixel_depth >> 3);
  178887. for (i = png_pass_start[pass]; i < row_width;
  178888. i += png_pass_inc[pass])
  178889. {
  178890. sp = row + (png_size_t)i * pixel_bytes;
  178891. if (dp != sp)
  178892. png_memcpy(dp, sp, pixel_bytes);
  178893. dp += pixel_bytes;
  178894. }
  178895. break;
  178896. }
  178897. }
  178898. row_info->width = (row_info->width +
  178899. png_pass_inc[pass] - 1 -
  178900. png_pass_start[pass]) /
  178901. png_pass_inc[pass];
  178902. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178903. row_info->width);
  178904. }
  178905. }
  178906. #endif
  178907. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178908. #define PNG_HISHIFT 10
  178909. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178910. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178911. void /* PRIVATE */
  178912. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178913. {
  178914. png_bytep best_row;
  178915. #ifndef PNG_NO_WRITE_FILTER
  178916. png_bytep prev_row, row_buf;
  178917. png_uint_32 mins, bpp;
  178918. png_byte filter_to_do = png_ptr->do_filter;
  178919. png_uint_32 row_bytes = row_info->rowbytes;
  178920. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178921. int num_p_filters = (int)png_ptr->num_prev_filters;
  178922. #endif
  178923. png_debug(1, "in png_write_find_filter\n");
  178924. bpp = (row_info->pixel_depth + 7) >> 3;
  178925. prev_row = png_ptr->prev_row;
  178926. #endif
  178927. best_row = png_ptr->row_buf;
  178928. #ifndef PNG_NO_WRITE_FILTER
  178929. row_buf = best_row;
  178930. mins = PNG_MAXSUM;
  178931. if ((filter_to_do & PNG_FILTER_NONE) &&
  178932. filter_to_do != PNG_FILTER_NONE)
  178933. {
  178934. png_bytep rp;
  178935. png_uint_32 sum = 0;
  178936. png_uint_32 i;
  178937. int v;
  178938. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178939. {
  178940. v = *rp;
  178941. sum += (v < 128) ? v : 256 - v;
  178942. }
  178943. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178944. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178945. {
  178946. png_uint_32 sumhi, sumlo;
  178947. int j;
  178948. sumlo = sum & PNG_LOMASK;
  178949. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178950. for (j = 0; j < num_p_filters; j++)
  178951. {
  178952. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178953. {
  178954. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178955. PNG_WEIGHT_SHIFT;
  178956. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178957. PNG_WEIGHT_SHIFT;
  178958. }
  178959. }
  178960. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178961. PNG_COST_SHIFT;
  178962. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178963. PNG_COST_SHIFT;
  178964. if (sumhi > PNG_HIMASK)
  178965. sum = PNG_MAXSUM;
  178966. else
  178967. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178968. }
  178969. #endif
  178970. mins = sum;
  178971. }
  178972. if (filter_to_do == PNG_FILTER_SUB)
  178973. {
  178974. png_bytep rp, lp, dp;
  178975. png_uint_32 i;
  178976. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178977. i++, rp++, dp++)
  178978. {
  178979. *dp = *rp;
  178980. }
  178981. for (lp = row_buf + 1; i < row_bytes;
  178982. i++, rp++, lp++, dp++)
  178983. {
  178984. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178985. }
  178986. best_row = png_ptr->sub_row;
  178987. }
  178988. else if (filter_to_do & PNG_FILTER_SUB)
  178989. {
  178990. png_bytep rp, dp, lp;
  178991. png_uint_32 sum = 0, lmins = mins;
  178992. png_uint_32 i;
  178993. int v;
  178994. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178995. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178996. {
  178997. int j;
  178998. png_uint_32 lmhi, lmlo;
  178999. lmlo = lmins & PNG_LOMASK;
  179000. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179001. for (j = 0; j < num_p_filters; j++)
  179002. {
  179003. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  179004. {
  179005. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179006. PNG_WEIGHT_SHIFT;
  179007. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179008. PNG_WEIGHT_SHIFT;
  179009. }
  179010. }
  179011. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179012. PNG_COST_SHIFT;
  179013. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179014. PNG_COST_SHIFT;
  179015. if (lmhi > PNG_HIMASK)
  179016. lmins = PNG_MAXSUM;
  179017. else
  179018. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179019. }
  179020. #endif
  179021. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  179022. i++, rp++, dp++)
  179023. {
  179024. v = *dp = *rp;
  179025. sum += (v < 128) ? v : 256 - v;
  179026. }
  179027. for (lp = row_buf + 1; i < row_bytes;
  179028. i++, rp++, lp++, dp++)
  179029. {
  179030. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  179031. sum += (v < 128) ? v : 256 - v;
  179032. if (sum > lmins) /* We are already worse, don't continue. */
  179033. break;
  179034. }
  179035. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179036. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179037. {
  179038. int j;
  179039. png_uint_32 sumhi, sumlo;
  179040. sumlo = sum & PNG_LOMASK;
  179041. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179042. for (j = 0; j < num_p_filters; j++)
  179043. {
  179044. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  179045. {
  179046. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  179047. PNG_WEIGHT_SHIFT;
  179048. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  179049. PNG_WEIGHT_SHIFT;
  179050. }
  179051. }
  179052. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179053. PNG_COST_SHIFT;
  179054. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179055. PNG_COST_SHIFT;
  179056. if (sumhi > PNG_HIMASK)
  179057. sum = PNG_MAXSUM;
  179058. else
  179059. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179060. }
  179061. #endif
  179062. if (sum < mins)
  179063. {
  179064. mins = sum;
  179065. best_row = png_ptr->sub_row;
  179066. }
  179067. }
  179068. if (filter_to_do == PNG_FILTER_UP)
  179069. {
  179070. png_bytep rp, dp, pp;
  179071. png_uint_32 i;
  179072. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  179073. pp = prev_row + 1; i < row_bytes;
  179074. i++, rp++, pp++, dp++)
  179075. {
  179076. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  179077. }
  179078. best_row = png_ptr->up_row;
  179079. }
  179080. else if (filter_to_do & PNG_FILTER_UP)
  179081. {
  179082. png_bytep rp, dp, pp;
  179083. png_uint_32 sum = 0, lmins = mins;
  179084. png_uint_32 i;
  179085. int v;
  179086. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179087. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179088. {
  179089. int j;
  179090. png_uint_32 lmhi, lmlo;
  179091. lmlo = lmins & PNG_LOMASK;
  179092. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179093. for (j = 0; j < num_p_filters; j++)
  179094. {
  179095. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  179096. {
  179097. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179098. PNG_WEIGHT_SHIFT;
  179099. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179100. PNG_WEIGHT_SHIFT;
  179101. }
  179102. }
  179103. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  179104. PNG_COST_SHIFT;
  179105. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  179106. PNG_COST_SHIFT;
  179107. if (lmhi > PNG_HIMASK)
  179108. lmins = PNG_MAXSUM;
  179109. else
  179110. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179111. }
  179112. #endif
  179113. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  179114. pp = prev_row + 1; i < row_bytes; i++)
  179115. {
  179116. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179117. sum += (v < 128) ? v : 256 - v;
  179118. if (sum > lmins) /* We are already worse, don't continue. */
  179119. break;
  179120. }
  179121. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179122. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179123. {
  179124. int j;
  179125. png_uint_32 sumhi, sumlo;
  179126. sumlo = sum & PNG_LOMASK;
  179127. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179128. for (j = 0; j < num_p_filters; j++)
  179129. {
  179130. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  179131. {
  179132. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179133. PNG_WEIGHT_SHIFT;
  179134. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179135. PNG_WEIGHT_SHIFT;
  179136. }
  179137. }
  179138. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179139. PNG_COST_SHIFT;
  179140. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179141. PNG_COST_SHIFT;
  179142. if (sumhi > PNG_HIMASK)
  179143. sum = PNG_MAXSUM;
  179144. else
  179145. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179146. }
  179147. #endif
  179148. if (sum < mins)
  179149. {
  179150. mins = sum;
  179151. best_row = png_ptr->up_row;
  179152. }
  179153. }
  179154. if (filter_to_do == PNG_FILTER_AVG)
  179155. {
  179156. png_bytep rp, dp, pp, lp;
  179157. png_uint_32 i;
  179158. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179159. pp = prev_row + 1; i < bpp; i++)
  179160. {
  179161. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179162. }
  179163. for (lp = row_buf + 1; i < row_bytes; i++)
  179164. {
  179165. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  179166. & 0xff);
  179167. }
  179168. best_row = png_ptr->avg_row;
  179169. }
  179170. else if (filter_to_do & PNG_FILTER_AVG)
  179171. {
  179172. png_bytep rp, dp, pp, lp;
  179173. png_uint_32 sum = 0, lmins = mins;
  179174. png_uint_32 i;
  179175. int v;
  179176. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179177. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179178. {
  179179. int j;
  179180. png_uint_32 lmhi, lmlo;
  179181. lmlo = lmins & PNG_LOMASK;
  179182. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179183. for (j = 0; j < num_p_filters; j++)
  179184. {
  179185. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  179186. {
  179187. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179188. PNG_WEIGHT_SHIFT;
  179189. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179190. PNG_WEIGHT_SHIFT;
  179191. }
  179192. }
  179193. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179194. PNG_COST_SHIFT;
  179195. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179196. PNG_COST_SHIFT;
  179197. if (lmhi > PNG_HIMASK)
  179198. lmins = PNG_MAXSUM;
  179199. else
  179200. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179201. }
  179202. #endif
  179203. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179204. pp = prev_row + 1; i < bpp; i++)
  179205. {
  179206. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179207. sum += (v < 128) ? v : 256 - v;
  179208. }
  179209. for (lp = row_buf + 1; i < row_bytes; i++)
  179210. {
  179211. v = *dp++ =
  179212. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  179213. sum += (v < 128) ? v : 256 - v;
  179214. if (sum > lmins) /* We are already worse, don't continue. */
  179215. break;
  179216. }
  179217. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179218. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179219. {
  179220. int j;
  179221. png_uint_32 sumhi, sumlo;
  179222. sumlo = sum & PNG_LOMASK;
  179223. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179224. for (j = 0; j < num_p_filters; j++)
  179225. {
  179226. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  179227. {
  179228. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179229. PNG_WEIGHT_SHIFT;
  179230. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179231. PNG_WEIGHT_SHIFT;
  179232. }
  179233. }
  179234. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179235. PNG_COST_SHIFT;
  179236. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179237. PNG_COST_SHIFT;
  179238. if (sumhi > PNG_HIMASK)
  179239. sum = PNG_MAXSUM;
  179240. else
  179241. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179242. }
  179243. #endif
  179244. if (sum < mins)
  179245. {
  179246. mins = sum;
  179247. best_row = png_ptr->avg_row;
  179248. }
  179249. }
  179250. if (filter_to_do == PNG_FILTER_PAETH)
  179251. {
  179252. png_bytep rp, dp, pp, cp, lp;
  179253. png_uint_32 i;
  179254. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179255. pp = prev_row + 1; i < bpp; i++)
  179256. {
  179257. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179258. }
  179259. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179260. {
  179261. int a, b, c, pa, pb, pc, p;
  179262. b = *pp++;
  179263. c = *cp++;
  179264. a = *lp++;
  179265. p = b - c;
  179266. pc = a - c;
  179267. #ifdef PNG_USE_ABS
  179268. pa = abs(p);
  179269. pb = abs(pc);
  179270. pc = abs(p + pc);
  179271. #else
  179272. pa = p < 0 ? -p : p;
  179273. pb = pc < 0 ? -pc : pc;
  179274. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179275. #endif
  179276. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179277. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179278. }
  179279. best_row = png_ptr->paeth_row;
  179280. }
  179281. else if (filter_to_do & PNG_FILTER_PAETH)
  179282. {
  179283. png_bytep rp, dp, pp, cp, lp;
  179284. png_uint_32 sum = 0, lmins = mins;
  179285. png_uint_32 i;
  179286. int v;
  179287. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179288. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179289. {
  179290. int j;
  179291. png_uint_32 lmhi, lmlo;
  179292. lmlo = lmins & PNG_LOMASK;
  179293. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179294. for (j = 0; j < num_p_filters; j++)
  179295. {
  179296. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179297. {
  179298. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179299. PNG_WEIGHT_SHIFT;
  179300. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179301. PNG_WEIGHT_SHIFT;
  179302. }
  179303. }
  179304. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179305. PNG_COST_SHIFT;
  179306. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179307. PNG_COST_SHIFT;
  179308. if (lmhi > PNG_HIMASK)
  179309. lmins = PNG_MAXSUM;
  179310. else
  179311. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179312. }
  179313. #endif
  179314. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179315. pp = prev_row + 1; i < bpp; i++)
  179316. {
  179317. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179318. sum += (v < 128) ? v : 256 - v;
  179319. }
  179320. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179321. {
  179322. int a, b, c, pa, pb, pc, p;
  179323. b = *pp++;
  179324. c = *cp++;
  179325. a = *lp++;
  179326. #ifndef PNG_SLOW_PAETH
  179327. p = b - c;
  179328. pc = a - c;
  179329. #ifdef PNG_USE_ABS
  179330. pa = abs(p);
  179331. pb = abs(pc);
  179332. pc = abs(p + pc);
  179333. #else
  179334. pa = p < 0 ? -p : p;
  179335. pb = pc < 0 ? -pc : pc;
  179336. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179337. #endif
  179338. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179339. #else /* PNG_SLOW_PAETH */
  179340. p = a + b - c;
  179341. pa = abs(p - a);
  179342. pb = abs(p - b);
  179343. pc = abs(p - c);
  179344. if (pa <= pb && pa <= pc)
  179345. p = a;
  179346. else if (pb <= pc)
  179347. p = b;
  179348. else
  179349. p = c;
  179350. #endif /* PNG_SLOW_PAETH */
  179351. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179352. sum += (v < 128) ? v : 256 - v;
  179353. if (sum > lmins) /* We are already worse, don't continue. */
  179354. break;
  179355. }
  179356. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179357. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179358. {
  179359. int j;
  179360. png_uint_32 sumhi, sumlo;
  179361. sumlo = sum & PNG_LOMASK;
  179362. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179363. for (j = 0; j < num_p_filters; j++)
  179364. {
  179365. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179366. {
  179367. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179368. PNG_WEIGHT_SHIFT;
  179369. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179370. PNG_WEIGHT_SHIFT;
  179371. }
  179372. }
  179373. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179374. PNG_COST_SHIFT;
  179375. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179376. PNG_COST_SHIFT;
  179377. if (sumhi > PNG_HIMASK)
  179378. sum = PNG_MAXSUM;
  179379. else
  179380. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179381. }
  179382. #endif
  179383. if (sum < mins)
  179384. {
  179385. best_row = png_ptr->paeth_row;
  179386. }
  179387. }
  179388. #endif /* PNG_NO_WRITE_FILTER */
  179389. png_write_filtered_row(png_ptr, best_row);
  179390. #ifndef PNG_NO_WRITE_FILTER
  179391. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179392. if (png_ptr->num_prev_filters > 0)
  179393. {
  179394. int j;
  179395. for (j = 1; j < num_p_filters; j++)
  179396. {
  179397. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  179398. }
  179399. png_ptr->prev_filters[j] = best_row[0];
  179400. }
  179401. #endif
  179402. #endif /* PNG_NO_WRITE_FILTER */
  179403. }
  179404. void /* PRIVATE */
  179405. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  179406. {
  179407. png_debug(1, "in png_write_filtered_row\n");
  179408. png_debug1(2, "filter = %d\n", filtered_row[0]);
  179409. png_ptr->zstream.next_in = filtered_row;
  179410. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  179411. do
  179412. {
  179413. int ret; /* return of zlib */
  179414. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  179415. if (ret != Z_OK)
  179416. {
  179417. if (png_ptr->zstream.msg != NULL)
  179418. png_error(png_ptr, png_ptr->zstream.msg);
  179419. else
  179420. png_error(png_ptr, "zlib error");
  179421. }
  179422. if (!(png_ptr->zstream.avail_out))
  179423. {
  179424. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  179425. png_ptr->zstream.next_out = png_ptr->zbuf;
  179426. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  179427. }
  179428. } while (png_ptr->zstream.avail_in);
  179429. if (png_ptr->prev_row != NULL)
  179430. {
  179431. png_bytep tptr;
  179432. tptr = png_ptr->prev_row;
  179433. png_ptr->prev_row = png_ptr->row_buf;
  179434. png_ptr->row_buf = tptr;
  179435. }
  179436. png_write_finish_row(png_ptr);
  179437. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  179438. png_ptr->flush_rows++;
  179439. if (png_ptr->flush_dist > 0 &&
  179440. png_ptr->flush_rows >= png_ptr->flush_dist)
  179441. {
  179442. png_write_flush(png_ptr);
  179443. }
  179444. #endif
  179445. }
  179446. #endif /* PNG_WRITE_SUPPORTED */
  179447. /*** End of inlined file: pngwutil.c ***/
  179448. }
  179449. #else
  179450. #define PNG_INTERNAL
  179451. #define PNG_SETJMP_NOT_SUPPORTED
  179452. #include <png.h>
  179453. #include <pngconf.h>
  179454. #endif
  179455. }
  179456. #ifdef _MSC_VER
  179457. #pragma warning (pop)
  179458. #endif
  179459. BEGIN_JUCE_NAMESPACE
  179460. using namespace pnglibNamespace;
  179461. using ::calloc;
  179462. using ::malloc;
  179463. using ::free;
  179464. static void pngReadCallback (png_structp pngReadStruct, png_bytep data, png_size_t length)
  179465. {
  179466. InputStream* const in = (InputStream*) png_get_io_ptr (pngReadStruct);
  179467. in->read (data, (int) length);
  179468. }
  179469. struct PNGErrorStruct {};
  179470. static void pngErrorCallback (png_structp, png_const_charp)
  179471. {
  179472. throw PNGErrorStruct();
  179473. }
  179474. Image* juce_loadPNGImageFromStream (InputStream& in)
  179475. {
  179476. Image* image = 0;
  179477. png_structp pngReadStruct;
  179478. png_infop pngInfoStruct;
  179479. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179480. if (pngReadStruct != 0)
  179481. {
  179482. pngInfoStruct = png_create_info_struct (pngReadStruct);
  179483. if (pngInfoStruct == 0)
  179484. {
  179485. png_destroy_read_struct (&pngReadStruct, 0, 0);
  179486. return 0;
  179487. }
  179488. png_set_error_fn (pngReadStruct, 0, pngErrorCallback, pngErrorCallback);
  179489. // read the header..
  179490. png_set_read_fn (pngReadStruct, &in, pngReadCallback);
  179491. png_uint_32 width, height;
  179492. int bitDepth, colorType, interlaceType;
  179493. png_read_info (pngReadStruct, pngInfoStruct);
  179494. png_get_IHDR (pngReadStruct, pngInfoStruct,
  179495. &width, &height,
  179496. &bitDepth, &colorType,
  179497. &interlaceType, 0, 0);
  179498. if (bitDepth == 16)
  179499. png_set_strip_16 (pngReadStruct);
  179500. if (colorType == PNG_COLOR_TYPE_PALETTE)
  179501. png_set_expand (pngReadStruct);
  179502. if (bitDepth < 8)
  179503. png_set_expand (pngReadStruct);
  179504. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179505. png_set_expand (pngReadStruct);
  179506. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179507. png_set_gray_to_rgb (pngReadStruct);
  179508. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179509. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179510. || pngInfoStruct->num_trans > 0;
  179511. // Load the image into a temp buffer in the pnglib format..
  179512. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179513. {
  179514. HeapBlock <png_bytep> rows (height);
  179515. for (int y = (int) height; --y >= 0;)
  179516. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179517. png_read_image (pngReadStruct, rows);
  179518. png_read_end (pngReadStruct, pngInfoStruct);
  179519. }
  179520. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179521. // now convert the data to a juce image format..
  179522. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179523. (int) width, (int) height, hasAlphaChan);
  179524. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179525. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179526. uint8* srcRow = tempBuffer;
  179527. uint8* destRow = destData.data;
  179528. for (int y = 0; y < (int) height; ++y)
  179529. {
  179530. const uint8* src = srcRow;
  179531. srcRow += (width << 2);
  179532. uint8* dest = destRow;
  179533. destRow += destData.lineStride;
  179534. if (hasAlphaChan)
  179535. {
  179536. for (int i = (int) width; --i >= 0;)
  179537. {
  179538. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179539. ((PixelARGB*) dest)->premultiply();
  179540. dest += destData.pixelStride;
  179541. src += 4;
  179542. }
  179543. }
  179544. else
  179545. {
  179546. for (int i = (int) width; --i >= 0;)
  179547. {
  179548. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179549. dest += destData.pixelStride;
  179550. src += 4;
  179551. }
  179552. }
  179553. }
  179554. }
  179555. return image;
  179556. }
  179557. static void pngWriteDataCallback (png_structp png_ptr, png_bytep data, png_size_t length)
  179558. {
  179559. OutputStream* const out = (OutputStream*) png_ptr->io_ptr;
  179560. const bool ok = out->write (data, (int) length);
  179561. (void) ok;
  179562. jassert (ok);
  179563. }
  179564. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179565. {
  179566. const int width = image.getWidth();
  179567. const int height = image.getHeight();
  179568. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179569. if (pngWriteStruct == 0)
  179570. return false;
  179571. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179572. if (pngInfoStruct == 0)
  179573. {
  179574. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179575. return false;
  179576. }
  179577. png_set_write_fn (pngWriteStruct, &out, pngWriteDataCallback, 0);
  179578. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179579. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179580. : PNG_COLOR_TYPE_RGB,
  179581. PNG_INTERLACE_NONE,
  179582. PNG_COMPRESSION_TYPE_BASE,
  179583. PNG_FILTER_TYPE_BASE);
  179584. HeapBlock <png_byte> rowData (width * 4);
  179585. png_color_8 sig_bit;
  179586. sig_bit.red = 8;
  179587. sig_bit.green = 8;
  179588. sig_bit.blue = 8;
  179589. sig_bit.alpha = 8;
  179590. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179591. png_write_info (pngWriteStruct, pngInfoStruct);
  179592. png_set_shift (pngWriteStruct, &sig_bit);
  179593. png_set_packing (pngWriteStruct);
  179594. const Image::BitmapData srcData (image, 0, 0, width, height);
  179595. for (int y = 0; y < height; ++y)
  179596. {
  179597. uint8* dst = (uint8*) rowData;
  179598. const uint8* src = srcData.getLinePointer (y);
  179599. if (image.hasAlphaChannel())
  179600. {
  179601. for (int i = width; --i >= 0;)
  179602. {
  179603. PixelARGB p (*(const PixelARGB*) src);
  179604. p.unpremultiply();
  179605. *dst++ = p.getRed();
  179606. *dst++ = p.getGreen();
  179607. *dst++ = p.getBlue();
  179608. *dst++ = p.getAlpha();
  179609. src += srcData.pixelStride;
  179610. }
  179611. }
  179612. else
  179613. {
  179614. for (int i = width; --i >= 0;)
  179615. {
  179616. *dst++ = ((const PixelRGB*) src)->getRed();
  179617. *dst++ = ((const PixelRGB*) src)->getGreen();
  179618. *dst++ = ((const PixelRGB*) src)->getBlue();
  179619. src += srcData.pixelStride;
  179620. }
  179621. }
  179622. png_write_rows (pngWriteStruct, &rowData, 1);
  179623. }
  179624. png_write_end (pngWriteStruct, pngInfoStruct);
  179625. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179626. out.flush();
  179627. return true;
  179628. }
  179629. END_JUCE_NAMESPACE
  179630. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179631. #endif
  179632. //==============================================================================
  179633. #if JUCE_BUILD_NATIVE
  179634. #if JUCE_WINDOWS
  179635. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179636. BEGIN_JUCE_NAMESPACE
  179637. #define JUCE_INCLUDED_FILE 1
  179638. // Now include the actual code files..
  179639. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179640. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179641. // compiled on its own).
  179642. #if JUCE_INCLUDED_FILE
  179643. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179644. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179645. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179646. #ifndef DOXYGEN
  179647. // use with DynamicLibraryLoader to simplify importing functions
  179648. //
  179649. // functionName: function to import
  179650. // localFunctionName: name you want to use to actually call it (must be different)
  179651. // returnType: the return type
  179652. // object: the DynamicLibraryLoader to use
  179653. // params: list of params (bracketed)
  179654. //
  179655. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179656. typedef returnType (WINAPI *type##localFunctionName) params; \
  179657. type##localFunctionName localFunctionName \
  179658. = (type##localFunctionName)object.findProcAddress (#functionName);
  179659. // loads and unloads a DLL automatically
  179660. class JUCE_API DynamicLibraryLoader
  179661. {
  179662. public:
  179663. DynamicLibraryLoader (const String& name);
  179664. ~DynamicLibraryLoader();
  179665. void* findProcAddress (const String& functionName);
  179666. private:
  179667. void* libHandle;
  179668. };
  179669. #endif
  179670. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179671. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179672. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179673. {
  179674. libHandle = LoadLibrary (name);
  179675. }
  179676. DynamicLibraryLoader::~DynamicLibraryLoader()
  179677. {
  179678. FreeLibrary ((HMODULE) libHandle);
  179679. }
  179680. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179681. {
  179682. return (void*) GetProcAddress ((HMODULE) libHandle, functionName);
  179683. }
  179684. #endif
  179685. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179686. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179687. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179688. // compiled on its own).
  179689. #if JUCE_INCLUDED_FILE
  179690. extern void juce_initialiseThreadEvents();
  179691. void Logger::outputDebugString (const String& text) throw()
  179692. {
  179693. OutputDebugString (text + T("\n"));
  179694. }
  179695. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  179696. {
  179697. String text;
  179698. va_list args;
  179699. va_start (args, format);
  179700. text.vprintf(format, args);
  179701. outputDebugString (text);
  179702. }
  179703. static int64 hiResTicksPerSecond;
  179704. static double hiResTicksScaleFactor;
  179705. #if JUCE_USE_INTRINSICS
  179706. // CPU info functions using intrinsics...
  179707. #pragma intrinsic (__cpuid)
  179708. #pragma intrinsic (__rdtsc)
  179709. const String SystemStats::getCpuVendor() throw()
  179710. {
  179711. int info [4];
  179712. __cpuid (info, 0);
  179713. char v [12];
  179714. memcpy (v, info + 1, 4);
  179715. memcpy (v + 4, info + 3, 4);
  179716. memcpy (v + 8, info + 2, 4);
  179717. return String (v, 12);
  179718. }
  179719. #else
  179720. // CPU info functions using old fashioned inline asm...
  179721. static void juce_getCpuVendor (char* const v)
  179722. {
  179723. int vendor[4];
  179724. zeromem (vendor, 16);
  179725. #ifdef JUCE_64BIT
  179726. #else
  179727. #ifndef __MINGW32__
  179728. __try
  179729. #endif
  179730. {
  179731. #if JUCE_GCC
  179732. unsigned int dummy = 0;
  179733. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179734. #else
  179735. __asm
  179736. {
  179737. mov eax, 0
  179738. cpuid
  179739. mov [vendor], ebx
  179740. mov [vendor + 4], edx
  179741. mov [vendor + 8], ecx
  179742. }
  179743. #endif
  179744. }
  179745. #ifndef __MINGW32__
  179746. __except (EXCEPTION_EXECUTE_HANDLER)
  179747. {
  179748. *v = 0;
  179749. }
  179750. #endif
  179751. #endif
  179752. memcpy (v, vendor, 16);
  179753. }
  179754. const String SystemStats::getCpuVendor() throw()
  179755. {
  179756. char v [16];
  179757. juce_getCpuVendor (v);
  179758. return String (v, 16);
  179759. }
  179760. #endif
  179761. struct CPUFlags
  179762. {
  179763. bool hasMMX : 1;
  179764. bool hasSSE : 1;
  179765. bool hasSSE2 : 1;
  179766. bool has3DNow : 1;
  179767. };
  179768. static CPUFlags cpuFlags;
  179769. bool SystemStats::hasMMX() throw()
  179770. {
  179771. return cpuFlags.hasMMX;
  179772. }
  179773. bool SystemStats::hasSSE() throw()
  179774. {
  179775. return cpuFlags.hasSSE;
  179776. }
  179777. bool SystemStats::hasSSE2() throw()
  179778. {
  179779. return cpuFlags.hasSSE2;
  179780. }
  179781. bool SystemStats::has3DNow() throw()
  179782. {
  179783. return cpuFlags.has3DNow;
  179784. }
  179785. void SystemStats::initialiseStats() throw()
  179786. {
  179787. juce_initialiseThreadEvents();
  179788. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179789. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179790. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179791. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179792. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179793. #else
  179794. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179795. #endif
  179796. LARGE_INTEGER f;
  179797. QueryPerformanceFrequency (&f);
  179798. hiResTicksPerSecond = f.QuadPart;
  179799. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179800. String s (SystemStats::getJUCEVersion());
  179801. #ifdef JUCE_DEBUG
  179802. const MMRESULT res = timeBeginPeriod (1);
  179803. jassert (res == TIMERR_NOERROR);
  179804. #else
  179805. timeBeginPeriod (1);
  179806. #endif
  179807. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179808. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179809. #endif
  179810. }
  179811. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179812. {
  179813. OSVERSIONINFO info;
  179814. info.dwOSVersionInfoSize = sizeof (info);
  179815. GetVersionEx (&info);
  179816. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179817. {
  179818. switch (info.dwMajorVersion)
  179819. {
  179820. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179821. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179822. default: jassertfalse; break; // !! not a supported OS!
  179823. }
  179824. }
  179825. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179826. {
  179827. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179828. return Win98;
  179829. }
  179830. return UnknownOS;
  179831. }
  179832. const String SystemStats::getOperatingSystemName() throw()
  179833. {
  179834. const char* name = "Unknown OS";
  179835. switch (getOperatingSystemType())
  179836. {
  179837. case Windows7: name = "Windows 7"; break;
  179838. case WinVista: name = "Windows Vista"; break;
  179839. case WinXP: name = "Windows XP"; break;
  179840. case Win2000: name = "Windows 2000"; break;
  179841. case Win98: name = "Windows 98"; break;
  179842. default: jassertfalse; break; // !! new type of OS?
  179843. }
  179844. return name;
  179845. }
  179846. bool SystemStats::isOperatingSystem64Bit() throw()
  179847. {
  179848. #ifdef _WIN64
  179849. return true;
  179850. #else
  179851. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179852. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179853. BOOL isWow64 = FALSE;
  179854. return (fnIsWow64Process != 0)
  179855. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179856. && (isWow64 != FALSE);
  179857. #endif
  179858. }
  179859. int SystemStats::getMemorySizeInMegabytes() throw()
  179860. {
  179861. MEMORYSTATUSEX mem;
  179862. mem.dwLength = sizeof (mem);
  179863. GlobalMemoryStatusEx (&mem);
  179864. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179865. }
  179866. int SystemStats::getNumCpus() throw()
  179867. {
  179868. SYSTEM_INFO systemInfo;
  179869. GetSystemInfo (&systemInfo);
  179870. return systemInfo.dwNumberOfProcessors;
  179871. }
  179872. uint32 juce_millisecondsSinceStartup() throw()
  179873. {
  179874. return (uint32) GetTickCount();
  179875. }
  179876. int64 Time::getHighResolutionTicks() throw()
  179877. {
  179878. LARGE_INTEGER ticks;
  179879. QueryPerformanceCounter (&ticks);
  179880. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179881. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179882. // fix for a very obscure PCI hardware bug that can make the counter
  179883. // sometimes jump forwards by a few seconds..
  179884. static int64 hiResTicksOffset = 0;
  179885. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179886. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179887. hiResTicksOffset = newOffset;
  179888. return ticks.QuadPart + hiResTicksOffset;
  179889. }
  179890. double Time::getMillisecondCounterHiRes() throw()
  179891. {
  179892. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179893. }
  179894. int64 Time::getHighResolutionTicksPerSecond() throw()
  179895. {
  179896. return hiResTicksPerSecond;
  179897. }
  179898. int64 SystemStats::getClockCycleCounter() throw()
  179899. {
  179900. #if JUCE_USE_INTRINSICS
  179901. // MS intrinsics version...
  179902. return __rdtsc();
  179903. #elif JUCE_GCC
  179904. // GNU inline asm version...
  179905. unsigned int hi = 0, lo = 0;
  179906. __asm__ __volatile__ (
  179907. "xor %%eax, %%eax \n\
  179908. xor %%edx, %%edx \n\
  179909. rdtsc \n\
  179910. movl %%eax, %[lo] \n\
  179911. movl %%edx, %[hi]"
  179912. :
  179913. : [hi] "m" (hi),
  179914. [lo] "m" (lo)
  179915. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179916. return (int64) ((((uint64) hi) << 32) | lo);
  179917. #else
  179918. // MSVC inline asm version...
  179919. unsigned int hi = 0, lo = 0;
  179920. __asm
  179921. {
  179922. xor eax, eax
  179923. xor edx, edx
  179924. rdtsc
  179925. mov lo, eax
  179926. mov hi, edx
  179927. }
  179928. return (int64) ((((uint64) hi) << 32) | lo);
  179929. #endif
  179930. }
  179931. int SystemStats::getCpuSpeedInMegaherz() throw()
  179932. {
  179933. const int64 cycles = SystemStats::getClockCycleCounter();
  179934. const uint32 millis = Time::getMillisecondCounter();
  179935. int lastResult = 0;
  179936. for (;;)
  179937. {
  179938. int n = 1000000;
  179939. while (--n > 0) {}
  179940. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179941. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179942. if (millisElapsed > 80)
  179943. {
  179944. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179945. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179946. return newResult;
  179947. lastResult = newResult;
  179948. }
  179949. }
  179950. }
  179951. bool Time::setSystemTimeToThisTime() const throw()
  179952. {
  179953. SYSTEMTIME st;
  179954. st.wDayOfWeek = 0;
  179955. st.wYear = (WORD) getYear();
  179956. st.wMonth = (WORD) (getMonth() + 1);
  179957. st.wDay = (WORD) getDayOfMonth();
  179958. st.wHour = (WORD) getHours();
  179959. st.wMinute = (WORD) getMinutes();
  179960. st.wSecond = (WORD) getSeconds();
  179961. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179962. // do this twice because of daylight saving conversion problems - the
  179963. // first one sets it up, the second one kicks it in.
  179964. return SetLocalTime (&st) != 0
  179965. && SetLocalTime (&st) != 0;
  179966. }
  179967. int SystemStats::getPageSize() throw()
  179968. {
  179969. SYSTEM_INFO systemInfo;
  179970. GetSystemInfo (&systemInfo);
  179971. return systemInfo.dwPageSize;
  179972. }
  179973. const String SystemStats::getLogonName()
  179974. {
  179975. TCHAR text [256];
  179976. DWORD len = numElementsInArray (text) - 2;
  179977. zerostruct (text);
  179978. GetUserName (text, &len);
  179979. return String (text, len);
  179980. }
  179981. const String SystemStats::getFullUserName()
  179982. {
  179983. return getLogonName();
  179984. }
  179985. #endif
  179986. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179987. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179988. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179989. // compiled on its own).
  179990. #if JUCE_INCLUDED_FILE
  179991. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179992. extern HWND juce_messageWindowHandle;
  179993. #endif
  179994. #if ! JUCE_USE_INTRINSICS
  179995. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179996. // older ones we have to actually call the ops as win32 functions..
  179997. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179998. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179999. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  180000. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  180001. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  180002. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  180003. #endif
  180004. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  180005. CriticalSection::CriticalSection() throw()
  180006. {
  180007. // (just to check the MS haven't changed this structure and broken things...)
  180008. #if _MSC_VER >= 1400
  180009. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  180010. #else
  180011. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  180012. #endif
  180013. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  180014. }
  180015. CriticalSection::~CriticalSection() throw()
  180016. {
  180017. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  180018. }
  180019. void CriticalSection::enter() const throw()
  180020. {
  180021. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  180022. }
  180023. bool CriticalSection::tryEnter() const throw()
  180024. {
  180025. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  180026. }
  180027. void CriticalSection::exit() const throw()
  180028. {
  180029. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  180030. }
  180031. WaitableEvent::WaitableEvent() throw()
  180032. : internal (CreateEvent (0, FALSE, FALSE, 0))
  180033. {
  180034. }
  180035. WaitableEvent::~WaitableEvent() throw()
  180036. {
  180037. CloseHandle (internal);
  180038. }
  180039. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  180040. {
  180041. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  180042. }
  180043. void WaitableEvent::signal() const throw()
  180044. {
  180045. SetEvent (internal);
  180046. }
  180047. void WaitableEvent::reset() const throw()
  180048. {
  180049. ResetEvent (internal);
  180050. }
  180051. void JUCE_API juce_threadEntryPoint (void*);
  180052. static unsigned int __stdcall threadEntryProc (void* userData)
  180053. {
  180054. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  180055. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  180056. GetCurrentThreadId(), TRUE);
  180057. #endif
  180058. juce_threadEntryPoint (userData);
  180059. _endthreadex (0);
  180060. return 0;
  180061. }
  180062. void juce_CloseThreadHandle (void* handle)
  180063. {
  180064. CloseHandle ((HANDLE) handle);
  180065. }
  180066. void* juce_createThread (void* userData)
  180067. {
  180068. unsigned int threadId;
  180069. return (void*) _beginthreadex (0, 0,
  180070. &threadEntryProc,
  180071. userData,
  180072. 0, &threadId);
  180073. }
  180074. void juce_killThread (void* handle)
  180075. {
  180076. if (handle != 0)
  180077. {
  180078. #ifdef JUCE_DEBUG
  180079. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  180080. #endif
  180081. TerminateThread (handle, 0);
  180082. }
  180083. }
  180084. void juce_setCurrentThreadName (const String& name)
  180085. {
  180086. #if defined (JUCE_DEBUG) && JUCE_MSVC
  180087. struct
  180088. {
  180089. DWORD dwType;
  180090. LPCSTR szName;
  180091. DWORD dwThreadID;
  180092. DWORD dwFlags;
  180093. } info;
  180094. info.dwType = 0x1000;
  180095. info.szName = name;
  180096. info.dwThreadID = GetCurrentThreadId();
  180097. info.dwFlags = 0;
  180098. #define MS_VC_EXCEPTION 0x406d1388
  180099. __try
  180100. {
  180101. RaiseException (MS_VC_EXCEPTION, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  180102. }
  180103. __except (EXCEPTION_CONTINUE_EXECUTION)
  180104. {}
  180105. #else
  180106. (void) name;
  180107. #endif
  180108. }
  180109. Thread::ThreadID Thread::getCurrentThreadId()
  180110. {
  180111. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  180112. }
  180113. // priority 1 to 10 where 5=normal, 1=low
  180114. bool juce_setThreadPriority (void* threadHandle, int priority)
  180115. {
  180116. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  180117. if (priority < 1)
  180118. pri = THREAD_PRIORITY_IDLE;
  180119. else if (priority < 2)
  180120. pri = THREAD_PRIORITY_LOWEST;
  180121. else if (priority < 5)
  180122. pri = THREAD_PRIORITY_BELOW_NORMAL;
  180123. else if (priority < 7)
  180124. pri = THREAD_PRIORITY_NORMAL;
  180125. else if (priority < 9)
  180126. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  180127. else if (priority < 10)
  180128. pri = THREAD_PRIORITY_HIGHEST;
  180129. if (threadHandle == 0)
  180130. threadHandle = GetCurrentThread();
  180131. return SetThreadPriority (threadHandle, pri) != FALSE;
  180132. }
  180133. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  180134. {
  180135. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  180136. }
  180137. static HANDLE sleepEvent = 0;
  180138. void juce_initialiseThreadEvents()
  180139. {
  180140. if (sleepEvent == 0)
  180141. #ifdef JUCE_DEBUG
  180142. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  180143. #else
  180144. sleepEvent = CreateEvent (0, 0, 0, 0);
  180145. #endif
  180146. }
  180147. void Thread::yield()
  180148. {
  180149. Sleep (0);
  180150. }
  180151. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  180152. {
  180153. if (millisecs >= 10)
  180154. {
  180155. Sleep (millisecs);
  180156. }
  180157. else
  180158. {
  180159. jassert (sleepEvent != 0);
  180160. // unlike Sleep() this is guaranteed to return to the current thread after
  180161. // the time expires, so we'll use this for short waits, which are more likely
  180162. // to need to be accurate
  180163. WaitForSingleObject (sleepEvent, millisecs);
  180164. }
  180165. }
  180166. static int lastProcessPriority = -1;
  180167. // called by WindowDriver because Windows does wierd things to process priority
  180168. // when you swap apps, and this forces an update when the app is brought to the front.
  180169. void juce_repeatLastProcessPriority()
  180170. {
  180171. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  180172. {
  180173. DWORD p;
  180174. switch (lastProcessPriority)
  180175. {
  180176. case Process::LowPriority:
  180177. p = IDLE_PRIORITY_CLASS;
  180178. break;
  180179. case Process::NormalPriority:
  180180. p = NORMAL_PRIORITY_CLASS;
  180181. break;
  180182. case Process::HighPriority:
  180183. p = HIGH_PRIORITY_CLASS;
  180184. break;
  180185. case Process::RealtimePriority:
  180186. p = REALTIME_PRIORITY_CLASS;
  180187. break;
  180188. default:
  180189. jassertfalse // bad priority value
  180190. return;
  180191. }
  180192. SetPriorityClass (GetCurrentProcess(), p);
  180193. }
  180194. }
  180195. void Process::setPriority (ProcessPriority prior)
  180196. {
  180197. if (lastProcessPriority != (int) prior)
  180198. {
  180199. lastProcessPriority = (int) prior;
  180200. juce_repeatLastProcessPriority();
  180201. }
  180202. }
  180203. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  180204. {
  180205. return IsDebuggerPresent() != FALSE;
  180206. }
  180207. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  180208. {
  180209. return juce_isRunningUnderDebugger();
  180210. }
  180211. void Process::raisePrivilege()
  180212. {
  180213. jassertfalse // xxx not implemented
  180214. }
  180215. void Process::lowerPrivilege()
  180216. {
  180217. jassertfalse // xxx not implemented
  180218. }
  180219. void Process::terminate()
  180220. {
  180221. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  180222. _CrtDumpMemoryLeaks();
  180223. #endif
  180224. // bullet in the head in case there's a problem shutting down..
  180225. ExitProcess (0);
  180226. }
  180227. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  180228. {
  180229. void* result = 0;
  180230. JUCE_TRY
  180231. {
  180232. result = (void*) LoadLibrary (name);
  180233. }
  180234. JUCE_CATCH_ALL
  180235. return result;
  180236. }
  180237. void PlatformUtilities::freeDynamicLibrary (void* h)
  180238. {
  180239. JUCE_TRY
  180240. {
  180241. if (h != 0)
  180242. FreeLibrary ((HMODULE) h);
  180243. }
  180244. JUCE_CATCH_ALL
  180245. }
  180246. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  180247. {
  180248. return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name)
  180249. : 0;
  180250. }
  180251. InterProcessLock::InterProcessLock (const String& name_)
  180252. : internal (0),
  180253. name (name_),
  180254. reentrancyLevel (0)
  180255. {
  180256. }
  180257. InterProcessLock::~InterProcessLock()
  180258. {
  180259. exit();
  180260. }
  180261. bool InterProcessLock::enter (const int timeOutMillisecs)
  180262. {
  180263. if (reentrancyLevel++ == 0)
  180264. {
  180265. internal = CreateMutex (0, TRUE, "Global\\" + name);
  180266. if (internal != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  180267. {
  180268. if (timeOutMillisecs == 0
  180269. || WaitForSingleObject (internal, (timeOutMillisecs < 0) ? INFINITE : timeOutMillisecs)
  180270. == WAIT_TIMEOUT)
  180271. {
  180272. ReleaseMutex (internal);
  180273. CloseHandle (internal);
  180274. internal = 0;
  180275. }
  180276. }
  180277. }
  180278. return (internal != 0);
  180279. }
  180280. void InterProcessLock::exit()
  180281. {
  180282. if (--reentrancyLevel == 0 && internal != 0)
  180283. {
  180284. ReleaseMutex (internal);
  180285. CloseHandle (internal);
  180286. internal = 0;
  180287. }
  180288. }
  180289. #endif
  180290. /*** End of inlined file: juce_win32_Threads.cpp ***/
  180291. /*** Start of inlined file: juce_win32_Files.cpp ***/
  180292. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180293. // compiled on its own).
  180294. #if JUCE_INCLUDED_FILE
  180295. #ifndef CSIDL_MYMUSIC
  180296. #define CSIDL_MYMUSIC 0x000d
  180297. #endif
  180298. #ifndef CSIDL_MYVIDEO
  180299. #define CSIDL_MYVIDEO 0x000e
  180300. #endif
  180301. const tchar File::separator = T('\\');
  180302. const tchar* File::separatorString = T("\\");
  180303. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  180304. {
  180305. if (fileName.isEmpty())
  180306. return false;
  180307. const DWORD attr = GetFileAttributes (fileName);
  180308. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  180309. : (attr != 0xffffffff);
  180310. }
  180311. bool juce_isDirectory (const String& fileName)
  180312. {
  180313. const DWORD attr = GetFileAttributes (fileName);
  180314. return (attr != 0xffffffff)
  180315. && ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180316. }
  180317. bool juce_canWriteToFile (const String& fileName)
  180318. {
  180319. const DWORD attr = GetFileAttributes (fileName);
  180320. return ((attr & FILE_ATTRIBUTE_READONLY) == 0);
  180321. }
  180322. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  180323. {
  180324. DWORD attr = GetFileAttributes (fileName);
  180325. if (attr == 0xffffffff)
  180326. return false;
  180327. if (isReadOnly != juce_canWriteToFile (fileName))
  180328. return true;
  180329. if (isReadOnly)
  180330. attr |= FILE_ATTRIBUTE_READONLY;
  180331. else
  180332. attr &= ~FILE_ATTRIBUTE_READONLY;
  180333. return SetFileAttributes (fileName, attr) != FALSE;
  180334. }
  180335. bool File::isHidden() const
  180336. {
  180337. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  180338. }
  180339. bool juce_deleteFile (const String& fileName)
  180340. {
  180341. if (juce_isDirectory (fileName))
  180342. return RemoveDirectory (fileName) != 0;
  180343. return DeleteFile (fileName) != 0;
  180344. }
  180345. bool File::moveToTrash() const
  180346. {
  180347. if (! exists())
  180348. return true;
  180349. SHFILEOPSTRUCT fos;
  180350. zerostruct (fos);
  180351. // The string we pass in must be double null terminated..
  180352. String doubleNullTermPath (getFullPathName() + " ");
  180353. TCHAR* p = (TCHAR*) (const TCHAR*) doubleNullTermPath;
  180354. p [getFullPathName().length()] = 0;
  180355. fos.wFunc = FO_DELETE;
  180356. fos.hwnd = (HWND) 0;
  180357. fos.pFrom = p;
  180358. fos.pTo = NULL;
  180359. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  180360. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  180361. return SHFileOperation (&fos) == 0;
  180362. }
  180363. bool juce_moveFile (const String& source, const String& dest)
  180364. {
  180365. return MoveFile (source, dest) != 0;
  180366. }
  180367. bool juce_copyFile (const String& source, const String& dest)
  180368. {
  180369. return CopyFile (source, dest, false) != 0;
  180370. }
  180371. void juce_createDirectory (const String& fileName)
  180372. {
  180373. if (! juce_fileExists (fileName, true))
  180374. {
  180375. CreateDirectory (fileName, 0);
  180376. }
  180377. }
  180378. // return 0 if not possible
  180379. void* juce_fileOpen (const String& fileName, bool forWriting)
  180380. {
  180381. HANDLE h;
  180382. if (forWriting)
  180383. {
  180384. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  180385. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  180386. if (h != INVALID_HANDLE_VALUE)
  180387. SetFilePointer (h, 0, 0, FILE_END);
  180388. else
  180389. h = 0;
  180390. }
  180391. else
  180392. {
  180393. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  180394. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  180395. if (h == INVALID_HANDLE_VALUE)
  180396. h = 0;
  180397. }
  180398. return (void*) h;
  180399. }
  180400. void juce_fileClose (void* handle)
  180401. {
  180402. CloseHandle (handle);
  180403. }
  180404. int juce_fileRead (void* handle, void* buffer, int size)
  180405. {
  180406. DWORD num = 0;
  180407. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  180408. return num;
  180409. }
  180410. int juce_fileWrite (void* handle, const void* buffer, int size)
  180411. {
  180412. DWORD num;
  180413. WriteFile ((HANDLE) handle,
  180414. buffer, size,
  180415. &num, 0);
  180416. return num;
  180417. }
  180418. int64 juce_fileSetPosition (void* handle, int64 pos)
  180419. {
  180420. LARGE_INTEGER li;
  180421. li.QuadPart = pos;
  180422. li.LowPart = SetFilePointer ((HANDLE) handle,
  180423. li.LowPart,
  180424. &li.HighPart,
  180425. FILE_BEGIN); // (returns -1 if it fails)
  180426. return li.QuadPart;
  180427. }
  180428. int64 juce_fileGetPosition (void* handle)
  180429. {
  180430. LARGE_INTEGER li;
  180431. li.QuadPart = 0;
  180432. li.LowPart = SetFilePointer ((HANDLE) handle,
  180433. 0, &li.HighPart,
  180434. FILE_CURRENT); // (returns -1 if it fails)
  180435. return jmax ((int64) 0, li.QuadPart);
  180436. }
  180437. void juce_fileFlush (void* handle)
  180438. {
  180439. FlushFileBuffers ((HANDLE) handle);
  180440. }
  180441. int64 juce_getFileSize (const String& fileName)
  180442. {
  180443. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180444. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180445. {
  180446. return (((int64) attributes.nFileSizeHigh) << 32)
  180447. | attributes.nFileSizeLow;
  180448. }
  180449. return 0;
  180450. }
  180451. static int64 fileTimeToTime (const FILETIME* const ft)
  180452. {
  180453. // tell me if this fails!
  180454. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME));
  180455. #if JUCE_GCC
  180456. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000LL) / 10000;
  180457. #else
  180458. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000) / 10000;
  180459. #endif
  180460. }
  180461. static void timeToFileTime (const int64 time, FILETIME* const ft)
  180462. {
  180463. #if JUCE_GCC
  180464. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000LL;
  180465. #else
  180466. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000;
  180467. #endif
  180468. }
  180469. void juce_getFileTimes (const String& fileName,
  180470. int64& modificationTime,
  180471. int64& accessTime,
  180472. int64& creationTime)
  180473. {
  180474. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180475. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180476. {
  180477. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  180478. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  180479. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  180480. }
  180481. else
  180482. {
  180483. creationTime = accessTime = modificationTime = 0;
  180484. }
  180485. }
  180486. bool juce_setFileTimes (const String& fileName,
  180487. int64 modificationTime,
  180488. int64 accessTime,
  180489. int64 creationTime)
  180490. {
  180491. FILETIME m, a, c;
  180492. if (modificationTime > 0)
  180493. timeToFileTime (modificationTime, &m);
  180494. if (accessTime > 0)
  180495. timeToFileTime (accessTime, &a);
  180496. if (creationTime > 0)
  180497. timeToFileTime (creationTime, &c);
  180498. void* const h = juce_fileOpen (fileName, true);
  180499. bool ok = false;
  180500. if (h != 0)
  180501. {
  180502. ok = SetFileTime ((HANDLE) h,
  180503. (creationTime > 0) ? &c : 0,
  180504. (accessTime > 0) ? &a : 0,
  180505. (modificationTime > 0) ? &m : 0) != 0;
  180506. juce_fileClose (h);
  180507. }
  180508. return ok;
  180509. }
  180510. // return '\0' separated list of strings
  180511. const StringArray juce_getFileSystemRoots()
  180512. {
  180513. TCHAR buffer [2048];
  180514. buffer[0] = 0;
  180515. buffer[1] = 0;
  180516. GetLogicalDriveStrings (2048, buffer);
  180517. TCHAR* n = buffer;
  180518. StringArray roots;
  180519. while (*n != 0)
  180520. {
  180521. roots.add (String (n));
  180522. while (*n++ != 0)
  180523. {
  180524. }
  180525. }
  180526. roots.sort (true);
  180527. return roots;
  180528. }
  180529. const String juce_getVolumeLabel (const String& filenameOnVolume,
  180530. int& volumeSerialNumber)
  180531. {
  180532. TCHAR n [4];
  180533. n[0] = *(const TCHAR*) filenameOnVolume;
  180534. n[1] = L':';
  180535. n[2] = L'\\';
  180536. n[3] = 0;
  180537. TCHAR dest [64];
  180538. DWORD serialNum;
  180539. if (! GetVolumeInformation (n, dest, 64, (DWORD*) &serialNum, 0, 0, 0, 0))
  180540. {
  180541. dest[0] = 0;
  180542. serialNum = 0;
  180543. }
  180544. volumeSerialNumber = serialNum;
  180545. return String (dest);
  180546. }
  180547. static int64 getDiskSpaceInfo (String fn, const bool total)
  180548. {
  180549. if (fn[1] == T(':'))
  180550. fn = fn.substring (0, 2) + T("\\");
  180551. ULARGE_INTEGER spc, tot, totFree;
  180552. if (GetDiskFreeSpaceEx (fn, &spc, &tot, &totFree))
  180553. return (int64) (total ? tot.QuadPart
  180554. : spc.QuadPart);
  180555. return 0;
  180556. }
  180557. int64 File::getBytesFreeOnVolume() const
  180558. {
  180559. return getDiskSpaceInfo (getFullPathName(), false);
  180560. }
  180561. int64 File::getVolumeTotalSize() const
  180562. {
  180563. return getDiskSpaceInfo (getFullPathName(), true);
  180564. }
  180565. static unsigned int getWindowsDriveType (const String& fileName)
  180566. {
  180567. TCHAR n[4];
  180568. n[0] = *(const TCHAR*) fileName;
  180569. n[1] = L':';
  180570. n[2] = L'\\';
  180571. n[3] = 0;
  180572. return GetDriveType (n);
  180573. }
  180574. bool File::isOnCDRomDrive() const
  180575. {
  180576. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180577. }
  180578. bool File::isOnHardDisk() const
  180579. {
  180580. if (fullPath.isEmpty())
  180581. return false;
  180582. const unsigned int n = getWindowsDriveType (getFullPathName());
  180583. if (fullPath.toLowerCase()[0] <= 'b'
  180584. && fullPath[1] == T(':'))
  180585. {
  180586. return n != DRIVE_REMOVABLE;
  180587. }
  180588. else
  180589. {
  180590. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180591. }
  180592. }
  180593. bool File::isOnRemovableDrive() const
  180594. {
  180595. if (fullPath.isEmpty())
  180596. return false;
  180597. const unsigned int n = getWindowsDriveType (getFullPathName());
  180598. return n == DRIVE_CDROM
  180599. || n == DRIVE_REMOTE
  180600. || n == DRIVE_REMOVABLE
  180601. || n == DRIVE_RAMDISK;
  180602. }
  180603. #define MAX_PATH_CHARS (MAX_PATH + 256)
  180604. static const File juce_getSpecialFolderPath (int type)
  180605. {
  180606. WCHAR path [MAX_PATH_CHARS];
  180607. if (SHGetSpecialFolderPath (0, path, type, 0))
  180608. return File (String (path));
  180609. return File::nonexistent;
  180610. }
  180611. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180612. {
  180613. int csidlType = 0;
  180614. switch (type)
  180615. {
  180616. case userHomeDirectory:
  180617. csidlType = CSIDL_PROFILE;
  180618. break;
  180619. case userDocumentsDirectory:
  180620. csidlType = CSIDL_PERSONAL;
  180621. break;
  180622. case userDesktopDirectory:
  180623. csidlType = CSIDL_DESKTOP;
  180624. break;
  180625. case userApplicationDataDirectory:
  180626. csidlType = CSIDL_APPDATA;
  180627. break;
  180628. case commonApplicationDataDirectory:
  180629. csidlType = CSIDL_COMMON_APPDATA;
  180630. break;
  180631. case globalApplicationsDirectory:
  180632. csidlType = CSIDL_PROGRAM_FILES;
  180633. break;
  180634. case userMusicDirectory:
  180635. csidlType = CSIDL_MYMUSIC;
  180636. break;
  180637. case userMoviesDirectory:
  180638. csidlType = CSIDL_MYVIDEO;
  180639. break;
  180640. case tempDirectory:
  180641. {
  180642. WCHAR dest [2048];
  180643. dest[0] = 0;
  180644. GetTempPath (2048, dest);
  180645. return File (String (dest));
  180646. }
  180647. case invokedExecutableFile:
  180648. case currentExecutableFile:
  180649. case currentApplicationFile:
  180650. {
  180651. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180652. WCHAR dest [MAX_PATH_CHARS];
  180653. dest[0] = 0;
  180654. GetModuleFileName (moduleHandle, dest, MAX_PATH_CHARS);
  180655. return File (String (dest));
  180656. }
  180657. break;
  180658. default:
  180659. jassertfalse // unknown type?
  180660. return File::nonexistent;
  180661. }
  180662. return juce_getSpecialFolderPath (csidlType);
  180663. }
  180664. const File File::getCurrentWorkingDirectory()
  180665. {
  180666. WCHAR dest [MAX_PATH_CHARS];
  180667. dest[0] = 0;
  180668. GetCurrentDirectory (MAX_PATH_CHARS, dest);
  180669. return File (String (dest));
  180670. }
  180671. bool File::setAsCurrentWorkingDirectory() const
  180672. {
  180673. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180674. }
  180675. const String File::getVersion() const
  180676. {
  180677. String result;
  180678. DWORD handle = 0;
  180679. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180680. HeapBlock <char> buffer;
  180681. buffer.calloc (bufferSize);
  180682. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180683. {
  180684. VS_FIXEDFILEINFO* vffi;
  180685. UINT len = 0;
  180686. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180687. {
  180688. result << (int) HIWORD (vffi->dwFileVersionMS) << "."
  180689. << (int) LOWORD (vffi->dwFileVersionMS) << "."
  180690. << (int) HIWORD (vffi->dwFileVersionLS) << "."
  180691. << (int) LOWORD (vffi->dwFileVersionLS);
  180692. }
  180693. }
  180694. return result;
  180695. }
  180696. const File File::getLinkedTarget() const
  180697. {
  180698. File result (*this);
  180699. String p (getFullPathName());
  180700. if (! exists())
  180701. p += T(".lnk");
  180702. else if (getFileExtension() != T(".lnk"))
  180703. return result;
  180704. ComSmartPtr <IShellLink> shellLink;
  180705. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180706. {
  180707. ComSmartPtr <IPersistFile> persistFile;
  180708. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180709. {
  180710. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180711. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180712. {
  180713. WIN32_FIND_DATA winFindData;
  180714. WCHAR resolvedPath [MAX_PATH];
  180715. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180716. result = File (resolvedPath);
  180717. }
  180718. }
  180719. }
  180720. return result;
  180721. }
  180722. template <class FindDataType>
  180723. static void getFindFileInfo (FindDataType& findData,
  180724. String& filename, bool* const isDir, bool* const isHidden,
  180725. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180726. bool* const isReadOnly)
  180727. {
  180728. filename = findData.cFileName;
  180729. if (isDir != 0)
  180730. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180731. if (isHidden != 0)
  180732. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180733. if (fileSize != 0)
  180734. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180735. if (modTime != 0)
  180736. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180737. if (creationTime != 0)
  180738. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180739. if (isReadOnly != 0)
  180740. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180741. }
  180742. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180743. bool* isDir, bool* isHidden, int64* fileSize,
  180744. Time* modTime, Time* creationTime, bool* isReadOnly)
  180745. {
  180746. String wc (directory);
  180747. if (! wc.endsWithChar (File::separator))
  180748. wc += File::separator;
  180749. wc += wildCard;
  180750. WIN32_FIND_DATA findData;
  180751. HANDLE h = FindFirstFile (wc, &findData);
  180752. if (h != INVALID_HANDLE_VALUE)
  180753. {
  180754. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180755. modTime, creationTime, isReadOnly);
  180756. return h;
  180757. }
  180758. firstResult = String::empty;
  180759. return 0;
  180760. }
  180761. bool juce_findFileNext (void* handle, String& resultFile,
  180762. bool* isDir, bool* isHidden, int64* fileSize,
  180763. Time* modTime, Time* creationTime, bool* isReadOnly)
  180764. {
  180765. WIN32_FIND_DATA findData;
  180766. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180767. {
  180768. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180769. modTime, creationTime, isReadOnly);
  180770. return true;
  180771. }
  180772. resultFile = String::empty;
  180773. return false;
  180774. }
  180775. void juce_findFileClose (void* handle)
  180776. {
  180777. FindClose (handle);
  180778. }
  180779. bool juce_launchFile (const String& fileName,
  180780. const String& parameters)
  180781. {
  180782. HINSTANCE hInstance = 0;
  180783. JUCE_TRY
  180784. {
  180785. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180786. }
  180787. JUCE_CATCH_ALL
  180788. return hInstance > (HINSTANCE) 32;
  180789. }
  180790. void File::revealToUser() const
  180791. {
  180792. if (isDirectory())
  180793. startAsProcess();
  180794. else if (getParentDirectory().exists())
  180795. getParentDirectory().startAsProcess();
  180796. }
  180797. struct NamedPipeInternal
  180798. {
  180799. HANDLE pipeH;
  180800. HANDLE cancelEvent;
  180801. bool connected, createdPipe;
  180802. NamedPipeInternal()
  180803. : pipeH (0),
  180804. cancelEvent (0),
  180805. connected (false),
  180806. createdPipe (false)
  180807. {
  180808. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180809. }
  180810. ~NamedPipeInternal()
  180811. {
  180812. disconnect();
  180813. if (pipeH != 0)
  180814. CloseHandle (pipeH);
  180815. CloseHandle (cancelEvent);
  180816. }
  180817. bool connect (const int timeOutMs)
  180818. {
  180819. if (! createdPipe)
  180820. return true;
  180821. if (! connected)
  180822. {
  180823. OVERLAPPED over;
  180824. zerostruct (over);
  180825. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180826. if (ConnectNamedPipe (pipeH, &over))
  180827. {
  180828. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180829. }
  180830. else
  180831. {
  180832. const int err = GetLastError();
  180833. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180834. {
  180835. HANDLE handles[] = { over.hEvent, cancelEvent };
  180836. if (WaitForMultipleObjects (2, handles, FALSE,
  180837. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180838. connected = true;
  180839. }
  180840. else if (err == ERROR_PIPE_CONNECTED)
  180841. {
  180842. connected = true;
  180843. }
  180844. }
  180845. CloseHandle (over.hEvent);
  180846. }
  180847. return connected;
  180848. }
  180849. void disconnect()
  180850. {
  180851. if (connected)
  180852. {
  180853. DisconnectNamedPipe (pipeH);
  180854. connected = false;
  180855. }
  180856. }
  180857. };
  180858. void NamedPipe::close()
  180859. {
  180860. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180861. delete intern;
  180862. internal = 0;
  180863. }
  180864. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180865. {
  180866. close();
  180867. NamedPipeInternal* const intern = new NamedPipeInternal();
  180868. String file ("\\\\.\\pipe\\");
  180869. file += pipeName;
  180870. intern->createdPipe = createPipe;
  180871. if (createPipe)
  180872. {
  180873. intern->pipeH = CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180874. PIPE_UNLIMITED_INSTANCES,
  180875. 4096, 4096, 0, NULL);
  180876. }
  180877. else
  180878. {
  180879. intern->pipeH = CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
  180880. FILE_FLAG_OVERLAPPED, 0);
  180881. }
  180882. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180883. {
  180884. internal = intern;
  180885. return true;
  180886. }
  180887. delete intern;
  180888. return false;
  180889. }
  180890. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180891. {
  180892. int bytesRead = -1;
  180893. bool waitAgain = true;
  180894. while (waitAgain && internal != 0)
  180895. {
  180896. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180897. waitAgain = false;
  180898. if (! intern->connect (timeOutMilliseconds))
  180899. break;
  180900. if (maxBytesToRead <= 0)
  180901. return 0;
  180902. OVERLAPPED over;
  180903. zerostruct (over);
  180904. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180905. unsigned long numRead;
  180906. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180907. {
  180908. bytesRead = (int) numRead;
  180909. }
  180910. else if (GetLastError() == ERROR_IO_PENDING)
  180911. {
  180912. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180913. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180914. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180915. : INFINITE);
  180916. if (waitResult != WAIT_OBJECT_0)
  180917. {
  180918. // if the operation timed out, let's cancel it...
  180919. CancelIo (intern->pipeH);
  180920. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180921. }
  180922. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180923. {
  180924. bytesRead = (int) numRead;
  180925. }
  180926. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180927. {
  180928. intern->disconnect();
  180929. waitAgain = true;
  180930. }
  180931. }
  180932. else
  180933. {
  180934. waitAgain = internal != 0;
  180935. Sleep (5);
  180936. }
  180937. CloseHandle (over.hEvent);
  180938. }
  180939. return bytesRead;
  180940. }
  180941. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180942. {
  180943. int bytesWritten = -1;
  180944. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180945. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180946. {
  180947. if (numBytesToWrite <= 0)
  180948. return 0;
  180949. OVERLAPPED over;
  180950. zerostruct (over);
  180951. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180952. unsigned long numWritten;
  180953. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180954. {
  180955. bytesWritten = (int) numWritten;
  180956. }
  180957. else if (GetLastError() == ERROR_IO_PENDING)
  180958. {
  180959. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180960. DWORD waitResult;
  180961. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180962. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180963. : INFINITE);
  180964. if (waitResult != WAIT_OBJECT_0)
  180965. {
  180966. CancelIo (intern->pipeH);
  180967. WaitForSingleObject (over.hEvent, INFINITE);
  180968. }
  180969. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180970. {
  180971. bytesWritten = (int) numWritten;
  180972. }
  180973. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180974. {
  180975. intern->disconnect();
  180976. }
  180977. }
  180978. CloseHandle (over.hEvent);
  180979. }
  180980. return bytesWritten;
  180981. }
  180982. void NamedPipe::cancelPendingReads()
  180983. {
  180984. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180985. if (intern != 0)
  180986. SetEvent (intern->cancelEvent);
  180987. }
  180988. #endif
  180989. /*** End of inlined file: juce_win32_Files.cpp ***/
  180990. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180991. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180992. // compiled on its own).
  180993. #if JUCE_INCLUDED_FILE
  180994. #ifndef INTERNET_FLAG_NEED_FILE
  180995. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180996. #endif
  180997. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180998. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180999. #endif
  181000. bool juce_isOnLine()
  181001. {
  181002. DWORD connectionType;
  181003. return InternetGetConnectedState (&connectionType, 0) != 0
  181004. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  181005. }
  181006. struct ConnectionAndRequestStruct
  181007. {
  181008. HINTERNET connection, request;
  181009. };
  181010. static HINTERNET sessionHandle = 0;
  181011. #ifndef WORKAROUND_TIMEOUT_BUG
  181012. //#define WORKAROUND_TIMEOUT_BUG 1
  181013. #endif
  181014. #if WORKAROUND_TIMEOUT_BUG
  181015. // Required because of a Microsoft bug in setting a timeout
  181016. class InternetConnectThread : public Thread
  181017. {
  181018. public:
  181019. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  181020. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  181021. {
  181022. startThread();
  181023. }
  181024. ~InternetConnectThread()
  181025. {
  181026. stopThread (60000);
  181027. }
  181028. void run()
  181029. {
  181030. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  181031. uc.nPort, _T(""), _T(""),
  181032. isFtp ? INTERNET_SERVICE_FTP
  181033. : INTERNET_SERVICE_HTTP,
  181034. 0, 0);
  181035. notify();
  181036. }
  181037. juce_UseDebuggingNewOperator
  181038. private:
  181039. URL_COMPONENTS& uc;
  181040. HINTERNET& connection;
  181041. const bool isFtp;
  181042. InternetConnectThread (const InternetConnectThread&);
  181043. InternetConnectThread& operator= (const InternetConnectThread&);
  181044. };
  181045. #endif
  181046. void* juce_openInternetFile (const String& url,
  181047. const String& headers,
  181048. const MemoryBlock& postData,
  181049. const bool isPost,
  181050. URL::OpenStreamProgressCallback* callback,
  181051. void* callbackContext,
  181052. int timeOutMs)
  181053. {
  181054. if (sessionHandle == 0)
  181055. sessionHandle = InternetOpen (_T("juce"),
  181056. INTERNET_OPEN_TYPE_PRECONFIG,
  181057. 0, 0, 0);
  181058. if (sessionHandle != 0)
  181059. {
  181060. // break up the url..
  181061. TCHAR file[1024], server[1024];
  181062. URL_COMPONENTS uc;
  181063. zerostruct (uc);
  181064. uc.dwStructSize = sizeof (uc);
  181065. uc.dwUrlPathLength = sizeof (file);
  181066. uc.dwHostNameLength = sizeof (server);
  181067. uc.lpszUrlPath = file;
  181068. uc.lpszHostName = server;
  181069. if (InternetCrackUrl (url, 0, 0, &uc))
  181070. {
  181071. int disable = 1;
  181072. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  181073. if (timeOutMs == 0)
  181074. timeOutMs = 30000;
  181075. else if (timeOutMs < 0)
  181076. timeOutMs = -1;
  181077. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  181078. const bool isFtp = url.startsWithIgnoreCase (T("ftp:"));
  181079. #if WORKAROUND_TIMEOUT_BUG
  181080. HINTERNET connection = 0;
  181081. {
  181082. InternetConnectThread connectThread (uc, connection, isFtp);
  181083. connectThread.wait (timeOutMs);
  181084. if (connection == 0)
  181085. {
  181086. InternetCloseHandle (sessionHandle);
  181087. sessionHandle = 0;
  181088. }
  181089. }
  181090. #else
  181091. HINTERNET connection = InternetConnect (sessionHandle,
  181092. uc.lpszHostName,
  181093. uc.nPort,
  181094. _T(""), _T(""),
  181095. isFtp ? INTERNET_SERVICE_FTP
  181096. : INTERNET_SERVICE_HTTP,
  181097. 0, 0);
  181098. #endif
  181099. if (connection != 0)
  181100. {
  181101. if (isFtp)
  181102. {
  181103. HINTERNET request = FtpOpenFile (connection,
  181104. uc.lpszUrlPath,
  181105. GENERIC_READ,
  181106. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  181107. 0);
  181108. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  181109. result->connection = connection;
  181110. result->request = request;
  181111. return result;
  181112. }
  181113. else
  181114. {
  181115. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  181116. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  181117. if (url.startsWithIgnoreCase (T("https:")))
  181118. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  181119. // IE7 seems to automatically work out when it's https)
  181120. HINTERNET request = HttpOpenRequest (connection,
  181121. isPost ? _T("POST")
  181122. : _T("GET"),
  181123. uc.lpszUrlPath,
  181124. 0, 0, mimeTypes, flags, 0);
  181125. if (request != 0)
  181126. {
  181127. INTERNET_BUFFERS buffers;
  181128. zerostruct (buffers);
  181129. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  181130. buffers.lpcszHeader = (LPCTSTR) headers;
  181131. buffers.dwHeadersLength = headers.length();
  181132. buffers.dwBufferTotal = (DWORD) postData.getSize();
  181133. ConnectionAndRequestStruct* result = 0;
  181134. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  181135. {
  181136. int bytesSent = 0;
  181137. for (;;)
  181138. {
  181139. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  181140. DWORD bytesDone = 0;
  181141. if (bytesToDo > 0
  181142. && ! InternetWriteFile (request,
  181143. ((const char*) postData.getData()) + bytesSent,
  181144. bytesToDo, &bytesDone))
  181145. {
  181146. break;
  181147. }
  181148. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  181149. {
  181150. result = new ConnectionAndRequestStruct();
  181151. result->connection = connection;
  181152. result->request = request;
  181153. HttpEndRequest (request, 0, 0, 0);
  181154. return result;
  181155. }
  181156. bytesSent += bytesDone;
  181157. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  181158. break;
  181159. }
  181160. }
  181161. InternetCloseHandle (request);
  181162. }
  181163. InternetCloseHandle (connection);
  181164. }
  181165. }
  181166. }
  181167. }
  181168. return 0;
  181169. }
  181170. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  181171. {
  181172. DWORD bytesRead = 0;
  181173. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181174. if (crs != 0)
  181175. InternetReadFile (crs->request,
  181176. buffer, bytesToRead,
  181177. &bytesRead);
  181178. return bytesRead;
  181179. }
  181180. int juce_seekInInternetFile (void* handle, int newPosition)
  181181. {
  181182. if (handle != 0)
  181183. {
  181184. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181185. return InternetSetFilePointer (crs->request,
  181186. newPosition, 0,
  181187. FILE_BEGIN, 0);
  181188. }
  181189. else
  181190. {
  181191. return -1;
  181192. }
  181193. }
  181194. int64 juce_getInternetFileContentLength (void* handle)
  181195. {
  181196. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181197. if (crs != 0)
  181198. {
  181199. DWORD index = 0;
  181200. DWORD result = 0;
  181201. DWORD size = sizeof (result);
  181202. if (HttpQueryInfo (crs->request,
  181203. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  181204. &result,
  181205. &size,
  181206. &index))
  181207. {
  181208. return (int64) result;
  181209. }
  181210. }
  181211. return -1;
  181212. }
  181213. void juce_closeInternetFile (void* handle)
  181214. {
  181215. if (handle != 0)
  181216. {
  181217. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  181218. InternetCloseHandle (crs->request);
  181219. InternetCloseHandle (crs->connection);
  181220. delete crs;
  181221. }
  181222. }
  181223. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  181224. {
  181225. int numFound = 0;
  181226. DynamicLibraryLoader dll ("iphlpapi.dll");
  181227. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  181228. if (getAdaptersInfo != 0)
  181229. {
  181230. ULONG len = sizeof (IP_ADAPTER_INFO);
  181231. MemoryBlock mb;
  181232. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181233. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  181234. {
  181235. mb.setSize (len);
  181236. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181237. }
  181238. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  181239. {
  181240. PIP_ADAPTER_INFO adapter = adapterInfo;
  181241. while (adapter != 0)
  181242. {
  181243. int64 mac = 0;
  181244. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  181245. mac = (mac << 8) | adapter->Address[i];
  181246. if (littleEndian)
  181247. mac = (int64) ByteOrder::swap ((uint64) mac);
  181248. if (numFound < maxNum && mac != 0)
  181249. addresses [numFound++] = mac;
  181250. adapter = adapter->Next;
  181251. }
  181252. }
  181253. }
  181254. return numFound;
  181255. }
  181256. struct ASTAT
  181257. {
  181258. ADAPTER_STATUS adapt;
  181259. NAME_BUFFER NameBuff [30];
  181260. };
  181261. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  181262. {
  181263. int numFound = 0;
  181264. DynamicLibraryLoader dll ("netapi32.dll");
  181265. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  181266. if (NetbiosCall != 0)
  181267. {
  181268. NCB ncb;
  181269. zerostruct (ncb);
  181270. ASTAT astat;
  181271. zerostruct (astat);
  181272. LANA_ENUM enums;
  181273. zerostruct (enums);
  181274. ncb.ncb_command = NCBENUM;
  181275. ncb.ncb_buffer = (unsigned char*) &enums;
  181276. ncb.ncb_length = sizeof (LANA_ENUM);
  181277. NetbiosCall (&ncb);
  181278. for (int i = 0; i < enums.length; ++i)
  181279. {
  181280. zerostruct (ncb);
  181281. ncb.ncb_command = NCBRESET;
  181282. ncb.ncb_lana_num = enums.lana[i];
  181283. if (NetbiosCall (&ncb) == 0)
  181284. {
  181285. zerostruct (ncb);
  181286. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  181287. ncb.ncb_command = NCBASTAT;
  181288. ncb.ncb_lana_num = enums.lana[i];
  181289. ncb.ncb_buffer = (unsigned char*) &astat;
  181290. ncb.ncb_length = sizeof (ASTAT);
  181291. if (NetbiosCall (&ncb) == 0)
  181292. {
  181293. if (astat.adapt.adapter_type == 0xfe)
  181294. {
  181295. uint64 mac = 0;
  181296. for (int i = 6; --i >= 0;)
  181297. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  181298. if (numFound < maxNum && mac != 0)
  181299. addresses [numFound++] = mac;
  181300. }
  181301. }
  181302. }
  181303. }
  181304. }
  181305. return numFound;
  181306. }
  181307. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  181308. {
  181309. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  181310. if (numFound == 0)
  181311. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  181312. return numFound;
  181313. }
  181314. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  181315. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  181316. const String& emailSubject,
  181317. const String& bodyText,
  181318. const StringArray& filesToAttach)
  181319. {
  181320. HMODULE h = LoadLibraryA ("MAPI32.dll");
  181321. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  181322. bool ok = false;
  181323. if (mapiSendMail != 0)
  181324. {
  181325. MapiMessage message;
  181326. zerostruct (message);
  181327. message.lpszSubject = (LPSTR) (LPCSTR) emailSubject;
  181328. message.lpszNoteText = (LPSTR) (LPCSTR) bodyText;
  181329. MapiRecipDesc recip;
  181330. zerostruct (recip);
  181331. recip.ulRecipClass = MAPI_TO;
  181332. String targetEmailAddress_ (targetEmailAddress);
  181333. if (targetEmailAddress_.isEmpty())
  181334. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  181335. recip.lpszName = (LPSTR) (LPCSTR) targetEmailAddress_;
  181336. message.nRecipCount = 1;
  181337. message.lpRecips = &recip;
  181338. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  181339. mb.fillWith (0);
  181340. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  181341. message.nFileCount = filesToAttach.size();
  181342. message.lpFiles = files;
  181343. for (int i = 0; i < filesToAttach.size(); ++i)
  181344. {
  181345. files[i].nPosition = (ULONG) -1;
  181346. files[i].lpszPathName = (LPSTR) (LPCSTR) filesToAttach [i];
  181347. }
  181348. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  181349. }
  181350. FreeLibrary (h);
  181351. return ok;
  181352. }
  181353. #endif
  181354. /*** End of inlined file: juce_win32_Network.cpp ***/
  181355. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  181356. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181357. // compiled on its own).
  181358. #if JUCE_INCLUDED_FILE
  181359. static HKEY findKeyForPath (String name,
  181360. const bool createForWriting,
  181361. String& valueName)
  181362. {
  181363. HKEY rootKey = 0;
  181364. if (name.startsWithIgnoreCase (T("HKEY_CURRENT_USER\\")))
  181365. rootKey = HKEY_CURRENT_USER;
  181366. else if (name.startsWithIgnoreCase (T("HKEY_LOCAL_MACHINE\\")))
  181367. rootKey = HKEY_LOCAL_MACHINE;
  181368. else if (name.startsWithIgnoreCase (T("HKEY_CLASSES_ROOT\\")))
  181369. rootKey = HKEY_CLASSES_ROOT;
  181370. if (rootKey != 0)
  181371. {
  181372. name = name.substring (name.indexOfChar (T('\\')) + 1);
  181373. const int lastSlash = name.lastIndexOfChar (T('\\'));
  181374. valueName = name.substring (lastSlash + 1);
  181375. name = name.substring (0, lastSlash);
  181376. HKEY key;
  181377. DWORD result;
  181378. if (createForWriting)
  181379. {
  181380. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  181381. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  181382. return key;
  181383. }
  181384. else
  181385. {
  181386. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  181387. return key;
  181388. }
  181389. }
  181390. return 0;
  181391. }
  181392. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  181393. const String& defaultValue)
  181394. {
  181395. String valueName, result (defaultValue);
  181396. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181397. if (k != 0)
  181398. {
  181399. WCHAR buffer [2048];
  181400. unsigned long bufferSize = sizeof (buffer);
  181401. DWORD type = REG_SZ;
  181402. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  181403. {
  181404. if (type == REG_SZ)
  181405. result = buffer;
  181406. else if (type == REG_DWORD)
  181407. result = String ((int) *(DWORD*) buffer);
  181408. }
  181409. RegCloseKey (k);
  181410. }
  181411. return result;
  181412. }
  181413. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  181414. const String& value)
  181415. {
  181416. String valueName;
  181417. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181418. if (k != 0)
  181419. {
  181420. RegSetValueEx (k, valueName, 0, REG_SZ,
  181421. (const BYTE*) (const WCHAR*) value,
  181422. sizeof (WCHAR) * (value.length() + 1));
  181423. RegCloseKey (k);
  181424. }
  181425. }
  181426. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  181427. {
  181428. bool exists = false;
  181429. String valueName;
  181430. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181431. if (k != 0)
  181432. {
  181433. unsigned char buffer [2048];
  181434. unsigned long bufferSize = sizeof (buffer);
  181435. DWORD type = 0;
  181436. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  181437. exists = true;
  181438. RegCloseKey (k);
  181439. }
  181440. return exists;
  181441. }
  181442. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  181443. {
  181444. String valueName;
  181445. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181446. if (k != 0)
  181447. {
  181448. RegDeleteValue (k, valueName);
  181449. RegCloseKey (k);
  181450. }
  181451. }
  181452. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  181453. {
  181454. String valueName;
  181455. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  181456. if (k != 0)
  181457. {
  181458. RegDeleteKey (k, valueName);
  181459. RegCloseKey (k);
  181460. }
  181461. }
  181462. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  181463. const String& symbolicDescription,
  181464. const String& fullDescription,
  181465. const File& targetExecutable,
  181466. int iconResourceNumber)
  181467. {
  181468. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  181469. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  181470. if (iconResourceNumber != 0)
  181471. setRegistryValue (key + "\\DefaultIcon\\",
  181472. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  181473. setRegistryValue (key + "\\", fullDescription);
  181474. setRegistryValue (key + "\\shell\\open\\command\\",
  181475. targetExecutable.getFullPathName() + " %1");
  181476. }
  181477. bool juce_IsRunningInWine()
  181478. {
  181479. HKEY key;
  181480. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  181481. {
  181482. RegCloseKey (key);
  181483. return true;
  181484. }
  181485. return false;
  181486. }
  181487. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  181488. {
  181489. String s (::GetCommandLineW());
  181490. StringArray tokens;
  181491. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  181492. return tokens.joinIntoString (T(" "), 1);
  181493. }
  181494. static void* currentModuleHandle = 0;
  181495. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  181496. {
  181497. if (currentModuleHandle == 0)
  181498. currentModuleHandle = GetModuleHandle (0);
  181499. return currentModuleHandle;
  181500. }
  181501. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  181502. {
  181503. currentModuleHandle = newHandle;
  181504. }
  181505. void PlatformUtilities::fpuReset()
  181506. {
  181507. #if JUCE_MSVC
  181508. _clearfp();
  181509. #endif
  181510. }
  181511. void PlatformUtilities::beep()
  181512. {
  181513. MessageBeep (MB_OK);
  181514. }
  181515. #endif
  181516. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  181517. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  181518. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  181519. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181520. // compiled on its own).
  181521. #if JUCE_INCLUDED_FILE
  181522. static const unsigned int specialId = WM_APP + 0x4400;
  181523. static const unsigned int broadcastId = WM_APP + 0x4403;
  181524. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  181525. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  181526. HWND juce_messageWindowHandle = 0;
  181527. extern long improbableWindowNumber; // defined in windowing.cpp
  181528. #ifndef WM_APPCOMMAND
  181529. #define WM_APPCOMMAND 0x0319
  181530. #endif
  181531. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  181532. const UINT message,
  181533. const WPARAM wParam,
  181534. const LPARAM lParam) throw()
  181535. {
  181536. JUCE_TRY
  181537. {
  181538. if (h == juce_messageWindowHandle)
  181539. {
  181540. if (message == specialCallbackId)
  181541. {
  181542. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  181543. return (LRESULT) (*func) ((void*) lParam);
  181544. }
  181545. else if (message == specialId)
  181546. {
  181547. // these are trapped early in the dispatch call, but must also be checked
  181548. // here in case there are windows modal dialog boxes doing their own
  181549. // dispatch loop and not calling our version
  181550. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  181551. return 0;
  181552. }
  181553. else if (message == broadcastId)
  181554. {
  181555. const ScopedPointer <String> messageString ((String*) lParam);
  181556. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  181557. return 0;
  181558. }
  181559. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  181560. {
  181561. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  181562. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  181563. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  181564. return 0;
  181565. }
  181566. }
  181567. }
  181568. JUCE_CATCH_EXCEPTION
  181569. return DefWindowProc (h, message, wParam, lParam);
  181570. }
  181571. static bool isEventBlockedByModalComps (MSG& m)
  181572. {
  181573. if (Component::getNumCurrentlyModalComponents() == 0
  181574. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  181575. return false;
  181576. switch (m.message)
  181577. {
  181578. case WM_MOUSEMOVE:
  181579. case WM_NCMOUSEMOVE:
  181580. case 0x020A: /* WM_MOUSEWHEEL */
  181581. case 0x020E: /* WM_MOUSEHWHEEL */
  181582. case WM_KEYUP:
  181583. case WM_SYSKEYUP:
  181584. case WM_CHAR:
  181585. case WM_APPCOMMAND:
  181586. case WM_LBUTTONUP:
  181587. case WM_MBUTTONUP:
  181588. case WM_RBUTTONUP:
  181589. case WM_MOUSEACTIVATE:
  181590. case WM_NCMOUSEHOVER:
  181591. case WM_MOUSEHOVER:
  181592. return true;
  181593. case WM_NCLBUTTONDOWN:
  181594. case WM_NCLBUTTONDBLCLK:
  181595. case WM_NCRBUTTONDOWN:
  181596. case WM_NCRBUTTONDBLCLK:
  181597. case WM_NCMBUTTONDOWN:
  181598. case WM_NCMBUTTONDBLCLK:
  181599. case WM_LBUTTONDOWN:
  181600. case WM_LBUTTONDBLCLK:
  181601. case WM_MBUTTONDOWN:
  181602. case WM_MBUTTONDBLCLK:
  181603. case WM_RBUTTONDOWN:
  181604. case WM_RBUTTONDBLCLK:
  181605. case WM_KEYDOWN:
  181606. case WM_SYSKEYDOWN:
  181607. {
  181608. Component* const modal = Component::getCurrentlyModalComponent (0);
  181609. if (modal != 0)
  181610. modal->inputAttemptWhenModal();
  181611. return true;
  181612. }
  181613. default:
  181614. break;
  181615. }
  181616. return false;
  181617. }
  181618. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181619. {
  181620. MSG m;
  181621. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181622. return false;
  181623. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181624. {
  181625. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181626. {
  181627. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181628. }
  181629. else if (m.message == WM_QUIT)
  181630. {
  181631. if (JUCEApplication::getInstance())
  181632. JUCEApplication::getInstance()->systemRequestedQuit();
  181633. }
  181634. else if (! isEventBlockedByModalComps (m))
  181635. {
  181636. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181637. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181638. {
  181639. // if it's someone else's window being clicked on, and the focus is
  181640. // currently on a juce window, pass the kb focus over..
  181641. HWND currentFocus = GetFocus();
  181642. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181643. SetFocus (m.hwnd);
  181644. }
  181645. TranslateMessage (&m);
  181646. DispatchMessage (&m);
  181647. }
  181648. }
  181649. return true;
  181650. }
  181651. bool juce_postMessageToSystemQueue (void* message)
  181652. {
  181653. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181654. }
  181655. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181656. void* userData)
  181657. {
  181658. if (MessageManager::getInstance()->isThisTheMessageThread())
  181659. {
  181660. return (*callback) (userData);
  181661. }
  181662. else
  181663. {
  181664. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181665. // deadlock because the message manager is blocked from running, and can't
  181666. // call your function..
  181667. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181668. return (void*) SendMessage (juce_messageWindowHandle,
  181669. specialCallbackId,
  181670. (WPARAM) callback,
  181671. (LPARAM) userData);
  181672. }
  181673. }
  181674. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181675. {
  181676. if (hwnd != juce_messageWindowHandle)
  181677. (reinterpret_cast <VoidArray*> (lParam))->add ((void*) hwnd);
  181678. return TRUE;
  181679. }
  181680. void MessageManager::broadcastMessage (const String& value) throw()
  181681. {
  181682. VoidArray windows;
  181683. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181684. const String localCopy (value);
  181685. COPYDATASTRUCT data;
  181686. data.dwData = broadcastId;
  181687. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181688. data.lpData = (void*) (const juce_wchar*) localCopy;
  181689. for (int i = windows.size(); --i >= 0;)
  181690. {
  181691. HWND hwnd = (HWND) windows.getUnchecked(i);
  181692. TCHAR windowName [64]; // no need to read longer strings than this
  181693. GetWindowText (hwnd, windowName, 64);
  181694. windowName [63] = 0;
  181695. if (String (windowName) == String (messageWindowName))
  181696. {
  181697. DWORD_PTR result;
  181698. SendMessageTimeout (hwnd, WM_COPYDATA,
  181699. (WPARAM) juce_messageWindowHandle,
  181700. (LPARAM) &data,
  181701. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181702. 8000,
  181703. &result);
  181704. }
  181705. }
  181706. }
  181707. static const String getMessageWindowClassName()
  181708. {
  181709. // this name has to be different for each app/dll instance because otherwise
  181710. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181711. // window class).
  181712. static int number = 0;
  181713. if (number == 0)
  181714. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181715. return T("JUCEcs_") + String (number);
  181716. }
  181717. void MessageManager::doPlatformSpecificInitialisation()
  181718. {
  181719. OleInitialize (0);
  181720. const String className (getMessageWindowClassName());
  181721. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181722. WNDCLASSEX wc;
  181723. zerostruct (wc);
  181724. wc.cbSize = sizeof (wc);
  181725. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181726. wc.cbWndExtra = 4;
  181727. wc.hInstance = hmod;
  181728. wc.lpszClassName = className;
  181729. RegisterClassEx (&wc);
  181730. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181731. messageWindowName,
  181732. 0, 0, 0, 0, 0, 0, 0,
  181733. hmod, 0);
  181734. }
  181735. void MessageManager::doPlatformSpecificShutdown()
  181736. {
  181737. DestroyWindow (juce_messageWindowHandle);
  181738. UnregisterClass (getMessageWindowClassName(), 0);
  181739. OleUninitialize();
  181740. }
  181741. #endif
  181742. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181743. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181744. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181745. // compiled on its own).
  181746. #if JUCE_INCLUDED_FILE
  181747. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181748. // these are in the windows SDK, but need to be repeated here for GCC..
  181749. #ifndef GET_APPCOMMAND_LPARAM
  181750. #define FAPPCOMMAND_MASK 0xF000
  181751. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181752. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181753. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181754. #define APPCOMMAND_MEDIA_STOP 13
  181755. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181756. #define WM_APPCOMMAND 0x0319
  181757. #endif
  181758. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181759. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181760. extern bool juce_IsRunningInWine();
  181761. #ifndef ULW_ALPHA
  181762. #define ULW_ALPHA 0x00000002
  181763. #endif
  181764. #ifndef AC_SRC_ALPHA
  181765. #define AC_SRC_ALPHA 0x01
  181766. #endif
  181767. #define DEBUG_REPAINT_TIMES 0
  181768. static HPALETTE palette = 0;
  181769. static bool createPaletteIfNeeded = true;
  181770. static bool shouldDeactivateTitleBar = true;
  181771. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181772. #define WM_TRAYNOTIFY WM_USER + 100
  181773. using ::abs;
  181774. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181775. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181776. bool Desktop::canUseSemiTransparentWindows() throw()
  181777. {
  181778. if (updateLayeredWindow == 0)
  181779. {
  181780. if (! juce_IsRunningInWine())
  181781. {
  181782. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181783. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181784. }
  181785. }
  181786. return updateLayeredWindow != 0;
  181787. }
  181788. #undef DefWindowProc
  181789. #define DefWindowProc DefWindowProcW
  181790. const int extendedKeyModifier = 0x10000;
  181791. const int KeyPress::spaceKey = VK_SPACE;
  181792. const int KeyPress::returnKey = VK_RETURN;
  181793. const int KeyPress::escapeKey = VK_ESCAPE;
  181794. const int KeyPress::backspaceKey = VK_BACK;
  181795. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181796. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181797. const int KeyPress::tabKey = VK_TAB;
  181798. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181799. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181800. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181801. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181802. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181803. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181804. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181805. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181806. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181807. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181808. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181809. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181810. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181811. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181812. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181813. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181814. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181815. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181816. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181817. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181818. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181819. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181820. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181821. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181822. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181823. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181824. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181825. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181826. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181827. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181828. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181829. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181830. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181831. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181832. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181833. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181834. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181835. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181836. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181837. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181838. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181839. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181840. const int KeyPress::playKey = 0x30000;
  181841. const int KeyPress::stopKey = 0x30001;
  181842. const int KeyPress::fastForwardKey = 0x30002;
  181843. const int KeyPress::rewindKey = 0x30003;
  181844. class WindowsBitmapImage : public Image
  181845. {
  181846. public:
  181847. HBITMAP hBitmap;
  181848. BITMAPV4HEADER bitmapInfo;
  181849. HDC hdc;
  181850. unsigned char* bitmapData;
  181851. WindowsBitmapImage (const PixelFormat format_,
  181852. const int w, const int h, const bool clearImage)
  181853. : Image (format_, w, h)
  181854. {
  181855. jassert (format_ == RGB || format_ == ARGB);
  181856. pixelStride = (format_ == RGB) ? 3 : 4;
  181857. zerostruct (bitmapInfo);
  181858. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181859. bitmapInfo.bV4Width = w;
  181860. bitmapInfo.bV4Height = h;
  181861. bitmapInfo.bV4Planes = 1;
  181862. bitmapInfo.bV4CSType = 1;
  181863. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181864. if (format_ == ARGB)
  181865. {
  181866. bitmapInfo.bV4AlphaMask = 0xff000000;
  181867. bitmapInfo.bV4RedMask = 0xff0000;
  181868. bitmapInfo.bV4GreenMask = 0xff00;
  181869. bitmapInfo.bV4BlueMask = 0xff;
  181870. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181871. }
  181872. else
  181873. {
  181874. bitmapInfo.bV4V4Compression = BI_RGB;
  181875. }
  181876. lineStride = -((w * pixelStride + 3) & ~3);
  181877. HDC dc = GetDC (0);
  181878. hdc = CreateCompatibleDC (dc);
  181879. ReleaseDC (0, dc);
  181880. SetMapMode (hdc, MM_TEXT);
  181881. hBitmap = CreateDIBSection (hdc,
  181882. (BITMAPINFO*) &(bitmapInfo),
  181883. DIB_RGB_COLORS,
  181884. (void**) &bitmapData,
  181885. 0, 0);
  181886. SelectObject (hdc, hBitmap);
  181887. if (format_ == ARGB && clearImage)
  181888. zeromem (bitmapData, abs (h * lineStride));
  181889. imageData = bitmapData - (lineStride * (h - 1));
  181890. }
  181891. ~WindowsBitmapImage()
  181892. {
  181893. DeleteDC (hdc);
  181894. DeleteObject (hBitmap);
  181895. }
  181896. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181897. const int x, const int y,
  181898. const RectangleList& maskedRegion) throw()
  181899. {
  181900. static HDRAWDIB hdd = 0;
  181901. static bool needToCreateDrawDib = true;
  181902. if (needToCreateDrawDib)
  181903. {
  181904. needToCreateDrawDib = false;
  181905. HDC dc = GetDC (0);
  181906. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181907. ReleaseDC (0, dc);
  181908. // only open if we're not palettised
  181909. if (n > 8)
  181910. hdd = DrawDibOpen();
  181911. }
  181912. if (createPaletteIfNeeded)
  181913. {
  181914. HDC dc = GetDC (0);
  181915. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181916. ReleaseDC (0, dc);
  181917. if (n <= 8)
  181918. palette = CreateHalftonePalette (dc);
  181919. createPaletteIfNeeded = false;
  181920. }
  181921. if (palette != 0)
  181922. {
  181923. SelectPalette (dc, palette, FALSE);
  181924. RealizePalette (dc);
  181925. SetStretchBltMode (dc, HALFTONE);
  181926. }
  181927. SetMapMode (dc, MM_TEXT);
  181928. if (transparent)
  181929. {
  181930. POINT p, pos;
  181931. SIZE size;
  181932. RECT windowBounds;
  181933. GetWindowRect (hwnd, &windowBounds);
  181934. p.x = -x;
  181935. p.y = -y;
  181936. pos.x = windowBounds.left;
  181937. pos.y = windowBounds.top;
  181938. size.cx = windowBounds.right - windowBounds.left;
  181939. size.cy = windowBounds.bottom - windowBounds.top;
  181940. BLENDFUNCTION bf;
  181941. bf.AlphaFormat = AC_SRC_ALPHA;
  181942. bf.BlendFlags = 0;
  181943. bf.BlendOp = AC_SRC_OVER;
  181944. bf.SourceConstantAlpha = 0xff;
  181945. if (! maskedRegion.isEmpty())
  181946. {
  181947. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181948. {
  181949. const Rectangle<int>& r = *i.getRectangle();
  181950. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181951. }
  181952. }
  181953. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181954. }
  181955. else
  181956. {
  181957. int savedDC = 0;
  181958. if (! maskedRegion.isEmpty())
  181959. {
  181960. savedDC = SaveDC (dc);
  181961. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181962. {
  181963. const Rectangle<int>& r = *i.getRectangle();
  181964. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181965. }
  181966. }
  181967. const int w = getWidth();
  181968. const int h = getHeight();
  181969. if (hdd == 0)
  181970. {
  181971. StretchDIBits (dc,
  181972. x, y, w, h,
  181973. 0, 0, w, h,
  181974. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181975. DIB_RGB_COLORS, SRCCOPY);
  181976. }
  181977. else
  181978. {
  181979. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181980. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181981. 0, 0, w, h, 0);
  181982. }
  181983. if (! maskedRegion.isEmpty())
  181984. RestoreDC (dc, savedDC);
  181985. }
  181986. }
  181987. juce_UseDebuggingNewOperator
  181988. private:
  181989. WindowsBitmapImage (const WindowsBitmapImage&);
  181990. const WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181991. };
  181992. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181993. static int currentModifiers = 0;
  181994. static int modifiersAtLastCallback = 0;
  181995. static void updateKeyModifiers() throw()
  181996. {
  181997. currentModifiers &= ~(ModifierKeys::shiftModifier
  181998. | ModifierKeys::ctrlModifier
  181999. | ModifierKeys::altModifier);
  182000. if ((GetKeyState (VK_SHIFT) & 0x8000) != 0)
  182001. currentModifiers |= ModifierKeys::shiftModifier;
  182002. if ((GetKeyState (VK_CONTROL) & 0x8000) != 0)
  182003. currentModifiers |= ModifierKeys::ctrlModifier;
  182004. if ((GetKeyState (VK_MENU) & 0x8000) != 0)
  182005. currentModifiers |= ModifierKeys::altModifier;
  182006. if ((GetKeyState (VK_RMENU) & 0x8000) != 0)
  182007. currentModifiers &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  182008. }
  182009. void ModifierKeys::updateCurrentModifiers() throw()
  182010. {
  182011. currentModifierFlags = currentModifiers;
  182012. }
  182013. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  182014. {
  182015. SHORT k = (SHORT) keyCode;
  182016. if ((keyCode & extendedKeyModifier) == 0
  182017. && (k >= (SHORT) T('a') && k <= (SHORT) T('z')))
  182018. k += (SHORT) T('A') - (SHORT) T('a');
  182019. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  182020. (SHORT) '+', VK_OEM_PLUS,
  182021. (SHORT) '-', VK_OEM_MINUS,
  182022. (SHORT) '.', VK_OEM_PERIOD,
  182023. (SHORT) ';', VK_OEM_1,
  182024. (SHORT) ':', VK_OEM_1,
  182025. (SHORT) '/', VK_OEM_2,
  182026. (SHORT) '?', VK_OEM_2,
  182027. (SHORT) '[', VK_OEM_4,
  182028. (SHORT) ']', VK_OEM_6 };
  182029. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  182030. if (k == translatedValues [i])
  182031. k = translatedValues [i + 1];
  182032. return (GetKeyState (k) & 0x8000) != 0;
  182033. }
  182034. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  182035. {
  182036. updateKeyModifiers();
  182037. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182038. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0)
  182039. currentModifiers |= ModifierKeys::leftButtonModifier;
  182040. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0)
  182041. currentModifiers |= ModifierKeys::rightButtonModifier;
  182042. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0)
  182043. currentModifiers |= ModifierKeys::middleButtonModifier;
  182044. return ModifierKeys (currentModifiers);
  182045. }
  182046. static int64 getMouseEventTime() throw()
  182047. {
  182048. static int64 eventTimeOffset = 0;
  182049. static DWORD lastMessageTime = 0;
  182050. const DWORD thisMessageTime = GetMessageTime();
  182051. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  182052. {
  182053. lastMessageTime = thisMessageTime;
  182054. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  182055. }
  182056. return eventTimeOffset + thisMessageTime;
  182057. }
  182058. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  182059. {
  182060. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  182061. return callback (userData);
  182062. else
  182063. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  182064. }
  182065. class Win32ComponentPeer : public ComponentPeer
  182066. {
  182067. public:
  182068. Win32ComponentPeer (Component* const component,
  182069. const int windowStyleFlags)
  182070. : ComponentPeer (component, windowStyleFlags),
  182071. dontRepaint (false),
  182072. fullScreen (false),
  182073. isDragging (false),
  182074. isMouseOver (false),
  182075. hasCreatedCaret (false),
  182076. currentWindowIcon (0),
  182077. taskBarIcon (0),
  182078. dropTarget (0)
  182079. {
  182080. callFunctionIfNotLocked (&createWindowCallback, (void*) this);
  182081. setTitle (component->getName());
  182082. if ((windowStyleFlags & windowHasDropShadow) != 0
  182083. && Desktop::canUseSemiTransparentWindows())
  182084. {
  182085. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  182086. if (shadower != 0)
  182087. shadower->setOwner (component);
  182088. }
  182089. else
  182090. {
  182091. shadower = 0;
  182092. }
  182093. }
  182094. ~Win32ComponentPeer()
  182095. {
  182096. setTaskBarIcon (0);
  182097. deleteAndZero (shadower);
  182098. // do this before the next bit to avoid messages arriving for this window
  182099. // before it's destroyed
  182100. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  182101. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  182102. if (currentWindowIcon != 0)
  182103. DestroyIcon (currentWindowIcon);
  182104. if (dropTarget != 0)
  182105. {
  182106. dropTarget->Release();
  182107. dropTarget = 0;
  182108. }
  182109. }
  182110. void* getNativeHandle() const
  182111. {
  182112. return (void*) hwnd;
  182113. }
  182114. void setVisible (bool shouldBeVisible)
  182115. {
  182116. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  182117. if (shouldBeVisible)
  182118. InvalidateRect (hwnd, 0, 0);
  182119. else
  182120. lastPaintTime = 0;
  182121. }
  182122. void setTitle (const String& title)
  182123. {
  182124. SetWindowText (hwnd, title);
  182125. }
  182126. void setPosition (int x, int y)
  182127. {
  182128. offsetWithinParent (x, y);
  182129. SetWindowPos (hwnd, 0,
  182130. x - windowBorder.getLeft(),
  182131. y - windowBorder.getTop(),
  182132. 0, 0,
  182133. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182134. }
  182135. void repaintNowIfTransparent()
  182136. {
  182137. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  182138. handlePaintMessage();
  182139. }
  182140. void updateBorderSize()
  182141. {
  182142. WINDOWINFO info;
  182143. info.cbSize = sizeof (info);
  182144. if (GetWindowInfo (hwnd, &info))
  182145. {
  182146. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  182147. info.rcClient.left - info.rcWindow.left,
  182148. info.rcWindow.bottom - info.rcClient.bottom,
  182149. info.rcWindow.right - info.rcClient.right);
  182150. }
  182151. }
  182152. void setSize (int w, int h)
  182153. {
  182154. SetWindowPos (hwnd, 0, 0, 0,
  182155. w + windowBorder.getLeftAndRight(),
  182156. h + windowBorder.getTopAndBottom(),
  182157. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182158. updateBorderSize();
  182159. repaintNowIfTransparent();
  182160. }
  182161. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  182162. {
  182163. fullScreen = isNowFullScreen;
  182164. offsetWithinParent (x, y);
  182165. SetWindowPos (hwnd, 0,
  182166. x - windowBorder.getLeft(),
  182167. y - windowBorder.getTop(),
  182168. w + windowBorder.getLeftAndRight(),
  182169. h + windowBorder.getTopAndBottom(),
  182170. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182171. updateBorderSize();
  182172. repaintNowIfTransparent();
  182173. }
  182174. void getBounds (int& x, int& y, int& w, int& h) const
  182175. {
  182176. RECT r;
  182177. GetWindowRect (hwnd, &r);
  182178. x = r.left;
  182179. y = r.top;
  182180. w = r.right - x;
  182181. h = r.bottom - y;
  182182. HWND parentH = GetParent (hwnd);
  182183. if (parentH != 0)
  182184. {
  182185. GetWindowRect (parentH, &r);
  182186. x -= r.left;
  182187. y -= r.top;
  182188. }
  182189. x += windowBorder.getLeft();
  182190. y += windowBorder.getTop();
  182191. w -= windowBorder.getLeftAndRight();
  182192. h -= windowBorder.getTopAndBottom();
  182193. }
  182194. int getScreenX() const
  182195. {
  182196. RECT r;
  182197. GetWindowRect (hwnd, &r);
  182198. return r.left + windowBorder.getLeft();
  182199. }
  182200. int getScreenY() const
  182201. {
  182202. RECT r;
  182203. GetWindowRect (hwnd, &r);
  182204. return r.top + windowBorder.getTop();
  182205. }
  182206. void relativePositionToGlobal (int& x, int& y)
  182207. {
  182208. RECT r;
  182209. GetWindowRect (hwnd, &r);
  182210. x += r.left + windowBorder.getLeft();
  182211. y += r.top + windowBorder.getTop();
  182212. }
  182213. void globalPositionToRelative (int& x, int& y)
  182214. {
  182215. RECT r;
  182216. GetWindowRect (hwnd, &r);
  182217. x -= r.left + windowBorder.getLeft();
  182218. y -= r.top + windowBorder.getTop();
  182219. }
  182220. void setMinimised (bool shouldBeMinimised)
  182221. {
  182222. if (shouldBeMinimised != isMinimised())
  182223. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  182224. }
  182225. bool isMinimised() const
  182226. {
  182227. WINDOWPLACEMENT wp;
  182228. wp.length = sizeof (WINDOWPLACEMENT);
  182229. GetWindowPlacement (hwnd, &wp);
  182230. return wp.showCmd == SW_SHOWMINIMIZED;
  182231. }
  182232. void setFullScreen (bool shouldBeFullScreen)
  182233. {
  182234. setMinimised (false);
  182235. if (fullScreen != shouldBeFullScreen)
  182236. {
  182237. fullScreen = shouldBeFullScreen;
  182238. const ComponentDeletionWatcher deletionChecker (component);
  182239. if (! fullScreen)
  182240. {
  182241. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  182242. if (hasTitleBar())
  182243. ShowWindow (hwnd, SW_SHOWNORMAL);
  182244. if (! boundsCopy.isEmpty())
  182245. {
  182246. setBounds (boundsCopy.getX(),
  182247. boundsCopy.getY(),
  182248. boundsCopy.getWidth(),
  182249. boundsCopy.getHeight(),
  182250. false);
  182251. }
  182252. }
  182253. else
  182254. {
  182255. if (hasTitleBar())
  182256. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  182257. else
  182258. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  182259. }
  182260. if (! deletionChecker.hasBeenDeleted())
  182261. handleMovedOrResized();
  182262. }
  182263. }
  182264. bool isFullScreen() const
  182265. {
  182266. if (! hasTitleBar())
  182267. return fullScreen;
  182268. WINDOWPLACEMENT wp;
  182269. wp.length = sizeof (wp);
  182270. GetWindowPlacement (hwnd, &wp);
  182271. return wp.showCmd == SW_SHOWMAXIMIZED;
  182272. }
  182273. bool contains (int x, int y, bool trueIfInAChildWindow) const
  182274. {
  182275. RECT r;
  182276. GetWindowRect (hwnd, &r);
  182277. POINT p;
  182278. p.x = x + r.left + windowBorder.getLeft();
  182279. p.y = y + r.top + windowBorder.getTop();
  182280. HWND w = WindowFromPoint (p);
  182281. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  182282. }
  182283. const BorderSize getFrameSize() const
  182284. {
  182285. return windowBorder;
  182286. }
  182287. bool setAlwaysOnTop (bool alwaysOnTop)
  182288. {
  182289. const bool oldDeactivate = shouldDeactivateTitleBar;
  182290. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182291. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  182292. 0, 0, 0, 0,
  182293. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182294. shouldDeactivateTitleBar = oldDeactivate;
  182295. if (shadower != 0)
  182296. shadower->componentBroughtToFront (*component);
  182297. return true;
  182298. }
  182299. void toFront (bool makeActive)
  182300. {
  182301. setMinimised (false);
  182302. const bool oldDeactivate = shouldDeactivateTitleBar;
  182303. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182304. callFunctionIfNotLocked (makeActive ? &toFrontCallback1
  182305. : &toFrontCallback2,
  182306. (void*) hwnd);
  182307. shouldDeactivateTitleBar = oldDeactivate;
  182308. if (! makeActive)
  182309. {
  182310. // in this case a broughttofront call won't have occured, so do it now..
  182311. handleBroughtToFront();
  182312. }
  182313. }
  182314. void toBehind (ComponentPeer* other)
  182315. {
  182316. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  182317. jassert (otherPeer != 0); // wrong type of window?
  182318. if (otherPeer != 0)
  182319. {
  182320. setMinimised (false);
  182321. // must be careful not to try to put a topmost window behind a normal one, or win32
  182322. // promotes the normal one to be topmost!
  182323. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  182324. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  182325. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182326. else if (otherPeer->getComponent()->isAlwaysOnTop())
  182327. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  182328. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182329. }
  182330. }
  182331. bool isFocused() const
  182332. {
  182333. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  182334. }
  182335. void grabFocus()
  182336. {
  182337. const bool oldDeactivate = shouldDeactivateTitleBar;
  182338. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182339. callFunctionIfNotLocked (&setFocusCallback, (void*) hwnd);
  182340. shouldDeactivateTitleBar = oldDeactivate;
  182341. }
  182342. void textInputRequired (int /*x*/, int /*y*/)
  182343. {
  182344. if (! hasCreatedCaret)
  182345. {
  182346. hasCreatedCaret = true;
  182347. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  182348. }
  182349. ShowCaret (hwnd);
  182350. SetCaretPos (0, 0);
  182351. }
  182352. void repaint (int x, int y, int w, int h)
  182353. {
  182354. const RECT r = { x, y, x + w, y + h };
  182355. InvalidateRect (hwnd, &r, FALSE);
  182356. }
  182357. void performAnyPendingRepaintsNow()
  182358. {
  182359. MSG m;
  182360. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  182361. DispatchMessage (&m);
  182362. }
  182363. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  182364. {
  182365. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  182366. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  182367. return 0;
  182368. }
  182369. void setTaskBarIcon (const Image* const image)
  182370. {
  182371. if (image != 0)
  182372. {
  182373. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  182374. if (taskBarIcon == 0)
  182375. {
  182376. taskBarIcon = new NOTIFYICONDATA();
  182377. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  182378. taskBarIcon->hWnd = (HWND) hwnd;
  182379. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  182380. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  182381. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  182382. taskBarIcon->hIcon = hicon;
  182383. taskBarIcon->szTip[0] = 0;
  182384. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  182385. }
  182386. else
  182387. {
  182388. HICON oldIcon = taskBarIcon->hIcon;
  182389. taskBarIcon->hIcon = hicon;
  182390. taskBarIcon->uFlags = NIF_ICON;
  182391. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182392. DestroyIcon (oldIcon);
  182393. }
  182394. DestroyIcon (hicon);
  182395. }
  182396. else if (taskBarIcon != 0)
  182397. {
  182398. taskBarIcon->uFlags = 0;
  182399. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  182400. DestroyIcon (taskBarIcon->hIcon);
  182401. deleteAndZero (taskBarIcon);
  182402. }
  182403. }
  182404. void setTaskBarIconToolTip (const String& toolTip) const
  182405. {
  182406. if (taskBarIcon != 0)
  182407. {
  182408. taskBarIcon->uFlags = NIF_TIP;
  182409. toolTip.copyToBuffer (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  182410. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182411. }
  182412. }
  182413. bool isInside (HWND h) const
  182414. {
  182415. return GetAncestor (hwnd, GA_ROOT) == h;
  182416. }
  182417. juce_UseDebuggingNewOperator
  182418. bool dontRepaint;
  182419. private:
  182420. HWND hwnd;
  182421. DropShadower* shadower;
  182422. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  182423. BorderSize windowBorder;
  182424. HICON currentWindowIcon;
  182425. NOTIFYICONDATA* taskBarIcon;
  182426. IDropTarget* dropTarget;
  182427. class TemporaryImage : public Timer
  182428. {
  182429. public:
  182430. TemporaryImage()
  182431. : image (0)
  182432. {
  182433. }
  182434. ~TemporaryImage()
  182435. {
  182436. delete image;
  182437. }
  182438. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  182439. {
  182440. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  182441. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  182442. {
  182443. delete image;
  182444. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  182445. }
  182446. startTimer (3000);
  182447. return image;
  182448. }
  182449. void timerCallback()
  182450. {
  182451. stopTimer();
  182452. deleteAndZero (image);
  182453. }
  182454. private:
  182455. WindowsBitmapImage* image;
  182456. TemporaryImage (const TemporaryImage&);
  182457. const TemporaryImage& operator= (const TemporaryImage&);
  182458. };
  182459. TemporaryImage offscreenImageGenerator;
  182460. class WindowClassHolder : public DeletedAtShutdown
  182461. {
  182462. public:
  182463. WindowClassHolder()
  182464. : windowClassName ("JUCE_")
  182465. {
  182466. // this name has to be different for each app/dll instance because otherwise
  182467. // poor old Win32 can get a bit confused (even despite it not being a process-global
  182468. // window class).
  182469. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  182470. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  182471. TCHAR moduleFile [1024];
  182472. moduleFile[0] = 0;
  182473. GetModuleFileName (moduleHandle, moduleFile, 1024);
  182474. WORD iconNum = 0;
  182475. WNDCLASSEX wcex;
  182476. wcex.cbSize = sizeof (wcex);
  182477. wcex.style = CS_OWNDC;
  182478. wcex.lpfnWndProc = (WNDPROC) windowProc;
  182479. wcex.lpszClassName = windowClassName;
  182480. wcex.cbClsExtra = 0;
  182481. wcex.cbWndExtra = 32;
  182482. wcex.hInstance = moduleHandle;
  182483. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182484. iconNum = 1;
  182485. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182486. wcex.hCursor = 0;
  182487. wcex.hbrBackground = 0;
  182488. wcex.lpszMenuName = 0;
  182489. RegisterClassEx (&wcex);
  182490. }
  182491. ~WindowClassHolder()
  182492. {
  182493. if (ComponentPeer::getNumPeers() == 0)
  182494. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  182495. clearSingletonInstance();
  182496. }
  182497. String windowClassName;
  182498. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  182499. };
  182500. static void* createWindowCallback (void* userData)
  182501. {
  182502. ((Win32ComponentPeer*) userData)->createWindow();
  182503. return 0;
  182504. }
  182505. void createWindow()
  182506. {
  182507. DWORD exstyle = WS_EX_ACCEPTFILES;
  182508. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  182509. if (hasTitleBar())
  182510. {
  182511. type |= WS_OVERLAPPED;
  182512. exstyle |= WS_EX_APPWINDOW;
  182513. if ((styleFlags & windowHasCloseButton) != 0)
  182514. {
  182515. type |= WS_SYSMENU;
  182516. }
  182517. else
  182518. {
  182519. // annoyingly, windows won't let you have a min/max button without a close button
  182520. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  182521. }
  182522. if ((styleFlags & windowIsResizable) != 0)
  182523. type |= WS_THICKFRAME;
  182524. }
  182525. else
  182526. {
  182527. type |= WS_POPUP | WS_SYSMENU;
  182528. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  182529. exstyle |= WS_EX_TOOLWINDOW;
  182530. else
  182531. exstyle |= WS_EX_APPWINDOW;
  182532. }
  182533. if ((styleFlags & windowHasMinimiseButton) != 0)
  182534. type |= WS_MINIMIZEBOX;
  182535. if ((styleFlags & windowHasMaximiseButton) != 0)
  182536. type |= WS_MAXIMIZEBOX;
  182537. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182538. exstyle |= WS_EX_TRANSPARENT;
  182539. if ((styleFlags & windowIsSemiTransparent) != 0
  182540. && Desktop::canUseSemiTransparentWindows())
  182541. exstyle |= WS_EX_LAYERED;
  182542. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  182543. if (hwnd != 0)
  182544. {
  182545. SetWindowLongPtr (hwnd, 0, 0);
  182546. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  182547. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  182548. if (dropTarget == 0)
  182549. dropTarget = new JuceDropTarget (this);
  182550. RegisterDragDrop (hwnd, dropTarget);
  182551. updateBorderSize();
  182552. // Calling this function here is (for some reason) necessary to make Windows
  182553. // correctly enable the menu items that we specify in the wm_initmenu message.
  182554. GetSystemMenu (hwnd, false);
  182555. }
  182556. else
  182557. {
  182558. jassertfalse
  182559. }
  182560. }
  182561. static void* destroyWindowCallback (void* handle)
  182562. {
  182563. RevokeDragDrop ((HWND) handle);
  182564. DestroyWindow ((HWND) handle);
  182565. return 0;
  182566. }
  182567. static void* toFrontCallback1 (void* h)
  182568. {
  182569. SetForegroundWindow ((HWND) h);
  182570. return 0;
  182571. }
  182572. static void* toFrontCallback2 (void* h)
  182573. {
  182574. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182575. return 0;
  182576. }
  182577. static void* setFocusCallback (void* h)
  182578. {
  182579. SetFocus ((HWND) h);
  182580. return 0;
  182581. }
  182582. static void* getFocusCallback (void*)
  182583. {
  182584. return (void*) GetFocus();
  182585. }
  182586. void offsetWithinParent (int& x, int& y) const
  182587. {
  182588. if (isTransparent())
  182589. {
  182590. HWND parentHwnd = GetParent (hwnd);
  182591. if (parentHwnd != 0)
  182592. {
  182593. RECT parentRect;
  182594. GetWindowRect (parentHwnd, &parentRect);
  182595. x += parentRect.left;
  182596. y += parentRect.top;
  182597. }
  182598. }
  182599. }
  182600. bool isTransparent() const
  182601. {
  182602. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  182603. }
  182604. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  182605. void setIcon (const Image& newIcon)
  182606. {
  182607. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182608. if (hicon != 0)
  182609. {
  182610. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182611. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182612. if (currentWindowIcon != 0)
  182613. DestroyIcon (currentWindowIcon);
  182614. currentWindowIcon = hicon;
  182615. }
  182616. }
  182617. void handlePaintMessage()
  182618. {
  182619. #if DEBUG_REPAINT_TIMES
  182620. const double paintStart = Time::getMillisecondCounterHiRes();
  182621. #endif
  182622. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182623. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182624. PAINTSTRUCT paintStruct;
  182625. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182626. // message and become re-entrant, but that's OK
  182627. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182628. // corrupt the image it's using to paint into, so do a check here.
  182629. static bool reentrant = false;
  182630. if (reentrant)
  182631. {
  182632. DeleteObject (rgn);
  182633. EndPaint (hwnd, &paintStruct);
  182634. return;
  182635. }
  182636. reentrant = true;
  182637. // this is the rectangle to update..
  182638. int x = paintStruct.rcPaint.left;
  182639. int y = paintStruct.rcPaint.top;
  182640. int w = paintStruct.rcPaint.right - x;
  182641. int h = paintStruct.rcPaint.bottom - y;
  182642. const bool transparent = isTransparent();
  182643. if (transparent)
  182644. {
  182645. // it's not possible to have a transparent window with a title bar at the moment!
  182646. jassert (! hasTitleBar());
  182647. RECT r;
  182648. GetWindowRect (hwnd, &r);
  182649. x = y = 0;
  182650. w = r.right - r.left;
  182651. h = r.bottom - r.top;
  182652. }
  182653. if (w > 0 && h > 0)
  182654. {
  182655. clearMaskedRegion();
  182656. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182657. RectangleList contextClip;
  182658. bool needToPaintAll = true;
  182659. if (regionType == COMPLEXREGION && ! transparent)
  182660. {
  182661. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182662. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182663. DeleteObject (clipRgn);
  182664. char rgnData [8192];
  182665. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182666. if (res > 0 && res <= sizeof (rgnData))
  182667. {
  182668. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182669. if (hdr->iType == RDH_RECTANGLES
  182670. && hdr->rcBound.right - hdr->rcBound.left >= w
  182671. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182672. {
  182673. needToPaintAll = false;
  182674. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182675. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182676. while (--num >= 0)
  182677. {
  182678. // (need to move this one pixel to the left because of a win32 bug)
  182679. const int cx = jmax (x, (int) rects->left - 1);
  182680. const int cy = rects->top;
  182681. const int cw = rects->right - cx;
  182682. const int ch = rects->bottom - rects->top;
  182683. if (cx + cw - x <= w && cy + ch - y <= h)
  182684. {
  182685. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  182686. }
  182687. else
  182688. {
  182689. needToPaintAll = true;
  182690. break;
  182691. }
  182692. ++rects;
  182693. }
  182694. }
  182695. }
  182696. }
  182697. if (needToPaintAll)
  182698. {
  182699. contextClip.clear();
  182700. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182701. }
  182702. if (transparent)
  182703. {
  182704. RectangleList::Iterator i (contextClip);
  182705. while (i.next())
  182706. {
  182707. const Rectangle<int>& r = *i.getRectangle();
  182708. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182709. }
  182710. }
  182711. // if the component's not opaque, this won't draw properly unless the platform can support this
  182712. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182713. updateCurrentModifiers();
  182714. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182715. context.clipToRectangleList (contextClip);
  182716. context.setOrigin (-x, -y);
  182717. handlePaint (context);
  182718. if (! dontRepaint)
  182719. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182720. }
  182721. DeleteObject (rgn);
  182722. EndPaint (hwnd, &paintStruct);
  182723. reentrant = false;
  182724. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182725. _fpreset(); // because some graphics cards can unmask FP exceptions
  182726. #endif
  182727. lastPaintTime = Time::getMillisecondCounter();
  182728. #if DEBUG_REPAINT_TIMES
  182729. const double elapsed = Time::getMillisecondCounterHiRes() - paintStart;
  182730. Logger::outputDebugString (T("repaint time: ") + String (elapsed, 2));
  182731. #endif
  182732. }
  182733. void doMouseMove (const int x, const int y)
  182734. {
  182735. static uint32 lastMouseTime = 0;
  182736. // this can be set to throttle the mouse-messages to less than a
  182737. // certain number per second, as things can get unresponsive
  182738. // if each drag or move callback has to do a lot of work.
  182739. const int maxMouseMovesPerSecond = 60;
  182740. const int64 mouseEventTime = getMouseEventTime();
  182741. if (! isMouseOver)
  182742. {
  182743. isMouseOver = true;
  182744. TRACKMOUSEEVENT tme;
  182745. tme.cbSize = sizeof (tme);
  182746. tme.dwFlags = TME_LEAVE;
  182747. tme.hwndTrack = hwnd;
  182748. tme.dwHoverTime = 0;
  182749. if (! TrackMouseEvent (&tme))
  182750. {
  182751. jassertfalse;
  182752. }
  182753. updateKeyModifiers();
  182754. handleMouseEnter (x, y, mouseEventTime);
  182755. }
  182756. else if (! isDragging)
  182757. {
  182758. if (((unsigned int) x) < (unsigned int) component->getWidth()
  182759. && ((unsigned int) y) < (unsigned int) component->getHeight())
  182760. {
  182761. RECT r;
  182762. GetWindowRect (hwnd, &r);
  182763. POINT p;
  182764. p.x = x + r.left + windowBorder.getLeft();
  182765. p.y = y + r.top + windowBorder.getTop();
  182766. if (WindowFromPoint (p) == hwnd)
  182767. {
  182768. const uint32 now = Time::getMillisecondCounter();
  182769. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182770. {
  182771. lastMouseTime = now;
  182772. handleMouseMove (x, y, mouseEventTime);
  182773. }
  182774. }
  182775. }
  182776. }
  182777. else
  182778. {
  182779. const uint32 now = Time::getMillisecondCounter();
  182780. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182781. {
  182782. lastMouseTime = now;
  182783. handleMouseDrag (x, y, mouseEventTime);
  182784. }
  182785. }
  182786. }
  182787. void doMouseDown (const int x, const int y, const WPARAM wParam)
  182788. {
  182789. if (GetCapture() != hwnd)
  182790. SetCapture (hwnd);
  182791. doMouseMove (x, y);
  182792. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182793. if ((wParam & MK_LBUTTON) != 0)
  182794. currentModifiers |= ModifierKeys::leftButtonModifier;
  182795. if ((wParam & MK_RBUTTON) != 0)
  182796. currentModifiers |= ModifierKeys::rightButtonModifier;
  182797. if ((wParam & MK_MBUTTON) != 0)
  182798. currentModifiers |= ModifierKeys::middleButtonModifier;
  182799. updateKeyModifiers();
  182800. isDragging = true;
  182801. handleMouseDown (x, y, getMouseEventTime());
  182802. }
  182803. void doMouseUp (const int x, const int y, const WPARAM wParam)
  182804. {
  182805. int numButtons = 0;
  182806. if ((wParam & MK_LBUTTON) != 0)
  182807. ++numButtons;
  182808. if ((wParam & MK_RBUTTON) != 0)
  182809. ++numButtons;
  182810. if ((wParam & MK_MBUTTON) != 0)
  182811. ++numButtons;
  182812. const int oldModifiers = currentModifiers;
  182813. // update the currentmodifiers only after the callback, so the callback
  182814. // knows which button was released.
  182815. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182816. if ((wParam & MK_LBUTTON) != 0)
  182817. currentModifiers |= ModifierKeys::leftButtonModifier;
  182818. if ((wParam & MK_RBUTTON) != 0)
  182819. currentModifiers |= ModifierKeys::rightButtonModifier;
  182820. if ((wParam & MK_MBUTTON) != 0)
  182821. currentModifiers |= ModifierKeys::middleButtonModifier;
  182822. updateKeyModifiers();
  182823. isDragging = false;
  182824. // release the mouse capture if the user's not still got a button down
  182825. if (numButtons == 0 && hwnd == GetCapture())
  182826. ReleaseCapture();
  182827. handleMouseUp (oldModifiers, x, y, getMouseEventTime());
  182828. }
  182829. void doCaptureChanged()
  182830. {
  182831. if (isDragging)
  182832. {
  182833. RECT wr;
  182834. GetWindowRect (hwnd, &wr);
  182835. const DWORD mp = GetMessagePos();
  182836. doMouseUp (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182837. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(),
  182838. (WPARAM) getMouseEventTime());
  182839. }
  182840. }
  182841. void doMouseExit()
  182842. {
  182843. if (isMouseOver)
  182844. {
  182845. isMouseOver = false;
  182846. RECT wr;
  182847. GetWindowRect (hwnd, &wr);
  182848. const DWORD mp = GetMessagePos();
  182849. handleMouseExit (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182850. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(),
  182851. getMouseEventTime());
  182852. }
  182853. }
  182854. void doMouseWheel (const WPARAM wParam, const bool isVertical)
  182855. {
  182856. updateKeyModifiers();
  182857. const int amount = jlimit (-1000, 1000, (int) (0.75f * (short) HIWORD (wParam)));
  182858. handleMouseWheel (isVertical ? 0 : amount,
  182859. isVertical ? amount : 0,
  182860. getMouseEventTime());
  182861. }
  182862. void sendModifierKeyChangeIfNeeded()
  182863. {
  182864. if (modifiersAtLastCallback != currentModifiers)
  182865. {
  182866. modifiersAtLastCallback = currentModifiers;
  182867. handleModifierKeysChange();
  182868. }
  182869. }
  182870. bool doKeyUp (const WPARAM key)
  182871. {
  182872. updateKeyModifiers();
  182873. switch (key)
  182874. {
  182875. case VK_SHIFT:
  182876. case VK_CONTROL:
  182877. case VK_MENU:
  182878. case VK_CAPITAL:
  182879. case VK_LWIN:
  182880. case VK_RWIN:
  182881. case VK_APPS:
  182882. case VK_NUMLOCK:
  182883. case VK_SCROLL:
  182884. case VK_LSHIFT:
  182885. case VK_RSHIFT:
  182886. case VK_LCONTROL:
  182887. case VK_LMENU:
  182888. case VK_RCONTROL:
  182889. case VK_RMENU:
  182890. sendModifierKeyChangeIfNeeded();
  182891. }
  182892. return handleKeyUpOrDown (false)
  182893. || Component::getCurrentlyModalComponent() != 0;
  182894. }
  182895. bool doKeyDown (const WPARAM key)
  182896. {
  182897. updateKeyModifiers();
  182898. bool used = false;
  182899. switch (key)
  182900. {
  182901. case VK_SHIFT:
  182902. case VK_LSHIFT:
  182903. case VK_RSHIFT:
  182904. case VK_CONTROL:
  182905. case VK_LCONTROL:
  182906. case VK_RCONTROL:
  182907. case VK_MENU:
  182908. case VK_LMENU:
  182909. case VK_RMENU:
  182910. case VK_LWIN:
  182911. case VK_RWIN:
  182912. case VK_CAPITAL:
  182913. case VK_NUMLOCK:
  182914. case VK_SCROLL:
  182915. case VK_APPS:
  182916. sendModifierKeyChangeIfNeeded();
  182917. break;
  182918. case VK_LEFT:
  182919. case VK_RIGHT:
  182920. case VK_UP:
  182921. case VK_DOWN:
  182922. case VK_PRIOR:
  182923. case VK_NEXT:
  182924. case VK_HOME:
  182925. case VK_END:
  182926. case VK_DELETE:
  182927. case VK_INSERT:
  182928. case VK_F1:
  182929. case VK_F2:
  182930. case VK_F3:
  182931. case VK_F4:
  182932. case VK_F5:
  182933. case VK_F6:
  182934. case VK_F7:
  182935. case VK_F8:
  182936. case VK_F9:
  182937. case VK_F10:
  182938. case VK_F11:
  182939. case VK_F12:
  182940. case VK_F13:
  182941. case VK_F14:
  182942. case VK_F15:
  182943. case VK_F16:
  182944. used = handleKeyUpOrDown (true);
  182945. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182946. break;
  182947. case VK_ADD:
  182948. case VK_SUBTRACT:
  182949. case VK_MULTIPLY:
  182950. case VK_DIVIDE:
  182951. case VK_SEPARATOR:
  182952. case VK_DECIMAL:
  182953. used = handleKeyUpOrDown (true);
  182954. break;
  182955. default:
  182956. used = handleKeyUpOrDown (true);
  182957. {
  182958. MSG msg;
  182959. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182960. {
  182961. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182962. // manually generate the key-press event that matches this key-down.
  182963. const UINT keyChar = MapVirtualKey (key, 2);
  182964. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182965. }
  182966. }
  182967. break;
  182968. }
  182969. if (Component::getCurrentlyModalComponent() != 0)
  182970. used = true;
  182971. return used;
  182972. }
  182973. bool doKeyChar (int key, const LPARAM flags)
  182974. {
  182975. updateKeyModifiers();
  182976. juce_wchar textChar = (juce_wchar) key;
  182977. const int virtualScanCode = (flags >> 16) & 0xff;
  182978. if (key >= '0' && key <= '9')
  182979. {
  182980. switch (virtualScanCode) // check for a numeric keypad scan-code
  182981. {
  182982. case 0x52:
  182983. case 0x4f:
  182984. case 0x50:
  182985. case 0x51:
  182986. case 0x4b:
  182987. case 0x4c:
  182988. case 0x4d:
  182989. case 0x47:
  182990. case 0x48:
  182991. case 0x49:
  182992. key = (key - '0') + KeyPress::numberPad0;
  182993. break;
  182994. default:
  182995. break;
  182996. }
  182997. }
  182998. else
  182999. {
  183000. // convert the scan code to an unmodified character code..
  183001. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  183002. UINT keyChar = MapVirtualKey (virtualKey, 2);
  183003. keyChar = LOWORD (keyChar);
  183004. if (keyChar != 0)
  183005. key = (int) keyChar;
  183006. // avoid sending junk text characters for some control-key combinations
  183007. if (textChar < ' ' && (currentModifiers & (ModifierKeys::ctrlModifier | ModifierKeys::altModifier)) != 0)
  183008. textChar = 0;
  183009. }
  183010. return handleKeyPress (key, textChar);
  183011. }
  183012. bool doAppCommand (const LPARAM lParam)
  183013. {
  183014. int key = 0;
  183015. switch (GET_APPCOMMAND_LPARAM (lParam))
  183016. {
  183017. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  183018. key = KeyPress::playKey;
  183019. break;
  183020. case APPCOMMAND_MEDIA_STOP:
  183021. key = KeyPress::stopKey;
  183022. break;
  183023. case APPCOMMAND_MEDIA_NEXTTRACK:
  183024. key = KeyPress::fastForwardKey;
  183025. break;
  183026. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  183027. key = KeyPress::rewindKey;
  183028. break;
  183029. }
  183030. if (key != 0)
  183031. {
  183032. updateKeyModifiers();
  183033. if (hwnd == GetActiveWindow())
  183034. {
  183035. handleKeyPress (key, 0);
  183036. return true;
  183037. }
  183038. }
  183039. return false;
  183040. }
  183041. class JuceDropTarget : public IDropTarget
  183042. {
  183043. public:
  183044. JuceDropTarget (Win32ComponentPeer* const owner_)
  183045. : owner (owner_),
  183046. refCount (1)
  183047. {
  183048. }
  183049. virtual ~JuceDropTarget()
  183050. {
  183051. jassert (refCount == 0);
  183052. }
  183053. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183054. {
  183055. if (id == IID_IUnknown || id == IID_IDropTarget)
  183056. {
  183057. AddRef();
  183058. *result = this;
  183059. return S_OK;
  183060. }
  183061. *result = 0;
  183062. return E_NOINTERFACE;
  183063. }
  183064. ULONG __stdcall AddRef() { return ++refCount; }
  183065. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183066. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183067. {
  183068. updateFileList (pDataObject);
  183069. int x = mousePos.x, y = mousePos.y;
  183070. owner->globalPositionToRelative (x, y);
  183071. owner->handleFileDragMove (files, x, y);
  183072. *pdwEffect = DROPEFFECT_COPY;
  183073. return S_OK;
  183074. }
  183075. HRESULT __stdcall DragLeave()
  183076. {
  183077. owner->handleFileDragExit (files);
  183078. return S_OK;
  183079. }
  183080. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183081. {
  183082. int x = mousePos.x, y = mousePos.y;
  183083. owner->globalPositionToRelative (x, y);
  183084. owner->handleFileDragMove (files, x, y);
  183085. *pdwEffect = DROPEFFECT_COPY;
  183086. return S_OK;
  183087. }
  183088. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183089. {
  183090. updateFileList (pDataObject);
  183091. int x = mousePos.x, y = mousePos.y;
  183092. owner->globalPositionToRelative (x, y);
  183093. owner->handleFileDragDrop (files, x, y);
  183094. *pdwEffect = DROPEFFECT_COPY;
  183095. return S_OK;
  183096. }
  183097. private:
  183098. Win32ComponentPeer* const owner;
  183099. int refCount;
  183100. StringArray files;
  183101. void updateFileList (IDataObject* const pDataObject)
  183102. {
  183103. files.clear();
  183104. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183105. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183106. if (pDataObject->GetData (&format, &medium) == S_OK)
  183107. {
  183108. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  183109. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  183110. unsigned int i = 0;
  183111. if (pDropFiles->fWide)
  183112. {
  183113. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  183114. for (;;)
  183115. {
  183116. unsigned int len = 0;
  183117. while (i + len < totalLen && fname [i + len] != 0)
  183118. ++len;
  183119. if (len == 0)
  183120. break;
  183121. files.add (String (fname + i, len));
  183122. i += len + 1;
  183123. }
  183124. }
  183125. else
  183126. {
  183127. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  183128. for (;;)
  183129. {
  183130. unsigned int len = 0;
  183131. while (i + len < totalLen && fname [i + len] != 0)
  183132. ++len;
  183133. if (len == 0)
  183134. break;
  183135. files.add (String (fname + i, len));
  183136. i += len + 1;
  183137. }
  183138. }
  183139. GlobalUnlock (medium.hGlobal);
  183140. }
  183141. }
  183142. JuceDropTarget (const JuceDropTarget&);
  183143. const JuceDropTarget& operator= (const JuceDropTarget&);
  183144. };
  183145. void doSettingChange()
  183146. {
  183147. Desktop::getInstance().refreshMonitorSizes();
  183148. if (fullScreen && ! isMinimised())
  183149. {
  183150. const Rectangle<int> r (component->getParentMonitorArea());
  183151. SetWindowPos (hwnd, 0,
  183152. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  183153. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  183154. }
  183155. }
  183156. public:
  183157. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  183158. {
  183159. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  183160. if (peer != 0)
  183161. return peer->peerWindowProc (h, message, wParam, lParam);
  183162. return DefWindowProc (h, message, wParam, lParam);
  183163. }
  183164. private:
  183165. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  183166. {
  183167. if (isValidPeer (this))
  183168. {
  183169. switch (message)
  183170. {
  183171. case WM_NCHITTEST:
  183172. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  183173. return HTTRANSPARENT;
  183174. if (hasTitleBar())
  183175. break;
  183176. return HTCLIENT;
  183177. case WM_PAINT:
  183178. handlePaintMessage();
  183179. return 0;
  183180. case WM_NCPAINT:
  183181. if (wParam != 1)
  183182. handlePaintMessage();
  183183. if (hasTitleBar())
  183184. break;
  183185. return 0;
  183186. case WM_ERASEBKGND:
  183187. case WM_NCCALCSIZE:
  183188. if (hasTitleBar())
  183189. break;
  183190. return 1;
  183191. case WM_MOUSEMOVE:
  183192. doMouseMove (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  183193. return 0;
  183194. case WM_MOUSELEAVE:
  183195. doMouseExit();
  183196. return 0;
  183197. case WM_LBUTTONDOWN:
  183198. case WM_MBUTTONDOWN:
  183199. case WM_RBUTTONDOWN:
  183200. doMouseDown (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), wParam);
  183201. return 0;
  183202. case WM_LBUTTONUP:
  183203. case WM_MBUTTONUP:
  183204. case WM_RBUTTONUP:
  183205. doMouseUp (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), wParam);
  183206. return 0;
  183207. case WM_CAPTURECHANGED:
  183208. doCaptureChanged();
  183209. return 0;
  183210. case WM_NCMOUSEMOVE:
  183211. if (hasTitleBar())
  183212. break;
  183213. return 0;
  183214. case 0x020A: /* WM_MOUSEWHEEL */
  183215. doMouseWheel (wParam, true);
  183216. return 0;
  183217. case 0x020E: /* WM_MOUSEHWHEEL */
  183218. doMouseWheel (wParam, false);
  183219. return 0;
  183220. case WM_WINDOWPOSCHANGING:
  183221. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  183222. {
  183223. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  183224. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  183225. {
  183226. if (constrainer != 0)
  183227. {
  183228. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  183229. component->getY() - windowBorder.getTop(),
  183230. component->getWidth() + windowBorder.getLeftAndRight(),
  183231. component->getHeight() + windowBorder.getTopAndBottom());
  183232. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  183233. constrainer->checkBounds (pos, current,
  183234. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  183235. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  183236. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  183237. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  183238. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  183239. wp->x = pos.getX();
  183240. wp->y = pos.getY();
  183241. wp->cx = pos.getWidth();
  183242. wp->cy = pos.getHeight();
  183243. }
  183244. }
  183245. }
  183246. return 0;
  183247. case WM_WINDOWPOSCHANGED:
  183248. handleMovedOrResized();
  183249. if (dontRepaint)
  183250. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  183251. return 0;
  183252. case WM_KEYDOWN:
  183253. case WM_SYSKEYDOWN:
  183254. if (doKeyDown (wParam))
  183255. return 0;
  183256. break;
  183257. case WM_KEYUP:
  183258. case WM_SYSKEYUP:
  183259. if (doKeyUp (wParam))
  183260. return 0;
  183261. break;
  183262. case WM_CHAR:
  183263. if (doKeyChar ((int) wParam, lParam))
  183264. return 0;
  183265. break;
  183266. case WM_APPCOMMAND:
  183267. if (doAppCommand (lParam))
  183268. return TRUE;
  183269. break;
  183270. case WM_SETFOCUS:
  183271. updateKeyModifiers();
  183272. handleFocusGain();
  183273. break;
  183274. case WM_KILLFOCUS:
  183275. if (hasCreatedCaret)
  183276. {
  183277. hasCreatedCaret = false;
  183278. DestroyCaret();
  183279. }
  183280. handleFocusLoss();
  183281. break;
  183282. case WM_ACTIVATEAPP:
  183283. // Windows does weird things to process priority when you swap apps,
  183284. // so this forces an update when the app is brought to the front
  183285. if (wParam != FALSE)
  183286. juce_repeatLastProcessPriority();
  183287. else
  183288. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  183289. juce_CheckCurrentlyFocusedTopLevelWindow();
  183290. modifiersAtLastCallback = -1;
  183291. return 0;
  183292. case WM_ACTIVATE:
  183293. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  183294. {
  183295. modifiersAtLastCallback = -1;
  183296. updateKeyModifiers();
  183297. if (isMinimised())
  183298. {
  183299. component->repaint();
  183300. handleMovedOrResized();
  183301. if (! isValidMessageListener())
  183302. return 0;
  183303. }
  183304. if (LOWORD (wParam) == WA_CLICKACTIVE
  183305. && component->isCurrentlyBlockedByAnotherModalComponent())
  183306. {
  183307. int mx, my;
  183308. component->getMouseXYRelative (mx, my);
  183309. Component* const underMouse = component->getComponentAt (mx, my);
  183310. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  183311. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  183312. return 0;
  183313. }
  183314. handleBroughtToFront();
  183315. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183316. Component::getCurrentlyModalComponent()->toFront (true);
  183317. return 0;
  183318. }
  183319. break;
  183320. case WM_NCACTIVATE:
  183321. // while a temporary window is being shown, prevent Windows from deactivating the
  183322. // title bars of our main windows.
  183323. if (wParam == 0 && ! shouldDeactivateTitleBar)
  183324. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  183325. break;
  183326. case WM_MOUSEACTIVATE:
  183327. if (! component->getMouseClickGrabsKeyboardFocus())
  183328. return MA_NOACTIVATE;
  183329. break;
  183330. case WM_SHOWWINDOW:
  183331. if (wParam != 0)
  183332. handleBroughtToFront();
  183333. break;
  183334. case WM_CLOSE:
  183335. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  183336. handleUserClosingWindow();
  183337. return 0;
  183338. case WM_QUERYENDSESSION:
  183339. if (JUCEApplication::getInstance() != 0)
  183340. {
  183341. JUCEApplication::getInstance()->systemRequestedQuit();
  183342. return MessageManager::getInstance()->hasStopMessageBeenSent();
  183343. }
  183344. return TRUE;
  183345. case WM_TRAYNOTIFY:
  183346. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183347. {
  183348. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  183349. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183350. {
  183351. Component* const current = Component::getCurrentlyModalComponent();
  183352. if (current != 0)
  183353. current->inputAttemptWhenModal();
  183354. }
  183355. }
  183356. else
  183357. {
  183358. const int oldModifiers = currentModifiers;
  183359. MouseEvent e (0, 0, ModifierKeys::getCurrentModifiersRealtime(), component,
  183360. getMouseEventTime(), 0, 0, getMouseEventTime(), 1, false);
  183361. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  183362. e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::leftButtonModifier);
  183363. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  183364. e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::rightButtonModifier);
  183365. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  183366. {
  183367. SetFocus (hwnd);
  183368. SetForegroundWindow (hwnd);
  183369. component->mouseDown (e);
  183370. }
  183371. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  183372. {
  183373. e.mods = ModifierKeys (oldModifiers);
  183374. component->mouseUp (e);
  183375. }
  183376. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183377. {
  183378. e.mods = ModifierKeys (oldModifiers);
  183379. component->mouseDoubleClick (e);
  183380. }
  183381. else if (lParam == WM_MOUSEMOVE)
  183382. {
  183383. component->mouseMove (e);
  183384. }
  183385. }
  183386. break;
  183387. case WM_SYNCPAINT:
  183388. return 0;
  183389. case WM_PALETTECHANGED:
  183390. InvalidateRect (h, 0, 0);
  183391. break;
  183392. case WM_DISPLAYCHANGE:
  183393. InvalidateRect (h, 0, 0);
  183394. createPaletteIfNeeded = true;
  183395. // intentional fall-through...
  183396. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  183397. doSettingChange();
  183398. break;
  183399. case WM_INITMENU:
  183400. if (! hasTitleBar())
  183401. {
  183402. if (isFullScreen())
  183403. {
  183404. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  183405. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  183406. }
  183407. else if (! isMinimised())
  183408. {
  183409. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  183410. }
  183411. }
  183412. break;
  183413. case WM_SYSCOMMAND:
  183414. switch (wParam & 0xfff0)
  183415. {
  183416. case SC_CLOSE:
  183417. if (sendInputAttemptWhenModalMessage())
  183418. return 0;
  183419. if (hasTitleBar())
  183420. {
  183421. PostMessage (h, WM_CLOSE, 0, 0);
  183422. return 0;
  183423. }
  183424. break;
  183425. case SC_KEYMENU:
  183426. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  183427. // obscure situations that can arise if a modal loop is started from an alt-key
  183428. // keypress).
  183429. if (hasTitleBar() && h == GetCapture())
  183430. ReleaseCapture();
  183431. break;
  183432. case SC_MAXIMIZE:
  183433. if (sendInputAttemptWhenModalMessage())
  183434. return 0;
  183435. setFullScreen (true);
  183436. return 0;
  183437. case SC_MINIMIZE:
  183438. if (sendInputAttemptWhenModalMessage())
  183439. return 0;
  183440. if (! hasTitleBar())
  183441. {
  183442. setMinimised (true);
  183443. return 0;
  183444. }
  183445. break;
  183446. case SC_RESTORE:
  183447. if (sendInputAttemptWhenModalMessage())
  183448. return 0;
  183449. if (hasTitleBar())
  183450. {
  183451. if (isFullScreen())
  183452. {
  183453. setFullScreen (false);
  183454. return 0;
  183455. }
  183456. }
  183457. else
  183458. {
  183459. if (isMinimised())
  183460. setMinimised (false);
  183461. else if (isFullScreen())
  183462. setFullScreen (false);
  183463. return 0;
  183464. }
  183465. break;
  183466. }
  183467. break;
  183468. case WM_NCLBUTTONDOWN:
  183469. case WM_NCRBUTTONDOWN:
  183470. case WM_NCMBUTTONDOWN:
  183471. sendInputAttemptWhenModalMessage();
  183472. break;
  183473. //case WM_IME_STARTCOMPOSITION;
  183474. // return 0;
  183475. case WM_GETDLGCODE:
  183476. return DLGC_WANTALLKEYS;
  183477. default:
  183478. break;
  183479. }
  183480. }
  183481. return DefWindowProc (h, message, wParam, lParam);
  183482. }
  183483. bool sendInputAttemptWhenModalMessage()
  183484. {
  183485. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183486. {
  183487. Component* const current = Component::getCurrentlyModalComponent();
  183488. if (current != 0)
  183489. current->inputAttemptWhenModal();
  183490. return true;
  183491. }
  183492. return false;
  183493. }
  183494. Win32ComponentPeer (const Win32ComponentPeer&);
  183495. const Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  183496. };
  183497. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  183498. {
  183499. return new Win32ComponentPeer (this, styleFlags);
  183500. }
  183501. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  183502. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  183503. {
  183504. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183505. if (wp != 0)
  183506. wp->setTaskBarIcon (&newImage);
  183507. }
  183508. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  183509. {
  183510. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183511. if (wp != 0)
  183512. wp->setTaskBarIconToolTip (tooltip);
  183513. }
  183514. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  183515. {
  183516. DWORD val = GetWindowLong (h, styleType);
  183517. if (bitIsSet)
  183518. val |= feature;
  183519. else
  183520. val &= ~feature;
  183521. SetWindowLongPtr (h, styleType, val);
  183522. SetWindowPos (h, 0, 0, 0, 0, 0,
  183523. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  183524. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  183525. }
  183526. bool Process::isForegroundProcess()
  183527. {
  183528. HWND fg = GetForegroundWindow();
  183529. if (fg == 0)
  183530. return true;
  183531. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  183532. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  183533. // have to see if any of our windows are children of the foreground window
  183534. fg = GetAncestor (fg, GA_ROOT);
  183535. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  183536. {
  183537. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  183538. if (wp != 0 && wp->isInside (fg))
  183539. return true;
  183540. }
  183541. return false;
  183542. }
  183543. bool AlertWindow::showNativeDialogBox (const String& title,
  183544. const String& bodyText,
  183545. bool isOkCancel)
  183546. {
  183547. return MessageBox (0, bodyText, title,
  183548. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  183549. : MB_OK)) == IDOK;
  183550. }
  183551. void Desktop::getMousePosition (int& x, int& y) throw()
  183552. {
  183553. POINT mousePos;
  183554. GetCursorPos (&mousePos);
  183555. x = mousePos.x;
  183556. y = mousePos.y;
  183557. }
  183558. void Desktop::setMousePosition (int x, int y) throw()
  183559. {
  183560. SetCursorPos (x, y);
  183561. }
  183562. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  183563. {
  183564. return new Image (format, imageWidth, imageHeight, clearImage);
  183565. }
  183566. class ScreenSaverDefeater : public Timer,
  183567. public DeletedAtShutdown
  183568. {
  183569. public:
  183570. ScreenSaverDefeater() throw()
  183571. {
  183572. startTimer (10000);
  183573. timerCallback();
  183574. }
  183575. ~ScreenSaverDefeater() {}
  183576. void timerCallback()
  183577. {
  183578. if (Process::isForegroundProcess())
  183579. {
  183580. // simulate a shift key getting pressed..
  183581. INPUT input[2];
  183582. input[0].type = INPUT_KEYBOARD;
  183583. input[0].ki.wVk = VK_SHIFT;
  183584. input[0].ki.dwFlags = 0;
  183585. input[0].ki.dwExtraInfo = 0;
  183586. input[1].type = INPUT_KEYBOARD;
  183587. input[1].ki.wVk = VK_SHIFT;
  183588. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  183589. input[1].ki.dwExtraInfo = 0;
  183590. SendInput (2, input, sizeof (INPUT));
  183591. }
  183592. }
  183593. };
  183594. static ScreenSaverDefeater* screenSaverDefeater = 0;
  183595. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  183596. {
  183597. if (isEnabled)
  183598. {
  183599. deleteAndZero (screenSaverDefeater);
  183600. }
  183601. else if (screenSaverDefeater == 0)
  183602. {
  183603. screenSaverDefeater = new ScreenSaverDefeater();
  183604. }
  183605. }
  183606. bool Desktop::isScreenSaverEnabled() throw()
  183607. {
  183608. return screenSaverDefeater == 0;
  183609. }
  183610. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  183611. {
  183612. if (enableOrDisable)
  183613. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  183614. }
  183615. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  183616. {
  183617. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  183618. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  183619. return TRUE;
  183620. }
  183621. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  183622. {
  183623. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  183624. // make sure the first in the list is the main monitor
  183625. for (int i = 1; i < monitorCoords.size(); ++i)
  183626. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  183627. monitorCoords.swap (i, 0);
  183628. if (monitorCoords.size() == 0)
  183629. {
  183630. RECT r;
  183631. GetWindowRect (GetDesktopWindow(), &r);
  183632. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  183633. }
  183634. if (clipToWorkArea)
  183635. {
  183636. // clip the main monitor to the active non-taskbar area
  183637. RECT r;
  183638. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  183639. Rectangle<int>& screen = monitorCoords.getReference (0);
  183640. screen.setPosition (jmax (screen.getX(), (int) r.left),
  183641. jmax (screen.getY(), (int) r.top));
  183642. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  183643. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  183644. }
  183645. }
  183646. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183647. {
  183648. Image* im = 0;
  183649. if (bitmap != 0)
  183650. {
  183651. BITMAP bm;
  183652. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183653. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183654. {
  183655. HDC tempDC = GetDC (0);
  183656. HDC dc = CreateCompatibleDC (tempDC);
  183657. ReleaseDC (0, tempDC);
  183658. SelectObject (dc, bitmap);
  183659. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183660. for (int y = bm.bmHeight; --y >= 0;)
  183661. {
  183662. for (int x = bm.bmWidth; --x >= 0;)
  183663. {
  183664. COLORREF col = GetPixel (dc, x, y);
  183665. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183666. (uint8) GetGValue (col),
  183667. (uint8) GetBValue (col)));
  183668. }
  183669. }
  183670. DeleteDC (dc);
  183671. }
  183672. }
  183673. return im;
  183674. }
  183675. static Image* createImageFromHICON (HICON icon) throw()
  183676. {
  183677. ICONINFO info;
  183678. if (GetIconInfo (icon, &info))
  183679. {
  183680. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183681. if (mask == 0)
  183682. return 0;
  183683. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183684. if (image == 0)
  183685. return mask;
  183686. for (int y = image->getHeight(); --y >= 0;)
  183687. {
  183688. for (int x = image->getWidth(); --x >= 0;)
  183689. {
  183690. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183691. if (brightness > 0.0f)
  183692. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183693. }
  183694. }
  183695. delete mask;
  183696. return image;
  183697. }
  183698. return 0;
  183699. }
  183700. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183701. {
  183702. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183703. ICONINFO info;
  183704. info.fIcon = isIcon;
  183705. info.xHotspot = hotspotX;
  183706. info.yHotspot = hotspotY;
  183707. info.hbmMask = mask;
  183708. HICON hi = 0;
  183709. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183710. {
  183711. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183712. Graphics g (bitmap);
  183713. g.drawImageAt (&image, 0, 0);
  183714. info.hbmColor = bitmap.hBitmap;
  183715. hi = CreateIconIndirect (&info);
  183716. }
  183717. else
  183718. {
  183719. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183720. HDC colDC = CreateCompatibleDC (GetDC (0));
  183721. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183722. SelectObject (colDC, colour);
  183723. SelectObject (alphaDC, mask);
  183724. for (int y = image.getHeight(); --y >= 0;)
  183725. {
  183726. for (int x = image.getWidth(); --x >= 0;)
  183727. {
  183728. const Colour c (image.getPixelAt (x, y));
  183729. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183730. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183731. }
  183732. }
  183733. DeleteDC (colDC);
  183734. DeleteDC (alphaDC);
  183735. info.hbmColor = colour;
  183736. hi = CreateIconIndirect (&info);
  183737. DeleteObject (colour);
  183738. }
  183739. DeleteObject (mask);
  183740. return hi;
  183741. }
  183742. Image* juce_createIconForFile (const File& file)
  183743. {
  183744. Image* image = 0;
  183745. TCHAR filename [1024];
  183746. file.getFullPathName().copyToBuffer (filename, 1023);
  183747. WORD iconNum = 0;
  183748. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183749. filename, &iconNum);
  183750. if (icon != 0)
  183751. {
  183752. image = createImageFromHICON (icon);
  183753. DestroyIcon (icon);
  183754. }
  183755. return image;
  183756. }
  183757. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  183758. {
  183759. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183760. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183761. const Image* im = &image;
  183762. Image* newIm = 0;
  183763. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183764. {
  183765. im = newIm = image.createCopy (maxW, maxH);
  183766. hotspotX = (hotspotX * maxW) / image.getWidth();
  183767. hotspotY = (hotspotY * maxH) / image.getHeight();
  183768. }
  183769. void* cursorH = 0;
  183770. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183771. if (os == SystemStats::WinXP)
  183772. {
  183773. cursorH = (void*) createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183774. }
  183775. else
  183776. {
  183777. const int stride = (maxW + 7) >> 3;
  183778. HeapBlock <uint8> andPlane, xorPlane;
  183779. andPlane.calloc (stride * maxH);
  183780. xorPlane.calloc (stride * maxH);
  183781. int index = 0;
  183782. for (int y = 0; y < maxH; ++y)
  183783. {
  183784. for (int x = 0; x < maxW; ++x)
  183785. {
  183786. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183787. const Colour pixelColour (im->getPixelAt (x, y));
  183788. if (pixelColour.getAlpha() < 127)
  183789. andPlane [index + (x >> 3)] |= bit;
  183790. else if (pixelColour.getBrightness() >= 0.5f)
  183791. xorPlane [index + (x >> 3)] |= bit;
  183792. }
  183793. index += stride;
  183794. }
  183795. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183796. }
  183797. delete newIm;
  183798. return cursorH;
  183799. }
  183800. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  183801. {
  183802. if (cursorHandle != 0 && ! isStandard)
  183803. DestroyCursor ((HCURSOR) cursorHandle);
  183804. }
  183805. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  183806. {
  183807. LPCTSTR cursorName = IDC_ARROW;
  183808. switch (type)
  183809. {
  183810. case MouseCursor::NormalCursor:
  183811. cursorName = IDC_ARROW;
  183812. break;
  183813. case MouseCursor::NoCursor:
  183814. return 0;
  183815. case MouseCursor::DraggingHandCursor:
  183816. {
  183817. static void* dragHandCursor = 0;
  183818. if (dragHandCursor == 0)
  183819. {
  183820. static const unsigned char dragHandData[] =
  183821. { 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,
  183822. 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,
  183823. 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 };
  183824. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183825. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183826. }
  183827. return dragHandCursor;
  183828. }
  183829. case MouseCursor::WaitCursor:
  183830. cursorName = IDC_WAIT;
  183831. break;
  183832. case MouseCursor::IBeamCursor:
  183833. cursorName = IDC_IBEAM;
  183834. break;
  183835. case MouseCursor::PointingHandCursor:
  183836. cursorName = MAKEINTRESOURCE(32649);
  183837. break;
  183838. case MouseCursor::LeftRightResizeCursor:
  183839. case MouseCursor::LeftEdgeResizeCursor:
  183840. case MouseCursor::RightEdgeResizeCursor:
  183841. cursorName = IDC_SIZEWE;
  183842. break;
  183843. case MouseCursor::UpDownResizeCursor:
  183844. case MouseCursor::TopEdgeResizeCursor:
  183845. case MouseCursor::BottomEdgeResizeCursor:
  183846. cursorName = IDC_SIZENS;
  183847. break;
  183848. case MouseCursor::TopLeftCornerResizeCursor:
  183849. case MouseCursor::BottomRightCornerResizeCursor:
  183850. cursorName = IDC_SIZENWSE;
  183851. break;
  183852. case MouseCursor::TopRightCornerResizeCursor:
  183853. case MouseCursor::BottomLeftCornerResizeCursor:
  183854. cursorName = IDC_SIZENESW;
  183855. break;
  183856. case MouseCursor::UpDownLeftRightResizeCursor:
  183857. cursorName = IDC_SIZEALL;
  183858. break;
  183859. case MouseCursor::CrosshairCursor:
  183860. cursorName = IDC_CROSS;
  183861. break;
  183862. case MouseCursor::CopyingCursor:
  183863. // can't seem to find one of these in the win32 list..
  183864. break;
  183865. }
  183866. HCURSOR cursorH = LoadCursor (0, cursorName);
  183867. if (cursorH == 0)
  183868. cursorH = LoadCursor (0, IDC_ARROW);
  183869. return (void*) cursorH;
  183870. }
  183871. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  183872. {
  183873. SetCursor ((HCURSOR) getHandle());
  183874. }
  183875. void MouseCursor::showInAllWindows() const throw()
  183876. {
  183877. showInWindow (0);
  183878. }
  183879. class JuceDropSource : public IDropSource
  183880. {
  183881. int refCount;
  183882. public:
  183883. JuceDropSource()
  183884. : refCount (1)
  183885. {
  183886. }
  183887. virtual ~JuceDropSource()
  183888. {
  183889. jassert (refCount == 0);
  183890. }
  183891. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183892. {
  183893. if (id == IID_IUnknown || id == IID_IDropSource)
  183894. {
  183895. AddRef();
  183896. *result = this;
  183897. return S_OK;
  183898. }
  183899. *result = 0;
  183900. return E_NOINTERFACE;
  183901. }
  183902. ULONG __stdcall AddRef() { return ++refCount; }
  183903. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183904. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183905. {
  183906. if (escapePressed)
  183907. return DRAGDROP_S_CANCEL;
  183908. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183909. return DRAGDROP_S_DROP;
  183910. return S_OK;
  183911. }
  183912. HRESULT __stdcall GiveFeedback (DWORD)
  183913. {
  183914. return DRAGDROP_S_USEDEFAULTCURSORS;
  183915. }
  183916. };
  183917. class JuceEnumFormatEtc : public IEnumFORMATETC
  183918. {
  183919. public:
  183920. JuceEnumFormatEtc (const FORMATETC* const format_)
  183921. : refCount (1),
  183922. format (format_),
  183923. index (0)
  183924. {
  183925. }
  183926. virtual ~JuceEnumFormatEtc()
  183927. {
  183928. jassert (refCount == 0);
  183929. }
  183930. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183931. {
  183932. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183933. {
  183934. AddRef();
  183935. *result = this;
  183936. return S_OK;
  183937. }
  183938. *result = 0;
  183939. return E_NOINTERFACE;
  183940. }
  183941. ULONG __stdcall AddRef() { return ++refCount; }
  183942. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183943. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183944. {
  183945. if (result == 0)
  183946. return E_POINTER;
  183947. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183948. newOne->index = index;
  183949. *result = newOne;
  183950. return S_OK;
  183951. }
  183952. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183953. {
  183954. if (pceltFetched != 0)
  183955. *pceltFetched = 0;
  183956. else if (celt != 1)
  183957. return S_FALSE;
  183958. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183959. {
  183960. copyFormatEtc (lpFormatEtc [0], *format);
  183961. ++index;
  183962. if (pceltFetched != 0)
  183963. *pceltFetched = 1;
  183964. return S_OK;
  183965. }
  183966. return S_FALSE;
  183967. }
  183968. HRESULT __stdcall Skip (ULONG celt)
  183969. {
  183970. if (index + (int) celt >= 1)
  183971. return S_FALSE;
  183972. index += celt;
  183973. return S_OK;
  183974. }
  183975. HRESULT __stdcall Reset()
  183976. {
  183977. index = 0;
  183978. return S_OK;
  183979. }
  183980. private:
  183981. int refCount;
  183982. const FORMATETC* const format;
  183983. int index;
  183984. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183985. {
  183986. dest = source;
  183987. if (source.ptd != 0)
  183988. {
  183989. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183990. *(dest.ptd) = *(source.ptd);
  183991. }
  183992. }
  183993. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183994. const JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183995. };
  183996. class JuceDataObject : public IDataObject
  183997. {
  183998. JuceDropSource* const dropSource;
  183999. const FORMATETC* const format;
  184000. const STGMEDIUM* const medium;
  184001. int refCount;
  184002. JuceDataObject (const JuceDataObject&);
  184003. const JuceDataObject& operator= (const JuceDataObject&);
  184004. public:
  184005. JuceDataObject (JuceDropSource* const dropSource_,
  184006. const FORMATETC* const format_,
  184007. const STGMEDIUM* const medium_)
  184008. : dropSource (dropSource_),
  184009. format (format_),
  184010. medium (medium_),
  184011. refCount (1)
  184012. {
  184013. }
  184014. virtual ~JuceDataObject()
  184015. {
  184016. jassert (refCount == 0);
  184017. }
  184018. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184019. {
  184020. if (id == IID_IUnknown || id == IID_IDataObject)
  184021. {
  184022. AddRef();
  184023. *result = this;
  184024. return S_OK;
  184025. }
  184026. *result = 0;
  184027. return E_NOINTERFACE;
  184028. }
  184029. ULONG __stdcall AddRef() { return ++refCount; }
  184030. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  184031. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  184032. {
  184033. if ((pFormatEtc->tymed & format->tymed) != 0
  184034. && pFormatEtc->cfFormat == format->cfFormat
  184035. && pFormatEtc->dwAspect == format->dwAspect)
  184036. {
  184037. pMedium->tymed = format->tymed;
  184038. pMedium->pUnkForRelease = 0;
  184039. if (format->tymed == TYMED_HGLOBAL)
  184040. {
  184041. const SIZE_T len = GlobalSize (medium->hGlobal);
  184042. void* const src = GlobalLock (medium->hGlobal);
  184043. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  184044. memcpy (dst, src, len);
  184045. GlobalUnlock (medium->hGlobal);
  184046. pMedium->hGlobal = dst;
  184047. return S_OK;
  184048. }
  184049. }
  184050. return DV_E_FORMATETC;
  184051. }
  184052. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  184053. {
  184054. if (f == 0)
  184055. return E_INVALIDARG;
  184056. if (f->tymed == format->tymed
  184057. && f->cfFormat == format->cfFormat
  184058. && f->dwAspect == format->dwAspect)
  184059. return S_OK;
  184060. return DV_E_FORMATETC;
  184061. }
  184062. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  184063. {
  184064. pFormatEtcOut->ptd = 0;
  184065. return E_NOTIMPL;
  184066. }
  184067. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  184068. {
  184069. if (result == 0)
  184070. return E_POINTER;
  184071. if (direction == DATADIR_GET)
  184072. {
  184073. *result = new JuceEnumFormatEtc (format);
  184074. return S_OK;
  184075. }
  184076. *result = 0;
  184077. return E_NOTIMPL;
  184078. }
  184079. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  184080. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  184081. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  184082. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  184083. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  184084. };
  184085. static HDROP createHDrop (const StringArray& fileNames) throw()
  184086. {
  184087. int totalChars = 0;
  184088. for (int i = fileNames.size(); --i >= 0;)
  184089. totalChars += fileNames[i].length() + 1;
  184090. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  184091. sizeof (DROPFILES)
  184092. + sizeof (WCHAR) * (totalChars + 2));
  184093. if (hDrop != 0)
  184094. {
  184095. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  184096. pDropFiles->pFiles = sizeof (DROPFILES);
  184097. pDropFiles->fWide = true;
  184098. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  184099. for (int i = 0; i < fileNames.size(); ++i)
  184100. {
  184101. fileNames[i].copyToBuffer (fname, 2048);
  184102. fname += fileNames[i].length() + 1;
  184103. }
  184104. *fname = 0;
  184105. GlobalUnlock (hDrop);
  184106. }
  184107. return hDrop;
  184108. }
  184109. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  184110. {
  184111. JuceDropSource* const source = new JuceDropSource();
  184112. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  184113. DWORD effect;
  184114. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  184115. data->Release();
  184116. source->Release();
  184117. return res == DRAGDROP_S_DROP;
  184118. }
  184119. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  184120. {
  184121. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  184122. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  184123. medium.hGlobal = createHDrop (files);
  184124. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  184125. : DROPEFFECT_COPY);
  184126. }
  184127. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  184128. {
  184129. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  184130. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  184131. const int numChars = text.length();
  184132. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  184133. char* d = (char*) GlobalLock (medium.hGlobal);
  184134. text.copyToBuffer ((WCHAR*) d, numChars + 1);
  184135. format.cfFormat = CF_UNICODETEXT;
  184136. GlobalUnlock (medium.hGlobal);
  184137. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  184138. }
  184139. #endif
  184140. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  184141. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  184142. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184143. // compiled on its own).
  184144. #if JUCE_INCLUDED_FILE
  184145. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  184146. NEWTEXTMETRICEXW*,
  184147. int type,
  184148. LPARAM lParam)
  184149. {
  184150. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184151. {
  184152. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184153. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters (T("@")));
  184154. }
  184155. return 1;
  184156. }
  184157. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  184158. NEWTEXTMETRICEXW*,
  184159. int type,
  184160. LPARAM lParam)
  184161. {
  184162. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184163. {
  184164. LOGFONTW lf;
  184165. zerostruct (lf);
  184166. lf.lfWeight = FW_DONTCARE;
  184167. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184168. lf.lfQuality = DEFAULT_QUALITY;
  184169. lf.lfCharSet = DEFAULT_CHARSET;
  184170. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184171. lf.lfPitchAndFamily = FF_DONTCARE;
  184172. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184173. fontName.copyToBuffer (lf.lfFaceName, LF_FACESIZE - 1);
  184174. HDC dc = CreateCompatibleDC (0);
  184175. EnumFontFamiliesEx (dc, &lf,
  184176. (FONTENUMPROCW) &wfontEnum2,
  184177. lParam, 0);
  184178. DeleteDC (dc);
  184179. }
  184180. return 1;
  184181. }
  184182. const StringArray Font::findAllTypefaceNames() throw()
  184183. {
  184184. StringArray results;
  184185. HDC dc = CreateCompatibleDC (0);
  184186. {
  184187. LOGFONTW lf;
  184188. zerostruct (lf);
  184189. lf.lfWeight = FW_DONTCARE;
  184190. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184191. lf.lfQuality = DEFAULT_QUALITY;
  184192. lf.lfCharSet = DEFAULT_CHARSET;
  184193. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184194. lf.lfPitchAndFamily = FF_DONTCARE;
  184195. lf.lfFaceName[0] = 0;
  184196. EnumFontFamiliesEx (dc, &lf,
  184197. (FONTENUMPROCW) &wfontEnum1,
  184198. (LPARAM) &results, 0);
  184199. }
  184200. DeleteDC (dc);
  184201. results.sort (true);
  184202. return results;
  184203. }
  184204. extern bool juce_IsRunningInWine();
  184205. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  184206. {
  184207. if (juce_IsRunningInWine())
  184208. {
  184209. // If we're running in Wine, then use fonts that might be available on Linux..
  184210. defaultSans = "Bitstream Vera Sans";
  184211. defaultSerif = "Bitstream Vera Serif";
  184212. defaultFixed = "Bitstream Vera Sans Mono";
  184213. }
  184214. else
  184215. {
  184216. defaultSans = "Verdana";
  184217. defaultSerif = "Times";
  184218. defaultFixed = "Lucida Console";
  184219. }
  184220. }
  184221. class FontDCHolder : private DeletedAtShutdown
  184222. {
  184223. public:
  184224. FontDCHolder() throw()
  184225. : dc (0), numKPs (0), size (0),
  184226. bold (false), italic (false)
  184227. {
  184228. }
  184229. ~FontDCHolder() throw()
  184230. {
  184231. if (dc != 0)
  184232. {
  184233. DeleteDC (dc);
  184234. DeleteObject (fontH);
  184235. }
  184236. clearSingletonInstance();
  184237. }
  184238. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  184239. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  184240. {
  184241. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  184242. {
  184243. fontName = fontName_;
  184244. bold = bold_;
  184245. italic = italic_;
  184246. size = size_;
  184247. if (dc != 0)
  184248. {
  184249. DeleteDC (dc);
  184250. DeleteObject (fontH);
  184251. kps.free();
  184252. }
  184253. fontH = 0;
  184254. dc = CreateCompatibleDC (0);
  184255. SetMapperFlags (dc, 0);
  184256. SetMapMode (dc, MM_TEXT);
  184257. LOGFONTW lfw;
  184258. zerostruct (lfw);
  184259. lfw.lfCharSet = DEFAULT_CHARSET;
  184260. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184261. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184262. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  184263. lfw.lfQuality = PROOF_QUALITY;
  184264. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  184265. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  184266. fontName.copyToBuffer (lfw.lfFaceName, LF_FACESIZE - 1);
  184267. lfw.lfHeight = size > 0 ? size : -256;
  184268. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  184269. if (standardSizedFont != 0)
  184270. {
  184271. if (SelectObject (dc, standardSizedFont) != 0)
  184272. {
  184273. fontH = standardSizedFont;
  184274. if (size == 0)
  184275. {
  184276. OUTLINETEXTMETRIC otm;
  184277. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  184278. {
  184279. lfw.lfHeight = -(int) otm.otmEMSquare;
  184280. fontH = CreateFontIndirect (&lfw);
  184281. SelectObject (dc, fontH);
  184282. DeleteObject (standardSizedFont);
  184283. }
  184284. }
  184285. }
  184286. else
  184287. {
  184288. jassertfalse
  184289. }
  184290. }
  184291. else
  184292. {
  184293. jassertfalse
  184294. }
  184295. }
  184296. return dc;
  184297. }
  184298. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  184299. {
  184300. if (kps == 0)
  184301. {
  184302. numKPs = GetKerningPairs (dc, 0, 0);
  184303. kps.calloc (numKPs);
  184304. GetKerningPairs (dc, numKPs, kps);
  184305. }
  184306. numKPs_ = numKPs;
  184307. return kps;
  184308. }
  184309. private:
  184310. HFONT fontH;
  184311. HDC dc;
  184312. String fontName;
  184313. HeapBlock <KERNINGPAIR> kps;
  184314. int numKPs, size;
  184315. bool bold, italic;
  184316. FontDCHolder (const FontDCHolder&);
  184317. const FontDCHolder& operator= (const FontDCHolder&);
  184318. };
  184319. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  184320. class WindowsTypeface : public CustomTypeface
  184321. {
  184322. public:
  184323. WindowsTypeface (const Font& font)
  184324. {
  184325. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  184326. font.isBold(), font.isItalic(), 0);
  184327. TEXTMETRIC tm;
  184328. tm.tmAscent = tm.tmHeight = 1;
  184329. tm.tmDefaultChar = 0;
  184330. GetTextMetrics (dc, &tm);
  184331. setCharacteristics (font.getTypefaceName(),
  184332. tm.tmAscent / (float) tm.tmHeight,
  184333. font.isBold(), font.isItalic(),
  184334. tm.tmDefaultChar);
  184335. }
  184336. bool loadGlyphIfPossible (const juce_wchar character)
  184337. {
  184338. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  184339. GLYPHMETRICS gm;
  184340. {
  184341. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  184342. WORD index = 0;
  184343. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  184344. && index == 0xffff)
  184345. {
  184346. return false;
  184347. }
  184348. }
  184349. Path glyphPath;
  184350. TEXTMETRIC tm;
  184351. if (! GetTextMetrics (dc, &tm))
  184352. {
  184353. addGlyph (character, glyphPath, 0);
  184354. return true;
  184355. }
  184356. const float height = (float) tm.tmHeight;
  184357. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  184358. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  184359. &gm, 0, 0, &identityMatrix);
  184360. if (bufSize > 0)
  184361. {
  184362. HeapBlock <char> data (bufSize);
  184363. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  184364. bufSize, data, &identityMatrix);
  184365. const TTPOLYGONHEADER* pheader = (TTPOLYGONHEADER*) data;
  184366. const float scaleX = 1.0f / height;
  184367. const float scaleY = -1.0f / height;
  184368. while ((char*) pheader < data + bufSize)
  184369. {
  184370. #define remapX(v) (scaleX * (v).x.value)
  184371. #define remapY(v) (scaleY * (v).y.value)
  184372. float x = remapX (pheader->pfxStart);
  184373. float y = remapY (pheader->pfxStart);
  184374. glyphPath.startNewSubPath (x, y);
  184375. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  184376. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  184377. while ((const char*) curve < curveEnd)
  184378. {
  184379. if (curve->wType == TT_PRIM_LINE)
  184380. {
  184381. for (int i = 0; i < curve->cpfx; ++i)
  184382. {
  184383. x = remapX (curve->apfx [i]);
  184384. y = remapY (curve->apfx [i]);
  184385. glyphPath.lineTo (x, y);
  184386. }
  184387. }
  184388. else if (curve->wType == TT_PRIM_QSPLINE)
  184389. {
  184390. for (int i = 0; i < curve->cpfx - 1; ++i)
  184391. {
  184392. const float x2 = remapX (curve->apfx [i]);
  184393. const float y2 = remapY (curve->apfx [i]);
  184394. float x3, y3;
  184395. if (i < curve->cpfx - 2)
  184396. {
  184397. x3 = 0.5f * (x2 + remapX (curve->apfx [i + 1]));
  184398. y3 = 0.5f * (y2 + remapY (curve->apfx [i + 1]));
  184399. }
  184400. else
  184401. {
  184402. x3 = remapX (curve->apfx [i + 1]);
  184403. y3 = remapY (curve->apfx [i + 1]);
  184404. }
  184405. glyphPath.quadraticTo (x2, y2, x3, y3);
  184406. x = x3;
  184407. y = y3;
  184408. }
  184409. }
  184410. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  184411. }
  184412. pheader = (const TTPOLYGONHEADER*) curve;
  184413. glyphPath.closeSubPath();
  184414. }
  184415. }
  184416. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  184417. int numKPs;
  184418. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  184419. for (int i = 0; i < numKPs; ++i)
  184420. {
  184421. if (kps[i].wFirst == character)
  184422. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  184423. kps[i].iKernAmount / height);
  184424. }
  184425. return true;
  184426. }
  184427. };
  184428. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  184429. {
  184430. return new WindowsTypeface (font);
  184431. }
  184432. #endif
  184433. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  184434. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  184435. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184436. // compiled on its own).
  184437. #if JUCE_INCLUDED_FILE
  184438. static const void* defaultDirPath = 0;
  184439. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  184440. static Component* currentExtraFileWin = 0;
  184441. static bool areThereAnyAlwaysOnTopWindows()
  184442. {
  184443. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  184444. {
  184445. Component* c = Desktop::getInstance().getComponent (i);
  184446. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  184447. return true;
  184448. }
  184449. return false;
  184450. }
  184451. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  184452. {
  184453. if (msg == BFFM_INITIALIZED)
  184454. {
  184455. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  184456. }
  184457. else if (msg == BFFM_VALIDATEFAILEDW)
  184458. {
  184459. returnedString = (LPCWSTR) lParam;
  184460. }
  184461. else if (msg == BFFM_VALIDATEFAILEDA)
  184462. {
  184463. returnedString = (const char*) lParam;
  184464. }
  184465. return 0;
  184466. }
  184467. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  184468. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  184469. {
  184470. if (currentExtraFileWin != 0)
  184471. {
  184472. if (uiMsg == WM_INITDIALOG)
  184473. {
  184474. HWND dialogH = GetParent (hdlg);
  184475. jassert (dialogH != 0);
  184476. if (dialogH == 0)
  184477. dialogH = hdlg;
  184478. RECT r, cr;
  184479. GetWindowRect (dialogH, &r);
  184480. GetClientRect (dialogH, &cr);
  184481. SetWindowPos (dialogH, 0,
  184482. r.left, r.top,
  184483. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  184484. jmax (150, (int) (r.bottom - r.top)),
  184485. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  184486. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  184487. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  184488. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  184489. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  184490. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  184491. }
  184492. else if (uiMsg == WM_NOTIFY)
  184493. {
  184494. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  184495. if (ofn->hdr.code == CDN_SELCHANGE)
  184496. {
  184497. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  184498. if (comp != 0)
  184499. {
  184500. TCHAR path [MAX_PATH * 2];
  184501. path[0] = 0;
  184502. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  184503. const String fn ((const WCHAR*) path);
  184504. comp->selectedFileChanged (File (fn));
  184505. }
  184506. }
  184507. }
  184508. }
  184509. return 0;
  184510. }
  184511. class FPComponentHolder : public Component
  184512. {
  184513. public:
  184514. FPComponentHolder()
  184515. {
  184516. setVisible (true);
  184517. setOpaque (true);
  184518. }
  184519. ~FPComponentHolder()
  184520. {
  184521. }
  184522. void paint (Graphics& g)
  184523. {
  184524. g.fillAll (Colours::lightgrey);
  184525. }
  184526. private:
  184527. FPComponentHolder (const FPComponentHolder&);
  184528. const FPComponentHolder& operator= (const FPComponentHolder&);
  184529. };
  184530. void FileChooser::showPlatformDialog (Array<File>& results,
  184531. const String& title,
  184532. const File& currentFileOrDirectory,
  184533. const String& filter,
  184534. bool selectsDirectory,
  184535. bool /*selectsFiles*/,
  184536. bool isSaveDialogue,
  184537. bool warnAboutOverwritingExistingFiles,
  184538. bool selectMultipleFiles,
  184539. FilePreviewComponent* extraInfoComponent)
  184540. {
  184541. const int numCharsAvailable = 32768;
  184542. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  184543. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  184544. int fnameIdx = 0;
  184545. JUCE_TRY
  184546. {
  184547. // use a modal window as the parent for this dialog box
  184548. // to block input from other app windows
  184549. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  184550. Component w (String::empty);
  184551. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  184552. mainMon.getY() + mainMon.getHeight() / 4,
  184553. 0, 0);
  184554. w.setOpaque (true);
  184555. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  184556. w.addToDesktop (0);
  184557. if (extraInfoComponent == 0)
  184558. w.enterModalState();
  184559. String initialDir;
  184560. if (currentFileOrDirectory.isDirectory())
  184561. {
  184562. initialDir = currentFileOrDirectory.getFullPathName();
  184563. }
  184564. else
  184565. {
  184566. currentFileOrDirectory.getFileName().copyToBuffer (fname, numCharsAvailable);
  184567. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  184568. }
  184569. if (currentExtraFileWin->isValidComponent())
  184570. {
  184571. jassertfalse
  184572. return;
  184573. }
  184574. if (selectsDirectory)
  184575. {
  184576. LPITEMIDLIST list = 0;
  184577. filenameSpace.fillWith (0);
  184578. {
  184579. BROWSEINFO bi;
  184580. zerostruct (bi);
  184581. bi.hwndOwner = (HWND) w.getWindowHandle();
  184582. bi.pszDisplayName = fname;
  184583. bi.lpszTitle = title;
  184584. bi.lpfn = browseCallbackProc;
  184585. #ifdef BIF_USENEWUI
  184586. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  184587. #else
  184588. bi.ulFlags = 0x50;
  184589. #endif
  184590. defaultDirPath = (const WCHAR*) initialDir;
  184591. list = SHBrowseForFolder (&bi);
  184592. if (! SHGetPathFromIDListW (list, fname))
  184593. {
  184594. fname[0] = 0;
  184595. returnedString = String::empty;
  184596. }
  184597. }
  184598. LPMALLOC al;
  184599. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  184600. al->Free (list);
  184601. defaultDirPath = 0;
  184602. if (returnedString.isNotEmpty())
  184603. {
  184604. const String stringFName (fname);
  184605. results.add (File (stringFName).getSiblingFile (returnedString));
  184606. returnedString = String::empty;
  184607. return;
  184608. }
  184609. }
  184610. else
  184611. {
  184612. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  184613. if (warnAboutOverwritingExistingFiles)
  184614. flags |= OFN_OVERWRITEPROMPT;
  184615. if (selectMultipleFiles)
  184616. flags |= OFN_ALLOWMULTISELECT;
  184617. if (extraInfoComponent != 0)
  184618. {
  184619. flags |= OFN_ENABLEHOOK;
  184620. currentExtraFileWin = new FPComponentHolder();
  184621. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  184622. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  184623. extraInfoComponent->getHeight());
  184624. currentExtraFileWin->addToDesktop (0);
  184625. currentExtraFileWin->enterModalState();
  184626. }
  184627. {
  184628. WCHAR filters [1024];
  184629. zeromem (filters, sizeof (filters));
  184630. filter.copyToBuffer (filters, 1024);
  184631. filter.copyToBuffer (filters + filter.length() + 1,
  184632. 1022 - filter.length());
  184633. OPENFILENAMEW of;
  184634. zerostruct (of);
  184635. #ifdef OPENFILENAME_SIZE_VERSION_400W
  184636. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  184637. #else
  184638. of.lStructSize = sizeof (of);
  184639. #endif
  184640. of.hwndOwner = (HWND) w.getWindowHandle();
  184641. of.lpstrFilter = filters;
  184642. of.nFilterIndex = 1;
  184643. of.lpstrFile = fname;
  184644. of.nMaxFile = numCharsAvailable;
  184645. of.lpstrInitialDir = initialDir;
  184646. of.lpstrTitle = title;
  184647. of.Flags = flags;
  184648. if (extraInfoComponent != 0)
  184649. of.lpfnHook = &openCallback;
  184650. if (isSaveDialogue)
  184651. {
  184652. if (! GetSaveFileName (&of))
  184653. fname[0] = 0;
  184654. else
  184655. fnameIdx = of.nFileOffset;
  184656. }
  184657. else
  184658. {
  184659. if (! GetOpenFileName (&of))
  184660. fname[0] = 0;
  184661. else
  184662. fnameIdx = of.nFileOffset;
  184663. }
  184664. }
  184665. }
  184666. }
  184667. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184668. catch (...)
  184669. {
  184670. fname[0] = 0;
  184671. }
  184672. #endif
  184673. deleteAndZero (currentExtraFileWin);
  184674. const WCHAR* const files = fname;
  184675. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184676. {
  184677. const WCHAR* filename = files + fnameIdx;
  184678. while (*filename != 0)
  184679. {
  184680. const String filepath (String (files) + T("\\") + String (filename));
  184681. results.add (File (filepath));
  184682. filename += CharacterFunctions::length (filename) + 1;
  184683. }
  184684. }
  184685. else if (files[0] != 0)
  184686. {
  184687. results.add (File (files));
  184688. }
  184689. }
  184690. #endif
  184691. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  184692. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  184693. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184694. // compiled on its own).
  184695. #if JUCE_INCLUDED_FILE
  184696. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  184697. {
  184698. if (OpenClipboard (0) != 0)
  184699. {
  184700. if (EmptyClipboard() != 0)
  184701. {
  184702. const int len = text.length();
  184703. if (len > 0)
  184704. {
  184705. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184706. (len + 1) * sizeof (wchar_t));
  184707. if (bufH != 0)
  184708. {
  184709. wchar_t* const data = (wchar_t*) GlobalLock (bufH);
  184710. text.copyToBuffer (data, len);
  184711. GlobalUnlock (bufH);
  184712. SetClipboardData (CF_UNICODETEXT, bufH);
  184713. }
  184714. }
  184715. }
  184716. CloseClipboard();
  184717. }
  184718. }
  184719. const String SystemClipboard::getTextFromClipboard() throw()
  184720. {
  184721. String result;
  184722. if (OpenClipboard (0) != 0)
  184723. {
  184724. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184725. if (bufH != 0)
  184726. {
  184727. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184728. if (data != 0)
  184729. {
  184730. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  184731. GlobalUnlock (bufH);
  184732. }
  184733. }
  184734. CloseClipboard();
  184735. }
  184736. return result;
  184737. }
  184738. #endif
  184739. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184740. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184741. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184742. // compiled on its own).
  184743. #if JUCE_INCLUDED_FILE
  184744. class JuceIStorage : public IStorage
  184745. {
  184746. int refCount;
  184747. public:
  184748. JuceIStorage() : refCount (1) {}
  184749. virtual ~JuceIStorage()
  184750. {
  184751. jassert (refCount == 0);
  184752. }
  184753. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184754. {
  184755. if (id == IID_IUnknown || id == IID_IStorage)
  184756. {
  184757. AddRef();
  184758. *result = this;
  184759. return S_OK;
  184760. }
  184761. *result = 0;
  184762. return E_NOINTERFACE;
  184763. }
  184764. ULONG __stdcall AddRef() { return ++refCount; }
  184765. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184766. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184767. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184768. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184769. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184770. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184771. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184772. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184773. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184774. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184775. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184776. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184777. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184778. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184779. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184780. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184781. juce_UseDebuggingNewOperator
  184782. };
  184783. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184784. {
  184785. int refCount;
  184786. HWND window;
  184787. public:
  184788. JuceOleInPlaceFrame (HWND window_)
  184789. : refCount (1),
  184790. window (window_)
  184791. {
  184792. }
  184793. virtual ~JuceOleInPlaceFrame()
  184794. {
  184795. jassert (refCount == 0);
  184796. }
  184797. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184798. {
  184799. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184800. {
  184801. AddRef();
  184802. *result = this;
  184803. return S_OK;
  184804. }
  184805. *result = 0;
  184806. return E_NOINTERFACE;
  184807. }
  184808. ULONG __stdcall AddRef() { return ++refCount; }
  184809. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184810. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184811. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184812. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184813. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184814. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184815. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184816. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184817. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184818. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184819. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184820. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184821. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184822. juce_UseDebuggingNewOperator
  184823. };
  184824. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184825. {
  184826. int refCount;
  184827. HWND window;
  184828. JuceOleInPlaceFrame* frame;
  184829. public:
  184830. JuceIOleInPlaceSite (HWND window_)
  184831. : refCount (1),
  184832. window (window_)
  184833. {
  184834. frame = new JuceOleInPlaceFrame (window);
  184835. }
  184836. virtual ~JuceIOleInPlaceSite()
  184837. {
  184838. jassert (refCount == 0);
  184839. frame->Release();
  184840. }
  184841. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184842. {
  184843. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184844. {
  184845. AddRef();
  184846. *result = this;
  184847. return S_OK;
  184848. }
  184849. *result = 0;
  184850. return E_NOINTERFACE;
  184851. }
  184852. ULONG __stdcall AddRef() { return ++refCount; }
  184853. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184854. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184855. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184856. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184857. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184858. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184859. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184860. {
  184861. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184862. *lplpFrame = frame;
  184863. *lplpDoc = 0;
  184864. lpFrameInfo->fMDIApp = FALSE;
  184865. lpFrameInfo->hwndFrame = window;
  184866. lpFrameInfo->haccel = 0;
  184867. lpFrameInfo->cAccelEntries = 0;
  184868. return S_OK;
  184869. }
  184870. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184871. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184872. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184873. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184874. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184875. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184876. juce_UseDebuggingNewOperator
  184877. };
  184878. class JuceIOleClientSite : public IOleClientSite
  184879. {
  184880. int refCount;
  184881. JuceIOleInPlaceSite* inplaceSite;
  184882. public:
  184883. JuceIOleClientSite (HWND window)
  184884. : refCount (1)
  184885. {
  184886. inplaceSite = new JuceIOleInPlaceSite (window);
  184887. }
  184888. virtual ~JuceIOleClientSite()
  184889. {
  184890. jassert (refCount == 0);
  184891. inplaceSite->Release();
  184892. }
  184893. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184894. {
  184895. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184896. {
  184897. AddRef();
  184898. *result = this;
  184899. return S_OK;
  184900. }
  184901. else if (id == IID_IOleInPlaceSite)
  184902. {
  184903. inplaceSite->AddRef();
  184904. *result = inplaceSite;
  184905. return S_OK;
  184906. }
  184907. *result = 0;
  184908. return E_NOINTERFACE;
  184909. }
  184910. ULONG __stdcall AddRef() { return ++refCount; }
  184911. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184912. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184913. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184914. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184915. HRESULT __stdcall ShowObject() { return S_OK; }
  184916. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184917. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184918. juce_UseDebuggingNewOperator
  184919. };
  184920. class ActiveXControlData : public ComponentMovementWatcher
  184921. {
  184922. ActiveXControlComponent* const owner;
  184923. bool wasShowing;
  184924. public:
  184925. HWND controlHWND;
  184926. IStorage* storage;
  184927. IOleClientSite* clientSite;
  184928. IOleObject* control;
  184929. ActiveXControlData (HWND hwnd,
  184930. ActiveXControlComponent* const owner_)
  184931. : ComponentMovementWatcher (owner_),
  184932. owner (owner_),
  184933. wasShowing (owner_ != 0 && owner_->isShowing()),
  184934. controlHWND (0),
  184935. storage (new JuceIStorage()),
  184936. clientSite (new JuceIOleClientSite (hwnd)),
  184937. control (0)
  184938. {
  184939. }
  184940. ~ActiveXControlData()
  184941. {
  184942. if (control != 0)
  184943. {
  184944. control->Close (OLECLOSE_NOSAVE);
  184945. control->Release();
  184946. }
  184947. clientSite->Release();
  184948. storage->Release();
  184949. }
  184950. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184951. {
  184952. Component* const topComp = owner->getTopLevelComponent();
  184953. if (topComp->getPeer() != 0)
  184954. {
  184955. int x = 0, y = 0;
  184956. owner->relativePositionToOtherComponent (topComp, x, y);
  184957. owner->setControlBounds (Rectangle<int> (x, y, owner->getWidth(), owner->getHeight()));
  184958. }
  184959. }
  184960. void componentPeerChanged()
  184961. {
  184962. const bool isShowingNow = owner->isShowing();
  184963. if (wasShowing != isShowingNow)
  184964. {
  184965. wasShowing = isShowingNow;
  184966. owner->setControlVisible (isShowingNow);
  184967. }
  184968. componentMovedOrResized (true, true);
  184969. }
  184970. void componentVisibilityChanged (Component&)
  184971. {
  184972. componentPeerChanged();
  184973. }
  184974. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184975. {
  184976. return ((ActiveXControlData*) ax->control) != 0
  184977. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184978. }
  184979. };
  184980. static VoidArray activeXComps;
  184981. static HWND getHWND (const ActiveXControlComponent* const component)
  184982. {
  184983. HWND hwnd = 0;
  184984. const IID iid = IID_IOleWindow;
  184985. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184986. if (window != 0)
  184987. {
  184988. window->GetWindow (&hwnd);
  184989. window->Release();
  184990. }
  184991. return hwnd;
  184992. }
  184993. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184994. {
  184995. RECT activeXRect, peerRect;
  184996. GetWindowRect (hwnd, &activeXRect);
  184997. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184998. const int mx = GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left;
  184999. const int my = GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top;
  185000. const int64 mouseEventTime = getMouseEventTime();
  185001. const int oldModifiers = currentModifiers;
  185002. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  185003. switch (message)
  185004. {
  185005. case WM_MOUSEMOVE:
  185006. if (ModifierKeys (currentModifiers).isAnyMouseButtonDown())
  185007. peer->handleMouseDrag (mx, my, mouseEventTime);
  185008. else
  185009. peer->handleMouseMove (mx, my, mouseEventTime);
  185010. break;
  185011. case WM_LBUTTONDOWN:
  185012. case WM_MBUTTONDOWN:
  185013. case WM_RBUTTONDOWN:
  185014. peer->handleMouseDown (mx, my, mouseEventTime);
  185015. break;
  185016. case WM_LBUTTONUP:
  185017. case WM_MBUTTONUP:
  185018. case WM_RBUTTONUP:
  185019. peer->handleMouseUp (oldModifiers, mx, my, mouseEventTime);
  185020. break;
  185021. default:
  185022. break;
  185023. }
  185024. }
  185025. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  185026. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  185027. {
  185028. for (int i = activeXComps.size(); --i >= 0;)
  185029. {
  185030. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) activeXComps.getUnchecked(i);
  185031. if (ActiveXControlData::doesWindowMatch (ax, hwnd))
  185032. {
  185033. switch (message)
  185034. {
  185035. case WM_MOUSEMOVE:
  185036. case WM_LBUTTONDOWN:
  185037. case WM_MBUTTONDOWN:
  185038. case WM_RBUTTONDOWN:
  185039. case WM_LBUTTONUP:
  185040. case WM_MBUTTONUP:
  185041. case WM_RBUTTONUP:
  185042. case WM_LBUTTONDBLCLK:
  185043. case WM_MBUTTONDBLCLK:
  185044. case WM_RBUTTONDBLCLK:
  185045. if (ax->isShowing())
  185046. {
  185047. ComponentPeer* const peer = ax->getPeer();
  185048. if (peer != 0)
  185049. {
  185050. offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  185051. if (! ax->areMouseEventsAllowed())
  185052. return 0;
  185053. }
  185054. }
  185055. break;
  185056. default:
  185057. break;
  185058. }
  185059. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  185060. }
  185061. }
  185062. return DefWindowProc (hwnd, message, wParam, lParam);
  185063. }
  185064. ActiveXControlComponent::ActiveXControlComponent()
  185065. : originalWndProc (0),
  185066. control (0),
  185067. mouseEventsAllowed (true)
  185068. {
  185069. activeXComps.add (this);
  185070. }
  185071. ActiveXControlComponent::~ActiveXControlComponent()
  185072. {
  185073. deleteControl();
  185074. activeXComps.removeValue (this);
  185075. }
  185076. void ActiveXControlComponent::paint (Graphics& g)
  185077. {
  185078. if (control == 0)
  185079. g.fillAll (Colours::lightgrey);
  185080. }
  185081. bool ActiveXControlComponent::createControl (const void* controlIID)
  185082. {
  185083. deleteControl();
  185084. ComponentPeer* const peer = getPeer();
  185085. // the component must have already been added to a real window when you call this!
  185086. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  185087. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  185088. {
  185089. int x = 0, y = 0;
  185090. relativePositionToOtherComponent (getTopLevelComponent(), x, y);
  185091. HWND hwnd = (HWND) peer->getNativeHandle();
  185092. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  185093. HRESULT hr;
  185094. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  185095. info->clientSite, info->storage,
  185096. (void**) &(info->control))) == S_OK)
  185097. {
  185098. info->control->SetHostNames (L"Juce", 0);
  185099. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  185100. {
  185101. RECT rect;
  185102. rect.left = x;
  185103. rect.top = y;
  185104. rect.right = x + getWidth();
  185105. rect.bottom = y + getHeight();
  185106. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  185107. {
  185108. control = info.release();
  185109. setControlBounds (Rectangle<int> (x, y, getWidth(), getHeight()));
  185110. ((ActiveXControlData*) control)->controlHWND = getHWND (this);
  185111. if (((ActiveXControlData*) control)->controlHWND != 0)
  185112. {
  185113. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  185114. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) activeXHookWndProc);
  185115. }
  185116. return true;
  185117. }
  185118. }
  185119. }
  185120. }
  185121. return false;
  185122. }
  185123. void ActiveXControlComponent::deleteControl()
  185124. {
  185125. ActiveXControlData* const info = (ActiveXControlData*) control;
  185126. if (info != 0)
  185127. {
  185128. delete info;
  185129. control = 0;
  185130. originalWndProc = 0;
  185131. }
  185132. }
  185133. void* ActiveXControlComponent::queryInterface (const void* iid) const
  185134. {
  185135. ActiveXControlData* const info = (ActiveXControlData*) control;
  185136. void* result = 0;
  185137. if (info != 0 && info->control != 0
  185138. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  185139. return result;
  185140. return 0;
  185141. }
  185142. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  185143. {
  185144. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  185145. if (hwnd != 0)
  185146. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  185147. }
  185148. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  185149. {
  185150. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  185151. if (hwnd != 0)
  185152. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  185153. }
  185154. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  185155. {
  185156. mouseEventsAllowed = eventsCanReachControl;
  185157. }
  185158. #endif
  185159. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  185160. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  185161. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185162. // compiled on its own).
  185163. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  185164. using namespace QTOLibrary;
  185165. using namespace QTOControlLib;
  185166. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  185167. static bool isQTAvailable = false;
  185168. struct QTMovieCompInternal
  185169. {
  185170. QTMovieCompInternal()
  185171. : dataHandle (0)
  185172. {
  185173. }
  185174. ~QTMovieCompInternal()
  185175. {
  185176. clearHandle();
  185177. }
  185178. IQTControlPtr qtControlInternal;
  185179. IQTMoviePtr qtMovieInternal;
  185180. Handle dataHandle;
  185181. void clearHandle()
  185182. {
  185183. if (dataHandle != 0)
  185184. {
  185185. DisposeHandle (dataHandle);
  185186. dataHandle = 0;
  185187. }
  185188. }
  185189. };
  185190. #define qtControl (((QTMovieCompInternal*) internal)->qtControlInternal)
  185191. #define qtMovie (((QTMovieCompInternal*) internal)->qtMovieInternal)
  185192. QuickTimeMovieComponent::QuickTimeMovieComponent()
  185193. : movieLoaded (false),
  185194. controllerVisible (true)
  185195. {
  185196. internal = new QTMovieCompInternal();
  185197. setMouseEventsAllowed (false);
  185198. }
  185199. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  185200. {
  185201. closeMovie();
  185202. qtControl = 0;
  185203. deleteControl();
  185204. delete internal;
  185205. internal = 0;
  185206. }
  185207. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  185208. {
  185209. if (! isQTAvailable)
  185210. {
  185211. isQTAvailable = (InitializeQTML (0) == noErr)
  185212. && (EnterMovies() == noErr);
  185213. }
  185214. return isQTAvailable;
  185215. }
  185216. void QuickTimeMovieComponent::createControlIfNeeded()
  185217. {
  185218. if (isShowing() && ! isControlCreated())
  185219. {
  185220. const IID qtIID = __uuidof (QTControl);
  185221. if (createControl (&qtIID))
  185222. {
  185223. const IID qtInterfaceIID = __uuidof (IQTControl);
  185224. qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  185225. if (qtControl != 0)
  185226. {
  185227. qtControl->Release(); // it has one ref too many at this point
  185228. qtControl->QuickTimeInitialize();
  185229. qtControl->PutSizing (qtMovieFitsControl);
  185230. if (movieFile != File::nonexistent)
  185231. loadMovie (movieFile, controllerVisible);
  185232. }
  185233. }
  185234. }
  185235. }
  185236. bool QuickTimeMovieComponent::isControlCreated() const
  185237. {
  185238. return isControlOpen();
  185239. }
  185240. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  185241. const bool isControllerVisible)
  185242. {
  185243. movieFile = File::nonexistent;
  185244. movieLoaded = false;
  185245. qtMovie = 0;
  185246. controllerVisible = isControllerVisible;
  185247. createControlIfNeeded();
  185248. if (isControlCreated())
  185249. {
  185250. if (qtControl != 0)
  185251. {
  185252. qtControl->Put_MovieHandle (0);
  185253. ((QTMovieCompInternal*) internal)->clearHandle();
  185254. Movie movie;
  185255. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, ((QTMovieCompInternal*) internal)->dataHandle))
  185256. {
  185257. qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  185258. qtMovie = qtControl->GetMovie();
  185259. if (qtMovie != 0)
  185260. qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  185261. : qtMovieControllerTypeNone);
  185262. }
  185263. if (movie == 0)
  185264. ((QTMovieCompInternal*) internal)->clearHandle();
  185265. }
  185266. movieLoaded = (qtMovie != 0);
  185267. }
  185268. else
  185269. {
  185270. // You're trying to open a movie when the control hasn't yet been created, probably because
  185271. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  185272. jassertfalse
  185273. }
  185274. delete movieStream;
  185275. return movieLoaded;
  185276. }
  185277. void QuickTimeMovieComponent::closeMovie()
  185278. {
  185279. stop();
  185280. movieFile = File::nonexistent;
  185281. movieLoaded = false;
  185282. qtMovie = 0;
  185283. if (qtControl != 0)
  185284. qtControl->Put_MovieHandle (0);
  185285. ((QTMovieCompInternal*) internal)->clearHandle();
  185286. }
  185287. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  185288. {
  185289. return movieFile;
  185290. }
  185291. bool QuickTimeMovieComponent::isMovieOpen() const
  185292. {
  185293. return movieLoaded;
  185294. }
  185295. double QuickTimeMovieComponent::getMovieDuration() const
  185296. {
  185297. if (qtMovie != 0)
  185298. return qtMovie->GetDuration() / (double) qtMovie->GetTimeScale();
  185299. return 0.0;
  185300. }
  185301. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  185302. {
  185303. if (qtMovie != 0)
  185304. {
  185305. struct QTRECT r = qtMovie->GetNaturalRect();
  185306. width = r.right - r.left;
  185307. height = r.bottom - r.top;
  185308. }
  185309. else
  185310. {
  185311. width = height = 0;
  185312. }
  185313. }
  185314. void QuickTimeMovieComponent::play()
  185315. {
  185316. if (qtMovie != 0)
  185317. qtMovie->Play();
  185318. }
  185319. void QuickTimeMovieComponent::stop()
  185320. {
  185321. if (qtMovie != 0)
  185322. qtMovie->Stop();
  185323. }
  185324. bool QuickTimeMovieComponent::isPlaying() const
  185325. {
  185326. return qtMovie != 0 && qtMovie->GetRate() != 0.0f;
  185327. }
  185328. void QuickTimeMovieComponent::setPosition (const double seconds)
  185329. {
  185330. if (qtMovie != 0)
  185331. qtMovie->PutTime ((long) (seconds * qtMovie->GetTimeScale()));
  185332. }
  185333. double QuickTimeMovieComponent::getPosition() const
  185334. {
  185335. if (qtMovie != 0)
  185336. return qtMovie->GetTime() / (double) qtMovie->GetTimeScale();
  185337. return 0.0;
  185338. }
  185339. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  185340. {
  185341. if (qtMovie != 0)
  185342. qtMovie->PutRate (newSpeed);
  185343. }
  185344. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  185345. {
  185346. if (qtMovie != 0)
  185347. {
  185348. qtMovie->PutAudioVolume (newVolume);
  185349. qtMovie->PutAudioMute (newVolume <= 0);
  185350. }
  185351. }
  185352. float QuickTimeMovieComponent::getMovieVolume() const
  185353. {
  185354. if (qtMovie != 0)
  185355. return qtMovie->GetAudioVolume();
  185356. return 0.0f;
  185357. }
  185358. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  185359. {
  185360. if (qtMovie != 0)
  185361. qtMovie->PutLoop (shouldLoop);
  185362. }
  185363. bool QuickTimeMovieComponent::isLooping() const
  185364. {
  185365. return qtMovie != 0 && qtMovie->GetLoop();
  185366. }
  185367. bool QuickTimeMovieComponent::isControllerVisible() const
  185368. {
  185369. return controllerVisible;
  185370. }
  185371. void QuickTimeMovieComponent::parentHierarchyChanged()
  185372. {
  185373. createControlIfNeeded();
  185374. QTCompBaseClass::parentHierarchyChanged();
  185375. }
  185376. void QuickTimeMovieComponent::visibilityChanged()
  185377. {
  185378. createControlIfNeeded();
  185379. QTCompBaseClass::visibilityChanged();
  185380. }
  185381. void QuickTimeMovieComponent::paint (Graphics& g)
  185382. {
  185383. if (! isControlCreated())
  185384. g.fillAll (Colours::black);
  185385. }
  185386. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  185387. {
  185388. Handle dataRef = 0;
  185389. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  185390. if (err == noErr)
  185391. {
  185392. Str255 suffix;
  185393. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  185394. StringPtr name = suffix;
  185395. err = PtrAndHand (name, dataRef, name[0] + 1);
  185396. if (err == noErr)
  185397. {
  185398. long atoms[3];
  185399. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  185400. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  185401. atoms[2] = EndianU32_NtoB (MovieFileType);
  185402. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  185403. if (err == noErr)
  185404. return dataRef;
  185405. }
  185406. DisposeHandle (dataRef);
  185407. }
  185408. return 0;
  185409. }
  185410. static CFStringRef juceStringToCFString (const String& s)
  185411. {
  185412. const int len = s.length();
  185413. const juce_wchar* const t = (const juce_wchar*) s;
  185414. HeapBlock <UniChar> temp (len + 2);
  185415. for (int i = 0; i <= len; ++i)
  185416. temp[i] = t[i];
  185417. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  185418. }
  185419. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  185420. {
  185421. Boolean trueBool = true;
  185422. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185423. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  185424. props[prop].propValueSize = sizeof (trueBool);
  185425. props[prop].propValueAddress = &trueBool;
  185426. ++prop;
  185427. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185428. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  185429. props[prop].propValueSize = sizeof (trueBool);
  185430. props[prop].propValueAddress = &trueBool;
  185431. ++prop;
  185432. Boolean isActive = true;
  185433. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  185434. props[prop].propID = kQTNewMoviePropertyID_Active;
  185435. props[prop].propValueSize = sizeof (isActive);
  185436. props[prop].propValueAddress = &isActive;
  185437. ++prop;
  185438. MacSetPort (0);
  185439. jassert (prop <= 5);
  185440. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  185441. return err == noErr;
  185442. }
  185443. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  185444. {
  185445. if (input == 0)
  185446. return false;
  185447. dataHandle = 0;
  185448. bool ok = false;
  185449. QTNewMoviePropertyElement props[5];
  185450. zeromem (props, sizeof (props));
  185451. int prop = 0;
  185452. DataReferenceRecord dr;
  185453. props[prop].propClass = kQTPropertyClass_DataLocation;
  185454. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  185455. props[prop].propValueSize = sizeof (dr);
  185456. props[prop].propValueAddress = (void*) &dr;
  185457. ++prop;
  185458. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  185459. if (fin != 0)
  185460. {
  185461. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  185462. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  185463. &dr.dataRef, &dr.dataRefType);
  185464. ok = openMovie (props, prop, movie);
  185465. DisposeHandle (dr.dataRef);
  185466. CFRelease (filePath);
  185467. }
  185468. else
  185469. {
  185470. // sanity-check because this currently needs to load the whole stream into memory..
  185471. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  185472. dataHandle = NewHandle ((Size) input->getTotalLength());
  185473. HLock (dataHandle);
  185474. // read the entire stream into memory - this is a pain, but can't get it to work
  185475. // properly using a custom callback to supply the data.
  185476. input->read (*dataHandle, (int) input->getTotalLength());
  185477. HUnlock (dataHandle);
  185478. // different types to get QT to try. (We should really be a bit smarter here by
  185479. // working out in advance which one the stream contains, rather than just trying
  185480. // each one)
  185481. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  185482. "\04.avi", "\04.m4a" };
  185483. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  185484. {
  185485. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  185486. dr.dataRefType = HandleDataHandlerSubType;
  185487. ok = openMovie (props, prop, movie);
  185488. DisposeHandle (dr.dataRef);
  185489. }
  185490. }
  185491. return ok;
  185492. }
  185493. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  185494. const bool isControllerVisible)
  185495. {
  185496. const bool ok = loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible);
  185497. movieFile = movieFile_;
  185498. return ok;
  185499. }
  185500. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  185501. const bool isControllerVisible)
  185502. {
  185503. return loadMovie ((InputStream*) movieURL.createInputStream (false), isControllerVisible);
  185504. }
  185505. void QuickTimeMovieComponent::goToStart()
  185506. {
  185507. setPosition (0.0);
  185508. }
  185509. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  185510. const RectanglePlacement& placement)
  185511. {
  185512. int normalWidth, normalHeight;
  185513. getMovieNormalSize (normalWidth, normalHeight);
  185514. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  185515. {
  185516. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  185517. placement.applyTo (x, y, w, h,
  185518. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  185519. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  185520. if (w > 0 && h > 0)
  185521. {
  185522. setBounds (roundToInt (x), roundToInt (y),
  185523. roundToInt (w), roundToInt (h));
  185524. }
  185525. }
  185526. else
  185527. {
  185528. setBounds (spaceToFitWithin);
  185529. }
  185530. }
  185531. #endif
  185532. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  185533. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185534. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185535. // compiled on its own).
  185536. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  185537. class WebBrowserComponentInternal : public ActiveXControlComponent
  185538. {
  185539. public:
  185540. WebBrowserComponentInternal()
  185541. : browser (0),
  185542. connectionPoint (0),
  185543. adviseCookie (0)
  185544. {
  185545. }
  185546. ~WebBrowserComponentInternal()
  185547. {
  185548. if (connectionPoint != 0)
  185549. connectionPoint->Unadvise (adviseCookie);
  185550. if (browser != 0)
  185551. browser->Release();
  185552. }
  185553. void createBrowser()
  185554. {
  185555. createControl (&CLSID_WebBrowser);
  185556. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  185557. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  185558. if (connectionPointContainer != 0)
  185559. {
  185560. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  185561. &connectionPoint);
  185562. if (connectionPoint != 0)
  185563. {
  185564. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  185565. jassert (owner != 0);
  185566. EventHandler* handler = new EventHandler (owner);
  185567. connectionPoint->Advise (handler, &adviseCookie);
  185568. }
  185569. }
  185570. }
  185571. void goToURL (const String& url,
  185572. const StringArray* headers,
  185573. const MemoryBlock* postData)
  185574. {
  185575. if (browser != 0)
  185576. {
  185577. LPSAFEARRAY sa = 0;
  185578. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  185579. VariantInit (&flags);
  185580. VariantInit (&frame);
  185581. VariantInit (&postDataVar);
  185582. VariantInit (&headersVar);
  185583. if (headers != 0)
  185584. {
  185585. V_VT (&headersVar) = VT_BSTR;
  185586. V_BSTR (&headersVar) = SysAllocString ((const tchar*) headers->joinIntoString ("\r\n"));
  185587. }
  185588. if (postData != 0 && postData->getSize() > 0)
  185589. {
  185590. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  185591. if (sa != 0)
  185592. {
  185593. void* data = 0;
  185594. SafeArrayAccessData (sa, &data);
  185595. jassert (data != 0);
  185596. if (data != 0)
  185597. {
  185598. postData->copyTo (data, 0, postData->getSize());
  185599. SafeArrayUnaccessData (sa);
  185600. VARIANT postDataVar2;
  185601. VariantInit (&postDataVar2);
  185602. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  185603. V_ARRAY (&postDataVar2) = sa;
  185604. postDataVar = postDataVar2;
  185605. }
  185606. }
  185607. }
  185608. browser->Navigate ((BSTR) (const OLECHAR*) url,
  185609. &flags, &frame,
  185610. &postDataVar, &headersVar);
  185611. if (sa != 0)
  185612. SafeArrayDestroy (sa);
  185613. VariantClear (&flags);
  185614. VariantClear (&frame);
  185615. VariantClear (&postDataVar);
  185616. VariantClear (&headersVar);
  185617. }
  185618. }
  185619. IWebBrowser2* browser;
  185620. juce_UseDebuggingNewOperator
  185621. private:
  185622. IConnectionPoint* connectionPoint;
  185623. DWORD adviseCookie;
  185624. class EventHandler : public IDispatch,
  185625. public ComponentMovementWatcher
  185626. {
  185627. public:
  185628. EventHandler (WebBrowserComponent* owner_)
  185629. : ComponentMovementWatcher (owner_),
  185630. owner (owner_),
  185631. refCount (0)
  185632. {
  185633. }
  185634. ~EventHandler()
  185635. {
  185636. }
  185637. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185638. {
  185639. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  185640. {
  185641. AddRef();
  185642. *result = this;
  185643. return S_OK;
  185644. }
  185645. *result = 0;
  185646. return E_NOINTERFACE;
  185647. }
  185648. ULONG __stdcall AddRef() { return ++refCount; }
  185649. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  185650. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  185651. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  185652. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  185653. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  185654. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  185655. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  185656. UINT __RPC_FAR* /*puArgErr*/)
  185657. {
  185658. switch (dispIdMember)
  185659. {
  185660. case DISPID_BEFORENAVIGATE2:
  185661. {
  185662. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  185663. String url;
  185664. if ((vurl->vt & VT_BYREF) != 0)
  185665. url = *vurl->pbstrVal;
  185666. else
  185667. url = vurl->bstrVal;
  185668. *pDispParams->rgvarg->pboolVal
  185669. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185670. : VARIANT_TRUE;
  185671. return S_OK;
  185672. }
  185673. default:
  185674. break;
  185675. }
  185676. return E_NOTIMPL;
  185677. }
  185678. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185679. void componentPeerChanged() {}
  185680. void componentVisibilityChanged (Component&)
  185681. {
  185682. owner->visibilityChanged();
  185683. }
  185684. juce_UseDebuggingNewOperator
  185685. private:
  185686. WebBrowserComponent* const owner;
  185687. int refCount;
  185688. EventHandler (const EventHandler&);
  185689. const EventHandler& operator= (const EventHandler&);
  185690. };
  185691. };
  185692. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185693. : browser (0),
  185694. blankPageShown (false),
  185695. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185696. {
  185697. setOpaque (true);
  185698. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185699. }
  185700. WebBrowserComponent::~WebBrowserComponent()
  185701. {
  185702. delete browser;
  185703. }
  185704. void WebBrowserComponent::goToURL (const String& url,
  185705. const StringArray* headers,
  185706. const MemoryBlock* postData)
  185707. {
  185708. lastURL = url;
  185709. lastHeaders.clear();
  185710. if (headers != 0)
  185711. lastHeaders = *headers;
  185712. lastPostData.setSize (0);
  185713. if (postData != 0)
  185714. lastPostData = *postData;
  185715. blankPageShown = false;
  185716. browser->goToURL (url, headers, postData);
  185717. }
  185718. void WebBrowserComponent::stop()
  185719. {
  185720. if (browser->browser != 0)
  185721. browser->browser->Stop();
  185722. }
  185723. void WebBrowserComponent::goBack()
  185724. {
  185725. lastURL = String::empty;
  185726. blankPageShown = false;
  185727. if (browser->browser != 0)
  185728. browser->browser->GoBack();
  185729. }
  185730. void WebBrowserComponent::goForward()
  185731. {
  185732. lastURL = String::empty;
  185733. if (browser->browser != 0)
  185734. browser->browser->GoForward();
  185735. }
  185736. void WebBrowserComponent::refresh()
  185737. {
  185738. if (browser->browser != 0)
  185739. browser->browser->Refresh();
  185740. }
  185741. void WebBrowserComponent::paint (Graphics& g)
  185742. {
  185743. if (browser->browser == 0)
  185744. g.fillAll (Colours::white);
  185745. }
  185746. void WebBrowserComponent::checkWindowAssociation()
  185747. {
  185748. if (isShowing())
  185749. {
  185750. if (browser->browser == 0 && getPeer() != 0)
  185751. {
  185752. browser->createBrowser();
  185753. reloadLastURL();
  185754. }
  185755. else
  185756. {
  185757. if (blankPageShown)
  185758. goBack();
  185759. }
  185760. }
  185761. else
  185762. {
  185763. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185764. {
  185765. // when the component becomes invisible, some stuff like flash
  185766. // carries on playing audio, so we need to force it onto a blank
  185767. // page to avoid this..
  185768. blankPageShown = true;
  185769. browser->goToURL ("about:blank", 0, 0);
  185770. }
  185771. }
  185772. }
  185773. void WebBrowserComponent::reloadLastURL()
  185774. {
  185775. if (lastURL.isNotEmpty())
  185776. {
  185777. goToURL (lastURL, &lastHeaders, &lastPostData);
  185778. lastURL = String::empty;
  185779. }
  185780. }
  185781. void WebBrowserComponent::parentHierarchyChanged()
  185782. {
  185783. checkWindowAssociation();
  185784. }
  185785. void WebBrowserComponent::resized()
  185786. {
  185787. browser->setSize (getWidth(), getHeight());
  185788. }
  185789. void WebBrowserComponent::visibilityChanged()
  185790. {
  185791. checkWindowAssociation();
  185792. }
  185793. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185794. {
  185795. return true;
  185796. }
  185797. #endif
  185798. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185799. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185800. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185801. // compiled on its own).
  185802. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185803. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185804. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185805. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185806. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185807. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185808. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185809. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185810. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185811. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185812. #define WGL_ACCELERATION_ARB 0x2003
  185813. #define WGL_SWAP_METHOD_ARB 0x2007
  185814. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185815. #define WGL_PIXEL_TYPE_ARB 0x2013
  185816. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185817. #define WGL_COLOR_BITS_ARB 0x2014
  185818. #define WGL_RED_BITS_ARB 0x2015
  185819. #define WGL_GREEN_BITS_ARB 0x2017
  185820. #define WGL_BLUE_BITS_ARB 0x2019
  185821. #define WGL_ALPHA_BITS_ARB 0x201B
  185822. #define WGL_DEPTH_BITS_ARB 0x2022
  185823. #define WGL_STENCIL_BITS_ARB 0x2023
  185824. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185825. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185826. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185827. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185828. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185829. #define WGL_STEREO_ARB 0x2012
  185830. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185831. #define WGL_SAMPLES_ARB 0x2042
  185832. #define WGL_TYPE_RGBA_ARB 0x202B
  185833. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185834. {
  185835. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185836. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185837. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185838. else
  185839. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185840. }
  185841. class WindowedGLContext : public OpenGLContext
  185842. {
  185843. public:
  185844. WindowedGLContext (Component* const component_,
  185845. HGLRC contextToShareWith,
  185846. const OpenGLPixelFormat& pixelFormat)
  185847. : renderContext (0),
  185848. nativeWindow (0),
  185849. dc (0),
  185850. component (component_)
  185851. {
  185852. jassert (component != 0);
  185853. createNativeWindow();
  185854. // Use a default pixel format that should be supported everywhere
  185855. PIXELFORMATDESCRIPTOR pfd;
  185856. zerostruct (pfd);
  185857. pfd.nSize = sizeof (pfd);
  185858. pfd.nVersion = 1;
  185859. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185860. pfd.iPixelType = PFD_TYPE_RGBA;
  185861. pfd.cColorBits = 24;
  185862. pfd.cDepthBits = 16;
  185863. const int format = ChoosePixelFormat (dc, &pfd);
  185864. if (format != 0)
  185865. SetPixelFormat (dc, format, &pfd);
  185866. renderContext = wglCreateContext (dc);
  185867. makeActive();
  185868. setPixelFormat (pixelFormat);
  185869. if (contextToShareWith != 0 && renderContext != 0)
  185870. wglShareLists (contextToShareWith, renderContext);
  185871. }
  185872. ~WindowedGLContext()
  185873. {
  185874. makeInactive();
  185875. wglDeleteContext (renderContext);
  185876. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185877. delete nativeWindow;
  185878. }
  185879. bool makeActive() const throw()
  185880. {
  185881. jassert (renderContext != 0);
  185882. return wglMakeCurrent (dc, renderContext) != 0;
  185883. }
  185884. bool makeInactive() const throw()
  185885. {
  185886. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185887. }
  185888. bool isActive() const throw()
  185889. {
  185890. return wglGetCurrentContext() == renderContext;
  185891. }
  185892. const OpenGLPixelFormat getPixelFormat() const
  185893. {
  185894. OpenGLPixelFormat pf;
  185895. makeActive();
  185896. StringArray availableExtensions;
  185897. getWglExtensions (dc, availableExtensions);
  185898. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185899. return pf;
  185900. }
  185901. void* getRawContext() const throw()
  185902. {
  185903. return renderContext;
  185904. }
  185905. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185906. {
  185907. makeActive();
  185908. PIXELFORMATDESCRIPTOR pfd;
  185909. zerostruct (pfd);
  185910. pfd.nSize = sizeof (pfd);
  185911. pfd.nVersion = 1;
  185912. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185913. pfd.iPixelType = PFD_TYPE_RGBA;
  185914. pfd.iLayerType = PFD_MAIN_PLANE;
  185915. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185916. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185917. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185918. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185919. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185920. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185921. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185922. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185923. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185924. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185925. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185926. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185927. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185928. int format = 0;
  185929. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185930. StringArray availableExtensions;
  185931. getWglExtensions (dc, availableExtensions);
  185932. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185933. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185934. {
  185935. int attributes[64];
  185936. int n = 0;
  185937. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185938. attributes[n++] = GL_TRUE;
  185939. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185940. attributes[n++] = GL_TRUE;
  185941. attributes[n++] = WGL_ACCELERATION_ARB;
  185942. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185943. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185944. attributes[n++] = GL_TRUE;
  185945. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185946. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185947. attributes[n++] = WGL_COLOR_BITS_ARB;
  185948. attributes[n++] = pfd.cColorBits;
  185949. attributes[n++] = WGL_RED_BITS_ARB;
  185950. attributes[n++] = pixelFormat.redBits;
  185951. attributes[n++] = WGL_GREEN_BITS_ARB;
  185952. attributes[n++] = pixelFormat.greenBits;
  185953. attributes[n++] = WGL_BLUE_BITS_ARB;
  185954. attributes[n++] = pixelFormat.blueBits;
  185955. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185956. attributes[n++] = pixelFormat.alphaBits;
  185957. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185958. attributes[n++] = pixelFormat.depthBufferBits;
  185959. if (pixelFormat.stencilBufferBits > 0)
  185960. {
  185961. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185962. attributes[n++] = pixelFormat.stencilBufferBits;
  185963. }
  185964. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185965. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185966. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185967. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185968. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185969. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185970. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185971. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185972. if (availableExtensions.contains ("WGL_ARB_multisample")
  185973. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185974. {
  185975. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185976. attributes[n++] = 1;
  185977. attributes[n++] = WGL_SAMPLES_ARB;
  185978. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185979. }
  185980. attributes[n++] = 0;
  185981. UINT formatsCount;
  185982. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185983. (void) ok;
  185984. jassert (ok);
  185985. }
  185986. else
  185987. {
  185988. format = ChoosePixelFormat (dc, &pfd);
  185989. }
  185990. if (format != 0)
  185991. {
  185992. makeInactive();
  185993. // win32 can't change the pixel format of a window, so need to delete the
  185994. // old one and create a new one..
  185995. jassert (nativeWindow != 0);
  185996. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185997. delete nativeWindow;
  185998. createNativeWindow();
  185999. if (SetPixelFormat (dc, format, &pfd))
  186000. {
  186001. wglDeleteContext (renderContext);
  186002. renderContext = wglCreateContext (dc);
  186003. jassert (renderContext != 0);
  186004. return renderContext != 0;
  186005. }
  186006. }
  186007. return false;
  186008. }
  186009. void updateWindowPosition (int x, int y, int w, int h, int)
  186010. {
  186011. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  186012. x, y, w, h,
  186013. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  186014. }
  186015. void repaint()
  186016. {
  186017. int x, y, w, h;
  186018. nativeWindow->getBounds (x, y, w, h);
  186019. nativeWindow->repaint (0, 0, w, h);
  186020. }
  186021. void swapBuffers()
  186022. {
  186023. SwapBuffers (dc);
  186024. }
  186025. bool setSwapInterval (const int numFramesPerSwap)
  186026. {
  186027. makeActive();
  186028. StringArray availableExtensions;
  186029. getWglExtensions (dc, availableExtensions);
  186030. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  186031. return availableExtensions.contains ("WGL_EXT_swap_control")
  186032. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  186033. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  186034. }
  186035. int getSwapInterval() const
  186036. {
  186037. makeActive();
  186038. StringArray availableExtensions;
  186039. getWglExtensions (dc, availableExtensions);
  186040. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  186041. if (availableExtensions.contains ("WGL_EXT_swap_control")
  186042. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  186043. return wglGetSwapIntervalEXT();
  186044. return 0;
  186045. }
  186046. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  186047. {
  186048. jassert (isActive());
  186049. StringArray availableExtensions;
  186050. getWglExtensions (dc, availableExtensions);
  186051. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  186052. int numTypes = 0;
  186053. if (availableExtensions.contains("WGL_ARB_pixel_format")
  186054. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  186055. {
  186056. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  186057. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  186058. jassertfalse
  186059. }
  186060. else
  186061. {
  186062. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  186063. }
  186064. OpenGLPixelFormat pf;
  186065. for (int i = 0; i < numTypes; ++i)
  186066. {
  186067. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  186068. {
  186069. bool alreadyListed = false;
  186070. for (int j = results.size(); --j >= 0;)
  186071. if (pf == *results.getUnchecked(j))
  186072. alreadyListed = true;
  186073. if (! alreadyListed)
  186074. results.add (new OpenGLPixelFormat (pf));
  186075. }
  186076. }
  186077. }
  186078. void* getNativeWindowHandle() const
  186079. {
  186080. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  186081. }
  186082. juce_UseDebuggingNewOperator
  186083. HGLRC renderContext;
  186084. private:
  186085. Win32ComponentPeer* nativeWindow;
  186086. Component* const component;
  186087. HDC dc;
  186088. void createNativeWindow()
  186089. {
  186090. nativeWindow = new Win32ComponentPeer (component, 0);
  186091. nativeWindow->dontRepaint = true;
  186092. nativeWindow->setVisible (true);
  186093. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  186094. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  186095. if (peer != 0)
  186096. {
  186097. SetParent (hwnd, (HWND) peer->getNativeHandle());
  186098. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  186099. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  186100. }
  186101. dc = GetDC (hwnd);
  186102. }
  186103. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  186104. OpenGLPixelFormat& result,
  186105. const StringArray& availableExtensions) const throw()
  186106. {
  186107. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  186108. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  186109. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  186110. {
  186111. int attributes[32];
  186112. int numAttributes = 0;
  186113. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  186114. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  186115. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  186116. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  186117. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  186118. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  186119. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  186120. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  186121. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  186122. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  186123. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  186124. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  186125. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  186126. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  186127. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  186128. if (availableExtensions.contains ("WGL_ARB_multisample"))
  186129. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  186130. int values[32];
  186131. zeromem (values, sizeof (values));
  186132. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  186133. {
  186134. int n = 0;
  186135. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  186136. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  186137. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  186138. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  186139. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  186140. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  186141. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  186142. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  186143. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  186144. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  186145. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  186146. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  186147. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  186148. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  186149. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  186150. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  186151. return isValidFormat;
  186152. }
  186153. else
  186154. {
  186155. jassertfalse
  186156. }
  186157. }
  186158. else
  186159. {
  186160. PIXELFORMATDESCRIPTOR pfd;
  186161. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  186162. {
  186163. result.redBits = pfd.cRedBits;
  186164. result.greenBits = pfd.cGreenBits;
  186165. result.blueBits = pfd.cBlueBits;
  186166. result.alphaBits = pfd.cAlphaBits;
  186167. result.depthBufferBits = pfd.cDepthBits;
  186168. result.stencilBufferBits = pfd.cStencilBits;
  186169. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  186170. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  186171. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  186172. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  186173. result.fullSceneAntiAliasingNumSamples = 0;
  186174. return true;
  186175. }
  186176. else
  186177. {
  186178. jassertfalse
  186179. }
  186180. }
  186181. return false;
  186182. }
  186183. WindowedGLContext (const WindowedGLContext&);
  186184. const WindowedGLContext& operator= (const WindowedGLContext&);
  186185. };
  186186. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  186187. const OpenGLPixelFormat& pixelFormat,
  186188. const OpenGLContext* const contextToShareWith)
  186189. {
  186190. WindowedGLContext* c = new WindowedGLContext (component,
  186191. contextToShareWith != 0 ? (HGLRC) contextToShareWith->getRawContext() : 0,
  186192. pixelFormat);
  186193. if (c->renderContext == 0)
  186194. deleteAndZero (c);
  186195. return c;
  186196. }
  186197. void* OpenGLComponent::getNativeWindowHandle() const
  186198. {
  186199. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle() : 0;
  186200. }
  186201. void juce_glViewport (const int w, const int h)
  186202. {
  186203. glViewport (0, 0, w, h);
  186204. }
  186205. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  186206. OwnedArray <OpenGLPixelFormat>& results)
  186207. {
  186208. Component tempComp;
  186209. {
  186210. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  186211. wc.makeActive();
  186212. wc.findAlternativeOpenGLPixelFormats (results);
  186213. }
  186214. }
  186215. #endif
  186216. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  186217. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  186218. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  186219. // compiled on its own).
  186220. #if JUCE_INCLUDED_FILE
  186221. #if JUCE_USE_CDREADER
  186222. //***************************************************************************
  186223. // %%% TARGET STATUS VALUES %%%
  186224. //***************************************************************************
  186225. #define STATUS_GOOD 0x00 // Status Good
  186226. #define STATUS_CHKCOND 0x02 // Check Condition
  186227. #define STATUS_CONDMET 0x04 // Condition Met
  186228. #define STATUS_BUSY 0x08 // Busy
  186229. #define STATUS_INTERM 0x10 // Intermediate
  186230. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  186231. #define STATUS_RESCONF 0x18 // Reservation conflict
  186232. #define STATUS_COMTERM 0x22 // Command Terminated
  186233. #define STATUS_QFULL 0x28 // Queue full
  186234. //***************************************************************************
  186235. // %%% SCSI MISCELLANEOUS EQUATES %%%
  186236. //***************************************************************************
  186237. #define MAXLUN 7 // Maximum Logical Unit Id
  186238. #define MAXTARG 7 // Maximum Target Id
  186239. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  186240. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  186241. //***************************************************************************
  186242. // %%% Commands for all Device Types %%%
  186243. //***************************************************************************
  186244. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  186245. #define SCSI_COMPARE 0x39 // Compare (O)
  186246. #define SCSI_COPY 0x18 // Copy (O)
  186247. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  186248. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  186249. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  186250. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  186251. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  186252. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  186253. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  186254. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  186255. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  186256. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  186257. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  186258. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  186259. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  186260. //***************************************************************************
  186261. // %%% Commands Unique to Direct Access Devices %%%
  186262. //***************************************************************************
  186263. #define SCSI_COMPARE 0x39 // Compare (O)
  186264. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  186265. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  186266. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  186267. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  186268. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  186269. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  186270. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  186271. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  186272. #define SCSI_READ_LONG 0x3E // Read Long (O)
  186273. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  186274. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  186275. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  186276. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  186277. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  186278. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  186279. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  186280. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  186281. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  186282. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  186283. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  186284. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  186285. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  186286. #define SCSI_VERIFY 0x2F // Verify (O)
  186287. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  186288. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  186289. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  186290. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  186291. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  186292. //***************************************************************************
  186293. // %%% Commands Unique to Sequential Access Devices %%%
  186294. //***************************************************************************
  186295. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  186296. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  186297. #define SCSI_LOCATE 0x2B // Locate (O)
  186298. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  186299. #define SCSI_READ_POS 0x34 // Read Position (O)
  186300. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  186301. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  186302. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  186303. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  186304. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  186305. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  186306. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  186307. //***************************************************************************
  186308. // %%% Commands Unique to Printer Devices %%%
  186309. //***************************************************************************
  186310. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  186311. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  186312. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  186313. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  186314. //***************************************************************************
  186315. // %%% Commands Unique to Processor Devices %%%
  186316. //***************************************************************************
  186317. #define SCSI_RECEIVE 0x08 // Receive (O)
  186318. #define SCSI_SEND 0x0A // Send (O)
  186319. //***************************************************************************
  186320. // %%% Commands Unique to Write-Once Devices %%%
  186321. //***************************************************************************
  186322. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  186323. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  186324. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  186325. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  186326. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  186327. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  186328. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  186329. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  186330. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  186331. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  186332. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  186333. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  186334. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  186335. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  186336. //***************************************************************************
  186337. // %%% Commands Unique to CD-ROM Devices %%%
  186338. //***************************************************************************
  186339. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  186340. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  186341. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  186342. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  186343. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  186344. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  186345. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  186346. #define SCSI_READHEADER 0x44 // Read Header (O)
  186347. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  186348. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  186349. //***************************************************************************
  186350. // %%% Commands Unique to Scanner Devices %%%
  186351. //***************************************************************************
  186352. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  186353. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  186354. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  186355. #define SCSI_SCAN 0x1B // Scan (O)
  186356. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  186357. //***************************************************************************
  186358. // %%% Commands Unique to Optical Memory Devices %%%
  186359. //***************************************************************************
  186360. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  186361. //***************************************************************************
  186362. // %%% Commands Unique to Medium Changer Devices %%%
  186363. //***************************************************************************
  186364. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  186365. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  186366. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  186367. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  186368. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  186369. //***************************************************************************
  186370. // %%% Commands Unique to Communication Devices %%%
  186371. //***************************************************************************
  186372. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  186373. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  186374. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  186375. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  186376. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  186377. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  186378. //***************************************************************************
  186379. // %%% Request Sense Data Format %%%
  186380. //***************************************************************************
  186381. typedef struct {
  186382. BYTE ErrorCode; // Error Code (70H or 71H)
  186383. BYTE SegmentNum; // Number of current segment descriptor
  186384. BYTE SenseKey; // Sense Key(See bit definitions too)
  186385. BYTE InfoByte0; // Information MSB
  186386. BYTE InfoByte1; // Information MID
  186387. BYTE InfoByte2; // Information MID
  186388. BYTE InfoByte3; // Information LSB
  186389. BYTE AddSenLen; // Additional Sense Length
  186390. BYTE ComSpecInf0; // Command Specific Information MSB
  186391. BYTE ComSpecInf1; // Command Specific Information MID
  186392. BYTE ComSpecInf2; // Command Specific Information MID
  186393. BYTE ComSpecInf3; // Command Specific Information LSB
  186394. BYTE AddSenseCode; // Additional Sense Code
  186395. BYTE AddSenQual; // Additional Sense Code Qualifier
  186396. BYTE FieldRepUCode; // Field Replaceable Unit Code
  186397. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  186398. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  186399. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  186400. BYTE AddSenseBytes; // Additional Sense Bytes
  186401. } SENSE_DATA_FMT;
  186402. //***************************************************************************
  186403. // %%% REQUEST SENSE ERROR CODE %%%
  186404. //***************************************************************************
  186405. #define SERROR_CURRENT 0x70 // Current Errors
  186406. #define SERROR_DEFERED 0x71 // Deferred Errors
  186407. //***************************************************************************
  186408. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  186409. //***************************************************************************
  186410. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  186411. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  186412. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  186413. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  186414. //***************************************************************************
  186415. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  186416. //***************************************************************************
  186417. #define KEY_NOSENSE 0x00 // No Sense
  186418. #define KEY_RECERROR 0x01 // Recovered Error
  186419. #define KEY_NOTREADY 0x02 // Not Ready
  186420. #define KEY_MEDIUMERR 0x03 // Medium Error
  186421. #define KEY_HARDERROR 0x04 // Hardware Error
  186422. #define KEY_ILLGLREQ 0x05 // Illegal Request
  186423. #define KEY_UNITATT 0x06 // Unit Attention
  186424. #define KEY_DATAPROT 0x07 // Data Protect
  186425. #define KEY_BLANKCHK 0x08 // Blank Check
  186426. #define KEY_VENDSPEC 0x09 // Vendor Specific
  186427. #define KEY_COPYABORT 0x0A // Copy Abort
  186428. #define KEY_EQUAL 0x0C // Equal (Search)
  186429. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  186430. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  186431. #define KEY_RESERVED 0x0F // Reserved
  186432. //***************************************************************************
  186433. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  186434. //***************************************************************************
  186435. #define DTYPE_DASD 0x00 // Disk Device
  186436. #define DTYPE_SEQD 0x01 // Tape Device
  186437. #define DTYPE_PRNT 0x02 // Printer
  186438. #define DTYPE_PROC 0x03 // Processor
  186439. #define DTYPE_WORM 0x04 // Write-once read-multiple
  186440. #define DTYPE_CROM 0x05 // CD-ROM device
  186441. #define DTYPE_SCAN 0x06 // Scanner device
  186442. #define DTYPE_OPTI 0x07 // Optical memory device
  186443. #define DTYPE_JUKE 0x08 // Medium Changer device
  186444. #define DTYPE_COMM 0x09 // Communications device
  186445. #define DTYPE_RESL 0x0A // Reserved (low)
  186446. #define DTYPE_RESH 0x1E // Reserved (high)
  186447. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  186448. //***************************************************************************
  186449. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  186450. //***************************************************************************
  186451. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  186452. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  186453. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  186454. #define ANSI_RESLO 0x3 // Reserved (low)
  186455. #define ANSI_RESHI 0x7 // Reserved (high)
  186456. typedef struct
  186457. {
  186458. USHORT Length;
  186459. UCHAR ScsiStatus;
  186460. UCHAR PathId;
  186461. UCHAR TargetId;
  186462. UCHAR Lun;
  186463. UCHAR CdbLength;
  186464. UCHAR SenseInfoLength;
  186465. UCHAR DataIn;
  186466. ULONG DataTransferLength;
  186467. ULONG TimeOutValue;
  186468. ULONG DataBufferOffset;
  186469. ULONG SenseInfoOffset;
  186470. UCHAR Cdb[16];
  186471. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  186472. typedef struct
  186473. {
  186474. USHORT Length;
  186475. UCHAR ScsiStatus;
  186476. UCHAR PathId;
  186477. UCHAR TargetId;
  186478. UCHAR Lun;
  186479. UCHAR CdbLength;
  186480. UCHAR SenseInfoLength;
  186481. UCHAR DataIn;
  186482. ULONG DataTransferLength;
  186483. ULONG TimeOutValue;
  186484. PVOID DataBuffer;
  186485. ULONG SenseInfoOffset;
  186486. UCHAR Cdb[16];
  186487. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  186488. typedef struct
  186489. {
  186490. SCSI_PASS_THROUGH_DIRECT spt;
  186491. ULONG Filler;
  186492. UCHAR ucSenseBuf[32];
  186493. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  186494. typedef struct
  186495. {
  186496. ULONG Length;
  186497. UCHAR PortNumber;
  186498. UCHAR PathId;
  186499. UCHAR TargetId;
  186500. UCHAR Lun;
  186501. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  186502. #define METHOD_BUFFERED 0
  186503. #define METHOD_IN_DIRECT 1
  186504. #define METHOD_OUT_DIRECT 2
  186505. #define METHOD_NEITHER 3
  186506. #define FILE_ANY_ACCESS 0
  186507. #ifndef FILE_READ_ACCESS
  186508. #define FILE_READ_ACCESS (0x0001)
  186509. #endif
  186510. #ifndef FILE_WRITE_ACCESS
  186511. #define FILE_WRITE_ACCESS (0x0002)
  186512. #endif
  186513. #define IOCTL_SCSI_BASE 0x00000004
  186514. #define SCSI_IOCTL_DATA_OUT 0
  186515. #define SCSI_IOCTL_DATA_IN 1
  186516. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  186517. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  186518. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  186519. )
  186520. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186521. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  186522. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186523. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  186524. #define SENSE_LEN 14
  186525. #define SRB_DIR_SCSI 0x00
  186526. #define SRB_POSTING 0x01
  186527. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  186528. #define SRB_DIR_IN 0x08
  186529. #define SRB_DIR_OUT 0x10
  186530. #define SRB_EVENT_NOTIFY 0x40
  186531. #define RESIDUAL_COUNT_SUPPORTED 0x02
  186532. #define MAX_SRB_TIMEOUT 1080001u
  186533. #define DEFAULT_SRB_TIMEOUT 1080001u
  186534. #define SC_HA_INQUIRY 0x00
  186535. #define SC_GET_DEV_TYPE 0x01
  186536. #define SC_EXEC_SCSI_CMD 0x02
  186537. #define SC_ABORT_SRB 0x03
  186538. #define SC_RESET_DEV 0x04
  186539. #define SC_SET_HA_PARMS 0x05
  186540. #define SC_GET_DISK_INFO 0x06
  186541. #define SC_RESCAN_SCSI_BUS 0x07
  186542. #define SC_GETSET_TIMEOUTS 0x08
  186543. #define SS_PENDING 0x00
  186544. #define SS_COMP 0x01
  186545. #define SS_ABORTED 0x02
  186546. #define SS_ABORT_FAIL 0x03
  186547. #define SS_ERR 0x04
  186548. #define SS_INVALID_CMD 0x80
  186549. #define SS_INVALID_HA 0x81
  186550. #define SS_NO_DEVICE 0x82
  186551. #define SS_INVALID_SRB 0xE0
  186552. #define SS_OLD_MANAGER 0xE1
  186553. #define SS_BUFFER_ALIGN 0xE1
  186554. #define SS_ILLEGAL_MODE 0xE2
  186555. #define SS_NO_ASPI 0xE3
  186556. #define SS_FAILED_INIT 0xE4
  186557. #define SS_ASPI_IS_BUSY 0xE5
  186558. #define SS_BUFFER_TO_BIG 0xE6
  186559. #define SS_BUFFER_TOO_BIG 0xE6
  186560. #define SS_MISMATCHED_COMPONENTS 0xE7
  186561. #define SS_NO_ADAPTERS 0xE8
  186562. #define SS_INSUFFICIENT_RESOURCES 0xE9
  186563. #define SS_ASPI_IS_SHUTDOWN 0xEA
  186564. #define SS_BAD_INSTALL 0xEB
  186565. #define HASTAT_OK 0x00
  186566. #define HASTAT_SEL_TO 0x11
  186567. #define HASTAT_DO_DU 0x12
  186568. #define HASTAT_BUS_FREE 0x13
  186569. #define HASTAT_PHASE_ERR 0x14
  186570. #define HASTAT_TIMEOUT 0x09
  186571. #define HASTAT_COMMAND_TIMEOUT 0x0B
  186572. #define HASTAT_MESSAGE_REJECT 0x0D
  186573. #define HASTAT_BUS_RESET 0x0E
  186574. #define HASTAT_PARITY_ERROR 0x0F
  186575. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  186576. #define PACKED
  186577. #pragma pack(1)
  186578. typedef struct
  186579. {
  186580. BYTE SRB_Cmd;
  186581. BYTE SRB_Status;
  186582. BYTE SRB_HaID;
  186583. BYTE SRB_Flags;
  186584. DWORD SRB_Hdr_Rsvd;
  186585. BYTE HA_Count;
  186586. BYTE HA_SCSI_ID;
  186587. BYTE HA_ManagerId[16];
  186588. BYTE HA_Identifier[16];
  186589. BYTE HA_Unique[16];
  186590. WORD HA_Rsvd1;
  186591. BYTE pad[20];
  186592. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  186593. typedef struct
  186594. {
  186595. BYTE SRB_Cmd;
  186596. BYTE SRB_Status;
  186597. BYTE SRB_HaID;
  186598. BYTE SRB_Flags;
  186599. DWORD SRB_Hdr_Rsvd;
  186600. BYTE SRB_Target;
  186601. BYTE SRB_Lun;
  186602. BYTE SRB_DeviceType;
  186603. BYTE SRB_Rsvd1;
  186604. BYTE pad[68];
  186605. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  186606. typedef struct
  186607. {
  186608. BYTE SRB_Cmd;
  186609. BYTE SRB_Status;
  186610. BYTE SRB_HaID;
  186611. BYTE SRB_Flags;
  186612. DWORD SRB_Hdr_Rsvd;
  186613. BYTE SRB_Target;
  186614. BYTE SRB_Lun;
  186615. WORD SRB_Rsvd1;
  186616. DWORD SRB_BufLen;
  186617. BYTE FAR *SRB_BufPointer;
  186618. BYTE SRB_SenseLen;
  186619. BYTE SRB_CDBLen;
  186620. BYTE SRB_HaStat;
  186621. BYTE SRB_TargStat;
  186622. VOID FAR *SRB_PostProc;
  186623. BYTE SRB_Rsvd2[20];
  186624. BYTE CDBByte[16];
  186625. BYTE SenseArea[SENSE_LEN+2];
  186626. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  186627. typedef struct
  186628. {
  186629. BYTE SRB_Cmd;
  186630. BYTE SRB_Status;
  186631. BYTE SRB_HaId;
  186632. BYTE SRB_Flags;
  186633. DWORD SRB_Hdr_Rsvd;
  186634. } PACKED SRB, *PSRB, FAR *LPSRB;
  186635. #pragma pack()
  186636. struct CDDeviceInfo
  186637. {
  186638. char vendor[9];
  186639. char productId[17];
  186640. char rev[5];
  186641. char vendorSpec[21];
  186642. BYTE ha;
  186643. BYTE tgt;
  186644. BYTE lun;
  186645. char scsiDriveLetter; // will be 0 if not using scsi
  186646. };
  186647. class CDReadBuffer
  186648. {
  186649. public:
  186650. int startFrame;
  186651. int numFrames;
  186652. int dataStartOffset;
  186653. int dataLength;
  186654. BYTE* buffer;
  186655. int bufferSize;
  186656. int index;
  186657. bool wantsIndex;
  186658. CDReadBuffer (const int numberOfFrames)
  186659. : startFrame (0),
  186660. numFrames (0),
  186661. dataStartOffset (0),
  186662. dataLength (0),
  186663. index (0),
  186664. wantsIndex (false)
  186665. {
  186666. bufferSize = 2352 * numberOfFrames;
  186667. buffer = (BYTE*) malloc (bufferSize);
  186668. }
  186669. ~CDReadBuffer()
  186670. {
  186671. free (buffer);
  186672. }
  186673. bool isZero() const
  186674. {
  186675. BYTE* p = buffer + dataStartOffset;
  186676. for (int i = dataLength; --i >= 0;)
  186677. if (*p++ != 0)
  186678. return false;
  186679. return true;
  186680. }
  186681. };
  186682. class CDDeviceHandle;
  186683. class CDController
  186684. {
  186685. public:
  186686. CDController();
  186687. virtual ~CDController();
  186688. virtual bool read (CDReadBuffer* t) = 0;
  186689. virtual void shutDown();
  186690. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186691. int getLastIndex();
  186692. public:
  186693. bool initialised;
  186694. CDDeviceHandle* deviceInfo;
  186695. int framesToCheck, framesOverlap;
  186696. void prepare (SRB_ExecSCSICmd& s);
  186697. void perform (SRB_ExecSCSICmd& s);
  186698. void setPaused (bool paused);
  186699. };
  186700. #pragma pack(1)
  186701. struct TOCTRACK
  186702. {
  186703. BYTE rsvd;
  186704. BYTE ADR;
  186705. BYTE trackNumber;
  186706. BYTE rsvd2;
  186707. BYTE addr[4];
  186708. };
  186709. struct TOC
  186710. {
  186711. WORD tocLen;
  186712. BYTE firstTrack;
  186713. BYTE lastTrack;
  186714. TOCTRACK tracks[100];
  186715. };
  186716. #pragma pack()
  186717. enum
  186718. {
  186719. READTYPE_ANY = 0,
  186720. READTYPE_ATAPI1 = 1,
  186721. READTYPE_ATAPI2 = 2,
  186722. READTYPE_READ6 = 3,
  186723. READTYPE_READ10 = 4,
  186724. READTYPE_READ_D8 = 5,
  186725. READTYPE_READ_D4 = 6,
  186726. READTYPE_READ_D4_1 = 7,
  186727. READTYPE_READ10_2 = 8
  186728. };
  186729. class CDDeviceHandle
  186730. {
  186731. public:
  186732. CDDeviceHandle (const CDDeviceInfo* const device)
  186733. : scsiHandle (0),
  186734. readType (READTYPE_ANY),
  186735. controller (0)
  186736. {
  186737. memcpy (&info, device, sizeof (info));
  186738. }
  186739. ~CDDeviceHandle()
  186740. {
  186741. if (controller != 0)
  186742. {
  186743. controller->shutDown();
  186744. delete controller;
  186745. }
  186746. if (scsiHandle != 0)
  186747. CloseHandle (scsiHandle);
  186748. }
  186749. bool readTOC (TOC* lpToc, bool useMSF);
  186750. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186751. void openDrawer (bool shouldBeOpen);
  186752. CDDeviceInfo info;
  186753. HANDLE scsiHandle;
  186754. BYTE readType;
  186755. private:
  186756. CDController* controller;
  186757. bool testController (const int readType,
  186758. CDController* const newController,
  186759. CDReadBuffer* const bufferToUse);
  186760. };
  186761. DWORD (*fGetASPI32SupportInfo)(void);
  186762. DWORD (*fSendASPI32Command)(LPSRB);
  186763. static HINSTANCE winAspiLib = 0;
  186764. static bool usingScsi = false;
  186765. static bool initialised = false;
  186766. static bool InitialiseCDRipper()
  186767. {
  186768. if (! initialised)
  186769. {
  186770. initialised = true;
  186771. OSVERSIONINFO info;
  186772. info.dwOSVersionInfoSize = sizeof (info);
  186773. GetVersionEx (&info);
  186774. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186775. if (! usingScsi)
  186776. {
  186777. fGetASPI32SupportInfo = 0;
  186778. fSendASPI32Command = 0;
  186779. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186780. if (winAspiLib != 0)
  186781. {
  186782. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186783. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186784. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186785. return false;
  186786. }
  186787. else
  186788. {
  186789. usingScsi = true;
  186790. }
  186791. }
  186792. }
  186793. return true;
  186794. }
  186795. static void DeinitialiseCDRipper()
  186796. {
  186797. if (winAspiLib != 0)
  186798. {
  186799. fGetASPI32SupportInfo = 0;
  186800. fSendASPI32Command = 0;
  186801. FreeLibrary (winAspiLib);
  186802. winAspiLib = 0;
  186803. }
  186804. initialised = false;
  186805. }
  186806. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186807. {
  186808. TCHAR devicePath[8];
  186809. devicePath[0] = '\\';
  186810. devicePath[1] = '\\';
  186811. devicePath[2] = '.';
  186812. devicePath[3] = '\\';
  186813. devicePath[4] = driveLetter;
  186814. devicePath[5] = ':';
  186815. devicePath[6] = 0;
  186816. OSVERSIONINFO info;
  186817. info.dwOSVersionInfoSize = sizeof (info);
  186818. GetVersionEx (&info);
  186819. DWORD flags = GENERIC_READ;
  186820. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186821. flags = GENERIC_READ | GENERIC_WRITE;
  186822. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186823. if (h == INVALID_HANDLE_VALUE)
  186824. {
  186825. flags ^= GENERIC_WRITE;
  186826. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186827. }
  186828. return h;
  186829. }
  186830. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186831. const char driveLetter,
  186832. HANDLE& deviceHandle,
  186833. const bool retryOnFailure = true)
  186834. {
  186835. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186836. zerostruct (s);
  186837. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186838. s.spt.CdbLength = srb->SRB_CDBLen;
  186839. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186840. ? SCSI_IOCTL_DATA_IN
  186841. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186842. ? SCSI_IOCTL_DATA_OUT
  186843. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186844. s.spt.DataTransferLength = srb->SRB_BufLen;
  186845. s.spt.TimeOutValue = 5;
  186846. s.spt.DataBuffer = srb->SRB_BufPointer;
  186847. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186848. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186849. srb->SRB_Status = SS_ERR;
  186850. srb->SRB_TargStat = 0x0004;
  186851. DWORD bytesReturned = 0;
  186852. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186853. &s, sizeof (s),
  186854. &s, sizeof (s),
  186855. &bytesReturned, 0) != 0)
  186856. {
  186857. srb->SRB_Status = SS_COMP;
  186858. }
  186859. else if (retryOnFailure)
  186860. {
  186861. const DWORD error = GetLastError();
  186862. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186863. {
  186864. if (error != ERROR_INVALID_HANDLE)
  186865. CloseHandle (deviceHandle);
  186866. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186867. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186868. }
  186869. }
  186870. return srb->SRB_Status;
  186871. }
  186872. // Controller types..
  186873. class ControllerType1 : public CDController
  186874. {
  186875. public:
  186876. ControllerType1() {}
  186877. ~ControllerType1() {}
  186878. bool read (CDReadBuffer* rb)
  186879. {
  186880. if (rb->numFrames * 2352 > rb->bufferSize)
  186881. return false;
  186882. SRB_ExecSCSICmd s;
  186883. prepare (s);
  186884. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186885. s.SRB_BufLen = rb->bufferSize;
  186886. s.SRB_BufPointer = rb->buffer;
  186887. s.SRB_CDBLen = 12;
  186888. s.CDBByte[0] = 0xBE;
  186889. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186890. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186891. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186892. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186893. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186894. perform (s);
  186895. if (s.SRB_Status != SS_COMP)
  186896. return false;
  186897. rb->dataLength = rb->numFrames * 2352;
  186898. rb->dataStartOffset = 0;
  186899. return true;
  186900. }
  186901. };
  186902. class ControllerType2 : public CDController
  186903. {
  186904. public:
  186905. ControllerType2() {}
  186906. ~ControllerType2() {}
  186907. void shutDown()
  186908. {
  186909. if (initialised)
  186910. {
  186911. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186912. SRB_ExecSCSICmd s;
  186913. prepare (s);
  186914. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186915. s.SRB_BufLen = 0x0C;
  186916. s.SRB_BufPointer = bufPointer;
  186917. s.SRB_CDBLen = 6;
  186918. s.CDBByte[0] = 0x15;
  186919. s.CDBByte[4] = 0x0C;
  186920. perform (s);
  186921. }
  186922. }
  186923. bool init()
  186924. {
  186925. SRB_ExecSCSICmd s;
  186926. s.SRB_Status = SS_ERR;
  186927. if (deviceInfo->readType == READTYPE_READ10_2)
  186928. {
  186929. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186930. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186931. for (int i = 0; i < 2; ++i)
  186932. {
  186933. prepare (s);
  186934. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186935. s.SRB_BufLen = 0x14;
  186936. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186937. s.SRB_CDBLen = 6;
  186938. s.CDBByte[0] = 0x15;
  186939. s.CDBByte[1] = 0x10;
  186940. s.CDBByte[4] = 0x14;
  186941. perform (s);
  186942. if (s.SRB_Status != SS_COMP)
  186943. return false;
  186944. }
  186945. }
  186946. else
  186947. {
  186948. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186949. prepare (s);
  186950. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186951. s.SRB_BufLen = 0x0C;
  186952. s.SRB_BufPointer = bufPointer;
  186953. s.SRB_CDBLen = 6;
  186954. s.CDBByte[0] = 0x15;
  186955. s.CDBByte[4] = 0x0C;
  186956. perform (s);
  186957. }
  186958. return s.SRB_Status == SS_COMP;
  186959. }
  186960. bool read (CDReadBuffer* rb)
  186961. {
  186962. if (rb->numFrames * 2352 > rb->bufferSize)
  186963. return false;
  186964. if (!initialised)
  186965. {
  186966. initialised = init();
  186967. if (!initialised)
  186968. return false;
  186969. }
  186970. SRB_ExecSCSICmd s;
  186971. prepare (s);
  186972. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186973. s.SRB_BufLen = rb->bufferSize;
  186974. s.SRB_BufPointer = rb->buffer;
  186975. s.SRB_CDBLen = 10;
  186976. s.CDBByte[0] = 0x28;
  186977. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186978. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186979. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186980. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186981. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186982. perform (s);
  186983. if (s.SRB_Status != SS_COMP)
  186984. return false;
  186985. rb->dataLength = rb->numFrames * 2352;
  186986. rb->dataStartOffset = 0;
  186987. return true;
  186988. }
  186989. };
  186990. class ControllerType3 : public CDController
  186991. {
  186992. public:
  186993. ControllerType3() {}
  186994. ~ControllerType3() {}
  186995. bool read (CDReadBuffer* rb)
  186996. {
  186997. if (rb->numFrames * 2352 > rb->bufferSize)
  186998. return false;
  186999. if (!initialised)
  187000. {
  187001. setPaused (false);
  187002. initialised = true;
  187003. }
  187004. SRB_ExecSCSICmd s;
  187005. prepare (s);
  187006. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187007. s.SRB_BufLen = rb->numFrames * 2352;
  187008. s.SRB_BufPointer = rb->buffer;
  187009. s.SRB_CDBLen = 12;
  187010. s.CDBByte[0] = 0xD8;
  187011. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  187012. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  187013. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  187014. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  187015. perform (s);
  187016. if (s.SRB_Status != SS_COMP)
  187017. return false;
  187018. rb->dataLength = rb->numFrames * 2352;
  187019. rb->dataStartOffset = 0;
  187020. return true;
  187021. }
  187022. };
  187023. class ControllerType4 : public CDController
  187024. {
  187025. public:
  187026. ControllerType4() {}
  187027. ~ControllerType4() {}
  187028. bool selectD4Mode()
  187029. {
  187030. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  187031. SRB_ExecSCSICmd s;
  187032. prepare (s);
  187033. s.SRB_Flags = SRB_EVENT_NOTIFY;
  187034. s.SRB_CDBLen = 6;
  187035. s.SRB_BufLen = 12;
  187036. s.SRB_BufPointer = bufPointer;
  187037. s.CDBByte[0] = 0x15;
  187038. s.CDBByte[1] = 0x10;
  187039. s.CDBByte[4] = 0x08;
  187040. perform (s);
  187041. return s.SRB_Status == SS_COMP;
  187042. }
  187043. bool read (CDReadBuffer* rb)
  187044. {
  187045. if (rb->numFrames * 2352 > rb->bufferSize)
  187046. return false;
  187047. if (!initialised)
  187048. {
  187049. setPaused (true);
  187050. if (deviceInfo->readType == READTYPE_READ_D4_1)
  187051. selectD4Mode();
  187052. initialised = true;
  187053. }
  187054. SRB_ExecSCSICmd s;
  187055. prepare (s);
  187056. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187057. s.SRB_BufLen = rb->bufferSize;
  187058. s.SRB_BufPointer = rb->buffer;
  187059. s.SRB_CDBLen = 10;
  187060. s.CDBByte[0] = 0xD4;
  187061. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  187062. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  187063. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  187064. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  187065. perform (s);
  187066. if (s.SRB_Status != SS_COMP)
  187067. return false;
  187068. rb->dataLength = rb->numFrames * 2352;
  187069. rb->dataStartOffset = 0;
  187070. return true;
  187071. }
  187072. };
  187073. CDController::CDController() : initialised (false)
  187074. {
  187075. }
  187076. CDController::~CDController()
  187077. {
  187078. }
  187079. void CDController::prepare (SRB_ExecSCSICmd& s)
  187080. {
  187081. zerostruct (s);
  187082. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187083. s.SRB_HaID = deviceInfo->info.ha;
  187084. s.SRB_Target = deviceInfo->info.tgt;
  187085. s.SRB_Lun = deviceInfo->info.lun;
  187086. s.SRB_SenseLen = SENSE_LEN;
  187087. }
  187088. void CDController::perform (SRB_ExecSCSICmd& s)
  187089. {
  187090. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187091. s.SRB_PostProc = (void*)event;
  187092. ResetEvent (event);
  187093. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  187094. deviceInfo->info.scsiDriveLetter,
  187095. deviceInfo->scsiHandle)
  187096. : fSendASPI32Command ((LPSRB)&s);
  187097. if (status == SS_PENDING)
  187098. WaitForSingleObject (event, 4000);
  187099. CloseHandle (event);
  187100. }
  187101. void CDController::setPaused (bool paused)
  187102. {
  187103. SRB_ExecSCSICmd s;
  187104. prepare (s);
  187105. s.SRB_Flags = SRB_EVENT_NOTIFY;
  187106. s.SRB_CDBLen = 10;
  187107. s.CDBByte[0] = 0x4B;
  187108. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  187109. perform (s);
  187110. }
  187111. void CDController::shutDown()
  187112. {
  187113. }
  187114. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  187115. {
  187116. if (overlapBuffer != 0)
  187117. {
  187118. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  187119. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  187120. if (doJitter
  187121. && overlapBuffer->startFrame > 0
  187122. && overlapBuffer->numFrames > 0
  187123. && overlapBuffer->dataLength > 0)
  187124. {
  187125. const int numFrames = rb->numFrames;
  187126. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  187127. {
  187128. rb->startFrame -= framesOverlap;
  187129. if (framesToCheck < framesOverlap
  187130. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  187131. rb->numFrames += framesOverlap;
  187132. }
  187133. else
  187134. {
  187135. overlapBuffer->dataLength = 0;
  187136. overlapBuffer->startFrame = 0;
  187137. overlapBuffer->numFrames = 0;
  187138. }
  187139. }
  187140. if (! read (rb))
  187141. return false;
  187142. if (doJitter)
  187143. {
  187144. const int checkLen = framesToCheck * 2352;
  187145. const int maxToCheck = rb->dataLength - checkLen;
  187146. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  187147. return true;
  187148. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  187149. bool found = false;
  187150. for (int i = 0; i < maxToCheck; ++i)
  187151. {
  187152. if (!memcmp (p, rb->buffer + i, checkLen))
  187153. {
  187154. i += checkLen;
  187155. rb->dataStartOffset = i;
  187156. rb->dataLength -= i;
  187157. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  187158. found = true;
  187159. break;
  187160. }
  187161. }
  187162. rb->numFrames = rb->dataLength / 2352;
  187163. rb->dataLength = 2352 * rb->numFrames;
  187164. if (!found)
  187165. return false;
  187166. }
  187167. if (canDoJitter)
  187168. {
  187169. memcpy (overlapBuffer->buffer,
  187170. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  187171. 2352 * framesToCheck);
  187172. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  187173. overlapBuffer->numFrames = framesToCheck;
  187174. overlapBuffer->dataLength = 2352 * framesToCheck;
  187175. overlapBuffer->dataStartOffset = 0;
  187176. }
  187177. else
  187178. {
  187179. overlapBuffer->startFrame = 0;
  187180. overlapBuffer->numFrames = 0;
  187181. overlapBuffer->dataLength = 0;
  187182. }
  187183. return true;
  187184. }
  187185. else
  187186. {
  187187. return read (rb);
  187188. }
  187189. }
  187190. int CDController::getLastIndex()
  187191. {
  187192. char qdata[100];
  187193. SRB_ExecSCSICmd s;
  187194. prepare (s);
  187195. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187196. s.SRB_BufLen = sizeof (qdata);
  187197. s.SRB_BufPointer = (BYTE*)qdata;
  187198. s.SRB_CDBLen = 12;
  187199. s.CDBByte[0] = 0x42;
  187200. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  187201. s.CDBByte[2] = 64;
  187202. s.CDBByte[3] = 1; // get current position
  187203. s.CDBByte[7] = 0;
  187204. s.CDBByte[8] = (BYTE)sizeof (qdata);
  187205. perform (s);
  187206. if (s.SRB_Status == SS_COMP)
  187207. return qdata[7];
  187208. return 0;
  187209. }
  187210. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  187211. {
  187212. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187213. SRB_ExecSCSICmd s;
  187214. zerostruct (s);
  187215. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187216. s.SRB_HaID = info.ha;
  187217. s.SRB_Target = info.tgt;
  187218. s.SRB_Lun = info.lun;
  187219. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187220. s.SRB_BufLen = 0x324;
  187221. s.SRB_BufPointer = (BYTE*)lpToc;
  187222. s.SRB_SenseLen = 0x0E;
  187223. s.SRB_CDBLen = 0x0A;
  187224. s.SRB_PostProc = (void*)event;
  187225. s.CDBByte[0] = 0x43;
  187226. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  187227. s.CDBByte[7] = 0x03;
  187228. s.CDBByte[8] = 0x24;
  187229. ResetEvent (event);
  187230. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187231. : fSendASPI32Command ((LPSRB)&s);
  187232. if (status == SS_PENDING)
  187233. WaitForSingleObject (event, 4000);
  187234. CloseHandle (event);
  187235. return (s.SRB_Status == SS_COMP);
  187236. }
  187237. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  187238. CDReadBuffer* const overlapBuffer)
  187239. {
  187240. if (controller == 0)
  187241. {
  187242. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  187243. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  187244. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  187245. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  187246. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  187247. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  187248. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  187249. }
  187250. buffer->index = 0;
  187251. if ((controller != 0)
  187252. && controller->readAudio (buffer, overlapBuffer))
  187253. {
  187254. if (buffer->wantsIndex)
  187255. buffer->index = controller->getLastIndex();
  187256. return true;
  187257. }
  187258. return false;
  187259. }
  187260. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  187261. {
  187262. if (shouldBeOpen)
  187263. {
  187264. if (controller != 0)
  187265. {
  187266. controller->shutDown();
  187267. delete controller;
  187268. controller = 0;
  187269. }
  187270. if (scsiHandle != 0)
  187271. {
  187272. CloseHandle (scsiHandle);
  187273. scsiHandle = 0;
  187274. }
  187275. }
  187276. SRB_ExecSCSICmd s;
  187277. zerostruct (s);
  187278. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187279. s.SRB_HaID = info.ha;
  187280. s.SRB_Target = info.tgt;
  187281. s.SRB_Lun = info.lun;
  187282. s.SRB_SenseLen = SENSE_LEN;
  187283. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187284. s.SRB_BufLen = 0;
  187285. s.SRB_BufPointer = 0;
  187286. s.SRB_CDBLen = 12;
  187287. s.CDBByte[0] = 0x1b;
  187288. s.CDBByte[1] = (BYTE)(info.lun << 5);
  187289. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  187290. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187291. s.SRB_PostProc = (void*)event;
  187292. ResetEvent (event);
  187293. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187294. : fSendASPI32Command ((LPSRB)&s);
  187295. if (status == SS_PENDING)
  187296. WaitForSingleObject (event, 4000);
  187297. CloseHandle (event);
  187298. }
  187299. bool CDDeviceHandle::testController (const int type,
  187300. CDController* const newController,
  187301. CDReadBuffer* const rb)
  187302. {
  187303. controller = newController;
  187304. readType = (BYTE)type;
  187305. controller->deviceInfo = this;
  187306. controller->framesToCheck = 1;
  187307. controller->framesOverlap = 3;
  187308. bool passed = false;
  187309. memset (rb->buffer, 0xcd, rb->bufferSize);
  187310. if (controller->read (rb))
  187311. {
  187312. passed = true;
  187313. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  187314. int wrong = 0;
  187315. for (int i = rb->dataLength / 4; --i >= 0;)
  187316. {
  187317. if (*p++ == (int) 0xcdcdcdcd)
  187318. {
  187319. if (++wrong == 4)
  187320. {
  187321. passed = false;
  187322. break;
  187323. }
  187324. }
  187325. else
  187326. {
  187327. wrong = 0;
  187328. }
  187329. }
  187330. }
  187331. if (! passed)
  187332. {
  187333. controller->shutDown();
  187334. delete controller;
  187335. controller = 0;
  187336. }
  187337. return passed;
  187338. }
  187339. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  187340. {
  187341. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187342. const int bufSize = 128;
  187343. BYTE buffer[bufSize];
  187344. zeromem (buffer, bufSize);
  187345. SRB_ExecSCSICmd s;
  187346. zerostruct (s);
  187347. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187348. s.SRB_HaID = ha;
  187349. s.SRB_Target = tgt;
  187350. s.SRB_Lun = lun;
  187351. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187352. s.SRB_BufLen = bufSize;
  187353. s.SRB_BufPointer = buffer;
  187354. s.SRB_SenseLen = SENSE_LEN;
  187355. s.SRB_CDBLen = 6;
  187356. s.SRB_PostProc = (void*)event;
  187357. s.CDBByte[0] = SCSI_INQUIRY;
  187358. s.CDBByte[4] = 100;
  187359. ResetEvent (event);
  187360. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  187361. WaitForSingleObject (event, 4000);
  187362. CloseHandle (event);
  187363. if (s.SRB_Status == SS_COMP)
  187364. {
  187365. memcpy (dev->vendor, &buffer[8], 8);
  187366. memcpy (dev->productId, &buffer[16], 16);
  187367. memcpy (dev->rev, &buffer[32], 4);
  187368. memcpy (dev->vendorSpec, &buffer[36], 20);
  187369. }
  187370. }
  187371. static int FindCDDevices (CDDeviceInfo* const list,
  187372. int maxItems)
  187373. {
  187374. int count = 0;
  187375. if (usingScsi)
  187376. {
  187377. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  187378. {
  187379. TCHAR drivePath[8];
  187380. drivePath[0] = driveLetter;
  187381. drivePath[1] = ':';
  187382. drivePath[2] = '\\';
  187383. drivePath[3] = 0;
  187384. if (GetDriveType (drivePath) == DRIVE_CDROM)
  187385. {
  187386. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  187387. if (h != INVALID_HANDLE_VALUE)
  187388. {
  187389. BYTE buffer[100], passThroughStruct[1024];
  187390. zeromem (buffer, sizeof (buffer));
  187391. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187392. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  187393. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  187394. p->spt.CdbLength = 6;
  187395. p->spt.SenseInfoLength = 24;
  187396. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  187397. p->spt.DataTransferLength = 100;
  187398. p->spt.TimeOutValue = 2;
  187399. p->spt.DataBuffer = buffer;
  187400. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  187401. p->spt.Cdb[0] = 0x12;
  187402. p->spt.Cdb[4] = 100;
  187403. DWORD bytesReturned = 0;
  187404. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  187405. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187406. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187407. &bytesReturned, 0) != 0)
  187408. {
  187409. zeromem (&list[count], sizeof (CDDeviceInfo));
  187410. list[count].scsiDriveLetter = driveLetter;
  187411. memcpy (list[count].vendor, &buffer[8], 8);
  187412. memcpy (list[count].productId, &buffer[16], 16);
  187413. memcpy (list[count].rev, &buffer[32], 4);
  187414. memcpy (list[count].vendorSpec, &buffer[36], 20);
  187415. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187416. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  187417. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  187418. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  187419. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  187420. &bytesReturned, 0) != 0)
  187421. {
  187422. list[count].ha = scsiAddr->PortNumber;
  187423. list[count].tgt = scsiAddr->TargetId;
  187424. list[count].lun = scsiAddr->Lun;
  187425. ++count;
  187426. }
  187427. }
  187428. CloseHandle (h);
  187429. }
  187430. }
  187431. }
  187432. }
  187433. else
  187434. {
  187435. const DWORD d = fGetASPI32SupportInfo();
  187436. BYTE status = HIBYTE (LOWORD (d));
  187437. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  187438. return 0;
  187439. const int numAdapters = LOBYTE (LOWORD (d));
  187440. for (BYTE ha = 0; ha < numAdapters; ++ha)
  187441. {
  187442. SRB_HAInquiry s;
  187443. zerostruct (s);
  187444. s.SRB_Cmd = SC_HA_INQUIRY;
  187445. s.SRB_HaID = ha;
  187446. fSendASPI32Command ((LPSRB)&s);
  187447. if (s.SRB_Status == SS_COMP)
  187448. {
  187449. maxItems = (int)s.HA_Unique[3];
  187450. if (maxItems == 0)
  187451. maxItems = 8;
  187452. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  187453. {
  187454. for (BYTE lun = 0; lun < 8; ++lun)
  187455. {
  187456. SRB_GDEVBlock sb;
  187457. zerostruct (sb);
  187458. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  187459. sb.SRB_HaID = ha;
  187460. sb.SRB_Target = tgt;
  187461. sb.SRB_Lun = lun;
  187462. fSendASPI32Command ((LPSRB) &sb);
  187463. if (sb.SRB_Status == SS_COMP
  187464. && sb.SRB_DeviceType == DTYPE_CROM)
  187465. {
  187466. zeromem (&list[count], sizeof (CDDeviceInfo));
  187467. list[count].ha = ha;
  187468. list[count].tgt = tgt;
  187469. list[count].lun = lun;
  187470. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  187471. ++count;
  187472. }
  187473. }
  187474. }
  187475. }
  187476. }
  187477. }
  187478. return count;
  187479. }
  187480. static int ripperUsers = 0;
  187481. static bool initialisedOk = false;
  187482. class DeinitialiseTimer : private Timer,
  187483. private DeletedAtShutdown
  187484. {
  187485. DeinitialiseTimer (const DeinitialiseTimer&);
  187486. const DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  187487. public:
  187488. DeinitialiseTimer()
  187489. {
  187490. startTimer (4000);
  187491. }
  187492. ~DeinitialiseTimer()
  187493. {
  187494. if (--ripperUsers == 0)
  187495. DeinitialiseCDRipper();
  187496. }
  187497. void timerCallback()
  187498. {
  187499. delete this;
  187500. }
  187501. juce_UseDebuggingNewOperator
  187502. };
  187503. static void incUserCount()
  187504. {
  187505. if (ripperUsers++ == 0)
  187506. initialisedOk = InitialiseCDRipper();
  187507. }
  187508. static void decUserCount()
  187509. {
  187510. new DeinitialiseTimer();
  187511. }
  187512. struct CDDeviceWrapper
  187513. {
  187514. CDDeviceHandle* cdH;
  187515. CDReadBuffer* overlapBuffer;
  187516. bool jitter;
  187517. };
  187518. static int getAddressOf (const TOCTRACK* const t)
  187519. {
  187520. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  187521. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  187522. }
  187523. static int getMSFAddressOf (const TOCTRACK* const t)
  187524. {
  187525. return 60 * t->addr[1] + t->addr[2];
  187526. }
  187527. static const int samplesPerFrame = 44100 / 75;
  187528. static const int bytesPerFrame = samplesPerFrame * 4;
  187529. const StringArray AudioCDReader::getAvailableCDNames()
  187530. {
  187531. StringArray results;
  187532. incUserCount();
  187533. if (initialisedOk)
  187534. {
  187535. CDDeviceInfo list[8];
  187536. const int num = FindCDDevices (list, 8);
  187537. decUserCount();
  187538. for (int i = 0; i < num; ++i)
  187539. {
  187540. String s;
  187541. if (list[i].scsiDriveLetter > 0)
  187542. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << T(": ");
  187543. s << String (list[i].vendor).trim()
  187544. << T(" ") << String (list[i].productId).trim()
  187545. << T(" ") << String (list[i].rev).trim();
  187546. results.add (s);
  187547. }
  187548. }
  187549. return results;
  187550. }
  187551. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  187552. {
  187553. SRB_GDEVBlock s;
  187554. zerostruct (s);
  187555. s.SRB_Cmd = SC_GET_DEV_TYPE;
  187556. s.SRB_HaID = device->ha;
  187557. s.SRB_Target = device->tgt;
  187558. s.SRB_Lun = device->lun;
  187559. if (usingScsi)
  187560. {
  187561. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  187562. if (h != INVALID_HANDLE_VALUE)
  187563. {
  187564. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  187565. cdh->scsiHandle = h;
  187566. return cdh;
  187567. }
  187568. }
  187569. else
  187570. {
  187571. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  187572. && s.SRB_DeviceType == DTYPE_CROM)
  187573. {
  187574. return new CDDeviceHandle (device);
  187575. }
  187576. }
  187577. return 0;
  187578. }
  187579. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  187580. {
  187581. incUserCount();
  187582. if (initialisedOk)
  187583. {
  187584. CDDeviceInfo list[8];
  187585. const int num = FindCDDevices (list, 8);
  187586. if (((unsigned int) deviceIndex) < (unsigned int) num)
  187587. {
  187588. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  187589. if (handle != 0)
  187590. {
  187591. CDDeviceWrapper* const d = new CDDeviceWrapper();
  187592. d->cdH = handle;
  187593. d->overlapBuffer = new CDReadBuffer(3);
  187594. return new AudioCDReader (d);
  187595. }
  187596. }
  187597. }
  187598. decUserCount();
  187599. return 0;
  187600. }
  187601. AudioCDReader::AudioCDReader (void* handle_)
  187602. : AudioFormatReader (0, T("CD Audio")),
  187603. handle (handle_),
  187604. indexingEnabled (false),
  187605. lastIndex (0),
  187606. firstFrameInBuffer (0),
  187607. samplesInBuffer (0)
  187608. {
  187609. jassert (handle_ != 0);
  187610. refreshTrackLengths();
  187611. sampleRate = 44100.0;
  187612. bitsPerSample = 16;
  187613. lengthInSamples = getPositionOfTrackStart (numTracks);
  187614. numChannels = 2;
  187615. usesFloatingPointData = false;
  187616. buffer.setSize (4 * bytesPerFrame, true);
  187617. }
  187618. AudioCDReader::~AudioCDReader()
  187619. {
  187620. CDDeviceWrapper* const device = (CDDeviceWrapper*)handle;
  187621. delete device->cdH;
  187622. delete device->overlapBuffer;
  187623. delete device;
  187624. decUserCount();
  187625. }
  187626. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  187627. int64 startSampleInFile, int numSamples)
  187628. {
  187629. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187630. bool ok = true;
  187631. while (numSamples > 0)
  187632. {
  187633. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  187634. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  187635. if (startSampleInFile >= bufferStartSample
  187636. && startSampleInFile < bufferEndSample)
  187637. {
  187638. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  187639. int* const l = destSamples[0] + startOffsetInDestBuffer;
  187640. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187641. const short* src = (const short*) buffer.getData();
  187642. src += 2 * (startSampleInFile - bufferStartSample);
  187643. for (int i = 0; i < toDo; ++i)
  187644. {
  187645. l[i] = src [i << 1] << 16;
  187646. if (r != 0)
  187647. r[i] = src [(i << 1) + 1] << 16;
  187648. }
  187649. startOffsetInDestBuffer += toDo;
  187650. startSampleInFile += toDo;
  187651. numSamples -= toDo;
  187652. }
  187653. else
  187654. {
  187655. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  187656. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  187657. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  187658. {
  187659. device->overlapBuffer->dataLength = 0;
  187660. device->overlapBuffer->startFrame = 0;
  187661. device->overlapBuffer->numFrames = 0;
  187662. device->jitter = false;
  187663. }
  187664. firstFrameInBuffer = frameNeeded;
  187665. lastIndex = 0;
  187666. CDReadBuffer readBuffer (framesInBuffer + 4);
  187667. readBuffer.wantsIndex = indexingEnabled;
  187668. int i;
  187669. for (i = 5; --i >= 0;)
  187670. {
  187671. readBuffer.startFrame = frameNeeded;
  187672. readBuffer.numFrames = framesInBuffer;
  187673. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187674. break;
  187675. else
  187676. device->overlapBuffer->dataLength = 0;
  187677. }
  187678. if (i >= 0)
  187679. {
  187680. memcpy ((char*) buffer.getData(),
  187681. readBuffer.buffer + readBuffer.dataStartOffset,
  187682. readBuffer.dataLength);
  187683. samplesInBuffer = readBuffer.dataLength >> 2;
  187684. lastIndex = readBuffer.index;
  187685. }
  187686. else
  187687. {
  187688. int* l = destSamples[0] + startOffsetInDestBuffer;
  187689. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187690. while (--numSamples >= 0)
  187691. {
  187692. *l++ = 0;
  187693. if (r != 0)
  187694. *r++ = 0;
  187695. }
  187696. // sometimes the read fails for just the very last couple of blocks, so
  187697. // we'll ignore and errors in the last half-second of the disk..
  187698. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187699. break;
  187700. }
  187701. }
  187702. }
  187703. return ok;
  187704. }
  187705. bool AudioCDReader::isCDStillPresent() const
  187706. {
  187707. TOC toc;
  187708. zerostruct (toc);
  187709. return ((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false);
  187710. }
  187711. int AudioCDReader::getNumTracks() const
  187712. {
  187713. return numTracks;
  187714. }
  187715. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187716. {
  187717. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187718. : 0;
  187719. }
  187720. void AudioCDReader::refreshTrackLengths()
  187721. {
  187722. zeromem (trackStarts, sizeof (trackStarts));
  187723. zeromem (audioTracks, sizeof (audioTracks));
  187724. TOC toc;
  187725. zerostruct (toc);
  187726. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187727. {
  187728. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187729. for (int i = 0; i <= numTracks; ++i)
  187730. {
  187731. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187732. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187733. }
  187734. }
  187735. else
  187736. {
  187737. numTracks = 0;
  187738. }
  187739. }
  187740. bool AudioCDReader::isTrackAudio (int trackNum) const
  187741. {
  187742. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187743. : false;
  187744. }
  187745. void AudioCDReader::enableIndexScanning (bool b)
  187746. {
  187747. indexingEnabled = b;
  187748. }
  187749. int AudioCDReader::getLastIndex() const
  187750. {
  187751. return lastIndex;
  187752. }
  187753. const int framesPerIndexRead = 4;
  187754. int AudioCDReader::getIndexAt (int samplePos)
  187755. {
  187756. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187757. const int frameNeeded = samplePos / samplesPerFrame;
  187758. device->overlapBuffer->dataLength = 0;
  187759. device->overlapBuffer->startFrame = 0;
  187760. device->overlapBuffer->numFrames = 0;
  187761. device->jitter = false;
  187762. firstFrameInBuffer = 0;
  187763. lastIndex = 0;
  187764. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187765. readBuffer.wantsIndex = true;
  187766. int i;
  187767. for (i = 5; --i >= 0;)
  187768. {
  187769. readBuffer.startFrame = frameNeeded;
  187770. readBuffer.numFrames = framesPerIndexRead;
  187771. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187772. break;
  187773. }
  187774. if (i >= 0)
  187775. return readBuffer.index;
  187776. return -1;
  187777. }
  187778. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187779. {
  187780. Array <int> indexes;
  187781. const int trackStart = getPositionOfTrackStart (trackNumber);
  187782. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187783. bool needToScan = true;
  187784. if (trackEnd - trackStart > 20 * 44100)
  187785. {
  187786. // check the end of the track for indexes before scanning the whole thing
  187787. needToScan = false;
  187788. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187789. bool seenAnIndex = false;
  187790. while (pos <= trackEnd - samplesPerFrame)
  187791. {
  187792. const int index = getIndexAt (pos);
  187793. if (index == 0)
  187794. {
  187795. // lead-out, so skip back a bit if we've not found any indexes yet..
  187796. if (seenAnIndex)
  187797. break;
  187798. pos -= 44100 * 5;
  187799. if (pos < trackStart)
  187800. break;
  187801. }
  187802. else
  187803. {
  187804. if (index > 0)
  187805. seenAnIndex = true;
  187806. if (index > 1)
  187807. {
  187808. needToScan = true;
  187809. break;
  187810. }
  187811. pos += samplesPerFrame * framesPerIndexRead;
  187812. }
  187813. }
  187814. }
  187815. if (needToScan)
  187816. {
  187817. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187818. int pos = trackStart;
  187819. int last = -1;
  187820. while (pos < trackEnd - samplesPerFrame * 10)
  187821. {
  187822. const int frameNeeded = pos / samplesPerFrame;
  187823. device->overlapBuffer->dataLength = 0;
  187824. device->overlapBuffer->startFrame = 0;
  187825. device->overlapBuffer->numFrames = 0;
  187826. device->jitter = false;
  187827. firstFrameInBuffer = 0;
  187828. CDReadBuffer readBuffer (4);
  187829. readBuffer.wantsIndex = true;
  187830. int i;
  187831. for (i = 5; --i >= 0;)
  187832. {
  187833. readBuffer.startFrame = frameNeeded;
  187834. readBuffer.numFrames = framesPerIndexRead;
  187835. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187836. break;
  187837. }
  187838. if (i < 0)
  187839. break;
  187840. if (readBuffer.index > last && readBuffer.index > 1)
  187841. {
  187842. last = readBuffer.index;
  187843. indexes.add (pos);
  187844. }
  187845. pos += samplesPerFrame * framesPerIndexRead;
  187846. }
  187847. indexes.removeValue (trackStart);
  187848. }
  187849. return indexes;
  187850. }
  187851. int AudioCDReader::getCDDBId()
  187852. {
  187853. refreshTrackLengths();
  187854. if (numTracks > 0)
  187855. {
  187856. TOC toc;
  187857. zerostruct (toc);
  187858. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187859. {
  187860. int n = 0;
  187861. for (int i = numTracks; --i >= 0;)
  187862. {
  187863. int j = getMSFAddressOf (&toc.tracks[i]);
  187864. while (j > 0)
  187865. {
  187866. n += (j % 10);
  187867. j /= 10;
  187868. }
  187869. }
  187870. if (n != 0)
  187871. {
  187872. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187873. - getMSFAddressOf (&toc.tracks[0]);
  187874. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187875. }
  187876. }
  187877. }
  187878. return 0;
  187879. }
  187880. void AudioCDReader::ejectDisk()
  187881. {
  187882. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187883. }
  187884. #endif
  187885. #if JUCE_USE_CDBURNER
  187886. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187887. {
  187888. CoInitialize (0);
  187889. IDiscMaster* dm;
  187890. IDiscRecorder* result = 0;
  187891. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187892. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187893. IID_IDiscMaster,
  187894. (void**) &dm)))
  187895. {
  187896. if (SUCCEEDED (dm->Open()))
  187897. {
  187898. IEnumDiscRecorders* drEnum = 0;
  187899. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187900. {
  187901. IDiscRecorder* dr = 0;
  187902. DWORD dummy;
  187903. int index = 0;
  187904. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187905. {
  187906. if (indexToOpen == index)
  187907. {
  187908. result = dr;
  187909. break;
  187910. }
  187911. else if (list != 0)
  187912. {
  187913. BSTR path;
  187914. if (SUCCEEDED (dr->GetPath (&path)))
  187915. list->add ((const WCHAR*) path);
  187916. }
  187917. ++index;
  187918. dr->Release();
  187919. }
  187920. drEnum->Release();
  187921. }
  187922. if (master == 0)
  187923. dm->Close();
  187924. }
  187925. if (master != 0)
  187926. *master = dm;
  187927. else
  187928. dm->Release();
  187929. }
  187930. return result;
  187931. }
  187932. const StringArray AudioCDBurner::findAvailableDevices()
  187933. {
  187934. StringArray devs;
  187935. enumCDBurners (&devs, -1, 0);
  187936. return devs;
  187937. }
  187938. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187939. {
  187940. AudioCDBurner* b = new AudioCDBurner (deviceIndex);
  187941. if (b->internal == 0)
  187942. deleteAndZero (b);
  187943. return b;
  187944. }
  187945. class CDBurnerInfo : public IDiscMasterProgressEvents
  187946. {
  187947. public:
  187948. CDBurnerInfo()
  187949. : refCount (1),
  187950. progress (0),
  187951. shouldCancel (false),
  187952. listener (0)
  187953. {
  187954. }
  187955. ~CDBurnerInfo()
  187956. {
  187957. }
  187958. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187959. {
  187960. if (result == 0)
  187961. return E_POINTER;
  187962. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187963. {
  187964. AddRef();
  187965. *result = this;
  187966. return S_OK;
  187967. }
  187968. *result = 0;
  187969. return E_NOINTERFACE;
  187970. }
  187971. ULONG __stdcall AddRef() { return ++refCount; }
  187972. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187973. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187974. {
  187975. if (listener != 0 && ! shouldCancel)
  187976. shouldCancel = listener->audioCDBurnProgress (progress);
  187977. *pbCancel = shouldCancel;
  187978. return S_OK;
  187979. }
  187980. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187981. {
  187982. progress = nCompleted / (float) nTotal;
  187983. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187984. return E_NOTIMPL;
  187985. }
  187986. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187987. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187988. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187989. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187990. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187991. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187992. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187993. IDiscMaster* discMaster;
  187994. IDiscRecorder* discRecorder;
  187995. IRedbookDiscMaster* redbook;
  187996. AudioCDBurner::BurnProgressListener* listener;
  187997. float progress;
  187998. bool shouldCancel;
  187999. private:
  188000. int refCount;
  188001. };
  188002. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  188003. : internal (0)
  188004. {
  188005. IDiscMaster* discMaster;
  188006. IDiscRecorder* dr = enumCDBurners (0, deviceIndex, &discMaster);
  188007. if (dr != 0)
  188008. {
  188009. IRedbookDiscMaster* redbook;
  188010. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  188011. hr = discMaster->SetActiveDiscRecorder (dr);
  188012. CDBurnerInfo* const info = new CDBurnerInfo();
  188013. internal = info;
  188014. info->discMaster = discMaster;
  188015. info->discRecorder = dr;
  188016. info->redbook = redbook;
  188017. }
  188018. }
  188019. AudioCDBurner::~AudioCDBurner()
  188020. {
  188021. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188022. if (info != 0)
  188023. {
  188024. info->discRecorder->Close();
  188025. info->redbook->Release();
  188026. info->discRecorder->Release();
  188027. info->discMaster->Release();
  188028. info->Release();
  188029. }
  188030. }
  188031. bool AudioCDBurner::isDiskPresent() const
  188032. {
  188033. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188034. HRESULT hr = info->discRecorder->OpenExclusive();
  188035. long type, flags;
  188036. hr = info->discRecorder->QueryMediaType (&type, &flags);
  188037. info->discRecorder->Close();
  188038. return hr == S_OK && type != 0 && (flags & MEDIA_WRITABLE) != 0;
  188039. }
  188040. int AudioCDBurner::getNumAvailableAudioBlocks() const
  188041. {
  188042. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188043. long blocksFree = 0;
  188044. info->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  188045. return blocksFree;
  188046. }
  188047. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener,
  188048. const bool ejectDiscAfterwards,
  188049. const bool performFakeBurnForTesting)
  188050. {
  188051. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188052. info->listener = listener;
  188053. info->progress = 0;
  188054. info->shouldCancel = false;
  188055. UINT_PTR cookie;
  188056. HRESULT hr = info->discMaster->ProgressAdvise (info, &cookie);
  188057. hr = info->discMaster->RecordDisc (performFakeBurnForTesting,
  188058. ejectDiscAfterwards);
  188059. String error;
  188060. if (hr != S_OK)
  188061. {
  188062. const char* e = "Couldn't open or write to the CD device";
  188063. if (hr == IMAPI_E_USERABORT)
  188064. e = "User cancelled the write operation";
  188065. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  188066. e = "No Disk present";
  188067. error = e;
  188068. }
  188069. info->discMaster->ProgressUnadvise (cookie);
  188070. info->listener = 0;
  188071. return error;
  188072. }
  188073. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamples)
  188074. {
  188075. if (source == 0)
  188076. return false;
  188077. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188078. long bytesPerBlock;
  188079. HRESULT hr = info->redbook->GetAudioBlockSize (&bytesPerBlock);
  188080. const int samplesPerBlock = bytesPerBlock / 4;
  188081. bool ok = true;
  188082. hr = info->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  188083. HeapBlock <byte> buffer (bytesPerBlock);
  188084. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  188085. int samplesDone = 0;
  188086. source->prepareToPlay (samplesPerBlock, 44100.0);
  188087. while (ok)
  188088. {
  188089. {
  188090. AudioSourceChannelInfo info;
  188091. info.buffer = &sourceBuffer;
  188092. info.numSamples = samplesPerBlock;
  188093. info.startSample = 0;
  188094. sourceBuffer.clear();
  188095. source->getNextAudioBlock (info);
  188096. }
  188097. zeromem (buffer, bytesPerBlock);
  188098. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  188099. buffer, samplesPerBlock, 4);
  188100. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  188101. buffer + 2, samplesPerBlock, 4);
  188102. hr = info->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  188103. if (hr != S_OK)
  188104. ok = false;
  188105. samplesDone += samplesPerBlock;
  188106. if (samplesDone >= numSamples)
  188107. break;
  188108. }
  188109. hr = info->redbook->CloseAudioTrack();
  188110. delete source;
  188111. return ok && hr == S_OK;
  188112. }
  188113. #endif
  188114. #endif
  188115. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  188116. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  188117. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188118. // compiled on its own).
  188119. #if JUCE_INCLUDED_FILE
  188120. static const int midiBufferSize = 1024 * 10;
  188121. static const int numInHeaders = 32;
  188122. static const int inBufferSize = 256;
  188123. static Array <void*, CriticalSection> activeMidiThreads;
  188124. using ::free;
  188125. class MidiInThread : public Thread
  188126. {
  188127. public:
  188128. MidiInThread (MidiInput* const input_,
  188129. MidiInputCallback* const callback_)
  188130. : Thread ("Juce Midi"),
  188131. hIn (0),
  188132. input (input_),
  188133. callback (callback_),
  188134. isStarted (false),
  188135. startTime (0),
  188136. pendingLength(0)
  188137. {
  188138. for (int i = numInHeaders; --i >= 0;)
  188139. {
  188140. zeromem (&hdr[i], sizeof (MIDIHDR));
  188141. hdr[i].lpData = inData[i];
  188142. hdr[i].dwBufferLength = inBufferSize;
  188143. }
  188144. };
  188145. ~MidiInThread()
  188146. {
  188147. stop();
  188148. if (hIn != 0)
  188149. {
  188150. int count = 5;
  188151. while (--count >= 0)
  188152. {
  188153. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  188154. break;
  188155. Sleep (20);
  188156. }
  188157. }
  188158. }
  188159. void handle (const uint32 message, const uint32 timeStamp) throw()
  188160. {
  188161. const int byte = message & 0xff;
  188162. if (byte < 0x80)
  188163. return;
  188164. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  188165. const double time = timeStampToTime (timeStamp);
  188166. lock.enter();
  188167. if (pendingLength < midiBufferSize - 12)
  188168. {
  188169. char* const p = pending + pendingLength;
  188170. *(double*) p = time;
  188171. *(uint32*) (p + 8) = numBytes;
  188172. *(uint32*) (p + 12) = message;
  188173. pendingLength += 12 + numBytes;
  188174. }
  188175. else
  188176. {
  188177. jassertfalse // midi buffer overflow! You might need to increase the size..
  188178. }
  188179. lock.exit();
  188180. notify();
  188181. }
  188182. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  188183. {
  188184. const int num = hdr->dwBytesRecorded;
  188185. if (num > 0)
  188186. {
  188187. const double time = timeStampToTime (timeStamp);
  188188. lock.enter();
  188189. if (pendingLength < midiBufferSize - (8 + num))
  188190. {
  188191. char* const p = pending + pendingLength;
  188192. *(double*) p = time;
  188193. *(uint32*) (p + 8) = num;
  188194. memcpy (p + 12, hdr->lpData, num);
  188195. pendingLength += 12 + num;
  188196. }
  188197. else
  188198. {
  188199. jassertfalse // midi buffer overflow! You might need to increase the size..
  188200. }
  188201. lock.exit();
  188202. notify();
  188203. }
  188204. }
  188205. void writeBlock (const int i) throw()
  188206. {
  188207. hdr[i].dwBytesRecorded = 0;
  188208. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188209. jassert (res == MMSYSERR_NOERROR);
  188210. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  188211. jassert (res == MMSYSERR_NOERROR);
  188212. }
  188213. void run()
  188214. {
  188215. MemoryBlock pendingCopy (64);
  188216. while (! threadShouldExit())
  188217. {
  188218. for (int i = 0; i < numInHeaders; ++i)
  188219. {
  188220. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188221. {
  188222. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188223. (void) res;
  188224. jassert (res == MMSYSERR_NOERROR);
  188225. writeBlock (i);
  188226. }
  188227. }
  188228. lock.enter();
  188229. int len = pendingLength;
  188230. if (len > 0)
  188231. {
  188232. pendingCopy.ensureSize (len);
  188233. pendingCopy.copyFrom (pending, 0, len);
  188234. pendingLength = 0;
  188235. }
  188236. lock.exit();
  188237. //xxx needs to figure out if blocks are broken up or not
  188238. if (len == 0)
  188239. {
  188240. wait (500);
  188241. }
  188242. else
  188243. {
  188244. const char* p = (const char*) pendingCopy.getData();
  188245. while (len > 0)
  188246. {
  188247. const double time = *(const double*) p;
  188248. const int messageLen = *(const int*) (p + 8);
  188249. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  188250. callback->handleIncomingMidiMessage (input, message);
  188251. p += 12 + messageLen;
  188252. len -= 12 + messageLen;
  188253. }
  188254. }
  188255. }
  188256. }
  188257. void start() throw()
  188258. {
  188259. jassert (hIn != 0);
  188260. if (hIn != 0 && ! isStarted)
  188261. {
  188262. stop();
  188263. activeMidiThreads.addIfNotAlreadyThere (this);
  188264. int i;
  188265. for (i = 0; i < numInHeaders; ++i)
  188266. writeBlock (i);
  188267. startTime = Time::getMillisecondCounter();
  188268. MMRESULT res = midiInStart (hIn);
  188269. jassert (res == MMSYSERR_NOERROR);
  188270. if (res == MMSYSERR_NOERROR)
  188271. {
  188272. isStarted = true;
  188273. pendingLength = 0;
  188274. startThread (6);
  188275. }
  188276. }
  188277. }
  188278. void stop() throw()
  188279. {
  188280. if (isStarted)
  188281. {
  188282. stopThread (5000);
  188283. midiInReset (hIn);
  188284. midiInStop (hIn);
  188285. activeMidiThreads.removeValue (this);
  188286. lock.enter();
  188287. lock.exit();
  188288. for (int i = numInHeaders; --i >= 0;)
  188289. {
  188290. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188291. {
  188292. int c = 10;
  188293. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  188294. Sleep (20);
  188295. jassert (c >= 0);
  188296. }
  188297. }
  188298. isStarted = false;
  188299. pendingLength = 0;
  188300. }
  188301. }
  188302. juce_UseDebuggingNewOperator
  188303. HMIDIIN hIn;
  188304. private:
  188305. MidiInput* input;
  188306. MidiInputCallback* callback;
  188307. bool isStarted;
  188308. uint32 startTime;
  188309. CriticalSection lock;
  188310. MIDIHDR hdr [numInHeaders];
  188311. char inData [numInHeaders] [inBufferSize];
  188312. int pendingLength;
  188313. char pending [midiBufferSize];
  188314. double timeStampToTime (uint32 timeStamp) throw()
  188315. {
  188316. timeStamp += startTime;
  188317. const uint32 now = Time::getMillisecondCounter();
  188318. if (timeStamp > now)
  188319. {
  188320. if (timeStamp > now + 2)
  188321. --startTime;
  188322. timeStamp = now;
  188323. }
  188324. return 0.001 * timeStamp;
  188325. }
  188326. MidiInThread (const MidiInThread&);
  188327. const MidiInThread& operator= (const MidiInThread&);
  188328. };
  188329. static void CALLBACK midiInCallback (HMIDIIN,
  188330. UINT uMsg,
  188331. DWORD_PTR dwInstance,
  188332. DWORD_PTR midiMessage,
  188333. DWORD_PTR timeStamp)
  188334. {
  188335. MidiInThread* const thread = (MidiInThread*) dwInstance;
  188336. if (thread != 0 && activeMidiThreads.contains (thread))
  188337. {
  188338. if (uMsg == MIM_DATA)
  188339. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  188340. else if (uMsg == MIM_LONGDATA)
  188341. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  188342. }
  188343. }
  188344. const StringArray MidiInput::getDevices()
  188345. {
  188346. StringArray s;
  188347. const int num = midiInGetNumDevs();
  188348. for (int i = 0; i < num; ++i)
  188349. {
  188350. MIDIINCAPS mc;
  188351. zerostruct (mc);
  188352. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188353. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188354. }
  188355. return s;
  188356. }
  188357. int MidiInput::getDefaultDeviceIndex()
  188358. {
  188359. return 0;
  188360. }
  188361. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  188362. {
  188363. if (callback == 0)
  188364. return 0;
  188365. UINT deviceId = MIDI_MAPPER;
  188366. int n = 0;
  188367. String name;
  188368. const int num = midiInGetNumDevs();
  188369. for (int i = 0; i < num; ++i)
  188370. {
  188371. MIDIINCAPS mc;
  188372. zerostruct (mc);
  188373. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188374. {
  188375. if (index == n)
  188376. {
  188377. deviceId = i;
  188378. name = String (mc.szPname, sizeof (mc.szPname));
  188379. break;
  188380. }
  188381. ++n;
  188382. }
  188383. }
  188384. ScopedPointer <MidiInput> in (new MidiInput (name));
  188385. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  188386. HMIDIIN h;
  188387. HRESULT err = midiInOpen (&h, deviceId,
  188388. (DWORD_PTR) &midiInCallback,
  188389. (DWORD_PTR) (MidiInThread*) thread,
  188390. CALLBACK_FUNCTION);
  188391. if (err == MMSYSERR_NOERROR)
  188392. {
  188393. thread->hIn = h;
  188394. in->internal = (void*) thread.release();
  188395. return in.release();
  188396. }
  188397. return 0;
  188398. }
  188399. MidiInput::MidiInput (const String& name_)
  188400. : name (name_),
  188401. internal (0)
  188402. {
  188403. }
  188404. MidiInput::~MidiInput()
  188405. {
  188406. if (internal != 0)
  188407. {
  188408. MidiInThread* const thread = (MidiInThread*) internal;
  188409. delete thread;
  188410. }
  188411. }
  188412. void MidiInput::start()
  188413. {
  188414. ((MidiInThread*) internal)->start();
  188415. }
  188416. void MidiInput::stop()
  188417. {
  188418. ((MidiInThread*) internal)->stop();
  188419. }
  188420. struct MidiOutHandle
  188421. {
  188422. int refCount;
  188423. UINT deviceId;
  188424. HMIDIOUT handle;
  188425. juce_UseDebuggingNewOperator
  188426. };
  188427. static Array <MidiOutHandle*> midiOutputHandles;
  188428. const StringArray MidiOutput::getDevices()
  188429. {
  188430. StringArray s;
  188431. const int num = midiOutGetNumDevs();
  188432. for (int i = 0; i < num; ++i)
  188433. {
  188434. MIDIOUTCAPS mc;
  188435. zerostruct (mc);
  188436. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188437. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188438. }
  188439. return s;
  188440. }
  188441. int MidiOutput::getDefaultDeviceIndex()
  188442. {
  188443. const int num = midiOutGetNumDevs();
  188444. int n = 0;
  188445. for (int i = 0; i < num; ++i)
  188446. {
  188447. MIDIOUTCAPS mc;
  188448. zerostruct (mc);
  188449. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188450. {
  188451. if ((mc.wTechnology & MOD_MAPPER) != 0)
  188452. return n;
  188453. ++n;
  188454. }
  188455. }
  188456. return 0;
  188457. }
  188458. MidiOutput* MidiOutput::openDevice (int index)
  188459. {
  188460. UINT deviceId = MIDI_MAPPER;
  188461. const int num = midiOutGetNumDevs();
  188462. int i, n = 0;
  188463. for (i = 0; i < num; ++i)
  188464. {
  188465. MIDIOUTCAPS mc;
  188466. zerostruct (mc);
  188467. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188468. {
  188469. // use the microsoft sw synth as a default - best not to allow deviceId
  188470. // to be MIDI_MAPPER, or else device sharing breaks
  188471. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase (T("microsoft")))
  188472. deviceId = i;
  188473. if (index == n)
  188474. {
  188475. deviceId = i;
  188476. break;
  188477. }
  188478. ++n;
  188479. }
  188480. }
  188481. for (i = midiOutputHandles.size(); --i >= 0;)
  188482. {
  188483. MidiOutHandle* const han = midiOutputHandles.getUnchecked(i);
  188484. if (han != 0 && han->deviceId == deviceId)
  188485. {
  188486. han->refCount++;
  188487. MidiOutput* const out = new MidiOutput();
  188488. out->internal = (void*) han;
  188489. return out;
  188490. }
  188491. }
  188492. for (i = 4; --i >= 0;)
  188493. {
  188494. HMIDIOUT h = 0;
  188495. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  188496. if (res == MMSYSERR_NOERROR)
  188497. {
  188498. MidiOutHandle* const han = new MidiOutHandle();
  188499. han->deviceId = deviceId;
  188500. han->refCount = 1;
  188501. han->handle = h;
  188502. midiOutputHandles.add (han);
  188503. MidiOutput* const out = new MidiOutput();
  188504. out->internal = (void*) han;
  188505. return out;
  188506. }
  188507. else if (res == MMSYSERR_ALLOCATED)
  188508. {
  188509. Sleep (100);
  188510. }
  188511. else
  188512. {
  188513. break;
  188514. }
  188515. }
  188516. return 0;
  188517. }
  188518. MidiOutput::~MidiOutput()
  188519. {
  188520. MidiOutHandle* const h = (MidiOutHandle*) internal;
  188521. if (midiOutputHandles.contains (h) && --(h->refCount) == 0)
  188522. {
  188523. midiOutClose (h->handle);
  188524. midiOutputHandles.removeValue (h);
  188525. delete h;
  188526. }
  188527. }
  188528. void MidiOutput::reset()
  188529. {
  188530. const MidiOutHandle* const h = (MidiOutHandle*) internal;
  188531. midiOutReset (h->handle);
  188532. }
  188533. bool MidiOutput::getVolume (float& leftVol,
  188534. float& rightVol)
  188535. {
  188536. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188537. DWORD n;
  188538. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  188539. {
  188540. const unsigned short* const nn = (const unsigned short*) &n;
  188541. rightVol = nn[0] / (float) 0xffff;
  188542. leftVol = nn[1] / (float) 0xffff;
  188543. return true;
  188544. }
  188545. else
  188546. {
  188547. rightVol = leftVol = 1.0f;
  188548. return false;
  188549. }
  188550. }
  188551. void MidiOutput::setVolume (float leftVol,
  188552. float rightVol)
  188553. {
  188554. const MidiOutHandle* const handle = (MidiOutHandle*) internal;
  188555. DWORD n;
  188556. unsigned short* const nn = (unsigned short*) &n;
  188557. nn[0] = (unsigned short) jlimit (0, 0xffff, (int)(rightVol * 0xffff));
  188558. nn[1] = (unsigned short) jlimit (0, 0xffff, (int)(leftVol * 0xffff));
  188559. midiOutSetVolume (handle->handle, n);
  188560. }
  188561. void MidiOutput::sendMessageNow (const MidiMessage& message)
  188562. {
  188563. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188564. if (message.getRawDataSize() > 3
  188565. || message.isSysEx())
  188566. {
  188567. MIDIHDR h;
  188568. zerostruct (h);
  188569. h.lpData = (char*) message.getRawData();
  188570. h.dwBufferLength = message.getRawDataSize();
  188571. h.dwBytesRecorded = message.getRawDataSize();
  188572. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  188573. {
  188574. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  188575. if (res == MMSYSERR_NOERROR)
  188576. {
  188577. while ((h.dwFlags & MHDR_DONE) == 0)
  188578. Sleep (1);
  188579. int count = 500; // 1 sec timeout
  188580. while (--count >= 0)
  188581. {
  188582. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188583. if (res == MIDIERR_STILLPLAYING)
  188584. Sleep (2);
  188585. else
  188586. break;
  188587. }
  188588. }
  188589. }
  188590. }
  188591. else
  188592. {
  188593. midiOutShortMsg (handle->handle,
  188594. *(unsigned int*) message.getRawData());
  188595. }
  188596. }
  188597. #endif
  188598. /*** End of inlined file: juce_win32_Midi.cpp ***/
  188599. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  188600. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188601. // compiled on its own).
  188602. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188603. #undef WINDOWS
  188604. // #define ASIO_DEBUGGING
  188605. #ifdef ASIO_DEBUGGING
  188606. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188607. #else
  188608. #define log(a) {}
  188609. #endif
  188610. #ifdef ASIO_DEBUGGING
  188611. static void logError (const String& context, long error)
  188612. {
  188613. String err ("unknown error");
  188614. if (error == ASE_NotPresent)
  188615. err = "Not Present";
  188616. else if (error == ASE_HWMalfunction)
  188617. err = "Hardware Malfunction";
  188618. else if (error == ASE_InvalidParameter)
  188619. err = "Invalid Parameter";
  188620. else if (error == ASE_InvalidMode)
  188621. err = "Invalid Mode";
  188622. else if (error == ASE_SPNotAdvancing)
  188623. err = "Sample position not advancing";
  188624. else if (error == ASE_NoClock)
  188625. err = "No Clock";
  188626. else if (error == ASE_NoMemory)
  188627. err = "Out of memory";
  188628. log (T("!!error: ") + context + T(" - ") + err);
  188629. }
  188630. #else
  188631. #define logError(a, b) {}
  188632. #endif
  188633. class ASIOAudioIODevice;
  188634. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188635. static const int maxASIOChannels = 160;
  188636. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188637. private Timer
  188638. {
  188639. public:
  188640. Component ourWindow;
  188641. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188642. const String& optionalDllForDirectLoading_)
  188643. : AudioIODevice (name_, T("ASIO")),
  188644. asioObject (0),
  188645. classId (classId_),
  188646. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188647. currentBitDepth (16),
  188648. currentSampleRate (0),
  188649. isOpen_ (false),
  188650. isStarted (false),
  188651. postOutput (true),
  188652. insideControlPanelModalLoop (false),
  188653. shouldUsePreferredSize (false)
  188654. {
  188655. name = name_;
  188656. ourWindow.addToDesktop (0);
  188657. windowHandle = ourWindow.getWindowHandle();
  188658. jassert (currentASIODev [slotNumber] == 0);
  188659. currentASIODev [slotNumber] = this;
  188660. openDevice();
  188661. }
  188662. ~ASIOAudioIODevice()
  188663. {
  188664. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188665. if (currentASIODev[i] == this)
  188666. currentASIODev[i] = 0;
  188667. close();
  188668. log ("ASIO - exiting");
  188669. removeCurrentDriver();
  188670. }
  188671. void updateSampleRates()
  188672. {
  188673. // find a list of sample rates..
  188674. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188675. sampleRates.clear();
  188676. if (asioObject != 0)
  188677. {
  188678. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188679. {
  188680. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188681. if (err == 0)
  188682. {
  188683. sampleRates.add ((int) possibleSampleRates[index]);
  188684. log (T("rate: ") + String ((int) possibleSampleRates[index]));
  188685. }
  188686. else if (err != ASE_NoClock)
  188687. {
  188688. logError (T("CanSampleRate"), err);
  188689. }
  188690. }
  188691. if (sampleRates.size() == 0)
  188692. {
  188693. double cr = 0;
  188694. const long err = asioObject->getSampleRate (&cr);
  188695. log (T("No sample rates supported - current rate: ") + String ((int) cr));
  188696. if (err == 0)
  188697. sampleRates.add ((int) cr);
  188698. }
  188699. }
  188700. }
  188701. const StringArray getOutputChannelNames()
  188702. {
  188703. return outputChannelNames;
  188704. }
  188705. const StringArray getInputChannelNames()
  188706. {
  188707. return inputChannelNames;
  188708. }
  188709. int getNumSampleRates()
  188710. {
  188711. return sampleRates.size();
  188712. }
  188713. double getSampleRate (int index)
  188714. {
  188715. return sampleRates [index];
  188716. }
  188717. int getNumBufferSizesAvailable()
  188718. {
  188719. return bufferSizes.size();
  188720. }
  188721. int getBufferSizeSamples (int index)
  188722. {
  188723. return bufferSizes [index];
  188724. }
  188725. int getDefaultBufferSize()
  188726. {
  188727. return preferredSize;
  188728. }
  188729. const String open (const BitArray& inputChannels,
  188730. const BitArray& outputChannels,
  188731. double sr,
  188732. int bufferSizeSamples)
  188733. {
  188734. close();
  188735. currentCallback = 0;
  188736. if (bufferSizeSamples <= 0)
  188737. shouldUsePreferredSize = true;
  188738. if (asioObject == 0 || ! isASIOOpen)
  188739. {
  188740. log ("Warning: device not open");
  188741. const String err (openDevice());
  188742. if (asioObject == 0 || ! isASIOOpen)
  188743. return err;
  188744. }
  188745. isStarted = false;
  188746. bufferIndex = -1;
  188747. long err = 0;
  188748. long newPreferredSize = 0;
  188749. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188750. minSize = 0;
  188751. maxSize = 0;
  188752. newPreferredSize = 0;
  188753. granularity = 0;
  188754. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188755. {
  188756. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188757. shouldUsePreferredSize = true;
  188758. preferredSize = newPreferredSize;
  188759. }
  188760. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188761. // dynamic changes to the buffer size...
  188762. shouldUsePreferredSize = shouldUsePreferredSize
  188763. || getName().containsIgnoreCase (T("Digidesign"));
  188764. if (shouldUsePreferredSize)
  188765. {
  188766. log ("Using preferred size for buffer..");
  188767. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188768. {
  188769. bufferSizeSamples = preferredSize;
  188770. }
  188771. else
  188772. {
  188773. bufferSizeSamples = 1024;
  188774. logError ("GetBufferSize1", err);
  188775. }
  188776. shouldUsePreferredSize = false;
  188777. }
  188778. int sampleRate = roundDoubleToInt (sr);
  188779. currentSampleRate = sampleRate;
  188780. currentBlockSizeSamples = bufferSizeSamples;
  188781. currentChansOut.clear();
  188782. currentChansIn.clear();
  188783. zeromem (inBuffers, sizeof (inBuffers));
  188784. zeromem (outBuffers, sizeof (outBuffers));
  188785. updateSampleRates();
  188786. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188787. sampleRate = sampleRates[0];
  188788. jassert (sampleRate != 0);
  188789. if (sampleRate == 0)
  188790. sampleRate = 44100;
  188791. long numSources = 32;
  188792. ASIOClockSource clocks[32];
  188793. zeromem (clocks, sizeof (clocks));
  188794. asioObject->getClockSources (clocks, &numSources);
  188795. bool isSourceSet = false;
  188796. // careful not to remove this loop because it does more than just logging!
  188797. int i;
  188798. for (i = 0; i < numSources; ++i)
  188799. {
  188800. String s ("clock: ");
  188801. s += clocks[i].name;
  188802. if (clocks[i].isCurrentSource)
  188803. {
  188804. isSourceSet = true;
  188805. s << " (cur)";
  188806. }
  188807. log (s);
  188808. }
  188809. if (numSources > 1 && ! isSourceSet)
  188810. {
  188811. log ("setting clock source");
  188812. asioObject->setClockSource (clocks[0].index);
  188813. Thread::sleep (20);
  188814. }
  188815. else
  188816. {
  188817. if (numSources == 0)
  188818. {
  188819. log ("ASIO - no clock sources!");
  188820. }
  188821. }
  188822. double cr = 0;
  188823. err = asioObject->getSampleRate (&cr);
  188824. if (err == 0)
  188825. {
  188826. currentSampleRate = cr;
  188827. }
  188828. else
  188829. {
  188830. logError ("GetSampleRate", err);
  188831. currentSampleRate = 0;
  188832. }
  188833. error = String::empty;
  188834. needToReset = false;
  188835. isReSync = false;
  188836. err = 0;
  188837. bool buffersCreated = false;
  188838. if (currentSampleRate != sampleRate)
  188839. {
  188840. log (T("ASIO samplerate: ") + String (currentSampleRate) + T(" to ") + String (sampleRate));
  188841. err = asioObject->setSampleRate (sampleRate);
  188842. if (err == ASE_NoClock && numSources > 0)
  188843. {
  188844. log ("trying to set a clock source..");
  188845. Thread::sleep (10);
  188846. err = asioObject->setClockSource (clocks[0].index);
  188847. if (err != 0)
  188848. {
  188849. logError ("SetClock", err);
  188850. }
  188851. Thread::sleep (10);
  188852. err = asioObject->setSampleRate (sampleRate);
  188853. }
  188854. }
  188855. if (err == 0)
  188856. {
  188857. currentSampleRate = sampleRate;
  188858. if (needToReset)
  188859. {
  188860. if (isReSync)
  188861. {
  188862. log ("Resync request");
  188863. }
  188864. log ("! Resetting ASIO after sample rate change");
  188865. removeCurrentDriver();
  188866. loadDriver();
  188867. const String error (initDriver());
  188868. if (error.isNotEmpty())
  188869. {
  188870. log (T("ASIOInit: ") + error);
  188871. }
  188872. needToReset = false;
  188873. isReSync = false;
  188874. }
  188875. numActiveInputChans = 0;
  188876. numActiveOutputChans = 0;
  188877. ASIOBufferInfo* info = bufferInfos;
  188878. int i;
  188879. for (i = 0; i < totalNumInputChans; ++i)
  188880. {
  188881. if (inputChannels[i])
  188882. {
  188883. currentChansIn.setBit (i);
  188884. info->isInput = 1;
  188885. info->channelNum = i;
  188886. info->buffers[0] = info->buffers[1] = 0;
  188887. ++info;
  188888. ++numActiveInputChans;
  188889. }
  188890. }
  188891. for (i = 0; i < totalNumOutputChans; ++i)
  188892. {
  188893. if (outputChannels[i])
  188894. {
  188895. currentChansOut.setBit (i);
  188896. info->isInput = 0;
  188897. info->channelNum = i;
  188898. info->buffers[0] = info->buffers[1] = 0;
  188899. ++info;
  188900. ++numActiveOutputChans;
  188901. }
  188902. }
  188903. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188904. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188905. if (currentASIODev[0] == this)
  188906. {
  188907. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188908. callbacks.asioMessage = &asioMessagesCallback0;
  188909. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188910. }
  188911. else if (currentASIODev[1] == this)
  188912. {
  188913. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188914. callbacks.asioMessage = &asioMessagesCallback1;
  188915. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188916. }
  188917. else if (currentASIODev[2] == this)
  188918. {
  188919. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188920. callbacks.asioMessage = &asioMessagesCallback2;
  188921. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188922. }
  188923. else
  188924. {
  188925. jassertfalse
  188926. }
  188927. log ("disposing buffers");
  188928. err = asioObject->disposeBuffers();
  188929. log (T("creating buffers: ") + String (totalBuffers) + T(", ") + String (currentBlockSizeSamples));
  188930. err = asioObject->createBuffers (bufferInfos,
  188931. totalBuffers,
  188932. currentBlockSizeSamples,
  188933. &callbacks);
  188934. if (err != 0)
  188935. {
  188936. currentBlockSizeSamples = preferredSize;
  188937. logError ("create buffers 2", err);
  188938. asioObject->disposeBuffers();
  188939. err = asioObject->createBuffers (bufferInfos,
  188940. totalBuffers,
  188941. currentBlockSizeSamples,
  188942. &callbacks);
  188943. }
  188944. if (err == 0)
  188945. {
  188946. buffersCreated = true;
  188947. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188948. int n = 0;
  188949. Array <int> types;
  188950. currentBitDepth = 16;
  188951. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188952. {
  188953. if (inputChannels[i])
  188954. {
  188955. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188956. ASIOChannelInfo channelInfo;
  188957. zerostruct (channelInfo);
  188958. channelInfo.channel = i;
  188959. channelInfo.isInput = 1;
  188960. asioObject->getChannelInfo (&channelInfo);
  188961. types.addIfNotAlreadyThere (channelInfo.type);
  188962. typeToFormatParameters (channelInfo.type,
  188963. inputChannelBitDepths[n],
  188964. inputChannelBytesPerSample[n],
  188965. inputChannelIsFloat[n],
  188966. inputChannelLittleEndian[n]);
  188967. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188968. ++n;
  188969. }
  188970. }
  188971. jassert (numActiveInputChans == n);
  188972. n = 0;
  188973. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188974. {
  188975. if (outputChannels[i])
  188976. {
  188977. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188978. ASIOChannelInfo channelInfo;
  188979. zerostruct (channelInfo);
  188980. channelInfo.channel = i;
  188981. channelInfo.isInput = 0;
  188982. asioObject->getChannelInfo (&channelInfo);
  188983. types.addIfNotAlreadyThere (channelInfo.type);
  188984. typeToFormatParameters (channelInfo.type,
  188985. outputChannelBitDepths[n],
  188986. outputChannelBytesPerSample[n],
  188987. outputChannelIsFloat[n],
  188988. outputChannelLittleEndian[n]);
  188989. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188990. ++n;
  188991. }
  188992. }
  188993. jassert (numActiveOutputChans == n);
  188994. for (i = types.size(); --i >= 0;)
  188995. {
  188996. log (T("channel format: ") + String (types[i]));
  188997. }
  188998. jassert (n <= totalBuffers);
  188999. for (i = 0; i < numActiveOutputChans; ++i)
  189000. {
  189001. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  189002. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  189003. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  189004. {
  189005. log ("!! Null buffers");
  189006. }
  189007. else
  189008. {
  189009. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  189010. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  189011. }
  189012. }
  189013. inputLatency = outputLatency = 0;
  189014. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  189015. {
  189016. log ("ASIO - no latencies");
  189017. }
  189018. else
  189019. {
  189020. log (T("ASIO latencies: ")
  189021. + String ((int) outputLatency)
  189022. + T(", ")
  189023. + String ((int) inputLatency));
  189024. }
  189025. isOpen_ = true;
  189026. log ("starting ASIO");
  189027. calledback = false;
  189028. err = asioObject->start();
  189029. if (err != 0)
  189030. {
  189031. isOpen_ = false;
  189032. log ("ASIO - stop on failure");
  189033. Thread::sleep (10);
  189034. asioObject->stop();
  189035. error = "Can't start device";
  189036. Thread::sleep (10);
  189037. }
  189038. else
  189039. {
  189040. int count = 300;
  189041. while (--count > 0 && ! calledback)
  189042. Thread::sleep (10);
  189043. isStarted = true;
  189044. if (! calledback)
  189045. {
  189046. error = "Device didn't start correctly";
  189047. log ("ASIO didn't callback - stopping..");
  189048. asioObject->stop();
  189049. }
  189050. }
  189051. }
  189052. else
  189053. {
  189054. error = "Can't create i/o buffers";
  189055. }
  189056. }
  189057. else
  189058. {
  189059. error = "Can't set sample rate: ";
  189060. error << sampleRate;
  189061. }
  189062. if (error.isNotEmpty())
  189063. {
  189064. logError (error, err);
  189065. if (asioObject != 0 && buffersCreated)
  189066. asioObject->disposeBuffers();
  189067. Thread::sleep (20);
  189068. isStarted = false;
  189069. isOpen_ = false;
  189070. close();
  189071. }
  189072. needToReset = false;
  189073. isReSync = false;
  189074. return error;
  189075. }
  189076. void close()
  189077. {
  189078. error = String::empty;
  189079. stopTimer();
  189080. stop();
  189081. if (isASIOOpen && isOpen_)
  189082. {
  189083. const ScopedLock sl (callbackLock);
  189084. isOpen_ = false;
  189085. isStarted = false;
  189086. needToReset = false;
  189087. isReSync = false;
  189088. log ("ASIO - stopping");
  189089. if (asioObject != 0)
  189090. {
  189091. Thread::sleep (20);
  189092. asioObject->stop();
  189093. Thread::sleep (10);
  189094. asioObject->disposeBuffers();
  189095. }
  189096. Thread::sleep (10);
  189097. }
  189098. }
  189099. bool isOpen()
  189100. {
  189101. return isOpen_ || insideControlPanelModalLoop;
  189102. }
  189103. int getCurrentBufferSizeSamples()
  189104. {
  189105. return currentBlockSizeSamples;
  189106. }
  189107. double getCurrentSampleRate()
  189108. {
  189109. return currentSampleRate;
  189110. }
  189111. const BitArray getActiveOutputChannels() const
  189112. {
  189113. return currentChansOut;
  189114. }
  189115. const BitArray getActiveInputChannels() const
  189116. {
  189117. return currentChansIn;
  189118. }
  189119. int getCurrentBitDepth()
  189120. {
  189121. return currentBitDepth;
  189122. }
  189123. int getOutputLatencyInSamples()
  189124. {
  189125. return outputLatency + currentBlockSizeSamples / 4;
  189126. }
  189127. int getInputLatencyInSamples()
  189128. {
  189129. return inputLatency + currentBlockSizeSamples / 4;
  189130. }
  189131. void start (AudioIODeviceCallback* callback)
  189132. {
  189133. if (callback != 0)
  189134. {
  189135. callback->audioDeviceAboutToStart (this);
  189136. const ScopedLock sl (callbackLock);
  189137. currentCallback = callback;
  189138. }
  189139. }
  189140. void stop()
  189141. {
  189142. AudioIODeviceCallback* const lastCallback = currentCallback;
  189143. {
  189144. const ScopedLock sl (callbackLock);
  189145. currentCallback = 0;
  189146. }
  189147. if (lastCallback != 0)
  189148. lastCallback->audioDeviceStopped();
  189149. }
  189150. bool isPlaying()
  189151. {
  189152. return isASIOOpen && (currentCallback != 0);
  189153. }
  189154. const String getLastError()
  189155. {
  189156. return error;
  189157. }
  189158. bool hasControlPanel() const
  189159. {
  189160. return true;
  189161. }
  189162. bool showControlPanel()
  189163. {
  189164. log ("ASIO - showing control panel");
  189165. Component modalWindow (String::empty);
  189166. modalWindow.setOpaque (true);
  189167. modalWindow.addToDesktop (0);
  189168. modalWindow.enterModalState();
  189169. bool done = false;
  189170. JUCE_TRY
  189171. {
  189172. // are there are devices that need to be closed before showing their control panel?
  189173. // close();
  189174. insideControlPanelModalLoop = true;
  189175. const uint32 started = Time::getMillisecondCounter();
  189176. if (asioObject != 0)
  189177. {
  189178. asioObject->controlPanel();
  189179. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  189180. log (T("spent: ") + String (spent));
  189181. if (spent > 300)
  189182. {
  189183. shouldUsePreferredSize = true;
  189184. done = true;
  189185. }
  189186. }
  189187. }
  189188. JUCE_CATCH_ALL
  189189. insideControlPanelModalLoop = false;
  189190. return done;
  189191. }
  189192. void resetRequest() throw()
  189193. {
  189194. needToReset = true;
  189195. }
  189196. void resyncRequest() throw()
  189197. {
  189198. needToReset = true;
  189199. isReSync = true;
  189200. }
  189201. void timerCallback()
  189202. {
  189203. if (! insideControlPanelModalLoop)
  189204. {
  189205. stopTimer();
  189206. // used to cause a reset
  189207. log ("! ASIO restart request!");
  189208. if (isOpen_)
  189209. {
  189210. AudioIODeviceCallback* const oldCallback = currentCallback;
  189211. close();
  189212. open (BitArray (currentChansIn), BitArray (currentChansOut),
  189213. currentSampleRate, currentBlockSizeSamples);
  189214. if (oldCallback != 0)
  189215. start (oldCallback);
  189216. }
  189217. }
  189218. else
  189219. {
  189220. startTimer (100);
  189221. }
  189222. }
  189223. juce_UseDebuggingNewOperator
  189224. private:
  189225. IASIO* volatile asioObject;
  189226. ASIOCallbacks callbacks;
  189227. void* windowHandle;
  189228. CLSID classId;
  189229. const String optionalDllForDirectLoading;
  189230. String error;
  189231. long totalNumInputChans, totalNumOutputChans;
  189232. StringArray inputChannelNames, outputChannelNames;
  189233. Array<int> sampleRates, bufferSizes;
  189234. long inputLatency, outputLatency;
  189235. long minSize, maxSize, preferredSize, granularity;
  189236. int volatile currentBlockSizeSamples;
  189237. int volatile currentBitDepth;
  189238. double volatile currentSampleRate;
  189239. BitArray currentChansOut, currentChansIn;
  189240. AudioIODeviceCallback* volatile currentCallback;
  189241. CriticalSection callbackLock;
  189242. ASIOBufferInfo bufferInfos [maxASIOChannels];
  189243. float* inBuffers [maxASIOChannels];
  189244. float* outBuffers [maxASIOChannels];
  189245. int inputChannelBitDepths [maxASIOChannels];
  189246. int outputChannelBitDepths [maxASIOChannels];
  189247. int inputChannelBytesPerSample [maxASIOChannels];
  189248. int outputChannelBytesPerSample [maxASIOChannels];
  189249. bool inputChannelIsFloat [maxASIOChannels];
  189250. bool outputChannelIsFloat [maxASIOChannels];
  189251. bool inputChannelLittleEndian [maxASIOChannels];
  189252. bool outputChannelLittleEndian [maxASIOChannels];
  189253. WaitableEvent event1;
  189254. HeapBlock <float> tempBuffer;
  189255. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  189256. bool isOpen_, isStarted;
  189257. bool volatile isASIOOpen;
  189258. bool volatile calledback;
  189259. bool volatile littleEndian, postOutput, needToReset, isReSync;
  189260. bool volatile insideControlPanelModalLoop;
  189261. bool volatile shouldUsePreferredSize;
  189262. void removeCurrentDriver()
  189263. {
  189264. if (asioObject != 0)
  189265. {
  189266. asioObject->Release();
  189267. asioObject = 0;
  189268. }
  189269. }
  189270. bool loadDriver()
  189271. {
  189272. removeCurrentDriver();
  189273. JUCE_TRY
  189274. {
  189275. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  189276. classId, (void**) &asioObject) == S_OK)
  189277. {
  189278. return true;
  189279. }
  189280. // If a class isn't registered but we have a path for it, we can fallback to
  189281. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  189282. if (optionalDllForDirectLoading.isNotEmpty())
  189283. {
  189284. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  189285. if (h != 0)
  189286. {
  189287. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  189288. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  189289. if (dllGetClassObject != 0)
  189290. {
  189291. IClassFactory* classFactory = 0;
  189292. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  189293. if (classFactory != 0)
  189294. {
  189295. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  189296. classFactory->Release();
  189297. }
  189298. return asioObject != 0;
  189299. }
  189300. }
  189301. }
  189302. }
  189303. JUCE_CATCH_ALL
  189304. asioObject = 0;
  189305. return false;
  189306. }
  189307. const String initDriver()
  189308. {
  189309. if (asioObject != 0)
  189310. {
  189311. char buffer [256];
  189312. zeromem (buffer, sizeof (buffer));
  189313. if (! asioObject->init (windowHandle))
  189314. {
  189315. asioObject->getErrorMessage (buffer);
  189316. return String (buffer, sizeof (buffer) - 1);
  189317. }
  189318. // just in case any daft drivers expect this to be called..
  189319. asioObject->getDriverName (buffer);
  189320. return String::empty;
  189321. }
  189322. return "No Driver";
  189323. }
  189324. const String openDevice()
  189325. {
  189326. // use this in case the driver starts opening dialog boxes..
  189327. Component modalWindow (String::empty);
  189328. modalWindow.setOpaque (true);
  189329. modalWindow.addToDesktop (0);
  189330. modalWindow.enterModalState();
  189331. // open the device and get its info..
  189332. log (T("opening ASIO device: ") + getName());
  189333. needToReset = false;
  189334. isReSync = false;
  189335. outputChannelNames.clear();
  189336. inputChannelNames.clear();
  189337. bufferSizes.clear();
  189338. sampleRates.clear();
  189339. isASIOOpen = false;
  189340. isOpen_ = false;
  189341. totalNumInputChans = 0;
  189342. totalNumOutputChans = 0;
  189343. numActiveInputChans = 0;
  189344. numActiveOutputChans = 0;
  189345. currentCallback = 0;
  189346. error = String::empty;
  189347. if (getName().isEmpty())
  189348. return error;
  189349. long err = 0;
  189350. if (loadDriver())
  189351. {
  189352. if ((error = initDriver()).isEmpty())
  189353. {
  189354. numActiveInputChans = 0;
  189355. numActiveOutputChans = 0;
  189356. totalNumInputChans = 0;
  189357. totalNumOutputChans = 0;
  189358. if (asioObject != 0
  189359. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  189360. {
  189361. log (String ((int) totalNumInputChans) + T(" in, ") + String ((int) totalNumOutputChans) + T(" out"));
  189362. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  189363. {
  189364. // find a list of buffer sizes..
  189365. log (String ((int) minSize) + T(" ") + String ((int) maxSize) + T(" ") + String ((int)preferredSize) + T(" ") + String ((int)granularity));
  189366. if (granularity >= 0)
  189367. {
  189368. granularity = jmax (1, (int) granularity);
  189369. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  189370. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  189371. }
  189372. else if (granularity < 0)
  189373. {
  189374. for (int i = 0; i < 18; ++i)
  189375. {
  189376. const int s = (1 << i);
  189377. if (s >= minSize && s <= maxSize)
  189378. bufferSizes.add (s);
  189379. }
  189380. }
  189381. if (! bufferSizes.contains (preferredSize))
  189382. bufferSizes.insert (0, preferredSize);
  189383. double currentRate = 0;
  189384. asioObject->getSampleRate (&currentRate);
  189385. if (currentRate <= 0.0 || currentRate > 192001.0)
  189386. {
  189387. log ("setting sample rate");
  189388. err = asioObject->setSampleRate (44100.0);
  189389. if (err != 0)
  189390. {
  189391. logError ("setting sample rate", err);
  189392. }
  189393. asioObject->getSampleRate (&currentRate);
  189394. }
  189395. currentSampleRate = currentRate;
  189396. postOutput = (asioObject->outputReady() == 0);
  189397. if (postOutput)
  189398. {
  189399. log ("ASIO outputReady = ok");
  189400. }
  189401. updateSampleRates();
  189402. // ..because cubase does it at this point
  189403. inputLatency = outputLatency = 0;
  189404. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  189405. {
  189406. log ("ASIO - no latencies");
  189407. }
  189408. log (String ("latencies: ")
  189409. + String ((int) inputLatency)
  189410. + T(", ") + String ((int) outputLatency));
  189411. // create some dummy buffers now.. because cubase does..
  189412. numActiveInputChans = 0;
  189413. numActiveOutputChans = 0;
  189414. ASIOBufferInfo* info = bufferInfos;
  189415. int i, numChans = 0;
  189416. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  189417. {
  189418. info->isInput = 1;
  189419. info->channelNum = i;
  189420. info->buffers[0] = info->buffers[1] = 0;
  189421. ++info;
  189422. ++numChans;
  189423. }
  189424. const int outputBufferIndex = numChans;
  189425. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  189426. {
  189427. info->isInput = 0;
  189428. info->channelNum = i;
  189429. info->buffers[0] = info->buffers[1] = 0;
  189430. ++info;
  189431. ++numChans;
  189432. }
  189433. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  189434. if (currentASIODev[0] == this)
  189435. {
  189436. callbacks.bufferSwitch = &bufferSwitchCallback0;
  189437. callbacks.asioMessage = &asioMessagesCallback0;
  189438. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  189439. }
  189440. else if (currentASIODev[1] == this)
  189441. {
  189442. callbacks.bufferSwitch = &bufferSwitchCallback1;
  189443. callbacks.asioMessage = &asioMessagesCallback1;
  189444. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  189445. }
  189446. else if (currentASIODev[2] == this)
  189447. {
  189448. callbacks.bufferSwitch = &bufferSwitchCallback2;
  189449. callbacks.asioMessage = &asioMessagesCallback2;
  189450. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  189451. }
  189452. else
  189453. {
  189454. jassertfalse
  189455. }
  189456. log (T("creating buffers (dummy): ") + String (numChans)
  189457. + T(", ") + String ((int) preferredSize));
  189458. if (preferredSize > 0)
  189459. {
  189460. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  189461. if (err != 0)
  189462. {
  189463. logError ("dummy buffers", err);
  189464. }
  189465. }
  189466. long newInps = 0, newOuts = 0;
  189467. asioObject->getChannels (&newInps, &newOuts);
  189468. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  189469. {
  189470. totalNumInputChans = newInps;
  189471. totalNumOutputChans = newOuts;
  189472. log (String ((int) totalNumInputChans) + T(" in; ")
  189473. + String ((int) totalNumOutputChans) + T(" out"));
  189474. }
  189475. updateSampleRates();
  189476. ASIOChannelInfo channelInfo;
  189477. channelInfo.type = 0;
  189478. for (i = 0; i < totalNumInputChans; ++i)
  189479. {
  189480. zerostruct (channelInfo);
  189481. channelInfo.channel = i;
  189482. channelInfo.isInput = 1;
  189483. asioObject->getChannelInfo (&channelInfo);
  189484. inputChannelNames.add (String (channelInfo.name));
  189485. }
  189486. for (i = 0; i < totalNumOutputChans; ++i)
  189487. {
  189488. zerostruct (channelInfo);
  189489. channelInfo.channel = i;
  189490. channelInfo.isInput = 0;
  189491. asioObject->getChannelInfo (&channelInfo);
  189492. outputChannelNames.add (String (channelInfo.name));
  189493. typeToFormatParameters (channelInfo.type,
  189494. outputChannelBitDepths[i],
  189495. outputChannelBytesPerSample[i],
  189496. outputChannelIsFloat[i],
  189497. outputChannelLittleEndian[i]);
  189498. if (i < 2)
  189499. {
  189500. // clear the channels that are used with the dummy stuff
  189501. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  189502. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  189503. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  189504. }
  189505. }
  189506. outputChannelNames.trim();
  189507. inputChannelNames.trim();
  189508. outputChannelNames.appendNumbersToDuplicates (false, true);
  189509. inputChannelNames.appendNumbersToDuplicates (false, true);
  189510. // start and stop because cubase does it..
  189511. asioObject->getLatencies (&inputLatency, &outputLatency);
  189512. if ((err = asioObject->start()) != 0)
  189513. {
  189514. // ignore an error here, as it might start later after setting other stuff up
  189515. logError ("ASIO start", err);
  189516. }
  189517. Thread::sleep (100);
  189518. asioObject->stop();
  189519. }
  189520. else
  189521. {
  189522. error = "Can't detect buffer sizes";
  189523. }
  189524. }
  189525. else
  189526. {
  189527. error = "Can't detect asio channels";
  189528. }
  189529. }
  189530. }
  189531. else
  189532. {
  189533. error = "No such device";
  189534. }
  189535. if (error.isNotEmpty())
  189536. {
  189537. logError (error, err);
  189538. if (asioObject != 0)
  189539. asioObject->disposeBuffers();
  189540. removeCurrentDriver();
  189541. isASIOOpen = false;
  189542. }
  189543. else
  189544. {
  189545. isASIOOpen = true;
  189546. log ("ASIO device open");
  189547. }
  189548. isOpen_ = false;
  189549. needToReset = false;
  189550. isReSync = false;
  189551. return error;
  189552. }
  189553. void callback (const long index) throw()
  189554. {
  189555. if (isStarted)
  189556. {
  189557. bufferIndex = index;
  189558. processBuffer();
  189559. }
  189560. else
  189561. {
  189562. if (postOutput && (asioObject != 0))
  189563. asioObject->outputReady();
  189564. }
  189565. calledback = true;
  189566. }
  189567. void processBuffer() throw()
  189568. {
  189569. const ASIOBufferInfo* const infos = bufferInfos;
  189570. const int bi = bufferIndex;
  189571. const ScopedLock sl (callbackLock);
  189572. if (needToReset)
  189573. {
  189574. needToReset = false;
  189575. if (isReSync)
  189576. {
  189577. log ("! ASIO resync");
  189578. isReSync = false;
  189579. }
  189580. else
  189581. {
  189582. startTimer (20);
  189583. }
  189584. }
  189585. if (bi >= 0)
  189586. {
  189587. const int samps = currentBlockSizeSamples;
  189588. if (currentCallback != 0)
  189589. {
  189590. int i;
  189591. for (i = 0; i < numActiveInputChans; ++i)
  189592. {
  189593. float* const dst = inBuffers[i];
  189594. jassert (dst != 0);
  189595. const char* const src = (const char*) (infos[i].buffers[bi]);
  189596. if (inputChannelIsFloat[i])
  189597. {
  189598. memcpy (dst, src, samps * sizeof (float));
  189599. }
  189600. else
  189601. {
  189602. jassert (dst == tempBuffer + (samps * i));
  189603. switch (inputChannelBitDepths[i])
  189604. {
  189605. case 16:
  189606. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189607. samps, inputChannelLittleEndian[i]);
  189608. break;
  189609. case 24:
  189610. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189611. samps, inputChannelLittleEndian[i]);
  189612. break;
  189613. case 32:
  189614. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189615. samps, inputChannelLittleEndian[i]);
  189616. break;
  189617. case 64:
  189618. jassertfalse
  189619. break;
  189620. }
  189621. }
  189622. }
  189623. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189624. numActiveInputChans,
  189625. outBuffers,
  189626. numActiveOutputChans,
  189627. samps);
  189628. for (i = 0; i < numActiveOutputChans; ++i)
  189629. {
  189630. float* const src = outBuffers[i];
  189631. jassert (src != 0);
  189632. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189633. if (outputChannelIsFloat[i])
  189634. {
  189635. memcpy (dst, src, samps * sizeof (float));
  189636. }
  189637. else
  189638. {
  189639. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189640. switch (outputChannelBitDepths[i])
  189641. {
  189642. case 16:
  189643. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189644. samps, outputChannelLittleEndian[i]);
  189645. break;
  189646. case 24:
  189647. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189648. samps, outputChannelLittleEndian[i]);
  189649. break;
  189650. case 32:
  189651. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189652. samps, outputChannelLittleEndian[i]);
  189653. break;
  189654. case 64:
  189655. jassertfalse
  189656. break;
  189657. }
  189658. }
  189659. }
  189660. }
  189661. else
  189662. {
  189663. for (int i = 0; i < numActiveOutputChans; ++i)
  189664. {
  189665. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189666. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189667. }
  189668. }
  189669. }
  189670. if (postOutput)
  189671. asioObject->outputReady();
  189672. }
  189673. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189674. {
  189675. if (currentASIODev[0] != 0)
  189676. currentASIODev[0]->callback (index);
  189677. return 0;
  189678. }
  189679. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189680. {
  189681. if (currentASIODev[1] != 0)
  189682. currentASIODev[1]->callback (index);
  189683. return 0;
  189684. }
  189685. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189686. {
  189687. if (currentASIODev[2] != 0)
  189688. currentASIODev[2]->callback (index);
  189689. return 0;
  189690. }
  189691. static void bufferSwitchCallback0 (long index, long) throw()
  189692. {
  189693. if (currentASIODev[0] != 0)
  189694. currentASIODev[0]->callback (index);
  189695. }
  189696. static void bufferSwitchCallback1 (long index, long) throw()
  189697. {
  189698. if (currentASIODev[1] != 0)
  189699. currentASIODev[1]->callback (index);
  189700. }
  189701. static void bufferSwitchCallback2 (long index, long) throw()
  189702. {
  189703. if (currentASIODev[2] != 0)
  189704. currentASIODev[2]->callback (index);
  189705. }
  189706. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189707. {
  189708. return asioMessagesCallback (selector, value, 0);
  189709. }
  189710. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189711. {
  189712. return asioMessagesCallback (selector, value, 1);
  189713. }
  189714. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189715. {
  189716. return asioMessagesCallback (selector, value, 2);
  189717. }
  189718. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189719. {
  189720. switch (selector)
  189721. {
  189722. case kAsioSelectorSupported:
  189723. if (value == kAsioResetRequest
  189724. || value == kAsioEngineVersion
  189725. || value == kAsioResyncRequest
  189726. || value == kAsioLatenciesChanged
  189727. || value == kAsioSupportsInputMonitor)
  189728. return 1;
  189729. break;
  189730. case kAsioBufferSizeChange:
  189731. break;
  189732. case kAsioResetRequest:
  189733. if (currentASIODev[deviceIndex] != 0)
  189734. currentASIODev[deviceIndex]->resetRequest();
  189735. return 1;
  189736. case kAsioResyncRequest:
  189737. if (currentASIODev[deviceIndex] != 0)
  189738. currentASIODev[deviceIndex]->resyncRequest();
  189739. return 1;
  189740. case kAsioLatenciesChanged:
  189741. return 1;
  189742. case kAsioEngineVersion:
  189743. return 2;
  189744. case kAsioSupportsTimeInfo:
  189745. case kAsioSupportsTimeCode:
  189746. return 0;
  189747. }
  189748. return 0;
  189749. }
  189750. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189751. {
  189752. }
  189753. static void convertInt16ToFloat (const char* src,
  189754. float* dest,
  189755. const int srcStrideBytes,
  189756. int numSamples,
  189757. const bool littleEndian) throw()
  189758. {
  189759. const double g = 1.0 / 32768.0;
  189760. if (littleEndian)
  189761. {
  189762. while (--numSamples >= 0)
  189763. {
  189764. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189765. src += srcStrideBytes;
  189766. }
  189767. }
  189768. else
  189769. {
  189770. while (--numSamples >= 0)
  189771. {
  189772. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189773. src += srcStrideBytes;
  189774. }
  189775. }
  189776. }
  189777. static void convertFloatToInt16 (const float* src,
  189778. char* dest,
  189779. const int dstStrideBytes,
  189780. int numSamples,
  189781. const bool littleEndian) throw()
  189782. {
  189783. const double maxVal = (double) 0x7fff;
  189784. if (littleEndian)
  189785. {
  189786. while (--numSamples >= 0)
  189787. {
  189788. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189789. dest += dstStrideBytes;
  189790. }
  189791. }
  189792. else
  189793. {
  189794. while (--numSamples >= 0)
  189795. {
  189796. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189797. dest += dstStrideBytes;
  189798. }
  189799. }
  189800. }
  189801. static void convertInt24ToFloat (const char* src,
  189802. float* dest,
  189803. const int srcStrideBytes,
  189804. int numSamples,
  189805. const bool littleEndian) throw()
  189806. {
  189807. const double g = 1.0 / 0x7fffff;
  189808. if (littleEndian)
  189809. {
  189810. while (--numSamples >= 0)
  189811. {
  189812. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189813. src += srcStrideBytes;
  189814. }
  189815. }
  189816. else
  189817. {
  189818. while (--numSamples >= 0)
  189819. {
  189820. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189821. src += srcStrideBytes;
  189822. }
  189823. }
  189824. }
  189825. static void convertFloatToInt24 (const float* src,
  189826. char* dest,
  189827. const int dstStrideBytes,
  189828. int numSamples,
  189829. const bool littleEndian) throw()
  189830. {
  189831. const double maxVal = (double) 0x7fffff;
  189832. if (littleEndian)
  189833. {
  189834. while (--numSamples >= 0)
  189835. {
  189836. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189837. dest += dstStrideBytes;
  189838. }
  189839. }
  189840. else
  189841. {
  189842. while (--numSamples >= 0)
  189843. {
  189844. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189845. dest += dstStrideBytes;
  189846. }
  189847. }
  189848. }
  189849. static void convertInt32ToFloat (const char* src,
  189850. float* dest,
  189851. const int srcStrideBytes,
  189852. int numSamples,
  189853. const bool littleEndian) throw()
  189854. {
  189855. const double g = 1.0 / 0x7fffffff;
  189856. if (littleEndian)
  189857. {
  189858. while (--numSamples >= 0)
  189859. {
  189860. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189861. src += srcStrideBytes;
  189862. }
  189863. }
  189864. else
  189865. {
  189866. while (--numSamples >= 0)
  189867. {
  189868. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189869. src += srcStrideBytes;
  189870. }
  189871. }
  189872. }
  189873. static void convertFloatToInt32 (const float* src,
  189874. char* dest,
  189875. const int dstStrideBytes,
  189876. int numSamples,
  189877. const bool littleEndian) throw()
  189878. {
  189879. const double maxVal = (double) 0x7fffffff;
  189880. if (littleEndian)
  189881. {
  189882. while (--numSamples >= 0)
  189883. {
  189884. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189885. dest += dstStrideBytes;
  189886. }
  189887. }
  189888. else
  189889. {
  189890. while (--numSamples >= 0)
  189891. {
  189892. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189893. dest += dstStrideBytes;
  189894. }
  189895. }
  189896. }
  189897. static void typeToFormatParameters (const long type,
  189898. int& bitDepth,
  189899. int& byteStride,
  189900. bool& formatIsFloat,
  189901. bool& littleEndian) throw()
  189902. {
  189903. bitDepth = 0;
  189904. littleEndian = false;
  189905. formatIsFloat = false;
  189906. switch (type)
  189907. {
  189908. case ASIOSTInt16MSB:
  189909. case ASIOSTInt16LSB:
  189910. case ASIOSTInt32MSB16:
  189911. case ASIOSTInt32LSB16:
  189912. bitDepth = 16; break;
  189913. case ASIOSTFloat32MSB:
  189914. case ASIOSTFloat32LSB:
  189915. formatIsFloat = true;
  189916. bitDepth = 32; break;
  189917. case ASIOSTInt32MSB:
  189918. case ASIOSTInt32LSB:
  189919. bitDepth = 32; break;
  189920. case ASIOSTInt24MSB:
  189921. case ASIOSTInt24LSB:
  189922. case ASIOSTInt32MSB24:
  189923. case ASIOSTInt32LSB24:
  189924. case ASIOSTInt32MSB18:
  189925. case ASIOSTInt32MSB20:
  189926. case ASIOSTInt32LSB18:
  189927. case ASIOSTInt32LSB20:
  189928. bitDepth = 24; break;
  189929. case ASIOSTFloat64MSB:
  189930. case ASIOSTFloat64LSB:
  189931. default:
  189932. bitDepth = 64;
  189933. break;
  189934. }
  189935. switch (type)
  189936. {
  189937. case ASIOSTInt16MSB:
  189938. case ASIOSTInt32MSB16:
  189939. case ASIOSTFloat32MSB:
  189940. case ASIOSTFloat64MSB:
  189941. case ASIOSTInt32MSB:
  189942. case ASIOSTInt32MSB18:
  189943. case ASIOSTInt32MSB20:
  189944. case ASIOSTInt32MSB24:
  189945. case ASIOSTInt24MSB:
  189946. littleEndian = false; break;
  189947. case ASIOSTInt16LSB:
  189948. case ASIOSTInt32LSB16:
  189949. case ASIOSTFloat32LSB:
  189950. case ASIOSTFloat64LSB:
  189951. case ASIOSTInt32LSB:
  189952. case ASIOSTInt32LSB18:
  189953. case ASIOSTInt32LSB20:
  189954. case ASIOSTInt32LSB24:
  189955. case ASIOSTInt24LSB:
  189956. littleEndian = true; break;
  189957. default:
  189958. break;
  189959. }
  189960. switch (type)
  189961. {
  189962. case ASIOSTInt16LSB:
  189963. case ASIOSTInt16MSB:
  189964. byteStride = 2; break;
  189965. case ASIOSTInt24LSB:
  189966. case ASIOSTInt24MSB:
  189967. byteStride = 3; break;
  189968. case ASIOSTInt32MSB16:
  189969. case ASIOSTInt32LSB16:
  189970. case ASIOSTInt32MSB:
  189971. case ASIOSTInt32MSB18:
  189972. case ASIOSTInt32MSB20:
  189973. case ASIOSTInt32MSB24:
  189974. case ASIOSTInt32LSB:
  189975. case ASIOSTInt32LSB18:
  189976. case ASIOSTInt32LSB20:
  189977. case ASIOSTInt32LSB24:
  189978. case ASIOSTFloat32LSB:
  189979. case ASIOSTFloat32MSB:
  189980. byteStride = 4; break;
  189981. case ASIOSTFloat64MSB:
  189982. case ASIOSTFloat64LSB:
  189983. byteStride = 8; break;
  189984. default:
  189985. break;
  189986. }
  189987. }
  189988. };
  189989. class ASIOAudioIODeviceType : public AudioIODeviceType
  189990. {
  189991. public:
  189992. ASIOAudioIODeviceType()
  189993. : AudioIODeviceType (T("ASIO")),
  189994. hasScanned (false)
  189995. {
  189996. CoInitialize (0);
  189997. }
  189998. ~ASIOAudioIODeviceType()
  189999. {
  190000. }
  190001. void scanForDevices()
  190002. {
  190003. hasScanned = true;
  190004. deviceNames.clear();
  190005. classIds.clear();
  190006. HKEY hk = 0;
  190007. int index = 0;
  190008. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  190009. {
  190010. for (;;)
  190011. {
  190012. char name [256];
  190013. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  190014. {
  190015. addDriverInfo (name, hk);
  190016. }
  190017. else
  190018. {
  190019. break;
  190020. }
  190021. }
  190022. RegCloseKey (hk);
  190023. }
  190024. }
  190025. const StringArray getDeviceNames (const bool /*wantInputNames*/) const
  190026. {
  190027. jassert (hasScanned); // need to call scanForDevices() before doing this
  190028. return deviceNames;
  190029. }
  190030. int getDefaultDeviceIndex (const bool) const
  190031. {
  190032. jassert (hasScanned); // need to call scanForDevices() before doing this
  190033. for (int i = deviceNames.size(); --i >= 0;)
  190034. if (deviceNames[i].containsIgnoreCase (T("asio4all")))
  190035. return i; // asio4all is a safe choice for a default..
  190036. #if JUCE_DEBUG
  190037. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase (T("digidesign")))
  190038. return 1; // (the digi m-box driver crashes the app when you run
  190039. // it in the debugger, which can be a bit annoying)
  190040. #endif
  190041. return 0;
  190042. }
  190043. static int findFreeSlot()
  190044. {
  190045. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  190046. if (currentASIODev[i] == 0)
  190047. return i;
  190048. jassertfalse; // unfortunately you can only have a finite number
  190049. // of ASIO devices open at the same time..
  190050. return -1;
  190051. }
  190052. int getIndexOfDevice (AudioIODevice* d, const bool /*asInput*/) const
  190053. {
  190054. jassert (hasScanned); // need to call scanForDevices() before doing this
  190055. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  190056. }
  190057. bool hasSeparateInputsAndOutputs() const { return false; }
  190058. AudioIODevice* createDevice (const String& outputDeviceName,
  190059. const String& inputDeviceName)
  190060. {
  190061. // ASIO can't open two different devices for input and output - they must be the same one.
  190062. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  190063. jassert (hasScanned); // need to call scanForDevices() before doing this
  190064. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  190065. : inputDeviceName);
  190066. if (index >= 0)
  190067. {
  190068. const int freeSlot = findFreeSlot();
  190069. if (freeSlot >= 0)
  190070. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  190071. }
  190072. return 0;
  190073. }
  190074. juce_UseDebuggingNewOperator
  190075. private:
  190076. StringArray deviceNames;
  190077. OwnedArray <CLSID> classIds;
  190078. bool hasScanned;
  190079. static bool checkClassIsOk (const String& classId)
  190080. {
  190081. HKEY hk = 0;
  190082. bool ok = false;
  190083. if (RegOpenKeyA (HKEY_CLASSES_ROOT, "clsid", &hk) == ERROR_SUCCESS)
  190084. {
  190085. int index = 0;
  190086. for (;;)
  190087. {
  190088. char buf [512];
  190089. if (RegEnumKeyA (hk, index++, buf, 512) == ERROR_SUCCESS)
  190090. {
  190091. if (classId.equalsIgnoreCase (buf))
  190092. {
  190093. HKEY subKey, pathKey;
  190094. if (RegOpenKeyExA (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  190095. {
  190096. if (RegOpenKeyExA (subKey, "InprocServer32", 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  190097. {
  190098. char pathName [600];
  190099. DWORD dtype = REG_SZ;
  190100. DWORD dsize = sizeof (pathName);
  190101. if (RegQueryValueExA (pathKey, 0, 0, &dtype,
  190102. (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  190103. {
  190104. OFSTRUCT of;
  190105. zerostruct (of);
  190106. of.cBytes = sizeof (of);
  190107. ok = (OpenFile (String (pathName), &of, OF_EXIST) != 0);
  190108. }
  190109. RegCloseKey (pathKey);
  190110. }
  190111. RegCloseKey (subKey);
  190112. }
  190113. break;
  190114. }
  190115. }
  190116. else
  190117. {
  190118. break;
  190119. }
  190120. }
  190121. RegCloseKey (hk);
  190122. }
  190123. return ok;
  190124. }
  190125. void addDriverInfo (const String& keyName, HKEY hk)
  190126. {
  190127. HKEY subKey;
  190128. if (RegOpenKeyExA (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  190129. {
  190130. char buf [256];
  190131. DWORD dtype = REG_SZ;
  190132. DWORD dsize = sizeof (buf);
  190133. zeromem (buf, dsize);
  190134. if (RegQueryValueExA (subKey, "clsid", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  190135. {
  190136. if (dsize > 0 && checkClassIsOk (buf))
  190137. {
  190138. wchar_t classIdStr [130];
  190139. MultiByteToWideChar (CP_ACP, 0, buf, -1, classIdStr, 128);
  190140. String deviceName;
  190141. CLSID classId;
  190142. if (CLSIDFromString ((LPOLESTR) classIdStr, &classId) == S_OK)
  190143. {
  190144. dtype = REG_SZ;
  190145. dsize = sizeof (buf);
  190146. if (RegQueryValueExA (subKey, "description", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  190147. deviceName = buf;
  190148. else
  190149. deviceName = keyName;
  190150. log (T("found ") + deviceName);
  190151. deviceNames.add (deviceName);
  190152. classIds.add (new CLSID (classId));
  190153. }
  190154. }
  190155. RegCloseKey (subKey);
  190156. }
  190157. }
  190158. }
  190159. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  190160. const ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  190161. };
  190162. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  190163. {
  190164. return new ASIOAudioIODeviceType();
  190165. }
  190166. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  190167. void* guid,
  190168. const String& optionalDllForDirectLoading)
  190169. {
  190170. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  190171. if (freeSlot < 0)
  190172. return 0;
  190173. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  190174. }
  190175. #undef log
  190176. #endif
  190177. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  190178. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  190179. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190180. // compiled on its own).
  190181. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  190182. END_JUCE_NAMESPACE
  190183. extern "C"
  190184. {
  190185. // Declare just the minimum number of interfaces for the DSound objects that we need..
  190186. typedef struct typeDSBUFFERDESC
  190187. {
  190188. DWORD dwSize;
  190189. DWORD dwFlags;
  190190. DWORD dwBufferBytes;
  190191. DWORD dwReserved;
  190192. LPWAVEFORMATEX lpwfxFormat;
  190193. GUID guid3DAlgorithm;
  190194. } DSBUFFERDESC;
  190195. struct IDirectSoundBuffer;
  190196. #undef INTERFACE
  190197. #define INTERFACE IDirectSound
  190198. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  190199. {
  190200. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190201. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190202. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190203. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  190204. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190205. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  190206. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  190207. STDMETHOD(Compact) (THIS) PURE;
  190208. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  190209. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  190210. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190211. };
  190212. #undef INTERFACE
  190213. #define INTERFACE IDirectSoundBuffer
  190214. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  190215. {
  190216. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190217. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190218. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190219. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190220. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190221. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190222. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  190223. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  190224. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  190225. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190226. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  190227. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190228. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  190229. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  190230. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  190231. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  190232. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  190233. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  190234. STDMETHOD(Stop) (THIS) PURE;
  190235. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190236. STDMETHOD(Restore) (THIS) PURE;
  190237. };
  190238. typedef struct typeDSCBUFFERDESC
  190239. {
  190240. DWORD dwSize;
  190241. DWORD dwFlags;
  190242. DWORD dwBufferBytes;
  190243. DWORD dwReserved;
  190244. LPWAVEFORMATEX lpwfxFormat;
  190245. } DSCBUFFERDESC;
  190246. struct IDirectSoundCaptureBuffer;
  190247. #undef INTERFACE
  190248. #define INTERFACE IDirectSoundCapture
  190249. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  190250. {
  190251. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190252. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190253. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190254. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  190255. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190256. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190257. };
  190258. #undef INTERFACE
  190259. #define INTERFACE IDirectSoundCaptureBuffer
  190260. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  190261. {
  190262. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190263. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190264. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190265. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190266. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190267. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190268. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190269. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  190270. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190271. STDMETHOD(Start) (THIS_ DWORD) PURE;
  190272. STDMETHOD(Stop) (THIS) PURE;
  190273. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190274. };
  190275. };
  190276. BEGIN_JUCE_NAMESPACE
  190277. static const String getDSErrorMessage (HRESULT hr)
  190278. {
  190279. const char* result = 0;
  190280. switch (hr)
  190281. {
  190282. case MAKE_HRESULT(1, 0x878, 10):
  190283. result = "Device already allocated";
  190284. break;
  190285. case MAKE_HRESULT(1, 0x878, 30):
  190286. result = "Control unavailable";
  190287. break;
  190288. case E_INVALIDARG:
  190289. result = "Invalid parameter";
  190290. break;
  190291. case MAKE_HRESULT(1, 0x878, 50):
  190292. result = "Invalid call";
  190293. break;
  190294. case E_FAIL:
  190295. result = "Generic error";
  190296. break;
  190297. case MAKE_HRESULT(1, 0x878, 70):
  190298. result = "Priority level error";
  190299. break;
  190300. case E_OUTOFMEMORY:
  190301. result = "Out of memory";
  190302. break;
  190303. case MAKE_HRESULT(1, 0x878, 100):
  190304. result = "Bad format";
  190305. break;
  190306. case E_NOTIMPL:
  190307. result = "Unsupported function";
  190308. break;
  190309. case MAKE_HRESULT(1, 0x878, 120):
  190310. result = "No driver";
  190311. break;
  190312. case MAKE_HRESULT(1, 0x878, 130):
  190313. result = "Already initialised";
  190314. break;
  190315. case CLASS_E_NOAGGREGATION:
  190316. result = "No aggregation";
  190317. break;
  190318. case MAKE_HRESULT(1, 0x878, 150):
  190319. result = "Buffer lost";
  190320. break;
  190321. case MAKE_HRESULT(1, 0x878, 160):
  190322. result = "Another app has priority";
  190323. break;
  190324. case MAKE_HRESULT(1, 0x878, 170):
  190325. result = "Uninitialised";
  190326. break;
  190327. case E_NOINTERFACE:
  190328. result = "No interface";
  190329. break;
  190330. case S_OK:
  190331. result = "No error";
  190332. break;
  190333. default:
  190334. return "Unknown error: " + String ((int) hr);
  190335. }
  190336. return result;
  190337. }
  190338. #define DS_DEBUGGING 1
  190339. #ifdef DS_DEBUGGING
  190340. #define CATCH JUCE_CATCH_EXCEPTION
  190341. #undef log
  190342. #define log(a) Logger::writeToLog(a);
  190343. #undef logError
  190344. #define logError(a) logDSError(a, __LINE__);
  190345. static void logDSError (HRESULT hr, int lineNum)
  190346. {
  190347. if (hr != S_OK)
  190348. {
  190349. String error ("DS error at line ");
  190350. error << lineNum << T(" - ") << getDSErrorMessage (hr);
  190351. log (error);
  190352. }
  190353. }
  190354. #else
  190355. #define CATCH JUCE_CATCH_ALL
  190356. #define log(a)
  190357. #define logError(a)
  190358. #endif
  190359. #define DSOUND_FUNCTION(functionName, params) \
  190360. typedef HRESULT (WINAPI *type##functionName) params; \
  190361. static type##functionName ds##functionName = 0;
  190362. #define DSOUND_FUNCTION_LOAD(functionName) \
  190363. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  190364. jassert (ds##functionName != 0);
  190365. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  190366. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  190367. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  190368. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  190369. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190370. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190371. static void initialiseDSoundFunctions()
  190372. {
  190373. if (dsDirectSoundCreate == 0)
  190374. {
  190375. HMODULE h = LoadLibraryA ("dsound.dll");
  190376. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  190377. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  190378. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  190379. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  190380. }
  190381. }
  190382. class DSoundInternalOutChannel
  190383. {
  190384. String name;
  190385. LPGUID guid;
  190386. int sampleRate, bufferSizeSamples;
  190387. float* leftBuffer;
  190388. float* rightBuffer;
  190389. IDirectSound* pDirectSound;
  190390. IDirectSoundBuffer* pOutputBuffer;
  190391. DWORD writeOffset;
  190392. int totalBytesPerBuffer;
  190393. int bytesPerBuffer;
  190394. unsigned int lastPlayCursor;
  190395. public:
  190396. int bitDepth;
  190397. bool doneFlag;
  190398. DSoundInternalOutChannel (const String& name_,
  190399. LPGUID guid_,
  190400. int rate,
  190401. int bufferSize,
  190402. float* left,
  190403. float* right)
  190404. : name (name_),
  190405. guid (guid_),
  190406. sampleRate (rate),
  190407. bufferSizeSamples (bufferSize),
  190408. leftBuffer (left),
  190409. rightBuffer (right),
  190410. pDirectSound (0),
  190411. pOutputBuffer (0),
  190412. bitDepth (16)
  190413. {
  190414. }
  190415. ~DSoundInternalOutChannel()
  190416. {
  190417. close();
  190418. }
  190419. void close()
  190420. {
  190421. HRESULT hr;
  190422. if (pOutputBuffer != 0)
  190423. {
  190424. JUCE_TRY
  190425. {
  190426. log (T("closing dsound out: ") + name);
  190427. hr = pOutputBuffer->Stop();
  190428. logError (hr);
  190429. }
  190430. CATCH
  190431. JUCE_TRY
  190432. {
  190433. hr = pOutputBuffer->Release();
  190434. logError (hr);
  190435. }
  190436. CATCH
  190437. pOutputBuffer = 0;
  190438. }
  190439. if (pDirectSound != 0)
  190440. {
  190441. JUCE_TRY
  190442. {
  190443. hr = pDirectSound->Release();
  190444. logError (hr);
  190445. }
  190446. CATCH
  190447. pDirectSound = 0;
  190448. }
  190449. }
  190450. const String open()
  190451. {
  190452. log (T("opening dsound out device: ") + name
  190453. + T(" rate=") + String (sampleRate)
  190454. + T(" bits=") + String (bitDepth)
  190455. + T(" buf=") + String (bufferSizeSamples));
  190456. pDirectSound = 0;
  190457. pOutputBuffer = 0;
  190458. writeOffset = 0;
  190459. String error;
  190460. HRESULT hr = E_NOINTERFACE;
  190461. if (dsDirectSoundCreate != 0)
  190462. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  190463. if (hr == S_OK)
  190464. {
  190465. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190466. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190467. const int numChannels = 2;
  190468. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  190469. logError (hr);
  190470. if (hr == S_OK)
  190471. {
  190472. IDirectSoundBuffer* pPrimaryBuffer;
  190473. DSBUFFERDESC primaryDesc;
  190474. zerostruct (primaryDesc);
  190475. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190476. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  190477. primaryDesc.dwBufferBytes = 0;
  190478. primaryDesc.lpwfxFormat = 0;
  190479. log ("opening dsound out step 2");
  190480. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  190481. logError (hr);
  190482. if (hr == S_OK)
  190483. {
  190484. WAVEFORMATEX wfFormat;
  190485. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190486. wfFormat.nChannels = (unsigned short) numChannels;
  190487. wfFormat.nSamplesPerSec = sampleRate;
  190488. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  190489. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  190490. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190491. wfFormat.cbSize = 0;
  190492. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  190493. logError (hr);
  190494. if (hr == S_OK)
  190495. {
  190496. DSBUFFERDESC secondaryDesc;
  190497. zerostruct (secondaryDesc);
  190498. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190499. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  190500. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  190501. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  190502. secondaryDesc.lpwfxFormat = &wfFormat;
  190503. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  190504. logError (hr);
  190505. if (hr == S_OK)
  190506. {
  190507. log ("opening dsound out step 3");
  190508. DWORD dwDataLen;
  190509. unsigned char* pDSBuffData;
  190510. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  190511. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  190512. logError (hr);
  190513. if (hr == S_OK)
  190514. {
  190515. zeromem (pDSBuffData, dwDataLen);
  190516. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  190517. if (hr == S_OK)
  190518. {
  190519. hr = pOutputBuffer->SetCurrentPosition (0);
  190520. if (hr == S_OK)
  190521. {
  190522. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  190523. if (hr == S_OK)
  190524. return String::empty;
  190525. }
  190526. }
  190527. }
  190528. }
  190529. }
  190530. }
  190531. }
  190532. }
  190533. error = getDSErrorMessage (hr);
  190534. close();
  190535. return error;
  190536. }
  190537. void synchronisePosition()
  190538. {
  190539. if (pOutputBuffer != 0)
  190540. {
  190541. DWORD playCursor;
  190542. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  190543. }
  190544. }
  190545. bool service()
  190546. {
  190547. if (pOutputBuffer == 0)
  190548. return true;
  190549. DWORD playCursor, writeCursor;
  190550. for (;;)
  190551. {
  190552. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  190553. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190554. {
  190555. pOutputBuffer->Restore();
  190556. continue;
  190557. }
  190558. if (hr == S_OK)
  190559. break;
  190560. logError (hr);
  190561. jassertfalse
  190562. return true;
  190563. }
  190564. int playWriteGap = writeCursor - playCursor;
  190565. if (playWriteGap < 0)
  190566. playWriteGap += totalBytesPerBuffer;
  190567. int bytesEmpty = playCursor - writeOffset;
  190568. if (bytesEmpty < 0)
  190569. bytesEmpty += totalBytesPerBuffer;
  190570. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  190571. {
  190572. writeOffset = writeCursor;
  190573. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  190574. }
  190575. if (bytesEmpty >= bytesPerBuffer)
  190576. {
  190577. LPBYTE lpbuf1 = 0;
  190578. LPBYTE lpbuf2 = 0;
  190579. DWORD dwSize1 = 0;
  190580. DWORD dwSize2 = 0;
  190581. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  190582. bytesPerBuffer,
  190583. (void**) &lpbuf1, &dwSize1,
  190584. (void**) &lpbuf2, &dwSize2, 0);
  190585. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190586. {
  190587. pOutputBuffer->Restore();
  190588. hr = pOutputBuffer->Lock (writeOffset,
  190589. bytesPerBuffer,
  190590. (void**) &lpbuf1, &dwSize1,
  190591. (void**) &lpbuf2, &dwSize2, 0);
  190592. }
  190593. if (hr == S_OK)
  190594. {
  190595. if (bitDepth == 16)
  190596. {
  190597. const float gainL = 32767.0f;
  190598. const float gainR = 32767.0f;
  190599. int* dest = (int*)lpbuf1;
  190600. const float* left = leftBuffer;
  190601. const float* right = rightBuffer;
  190602. int samples1 = dwSize1 >> 2;
  190603. int samples2 = dwSize2 >> 2;
  190604. if (left == 0)
  190605. {
  190606. while (--samples1 >= 0)
  190607. {
  190608. int r = roundToInt (gainR * *right++);
  190609. if (r < -32768)
  190610. r = -32768;
  190611. else if (r > 32767)
  190612. r = 32767;
  190613. *dest++ = (r << 16);
  190614. }
  190615. dest = (int*)lpbuf2;
  190616. while (--samples2 >= 0)
  190617. {
  190618. int r = roundToInt (gainR * *right++);
  190619. if (r < -32768)
  190620. r = -32768;
  190621. else if (r > 32767)
  190622. r = 32767;
  190623. *dest++ = (r << 16);
  190624. }
  190625. }
  190626. else if (right == 0)
  190627. {
  190628. while (--samples1 >= 0)
  190629. {
  190630. int l = roundToInt (gainL * *left++);
  190631. if (l < -32768)
  190632. l = -32768;
  190633. else if (l > 32767)
  190634. l = 32767;
  190635. l &= 0xffff;
  190636. *dest++ = l;
  190637. }
  190638. dest = (int*)lpbuf2;
  190639. while (--samples2 >= 0)
  190640. {
  190641. int l = roundToInt (gainL * *left++);
  190642. if (l < -32768)
  190643. l = -32768;
  190644. else if (l > 32767)
  190645. l = 32767;
  190646. l &= 0xffff;
  190647. *dest++ = l;
  190648. }
  190649. }
  190650. else
  190651. {
  190652. while (--samples1 >= 0)
  190653. {
  190654. int l = roundToInt (gainL * *left++);
  190655. if (l < -32768)
  190656. l = -32768;
  190657. else if (l > 32767)
  190658. l = 32767;
  190659. l &= 0xffff;
  190660. int r = roundToInt (gainR * *right++);
  190661. if (r < -32768)
  190662. r = -32768;
  190663. else if (r > 32767)
  190664. r = 32767;
  190665. *dest++ = (r << 16) | l;
  190666. }
  190667. dest = (int*)lpbuf2;
  190668. while (--samples2 >= 0)
  190669. {
  190670. int l = roundToInt (gainL * *left++);
  190671. if (l < -32768)
  190672. l = -32768;
  190673. else if (l > 32767)
  190674. l = 32767;
  190675. l &= 0xffff;
  190676. int r = roundToInt (gainR * *right++);
  190677. if (r < -32768)
  190678. r = -32768;
  190679. else if (r > 32767)
  190680. r = 32767;
  190681. *dest++ = (r << 16) | l;
  190682. }
  190683. }
  190684. }
  190685. else
  190686. {
  190687. jassertfalse
  190688. }
  190689. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190690. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190691. }
  190692. else
  190693. {
  190694. jassertfalse
  190695. logError (hr);
  190696. }
  190697. bytesEmpty -= bytesPerBuffer;
  190698. return true;
  190699. }
  190700. else
  190701. {
  190702. return false;
  190703. }
  190704. }
  190705. };
  190706. struct DSoundInternalInChannel
  190707. {
  190708. String name;
  190709. LPGUID guid;
  190710. int sampleRate, bufferSizeSamples;
  190711. float* leftBuffer;
  190712. float* rightBuffer;
  190713. IDirectSound* pDirectSound;
  190714. IDirectSoundCapture* pDirectSoundCapture;
  190715. IDirectSoundCaptureBuffer* pInputBuffer;
  190716. public:
  190717. unsigned int readOffset;
  190718. int bytesPerBuffer, totalBytesPerBuffer;
  190719. int bitDepth;
  190720. bool doneFlag;
  190721. DSoundInternalInChannel (const String& name_,
  190722. LPGUID guid_,
  190723. int rate,
  190724. int bufferSize,
  190725. float* left,
  190726. float* right)
  190727. : name (name_),
  190728. guid (guid_),
  190729. sampleRate (rate),
  190730. bufferSizeSamples (bufferSize),
  190731. leftBuffer (left),
  190732. rightBuffer (right),
  190733. pDirectSound (0),
  190734. pDirectSoundCapture (0),
  190735. pInputBuffer (0),
  190736. bitDepth (16)
  190737. {
  190738. }
  190739. ~DSoundInternalInChannel()
  190740. {
  190741. close();
  190742. }
  190743. void close()
  190744. {
  190745. HRESULT hr;
  190746. if (pInputBuffer != 0)
  190747. {
  190748. JUCE_TRY
  190749. {
  190750. log (T("closing dsound in: ") + name);
  190751. hr = pInputBuffer->Stop();
  190752. logError (hr);
  190753. }
  190754. CATCH
  190755. JUCE_TRY
  190756. {
  190757. hr = pInputBuffer->Release();
  190758. logError (hr);
  190759. }
  190760. CATCH
  190761. pInputBuffer = 0;
  190762. }
  190763. if (pDirectSoundCapture != 0)
  190764. {
  190765. JUCE_TRY
  190766. {
  190767. hr = pDirectSoundCapture->Release();
  190768. logError (hr);
  190769. }
  190770. CATCH
  190771. pDirectSoundCapture = 0;
  190772. }
  190773. if (pDirectSound != 0)
  190774. {
  190775. JUCE_TRY
  190776. {
  190777. hr = pDirectSound->Release();
  190778. logError (hr);
  190779. }
  190780. CATCH
  190781. pDirectSound = 0;
  190782. }
  190783. }
  190784. const String open()
  190785. {
  190786. log (T("opening dsound in device: ") + name
  190787. + T(" rate=") + String (sampleRate) + T(" bits=") + String (bitDepth) + T(" buf=") + String (bufferSizeSamples));
  190788. pDirectSound = 0;
  190789. pDirectSoundCapture = 0;
  190790. pInputBuffer = 0;
  190791. readOffset = 0;
  190792. totalBytesPerBuffer = 0;
  190793. String error;
  190794. HRESULT hr = E_NOINTERFACE;
  190795. if (dsDirectSoundCaptureCreate != 0)
  190796. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190797. logError (hr);
  190798. if (hr == S_OK)
  190799. {
  190800. const int numChannels = 2;
  190801. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190802. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190803. WAVEFORMATEX wfFormat;
  190804. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190805. wfFormat.nChannels = (unsigned short)numChannels;
  190806. wfFormat.nSamplesPerSec = sampleRate;
  190807. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190808. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190809. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190810. wfFormat.cbSize = 0;
  190811. DSCBUFFERDESC captureDesc;
  190812. zerostruct (captureDesc);
  190813. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190814. captureDesc.dwFlags = 0;
  190815. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190816. captureDesc.lpwfxFormat = &wfFormat;
  190817. log (T("opening dsound in step 2"));
  190818. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190819. logError (hr);
  190820. if (hr == S_OK)
  190821. {
  190822. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190823. logError (hr);
  190824. if (hr == S_OK)
  190825. return String::empty;
  190826. }
  190827. }
  190828. error = getDSErrorMessage (hr);
  190829. close();
  190830. return error;
  190831. }
  190832. void synchronisePosition()
  190833. {
  190834. if (pInputBuffer != 0)
  190835. {
  190836. DWORD capturePos;
  190837. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190838. }
  190839. }
  190840. bool service()
  190841. {
  190842. if (pInputBuffer == 0)
  190843. return true;
  190844. DWORD capturePos, readPos;
  190845. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190846. logError (hr);
  190847. if (hr != S_OK)
  190848. return true;
  190849. int bytesFilled = readPos - readOffset;
  190850. if (bytesFilled < 0)
  190851. bytesFilled += totalBytesPerBuffer;
  190852. if (bytesFilled >= bytesPerBuffer)
  190853. {
  190854. LPBYTE lpbuf1 = 0;
  190855. LPBYTE lpbuf2 = 0;
  190856. DWORD dwsize1 = 0;
  190857. DWORD dwsize2 = 0;
  190858. HRESULT hr = pInputBuffer->Lock (readOffset,
  190859. bytesPerBuffer,
  190860. (void**) &lpbuf1, &dwsize1,
  190861. (void**) &lpbuf2, &dwsize2, 0);
  190862. if (hr == S_OK)
  190863. {
  190864. if (bitDepth == 16)
  190865. {
  190866. const float g = 1.0f / 32768.0f;
  190867. float* destL = leftBuffer;
  190868. float* destR = rightBuffer;
  190869. int samples1 = dwsize1 >> 2;
  190870. int samples2 = dwsize2 >> 2;
  190871. const short* src = (const short*)lpbuf1;
  190872. if (destL == 0)
  190873. {
  190874. while (--samples1 >= 0)
  190875. {
  190876. ++src;
  190877. *destR++ = *src++ * g;
  190878. }
  190879. src = (const short*)lpbuf2;
  190880. while (--samples2 >= 0)
  190881. {
  190882. ++src;
  190883. *destR++ = *src++ * g;
  190884. }
  190885. }
  190886. else if (destR == 0)
  190887. {
  190888. while (--samples1 >= 0)
  190889. {
  190890. *destL++ = *src++ * g;
  190891. ++src;
  190892. }
  190893. src = (const short*)lpbuf2;
  190894. while (--samples2 >= 0)
  190895. {
  190896. *destL++ = *src++ * g;
  190897. ++src;
  190898. }
  190899. }
  190900. else
  190901. {
  190902. while (--samples1 >= 0)
  190903. {
  190904. *destL++ = *src++ * g;
  190905. *destR++ = *src++ * g;
  190906. }
  190907. src = (const short*)lpbuf2;
  190908. while (--samples2 >= 0)
  190909. {
  190910. *destL++ = *src++ * g;
  190911. *destR++ = *src++ * g;
  190912. }
  190913. }
  190914. }
  190915. else
  190916. {
  190917. jassertfalse
  190918. }
  190919. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190920. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190921. }
  190922. else
  190923. {
  190924. logError (hr);
  190925. jassertfalse
  190926. }
  190927. bytesFilled -= bytesPerBuffer;
  190928. return true;
  190929. }
  190930. else
  190931. {
  190932. return false;
  190933. }
  190934. }
  190935. };
  190936. class DSoundAudioIODevice : public AudioIODevice,
  190937. public Thread
  190938. {
  190939. public:
  190940. DSoundAudioIODevice (const String& deviceName,
  190941. const int outputDeviceIndex_,
  190942. const int inputDeviceIndex_)
  190943. : AudioIODevice (deviceName, "DirectSound"),
  190944. Thread ("Juce DSound"),
  190945. isOpen_ (false),
  190946. isStarted (false),
  190947. outputDeviceIndex (outputDeviceIndex_),
  190948. inputDeviceIndex (inputDeviceIndex_),
  190949. numInputBuffers (0),
  190950. numOutputBuffers (0),
  190951. totalSamplesOut (0),
  190952. sampleRate (0.0),
  190953. inputBuffers (0),
  190954. outputBuffers (0),
  190955. callback (0),
  190956. bufferSizeSamples (0)
  190957. {
  190958. if (outputDeviceIndex_ >= 0)
  190959. {
  190960. outChannels.add (TRANS("Left"));
  190961. outChannels.add (TRANS("Right"));
  190962. }
  190963. if (inputDeviceIndex_ >= 0)
  190964. {
  190965. inChannels.add (TRANS("Left"));
  190966. inChannels.add (TRANS("Right"));
  190967. }
  190968. }
  190969. ~DSoundAudioIODevice()
  190970. {
  190971. close();
  190972. }
  190973. const StringArray getOutputChannelNames()
  190974. {
  190975. return outChannels;
  190976. }
  190977. const StringArray getInputChannelNames()
  190978. {
  190979. return inChannels;
  190980. }
  190981. int getNumSampleRates()
  190982. {
  190983. return 4;
  190984. }
  190985. double getSampleRate (int index)
  190986. {
  190987. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190988. return samps [jlimit (0, 3, index)];
  190989. }
  190990. int getNumBufferSizesAvailable()
  190991. {
  190992. return 50;
  190993. }
  190994. int getBufferSizeSamples (int index)
  190995. {
  190996. int n = 64;
  190997. for (int i = 0; i < index; ++i)
  190998. n += (n < 512) ? 32
  190999. : ((n < 1024) ? 64
  191000. : ((n < 2048) ? 128 : 256));
  191001. return n;
  191002. }
  191003. int getDefaultBufferSize()
  191004. {
  191005. return 2560;
  191006. }
  191007. const String open (const BitArray& inputChannels,
  191008. const BitArray& outputChannels,
  191009. double sampleRate,
  191010. int bufferSizeSamples)
  191011. {
  191012. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  191013. isOpen_ = lastError.isEmpty();
  191014. return lastError;
  191015. }
  191016. void close()
  191017. {
  191018. stop();
  191019. if (isOpen_)
  191020. {
  191021. closeDevice();
  191022. isOpen_ = false;
  191023. }
  191024. }
  191025. bool isOpen()
  191026. {
  191027. return isOpen_ && isThreadRunning();
  191028. }
  191029. int getCurrentBufferSizeSamples()
  191030. {
  191031. return bufferSizeSamples;
  191032. }
  191033. double getCurrentSampleRate()
  191034. {
  191035. return sampleRate;
  191036. }
  191037. int getCurrentBitDepth()
  191038. {
  191039. int i, bits = 256;
  191040. for (i = inChans.size(); --i >= 0;)
  191041. bits = jmin (bits, inChans[i]->bitDepth);
  191042. for (i = outChans.size(); --i >= 0;)
  191043. bits = jmin (bits, outChans[i]->bitDepth);
  191044. if (bits > 32)
  191045. bits = 16;
  191046. return bits;
  191047. }
  191048. const BitArray getActiveOutputChannels() const
  191049. {
  191050. return enabledOutputs;
  191051. }
  191052. const BitArray getActiveInputChannels() const
  191053. {
  191054. return enabledInputs;
  191055. }
  191056. int getOutputLatencyInSamples()
  191057. {
  191058. return (int) (getCurrentBufferSizeSamples() * 1.5);
  191059. }
  191060. int getInputLatencyInSamples()
  191061. {
  191062. return getOutputLatencyInSamples();
  191063. }
  191064. void start (AudioIODeviceCallback* call)
  191065. {
  191066. if (isOpen_ && call != 0 && ! isStarted)
  191067. {
  191068. if (! isThreadRunning())
  191069. {
  191070. // something gone wrong and the thread's stopped..
  191071. isOpen_ = false;
  191072. return;
  191073. }
  191074. call->audioDeviceAboutToStart (this);
  191075. const ScopedLock sl (startStopLock);
  191076. callback = call;
  191077. isStarted = true;
  191078. }
  191079. }
  191080. void stop()
  191081. {
  191082. if (isStarted)
  191083. {
  191084. AudioIODeviceCallback* const callbackLocal = callback;
  191085. {
  191086. const ScopedLock sl (startStopLock);
  191087. isStarted = false;
  191088. }
  191089. if (callbackLocal != 0)
  191090. callbackLocal->audioDeviceStopped();
  191091. }
  191092. }
  191093. bool isPlaying()
  191094. {
  191095. return isStarted && isOpen_ && isThreadRunning();
  191096. }
  191097. const String getLastError()
  191098. {
  191099. return lastError;
  191100. }
  191101. juce_UseDebuggingNewOperator
  191102. StringArray inChannels, outChannels;
  191103. int outputDeviceIndex, inputDeviceIndex;
  191104. private:
  191105. bool isOpen_;
  191106. bool isStarted;
  191107. String lastError;
  191108. OwnedArray <DSoundInternalInChannel> inChans;
  191109. OwnedArray <DSoundInternalOutChannel> outChans;
  191110. WaitableEvent startEvent;
  191111. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  191112. int volatile totalSamplesOut;
  191113. int64 volatile lastBlockTime;
  191114. double sampleRate;
  191115. BitArray enabledInputs, enabledOutputs;
  191116. HeapBlock <float*> inputBuffers, outputBuffers;
  191117. AudioIODeviceCallback* callback;
  191118. CriticalSection startStopLock;
  191119. DSoundAudioIODevice (const DSoundAudioIODevice&);
  191120. const DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  191121. const String openDevice (const BitArray& inputChannels,
  191122. const BitArray& outputChannels,
  191123. double sampleRate_,
  191124. int bufferSizeSamples_);
  191125. void closeDevice()
  191126. {
  191127. isStarted = false;
  191128. stopThread (5000);
  191129. inChans.clear();
  191130. outChans.clear();
  191131. int i;
  191132. for (i = 0; i < numInputBuffers; ++i)
  191133. juce_free (inputBuffers[i]);
  191134. inputBuffers.free();
  191135. numInputBuffers = 0;
  191136. for (i = 0; i < numOutputBuffers; ++i)
  191137. juce_free (outputBuffers[i]);
  191138. outputBuffers.free();
  191139. numOutputBuffers = 0;
  191140. }
  191141. void resync()
  191142. {
  191143. if (! threadShouldExit())
  191144. {
  191145. sleep (5);
  191146. int i;
  191147. for (i = 0; i < outChans.size(); ++i)
  191148. outChans.getUnchecked(i)->synchronisePosition();
  191149. for (i = 0; i < inChans.size(); ++i)
  191150. inChans.getUnchecked(i)->synchronisePosition();
  191151. }
  191152. }
  191153. public:
  191154. void run()
  191155. {
  191156. while (! threadShouldExit())
  191157. {
  191158. if (wait (100))
  191159. break;
  191160. }
  191161. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  191162. const int maxTimeMS = jmax (5, 3 * latencyMs);
  191163. while (! threadShouldExit())
  191164. {
  191165. int numToDo = 0;
  191166. uint32 startTime = Time::getMillisecondCounter();
  191167. int i;
  191168. for (i = inChans.size(); --i >= 0;)
  191169. {
  191170. inChans.getUnchecked(i)->doneFlag = false;
  191171. ++numToDo;
  191172. }
  191173. for (i = outChans.size(); --i >= 0;)
  191174. {
  191175. outChans.getUnchecked(i)->doneFlag = false;
  191176. ++numToDo;
  191177. }
  191178. if (numToDo > 0)
  191179. {
  191180. const int maxCount = 3;
  191181. int count = maxCount;
  191182. for (;;)
  191183. {
  191184. for (i = inChans.size(); --i >= 0;)
  191185. {
  191186. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  191187. if ((! in->doneFlag) && in->service())
  191188. {
  191189. in->doneFlag = true;
  191190. --numToDo;
  191191. }
  191192. }
  191193. for (i = outChans.size(); --i >= 0;)
  191194. {
  191195. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  191196. if ((! out->doneFlag) && out->service())
  191197. {
  191198. out->doneFlag = true;
  191199. --numToDo;
  191200. }
  191201. }
  191202. if (numToDo <= 0)
  191203. break;
  191204. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  191205. {
  191206. resync();
  191207. break;
  191208. }
  191209. if (--count <= 0)
  191210. {
  191211. Sleep (1);
  191212. count = maxCount;
  191213. }
  191214. if (threadShouldExit())
  191215. return;
  191216. }
  191217. }
  191218. else
  191219. {
  191220. sleep (1);
  191221. }
  191222. const ScopedLock sl (startStopLock);
  191223. if (isStarted)
  191224. {
  191225. JUCE_TRY
  191226. {
  191227. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191228. numInputBuffers,
  191229. outputBuffers,
  191230. numOutputBuffers,
  191231. bufferSizeSamples);
  191232. }
  191233. JUCE_CATCH_EXCEPTION
  191234. totalSamplesOut += bufferSizeSamples;
  191235. }
  191236. else
  191237. {
  191238. for (i = 0; i < numOutputBuffers; ++i)
  191239. if (outputBuffers[i] != 0)
  191240. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  191241. totalSamplesOut = 0;
  191242. sleep (1);
  191243. }
  191244. }
  191245. }
  191246. };
  191247. class DSoundAudioIODeviceType : public AudioIODeviceType
  191248. {
  191249. public:
  191250. DSoundAudioIODeviceType()
  191251. : AudioIODeviceType (T("DirectSound")),
  191252. hasScanned (false)
  191253. {
  191254. initialiseDSoundFunctions();
  191255. }
  191256. ~DSoundAudioIODeviceType()
  191257. {
  191258. }
  191259. void scanForDevices()
  191260. {
  191261. hasScanned = true;
  191262. outputDeviceNames.clear();
  191263. outputGuids.clear();
  191264. inputDeviceNames.clear();
  191265. inputGuids.clear();
  191266. if (dsDirectSoundEnumerateW != 0)
  191267. {
  191268. dsDirectSoundEnumerateW (outputEnumProcW, this);
  191269. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  191270. }
  191271. }
  191272. const StringArray getDeviceNames (const bool wantInputNames) const
  191273. {
  191274. jassert (hasScanned); // need to call scanForDevices() before doing this
  191275. return wantInputNames ? inputDeviceNames
  191276. : outputDeviceNames;
  191277. }
  191278. int getDefaultDeviceIndex (const bool /*forInput*/) const
  191279. {
  191280. jassert (hasScanned); // need to call scanForDevices() before doing this
  191281. return 0;
  191282. }
  191283. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  191284. {
  191285. jassert (hasScanned); // need to call scanForDevices() before doing this
  191286. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  191287. if (d == 0)
  191288. return -1;
  191289. return asInput ? d->inputDeviceIndex
  191290. : d->outputDeviceIndex;
  191291. }
  191292. bool hasSeparateInputsAndOutputs() const { return true; }
  191293. AudioIODevice* createDevice (const String& outputDeviceName,
  191294. const String& inputDeviceName)
  191295. {
  191296. jassert (hasScanned); // need to call scanForDevices() before doing this
  191297. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191298. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191299. if (outputIndex >= 0 || inputIndex >= 0)
  191300. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191301. : inputDeviceName,
  191302. outputIndex, inputIndex);
  191303. return 0;
  191304. }
  191305. juce_UseDebuggingNewOperator
  191306. StringArray outputDeviceNames;
  191307. OwnedArray <GUID> outputGuids;
  191308. StringArray inputDeviceNames;
  191309. OwnedArray <GUID> inputGuids;
  191310. private:
  191311. bool hasScanned;
  191312. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  191313. {
  191314. desc = desc.trim();
  191315. if (desc.isNotEmpty())
  191316. {
  191317. const String origDesc (desc);
  191318. int n = 2;
  191319. while (outputDeviceNames.contains (desc))
  191320. desc = origDesc + T(" (") + String (n++) + T(")");
  191321. outputDeviceNames.add (desc);
  191322. if (lpGUID != 0)
  191323. outputGuids.add (new GUID (*lpGUID));
  191324. else
  191325. outputGuids.add (0);
  191326. }
  191327. return TRUE;
  191328. }
  191329. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191330. {
  191331. return ((DSoundAudioIODeviceType*) object)
  191332. ->outputEnumProc (lpGUID, String (description));
  191333. }
  191334. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191335. {
  191336. return ((DSoundAudioIODeviceType*) object)
  191337. ->outputEnumProc (lpGUID, String (description));
  191338. }
  191339. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  191340. {
  191341. desc = desc.trim();
  191342. if (desc.isNotEmpty())
  191343. {
  191344. const String origDesc (desc);
  191345. int n = 2;
  191346. while (inputDeviceNames.contains (desc))
  191347. desc = origDesc + T(" (") + String (n++) + T(")");
  191348. inputDeviceNames.add (desc);
  191349. if (lpGUID != 0)
  191350. inputGuids.add (new GUID (*lpGUID));
  191351. else
  191352. inputGuids.add (0);
  191353. }
  191354. return TRUE;
  191355. }
  191356. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191357. {
  191358. return ((DSoundAudioIODeviceType*) object)
  191359. ->inputEnumProc (lpGUID, String (description));
  191360. }
  191361. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191362. {
  191363. return ((DSoundAudioIODeviceType*) object)
  191364. ->inputEnumProc (lpGUID, String (description));
  191365. }
  191366. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  191367. const DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  191368. };
  191369. const String DSoundAudioIODevice::openDevice (const BitArray& inputChannels,
  191370. const BitArray& outputChannels,
  191371. double sampleRate_,
  191372. int bufferSizeSamples_)
  191373. {
  191374. closeDevice();
  191375. totalSamplesOut = 0;
  191376. sampleRate = sampleRate_;
  191377. if (bufferSizeSamples_ <= 0)
  191378. bufferSizeSamples_ = 960; // use as a default size if none is set.
  191379. bufferSizeSamples = bufferSizeSamples_ & ~7;
  191380. DSoundAudioIODeviceType dlh;
  191381. dlh.scanForDevices();
  191382. enabledInputs = inputChannels;
  191383. enabledInputs.setRange (inChannels.size(),
  191384. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  191385. false);
  191386. numInputBuffers = enabledInputs.countNumberOfSetBits();
  191387. inputBuffers.calloc (numInputBuffers + 2);
  191388. int i, numIns = 0;
  191389. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  191390. {
  191391. float* left = 0;
  191392. float* right = 0;
  191393. if (enabledInputs[i])
  191394. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191395. if (enabledInputs[i + 1])
  191396. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191397. if (left != 0 || right != 0)
  191398. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  191399. dlh.inputGuids [inputDeviceIndex],
  191400. (int) sampleRate, bufferSizeSamples,
  191401. left, right));
  191402. }
  191403. enabledOutputs = outputChannels;
  191404. enabledOutputs.setRange (outChannels.size(),
  191405. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  191406. false);
  191407. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  191408. outputBuffers.calloc (numOutputBuffers + 2);
  191409. int numOuts = 0;
  191410. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  191411. {
  191412. float* left = 0;
  191413. float* right = 0;
  191414. if (enabledOutputs[i])
  191415. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191416. if (enabledOutputs[i + 1])
  191417. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191418. if (left != 0 || right != 0)
  191419. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  191420. dlh.outputGuids [outputDeviceIndex],
  191421. (int) sampleRate, bufferSizeSamples,
  191422. left, right));
  191423. }
  191424. String error;
  191425. // boost our priority while opening the devices to try to get better sync between them
  191426. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  191427. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  191428. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  191429. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  191430. for (i = 0; i < outChans.size(); ++i)
  191431. {
  191432. error = outChans[i]->open();
  191433. if (error.isNotEmpty())
  191434. {
  191435. error = T("Error opening ") + dlh.outputDeviceNames[i]
  191436. + T(": \"") + error + T("\"");
  191437. break;
  191438. }
  191439. }
  191440. if (error.isEmpty())
  191441. {
  191442. for (i = 0; i < inChans.size(); ++i)
  191443. {
  191444. error = inChans[i]->open();
  191445. if (error.isNotEmpty())
  191446. {
  191447. error = T("Error opening ") + dlh.inputDeviceNames[i]
  191448. + T(": \"") + error + T("\"");
  191449. break;
  191450. }
  191451. }
  191452. }
  191453. if (error.isEmpty())
  191454. {
  191455. totalSamplesOut = 0;
  191456. for (i = 0; i < outChans.size(); ++i)
  191457. outChans.getUnchecked(i)->synchronisePosition();
  191458. for (i = 0; i < inChans.size(); ++i)
  191459. inChans.getUnchecked(i)->synchronisePosition();
  191460. startThread (9);
  191461. sleep (10);
  191462. notify();
  191463. }
  191464. else
  191465. {
  191466. log (error);
  191467. }
  191468. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  191469. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  191470. return error;
  191471. }
  191472. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  191473. {
  191474. return new DSoundAudioIODeviceType();
  191475. }
  191476. #undef log
  191477. #endif
  191478. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  191479. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  191480. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191481. // compiled on its own).
  191482. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  191483. #if 1
  191484. const String getAudioErrorDesc (HRESULT hr)
  191485. {
  191486. const char* e = 0;
  191487. switch (hr)
  191488. {
  191489. case E_POINTER: e = "E_POINTER"; break;
  191490. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  191491. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  191492. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  191493. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  191494. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  191495. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  191496. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  191497. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  191498. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  191499. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  191500. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  191501. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  191502. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  191503. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  191504. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  191505. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  191506. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  191507. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  191508. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  191509. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  191510. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  191511. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  191512. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  191513. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  191514. default: return String::toHexString ((int) hr);
  191515. }
  191516. return e;
  191517. }
  191518. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  191519. #define OK(a) wasapi_checkResult(a)
  191520. static bool wasapi_checkResult (HRESULT hr)
  191521. {
  191522. logFailure (hr);
  191523. return SUCCEEDED (hr);
  191524. }
  191525. #else
  191526. #define logFailure(hr) {}
  191527. #define OK(a) SUCCEEDED(a)
  191528. #endif
  191529. static const String wasapi_getDeviceID (IMMDevice* const device)
  191530. {
  191531. String s;
  191532. WCHAR* deviceId = 0;
  191533. if (OK (device->GetId (&deviceId)))
  191534. {
  191535. s = String (deviceId);
  191536. CoTaskMemFree (deviceId);
  191537. }
  191538. return s;
  191539. }
  191540. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  191541. {
  191542. EDataFlow flow = eRender;
  191543. ComSmartPtr <IMMEndpoint> endPoint;
  191544. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  191545. (void) OK (endPoint->GetDataFlow (&flow));
  191546. return flow;
  191547. }
  191548. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  191549. {
  191550. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  191551. }
  191552. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  191553. {
  191554. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  191555. : sizeof (WAVEFORMATEX));
  191556. }
  191557. class WASAPIDeviceBase
  191558. {
  191559. public:
  191560. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191561. : device (device_),
  191562. sampleRate (0),
  191563. numChannels (0),
  191564. actualNumChannels (0),
  191565. defaultSampleRate (0),
  191566. minBufferSize (0),
  191567. defaultBufferSize (0),
  191568. latencySamples (0),
  191569. useExclusiveMode (useExclusiveMode_)
  191570. {
  191571. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  191572. ComSmartPtr <IAudioClient> tempClient (createClient());
  191573. if (tempClient == 0)
  191574. return;
  191575. REFERENCE_TIME defaultPeriod, minPeriod;
  191576. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  191577. return;
  191578. WAVEFORMATEX* mixFormat = 0;
  191579. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  191580. return;
  191581. WAVEFORMATEXTENSIBLE format;
  191582. wasapi_copyWavFormat (format, mixFormat);
  191583. CoTaskMemFree (mixFormat);
  191584. actualNumChannels = numChannels = format.Format.nChannels;
  191585. defaultSampleRate = format.Format.nSamplesPerSec;
  191586. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  191587. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  191588. FloatElementComparator<double> comparator;
  191589. rates.addSorted (comparator, defaultSampleRate);
  191590. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191591. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  191592. {
  191593. if (ratesToTest[i] == defaultSampleRate)
  191594. continue;
  191595. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191596. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191597. (WAVEFORMATEX*) &format, 0)))
  191598. if (! rates.contains (ratesToTest[i]))
  191599. rates.addSorted (comparator, ratesToTest[i]);
  191600. }
  191601. }
  191602. ~WASAPIDeviceBase()
  191603. {
  191604. device = 0;
  191605. CloseHandle (clientEvent);
  191606. }
  191607. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191608. bool openClient (const double newSampleRate, const BitArray& newChannels)
  191609. {
  191610. sampleRate = newSampleRate;
  191611. channels = newChannels;
  191612. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191613. numChannels = channels.getHighestBit() + 1;
  191614. if (numChannels == 0)
  191615. return true;
  191616. client = createClient();
  191617. if (client != 0
  191618. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191619. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191620. {
  191621. channelMaps.clear();
  191622. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191623. if (channels[i])
  191624. channelMaps.add (i);
  191625. REFERENCE_TIME latency;
  191626. if (OK (client->GetStreamLatency (&latency)))
  191627. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191628. (void) OK (client->GetBufferSize (&actualBufferSize));
  191629. return OK (client->SetEventHandle (clientEvent));
  191630. }
  191631. return false;
  191632. }
  191633. void closeClient()
  191634. {
  191635. if (client != 0)
  191636. client->Stop();
  191637. client = 0;
  191638. ResetEvent (clientEvent);
  191639. }
  191640. ComSmartPtr <IMMDevice> device;
  191641. ComSmartPtr <IAudioClient> client;
  191642. double sampleRate, defaultSampleRate;
  191643. int numChannels, actualNumChannels;
  191644. int minBufferSize, defaultBufferSize, latencySamples;
  191645. const bool useExclusiveMode;
  191646. Array <double> rates;
  191647. HANDLE clientEvent;
  191648. BitArray channels;
  191649. AudioDataConverters::DataFormat dataFormat;
  191650. Array <int> channelMaps;
  191651. UINT32 actualBufferSize;
  191652. int bytesPerSample;
  191653. private:
  191654. const ComSmartPtr <IAudioClient> createClient()
  191655. {
  191656. ComSmartPtr <IAudioClient> client;
  191657. if (device != 0)
  191658. {
  191659. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191660. logFailure (hr);
  191661. }
  191662. return client;
  191663. }
  191664. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191665. {
  191666. WAVEFORMATEXTENSIBLE format;
  191667. zerostruct (format);
  191668. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191669. {
  191670. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191671. }
  191672. else
  191673. {
  191674. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191675. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191676. }
  191677. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191678. format.Format.nChannels = (WORD) numChannels;
  191679. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191680. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191681. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191682. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191683. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191684. switch (numChannels)
  191685. {
  191686. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191687. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191688. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191689. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191690. 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;
  191691. default: break;
  191692. }
  191693. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191694. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191695. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191696. logFailure (hr);
  191697. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191698. {
  191699. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191700. hr = S_OK;
  191701. }
  191702. CoTaskMemFree (nearestFormat);
  191703. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191704. if (useExclusiveMode)
  191705. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191706. GUID session;
  191707. if (hr == S_OK
  191708. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191709. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191710. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191711. {
  191712. actualNumChannels = format.Format.nChannels;
  191713. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191714. bytesPerSample = format.Format.wBitsPerSample / 8;
  191715. dataFormat = isFloat ? AudioDataConverters::float32LE
  191716. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191717. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191718. : AudioDataConverters::int16LE)));
  191719. return true;
  191720. }
  191721. return false;
  191722. }
  191723. };
  191724. class WASAPIInputDevice : public WASAPIDeviceBase
  191725. {
  191726. public:
  191727. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191728. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191729. reservoir (1, 1)
  191730. {
  191731. }
  191732. ~WASAPIInputDevice()
  191733. {
  191734. close();
  191735. }
  191736. bool open (const double newSampleRate, const BitArray& newChannels)
  191737. {
  191738. reservoirSize = 0;
  191739. reservoirCapacity = 16384;
  191740. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191741. return openClient (newSampleRate, newChannels)
  191742. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191743. }
  191744. void close()
  191745. {
  191746. closeClient();
  191747. captureClient = 0;
  191748. reservoir.setSize (0);
  191749. }
  191750. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191751. {
  191752. if (numChannels <= 0)
  191753. return;
  191754. int offset = 0;
  191755. while (bufferSize > 0)
  191756. {
  191757. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191758. {
  191759. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191760. for (int i = 0; i < numDestBuffers; ++i)
  191761. {
  191762. float* const dest = destBuffers[i] + offset;
  191763. const int srcChan = channelMaps.getUnchecked(i);
  191764. switch (dataFormat)
  191765. {
  191766. case AudioDataConverters::float32LE:
  191767. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191768. break;
  191769. case AudioDataConverters::int32LE:
  191770. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191771. break;
  191772. case AudioDataConverters::int24LE:
  191773. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191774. break;
  191775. case AudioDataConverters::int16LE:
  191776. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191777. break;
  191778. default: jassertfalse; break;
  191779. }
  191780. }
  191781. bufferSize -= samplesToDo;
  191782. offset += samplesToDo;
  191783. reservoirSize -= samplesToDo;
  191784. }
  191785. else
  191786. {
  191787. UINT32 packetLength = 0;
  191788. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191789. break;
  191790. if (packetLength == 0)
  191791. {
  191792. if (thread.threadShouldExit())
  191793. break;
  191794. Thread::sleep (1);
  191795. continue;
  191796. }
  191797. uint8* inputData = 0;
  191798. UINT32 numSamplesAvailable;
  191799. DWORD flags;
  191800. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191801. {
  191802. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191803. for (int i = 0; i < numDestBuffers; ++i)
  191804. {
  191805. float* const dest = destBuffers[i] + offset;
  191806. const int srcChan = channelMaps.getUnchecked(i);
  191807. switch (dataFormat)
  191808. {
  191809. case AudioDataConverters::float32LE:
  191810. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191811. break;
  191812. case AudioDataConverters::int32LE:
  191813. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191814. break;
  191815. case AudioDataConverters::int24LE:
  191816. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191817. break;
  191818. case AudioDataConverters::int16LE:
  191819. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191820. break;
  191821. default: jassertfalse; break;
  191822. }
  191823. }
  191824. bufferSize -= samplesToDo;
  191825. offset += samplesToDo;
  191826. if (samplesToDo < (int) numSamplesAvailable)
  191827. {
  191828. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191829. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191830. bytesPerSample * actualNumChannels * reservoirSize);
  191831. }
  191832. captureClient->ReleaseBuffer (numSamplesAvailable);
  191833. }
  191834. }
  191835. }
  191836. }
  191837. ComSmartPtr <IAudioCaptureClient> captureClient;
  191838. MemoryBlock reservoir;
  191839. int reservoirSize, reservoirCapacity;
  191840. };
  191841. class WASAPIOutputDevice : public WASAPIDeviceBase
  191842. {
  191843. public:
  191844. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191845. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191846. {
  191847. }
  191848. ~WASAPIOutputDevice()
  191849. {
  191850. close();
  191851. }
  191852. bool open (const double newSampleRate, const BitArray& newChannels)
  191853. {
  191854. return openClient (newSampleRate, newChannels)
  191855. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191856. }
  191857. void close()
  191858. {
  191859. closeClient();
  191860. renderClient = 0;
  191861. }
  191862. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191863. {
  191864. if (numChannels <= 0)
  191865. return;
  191866. int offset = 0;
  191867. while (bufferSize > 0)
  191868. {
  191869. UINT32 padding = 0;
  191870. if (! OK (client->GetCurrentPadding (&padding)))
  191871. return;
  191872. int samplesToDo = useExclusiveMode ? bufferSize
  191873. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191874. if (samplesToDo <= 0)
  191875. {
  191876. if (thread.threadShouldExit())
  191877. break;
  191878. Thread::sleep (0);
  191879. continue;
  191880. }
  191881. uint8* outputData = 0;
  191882. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191883. {
  191884. for (int i = 0; i < numSrcBuffers; ++i)
  191885. {
  191886. const float* const source = srcBuffers[i] + offset;
  191887. const int destChan = channelMaps.getUnchecked(i);
  191888. switch (dataFormat)
  191889. {
  191890. case AudioDataConverters::float32LE:
  191891. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191892. break;
  191893. case AudioDataConverters::int32LE:
  191894. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191895. break;
  191896. case AudioDataConverters::int24LE:
  191897. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191898. break;
  191899. case AudioDataConverters::int16LE:
  191900. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191901. break;
  191902. default: jassertfalse; break;
  191903. }
  191904. }
  191905. renderClient->ReleaseBuffer (samplesToDo, 0);
  191906. offset += samplesToDo;
  191907. bufferSize -= samplesToDo;
  191908. }
  191909. }
  191910. }
  191911. ComSmartPtr <IAudioRenderClient> renderClient;
  191912. };
  191913. class WASAPIAudioIODevice : public AudioIODevice,
  191914. public Thread
  191915. {
  191916. public:
  191917. WASAPIAudioIODevice (const String& deviceName,
  191918. const String& outputDeviceId_,
  191919. const String& inputDeviceId_,
  191920. const bool useExclusiveMode_)
  191921. : AudioIODevice (deviceName, "Windows Audio"),
  191922. Thread ("Juce WASAPI"),
  191923. isOpen_ (false),
  191924. isStarted (false),
  191925. outputDevice (0),
  191926. outputDeviceId (outputDeviceId_),
  191927. inputDevice (0),
  191928. inputDeviceId (inputDeviceId_),
  191929. useExclusiveMode (useExclusiveMode_),
  191930. currentBufferSizeSamples (0),
  191931. currentSampleRate (0),
  191932. callback (0)
  191933. {
  191934. }
  191935. ~WASAPIAudioIODevice()
  191936. {
  191937. close();
  191938. deleteAndZero (inputDevice);
  191939. deleteAndZero (outputDevice);
  191940. }
  191941. bool initialise()
  191942. {
  191943. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191944. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191945. latencyIn = latencyOut = 0;
  191946. Array <double> ratesIn, ratesOut;
  191947. if (createDevices())
  191948. {
  191949. jassert (inputDevice != 0 || outputDevice != 0);
  191950. if (inputDevice != 0 && outputDevice != 0)
  191951. {
  191952. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191953. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191954. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191955. sampleRates = inputDevice->rates;
  191956. sampleRates.removeValuesNotIn (outputDevice->rates);
  191957. }
  191958. else
  191959. {
  191960. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191961. defaultSampleRate = d->defaultSampleRate;
  191962. minBufferSize = d->minBufferSize;
  191963. defaultBufferSize = d->defaultBufferSize;
  191964. sampleRates = d->rates;
  191965. }
  191966. IntegerElementComparator<int> comparator;
  191967. bufferSizes.addSorted (comparator, defaultBufferSize);
  191968. if (minBufferSize != defaultBufferSize)
  191969. bufferSizes.addSorted (comparator, minBufferSize);
  191970. int n = 64;
  191971. for (int i = 0; i < 40; ++i)
  191972. {
  191973. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191974. bufferSizes.addSorted (comparator, n);
  191975. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191976. }
  191977. return true;
  191978. }
  191979. return false;
  191980. }
  191981. const StringArray getOutputChannelNames()
  191982. {
  191983. StringArray outChannels;
  191984. if (outputDevice != 0)
  191985. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191986. outChannels.add ("Output channel " + String (i));
  191987. return outChannels;
  191988. }
  191989. const StringArray getInputChannelNames()
  191990. {
  191991. StringArray inChannels;
  191992. if (inputDevice != 0)
  191993. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191994. inChannels.add ("Input channel " + String (i));
  191995. return inChannels;
  191996. }
  191997. int getNumSampleRates() { return sampleRates.size(); }
  191998. double getSampleRate (int index) { return sampleRates [index]; }
  191999. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  192000. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  192001. int getDefaultBufferSize() { return defaultBufferSize; }
  192002. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  192003. double getCurrentSampleRate() { return currentSampleRate; }
  192004. int getCurrentBitDepth() { return 32; }
  192005. int getOutputLatencyInSamples() { return latencyOut; }
  192006. int getInputLatencyInSamples() { return latencyIn; }
  192007. const BitArray getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BitArray(); }
  192008. const BitArray getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BitArray(); }
  192009. const String getLastError() { return lastError; }
  192010. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  192011. double sampleRate, int bufferSizeSamples)
  192012. {
  192013. close();
  192014. lastError = String::empty;
  192015. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  192016. {
  192017. lastError = "The input and output devices don't share a common sample rate!";
  192018. return lastError;
  192019. }
  192020. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  192021. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  192022. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  192023. {
  192024. lastError = "Couldn't open the input device!";
  192025. return lastError;
  192026. }
  192027. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  192028. {
  192029. close();
  192030. lastError = "Couldn't open the output device!";
  192031. return lastError;
  192032. }
  192033. if (inputDevice != 0)
  192034. ResetEvent (inputDevice->clientEvent);
  192035. if (outputDevice != 0)
  192036. ResetEvent (outputDevice->clientEvent);
  192037. startThread (8);
  192038. Thread::sleep (5);
  192039. if (inputDevice != 0 && inputDevice->client != 0)
  192040. {
  192041. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  192042. HRESULT hr = inputDevice->client->Start();
  192043. logFailure (hr); //xxx handle this
  192044. }
  192045. if (outputDevice != 0 && outputDevice->client != 0)
  192046. {
  192047. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  192048. HRESULT hr = outputDevice->client->Start();
  192049. logFailure (hr); //xxx handle this
  192050. }
  192051. isOpen_ = true;
  192052. return lastError;
  192053. }
  192054. void close()
  192055. {
  192056. stop();
  192057. if (inputDevice != 0)
  192058. SetEvent (inputDevice->clientEvent);
  192059. if (outputDevice != 0)
  192060. SetEvent (outputDevice->clientEvent);
  192061. stopThread (5000);
  192062. if (inputDevice != 0)
  192063. inputDevice->close();
  192064. if (outputDevice != 0)
  192065. outputDevice->close();
  192066. isOpen_ = false;
  192067. }
  192068. bool isOpen() { return isOpen_ && isThreadRunning(); }
  192069. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  192070. void start (AudioIODeviceCallback* call)
  192071. {
  192072. if (isOpen_ && call != 0 && ! isStarted)
  192073. {
  192074. if (! isThreadRunning())
  192075. {
  192076. // something's gone wrong and the thread's stopped..
  192077. isOpen_ = false;
  192078. return;
  192079. }
  192080. call->audioDeviceAboutToStart (this);
  192081. const ScopedLock sl (startStopLock);
  192082. callback = call;
  192083. isStarted = true;
  192084. }
  192085. }
  192086. void stop()
  192087. {
  192088. if (isStarted)
  192089. {
  192090. AudioIODeviceCallback* const callbackLocal = callback;
  192091. {
  192092. const ScopedLock sl (startStopLock);
  192093. isStarted = false;
  192094. }
  192095. if (callbackLocal != 0)
  192096. callbackLocal->audioDeviceStopped();
  192097. }
  192098. }
  192099. void setMMThreadPriority()
  192100. {
  192101. DynamicLibraryLoader dll ("avrt.dll");
  192102. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  192103. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  192104. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  192105. {
  192106. DWORD dummy = 0;
  192107. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  192108. if (h != 0)
  192109. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  192110. }
  192111. }
  192112. void run()
  192113. {
  192114. setMMThreadPriority();
  192115. const int bufferSize = currentBufferSizeSamples;
  192116. HANDLE events[2];
  192117. int numEvents = 0;
  192118. if (inputDevice != 0)
  192119. events [numEvents++] = inputDevice->clientEvent;
  192120. if (outputDevice != 0)
  192121. events [numEvents++] = outputDevice->clientEvent;
  192122. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  192123. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  192124. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  192125. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  192126. float** const inputBuffers = ins.getArrayOfChannels();
  192127. float** const outputBuffers = outs.getArrayOfChannels();
  192128. ins.clear();
  192129. while (! threadShouldExit())
  192130. {
  192131. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  192132. : WaitForMultipleObjects (numEvents, events, true, 1000);
  192133. if (result == WAIT_TIMEOUT)
  192134. continue;
  192135. if (threadShouldExit())
  192136. break;
  192137. if (inputDevice != 0)
  192138. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  192139. // Make the callback..
  192140. {
  192141. const ScopedLock sl (startStopLock);
  192142. if (isStarted)
  192143. {
  192144. JUCE_TRY
  192145. {
  192146. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  192147. numInputBuffers,
  192148. outputBuffers,
  192149. numOutputBuffers,
  192150. bufferSize);
  192151. }
  192152. JUCE_CATCH_EXCEPTION
  192153. }
  192154. else
  192155. {
  192156. outs.clear();
  192157. }
  192158. }
  192159. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  192160. continue;
  192161. if (outputDevice != 0)
  192162. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  192163. }
  192164. }
  192165. juce_UseDebuggingNewOperator
  192166. String outputDeviceId, inputDeviceId;
  192167. String lastError;
  192168. private:
  192169. // Device stats...
  192170. WASAPIInputDevice* inputDevice;
  192171. WASAPIOutputDevice* outputDevice;
  192172. const bool useExclusiveMode;
  192173. double defaultSampleRate;
  192174. int minBufferSize, defaultBufferSize;
  192175. int latencyIn, latencyOut;
  192176. Array <double> sampleRates;
  192177. Array <int> bufferSizes;
  192178. // Active state...
  192179. bool isOpen_, isStarted;
  192180. int currentBufferSizeSamples;
  192181. double currentSampleRate;
  192182. AudioIODeviceCallback* callback;
  192183. CriticalSection startStopLock;
  192184. bool createDevices()
  192185. {
  192186. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192187. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192188. return false;
  192189. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192190. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  192191. return false;
  192192. UINT32 numDevices = 0;
  192193. if (! OK (deviceCollection->GetCount (&numDevices)))
  192194. return false;
  192195. for (UINT32 i = 0; i < numDevices; ++i)
  192196. {
  192197. ComSmartPtr <IMMDevice> device;
  192198. if (! OK (deviceCollection->Item (i, &device)))
  192199. continue;
  192200. const String deviceId (wasapi_getDeviceID (device));
  192201. if (deviceId.isEmpty())
  192202. continue;
  192203. const EDataFlow flow = wasapi_getDataFlow (device);
  192204. if (deviceId == inputDeviceId && flow == eCapture)
  192205. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  192206. else if (deviceId == outputDeviceId && flow == eRender)
  192207. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  192208. }
  192209. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  192210. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  192211. }
  192212. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  192213. const WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  192214. };
  192215. class WASAPIAudioIODeviceType : public AudioIODeviceType
  192216. {
  192217. public:
  192218. WASAPIAudioIODeviceType()
  192219. : AudioIODeviceType (T("Windows Audio")),
  192220. hasScanned (false)
  192221. {
  192222. }
  192223. ~WASAPIAudioIODeviceType()
  192224. {
  192225. }
  192226. void scanForDevices()
  192227. {
  192228. hasScanned = true;
  192229. outputDeviceNames.clear();
  192230. inputDeviceNames.clear();
  192231. outputDeviceIds.clear();
  192232. inputDeviceIds.clear();
  192233. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192234. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192235. return;
  192236. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  192237. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  192238. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192239. UINT32 numDevices = 0;
  192240. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  192241. && OK (deviceCollection->GetCount (&numDevices))))
  192242. return;
  192243. for (UINT32 i = 0; i < numDevices; ++i)
  192244. {
  192245. ComSmartPtr <IMMDevice> device;
  192246. if (! OK (deviceCollection->Item (i, &device)))
  192247. continue;
  192248. const String deviceId (wasapi_getDeviceID (device));
  192249. DWORD state = 0;
  192250. if (! OK (device->GetState (&state)))
  192251. continue;
  192252. if (state != DEVICE_STATE_ACTIVE)
  192253. continue;
  192254. String name;
  192255. {
  192256. ComSmartPtr <IPropertyStore> properties;
  192257. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  192258. continue;
  192259. PROPVARIANT value;
  192260. PropVariantInit (&value);
  192261. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  192262. name = value.pwszVal;
  192263. PropVariantClear (&value);
  192264. }
  192265. const EDataFlow flow = wasapi_getDataFlow (device);
  192266. if (flow == eRender)
  192267. {
  192268. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  192269. outputDeviceIds.insert (index, deviceId);
  192270. outputDeviceNames.insert (index, name);
  192271. }
  192272. else if (flow == eCapture)
  192273. {
  192274. const int index = (deviceId == defaultCapture) ? 0 : -1;
  192275. inputDeviceIds.insert (index, deviceId);
  192276. inputDeviceNames.insert (index, name);
  192277. }
  192278. }
  192279. inputDeviceNames.appendNumbersToDuplicates (false, false);
  192280. outputDeviceNames.appendNumbersToDuplicates (false, false);
  192281. }
  192282. const StringArray getDeviceNames (const bool wantInputNames) const
  192283. {
  192284. jassert (hasScanned); // need to call scanForDevices() before doing this
  192285. return wantInputNames ? inputDeviceNames
  192286. : outputDeviceNames;
  192287. }
  192288. int getDefaultDeviceIndex (const bool /*forInput*/) const
  192289. {
  192290. jassert (hasScanned); // need to call scanForDevices() before doing this
  192291. return 0;
  192292. }
  192293. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  192294. {
  192295. jassert (hasScanned); // need to call scanForDevices() before doing this
  192296. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  192297. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  192298. : outputDeviceIds.indexOf (d->outputDeviceId));
  192299. }
  192300. bool hasSeparateInputsAndOutputs() const { return true; }
  192301. AudioIODevice* createDevice (const String& outputDeviceName,
  192302. const String& inputDeviceName)
  192303. {
  192304. jassert (hasScanned); // need to call scanForDevices() before doing this
  192305. const bool useExclusiveMode = false;
  192306. WASAPIAudioIODevice* d = 0;
  192307. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  192308. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  192309. if (outputIndex >= 0 || inputIndex >= 0)
  192310. {
  192311. d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  192312. : inputDeviceName,
  192313. outputDeviceIds [outputIndex],
  192314. inputDeviceIds [inputIndex],
  192315. useExclusiveMode);
  192316. if (! d->initialise())
  192317. deleteAndZero (d);
  192318. }
  192319. return d;
  192320. }
  192321. juce_UseDebuggingNewOperator
  192322. StringArray outputDeviceNames, outputDeviceIds;
  192323. StringArray inputDeviceNames, inputDeviceIds;
  192324. private:
  192325. bool hasScanned;
  192326. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  192327. {
  192328. String s;
  192329. IMMDevice* dev = 0;
  192330. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  192331. eMultimedia, &dev)))
  192332. {
  192333. WCHAR* deviceId = 0;
  192334. if (OK (dev->GetId (&deviceId)))
  192335. {
  192336. s = String (deviceId);
  192337. CoTaskMemFree (deviceId);
  192338. }
  192339. dev->Release();
  192340. }
  192341. return s;
  192342. }
  192343. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  192344. const WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  192345. };
  192346. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  192347. {
  192348. return new WASAPIAudioIODeviceType();
  192349. }
  192350. #undef logFailure
  192351. #undef OK
  192352. #endif
  192353. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  192354. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  192355. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  192356. // compiled on its own).
  192357. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  192358. class DShowCameraDeviceInteral : public ChangeBroadcaster
  192359. {
  192360. public:
  192361. DShowCameraDeviceInteral (CameraDevice* const owner_,
  192362. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  192363. const ComSmartPtr <IBaseFilter>& filter_,
  192364. int minWidth, int minHeight,
  192365. int maxWidth, int maxHeight)
  192366. : owner (owner_),
  192367. captureGraphBuilder (captureGraphBuilder_),
  192368. filter (filter_),
  192369. ok (false),
  192370. imageNeedsFlipping (false),
  192371. width (0),
  192372. height (0),
  192373. activeUsers (0),
  192374. recordNextFrameTime (false),
  192375. activeImage (0),
  192376. loadingImage (0)
  192377. {
  192378. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  192379. if (FAILED (hr))
  192380. return;
  192381. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  192382. if (FAILED (hr))
  192383. return;
  192384. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  192385. if (FAILED (hr))
  192386. return;
  192387. {
  192388. ComSmartPtr <IAMStreamConfig> streamConfig;
  192389. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE,
  192390. 0,
  192391. filter,
  192392. IID_IAMStreamConfig,
  192393. (void**) &streamConfig);
  192394. if (streamConfig != 0)
  192395. {
  192396. getVideoSizes (streamConfig);
  192397. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  192398. return;
  192399. }
  192400. }
  192401. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  192402. if (FAILED (hr))
  192403. return;
  192404. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  192405. if (FAILED (hr))
  192406. return;
  192407. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  192408. if (FAILED (hr))
  192409. return;
  192410. if (! connectFilters (filter, smartTee))
  192411. return;
  192412. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  192413. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  192414. if (FAILED (hr))
  192415. return;
  192416. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  192417. if (FAILED (hr))
  192418. return;
  192419. AM_MEDIA_TYPE mt;
  192420. zerostruct (mt);
  192421. mt.majortype = MEDIATYPE_Video;
  192422. mt.subtype = MEDIASUBTYPE_RGB24;
  192423. mt.formattype = FORMAT_VideoInfo;
  192424. sampleGrabber->SetMediaType (&mt);
  192425. callback = new GrabberCallback (*this);
  192426. sampleGrabber->SetCallback (callback, 1);
  192427. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  192428. if (FAILED (hr))
  192429. return;
  192430. ComSmartPtr <IPin> grabberInputPin;
  192431. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  192432. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  192433. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  192434. return;
  192435. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  192436. if (FAILED (hr))
  192437. return;
  192438. zerostruct (mt);
  192439. hr = sampleGrabber->GetConnectedMediaType (&mt);
  192440. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  192441. width = pVih->bmiHeader.biWidth;
  192442. height = pVih->bmiHeader.biHeight;
  192443. ComSmartPtr <IBaseFilter> nullFilter;
  192444. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  192445. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  192446. if (connectFilters (sampleGrabberBase, nullFilter)
  192447. && addGraphToRot())
  192448. {
  192449. activeImage = new Image (Image::RGB, width, height, true);
  192450. loadingImage = new Image (Image::RGB, width, height, true);
  192451. ok = true;
  192452. }
  192453. }
  192454. ~DShowCameraDeviceInteral()
  192455. {
  192456. if (mediaControl != 0)
  192457. mediaControl->Stop();
  192458. removeGraphFromRot();
  192459. for (int i = viewerComps.size(); --i >= 0;)
  192460. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  192461. callback = 0;
  192462. graphBuilder = 0;
  192463. sampleGrabber = 0;
  192464. mediaControl = 0;
  192465. filter = 0;
  192466. captureGraphBuilder = 0;
  192467. smartTee = 0;
  192468. smartTeePreviewOutputPin = 0;
  192469. smartTeeCaptureOutputPin = 0;
  192470. mux = 0;
  192471. fileWriter = 0;
  192472. delete activeImage;
  192473. delete loadingImage;
  192474. }
  192475. void addUser()
  192476. {
  192477. if (ok && activeUsers++ == 0)
  192478. mediaControl->Run();
  192479. }
  192480. void removeUser()
  192481. {
  192482. if (ok && --activeUsers == 0)
  192483. mediaControl->Stop();
  192484. }
  192485. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  192486. {
  192487. if (recordNextFrameTime)
  192488. {
  192489. const double defaultCameraLatency = 0.1;
  192490. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  192491. recordNextFrameTime = false;
  192492. ComSmartPtr <IPin> pin;
  192493. if (getPin (filter, PINDIR_OUTPUT, &pin))
  192494. {
  192495. ComSmartPtr <IAMPushSource> pushSource;
  192496. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  192497. if (pushSource != 0)
  192498. {
  192499. REFERENCE_TIME latency = 0;
  192500. hr = pushSource->GetLatency (&latency);
  192501. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  192502. }
  192503. }
  192504. }
  192505. imageSwapLock.enter();
  192506. const int lineStride = width * 3;
  192507. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  192508. for (int i = 0; i < height; ++i)
  192509. memcpy (destData.getLinePointer ((height - 1) - i),
  192510. buffer + lineStride * i,
  192511. lineStride);
  192512. imageNeedsFlipping = true;
  192513. imageSwapLock.exit();
  192514. callListeners (*loadingImage);
  192515. sendChangeMessage (this);
  192516. }
  192517. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  192518. {
  192519. if (imageNeedsFlipping)
  192520. {
  192521. imageSwapLock.enter();
  192522. swapVariables (loadingImage, activeImage);
  192523. imageNeedsFlipping = false;
  192524. imageSwapLock.exit();
  192525. }
  192526. RectanglePlacement rp (RectanglePlacement::centred);
  192527. double dx = 0, dy = 0, dw = width, dh = height;
  192528. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  192529. const int rx = roundToInt (dx), ry = roundToInt (dy);
  192530. const int rw = roundToInt (dw), rh = roundToInt (dh);
  192531. g.saveState();
  192532. g.excludeClipRegion (rx, ry, rw, rh);
  192533. g.fillAll (Colours::black);
  192534. g.restoreState();
  192535. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  192536. }
  192537. bool createFileCaptureFilter (const File& file)
  192538. {
  192539. removeFileCaptureFilter();
  192540. file.deleteFile();
  192541. mediaControl->Stop();
  192542. firstRecordedTime = Time();
  192543. recordNextFrameTime = true;
  192544. HRESULT hr = mux.CoCreateInstance (CLSID_AviDest, CLSCTX_INPROC_SERVER);
  192545. if (SUCCEEDED (hr))
  192546. {
  192547. hr = graphBuilder->AddFilter (mux, _T("AVI Mux"));
  192548. if (SUCCEEDED (hr))
  192549. {
  192550. fileWriter.CoCreateInstance (CLSID_FileWriter, CLSCTX_INPROC_SERVER);
  192551. if (SUCCEEDED (hr))
  192552. {
  192553. ComSmartPtr <IFileSinkFilter> fileSink;
  192554. hr = fileWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  192555. if (SUCCEEDED (hr))
  192556. {
  192557. AM_MEDIA_TYPE mt;
  192558. zerostruct (mt);
  192559. mt.majortype = MEDIATYPE_Stream;
  192560. mt.subtype = MEDIASUBTYPE_Avi;
  192561. mt.formattype = FORMAT_VideoInfo;
  192562. hr = fileSink->SetFileName (file.getFullPathName(), &mt);
  192563. if (SUCCEEDED (hr))
  192564. {
  192565. hr = graphBuilder->AddFilter (fileWriter, _T("File Writer"));
  192566. if (SUCCEEDED (hr))
  192567. {
  192568. ComSmartPtr <IPin> muxInputPin, muxOutputPin, writerInput;
  192569. if (getPin (mux, PINDIR_INPUT, &muxInputPin)
  192570. && getPin (mux, PINDIR_OUTPUT, &muxOutputPin)
  192571. && getPin (fileWriter, PINDIR_INPUT, &writerInput))
  192572. {
  192573. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, muxInputPin);
  192574. if (SUCCEEDED (hr))
  192575. {
  192576. hr = graphBuilder->Connect (muxOutputPin, writerInput);
  192577. if (SUCCEEDED (hr))
  192578. {
  192579. if (ok && activeUsers > 0)
  192580. mediaControl->Run();
  192581. return true;
  192582. }
  192583. }
  192584. }
  192585. }
  192586. }
  192587. }
  192588. }
  192589. }
  192590. }
  192591. removeFileCaptureFilter();
  192592. if (ok && activeUsers > 0)
  192593. mediaControl->Run();
  192594. return false;
  192595. }
  192596. void removeFileCaptureFilter()
  192597. {
  192598. mediaControl->Stop();
  192599. if (mux != 0)
  192600. {
  192601. graphBuilder->RemoveFilter (mux);
  192602. mux = 0;
  192603. }
  192604. if (fileWriter != 0)
  192605. {
  192606. graphBuilder->RemoveFilter (fileWriter);
  192607. fileWriter = 0;
  192608. }
  192609. if (ok && activeUsers > 0)
  192610. mediaControl->Run();
  192611. }
  192612. void addListener (CameraImageListener* listenerToAdd)
  192613. {
  192614. const ScopedLock sl (listenerLock);
  192615. if (listeners.size() == 0)
  192616. addUser();
  192617. listeners.addIfNotAlreadyThere (listenerToAdd);
  192618. }
  192619. void removeListener (CameraImageListener* listenerToRemove)
  192620. {
  192621. const ScopedLock sl (listenerLock);
  192622. listeners.removeValue (listenerToRemove);
  192623. if (listeners.size() == 0)
  192624. removeUser();
  192625. }
  192626. void callListeners (Image& image)
  192627. {
  192628. const ScopedLock sl (listenerLock);
  192629. for (int i = listeners.size(); --i >= 0;)
  192630. {
  192631. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192632. if (l != 0)
  192633. l->imageReceived (image);
  192634. }
  192635. }
  192636. class DShowCaptureViewerComp : public Component,
  192637. public ChangeListener
  192638. {
  192639. public:
  192640. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192641. : owner (owner_)
  192642. {
  192643. setOpaque (true);
  192644. owner->addChangeListener (this);
  192645. owner->addUser();
  192646. owner->viewerComps.add (this);
  192647. setSize (owner_->width, owner_->height);
  192648. }
  192649. ~DShowCaptureViewerComp()
  192650. {
  192651. if (owner != 0)
  192652. {
  192653. owner->viewerComps.removeValue (this);
  192654. owner->removeUser();
  192655. owner->removeChangeListener (this);
  192656. }
  192657. }
  192658. void ownerDeleted()
  192659. {
  192660. owner = 0;
  192661. }
  192662. void paint (Graphics& g)
  192663. {
  192664. g.setColour (Colours::black);
  192665. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192666. if (owner != 0)
  192667. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192668. else
  192669. g.fillAll (Colours::black);
  192670. }
  192671. void changeListenerCallback (void*)
  192672. {
  192673. repaint();
  192674. }
  192675. private:
  192676. DShowCameraDeviceInteral* owner;
  192677. };
  192678. bool ok;
  192679. int width, height;
  192680. Time firstRecordedTime;
  192681. VoidArray viewerComps;
  192682. private:
  192683. CameraDevice* const owner;
  192684. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192685. ComSmartPtr <IBaseFilter> filter;
  192686. ComSmartPtr <IBaseFilter> smartTee;
  192687. ComSmartPtr <IGraphBuilder> graphBuilder;
  192688. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192689. ComSmartPtr <IMediaControl> mediaControl;
  192690. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192691. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192692. ComSmartPtr <IBaseFilter> mux, fileWriter;
  192693. int activeUsers;
  192694. Array <int> widths, heights;
  192695. DWORD graphRegistrationID;
  192696. CriticalSection imageSwapLock;
  192697. bool imageNeedsFlipping;
  192698. Image* loadingImage;
  192699. Image* activeImage;
  192700. bool recordNextFrameTime;
  192701. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192702. {
  192703. widths.clear();
  192704. heights.clear();
  192705. int count = 0, size = 0;
  192706. streamConfig->GetNumberOfCapabilities (&count, &size);
  192707. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192708. {
  192709. for (int i = 0; i < count; ++i)
  192710. {
  192711. VIDEO_STREAM_CONFIG_CAPS scc;
  192712. AM_MEDIA_TYPE* config;
  192713. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192714. if (SUCCEEDED (hr))
  192715. {
  192716. const int w = scc.InputSize.cx;
  192717. const int h = scc.InputSize.cy;
  192718. bool duplicate = false;
  192719. for (int j = widths.size(); --j >= 0;)
  192720. {
  192721. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192722. {
  192723. duplicate = true;
  192724. break;
  192725. }
  192726. }
  192727. if (! duplicate)
  192728. {
  192729. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192730. widths.add (w);
  192731. heights.add (h);
  192732. }
  192733. deleteMediaType (config);
  192734. }
  192735. }
  192736. }
  192737. }
  192738. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192739. const int minWidth, const int minHeight,
  192740. const int maxWidth, const int maxHeight)
  192741. {
  192742. int count = 0, size = 0;
  192743. streamConfig->GetNumberOfCapabilities (&count, &size);
  192744. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192745. {
  192746. for (int i = 0; i < count; ++i)
  192747. {
  192748. VIDEO_STREAM_CONFIG_CAPS scc;
  192749. AM_MEDIA_TYPE* config;
  192750. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192751. if (SUCCEEDED (hr))
  192752. {
  192753. if (scc.InputSize.cx >= minWidth
  192754. && scc.InputSize.cy >= minHeight
  192755. && scc.InputSize.cx <= maxWidth
  192756. && scc.InputSize.cy <= maxHeight)
  192757. {
  192758. hr = streamConfig->SetFormat (config);
  192759. deleteMediaType (config);
  192760. return SUCCEEDED (hr);
  192761. }
  192762. deleteMediaType (config);
  192763. }
  192764. }
  192765. }
  192766. return false;
  192767. }
  192768. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192769. {
  192770. ComSmartPtr <IEnumPins> enumerator;
  192771. ComSmartPtr <IPin> pin;
  192772. filter->EnumPins (&enumerator);
  192773. while (enumerator->Next (1, &pin, 0) == S_OK)
  192774. {
  192775. PIN_DIRECTION dir;
  192776. pin->QueryDirection (&dir);
  192777. if (wantedDirection == dir)
  192778. {
  192779. PIN_INFO info;
  192780. zerostruct (info);
  192781. pin->QueryPinInfo (&info);
  192782. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192783. {
  192784. pin.p->AddRef();
  192785. *result = pin;
  192786. return true;
  192787. }
  192788. }
  192789. }
  192790. return false;
  192791. }
  192792. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192793. {
  192794. ComSmartPtr <IPin> in, out;
  192795. return getPin (first, PINDIR_OUTPUT, &out)
  192796. && getPin (second, PINDIR_INPUT, &in)
  192797. && SUCCEEDED (graphBuilder->Connect (out, in));
  192798. }
  192799. bool addGraphToRot()
  192800. {
  192801. ComSmartPtr <IRunningObjectTable> rot;
  192802. if (FAILED (GetRunningObjectTable (0, &rot)))
  192803. return false;
  192804. ComSmartPtr <IMoniker> moniker;
  192805. WCHAR buffer[128];
  192806. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192807. if (FAILED (hr))
  192808. return false;
  192809. graphRegistrationID = 0;
  192810. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192811. }
  192812. void removeGraphFromRot()
  192813. {
  192814. ComSmartPtr <IRunningObjectTable> rot;
  192815. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192816. rot->Revoke (graphRegistrationID);
  192817. }
  192818. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192819. {
  192820. if (pmt->cbFormat != 0)
  192821. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192822. if (pmt->pUnk != 0)
  192823. pmt->pUnk->Release();
  192824. CoTaskMemFree (pmt);
  192825. }
  192826. class GrabberCallback : public ISampleGrabberCB
  192827. {
  192828. public:
  192829. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192830. : owner (owner_)
  192831. {
  192832. }
  192833. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192834. {
  192835. if (id == IID_IUnknown)
  192836. *result = dynamic_cast <IUnknown*> (this);
  192837. else if (id == IID_ISampleGrabberCB)
  192838. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192839. else
  192840. {
  192841. *result = 0;
  192842. return E_NOINTERFACE;
  192843. }
  192844. AddRef();
  192845. return S_OK;
  192846. }
  192847. ULONG __stdcall AddRef() { return ++refCount; }
  192848. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192849. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192850. {
  192851. return E_FAIL;
  192852. }
  192853. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192854. {
  192855. owner.handleFrame (time, buffer, bufferSize);
  192856. return S_OK;
  192857. }
  192858. private:
  192859. int refCount;
  192860. DShowCameraDeviceInteral& owner;
  192861. GrabberCallback (const GrabberCallback&);
  192862. const GrabberCallback& operator= (const GrabberCallback&);
  192863. };
  192864. ComSmartPtr <GrabberCallback> callback;
  192865. VoidArray listeners;
  192866. CriticalSection listenerLock;
  192867. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192868. const DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192869. };
  192870. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192871. : name (name_)
  192872. {
  192873. isRecording = false;
  192874. }
  192875. CameraDevice::~CameraDevice()
  192876. {
  192877. stopRecording();
  192878. delete (DShowCameraDeviceInteral*) internal;
  192879. internal = 0;
  192880. }
  192881. Component* CameraDevice::createViewerComponent()
  192882. {
  192883. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192884. }
  192885. const String CameraDevice::getFileExtension()
  192886. {
  192887. return ".avi";
  192888. }
  192889. void CameraDevice::startRecordingToFile (const File& file)
  192890. {
  192891. stopRecording();
  192892. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192893. d->addUser();
  192894. isRecording = d->createFileCaptureFilter (file);
  192895. }
  192896. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192897. {
  192898. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192899. return d->firstRecordedTime;
  192900. }
  192901. void CameraDevice::stopRecording()
  192902. {
  192903. if (isRecording)
  192904. {
  192905. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192906. d->removeFileCaptureFilter();
  192907. d->removeUser();
  192908. isRecording = false;
  192909. }
  192910. }
  192911. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192912. {
  192913. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192914. if (listenerToAdd != 0)
  192915. d->addListener (listenerToAdd);
  192916. }
  192917. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192918. {
  192919. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192920. if (listenerToRemove != 0)
  192921. d->removeListener (listenerToRemove);
  192922. }
  192923. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192924. const int deviceIndexToOpen,
  192925. String& name)
  192926. {
  192927. int index = 0;
  192928. ComSmartPtr <IBaseFilter> result;
  192929. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192930. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192931. if (SUCCEEDED (hr))
  192932. {
  192933. ComSmartPtr <IEnumMoniker> enumerator;
  192934. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192935. if (SUCCEEDED (hr) && enumerator != 0)
  192936. {
  192937. ComSmartPtr <IBaseFilter> captureFilter;
  192938. ComSmartPtr <IMoniker> moniker;
  192939. ULONG fetched;
  192940. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192941. {
  192942. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192943. if (SUCCEEDED (hr))
  192944. {
  192945. ComSmartPtr <IPropertyBag> propertyBag;
  192946. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192947. if (SUCCEEDED (hr))
  192948. {
  192949. VARIANT var;
  192950. var.vt = VT_BSTR;
  192951. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192952. propertyBag = 0;
  192953. if (SUCCEEDED (hr))
  192954. {
  192955. if (names != 0)
  192956. names->add (var.bstrVal);
  192957. if (index == deviceIndexToOpen)
  192958. {
  192959. name = var.bstrVal;
  192960. result = captureFilter;
  192961. captureFilter = 0;
  192962. break;
  192963. }
  192964. ++index;
  192965. }
  192966. moniker = 0;
  192967. }
  192968. captureFilter = 0;
  192969. }
  192970. }
  192971. }
  192972. }
  192973. return result;
  192974. }
  192975. const StringArray CameraDevice::getAvailableDevices()
  192976. {
  192977. StringArray devs;
  192978. String dummy;
  192979. enumerateCameras (&devs, -1, dummy);
  192980. return devs;
  192981. }
  192982. CameraDevice* CameraDevice::openDevice (int index,
  192983. int minWidth, int minHeight,
  192984. int maxWidth, int maxHeight)
  192985. {
  192986. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192987. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192988. if (SUCCEEDED (hr))
  192989. {
  192990. String name;
  192991. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192992. if (filter != 0)
  192993. {
  192994. CameraDevice* const cam = new CameraDevice (name, index);
  192995. DShowCameraDeviceInteral* const intern
  192996. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192997. minWidth, minHeight, maxWidth, maxHeight);
  192998. cam->internal = intern;
  192999. if (intern->ok)
  193000. return cam;
  193001. else
  193002. delete cam;
  193003. }
  193004. }
  193005. return 0;
  193006. }
  193007. #endif
  193008. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  193009. #endif
  193010. // Auto-link the other win32 libs that are needed by library calls..
  193011. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  193012. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  193013. // Auto-links to various win32 libs that are needed by library calls..
  193014. #pragma comment(lib, "kernel32.lib")
  193015. #pragma comment(lib, "user32.lib")
  193016. #pragma comment(lib, "shell32.lib")
  193017. #pragma comment(lib, "gdi32.lib")
  193018. #pragma comment(lib, "vfw32.lib")
  193019. #pragma comment(lib, "comdlg32.lib")
  193020. #pragma comment(lib, "winmm.lib")
  193021. #pragma comment(lib, "wininet.lib")
  193022. #pragma comment(lib, "ole32.lib")
  193023. #pragma comment(lib, "oleaut32.lib")
  193024. #pragma comment(lib, "advapi32.lib")
  193025. #pragma comment(lib, "ws2_32.lib")
  193026. #pragma comment(lib, "comsupp.lib")
  193027. #pragma comment(lib, "version.lib")
  193028. #if JUCE_OPENGL
  193029. #pragma comment(lib, "OpenGL32.Lib")
  193030. #pragma comment(lib, "GlU32.Lib")
  193031. #endif
  193032. #if JUCE_QUICKTIME
  193033. #pragma comment (lib, "QTMLClient.lib")
  193034. #endif
  193035. #if JUCE_USE_CAMERA
  193036. #pragma comment (lib, "Strmiids.lib")
  193037. #endif
  193038. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  193039. #endif
  193040. END_JUCE_NAMESPACE
  193041. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  193042. #endif
  193043. #if JUCE_LINUX
  193044. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  193045. BEGIN_JUCE_NAMESPACE
  193046. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  193047. #define SUPPORT_AFFINITIES 1
  193048. #endif
  193049. #define JUCE_INCLUDED_FILE 1
  193050. // Now include the actual code files..
  193051. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  193052. CriticalSection::CriticalSection() throw()
  193053. {
  193054. pthread_mutexattr_t atts;
  193055. pthread_mutexattr_init (&atts);
  193056. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  193057. pthread_mutex_init (&internal, &atts);
  193058. }
  193059. CriticalSection::~CriticalSection() throw()
  193060. {
  193061. pthread_mutex_destroy (&internal);
  193062. }
  193063. void CriticalSection::enter() const throw()
  193064. {
  193065. pthread_mutex_lock (&internal);
  193066. }
  193067. bool CriticalSection::tryEnter() const throw()
  193068. {
  193069. return pthread_mutex_trylock (&internal) == 0;
  193070. }
  193071. void CriticalSection::exit() const throw()
  193072. {
  193073. pthread_mutex_unlock (&internal);
  193074. }
  193075. struct EventStruct
  193076. {
  193077. pthread_cond_t condition;
  193078. pthread_mutex_t mutex;
  193079. bool triggered;
  193080. };
  193081. WaitableEvent::WaitableEvent() throw()
  193082. {
  193083. EventStruct* const es = new EventStruct();
  193084. es->triggered = false;
  193085. pthread_cond_init (&es->condition, 0);
  193086. pthread_mutex_init (&es->mutex, 0);
  193087. internal = es;
  193088. }
  193089. WaitableEvent::~WaitableEvent() throw()
  193090. {
  193091. EventStruct* const es = (EventStruct*) internal;
  193092. pthread_cond_destroy (&es->condition);
  193093. pthread_mutex_destroy (&es->mutex);
  193094. delete es;
  193095. }
  193096. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  193097. {
  193098. EventStruct* const es = (EventStruct*) internal;
  193099. pthread_mutex_lock (&es->mutex);
  193100. if (timeOutMillisecs < 0)
  193101. {
  193102. while (! es->triggered)
  193103. pthread_cond_wait (&es->condition, &es->mutex);
  193104. }
  193105. else
  193106. {
  193107. while (! es->triggered)
  193108. {
  193109. struct timeval t;
  193110. gettimeofday (&t, 0);
  193111. struct timespec time;
  193112. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  193113. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  193114. if (time.tv_nsec >= 1000000000)
  193115. {
  193116. time.tv_nsec -= 1000000000;
  193117. time.tv_sec++;
  193118. }
  193119. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  193120. {
  193121. pthread_mutex_unlock (&es->mutex);
  193122. return false;
  193123. }
  193124. }
  193125. }
  193126. es->triggered = false;
  193127. pthread_mutex_unlock (&es->mutex);
  193128. return true;
  193129. }
  193130. void WaitableEvent::signal() const throw()
  193131. {
  193132. EventStruct* const es = (EventStruct*) internal;
  193133. pthread_mutex_lock (&es->mutex);
  193134. es->triggered = true;
  193135. pthread_cond_broadcast (&es->condition);
  193136. pthread_mutex_unlock (&es->mutex);
  193137. }
  193138. void WaitableEvent::reset() const throw()
  193139. {
  193140. EventStruct* const es = (EventStruct*) internal;
  193141. pthread_mutex_lock (&es->mutex);
  193142. es->triggered = false;
  193143. pthread_mutex_unlock (&es->mutex);
  193144. }
  193145. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  193146. {
  193147. struct timespec time;
  193148. time.tv_sec = millisecs / 1000;
  193149. time.tv_nsec = (millisecs % 1000) * 1000000;
  193150. nanosleep (&time, 0);
  193151. }
  193152. const tchar File::separator = T('/');
  193153. const tchar* File::separatorString = T("/");
  193154. bool juce_copyFile (const String& s, const String& d);
  193155. static bool juce_stat (const String& fileName, struct stat& info)
  193156. {
  193157. return fileName.isNotEmpty()
  193158. && (stat (fileName.toUTF8(), &info) == 0);
  193159. }
  193160. bool juce_isDirectory (const String& fileName)
  193161. {
  193162. struct stat info;
  193163. return fileName.isEmpty()
  193164. || (juce_stat (fileName, info)
  193165. && ((info.st_mode & S_IFDIR) != 0));
  193166. }
  193167. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  193168. {
  193169. if (fileName.isEmpty())
  193170. return false;
  193171. const char* const fileNameUTF8 = fileName.toUTF8();
  193172. bool exists = access (fileNameUTF8, F_OK) == 0;
  193173. if (exists && dontCountDirectories)
  193174. {
  193175. struct stat info;
  193176. const int res = stat (fileNameUTF8, &info);
  193177. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  193178. exists = false;
  193179. }
  193180. return exists;
  193181. }
  193182. int64 juce_getFileSize (const String& fileName)
  193183. {
  193184. struct stat info;
  193185. return juce_stat (fileName, info) ? info.st_size : 0;
  193186. }
  193187. bool juce_canWriteToFile (const String& fileName)
  193188. {
  193189. return access (fileName.toUTF8(), W_OK) == 0;
  193190. }
  193191. bool juce_deleteFile (const String& fileName)
  193192. {
  193193. if (juce_isDirectory (fileName))
  193194. return rmdir ((const char*) fileName.toUTF8()) == 0;
  193195. else
  193196. return remove ((const char*) fileName.toUTF8()) == 0;
  193197. }
  193198. bool juce_moveFile (const String& source, const String& dest)
  193199. {
  193200. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  193201. return true;
  193202. if (juce_canWriteToFile (source)
  193203. && juce_copyFile (source, dest))
  193204. {
  193205. if (juce_deleteFile (source))
  193206. return true;
  193207. juce_deleteFile (dest);
  193208. }
  193209. return false;
  193210. }
  193211. void juce_createDirectory (const String& fileName)
  193212. {
  193213. mkdir (fileName.toUTF8(), 0777);
  193214. }
  193215. void* juce_fileOpen (const String& fileName, bool forWriting)
  193216. {
  193217. int flags = O_RDONLY;
  193218. if (forWriting)
  193219. {
  193220. if (juce_fileExists (fileName, false))
  193221. {
  193222. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  193223. if (f != -1)
  193224. lseek (f, 0, SEEK_END);
  193225. return (void*) f;
  193226. }
  193227. else
  193228. {
  193229. flags = O_RDWR + O_CREAT;
  193230. }
  193231. }
  193232. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  193233. }
  193234. void juce_fileClose (void* handle)
  193235. {
  193236. if (handle != 0)
  193237. close ((int) (pointer_sized_int) handle);
  193238. }
  193239. int juce_fileRead (void* handle, void* buffer, int size)
  193240. {
  193241. if (handle != 0)
  193242. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  193243. return 0;
  193244. }
  193245. int juce_fileWrite (void* handle, const void* buffer, int size)
  193246. {
  193247. if (handle != 0)
  193248. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  193249. return 0;
  193250. }
  193251. int64 juce_fileSetPosition (void* handle, int64 pos)
  193252. {
  193253. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  193254. return pos;
  193255. return -1;
  193256. }
  193257. int64 juce_fileGetPosition (void* handle)
  193258. {
  193259. if (handle != 0)
  193260. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  193261. else
  193262. return -1;
  193263. }
  193264. void juce_fileFlush (void* handle)
  193265. {
  193266. if (handle != 0)
  193267. fsync ((int) (pointer_sized_int) handle);
  193268. }
  193269. const File juce_getExecutableFile()
  193270. {
  193271. Dl_info exeInfo;
  193272. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  193273. return File (exeInfo.dli_fname);
  193274. }
  193275. // if this file doesn't exist, find a parent of it that does..
  193276. static bool doStatFS (const File* file, struct statfs& result)
  193277. {
  193278. File f (*file);
  193279. for (int i = 5; --i >= 0;)
  193280. {
  193281. if (f.exists())
  193282. break;
  193283. f = f.getParentDirectory();
  193284. }
  193285. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  193286. }
  193287. int64 File::getBytesFreeOnVolume() const
  193288. {
  193289. struct statfs buf;
  193290. if (doStatFS (this, buf))
  193291. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  193292. return 0;
  193293. }
  193294. int64 File::getVolumeTotalSize() const
  193295. {
  193296. struct statfs buf;
  193297. if (doStatFS (this, buf))
  193298. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  193299. return 0;
  193300. }
  193301. const String juce_getVolumeLabel (const String& filenameOnVolume,
  193302. int& volumeSerialNumber)
  193303. {
  193304. volumeSerialNumber = 0;
  193305. #if JUCE_MAC
  193306. struct VolAttrBuf
  193307. {
  193308. u_int32_t length;
  193309. attrreference_t mountPointRef;
  193310. char mountPointSpace [MAXPATHLEN];
  193311. } attrBuf;
  193312. struct attrlist attrList;
  193313. zerostruct (attrList);
  193314. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  193315. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  193316. File f (filenameOnVolume);
  193317. for (;;)
  193318. {
  193319. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  193320. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  193321. {
  193322. return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  193323. (int) attrBuf.mountPointRef.attr_length);
  193324. }
  193325. const File parent (f.getParentDirectory());
  193326. if (f == parent)
  193327. break;
  193328. f = parent;
  193329. }
  193330. #endif
  193331. return String::empty;
  193332. }
  193333. void juce_runSystemCommand (const String& command)
  193334. {
  193335. int result = system ((const char*) command.toUTF8());
  193336. (void) result;
  193337. }
  193338. const String juce_getOutputFromCommand (const String& command)
  193339. {
  193340. // slight bodge here, as we just pipe the output into a temp file and read it...
  193341. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  193342. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  193343. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  193344. String result (tempFile.loadFileAsString());
  193345. tempFile.deleteFile();
  193346. return result;
  193347. }
  193348. InterProcessLock::InterProcessLock (const String& name_)
  193349. : internal (0),
  193350. name (name_),
  193351. reentrancyLevel (0)
  193352. {
  193353. #if JUCE_MAC
  193354. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  193355. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  193356. #else
  193357. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  193358. #endif
  193359. temp.create();
  193360. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  193361. }
  193362. InterProcessLock::~InterProcessLock()
  193363. {
  193364. while (reentrancyLevel > 0)
  193365. this->exit();
  193366. close (internal);
  193367. }
  193368. bool InterProcessLock::enter (const int timeOutMillisecs)
  193369. {
  193370. if (internal == 0)
  193371. return false;
  193372. if (reentrancyLevel != 0)
  193373. return true;
  193374. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  193375. struct flock fl;
  193376. zerostruct (fl);
  193377. fl.l_whence = SEEK_SET;
  193378. fl.l_type = F_WRLCK;
  193379. for (;;)
  193380. {
  193381. const int result = fcntl (internal, F_SETLK, &fl);
  193382. if (result >= 0)
  193383. {
  193384. ++reentrancyLevel;
  193385. return true;
  193386. }
  193387. if (errno != EINTR)
  193388. {
  193389. if (timeOutMillisecs == 0
  193390. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  193391. break;
  193392. Thread::sleep (10);
  193393. }
  193394. }
  193395. return false;
  193396. }
  193397. void InterProcessLock::exit()
  193398. {
  193399. if (reentrancyLevel > 0 && internal != 0)
  193400. {
  193401. --reentrancyLevel;
  193402. struct flock fl;
  193403. zerostruct (fl);
  193404. fl.l_whence = SEEK_SET;
  193405. fl.l_type = F_UNLCK;
  193406. for (;;)
  193407. {
  193408. const int result = fcntl (internal, F_SETLKW, &fl);
  193409. if (result >= 0 || errno != EINTR)
  193410. break;
  193411. }
  193412. }
  193413. }
  193414. /*** End of inlined file: juce_posix_SharedCode.h ***/
  193415. /*** Start of inlined file: juce_linux_Files.cpp ***/
  193416. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193417. // compiled on its own).
  193418. #if JUCE_INCLUDED_FILE
  193419. #define U_ISOFS_SUPER_MAGIC (short) 0x9660 // linux/iso_fs.h
  193420. #define U_MSDOS_SUPER_MAGIC (short) 0x4d44 // linux/msdos_fs.h
  193421. #define U_NFS_SUPER_MAGIC (short) 0x6969 // linux/nfs_fs.h
  193422. #define U_SMB_SUPER_MAGIC (short) 0x517B // linux/smb_fs.h
  193423. void juce_getFileTimes (const String& fileName,
  193424. int64& modificationTime,
  193425. int64& accessTime,
  193426. int64& creationTime)
  193427. {
  193428. modificationTime = 0;
  193429. accessTime = 0;
  193430. creationTime = 0;
  193431. struct stat info;
  193432. const int res = stat (fileName.toUTF8(), &info);
  193433. if (res == 0)
  193434. {
  193435. modificationTime = (int64) info.st_mtime * 1000;
  193436. accessTime = (int64) info.st_atime * 1000;
  193437. creationTime = (int64) info.st_ctime * 1000;
  193438. }
  193439. }
  193440. bool juce_setFileTimes (const String& fileName,
  193441. int64 modificationTime,
  193442. int64 accessTime,
  193443. int64 creationTime)
  193444. {
  193445. struct utimbuf times;
  193446. times.actime = (time_t) (accessTime / 1000);
  193447. times.modtime = (time_t) (modificationTime / 1000);
  193448. return utime (fileName.toUTF8(), &times) == 0;
  193449. }
  193450. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  193451. {
  193452. struct stat info;
  193453. const int res = stat (fileName.toUTF8(), &info);
  193454. if (res != 0)
  193455. return false;
  193456. info.st_mode &= 0777; // Just permissions
  193457. if( isReadOnly )
  193458. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  193459. else
  193460. // Give everybody write permission?
  193461. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  193462. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  193463. }
  193464. bool juce_copyFile (const String& s, const String& d)
  193465. {
  193466. const File source (s), dest (d);
  193467. FileInputStream* in = source.createInputStream();
  193468. bool ok = false;
  193469. if (in != 0)
  193470. {
  193471. if (dest.deleteFile())
  193472. {
  193473. FileOutputStream* const out = dest.createOutputStream();
  193474. if (out != 0)
  193475. {
  193476. const int bytesCopied = out->writeFromInputStream (*in, -1);
  193477. delete out;
  193478. ok = (bytesCopied == source.getSize());
  193479. if (! ok)
  193480. dest.deleteFile();
  193481. }
  193482. }
  193483. delete in;
  193484. }
  193485. return ok;
  193486. }
  193487. const StringArray juce_getFileSystemRoots()
  193488. {
  193489. StringArray s;
  193490. s.add (T("/"));
  193491. return s;
  193492. }
  193493. bool File::isOnCDRomDrive() const
  193494. {
  193495. struct statfs buf;
  193496. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193497. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  193498. // Assume not if this fails for some reason
  193499. return false;
  193500. }
  193501. bool File::isOnHardDisk() const
  193502. {
  193503. struct statfs buf;
  193504. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193505. {
  193506. switch (buf.f_type)
  193507. {
  193508. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  193509. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  193510. case U_NFS_SUPER_MAGIC: // Network NFS
  193511. case U_SMB_SUPER_MAGIC: // Network Samba
  193512. return false;
  193513. default:
  193514. // Assume anything else is a hard-disk (but note it could
  193515. // be a RAM disk. There isn't a good way of determining
  193516. // this for sure)
  193517. return true;
  193518. }
  193519. }
  193520. // Assume so if this fails for some reason
  193521. return true;
  193522. }
  193523. bool File::isOnRemovableDrive() const
  193524. {
  193525. jassertfalse // xxx not implemented for linux!
  193526. return false;
  193527. }
  193528. bool File::isHidden() const
  193529. {
  193530. return getFileName().startsWithChar (T('.'));
  193531. }
  193532. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  193533. const File File::getSpecialLocation (const SpecialLocationType type)
  193534. {
  193535. switch (type)
  193536. {
  193537. case userHomeDirectory:
  193538. {
  193539. const char* homeDir = getenv ("HOME");
  193540. if (homeDir == 0)
  193541. {
  193542. struct passwd* const pw = getpwuid (getuid());
  193543. if (pw != 0)
  193544. homeDir = pw->pw_dir;
  193545. }
  193546. return File (String::fromUTF8 ((const uint8*) homeDir));
  193547. }
  193548. case userDocumentsDirectory:
  193549. case userMusicDirectory:
  193550. case userMoviesDirectory:
  193551. case userApplicationDataDirectory:
  193552. return File ("~");
  193553. case userDesktopDirectory:
  193554. return File ("~/Desktop");
  193555. case commonApplicationDataDirectory:
  193556. return File ("/var");
  193557. case globalApplicationsDirectory:
  193558. return File ("/usr");
  193559. case tempDirectory:
  193560. {
  193561. File tmp ("/var/tmp");
  193562. if (! tmp.isDirectory())
  193563. {
  193564. tmp = T("/tmp");
  193565. if (! tmp.isDirectory())
  193566. tmp = File::getCurrentWorkingDirectory();
  193567. }
  193568. return tmp;
  193569. }
  193570. case invokedExecutableFile:
  193571. if (juce_Argv0 != 0)
  193572. return File (String::fromUTF8 ((const uint8*) juce_Argv0));
  193573. // deliberate fall-through...
  193574. case currentExecutableFile:
  193575. case currentApplicationFile:
  193576. return juce_getExecutableFile();
  193577. default:
  193578. jassertfalse // unknown type?
  193579. break;
  193580. }
  193581. return File::nonexistent;
  193582. }
  193583. const File File::getCurrentWorkingDirectory()
  193584. {
  193585. char buf [2048];
  193586. return File (String::fromUTF8 ((const uint8*) getcwd (buf, sizeof (buf))));
  193587. }
  193588. bool File::setAsCurrentWorkingDirectory() const
  193589. {
  193590. return chdir (getFullPathName().toUTF8()) == 0;
  193591. }
  193592. const String File::getVersion() const
  193593. {
  193594. return String::empty; // xxx not yet implemented
  193595. }
  193596. const File File::getLinkedTarget() const
  193597. {
  193598. char buffer [4096];
  193599. size_t numChars = readlink ((const char*) getFullPathName().toUTF8(),
  193600. buffer, sizeof (buffer));
  193601. if (numChars > 0 && numChars <= sizeof (buffer))
  193602. return File (String::fromUTF8 ((const uint8*) buffer, (int) numChars));
  193603. return *this;
  193604. }
  193605. bool File::moveToTrash() const
  193606. {
  193607. if (! exists())
  193608. return true;
  193609. File trashCan (T("~/.Trash"));
  193610. if (! trashCan.isDirectory())
  193611. trashCan = T("~/.local/share/Trash/files");
  193612. if (! trashCan.isDirectory())
  193613. return false;
  193614. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193615. getFileExtension()));
  193616. }
  193617. struct FindFileStruct
  193618. {
  193619. String parentDir, wildCard;
  193620. DIR* dir;
  193621. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193622. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193623. {
  193624. const char* const wildcardUTF8 = wildCard.toUTF8();
  193625. for (;;)
  193626. {
  193627. struct dirent* const de = readdir (dir);
  193628. if (de == 0)
  193629. break;
  193630. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193631. {
  193632. result = String::fromUTF8 ((const uint8*) de->d_name);
  193633. const String path (parentDir + result);
  193634. if (isDir != 0 || fileSize != 0)
  193635. {
  193636. struct stat info;
  193637. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193638. if (isDir != 0)
  193639. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193640. if (isHidden != 0)
  193641. *isHidden = (de->d_name[0] == '.');
  193642. if (fileSize != 0)
  193643. *fileSize = statOk ? info.st_size : 0;
  193644. }
  193645. if (modTime != 0 || creationTime != 0)
  193646. {
  193647. int64 m, a, c;
  193648. juce_getFileTimes (path, m, a, c);
  193649. if (modTime != 0)
  193650. *modTime = m;
  193651. if (creationTime != 0)
  193652. *creationTime = c;
  193653. }
  193654. if (isReadOnly != 0)
  193655. *isReadOnly = ! juce_canWriteToFile (path);
  193656. return true;
  193657. }
  193658. }
  193659. return false;
  193660. }
  193661. };
  193662. // returns 0 on failure
  193663. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193664. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193665. Time* creationTime, bool* isReadOnly)
  193666. {
  193667. DIR* d = opendir (directory.toUTF8());
  193668. if (d != 0)
  193669. {
  193670. FindFileStruct* ff = new FindFileStruct();
  193671. ff->parentDir = directory;
  193672. if (!ff->parentDir.endsWithChar (File::separator))
  193673. ff->parentDir += File::separator;
  193674. ff->wildCard = wildCard;
  193675. if (wildCard == T("*.*"))
  193676. ff->wildCard = T("*");
  193677. ff->dir = d;
  193678. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193679. {
  193680. return ff;
  193681. }
  193682. else
  193683. {
  193684. firstResultFile = String::empty;
  193685. isDir = false;
  193686. isHidden = false;
  193687. closedir (d);
  193688. delete ff;
  193689. }
  193690. }
  193691. return 0;
  193692. }
  193693. bool juce_findFileNext (void* handle, String& resultFile,
  193694. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193695. {
  193696. FindFileStruct* const ff = (FindFileStruct*) handle;
  193697. if (ff != 0)
  193698. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193699. return false;
  193700. }
  193701. void juce_findFileClose (void* handle)
  193702. {
  193703. FindFileStruct* const ff = (FindFileStruct*) handle;
  193704. if (ff != 0)
  193705. {
  193706. closedir (ff->dir);
  193707. delete ff;
  193708. }
  193709. }
  193710. bool juce_launchFile (const String& fileName,
  193711. const String& parameters)
  193712. {
  193713. String cmdString (fileName.replace (T(" "), T("\\ "),false));
  193714. cmdString << " " << parameters;
  193715. if (URL::isProbablyAWebsiteURL (fileName)
  193716. || cmdString.startsWithIgnoreCase (T("file:"))
  193717. || URL::isProbablyAnEmailAddress (fileName))
  193718. {
  193719. // create a command that tries to launch a bunch of likely browsers
  193720. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193721. StringArray cmdLines;
  193722. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193723. cmdLines.add (String (browserNames[i]) + T(" ") + cmdString.trim().quoted());
  193724. cmdString = cmdLines.joinIntoString (T(" || "));
  193725. }
  193726. const char* const argv[4] = { "/bin/sh", "-c", (const char*) cmdString.toUTF8(), 0 };
  193727. const int cpid = fork();
  193728. if (cpid == 0)
  193729. {
  193730. setsid();
  193731. // Child process
  193732. execve (argv[0], (char**) argv, environ);
  193733. exit (0);
  193734. }
  193735. return cpid >= 0;
  193736. }
  193737. void File::revealToUser() const
  193738. {
  193739. if (isDirectory())
  193740. startAsProcess();
  193741. else if (getParentDirectory().exists())
  193742. getParentDirectory().startAsProcess();
  193743. }
  193744. #endif
  193745. /*** End of inlined file: juce_linux_Files.cpp ***/
  193746. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193747. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193748. // compiled on its own).
  193749. #if JUCE_INCLUDED_FILE
  193750. struct NamedPipeInternal
  193751. {
  193752. String pipeInName, pipeOutName;
  193753. int pipeIn, pipeOut;
  193754. bool volatile createdPipe, blocked, stopReadOperation;
  193755. static void signalHandler (int) {}
  193756. };
  193757. void NamedPipe::cancelPendingReads()
  193758. {
  193759. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193760. {
  193761. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193762. intern->stopReadOperation = true;
  193763. char buffer [1] = { 0 };
  193764. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193765. (void) bytesWritten;
  193766. int timeout = 2000;
  193767. while (intern->blocked && --timeout >= 0)
  193768. Thread::sleep (2);
  193769. intern->stopReadOperation = false;
  193770. }
  193771. }
  193772. void NamedPipe::close()
  193773. {
  193774. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193775. if (intern != 0)
  193776. {
  193777. internal = 0;
  193778. if (intern->pipeIn != -1)
  193779. ::close (intern->pipeIn);
  193780. if (intern->pipeOut != -1)
  193781. ::close (intern->pipeOut);
  193782. if (intern->createdPipe)
  193783. {
  193784. unlink (intern->pipeInName);
  193785. unlink (intern->pipeOutName);
  193786. }
  193787. delete intern;
  193788. }
  193789. }
  193790. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193791. {
  193792. close();
  193793. NamedPipeInternal* const intern = new NamedPipeInternal();
  193794. internal = intern;
  193795. intern->createdPipe = createPipe;
  193796. intern->blocked = false;
  193797. intern->stopReadOperation = false;
  193798. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193799. siginterrupt (SIGPIPE, 1);
  193800. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  193801. intern->pipeInName = pipePath + T("_in");
  193802. intern->pipeOutName = pipePath + T("_out");
  193803. intern->pipeIn = -1;
  193804. intern->pipeOut = -1;
  193805. if (createPipe)
  193806. {
  193807. if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST)
  193808. || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST))
  193809. {
  193810. delete intern;
  193811. internal = 0;
  193812. return false;
  193813. }
  193814. }
  193815. return true;
  193816. }
  193817. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193818. {
  193819. int bytesRead = -1;
  193820. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193821. if (intern != 0)
  193822. {
  193823. intern->blocked = true;
  193824. if (intern->pipeIn == -1)
  193825. {
  193826. if (intern->createdPipe)
  193827. intern->pipeIn = ::open (intern->pipeInName, O_RDWR);
  193828. else
  193829. intern->pipeIn = ::open (intern->pipeOutName, O_RDWR);
  193830. if (intern->pipeIn == -1)
  193831. {
  193832. intern->blocked = false;
  193833. return -1;
  193834. }
  193835. }
  193836. bytesRead = 0;
  193837. char* p = (char*) destBuffer;
  193838. while (bytesRead < maxBytesToRead)
  193839. {
  193840. const int bytesThisTime = maxBytesToRead - bytesRead;
  193841. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193842. if (numRead <= 0 || intern->stopReadOperation)
  193843. {
  193844. bytesRead = -1;
  193845. break;
  193846. }
  193847. bytesRead += numRead;
  193848. p += bytesRead;
  193849. }
  193850. intern->blocked = false;
  193851. }
  193852. return bytesRead;
  193853. }
  193854. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193855. {
  193856. int bytesWritten = -1;
  193857. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193858. if (intern != 0)
  193859. {
  193860. if (intern->pipeOut == -1)
  193861. {
  193862. if (intern->createdPipe)
  193863. intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY);
  193864. else
  193865. intern->pipeOut = ::open (intern->pipeInName, O_WRONLY);
  193866. if (intern->pipeOut == -1)
  193867. {
  193868. return -1;
  193869. }
  193870. }
  193871. const char* p = (const char*) sourceBuffer;
  193872. bytesWritten = 0;
  193873. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193874. while (bytesWritten < numBytesToWrite
  193875. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193876. {
  193877. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193878. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193879. if (numWritten <= 0)
  193880. {
  193881. bytesWritten = -1;
  193882. break;
  193883. }
  193884. bytesWritten += numWritten;
  193885. p += bytesWritten;
  193886. }
  193887. }
  193888. return bytesWritten;
  193889. }
  193890. #endif
  193891. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193892. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193893. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193894. // compiled on its own).
  193895. #if JUCE_INCLUDED_FILE
  193896. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  193897. {
  193898. int numResults = 0;
  193899. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193900. if (s != -1)
  193901. {
  193902. char buf [1024];
  193903. struct ifconf ifc;
  193904. ifc.ifc_len = sizeof (buf);
  193905. ifc.ifc_buf = buf;
  193906. ioctl (s, SIOCGIFCONF, &ifc);
  193907. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193908. {
  193909. struct ifreq ifr;
  193910. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193911. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193912. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193913. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193914. && numResults < maxNum)
  193915. {
  193916. int64 a = 0;
  193917. for (int j = 6; --j >= 0;)
  193918. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193919. *addresses++ = a;
  193920. ++numResults;
  193921. }
  193922. }
  193923. close (s);
  193924. }
  193925. return numResults;
  193926. }
  193927. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193928. const String& emailSubject,
  193929. const String& bodyText,
  193930. const StringArray& filesToAttach)
  193931. {
  193932. jassertfalse // xxx todo
  193933. return false;
  193934. }
  193935. class JUCE_HTTPSocketStream
  193936. {
  193937. public:
  193938. JUCE_HTTPSocketStream()
  193939. : readPosition (0),
  193940. socketHandle (-1),
  193941. levelsOfRedirection (0),
  193942. timeoutSeconds (15)
  193943. {
  193944. }
  193945. ~JUCE_HTTPSocketStream()
  193946. {
  193947. closeSocket();
  193948. }
  193949. bool open (const String& url,
  193950. const String& headers,
  193951. const MemoryBlock& postData,
  193952. const bool isPost,
  193953. URL::OpenStreamProgressCallback* callback,
  193954. void* callbackContext,
  193955. int timeOutMs)
  193956. {
  193957. closeSocket();
  193958. uint32 timeOutTime = Time::getMillisecondCounter();
  193959. if (timeOutMs == 0)
  193960. timeOutTime += 60000;
  193961. else if (timeOutMs < 0)
  193962. timeOutTime = 0xffffffff;
  193963. else
  193964. timeOutTime += timeOutMs;
  193965. String hostName, hostPath;
  193966. int hostPort;
  193967. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193968. return false;
  193969. const struct hostent* host = 0;
  193970. int port = 0;
  193971. String proxyName, proxyPath;
  193972. int proxyPort = 0;
  193973. String proxyURL (getenv ("http_proxy"));
  193974. if (proxyURL.startsWithIgnoreCase (T("http://")))
  193975. {
  193976. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193977. return false;
  193978. host = gethostbyname ((const char*) proxyName.toUTF8());
  193979. port = proxyPort;
  193980. }
  193981. else
  193982. {
  193983. host = gethostbyname ((const char*) hostName.toUTF8());
  193984. port = hostPort;
  193985. }
  193986. if (host == 0)
  193987. return false;
  193988. struct sockaddr_in address;
  193989. zerostruct (address);
  193990. memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
  193991. address.sin_family = host->h_addrtype;
  193992. address.sin_port = htons (port);
  193993. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193994. if (socketHandle == -1)
  193995. return false;
  193996. int receiveBufferSize = 16384;
  193997. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193998. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193999. #if JUCE_MAC
  194000. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  194001. #endif
  194002. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  194003. {
  194004. closeSocket();
  194005. return false;
  194006. }
  194007. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  194008. proxyName, proxyPort,
  194009. hostPath, url,
  194010. headers, postData,
  194011. isPost));
  194012. size_t totalHeaderSent = 0;
  194013. while (totalHeaderSent < requestHeader.getSize())
  194014. {
  194015. if (Time::getMillisecondCounter() > timeOutTime)
  194016. {
  194017. closeSocket();
  194018. return false;
  194019. }
  194020. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  194021. if (send (socketHandle,
  194022. ((const char*) requestHeader.getData()) + totalHeaderSent,
  194023. numToSend, 0)
  194024. != numToSend)
  194025. {
  194026. closeSocket();
  194027. return false;
  194028. }
  194029. totalHeaderSent += numToSend;
  194030. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  194031. {
  194032. closeSocket();
  194033. return false;
  194034. }
  194035. }
  194036. const String responseHeader (readResponse (timeOutTime));
  194037. if (responseHeader.isNotEmpty())
  194038. {
  194039. //DBG (responseHeader);
  194040. StringArray lines;
  194041. lines.addLines (responseHeader);
  194042. // NB - using charToString() here instead of just T(" "), because that was
  194043. // causing a mysterious gcc internal compiler error...
  194044. const int statusCode = responseHeader.fromFirstOccurrenceOf (String::charToString (T(' ')), false, false)
  194045. .substring (0, 3).getIntValue();
  194046. //int contentLength = findHeaderItem (lines, T("Content-Length:")).getIntValue();
  194047. //bool isChunked = findHeaderItem (lines, T("Transfer-Encoding:")).equalsIgnoreCase ("chunked");
  194048. String location (findHeaderItem (lines, T("Location:")));
  194049. if (statusCode >= 300 && statusCode < 400
  194050. && location.isNotEmpty())
  194051. {
  194052. if (! location.startsWithIgnoreCase (T("http://")))
  194053. location = T("http://") + location;
  194054. if (levelsOfRedirection++ < 3)
  194055. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  194056. }
  194057. else
  194058. {
  194059. levelsOfRedirection = 0;
  194060. return true;
  194061. }
  194062. }
  194063. closeSocket();
  194064. return false;
  194065. }
  194066. int read (void* buffer, int bytesToRead)
  194067. {
  194068. fd_set readbits;
  194069. FD_ZERO (&readbits);
  194070. FD_SET (socketHandle, &readbits);
  194071. struct timeval tv;
  194072. tv.tv_sec = timeoutSeconds;
  194073. tv.tv_usec = 0;
  194074. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  194075. return 0; // (timeout)
  194076. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  194077. readPosition += bytesRead;
  194078. return bytesRead;
  194079. }
  194080. int readPosition;
  194081. juce_UseDebuggingNewOperator
  194082. private:
  194083. int socketHandle, levelsOfRedirection;
  194084. const int timeoutSeconds;
  194085. void closeSocket()
  194086. {
  194087. if (socketHandle >= 0)
  194088. close (socketHandle);
  194089. socketHandle = -1;
  194090. }
  194091. const MemoryBlock createRequestHeader (const String& hostName,
  194092. const int hostPort,
  194093. const String& proxyName,
  194094. const int proxyPort,
  194095. const String& hostPath,
  194096. const String& originalURL,
  194097. const String& headers,
  194098. const MemoryBlock& postData,
  194099. const bool isPost)
  194100. {
  194101. String header (isPost ? "POST " : "GET ");
  194102. if (proxyName.isEmpty())
  194103. {
  194104. header << hostPath << " HTTP/1.0\r\nHost: "
  194105. << hostName << ':' << hostPort;
  194106. }
  194107. else
  194108. {
  194109. header << originalURL << " HTTP/1.0\r\nHost: "
  194110. << proxyName << ':' << proxyPort;
  194111. }
  194112. header << "\r\nUser-Agent: JUCE/"
  194113. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  194114. << "\r\nConnection: Close\r\nContent-Length: "
  194115. << postData.getSize() << "\r\n"
  194116. << headers << "\r\n";
  194117. MemoryBlock mb;
  194118. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  194119. mb.append (postData.getData(), postData.getSize());
  194120. return mb;
  194121. }
  194122. const String readResponse (const uint32 timeOutTime)
  194123. {
  194124. int bytesRead = 0, numConsecutiveLFs = 0;
  194125. MemoryBlock buffer (1024, true);
  194126. while (numConsecutiveLFs < 2 && bytesRead < 32768
  194127. && Time::getMillisecondCounter() <= timeOutTime)
  194128. {
  194129. fd_set readbits;
  194130. FD_ZERO (&readbits);
  194131. FD_SET (socketHandle, &readbits);
  194132. struct timeval tv;
  194133. tv.tv_sec = timeoutSeconds;
  194134. tv.tv_usec = 0;
  194135. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  194136. return String::empty; // (timeout)
  194137. buffer.ensureSize (bytesRead + 8, true);
  194138. char* const dest = (char*) buffer.getData() + bytesRead;
  194139. if (recv (socketHandle, dest, 1, 0) == -1)
  194140. return String::empty;
  194141. const char lastByte = *dest;
  194142. ++bytesRead;
  194143. if (lastByte == '\n')
  194144. ++numConsecutiveLFs;
  194145. else if (lastByte != '\r')
  194146. numConsecutiveLFs = 0;
  194147. }
  194148. const String header (String::fromUTF8 ((const uint8*) buffer.getData()));
  194149. if (header.startsWithIgnoreCase (T("HTTP/")))
  194150. return header.trimEnd();
  194151. return String::empty;
  194152. }
  194153. static bool decomposeURL (const String& url,
  194154. String& host, String& path, int& port)
  194155. {
  194156. if (! url.startsWithIgnoreCase (T("http://")))
  194157. return false;
  194158. const int nextSlash = url.indexOfChar (7, '/');
  194159. int nextColon = url.indexOfChar (7, ':');
  194160. if (nextColon > nextSlash && nextSlash > 0)
  194161. nextColon = -1;
  194162. if (nextColon >= 0)
  194163. {
  194164. host = url.substring (7, nextColon);
  194165. if (nextSlash >= 0)
  194166. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  194167. else
  194168. port = url.substring (nextColon + 1).getIntValue();
  194169. }
  194170. else
  194171. {
  194172. port = 80;
  194173. if (nextSlash >= 0)
  194174. host = url.substring (7, nextSlash);
  194175. else
  194176. host = url.substring (7);
  194177. }
  194178. if (nextSlash >= 0)
  194179. path = url.substring (nextSlash);
  194180. else
  194181. path = T("/");
  194182. return true;
  194183. }
  194184. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  194185. {
  194186. for (int i = 0; i < lines.size(); ++i)
  194187. if (lines[i].startsWithIgnoreCase (itemName))
  194188. return lines[i].substring (itemName.length()).trim();
  194189. return String::empty;
  194190. }
  194191. };
  194192. bool juce_isOnLine()
  194193. {
  194194. return true;
  194195. }
  194196. void* juce_openInternetFile (const String& url,
  194197. const String& headers,
  194198. const MemoryBlock& postData,
  194199. const bool isPost,
  194200. URL::OpenStreamProgressCallback* callback,
  194201. void* callbackContext,
  194202. int timeOutMs)
  194203. {
  194204. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  194205. if (s->open (url, headers, postData, isPost,
  194206. callback, callbackContext, timeOutMs))
  194207. return s;
  194208. delete s;
  194209. return 0;
  194210. }
  194211. void juce_closeInternetFile (void* handle)
  194212. {
  194213. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194214. if (s != 0)
  194215. delete s;
  194216. }
  194217. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  194218. {
  194219. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194220. if (s != 0)
  194221. return s->read (buffer, bytesToRead);
  194222. return 0;
  194223. }
  194224. int64 juce_getInternetFileContentLength (void* handle)
  194225. {
  194226. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194227. if (s != 0)
  194228. {
  194229. //xxx todo
  194230. jassertfalse
  194231. }
  194232. return -1;
  194233. }
  194234. int juce_seekInInternetFile (void* handle, int newPosition)
  194235. {
  194236. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194237. if (s != 0)
  194238. return s->readPosition;
  194239. return 0;
  194240. }
  194241. #endif
  194242. /*** End of inlined file: juce_linux_Network.cpp ***/
  194243. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  194244. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194245. // compiled on its own).
  194246. #if JUCE_INCLUDED_FILE
  194247. void Logger::outputDebugString (const String& text) throw()
  194248. {
  194249. fputs (text.toUTF8(), stdout);
  194250. fputs ("\n", stdout);
  194251. }
  194252. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  194253. {
  194254. String text;
  194255. va_list args;
  194256. va_start (args, format);
  194257. text.vprintf(format, args);
  194258. outputDebugString(text);
  194259. }
  194260. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  194261. {
  194262. return Linux;
  194263. }
  194264. const String SystemStats::getOperatingSystemName() throw()
  194265. {
  194266. return T("Linux");
  194267. }
  194268. bool SystemStats::isOperatingSystem64Bit() throw()
  194269. {
  194270. #if JUCE_64BIT
  194271. return true;
  194272. #else
  194273. //xxx not sure how to find this out?..
  194274. return false;
  194275. #endif
  194276. }
  194277. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  194278. {
  194279. String info;
  194280. char buf [256];
  194281. FILE* f = fopen ("/proc/cpuinfo", "r");
  194282. while (f != 0 && fgets (buf, sizeof(buf), f))
  194283. {
  194284. if (strncmp (buf, key, strlen (key)) == 0)
  194285. {
  194286. char* p = buf;
  194287. while (*p && *p != '\n')
  194288. ++p;
  194289. if (*p != 0)
  194290. *p = 0;
  194291. p = buf;
  194292. while (*p != 0 && *p != ':')
  194293. ++p;
  194294. if (*p != 0 && *(p + 1) != 0)
  194295. info = p + 2;
  194296. if (! lastOne)
  194297. break;
  194298. }
  194299. }
  194300. fclose (f);
  194301. return info;
  194302. }
  194303. bool SystemStats::hasMMX() throw()
  194304. {
  194305. return getCpuInfo ("flags").contains (T("mmx"));
  194306. }
  194307. bool SystemStats::hasSSE() throw()
  194308. {
  194309. return getCpuInfo ("flags").contains (T("sse"));
  194310. }
  194311. bool SystemStats::hasSSE2() throw()
  194312. {
  194313. return getCpuInfo ("flags").contains (T("sse2"));
  194314. }
  194315. bool SystemStats::has3DNow() throw()
  194316. {
  194317. return getCpuInfo ("flags").contains (T("3dnow"));
  194318. }
  194319. const String SystemStats::getCpuVendor() throw()
  194320. {
  194321. return getCpuInfo ("vendor_id");
  194322. }
  194323. int SystemStats::getCpuSpeedInMegaherz() throw()
  194324. {
  194325. const String speed (getCpuInfo ("cpu MHz"));
  194326. return (int) (speed.getFloatValue() + 0.5f);
  194327. }
  194328. int SystemStats::getMemorySizeInMegabytes() throw()
  194329. {
  194330. struct sysinfo sysi;
  194331. if (sysinfo (&sysi) == 0)
  194332. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  194333. return 0;
  194334. }
  194335. uint32 juce_millisecondsSinceStartup() throw()
  194336. {
  194337. static unsigned int calibrate = 0;
  194338. static bool calibrated = false;
  194339. timeval t;
  194340. unsigned int ret = 0;
  194341. if (! gettimeofday (&t, 0))
  194342. {
  194343. if (! calibrated)
  194344. {
  194345. struct sysinfo sysi;
  194346. if (sysinfo (&sysi) == 0)
  194347. // Safe to assume system was not brought up earlier than 1970!
  194348. calibrate = t.tv_sec - sysi.uptime;
  194349. calibrated = true;
  194350. }
  194351. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  194352. }
  194353. return ret;
  194354. }
  194355. double Time::getMillisecondCounterHiRes() throw()
  194356. {
  194357. return getHighResolutionTicks() * 0.001;
  194358. }
  194359. int64 Time::getHighResolutionTicks() throw()
  194360. {
  194361. timeval t;
  194362. if (gettimeofday (&t, 0))
  194363. return 0;
  194364. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  194365. }
  194366. int64 Time::getHighResolutionTicksPerSecond() throw()
  194367. {
  194368. // Microseconds
  194369. return 1000000;
  194370. }
  194371. bool Time::setSystemTimeToThisTime() const throw()
  194372. {
  194373. timeval t;
  194374. t.tv_sec = millisSinceEpoch % 1000000;
  194375. t.tv_usec = millisSinceEpoch - t.tv_sec;
  194376. return settimeofday (&t, NULL) ? false : true;
  194377. }
  194378. int SystemStats::getPageSize() throw()
  194379. {
  194380. static int systemPageSize = 0;
  194381. if (systemPageSize == 0)
  194382. systemPageSize = sysconf (_SC_PAGESIZE);
  194383. return systemPageSize;
  194384. }
  194385. int SystemStats::getNumCpus() throw()
  194386. {
  194387. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  194388. return lastCpu + 1;
  194389. }
  194390. const String SystemStats::getLogonName()
  194391. {
  194392. const char* user = getenv ("USER");
  194393. if (user == 0)
  194394. {
  194395. struct passwd* const pw = getpwuid (getuid());
  194396. if (pw != 0)
  194397. user = pw->pw_name;
  194398. }
  194399. return String::fromUTF8 ((const uint8*) user);
  194400. }
  194401. const String SystemStats::getFullUserName()
  194402. {
  194403. return getLogonName();
  194404. }
  194405. void SystemStats::initialiseStats() throw()
  194406. {
  194407. // Process starts off as root when running suid
  194408. Process::lowerPrivilege();
  194409. String s (SystemStats::getJUCEVersion());
  194410. }
  194411. void PlatformUtilities::fpuReset()
  194412. {
  194413. }
  194414. #endif
  194415. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  194416. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  194417. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194418. // compiled on its own).
  194419. #if JUCE_INCLUDED_FILE
  194420. void JUCE_API juce_threadEntryPoint (void*);
  194421. void* threadEntryProc (void* value)
  194422. {
  194423. // New threads start off as root when running suid
  194424. Process::lowerPrivilege();
  194425. juce_threadEntryPoint (value);
  194426. return 0;
  194427. }
  194428. void* juce_createThread (void* userData)
  194429. {
  194430. pthread_t handle = 0;
  194431. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  194432. {
  194433. pthread_detach (handle);
  194434. return (void*)handle;
  194435. }
  194436. return 0;
  194437. }
  194438. void juce_killThread (void* handle)
  194439. {
  194440. if (handle != 0)
  194441. pthread_cancel ((pthread_t)handle);
  194442. }
  194443. void juce_setCurrentThreadName (const String& /*name*/)
  194444. {
  194445. }
  194446. Thread::ThreadID Thread::getCurrentThreadId()
  194447. {
  194448. return (ThreadID) pthread_self();
  194449. }
  194450. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  194451. // priority of the current thread
  194452. bool juce_setThreadPriority (void* handle, int priority)
  194453. {
  194454. struct sched_param param;
  194455. int policy, maxp, minp, pri;
  194456. if (handle == 0)
  194457. handle = (void*) pthread_self();
  194458. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  194459. && policy != SCHED_OTHER)
  194460. {
  194461. minp = sched_get_priority_min(policy);
  194462. maxp = sched_get_priority_max(policy);
  194463. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  194464. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  194465. // Realtime process priority
  194466. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  194467. else
  194468. // High process priority
  194469. param.__sched_priority = minp + pri;
  194470. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  194471. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  194472. }
  194473. return false;
  194474. }
  194475. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  194476. {
  194477. #if SUPPORT_AFFINITIES
  194478. cpu_set_t affinity;
  194479. CPU_ZERO (&affinity);
  194480. for (int i = 0; i < 32; ++i)
  194481. if ((affinityMask & (1 << i)) != 0)
  194482. CPU_SET (i, &affinity);
  194483. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  194484. sched_yield();
  194485. #else
  194486. /* affinities aren't supported because either the appropriate header files weren't found,
  194487. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  194488. */
  194489. jassertfalse
  194490. #endif
  194491. }
  194492. void Thread::yield()
  194493. {
  194494. sched_yield();
  194495. }
  194496. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  194497. void Process::setPriority (ProcessPriority prior)
  194498. {
  194499. struct sched_param param;
  194500. int policy, maxp, minp;
  194501. const int p = (int) prior;
  194502. if (p <= 1)
  194503. policy = SCHED_OTHER;
  194504. else
  194505. policy = SCHED_RR;
  194506. minp = sched_get_priority_min (policy);
  194507. maxp = sched_get_priority_max (policy);
  194508. if (p < 2)
  194509. param.__sched_priority = 0;
  194510. else if (p == 2 )
  194511. // Set to middle of lower realtime priority range
  194512. param.__sched_priority = minp + (maxp - minp) / 4;
  194513. else
  194514. // Set to middle of higher realtime priority range
  194515. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  194516. pthread_setschedparam (pthread_self(), policy, &param);
  194517. }
  194518. void Process::terminate()
  194519. {
  194520. exit (0);
  194521. }
  194522. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  194523. {
  194524. static char testResult = 0;
  194525. if (testResult == 0)
  194526. {
  194527. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  194528. if (testResult >= 0)
  194529. {
  194530. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  194531. testResult = 1;
  194532. }
  194533. }
  194534. return testResult < 0;
  194535. }
  194536. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  194537. {
  194538. return juce_isRunningUnderDebugger();
  194539. }
  194540. void Process::raisePrivilege()
  194541. {
  194542. // If running suid root, change effective user
  194543. // to root
  194544. if (geteuid() != 0 && getuid() == 0)
  194545. {
  194546. setreuid (geteuid(), getuid());
  194547. setregid (getegid(), getgid());
  194548. }
  194549. }
  194550. void Process::lowerPrivilege()
  194551. {
  194552. // If runing suid root, change effective user
  194553. // back to real user
  194554. if (geteuid() == 0 && getuid() != 0)
  194555. {
  194556. setreuid (geteuid(), getuid());
  194557. setregid (getegid(), getgid());
  194558. }
  194559. }
  194560. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194561. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  194562. {
  194563. return dlopen ((const char*) name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  194564. }
  194565. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194566. {
  194567. dlclose(handle);
  194568. }
  194569. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194570. {
  194571. return dlsym (libraryHandle, (const char*) procedureName);
  194572. }
  194573. #endif
  194574. #endif
  194575. /*** End of inlined file: juce_linux_Threads.cpp ***/
  194576. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194577. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  194578. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194579. // compiled on its own).
  194580. #if JUCE_INCLUDED_FILE
  194581. #ifdef JUCE_DEBUG
  194582. #define JUCE_DEBUG_XERRORS 1
  194583. #endif
  194584. extern Display* display;
  194585. extern Window juce_messageWindowHandle;
  194586. static String localClipboardContent;
  194587. static Atom atom_UTF8_STRING;
  194588. static Atom atom_CLIPBOARD;
  194589. static Atom atom_TARGETS;
  194590. static void initSelectionAtoms()
  194591. {
  194592. static bool isInitialised = false;
  194593. if (! isInitialised)
  194594. {
  194595. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194596. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194597. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194598. }
  194599. }
  194600. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194601. // works only for strings shorter than 1000000 bytes
  194602. static String juce_readWindowProperty (Window window, Atom prop,
  194603. Atom fmt, // XA_STRING or UTF8_STRING
  194604. bool deleteAfterReading)
  194605. {
  194606. String returnData;
  194607. uint8 *clipData;
  194608. Atom actualType;
  194609. int actualFormat;
  194610. unsigned long numItems, bytesLeft;
  194611. if (XGetWindowProperty (display, window, prop,
  194612. 0L /* offset */, 1000000 /* length (max) */, False,
  194613. AnyPropertyType /* format */,
  194614. &actualType, &actualFormat, &numItems, &bytesLeft,
  194615. &clipData) == Success)
  194616. {
  194617. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194618. {
  194619. returnData = String::fromUTF8 (clipData, numItems);
  194620. }
  194621. else if (actualType == XA_STRING && actualFormat == 8)
  194622. {
  194623. returnData = String ((const char*) clipData, numItems);
  194624. }
  194625. if (clipData != 0)
  194626. XFree (clipData);
  194627. jassert (bytesLeft == 0 || numItems == 1000000);
  194628. }
  194629. if (deleteAfterReading)
  194630. XDeleteProperty (display, window, prop);
  194631. return returnData;
  194632. }
  194633. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194634. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194635. {
  194636. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194637. // The selection owner will be asked to set the JUCE_SEL property on the
  194638. // juce_messageWindowHandle with the selection content
  194639. XConvertSelection (display, selection, requested_format, property_name,
  194640. juce_messageWindowHandle, CurrentTime);
  194641. int timeoutMs = 200; // will wait at most for 200 ms
  194642. do
  194643. {
  194644. XEvent event;
  194645. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194646. {
  194647. if (event.xselection.property == property_name)
  194648. {
  194649. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194650. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194651. event.xselection.property,
  194652. requested_format, true);
  194653. return true;
  194654. }
  194655. else
  194656. {
  194657. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194658. }
  194659. }
  194660. // not very elegant.. we could do a select() or something like that...
  194661. // however clipboard content requesting is inherently slow on x11, it
  194662. // often takes 50ms or more so...
  194663. Thread::sleep (4);
  194664. timeoutMs -= 4;
  194665. }
  194666. while (timeoutMs > 0);
  194667. DBG("timeout for juce_requestSelectionContent");
  194668. return false;
  194669. }
  194670. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194671. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194672. {
  194673. initSelectionAtoms();
  194674. // the selection content is sent to the target window as a window property
  194675. XSelectionEvent reply;
  194676. reply.type = SelectionNotify;
  194677. reply.display = evt.display;
  194678. reply.requestor = evt.requestor;
  194679. reply.selection = evt.selection;
  194680. reply.target = evt.target;
  194681. reply.property = None; // == "fail"
  194682. reply.time = evt.time;
  194683. HeapBlock <char> data;
  194684. int propertyFormat = 0, numDataItems = 0;
  194685. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194686. {
  194687. if (evt.target == XA_STRING)
  194688. {
  194689. // format data according to system locale
  194690. numDataItems = localClipboardContent.length();
  194691. data.calloc (numDataItems + 2);
  194692. localClipboardContent.copyToBuffer ((char*) data, numDataItems + 1);
  194693. propertyFormat = 8; // bits/item
  194694. }
  194695. else if (evt.target == atom_UTF8_STRING)
  194696. {
  194697. // translate to utf8
  194698. numDataItems = localClipboardContent.copyToUTF8 (0);
  194699. data.calloc (numDataItems + 2);
  194700. localClipboardContent.copyToUTF8 (data, numDataItems + 1);
  194701. propertyFormat = 8; // bits/item
  194702. }
  194703. else if (evt.target == atom_TARGETS)
  194704. {
  194705. // another application wants to know what we are able to send
  194706. numDataItems = 2;
  194707. propertyFormat = 32; // atoms are 32-bit
  194708. data.calloc (numDataItems * 4);
  194709. ((Atom*) data)[0] = atom_UTF8_STRING;
  194710. ((Atom*) data)[1] = XA_STRING;
  194711. }
  194712. }
  194713. else
  194714. {
  194715. DBG ("requested unsupported clipboard");
  194716. }
  194717. if (data != 0)
  194718. {
  194719. const int maxReasonableSelectionSize = 1000000;
  194720. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194721. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194722. {
  194723. XChangeProperty (evt.display, evt.requestor,
  194724. evt.property, evt.target,
  194725. propertyFormat /* 8 or 32 */, PropModeReplace,
  194726. (const unsigned char*) data, numDataItems);
  194727. reply.property = evt.property; // " == success"
  194728. }
  194729. }
  194730. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194731. }
  194732. void SystemClipboard::copyTextToClipboard (const String& clipText) throw()
  194733. {
  194734. initSelectionAtoms();
  194735. localClipboardContent = clipText;
  194736. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194737. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194738. }
  194739. const String SystemClipboard::getTextFromClipboard() throw()
  194740. {
  194741. initSelectionAtoms();
  194742. String content;
  194743. Atom selection = XA_PRIMARY;
  194744. Window selectionOwner = None;
  194745. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194746. {
  194747. selection = atom_CLIPBOARD;
  194748. selectionOwner = XGetSelectionOwner (display, selection);
  194749. }
  194750. if (selectionOwner != None)
  194751. {
  194752. if (selectionOwner == juce_messageWindowHandle)
  194753. {
  194754. content = localClipboardContent;
  194755. }
  194756. else
  194757. {
  194758. // first try: we want an utf8 string
  194759. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194760. if (! ok)
  194761. {
  194762. // second chance, ask for a good old locale-dependent string ..
  194763. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194764. }
  194765. }
  194766. }
  194767. return content;
  194768. }
  194769. #endif
  194770. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194771. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194772. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194773. // compiled on its own).
  194774. #if JUCE_INCLUDED_FILE
  194775. #ifdef JUCE_DEBUG
  194776. #define JUCE_DEBUG_XERRORS 1
  194777. #endif
  194778. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194779. Window juce_messageWindowHandle = None;
  194780. #define SpecialAtom "JUCESpecialAtom"
  194781. #define BroadcastAtom "JUCEBroadcastAtom"
  194782. #define SpecialCallbackAtom "JUCESpecialCallbackAtom"
  194783. static Atom specialId;
  194784. static Atom broadcastId;
  194785. static Atom specialCallbackId;
  194786. // This is referenced from Windowing.cpp
  194787. XContext improbableNumber;
  194788. // Defined in Windowing.cpp
  194789. extern void juce_windowMessageReceive (XEvent* event);
  194790. // Defined in Clipboard.cpp
  194791. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt);
  194792. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194793. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194794. class InternalMessageQueue
  194795. {
  194796. public:
  194797. InternalMessageQueue()
  194798. : bytesInSocket (0)
  194799. {
  194800. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194801. (void) ret; jassert (ret == 0);
  194802. setNonBlocking (fd[0]);
  194803. setNonBlocking (fd[1]);
  194804. }
  194805. ~InternalMessageQueue()
  194806. {
  194807. close (fd[0]);
  194808. close (fd[1]);
  194809. }
  194810. void postMessage (Message* msg)
  194811. {
  194812. const int maxBytesInSocketQueue = 128;
  194813. ScopedLock sl (lock);
  194814. queue.add (msg);
  194815. if (bytesInSocket < maxBytesInSocketQueue)
  194816. {
  194817. ++bytesInSocket;
  194818. ScopedUnlock ul (lock);
  194819. const unsigned char x = 0xff;
  194820. size_t bytesWritten = write (fd[0], &x, 1);
  194821. (void) bytesWritten;
  194822. }
  194823. }
  194824. bool isEmpty() const
  194825. {
  194826. ScopedLock sl (lock);
  194827. return queue.size() == 0;
  194828. }
  194829. Message* popNextMessage()
  194830. {
  194831. ScopedLock sl (lock);
  194832. if (bytesInSocket > 0)
  194833. {
  194834. --bytesInSocket;
  194835. ScopedUnlock ul (lock);
  194836. unsigned char x;
  194837. size_t numBytes = read (fd[1], &x, 1);
  194838. (void) numBytes;
  194839. }
  194840. Message* m = queue[0];
  194841. queue.remove (0, false /* deleteObject */);
  194842. return m;
  194843. }
  194844. int getWaitHandle() const { return fd[1]; }
  194845. private:
  194846. CriticalSection lock;
  194847. OwnedArray <Message> queue;
  194848. int fd[2];
  194849. int bytesInSocket;
  194850. static bool setNonBlocking (int handle)
  194851. {
  194852. int socketFlags = fcntl (handle, F_GETFL, 0);
  194853. if (socketFlags == -1)
  194854. return false;
  194855. socketFlags |= O_NONBLOCK;
  194856. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194857. }
  194858. };
  194859. struct MessageThreadFuncCall
  194860. {
  194861. enum { uniqueID = 0x73774623 };
  194862. MessageCallbackFunction* func;
  194863. void* parameter;
  194864. void* result;
  194865. CriticalSection lock;
  194866. WaitableEvent event;
  194867. };
  194868. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194869. // error handling in X11
  194870. static bool errorOccurred = false;
  194871. static bool keyboardBreakOccurred = false;
  194872. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194873. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194874. // Usually happens when client-server connection is broken
  194875. static int ioErrorHandler (Display* display)
  194876. {
  194877. DBG (T("ERROR: connection to X server broken.. terminating."));
  194878. errorOccurred = true;
  194879. if (JUCEApplication::getInstance() != 0)
  194880. Process::terminate();
  194881. return 0;
  194882. }
  194883. // A protocol error has occurred
  194884. static int errorHandler (Display* display, XErrorEvent* event)
  194885. {
  194886. #ifdef JUCE_DEBUG_XERRORS
  194887. char errorStr[64] = { 0 };
  194888. char requestStr[64] = { 0 };
  194889. XGetErrorText (display, event->error_code, errorStr, 64);
  194890. XGetErrorDatabaseText (display,
  194891. "XRequest",
  194892. (const char*) String (event->request_code),
  194893. "Unknown",
  194894. requestStr,
  194895. 64);
  194896. DBG (T("ERROR: X returned ") + String (errorStr) + T(" for operation ") + String (requestStr));
  194897. #endif
  194898. return 0;
  194899. }
  194900. // Breakin from keyboard
  194901. static void signalHandler (int sig)
  194902. {
  194903. if (sig == SIGINT)
  194904. {
  194905. keyboardBreakOccurred = true;
  194906. return;
  194907. }
  194908. static bool reentrant = false;
  194909. if (! reentrant)
  194910. {
  194911. reentrant = true;
  194912. // Illegal instruction
  194913. fflush (stdout);
  194914. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194915. errorOccurred = true;
  194916. if (JUCEApplication::getInstance() != 0)
  194917. Process::terminate();
  194918. }
  194919. else
  194920. {
  194921. if (JUCEApplication::getInstance() != 0)
  194922. exit(0);
  194923. }
  194924. }
  194925. void MessageManager::doPlatformSpecificInitialisation()
  194926. {
  194927. // Initialise xlib for multiple thread support
  194928. static bool initThreadCalled = false;
  194929. if (! initThreadCalled)
  194930. {
  194931. if (! XInitThreads())
  194932. {
  194933. // This is fatal! Print error and closedown
  194934. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194935. if (JUCEApplication::getInstance() != 0)
  194936. Process::terminate();
  194937. return;
  194938. }
  194939. initThreadCalled = true;
  194940. }
  194941. // This is called if the client/server connection is broken
  194942. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194943. // This is called if a protocol error occurs
  194944. oldErrorHandler = XSetErrorHandler (errorHandler);
  194945. // Install signal handler for break-in
  194946. struct sigaction saction;
  194947. sigset_t maskSet;
  194948. sigemptyset (&maskSet);
  194949. saction.sa_handler = signalHandler;
  194950. saction.sa_mask = maskSet;
  194951. saction.sa_flags = 0;
  194952. sigaction (SIGINT, &saction, NULL);
  194953. #ifndef _DEBUG
  194954. // Setup signal handlers for various fatal errors
  194955. sigaction (SIGILL, &saction, NULL);
  194956. sigaction (SIGBUS, &saction, NULL);
  194957. sigaction (SIGFPE, &saction, NULL);
  194958. sigaction (SIGSEGV, &saction, NULL);
  194959. sigaction (SIGSYS, &saction, NULL);
  194960. #endif
  194961. // Create the internal message queue
  194962. juce_internalMessageQueue = new InternalMessageQueue();
  194963. // Try to connect to a display
  194964. String displayName (getenv ("DISPLAY"));
  194965. if (displayName.isEmpty())
  194966. displayName = T(":0.0");
  194967. display = XOpenDisplay (displayName);
  194968. if (display == 0)
  194969. {
  194970. // This is not fatal! we can run headless.
  194971. return;
  194972. }
  194973. // Get defaults for various properties
  194974. int screen = DefaultScreen (display);
  194975. Window root = RootWindow (display, screen);
  194976. Visual* visual = DefaultVisual (display, screen);
  194977. // Create atoms for our ClientMessages (these cannot be deleted)
  194978. specialId = XInternAtom (display, SpecialAtom, false);
  194979. broadcastId = XInternAtom (display, BroadcastAtom, false);
  194980. specialCallbackId = XInternAtom (display, SpecialCallbackAtom, false);
  194981. // Create a context to store user data associated with Windows we
  194982. // create in WindowDriver
  194983. improbableNumber = XUniqueContext();
  194984. // We're only interested in client messages for this window
  194985. // which are always sent
  194986. XSetWindowAttributes swa;
  194987. swa.event_mask = NoEventMask;
  194988. // Create our message window (this will never be mapped)
  194989. juce_messageWindowHandle = XCreateWindow (display, root,
  194990. 0, 0, 1, 1, 0, 0, InputOnly,
  194991. visual, CWEventMask, &swa);
  194992. }
  194993. void MessageManager::doPlatformSpecificShutdown()
  194994. {
  194995. deleteAndZero (juce_internalMessageQueue);
  194996. if (display != 0 && ! errorOccurred)
  194997. {
  194998. XDestroyWindow (display, juce_messageWindowHandle);
  194999. XCloseDisplay (display);
  195000. // reset pointers
  195001. juce_messageWindowHandle = 0;
  195002. display = 0;
  195003. // Restore original error handlers
  195004. XSetIOErrorHandler (oldIOErrorHandler);
  195005. oldIOErrorHandler = 0;
  195006. XSetErrorHandler (oldErrorHandler);
  195007. oldErrorHandler = 0;
  195008. }
  195009. }
  195010. bool juce_postMessageToSystemQueue (void* message)
  195011. {
  195012. if (errorOccurred)
  195013. return false;
  195014. juce_internalMessageQueue->postMessage ((Message*) message);
  195015. return true;
  195016. }
  195017. void MessageManager::broadcastMessage (const String& value) throw()
  195018. {
  195019. }
  195020. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  195021. void* parameter)
  195022. {
  195023. if (errorOccurred)
  195024. return 0;
  195025. if (! isThisTheMessageThread())
  195026. {
  195027. MessageThreadFuncCall messageCallContext;
  195028. messageCallContext.func = func;
  195029. messageCallContext.parameter = parameter;
  195030. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  195031. 0, 0, &messageCallContext));
  195032. // Wait for it to complete before continuing
  195033. messageCallContext.event.wait();
  195034. return messageCallContext.result;
  195035. }
  195036. else
  195037. {
  195038. // Just call the function directly
  195039. return func (parameter);
  195040. }
  195041. }
  195042. // Wait for an event (either XEvent, or an internal Message)
  195043. static bool juce_sleepUntilEvent (const int timeoutMs)
  195044. {
  195045. if (! juce_internalMessageQueue->isEmpty())
  195046. return true;
  195047. if (display != 0)
  195048. {
  195049. ScopedXLock xlock;
  195050. if (XPending (display))
  195051. return true;
  195052. }
  195053. struct timeval tv;
  195054. tv.tv_sec = 0;
  195055. tv.tv_usec = timeoutMs * 1000;
  195056. int fd0 = juce_internalMessageQueue->getWaitHandle();
  195057. int fdmax = fd0;
  195058. fd_set readset;
  195059. FD_ZERO (&readset);
  195060. FD_SET (fd0, &readset);
  195061. if (display != 0)
  195062. {
  195063. ScopedXLock xlock;
  195064. int fd1 = XConnectionNumber (display);
  195065. FD_SET (fd1, &readset);
  195066. fdmax = jmax (fd0, fd1);
  195067. }
  195068. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  195069. return (ret > 0); // ret <= 0 if error or timeout
  195070. }
  195071. // Handle next XEvent (if any)
  195072. static bool juce_dispatchNextXEvent()
  195073. {
  195074. if (display == 0)
  195075. return false;
  195076. XEvent evt;
  195077. {
  195078. ScopedXLock xlock;
  195079. if (! XPending (display))
  195080. return false;
  195081. XNextEvent (display, &evt);
  195082. }
  195083. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  195084. {
  195085. juce_handleSelectionRequest (evt.xselectionrequest);
  195086. }
  195087. else if (evt.xany.window != juce_messageWindowHandle)
  195088. {
  195089. juce_windowMessageReceive (&evt);
  195090. }
  195091. return true;
  195092. }
  195093. // Handle next internal Message (if any)
  195094. static bool juce_dispatchNextInternalMessage()
  195095. {
  195096. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  195097. if (msg == 0)
  195098. return false;
  195099. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  195100. {
  195101. // Handle callback message
  195102. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  195103. call->result = (*(call->func)) (call->parameter);
  195104. call->event.signal();
  195105. }
  195106. else
  195107. {
  195108. // Handle "normal" messages
  195109. MessageManager::getInstance()->deliverMessage (msg.release());
  195110. }
  195111. return true;
  195112. }
  195113. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  195114. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  195115. {
  195116. for (;;)
  195117. {
  195118. if (errorOccurred)
  195119. break;
  195120. if (keyboardBreakOccurred)
  195121. {
  195122. errorOccurred = true;
  195123. if (JUCEApplication::getInstance() != 0)
  195124. Process::terminate();
  195125. break;
  195126. }
  195127. static int totalEventCount = 0;
  195128. ++totalEventCount;
  195129. // The purpose here is to give either priority to XEvents or
  195130. // to internal messages This is necessary to keep a "good"
  195131. // behaviour when the cpu is overloaded
  195132. if (totalEventCount & 1)
  195133. {
  195134. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  195135. return true;
  195136. }
  195137. else
  195138. {
  195139. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  195140. return true;
  195141. }
  195142. if (returnIfNoPendingMessages) // early exit
  195143. break;
  195144. // the timeout is to be on the safe side, but it does not seem to be useful
  195145. juce_sleepUntilEvent (2000);
  195146. }
  195147. return false;
  195148. }
  195149. #endif
  195150. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  195151. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  195152. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195153. // compiled on its own).
  195154. #if JUCE_INCLUDED_FILE
  195155. class FreeTypeFontFace
  195156. {
  195157. public:
  195158. enum FontStyle
  195159. {
  195160. Plain = 0,
  195161. Bold = 1,
  195162. Italic = 2
  195163. };
  195164. struct FontNameIndex
  195165. {
  195166. String fileName;
  195167. int faceIndex;
  195168. };
  195169. FreeTypeFontFace (const String& familyName) throw()
  195170. : hasSerif (false),
  195171. monospaced (false)
  195172. {
  195173. family = familyName;
  195174. }
  195175. void setFileName (const String& name, const int faceIndex, FontStyle style) throw()
  195176. {
  195177. if (names [(int) style].fileName.isEmpty())
  195178. {
  195179. names [(int) style].fileName = name;
  195180. names [(int) style].faceIndex = faceIndex;
  195181. }
  195182. }
  195183. const String& getFamilyName() const throw() { return family; }
  195184. const String& getFileName (const int style, int& faceIndex) const throw()
  195185. {
  195186. faceIndex = names[style].faceIndex;
  195187. return names[style].fileName;
  195188. }
  195189. void setMonospaced (bool mono) throw() { monospaced = mono; }
  195190. bool getMonospaced() const throw() { return monospaced; }
  195191. void setSerif (const bool serif) throw() { hasSerif = serif; }
  195192. bool getSerif() const throw() { return hasSerif; }
  195193. private:
  195194. String family;
  195195. FontNameIndex names[4];
  195196. bool hasSerif, monospaced;
  195197. };
  195198. class FreeTypeInterface : public DeletedAtShutdown
  195199. {
  195200. public:
  195201. FreeTypeInterface() throw()
  195202. : lastFace (0),
  195203. lastBold (false),
  195204. lastItalic (false)
  195205. {
  195206. if (FT_Init_FreeType (&ftLib) != 0)
  195207. {
  195208. ftLib = 0;
  195209. DBG (T("Failed to initialize FreeType"));
  195210. }
  195211. StringArray fontDirs;
  195212. fontDirs.addTokens (String (getenv ("JUCE_FONT_PATH")), T(";,"), 0);
  195213. fontDirs.removeEmptyStrings (true);
  195214. if (fontDirs.size() == 0)
  195215. {
  195216. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  195217. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  195218. if (fontsInfo != 0)
  195219. {
  195220. forEachXmlChildElementWithTagName (*fontsInfo, e, T("dir"))
  195221. {
  195222. fontDirs.add (e->getAllSubText().trim());
  195223. }
  195224. delete fontsInfo;
  195225. }
  195226. }
  195227. if (fontDirs.size() == 0)
  195228. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  195229. for (int i = 0; i < fontDirs.size(); ++i)
  195230. enumerateFaces (fontDirs[i]);
  195231. }
  195232. ~FreeTypeInterface() throw()
  195233. {
  195234. if (lastFace != 0)
  195235. FT_Done_Face (lastFace);
  195236. if (ftLib != 0)
  195237. FT_Done_FreeType (ftLib);
  195238. clearSingletonInstance();
  195239. }
  195240. FreeTypeFontFace* findOrCreate (const String& familyName,
  195241. const bool create = false) throw()
  195242. {
  195243. for (int i = 0; i < faces.size(); i++)
  195244. if (faces[i]->getFamilyName() == familyName)
  195245. return faces[i];
  195246. if (! create)
  195247. return NULL;
  195248. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  195249. faces.add (newFace);
  195250. return newFace;
  195251. }
  195252. // Enumerate all font faces available in a given directory
  195253. void enumerateFaces (const String& path) throw()
  195254. {
  195255. File dirPath (path);
  195256. if (path.isEmpty() || ! dirPath.isDirectory())
  195257. return;
  195258. DirectoryIterator di (dirPath, true);
  195259. while (di.next())
  195260. {
  195261. File possible (di.getFile());
  195262. if (possible.hasFileExtension (T("ttf"))
  195263. || possible.hasFileExtension (T("pfb"))
  195264. || possible.hasFileExtension (T("pcf")))
  195265. {
  195266. FT_Face face;
  195267. int faceIndex = 0;
  195268. int numFaces = 0;
  195269. do
  195270. {
  195271. if (FT_New_Face (ftLib,
  195272. possible.getFullPathName(),
  195273. faceIndex,
  195274. &face) == 0)
  195275. {
  195276. if (faceIndex == 0)
  195277. numFaces = face->num_faces;
  195278. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  195279. {
  195280. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  195281. int style = (int) FreeTypeFontFace::Plain;
  195282. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  195283. style |= (int) FreeTypeFontFace::Bold;
  195284. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  195285. style |= (int) FreeTypeFontFace::Italic;
  195286. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  195287. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  195288. // Surely there must be a better way to do this?
  195289. const String name (face->family_name);
  195290. newFace->setSerif (! (name.containsIgnoreCase (T("Sans"))
  195291. || name.containsIgnoreCase (T("Verdana"))
  195292. || name.containsIgnoreCase (T("Arial"))));
  195293. }
  195294. FT_Done_Face (face);
  195295. }
  195296. ++faceIndex;
  195297. }
  195298. while (faceIndex < numFaces);
  195299. }
  195300. }
  195301. }
  195302. // Create a FreeType face object for a given font
  195303. FT_Face createFT_Face (const String& fontName,
  195304. const bool bold,
  195305. const bool italic) throw()
  195306. {
  195307. FT_Face face = 0;
  195308. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  195309. {
  195310. face = lastFace;
  195311. }
  195312. else
  195313. {
  195314. if (lastFace != 0)
  195315. {
  195316. FT_Done_Face (lastFace);
  195317. lastFace = 0;
  195318. }
  195319. lastFontName = fontName;
  195320. lastBold = bold;
  195321. lastItalic = italic;
  195322. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  195323. if (ftFace != 0)
  195324. {
  195325. int style = (int) FreeTypeFontFace::Plain;
  195326. if (bold)
  195327. style |= (int) FreeTypeFontFace::Bold;
  195328. if (italic)
  195329. style |= (int) FreeTypeFontFace::Italic;
  195330. int faceIndex;
  195331. String fileName (ftFace->getFileName (style, faceIndex));
  195332. if (fileName.isEmpty())
  195333. {
  195334. style ^= (int) FreeTypeFontFace::Bold;
  195335. fileName = ftFace->getFileName (style, faceIndex);
  195336. if (fileName.isEmpty())
  195337. {
  195338. style ^= (int) FreeTypeFontFace::Bold;
  195339. style ^= (int) FreeTypeFontFace::Italic;
  195340. fileName = ftFace->getFileName (style, faceIndex);
  195341. if (! fileName.length())
  195342. {
  195343. style ^= (int) FreeTypeFontFace::Bold;
  195344. fileName = ftFace->getFileName (style, faceIndex);
  195345. }
  195346. }
  195347. }
  195348. if (! FT_New_Face (ftLib, (const char*) fileName, faceIndex, &lastFace))
  195349. {
  195350. face = lastFace;
  195351. // If there isn't a unicode charmap then select the first one.
  195352. if (FT_Select_Charmap (face, ft_encoding_unicode))
  195353. FT_Set_Charmap (face, face->charmaps[0]);
  195354. }
  195355. }
  195356. }
  195357. return face;
  195358. }
  195359. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character) throw()
  195360. {
  195361. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  195362. const float height = (float) (face->ascender - face->descender);
  195363. const float scaleX = 1.0f / height;
  195364. const float scaleY = -1.0f / height;
  195365. Path destShape;
  195366. #define CONVERTX(val) (scaleX * (val).x)
  195367. #define CONVERTY(val) (scaleY * (val).y)
  195368. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  195369. || face->glyph->format != ft_glyph_format_outline)
  195370. {
  195371. return false;
  195372. }
  195373. const FT_Outline* const outline = &face->glyph->outline;
  195374. const short* const contours = outline->contours;
  195375. const char* const tags = outline->tags;
  195376. FT_Vector* const points = outline->points;
  195377. for (int c = 0; c < outline->n_contours; c++)
  195378. {
  195379. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  195380. const int endPoint = contours[c];
  195381. for (int p = startPoint; p <= endPoint; p++)
  195382. {
  195383. const float x = CONVERTX (points[p]);
  195384. const float y = CONVERTY (points[p]);
  195385. if (p == startPoint)
  195386. {
  195387. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195388. {
  195389. float x2 = CONVERTX (points [endPoint]);
  195390. float y2 = CONVERTY (points [endPoint]);
  195391. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  195392. {
  195393. x2 = (x + x2) * 0.5f;
  195394. y2 = (y + y2) * 0.5f;
  195395. }
  195396. destShape.startNewSubPath (x2, y2);
  195397. }
  195398. else
  195399. {
  195400. destShape.startNewSubPath (x, y);
  195401. }
  195402. }
  195403. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  195404. {
  195405. if (p != startPoint)
  195406. destShape.lineTo (x, y);
  195407. }
  195408. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195409. {
  195410. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  195411. float x2 = CONVERTX (points [nextIndex]);
  195412. float y2 = CONVERTY (points [nextIndex]);
  195413. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  195414. {
  195415. x2 = (x + x2) * 0.5f;
  195416. y2 = (y + y2) * 0.5f;
  195417. }
  195418. else
  195419. {
  195420. ++p;
  195421. }
  195422. destShape.quadraticTo (x, y, x2, y2);
  195423. }
  195424. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  195425. {
  195426. if (p >= endPoint)
  195427. return false;
  195428. const int next1 = p + 1;
  195429. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  195430. const float x2 = CONVERTX (points [next1]);
  195431. const float y2 = CONVERTY (points [next1]);
  195432. const float x3 = CONVERTX (points [next2]);
  195433. const float y3 = CONVERTY (points [next2]);
  195434. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  195435. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  195436. return false;
  195437. destShape.cubicTo (x, y, x2, y2, x3, y3);
  195438. p += 2;
  195439. }
  195440. }
  195441. destShape.closeSubPath();
  195442. }
  195443. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  195444. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  195445. addKerning (face, dest, character, glyphIndex);
  195446. return true;
  195447. }
  195448. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex) throw()
  195449. {
  195450. const float height = (float) (face->ascender - face->descender);
  195451. uint32 rightGlyphIndex;
  195452. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  195453. while (rightGlyphIndex != 0)
  195454. {
  195455. FT_Vector kerning;
  195456. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  195457. {
  195458. if (kerning.x != 0)
  195459. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  195460. }
  195461. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  195462. }
  195463. }
  195464. // Add a glyph to a font
  195465. bool addGlyphToFont (const uint32 character,
  195466. const tchar* fontName, bool bold, bool italic,
  195467. CustomTypeface& dest) throw()
  195468. {
  195469. FT_Face face = createFT_Face (fontName, bold, italic);
  195470. if (face != 0)
  195471. return addGlyph (face, dest, character);
  195472. return false;
  195473. }
  195474. void getFamilyNames (StringArray& familyNames) const throw()
  195475. {
  195476. for (int i = 0; i < faces.size(); i++)
  195477. familyNames.add (faces[i]->getFamilyName());
  195478. }
  195479. void getMonospacedNames (StringArray& monoSpaced) const throw()
  195480. {
  195481. for (int i = 0; i < faces.size(); i++)
  195482. if (faces[i]->getMonospaced())
  195483. monoSpaced.add (faces[i]->getFamilyName());
  195484. }
  195485. void getSerifNames (StringArray& serif) const throw()
  195486. {
  195487. for (int i = 0; i < faces.size(); i++)
  195488. if (faces[i]->getSerif())
  195489. serif.add (faces[i]->getFamilyName());
  195490. }
  195491. void getSansSerifNames (StringArray& sansSerif) const throw()
  195492. {
  195493. for (int i = 0; i < faces.size(); i++)
  195494. if (! faces[i]->getSerif())
  195495. sansSerif.add (faces[i]->getFamilyName());
  195496. }
  195497. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  195498. private:
  195499. FT_Library ftLib;
  195500. FT_Face lastFace;
  195501. String lastFontName;
  195502. bool lastBold, lastItalic;
  195503. OwnedArray<FreeTypeFontFace> faces;
  195504. };
  195505. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  195506. class FreetypeTypeface : public CustomTypeface
  195507. {
  195508. public:
  195509. FreetypeTypeface (const Font& font)
  195510. {
  195511. FT_Face face = FreeTypeInterface::getInstance()
  195512. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  195513. if (face == 0)
  195514. {
  195515. #ifdef JUCE_DEBUG
  195516. String msg (T("Failed to create typeface: "));
  195517. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  195518. DBG (msg);
  195519. #endif
  195520. }
  195521. else
  195522. {
  195523. setCharacteristics (font.getTypefaceName(),
  195524. face->ascender / (float) (face->ascender - face->descender),
  195525. font.isBold(), font.isItalic(),
  195526. L' ');
  195527. }
  195528. }
  195529. bool loadGlyphIfPossible (const juce_wchar character)
  195530. {
  195531. return FreeTypeInterface::getInstance()
  195532. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  195533. }
  195534. };
  195535. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  195536. {
  195537. return new FreetypeTypeface (font);
  195538. }
  195539. const StringArray Font::findAllTypefaceNames() throw()
  195540. {
  195541. StringArray s;
  195542. FreeTypeInterface::getInstance()->getFamilyNames (s);
  195543. s.sort (true);
  195544. return s;
  195545. }
  195546. static const String pickBestFont (const StringArray& names,
  195547. const char* const choicesString)
  195548. {
  195549. StringArray choices;
  195550. choices.addTokens (String (choicesString), T(","), 0);
  195551. choices.trim();
  195552. choices.removeEmptyStrings();
  195553. int i, j;
  195554. for (j = 0; j < choices.size(); ++j)
  195555. if (names.contains (choices[j], true))
  195556. return choices[j];
  195557. for (j = 0; j < choices.size(); ++j)
  195558. for (i = 0; i < names.size(); i++)
  195559. if (names[i].startsWithIgnoreCase (choices[j]))
  195560. return names[i];
  195561. for (j = 0; j < choices.size(); ++j)
  195562. for (i = 0; i < names.size(); i++)
  195563. if (names[i].containsIgnoreCase (choices[j]))
  195564. return names[i];
  195565. return names[0];
  195566. }
  195567. static const String linux_getDefaultSansSerifFontName()
  195568. {
  195569. StringArray allFonts;
  195570. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  195571. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  195572. }
  195573. static const String linux_getDefaultSerifFontName()
  195574. {
  195575. StringArray allFonts;
  195576. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  195577. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  195578. }
  195579. static const String linux_getDefaultMonospacedFontName()
  195580. {
  195581. StringArray allFonts;
  195582. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  195583. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  195584. }
  195585. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  195586. {
  195587. defaultSans = linux_getDefaultSansSerifFontName();
  195588. defaultSerif = linux_getDefaultSerifFontName();
  195589. defaultFixed = linux_getDefaultMonospacedFontName();
  195590. }
  195591. #endif
  195592. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  195593. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  195594. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195595. // compiled on its own).
  195596. #if JUCE_INCLUDED_FILE
  195597. #define TAKE_FOCUS 0
  195598. #define DELETE_WINDOW 1
  195599. #define SYSTEM_TRAY_REQUEST_DOCK 0
  195600. #define SYSTEM_TRAY_BEGIN_MESSAGE 1
  195601. #define SYSTEM_TRAY_CANCEL_MESSAGE 2
  195602. static const int repaintTimerPeriod = 1000 / 100; // 100 fps maximum
  195603. static Atom wm_ChangeState = None;
  195604. static Atom wm_State = None;
  195605. static Atom wm_Protocols = None;
  195606. static Atom wm_ProtocolList [2] = { None, None };
  195607. static Atom wm_ActiveWin = None;
  195608. #define ourDndVersion 3
  195609. static Atom XA_XdndAware = None;
  195610. static Atom XA_XdndEnter = None;
  195611. static Atom XA_XdndLeave = None;
  195612. static Atom XA_XdndPosition = None;
  195613. static Atom XA_XdndStatus = None;
  195614. static Atom XA_XdndDrop = None;
  195615. static Atom XA_XdndFinished = None;
  195616. static Atom XA_XdndSelection = None;
  195617. static Atom XA_XdndProxy = None;
  195618. static Atom XA_XdndTypeList = None;
  195619. static Atom XA_XdndActionList = None;
  195620. static Atom XA_XdndActionDescription = None;
  195621. static Atom XA_XdndActionCopy = None;
  195622. static Atom XA_XdndActionMove = None;
  195623. static Atom XA_XdndActionLink = None;
  195624. static Atom XA_XdndActionAsk = None;
  195625. static Atom XA_XdndActionPrivate = None;
  195626. static Atom XA_JXSelectionWindowProperty = None;
  195627. static Atom XA_MimeTextPlain = None;
  195628. static Atom XA_MimeTextUriList = None;
  195629. static Atom XA_MimeRootDrop = None;
  195630. static XErrorHandler oldHandler = 0;
  195631. static int trappedErrorCode = 0;
  195632. extern "C" int errorTrapHandler (Display* dpy, XErrorEvent* err)
  195633. {
  195634. trappedErrorCode = err->error_code;
  195635. return 0;
  195636. }
  195637. static void trapErrors()
  195638. {
  195639. trappedErrorCode = 0;
  195640. oldHandler = XSetErrorHandler (errorTrapHandler);
  195641. }
  195642. static bool untrapErrors()
  195643. {
  195644. XSetErrorHandler (oldHandler);
  195645. return (trappedErrorCode == 0);
  195646. }
  195647. static bool isActiveApplication = false;
  195648. bool Process::isForegroundProcess()
  195649. {
  195650. return isActiveApplication;
  195651. }
  195652. // These are defined in juce_linux_Messaging.cpp
  195653. extern Display* display;
  195654. extern XContext improbableNumber;
  195655. static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  195656. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  195657. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  195658. static int pointerMap[5];
  195659. static int lastMousePosX = 0, lastMousePosY = 0;
  195660. enum MouseButtons
  195661. {
  195662. NoButton = 0,
  195663. LeftButton = 1,
  195664. MiddleButton = 2,
  195665. RightButton = 3,
  195666. WheelUp = 4,
  195667. WheelDown = 5
  195668. };
  195669. static void getMousePos (int& x, int& y, int& mouseMods) throw()
  195670. {
  195671. Window root, child;
  195672. int winx, winy;
  195673. unsigned int mask;
  195674. mouseMods = 0;
  195675. ScopedXLock xlock;
  195676. if (XQueryPointer (display,
  195677. RootWindow (display, DefaultScreen (display)),
  195678. &root, &child,
  195679. &x, &y, &winx, &winy, &mask) == False)
  195680. {
  195681. // Pointer not on the default screen
  195682. x = y = -1;
  195683. }
  195684. else
  195685. {
  195686. if ((mask & Button1Mask) != 0)
  195687. mouseMods |= ModifierKeys::leftButtonModifier;
  195688. if ((mask & Button2Mask) != 0)
  195689. mouseMods |= ModifierKeys::middleButtonModifier;
  195690. if ((mask & Button3Mask) != 0)
  195691. mouseMods |= ModifierKeys::rightButtonModifier;
  195692. }
  195693. }
  195694. static int AltMask = 0;
  195695. static int NumLockMask = 0;
  195696. static bool numLock = 0;
  195697. static bool capsLock = 0;
  195698. static char keyStates [32];
  195699. static void updateKeyStates (const int keycode, const bool press) throw()
  195700. {
  195701. const int keybyte = keycode >> 3;
  195702. const int keybit = (1 << (keycode & 7));
  195703. if (press)
  195704. keyStates [keybyte] |= keybit;
  195705. else
  195706. keyStates [keybyte] &= ~keybit;
  195707. }
  195708. static bool keyDown (const int keycode) throw()
  195709. {
  195710. const int keybyte = keycode >> 3;
  195711. const int keybit = (1 << (keycode & 7));
  195712. return (keyStates [keybyte] & keybit) != 0;
  195713. }
  195714. static const int extendedKeyModifier = 0x10000000;
  195715. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  195716. {
  195717. int keysym;
  195718. if (keyCode & extendedKeyModifier)
  195719. {
  195720. keysym = 0xff00 | (keyCode & 0xff);
  195721. }
  195722. else
  195723. {
  195724. keysym = keyCode;
  195725. if (keysym == (XK_Tab & 0xff)
  195726. || keysym == (XK_Return & 0xff)
  195727. || keysym == (XK_Escape & 0xff)
  195728. || keysym == (XK_BackSpace & 0xff))
  195729. {
  195730. keysym |= 0xff00;
  195731. }
  195732. }
  195733. ScopedXLock xlock;
  195734. return keyDown (XKeysymToKeycode (display, keysym));
  195735. }
  195736. // Alt and Num lock are not defined by standard X
  195737. // modifier constants: check what they're mapped to
  195738. static void getModifierMapping() throw()
  195739. {
  195740. ScopedXLock xlock;
  195741. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  195742. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  195743. AltMask = 0;
  195744. NumLockMask = 0;
  195745. XModifierKeymap* mapping = XGetModifierMapping (display);
  195746. if (mapping)
  195747. {
  195748. for (int i = 0; i < 8; i++)
  195749. {
  195750. if (mapping->modifiermap [i << 1] == altLeftCode)
  195751. AltMask = 1 << i;
  195752. else if (mapping->modifiermap [i << 1] == numLockCode)
  195753. NumLockMask = 1 << i;
  195754. }
  195755. XFreeModifiermap (mapping);
  195756. }
  195757. }
  195758. static int currentModifiers = 0;
  195759. void ModifierKeys::updateCurrentModifiers() throw()
  195760. {
  195761. currentModifierFlags = currentModifiers;
  195762. }
  195763. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  195764. {
  195765. int x, y, mouseMods;
  195766. getMousePos (x, y, mouseMods);
  195767. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  195768. currentModifiers |= mouseMods;
  195769. return ModifierKeys (currentModifiers);
  195770. }
  195771. static void updateKeyModifiers (const int status) throw()
  195772. {
  195773. currentModifiers &= ~(ModifierKeys::shiftModifier
  195774. | ModifierKeys::ctrlModifier
  195775. | ModifierKeys::altModifier);
  195776. if (status & ShiftMask)
  195777. currentModifiers |= ModifierKeys::shiftModifier;
  195778. if (status & ControlMask)
  195779. currentModifiers |= ModifierKeys::ctrlModifier;
  195780. if (status & AltMask)
  195781. currentModifiers |= ModifierKeys::altModifier;
  195782. numLock = ((status & NumLockMask) != 0);
  195783. capsLock = ((status & LockMask) != 0);
  195784. }
  195785. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  195786. {
  195787. int modifier = 0;
  195788. bool isModifier = true;
  195789. switch (sym)
  195790. {
  195791. case XK_Shift_L:
  195792. case XK_Shift_R:
  195793. modifier = ModifierKeys::shiftModifier;
  195794. break;
  195795. case XK_Control_L:
  195796. case XK_Control_R:
  195797. modifier = ModifierKeys::ctrlModifier;
  195798. break;
  195799. case XK_Alt_L:
  195800. case XK_Alt_R:
  195801. modifier = ModifierKeys::altModifier;
  195802. break;
  195803. case XK_Num_Lock:
  195804. if (press)
  195805. numLock = ! numLock;
  195806. break;
  195807. case XK_Caps_Lock:
  195808. if (press)
  195809. capsLock = ! capsLock;
  195810. break;
  195811. case XK_Scroll_Lock:
  195812. break;
  195813. default:
  195814. isModifier = false;
  195815. break;
  195816. }
  195817. if (modifier != 0)
  195818. {
  195819. if (press)
  195820. currentModifiers |= modifier;
  195821. else
  195822. currentModifiers &= ~modifier;
  195823. }
  195824. return isModifier;
  195825. }
  195826. #if JUCE_USE_XSHM
  195827. static bool isShmAvailable() throw()
  195828. {
  195829. ScopedXLock xlock;
  195830. static bool isChecked = false;
  195831. static bool isAvailable = false;
  195832. if (! isChecked)
  195833. {
  195834. isChecked = true;
  195835. int major, minor;
  195836. Bool pixmaps;
  195837. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195838. {
  195839. trapErrors();
  195840. XShmSegmentInfo segmentInfo;
  195841. zerostruct (segmentInfo);
  195842. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195843. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195844. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195845. xImage->bytes_per_line * xImage->height,
  195846. IPC_CREAT | 0777)) >= 0)
  195847. {
  195848. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195849. if (segmentInfo.shmaddr != (void*) -1)
  195850. {
  195851. segmentInfo.readOnly = False;
  195852. xImage->data = segmentInfo.shmaddr;
  195853. XSync (display, False);
  195854. if (XShmAttach (display, &segmentInfo) != 0)
  195855. {
  195856. XSync (display, False);
  195857. XShmDetach (display, &segmentInfo);
  195858. isAvailable = true;
  195859. }
  195860. }
  195861. XFlush (display);
  195862. XDestroyImage (xImage);
  195863. shmdt (segmentInfo.shmaddr);
  195864. }
  195865. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195866. isAvailable &= untrapErrors();
  195867. }
  195868. }
  195869. return isAvailable;
  195870. }
  195871. #endif
  195872. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  195873. {
  195874. ScopedXLock xlock;
  195875. const int width = image.getWidth();
  195876. const int height = image.getHeight();
  195877. HeapBlock <uint32> colour (width * height);
  195878. int index = 0;
  195879. for (int y = 0; y < height; ++y)
  195880. for (int x = 0; x < width; ++x)
  195881. colour[index++] = image.getPixelAt (x, y).getARGB();
  195882. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  195883. 0, (char*) colour, width, height, 32, 0);
  195884. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  195885. width, height, 24);
  195886. GC gc = XCreateGC (display, pixmap, 0, 0);
  195887. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  195888. XFreeGC (display, gc);
  195889. return pixmap;
  195890. }
  195891. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  195892. {
  195893. ScopedXLock xlock;
  195894. const int width = image.getWidth();
  195895. const int height = image.getHeight();
  195896. const int stride = (width + 7) >> 3;
  195897. HeapBlock <uint8> mask;
  195898. mask.calloc (stride * height);
  195899. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  195900. for (int y = 0; y < height; ++y)
  195901. {
  195902. for (int x = 0; x < width; ++x)
  195903. {
  195904. const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  195905. const int offset = y * stride + (x >> 3);
  195906. if (image.getPixelAt (x, y).getAlpha() >= 128)
  195907. mask[offset] |= bit;
  195908. }
  195909. }
  195910. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  195911. (char*) mask, width, height, 1, 0, 1);
  195912. }
  195913. class XBitmapImage : public Image
  195914. {
  195915. public:
  195916. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195917. const bool clearImage, const bool is16Bit_)
  195918. : Image (format_, w, h),
  195919. is16Bit (is16Bit_)
  195920. {
  195921. jassert (format_ == RGB || format_ == ARGB);
  195922. pixelStride = (format_ == RGB) ? 3 : 4;
  195923. lineStride = ((w * pixelStride + 3) & ~3);
  195924. ScopedXLock xlock;
  195925. Visual* const visual = DefaultVisual (display, DefaultScreen (display));
  195926. #if JUCE_USE_XSHM
  195927. usingXShm = false;
  195928. if ((! is16Bit) && isShmAvailable())
  195929. {
  195930. zerostruct (segmentInfo);
  195931. xImage = XShmCreateImage (display, visual, 24, ZPixmap, 0, &segmentInfo, w, h);
  195932. if (xImage != 0)
  195933. {
  195934. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195935. xImage->bytes_per_line * xImage->height,
  195936. IPC_CREAT | 0777)) >= 0)
  195937. {
  195938. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195939. if (segmentInfo.shmaddr != (void*) -1)
  195940. {
  195941. segmentInfo.readOnly = False;
  195942. xImage->data = segmentInfo.shmaddr;
  195943. imageData = (uint8*) segmentInfo.shmaddr;
  195944. XSync (display, False);
  195945. if (XShmAttach (display, &segmentInfo) != 0)
  195946. {
  195947. XSync (display, False);
  195948. usingXShm = true;
  195949. }
  195950. else
  195951. {
  195952. jassertfalse
  195953. }
  195954. }
  195955. else
  195956. {
  195957. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195958. }
  195959. }
  195960. }
  195961. }
  195962. if (! usingXShm)
  195963. #endif
  195964. {
  195965. imageDataAllocated.malloc (lineStride * h);
  195966. imageData = imageDataAllocated;
  195967. if (format_ == ARGB && clearImage)
  195968. zeromem (imageData, h * lineStride);
  195969. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195970. xImage->width = w;
  195971. xImage->height = h;
  195972. xImage->xoffset = 0;
  195973. xImage->format = ZPixmap;
  195974. xImage->data = (char*) imageData;
  195975. xImage->byte_order = ImageByteOrder (display);
  195976. xImage->bitmap_unit = BitmapUnit (display);
  195977. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195978. xImage->bitmap_pad = 32;
  195979. xImage->depth = pixelStride * 8;
  195980. xImage->bytes_per_line = lineStride;
  195981. xImage->bits_per_pixel = pixelStride * 8;
  195982. xImage->red_mask = 0x00FF0000;
  195983. xImage->green_mask = 0x0000FF00;
  195984. xImage->blue_mask = 0x000000FF;
  195985. if (is16Bit)
  195986. {
  195987. const int pixelStride = 2;
  195988. const int lineStride = ((w * pixelStride + 3) & ~3);
  195989. imageData16Bit.malloc (lineStride * h);
  195990. xImage->data = imageData16Bit;
  195991. xImage->bitmap_pad = 16;
  195992. xImage->depth = pixelStride * 8;
  195993. xImage->bytes_per_line = lineStride;
  195994. xImage->bits_per_pixel = pixelStride * 8;
  195995. xImage->red_mask = visual->red_mask;
  195996. xImage->green_mask = visual->green_mask;
  195997. xImage->blue_mask = visual->blue_mask;
  195998. }
  195999. if (! XInitImage (xImage))
  196000. {
  196001. jassertfalse
  196002. }
  196003. }
  196004. }
  196005. ~XBitmapImage()
  196006. {
  196007. ScopedXLock xlock;
  196008. #if JUCE_USE_XSHM
  196009. if (usingXShm)
  196010. {
  196011. XShmDetach (display, &segmentInfo);
  196012. XFlush (display);
  196013. XDestroyImage (xImage);
  196014. shmdt (segmentInfo.shmaddr);
  196015. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  196016. }
  196017. else
  196018. #endif
  196019. {
  196020. xImage->data = 0;
  196021. XDestroyImage (xImage);
  196022. }
  196023. }
  196024. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  196025. {
  196026. ScopedXLock xlock;
  196027. static GC gc = 0;
  196028. if (gc == 0)
  196029. gc = DefaultGC (display, DefaultScreen (display));
  196030. if (is16Bit)
  196031. {
  196032. const uint32 rMask = xImage->red_mask;
  196033. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  196034. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  196035. const uint32 gMask = xImage->green_mask;
  196036. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  196037. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  196038. const uint32 bMask = xImage->blue_mask;
  196039. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  196040. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  196041. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  196042. for (int y = sy; y < sy + dh; ++y)
  196043. {
  196044. const uint8* p = srcData.getPixelPointer (sx, y);
  196045. for (int x = sx; x < sx + dw; ++x)
  196046. {
  196047. const PixelRGB* const pixel = (const PixelRGB*) p;
  196048. p += srcData.pixelStride;
  196049. XPutPixel (xImage, x, y,
  196050. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  196051. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  196052. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  196053. }
  196054. }
  196055. }
  196056. // blit results to screen.
  196057. #if JUCE_USE_XSHM
  196058. if (usingXShm)
  196059. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  196060. else
  196061. #endif
  196062. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  196063. }
  196064. juce_UseDebuggingNewOperator
  196065. private:
  196066. XImage* xImage;
  196067. const bool is16Bit;
  196068. HeapBlock <char> imageData16Bit;
  196069. #if JUCE_USE_XSHM
  196070. XShmSegmentInfo segmentInfo;
  196071. bool usingXShm;
  196072. #endif
  196073. static int getShiftNeeded (const uint32 mask) throw()
  196074. {
  196075. for (int i = 32; --i >= 0;)
  196076. if (((mask >> i) & 1) != 0)
  196077. return i - 7;
  196078. jassertfalse
  196079. return 0;
  196080. }
  196081. };
  196082. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  196083. class LinuxComponentPeer : public ComponentPeer
  196084. {
  196085. public:
  196086. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  196087. : ComponentPeer (component, windowStyleFlags),
  196088. windowH (0),
  196089. parentWindow (0),
  196090. wx (0),
  196091. wy (0),
  196092. ww (0),
  196093. wh (0),
  196094. taskbarImage (0),
  196095. fullScreen (false),
  196096. entered (false),
  196097. mapped (false)
  196098. {
  196099. // it's dangerous to create a window on a thread other than the message thread..
  196100. checkMessageManagerIsLocked
  196101. repainter = new LinuxRepaintManager (this);
  196102. createWindow();
  196103. setTitle (component->getName());
  196104. }
  196105. ~LinuxComponentPeer()
  196106. {
  196107. // it's dangerous to delete a window on a thread other than the message thread..
  196108. checkMessageManagerIsLocked
  196109. deleteTaskBarIcon();
  196110. deleteIconPixmaps();
  196111. destroyWindow();
  196112. windowH = 0;
  196113. }
  196114. void* getNativeHandle() const
  196115. {
  196116. return (void*) windowH;
  196117. }
  196118. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  196119. {
  196120. XPointer peer = 0;
  196121. ScopedXLock xlock;
  196122. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  196123. {
  196124. if (peer != 0 && ! ((LinuxComponentPeer*) peer)->isValidMessageListener())
  196125. peer = 0;
  196126. }
  196127. return (LinuxComponentPeer*) peer;
  196128. }
  196129. void setVisible (bool shouldBeVisible)
  196130. {
  196131. ScopedXLock xlock;
  196132. if (shouldBeVisible)
  196133. XMapWindow (display, windowH);
  196134. else
  196135. XUnmapWindow (display, windowH);
  196136. }
  196137. void setTitle (const String& title)
  196138. {
  196139. setWindowTitle (windowH, title);
  196140. }
  196141. void setPosition (int x, int y)
  196142. {
  196143. setBounds (x, y, ww, wh, false);
  196144. }
  196145. void setSize (int w, int h)
  196146. {
  196147. setBounds (wx, wy, w, h, false);
  196148. }
  196149. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  196150. {
  196151. fullScreen = isNowFullScreen;
  196152. if (windowH != 0)
  196153. {
  196154. const ComponentDeletionWatcher deletionChecker (component);
  196155. wx = x;
  196156. wy = y;
  196157. ww = jmax (1, w);
  196158. wh = jmax (1, h);
  196159. ScopedXLock xlock;
  196160. // Make sure the Window manager does what we want
  196161. XSizeHints* hints = XAllocSizeHints();
  196162. hints->flags = USSize | USPosition;
  196163. hints->width = ww;
  196164. hints->height = wh;
  196165. hints->x = wx;
  196166. hints->y = wy;
  196167. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  196168. {
  196169. hints->min_width = hints->max_width = hints->width;
  196170. hints->min_height = hints->max_height = hints->height;
  196171. hints->flags |= PMinSize | PMaxSize;
  196172. }
  196173. XSetWMNormalHints (display, windowH, hints);
  196174. XFree (hints);
  196175. XMoveResizeWindow (display, windowH,
  196176. wx - windowBorder.getLeft(),
  196177. wy - windowBorder.getTop(), ww, wh);
  196178. if (! deletionChecker.hasBeenDeleted())
  196179. {
  196180. updateBorderSize();
  196181. handleMovedOrResized();
  196182. }
  196183. }
  196184. }
  196185. void getBounds (int& x, int& y, int& w, int& h) const
  196186. {
  196187. x = wx;
  196188. y = wy;
  196189. w = ww;
  196190. h = wh;
  196191. }
  196192. int getScreenX() const
  196193. {
  196194. return wx;
  196195. }
  196196. int getScreenY() const
  196197. {
  196198. return wy;
  196199. }
  196200. void relativePositionToGlobal (int& x, int& y)
  196201. {
  196202. x += wx;
  196203. y += wy;
  196204. }
  196205. void globalPositionToRelative (int& x, int& y)
  196206. {
  196207. x -= wx;
  196208. y -= wy;
  196209. }
  196210. void setMinimised (bool shouldBeMinimised)
  196211. {
  196212. if (shouldBeMinimised)
  196213. {
  196214. Window root = RootWindow (display, DefaultScreen (display));
  196215. XClientMessageEvent clientMsg;
  196216. clientMsg.display = display;
  196217. clientMsg.window = windowH;
  196218. clientMsg.type = ClientMessage;
  196219. clientMsg.format = 32;
  196220. clientMsg.message_type = wm_ChangeState;
  196221. clientMsg.data.l[0] = IconicState;
  196222. ScopedXLock xlock;
  196223. XSendEvent (display, root, false,
  196224. SubstructureRedirectMask | SubstructureNotifyMask,
  196225. (XEvent*) &clientMsg);
  196226. }
  196227. else
  196228. {
  196229. setVisible (true);
  196230. }
  196231. }
  196232. bool isMinimised() const
  196233. {
  196234. bool minimised = false;
  196235. unsigned char* stateProp;
  196236. unsigned long nitems, bytesLeft;
  196237. Atom actualType;
  196238. int actualFormat;
  196239. ScopedXLock xlock;
  196240. if (XGetWindowProperty (display, windowH, wm_State, 0, 64, False,
  196241. wm_State, &actualType, &actualFormat, &nitems, &bytesLeft,
  196242. &stateProp) == Success
  196243. && actualType == wm_State
  196244. && actualFormat == 32
  196245. && nitems > 0)
  196246. {
  196247. if (((unsigned long*) stateProp)[0] == IconicState)
  196248. minimised = true;
  196249. XFree (stateProp);
  196250. }
  196251. return minimised;
  196252. }
  196253. void setFullScreen (const bool shouldBeFullScreen)
  196254. {
  196255. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  196256. setMinimised (false);
  196257. if (fullScreen != shouldBeFullScreen)
  196258. {
  196259. if (shouldBeFullScreen)
  196260. r = Desktop::getInstance().getMainMonitorArea();
  196261. if (! r.isEmpty())
  196262. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  196263. getComponent()->repaint();
  196264. }
  196265. }
  196266. bool isFullScreen() const
  196267. {
  196268. return fullScreen;
  196269. }
  196270. bool isChildWindowOf (Window possibleParent) const
  196271. {
  196272. Window* windowList = 0;
  196273. uint32 windowListSize = 0;
  196274. Window parent, root;
  196275. ScopedXLock xlock;
  196276. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  196277. {
  196278. if (windowList != 0)
  196279. XFree (windowList);
  196280. return parent == possibleParent;
  196281. }
  196282. return false;
  196283. }
  196284. bool isFrontWindow() const
  196285. {
  196286. Window* windowList = 0;
  196287. uint32 windowListSize = 0;
  196288. bool result = false;
  196289. ScopedXLock xlock;
  196290. Window parent, root = RootWindow (display, DefaultScreen (display));
  196291. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  196292. {
  196293. for (int i = windowListSize; --i >= 0;)
  196294. {
  196295. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  196296. if (peer != 0)
  196297. {
  196298. result = (peer == this);
  196299. break;
  196300. }
  196301. }
  196302. }
  196303. if (windowList != 0)
  196304. XFree (windowList);
  196305. return result;
  196306. }
  196307. bool contains (int x, int y, bool trueIfInAChildWindow) const
  196308. {
  196309. jassert (x >= 0 && y >= 0 && x < ww && y < wh); // should only be called for points that are actually inside the bounds
  196310. if (((unsigned int) x) >= (unsigned int) ww
  196311. || ((unsigned int) y) >= (unsigned int) wh)
  196312. return false;
  196313. bool inFront = false;
  196314. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  196315. {
  196316. Component* const c = Desktop::getInstance().getComponent (i);
  196317. if (inFront)
  196318. {
  196319. if (c->contains (x + wx - c->getScreenX(),
  196320. y + wy - c->getScreenY()))
  196321. {
  196322. return false;
  196323. }
  196324. }
  196325. else if (c == getComponent())
  196326. {
  196327. inFront = true;
  196328. }
  196329. }
  196330. if (trueIfInAChildWindow)
  196331. return true;
  196332. ::Window root, child;
  196333. unsigned int bw, depth;
  196334. int wx, wy, w, h;
  196335. ScopedXLock xlock;
  196336. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196337. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  196338. &bw, &depth))
  196339. {
  196340. return false;
  196341. }
  196342. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  196343. return false;
  196344. return child == None;
  196345. }
  196346. const BorderSize getFrameSize() const
  196347. {
  196348. return BorderSize();
  196349. }
  196350. bool setAlwaysOnTop (bool alwaysOnTop)
  196351. {
  196352. if (windowH != 0)
  196353. {
  196354. const bool wasVisible = component->isVisible();
  196355. if (wasVisible)
  196356. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  196357. {
  196358. ScopedXLock xlock;
  196359. XSetWindowAttributes swa;
  196360. swa.override_redirect = alwaysOnTop ? True : False;
  196361. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  196362. }
  196363. if (wasVisible)
  196364. setVisible (true);
  196365. }
  196366. return true;
  196367. }
  196368. void toFront (bool makeActive)
  196369. {
  196370. if (makeActive)
  196371. {
  196372. setVisible (true);
  196373. grabFocus();
  196374. }
  196375. XEvent ev;
  196376. ev.xclient.type = ClientMessage;
  196377. ev.xclient.serial = 0;
  196378. ev.xclient.send_event = True;
  196379. ev.xclient.message_type = wm_ActiveWin;
  196380. ev.xclient.window = windowH;
  196381. ev.xclient.format = 32;
  196382. ev.xclient.data.l[0] = 2;
  196383. ev.xclient.data.l[1] = CurrentTime;
  196384. ev.xclient.data.l[2] = 0;
  196385. ev.xclient.data.l[3] = 0;
  196386. ev.xclient.data.l[4] = 0;
  196387. {
  196388. ScopedXLock xlock;
  196389. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  196390. False,
  196391. SubstructureRedirectMask | SubstructureNotifyMask,
  196392. &ev);
  196393. XWindowAttributes attr;
  196394. XGetWindowAttributes (display, windowH, &attr);
  196395. if (attr.override_redirect)
  196396. XRaiseWindow (display, windowH);
  196397. XSync (display, False);
  196398. }
  196399. handleBroughtToFront();
  196400. }
  196401. void toBehind (ComponentPeer* other)
  196402. {
  196403. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  196404. jassert (otherPeer != 0); // wrong type of window?
  196405. if (otherPeer != 0)
  196406. {
  196407. setMinimised (false);
  196408. Window newStack[] = { otherPeer->windowH, windowH };
  196409. ScopedXLock xlock;
  196410. XRestackWindows (display, newStack, 2);
  196411. }
  196412. }
  196413. bool isFocused() const
  196414. {
  196415. int revert;
  196416. Window focusedWindow = 0;
  196417. ScopedXLock xlock;
  196418. XGetInputFocus (display, &focusedWindow, &revert);
  196419. return focusedWindow == windowH;
  196420. }
  196421. void grabFocus()
  196422. {
  196423. XWindowAttributes atts;
  196424. ScopedXLock xlock;
  196425. if (windowH != 0
  196426. && XGetWindowAttributes (display, windowH, &atts)
  196427. && atts.map_state == IsViewable
  196428. && ! isFocused())
  196429. {
  196430. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  196431. isActiveApplication = true;
  196432. }
  196433. }
  196434. void textInputRequired (int /*x*/, int /*y*/)
  196435. {
  196436. }
  196437. void repaint (int x, int y, int w, int h)
  196438. {
  196439. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  196440. 0, 0,
  196441. getComponent()->getWidth(),
  196442. getComponent()->getHeight()))
  196443. {
  196444. repainter->repaint (x, y, w, h);
  196445. }
  196446. }
  196447. void performAnyPendingRepaintsNow()
  196448. {
  196449. repainter->performAnyPendingRepaintsNow();
  196450. }
  196451. void setIcon (const Image& newIcon)
  196452. {
  196453. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  196454. HeapBlock <unsigned long> data (dataSize);
  196455. int index = 0;
  196456. data[index++] = newIcon.getWidth();
  196457. data[index++] = newIcon.getHeight();
  196458. for (int y = 0; y < newIcon.getHeight(); ++y)
  196459. for (int x = 0; x < newIcon.getWidth(); ++x)
  196460. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  196461. ScopedXLock xlock;
  196462. XChangeProperty (display, windowH,
  196463. XInternAtom (display, "_NET_WM_ICON", False),
  196464. XA_CARDINAL, 32, PropModeReplace,
  196465. (unsigned char*) data, dataSize);
  196466. deleteIconPixmaps();
  196467. XWMHints* wmHints = XGetWMHints (display, windowH);
  196468. if (wmHints == 0)
  196469. wmHints = XAllocWMHints();
  196470. wmHints->flags |= IconPixmapHint | IconMaskHint;
  196471. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  196472. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  196473. XSetWMHints (display, windowH, wmHints);
  196474. XFree (wmHints);
  196475. XSync (display, False);
  196476. }
  196477. void deleteIconPixmaps()
  196478. {
  196479. ScopedXLock xlock;
  196480. XWMHints* wmHints = XGetWMHints (display, windowH);
  196481. if (wmHints != 0)
  196482. {
  196483. if ((wmHints->flags & IconPixmapHint) != 0)
  196484. {
  196485. wmHints->flags &= ~IconPixmapHint;
  196486. XFreePixmap (display, wmHints->icon_pixmap);
  196487. }
  196488. if ((wmHints->flags & IconMaskHint) != 0)
  196489. {
  196490. wmHints->flags &= ~IconMaskHint;
  196491. XFreePixmap (display, wmHints->icon_mask);
  196492. }
  196493. XSetWMHints (display, windowH, wmHints);
  196494. XFree (wmHints);
  196495. }
  196496. }
  196497. void handleWindowMessage (XEvent* event)
  196498. {
  196499. switch (event->xany.type)
  196500. {
  196501. case 2: // 'KeyPress'
  196502. {
  196503. ScopedXLock xlock;
  196504. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  196505. updateKeyStates (keyEvent->keycode, true);
  196506. char utf8 [64];
  196507. zeromem (utf8, sizeof (utf8));
  196508. KeySym sym;
  196509. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  196510. const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 ((const uint8*) utf8, sizeof (utf8) - 1);
  196511. int keyCode = (int) unicodeChar;
  196512. if (keyCode < 0x20)
  196513. keyCode = XKeycodeToKeysym (display, keyEvent->keycode,
  196514. (currentModifiers & ModifierKeys::shiftModifier) != 0 ? 1 : 0);
  196515. const int oldMods = currentModifiers;
  196516. bool keyPressed = false;
  196517. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  196518. if ((sym & 0xff00) == 0xff00)
  196519. {
  196520. // Translate keypad
  196521. if (sym == XK_KP_Divide)
  196522. keyCode = XK_slash;
  196523. else if (sym == XK_KP_Multiply)
  196524. keyCode = XK_asterisk;
  196525. else if (sym == XK_KP_Subtract)
  196526. keyCode = XK_hyphen;
  196527. else if (sym == XK_KP_Add)
  196528. keyCode = XK_plus;
  196529. else if (sym == XK_KP_Enter)
  196530. keyCode = XK_Return;
  196531. else if (sym == XK_KP_Decimal)
  196532. keyCode = numLock ? XK_period : XK_Delete;
  196533. else if (sym == XK_KP_0)
  196534. keyCode = numLock ? XK_0 : XK_Insert;
  196535. else if (sym == XK_KP_1)
  196536. keyCode = numLock ? XK_1 : XK_End;
  196537. else if (sym == XK_KP_2)
  196538. keyCode = numLock ? XK_2 : XK_Down;
  196539. else if (sym == XK_KP_3)
  196540. keyCode = numLock ? XK_3 : XK_Page_Down;
  196541. else if (sym == XK_KP_4)
  196542. keyCode = numLock ? XK_4 : XK_Left;
  196543. else if (sym == XK_KP_5)
  196544. keyCode = XK_5;
  196545. else if (sym == XK_KP_6)
  196546. keyCode = numLock ? XK_6 : XK_Right;
  196547. else if (sym == XK_KP_7)
  196548. keyCode = numLock ? XK_7 : XK_Home;
  196549. else if (sym == XK_KP_8)
  196550. keyCode = numLock ? XK_8 : XK_Up;
  196551. else if (sym == XK_KP_9)
  196552. keyCode = numLock ? XK_9 : XK_Page_Up;
  196553. switch (sym)
  196554. {
  196555. case XK_Left:
  196556. case XK_Right:
  196557. case XK_Up:
  196558. case XK_Down:
  196559. case XK_Page_Up:
  196560. case XK_Page_Down:
  196561. case XK_End:
  196562. case XK_Home:
  196563. case XK_Delete:
  196564. case XK_Insert:
  196565. keyPressed = true;
  196566. keyCode = (sym & 0xff) | extendedKeyModifier;
  196567. break;
  196568. case XK_Tab:
  196569. case XK_Return:
  196570. case XK_Escape:
  196571. case XK_BackSpace:
  196572. keyPressed = true;
  196573. keyCode &= 0xff;
  196574. break;
  196575. default:
  196576. {
  196577. if (sym >= XK_F1 && sym <= XK_F16)
  196578. {
  196579. keyPressed = true;
  196580. keyCode = (sym & 0xff) | extendedKeyModifier;
  196581. }
  196582. break;
  196583. }
  196584. }
  196585. }
  196586. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196587. keyPressed = true;
  196588. if (oldMods != currentModifiers)
  196589. handleModifierKeysChange();
  196590. if (keyDownChange)
  196591. handleKeyUpOrDown (true);
  196592. if (keyPressed)
  196593. handleKeyPress (keyCode, unicodeChar);
  196594. break;
  196595. }
  196596. case KeyRelease:
  196597. {
  196598. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196599. updateKeyStates (keyEvent->keycode, false);
  196600. ScopedXLock xlock;
  196601. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196602. const int oldMods = currentModifiers;
  196603. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196604. if (oldMods != currentModifiers)
  196605. handleModifierKeysChange();
  196606. if (keyDownChange)
  196607. handleKeyUpOrDown (false);
  196608. break;
  196609. }
  196610. case ButtonPress:
  196611. {
  196612. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196613. bool buttonMsg = false;
  196614. bool wheelUpMsg = false;
  196615. bool wheelDownMsg = false;
  196616. const int map = pointerMap [buttonPressEvent->button - Button1];
  196617. if (map == LeftButton)
  196618. {
  196619. currentModifiers |= ModifierKeys::leftButtonModifier;
  196620. buttonMsg = true;
  196621. }
  196622. else if (map == RightButton)
  196623. {
  196624. currentModifiers |= ModifierKeys::rightButtonModifier;
  196625. buttonMsg = true;
  196626. }
  196627. else if (map == MiddleButton)
  196628. {
  196629. currentModifiers |= ModifierKeys::middleButtonModifier;
  196630. buttonMsg = true;
  196631. }
  196632. else if (map == WheelUp)
  196633. {
  196634. wheelUpMsg = true;
  196635. }
  196636. else if (map == WheelDown)
  196637. {
  196638. wheelDownMsg = true;
  196639. }
  196640. updateKeyModifiers (buttonPressEvent->state);
  196641. if (buttonMsg)
  196642. {
  196643. toFront (true);
  196644. handleMouseDown (buttonPressEvent->x, buttonPressEvent->y,
  196645. getEventTime (buttonPressEvent->time));
  196646. }
  196647. else if (wheelUpMsg || wheelDownMsg)
  196648. {
  196649. handleMouseWheel (0, wheelDownMsg ? -84 : 84,
  196650. getEventTime (buttonPressEvent->time));
  196651. }
  196652. lastMousePosX = lastMousePosY = 0x100000;
  196653. break;
  196654. }
  196655. case ButtonRelease:
  196656. {
  196657. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196658. const int oldModifiers = currentModifiers;
  196659. const int map = pointerMap [buttonRelEvent->button - Button1];
  196660. if (map == LeftButton)
  196661. currentModifiers &= ~ModifierKeys::leftButtonModifier;
  196662. else if (map == RightButton)
  196663. currentModifiers &= ~ModifierKeys::rightButtonModifier;
  196664. else if (map == MiddleButton)
  196665. currentModifiers &= ~ModifierKeys::middleButtonModifier;
  196666. updateKeyModifiers (buttonRelEvent->state);
  196667. handleMouseUp (oldModifiers,
  196668. buttonRelEvent->x, buttonRelEvent->y,
  196669. getEventTime (buttonRelEvent->time));
  196670. lastMousePosX = lastMousePosY = 0x100000;
  196671. break;
  196672. }
  196673. case MotionNotify:
  196674. {
  196675. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196676. updateKeyModifiers (movedEvent->state);
  196677. int x, y, mouseMods;
  196678. getMousePos (x, y, mouseMods);
  196679. if (lastMousePosX != x || lastMousePosY != y)
  196680. {
  196681. lastMousePosX = x;
  196682. lastMousePosY = y;
  196683. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196684. {
  196685. Window wRoot = 0, wParent = 0;
  196686. Window* wChild = 0;
  196687. unsigned int numChildren;
  196688. {
  196689. ScopedXLock xlock;
  196690. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196691. }
  196692. if (wParent != 0
  196693. && wParent != windowH
  196694. && wParent != wRoot)
  196695. {
  196696. parentWindow = wParent;
  196697. updateBounds();
  196698. x -= getScreenX();
  196699. y -= getScreenY();
  196700. }
  196701. else
  196702. {
  196703. parentWindow = 0;
  196704. x -= getScreenX();
  196705. y -= getScreenY();
  196706. }
  196707. }
  196708. else
  196709. {
  196710. x -= getScreenX();
  196711. y -= getScreenY();
  196712. }
  196713. if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0)
  196714. handleMouseMove (x, y, getEventTime (movedEvent->time));
  196715. else
  196716. handleMouseDrag (x, y, getEventTime (movedEvent->time));
  196717. }
  196718. break;
  196719. }
  196720. case EnterNotify:
  196721. {
  196722. lastMousePosX = lastMousePosY = 0x100000;
  196723. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196724. if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0
  196725. && ! entered)
  196726. {
  196727. updateKeyModifiers (enterEvent->state);
  196728. handleMouseEnter (enterEvent->x, enterEvent->y, getEventTime (enterEvent->time));
  196729. entered = true;
  196730. }
  196731. break;
  196732. }
  196733. case LeaveNotify:
  196734. {
  196735. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196736. // Suppress the normal leave if we've got a pointer grab, or if
  196737. // it's a bogus one caused by clicking a mouse button when running
  196738. // in a Window manager
  196739. if (((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0
  196740. && leaveEvent->mode == NotifyNormal)
  196741. || leaveEvent->mode == NotifyUngrab)
  196742. {
  196743. updateKeyModifiers (leaveEvent->state);
  196744. handleMouseExit (leaveEvent->x, leaveEvent->y, getEventTime (leaveEvent->time));
  196745. entered = false;
  196746. }
  196747. break;
  196748. }
  196749. case FocusIn:
  196750. {
  196751. isActiveApplication = true;
  196752. if (isFocused())
  196753. handleFocusGain();
  196754. break;
  196755. }
  196756. case FocusOut:
  196757. {
  196758. isActiveApplication = false;
  196759. if (! isFocused())
  196760. handleFocusLoss();
  196761. break;
  196762. }
  196763. case Expose:
  196764. {
  196765. // Batch together all pending expose events
  196766. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196767. XEvent nextEvent;
  196768. ScopedXLock xlock;
  196769. if (exposeEvent->window != windowH)
  196770. {
  196771. Window child;
  196772. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196773. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196774. &child);
  196775. }
  196776. repaint (exposeEvent->x, exposeEvent->y,
  196777. exposeEvent->width, exposeEvent->height);
  196778. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196779. {
  196780. XPeekEvent (display, (XEvent*) &nextEvent);
  196781. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196782. break;
  196783. XNextEvent (display, (XEvent*) &nextEvent);
  196784. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196785. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196786. nextExposeEvent->width, nextExposeEvent->height);
  196787. }
  196788. break;
  196789. }
  196790. case CirculateNotify:
  196791. case CreateNotify:
  196792. case DestroyNotify:
  196793. // Think we can ignore these
  196794. break;
  196795. case ConfigureNotify:
  196796. {
  196797. updateBounds();
  196798. updateBorderSize();
  196799. handleMovedOrResized();
  196800. // if the native title bar is dragged, need to tell any active menus, etc.
  196801. if ((styleFlags & windowHasTitleBar) != 0
  196802. && component->isCurrentlyBlockedByAnotherModalComponent())
  196803. {
  196804. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196805. if (currentModalComp != 0)
  196806. currentModalComp->inputAttemptWhenModal();
  196807. }
  196808. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196809. if (confEvent->window == windowH
  196810. && confEvent->above != 0
  196811. && isFrontWindow())
  196812. {
  196813. handleBroughtToFront();
  196814. }
  196815. break;
  196816. }
  196817. case ReparentNotify:
  196818. case GravityNotify:
  196819. {
  196820. parentWindow = 0;
  196821. Window wRoot = 0;
  196822. Window* wChild = 0;
  196823. unsigned int numChildren;
  196824. {
  196825. ScopedXLock xlock;
  196826. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196827. }
  196828. if (parentWindow == windowH || parentWindow == wRoot)
  196829. parentWindow = 0;
  196830. updateBounds();
  196831. updateBorderSize();
  196832. handleMovedOrResized();
  196833. break;
  196834. }
  196835. case MapNotify:
  196836. mapped = true;
  196837. handleBroughtToFront();
  196838. break;
  196839. case UnmapNotify:
  196840. mapped = false;
  196841. break;
  196842. case MappingNotify:
  196843. {
  196844. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196845. if (mappingEvent->request != MappingPointer)
  196846. {
  196847. // Deal with modifier/keyboard mapping
  196848. ScopedXLock xlock;
  196849. XRefreshKeyboardMapping (mappingEvent);
  196850. getModifierMapping();
  196851. }
  196852. break;
  196853. }
  196854. case ClientMessage:
  196855. {
  196856. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196857. if (clientMsg->message_type == wm_Protocols && clientMsg->format == 32)
  196858. {
  196859. const Atom atom = (Atom) clientMsg->data.l[0];
  196860. if (atom == wm_ProtocolList [TAKE_FOCUS])
  196861. {
  196862. XWindowAttributes atts;
  196863. ScopedXLock xlock;
  196864. if (clientMsg->window != 0
  196865. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196866. {
  196867. if (atts.map_state == IsViewable)
  196868. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196869. }
  196870. }
  196871. else if (atom == wm_ProtocolList [DELETE_WINDOW])
  196872. {
  196873. handleUserClosingWindow();
  196874. }
  196875. }
  196876. else if (clientMsg->message_type == XA_XdndEnter)
  196877. {
  196878. handleDragAndDropEnter (clientMsg);
  196879. }
  196880. else if (clientMsg->message_type == XA_XdndLeave)
  196881. {
  196882. resetDragAndDrop();
  196883. }
  196884. else if (clientMsg->message_type == XA_XdndPosition)
  196885. {
  196886. handleDragAndDropPosition (clientMsg);
  196887. }
  196888. else if (clientMsg->message_type == XA_XdndDrop)
  196889. {
  196890. handleDragAndDropDrop (clientMsg);
  196891. }
  196892. else if (clientMsg->message_type == XA_XdndStatus)
  196893. {
  196894. handleDragAndDropStatus (clientMsg);
  196895. }
  196896. else if (clientMsg->message_type == XA_XdndFinished)
  196897. {
  196898. resetDragAndDrop();
  196899. }
  196900. break;
  196901. }
  196902. case SelectionNotify:
  196903. handleDragAndDropSelection (event);
  196904. break;
  196905. case SelectionClear:
  196906. case SelectionRequest:
  196907. break;
  196908. default:
  196909. #if JUCE_USE_XSHM
  196910. {
  196911. ScopedXLock xlock;
  196912. if (event->xany.type == XShmGetEventBase (display))
  196913. repainter->notifyPaintCompleted();
  196914. }
  196915. #endif
  196916. break;
  196917. }
  196918. }
  196919. void showMouseCursor (Cursor cursor) throw()
  196920. {
  196921. ScopedXLock xlock;
  196922. XDefineCursor (display, windowH, cursor);
  196923. }
  196924. void setTaskBarIcon (const Image& image)
  196925. {
  196926. ScopedXLock xlock;
  196927. deleteTaskBarIcon();
  196928. taskbarImage = image.createCopy();
  196929. Screen* const screen = XDefaultScreenOfDisplay (display);
  196930. const int screenNumber = XScreenNumberOfScreen (screen);
  196931. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196932. screenAtom << screenNumber;
  196933. Atom selectionAtom = XInternAtom (display, (const char*) screenAtom, false);
  196934. XGrabServer (display);
  196935. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196936. if (managerWin != None)
  196937. XSelectInput (display, managerWin, StructureNotifyMask);
  196938. XUngrabServer (display);
  196939. XFlush (display);
  196940. if (managerWin != None)
  196941. {
  196942. XEvent ev;
  196943. zerostruct (ev);
  196944. ev.xclient.type = ClientMessage;
  196945. ev.xclient.window = managerWin;
  196946. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196947. ev.xclient.format = 32;
  196948. ev.xclient.data.l[0] = CurrentTime;
  196949. ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
  196950. ev.xclient.data.l[2] = windowH;
  196951. ev.xclient.data.l[3] = 0;
  196952. ev.xclient.data.l[4] = 0;
  196953. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196954. XSync (display, False);
  196955. }
  196956. // For older KDE's ...
  196957. long atomData = 1;
  196958. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196959. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196960. // For more recent KDE's...
  196961. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196962. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196963. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196964. XSizeHints* hints = XAllocSizeHints();
  196965. hints->flags = PMinSize;
  196966. hints->min_width = 22;
  196967. hints->min_height = 22;
  196968. XSetWMNormalHints (display, windowH, hints);
  196969. XFree (hints);
  196970. }
  196971. void deleteTaskBarIcon()
  196972. {
  196973. deleteAndZero (taskbarImage);
  196974. }
  196975. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196976. juce_UseDebuggingNewOperator
  196977. bool dontRepaint;
  196978. private:
  196979. class LinuxRepaintManager : public Timer
  196980. {
  196981. public:
  196982. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196983. : peer (peer_),
  196984. lastTimeImageUsed (0)
  196985. {
  196986. #if JUCE_USE_XSHM
  196987. shmCompletedDrawing = true;
  196988. useARGBImagesForRendering = isShmAvailable();
  196989. if (useARGBImagesForRendering)
  196990. {
  196991. ScopedXLock xlock;
  196992. XShmSegmentInfo segmentinfo;
  196993. XImage* const testImage
  196994. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196995. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196996. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196997. XDestroyImage (testImage);
  196998. }
  196999. #endif
  197000. }
  197001. ~LinuxRepaintManager()
  197002. {
  197003. }
  197004. void timerCallback()
  197005. {
  197006. #if JUCE_USE_XSHM
  197007. if (! shmCompletedDrawing)
  197008. return;
  197009. #endif
  197010. if (! regionsNeedingRepaint.isEmpty())
  197011. {
  197012. stopTimer();
  197013. performAnyPendingRepaintsNow();
  197014. }
  197015. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  197016. {
  197017. stopTimer();
  197018. image = 0;
  197019. }
  197020. }
  197021. void repaint (int x, int y, int w, int h)
  197022. {
  197023. if (! isTimerRunning())
  197024. startTimer (repaintTimerPeriod);
  197025. regionsNeedingRepaint.add (x, y, w, h);
  197026. }
  197027. void performAnyPendingRepaintsNow()
  197028. {
  197029. #if JUCE_USE_XSHM
  197030. if (! shmCompletedDrawing)
  197031. {
  197032. startTimer (repaintTimerPeriod);
  197033. return;
  197034. }
  197035. #endif
  197036. peer->clearMaskedRegion();
  197037. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  197038. regionsNeedingRepaint.clear();
  197039. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  197040. if (! totalArea.isEmpty())
  197041. {
  197042. if (image == 0 || image->getWidth() < totalArea.getWidth()
  197043. || image->getHeight() < totalArea.getHeight())
  197044. {
  197045. #if JUCE_USE_XSHM
  197046. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  197047. : Image::RGB,
  197048. #else
  197049. image = new XBitmapImage (Image::RGB,
  197050. #endif
  197051. (totalArea.getWidth() + 31) & ~31,
  197052. (totalArea.getHeight() + 31) & ~31,
  197053. false,
  197054. peer->depthIs16Bit);
  197055. }
  197056. startTimer (repaintTimerPeriod);
  197057. LowLevelGraphicsSoftwareRenderer context (*image);
  197058. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  197059. if (context.clipToRectangleList (originalRepaintRegion))
  197060. peer->handlePaint (context);
  197061. if (! peer->maskedRegion.isEmpty())
  197062. originalRepaintRegion.subtract (peer->maskedRegion);
  197063. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  197064. {
  197065. #if JUCE_USE_XSHM
  197066. shmCompletedDrawing = false;
  197067. #endif
  197068. const Rectangle<int>& r = *i.getRectangle();
  197069. image->blitToWindow (peer->windowH,
  197070. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  197071. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  197072. }
  197073. }
  197074. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  197075. startTimer (repaintTimerPeriod);
  197076. }
  197077. #if JUCE_USE_XSHM
  197078. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  197079. #endif
  197080. private:
  197081. LinuxComponentPeer* const peer;
  197082. ScopedPointer <XBitmapImage> image;
  197083. uint32 lastTimeImageUsed;
  197084. RectangleList regionsNeedingRepaint;
  197085. #if JUCE_USE_XSHM
  197086. bool useARGBImagesForRendering, shmCompletedDrawing;
  197087. #endif
  197088. LinuxRepaintManager (const LinuxRepaintManager&);
  197089. const LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  197090. };
  197091. ScopedPointer <LinuxRepaintManager> repainter;
  197092. friend class LinuxRepaintManager;
  197093. Window windowH, parentWindow;
  197094. int wx, wy, ww, wh;
  197095. Image* taskbarImage;
  197096. bool fullScreen, entered, mapped, depthIs16Bit;
  197097. BorderSize windowBorder;
  197098. struct MotifWmHints
  197099. {
  197100. unsigned long flags;
  197101. unsigned long functions;
  197102. unsigned long decorations;
  197103. long input_mode;
  197104. unsigned long status;
  197105. };
  197106. void removeWindowDecorations (Window wndH)
  197107. {
  197108. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  197109. if (hints != None)
  197110. {
  197111. MotifWmHints motifHints;
  197112. zerostruct (motifHints);
  197113. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  197114. motifHints.decorations = 0;
  197115. ScopedXLock xlock;
  197116. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197117. (unsigned char*) &motifHints, 4);
  197118. }
  197119. hints = XInternAtom (display, "_WIN_HINTS", True);
  197120. if (hints != None)
  197121. {
  197122. long gnomeHints = 0;
  197123. ScopedXLock xlock;
  197124. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197125. (unsigned char*) &gnomeHints, 1);
  197126. }
  197127. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  197128. if (hints != None)
  197129. {
  197130. long kwmHints = 2; /*KDE_tinyDecoration*/
  197131. ScopedXLock xlock;
  197132. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197133. (unsigned char*) &kwmHints, 1);
  197134. }
  197135. hints = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  197136. if (hints != None)
  197137. {
  197138. ScopedXLock xlock;
  197139. int netHints [2];
  197140. int numHints = 0;
  197141. if ((styleFlags & windowIsTemporary) != 0)
  197142. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_MENU", True);
  197143. else
  197144. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  197145. if (netHints [numHints] != 0)
  197146. ++numHints;
  197147. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  197148. if (netHints [numHints] != 0)
  197149. ++numHints;
  197150. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197151. (unsigned char*) &netHints, numHints);
  197152. }
  197153. }
  197154. void addWindowButtons (Window wndH)
  197155. {
  197156. ScopedXLock xlock;
  197157. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  197158. if (hints != None)
  197159. {
  197160. MotifWmHints motifHints;
  197161. zerostruct (motifHints);
  197162. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  197163. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  197164. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  197165. if ((styleFlags & windowHasCloseButton) != 0)
  197166. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  197167. if ((styleFlags & windowHasMinimiseButton) != 0)
  197168. {
  197169. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  197170. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  197171. }
  197172. if ((styleFlags & windowHasMaximiseButton) != 0)
  197173. {
  197174. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  197175. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  197176. }
  197177. if ((styleFlags & windowIsResizable) != 0)
  197178. {
  197179. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  197180. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  197181. }
  197182. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  197183. }
  197184. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  197185. if (hints != None)
  197186. {
  197187. int netHints [6];
  197188. int num = 0;
  197189. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  197190. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  197191. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  197192. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  197193. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197194. (unsigned char*) &netHints, num);
  197195. }
  197196. }
  197197. void createWindow()
  197198. {
  197199. ScopedXLock xlock;
  197200. static bool atomsInitialised = false;
  197201. if (! atomsInitialised)
  197202. {
  197203. atomsInitialised = true;
  197204. wm_Protocols = XInternAtom (display, "WM_PROTOCOLS", 1);
  197205. wm_ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", 1);
  197206. wm_ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", 1);
  197207. wm_ChangeState = XInternAtom (display, "WM_CHANGE_STATE", 1);
  197208. wm_State = XInternAtom (display, "WM_STATE", 1);
  197209. wm_ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  197210. XA_XdndAware = XInternAtom (display, "XdndAware", 0);
  197211. XA_XdndEnter = XInternAtom (display, "XdndEnter", 0);
  197212. XA_XdndLeave = XInternAtom (display, "XdndLeave", 0);
  197213. XA_XdndPosition = XInternAtom (display, "XdndPosition", 0);
  197214. XA_XdndStatus = XInternAtom (display, "XdndStatus", 0);
  197215. XA_XdndDrop = XInternAtom (display, "XdndDrop", 0);
  197216. XA_XdndFinished = XInternAtom (display, "XdndFinished", 0);
  197217. XA_XdndSelection = XInternAtom (display, "XdndSelection", 0);
  197218. XA_XdndProxy = XInternAtom (display, "XdndProxy", 0);
  197219. XA_XdndTypeList = XInternAtom (display, "XdndTypeList", 0);
  197220. XA_XdndActionList = XInternAtom (display, "XdndActionList", 0);
  197221. XA_XdndActionCopy = XInternAtom (display, "XdndActionCopy", 0);
  197222. XA_XdndActionMove = XInternAtom (display, "XdndActionMove", 0);
  197223. XA_XdndActionLink = XInternAtom (display, "XdndActionLink", 0);
  197224. XA_XdndActionAsk = XInternAtom (display, "XdndActionAsk", 0);
  197225. XA_XdndActionPrivate = XInternAtom (display, "XdndActionPrivate", 0);
  197226. XA_XdndActionDescription = XInternAtom (display, "XdndActionDescription", 0);
  197227. XA_JXSelectionWindowProperty = XInternAtom (display, "JXSelectionWindowProperty", 0);
  197228. XA_MimeTextPlain = XInternAtom (display, "text/plain", 0);
  197229. XA_MimeTextUriList = XInternAtom (display, "text/uri-list", 0);
  197230. XA_MimeRootDrop = XInternAtom (display, "application/x-rootwindow-drop", 0);
  197231. }
  197232. resetDragAndDrop();
  197233. XA_OtherMime = XA_MimeTextPlain; // xxx why??
  197234. allowedMimeTypeAtoms [0] = XA_MimeTextPlain;
  197235. allowedMimeTypeAtoms [1] = XA_OtherMime;
  197236. allowedMimeTypeAtoms [2] = XA_MimeTextUriList;
  197237. allowedActions [0] = XA_XdndActionMove;
  197238. allowedActions [1] = XA_XdndActionCopy;
  197239. allowedActions [2] = XA_XdndActionLink;
  197240. allowedActions [3] = XA_XdndActionAsk;
  197241. allowedActions [4] = XA_XdndActionPrivate;
  197242. // Get defaults for various properties
  197243. const int screen = DefaultScreen (display);
  197244. Window root = RootWindow (display, screen);
  197245. // Attempt to create a 24-bit window on the default screen. If this is not
  197246. // possible then exit
  197247. XVisualInfo desiredVisual;
  197248. desiredVisual.screen = screen;
  197249. desiredVisual.depth = 24;
  197250. depthIs16Bit = false;
  197251. int numVisuals;
  197252. XVisualInfo* visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197253. &desiredVisual, &numVisuals);
  197254. if (numVisuals < 1 || visuals == 0)
  197255. {
  197256. XFree (visuals);
  197257. desiredVisual.depth = 16;
  197258. visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197259. &desiredVisual, &numVisuals);
  197260. if (numVisuals < 1 || visuals == 0)
  197261. {
  197262. Logger::outputDebugString ("ERROR: System doesn't support 24 or 16 bit RGB display.\n");
  197263. Process::terminate();
  197264. }
  197265. depthIs16Bit = true;
  197266. }
  197267. XFree (visuals);
  197268. // Set up the window attributes
  197269. XSetWindowAttributes swa;
  197270. swa.border_pixel = 0;
  197271. swa.background_pixmap = None;
  197272. swa.colormap = DefaultColormap (display, screen);
  197273. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  197274. swa.event_mask = eventMask;
  197275. Window wndH = XCreateWindow (display, root,
  197276. 0, 0, 1, 1,
  197277. 0, 0, InputOutput, (Visual*) CopyFromParent,
  197278. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  197279. &swa);
  197280. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  197281. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  197282. GrabModeAsync, GrabModeAsync, None, None);
  197283. // Set the window context to identify the window handle object
  197284. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  197285. {
  197286. // Failed
  197287. jassertfalse
  197288. Logger::outputDebugString ("Failed to create context information for window.\n");
  197289. XDestroyWindow (display, wndH);
  197290. wndH = 0;
  197291. }
  197292. // Set window manager hints
  197293. XWMHints* wmHints = XAllocWMHints();
  197294. wmHints->flags = InputHint | StateHint;
  197295. wmHints->input = True; // Locally active input model
  197296. wmHints->initial_state = NormalState;
  197297. XSetWMHints (display, wndH, wmHints);
  197298. XFree (wmHints);
  197299. if ((styleFlags & windowIsSemiTransparent) != 0)
  197300. {
  197301. //xxx
  197302. }
  197303. if ((styleFlags & windowAppearsOnTaskbar) != 0)
  197304. {
  197305. //xxx
  197306. }
  197307. //XSetTransientForHint (display, wndH, RootWindow (display, DefaultScreen (display)));
  197308. if ((styleFlags & windowHasTitleBar) == 0)
  197309. removeWindowDecorations (wndH);
  197310. else
  197311. addWindowButtons (wndH);
  197312. // Set window manager protocols
  197313. XChangeProperty (display, wndH, wm_Protocols, XA_ATOM, 32, PropModeReplace,
  197314. (unsigned char*) wm_ProtocolList, 2);
  197315. // Set drag and drop flags
  197316. XChangeProperty (display, wndH, XA_XdndTypeList, XA_ATOM, 32, PropModeReplace,
  197317. (const unsigned char*) allowedMimeTypeAtoms, numElementsInArray (allowedMimeTypeAtoms));
  197318. XChangeProperty (display, wndH, XA_XdndActionList, XA_ATOM, 32, PropModeReplace,
  197319. (const unsigned char*) allowedActions, numElementsInArray (allowedActions));
  197320. XChangeProperty (display, wndH, XA_XdndActionDescription, XA_STRING, 8, PropModeReplace,
  197321. (const unsigned char*) "", 0);
  197322. unsigned long dndVersion = ourDndVersion;
  197323. XChangeProperty (display, wndH, XA_XdndAware, XA_ATOM, 32, PropModeReplace,
  197324. (const unsigned char*) &dndVersion, 1);
  197325. // Set window name
  197326. setWindowTitle (wndH, getComponent()->getName());
  197327. // Initialise the pointer and keyboard mapping
  197328. // This is not the same as the logical pointer mapping the X server uses:
  197329. // we don't mess with this.
  197330. static bool mappingInitialised = false;
  197331. if (! mappingInitialised)
  197332. {
  197333. mappingInitialised = true;
  197334. const int numButtons = XGetPointerMapping (display, 0, 0);
  197335. if (numButtons == 2)
  197336. {
  197337. pointerMap[0] = LeftButton;
  197338. pointerMap[1] = RightButton;
  197339. pointerMap[2] = pointerMap[3] = pointerMap[4] = NoButton;
  197340. }
  197341. else if (numButtons >= 3)
  197342. {
  197343. pointerMap[0] = LeftButton;
  197344. pointerMap[1] = MiddleButton;
  197345. pointerMap[2] = RightButton;
  197346. if (numButtons >= 5)
  197347. {
  197348. pointerMap[3] = WheelUp;
  197349. pointerMap[4] = WheelDown;
  197350. }
  197351. }
  197352. getModifierMapping();
  197353. }
  197354. windowH = wndH;
  197355. }
  197356. void destroyWindow()
  197357. {
  197358. ScopedXLock xlock;
  197359. XPointer handlePointer;
  197360. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  197361. XDeleteContext (display, (XID) windowH, improbableNumber);
  197362. XDestroyWindow (display, windowH);
  197363. // Wait for it to complete and then remove any events for this
  197364. // window from the event queue.
  197365. XSync (display, false);
  197366. XEvent event;
  197367. while (XCheckWindowEvent (display, windowH, eventMask, &event) == True)
  197368. {}
  197369. }
  197370. static int64 getEventTime (::Time t) throw()
  197371. {
  197372. static int64 eventTimeOffset = 0x12345678;
  197373. const int64 thisMessageTime = t;
  197374. if (eventTimeOffset == 0x12345678)
  197375. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  197376. return eventTimeOffset + thisMessageTime;
  197377. }
  197378. static void setWindowTitle (Window xwin, const char* const title) throw()
  197379. {
  197380. XTextProperty nameProperty;
  197381. char* strings[] = { (char*) title };
  197382. ScopedXLock xlock;
  197383. if (XStringListToTextProperty (strings, 1, &nameProperty))
  197384. {
  197385. XSetWMName (display, xwin, &nameProperty);
  197386. XSetWMIconName (display, xwin, &nameProperty);
  197387. XFree (nameProperty.value);
  197388. }
  197389. }
  197390. void updateBorderSize()
  197391. {
  197392. if ((styleFlags & windowHasTitleBar) == 0)
  197393. {
  197394. windowBorder = BorderSize (0);
  197395. }
  197396. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  197397. {
  197398. ScopedXLock xlock;
  197399. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  197400. if (hints != None)
  197401. {
  197402. unsigned char* data = 0;
  197403. unsigned long nitems, bytesLeft;
  197404. Atom actualType;
  197405. int actualFormat;
  197406. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  197407. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197408. &data) == Success)
  197409. {
  197410. const unsigned long* const sizes = (const unsigned long*) data;
  197411. if (actualFormat == 32)
  197412. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  197413. (int) sizes[3], (int) sizes[1]);
  197414. XFree (data);
  197415. }
  197416. }
  197417. }
  197418. }
  197419. void updateBounds()
  197420. {
  197421. jassert (windowH != 0);
  197422. if (windowH != 0)
  197423. {
  197424. Window root, child;
  197425. unsigned int bw, depth;
  197426. ScopedXLock xlock;
  197427. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  197428. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  197429. &bw, &depth))
  197430. {
  197431. wx = wy = ww = wh = 0;
  197432. }
  197433. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  197434. {
  197435. wx = wy = 0;
  197436. }
  197437. }
  197438. }
  197439. void resetDragAndDrop()
  197440. {
  197441. dragAndDropFiles.clear();
  197442. lastDropX = lastDropY = -1;
  197443. dragAndDropCurrentMimeType = 0;
  197444. dragAndDropSourceWindow = 0;
  197445. srcMimeTypeAtomList.clear();
  197446. }
  197447. void sendDragAndDropMessage (XClientMessageEvent& msg)
  197448. {
  197449. msg.type = ClientMessage;
  197450. msg.display = display;
  197451. msg.window = dragAndDropSourceWindow;
  197452. msg.format = 32;
  197453. msg.data.l[0] = windowH;
  197454. ScopedXLock xlock;
  197455. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  197456. }
  197457. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  197458. {
  197459. XClientMessageEvent msg;
  197460. zerostruct (msg);
  197461. msg.message_type = XA_XdndStatus;
  197462. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  197463. msg.data.l[4] = dropAction;
  197464. sendDragAndDropMessage (msg);
  197465. }
  197466. void sendDragAndDropLeave()
  197467. {
  197468. XClientMessageEvent msg;
  197469. zerostruct (msg);
  197470. msg.message_type = XA_XdndLeave;
  197471. sendDragAndDropMessage (msg);
  197472. }
  197473. void sendDragAndDropFinish()
  197474. {
  197475. XClientMessageEvent msg;
  197476. zerostruct (msg);
  197477. msg.message_type = XA_XdndFinished;
  197478. sendDragAndDropMessage (msg);
  197479. }
  197480. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  197481. {
  197482. if ((clientMsg->data.l[1] & 1) == 0)
  197483. {
  197484. sendDragAndDropLeave();
  197485. if (dragAndDropFiles.size() > 0)
  197486. handleFileDragExit (dragAndDropFiles);
  197487. dragAndDropFiles.clear();
  197488. }
  197489. }
  197490. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  197491. {
  197492. if (dragAndDropSourceWindow == 0)
  197493. return;
  197494. dragAndDropSourceWindow = clientMsg->data.l[0];
  197495. const int dropX = ((int) clientMsg->data.l[2] >> 16) - getScreenX();
  197496. const int dropY = ((int) clientMsg->data.l[2] & 0xffff) - getScreenY();
  197497. if (lastDropX != dropX || lastDropY != dropY)
  197498. {
  197499. lastDropX = dropX;
  197500. lastDropY = dropY;
  197501. dragAndDropTimestamp = clientMsg->data.l[3];
  197502. Atom targetAction = XA_XdndActionCopy;
  197503. for (int i = numElementsInArray (allowedActions); --i >= 0;)
  197504. {
  197505. if ((Atom) clientMsg->data.l[4] == allowedActions[i])
  197506. {
  197507. targetAction = allowedActions[i];
  197508. break;
  197509. }
  197510. }
  197511. sendDragAndDropStatus (true, targetAction);
  197512. if (dragAndDropFiles.size() == 0)
  197513. updateDraggedFileList (clientMsg);
  197514. if (dragAndDropFiles.size() > 0)
  197515. handleFileDragMove (dragAndDropFiles, dropX, dropY);
  197516. }
  197517. }
  197518. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197519. {
  197520. if (dragAndDropFiles.size() == 0)
  197521. updateDraggedFileList (clientMsg);
  197522. const StringArray files (dragAndDropFiles);
  197523. const int lastX = lastDropX, lastY = lastDropY;
  197524. sendDragAndDropFinish();
  197525. resetDragAndDrop();
  197526. if (files.size() > 0)
  197527. handleFileDragDrop (files, lastX, lastY);
  197528. }
  197529. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197530. {
  197531. dragAndDropFiles.clear();
  197532. srcMimeTypeAtomList.clear();
  197533. dragAndDropCurrentMimeType = 0;
  197534. const int dndCurrentVersion = (int) (clientMsg->data.l[1] & 0xff000000) >> 24;
  197535. if (dndCurrentVersion < 3 || dndCurrentVersion > ourDndVersion)
  197536. {
  197537. dragAndDropSourceWindow = 0;
  197538. return;
  197539. }
  197540. dragAndDropSourceWindow = clientMsg->data.l[0];
  197541. if ((clientMsg->data.l[1] & 1) != 0)
  197542. {
  197543. Atom actual;
  197544. int format;
  197545. unsigned long count = 0, remaining = 0;
  197546. unsigned char* data = 0;
  197547. ScopedXLock xlock;
  197548. XGetWindowProperty (display, dragAndDropSourceWindow, XA_XdndTypeList,
  197549. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197550. &count, &remaining, &data);
  197551. if (data != 0)
  197552. {
  197553. if (actual == XA_ATOM && format == 32 && count != 0)
  197554. {
  197555. const unsigned long* const types = (const unsigned long*) data;
  197556. for (unsigned int i = 0; i < count; ++i)
  197557. if (types[i] != None)
  197558. srcMimeTypeAtomList.add (types[i]);
  197559. }
  197560. XFree (data);
  197561. }
  197562. }
  197563. if (srcMimeTypeAtomList.size() == 0)
  197564. {
  197565. for (int i = 2; i < 5; ++i)
  197566. if (clientMsg->data.l[i] != None)
  197567. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197568. if (srcMimeTypeAtomList.size() == 0)
  197569. {
  197570. dragAndDropSourceWindow = 0;
  197571. return;
  197572. }
  197573. }
  197574. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197575. for (int j = 0; j < numElementsInArray (allowedMimeTypeAtoms); ++j)
  197576. if (srcMimeTypeAtomList[i] == allowedMimeTypeAtoms[j])
  197577. dragAndDropCurrentMimeType = allowedMimeTypeAtoms[j];
  197578. handleDragAndDropPosition (clientMsg);
  197579. }
  197580. void handleDragAndDropSelection (const XEvent* const evt)
  197581. {
  197582. dragAndDropFiles.clear();
  197583. if (evt->xselection.property != 0)
  197584. {
  197585. StringArray lines;
  197586. {
  197587. MemoryBlock dropData;
  197588. for (;;)
  197589. {
  197590. Atom actual;
  197591. uint8* data = 0;
  197592. unsigned long count = 0, remaining = 0;
  197593. int format = 0;
  197594. ScopedXLock xlock;
  197595. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197596. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197597. &format, &count, &remaining, &data) == Success)
  197598. {
  197599. dropData.append (data, count * format / 8);
  197600. XFree (data);
  197601. if (remaining == 0)
  197602. break;
  197603. }
  197604. else
  197605. {
  197606. XFree (data);
  197607. break;
  197608. }
  197609. }
  197610. lines.addLines (dropData.toString());
  197611. }
  197612. for (int i = 0; i < lines.size(); ++i)
  197613. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf (T("file://"), false, true)));
  197614. dragAndDropFiles.trim();
  197615. dragAndDropFiles.removeEmptyStrings();
  197616. }
  197617. }
  197618. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197619. {
  197620. dragAndDropFiles.clear();
  197621. if (dragAndDropSourceWindow != None
  197622. && dragAndDropCurrentMimeType != 0)
  197623. {
  197624. dragAndDropTimestamp = clientMsg->data.l[2];
  197625. ScopedXLock xlock;
  197626. XConvertSelection (display,
  197627. XA_XdndSelection,
  197628. dragAndDropCurrentMimeType,
  197629. XA_JXSelectionWindowProperty,
  197630. windowH,
  197631. dragAndDropTimestamp);
  197632. }
  197633. }
  197634. StringArray dragAndDropFiles;
  197635. int dragAndDropTimestamp, lastDropX, lastDropY;
  197636. Atom XA_OtherMime, dragAndDropCurrentMimeType;
  197637. Window dragAndDropSourceWindow;
  197638. unsigned int allowedActions [5];
  197639. unsigned int allowedMimeTypeAtoms [3];
  197640. Array <Atom> srcMimeTypeAtomList;
  197641. };
  197642. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197643. {
  197644. if (enableOrDisable)
  197645. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197646. }
  197647. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197648. {
  197649. return new LinuxComponentPeer (this, styleFlags);
  197650. }
  197651. // (this callback is hooked up in the messaging code)
  197652. void juce_windowMessageReceive (XEvent* event)
  197653. {
  197654. if (event->xany.window != None)
  197655. {
  197656. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197657. if (ComponentPeer::isValidPeer (peer))
  197658. peer->handleWindowMessage (event);
  197659. }
  197660. else
  197661. {
  197662. switch (event->xany.type)
  197663. {
  197664. case KeymapNotify:
  197665. {
  197666. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197667. memcpy (keyStates, keymapEvent->key_vector, 32);
  197668. break;
  197669. }
  197670. default:
  197671. break;
  197672. }
  197673. }
  197674. }
  197675. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197676. {
  197677. if (display == 0)
  197678. return;
  197679. #if JUCE_USE_XINERAMA
  197680. int major_opcode, first_event, first_error;
  197681. ScopedXLock xlock;
  197682. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197683. {
  197684. typedef Bool (*tXineramaIsActive) (Display*);
  197685. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197686. static tXineramaIsActive xXineramaIsActive = 0;
  197687. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197688. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197689. {
  197690. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197691. if (h != 0)
  197692. {
  197693. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197694. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197695. }
  197696. }
  197697. if (xXineramaIsActive != 0
  197698. && xXineramaQueryScreens != 0
  197699. && xXineramaIsActive (display))
  197700. {
  197701. int numMonitors = 0;
  197702. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197703. if (screens != 0)
  197704. {
  197705. for (int i = numMonitors; --i >= 0;)
  197706. {
  197707. int index = screens[i].screen_number;
  197708. if (index >= 0)
  197709. {
  197710. while (monitorCoords.size() < index)
  197711. monitorCoords.add (Rectangle<int>());
  197712. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197713. screens[i].y_org,
  197714. screens[i].width,
  197715. screens[i].height));
  197716. }
  197717. }
  197718. XFree (screens);
  197719. }
  197720. }
  197721. }
  197722. if (monitorCoords.size() == 0)
  197723. #endif
  197724. {
  197725. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197726. if (hints != None)
  197727. {
  197728. const int numMonitors = ScreenCount (display);
  197729. for (int i = 0; i < numMonitors; ++i)
  197730. {
  197731. Window root = RootWindow (display, i);
  197732. unsigned long nitems, bytesLeft;
  197733. Atom actualType;
  197734. int actualFormat;
  197735. unsigned char* data = 0;
  197736. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197737. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197738. &data) == Success)
  197739. {
  197740. const long* const position = (const long*) data;
  197741. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197742. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197743. position[2], position[3]));
  197744. XFree (data);
  197745. }
  197746. }
  197747. }
  197748. if (monitorCoords.size() == 0)
  197749. {
  197750. monitorCoords.add (Rectangle<int> (0, 0,
  197751. DisplayWidth (display, DefaultScreen (display)),
  197752. DisplayHeight (display, DefaultScreen (display))));
  197753. }
  197754. }
  197755. }
  197756. bool Desktop::canUseSemiTransparentWindows() throw()
  197757. {
  197758. return false;
  197759. }
  197760. void Desktop::getMousePosition (int& x, int& y) throw()
  197761. {
  197762. int mouseMods;
  197763. getMousePos (x, y, mouseMods);
  197764. }
  197765. void Desktop::setMousePosition (int x, int y) throw()
  197766. {
  197767. ScopedXLock xlock;
  197768. Window root = RootWindow (display, DefaultScreen (display));
  197769. XWarpPointer (display, None, root, 0, 0, 0, 0, x, y);
  197770. }
  197771. static bool screenSaverAllowed = true;
  197772. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197773. {
  197774. if (screenSaverAllowed != isEnabled)
  197775. {
  197776. screenSaverAllowed = isEnabled;
  197777. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197778. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197779. if (xScreenSaverSuspend == 0)
  197780. {
  197781. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197782. if (h != 0)
  197783. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197784. }
  197785. ScopedXLock xlock;
  197786. if (xScreenSaverSuspend != 0)
  197787. xScreenSaverSuspend (display, ! isEnabled);
  197788. }
  197789. }
  197790. bool Desktop::isScreenSaverEnabled() throw()
  197791. {
  197792. return screenSaverAllowed;
  197793. }
  197794. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  197795. {
  197796. ScopedXLock xlock;
  197797. Window root = RootWindow (display, DefaultScreen (display));
  197798. const unsigned int imageW = image.getWidth();
  197799. const unsigned int imageH = image.getHeight();
  197800. unsigned int cursorW, cursorH;
  197801. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197802. return 0;
  197803. Image im (Image::ARGB, cursorW, cursorH, true);
  197804. Graphics g (im);
  197805. if (imageW > cursorW || imageH > cursorH)
  197806. {
  197807. hotspotX = (hotspotX * cursorW) / imageW;
  197808. hotspotY = (hotspotY * cursorH) / imageH;
  197809. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197810. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197811. false);
  197812. }
  197813. else
  197814. {
  197815. g.drawImageAt (&image, 0, 0);
  197816. }
  197817. const int stride = (cursorW + 7) >> 3;
  197818. HeapBlock <uint8> maskPlane, sourcePlane;
  197819. maskPlane.calloc (stride * cursorH);
  197820. sourcePlane.calloc (stride * cursorH);
  197821. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197822. for (int y = cursorH; --y >= 0;)
  197823. {
  197824. for (int x = cursorW; --x >= 0;)
  197825. {
  197826. const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197827. const int offset = y * stride + (x >> 3);
  197828. const Colour c (im.getPixelAt (x, y));
  197829. if (c.getAlpha() >= 128)
  197830. maskPlane[offset] |= mask;
  197831. if (c.getBrightness() >= 0.5f)
  197832. sourcePlane[offset] |= mask;
  197833. }
  197834. }
  197835. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, (char*) sourcePlane, cursorW, cursorH, 0xffff, 0, 1);
  197836. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, (char*) maskPlane, cursorW, cursorH, 0xffff, 0, 1);
  197837. XColor white, black;
  197838. black.red = black.green = black.blue = 0;
  197839. white.red = white.green = white.blue = 0xffff;
  197840. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197841. XFreePixmap (display, sourcePixmap);
  197842. XFreePixmap (display, maskPixmap);
  197843. return result;
  197844. }
  197845. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  197846. {
  197847. ScopedXLock xlock;
  197848. if (cursorHandle != None)
  197849. XFreeCursor (display, (Cursor) cursorHandle);
  197850. }
  197851. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  197852. {
  197853. unsigned int shape;
  197854. switch (type)
  197855. {
  197856. case MouseCursor::NoCursor:
  197857. {
  197858. const Image im (Image::ARGB, 16, 16, true);
  197859. return juce_createMouseCursorFromImage (im, 0, 0);
  197860. }
  197861. case MouseCursor::NormalCursor:
  197862. return (void*) None; // Use parent cursor
  197863. case MouseCursor::DraggingHandCursor:
  197864. {
  197865. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197866. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197867. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197868. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197869. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197870. const int dragHandDataSize = 99;
  197871. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) dragHandData, dragHandDataSize));
  197872. return juce_createMouseCursorFromImage (*im, 8, 7);
  197873. }
  197874. case MouseCursor::CopyingCursor:
  197875. {
  197876. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197877. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197878. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197879. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197880. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197881. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197882. const int copyCursorSize = 119;
  197883. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) copyCursorData, copyCursorSize));
  197884. return juce_createMouseCursorFromImage (*im, 1, 3);
  197885. }
  197886. case MouseCursor::WaitCursor:
  197887. shape = XC_watch;
  197888. break;
  197889. case MouseCursor::IBeamCursor:
  197890. shape = XC_xterm;
  197891. break;
  197892. case MouseCursor::PointingHandCursor:
  197893. shape = XC_hand2;
  197894. break;
  197895. case MouseCursor::LeftRightResizeCursor:
  197896. shape = XC_sb_h_double_arrow;
  197897. break;
  197898. case MouseCursor::UpDownResizeCursor:
  197899. shape = XC_sb_v_double_arrow;
  197900. break;
  197901. case MouseCursor::UpDownLeftRightResizeCursor:
  197902. shape = XC_fleur;
  197903. break;
  197904. case MouseCursor::TopEdgeResizeCursor:
  197905. shape = XC_top_side;
  197906. break;
  197907. case MouseCursor::BottomEdgeResizeCursor:
  197908. shape = XC_bottom_side;
  197909. break;
  197910. case MouseCursor::LeftEdgeResizeCursor:
  197911. shape = XC_left_side;
  197912. break;
  197913. case MouseCursor::RightEdgeResizeCursor:
  197914. shape = XC_right_side;
  197915. break;
  197916. case MouseCursor::TopLeftCornerResizeCursor:
  197917. shape = XC_top_left_corner;
  197918. break;
  197919. case MouseCursor::TopRightCornerResizeCursor:
  197920. shape = XC_top_right_corner;
  197921. break;
  197922. case MouseCursor::BottomLeftCornerResizeCursor:
  197923. shape = XC_bottom_left_corner;
  197924. break;
  197925. case MouseCursor::BottomRightCornerResizeCursor:
  197926. shape = XC_bottom_right_corner;
  197927. break;
  197928. case MouseCursor::CrosshairCursor:
  197929. shape = XC_crosshair;
  197930. break;
  197931. default:
  197932. return (void*) None; // Use parent cursor
  197933. }
  197934. ScopedXLock xlock;
  197935. return (void*) XCreateFontCursor (display, shape);
  197936. }
  197937. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  197938. {
  197939. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197940. if (lp != 0)
  197941. lp->showMouseCursor ((Cursor) getHandle());
  197942. }
  197943. void MouseCursor::showInAllWindows() const throw()
  197944. {
  197945. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197946. showInWindow (ComponentPeer::getPeer (i));
  197947. }
  197948. Image* juce_createIconForFile (const File& file)
  197949. {
  197950. return 0;
  197951. }
  197952. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197953. {
  197954. return new Image (format, imageWidth, imageHeight, clearImage);
  197955. }
  197956. #if JUCE_OPENGL
  197957. class WindowedGLContext : public OpenGLContext
  197958. {
  197959. public:
  197960. WindowedGLContext (Component* const component,
  197961. const OpenGLPixelFormat& pixelFormat_,
  197962. GLXContext sharedContext)
  197963. : renderContext (0),
  197964. embeddedWindow (0),
  197965. pixelFormat (pixelFormat_)
  197966. {
  197967. jassert (component != 0);
  197968. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197969. if (peer == 0)
  197970. return;
  197971. ScopedXLock xlock;
  197972. XSync (display, False);
  197973. GLint attribs [64];
  197974. int n = 0;
  197975. attribs[n++] = GLX_RGBA;
  197976. attribs[n++] = GLX_DOUBLEBUFFER;
  197977. attribs[n++] = GLX_RED_SIZE;
  197978. attribs[n++] = pixelFormat.redBits;
  197979. attribs[n++] = GLX_GREEN_SIZE;
  197980. attribs[n++] = pixelFormat.greenBits;
  197981. attribs[n++] = GLX_BLUE_SIZE;
  197982. attribs[n++] = pixelFormat.blueBits;
  197983. attribs[n++] = GLX_ALPHA_SIZE;
  197984. attribs[n++] = pixelFormat.alphaBits;
  197985. attribs[n++] = GLX_DEPTH_SIZE;
  197986. attribs[n++] = pixelFormat.depthBufferBits;
  197987. attribs[n++] = GLX_STENCIL_SIZE;
  197988. attribs[n++] = pixelFormat.stencilBufferBits;
  197989. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197990. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197991. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197992. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197993. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197994. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197995. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197996. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197997. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197998. attribs[n++] = None;
  197999. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  198000. if (bestVisual == 0)
  198001. return;
  198002. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  198003. Window windowH = (Window) peer->getNativeHandle();
  198004. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  198005. XSetWindowAttributes swa;
  198006. swa.colormap = colourMap;
  198007. swa.border_pixel = 0;
  198008. swa.event_mask = ExposureMask | StructureNotifyMask;
  198009. embeddedWindow = XCreateWindow (display, windowH,
  198010. 0, 0, 1, 1, 0,
  198011. bestVisual->depth,
  198012. InputOutput,
  198013. bestVisual->visual,
  198014. CWBorderPixel | CWColormap | CWEventMask,
  198015. &swa);
  198016. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  198017. XMapWindow (display, embeddedWindow);
  198018. XFreeColormap (display, colourMap);
  198019. XFree (bestVisual);
  198020. XSync (display, False);
  198021. }
  198022. ~WindowedGLContext()
  198023. {
  198024. makeInactive();
  198025. ScopedXLock xlock;
  198026. glXDestroyContext (display, renderContext);
  198027. XUnmapWindow (display, embeddedWindow);
  198028. XDestroyWindow (display, embeddedWindow);
  198029. }
  198030. bool makeActive() const throw()
  198031. {
  198032. jassert (renderContext != 0);
  198033. ScopedXLock xlock;
  198034. return glXMakeCurrent (display, embeddedWindow, renderContext)
  198035. && XSync (display, False);
  198036. }
  198037. bool makeInactive() const throw()
  198038. {
  198039. ScopedXLock xlock;
  198040. return (! isActive()) || glXMakeCurrent (display, None, 0);
  198041. }
  198042. bool isActive() const throw()
  198043. {
  198044. ScopedXLock xlock;
  198045. return glXGetCurrentContext() == renderContext;
  198046. }
  198047. const OpenGLPixelFormat getPixelFormat() const
  198048. {
  198049. return pixelFormat;
  198050. }
  198051. void* getRawContext() const throw()
  198052. {
  198053. return renderContext;
  198054. }
  198055. void updateWindowPosition (int x, int y, int w, int h, int)
  198056. {
  198057. ScopedXLock xlock;
  198058. XMoveResizeWindow (display, embeddedWindow,
  198059. x, y, jmax (1, w), jmax (1, h));
  198060. }
  198061. void swapBuffers()
  198062. {
  198063. ScopedXLock xlock;
  198064. glXSwapBuffers (display, embeddedWindow);
  198065. }
  198066. bool setSwapInterval (const int numFramesPerSwap)
  198067. {
  198068. // xxx needs doing..
  198069. return false;
  198070. }
  198071. int getSwapInterval() const
  198072. {
  198073. // xxx needs doing..
  198074. return 0;
  198075. }
  198076. void repaint()
  198077. {
  198078. }
  198079. juce_UseDebuggingNewOperator
  198080. GLXContext renderContext;
  198081. private:
  198082. Window embeddedWindow;
  198083. OpenGLPixelFormat pixelFormat;
  198084. WindowedGLContext (const WindowedGLContext&);
  198085. const WindowedGLContext& operator= (const WindowedGLContext&);
  198086. };
  198087. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  198088. const OpenGLPixelFormat& pixelFormat,
  198089. const OpenGLContext* const contextToShareWith)
  198090. {
  198091. WindowedGLContext* c = new WindowedGLContext (component, pixelFormat,
  198092. contextToShareWith != 0 ? (GLXContext) contextToShareWith->getRawContext() : 0);
  198093. if (c->renderContext == 0)
  198094. deleteAndZero (c);
  198095. return c;
  198096. }
  198097. void juce_glViewport (const int w, const int h)
  198098. {
  198099. glViewport (0, 0, w, h);
  198100. }
  198101. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  198102. OwnedArray <OpenGLPixelFormat>& results)
  198103. {
  198104. results.add (new OpenGLPixelFormat()); // xxx
  198105. }
  198106. #endif
  198107. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  198108. {
  198109. jassertfalse // not implemented!
  198110. return false;
  198111. }
  198112. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  198113. {
  198114. jassertfalse // not implemented!
  198115. return false;
  198116. }
  198117. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  198118. {
  198119. if (! isOnDesktop ())
  198120. addToDesktop (0);
  198121. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  198122. if (wp != 0)
  198123. {
  198124. wp->setTaskBarIcon (newImage);
  198125. setVisible (true);
  198126. toFront (false);
  198127. repaint();
  198128. }
  198129. }
  198130. void SystemTrayIconComponent::paint (Graphics& g)
  198131. {
  198132. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  198133. if (wp != 0)
  198134. {
  198135. const Image* const image = wp->getTaskbarIcon();
  198136. if (image != 0)
  198137. {
  198138. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  198139. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  198140. false);
  198141. }
  198142. }
  198143. }
  198144. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  198145. {
  198146. // xxx not yet implemented!
  198147. }
  198148. void PlatformUtilities::beep()
  198149. {
  198150. std::cout << "\a" << std::flush;
  198151. }
  198152. bool AlertWindow::showNativeDialogBox (const String& title,
  198153. const String& bodyText,
  198154. bool isOkCancel)
  198155. {
  198156. // xxx this is supposed to pop up an alert!
  198157. Logger::outputDebugString (title + ": " + bodyText);
  198158. // use a non-native one for the time being..
  198159. if (isOkCancel)
  198160. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  198161. else
  198162. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  198163. return true;
  198164. }
  198165. const int KeyPress::spaceKey = XK_space & 0xff;
  198166. const int KeyPress::returnKey = XK_Return & 0xff;
  198167. const int KeyPress::escapeKey = XK_Escape & 0xff;
  198168. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  198169. const int KeyPress::leftKey = (XK_Left & 0xff) | extendedKeyModifier;
  198170. const int KeyPress::rightKey = (XK_Right & 0xff) | extendedKeyModifier;
  198171. const int KeyPress::upKey = (XK_Up & 0xff) | extendedKeyModifier;
  198172. const int KeyPress::downKey = (XK_Down & 0xff) | extendedKeyModifier;
  198173. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | extendedKeyModifier;
  198174. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | extendedKeyModifier;
  198175. const int KeyPress::endKey = (XK_End & 0xff) | extendedKeyModifier;
  198176. const int KeyPress::homeKey = (XK_Home & 0xff) | extendedKeyModifier;
  198177. const int KeyPress::insertKey = (XK_Insert & 0xff) | extendedKeyModifier;
  198178. const int KeyPress::deleteKey = (XK_Delete & 0xff) | extendedKeyModifier;
  198179. const int KeyPress::tabKey = XK_Tab & 0xff;
  198180. const int KeyPress::F1Key = (XK_F1 & 0xff) | extendedKeyModifier;
  198181. const int KeyPress::F2Key = (XK_F2 & 0xff) | extendedKeyModifier;
  198182. const int KeyPress::F3Key = (XK_F3 & 0xff) | extendedKeyModifier;
  198183. const int KeyPress::F4Key = (XK_F4 & 0xff) | extendedKeyModifier;
  198184. const int KeyPress::F5Key = (XK_F5 & 0xff) | extendedKeyModifier;
  198185. const int KeyPress::F6Key = (XK_F6 & 0xff) | extendedKeyModifier;
  198186. const int KeyPress::F7Key = (XK_F7 & 0xff) | extendedKeyModifier;
  198187. const int KeyPress::F8Key = (XK_F8 & 0xff) | extendedKeyModifier;
  198188. const int KeyPress::F9Key = (XK_F9 & 0xff) | extendedKeyModifier;
  198189. const int KeyPress::F10Key = (XK_F10 & 0xff) | extendedKeyModifier;
  198190. const int KeyPress::F11Key = (XK_F11 & 0xff) | extendedKeyModifier;
  198191. const int KeyPress::F12Key = (XK_F12 & 0xff) | extendedKeyModifier;
  198192. const int KeyPress::F13Key = (XK_F13 & 0xff) | extendedKeyModifier;
  198193. const int KeyPress::F14Key = (XK_F14 & 0xff) | extendedKeyModifier;
  198194. const int KeyPress::F15Key = (XK_F15 & 0xff) | extendedKeyModifier;
  198195. const int KeyPress::F16Key = (XK_F16 & 0xff) | extendedKeyModifier;
  198196. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | extendedKeyModifier;
  198197. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | extendedKeyModifier;
  198198. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | extendedKeyModifier;
  198199. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | extendedKeyModifier;
  198200. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | extendedKeyModifier;
  198201. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | extendedKeyModifier;
  198202. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | extendedKeyModifier;
  198203. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| extendedKeyModifier;
  198204. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| extendedKeyModifier;
  198205. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| extendedKeyModifier;
  198206. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| extendedKeyModifier;
  198207. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| extendedKeyModifier;
  198208. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| extendedKeyModifier;
  198209. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| extendedKeyModifier;
  198210. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| extendedKeyModifier;
  198211. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| extendedKeyModifier;
  198212. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| extendedKeyModifier;
  198213. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| extendedKeyModifier;
  198214. const int KeyPress::playKey = (0xffeeff00) | extendedKeyModifier;
  198215. const int KeyPress::stopKey = (0xffeeff01) | extendedKeyModifier;
  198216. const int KeyPress::fastForwardKey = (0xffeeff02) | extendedKeyModifier;
  198217. const int KeyPress::rewindKey = (0xffeeff03) | extendedKeyModifier;
  198218. #endif
  198219. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  198220. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  198221. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198222. // compiled on its own).
  198223. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  198224. static const int maxNumChans = 64;
  198225. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  198226. {
  198227. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  198228. snd_pcm_hw_params_t* hwParams;
  198229. snd_pcm_hw_params_alloca (&hwParams);
  198230. for (int i = 0; ratesToTry[i] != 0; ++i)
  198231. {
  198232. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  198233. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  198234. {
  198235. rates.addIfNotAlreadyThere (ratesToTry[i]);
  198236. }
  198237. }
  198238. }
  198239. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  198240. {
  198241. snd_pcm_hw_params_t *params;
  198242. snd_pcm_hw_params_alloca (&params);
  198243. if (snd_pcm_hw_params_any (handle, params) >= 0)
  198244. {
  198245. snd_pcm_hw_params_get_channels_min (params, minChans);
  198246. snd_pcm_hw_params_get_channels_max (params, maxChans);
  198247. }
  198248. }
  198249. static void getDeviceProperties (const String& id,
  198250. unsigned int& minChansOut,
  198251. unsigned int& maxChansOut,
  198252. unsigned int& minChansIn,
  198253. unsigned int& maxChansIn,
  198254. Array <int>& rates)
  198255. {
  198256. if (id.isEmpty())
  198257. return;
  198258. snd_ctl_t* handle;
  198259. if (snd_ctl_open (&handle, id.upToLastOccurrenceOf (T(","), false, false), SND_CTL_NONBLOCK) >= 0)
  198260. {
  198261. snd_pcm_info_t* info;
  198262. snd_pcm_info_alloca (&info);
  198263. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  198264. snd_pcm_info_set_device (info, id.fromLastOccurrenceOf (T(","), false, false).getIntValue());
  198265. snd_pcm_info_set_subdevice (info, 0);
  198266. if (snd_ctl_pcm_info (handle, info) >= 0)
  198267. {
  198268. snd_pcm_t* pcmHandle;
  198269. if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198270. {
  198271. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  198272. getDeviceSampleRates (pcmHandle, rates);
  198273. snd_pcm_close (pcmHandle);
  198274. }
  198275. }
  198276. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  198277. if (snd_ctl_pcm_info (handle, info) >= 0)
  198278. {
  198279. snd_pcm_t* pcmHandle;
  198280. if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198281. {
  198282. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  198283. if (rates.size() == 0)
  198284. getDeviceSampleRates (pcmHandle, rates);
  198285. snd_pcm_close (pcmHandle);
  198286. }
  198287. }
  198288. snd_ctl_close (handle);
  198289. }
  198290. }
  198291. class ALSADevice
  198292. {
  198293. public:
  198294. ALSADevice (const String& id,
  198295. const bool forInput)
  198296. : handle (0),
  198297. bitDepth (16),
  198298. numChannelsRunning (0),
  198299. isInput (forInput),
  198300. sampleFormat (AudioDataConverters::int16LE)
  198301. {
  198302. failed (snd_pcm_open (&handle, id,
  198303. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  198304. SND_PCM_ASYNC));
  198305. }
  198306. ~ALSADevice()
  198307. {
  198308. if (handle != 0)
  198309. snd_pcm_close (handle);
  198310. }
  198311. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  198312. {
  198313. if (handle == 0)
  198314. return false;
  198315. snd_pcm_hw_params_t* hwParams;
  198316. snd_pcm_hw_params_alloca (&hwParams);
  198317. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  198318. return false;
  198319. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  198320. isInterleaved = false;
  198321. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  198322. isInterleaved = true;
  198323. else
  198324. {
  198325. jassertfalse
  198326. return false;
  198327. }
  198328. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  198329. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  198330. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  198331. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  198332. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  198333. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  198334. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  198335. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  198336. bitDepth = 0;
  198337. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  198338. {
  198339. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  198340. {
  198341. bitDepth = formatsToTry [i + 1];
  198342. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  198343. break;
  198344. }
  198345. }
  198346. if (bitDepth == 0)
  198347. {
  198348. error = "device doesn't support a compatible PCM format";
  198349. DBG (T("ALSA error: ") + error + T("\n"));
  198350. return false;
  198351. }
  198352. int dir = 0;
  198353. unsigned int periods = 4;
  198354. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  198355. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  198356. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  198357. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  198358. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  198359. || failed (snd_pcm_hw_params (handle, hwParams)))
  198360. {
  198361. return false;
  198362. }
  198363. snd_pcm_sw_params_t* swParams;
  198364. snd_pcm_sw_params_alloca (&swParams);
  198365. snd_pcm_uframes_t boundary;
  198366. if (failed (snd_pcm_sw_params_current (handle, swParams))
  198367. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  198368. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  198369. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  198370. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  198371. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  198372. || failed (snd_pcm_sw_params (handle, swParams)))
  198373. {
  198374. return false;
  198375. }
  198376. numChannelsRunning = numChannels;
  198377. return true;
  198378. }
  198379. bool write (float** const data, const int numSamples)
  198380. {
  198381. if (isInterleaved)
  198382. {
  198383. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198384. float* interleaved = (float*) scratch;
  198385. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  198386. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198387. snd_pcm_sframes_t num = snd_pcm_writei (handle, (void*) interleaved, numSamples);
  198388. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198389. return false;
  198390. }
  198391. else
  198392. {
  198393. for (int i = 0; i < numChannelsRunning; ++i)
  198394. if (data[i] != 0)
  198395. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  198396. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  198397. if (failed (num))
  198398. {
  198399. if (num == -EPIPE)
  198400. {
  198401. if (failed (snd_pcm_prepare (handle)))
  198402. return false;
  198403. }
  198404. else if (num != -ESTRPIPE)
  198405. return false;
  198406. }
  198407. }
  198408. return true;
  198409. }
  198410. bool read (float** const data, const int numSamples)
  198411. {
  198412. if (isInterleaved)
  198413. {
  198414. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198415. float* interleaved = (float*) scratch;
  198416. snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples);
  198417. if (failed (num))
  198418. {
  198419. if (num == -EPIPE)
  198420. {
  198421. if (failed (snd_pcm_prepare (handle)))
  198422. return false;
  198423. }
  198424. else if (num != -ESTRPIPE)
  198425. return false;
  198426. }
  198427. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198428. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198429. }
  198430. else
  198431. {
  198432. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198433. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198434. return false;
  198435. for (int i = 0; i < numChannelsRunning; ++i)
  198436. if (data[i] != 0)
  198437. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198438. }
  198439. return true;
  198440. }
  198441. juce_UseDebuggingNewOperator
  198442. snd_pcm_t* handle;
  198443. String error;
  198444. int bitDepth, numChannelsRunning;
  198445. private:
  198446. const bool isInput;
  198447. bool isInterleaved;
  198448. MemoryBlock scratch;
  198449. AudioDataConverters::DataFormat sampleFormat;
  198450. bool failed (const int errorNum)
  198451. {
  198452. if (errorNum >= 0)
  198453. return false;
  198454. error = snd_strerror (errorNum);
  198455. DBG (T("ALSA error: ") + error + T("\n"));
  198456. return true;
  198457. }
  198458. };
  198459. class ALSAThread : public Thread
  198460. {
  198461. public:
  198462. ALSAThread (const String& inputId_,
  198463. const String& outputId_)
  198464. : Thread ("Juce ALSA"),
  198465. sampleRate (0),
  198466. bufferSize (0),
  198467. callback (0),
  198468. inputId (inputId_),
  198469. outputId (outputId_),
  198470. outputDevice (0),
  198471. inputDevice (0),
  198472. numCallbacks (0),
  198473. totalNumInputChannels (0),
  198474. totalNumOutputChannels (0)
  198475. {
  198476. zeromem (outputChannelData, sizeof (outputChannelData));
  198477. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198478. zeromem (inputChannelData, sizeof (inputChannelData));
  198479. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198480. initialiseRatesAndChannels();
  198481. }
  198482. ~ALSAThread()
  198483. {
  198484. close();
  198485. }
  198486. void open (BitArray inputChannels,
  198487. BitArray outputChannels,
  198488. const double sampleRate_,
  198489. const int bufferSize_)
  198490. {
  198491. close();
  198492. error = String::empty;
  198493. sampleRate = sampleRate_;
  198494. bufferSize = bufferSize_;
  198495. currentInputChans.clear();
  198496. currentOutputChans.clear();
  198497. if (inputChannels.getHighestBit() >= 0)
  198498. {
  198499. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198500. {
  198501. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198502. if (inputChannels[i])
  198503. {
  198504. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198505. currentInputChans.setBit (i);
  198506. }
  198507. }
  198508. }
  198509. if (outputChannels.getHighestBit() >= 0)
  198510. {
  198511. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198512. {
  198513. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198514. if (outputChannels[i])
  198515. {
  198516. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198517. currentOutputChans.setBit (i);
  198518. }
  198519. }
  198520. }
  198521. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198522. {
  198523. outputDevice = new ALSADevice (outputId, false);
  198524. if (outputDevice->error.isNotEmpty())
  198525. {
  198526. error = outputDevice->error;
  198527. deleteAndZero (outputDevice);
  198528. return;
  198529. }
  198530. currentOutputChans.setRange (0, minChansOut, true);
  198531. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198532. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198533. bufferSize))
  198534. {
  198535. error = outputDevice->error;
  198536. deleteAndZero (outputDevice);
  198537. return;
  198538. }
  198539. }
  198540. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198541. {
  198542. inputDevice = new ALSADevice (inputId, true);
  198543. if (inputDevice->error.isNotEmpty())
  198544. {
  198545. error = inputDevice->error;
  198546. deleteAndZero (inputDevice);
  198547. return;
  198548. }
  198549. currentInputChans.setRange (0, minChansIn, true);
  198550. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198551. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198552. bufferSize))
  198553. {
  198554. error = inputDevice->error;
  198555. deleteAndZero (inputDevice);
  198556. return;
  198557. }
  198558. }
  198559. if (outputDevice == 0 && inputDevice == 0)
  198560. {
  198561. error = "no channels";
  198562. return;
  198563. }
  198564. if (outputDevice != 0 && inputDevice != 0)
  198565. {
  198566. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198567. }
  198568. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198569. return;
  198570. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198571. return;
  198572. startThread (9);
  198573. int count = 1000;
  198574. while (numCallbacks == 0)
  198575. {
  198576. sleep (5);
  198577. if (--count < 0 || ! isThreadRunning())
  198578. {
  198579. error = "device didn't start";
  198580. break;
  198581. }
  198582. }
  198583. }
  198584. void close()
  198585. {
  198586. stopThread (6000);
  198587. deleteAndZero (inputDevice);
  198588. deleteAndZero (outputDevice);
  198589. for (int i = 0; i < maxNumChans; ++i)
  198590. {
  198591. juce_free (inputChannelData [i]);
  198592. juce_free (outputChannelData [i]);
  198593. }
  198594. zeromem (outputChannelData, sizeof (outputChannelData));
  198595. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198596. zeromem (inputChannelData, sizeof (inputChannelData));
  198597. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198598. totalNumOutputChannels = 0;
  198599. totalNumInputChannels = 0;
  198600. numCallbacks = 0;
  198601. }
  198602. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198603. {
  198604. const ScopedLock sl (callbackLock);
  198605. callback = newCallback;
  198606. }
  198607. void run()
  198608. {
  198609. while (! threadShouldExit())
  198610. {
  198611. if (inputDevice != 0)
  198612. {
  198613. if (! inputDevice->read (inputChannelData, bufferSize))
  198614. {
  198615. DBG ("ALSA: read failure");
  198616. break;
  198617. }
  198618. }
  198619. if (threadShouldExit())
  198620. break;
  198621. {
  198622. const ScopedLock sl (callbackLock);
  198623. ++numCallbacks;
  198624. if (callback != 0)
  198625. {
  198626. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198627. totalNumInputChannels,
  198628. outputChannelDataForCallback,
  198629. totalNumOutputChannels,
  198630. bufferSize);
  198631. }
  198632. else
  198633. {
  198634. for (int i = 0; i < totalNumOutputChannels; ++i)
  198635. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198636. }
  198637. }
  198638. if (outputDevice != 0)
  198639. {
  198640. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198641. if (threadShouldExit())
  198642. break;
  198643. failed (snd_pcm_avail_update (outputDevice->handle));
  198644. if (! outputDevice->write (outputChannelData, bufferSize))
  198645. {
  198646. DBG ("ALSA: write failure");
  198647. break;
  198648. }
  198649. }
  198650. }
  198651. }
  198652. int getBitDepth() const throw()
  198653. {
  198654. if (outputDevice != 0)
  198655. return outputDevice->bitDepth;
  198656. if (inputDevice != 0)
  198657. return inputDevice->bitDepth;
  198658. return 16;
  198659. }
  198660. juce_UseDebuggingNewOperator
  198661. String error;
  198662. double sampleRate;
  198663. int bufferSize;
  198664. BitArray currentInputChans, currentOutputChans;
  198665. Array <int> sampleRates;
  198666. StringArray channelNamesOut, channelNamesIn;
  198667. AudioIODeviceCallback* callback;
  198668. private:
  198669. const String inputId, outputId;
  198670. ALSADevice* outputDevice;
  198671. ALSADevice* inputDevice;
  198672. int numCallbacks;
  198673. CriticalSection callbackLock;
  198674. float* outputChannelData [maxNumChans];
  198675. float* outputChannelDataForCallback [maxNumChans];
  198676. int totalNumInputChannels;
  198677. float* inputChannelData [maxNumChans];
  198678. float* inputChannelDataForCallback [maxNumChans];
  198679. int totalNumOutputChannels;
  198680. unsigned int minChansOut, maxChansOut;
  198681. unsigned int minChansIn, maxChansIn;
  198682. bool failed (const int errorNum) throw()
  198683. {
  198684. if (errorNum >= 0)
  198685. return false;
  198686. error = snd_strerror (errorNum);
  198687. DBG (T("ALSA error: ") + error + T("\n"));
  198688. return true;
  198689. }
  198690. void initialiseRatesAndChannels() throw()
  198691. {
  198692. sampleRates.clear();
  198693. channelNamesOut.clear();
  198694. channelNamesIn.clear();
  198695. minChansOut = 0;
  198696. maxChansOut = 0;
  198697. minChansIn = 0;
  198698. maxChansIn = 0;
  198699. unsigned int dummy = 0;
  198700. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198701. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198702. unsigned int i;
  198703. for (i = 0; i < maxChansOut; ++i)
  198704. channelNamesOut.add (T("channel ") + String ((int) i + 1));
  198705. for (i = 0; i < maxChansIn; ++i)
  198706. channelNamesIn.add (T("channel ") + String ((int) i + 1));
  198707. }
  198708. };
  198709. class ALSAAudioIODevice : public AudioIODevice
  198710. {
  198711. public:
  198712. ALSAAudioIODevice (const String& deviceName,
  198713. const String& inputId_,
  198714. const String& outputId_)
  198715. : AudioIODevice (deviceName, T("ALSA")),
  198716. inputId (inputId_),
  198717. outputId (outputId_),
  198718. isOpen_ (false),
  198719. isStarted (false),
  198720. internal (0)
  198721. {
  198722. internal = new ALSAThread (inputId, outputId);
  198723. }
  198724. ~ALSAAudioIODevice()
  198725. {
  198726. delete internal;
  198727. }
  198728. const StringArray getOutputChannelNames()
  198729. {
  198730. return internal->channelNamesOut;
  198731. }
  198732. const StringArray getInputChannelNames()
  198733. {
  198734. return internal->channelNamesIn;
  198735. }
  198736. int getNumSampleRates()
  198737. {
  198738. return internal->sampleRates.size();
  198739. }
  198740. double getSampleRate (int index)
  198741. {
  198742. return internal->sampleRates [index];
  198743. }
  198744. int getNumBufferSizesAvailable()
  198745. {
  198746. return 50;
  198747. }
  198748. int getBufferSizeSamples (int index)
  198749. {
  198750. int n = 16;
  198751. for (int i = 0; i < index; ++i)
  198752. n += n < 64 ? 16
  198753. : (n < 512 ? 32
  198754. : (n < 1024 ? 64
  198755. : (n < 2048 ? 128 : 256)));
  198756. return n;
  198757. }
  198758. int getDefaultBufferSize()
  198759. {
  198760. return 512;
  198761. }
  198762. const String open (const BitArray& inputChannels,
  198763. const BitArray& outputChannels,
  198764. double sampleRate,
  198765. int bufferSizeSamples)
  198766. {
  198767. close();
  198768. if (bufferSizeSamples <= 0)
  198769. bufferSizeSamples = getDefaultBufferSize();
  198770. if (sampleRate <= 0)
  198771. {
  198772. for (int i = 0; i < getNumSampleRates(); ++i)
  198773. {
  198774. if (getSampleRate (i) >= 44100)
  198775. {
  198776. sampleRate = getSampleRate (i);
  198777. break;
  198778. }
  198779. }
  198780. }
  198781. internal->open (inputChannels, outputChannels,
  198782. sampleRate, bufferSizeSamples);
  198783. isOpen_ = internal->error.isEmpty();
  198784. return internal->error;
  198785. }
  198786. void close()
  198787. {
  198788. stop();
  198789. internal->close();
  198790. isOpen_ = false;
  198791. }
  198792. bool isOpen()
  198793. {
  198794. return isOpen_;
  198795. }
  198796. int getCurrentBufferSizeSamples()
  198797. {
  198798. return internal->bufferSize;
  198799. }
  198800. double getCurrentSampleRate()
  198801. {
  198802. return internal->sampleRate;
  198803. }
  198804. int getCurrentBitDepth()
  198805. {
  198806. return internal->getBitDepth();
  198807. }
  198808. const BitArray getActiveOutputChannels() const
  198809. {
  198810. return internal->currentOutputChans;
  198811. }
  198812. const BitArray getActiveInputChannels() const
  198813. {
  198814. return internal->currentInputChans;
  198815. }
  198816. int getOutputLatencyInSamples()
  198817. {
  198818. return 0;
  198819. }
  198820. int getInputLatencyInSamples()
  198821. {
  198822. return 0;
  198823. }
  198824. void start (AudioIODeviceCallback* callback)
  198825. {
  198826. if (! isOpen_)
  198827. callback = 0;
  198828. internal->setCallback (callback);
  198829. if (callback != 0)
  198830. callback->audioDeviceAboutToStart (this);
  198831. isStarted = (callback != 0);
  198832. }
  198833. void stop()
  198834. {
  198835. AudioIODeviceCallback* const oldCallback = internal->callback;
  198836. start (0);
  198837. if (oldCallback != 0)
  198838. oldCallback->audioDeviceStopped();
  198839. }
  198840. bool isPlaying()
  198841. {
  198842. return isStarted && internal->error.isEmpty();
  198843. }
  198844. const String getLastError()
  198845. {
  198846. return internal->error;
  198847. }
  198848. String inputId, outputId;
  198849. private:
  198850. bool isOpen_, isStarted;
  198851. ALSAThread* internal;
  198852. };
  198853. class ALSAAudioIODeviceType : public AudioIODeviceType
  198854. {
  198855. public:
  198856. ALSAAudioIODeviceType()
  198857. : AudioIODeviceType (T("ALSA")),
  198858. hasScanned (false)
  198859. {
  198860. }
  198861. ~ALSAAudioIODeviceType()
  198862. {
  198863. }
  198864. void scanForDevices()
  198865. {
  198866. if (hasScanned)
  198867. return;
  198868. hasScanned = true;
  198869. inputNames.clear();
  198870. inputIds.clear();
  198871. outputNames.clear();
  198872. outputIds.clear();
  198873. snd_ctl_t* handle;
  198874. snd_ctl_card_info_t* info;
  198875. snd_ctl_card_info_alloca (&info);
  198876. int cardNum = -1;
  198877. while (outputIds.size() + inputIds.size() <= 32)
  198878. {
  198879. snd_card_next (&cardNum);
  198880. if (cardNum < 0)
  198881. break;
  198882. if (snd_ctl_open (&handle, T("hw:") + String (cardNum), SND_CTL_NONBLOCK) >= 0)
  198883. {
  198884. if (snd_ctl_card_info (handle, info) >= 0)
  198885. {
  198886. String cardId (snd_ctl_card_info_get_id (info));
  198887. if (cardId.removeCharacters (T("0123456789")).isEmpty())
  198888. cardId = String (cardNum);
  198889. int device = -1;
  198890. for (;;)
  198891. {
  198892. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198893. break;
  198894. String id, name;
  198895. id << "hw:" << cardId << ',' << device;
  198896. bool isInput, isOutput;
  198897. if (testDevice (id, isInput, isOutput))
  198898. {
  198899. name << snd_ctl_card_info_get_name (info);
  198900. if (name.isEmpty())
  198901. name = id;
  198902. if (isInput)
  198903. {
  198904. inputNames.add (name);
  198905. inputIds.add (id);
  198906. }
  198907. if (isOutput)
  198908. {
  198909. outputNames.add (name);
  198910. outputIds.add (id);
  198911. }
  198912. }
  198913. }
  198914. }
  198915. snd_ctl_close (handle);
  198916. }
  198917. }
  198918. inputNames.appendNumbersToDuplicates (false, true);
  198919. outputNames.appendNumbersToDuplicates (false, true);
  198920. }
  198921. const StringArray getDeviceNames (const bool wantInputNames) const
  198922. {
  198923. jassert (hasScanned); // need to call scanForDevices() before doing this
  198924. return wantInputNames ? inputNames : outputNames;
  198925. }
  198926. int getDefaultDeviceIndex (const bool forInput) const
  198927. {
  198928. jassert (hasScanned); // need to call scanForDevices() before doing this
  198929. return 0;
  198930. }
  198931. bool hasSeparateInputsAndOutputs() const { return true; }
  198932. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  198933. {
  198934. jassert (hasScanned); // need to call scanForDevices() before doing this
  198935. ALSAAudioIODevice* const d = dynamic_cast <ALSAAudioIODevice*> (device);
  198936. if (d == 0)
  198937. return -1;
  198938. return asInput ? inputIds.indexOf (d->inputId)
  198939. : outputIds.indexOf (d->outputId);
  198940. }
  198941. AudioIODevice* createDevice (const String& outputDeviceName,
  198942. const String& inputDeviceName)
  198943. {
  198944. jassert (hasScanned); // need to call scanForDevices() before doing this
  198945. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198946. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198947. String deviceName (outputIndex >= 0 ? outputDeviceName
  198948. : inputDeviceName);
  198949. if (inputIndex >= 0 || outputIndex >= 0)
  198950. return new ALSAAudioIODevice (deviceName,
  198951. inputIds [inputIndex],
  198952. outputIds [outputIndex]);
  198953. return 0;
  198954. }
  198955. juce_UseDebuggingNewOperator
  198956. private:
  198957. StringArray inputNames, outputNames, inputIds, outputIds;
  198958. bool hasScanned;
  198959. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198960. {
  198961. unsigned int minChansOut = 0, maxChansOut = 0;
  198962. unsigned int minChansIn = 0, maxChansIn = 0;
  198963. Array <int> rates;
  198964. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198965. DBG (T("ALSA device: ") + id
  198966. + T(" outs=") + String ((int) minChansOut) + T("-") + String ((int) maxChansOut)
  198967. + T(" ins=") + String ((int) minChansIn) + T("-") + String ((int) maxChansIn)
  198968. + T(" rates=") + String (rates.size()));
  198969. isInput = maxChansIn > 0;
  198970. isOutput = maxChansOut > 0;
  198971. return (isInput || isOutput) && rates.size() > 0;
  198972. }
  198973. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198974. const ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198975. };
  198976. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198977. {
  198978. return new ALSAAudioIODeviceType();
  198979. }
  198980. #endif
  198981. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198982. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198983. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198984. // compiled on its own).
  198985. #ifdef JUCE_INCLUDED_FILE
  198986. #if JUCE_JACK
  198987. static void* juce_libjack_handle = 0;
  198988. void* juce_load_jack_function (const char* const name)
  198989. {
  198990. if (juce_libjack_handle == 0)
  198991. return 0;
  198992. return dlsym (juce_libjack_handle, name);
  198993. }
  198994. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198995. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198996. return_type fn_name argument_types { \
  198997. static fn_name##_ptr_t fn = 0; \
  198998. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198999. if (fn) return (*fn)arguments; \
  199000. else return 0; \
  199001. }
  199002. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  199003. typedef void (*fn_name##_ptr_t)argument_types; \
  199004. void fn_name argument_types { \
  199005. static fn_name##_ptr_t fn = 0; \
  199006. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  199007. if (fn) (*fn)arguments; \
  199008. }
  199009. 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));
  199010. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  199011. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  199012. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  199013. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  199014. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  199015. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  199016. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  199017. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  199018. 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));
  199019. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  199020. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  199021. 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));
  199022. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  199023. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  199024. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  199025. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  199026. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  199027. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  199028. #if JUCE_DEBUG
  199029. #define JACK_LOGGING_ENABLED 1
  199030. #endif
  199031. #if JACK_LOGGING_ENABLED
  199032. static void jack_Log (const String& s)
  199033. {
  199034. puts (s);
  199035. }
  199036. static void dumpJackErrorMessage (const jack_status_t status) throw()
  199037. {
  199038. if (status & JackServerFailed || status & JackServerError)
  199039. jack_Log ("Unable to connect to JACK server");
  199040. if (status & JackVersionError)
  199041. jack_Log ("Client's protocol version does not match");
  199042. if (status & JackInvalidOption)
  199043. jack_Log ("The operation contained an invalid or unsupported option");
  199044. if (status & JackNameNotUnique)
  199045. jack_Log ("The desired client name was not unique");
  199046. if (status & JackNoSuchClient)
  199047. jack_Log ("Requested client does not exist");
  199048. if (status & JackInitFailure)
  199049. jack_Log ("Unable to initialize client");
  199050. }
  199051. #else
  199052. #define dumpJackErrorMessage(a) {}
  199053. #define jack_Log(...) {}
  199054. #endif
  199055. #ifndef JUCE_JACK_CLIENT_NAME
  199056. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  199057. #endif
  199058. class JackAudioIODevice : public AudioIODevice
  199059. {
  199060. public:
  199061. JackAudioIODevice (const String& deviceName,
  199062. const String& inputId_,
  199063. const String& outputId_)
  199064. : AudioIODevice (deviceName, T("JACK")),
  199065. inputId (inputId_),
  199066. outputId (outputId_),
  199067. isOpen_ (false),
  199068. callback (0),
  199069. totalNumberOfInputChannels (0),
  199070. totalNumberOfOutputChannels (0)
  199071. {
  199072. jassert (deviceName.isNotEmpty());
  199073. jack_status_t status;
  199074. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  199075. if (client == 0)
  199076. {
  199077. dumpJackErrorMessage (status);
  199078. }
  199079. else
  199080. {
  199081. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  199082. // open input ports
  199083. const StringArray inputChannels (getInputChannelNames());
  199084. for (int i = 0; i < inputChannels.size(); i++)
  199085. {
  199086. String inputName;
  199087. inputName << "in_" << (++totalNumberOfInputChannels);
  199088. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) inputName,
  199089. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  199090. }
  199091. // open output ports
  199092. const StringArray outputChannels (getOutputChannelNames());
  199093. for (int i = 0; i < outputChannels.size (); i++)
  199094. {
  199095. String outputName;
  199096. outputName << "out_" << (++totalNumberOfOutputChannels);
  199097. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) outputName,
  199098. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  199099. }
  199100. inChans.calloc (totalNumberOfInputChannels + 2);
  199101. outChans.calloc (totalNumberOfOutputChannels + 2);
  199102. }
  199103. }
  199104. ~JackAudioIODevice()
  199105. {
  199106. close();
  199107. if (client != 0)
  199108. {
  199109. JUCE_NAMESPACE::jack_client_close (client);
  199110. client = 0;
  199111. }
  199112. }
  199113. const StringArray getChannelNames (bool forInput) const
  199114. {
  199115. StringArray names;
  199116. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  199117. forInput ? JackPortIsInput : JackPortIsOutput);
  199118. if (ports != 0)
  199119. {
  199120. int j = 0;
  199121. while (ports[j] != 0)
  199122. {
  199123. const String portName (ports [j++]);
  199124. if (portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199125. names.add (portName.fromFirstOccurrenceOf (T(":"), false, false));
  199126. }
  199127. free (ports);
  199128. }
  199129. return names;
  199130. }
  199131. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  199132. const StringArray getInputChannelNames() { return getChannelNames (true); }
  199133. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  199134. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  199135. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  199136. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  199137. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  199138. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  199139. double sampleRate, int bufferSizeSamples)
  199140. {
  199141. if (client == 0)
  199142. {
  199143. lastError = T("No JACK client running");
  199144. return lastError;
  199145. }
  199146. lastError = String::empty;
  199147. close();
  199148. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  199149. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  199150. JUCE_NAMESPACE::jack_activate (client);
  199151. isOpen_ = true;
  199152. if (! inputChannels.isEmpty())
  199153. {
  199154. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199155. if (ports != 0)
  199156. {
  199157. const int numInputChannels = inputChannels.getHighestBit () + 1;
  199158. for (int i = 0; i < numInputChannels; ++i)
  199159. {
  199160. const String portName (ports[i]);
  199161. if (inputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199162. {
  199163. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  199164. if (error != 0)
  199165. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199166. }
  199167. }
  199168. free (ports);
  199169. }
  199170. }
  199171. if (! outputChannels.isEmpty())
  199172. {
  199173. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199174. if (ports != 0)
  199175. {
  199176. const int numOutputChannels = outputChannels.getHighestBit () + 1;
  199177. for (int i = 0; i < numOutputChannels; ++i)
  199178. {
  199179. const String portName (ports[i]);
  199180. if (outputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199181. {
  199182. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  199183. if (error != 0)
  199184. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199185. }
  199186. }
  199187. free (ports);
  199188. }
  199189. }
  199190. return lastError;
  199191. }
  199192. void close()
  199193. {
  199194. stop();
  199195. if (client != 0)
  199196. {
  199197. JUCE_NAMESPACE::jack_deactivate (client);
  199198. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  199199. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  199200. }
  199201. isOpen_ = false;
  199202. }
  199203. void start (AudioIODeviceCallback* newCallback)
  199204. {
  199205. if (isOpen_ && newCallback != callback)
  199206. {
  199207. if (newCallback != 0)
  199208. newCallback->audioDeviceAboutToStart (this);
  199209. AudioIODeviceCallback* const oldCallback = callback;
  199210. {
  199211. const ScopedLock sl (callbackLock);
  199212. callback = newCallback;
  199213. }
  199214. if (oldCallback != 0)
  199215. oldCallback->audioDeviceStopped();
  199216. }
  199217. }
  199218. void stop()
  199219. {
  199220. start (0);
  199221. }
  199222. bool isOpen() { return isOpen_; }
  199223. bool isPlaying() { return callback != 0; }
  199224. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  199225. double getCurrentSampleRate() { return getSampleRate (0); }
  199226. int getCurrentBitDepth() { return 32; }
  199227. const String getLastError() { return lastError; }
  199228. const BitArray getActiveOutputChannels() const
  199229. {
  199230. BitArray outputBits;
  199231. for (int i = 0; i < outputPorts.size(); i++)
  199232. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  199233. outputBits.setBit (i);
  199234. return outputBits;
  199235. }
  199236. const BitArray getActiveInputChannels() const
  199237. {
  199238. BitArray inputBits;
  199239. for (int i = 0; i < inputPorts.size(); i++)
  199240. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  199241. inputBits.setBit (i);
  199242. return inputBits;
  199243. }
  199244. int getOutputLatencyInSamples()
  199245. {
  199246. int latency = 0;
  199247. for (int i = 0; i < outputPorts.size(); i++)
  199248. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  199249. return latency;
  199250. }
  199251. int getInputLatencyInSamples()
  199252. {
  199253. int latency = 0;
  199254. for (int i = 0; i < inputPorts.size(); i++)
  199255. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  199256. return latency;
  199257. }
  199258. String inputId, outputId;
  199259. private:
  199260. void process (const int numSamples)
  199261. {
  199262. int i, numActiveInChans = 0, numActiveOutChans = 0;
  199263. for (i = 0; i < totalNumberOfInputChannels; ++i)
  199264. {
  199265. jack_default_audio_sample_t* in
  199266. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  199267. if (in != 0)
  199268. inChans [numActiveInChans++] = (float*) in;
  199269. }
  199270. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  199271. {
  199272. jack_default_audio_sample_t* out
  199273. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  199274. if (out != 0)
  199275. outChans [numActiveOutChans++] = (float*) out;
  199276. }
  199277. const ScopedLock sl (callbackLock);
  199278. if (callback != 0)
  199279. {
  199280. callback->audioDeviceIOCallback ((const float**) inChans, numActiveInChans,
  199281. outChans, numActiveOutChans, numSamples);
  199282. }
  199283. else
  199284. {
  199285. for (i = 0; i < numActiveOutChans; ++i)
  199286. zeromem (outChans[i], sizeof (float) * numSamples);
  199287. }
  199288. }
  199289. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  199290. {
  199291. if (callbackArgument != 0)
  199292. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  199293. return 0;
  199294. }
  199295. static void threadInitCallback (void* callbackArgument)
  199296. {
  199297. jack_Log ("JackAudioIODevice::initialise");
  199298. }
  199299. static void shutdownCallback (void* callbackArgument)
  199300. {
  199301. jack_Log ("JackAudioIODevice::shutdown");
  199302. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  199303. if (device != 0)
  199304. {
  199305. device->client = 0;
  199306. device->close();
  199307. }
  199308. }
  199309. static void errorCallback (const char* msg)
  199310. {
  199311. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  199312. }
  199313. bool isOpen_;
  199314. jack_client_t* client;
  199315. String lastError;
  199316. AudioIODeviceCallback* callback;
  199317. CriticalSection callbackLock;
  199318. HeapBlock <float*> inChans, outChans;
  199319. int totalNumberOfInputChannels;
  199320. int totalNumberOfOutputChannels;
  199321. VoidArray inputPorts, outputPorts;
  199322. };
  199323. class JackAudioIODeviceType : public AudioIODeviceType
  199324. {
  199325. public:
  199326. JackAudioIODeviceType()
  199327. : AudioIODeviceType (T("JACK")),
  199328. hasScanned (false)
  199329. {
  199330. }
  199331. ~JackAudioIODeviceType()
  199332. {
  199333. }
  199334. void scanForDevices()
  199335. {
  199336. hasScanned = true;
  199337. inputNames.clear();
  199338. inputIds.clear();
  199339. outputNames.clear();
  199340. outputIds.clear();
  199341. if (juce_libjack_handle == 0)
  199342. {
  199343. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  199344. if (juce_libjack_handle == 0)
  199345. return;
  199346. }
  199347. // open a dummy client
  199348. jack_status_t status;
  199349. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  199350. if (client == 0)
  199351. {
  199352. dumpJackErrorMessage (status);
  199353. }
  199354. else
  199355. {
  199356. // scan for output devices
  199357. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199358. if (ports != 0)
  199359. {
  199360. int j = 0;
  199361. while (ports[j] != 0)
  199362. {
  199363. String clientName (ports[j]);
  199364. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199365. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199366. && ! inputNames.contains (clientName))
  199367. {
  199368. inputNames.add (clientName);
  199369. inputIds.add (ports [j]);
  199370. }
  199371. ++j;
  199372. }
  199373. free (ports);
  199374. }
  199375. // scan for input devices
  199376. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199377. if (ports != 0)
  199378. {
  199379. int j = 0;
  199380. while (ports[j] != 0)
  199381. {
  199382. String clientName (ports[j]);
  199383. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199384. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199385. && ! outputNames.contains (clientName))
  199386. {
  199387. outputNames.add (clientName);
  199388. outputIds.add (ports [j]);
  199389. }
  199390. ++j;
  199391. }
  199392. free (ports);
  199393. }
  199394. JUCE_NAMESPACE::jack_client_close (client);
  199395. }
  199396. }
  199397. const StringArray getDeviceNames (const bool wantInputNames) const
  199398. {
  199399. jassert (hasScanned); // need to call scanForDevices() before doing this
  199400. return wantInputNames ? inputNames : outputNames;
  199401. }
  199402. int getDefaultDeviceIndex (const bool forInput) const
  199403. {
  199404. jassert (hasScanned); // need to call scanForDevices() before doing this
  199405. return 0;
  199406. }
  199407. bool hasSeparateInputsAndOutputs() const { return true; }
  199408. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  199409. {
  199410. jassert (hasScanned); // need to call scanForDevices() before doing this
  199411. JackAudioIODevice* const d = dynamic_cast <JackAudioIODevice*> (device);
  199412. if (d == 0)
  199413. return -1;
  199414. return asInput ? inputIds.indexOf (d->inputId)
  199415. : outputIds.indexOf (d->outputId);
  199416. }
  199417. AudioIODevice* createDevice (const String& outputDeviceName,
  199418. const String& inputDeviceName)
  199419. {
  199420. jassert (hasScanned); // need to call scanForDevices() before doing this
  199421. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199422. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199423. if (inputIndex >= 0 || outputIndex >= 0)
  199424. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199425. : inputDeviceName,
  199426. inputIds [inputIndex],
  199427. outputIds [outputIndex]);
  199428. return 0;
  199429. }
  199430. juce_UseDebuggingNewOperator
  199431. private:
  199432. StringArray inputNames, outputNames, inputIds, outputIds;
  199433. bool hasScanned;
  199434. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199435. const JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199436. };
  199437. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199438. {
  199439. return new JackAudioIODeviceType();
  199440. }
  199441. #else // if JACK is turned off..
  199442. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199443. #endif
  199444. #endif
  199445. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199446. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199447. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199448. // compiled on its own).
  199449. #if JUCE_INCLUDED_FILE
  199450. #if JUCE_ALSA
  199451. static snd_seq_t* iterateDevices (const bool forInput,
  199452. StringArray& deviceNamesFound,
  199453. const int deviceIndexToOpen)
  199454. {
  199455. snd_seq_t* returnedHandle = 0;
  199456. snd_seq_t* seqHandle;
  199457. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199458. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199459. {
  199460. snd_seq_system_info_t* systemInfo;
  199461. snd_seq_client_info_t* clientInfo;
  199462. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199463. {
  199464. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199465. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199466. {
  199467. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199468. while (--numClients >= 0 && returnedHandle == 0)
  199469. {
  199470. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199471. {
  199472. snd_seq_port_info_t* portInfo;
  199473. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199474. {
  199475. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199476. const int client = snd_seq_client_info_get_client (clientInfo);
  199477. snd_seq_port_info_set_client (portInfo, client);
  199478. snd_seq_port_info_set_port (portInfo, -1);
  199479. while (--numPorts >= 0)
  199480. {
  199481. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199482. && (snd_seq_port_info_get_capability (portInfo)
  199483. & (forInput ? SND_SEQ_PORT_CAP_READ
  199484. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199485. {
  199486. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199487. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199488. {
  199489. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199490. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199491. if (sourcePort != -1)
  199492. {
  199493. snd_seq_set_client_name (seqHandle,
  199494. forInput ? "Juce Midi Input"
  199495. : "Juce Midi Output");
  199496. const int portId
  199497. = snd_seq_create_simple_port (seqHandle,
  199498. forInput ? "Juce Midi In Port"
  199499. : "Juce Midi Out Port",
  199500. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199501. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199502. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199503. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199504. returnedHandle = seqHandle;
  199505. }
  199506. }
  199507. }
  199508. }
  199509. snd_seq_port_info_free (portInfo);
  199510. }
  199511. }
  199512. }
  199513. snd_seq_client_info_free (clientInfo);
  199514. }
  199515. snd_seq_system_info_free (systemInfo);
  199516. }
  199517. if (returnedHandle == 0)
  199518. snd_seq_close (seqHandle);
  199519. }
  199520. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199521. return returnedHandle;
  199522. }
  199523. static snd_seq_t* createDevice (const bool forInput,
  199524. const String& deviceNameToOpen)
  199525. {
  199526. snd_seq_t* seqHandle = 0;
  199527. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199528. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199529. {
  199530. snd_seq_set_client_name (seqHandle,
  199531. (const char*) (forInput ? (deviceNameToOpen + T(" Input"))
  199532. : (deviceNameToOpen + T(" Output"))));
  199533. const int portId
  199534. = snd_seq_create_simple_port (seqHandle,
  199535. forInput ? "in"
  199536. : "out",
  199537. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199538. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199539. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199540. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199541. if (portId < 0)
  199542. {
  199543. snd_seq_close (seqHandle);
  199544. seqHandle = 0;
  199545. }
  199546. }
  199547. return seqHandle;
  199548. }
  199549. class MidiOutputDevice
  199550. {
  199551. public:
  199552. MidiOutputDevice (MidiOutput* const midiOutput_,
  199553. snd_seq_t* const seqHandle_)
  199554. :
  199555. midiOutput (midiOutput_),
  199556. seqHandle (seqHandle_),
  199557. maxEventSize (16 * 1024)
  199558. {
  199559. jassert (seqHandle != 0 && midiOutput != 0);
  199560. snd_midi_event_new (maxEventSize, &midiParser);
  199561. }
  199562. ~MidiOutputDevice()
  199563. {
  199564. snd_midi_event_free (midiParser);
  199565. snd_seq_close (seqHandle);
  199566. }
  199567. void sendMessageNow (const MidiMessage& message)
  199568. {
  199569. if (message.getRawDataSize() > maxEventSize)
  199570. {
  199571. maxEventSize = message.getRawDataSize();
  199572. snd_midi_event_free (midiParser);
  199573. snd_midi_event_new (maxEventSize, &midiParser);
  199574. }
  199575. snd_seq_event_t event;
  199576. snd_seq_ev_clear (&event);
  199577. snd_midi_event_encode (midiParser,
  199578. message.getRawData(),
  199579. message.getRawDataSize(),
  199580. &event);
  199581. snd_midi_event_reset_encode (midiParser);
  199582. snd_seq_ev_set_source (&event, 0);
  199583. snd_seq_ev_set_subs (&event);
  199584. snd_seq_ev_set_direct (&event);
  199585. snd_seq_event_output (seqHandle, &event);
  199586. snd_seq_drain_output (seqHandle);
  199587. }
  199588. juce_UseDebuggingNewOperator
  199589. private:
  199590. MidiOutput* const midiOutput;
  199591. snd_seq_t* const seqHandle;
  199592. snd_midi_event_t* midiParser;
  199593. int maxEventSize;
  199594. };
  199595. const StringArray MidiOutput::getDevices()
  199596. {
  199597. StringArray devices;
  199598. iterateDevices (false, devices, -1);
  199599. return devices;
  199600. }
  199601. int MidiOutput::getDefaultDeviceIndex()
  199602. {
  199603. return 0;
  199604. }
  199605. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199606. {
  199607. MidiOutput* newDevice = 0;
  199608. StringArray devices;
  199609. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199610. if (handle != 0)
  199611. {
  199612. newDevice = new MidiOutput();
  199613. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199614. }
  199615. return newDevice;
  199616. }
  199617. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199618. {
  199619. MidiOutput* newDevice = 0;
  199620. snd_seq_t* const handle = createDevice (false, deviceName);
  199621. if (handle != 0)
  199622. {
  199623. newDevice = new MidiOutput();
  199624. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199625. }
  199626. return newDevice;
  199627. }
  199628. MidiOutput::~MidiOutput()
  199629. {
  199630. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199631. delete device;
  199632. }
  199633. void MidiOutput::reset()
  199634. {
  199635. }
  199636. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199637. {
  199638. return false;
  199639. }
  199640. void MidiOutput::setVolume (float leftVol, float rightVol)
  199641. {
  199642. }
  199643. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199644. {
  199645. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199646. }
  199647. class MidiInputThread : public Thread
  199648. {
  199649. public:
  199650. MidiInputThread (MidiInput* const midiInput_,
  199651. snd_seq_t* const seqHandle_,
  199652. MidiInputCallback* const callback_)
  199653. : Thread (T("Juce MIDI Input")),
  199654. midiInput (midiInput_),
  199655. seqHandle (seqHandle_),
  199656. callback (callback_)
  199657. {
  199658. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199659. }
  199660. ~MidiInputThread()
  199661. {
  199662. snd_seq_close (seqHandle);
  199663. }
  199664. void run()
  199665. {
  199666. const int maxEventSize = 16 * 1024;
  199667. snd_midi_event_t* midiParser;
  199668. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199669. {
  199670. HeapBlock <uint8> buffer (maxEventSize);
  199671. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199672. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199673. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199674. while (! threadShouldExit())
  199675. {
  199676. if (poll (pfd, numPfds, 500) > 0)
  199677. {
  199678. snd_seq_event_t* inputEvent = 0;
  199679. snd_seq_nonblock (seqHandle, 1);
  199680. do
  199681. {
  199682. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199683. {
  199684. // xxx what about SYSEXes that are too big for the buffer?
  199685. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199686. snd_midi_event_reset_decode (midiParser);
  199687. if (numBytes > 0)
  199688. {
  199689. const MidiMessage message ((const uint8*) buffer,
  199690. numBytes,
  199691. Time::getMillisecondCounter() * 0.001);
  199692. callback->handleIncomingMidiMessage (midiInput, message);
  199693. }
  199694. snd_seq_free_event (inputEvent);
  199695. }
  199696. }
  199697. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199698. snd_seq_free_event (inputEvent);
  199699. }
  199700. }
  199701. snd_midi_event_free (midiParser);
  199702. }
  199703. };
  199704. juce_UseDebuggingNewOperator
  199705. private:
  199706. MidiInput* const midiInput;
  199707. snd_seq_t* const seqHandle;
  199708. MidiInputCallback* const callback;
  199709. };
  199710. MidiInput::MidiInput (const String& name_)
  199711. : name (name_),
  199712. internal (0)
  199713. {
  199714. }
  199715. MidiInput::~MidiInput()
  199716. {
  199717. stop();
  199718. MidiInputThread* const thread = (MidiInputThread*) internal;
  199719. delete thread;
  199720. }
  199721. void MidiInput::start()
  199722. {
  199723. ((MidiInputThread*) internal)->startThread();
  199724. }
  199725. void MidiInput::stop()
  199726. {
  199727. ((MidiInputThread*) internal)->stopThread (3000);
  199728. }
  199729. int MidiInput::getDefaultDeviceIndex()
  199730. {
  199731. return 0;
  199732. }
  199733. const StringArray MidiInput::getDevices()
  199734. {
  199735. StringArray devices;
  199736. iterateDevices (true, devices, -1);
  199737. return devices;
  199738. }
  199739. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199740. {
  199741. MidiInput* newDevice = 0;
  199742. StringArray devices;
  199743. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199744. if (handle != 0)
  199745. {
  199746. newDevice = new MidiInput (devices [deviceIndex]);
  199747. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199748. }
  199749. return newDevice;
  199750. }
  199751. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199752. {
  199753. MidiInput* newDevice = 0;
  199754. snd_seq_t* const handle = createDevice (true, deviceName);
  199755. if (handle != 0)
  199756. {
  199757. newDevice = new MidiInput (deviceName);
  199758. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199759. }
  199760. return newDevice;
  199761. }
  199762. #else
  199763. // (These are just stub functions if ALSA is unavailable...)
  199764. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199765. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199766. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199767. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199768. MidiOutput::~MidiOutput() {}
  199769. void MidiOutput::reset() {}
  199770. bool MidiOutput::getVolume (float&, float&) { return false; }
  199771. void MidiOutput::setVolume (float, float) {}
  199772. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199773. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199774. MidiInput::~MidiInput() {}
  199775. void MidiInput::start() {}
  199776. void MidiInput::stop() {}
  199777. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199778. const StringArray MidiInput::getDevices() { return StringArray(); }
  199779. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199780. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199781. #endif
  199782. #endif
  199783. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199784. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199785. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199786. // compiled on its own).
  199787. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199788. AudioCDReader::AudioCDReader()
  199789. : AudioFormatReader (0, T("CD Audio"))
  199790. {
  199791. }
  199792. const StringArray AudioCDReader::getAvailableCDNames()
  199793. {
  199794. StringArray names;
  199795. return names;
  199796. }
  199797. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199798. {
  199799. return 0;
  199800. }
  199801. AudioCDReader::~AudioCDReader()
  199802. {
  199803. }
  199804. void AudioCDReader::refreshTrackLengths()
  199805. {
  199806. }
  199807. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199808. int64 startSampleInFile, int numSamples)
  199809. {
  199810. return false;
  199811. }
  199812. bool AudioCDReader::isCDStillPresent() const
  199813. {
  199814. return false;
  199815. }
  199816. int AudioCDReader::getNumTracks() const
  199817. {
  199818. return 0;
  199819. }
  199820. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199821. {
  199822. return 0;
  199823. }
  199824. bool AudioCDReader::isTrackAudio (int trackNum) const
  199825. {
  199826. return false;
  199827. }
  199828. void AudioCDReader::enableIndexScanning (bool b)
  199829. {
  199830. }
  199831. int AudioCDReader::getLastIndex() const
  199832. {
  199833. return 0;
  199834. }
  199835. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199836. {
  199837. return Array<int>();
  199838. }
  199839. int AudioCDReader::getCDDBId()
  199840. {
  199841. return 0;
  199842. }
  199843. #endif
  199844. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199845. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199846. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199847. // compiled on its own).
  199848. #if JUCE_INCLUDED_FILE
  199849. void FileChooser::showPlatformDialog (Array<File>& results,
  199850. const String& title,
  199851. const File& file,
  199852. const String& filters,
  199853. bool isDirectory,
  199854. bool selectsFiles,
  199855. bool isSave,
  199856. bool warnAboutOverwritingExistingFiles,
  199857. bool selectMultipleFiles,
  199858. FilePreviewComponent* previewComponent)
  199859. {
  199860. const tchar* const separator = T(":");
  199861. String command ("zenity --file-selection");
  199862. if (title.isNotEmpty())
  199863. command << " --title=\"" << title << "\"";
  199864. if (file != File::nonexistent)
  199865. command << " --filename=\"" << file.getFullPathName () << "\"";
  199866. if (isDirectory)
  199867. command << " --directory";
  199868. if (isSave)
  199869. command << " --save";
  199870. if (selectMultipleFiles)
  199871. command << " --multiple --separator=\"" << separator << "\"";
  199872. command << " 2>&1";
  199873. MemoryOutputStream result;
  199874. int status = -1;
  199875. FILE* stream = popen ((const char*) command.toUTF8(), "r");
  199876. if (stream != 0)
  199877. {
  199878. for (;;)
  199879. {
  199880. char buffer [1024];
  199881. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199882. if (bytesRead <= 0)
  199883. break;
  199884. result.write (buffer, bytesRead);
  199885. }
  199886. status = pclose (stream);
  199887. }
  199888. if (status == 0)
  199889. {
  199890. String resultString (String::fromUTF8 ((const uint8*) result.getData(), result.getDataSize()));
  199891. StringArray tokens;
  199892. if (selectMultipleFiles)
  199893. tokens.addTokens (resultString, separator, 0);
  199894. else
  199895. tokens.add (resultString);
  199896. for (int i = 0; i < tokens.size(); i++)
  199897. results.add (File (tokens[i]));
  199898. return;
  199899. }
  199900. //xxx ain't got one!
  199901. jassertfalse
  199902. }
  199903. #endif
  199904. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199905. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199906. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199907. // compiled on its own).
  199908. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199909. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199910. : browser (0),
  199911. blankPageShown (false),
  199912. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199913. {
  199914. setOpaque (true);
  199915. }
  199916. WebBrowserComponent::~WebBrowserComponent()
  199917. {
  199918. }
  199919. void WebBrowserComponent::goToURL (const String& url,
  199920. const StringArray* headers,
  199921. const MemoryBlock* postData)
  199922. {
  199923. lastURL = url;
  199924. lastHeaders.clear();
  199925. if (headers != 0)
  199926. lastHeaders = *headers;
  199927. lastPostData.setSize (0);
  199928. if (postData != 0)
  199929. lastPostData = *postData;
  199930. blankPageShown = false;
  199931. }
  199932. void WebBrowserComponent::stop()
  199933. {
  199934. }
  199935. void WebBrowserComponent::goBack()
  199936. {
  199937. lastURL = String::empty;
  199938. blankPageShown = false;
  199939. }
  199940. void WebBrowserComponent::goForward()
  199941. {
  199942. lastURL = String::empty;
  199943. }
  199944. void WebBrowserComponent::refresh()
  199945. {
  199946. }
  199947. void WebBrowserComponent::paint (Graphics& g)
  199948. {
  199949. g.fillAll (Colours::white);
  199950. }
  199951. void WebBrowserComponent::checkWindowAssociation()
  199952. {
  199953. }
  199954. void WebBrowserComponent::reloadLastURL()
  199955. {
  199956. if (lastURL.isNotEmpty())
  199957. {
  199958. goToURL (lastURL, &lastHeaders, &lastPostData);
  199959. lastURL = String::empty;
  199960. }
  199961. }
  199962. void WebBrowserComponent::parentHierarchyChanged()
  199963. {
  199964. checkWindowAssociation();
  199965. }
  199966. void WebBrowserComponent::resized()
  199967. {
  199968. }
  199969. void WebBrowserComponent::visibilityChanged()
  199970. {
  199971. checkWindowAssociation();
  199972. }
  199973. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199974. {
  199975. return true;
  199976. }
  199977. #endif
  199978. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199979. #endif
  199980. END_JUCE_NAMESPACE
  199981. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199982. #endif
  199983. #if JUCE_MAC || JUCE_IPHONE
  199984. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199985. BEGIN_JUCE_NAMESPACE
  199986. #undef Point
  199987. #define JUCE_INCLUDED_FILE 1
  199988. // Now include the actual code files..
  199989. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199990. #ifndef JUCE_ObjCExtraSuffix
  199991. #define JUCE_ObjCExtraSuffix 3
  199992. #endif
  199993. #define appendMacro1(a, b, c, d) a ## _ ## b ## _ ## c ## _ ## d
  199994. #define appendMacro2(a, b, c, d) appendMacro1(a, b, c, d)
  199995. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_ObjCExtraSuffix)
  199996. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199997. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199998. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199999. // compiled on its own).
  200000. #if JUCE_INCLUDED_FILE
  200001. static const String nsStringToJuce (NSString* s)
  200002. {
  200003. return String::fromUTF8 ((uint8*) [s UTF8String]);
  200004. }
  200005. static NSString* juceStringToNS (const String& s)
  200006. {
  200007. return [NSString stringWithUTF8String: (const char*) s.toUTF8()];
  200008. }
  200009. static const String convertUTF16ToString (const UniChar* utf16)
  200010. {
  200011. String s;
  200012. while (*utf16 != 0)
  200013. s += (juce_wchar) *utf16++;
  200014. return s;
  200015. }
  200016. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  200017. {
  200018. String result;
  200019. if (cfString != 0)
  200020. {
  200021. #if JUCE_STRINGS_ARE_UNICODE
  200022. CFRange range = { 0, CFStringGetLength (cfString) };
  200023. HeapBlock <UniChar> u (range.length + 1);
  200024. CFStringGetCharacters (cfString, range, u);
  200025. u[range.length] = 0;
  200026. result = convertUTF16ToString (u);
  200027. #else
  200028. const int len = CFStringGetLength (cfString);
  200029. HeapBlock <char> buffer (len + 1);
  200030. CFStringGetCString (cfString, buffer, len + 1, CFStringGetSystemEncoding());
  200031. result = buffer;
  200032. #endif
  200033. }
  200034. return result;
  200035. }
  200036. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  200037. {
  200038. #if JUCE_STRINGS_ARE_UNICODE
  200039. const int len = s.length();
  200040. const juce_wchar* t = (const juce_wchar*) s;
  200041. HeapBlock <UniChar> temp (len + 2);
  200042. for (int i = 0; i <= len; ++i)
  200043. temp[i] = t[i];
  200044. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  200045. #else
  200046. return CFStringCreateWithCString (kCFAllocatorDefault,
  200047. (const char*) s,
  200048. CFStringGetSystemEncoding());
  200049. #endif
  200050. }
  200051. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  200052. {
  200053. #if JUCE_IPHONE
  200054. const ScopedAutoReleasePool pool;
  200055. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  200056. #else
  200057. UnicodeMapping map;
  200058. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  200059. kUnicodeNoSubset,
  200060. kTextEncodingDefaultFormat);
  200061. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  200062. kUnicodeCanonicalCompVariant,
  200063. kTextEncodingDefaultFormat);
  200064. map.mappingVersion = kUnicodeUseLatestMapping;
  200065. UnicodeToTextInfo conversionInfo = 0;
  200066. String result;
  200067. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  200068. {
  200069. const int len = s.length();
  200070. HeapBlock <UniChar> tempIn, tempOut;
  200071. tempIn.calloc (len + 2);
  200072. tempOut.calloc (len + 2);
  200073. for (int i = 0; i <= len; ++i)
  200074. tempIn[i] = s[i];
  200075. ByteCount bytesRead = 0;
  200076. ByteCount outputBufferSize = 0;
  200077. if (ConvertFromUnicodeToText (conversionInfo,
  200078. len * sizeof (UniChar), tempIn,
  200079. kUnicodeDefaultDirectionMask,
  200080. 0, 0, 0, 0,
  200081. len * sizeof (UniChar), &bytesRead,
  200082. &outputBufferSize, tempOut) == noErr)
  200083. {
  200084. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  200085. tchar* t = const_cast <tchar*> ((const tchar*) result);
  200086. unsigned int i;
  200087. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  200088. t[i] = (tchar) tempOut[i];
  200089. t[i] = 0;
  200090. }
  200091. DisposeUnicodeToTextInfo (&conversionInfo);
  200092. }
  200093. return result;
  200094. #endif
  200095. }
  200096. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  200097. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  200098. {
  200099. #if JUCE_IPHONE
  200100. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  200101. forPasteboardType: @"public.text"];
  200102. #else
  200103. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  200104. owner: nil];
  200105. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  200106. forType: NSStringPboardType];
  200107. #endif
  200108. }
  200109. const String SystemClipboard::getTextFromClipboard() throw()
  200110. {
  200111. #if JUCE_IPHONE
  200112. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  200113. #else
  200114. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  200115. #endif
  200116. return text == 0 ? String::empty
  200117. : nsStringToJuce (text);
  200118. }
  200119. #endif
  200120. #endif
  200121. /*** End of inlined file: juce_mac_Strings.mm ***/
  200122. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  200123. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200124. // compiled on its own).
  200125. #if JUCE_INCLUDED_FILE
  200126. static int64 highResTimerFrequency = 0;
  200127. static double highResTimerToMillisecRatio = 0;
  200128. #if JUCE_INTEL
  200129. static void juce_getCpuVendor (char* const v) throw()
  200130. {
  200131. int vendor[4];
  200132. zerostruct (vendor);
  200133. int dummy = 0;
  200134. asm ("mov %%ebx, %%esi \n\t"
  200135. "cpuid \n\t"
  200136. "xchg %%esi, %%ebx"
  200137. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  200138. memcpy (v, vendor, 16);
  200139. }
  200140. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  200141. {
  200142. unsigned int cpu = 0;
  200143. unsigned int ext = 0;
  200144. unsigned int family = 0;
  200145. unsigned int dummy = 0;
  200146. asm ("mov %%ebx, %%esi \n\t"
  200147. "cpuid \n\t"
  200148. "xchg %%esi, %%ebx"
  200149. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  200150. familyModel = family;
  200151. extFeatures = ext;
  200152. return cpu;
  200153. }
  200154. struct CPUFlags
  200155. {
  200156. bool hasMMX : 1;
  200157. bool hasSSE : 1;
  200158. bool hasSSE2 : 1;
  200159. bool has3DNow : 1;
  200160. };
  200161. static CPUFlags cpuFlags;
  200162. #endif
  200163. void SystemStats::initialiseStats() throw()
  200164. {
  200165. static bool initialised = false;
  200166. if (! initialised)
  200167. {
  200168. initialised = true;
  200169. #if JUCE_MAC
  200170. // extremely annoying: adding this line stops the apple menu items from working. Of
  200171. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  200172. // any events.
  200173. //NSApplicationLoad();
  200174. [NSApplication sharedApplication];
  200175. #endif
  200176. #if JUCE_INTEL
  200177. {
  200178. unsigned int familyModel, extFeatures;
  200179. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  200180. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  200181. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  200182. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  200183. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  200184. }
  200185. #endif
  200186. mach_timebase_info_data_t timebase;
  200187. (void) mach_timebase_info (&timebase);
  200188. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  200189. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  200190. String s (SystemStats::getJUCEVersion());
  200191. rlimit lim;
  200192. getrlimit (RLIMIT_NOFILE, &lim);
  200193. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  200194. setrlimit (RLIMIT_NOFILE, &lim);
  200195. }
  200196. }
  200197. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  200198. {
  200199. return MacOSX;
  200200. }
  200201. const String SystemStats::getOperatingSystemName() throw()
  200202. {
  200203. return T("Mac OS X");
  200204. }
  200205. bool SystemStats::isOperatingSystem64Bit() throw()
  200206. {
  200207. #if JUCE_64BIT
  200208. return true;
  200209. #else
  200210. //xxx not sure how to find this out?..
  200211. return false;
  200212. #endif
  200213. }
  200214. int SystemStats::getMemorySizeInMegabytes() throw()
  200215. {
  200216. uint64 mem = 0;
  200217. size_t memSize = sizeof (mem);
  200218. int mib[] = { CTL_HW, HW_MEMSIZE };
  200219. sysctl (mib, 2, &mem, &memSize, 0, 0);
  200220. return (int) (mem / (1024 * 1024));
  200221. }
  200222. bool SystemStats::hasMMX() throw()
  200223. {
  200224. #if JUCE_INTEL
  200225. return cpuFlags.hasMMX;
  200226. #else
  200227. return false;
  200228. #endif
  200229. }
  200230. bool SystemStats::hasSSE() throw()
  200231. {
  200232. #if JUCE_INTEL
  200233. return cpuFlags.hasSSE;
  200234. #else
  200235. return false;
  200236. #endif
  200237. }
  200238. bool SystemStats::hasSSE2() throw()
  200239. {
  200240. #if JUCE_INTEL
  200241. return cpuFlags.hasSSE2;
  200242. #else
  200243. return false;
  200244. #endif
  200245. }
  200246. bool SystemStats::has3DNow() throw()
  200247. {
  200248. #if JUCE_INTEL
  200249. return cpuFlags.has3DNow;
  200250. #else
  200251. return false;
  200252. #endif
  200253. }
  200254. const String SystemStats::getCpuVendor() throw()
  200255. {
  200256. #if JUCE_INTEL
  200257. char v [16];
  200258. juce_getCpuVendor (v);
  200259. return String (v, 16);
  200260. #else
  200261. return String::empty;
  200262. #endif
  200263. }
  200264. int SystemStats::getCpuSpeedInMegaherz() throw()
  200265. {
  200266. uint64 speedHz = 0;
  200267. size_t speedSize = sizeof (speedHz);
  200268. int mib[] = { CTL_HW, HW_CPU_FREQ };
  200269. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  200270. #if JUCE_BIG_ENDIAN
  200271. if (speedSize == 4)
  200272. speedHz >>= 32;
  200273. #endif
  200274. return (int) (speedHz / 1000000);
  200275. }
  200276. int SystemStats::getNumCpus() throw()
  200277. {
  200278. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  200279. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  200280. #else
  200281. return MPProcessors();
  200282. #endif
  200283. }
  200284. const String SystemStats::getLogonName()
  200285. {
  200286. return nsStringToJuce (NSUserName());
  200287. }
  200288. const String SystemStats::getFullUserName()
  200289. {
  200290. return nsStringToJuce (NSFullUserName());
  200291. }
  200292. uint32 juce_millisecondsSinceStartup() throw()
  200293. {
  200294. return (uint32) (mach_absolute_time() * highResTimerToMillisecRatio);
  200295. }
  200296. double Time::getMillisecondCounterHiRes() throw()
  200297. {
  200298. return mach_absolute_time() * highResTimerToMillisecRatio;
  200299. }
  200300. int64 Time::getHighResolutionTicks() throw()
  200301. {
  200302. return (int64) mach_absolute_time();
  200303. }
  200304. int64 Time::getHighResolutionTicksPerSecond() throw()
  200305. {
  200306. return highResTimerFrequency;
  200307. }
  200308. int64 SystemStats::getClockCycleCounter() throw()
  200309. {
  200310. return (int64) mach_absolute_time();
  200311. }
  200312. bool Time::setSystemTimeToThisTime() const throw()
  200313. {
  200314. jassertfalse
  200315. return false;
  200316. }
  200317. int SystemStats::getPageSize() throw()
  200318. {
  200319. return (int) NSPageSize();
  200320. }
  200321. void PlatformUtilities::fpuReset()
  200322. {
  200323. }
  200324. #endif
  200325. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  200326. /*** Start of inlined file: juce_mac_Network.mm ***/
  200327. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200328. // compiled on its own).
  200329. #if JUCE_INCLUDED_FILE
  200330. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  200331. {
  200332. #ifndef IFT_ETHER
  200333. #define IFT_ETHER 6
  200334. #endif
  200335. ifaddrs* addrs = 0;
  200336. int numResults = 0;
  200337. if (getifaddrs (&addrs) == 0)
  200338. {
  200339. const ifaddrs* cursor = addrs;
  200340. while (cursor != 0 && numResults < maxNum)
  200341. {
  200342. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  200343. if (sto->ss_family == AF_LINK)
  200344. {
  200345. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  200346. if (sadd->sdl_type == IFT_ETHER)
  200347. {
  200348. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  200349. uint64 a = 0;
  200350. for (int i = 6; --i >= 0;)
  200351. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  200352. *addresses++ = (int64) a;
  200353. ++numResults;
  200354. }
  200355. }
  200356. cursor = cursor->ifa_next;
  200357. }
  200358. freeifaddrs (addrs);
  200359. }
  200360. return numResults;
  200361. }
  200362. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  200363. const String& emailSubject,
  200364. const String& bodyText,
  200365. const StringArray& filesToAttach)
  200366. {
  200367. #if JUCE_IPHONE
  200368. //xxx probably need to use MFMailComposeViewController
  200369. jassertfalse
  200370. return false;
  200371. #else
  200372. const ScopedAutoReleasePool pool;
  200373. String script;
  200374. script << "tell application \"Mail\"\r\n"
  200375. "set newMessage to make new outgoing message with properties {subject:\""
  200376. << emailSubject.replace (T("\""), T("\\\""))
  200377. << "\", content:\""
  200378. << bodyText.replace (T("\""), T("\\\""))
  200379. << "\" & return & return}\r\n"
  200380. "tell newMessage\r\n"
  200381. "set visible to true\r\n"
  200382. "set sender to \"sdfsdfsdfewf\"\r\n"
  200383. "make new to recipient at end of to recipients with properties {address:\""
  200384. << targetEmailAddress
  200385. << "\"}\r\n";
  200386. for (int i = 0; i < filesToAttach.size(); ++i)
  200387. {
  200388. script << "tell content\r\n"
  200389. "make new attachment with properties {file name:\""
  200390. << filesToAttach[i].replace (T("\""), T("\\\""))
  200391. << "\"} at after the last paragraph\r\n"
  200392. "end tell\r\n";
  200393. }
  200394. script << "end tell\r\n"
  200395. "end tell\r\n";
  200396. NSAppleScript* s = [[NSAppleScript alloc]
  200397. initWithSource: juceStringToNS (script)];
  200398. NSDictionary* error = 0;
  200399. const bool ok = [s executeAndReturnError: &error] != nil;
  200400. [s release];
  200401. return ok;
  200402. #endif
  200403. }
  200404. END_JUCE_NAMESPACE
  200405. using namespace JUCE_NAMESPACE;
  200406. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  200407. @interface JuceURLConnection : NSObject
  200408. {
  200409. @public
  200410. NSURLRequest* request;
  200411. NSURLConnection* connection;
  200412. NSMutableData* data;
  200413. Thread* runLoopThread;
  200414. bool initialised, hasFailed, hasFinished;
  200415. int position;
  200416. int64 contentLength;
  200417. NSLock* dataLock;
  200418. }
  200419. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  200420. - (void) dealloc;
  200421. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  200422. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  200423. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  200424. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  200425. - (BOOL) isOpen;
  200426. - (int) read: (char*) dest numBytes: (int) num;
  200427. - (int) readPosition;
  200428. - (void) stop;
  200429. - (void) createConnection;
  200430. @end
  200431. class JuceURLConnectionMessageThread : public Thread
  200432. {
  200433. JuceURLConnection* owner;
  200434. public:
  200435. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200436. : Thread (T("http connection")),
  200437. owner (owner_)
  200438. {
  200439. }
  200440. ~JuceURLConnectionMessageThread()
  200441. {
  200442. stopThread (10000);
  200443. }
  200444. void run()
  200445. {
  200446. [owner createConnection];
  200447. while (! threadShouldExit())
  200448. {
  200449. const ScopedAutoReleasePool pool;
  200450. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200451. }
  200452. }
  200453. };
  200454. @implementation JuceURLConnection
  200455. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200456. withCallback: (URL::OpenStreamProgressCallback*) callback
  200457. withContext: (void*) context;
  200458. {
  200459. [super init];
  200460. request = req;
  200461. [request retain];
  200462. data = [[NSMutableData data] retain];
  200463. dataLock = [[NSLock alloc] init];
  200464. connection = 0;
  200465. initialised = false;
  200466. hasFailed = false;
  200467. hasFinished = false;
  200468. contentLength = -1;
  200469. runLoopThread = new JuceURLConnectionMessageThread (self);
  200470. runLoopThread->startThread();
  200471. while (runLoopThread->isThreadRunning() && ! initialised)
  200472. {
  200473. if (callback != 0)
  200474. callback (context, -1, (int) [[request HTTPBody] length]);
  200475. Thread::sleep (1);
  200476. }
  200477. return self;
  200478. }
  200479. - (void) dealloc
  200480. {
  200481. [self stop];
  200482. delete runLoopThread;
  200483. [connection release];
  200484. [data release];
  200485. [dataLock release];
  200486. [request release];
  200487. [super dealloc];
  200488. }
  200489. - (void) createConnection
  200490. {
  200491. connection = [[NSURLConnection alloc] initWithRequest: request
  200492. delegate: [self retain]];
  200493. if (connection == nil)
  200494. runLoopThread->signalThreadShouldExit();
  200495. }
  200496. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200497. {
  200498. [dataLock lock];
  200499. [data setLength: 0];
  200500. [dataLock unlock];
  200501. initialised = true;
  200502. contentLength = [response expectedContentLength];
  200503. }
  200504. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200505. {
  200506. DBG (nsStringToJuce ([error description]));
  200507. hasFailed = true;
  200508. initialised = true;
  200509. runLoopThread->signalThreadShouldExit();
  200510. }
  200511. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200512. {
  200513. [dataLock lock];
  200514. [data appendData: newData];
  200515. [dataLock unlock];
  200516. initialised = true;
  200517. }
  200518. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200519. {
  200520. hasFinished = true;
  200521. initialised = true;
  200522. runLoopThread->signalThreadShouldExit();
  200523. }
  200524. - (BOOL) isOpen
  200525. {
  200526. return connection != 0 && ! hasFailed;
  200527. }
  200528. - (int) readPosition
  200529. {
  200530. return position;
  200531. }
  200532. - (int) read: (char*) dest numBytes: (int) numNeeded
  200533. {
  200534. int numDone = 0;
  200535. while (numNeeded > 0)
  200536. {
  200537. int available = jmin (numNeeded, (int) [data length]);
  200538. if (available > 0)
  200539. {
  200540. [dataLock lock];
  200541. [data getBytes: dest length: available];
  200542. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200543. [dataLock unlock];
  200544. numDone += available;
  200545. numNeeded -= available;
  200546. dest += available;
  200547. }
  200548. else
  200549. {
  200550. if (hasFailed || hasFinished)
  200551. break;
  200552. Thread::sleep (1);
  200553. }
  200554. }
  200555. position += numDone;
  200556. return numDone;
  200557. }
  200558. - (void) stop
  200559. {
  200560. [connection cancel];
  200561. runLoopThread->stopThread (10000);
  200562. }
  200563. @end
  200564. BEGIN_JUCE_NAMESPACE
  200565. bool juce_isOnLine()
  200566. {
  200567. return true;
  200568. }
  200569. void* juce_openInternetFile (const String& url,
  200570. const String& headers,
  200571. const MemoryBlock& postData,
  200572. const bool isPost,
  200573. URL::OpenStreamProgressCallback* callback,
  200574. void* callbackContext,
  200575. int timeOutMs)
  200576. {
  200577. const ScopedAutoReleasePool pool;
  200578. NSMutableURLRequest* req = [NSMutableURLRequest
  200579. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200580. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200581. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200582. if (req == nil)
  200583. return 0;
  200584. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200585. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200586. StringArray headerLines;
  200587. headerLines.addLines (headers);
  200588. headerLines.removeEmptyStrings (true);
  200589. for (int i = 0; i < headerLines.size(); ++i)
  200590. {
  200591. const String key (headerLines[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  200592. const String value (headerLines[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  200593. if (key.isNotEmpty() && value.isNotEmpty())
  200594. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200595. }
  200596. if (isPost && postData.getSize() > 0)
  200597. {
  200598. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200599. length: postData.getSize()]];
  200600. }
  200601. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200602. withCallback: callback
  200603. withContext: callbackContext];
  200604. if ([s isOpen])
  200605. return s;
  200606. [s release];
  200607. return 0;
  200608. }
  200609. void juce_closeInternetFile (void* handle)
  200610. {
  200611. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200612. if (s != 0)
  200613. {
  200614. const ScopedAutoReleasePool pool;
  200615. [s stop];
  200616. [s release];
  200617. }
  200618. }
  200619. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200620. {
  200621. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200622. if (s != 0)
  200623. {
  200624. const ScopedAutoReleasePool pool;
  200625. return [s read: (char*) buffer numBytes: bytesToRead];
  200626. }
  200627. return 0;
  200628. }
  200629. int64 juce_getInternetFileContentLength (void* handle)
  200630. {
  200631. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200632. if (s != 0)
  200633. return s->contentLength;
  200634. return -1;
  200635. }
  200636. int juce_seekInInternetFile (void* handle, int newPosition)
  200637. {
  200638. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200639. if (s != 0)
  200640. return [s readPosition];
  200641. return 0;
  200642. }
  200643. #endif
  200644. /*** End of inlined file: juce_mac_Network.mm ***/
  200645. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200646. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200647. // compiled on its own).
  200648. #if JUCE_INCLUDED_FILE
  200649. struct NamedPipeInternal
  200650. {
  200651. String pipeInName, pipeOutName;
  200652. int pipeIn, pipeOut;
  200653. bool volatile createdPipe, blocked, stopReadOperation;
  200654. static void signalHandler (int) {}
  200655. };
  200656. void NamedPipe::cancelPendingReads()
  200657. {
  200658. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200659. {
  200660. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200661. intern->stopReadOperation = true;
  200662. char buffer [1] = { 0 };
  200663. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200664. (void) bytesWritten;
  200665. int timeout = 2000;
  200666. while (intern->blocked && --timeout >= 0)
  200667. Thread::sleep (2);
  200668. intern->stopReadOperation = false;
  200669. }
  200670. }
  200671. void NamedPipe::close()
  200672. {
  200673. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200674. if (intern != 0)
  200675. {
  200676. internal = 0;
  200677. if (intern->pipeIn != -1)
  200678. ::close (intern->pipeIn);
  200679. if (intern->pipeOut != -1)
  200680. ::close (intern->pipeOut);
  200681. if (intern->createdPipe)
  200682. {
  200683. unlink (intern->pipeInName);
  200684. unlink (intern->pipeOutName);
  200685. }
  200686. delete intern;
  200687. }
  200688. }
  200689. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200690. {
  200691. close();
  200692. NamedPipeInternal* const intern = new NamedPipeInternal();
  200693. internal = intern;
  200694. intern->createdPipe = createPipe;
  200695. intern->blocked = false;
  200696. intern->stopReadOperation = false;
  200697. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200698. siginterrupt (SIGPIPE, 1);
  200699. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  200700. intern->pipeInName = pipePath + T("_in");
  200701. intern->pipeOutName = pipePath + T("_out");
  200702. intern->pipeIn = -1;
  200703. intern->pipeOut = -1;
  200704. if (createPipe)
  200705. {
  200706. if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST)
  200707. || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST))
  200708. {
  200709. delete intern;
  200710. internal = 0;
  200711. return false;
  200712. }
  200713. }
  200714. return true;
  200715. }
  200716. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200717. {
  200718. int bytesRead = -1;
  200719. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200720. if (intern != 0)
  200721. {
  200722. intern->blocked = true;
  200723. if (intern->pipeIn == -1)
  200724. {
  200725. if (intern->createdPipe)
  200726. intern->pipeIn = ::open (intern->pipeInName, O_RDWR);
  200727. else
  200728. intern->pipeIn = ::open (intern->pipeOutName, O_RDWR);
  200729. if (intern->pipeIn == -1)
  200730. {
  200731. intern->blocked = false;
  200732. return -1;
  200733. }
  200734. }
  200735. bytesRead = 0;
  200736. char* p = (char*) destBuffer;
  200737. while (bytesRead < maxBytesToRead)
  200738. {
  200739. const int bytesThisTime = maxBytesToRead - bytesRead;
  200740. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200741. if (numRead <= 0 || intern->stopReadOperation)
  200742. {
  200743. bytesRead = -1;
  200744. break;
  200745. }
  200746. bytesRead += numRead;
  200747. p += bytesRead;
  200748. }
  200749. intern->blocked = false;
  200750. }
  200751. return bytesRead;
  200752. }
  200753. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200754. {
  200755. int bytesWritten = -1;
  200756. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200757. if (intern != 0)
  200758. {
  200759. if (intern->pipeOut == -1)
  200760. {
  200761. if (intern->createdPipe)
  200762. intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY);
  200763. else
  200764. intern->pipeOut = ::open (intern->pipeInName, O_WRONLY);
  200765. if (intern->pipeOut == -1)
  200766. {
  200767. return -1;
  200768. }
  200769. }
  200770. const char* p = (const char*) sourceBuffer;
  200771. bytesWritten = 0;
  200772. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200773. while (bytesWritten < numBytesToWrite
  200774. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200775. {
  200776. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200777. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200778. if (numWritten <= 0)
  200779. {
  200780. bytesWritten = -1;
  200781. break;
  200782. }
  200783. bytesWritten += numWritten;
  200784. p += bytesWritten;
  200785. }
  200786. }
  200787. return bytesWritten;
  200788. }
  200789. #endif
  200790. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200791. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200792. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200793. // compiled on its own).
  200794. #if JUCE_INCLUDED_FILE
  200795. void JUCE_API juce_threadEntryPoint (void*);
  200796. void* threadEntryProc (void* userData)
  200797. {
  200798. const ScopedAutoReleasePool pool;
  200799. juce_threadEntryPoint (userData);
  200800. return 0;
  200801. }
  200802. void* juce_createThread (void* userData)
  200803. {
  200804. pthread_t handle = 0;
  200805. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200806. {
  200807. pthread_detach (handle);
  200808. return (void*) handle;
  200809. }
  200810. return 0;
  200811. }
  200812. void juce_killThread (void* handle)
  200813. {
  200814. if (handle != 0)
  200815. pthread_cancel ((pthread_t) handle);
  200816. }
  200817. void juce_setCurrentThreadName (const String& /*name*/)
  200818. {
  200819. }
  200820. Thread::ThreadID Thread::getCurrentThreadId()
  200821. {
  200822. return (ThreadID) pthread_self();
  200823. }
  200824. bool juce_setThreadPriority (void* handle, int priority)
  200825. {
  200826. if (handle == 0)
  200827. handle = (void*) pthread_self();
  200828. struct sched_param param;
  200829. int policy;
  200830. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200831. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200832. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200833. }
  200834. void Thread::yield()
  200835. {
  200836. sched_yield();
  200837. }
  200838. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200839. {
  200840. // xxx
  200841. jassertfalse
  200842. }
  200843. bool Process::isForegroundProcess()
  200844. {
  200845. #if JUCE_MAC
  200846. return [NSApp isActive];
  200847. #else
  200848. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200849. #endif
  200850. }
  200851. void Process::raisePrivilege()
  200852. {
  200853. jassertfalse
  200854. }
  200855. void Process::lowerPrivilege()
  200856. {
  200857. jassertfalse
  200858. }
  200859. void Process::terminate()
  200860. {
  200861. exit (0);
  200862. }
  200863. void Process::setPriority (ProcessPriority p)
  200864. {
  200865. // xxx
  200866. }
  200867. #endif
  200868. /*** End of inlined file: juce_mac_Threads.mm ***/
  200869. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200870. CriticalSection::CriticalSection() throw()
  200871. {
  200872. pthread_mutexattr_t atts;
  200873. pthread_mutexattr_init (&atts);
  200874. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200875. pthread_mutex_init (&internal, &atts);
  200876. }
  200877. CriticalSection::~CriticalSection() throw()
  200878. {
  200879. pthread_mutex_destroy (&internal);
  200880. }
  200881. void CriticalSection::enter() const throw()
  200882. {
  200883. pthread_mutex_lock (&internal);
  200884. }
  200885. bool CriticalSection::tryEnter() const throw()
  200886. {
  200887. return pthread_mutex_trylock (&internal) == 0;
  200888. }
  200889. void CriticalSection::exit() const throw()
  200890. {
  200891. pthread_mutex_unlock (&internal);
  200892. }
  200893. struct EventStruct
  200894. {
  200895. pthread_cond_t condition;
  200896. pthread_mutex_t mutex;
  200897. bool triggered;
  200898. };
  200899. WaitableEvent::WaitableEvent() throw()
  200900. {
  200901. EventStruct* const es = new EventStruct();
  200902. es->triggered = false;
  200903. pthread_cond_init (&es->condition, 0);
  200904. pthread_mutex_init (&es->mutex, 0);
  200905. internal = es;
  200906. }
  200907. WaitableEvent::~WaitableEvent() throw()
  200908. {
  200909. EventStruct* const es = (EventStruct*) internal;
  200910. pthread_cond_destroy (&es->condition);
  200911. pthread_mutex_destroy (&es->mutex);
  200912. delete es;
  200913. }
  200914. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200915. {
  200916. EventStruct* const es = (EventStruct*) internal;
  200917. pthread_mutex_lock (&es->mutex);
  200918. if (timeOutMillisecs < 0)
  200919. {
  200920. while (! es->triggered)
  200921. pthread_cond_wait (&es->condition, &es->mutex);
  200922. }
  200923. else
  200924. {
  200925. while (! es->triggered)
  200926. {
  200927. struct timeval t;
  200928. gettimeofday (&t, 0);
  200929. struct timespec time;
  200930. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  200931. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200932. if (time.tv_nsec >= 1000000000)
  200933. {
  200934. time.tv_nsec -= 1000000000;
  200935. time.tv_sec++;
  200936. }
  200937. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  200938. {
  200939. pthread_mutex_unlock (&es->mutex);
  200940. return false;
  200941. }
  200942. }
  200943. }
  200944. es->triggered = false;
  200945. pthread_mutex_unlock (&es->mutex);
  200946. return true;
  200947. }
  200948. void WaitableEvent::signal() const throw()
  200949. {
  200950. EventStruct* const es = (EventStruct*) internal;
  200951. pthread_mutex_lock (&es->mutex);
  200952. es->triggered = true;
  200953. pthread_cond_broadcast (&es->condition);
  200954. pthread_mutex_unlock (&es->mutex);
  200955. }
  200956. void WaitableEvent::reset() const throw()
  200957. {
  200958. EventStruct* const es = (EventStruct*) internal;
  200959. pthread_mutex_lock (&es->mutex);
  200960. es->triggered = false;
  200961. pthread_mutex_unlock (&es->mutex);
  200962. }
  200963. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200964. {
  200965. struct timespec time;
  200966. time.tv_sec = millisecs / 1000;
  200967. time.tv_nsec = (millisecs % 1000) * 1000000;
  200968. nanosleep (&time, 0);
  200969. }
  200970. const tchar File::separator = T('/');
  200971. const tchar* File::separatorString = T("/");
  200972. bool juce_copyFile (const String& s, const String& d);
  200973. static bool juce_stat (const String& fileName, struct stat& info)
  200974. {
  200975. return fileName.isNotEmpty()
  200976. && (stat (fileName.toUTF8(), &info) == 0);
  200977. }
  200978. bool juce_isDirectory (const String& fileName)
  200979. {
  200980. struct stat info;
  200981. return fileName.isEmpty()
  200982. || (juce_stat (fileName, info)
  200983. && ((info.st_mode & S_IFDIR) != 0));
  200984. }
  200985. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200986. {
  200987. if (fileName.isEmpty())
  200988. return false;
  200989. const char* const fileNameUTF8 = fileName.toUTF8();
  200990. bool exists = access (fileNameUTF8, F_OK) == 0;
  200991. if (exists && dontCountDirectories)
  200992. {
  200993. struct stat info;
  200994. const int res = stat (fileNameUTF8, &info);
  200995. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200996. exists = false;
  200997. }
  200998. return exists;
  200999. }
  201000. int64 juce_getFileSize (const String& fileName)
  201001. {
  201002. struct stat info;
  201003. return juce_stat (fileName, info) ? info.st_size : 0;
  201004. }
  201005. bool juce_canWriteToFile (const String& fileName)
  201006. {
  201007. return access (fileName.toUTF8(), W_OK) == 0;
  201008. }
  201009. bool juce_deleteFile (const String& fileName)
  201010. {
  201011. if (juce_isDirectory (fileName))
  201012. return rmdir ((const char*) fileName.toUTF8()) == 0;
  201013. else
  201014. return remove ((const char*) fileName.toUTF8()) == 0;
  201015. }
  201016. bool juce_moveFile (const String& source, const String& dest)
  201017. {
  201018. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  201019. return true;
  201020. if (juce_canWriteToFile (source)
  201021. && juce_copyFile (source, dest))
  201022. {
  201023. if (juce_deleteFile (source))
  201024. return true;
  201025. juce_deleteFile (dest);
  201026. }
  201027. return false;
  201028. }
  201029. void juce_createDirectory (const String& fileName)
  201030. {
  201031. mkdir (fileName.toUTF8(), 0777);
  201032. }
  201033. void* juce_fileOpen (const String& fileName, bool forWriting)
  201034. {
  201035. int flags = O_RDONLY;
  201036. if (forWriting)
  201037. {
  201038. if (juce_fileExists (fileName, false))
  201039. {
  201040. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  201041. if (f != -1)
  201042. lseek (f, 0, SEEK_END);
  201043. return (void*) f;
  201044. }
  201045. else
  201046. {
  201047. flags = O_RDWR + O_CREAT;
  201048. }
  201049. }
  201050. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  201051. }
  201052. void juce_fileClose (void* handle)
  201053. {
  201054. if (handle != 0)
  201055. close ((int) (pointer_sized_int) handle);
  201056. }
  201057. int juce_fileRead (void* handle, void* buffer, int size)
  201058. {
  201059. if (handle != 0)
  201060. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  201061. return 0;
  201062. }
  201063. int juce_fileWrite (void* handle, const void* buffer, int size)
  201064. {
  201065. if (handle != 0)
  201066. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  201067. return 0;
  201068. }
  201069. int64 juce_fileSetPosition (void* handle, int64 pos)
  201070. {
  201071. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  201072. return pos;
  201073. return -1;
  201074. }
  201075. int64 juce_fileGetPosition (void* handle)
  201076. {
  201077. if (handle != 0)
  201078. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  201079. else
  201080. return -1;
  201081. }
  201082. void juce_fileFlush (void* handle)
  201083. {
  201084. if (handle != 0)
  201085. fsync ((int) (pointer_sized_int) handle);
  201086. }
  201087. const File juce_getExecutableFile()
  201088. {
  201089. Dl_info exeInfo;
  201090. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  201091. return File (exeInfo.dli_fname);
  201092. }
  201093. // if this file doesn't exist, find a parent of it that does..
  201094. static bool doStatFS (const File* file, struct statfs& result)
  201095. {
  201096. File f (*file);
  201097. for (int i = 5; --i >= 0;)
  201098. {
  201099. if (f.exists())
  201100. break;
  201101. f = f.getParentDirectory();
  201102. }
  201103. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  201104. }
  201105. int64 File::getBytesFreeOnVolume() const
  201106. {
  201107. struct statfs buf;
  201108. if (doStatFS (this, buf))
  201109. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  201110. return 0;
  201111. }
  201112. int64 File::getVolumeTotalSize() const
  201113. {
  201114. struct statfs buf;
  201115. if (doStatFS (this, buf))
  201116. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  201117. return 0;
  201118. }
  201119. const String juce_getVolumeLabel (const String& filenameOnVolume,
  201120. int& volumeSerialNumber)
  201121. {
  201122. volumeSerialNumber = 0;
  201123. #if JUCE_MAC
  201124. struct VolAttrBuf
  201125. {
  201126. u_int32_t length;
  201127. attrreference_t mountPointRef;
  201128. char mountPointSpace [MAXPATHLEN];
  201129. } attrBuf;
  201130. struct attrlist attrList;
  201131. zerostruct (attrList);
  201132. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  201133. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  201134. File f (filenameOnVolume);
  201135. for (;;)
  201136. {
  201137. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  201138. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  201139. {
  201140. return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  201141. (int) attrBuf.mountPointRef.attr_length);
  201142. }
  201143. const File parent (f.getParentDirectory());
  201144. if (f == parent)
  201145. break;
  201146. f = parent;
  201147. }
  201148. #endif
  201149. return String::empty;
  201150. }
  201151. void juce_runSystemCommand (const String& command)
  201152. {
  201153. int result = system ((const char*) command.toUTF8());
  201154. (void) result;
  201155. }
  201156. const String juce_getOutputFromCommand (const String& command)
  201157. {
  201158. // slight bodge here, as we just pipe the output into a temp file and read it...
  201159. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  201160. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  201161. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  201162. String result (tempFile.loadFileAsString());
  201163. tempFile.deleteFile();
  201164. return result;
  201165. }
  201166. InterProcessLock::InterProcessLock (const String& name_)
  201167. : internal (0),
  201168. name (name_),
  201169. reentrancyLevel (0)
  201170. {
  201171. #if JUCE_MAC
  201172. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  201173. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  201174. #else
  201175. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  201176. #endif
  201177. temp.create();
  201178. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  201179. }
  201180. InterProcessLock::~InterProcessLock()
  201181. {
  201182. while (reentrancyLevel > 0)
  201183. this->exit();
  201184. close (internal);
  201185. }
  201186. bool InterProcessLock::enter (const int timeOutMillisecs)
  201187. {
  201188. if (internal == 0)
  201189. return false;
  201190. if (reentrancyLevel != 0)
  201191. return true;
  201192. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  201193. struct flock fl;
  201194. zerostruct (fl);
  201195. fl.l_whence = SEEK_SET;
  201196. fl.l_type = F_WRLCK;
  201197. for (;;)
  201198. {
  201199. const int result = fcntl (internal, F_SETLK, &fl);
  201200. if (result >= 0)
  201201. {
  201202. ++reentrancyLevel;
  201203. return true;
  201204. }
  201205. if (errno != EINTR)
  201206. {
  201207. if (timeOutMillisecs == 0
  201208. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  201209. break;
  201210. Thread::sleep (10);
  201211. }
  201212. }
  201213. return false;
  201214. }
  201215. void InterProcessLock::exit()
  201216. {
  201217. if (reentrancyLevel > 0 && internal != 0)
  201218. {
  201219. --reentrancyLevel;
  201220. struct flock fl;
  201221. zerostruct (fl);
  201222. fl.l_whence = SEEK_SET;
  201223. fl.l_type = F_UNLCK;
  201224. for (;;)
  201225. {
  201226. const int result = fcntl (internal, F_SETLKW, &fl);
  201227. if (result >= 0 || errno != EINTR)
  201228. break;
  201229. }
  201230. }
  201231. }
  201232. /*** End of inlined file: juce_posix_SharedCode.h ***/
  201233. /*** Start of inlined file: juce_mac_Files.mm ***/
  201234. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201235. // compiled on its own).
  201236. #if JUCE_INCLUDED_FILE
  201237. void juce_getFileTimes (const String& fileName,
  201238. int64& modificationTime,
  201239. int64& accessTime,
  201240. int64& creationTime)
  201241. {
  201242. modificationTime = 0;
  201243. accessTime = 0;
  201244. creationTime = 0;
  201245. struct stat info;
  201246. const int res = stat (fileName.toUTF8(), &info);
  201247. if (res == 0)
  201248. {
  201249. modificationTime = (int64) info.st_mtime * 1000;
  201250. accessTime = (int64) info.st_atime * 1000;
  201251. creationTime = (int64) info.st_ctime * 1000;
  201252. }
  201253. }
  201254. bool juce_setFileTimes (const String& fileName,
  201255. int64 modificationTime,
  201256. int64 accessTime,
  201257. int64 creationTime)
  201258. {
  201259. struct utimbuf times;
  201260. times.actime = (time_t) (accessTime / 1000);
  201261. times.modtime = (time_t) (modificationTime / 1000);
  201262. return utime (fileName.toUTF8(), &times) == 0;
  201263. }
  201264. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  201265. {
  201266. struct stat info;
  201267. const int res = stat (fileName.toUTF8(), &info);
  201268. if (res != 0)
  201269. return false;
  201270. info.st_mode &= 0777; // Just permissions
  201271. if (isReadOnly)
  201272. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  201273. else
  201274. // Give everybody write permission?
  201275. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  201276. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  201277. }
  201278. bool juce_copyFile (const String& src, const String& dst)
  201279. {
  201280. const ScopedAutoReleasePool pool;
  201281. NSFileManager* fm = [NSFileManager defaultManager];
  201282. return [fm fileExistsAtPath: juceStringToNS (src)]
  201283. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201284. && [fm copyItemAtPath: juceStringToNS (src)
  201285. toPath: juceStringToNS (dst)
  201286. error: nil];
  201287. #else
  201288. && [fm copyPath: juceStringToNS (src)
  201289. toPath: juceStringToNS (dst)
  201290. handler: nil];
  201291. #endif
  201292. }
  201293. const StringArray juce_getFileSystemRoots()
  201294. {
  201295. StringArray s;
  201296. s.add (T("/"));
  201297. return s;
  201298. }
  201299. static bool isFileOnDriveType (const File* const f, const char** types)
  201300. {
  201301. struct statfs buf;
  201302. if (doStatFS (f, buf))
  201303. {
  201304. const String type (buf.f_fstypename);
  201305. while (*types != 0)
  201306. if (type.equalsIgnoreCase (*types++))
  201307. return true;
  201308. }
  201309. return false;
  201310. }
  201311. bool File::isOnCDRomDrive() const
  201312. {
  201313. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  201314. return isFileOnDriveType (this, (const char**) cdTypes);
  201315. }
  201316. bool File::isOnHardDisk() const
  201317. {
  201318. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  201319. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  201320. }
  201321. bool File::isOnRemovableDrive() const
  201322. {
  201323. #if JUCE_IPHONE
  201324. return false; // xxx is this possible?
  201325. #else
  201326. const ScopedAutoReleasePool pool;
  201327. BOOL removable = false;
  201328. [[NSWorkspace sharedWorkspace]
  201329. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  201330. isRemovable: &removable
  201331. isWritable: nil
  201332. isUnmountable: nil
  201333. description: nil
  201334. type: nil];
  201335. return removable;
  201336. #endif
  201337. }
  201338. static bool juce_isHiddenFile (const String& path)
  201339. {
  201340. #if JUCE_IPHONE
  201341. return File (path).getFileName().startsWithChar (T('.'));
  201342. #else
  201343. FSRef ref;
  201344. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  201345. return false;
  201346. FSCatalogInfo info;
  201347. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  201348. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  201349. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201350. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201351. #endif
  201352. }
  201353. bool File::isHidden() const
  201354. {
  201355. return juce_isHiddenFile (getFullPathName());
  201356. }
  201357. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  201358. const File File::getSpecialLocation (const SpecialLocationType type)
  201359. {
  201360. const ScopedAutoReleasePool pool;
  201361. String resultPath;
  201362. switch (type)
  201363. {
  201364. case userHomeDirectory:
  201365. resultPath = nsStringToJuce (NSHomeDirectory());
  201366. break;
  201367. case userDocumentsDirectory:
  201368. resultPath = "~/Documents";
  201369. break;
  201370. case userDesktopDirectory:
  201371. resultPath = "~/Desktop";
  201372. break;
  201373. case userApplicationDataDirectory:
  201374. resultPath = "~/Library";
  201375. break;
  201376. case commonApplicationDataDirectory:
  201377. resultPath = "/Library";
  201378. break;
  201379. case globalApplicationsDirectory:
  201380. resultPath = "/Applications";
  201381. break;
  201382. case userMusicDirectory:
  201383. resultPath = "~/Music";
  201384. break;
  201385. case userMoviesDirectory:
  201386. resultPath = "~/Movies";
  201387. break;
  201388. case tempDirectory:
  201389. {
  201390. File tmp (T("~/Library/Caches/") + juce_getExecutableFile().getFileNameWithoutExtension());
  201391. tmp.createDirectory();
  201392. return tmp.getFullPathName();
  201393. }
  201394. case invokedExecutableFile:
  201395. if (juce_Argv0 != 0)
  201396. return File (String::fromUTF8 ((const uint8*) juce_Argv0));
  201397. // deliberate fall-through...
  201398. case currentExecutableFile:
  201399. return juce_getExecutableFile();
  201400. case currentApplicationFile:
  201401. {
  201402. const File exe (juce_getExecutableFile());
  201403. const File parent (exe.getParentDirectory());
  201404. return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
  201405. ? parent.getParentDirectory().getParentDirectory()
  201406. : exe;
  201407. }
  201408. default:
  201409. jassertfalse // unknown type?
  201410. break;
  201411. }
  201412. if (resultPath != 0)
  201413. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201414. return File::nonexistent;
  201415. }
  201416. const File File::getCurrentWorkingDirectory()
  201417. {
  201418. char buf [2048];
  201419. getcwd (buf, sizeof(buf));
  201420. return File (PlatformUtilities::convertToPrecomposedUnicode (buf));
  201421. }
  201422. bool File::setAsCurrentWorkingDirectory() const
  201423. {
  201424. return chdir (getFullPathName().toUTF8()) == 0;
  201425. }
  201426. const String File::getVersion() const
  201427. {
  201428. const ScopedAutoReleasePool pool;
  201429. String result;
  201430. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201431. if (bundle != 0)
  201432. {
  201433. NSDictionary* info = [bundle infoDictionary];
  201434. if (info != 0)
  201435. {
  201436. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201437. if (name != nil)
  201438. result = nsStringToJuce (name);
  201439. }
  201440. }
  201441. return result;
  201442. }
  201443. const File File::getLinkedTarget() const
  201444. {
  201445. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201446. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201447. #else
  201448. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201449. #endif
  201450. if (dest != nil)
  201451. return File (nsStringToJuce (dest));
  201452. return *this;
  201453. }
  201454. bool File::moveToTrash() const
  201455. {
  201456. if (! exists())
  201457. return true;
  201458. #if JUCE_IPHONE
  201459. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201460. #else
  201461. const ScopedAutoReleasePool pool;
  201462. NSString* p = juceStringToNS (getFullPathName());
  201463. return [[NSWorkspace sharedWorkspace]
  201464. performFileOperation: NSWorkspaceRecycleOperation
  201465. source: [p stringByDeletingLastPathComponent]
  201466. destination: @""
  201467. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201468. tag: nil ];
  201469. #endif
  201470. }
  201471. struct FindFileStruct
  201472. {
  201473. NSDirectoryEnumerator* enumerator;
  201474. String parentDir, wildCard;
  201475. };
  201476. bool juce_findFileNext (void* handle, String& resultFile,
  201477. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201478. {
  201479. ScopedAutoReleasePool pool;
  201480. FindFileStruct* ff = (FindFileStruct*) handle;
  201481. NSString* file;
  201482. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201483. for (;;)
  201484. {
  201485. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201486. return false;
  201487. [ff->enumerator skipDescendents];
  201488. resultFile = nsStringToJuce (file);
  201489. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201490. continue;
  201491. const String path (ff->parentDir + resultFile);
  201492. if (isDir != 0 || fileSize != 0)
  201493. {
  201494. struct stat info;
  201495. const bool statOk = juce_stat (path, info);
  201496. if (isDir != 0)
  201497. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201498. if (isHidden != 0)
  201499. *isHidden = juce_isHiddenFile (path);
  201500. if (fileSize != 0)
  201501. *fileSize = statOk ? info.st_size : 0;
  201502. }
  201503. if (modTime != 0 || creationTime != 0)
  201504. {
  201505. int64 m, a, c;
  201506. juce_getFileTimes (path, m, a, c);
  201507. if (modTime != 0)
  201508. *modTime = m;
  201509. if (creationTime != 0)
  201510. *creationTime = c;
  201511. }
  201512. if (isReadOnly != 0)
  201513. *isReadOnly = ! juce_canWriteToFile (path);
  201514. return true;
  201515. }
  201516. }
  201517. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201518. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201519. Time* creationTime, bool* isReadOnly)
  201520. {
  201521. ScopedAutoReleasePool pool;
  201522. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201523. if (e != 0)
  201524. {
  201525. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201526. ff->enumerator = [e retain];
  201527. ff->parentDir = directory;
  201528. ff->wildCard = wildCard;
  201529. if (! ff->parentDir.endsWithChar (File::separator))
  201530. ff->parentDir += File::separator;
  201531. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201532. return ff.release();
  201533. [e release];
  201534. }
  201535. return 0;
  201536. }
  201537. void juce_findFileClose (void* handle)
  201538. {
  201539. ScopedAutoReleasePool pool;
  201540. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201541. [ff->enumerator release];
  201542. }
  201543. bool juce_launchExecutable (const String& pathAndArguments)
  201544. {
  201545. const char* const argv[4] = { "/bin/sh", "-c", (const char*) pathAndArguments, 0 };
  201546. const int cpid = fork();
  201547. if (cpid == 0)
  201548. {
  201549. // Child process
  201550. if (execve (argv[0], (char**) argv, 0) < 0)
  201551. exit (0);
  201552. }
  201553. else
  201554. {
  201555. if (cpid < 0)
  201556. return false;
  201557. }
  201558. return true;
  201559. }
  201560. bool juce_launchFile (const String& fileName, const String& parameters)
  201561. {
  201562. #if JUCE_IPHONE
  201563. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201564. #else
  201565. const ScopedAutoReleasePool pool;
  201566. if (parameters.isEmpty())
  201567. {
  201568. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201569. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201570. }
  201571. bool ok = false;
  201572. FSRef ref;
  201573. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201574. {
  201575. if (PlatformUtilities::isBundle (fileName))
  201576. {
  201577. NSMutableArray* urls = [NSMutableArray array];
  201578. StringArray docs;
  201579. docs.addTokens (parameters, true);
  201580. for (int i = 0; i < docs.size(); ++i)
  201581. [urls addObject: juceStringToNS (docs[i])];
  201582. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201583. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201584. options: 0
  201585. additionalEventParamDescriptor: nil
  201586. launchIdentifiers: nil];
  201587. }
  201588. else
  201589. {
  201590. ok = juce_launchExecutable (T("\"") + fileName + T("\" ") + parameters);
  201591. }
  201592. }
  201593. return ok;
  201594. #endif
  201595. }
  201596. void File::revealToUser() const
  201597. {
  201598. #if ! JUCE_IPHONE
  201599. if (exists())
  201600. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201601. else if (getParentDirectory().exists())
  201602. getParentDirectory().revealToUser();
  201603. #endif
  201604. }
  201605. #if ! JUCE_IPHONE
  201606. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201607. {
  201608. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201609. }
  201610. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201611. {
  201612. uint8 path [2048];
  201613. zeromem (path, sizeof (path));
  201614. String result;
  201615. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201616. result = String::fromUTF8 (path);
  201617. return PlatformUtilities::convertToPrecomposedUnicode (result);
  201618. }
  201619. #endif
  201620. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201621. {
  201622. const ScopedAutoReleasePool pool;
  201623. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201624. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201625. #else
  201626. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201627. #endif
  201628. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201629. return [fileDict fileHFSTypeCode];
  201630. }
  201631. bool PlatformUtilities::isBundle (const String& filename)
  201632. {
  201633. #if JUCE_IPHONE
  201634. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201635. #else
  201636. const ScopedAutoReleasePool pool;
  201637. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201638. #endif
  201639. }
  201640. #endif
  201641. /*** End of inlined file: juce_mac_Files.mm ***/
  201642. #if JUCE_IPHONE
  201643. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201644. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201645. // compiled on its own).
  201646. #if JUCE_INCLUDED_FILE
  201647. static JUCEApplication* juce_intialisingApp;
  201648. END_JUCE_NAMESPACE
  201649. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201650. {
  201651. }
  201652. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201653. - (void) applicationWillResignActive: (UIApplication*) application;
  201654. @end
  201655. @implementation JuceAppStartupDelegate
  201656. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201657. {
  201658. String dummy;
  201659. if (! juce_intialisingApp->initialiseApp (dummy))
  201660. exit (0);
  201661. }
  201662. - (void) applicationWillResignActive: (UIApplication*) application
  201663. {
  201664. JUCEApplication::shutdownAppAndClearUp();
  201665. }
  201666. @end
  201667. BEGIN_JUCE_NAMESPACE
  201668. int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app)
  201669. {
  201670. juce_intialisingApp = app;
  201671. return UIApplicationMain (argc, argv, nil, @"JuceAppStartupDelegate");
  201672. }
  201673. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201674. {
  201675. pool = [[NSAutoreleasePool alloc] init];
  201676. }
  201677. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201678. {
  201679. [((NSAutoreleasePool*) pool) release];
  201680. }
  201681. void PlatformUtilities::beep()
  201682. {
  201683. //xxx
  201684. //AudioServicesPlaySystemSound ();
  201685. }
  201686. void PlatformUtilities::addItemToDock (const File& file)
  201687. {
  201688. }
  201689. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201690. END_JUCE_NAMESPACE
  201691. @interface JuceAlertBoxDelegate : NSObject
  201692. {
  201693. @public
  201694. bool clickedOk;
  201695. }
  201696. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201697. @end
  201698. @implementation JuceAlertBoxDelegate
  201699. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201700. {
  201701. clickedOk = (buttonIndex == 0);
  201702. alertView.hidden = true;
  201703. }
  201704. @end
  201705. BEGIN_JUCE_NAMESPACE
  201706. // (This function is used directly by other bits of code)
  201707. bool juce_iPhoneShowModalAlert (const String& title,
  201708. const String& bodyText,
  201709. NSString* okButtonText,
  201710. NSString* cancelButtonText)
  201711. {
  201712. const ScopedAutoReleasePool pool;
  201713. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201714. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201715. message: juceStringToNS (bodyText)
  201716. delegate: callback
  201717. cancelButtonTitle: okButtonText
  201718. otherButtonTitles: cancelButtonText, nil];
  201719. [alert retain];
  201720. [alert show];
  201721. while (! alert.hidden && alert.superview != nil)
  201722. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201723. const bool result = callback->clickedOk;
  201724. [alert release];
  201725. [callback release];
  201726. return result;
  201727. }
  201728. bool AlertWindow::showNativeDialogBox (const String& title,
  201729. const String& bodyText,
  201730. bool isOkCancel)
  201731. {
  201732. return juce_iPhoneShowModalAlert (title, bodyText,
  201733. @"OK",
  201734. isOkCancel ? @"Cancel" : nil);
  201735. }
  201736. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201737. {
  201738. jassertfalse // no such thing on the iphone!
  201739. return false;
  201740. }
  201741. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201742. {
  201743. jassertfalse // no such thing on the iphone!
  201744. return false;
  201745. }
  201746. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201747. {
  201748. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201749. }
  201750. bool Desktop::isScreenSaverEnabled() throw()
  201751. {
  201752. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201753. }
  201754. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201755. {
  201756. const ScopedAutoReleasePool pool;
  201757. monitorCoords.clear();
  201758. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201759. : [[UIScreen mainScreen] bounds];
  201760. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201761. (int) r.origin.y,
  201762. (int) r.size.width,
  201763. (int) r.size.height));
  201764. }
  201765. #endif
  201766. #endif
  201767. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201768. #else
  201769. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201770. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201771. // compiled on its own).
  201772. #if JUCE_INCLUDED_FILE
  201773. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201774. {
  201775. pool = [[NSAutoreleasePool alloc] init];
  201776. }
  201777. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201778. {
  201779. [((NSAutoreleasePool*) pool) release];
  201780. }
  201781. void PlatformUtilities::beep()
  201782. {
  201783. NSBeep();
  201784. }
  201785. void PlatformUtilities::addItemToDock (const File& file)
  201786. {
  201787. // check that it's not already there...
  201788. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201789. .containsIgnoreCase (file.getFullPathName()))
  201790. {
  201791. 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>"
  201792. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201793. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201794. }
  201795. }
  201796. int PlatformUtilities::getOSXMinorVersionNumber()
  201797. {
  201798. SInt32 versionMinor = 0;
  201799. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201800. (void) err;
  201801. jassert (err == noErr);
  201802. return (int) versionMinor;
  201803. }
  201804. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201805. bool AlertWindow::showNativeDialogBox (const String& title,
  201806. const String& bodyText,
  201807. bool isOkCancel)
  201808. {
  201809. const ScopedAutoReleasePool pool;
  201810. return NSRunAlertPanel (juceStringToNS (title),
  201811. juceStringToNS (bodyText),
  201812. @"Ok",
  201813. isOkCancel ? @"Cancel" : nil,
  201814. nil) == NSAlertDefaultReturn;
  201815. }
  201816. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201817. {
  201818. if (files.size() == 0)
  201819. return false;
  201820. Component* sourceComp = Component::getComponentUnderMouse();
  201821. if (sourceComp == 0)
  201822. {
  201823. jassertfalse // this method must be called in response to a
  201824. // component's mouseDrag event!
  201825. return false;
  201826. }
  201827. const ScopedAutoReleasePool pool;
  201828. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201829. if (view == 0)
  201830. return false;
  201831. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201832. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201833. owner: nil];
  201834. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201835. for (int i = 0; i < files.size(); ++i)
  201836. [filesArray addObject: juceStringToNS (files[i])];
  201837. [pboard setPropertyList: filesArray
  201838. forType: NSFilenamesPboardType];
  201839. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201840. fromView: nil];
  201841. dragPosition.x -= 16;
  201842. dragPosition.y -= 16;
  201843. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201844. at: dragPosition
  201845. offset: NSMakeSize (0, 0)
  201846. event: [[view window] currentEvent]
  201847. pasteboard: pboard
  201848. source: view
  201849. slideBack: YES];
  201850. return true;
  201851. }
  201852. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201853. {
  201854. jassertfalse // not implemented!
  201855. return false;
  201856. }
  201857. bool Desktop::canUseSemiTransparentWindows() throw()
  201858. {
  201859. return true;
  201860. }
  201861. void Desktop::getMousePosition (int& x, int& y) throw()
  201862. {
  201863. const ScopedAutoReleasePool pool;
  201864. const NSPoint p ([NSEvent mouseLocation]);
  201865. x = roundToInt (p.x);
  201866. y = roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y);
  201867. }
  201868. void Desktop::setMousePosition (int x, int y) throw()
  201869. {
  201870. // this rubbish needs to be done around the warp call, to avoid causing a
  201871. // bizarre glitch..
  201872. CGAssociateMouseAndMouseCursorPosition (false);
  201873. CGWarpMouseCursorPosition (CGPointMake (x, y));
  201874. CGAssociateMouseAndMouseCursorPosition (true);
  201875. }
  201876. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201877. class ScreenSaverDefeater : public Timer,
  201878. public DeletedAtShutdown
  201879. {
  201880. public:
  201881. ScreenSaverDefeater() throw()
  201882. {
  201883. startTimer (10000);
  201884. timerCallback();
  201885. }
  201886. ~ScreenSaverDefeater() {}
  201887. void timerCallback()
  201888. {
  201889. if (Process::isForegroundProcess())
  201890. UpdateSystemActivity (UsrActivity);
  201891. }
  201892. };
  201893. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201894. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201895. {
  201896. if (isEnabled)
  201897. {
  201898. deleteAndZero (screenSaverDefeater);
  201899. }
  201900. else if (screenSaverDefeater == 0)
  201901. {
  201902. screenSaverDefeater = new ScreenSaverDefeater();
  201903. }
  201904. }
  201905. bool Desktop::isScreenSaverEnabled() throw()
  201906. {
  201907. return screenSaverDefeater == 0;
  201908. }
  201909. #else
  201910. static IOPMAssertionID screenSaverDisablerID = 0;
  201911. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201912. {
  201913. if (isEnabled)
  201914. {
  201915. if (screenSaverDisablerID != 0)
  201916. {
  201917. IOPMAssertionRelease (screenSaverDisablerID);
  201918. screenSaverDisablerID = 0;
  201919. }
  201920. }
  201921. else
  201922. {
  201923. if (screenSaverDisablerID == 0)
  201924. {
  201925. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201926. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201927. CFSTR ("Juce"), &screenSaverDisablerID);
  201928. #else
  201929. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201930. &screenSaverDisablerID);
  201931. #endif
  201932. }
  201933. }
  201934. }
  201935. bool Desktop::isScreenSaverEnabled() throw()
  201936. {
  201937. return screenSaverDisablerID == 0;
  201938. }
  201939. #endif
  201940. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201941. {
  201942. const ScopedAutoReleasePool pool;
  201943. monitorCoords.clear();
  201944. NSArray* screens = [NSScreen screens];
  201945. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201946. for (unsigned int i = 0; i < [screens count]; ++i)
  201947. {
  201948. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201949. NSRect r = clipToWorkArea ? [s visibleFrame]
  201950. : [s frame];
  201951. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201952. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201953. (int) r.size.width,
  201954. (int) r.size.height));
  201955. }
  201956. jassert (monitorCoords.size() > 0);
  201957. }
  201958. #endif
  201959. #endif
  201960. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201961. #endif
  201962. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201963. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201964. // compiled on its own).
  201965. #if JUCE_INCLUDED_FILE
  201966. void Logger::outputDebugString (const String& text) throw()
  201967. {
  201968. std::cerr << (const char*) text.toUTF8() << std::endl;
  201969. }
  201970. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  201971. {
  201972. String text;
  201973. va_list args;
  201974. va_start (args, format);
  201975. text.vprintf (format, args);
  201976. outputDebugString (text);
  201977. }
  201978. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201979. {
  201980. static char testResult = 0;
  201981. if (testResult == 0)
  201982. {
  201983. struct kinfo_proc info;
  201984. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201985. size_t sz = sizeof (info);
  201986. sysctl (m, 4, &info, &sz, 0, 0);
  201987. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201988. }
  201989. return testResult > 0;
  201990. }
  201991. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201992. {
  201993. return juce_isRunningUnderDebugger();
  201994. }
  201995. #endif
  201996. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201997. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201998. #if JUCE_IPHONE
  201999. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  202000. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202001. // compiled on its own).
  202002. #if JUCE_INCLUDED_FILE
  202003. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202004. #define SUPPORT_10_4_FONTS 1
  202005. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  202006. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202007. #define SUPPORT_ONLY_10_4_FONTS 1
  202008. #endif
  202009. END_JUCE_NAMESPACE
  202010. @interface NSFont (PrivateHack)
  202011. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  202012. @end
  202013. BEGIN_JUCE_NAMESPACE
  202014. #endif
  202015. class MacTypeface : public Typeface
  202016. {
  202017. public:
  202018. MacTypeface (const Font& font)
  202019. : Typeface (font.getTypefaceName())
  202020. {
  202021. const ScopedAutoReleasePool pool;
  202022. renderingTransform = CGAffineTransformIdentity;
  202023. bool needsItalicTransform = false;
  202024. #if JUCE_IPHONE
  202025. NSString* fontName = juceStringToNS (font.getTypefaceName());
  202026. if (font.isItalic() || font.isBold())
  202027. {
  202028. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  202029. for (NSString* i in familyFonts)
  202030. {
  202031. const String fn (nsStringToJuce (i));
  202032. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  202033. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  202034. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  202035. || afterDash.containsIgnoreCase (T("italic"))
  202036. || fn.endsWithIgnoreCase (T("oblique"))
  202037. || fn.endsWithIgnoreCase (T("italic"));
  202038. if (probablyBold == font.isBold()
  202039. && probablyItalic == font.isItalic())
  202040. {
  202041. fontName = i;
  202042. needsItalicTransform = false;
  202043. break;
  202044. }
  202045. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  202046. {
  202047. fontName = i;
  202048. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  202049. }
  202050. }
  202051. if (needsItalicTransform)
  202052. renderingTransform.c = 0.15f;
  202053. }
  202054. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  202055. const int ascender = abs (CGFontGetAscent (fontRef));
  202056. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  202057. ascent = ascender / totalHeight;
  202058. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202059. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  202060. #else
  202061. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  202062. if (font.isItalic())
  202063. {
  202064. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  202065. toHaveTrait: NSItalicFontMask];
  202066. if (newFont == nsFont)
  202067. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  202068. nsFont = newFont;
  202069. }
  202070. if (font.isBold())
  202071. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  202072. [nsFont retain];
  202073. ascent = fabsf ((float) [nsFont ascender]);
  202074. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  202075. ascent /= totalSize;
  202076. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  202077. if (needsItalicTransform)
  202078. {
  202079. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  202080. renderingTransform.c = 0.15f;
  202081. }
  202082. #if SUPPORT_ONLY_10_4_FONTS
  202083. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202084. if (atsFont == 0)
  202085. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202086. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  202087. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  202088. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202089. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  202090. #else
  202091. #if SUPPORT_10_4_FONTS
  202092. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202093. {
  202094. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202095. if (atsFont == 0)
  202096. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202097. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  202098. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  202099. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202100. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  202101. }
  202102. else
  202103. #endif
  202104. {
  202105. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  202106. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  202107. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202108. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  202109. }
  202110. #endif
  202111. #endif
  202112. }
  202113. ~MacTypeface()
  202114. {
  202115. #if ! JUCE_IPHONE
  202116. [nsFont release];
  202117. #endif
  202118. if (fontRef != 0)
  202119. CGFontRelease (fontRef);
  202120. }
  202121. float getAscent() const
  202122. {
  202123. return ascent;
  202124. }
  202125. float getDescent() const
  202126. {
  202127. return 1.0f - ascent;
  202128. }
  202129. float getStringWidth (const String& text)
  202130. {
  202131. if (fontRef == 0 || text.isEmpty())
  202132. return 0;
  202133. const int length = text.length();
  202134. HeapBlock <CGGlyph> glyphs;
  202135. createGlyphsForString (text, length, glyphs);
  202136. float x = 0;
  202137. #if SUPPORT_ONLY_10_4_FONTS
  202138. HeapBlock <NSSize> advances (length);
  202139. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202140. for (int i = 0; i < length; ++i)
  202141. x += advances[i].width;
  202142. #else
  202143. #if SUPPORT_10_4_FONTS
  202144. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202145. {
  202146. HeapBlock <NSSize> advances (length);
  202147. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202148. for (int i = 0; i < length; ++i)
  202149. x += advances[i].width;
  202150. }
  202151. else
  202152. #endif
  202153. {
  202154. HeapBlock <int> advances (length);
  202155. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202156. for (int i = 0; i < length; ++i)
  202157. x += advances[i];
  202158. }
  202159. #endif
  202160. return x * unitsToHeightScaleFactor;
  202161. }
  202162. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  202163. {
  202164. xOffsets.add (0);
  202165. if (fontRef == 0 || text.isEmpty())
  202166. return;
  202167. const int length = text.length();
  202168. HeapBlock <CGGlyph> glyphs;
  202169. createGlyphsForString (text, length, glyphs);
  202170. #if SUPPORT_ONLY_10_4_FONTS
  202171. HeapBlock <NSSize> advances (length);
  202172. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202173. int x = 0;
  202174. for (int i = 0; i < length; ++i)
  202175. {
  202176. x += advances[i].width;
  202177. xOffsets.add (x * unitsToHeightScaleFactor);
  202178. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202179. }
  202180. #else
  202181. #if SUPPORT_10_4_FONTS
  202182. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202183. {
  202184. HeapBlock <NSSize> advances (length);
  202185. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202186. float x = 0;
  202187. for (int i = 0; i < length; ++i)
  202188. {
  202189. x += advances[i].width;
  202190. xOffsets.add (x * unitsToHeightScaleFactor);
  202191. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202192. }
  202193. }
  202194. else
  202195. #endif
  202196. {
  202197. HeapBlock <int> advances (length);
  202198. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202199. {
  202200. int x = 0;
  202201. for (int i = 0; i < length; ++i)
  202202. {
  202203. x += advances [i];
  202204. xOffsets.add (x * unitsToHeightScaleFactor);
  202205. resultGlyphs.add (glyphs[i]);
  202206. }
  202207. }
  202208. }
  202209. #endif
  202210. }
  202211. bool getOutlineForGlyph (int glyphNumber, Path& path)
  202212. {
  202213. #if JUCE_IPHONE
  202214. return false;
  202215. #else
  202216. if (nsFont == 0)
  202217. return false;
  202218. // we might need to apply a transform to the path, so it mustn't have anything else in it
  202219. jassert (path.isEmpty());
  202220. const ScopedAutoReleasePool pool;
  202221. NSBezierPath* bez = [NSBezierPath bezierPath];
  202222. [bez moveToPoint: NSMakePoint (0, 0)];
  202223. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  202224. inFont: nsFont];
  202225. for (int i = 0; i < [bez elementCount]; ++i)
  202226. {
  202227. NSPoint p[3];
  202228. switch ([bez elementAtIndex: i associatedPoints: p])
  202229. {
  202230. case NSMoveToBezierPathElement:
  202231. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  202232. break;
  202233. case NSLineToBezierPathElement:
  202234. path.lineTo ((float) p[0].x, (float) -p[0].y);
  202235. break;
  202236. case NSCurveToBezierPathElement:
  202237. 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);
  202238. break;
  202239. case NSClosePathBezierPathElement:
  202240. path.closeSubPath();
  202241. break;
  202242. default:
  202243. jassertfalse
  202244. break;
  202245. }
  202246. }
  202247. path.applyTransform (pathTransform);
  202248. return true;
  202249. #endif
  202250. }
  202251. juce_UseDebuggingNewOperator
  202252. CGFontRef fontRef;
  202253. float fontHeightToCGSizeFactor;
  202254. CGAffineTransform renderingTransform;
  202255. private:
  202256. float ascent, unitsToHeightScaleFactor;
  202257. #if JUCE_IPHONE
  202258. #else
  202259. NSFont* nsFont;
  202260. AffineTransform pathTransform;
  202261. #endif
  202262. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  202263. {
  202264. #if SUPPORT_10_4_FONTS
  202265. #if ! SUPPORT_ONLY_10_4_FONTS
  202266. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202267. #endif
  202268. {
  202269. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  202270. NSGlyph* const g = (NSGlyph*) glyphs;
  202271. for (int i = 0; i < length; ++i)
  202272. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  202273. return;
  202274. }
  202275. #endif
  202276. #if ! SUPPORT_ONLY_10_4_FONTS
  202277. if (charToGlyphMapper == 0)
  202278. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  202279. glyphs.malloc (length);
  202280. for (int i = 0; i < length; ++i)
  202281. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  202282. #endif
  202283. }
  202284. #if ! SUPPORT_ONLY_10_4_FONTS
  202285. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  202286. class CharToGlyphMapper
  202287. {
  202288. public:
  202289. CharToGlyphMapper (CGFontRef fontRef)
  202290. : segCount (0), endCode (0), startCode (0), idDelta (0),
  202291. idRangeOffset (0), glyphIndexes (0)
  202292. {
  202293. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  202294. if (cmapTable != 0)
  202295. {
  202296. const int numSubtables = getValue16 (cmapTable, 2);
  202297. for (int i = 0; i < numSubtables; ++i)
  202298. {
  202299. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  202300. {
  202301. const int offset = getValue32 (cmapTable, i * 8 + 8);
  202302. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  202303. {
  202304. const int length = getValue16 (cmapTable, offset + 2);
  202305. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  202306. segCount = segCountX2 / 2;
  202307. const int endCodeOffset = offset + 14;
  202308. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  202309. const int idDeltaOffset = startCodeOffset + segCountX2;
  202310. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  202311. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  202312. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  202313. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  202314. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  202315. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  202316. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  202317. }
  202318. break;
  202319. }
  202320. }
  202321. CFRelease (cmapTable);
  202322. }
  202323. }
  202324. ~CharToGlyphMapper()
  202325. {
  202326. if (endCode != 0)
  202327. {
  202328. CFRelease (endCode);
  202329. CFRelease (startCode);
  202330. CFRelease (idDelta);
  202331. CFRelease (idRangeOffset);
  202332. CFRelease (glyphIndexes);
  202333. }
  202334. }
  202335. int getGlyphForCharacter (const juce_wchar c) const
  202336. {
  202337. for (int i = 0; i < segCount; ++i)
  202338. {
  202339. if (getValue16 (endCode, i * 2) >= c)
  202340. {
  202341. const int start = getValue16 (startCode, i * 2);
  202342. if (start > c)
  202343. break;
  202344. const int delta = getValue16 (idDelta, i * 2);
  202345. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  202346. if (rangeOffset == 0)
  202347. return delta + c;
  202348. else
  202349. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  202350. }
  202351. }
  202352. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  202353. return jmax (-1, c - 29);
  202354. }
  202355. private:
  202356. int segCount;
  202357. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  202358. static uint16 getValue16 (CFDataRef data, const int index)
  202359. {
  202360. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  202361. }
  202362. static uint32 getValue32 (CFDataRef data, const int index)
  202363. {
  202364. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  202365. }
  202366. };
  202367. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  202368. #endif
  202369. };
  202370. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  202371. {
  202372. return new MacTypeface (font);
  202373. }
  202374. const StringArray Font::findAllTypefaceNames() throw()
  202375. {
  202376. StringArray names;
  202377. const ScopedAutoReleasePool pool;
  202378. #if JUCE_IPHONE
  202379. NSArray* fonts = [UIFont familyNames];
  202380. #else
  202381. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  202382. #endif
  202383. for (unsigned int i = 0; i < [fonts count]; ++i)
  202384. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  202385. names.sort (true);
  202386. return names;
  202387. }
  202388. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  202389. {
  202390. #if JUCE_IPHONE
  202391. defaultSans = "Helvetica";
  202392. defaultSerif = "Times New Roman";
  202393. defaultFixed = "Courier New";
  202394. #else
  202395. defaultSans = "Lucida Grande";
  202396. defaultSerif = "Times New Roman";
  202397. defaultFixed = "Monaco";
  202398. #endif
  202399. }
  202400. #endif
  202401. /*** End of inlined file: juce_mac_Fonts.mm ***/
  202402. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202403. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202404. // compiled on its own).
  202405. #if JUCE_INCLUDED_FILE
  202406. class CoreGraphicsImage : public Image
  202407. {
  202408. public:
  202409. CoreGraphicsImage (const PixelFormat format_,
  202410. const int imageWidth_,
  202411. const int imageHeight_,
  202412. const bool clearImage)
  202413. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202414. {
  202415. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  202416. : CGColorSpaceCreateDeviceRGB();
  202417. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202418. colourSpace, getCGImageFlags (*this));
  202419. CGColorSpaceRelease (colourSpace);
  202420. }
  202421. ~CoreGraphicsImage()
  202422. {
  202423. CGContextRelease (context);
  202424. }
  202425. LowLevelGraphicsContext* createLowLevelContext();
  202426. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202427. {
  202428. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202429. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202430. {
  202431. return CGBitmapContextCreateImage (nativeImage->context);
  202432. }
  202433. else
  202434. {
  202435. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202436. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202437. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202438. 8, srcData.pixelStride * 8, srcData.lineStride,
  202439. colourSpace, getCGImageFlags (juceImage), provider,
  202440. 0, true, kCGRenderingIntentDefault);
  202441. CGDataProviderRelease (provider);
  202442. return imageRef;
  202443. }
  202444. }
  202445. #if JUCE_MAC
  202446. static NSImage* createNSImage (const Image& image)
  202447. {
  202448. const ScopedAutoReleasePool pool;
  202449. NSImage* im = [[NSImage alloc] init];
  202450. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202451. [im lockFocus];
  202452. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202453. CGImageRef imageRef = createImage (image, false, colourSpace);
  202454. CGColorSpaceRelease (colourSpace);
  202455. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202456. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202457. CGImageRelease (imageRef);
  202458. [im unlockFocus];
  202459. return im;
  202460. }
  202461. #endif
  202462. CGContextRef context;
  202463. private:
  202464. static CGBitmapInfo getCGImageFlags (const Image& image)
  202465. {
  202466. #if JUCE_BIG_ENDIAN
  202467. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202468. #else
  202469. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202470. #endif
  202471. }
  202472. };
  202473. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202474. {
  202475. #if USE_COREGRAPHICS_RENDERING
  202476. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202477. #else
  202478. return new Image (format, imageWidth, imageHeight, clearImage);
  202479. #endif
  202480. }
  202481. class CoreGraphicsContext : public LowLevelGraphicsContext
  202482. {
  202483. public:
  202484. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202485. : context (context_),
  202486. flipHeight (flipHeight_),
  202487. numGradientLookupEntries (0)
  202488. {
  202489. CGContextRetain (context);
  202490. CGContextSaveGState(context);
  202491. CGContextSetShouldSmoothFonts (context, true);
  202492. CGContextSetShouldAntialias (context, true);
  202493. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202494. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202495. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202496. gradientCallbacks.version = 0;
  202497. gradientCallbacks.evaluate = gradientCallback;
  202498. gradientCallbacks.releaseInfo = 0;
  202499. state = new SavedState();
  202500. }
  202501. ~CoreGraphicsContext()
  202502. {
  202503. CGContextRestoreGState (context);
  202504. CGContextRelease (context);
  202505. CGColorSpaceRelease (rgbColourSpace);
  202506. CGColorSpaceRelease (greyColourSpace);
  202507. }
  202508. bool isVectorDevice() const { return false; }
  202509. void setOrigin (int x, int y)
  202510. {
  202511. CGContextTranslateCTM (context, x, -y);
  202512. }
  202513. bool clipToRectangle (const Rectangle<int>& r)
  202514. {
  202515. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202516. return ! isClipEmpty();
  202517. }
  202518. bool clipToRectangleList (const RectangleList& clipRegion)
  202519. {
  202520. if (clipRegion.isEmpty())
  202521. {
  202522. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202523. return false;
  202524. }
  202525. else
  202526. {
  202527. const int numRects = clipRegion.getNumRectangles();
  202528. HeapBlock <CGRect> rects (numRects);
  202529. for (int i = 0; i < numRects; ++i)
  202530. {
  202531. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202532. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202533. }
  202534. CGContextClipToRects (context, rects, numRects);
  202535. return ! isClipEmpty();
  202536. }
  202537. }
  202538. void excludeClipRectangle (const Rectangle<int>& r)
  202539. {
  202540. RectangleList remaining (getClipBounds());
  202541. remaining.subtract (r);
  202542. clipToRectangleList (remaining);
  202543. }
  202544. void clipToPath (const Path& path, const AffineTransform& transform)
  202545. {
  202546. createPath (path, transform);
  202547. CGContextClip (context);
  202548. }
  202549. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202550. {
  202551. if (! transform.isSingularity())
  202552. {
  202553. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202554. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202555. flip();
  202556. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202557. applyTransform (t);
  202558. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202559. CGContextClipToMask (context, r, image);
  202560. applyTransform (t.inverted());
  202561. flip();
  202562. CGImageRelease (image);
  202563. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202564. }
  202565. }
  202566. bool clipRegionIntersects (const Rectangle<int>& r)
  202567. {
  202568. return getClipBounds().intersects (r);
  202569. }
  202570. const Rectangle<int> getClipBounds() const
  202571. {
  202572. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202573. return Rectangle<int> (roundToInt (bounds.origin.x),
  202574. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202575. roundToInt (bounds.size.width),
  202576. roundToInt (bounds.size.height));
  202577. }
  202578. bool isClipEmpty() const
  202579. {
  202580. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202581. }
  202582. void saveState()
  202583. {
  202584. CGContextSaveGState (context);
  202585. stateStack.add (new SavedState (*state));
  202586. }
  202587. void restoreState()
  202588. {
  202589. CGContextRestoreGState (context);
  202590. SavedState* const top = stateStack.getLast();
  202591. if (top != 0)
  202592. {
  202593. state = top;
  202594. stateStack.removeLast (1, false);
  202595. }
  202596. else
  202597. {
  202598. jassertfalse // trying to pop with an empty stack!
  202599. }
  202600. }
  202601. void setFill (const FillType& fillType)
  202602. {
  202603. state->fillType = fillType;
  202604. if (fillType.isColour())
  202605. {
  202606. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202607. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202608. CGContextSetAlpha (context, 1.0f);
  202609. }
  202610. }
  202611. void setOpacity (float newOpacity)
  202612. {
  202613. state->fillType.setOpacity (newOpacity);
  202614. setFill (state->fillType);
  202615. }
  202616. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202617. {
  202618. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202619. ? kCGInterpolationLow
  202620. : kCGInterpolationHigh);
  202621. }
  202622. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202623. {
  202624. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202625. if (replaceExistingContents)
  202626. {
  202627. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202628. CGContextClearRect (context, cgRect);
  202629. #else
  202630. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202631. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202632. CGContextClearRect (context, cgRect);
  202633. else
  202634. #endif
  202635. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202636. #endif
  202637. fillRect (r, false);
  202638. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202639. }
  202640. else
  202641. {
  202642. if (state->fillType.isColour())
  202643. {
  202644. CGContextFillRect (context, cgRect);
  202645. }
  202646. else if (state->fillType.isGradient())
  202647. {
  202648. CGContextSaveGState (context);
  202649. CGContextClipToRect (context, cgRect);
  202650. drawGradient();
  202651. CGContextRestoreGState (context);
  202652. }
  202653. else
  202654. {
  202655. CGContextSaveGState (context);
  202656. CGContextClipToRect (context, cgRect);
  202657. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202658. CGContextRestoreGState (context);
  202659. }
  202660. }
  202661. }
  202662. void fillPath (const Path& path, const AffineTransform& transform)
  202663. {
  202664. CGContextSaveGState (context);
  202665. if (state->fillType.isColour())
  202666. {
  202667. flip();
  202668. applyTransform (transform);
  202669. createPath (path);
  202670. if (path.isUsingNonZeroWinding())
  202671. CGContextFillPath (context);
  202672. else
  202673. CGContextEOFillPath (context);
  202674. }
  202675. else
  202676. {
  202677. createPath (path, transform);
  202678. if (path.isUsingNonZeroWinding())
  202679. CGContextClip (context);
  202680. else
  202681. CGContextEOClip (context);
  202682. if (state->fillType.isGradient())
  202683. drawGradient();
  202684. else
  202685. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202686. }
  202687. CGContextRestoreGState (context);
  202688. }
  202689. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202690. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202691. {
  202692. jassert (sourceImage.getBounds().contains (srcClip));
  202693. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202694. CGImageRef image = fullImage;
  202695. if (srcClip != sourceImage.getBounds())
  202696. {
  202697. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202698. srcClip.getWidth(), srcClip.getHeight()));
  202699. CGImageRelease (fullImage);
  202700. }
  202701. CGContextSaveGState (context);
  202702. CGContextSetAlpha (context, state->fillType.getOpacity());
  202703. flip();
  202704. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202705. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202706. if (fillEntireClipAsTiles)
  202707. {
  202708. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  202709. CGContextDrawTiledImage (context, imageRect, image);
  202710. #else
  202711. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202712. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202713. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202714. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202715. CGContextDrawTiledImage (context, imageRect, image);
  202716. else
  202717. #endif
  202718. {
  202719. // Fallback to manually doing a tiled fill on 10.4
  202720. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202721. const int iw = srcClip.getWidth();
  202722. const int ih = srcClip.getHeight();
  202723. int x = 0, y = 0;
  202724. while (x > clip.origin.x) x -= iw;
  202725. while (y > clip.origin.y) y -= ih;
  202726. const int right = (int) (clip.origin.x + clip.size.width);
  202727. const int bottom = (int) (clip.origin.y + clip.size.height);
  202728. while (y < bottom)
  202729. {
  202730. for (int x2 = x; x2 < right; x2 += iw)
  202731. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202732. y += ih;
  202733. }
  202734. }
  202735. #endif
  202736. }
  202737. else
  202738. {
  202739. CGContextDrawImage (context, imageRect, image);
  202740. }
  202741. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202742. CGContextRestoreGState (context);
  202743. }
  202744. void drawLine (double x1, double y1, double x2, double y2)
  202745. {
  202746. CGContextSetLineCap (context, kCGLineCapSquare);
  202747. CGContextSetLineWidth (context, 1.0f);
  202748. CGContextSetRGBStrokeColor (context,
  202749. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202750. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202751. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  202752. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  202753. CGContextStrokeLineSegments (context, line, 1);
  202754. }
  202755. void drawVerticalLine (const int x, double top, double bottom)
  202756. {
  202757. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202758. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202759. #else
  202760. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202761. // the x co-ord slightly to trick it..
  202762. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202763. #endif
  202764. }
  202765. void drawHorizontalLine (const int y, double left, double right)
  202766. {
  202767. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202768. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202769. #else
  202770. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202771. // the x co-ord slightly to trick it..
  202772. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202773. #endif
  202774. }
  202775. void setFont (const Font& newFont)
  202776. {
  202777. if (state->font != newFont)
  202778. {
  202779. state->fontRef = 0;
  202780. state->font = newFont;
  202781. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202782. if (mf != 0)
  202783. {
  202784. state->fontRef = mf->fontRef;
  202785. CGContextSetFont (context, state->fontRef);
  202786. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202787. state->fontTransform = mf->renderingTransform;
  202788. state->fontTransform.a *= state->font.getHorizontalScale();
  202789. CGContextSetTextMatrix (context, state->fontTransform);
  202790. }
  202791. }
  202792. }
  202793. const Font getFont()
  202794. {
  202795. return state->font;
  202796. }
  202797. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202798. {
  202799. if (state->fontRef != 0 && state->fillType.isColour())
  202800. {
  202801. if (transform.isOnlyTranslation())
  202802. {
  202803. CGGlyph g = glyphNumber;
  202804. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202805. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202806. }
  202807. else
  202808. {
  202809. CGContextSaveGState (context);
  202810. flip();
  202811. applyTransform (transform);
  202812. CGAffineTransform t = state->fontTransform;
  202813. t.d = -t.d;
  202814. CGContextSetTextMatrix (context, t);
  202815. CGGlyph g = glyphNumber;
  202816. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202817. CGContextSetTextMatrix (context, state->fontTransform);
  202818. CGContextRestoreGState (context);
  202819. }
  202820. }
  202821. else
  202822. {
  202823. Path p;
  202824. Font& f = state->font;
  202825. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202826. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202827. .followedBy (transform));
  202828. }
  202829. }
  202830. private:
  202831. CGContextRef context;
  202832. const float flipHeight;
  202833. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202834. CGFunctionCallbacks gradientCallbacks;
  202835. struct SavedState
  202836. {
  202837. SavedState()
  202838. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202839. {
  202840. }
  202841. SavedState (const SavedState& other)
  202842. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202843. fontTransform (other.fontTransform)
  202844. {
  202845. }
  202846. ~SavedState()
  202847. {
  202848. }
  202849. FillType fillType;
  202850. Font font;
  202851. CGFontRef fontRef;
  202852. CGAffineTransform fontTransform;
  202853. };
  202854. ScopedPointer <SavedState> state;
  202855. OwnedArray <SavedState> stateStack;
  202856. HeapBlock <PixelARGB> gradientLookupTable;
  202857. int numGradientLookupEntries;
  202858. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202859. {
  202860. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  202861. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202862. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202863. colour.unpremultiply();
  202864. outData[0] = colour.getRed() / 255.0f;
  202865. outData[1] = colour.getGreen() / 255.0f;
  202866. outData[2] = colour.getBlue() / 255.0f;
  202867. outData[3] = colour.getAlpha() / 255.0f;
  202868. }
  202869. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202870. {
  202871. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202872. --numGradientLookupEntries;
  202873. CGShadingRef result = 0;
  202874. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  202875. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202876. if (gradient.isRadial)
  202877. {
  202878. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202879. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202880. function, true, true);
  202881. }
  202882. else
  202883. {
  202884. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202885. CGPointMake (gradient.x2, gradient.y2),
  202886. function, true, true);
  202887. }
  202888. CGFunctionRelease (function);
  202889. return result;
  202890. }
  202891. void drawGradient()
  202892. {
  202893. flip();
  202894. applyTransform (state->fillType.transform);
  202895. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202896. // you draw a gradient with high quality interp enabled).
  202897. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202898. CGContextSetAlpha (context, state->fillType.getOpacity());
  202899. CGContextDrawShading (context, shading);
  202900. CGShadingRelease (shading);
  202901. }
  202902. void createPath (const Path& path) const
  202903. {
  202904. CGContextBeginPath (context);
  202905. Path::Iterator i (path);
  202906. while (i.next())
  202907. {
  202908. switch (i.elementType)
  202909. {
  202910. case Path::Iterator::startNewSubPath:
  202911. CGContextMoveToPoint (context, i.x1, i.y1);
  202912. break;
  202913. case Path::Iterator::lineTo:
  202914. CGContextAddLineToPoint (context, i.x1, i.y1);
  202915. break;
  202916. case Path::Iterator::quadraticTo:
  202917. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202918. break;
  202919. case Path::Iterator::cubicTo:
  202920. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202921. break;
  202922. case Path::Iterator::closePath:
  202923. CGContextClosePath (context); break;
  202924. default:
  202925. jassertfalse
  202926. break;
  202927. }
  202928. }
  202929. }
  202930. void createPath (const Path& path, const AffineTransform& transform) const
  202931. {
  202932. CGContextBeginPath (context);
  202933. Path::Iterator i (path);
  202934. while (i.next())
  202935. {
  202936. switch (i.elementType)
  202937. {
  202938. case Path::Iterator::startNewSubPath:
  202939. transform.transformPoint (i.x1, i.y1);
  202940. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202941. break;
  202942. case Path::Iterator::lineTo:
  202943. transform.transformPoint (i.x1, i.y1);
  202944. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202945. break;
  202946. case Path::Iterator::quadraticTo:
  202947. transform.transformPoint (i.x1, i.y1);
  202948. transform.transformPoint (i.x2, i.y2);
  202949. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202950. break;
  202951. case Path::Iterator::cubicTo:
  202952. transform.transformPoint (i.x1, i.y1);
  202953. transform.transformPoint (i.x2, i.y2);
  202954. transform.transformPoint (i.x3, i.y3);
  202955. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202956. break;
  202957. case Path::Iterator::closePath:
  202958. CGContextClosePath (context); break;
  202959. default:
  202960. jassertfalse
  202961. break;
  202962. }
  202963. }
  202964. }
  202965. static Image* createAlphaChannelImage (const Image& im)
  202966. {
  202967. if (im.getFormat() == Image::SingleChannel)
  202968. return const_cast <Image*> (&im);
  202969. return im.createCopyOfAlphaChannel();
  202970. }
  202971. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202972. {
  202973. if (im.getFormat() != Image::SingleChannel)
  202974. delete alphaIm;
  202975. }
  202976. void flip() const
  202977. {
  202978. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202979. }
  202980. void applyTransform (const AffineTransform& transform) const
  202981. {
  202982. CGAffineTransform t;
  202983. t.a = transform.mat00;
  202984. t.b = transform.mat10;
  202985. t.c = transform.mat01;
  202986. t.d = transform.mat11;
  202987. t.tx = transform.mat02;
  202988. t.ty = transform.mat12;
  202989. CGContextConcatCTM (context, t);
  202990. }
  202991. float flipY (float y) const
  202992. {
  202993. return flipHeight - y;
  202994. }
  202995. };
  202996. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202997. {
  202998. return new CoreGraphicsContext (context, imageHeight);
  202999. }
  203000. #endif
  203001. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  203002. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203003. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203004. // compiled on its own).
  203005. #if JUCE_INCLUDED_FILE
  203006. class UIViewComponentPeer;
  203007. END_JUCE_NAMESPACE
  203008. #define JuceUIView MakeObjCClassName(JuceUIView)
  203009. @interface JuceUIView : UIView
  203010. {
  203011. @public
  203012. UIViewComponentPeer* owner;
  203013. }
  203014. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  203015. - (void) dealloc;
  203016. - (void) drawRect: (CGRect) r;
  203017. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  203018. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  203019. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  203020. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  203021. - (BOOL) becomeFirstResponder;
  203022. - (BOOL) resignFirstResponder;
  203023. - (BOOL) canBecomeFirstResponder;
  203024. - (void) asyncRepaint: (id) rect;
  203025. @end
  203026. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  203027. @interface JuceUIWindow : UIWindow
  203028. {
  203029. @private
  203030. UIViewComponentPeer* owner;
  203031. bool isZooming;
  203032. }
  203033. - (void) setOwner: (UIViewComponentPeer*) owner;
  203034. - (void) becomeKeyWindow;
  203035. @end
  203036. BEGIN_JUCE_NAMESPACE
  203037. class UIViewComponentPeer : public ComponentPeer
  203038. {
  203039. public:
  203040. UIViewComponentPeer (Component* const component,
  203041. const int windowStyleFlags,
  203042. UIView* viewToAttachTo);
  203043. ~UIViewComponentPeer();
  203044. void* getNativeHandle() const;
  203045. void setVisible (bool shouldBeVisible);
  203046. void setTitle (const String& title);
  203047. void setPosition (int x, int y);
  203048. void setSize (int w, int h);
  203049. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  203050. void getBounds (int& x, int& y, int& w, int& h, const bool global) const;
  203051. void getBounds (int& x, int& y, int& w, int& h) const;
  203052. int getScreenX() const;
  203053. int getScreenY() const;
  203054. void relativePositionToGlobal (int& x, int& y);
  203055. void globalPositionToRelative (int& x, int& y);
  203056. void setMinimised (bool shouldBeMinimised);
  203057. bool isMinimised() const;
  203058. void setFullScreen (bool shouldBeFullScreen);
  203059. bool isFullScreen() const;
  203060. bool contains (int x, int y, bool trueIfInAChildWindow) const;
  203061. const BorderSize getFrameSize() const;
  203062. bool setAlwaysOnTop (bool alwaysOnTop);
  203063. void toFront (bool makeActiveWindow);
  203064. void toBehind (ComponentPeer* other);
  203065. void setIcon (const Image& newIcon);
  203066. virtual void drawRect (CGRect r);
  203067. virtual bool canBecomeKeyWindow();
  203068. virtual bool windowShouldClose();
  203069. virtual void redirectMovedOrResized();
  203070. virtual CGRect constrainRect (CGRect r);
  203071. virtual void viewFocusGain();
  203072. virtual void viewFocusLoss();
  203073. bool isFocused() const;
  203074. void grabFocus();
  203075. void textInputRequired (int x, int y);
  203076. void repaint (int x, int y, int w, int h);
  203077. void performAnyPendingRepaintsNow();
  203078. juce_UseDebuggingNewOperator
  203079. UIWindow* window;
  203080. JuceUIView* view;
  203081. bool isSharedWindow, fullScreen, insideDrawRect;
  203082. };
  203083. END_JUCE_NAMESPACE
  203084. @implementation JuceUIView
  203085. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  203086. withFrame: (CGRect) frame
  203087. {
  203088. [super initWithFrame: frame];
  203089. owner = owner_;
  203090. return self;
  203091. }
  203092. - (void) dealloc
  203093. {
  203094. [super dealloc];
  203095. }
  203096. - (void) drawRect: (CGRect) r
  203097. {
  203098. if (owner != 0)
  203099. owner->drawRect (r);
  203100. }
  203101. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  203102. {
  203103. return false;
  203104. }
  203105. static int currentModifiers = 0;
  203106. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  203107. {
  203108. return ModifierKeys (currentModifiers);
  203109. }
  203110. void ModifierKeys::updateCurrentModifiers() throw()
  203111. {
  203112. currentModifierFlags = currentModifiers;
  203113. }
  203114. static int getModifierForButtonNumber (const int num)
  203115. {
  203116. return num == 0 ? ModifierKeys::leftButtonModifier
  203117. : (num == 1 ? ModifierKeys::rightButtonModifier
  203118. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  203119. }
  203120. static int64 getMouseTime (UIEvent* e)
  203121. {
  203122. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  203123. + (int64) ([e timestamp] * 1000.0);
  203124. }
  203125. int juce_lastMouseX = 0, juce_lastMouseY = 0;
  203126. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  203127. {
  203128. if (owner == 0)
  203129. return;
  203130. NSArray* const t = [[event touchesForView: self] allObjects];
  203131. switch ([t count])
  203132. {
  203133. case 1: // One finger..
  203134. {
  203135. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203136. currentModifiers |= getModifierForButtonNumber (0);
  203137. int x, y, w, h;
  203138. owner->getBounds (x, y, w, h, true);
  203139. juce_lastMouseX = x + (int) p.x;
  203140. juce_lastMouseY = y + (int) p.y;
  203141. owner->handleMouseMove ((int) p.x, (int) p.y, getMouseTime (event));
  203142. if (owner != 0)
  203143. owner->handleMouseDown ((int) p.x, (int) p.y, getMouseTime (event));
  203144. }
  203145. default:
  203146. //xxx multi-touch..
  203147. break;
  203148. }
  203149. }
  203150. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  203151. {
  203152. if (owner == 0)
  203153. return;
  203154. NSArray* const t = [[event touchesForView: self] allObjects];
  203155. switch ([t count])
  203156. {
  203157. case 1: // One finger..
  203158. {
  203159. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203160. int x, y, w, h;
  203161. owner->getBounds (x, y, w, h, true);
  203162. juce_lastMouseX = x + (int) p.x;
  203163. juce_lastMouseY = y + (int) p.y;
  203164. owner->handleMouseDrag ((int) p.x, (int) p.y, getMouseTime (event));
  203165. }
  203166. default:
  203167. //xxx multi-touch..
  203168. break;
  203169. }
  203170. }
  203171. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  203172. {
  203173. if (owner == 0)
  203174. return;
  203175. NSArray* const t = [[event touchesForView: self] allObjects];
  203176. switch ([t count])
  203177. {
  203178. case 1: // One finger..
  203179. {
  203180. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203181. int x, y, w, h;
  203182. owner->getBounds (x, y, w, h, true);
  203183. juce_lastMouseX = x + (int) p.x;
  203184. juce_lastMouseY = y + (int) p.y;
  203185. const int oldMods = currentModifiers;
  203186. currentModifiers &= ~getModifierForButtonNumber (0);
  203187. owner->handleMouseUp (oldMods, (int) p.x, (int) p.y, getMouseTime (event));
  203188. }
  203189. default:
  203190. //xxx multi-touch..
  203191. break;
  203192. }
  203193. }
  203194. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  203195. {
  203196. [self touchesEnded: touches withEvent: event];
  203197. }
  203198. - (BOOL) becomeFirstResponder
  203199. {
  203200. if (owner != 0)
  203201. owner->viewFocusGain();
  203202. return true;
  203203. }
  203204. - (BOOL) resignFirstResponder
  203205. {
  203206. if (owner != 0)
  203207. owner->viewFocusLoss();
  203208. return true;
  203209. }
  203210. - (BOOL) canBecomeFirstResponder
  203211. {
  203212. return owner != 0 && owner->canBecomeKeyWindow();
  203213. }
  203214. - (void) asyncRepaint: (id) rect
  203215. {
  203216. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  203217. [self setNeedsDisplayInRect: *r];
  203218. }
  203219. @end
  203220. @implementation JuceUIWindow
  203221. - (void) setOwner: (UIViewComponentPeer*) owner_
  203222. {
  203223. owner = owner_;
  203224. isZooming = false;
  203225. }
  203226. - (void) becomeKeyWindow
  203227. {
  203228. [super becomeKeyWindow];
  203229. if (owner != 0)
  203230. owner->grabFocus();
  203231. }
  203232. @end
  203233. BEGIN_JUCE_NAMESPACE
  203234. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  203235. const int windowStyleFlags,
  203236. UIView* viewToAttachTo)
  203237. : ComponentPeer (component, windowStyleFlags),
  203238. window (0),
  203239. view (0),
  203240. isSharedWindow (viewToAttachTo != 0),
  203241. fullScreen (false),
  203242. insideDrawRect (false)
  203243. {
  203244. CGRect r;
  203245. r.origin.x = 0;
  203246. r.origin.y = 0;
  203247. r.size.width = (float) component->getWidth();
  203248. r.size.height = (float) component->getHeight();
  203249. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  203250. if (isSharedWindow)
  203251. {
  203252. window = [viewToAttachTo window];
  203253. [viewToAttachTo addSubview: view];
  203254. setVisible (component->isVisible());
  203255. }
  203256. else
  203257. {
  203258. r.origin.x = (float) component->getX();
  203259. r.origin.y = (float) component->getY();
  203260. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  203261. window = [[JuceUIWindow alloc] init];
  203262. window.frame = r;
  203263. window.opaque = component->isOpaque();
  203264. view.opaque = component->isOpaque();
  203265. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203266. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203267. [((JuceUIWindow*) window) setOwner: this];
  203268. if (component->isAlwaysOnTop())
  203269. window.windowLevel = UIWindowLevelAlert;
  203270. [window addSubview: view];
  203271. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203272. view.hidden = ! component->isVisible();
  203273. window.hidden = ! component->isVisible();
  203274. }
  203275. setTitle (component->getName());
  203276. }
  203277. UIViewComponentPeer::~UIViewComponentPeer()
  203278. {
  203279. view->owner = 0;
  203280. [view removeFromSuperview];
  203281. [view release];
  203282. if (! isSharedWindow)
  203283. {
  203284. [((JuceUIWindow*) window) setOwner: 0];
  203285. [window release];
  203286. }
  203287. }
  203288. void* UIViewComponentPeer::getNativeHandle() const
  203289. {
  203290. return view;
  203291. }
  203292. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  203293. {
  203294. view.hidden = ! shouldBeVisible;
  203295. if (! isSharedWindow)
  203296. window.hidden = ! shouldBeVisible;
  203297. }
  203298. void UIViewComponentPeer::setTitle (const String& title)
  203299. {
  203300. // xxx is this possible?
  203301. }
  203302. void UIViewComponentPeer::setPosition (int x, int y)
  203303. {
  203304. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  203305. }
  203306. void UIViewComponentPeer::setSize (int w, int h)
  203307. {
  203308. setBounds (component->getX(), component->getY(), w, h, false);
  203309. }
  203310. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  203311. {
  203312. fullScreen = isNowFullScreen;
  203313. w = jmax (0, w);
  203314. h = jmax (0, h);
  203315. CGRect r;
  203316. r.origin.x = (float) x;
  203317. r.origin.y = (float) y;
  203318. r.size.width = (float) w;
  203319. r.size.height = (float) h;
  203320. if (isSharedWindow)
  203321. {
  203322. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  203323. if ([view frame].size.width != r.size.width
  203324. || [view frame].size.height != r.size.height)
  203325. [view setNeedsDisplay];
  203326. view.frame = r;
  203327. }
  203328. else
  203329. {
  203330. window.frame = r;
  203331. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203332. }
  203333. }
  203334. void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const
  203335. {
  203336. CGRect r = [view frame];
  203337. if (global && [view window] != 0)
  203338. {
  203339. r = [view convertRect: r toView: nil];
  203340. CGRect wr = [[view window] frame];
  203341. r.origin.x += wr.origin.x;
  203342. r.origin.y += wr.origin.y;
  203343. }
  203344. x = (int) r.origin.x;
  203345. y = (int) r.origin.y;
  203346. w = (int) r.size.width;
  203347. h = (int) r.size.height;
  203348. }
  203349. void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const
  203350. {
  203351. getBounds (x, y, w, h, ! isSharedWindow);
  203352. }
  203353. int UIViewComponentPeer::getScreenX() const
  203354. {
  203355. int x, y, w, h;
  203356. getBounds (x, y, w, h, true);
  203357. return x;
  203358. }
  203359. int UIViewComponentPeer::getScreenY() const
  203360. {
  203361. int x, y, w, h;
  203362. getBounds (x, y, w, h, true);
  203363. return y;
  203364. }
  203365. void UIViewComponentPeer::relativePositionToGlobal (int& x, int& y)
  203366. {
  203367. int wx, wy, ww, wh;
  203368. getBounds (wx, wy, ww, wh, true);
  203369. x += wx;
  203370. y += wy;
  203371. }
  203372. void UIViewComponentPeer::globalPositionToRelative (int& x, int& y)
  203373. {
  203374. int wx, wy, ww, wh;
  203375. getBounds (wx, wy, ww, wh, true);
  203376. x -= wx;
  203377. y -= wy;
  203378. }
  203379. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  203380. {
  203381. if (constrainer != 0)
  203382. {
  203383. CGRect current = [window frame];
  203384. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  203385. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  203386. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  203387. (int) r.size.width, (int) r.size.height);
  203388. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  203389. (int) current.size.width, (int) current.size.height);
  203390. constrainer->checkBounds (pos, original,
  203391. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  203392. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  203393. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  203394. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  203395. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  203396. r.origin.x = pos.getX();
  203397. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  203398. r.size.width = pos.getWidth();
  203399. r.size.height = pos.getHeight();
  203400. }
  203401. return r;
  203402. }
  203403. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  203404. {
  203405. // xxx
  203406. }
  203407. bool UIViewComponentPeer::isMinimised() const
  203408. {
  203409. return false;
  203410. }
  203411. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  203412. {
  203413. if (! isSharedWindow)
  203414. {
  203415. Rectangle<int> r (lastNonFullscreenBounds);
  203416. setMinimised (false);
  203417. if (fullScreen != shouldBeFullScreen)
  203418. {
  203419. if (shouldBeFullScreen)
  203420. r = Desktop::getInstance().getMainMonitorArea();
  203421. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  203422. if (r != getComponent()->getBounds() && ! r.isEmpty())
  203423. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  203424. }
  203425. }
  203426. }
  203427. bool UIViewComponentPeer::isFullScreen() const
  203428. {
  203429. return fullScreen;
  203430. }
  203431. bool UIViewComponentPeer::contains (int x, int y, bool trueIfInAChildWindow) const
  203432. {
  203433. if (((unsigned int) x) >= (unsigned int) component->getWidth()
  203434. || ((unsigned int) y) >= (unsigned int) component->getHeight())
  203435. return false;
  203436. CGPoint p;
  203437. p.x = (float) x;
  203438. p.y = (float) y;
  203439. UIView* v = [view hitTest: p withEvent: nil];
  203440. if (trueIfInAChildWindow)
  203441. return v != nil;
  203442. return v == view;
  203443. }
  203444. const BorderSize UIViewComponentPeer::getFrameSize() const
  203445. {
  203446. BorderSize b;
  203447. if (! isSharedWindow)
  203448. {
  203449. CGRect v = [view convertRect: [view frame] toView: nil];
  203450. CGRect w = [window frame];
  203451. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203452. b.setBottom ((int) v.origin.y);
  203453. b.setLeft ((int) v.origin.x);
  203454. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203455. }
  203456. return b;
  203457. }
  203458. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203459. {
  203460. if (! isSharedWindow)
  203461. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203462. return true;
  203463. }
  203464. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203465. {
  203466. if (isSharedWindow)
  203467. [[view superview] bringSubviewToFront: view];
  203468. if (window != 0 && component->isVisible())
  203469. [window makeKeyAndVisible];
  203470. }
  203471. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203472. {
  203473. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203474. if (isSharedWindow)
  203475. {
  203476. [[view superview] insertSubview: view belowSubview: o->view];
  203477. }
  203478. else
  203479. {
  203480. jassertfalse // don't know how to do this
  203481. }
  203482. }
  203483. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203484. {
  203485. // to do..
  203486. }
  203487. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203488. void UIViewComponentPeer::viewFocusGain()
  203489. {
  203490. if (currentlyFocusedPeer != this)
  203491. {
  203492. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203493. currentlyFocusedPeer->handleFocusLoss();
  203494. currentlyFocusedPeer = this;
  203495. handleFocusGain();
  203496. }
  203497. }
  203498. void UIViewComponentPeer::viewFocusLoss()
  203499. {
  203500. if (currentlyFocusedPeer == this)
  203501. {
  203502. currentlyFocusedPeer = 0;
  203503. handleFocusLoss();
  203504. }
  203505. }
  203506. void juce_HandleProcessFocusChange()
  203507. {
  203508. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203509. {
  203510. if (Process::isForegroundProcess())
  203511. {
  203512. currentlyFocusedPeer->handleFocusGain();
  203513. ComponentPeer::bringModalComponentToFront();
  203514. }
  203515. else
  203516. {
  203517. currentlyFocusedPeer->handleFocusLoss();
  203518. // turn kiosk mode off if we lose focus..
  203519. Desktop::getInstance().setKioskModeComponent (0);
  203520. }
  203521. }
  203522. }
  203523. bool UIViewComponentPeer::isFocused() const
  203524. {
  203525. return isSharedWindow ? this == currentlyFocusedPeer
  203526. : (window != 0 && [window isKeyWindow]);
  203527. }
  203528. void UIViewComponentPeer::grabFocus()
  203529. {
  203530. if (window != 0)
  203531. {
  203532. [window makeKeyWindow];
  203533. viewFocusGain();
  203534. }
  203535. }
  203536. void UIViewComponentPeer::textInputRequired (int /*x*/, int /*y*/)
  203537. {
  203538. }
  203539. void UIViewComponentPeer::drawRect (CGRect r)
  203540. {
  203541. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203542. return;
  203543. CGContextRef cg = UIGraphicsGetCurrentContext();
  203544. if (! component->isOpaque())
  203545. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203546. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203547. CoreGraphicsContext g (cg, view.bounds.size.height);
  203548. insideDrawRect = true;
  203549. handlePaint (g);
  203550. insideDrawRect = false;
  203551. }
  203552. bool UIViewComponentPeer::canBecomeKeyWindow()
  203553. {
  203554. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203555. }
  203556. bool UIViewComponentPeer::windowShouldClose()
  203557. {
  203558. if (! isValidPeer (this))
  203559. return YES;
  203560. handleUserClosingWindow();
  203561. return NO;
  203562. }
  203563. void UIViewComponentPeer::redirectMovedOrResized()
  203564. {
  203565. handleMovedOrResized();
  203566. }
  203567. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203568. {
  203569. }
  203570. class AsyncRepaintMessage : public CallbackMessage
  203571. {
  203572. public:
  203573. UIViewComponentPeer* const peer;
  203574. const Rectangle<int> rect;
  203575. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203576. : peer (peer_), rect (rect_)
  203577. {
  203578. }
  203579. void messageCallback()
  203580. {
  203581. if (ComponentPeer::isValidPeer (peer))
  203582. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203583. }
  203584. };
  203585. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203586. {
  203587. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203588. {
  203589. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203590. }
  203591. else
  203592. {
  203593. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203594. }
  203595. }
  203596. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203597. {
  203598. }
  203599. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203600. {
  203601. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203602. }
  203603. Image* juce_createIconForFile (const File& file)
  203604. {
  203605. return 0;
  203606. }
  203607. bool Desktop::canUseSemiTransparentWindows() throw()
  203608. {
  203609. return true;
  203610. }
  203611. void Desktop::getMousePosition (int& x, int& y) throw()
  203612. {
  203613. x = juce_lastMouseX;
  203614. y = juce_lastMouseY;
  203615. }
  203616. void Desktop::setMousePosition (int x, int y) throw()
  203617. {
  203618. }
  203619. const int KeyPress::spaceKey = ' ';
  203620. const int KeyPress::returnKey = 0x0d;
  203621. const int KeyPress::escapeKey = 0x1b;
  203622. const int KeyPress::backspaceKey = 0x7f;
  203623. const int KeyPress::leftKey = 0x1000;
  203624. const int KeyPress::rightKey = 0x1001;
  203625. const int KeyPress::upKey = 0x1002;
  203626. const int KeyPress::downKey = 0x1003;
  203627. const int KeyPress::pageUpKey = 0x1004;
  203628. const int KeyPress::pageDownKey = 0x1005;
  203629. const int KeyPress::endKey = 0x1006;
  203630. const int KeyPress::homeKey = 0x1007;
  203631. const int KeyPress::deleteKey = 0x1008;
  203632. const int KeyPress::insertKey = -1;
  203633. const int KeyPress::tabKey = 9;
  203634. const int KeyPress::F1Key = 0x2001;
  203635. const int KeyPress::F2Key = 0x2002;
  203636. const int KeyPress::F3Key = 0x2003;
  203637. const int KeyPress::F4Key = 0x2004;
  203638. const int KeyPress::F5Key = 0x2005;
  203639. const int KeyPress::F6Key = 0x2006;
  203640. const int KeyPress::F7Key = 0x2007;
  203641. const int KeyPress::F8Key = 0x2008;
  203642. const int KeyPress::F9Key = 0x2009;
  203643. const int KeyPress::F10Key = 0x200a;
  203644. const int KeyPress::F11Key = 0x200b;
  203645. const int KeyPress::F12Key = 0x200c;
  203646. const int KeyPress::F13Key = 0x200d;
  203647. const int KeyPress::F14Key = 0x200e;
  203648. const int KeyPress::F15Key = 0x200f;
  203649. const int KeyPress::F16Key = 0x2010;
  203650. const int KeyPress::numberPad0 = 0x30020;
  203651. const int KeyPress::numberPad1 = 0x30021;
  203652. const int KeyPress::numberPad2 = 0x30022;
  203653. const int KeyPress::numberPad3 = 0x30023;
  203654. const int KeyPress::numberPad4 = 0x30024;
  203655. const int KeyPress::numberPad5 = 0x30025;
  203656. const int KeyPress::numberPad6 = 0x30026;
  203657. const int KeyPress::numberPad7 = 0x30027;
  203658. const int KeyPress::numberPad8 = 0x30028;
  203659. const int KeyPress::numberPad9 = 0x30029;
  203660. const int KeyPress::numberPadAdd = 0x3002a;
  203661. const int KeyPress::numberPadSubtract = 0x3002b;
  203662. const int KeyPress::numberPadMultiply = 0x3002c;
  203663. const int KeyPress::numberPadDivide = 0x3002d;
  203664. const int KeyPress::numberPadSeparator = 0x3002e;
  203665. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203666. const int KeyPress::numberPadEquals = 0x30030;
  203667. const int KeyPress::numberPadDelete = 0x30031;
  203668. const int KeyPress::playKey = 0x30000;
  203669. const int KeyPress::stopKey = 0x30001;
  203670. const int KeyPress::fastForwardKey = 0x30002;
  203671. const int KeyPress::rewindKey = 0x30003;
  203672. #endif
  203673. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203674. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203675. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203676. // compiled on its own).
  203677. #if JUCE_INCLUDED_FILE
  203678. struct CallbackMessagePayload
  203679. {
  203680. MessageCallbackFunction* function;
  203681. void* parameter;
  203682. void* volatile result;
  203683. bool volatile hasBeenExecuted;
  203684. };
  203685. END_JUCE_NAMESPACE
  203686. using namespace JUCE_NAMESPACE;
  203687. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203688. {
  203689. }
  203690. - (JuceAppDelegate*) init;
  203691. - (void) dealloc;
  203692. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203693. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203694. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203695. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203696. - (void) customEvent: (id) data;
  203697. - (void) performCallback: (id) info;
  203698. @end
  203699. @implementation JuceAppDelegate
  203700. - (JuceAppDelegate*) init
  203701. {
  203702. [super init];
  203703. [[UIApplication sharedApplication] setDelegate: self];
  203704. return self;
  203705. }
  203706. - (void) dealloc
  203707. {
  203708. [[UIApplication sharedApplication] setDelegate: nil];
  203709. [super dealloc];
  203710. }
  203711. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203712. {
  203713. if (JUCEApplication::getInstance() != 0)
  203714. {
  203715. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203716. return YES;
  203717. }
  203718. return NO;
  203719. }
  203720. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203721. {
  203722. juce_HandleProcessFocusChange();
  203723. }
  203724. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203725. {
  203726. juce_HandleProcessFocusChange();
  203727. }
  203728. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203729. {
  203730. juce_HandleProcessFocusChange();
  203731. }
  203732. - (void) customEvent: (id) n
  203733. {
  203734. NSData* data = (NSData*) n;
  203735. void* message = 0;
  203736. [data getBytes: &message length: sizeof (message)];
  203737. [data release];
  203738. if (message != 0)
  203739. MessageManager::getInstance()->deliverMessage (message);
  203740. }
  203741. - (void) performCallback: (id) info
  203742. {
  203743. if ([info isKindOfClass: [NSData class]])
  203744. {
  203745. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203746. if (pl != 0)
  203747. {
  203748. pl->result = (*pl->function) (pl->parameter);
  203749. pl->hasBeenExecuted = true;
  203750. }
  203751. }
  203752. else
  203753. {
  203754. jassertfalse // should never get here!
  203755. }
  203756. }
  203757. @end
  203758. BEGIN_JUCE_NAMESPACE
  203759. static JuceAppDelegate* juceAppDelegate = 0;
  203760. void MessageManager::runDispatchLoop()
  203761. {
  203762. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203763. runDispatchLoopUntil (-1);
  203764. }
  203765. void MessageManager::stopDispatchLoop()
  203766. {
  203767. exit (0); // iPhone apps get no mercy..
  203768. }
  203769. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203770. {
  203771. const ScopedAutoReleasePool pool;
  203772. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203773. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203774. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203775. while (! quitMessagePosted)
  203776. {
  203777. const ScopedAutoReleasePool pool;
  203778. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203779. beforeDate: endDate];
  203780. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203781. break;
  203782. }
  203783. return ! quitMessagePosted;
  203784. }
  203785. static CFRunLoopRef runLoop = 0;
  203786. static CFRunLoopSourceRef runLoopSource = 0;
  203787. static Array <void*, CriticalSection>* pendingMessages = 0;
  203788. static void runLoopSourceCallback (void*)
  203789. {
  203790. if (pendingMessages != 0)
  203791. {
  203792. int numDispatched = 0;
  203793. do
  203794. {
  203795. void* const nextMessage = pendingMessages->remove (0);
  203796. if (nextMessage == 0)
  203797. return;
  203798. const ScopedAutoReleasePool pool;
  203799. MessageManager::getInstance()->deliverMessage (nextMessage);
  203800. } while (++numDispatched <= 4);
  203801. CFRunLoopSourceSignal (runLoopSource);
  203802. CFRunLoopWakeUp (runLoop);
  203803. }
  203804. }
  203805. void MessageManager::doPlatformSpecificInitialisation()
  203806. {
  203807. pendingMessages = new Array <void*, CriticalSection>();
  203808. runLoop = CFRunLoopGetCurrent();
  203809. CFRunLoopSourceContext sourceContext;
  203810. zerostruct (sourceContext);
  203811. sourceContext.perform = runLoopSourceCallback;
  203812. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203813. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203814. if (juceAppDelegate == 0)
  203815. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203816. }
  203817. void MessageManager::doPlatformSpecificShutdown()
  203818. {
  203819. CFRunLoopSourceInvalidate (runLoopSource);
  203820. CFRelease (runLoopSource);
  203821. runLoopSource = 0;
  203822. if (pendingMessages != 0)
  203823. {
  203824. while (pendingMessages->size() > 0)
  203825. delete ((Message*) pendingMessages->remove(0));
  203826. deleteAndZero (pendingMessages);
  203827. }
  203828. if (juceAppDelegate != 0)
  203829. {
  203830. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203831. [juceAppDelegate release];
  203832. juceAppDelegate = 0;
  203833. }
  203834. }
  203835. bool juce_postMessageToSystemQueue (void* message)
  203836. {
  203837. if (pendingMessages != 0)
  203838. {
  203839. pendingMessages->add (message);
  203840. CFRunLoopSourceSignal (runLoopSource);
  203841. CFRunLoopWakeUp (runLoop);
  203842. }
  203843. return true;
  203844. }
  203845. void MessageManager::broadcastMessage (const String& value) throw()
  203846. {
  203847. }
  203848. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203849. void* data)
  203850. {
  203851. if (isThisTheMessageThread())
  203852. {
  203853. return (*callback) (data);
  203854. }
  203855. else
  203856. {
  203857. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203858. // deadlock because the message manager is blocked from running, so can never
  203859. // call your function..
  203860. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203861. const ScopedAutoReleasePool pool;
  203862. CallbackMessagePayload cmp;
  203863. cmp.function = callback;
  203864. cmp.parameter = data;
  203865. cmp.result = 0;
  203866. cmp.hasBeenExecuted = false;
  203867. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203868. withObject: [NSData dataWithBytesNoCopy: &cmp
  203869. length: sizeof (cmp)
  203870. freeWhenDone: NO]
  203871. waitUntilDone: YES];
  203872. return cmp.result;
  203873. }
  203874. }
  203875. #endif
  203876. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203877. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203878. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203879. // compiled on its own).
  203880. #if JUCE_INCLUDED_FILE
  203881. #if JUCE_MAC
  203882. END_JUCE_NAMESPACE
  203883. using namespace JUCE_NAMESPACE;
  203884. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203885. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203886. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203887. #else
  203888. @interface JuceFileChooserDelegate : NSObject
  203889. #endif
  203890. {
  203891. StringArray* filters;
  203892. }
  203893. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203894. - (void) dealloc;
  203895. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203896. @end
  203897. @implementation JuceFileChooserDelegate
  203898. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203899. {
  203900. [super init];
  203901. filters = filters_;
  203902. return self;
  203903. }
  203904. - (void) dealloc
  203905. {
  203906. delete filters;
  203907. [super dealloc];
  203908. }
  203909. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203910. {
  203911. const File f (nsStringToJuce (filename));
  203912. for (int i = filters->size(); --i >= 0;)
  203913. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203914. return true;
  203915. return f.isDirectory();
  203916. }
  203917. @end
  203918. BEGIN_JUCE_NAMESPACE
  203919. void FileChooser::showPlatformDialog (Array<File>& results,
  203920. const String& title,
  203921. const File& currentFileOrDirectory,
  203922. const String& filter,
  203923. bool selectsDirectory,
  203924. bool selectsFiles,
  203925. bool isSaveDialogue,
  203926. bool warnAboutOverwritingExistingFiles,
  203927. bool selectMultipleFiles,
  203928. FilePreviewComponent* extraInfoComponent)
  203929. {
  203930. const ScopedAutoReleasePool pool;
  203931. StringArray* filters = new StringArray();
  203932. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  203933. filters->trim();
  203934. filters->removeEmptyStrings();
  203935. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203936. [delegate autorelease];
  203937. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203938. : [NSOpenPanel openPanel];
  203939. [panel setTitle: juceStringToNS (title)];
  203940. if (! isSaveDialogue)
  203941. {
  203942. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203943. [openPanel setCanChooseDirectories: selectsDirectory];
  203944. [openPanel setCanChooseFiles: selectsFiles];
  203945. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203946. }
  203947. [panel setDelegate: delegate];
  203948. if (isSaveDialogue || selectsDirectory)
  203949. [panel setCanCreateDirectories: YES];
  203950. String directory, filename;
  203951. if (currentFileOrDirectory.isDirectory())
  203952. {
  203953. directory = currentFileOrDirectory.getFullPathName();
  203954. }
  203955. else
  203956. {
  203957. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203958. filename = currentFileOrDirectory.getFileName();
  203959. }
  203960. if ([panel runModalForDirectory: juceStringToNS (directory)
  203961. file: juceStringToNS (filename)]
  203962. == NSOKButton)
  203963. {
  203964. if (isSaveDialogue)
  203965. {
  203966. results.add (File (nsStringToJuce ([panel filename])));
  203967. }
  203968. else
  203969. {
  203970. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203971. NSArray* urls = [openPanel filenames];
  203972. for (unsigned int i = 0; i < [urls count]; ++i)
  203973. {
  203974. NSString* f = [urls objectAtIndex: i];
  203975. results.add (File (nsStringToJuce (f)));
  203976. }
  203977. }
  203978. }
  203979. [panel setDelegate: nil];
  203980. }
  203981. #else
  203982. void FileChooser::showPlatformDialog (Array<File>& results,
  203983. const String& title,
  203984. const File& currentFileOrDirectory,
  203985. const String& filter,
  203986. bool selectsDirectory,
  203987. bool selectsFiles,
  203988. bool isSaveDialogue,
  203989. bool warnAboutOverwritingExistingFiles,
  203990. bool selectMultipleFiles,
  203991. FilePreviewComponent* extraInfoComponent)
  203992. {
  203993. const ScopedAutoReleasePool pool;
  203994. jassertfalse //xxx to do
  203995. }
  203996. #endif
  203997. #endif
  203998. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203999. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  204000. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204001. // compiled on its own).
  204002. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  204003. #if JUCE_MAC
  204004. END_JUCE_NAMESPACE
  204005. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  204006. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  204007. {
  204008. CriticalSection* contextLock;
  204009. bool needsUpdate;
  204010. }
  204011. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  204012. - (bool) makeActive;
  204013. - (void) makeInactive;
  204014. - (void) reshape;
  204015. @end
  204016. @implementation ThreadSafeNSOpenGLView
  204017. - (id) initWithFrame: (NSRect) frameRect
  204018. pixelFormat: (NSOpenGLPixelFormat*) format
  204019. {
  204020. contextLock = new CriticalSection();
  204021. self = [super initWithFrame: frameRect pixelFormat: format];
  204022. if (self != nil)
  204023. [[NSNotificationCenter defaultCenter] addObserver: self
  204024. selector: @selector (_surfaceNeedsUpdate:)
  204025. name: NSViewGlobalFrameDidChangeNotification
  204026. object: self];
  204027. return self;
  204028. }
  204029. - (void) dealloc
  204030. {
  204031. [[NSNotificationCenter defaultCenter] removeObserver: self];
  204032. delete contextLock;
  204033. [super dealloc];
  204034. }
  204035. - (bool) makeActive
  204036. {
  204037. const ScopedLock sl (*contextLock);
  204038. if ([self openGLContext] == 0)
  204039. return false;
  204040. [[self openGLContext] makeCurrentContext];
  204041. if (needsUpdate)
  204042. {
  204043. [super update];
  204044. needsUpdate = false;
  204045. }
  204046. return true;
  204047. }
  204048. - (void) makeInactive
  204049. {
  204050. const ScopedLock sl (*contextLock);
  204051. [NSOpenGLContext clearCurrentContext];
  204052. }
  204053. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  204054. {
  204055. const ScopedLock sl (*contextLock);
  204056. needsUpdate = true;
  204057. }
  204058. - (void) update
  204059. {
  204060. const ScopedLock sl (*contextLock);
  204061. needsUpdate = true;
  204062. }
  204063. - (void) reshape
  204064. {
  204065. const ScopedLock sl (*contextLock);
  204066. needsUpdate = true;
  204067. }
  204068. @end
  204069. BEGIN_JUCE_NAMESPACE
  204070. class WindowedGLContext : public OpenGLContext
  204071. {
  204072. public:
  204073. WindowedGLContext (Component* const component,
  204074. const OpenGLPixelFormat& pixelFormat_,
  204075. NSOpenGLContext* sharedContext)
  204076. : renderContext (0),
  204077. pixelFormat (pixelFormat_)
  204078. {
  204079. jassert (component != 0);
  204080. NSOpenGLPixelFormatAttribute attribs [64];
  204081. int n = 0;
  204082. attribs[n++] = NSOpenGLPFADoubleBuffer;
  204083. attribs[n++] = NSOpenGLPFAAccelerated;
  204084. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  204085. attribs[n++] = NSOpenGLPFAColorSize;
  204086. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  204087. pixelFormat.greenBits,
  204088. pixelFormat.blueBits);
  204089. attribs[n++] = NSOpenGLPFAAlphaSize;
  204090. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  204091. attribs[n++] = NSOpenGLPFADepthSize;
  204092. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  204093. attribs[n++] = NSOpenGLPFAStencilSize;
  204094. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  204095. attribs[n++] = NSOpenGLPFAAccumSize;
  204096. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  204097. pixelFormat.accumulationBufferGreenBits,
  204098. pixelFormat.accumulationBufferBlueBits,
  204099. pixelFormat.accumulationBufferAlphaBits);
  204100. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  204101. attribs[n++] = NSOpenGLPFASampleBuffers;
  204102. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  204103. attribs[n++] = NSOpenGLPFAClosestPolicy;
  204104. attribs[n++] = NSOpenGLPFANoRecovery;
  204105. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  204106. NSOpenGLPixelFormat* format
  204107. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  204108. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204109. pixelFormat: format];
  204110. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  204111. shareContext: sharedContext] autorelease];
  204112. const GLint swapInterval = 1;
  204113. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  204114. [view setOpenGLContext: renderContext];
  204115. [renderContext setView: view];
  204116. [format release];
  204117. viewHolder = new NSViewComponentInternal (view, component);
  204118. }
  204119. ~WindowedGLContext()
  204120. {
  204121. makeInactive();
  204122. [renderContext clearDrawable];
  204123. viewHolder = 0;
  204124. }
  204125. bool makeActive() const throw()
  204126. {
  204127. jassert (renderContext != 0);
  204128. [view makeActive];
  204129. return isActive();
  204130. }
  204131. bool makeInactive() const throw()
  204132. {
  204133. [view makeInactive];
  204134. return true;
  204135. }
  204136. bool isActive() const throw()
  204137. {
  204138. return [NSOpenGLContext currentContext] == renderContext;
  204139. }
  204140. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  204141. void* getRawContext() const throw() { return renderContext; }
  204142. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  204143. {
  204144. }
  204145. void swapBuffers()
  204146. {
  204147. [renderContext flushBuffer];
  204148. }
  204149. bool setSwapInterval (const int numFramesPerSwap)
  204150. {
  204151. [renderContext setValues: (const GLint*) &numFramesPerSwap
  204152. forParameter: NSOpenGLCPSwapInterval];
  204153. return true;
  204154. }
  204155. int getSwapInterval() const
  204156. {
  204157. GLint numFrames = 0;
  204158. [renderContext getValues: &numFrames
  204159. forParameter: NSOpenGLCPSwapInterval];
  204160. return numFrames;
  204161. }
  204162. void repaint()
  204163. {
  204164. // we need to invalidate the juce view that holds this gl view, to make it
  204165. // cause a repaint callback
  204166. NSView* v = (NSView*) viewHolder->view;
  204167. NSRect r = [v frame];
  204168. // bit of a bodge here.. if we only invalidate the area of the gl component,
  204169. // it's completely covered by the NSOpenGLView, so the OS throws away the
  204170. // repaint message, thus never causing our paint() callback, and never repainting
  204171. // the comp. So invalidating just a little bit around the edge helps..
  204172. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  204173. }
  204174. void* getNativeWindowHandle() const { return viewHolder->view; }
  204175. juce_UseDebuggingNewOperator
  204176. NSOpenGLContext* renderContext;
  204177. ThreadSafeNSOpenGLView* view;
  204178. private:
  204179. OpenGLPixelFormat pixelFormat;
  204180. ScopedPointer <NSViewComponentInternal> viewHolder;
  204181. WindowedGLContext (const WindowedGLContext&);
  204182. const WindowedGLContext& operator= (const WindowedGLContext&);
  204183. };
  204184. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204185. const OpenGLPixelFormat& pixelFormat,
  204186. const OpenGLContext* const contextToShareWith)
  204187. {
  204188. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  204189. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  204190. return (c->renderContext != 0) ? c.release() : 0;
  204191. }
  204192. void* OpenGLComponent::getNativeWindowHandle() const
  204193. {
  204194. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  204195. : 0;
  204196. }
  204197. void juce_glViewport (const int w, const int h)
  204198. {
  204199. glViewport (0, 0, w, h);
  204200. }
  204201. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204202. OwnedArray <OpenGLPixelFormat>& results)
  204203. {
  204204. /* GLint attribs [64];
  204205. int n = 0;
  204206. attribs[n++] = AGL_RGBA;
  204207. attribs[n++] = AGL_DOUBLEBUFFER;
  204208. attribs[n++] = AGL_ACCELERATED;
  204209. attribs[n++] = AGL_NO_RECOVERY;
  204210. attribs[n++] = AGL_NONE;
  204211. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  204212. while (p != 0)
  204213. {
  204214. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  204215. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  204216. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  204217. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  204218. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  204219. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  204220. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  204221. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  204222. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  204223. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  204224. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  204225. results.add (pf);
  204226. p = aglNextPixelFormat (p);
  204227. }*/
  204228. //jassertfalse //xxx can't see how you do this in cocoa!
  204229. }
  204230. #else
  204231. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204232. const OpenGLPixelFormat& pixelFormat,
  204233. const OpenGLContext* const contextToShareWith)
  204234. {
  204235. return 0;
  204236. }
  204237. void juce_glViewport (const int w, const int h)
  204238. {
  204239. //glViewport (0, 0, w, h);
  204240. }
  204241. #endif
  204242. #endif
  204243. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  204244. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  204245. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204246. // compiled on its own).
  204247. #if JUCE_INCLUDED_FILE
  204248. #if JUCE_MAC
  204249. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  204250. {
  204251. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204252. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204253. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204254. [im release];
  204255. return (void*) c;
  204256. }
  204257. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  204258. {
  204259. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  204260. jassert (im != 0);
  204261. if (im == 0)
  204262. return 0;
  204263. return juce_createMouseCursorFromImage (*im,
  204264. (int) (hx * im->getWidth()),
  204265. (int) (hy * im->getHeight()));
  204266. }
  204267. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204268. {
  204269. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204270. MemoryBlock mb;
  204271. if (f.getChildFile (filename).loadFileAsData (mb))
  204272. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  204273. return 0;
  204274. }
  204275. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  204276. {
  204277. const ScopedAutoReleasePool pool;
  204278. NSCursor* c = 0;
  204279. switch (type)
  204280. {
  204281. case MouseCursor::NormalCursor:
  204282. c = [NSCursor arrowCursor];
  204283. break;
  204284. case MouseCursor::NoCursor:
  204285. {
  204286. Image blank (Image::ARGB, 8, 8, true);
  204287. return juce_createMouseCursorFromImage (blank, 0, 0);
  204288. }
  204289. case MouseCursor::DraggingHandCursor:
  204290. c = [NSCursor openHandCursor];
  204291. break;
  204292. case MouseCursor::CopyingCursor:
  204293. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204294. case MouseCursor::WaitCursor:
  204295. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204296. break;
  204297. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204298. case MouseCursor::IBeamCursor:
  204299. c = [NSCursor IBeamCursor];
  204300. break;
  204301. case MouseCursor::PointingHandCursor:
  204302. c = [NSCursor pointingHandCursor];
  204303. break;
  204304. case MouseCursor::LeftRightResizeCursor:
  204305. c = [NSCursor resizeLeftRightCursor];
  204306. break;
  204307. case MouseCursor::LeftEdgeResizeCursor:
  204308. c = [NSCursor resizeLeftCursor];
  204309. break;
  204310. case MouseCursor::RightEdgeResizeCursor:
  204311. c = [NSCursor resizeRightCursor];
  204312. break;
  204313. case MouseCursor::UpDownResizeCursor:
  204314. case MouseCursor::TopEdgeResizeCursor:
  204315. case MouseCursor::BottomEdgeResizeCursor:
  204316. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204317. case MouseCursor::TopLeftCornerResizeCursor:
  204318. case MouseCursor::BottomRightCornerResizeCursor:
  204319. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204320. case MouseCursor::TopRightCornerResizeCursor:
  204321. case MouseCursor::BottomLeftCornerResizeCursor:
  204322. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204323. case MouseCursor::UpDownLeftRightResizeCursor:
  204324. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204325. case MouseCursor::CrosshairCursor:
  204326. c = [NSCursor crosshairCursor];
  204327. break;
  204328. }
  204329. [c retain];
  204330. return (void*) c;
  204331. }
  204332. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204333. {
  204334. NSCursor* c = (NSCursor*) cursorHandle;
  204335. [c release];
  204336. }
  204337. void MouseCursor::showInAllWindows() const throw()
  204338. {
  204339. showInWindow (0);
  204340. }
  204341. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204342. {
  204343. NSCursor* const c = (NSCursor*) getHandle();
  204344. [c set];
  204345. }
  204346. #else
  204347. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204348. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204349. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204350. void MouseCursor::showInAllWindows() const throw() {}
  204351. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204352. #endif
  204353. #endif
  204354. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204355. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204356. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204357. // compiled on its own).
  204358. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204359. #if JUCE_MAC
  204360. END_JUCE_NAMESPACE
  204361. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204362. @interface DownloadClickDetector : NSObject
  204363. {
  204364. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204365. }
  204366. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204367. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204368. request: (NSURLRequest*) request
  204369. frame: (WebFrame*) frame
  204370. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204371. @end
  204372. @implementation DownloadClickDetector
  204373. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204374. {
  204375. [super init];
  204376. ownerComponent = ownerComponent_;
  204377. return self;
  204378. }
  204379. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204380. request: (NSURLRequest*) request
  204381. frame: (WebFrame*) frame
  204382. decisionListener: (id <WebPolicyDecisionListener>) listener
  204383. {
  204384. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204385. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204386. [listener use];
  204387. else
  204388. [listener ignore];
  204389. }
  204390. @end
  204391. BEGIN_JUCE_NAMESPACE
  204392. class WebBrowserComponentInternal : public NSViewComponent
  204393. {
  204394. public:
  204395. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204396. {
  204397. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204398. frameName: @""
  204399. groupName: @""];
  204400. setView (webView);
  204401. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204402. [webView setPolicyDelegate: clickListener];
  204403. }
  204404. ~WebBrowserComponentInternal()
  204405. {
  204406. [webView setPolicyDelegate: nil];
  204407. [clickListener release];
  204408. setView (0);
  204409. }
  204410. void goToURL (const String& url,
  204411. const StringArray* headers,
  204412. const MemoryBlock* postData)
  204413. {
  204414. NSMutableURLRequest* r
  204415. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204416. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204417. timeoutInterval: 30.0];
  204418. if (postData != 0 && postData->getSize() > 0)
  204419. {
  204420. [r setHTTPMethod: @"POST"];
  204421. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204422. length: postData->getSize()]];
  204423. }
  204424. if (headers != 0)
  204425. {
  204426. for (int i = 0; i < headers->size(); ++i)
  204427. {
  204428. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  204429. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  204430. [r setValue: juceStringToNS (headerValue)
  204431. forHTTPHeaderField: juceStringToNS (headerName)];
  204432. }
  204433. }
  204434. stop();
  204435. [[webView mainFrame] loadRequest: r];
  204436. }
  204437. void goBack()
  204438. {
  204439. [webView goBack];
  204440. }
  204441. void goForward()
  204442. {
  204443. [webView goForward];
  204444. }
  204445. void stop()
  204446. {
  204447. [webView stopLoading: nil];
  204448. }
  204449. void refresh()
  204450. {
  204451. [webView reload: nil];
  204452. }
  204453. private:
  204454. WebView* webView;
  204455. DownloadClickDetector* clickListener;
  204456. };
  204457. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204458. : browser (0),
  204459. blankPageShown (false),
  204460. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204461. {
  204462. setOpaque (true);
  204463. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204464. }
  204465. WebBrowserComponent::~WebBrowserComponent()
  204466. {
  204467. deleteAndZero (browser);
  204468. }
  204469. void WebBrowserComponent::goToURL (const String& url,
  204470. const StringArray* headers,
  204471. const MemoryBlock* postData)
  204472. {
  204473. lastURL = url;
  204474. lastHeaders.clear();
  204475. if (headers != 0)
  204476. lastHeaders = *headers;
  204477. lastPostData.setSize (0);
  204478. if (postData != 0)
  204479. lastPostData = *postData;
  204480. blankPageShown = false;
  204481. browser->goToURL (url, headers, postData);
  204482. }
  204483. void WebBrowserComponent::stop()
  204484. {
  204485. browser->stop();
  204486. }
  204487. void WebBrowserComponent::goBack()
  204488. {
  204489. lastURL = String::empty;
  204490. blankPageShown = false;
  204491. browser->goBack();
  204492. }
  204493. void WebBrowserComponent::goForward()
  204494. {
  204495. lastURL = String::empty;
  204496. browser->goForward();
  204497. }
  204498. void WebBrowserComponent::refresh()
  204499. {
  204500. browser->refresh();
  204501. }
  204502. void WebBrowserComponent::paint (Graphics& g)
  204503. {
  204504. }
  204505. void WebBrowserComponent::checkWindowAssociation()
  204506. {
  204507. if (isShowing())
  204508. {
  204509. if (blankPageShown)
  204510. goBack();
  204511. }
  204512. else
  204513. {
  204514. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204515. {
  204516. // when the component becomes invisible, some stuff like flash
  204517. // carries on playing audio, so we need to force it onto a blank
  204518. // page to avoid this, (and send it back when it's made visible again).
  204519. blankPageShown = true;
  204520. browser->goToURL ("about:blank", 0, 0);
  204521. }
  204522. }
  204523. }
  204524. void WebBrowserComponent::reloadLastURL()
  204525. {
  204526. if (lastURL.isNotEmpty())
  204527. {
  204528. goToURL (lastURL, &lastHeaders, &lastPostData);
  204529. lastURL = String::empty;
  204530. }
  204531. }
  204532. void WebBrowserComponent::parentHierarchyChanged()
  204533. {
  204534. checkWindowAssociation();
  204535. }
  204536. void WebBrowserComponent::resized()
  204537. {
  204538. browser->setSize (getWidth(), getHeight());
  204539. }
  204540. void WebBrowserComponent::visibilityChanged()
  204541. {
  204542. checkWindowAssociation();
  204543. }
  204544. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204545. {
  204546. return true;
  204547. }
  204548. #else
  204549. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204550. {
  204551. }
  204552. WebBrowserComponent::~WebBrowserComponent()
  204553. {
  204554. }
  204555. void WebBrowserComponent::goToURL (const String& url,
  204556. const StringArray* headers,
  204557. const MemoryBlock* postData)
  204558. {
  204559. }
  204560. void WebBrowserComponent::stop()
  204561. {
  204562. }
  204563. void WebBrowserComponent::goBack()
  204564. {
  204565. }
  204566. void WebBrowserComponent::goForward()
  204567. {
  204568. }
  204569. void WebBrowserComponent::refresh()
  204570. {
  204571. }
  204572. void WebBrowserComponent::paint (Graphics& g)
  204573. {
  204574. }
  204575. void WebBrowserComponent::checkWindowAssociation()
  204576. {
  204577. }
  204578. void WebBrowserComponent::reloadLastURL()
  204579. {
  204580. }
  204581. void WebBrowserComponent::parentHierarchyChanged()
  204582. {
  204583. }
  204584. void WebBrowserComponent::resized()
  204585. {
  204586. }
  204587. void WebBrowserComponent::visibilityChanged()
  204588. {
  204589. }
  204590. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204591. {
  204592. return true;
  204593. }
  204594. #endif
  204595. #endif
  204596. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204597. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204598. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204599. // compiled on its own).
  204600. #if JUCE_INCLUDED_FILE
  204601. class IPhoneAudioIODevice : public AudioIODevice
  204602. {
  204603. public:
  204604. IPhoneAudioIODevice (const String& deviceName)
  204605. : AudioIODevice (deviceName, T("Audio")),
  204606. audioUnit (0),
  204607. isRunning (false),
  204608. callback (0),
  204609. actualBufferSize (0),
  204610. floatData (1, 2)
  204611. {
  204612. numInputChannels = 2;
  204613. numOutputChannels = 2;
  204614. preferredBufferSize = 0;
  204615. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204616. updateDeviceInfo();
  204617. }
  204618. ~IPhoneAudioIODevice()
  204619. {
  204620. close();
  204621. }
  204622. const StringArray getOutputChannelNames()
  204623. {
  204624. StringArray s;
  204625. s.add ("Left");
  204626. s.add ("Right");
  204627. return s;
  204628. }
  204629. const StringArray getInputChannelNames()
  204630. {
  204631. StringArray s;
  204632. if (audioInputIsAvailable)
  204633. {
  204634. s.add ("Left");
  204635. s.add ("Right");
  204636. }
  204637. return s;
  204638. }
  204639. int getNumSampleRates()
  204640. {
  204641. return 1;
  204642. }
  204643. double getSampleRate (int index)
  204644. {
  204645. return sampleRate;
  204646. }
  204647. int getNumBufferSizesAvailable()
  204648. {
  204649. return 1;
  204650. }
  204651. int getBufferSizeSamples (int index)
  204652. {
  204653. return getDefaultBufferSize();
  204654. }
  204655. int getDefaultBufferSize()
  204656. {
  204657. return 1024;
  204658. }
  204659. const String open (const BitArray& inputChannels,
  204660. const BitArray& outputChannels,
  204661. double sampleRate,
  204662. int bufferSize)
  204663. {
  204664. close();
  204665. lastError = String::empty;
  204666. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204667. // xxx set up channel mapping
  204668. activeOutputChans = outputChannels;
  204669. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204670. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204671. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204672. activeInputChans = inputChannels;
  204673. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204674. numInputChannels = activeInputChans.countNumberOfSetBits();
  204675. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204676. AudioSessionSetActive (true);
  204677. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204678. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204679. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204680. fixAudioRouteIfSetToReceiver();
  204681. updateDeviceInfo();
  204682. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204683. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204684. actualBufferSize = preferredBufferSize;
  204685. prepareFloatBuffers();
  204686. isRunning = true;
  204687. propertyChanged (0, 0, 0); // creates and starts the AU
  204688. lastError = audioUnit != 0 ? String::empty
  204689. : T("Couldn't open the device");
  204690. return lastError;
  204691. }
  204692. void close()
  204693. {
  204694. if (isRunning)
  204695. {
  204696. isRunning = false;
  204697. AudioSessionSetActive (false);
  204698. if (audioUnit != 0)
  204699. {
  204700. AudioComponentInstanceDispose (audioUnit);
  204701. audioUnit = 0;
  204702. }
  204703. }
  204704. }
  204705. bool isOpen()
  204706. {
  204707. return isRunning;
  204708. }
  204709. int getCurrentBufferSizeSamples()
  204710. {
  204711. return actualBufferSize;
  204712. }
  204713. double getCurrentSampleRate()
  204714. {
  204715. return sampleRate;
  204716. }
  204717. int getCurrentBitDepth()
  204718. {
  204719. return 16;
  204720. }
  204721. const BitArray getActiveOutputChannels() const
  204722. {
  204723. return activeOutputChans;
  204724. }
  204725. const BitArray getActiveInputChannels() const
  204726. {
  204727. return activeInputChans;
  204728. }
  204729. int getOutputLatencyInSamples()
  204730. {
  204731. return 0; //xxx
  204732. }
  204733. int getInputLatencyInSamples()
  204734. {
  204735. return 0; //xxx
  204736. }
  204737. void start (AudioIODeviceCallback* callback_)
  204738. {
  204739. if (isRunning && callback != callback_)
  204740. {
  204741. if (callback_ != 0)
  204742. callback_->audioDeviceAboutToStart (this);
  204743. callbackLock.enter();
  204744. callback = callback_;
  204745. callbackLock.exit();
  204746. }
  204747. }
  204748. void stop()
  204749. {
  204750. if (isRunning)
  204751. {
  204752. callbackLock.enter();
  204753. AudioIODeviceCallback* const lastCallback = callback;
  204754. callback = 0;
  204755. callbackLock.exit();
  204756. if (lastCallback != 0)
  204757. lastCallback->audioDeviceStopped();
  204758. }
  204759. }
  204760. bool isPlaying()
  204761. {
  204762. return isRunning && callback != 0;
  204763. }
  204764. const String getLastError()
  204765. {
  204766. return lastError;
  204767. }
  204768. private:
  204769. CriticalSection callbackLock;
  204770. Float64 sampleRate;
  204771. int numInputChannels, numOutputChannels;
  204772. int preferredBufferSize;
  204773. int actualBufferSize;
  204774. bool isRunning;
  204775. String lastError;
  204776. AudioStreamBasicDescription format;
  204777. AudioUnit audioUnit;
  204778. UInt32 audioInputIsAvailable;
  204779. AudioIODeviceCallback* callback;
  204780. BitArray activeOutputChans, activeInputChans;
  204781. AudioSampleBuffer floatData;
  204782. float* inputChannels[3];
  204783. float* outputChannels[3];
  204784. bool monoInputChannelNumber, monoOutputChannelNumber;
  204785. void prepareFloatBuffers()
  204786. {
  204787. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204788. zerostruct (inputChannels);
  204789. zerostruct (outputChannels);
  204790. for (int i = 0; i < numInputChannels; ++i)
  204791. inputChannels[i] = floatData.getSampleData (i);
  204792. for (int i = 0; i < numOutputChannels; ++i)
  204793. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204794. }
  204795. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204796. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204797. {
  204798. OSStatus err = noErr;
  204799. if (audioInputIsAvailable)
  204800. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204801. const ScopedLock sl (callbackLock);
  204802. if (callback != 0)
  204803. {
  204804. if (audioInputIsAvailable && numInputChannels > 0)
  204805. {
  204806. short* shortData = (short*) ioData->mBuffers[0].mData;
  204807. if (numInputChannels >= 2)
  204808. {
  204809. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204810. {
  204811. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204812. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204813. }
  204814. }
  204815. else
  204816. {
  204817. if (monoInputChannelNumber > 0)
  204818. ++shortData;
  204819. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204820. {
  204821. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204822. ++shortData;
  204823. }
  204824. }
  204825. }
  204826. else
  204827. {
  204828. for (int i = numInputChannels; --i >= 0;)
  204829. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204830. }
  204831. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204832. outputChannels, numOutputChannels,
  204833. (int) inNumberFrames);
  204834. short* shortData = (short*) ioData->mBuffers[0].mData;
  204835. int n = 0;
  204836. if (numOutputChannels >= 2)
  204837. {
  204838. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204839. {
  204840. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204841. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204842. }
  204843. }
  204844. else if (numOutputChannels == 1)
  204845. {
  204846. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204847. {
  204848. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204849. shortData [n++] = s;
  204850. shortData [n++] = s;
  204851. }
  204852. }
  204853. else
  204854. {
  204855. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204856. }
  204857. }
  204858. else
  204859. {
  204860. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204861. }
  204862. return err;
  204863. }
  204864. void updateDeviceInfo()
  204865. {
  204866. UInt32 size = sizeof (sampleRate);
  204867. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204868. size = sizeof (audioInputIsAvailable);
  204869. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204870. }
  204871. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204872. {
  204873. if (! isRunning)
  204874. return;
  204875. if (inPropertyValue != 0)
  204876. {
  204877. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204878. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204879. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204880. SInt32 routeChangeReason;
  204881. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204882. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204883. fixAudioRouteIfSetToReceiver();
  204884. }
  204885. updateDeviceInfo();
  204886. createAudioUnit();
  204887. AudioSessionSetActive (true);
  204888. if (audioUnit != 0)
  204889. {
  204890. UInt32 formatSize = sizeof (format);
  204891. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204892. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204893. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204894. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204895. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204896. AudioOutputUnitStart (audioUnit);
  204897. }
  204898. }
  204899. void interruptionListener (UInt32 inInterruption)
  204900. {
  204901. if (inInterruption == kAudioSessionEndInterruption)
  204902. {
  204903. isRunning = true;
  204904. AudioSessionSetActive (true);
  204905. AudioOutputUnitStart (audioUnit);
  204906. }
  204907. }
  204908. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204909. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204910. {
  204911. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204912. }
  204913. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204914. {
  204915. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204916. }
  204917. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204918. {
  204919. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204920. }
  204921. void resetFormat (const int numChannels)
  204922. {
  204923. memset (&format, 0, sizeof (format));
  204924. format.mFormatID = kAudioFormatLinearPCM;
  204925. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204926. format.mBitsPerChannel = 8 * sizeof (short);
  204927. format.mChannelsPerFrame = 2;
  204928. format.mFramesPerPacket = 1;
  204929. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204930. }
  204931. bool createAudioUnit()
  204932. {
  204933. if (audioUnit != 0)
  204934. {
  204935. AudioComponentInstanceDispose (audioUnit);
  204936. audioUnit = 0;
  204937. }
  204938. resetFormat (2);
  204939. AudioComponentDescription desc;
  204940. desc.componentType = kAudioUnitType_Output;
  204941. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204942. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204943. desc.componentFlags = 0;
  204944. desc.componentFlagsMask = 0;
  204945. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204946. AudioComponentInstanceNew (comp, &audioUnit);
  204947. if (audioUnit == 0)
  204948. return false;
  204949. const UInt32 one = 1;
  204950. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204951. AudioChannelLayout layout;
  204952. layout.mChannelBitmap = 0;
  204953. layout.mNumberChannelDescriptions = 0;
  204954. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204955. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204956. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204957. AURenderCallbackStruct inputProc;
  204958. inputProc.inputProc = processStatic;
  204959. inputProc.inputProcRefCon = this;
  204960. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204961. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204962. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204963. AudioUnitInitialize (audioUnit);
  204964. return true;
  204965. }
  204966. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204967. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204968. static void fixAudioRouteIfSetToReceiver()
  204969. {
  204970. CFStringRef audioRoute = 0;
  204971. UInt32 propertySize = sizeof (audioRoute);
  204972. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204973. {
  204974. NSString* route = (NSString*) audioRoute;
  204975. //DBG ("audio route: " + nsStringToJuce (route));
  204976. if ([route hasPrefix: @"Receiver"])
  204977. {
  204978. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204979. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204980. }
  204981. CFRelease (audioRoute);
  204982. }
  204983. }
  204984. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204985. const IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204986. };
  204987. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204988. {
  204989. public:
  204990. IPhoneAudioIODeviceType()
  204991. : AudioIODeviceType (T("iPhone Audio"))
  204992. {
  204993. }
  204994. ~IPhoneAudioIODeviceType()
  204995. {
  204996. }
  204997. void scanForDevices()
  204998. {
  204999. }
  205000. const StringArray getDeviceNames (const bool wantInputNames) const
  205001. {
  205002. StringArray s;
  205003. s.add ("iPhone Audio");
  205004. return s;
  205005. }
  205006. int getDefaultDeviceIndex (const bool forInput) const
  205007. {
  205008. return 0;
  205009. }
  205010. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  205011. {
  205012. return device != 0 ? 0 : -1;
  205013. }
  205014. bool hasSeparateInputsAndOutputs() const { return false; }
  205015. AudioIODevice* createDevice (const String& outputDeviceName,
  205016. const String& inputDeviceName)
  205017. {
  205018. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  205019. {
  205020. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  205021. : inputDeviceName);
  205022. }
  205023. return 0;
  205024. }
  205025. juce_UseDebuggingNewOperator
  205026. private:
  205027. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  205028. const IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  205029. };
  205030. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  205031. {
  205032. return new IPhoneAudioIODeviceType();
  205033. }
  205034. #endif
  205035. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  205036. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  205037. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205038. // compiled on its own).
  205039. #if JUCE_INCLUDED_FILE
  205040. #if JUCE_MAC
  205041. #undef log
  205042. #define log(a) Logger::writeToLog(a)
  205043. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  205044. {
  205045. if (err == noErr)
  205046. return true;
  205047. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  205048. jassertfalse
  205049. return false;
  205050. }
  205051. #undef OK
  205052. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  205053. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  205054. {
  205055. String result;
  205056. CFStringRef str = 0;
  205057. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  205058. if (str != 0)
  205059. {
  205060. result = PlatformUtilities::cfStringToJuceString (str);
  205061. CFRelease (str);
  205062. str = 0;
  205063. }
  205064. MIDIEntityRef entity = 0;
  205065. MIDIEndpointGetEntity (endpoint, &entity);
  205066. if (entity == 0)
  205067. return result; // probably virtual
  205068. if (result.isEmpty())
  205069. {
  205070. // endpoint name has zero length - try the entity
  205071. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  205072. if (str != 0)
  205073. {
  205074. result += PlatformUtilities::cfStringToJuceString (str);
  205075. CFRelease (str);
  205076. str = 0;
  205077. }
  205078. }
  205079. // now consider the device's name
  205080. MIDIDeviceRef device = 0;
  205081. MIDIEntityGetDevice (entity, &device);
  205082. if (device == 0)
  205083. return result;
  205084. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  205085. if (str != 0)
  205086. {
  205087. const String s (PlatformUtilities::cfStringToJuceString (str));
  205088. CFRelease (str);
  205089. // if an external device has only one entity, throw away
  205090. // the endpoint name and just use the device name
  205091. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  205092. {
  205093. result = s;
  205094. }
  205095. else if (! result.startsWithIgnoreCase (s))
  205096. {
  205097. // prepend the device name to the entity name
  205098. result = (s + T(" ") + result).trimEnd();
  205099. }
  205100. }
  205101. return result;
  205102. }
  205103. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  205104. {
  205105. String result;
  205106. // Does the endpoint have connections?
  205107. CFDataRef connections = 0;
  205108. int numConnections = 0;
  205109. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  205110. if (connections != 0)
  205111. {
  205112. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  205113. if (numConnections > 0)
  205114. {
  205115. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  205116. for (int i = 0; i < numConnections; ++i, ++pid)
  205117. {
  205118. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  205119. MIDIObjectRef connObject;
  205120. MIDIObjectType connObjectType;
  205121. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  205122. if (err == noErr)
  205123. {
  205124. String s;
  205125. if (connObjectType == kMIDIObjectType_ExternalSource
  205126. || connObjectType == kMIDIObjectType_ExternalDestination)
  205127. {
  205128. // Connected to an external device's endpoint (10.3 and later).
  205129. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  205130. }
  205131. else
  205132. {
  205133. // Connected to an external device (10.2) (or something else, catch-all)
  205134. CFStringRef str = 0;
  205135. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  205136. if (str != 0)
  205137. {
  205138. s = PlatformUtilities::cfStringToJuceString (str);
  205139. CFRelease (str);
  205140. }
  205141. }
  205142. if (s.isNotEmpty())
  205143. {
  205144. if (result.isNotEmpty())
  205145. result += (", ");
  205146. result += s;
  205147. }
  205148. }
  205149. }
  205150. }
  205151. CFRelease (connections);
  205152. }
  205153. if (result.isNotEmpty())
  205154. return result;
  205155. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  205156. return getEndpointName (endpoint, false);
  205157. }
  205158. const StringArray MidiOutput::getDevices()
  205159. {
  205160. StringArray s;
  205161. const ItemCount num = MIDIGetNumberOfDestinations();
  205162. for (ItemCount i = 0; i < num; ++i)
  205163. {
  205164. MIDIEndpointRef dest = MIDIGetDestination (i);
  205165. if (dest != 0)
  205166. {
  205167. String name (getConnectedEndpointName (dest));
  205168. if (name.isEmpty())
  205169. name = "<error>";
  205170. s.add (name);
  205171. }
  205172. else
  205173. {
  205174. s.add ("<error>");
  205175. }
  205176. }
  205177. return s;
  205178. }
  205179. int MidiOutput::getDefaultDeviceIndex()
  205180. {
  205181. return 0;
  205182. }
  205183. static MIDIClientRef globalMidiClient;
  205184. static bool hasGlobalClientBeenCreated = false;
  205185. static bool makeSureClientExists()
  205186. {
  205187. if (! hasGlobalClientBeenCreated)
  205188. {
  205189. String name (T("JUCE"));
  205190. if (JUCEApplication::getInstance() != 0)
  205191. name = JUCEApplication::getInstance()->getApplicationName();
  205192. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  205193. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  205194. CFRelease (appName);
  205195. }
  205196. return hasGlobalClientBeenCreated;
  205197. }
  205198. class MidiPortAndEndpoint
  205199. {
  205200. public:
  205201. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  205202. : port (port_), endPoint (endPoint_)
  205203. {
  205204. }
  205205. ~MidiPortAndEndpoint()
  205206. {
  205207. if (port != 0)
  205208. MIDIPortDispose (port);
  205209. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205210. MIDIEndpointDispose (endPoint);
  205211. }
  205212. MIDIPortRef port;
  205213. MIDIEndpointRef endPoint;
  205214. };
  205215. MidiOutput* MidiOutput::openDevice (int index)
  205216. {
  205217. MidiOutput* mo = 0;
  205218. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205219. {
  205220. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205221. CFStringRef pname;
  205222. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205223. {
  205224. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  205225. if (makeSureClientExists())
  205226. {
  205227. MIDIPortRef port;
  205228. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205229. {
  205230. mo = new MidiOutput();
  205231. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  205232. }
  205233. }
  205234. CFRelease (pname);
  205235. }
  205236. }
  205237. return mo;
  205238. }
  205239. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205240. {
  205241. MidiOutput* mo = 0;
  205242. if (makeSureClientExists())
  205243. {
  205244. MIDIEndpointRef endPoint;
  205245. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205246. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205247. {
  205248. mo = new MidiOutput();
  205249. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  205250. }
  205251. CFRelease (name);
  205252. }
  205253. return mo;
  205254. }
  205255. MidiOutput::~MidiOutput()
  205256. {
  205257. delete (MidiPortAndEndpoint*) internal;
  205258. }
  205259. void MidiOutput::reset()
  205260. {
  205261. }
  205262. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205263. {
  205264. return false;
  205265. }
  205266. void MidiOutput::setVolume (float leftVol, float rightVol)
  205267. {
  205268. }
  205269. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205270. {
  205271. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205272. if (message.isSysEx())
  205273. {
  205274. const int maxPacketSize = 256;
  205275. int pos = 0, bytesLeft = message.getRawDataSize();
  205276. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205277. HeapBlock <MIDIPacketList> packets;
  205278. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205279. packets->numPackets = numPackets;
  205280. MIDIPacket* p = packets->packet;
  205281. for (int i = 0; i < numPackets; ++i)
  205282. {
  205283. p->timeStamp = 0;
  205284. p->length = jmin (maxPacketSize, bytesLeft);
  205285. memcpy (p->data, message.getRawData() + pos, p->length);
  205286. pos += p->length;
  205287. bytesLeft -= p->length;
  205288. p = MIDIPacketNext (p);
  205289. }
  205290. if (mpe->port != 0)
  205291. MIDISend (mpe->port, mpe->endPoint, packets);
  205292. else
  205293. MIDIReceived (mpe->endPoint, packets);
  205294. }
  205295. else
  205296. {
  205297. MIDIPacketList packets;
  205298. packets.numPackets = 1;
  205299. packets.packet[0].timeStamp = 0;
  205300. packets.packet[0].length = message.getRawDataSize();
  205301. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205302. if (mpe->port != 0)
  205303. MIDISend (mpe->port, mpe->endPoint, &packets);
  205304. else
  205305. MIDIReceived (mpe->endPoint, &packets);
  205306. }
  205307. }
  205308. const StringArray MidiInput::getDevices()
  205309. {
  205310. StringArray s;
  205311. const ItemCount num = MIDIGetNumberOfSources();
  205312. for (ItemCount i = 0; i < num; ++i)
  205313. {
  205314. MIDIEndpointRef source = MIDIGetSource (i);
  205315. if (source != 0)
  205316. {
  205317. String name (getConnectedEndpointName (source));
  205318. if (name.isEmpty())
  205319. name = "<error>";
  205320. s.add (name);
  205321. }
  205322. else
  205323. {
  205324. s.add ("<error>");
  205325. }
  205326. }
  205327. return s;
  205328. }
  205329. int MidiInput::getDefaultDeviceIndex()
  205330. {
  205331. return 0;
  205332. }
  205333. struct MidiPortAndCallback
  205334. {
  205335. MidiInput* input;
  205336. MidiPortAndEndpoint* portAndEndpoint;
  205337. MidiInputCallback* callback;
  205338. MemoryBlock pendingData;
  205339. int pendingBytes;
  205340. double pendingDataTime;
  205341. bool active;
  205342. };
  205343. static CriticalSection callbackLock;
  205344. static VoidArray activeCallbacks;
  205345. static void processSysex (MidiPortAndCallback* const mpc, const uint8*& d, int& size, const double time)
  205346. {
  205347. if (*d == 0xf0)
  205348. {
  205349. mpc->pendingBytes = 0;
  205350. mpc->pendingDataTime = time;
  205351. }
  205352. mpc->pendingData.ensureSize (mpc->pendingBytes + size, false);
  205353. uint8* totalMessage = (uint8*) mpc->pendingData.getData();
  205354. uint8* dest = totalMessage + mpc->pendingBytes;
  205355. while (size > 0)
  205356. {
  205357. if (mpc->pendingBytes > 0 && *d >= 0x80)
  205358. {
  205359. if (*d >= 0xfa || *d == 0xf8)
  205360. {
  205361. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (*d, time));
  205362. ++d;
  205363. --size;
  205364. }
  205365. else
  205366. {
  205367. if (*d == 0xf7)
  205368. {
  205369. *dest++ = *d++;
  205370. mpc->pendingBytes++;
  205371. --size;
  205372. }
  205373. break;
  205374. }
  205375. }
  205376. else
  205377. {
  205378. *dest++ = *d++;
  205379. mpc->pendingBytes++;
  205380. --size;
  205381. }
  205382. }
  205383. if (totalMessage [mpc->pendingBytes - 1] == 0xf7)
  205384. {
  205385. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (totalMessage,
  205386. mpc->pendingBytes,
  205387. mpc->pendingDataTime));
  205388. mpc->pendingBytes = 0;
  205389. }
  205390. else
  205391. {
  205392. mpc->callback->handlePartialSysexMessage (mpc->input,
  205393. totalMessage,
  205394. mpc->pendingBytes,
  205395. mpc->pendingDataTime);
  205396. }
  205397. }
  205398. static void midiInputProc (const MIDIPacketList* pktlist,
  205399. void* readProcRefCon,
  205400. void* srcConnRefCon)
  205401. {
  205402. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205403. const double originalTime = time;
  205404. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205405. const ScopedLock sl (callbackLock);
  205406. if (activeCallbacks.contains (mpc) && mpc->active)
  205407. {
  205408. const MIDIPacket* packet = &pktlist->packet[0];
  205409. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205410. {
  205411. const uint8* d = (const uint8*) (packet->data);
  205412. int size = packet->length;
  205413. while (size > 0)
  205414. {
  205415. time = originalTime;
  205416. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205417. {
  205418. processSysex (mpc, d, size, time);
  205419. }
  205420. else
  205421. {
  205422. int used = 0;
  205423. const MidiMessage m (d, size, used, 0, time);
  205424. if (used <= 0)
  205425. {
  205426. jassertfalse // malformed midi message
  205427. break;
  205428. }
  205429. else
  205430. {
  205431. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205432. }
  205433. size -= used;
  205434. d += used;
  205435. }
  205436. }
  205437. packet = MIDIPacketNext (packet);
  205438. }
  205439. }
  205440. }
  205441. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205442. {
  205443. MidiInput* mi = 0;
  205444. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205445. {
  205446. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205447. if (endPoint != 0)
  205448. {
  205449. CFStringRef pname;
  205450. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205451. {
  205452. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  205453. if (makeSureClientExists())
  205454. {
  205455. MIDIPortRef port;
  205456. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205457. mpc->active = false;
  205458. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205459. {
  205460. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205461. {
  205462. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205463. mpc->callback = callback;
  205464. mpc->pendingBytes = 0;
  205465. mpc->pendingData.ensureSize (128);
  205466. mi = new MidiInput (getDevices() [index]);
  205467. mpc->input = mi;
  205468. mi->internal = (void*) mpc;
  205469. const ScopedLock sl (callbackLock);
  205470. activeCallbacks.add (mpc.release());
  205471. }
  205472. else
  205473. {
  205474. OK (MIDIPortDispose (port));
  205475. }
  205476. }
  205477. }
  205478. }
  205479. CFRelease (pname);
  205480. }
  205481. }
  205482. return mi;
  205483. }
  205484. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205485. {
  205486. MidiInput* mi = 0;
  205487. if (makeSureClientExists())
  205488. {
  205489. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205490. mpc->active = false;
  205491. MIDIEndpointRef endPoint;
  205492. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205493. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205494. {
  205495. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205496. mpc->callback = callback;
  205497. mpc->pendingBytes = 0;
  205498. mpc->pendingData.ensureSize (128);
  205499. mi = new MidiInput (deviceName);
  205500. mpc->input = mi;
  205501. mi->internal = (void*) mpc;
  205502. const ScopedLock sl (callbackLock);
  205503. activeCallbacks.add (mpc.release());
  205504. }
  205505. CFRelease (name);
  205506. }
  205507. return mi;
  205508. }
  205509. MidiInput::MidiInput (const String& name_)
  205510. : name (name_)
  205511. {
  205512. }
  205513. MidiInput::~MidiInput()
  205514. {
  205515. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205516. mpc->active = false;
  205517. callbackLock.enter();
  205518. activeCallbacks.removeValue (mpc);
  205519. callbackLock.exit();
  205520. if (mpc->portAndEndpoint->port != 0)
  205521. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205522. delete mpc->portAndEndpoint;
  205523. delete mpc;
  205524. }
  205525. void MidiInput::start()
  205526. {
  205527. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205528. const ScopedLock sl (callbackLock);
  205529. mpc->active = true;
  205530. }
  205531. void MidiInput::stop()
  205532. {
  205533. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205534. const ScopedLock sl (callbackLock);
  205535. mpc->active = false;
  205536. }
  205537. #undef log
  205538. #else
  205539. MidiOutput::~MidiOutput()
  205540. {
  205541. }
  205542. void MidiOutput::reset()
  205543. {
  205544. }
  205545. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205546. {
  205547. return false;
  205548. }
  205549. void MidiOutput::setVolume (float leftVol, float rightVol)
  205550. {
  205551. }
  205552. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205553. {
  205554. }
  205555. const StringArray MidiOutput::getDevices()
  205556. {
  205557. return StringArray();
  205558. }
  205559. MidiOutput* MidiOutput::openDevice (int index)
  205560. {
  205561. return 0;
  205562. }
  205563. const StringArray MidiInput::getDevices()
  205564. {
  205565. return StringArray();
  205566. }
  205567. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205568. {
  205569. return 0;
  205570. }
  205571. #endif
  205572. #endif
  205573. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205574. #else
  205575. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205576. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205577. // compiled on its own).
  205578. #if JUCE_INCLUDED_FILE
  205579. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205580. #define SUPPORT_10_4_FONTS 1
  205581. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205582. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205583. #define SUPPORT_ONLY_10_4_FONTS 1
  205584. #endif
  205585. END_JUCE_NAMESPACE
  205586. @interface NSFont (PrivateHack)
  205587. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205588. @end
  205589. BEGIN_JUCE_NAMESPACE
  205590. #endif
  205591. class MacTypeface : public Typeface
  205592. {
  205593. public:
  205594. MacTypeface (const Font& font)
  205595. : Typeface (font.getTypefaceName())
  205596. {
  205597. const ScopedAutoReleasePool pool;
  205598. renderingTransform = CGAffineTransformIdentity;
  205599. bool needsItalicTransform = false;
  205600. #if JUCE_IPHONE
  205601. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205602. if (font.isItalic() || font.isBold())
  205603. {
  205604. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205605. for (NSString* i in familyFonts)
  205606. {
  205607. const String fn (nsStringToJuce (i));
  205608. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  205609. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  205610. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  205611. || afterDash.containsIgnoreCase (T("italic"))
  205612. || fn.endsWithIgnoreCase (T("oblique"))
  205613. || fn.endsWithIgnoreCase (T("italic"));
  205614. if (probablyBold == font.isBold()
  205615. && probablyItalic == font.isItalic())
  205616. {
  205617. fontName = i;
  205618. needsItalicTransform = false;
  205619. break;
  205620. }
  205621. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205622. {
  205623. fontName = i;
  205624. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205625. }
  205626. }
  205627. if (needsItalicTransform)
  205628. renderingTransform.c = 0.15f;
  205629. }
  205630. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205631. const int ascender = abs (CGFontGetAscent (fontRef));
  205632. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205633. ascent = ascender / totalHeight;
  205634. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205635. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205636. #else
  205637. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205638. if (font.isItalic())
  205639. {
  205640. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205641. toHaveTrait: NSItalicFontMask];
  205642. if (newFont == nsFont)
  205643. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205644. nsFont = newFont;
  205645. }
  205646. if (font.isBold())
  205647. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205648. [nsFont retain];
  205649. ascent = fabsf ((float) [nsFont ascender]);
  205650. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205651. ascent /= totalSize;
  205652. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205653. if (needsItalicTransform)
  205654. {
  205655. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205656. renderingTransform.c = 0.15f;
  205657. }
  205658. #if SUPPORT_ONLY_10_4_FONTS
  205659. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205660. if (atsFont == 0)
  205661. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205662. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205663. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205664. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205665. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205666. #else
  205667. #if SUPPORT_10_4_FONTS
  205668. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205669. {
  205670. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205671. if (atsFont == 0)
  205672. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205673. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205674. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205675. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205676. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205677. }
  205678. else
  205679. #endif
  205680. {
  205681. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205682. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205683. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205684. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205685. }
  205686. #endif
  205687. #endif
  205688. }
  205689. ~MacTypeface()
  205690. {
  205691. #if ! JUCE_IPHONE
  205692. [nsFont release];
  205693. #endif
  205694. if (fontRef != 0)
  205695. CGFontRelease (fontRef);
  205696. }
  205697. float getAscent() const
  205698. {
  205699. return ascent;
  205700. }
  205701. float getDescent() const
  205702. {
  205703. return 1.0f - ascent;
  205704. }
  205705. float getStringWidth (const String& text)
  205706. {
  205707. if (fontRef == 0 || text.isEmpty())
  205708. return 0;
  205709. const int length = text.length();
  205710. HeapBlock <CGGlyph> glyphs;
  205711. createGlyphsForString (text, length, glyphs);
  205712. float x = 0;
  205713. #if SUPPORT_ONLY_10_4_FONTS
  205714. HeapBlock <NSSize> advances (length);
  205715. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205716. for (int i = 0; i < length; ++i)
  205717. x += advances[i].width;
  205718. #else
  205719. #if SUPPORT_10_4_FONTS
  205720. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205721. {
  205722. HeapBlock <NSSize> advances (length);
  205723. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205724. for (int i = 0; i < length; ++i)
  205725. x += advances[i].width;
  205726. }
  205727. else
  205728. #endif
  205729. {
  205730. HeapBlock <int> advances (length);
  205731. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205732. for (int i = 0; i < length; ++i)
  205733. x += advances[i];
  205734. }
  205735. #endif
  205736. return x * unitsToHeightScaleFactor;
  205737. }
  205738. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205739. {
  205740. xOffsets.add (0);
  205741. if (fontRef == 0 || text.isEmpty())
  205742. return;
  205743. const int length = text.length();
  205744. HeapBlock <CGGlyph> glyphs;
  205745. createGlyphsForString (text, length, glyphs);
  205746. #if SUPPORT_ONLY_10_4_FONTS
  205747. HeapBlock <NSSize> advances (length);
  205748. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205749. int x = 0;
  205750. for (int i = 0; i < length; ++i)
  205751. {
  205752. x += advances[i].width;
  205753. xOffsets.add (x * unitsToHeightScaleFactor);
  205754. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205755. }
  205756. #else
  205757. #if SUPPORT_10_4_FONTS
  205758. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205759. {
  205760. HeapBlock <NSSize> advances (length);
  205761. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205762. float x = 0;
  205763. for (int i = 0; i < length; ++i)
  205764. {
  205765. x += advances[i].width;
  205766. xOffsets.add (x * unitsToHeightScaleFactor);
  205767. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205768. }
  205769. }
  205770. else
  205771. #endif
  205772. {
  205773. HeapBlock <int> advances (length);
  205774. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205775. {
  205776. int x = 0;
  205777. for (int i = 0; i < length; ++i)
  205778. {
  205779. x += advances [i];
  205780. xOffsets.add (x * unitsToHeightScaleFactor);
  205781. resultGlyphs.add (glyphs[i]);
  205782. }
  205783. }
  205784. }
  205785. #endif
  205786. }
  205787. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205788. {
  205789. #if JUCE_IPHONE
  205790. return false;
  205791. #else
  205792. if (nsFont == 0)
  205793. return false;
  205794. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205795. jassert (path.isEmpty());
  205796. const ScopedAutoReleasePool pool;
  205797. NSBezierPath* bez = [NSBezierPath bezierPath];
  205798. [bez moveToPoint: NSMakePoint (0, 0)];
  205799. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205800. inFont: nsFont];
  205801. for (int i = 0; i < [bez elementCount]; ++i)
  205802. {
  205803. NSPoint p[3];
  205804. switch ([bez elementAtIndex: i associatedPoints: p])
  205805. {
  205806. case NSMoveToBezierPathElement:
  205807. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205808. break;
  205809. case NSLineToBezierPathElement:
  205810. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205811. break;
  205812. case NSCurveToBezierPathElement:
  205813. 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);
  205814. break;
  205815. case NSClosePathBezierPathElement:
  205816. path.closeSubPath();
  205817. break;
  205818. default:
  205819. jassertfalse
  205820. break;
  205821. }
  205822. }
  205823. path.applyTransform (pathTransform);
  205824. return true;
  205825. #endif
  205826. }
  205827. juce_UseDebuggingNewOperator
  205828. CGFontRef fontRef;
  205829. float fontHeightToCGSizeFactor;
  205830. CGAffineTransform renderingTransform;
  205831. private:
  205832. float ascent, unitsToHeightScaleFactor;
  205833. #if JUCE_IPHONE
  205834. #else
  205835. NSFont* nsFont;
  205836. AffineTransform pathTransform;
  205837. #endif
  205838. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205839. {
  205840. #if SUPPORT_10_4_FONTS
  205841. #if ! SUPPORT_ONLY_10_4_FONTS
  205842. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205843. #endif
  205844. {
  205845. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205846. NSGlyph* const g = (NSGlyph*) glyphs;
  205847. for (int i = 0; i < length; ++i)
  205848. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205849. return;
  205850. }
  205851. #endif
  205852. #if ! SUPPORT_ONLY_10_4_FONTS
  205853. if (charToGlyphMapper == 0)
  205854. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205855. glyphs.malloc (length);
  205856. for (int i = 0; i < length; ++i)
  205857. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205858. #endif
  205859. }
  205860. #if ! SUPPORT_ONLY_10_4_FONTS
  205861. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205862. class CharToGlyphMapper
  205863. {
  205864. public:
  205865. CharToGlyphMapper (CGFontRef fontRef)
  205866. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205867. idRangeOffset (0), glyphIndexes (0)
  205868. {
  205869. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205870. if (cmapTable != 0)
  205871. {
  205872. const int numSubtables = getValue16 (cmapTable, 2);
  205873. for (int i = 0; i < numSubtables; ++i)
  205874. {
  205875. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205876. {
  205877. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205878. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205879. {
  205880. const int length = getValue16 (cmapTable, offset + 2);
  205881. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205882. segCount = segCountX2 / 2;
  205883. const int endCodeOffset = offset + 14;
  205884. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205885. const int idDeltaOffset = startCodeOffset + segCountX2;
  205886. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205887. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205888. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205889. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205890. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205891. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205892. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205893. }
  205894. break;
  205895. }
  205896. }
  205897. CFRelease (cmapTable);
  205898. }
  205899. }
  205900. ~CharToGlyphMapper()
  205901. {
  205902. if (endCode != 0)
  205903. {
  205904. CFRelease (endCode);
  205905. CFRelease (startCode);
  205906. CFRelease (idDelta);
  205907. CFRelease (idRangeOffset);
  205908. CFRelease (glyphIndexes);
  205909. }
  205910. }
  205911. int getGlyphForCharacter (const juce_wchar c) const
  205912. {
  205913. for (int i = 0; i < segCount; ++i)
  205914. {
  205915. if (getValue16 (endCode, i * 2) >= c)
  205916. {
  205917. const int start = getValue16 (startCode, i * 2);
  205918. if (start > c)
  205919. break;
  205920. const int delta = getValue16 (idDelta, i * 2);
  205921. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205922. if (rangeOffset == 0)
  205923. return delta + c;
  205924. else
  205925. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205926. }
  205927. }
  205928. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205929. return jmax (-1, c - 29);
  205930. }
  205931. private:
  205932. int segCount;
  205933. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205934. static uint16 getValue16 (CFDataRef data, const int index)
  205935. {
  205936. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205937. }
  205938. static uint32 getValue32 (CFDataRef data, const int index)
  205939. {
  205940. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205941. }
  205942. };
  205943. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205944. #endif
  205945. };
  205946. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205947. {
  205948. return new MacTypeface (font);
  205949. }
  205950. const StringArray Font::findAllTypefaceNames() throw()
  205951. {
  205952. StringArray names;
  205953. const ScopedAutoReleasePool pool;
  205954. #if JUCE_IPHONE
  205955. NSArray* fonts = [UIFont familyNames];
  205956. #else
  205957. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205958. #endif
  205959. for (unsigned int i = 0; i < [fonts count]; ++i)
  205960. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205961. names.sort (true);
  205962. return names;
  205963. }
  205964. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  205965. {
  205966. #if JUCE_IPHONE
  205967. defaultSans = "Helvetica";
  205968. defaultSerif = "Times New Roman";
  205969. defaultFixed = "Courier New";
  205970. #else
  205971. defaultSans = "Lucida Grande";
  205972. defaultSerif = "Times New Roman";
  205973. defaultFixed = "Monaco";
  205974. #endif
  205975. }
  205976. #endif
  205977. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205978. // (must go before juce_mac_CoreGraphicsContext.mm)
  205979. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205980. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205981. // compiled on its own).
  205982. #if JUCE_INCLUDED_FILE
  205983. class CoreGraphicsImage : public Image
  205984. {
  205985. public:
  205986. CoreGraphicsImage (const PixelFormat format_,
  205987. const int imageWidth_,
  205988. const int imageHeight_,
  205989. const bool clearImage)
  205990. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205991. {
  205992. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  205993. : CGColorSpaceCreateDeviceRGB();
  205994. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205995. colourSpace, getCGImageFlags (*this));
  205996. CGColorSpaceRelease (colourSpace);
  205997. }
  205998. ~CoreGraphicsImage()
  205999. {
  206000. CGContextRelease (context);
  206001. }
  206002. LowLevelGraphicsContext* createLowLevelContext();
  206003. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  206004. {
  206005. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  206006. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  206007. {
  206008. return CGBitmapContextCreateImage (nativeImage->context);
  206009. }
  206010. else
  206011. {
  206012. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  206013. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  206014. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  206015. 8, srcData.pixelStride * 8, srcData.lineStride,
  206016. colourSpace, getCGImageFlags (juceImage), provider,
  206017. 0, true, kCGRenderingIntentDefault);
  206018. CGDataProviderRelease (provider);
  206019. return imageRef;
  206020. }
  206021. }
  206022. #if JUCE_MAC
  206023. static NSImage* createNSImage (const Image& image)
  206024. {
  206025. const ScopedAutoReleasePool pool;
  206026. NSImage* im = [[NSImage alloc] init];
  206027. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  206028. [im lockFocus];
  206029. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  206030. CGImageRef imageRef = createImage (image, false, colourSpace);
  206031. CGColorSpaceRelease (colourSpace);
  206032. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  206033. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  206034. CGImageRelease (imageRef);
  206035. [im unlockFocus];
  206036. return im;
  206037. }
  206038. #endif
  206039. CGContextRef context;
  206040. private:
  206041. static CGBitmapInfo getCGImageFlags (const Image& image)
  206042. {
  206043. #if JUCE_BIG_ENDIAN
  206044. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  206045. #else
  206046. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  206047. #endif
  206048. }
  206049. };
  206050. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  206051. {
  206052. #if USE_COREGRAPHICS_RENDERING
  206053. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  206054. #else
  206055. return new Image (format, imageWidth, imageHeight, clearImage);
  206056. #endif
  206057. }
  206058. class CoreGraphicsContext : public LowLevelGraphicsContext
  206059. {
  206060. public:
  206061. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  206062. : context (context_),
  206063. flipHeight (flipHeight_),
  206064. numGradientLookupEntries (0)
  206065. {
  206066. CGContextRetain (context);
  206067. CGContextSaveGState(context);
  206068. CGContextSetShouldSmoothFonts (context, true);
  206069. CGContextSetShouldAntialias (context, true);
  206070. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206071. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  206072. greyColourSpace = CGColorSpaceCreateDeviceGray();
  206073. gradientCallbacks.version = 0;
  206074. gradientCallbacks.evaluate = gradientCallback;
  206075. gradientCallbacks.releaseInfo = 0;
  206076. state = new SavedState();
  206077. }
  206078. ~CoreGraphicsContext()
  206079. {
  206080. CGContextRestoreGState (context);
  206081. CGContextRelease (context);
  206082. CGColorSpaceRelease (rgbColourSpace);
  206083. CGColorSpaceRelease (greyColourSpace);
  206084. }
  206085. bool isVectorDevice() const { return false; }
  206086. void setOrigin (int x, int y)
  206087. {
  206088. CGContextTranslateCTM (context, x, -y);
  206089. }
  206090. bool clipToRectangle (const Rectangle<int>& r)
  206091. {
  206092. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  206093. return ! isClipEmpty();
  206094. }
  206095. bool clipToRectangleList (const RectangleList& clipRegion)
  206096. {
  206097. if (clipRegion.isEmpty())
  206098. {
  206099. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  206100. return false;
  206101. }
  206102. else
  206103. {
  206104. const int numRects = clipRegion.getNumRectangles();
  206105. HeapBlock <CGRect> rects (numRects);
  206106. for (int i = 0; i < numRects; ++i)
  206107. {
  206108. const Rectangle<int>& r = clipRegion.getRectangle(i);
  206109. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206110. }
  206111. CGContextClipToRects (context, rects, numRects);
  206112. return ! isClipEmpty();
  206113. }
  206114. }
  206115. void excludeClipRectangle (const Rectangle<int>& r)
  206116. {
  206117. RectangleList remaining (getClipBounds());
  206118. remaining.subtract (r);
  206119. clipToRectangleList (remaining);
  206120. }
  206121. void clipToPath (const Path& path, const AffineTransform& transform)
  206122. {
  206123. createPath (path, transform);
  206124. CGContextClip (context);
  206125. }
  206126. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  206127. {
  206128. if (! transform.isSingularity())
  206129. {
  206130. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  206131. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  206132. flip();
  206133. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  206134. applyTransform (t);
  206135. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  206136. CGContextClipToMask (context, r, image);
  206137. applyTransform (t.inverted());
  206138. flip();
  206139. CGImageRelease (image);
  206140. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  206141. }
  206142. }
  206143. bool clipRegionIntersects (const Rectangle<int>& r)
  206144. {
  206145. return getClipBounds().intersects (r);
  206146. }
  206147. const Rectangle<int> getClipBounds() const
  206148. {
  206149. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206150. return Rectangle<int> (roundToInt (bounds.origin.x),
  206151. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  206152. roundToInt (bounds.size.width),
  206153. roundToInt (bounds.size.height));
  206154. }
  206155. bool isClipEmpty() const
  206156. {
  206157. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  206158. }
  206159. void saveState()
  206160. {
  206161. CGContextSaveGState (context);
  206162. stateStack.add (new SavedState (*state));
  206163. }
  206164. void restoreState()
  206165. {
  206166. CGContextRestoreGState (context);
  206167. SavedState* const top = stateStack.getLast();
  206168. if (top != 0)
  206169. {
  206170. state = top;
  206171. stateStack.removeLast (1, false);
  206172. }
  206173. else
  206174. {
  206175. jassertfalse // trying to pop with an empty stack!
  206176. }
  206177. }
  206178. void setFill (const FillType& fillType)
  206179. {
  206180. state->fillType = fillType;
  206181. if (fillType.isColour())
  206182. {
  206183. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  206184. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  206185. CGContextSetAlpha (context, 1.0f);
  206186. }
  206187. }
  206188. void setOpacity (float newOpacity)
  206189. {
  206190. state->fillType.setOpacity (newOpacity);
  206191. setFill (state->fillType);
  206192. }
  206193. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  206194. {
  206195. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  206196. ? kCGInterpolationLow
  206197. : kCGInterpolationHigh);
  206198. }
  206199. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  206200. {
  206201. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206202. if (replaceExistingContents)
  206203. {
  206204. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  206205. CGContextClearRect (context, cgRect);
  206206. #else
  206207. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206208. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206209. CGContextClearRect (context, cgRect);
  206210. else
  206211. #endif
  206212. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206213. #endif
  206214. fillRect (r, false);
  206215. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206216. }
  206217. else
  206218. {
  206219. if (state->fillType.isColour())
  206220. {
  206221. CGContextFillRect (context, cgRect);
  206222. }
  206223. else if (state->fillType.isGradient())
  206224. {
  206225. CGContextSaveGState (context);
  206226. CGContextClipToRect (context, cgRect);
  206227. drawGradient();
  206228. CGContextRestoreGState (context);
  206229. }
  206230. else
  206231. {
  206232. CGContextSaveGState (context);
  206233. CGContextClipToRect (context, cgRect);
  206234. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206235. CGContextRestoreGState (context);
  206236. }
  206237. }
  206238. }
  206239. void fillPath (const Path& path, const AffineTransform& transform)
  206240. {
  206241. CGContextSaveGState (context);
  206242. if (state->fillType.isColour())
  206243. {
  206244. flip();
  206245. applyTransform (transform);
  206246. createPath (path);
  206247. if (path.isUsingNonZeroWinding())
  206248. CGContextFillPath (context);
  206249. else
  206250. CGContextEOFillPath (context);
  206251. }
  206252. else
  206253. {
  206254. createPath (path, transform);
  206255. if (path.isUsingNonZeroWinding())
  206256. CGContextClip (context);
  206257. else
  206258. CGContextEOClip (context);
  206259. if (state->fillType.isGradient())
  206260. drawGradient();
  206261. else
  206262. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206263. }
  206264. CGContextRestoreGState (context);
  206265. }
  206266. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  206267. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206268. {
  206269. jassert (sourceImage.getBounds().contains (srcClip));
  206270. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206271. CGImageRef image = fullImage;
  206272. if (srcClip != sourceImage.getBounds())
  206273. {
  206274. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206275. srcClip.getWidth(), srcClip.getHeight()));
  206276. CGImageRelease (fullImage);
  206277. }
  206278. CGContextSaveGState (context);
  206279. CGContextSetAlpha (context, state->fillType.getOpacity());
  206280. flip();
  206281. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206282. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206283. if (fillEntireClipAsTiles)
  206284. {
  206285. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  206286. CGContextDrawTiledImage (context, imageRect, image);
  206287. #else
  206288. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206289. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206290. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206291. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206292. CGContextDrawTiledImage (context, imageRect, image);
  206293. else
  206294. #endif
  206295. {
  206296. // Fallback to manually doing a tiled fill on 10.4
  206297. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206298. const int iw = srcClip.getWidth();
  206299. const int ih = srcClip.getHeight();
  206300. int x = 0, y = 0;
  206301. while (x > clip.origin.x) x -= iw;
  206302. while (y > clip.origin.y) y -= ih;
  206303. const int right = (int) (clip.origin.x + clip.size.width);
  206304. const int bottom = (int) (clip.origin.y + clip.size.height);
  206305. while (y < bottom)
  206306. {
  206307. for (int x2 = x; x2 < right; x2 += iw)
  206308. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206309. y += ih;
  206310. }
  206311. }
  206312. #endif
  206313. }
  206314. else
  206315. {
  206316. CGContextDrawImage (context, imageRect, image);
  206317. }
  206318. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206319. CGContextRestoreGState (context);
  206320. }
  206321. void drawLine (double x1, double y1, double x2, double y2)
  206322. {
  206323. CGContextSetLineCap (context, kCGLineCapSquare);
  206324. CGContextSetLineWidth (context, 1.0f);
  206325. CGContextSetRGBStrokeColor (context,
  206326. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206327. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206328. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  206329. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  206330. CGContextStrokeLineSegments (context, line, 1);
  206331. }
  206332. void drawVerticalLine (const int x, double top, double bottom)
  206333. {
  206334. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206335. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206336. #else
  206337. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206338. // the x co-ord slightly to trick it..
  206339. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206340. #endif
  206341. }
  206342. void drawHorizontalLine (const int y, double left, double right)
  206343. {
  206344. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206345. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206346. #else
  206347. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206348. // the x co-ord slightly to trick it..
  206349. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206350. #endif
  206351. }
  206352. void setFont (const Font& newFont)
  206353. {
  206354. if (state->font != newFont)
  206355. {
  206356. state->fontRef = 0;
  206357. state->font = newFont;
  206358. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206359. if (mf != 0)
  206360. {
  206361. state->fontRef = mf->fontRef;
  206362. CGContextSetFont (context, state->fontRef);
  206363. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206364. state->fontTransform = mf->renderingTransform;
  206365. state->fontTransform.a *= state->font.getHorizontalScale();
  206366. CGContextSetTextMatrix (context, state->fontTransform);
  206367. }
  206368. }
  206369. }
  206370. const Font getFont()
  206371. {
  206372. return state->font;
  206373. }
  206374. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206375. {
  206376. if (state->fontRef != 0 && state->fillType.isColour())
  206377. {
  206378. if (transform.isOnlyTranslation())
  206379. {
  206380. CGGlyph g = glyphNumber;
  206381. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206382. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206383. }
  206384. else
  206385. {
  206386. CGContextSaveGState (context);
  206387. flip();
  206388. applyTransform (transform);
  206389. CGAffineTransform t = state->fontTransform;
  206390. t.d = -t.d;
  206391. CGContextSetTextMatrix (context, t);
  206392. CGGlyph g = glyphNumber;
  206393. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206394. CGContextSetTextMatrix (context, state->fontTransform);
  206395. CGContextRestoreGState (context);
  206396. }
  206397. }
  206398. else
  206399. {
  206400. Path p;
  206401. Font& f = state->font;
  206402. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206403. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206404. .followedBy (transform));
  206405. }
  206406. }
  206407. private:
  206408. CGContextRef context;
  206409. const float flipHeight;
  206410. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206411. CGFunctionCallbacks gradientCallbacks;
  206412. struct SavedState
  206413. {
  206414. SavedState()
  206415. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206416. {
  206417. }
  206418. SavedState (const SavedState& other)
  206419. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206420. fontTransform (other.fontTransform)
  206421. {
  206422. }
  206423. ~SavedState()
  206424. {
  206425. }
  206426. FillType fillType;
  206427. Font font;
  206428. CGFontRef fontRef;
  206429. CGAffineTransform fontTransform;
  206430. };
  206431. ScopedPointer <SavedState> state;
  206432. OwnedArray <SavedState> stateStack;
  206433. HeapBlock <PixelARGB> gradientLookupTable;
  206434. int numGradientLookupEntries;
  206435. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206436. {
  206437. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206438. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206439. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206440. colour.unpremultiply();
  206441. outData[0] = colour.getRed() / 255.0f;
  206442. outData[1] = colour.getGreen() / 255.0f;
  206443. outData[2] = colour.getBlue() / 255.0f;
  206444. outData[3] = colour.getAlpha() / 255.0f;
  206445. }
  206446. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206447. {
  206448. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206449. --numGradientLookupEntries;
  206450. CGShadingRef result = 0;
  206451. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  206452. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206453. if (gradient.isRadial)
  206454. {
  206455. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206456. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206457. function, true, true);
  206458. }
  206459. else
  206460. {
  206461. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206462. CGPointMake (gradient.x2, gradient.y2),
  206463. function, true, true);
  206464. }
  206465. CGFunctionRelease (function);
  206466. return result;
  206467. }
  206468. void drawGradient()
  206469. {
  206470. flip();
  206471. applyTransform (state->fillType.transform);
  206472. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206473. // you draw a gradient with high quality interp enabled).
  206474. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206475. CGContextSetAlpha (context, state->fillType.getOpacity());
  206476. CGContextDrawShading (context, shading);
  206477. CGShadingRelease (shading);
  206478. }
  206479. void createPath (const Path& path) const
  206480. {
  206481. CGContextBeginPath (context);
  206482. Path::Iterator i (path);
  206483. while (i.next())
  206484. {
  206485. switch (i.elementType)
  206486. {
  206487. case Path::Iterator::startNewSubPath:
  206488. CGContextMoveToPoint (context, i.x1, i.y1);
  206489. break;
  206490. case Path::Iterator::lineTo:
  206491. CGContextAddLineToPoint (context, i.x1, i.y1);
  206492. break;
  206493. case Path::Iterator::quadraticTo:
  206494. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206495. break;
  206496. case Path::Iterator::cubicTo:
  206497. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206498. break;
  206499. case Path::Iterator::closePath:
  206500. CGContextClosePath (context); break;
  206501. default:
  206502. jassertfalse
  206503. break;
  206504. }
  206505. }
  206506. }
  206507. void createPath (const Path& path, const AffineTransform& transform) const
  206508. {
  206509. CGContextBeginPath (context);
  206510. Path::Iterator i (path);
  206511. while (i.next())
  206512. {
  206513. switch (i.elementType)
  206514. {
  206515. case Path::Iterator::startNewSubPath:
  206516. transform.transformPoint (i.x1, i.y1);
  206517. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206518. break;
  206519. case Path::Iterator::lineTo:
  206520. transform.transformPoint (i.x1, i.y1);
  206521. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206522. break;
  206523. case Path::Iterator::quadraticTo:
  206524. transform.transformPoint (i.x1, i.y1);
  206525. transform.transformPoint (i.x2, i.y2);
  206526. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206527. break;
  206528. case Path::Iterator::cubicTo:
  206529. transform.transformPoint (i.x1, i.y1);
  206530. transform.transformPoint (i.x2, i.y2);
  206531. transform.transformPoint (i.x3, i.y3);
  206532. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206533. break;
  206534. case Path::Iterator::closePath:
  206535. CGContextClosePath (context); break;
  206536. default:
  206537. jassertfalse
  206538. break;
  206539. }
  206540. }
  206541. }
  206542. static Image* createAlphaChannelImage (const Image& im)
  206543. {
  206544. if (im.getFormat() == Image::SingleChannel)
  206545. return const_cast <Image*> (&im);
  206546. return im.createCopyOfAlphaChannel();
  206547. }
  206548. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206549. {
  206550. if (im.getFormat() != Image::SingleChannel)
  206551. delete alphaIm;
  206552. }
  206553. void flip() const
  206554. {
  206555. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206556. }
  206557. void applyTransform (const AffineTransform& transform) const
  206558. {
  206559. CGAffineTransform t;
  206560. t.a = transform.mat00;
  206561. t.b = transform.mat10;
  206562. t.c = transform.mat01;
  206563. t.d = transform.mat11;
  206564. t.tx = transform.mat02;
  206565. t.ty = transform.mat12;
  206566. CGContextConcatCTM (context, t);
  206567. }
  206568. float flipY (float y) const
  206569. {
  206570. return flipHeight - y;
  206571. }
  206572. };
  206573. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206574. {
  206575. return new CoreGraphicsContext (context, imageHeight);
  206576. }
  206577. #endif
  206578. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206579. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206580. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206581. // compiled on its own).
  206582. #if JUCE_INCLUDED_FILE
  206583. class NSViewComponentPeer;
  206584. END_JUCE_NAMESPACE
  206585. #define JuceNSView MakeObjCClassName(JuceNSView)
  206586. @interface JuceNSView : NSView
  206587. {
  206588. @public
  206589. NSViewComponentPeer* owner;
  206590. NSNotificationCenter* notificationCenter;
  206591. }
  206592. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206593. - (void) dealloc;
  206594. - (BOOL) isOpaque;
  206595. - (void) drawRect: (NSRect) r;
  206596. - (void) mouseDown: (NSEvent*) ev;
  206597. - (void) asyncMouseDown: (NSEvent*) ev;
  206598. - (void) mouseUp: (NSEvent*) ev;
  206599. - (void) asyncMouseUp: (NSEvent*) ev;
  206600. - (void) mouseDragged: (NSEvent*) ev;
  206601. - (void) mouseMoved: (NSEvent*) ev;
  206602. - (void) mouseEntered: (NSEvent*) ev;
  206603. - (void) mouseExited: (NSEvent*) ev;
  206604. - (void) rightMouseDown: (NSEvent*) ev;
  206605. - (void) rightMouseDragged: (NSEvent*) ev;
  206606. - (void) rightMouseUp: (NSEvent*) ev;
  206607. - (void) otherMouseDown: (NSEvent*) ev;
  206608. - (void) otherMouseDragged: (NSEvent*) ev;
  206609. - (void) otherMouseUp: (NSEvent*) ev;
  206610. - (void) scrollWheel: (NSEvent*) ev;
  206611. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206612. - (void) frameChanged: (NSNotification*) n;
  206613. - (void) viewDidMoveToWindow;
  206614. - (void) keyDown: (NSEvent*) ev;
  206615. - (void) keyUp: (NSEvent*) ev;
  206616. - (void) flagsChanged: (NSEvent*) ev;
  206617. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206618. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206619. #endif
  206620. - (BOOL) becomeFirstResponder;
  206621. - (BOOL) resignFirstResponder;
  206622. - (BOOL) acceptsFirstResponder;
  206623. - (void) asyncRepaint: (id) rect;
  206624. - (NSArray*) getSupportedDragTypes;
  206625. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206626. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206627. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206628. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206629. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206630. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206631. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206632. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206633. @end
  206634. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206635. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206636. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206637. #else
  206638. @interface JuceNSWindow : NSWindow
  206639. #endif
  206640. {
  206641. @private
  206642. NSViewComponentPeer* owner;
  206643. bool isZooming;
  206644. }
  206645. - (void) setOwner: (NSViewComponentPeer*) owner;
  206646. - (BOOL) canBecomeKeyWindow;
  206647. - (void) becomeKeyWindow;
  206648. - (BOOL) windowShouldClose: (id) window;
  206649. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206650. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206651. - (void) zoom: (id) sender;
  206652. @end
  206653. BEGIN_JUCE_NAMESPACE
  206654. class NSViewComponentPeer : public ComponentPeer
  206655. {
  206656. public:
  206657. NSViewComponentPeer (Component* const component,
  206658. const int windowStyleFlags,
  206659. NSView* viewToAttachTo);
  206660. ~NSViewComponentPeer();
  206661. void* getNativeHandle() const;
  206662. void setVisible (bool shouldBeVisible);
  206663. void setTitle (const String& title);
  206664. void setPosition (int x, int y);
  206665. void setSize (int w, int h);
  206666. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206667. void getBounds (int& x, int& y, int& w, int& h, const bool global) const;
  206668. void getBounds (int& x, int& y, int& w, int& h) const;
  206669. int getScreenX() const;
  206670. int getScreenY() const;
  206671. void relativePositionToGlobal (int& x, int& y);
  206672. void globalPositionToRelative (int& x, int& y);
  206673. void setMinimised (bool shouldBeMinimised);
  206674. bool isMinimised() const;
  206675. void setFullScreen (bool shouldBeFullScreen);
  206676. bool isFullScreen() const;
  206677. bool contains (int x, int y, bool trueIfInAChildWindow) const;
  206678. const BorderSize getFrameSize() const;
  206679. bool setAlwaysOnTop (bool alwaysOnTop);
  206680. void toFront (bool makeActiveWindow);
  206681. void toBehind (ComponentPeer* other);
  206682. void setIcon (const Image& newIcon);
  206683. const StringArray getAvailableRenderingEngines() throw();
  206684. int getCurrentRenderingEngine() throw();
  206685. void setCurrentRenderingEngine (int index) throw();
  206686. virtual void redirectMouseDown (NSEvent* ev);
  206687. virtual void redirectMouseUp (NSEvent* ev);
  206688. virtual void redirectMouseDrag (NSEvent* ev);
  206689. virtual void redirectMouseMove (NSEvent* ev);
  206690. virtual void redirectMouseEnter (NSEvent* ev);
  206691. virtual void redirectMouseExit (NSEvent* ev);
  206692. virtual void redirectMouseWheel (NSEvent* ev);
  206693. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206694. virtual bool redirectKeyDown (NSEvent* ev);
  206695. virtual bool redirectKeyUp (NSEvent* ev);
  206696. virtual void redirectModKeyChange (NSEvent* ev);
  206697. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206698. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206699. #endif
  206700. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206701. virtual bool isOpaque();
  206702. virtual void drawRect (NSRect r);
  206703. virtual bool canBecomeKeyWindow();
  206704. virtual bool windowShouldClose();
  206705. virtual void redirectMovedOrResized();
  206706. virtual void viewMovedToWindow();
  206707. virtual NSRect constrainRect (NSRect r);
  206708. static void showArrowCursorIfNeeded();
  206709. virtual void viewFocusGain();
  206710. virtual void viewFocusLoss();
  206711. bool isFocused() const;
  206712. void grabFocus();
  206713. void textInputRequired (int x, int y);
  206714. void repaint (int x, int y, int w, int h);
  206715. void performAnyPendingRepaintsNow();
  206716. juce_UseDebuggingNewOperator
  206717. NSWindow* window;
  206718. JuceNSView* view;
  206719. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206720. };
  206721. END_JUCE_NAMESPACE
  206722. @implementation JuceNSView
  206723. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206724. withFrame: (NSRect) frame
  206725. {
  206726. [super initWithFrame: frame];
  206727. owner = owner_;
  206728. notificationCenter = [NSNotificationCenter defaultCenter];
  206729. [notificationCenter addObserver: self
  206730. selector: @selector (frameChanged:)
  206731. name: NSViewFrameDidChangeNotification
  206732. object: self];
  206733. if (! owner_->isSharedWindow)
  206734. {
  206735. [notificationCenter addObserver: self
  206736. selector: @selector (frameChanged:)
  206737. name: NSWindowDidMoveNotification
  206738. object: owner_->window];
  206739. }
  206740. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206741. return self;
  206742. }
  206743. - (void) dealloc
  206744. {
  206745. [notificationCenter removeObserver: self];
  206746. [super dealloc];
  206747. }
  206748. - (void) drawRect: (NSRect) r
  206749. {
  206750. if (owner != 0)
  206751. owner->drawRect (r);
  206752. }
  206753. - (BOOL) isOpaque
  206754. {
  206755. return owner == 0 || owner->isOpaque();
  206756. }
  206757. - (void) mouseDown: (NSEvent*) ev
  206758. {
  206759. // In some host situations, the host will stop modal loops from working
  206760. // correctly if they're called from a mouse event, so we'll trigger
  206761. // the event asynchronously..
  206762. if (JUCEApplication::getInstance() == 0)
  206763. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206764. withObject: ev
  206765. waitUntilDone: NO];
  206766. else
  206767. [self asyncMouseDown: ev];
  206768. }
  206769. - (void) asyncMouseDown: (NSEvent*) ev
  206770. {
  206771. if (owner != 0)
  206772. owner->redirectMouseDown (ev);
  206773. }
  206774. - (void) mouseUp: (NSEvent*) ev
  206775. {
  206776. // In some host situations, the host will stop modal loops from working
  206777. // correctly if they're called from a mouse event, so we'll trigger
  206778. // the event asynchronously..
  206779. if (JUCEApplication::getInstance() == 0)
  206780. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206781. withObject: ev
  206782. waitUntilDone: NO];
  206783. else
  206784. [self asyncMouseUp: ev];
  206785. }
  206786. - (void) asyncMouseUp: (NSEvent*) ev
  206787. {
  206788. if (owner != 0)
  206789. owner->redirectMouseUp (ev);
  206790. }
  206791. - (void) mouseDragged: (NSEvent*) ev
  206792. {
  206793. if (owner != 0)
  206794. owner->redirectMouseDrag (ev);
  206795. }
  206796. - (void) mouseMoved: (NSEvent*) ev
  206797. {
  206798. if (owner != 0)
  206799. owner->redirectMouseMove (ev);
  206800. }
  206801. - (void) mouseEntered: (NSEvent*) ev
  206802. {
  206803. if (owner != 0)
  206804. owner->redirectMouseEnter (ev);
  206805. }
  206806. - (void) mouseExited: (NSEvent*) ev
  206807. {
  206808. if (owner != 0)
  206809. owner->redirectMouseExit (ev);
  206810. }
  206811. - (void) rightMouseDown: (NSEvent*) ev
  206812. {
  206813. [self mouseDown: ev];
  206814. }
  206815. - (void) rightMouseDragged: (NSEvent*) ev
  206816. {
  206817. [self mouseDragged: ev];
  206818. }
  206819. - (void) rightMouseUp: (NSEvent*) ev
  206820. {
  206821. [self mouseUp: ev];
  206822. }
  206823. - (void) otherMouseDown: (NSEvent*) ev
  206824. {
  206825. [self mouseDown: ev];
  206826. }
  206827. - (void) otherMouseDragged: (NSEvent*) ev
  206828. {
  206829. [self mouseDragged: ev];
  206830. }
  206831. - (void) otherMouseUp: (NSEvent*) ev
  206832. {
  206833. [self mouseUp: ev];
  206834. }
  206835. - (void) scrollWheel: (NSEvent*) ev
  206836. {
  206837. if (owner != 0)
  206838. owner->redirectMouseWheel (ev);
  206839. }
  206840. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206841. {
  206842. return YES;
  206843. }
  206844. - (void) frameChanged: (NSNotification*) n
  206845. {
  206846. if (owner != 0)
  206847. owner->redirectMovedOrResized();
  206848. }
  206849. - (void) viewDidMoveToWindow
  206850. {
  206851. if (owner != 0)
  206852. owner->viewMovedToWindow();
  206853. }
  206854. - (void) asyncRepaint: (id) rect
  206855. {
  206856. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206857. [self setNeedsDisplayInRect: *r];
  206858. }
  206859. - (void) keyDown: (NSEvent*) ev
  206860. {
  206861. if (owner == 0 || ! owner->redirectKeyDown (ev))
  206862. [super keyDown: ev];
  206863. }
  206864. - (void) keyUp: (NSEvent*) ev
  206865. {
  206866. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206867. [super keyUp: ev];
  206868. }
  206869. - (void) flagsChanged: (NSEvent*) ev
  206870. {
  206871. if (owner != 0)
  206872. owner->redirectModKeyChange (ev);
  206873. }
  206874. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206875. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206876. {
  206877. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206878. return true;
  206879. return [super performKeyEquivalent: ev];
  206880. }
  206881. #endif
  206882. - (BOOL) becomeFirstResponder
  206883. {
  206884. if (owner != 0)
  206885. owner->viewFocusGain();
  206886. return true;
  206887. }
  206888. - (BOOL) resignFirstResponder
  206889. {
  206890. if (owner != 0)
  206891. owner->viewFocusLoss();
  206892. return true;
  206893. }
  206894. - (BOOL) acceptsFirstResponder
  206895. {
  206896. return owner != 0 && owner->canBecomeKeyWindow();
  206897. }
  206898. - (NSArray*) getSupportedDragTypes
  206899. {
  206900. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206901. }
  206902. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206903. {
  206904. return owner != 0 && owner->sendDragCallback (type, sender);
  206905. }
  206906. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206907. {
  206908. if ([self sendDragCallback: 0 sender: sender])
  206909. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206910. else
  206911. return NSDragOperationNone;
  206912. }
  206913. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206914. {
  206915. if ([self sendDragCallback: 0 sender: sender])
  206916. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206917. else
  206918. return NSDragOperationNone;
  206919. }
  206920. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206921. {
  206922. [self sendDragCallback: 1 sender: sender];
  206923. }
  206924. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206925. {
  206926. [self sendDragCallback: 1 sender: sender];
  206927. }
  206928. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206929. {
  206930. return YES;
  206931. }
  206932. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206933. {
  206934. return [self sendDragCallback: 2 sender: sender];
  206935. }
  206936. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206937. {
  206938. }
  206939. @end
  206940. @implementation JuceNSWindow
  206941. - (void) setOwner: (NSViewComponentPeer*) owner_
  206942. {
  206943. owner = owner_;
  206944. isZooming = false;
  206945. }
  206946. - (BOOL) canBecomeKeyWindow
  206947. {
  206948. return owner != 0 && owner->canBecomeKeyWindow();
  206949. }
  206950. - (void) becomeKeyWindow
  206951. {
  206952. [super becomeKeyWindow];
  206953. if (owner != 0)
  206954. owner->grabFocus();
  206955. }
  206956. - (BOOL) windowShouldClose: (id) window
  206957. {
  206958. return owner == 0 || owner->windowShouldClose();
  206959. }
  206960. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206961. {
  206962. if (owner != 0)
  206963. frameRect = owner->constrainRect (frameRect);
  206964. return frameRect;
  206965. }
  206966. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206967. {
  206968. if (isZooming)
  206969. return proposedFrameSize;
  206970. NSRect frameRect = [self frame];
  206971. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206972. frameRect.size = proposedFrameSize;
  206973. if (owner != 0)
  206974. frameRect = owner->constrainRect (frameRect);
  206975. return frameRect.size;
  206976. }
  206977. - (void) zoom: (id) sender
  206978. {
  206979. isZooming = true;
  206980. [super zoom: sender];
  206981. isZooming = false;
  206982. }
  206983. - (void) windowWillMove: (NSNotification*) notification
  206984. {
  206985. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  206986. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  206987. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  206988. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  206989. }
  206990. @end
  206991. BEGIN_JUCE_NAMESPACE
  206992. static ComponentPeer* currentlyFocusedPeer = 0;
  206993. static VoidArray keysCurrentlyDown;
  206994. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  206995. {
  206996. if (keysCurrentlyDown.contains ((void*) keyCode))
  206997. return true;
  206998. if (keyCode >= 'A' && keyCode <= 'Z'
  206999. && keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  207000. return true;
  207001. if (keyCode >= 'a' && keyCode <= 'z'
  207002. && keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  207003. return true;
  207004. return false;
  207005. }
  207006. static int getKeyCodeFromEvent (NSEvent* ev)
  207007. {
  207008. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207009. int keyCode = unmodified[0];
  207010. if (keyCode == 0x19) // (backwards-tab)
  207011. keyCode = '\t';
  207012. else if (keyCode == 0x03) // (enter)
  207013. keyCode = '\r';
  207014. return keyCode;
  207015. }
  207016. static int currentModifiers = 0;
  207017. static void updateModifiers (NSEvent* e)
  207018. {
  207019. int m = currentModifiers & ~(ModifierKeys::shiftModifier | ModifierKeys::ctrlModifier
  207020. | ModifierKeys::altModifier | ModifierKeys::commandModifier);
  207021. if (([e modifierFlags] & NSShiftKeyMask) != 0)
  207022. m |= ModifierKeys::shiftModifier;
  207023. if (([e modifierFlags] & NSControlKeyMask) != 0)
  207024. m |= ModifierKeys::ctrlModifier;
  207025. if (([e modifierFlags] & NSAlternateKeyMask) != 0)
  207026. m |= ModifierKeys::altModifier;
  207027. if (([e modifierFlags] & NSCommandKeyMask) != 0)
  207028. m |= ModifierKeys::commandModifier;
  207029. currentModifiers = m;
  207030. }
  207031. static void updateKeysDown (NSEvent* ev, bool isKeyDown)
  207032. {
  207033. updateModifiers (ev);
  207034. int keyCode = getKeyCodeFromEvent (ev);
  207035. if (keyCode != 0)
  207036. {
  207037. if (isKeyDown)
  207038. keysCurrentlyDown.addIfNotAlreadyThere ((void*) keyCode);
  207039. else
  207040. keysCurrentlyDown.removeValue ((void*) keyCode);
  207041. }
  207042. }
  207043. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  207044. {
  207045. return ModifierKeys (currentModifiers);
  207046. }
  207047. void ModifierKeys::updateCurrentModifiers() throw()
  207048. {
  207049. currentModifierFlags = currentModifiers;
  207050. }
  207051. static int64 getMouseTime (NSEvent* e)
  207052. {
  207053. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  207054. + (int64) ([e timestamp] * 1000.0);
  207055. }
  207056. static void getMousePos (NSEvent* e, NSView* view, int& x, int& y)
  207057. {
  207058. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  207059. x = roundToInt (p.x);
  207060. y = roundToInt ([view frame].size.height - p.y);
  207061. }
  207062. static int getModifierForButtonNumber (const NSInteger num)
  207063. {
  207064. return num == 0 ? ModifierKeys::leftButtonModifier
  207065. : (num == 1 ? ModifierKeys::rightButtonModifier
  207066. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  207067. }
  207068. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  207069. const int windowStyleFlags,
  207070. NSView* viewToAttachTo)
  207071. : ComponentPeer (component_, windowStyleFlags),
  207072. window (0),
  207073. view (0),
  207074. isSharedWindow (viewToAttachTo != 0),
  207075. fullScreen (false),
  207076. insideDrawRect (false),
  207077. #if USE_COREGRAPHICS_RENDERING
  207078. usingCoreGraphics (true),
  207079. #else
  207080. usingCoreGraphics (false),
  207081. #endif
  207082. recursiveToFrontCall (false)
  207083. {
  207084. NSRect r;
  207085. r.origin.x = 0;
  207086. r.origin.y = 0;
  207087. r.size.width = (float) component->getWidth();
  207088. r.size.height = (float) component->getHeight();
  207089. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  207090. [view setPostsFrameChangedNotifications: YES];
  207091. if (isSharedWindow)
  207092. {
  207093. window = [viewToAttachTo window];
  207094. [viewToAttachTo addSubview: view];
  207095. setVisible (component->isVisible());
  207096. }
  207097. else
  207098. {
  207099. r.origin.x = (float) component->getX();
  207100. r.origin.y = (float) component->getY();
  207101. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207102. unsigned int style = 0;
  207103. if ((windowStyleFlags & windowHasTitleBar) == 0)
  207104. style = NSBorderlessWindowMask;
  207105. else
  207106. style = NSTitledWindowMask;
  207107. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207108. style |= NSMiniaturizableWindowMask;
  207109. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207110. style |= NSClosableWindowMask;
  207111. if ((windowStyleFlags & windowIsResizable) != 0)
  207112. style |= NSResizableWindowMask;
  207113. window = [[JuceNSWindow alloc] initWithContentRect: r
  207114. styleMask: style
  207115. backing: NSBackingStoreBuffered
  207116. defer: YES];
  207117. [((JuceNSWindow*) window) setOwner: this];
  207118. [window orderOut: nil];
  207119. [window setDelegate: (JuceNSWindow*) window];
  207120. [window setOpaque: component->isOpaque()];
  207121. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207122. if (component->isAlwaysOnTop())
  207123. [window setLevel: NSFloatingWindowLevel];
  207124. [window setContentView: view];
  207125. [window setAutodisplay: YES];
  207126. [window setAcceptsMouseMovedEvents: YES];
  207127. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207128. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207129. [window setReleasedWhenClosed: YES];
  207130. [window retain];
  207131. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207132. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207133. }
  207134. setTitle (component->getName());
  207135. }
  207136. NSViewComponentPeer::~NSViewComponentPeer()
  207137. {
  207138. view->owner = 0;
  207139. [view removeFromSuperview];
  207140. [view release];
  207141. if (! isSharedWindow)
  207142. {
  207143. [((JuceNSWindow*) window) setOwner: 0];
  207144. [window close];
  207145. [window release];
  207146. }
  207147. }
  207148. void* NSViewComponentPeer::getNativeHandle() const
  207149. {
  207150. return view;
  207151. }
  207152. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207153. {
  207154. if (isSharedWindow)
  207155. {
  207156. [view setHidden: ! shouldBeVisible];
  207157. }
  207158. else
  207159. {
  207160. if (shouldBeVisible)
  207161. {
  207162. [window orderFront: nil];
  207163. handleBroughtToFront();
  207164. }
  207165. else
  207166. {
  207167. [window orderOut: nil];
  207168. }
  207169. }
  207170. }
  207171. void NSViewComponentPeer::setTitle (const String& title)
  207172. {
  207173. const ScopedAutoReleasePool pool;
  207174. if (! isSharedWindow)
  207175. [window setTitle: juceStringToNS (title)];
  207176. }
  207177. void NSViewComponentPeer::setPosition (int x, int y)
  207178. {
  207179. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207180. }
  207181. void NSViewComponentPeer::setSize (int w, int h)
  207182. {
  207183. setBounds (component->getX(), component->getY(), w, h, false);
  207184. }
  207185. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  207186. {
  207187. fullScreen = isNowFullScreen;
  207188. w = jmax (0, w);
  207189. h = jmax (0, h);
  207190. NSRect r;
  207191. r.origin.x = (float) x;
  207192. r.origin.y = (float) y;
  207193. r.size.width = (float) w;
  207194. r.size.height = (float) h;
  207195. if (isSharedWindow)
  207196. {
  207197. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207198. if ([view frame].size.width != r.size.width
  207199. || [view frame].size.height != r.size.height)
  207200. [view setNeedsDisplay: true];
  207201. [view setFrame: r];
  207202. }
  207203. else
  207204. {
  207205. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207206. [window setFrame: [window frameRectForContentRect: r]
  207207. display: true];
  207208. }
  207209. }
  207210. void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const
  207211. {
  207212. NSRect r = [view frame];
  207213. if (global && [view window] != 0)
  207214. {
  207215. r = [view convertRect: r toView: nil];
  207216. NSRect wr = [[view window] frame];
  207217. r.origin.x += wr.origin.x;
  207218. r.origin.y += wr.origin.y;
  207219. y = (int) ([[[NSScreen screens] objectAtIndex:0] frame].size.height - r.origin.y - r.size.height);
  207220. }
  207221. else
  207222. {
  207223. y = (int) ([[view superview] frame].size.height - r.origin.y - r.size.height);
  207224. }
  207225. x = (int) r.origin.x;
  207226. w = (int) r.size.width;
  207227. h = (int) r.size.height;
  207228. }
  207229. void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const
  207230. {
  207231. getBounds (x, y, w, h, ! isSharedWindow);
  207232. }
  207233. int NSViewComponentPeer::getScreenX() const
  207234. {
  207235. int x, y, w, h;
  207236. getBounds (x, y, w, h, true);
  207237. return x;
  207238. }
  207239. int NSViewComponentPeer::getScreenY() const
  207240. {
  207241. int x, y, w, h;
  207242. getBounds (x, y, w, h, true);
  207243. return y;
  207244. }
  207245. void NSViewComponentPeer::relativePositionToGlobal (int& x, int& y)
  207246. {
  207247. int wx, wy, ww, wh;
  207248. getBounds (wx, wy, ww, wh, true);
  207249. x += wx;
  207250. y += wy;
  207251. }
  207252. void NSViewComponentPeer::globalPositionToRelative (int& x, int& y)
  207253. {
  207254. int wx, wy, ww, wh;
  207255. getBounds (wx, wy, ww, wh, true);
  207256. x -= wx;
  207257. y -= wy;
  207258. }
  207259. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207260. {
  207261. if (constrainer != 0)
  207262. {
  207263. NSRect current = [window frame];
  207264. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207265. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207266. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207267. (int) r.size.width, (int) r.size.height);
  207268. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207269. (int) current.size.width, (int) current.size.height);
  207270. constrainer->checkBounds (pos, original,
  207271. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207272. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207273. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207274. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207275. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207276. r.origin.x = pos.getX();
  207277. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207278. r.size.width = pos.getWidth();
  207279. r.size.height = pos.getHeight();
  207280. }
  207281. return r;
  207282. }
  207283. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207284. {
  207285. if (! isSharedWindow)
  207286. {
  207287. if (shouldBeMinimised)
  207288. [window miniaturize: nil];
  207289. else
  207290. [window deminiaturize: nil];
  207291. }
  207292. }
  207293. bool NSViewComponentPeer::isMinimised() const
  207294. {
  207295. return window != 0 && [window isMiniaturized];
  207296. }
  207297. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207298. {
  207299. if (! isSharedWindow)
  207300. {
  207301. Rectangle<int> r (lastNonFullscreenBounds);
  207302. setMinimised (false);
  207303. if (fullScreen != shouldBeFullScreen)
  207304. {
  207305. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207306. {
  207307. fullScreen = true;
  207308. [window performZoom: nil];
  207309. }
  207310. else
  207311. {
  207312. if (shouldBeFullScreen)
  207313. r = Desktop::getInstance().getMainMonitorArea();
  207314. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207315. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207316. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207317. }
  207318. }
  207319. }
  207320. }
  207321. bool NSViewComponentPeer::isFullScreen() const
  207322. {
  207323. return fullScreen;
  207324. }
  207325. bool NSViewComponentPeer::contains (int x, int y, bool trueIfInAChildWindow) const
  207326. {
  207327. if (((unsigned int) x) >= (unsigned int) component->getWidth()
  207328. || ((unsigned int) y) >= (unsigned int) component->getHeight())
  207329. return false;
  207330. NSPoint p;
  207331. p.x = (float) x;
  207332. p.y = (float) y;
  207333. NSView* v = [view hitTest: p];
  207334. if (trueIfInAChildWindow)
  207335. return v != nil;
  207336. return v == view;
  207337. }
  207338. const BorderSize NSViewComponentPeer::getFrameSize() const
  207339. {
  207340. BorderSize b;
  207341. if (! isSharedWindow)
  207342. {
  207343. NSRect v = [view convertRect: [view frame] toView: nil];
  207344. NSRect w = [window frame];
  207345. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207346. b.setBottom ((int) v.origin.y);
  207347. b.setLeft ((int) v.origin.x);
  207348. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207349. }
  207350. return b;
  207351. }
  207352. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207353. {
  207354. if (! isSharedWindow)
  207355. {
  207356. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207357. : NSNormalWindowLevel];
  207358. }
  207359. return true;
  207360. }
  207361. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207362. {
  207363. if (isSharedWindow)
  207364. {
  207365. [[view superview] addSubview: view
  207366. positioned: NSWindowAbove
  207367. relativeTo: nil];
  207368. }
  207369. if (window != 0 && component->isVisible())
  207370. {
  207371. if (makeActiveWindow)
  207372. [window makeKeyAndOrderFront: nil];
  207373. else
  207374. [window orderFront: nil];
  207375. if (! recursiveToFrontCall)
  207376. {
  207377. recursiveToFrontCall = true;
  207378. handleBroughtToFront();
  207379. recursiveToFrontCall = false;
  207380. }
  207381. }
  207382. }
  207383. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207384. {
  207385. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207386. if (isSharedWindow)
  207387. {
  207388. [[view superview] addSubview: view
  207389. positioned: NSWindowBelow
  207390. relativeTo: o->view];
  207391. }
  207392. else
  207393. {
  207394. [window orderWindow: NSWindowBelow
  207395. relativeTo: o->window != 0 ? [o->window windowNumber]
  207396. : nil ];
  207397. }
  207398. }
  207399. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207400. {
  207401. // to do..
  207402. }
  207403. void NSViewComponentPeer::viewFocusGain()
  207404. {
  207405. if (currentlyFocusedPeer != this)
  207406. {
  207407. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207408. currentlyFocusedPeer->handleFocusLoss();
  207409. currentlyFocusedPeer = this;
  207410. handleFocusGain();
  207411. }
  207412. }
  207413. void NSViewComponentPeer::viewFocusLoss()
  207414. {
  207415. if (currentlyFocusedPeer == this)
  207416. {
  207417. currentlyFocusedPeer = 0;
  207418. handleFocusLoss();
  207419. }
  207420. }
  207421. void juce_HandleProcessFocusChange()
  207422. {
  207423. keysCurrentlyDown.clear();
  207424. if (NSViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  207425. {
  207426. if (Process::isForegroundProcess())
  207427. {
  207428. currentlyFocusedPeer->handleFocusGain();
  207429. ComponentPeer::bringModalComponentToFront();
  207430. }
  207431. else
  207432. {
  207433. currentlyFocusedPeer->handleFocusLoss();
  207434. // turn kiosk mode off if we lose focus..
  207435. Desktop::getInstance().setKioskModeComponent (0);
  207436. }
  207437. }
  207438. }
  207439. bool NSViewComponentPeer::isFocused() const
  207440. {
  207441. return isSharedWindow ? this == currentlyFocusedPeer
  207442. : (window != 0 && [window isKeyWindow]);
  207443. }
  207444. void NSViewComponentPeer::grabFocus()
  207445. {
  207446. if (window != 0)
  207447. {
  207448. [window makeKeyWindow];
  207449. [window makeFirstResponder: view];
  207450. viewFocusGain();
  207451. }
  207452. }
  207453. void NSViewComponentPeer::textInputRequired (int /*x*/, int /*y*/)
  207454. {
  207455. }
  207456. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207457. {
  207458. String unicode (nsStringToJuce ([ev characters]));
  207459. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207460. int keyCode = getKeyCodeFromEvent (ev);
  207461. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207462. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207463. if (unicode.isNotEmpty() || keyCode != 0)
  207464. {
  207465. if (isKeyDown)
  207466. {
  207467. bool used = false;
  207468. while (unicode.length() > 0)
  207469. {
  207470. juce_wchar textCharacter = unicode[0];
  207471. unicode = unicode.substring (1);
  207472. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207473. textCharacter = 0;
  207474. used = handleKeyUpOrDown (true) || used;
  207475. used = handleKeyPress (keyCode, textCharacter) || used;
  207476. }
  207477. return used;
  207478. }
  207479. else
  207480. {
  207481. if (handleKeyUpOrDown (false))
  207482. return true;
  207483. }
  207484. }
  207485. return false;
  207486. }
  207487. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207488. {
  207489. updateKeysDown (ev, true);
  207490. bool used = handleKeyEvent (ev, true);
  207491. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207492. {
  207493. // for command keys, the key-up event is thrown away, so simulate one..
  207494. updateKeysDown (ev, false);
  207495. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207496. }
  207497. // (If we're running modally, don't allow unused keystrokes to be passed
  207498. // along to other blocked views..)
  207499. if (Component::getCurrentlyModalComponent() != 0)
  207500. used = true;
  207501. return used;
  207502. }
  207503. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207504. {
  207505. updateKeysDown (ev, false);
  207506. return handleKeyEvent (ev, false)
  207507. || Component::getCurrentlyModalComponent() != 0;
  207508. }
  207509. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207510. {
  207511. keysCurrentlyDown.clear();
  207512. handleKeyUpOrDown (true);
  207513. updateModifiers (ev);
  207514. handleModifierKeysChange();
  207515. }
  207516. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207517. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207518. {
  207519. if ([ev type] == NSKeyDown)
  207520. return redirectKeyDown (ev);
  207521. else if ([ev type] == NSKeyUp)
  207522. return redirectKeyUp (ev);
  207523. return false;
  207524. }
  207525. #endif
  207526. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207527. {
  207528. updateModifiers (ev);
  207529. currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]);
  207530. int x, y;
  207531. getMousePos (ev, view, x, y);
  207532. handleMouseDown (x, y, getMouseTime (ev));
  207533. }
  207534. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207535. {
  207536. const int oldMods = currentModifiers;
  207537. updateModifiers (ev);
  207538. currentModifiers &= ~getModifierForButtonNumber ([ev buttonNumber]);
  207539. int x, y;
  207540. getMousePos (ev, view, x, y);
  207541. handleMouseUp (oldMods, x, y, getMouseTime (ev));
  207542. showArrowCursorIfNeeded();
  207543. }
  207544. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207545. {
  207546. updateModifiers (ev);
  207547. currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]);
  207548. int x, y;
  207549. getMousePos (ev, view, x, y);
  207550. handleMouseDrag (x, y, getMouseTime (ev));
  207551. }
  207552. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207553. {
  207554. updateModifiers (ev);
  207555. int x, y;
  207556. getMousePos (ev, view, x, y);
  207557. handleMouseMove (x, y, getMouseTime (ev));
  207558. showArrowCursorIfNeeded();
  207559. }
  207560. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207561. {
  207562. updateModifiers (ev);
  207563. int x, y;
  207564. getMousePos (ev, view, x, y);
  207565. handleMouseEnter (x, y, getMouseTime (ev));
  207566. }
  207567. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207568. {
  207569. updateModifiers (ev);
  207570. int x, y;
  207571. getMousePos (ev, view, x, y);
  207572. handleMouseExit (x, y, getMouseTime (ev));
  207573. }
  207574. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207575. {
  207576. updateModifiers (ev);
  207577. handleMouseWheel (roundToInt ([ev deltaX] * 10.0f),
  207578. roundToInt ([ev deltaY] * 10.0f),
  207579. getMouseTime (ev));
  207580. }
  207581. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207582. {
  207583. if (Component::getComponentUnderMouse() == 0)
  207584. {
  207585. int mx, my;
  207586. Desktop::getInstance().getMousePosition (mx, my);
  207587. if (Desktop::getInstance().findComponentAt (mx, my) == 0)
  207588. [[NSCursor arrowCursor] set];
  207589. }
  207590. }
  207591. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207592. {
  207593. NSString* bestType
  207594. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207595. if (bestType == nil)
  207596. return false;
  207597. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207598. int x = (int) p.x;
  207599. int y = (int) ([view frame].size.height - p.y);
  207600. StringArray files;
  207601. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207602. if (list == nil)
  207603. return false;
  207604. if ([list isKindOfClass: [NSArray class]])
  207605. {
  207606. NSArray* items = (NSArray*) list;
  207607. for (unsigned int i = 0; i < [items count]; ++i)
  207608. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207609. }
  207610. if (files.size() == 0)
  207611. return false;
  207612. if (type == 0)
  207613. handleFileDragMove (files, x, y);
  207614. else if (type == 1)
  207615. handleFileDragExit (files);
  207616. else if (type == 2)
  207617. handleFileDragDrop (files, x, y);
  207618. return true;
  207619. }
  207620. bool NSViewComponentPeer::isOpaque()
  207621. {
  207622. if (! getComponent()->isValidComponent())
  207623. return true;
  207624. return getComponent()->isOpaque();
  207625. }
  207626. void NSViewComponentPeer::drawRect (NSRect r)
  207627. {
  207628. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207629. return;
  207630. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207631. if (! component->isOpaque())
  207632. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207633. #if USE_COREGRAPHICS_RENDERING
  207634. if (usingCoreGraphics)
  207635. {
  207636. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207637. insideDrawRect = true;
  207638. handlePaint (context);
  207639. insideDrawRect = false;
  207640. }
  207641. else
  207642. #endif
  207643. {
  207644. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207645. (int) (r.size.width + 0.5f),
  207646. (int) (r.size.height + 0.5f),
  207647. ! getComponent()->isOpaque());
  207648. LowLevelGraphicsSoftwareRenderer context (temp);
  207649. context.setOrigin (-roundToInt (r.origin.x),
  207650. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207651. const NSRect* rects = 0;
  207652. NSInteger numRects = 0;
  207653. [view getRectsBeingDrawn: &rects count: &numRects];
  207654. RectangleList clip;
  207655. for (int i = 0; i < numRects; ++i)
  207656. {
  207657. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207658. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207659. roundToInt (rects[i].size.width),
  207660. roundToInt (rects[i].size.height)));
  207661. }
  207662. if (context.clipToRectangleList (clip))
  207663. {
  207664. insideDrawRect = true;
  207665. handlePaint (context);
  207666. insideDrawRect = false;
  207667. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207668. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207669. CGColorSpaceRelease (colourSpace);
  207670. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207671. CGImageRelease (image);
  207672. }
  207673. }
  207674. }
  207675. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207676. {
  207677. StringArray s;
  207678. s.add ("Software Renderer");
  207679. #if USE_COREGRAPHICS_RENDERING
  207680. s.add ("CoreGraphics Renderer");
  207681. #endif
  207682. return s;
  207683. }
  207684. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207685. {
  207686. return usingCoreGraphics ? 1 : 0;
  207687. }
  207688. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207689. {
  207690. #if USE_COREGRAPHICS_RENDERING
  207691. if (usingCoreGraphics != (index > 0))
  207692. {
  207693. usingCoreGraphics = index > 0;
  207694. [view setNeedsDisplay: true];
  207695. }
  207696. #endif
  207697. }
  207698. bool NSViewComponentPeer::canBecomeKeyWindow()
  207699. {
  207700. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207701. }
  207702. bool NSViewComponentPeer::windowShouldClose()
  207703. {
  207704. if (! isValidPeer (this))
  207705. return YES;
  207706. handleUserClosingWindow();
  207707. return NO;
  207708. }
  207709. void NSViewComponentPeer::redirectMovedOrResized()
  207710. {
  207711. handleMovedOrResized();
  207712. }
  207713. void NSViewComponentPeer::viewMovedToWindow()
  207714. {
  207715. if (isSharedWindow)
  207716. window = [view window];
  207717. }
  207718. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207719. {
  207720. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207721. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207722. // is apparently still available in 64-bit apps..
  207723. if (enableOrDisable)
  207724. {
  207725. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207726. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207727. }
  207728. else
  207729. {
  207730. SetSystemUIMode (kUIModeNormal, 0);
  207731. }
  207732. }
  207733. class AsyncRepaintMessage : public CallbackMessage
  207734. {
  207735. public:
  207736. NSViewComponentPeer* const peer;
  207737. const Rectangle<int> rect;
  207738. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207739. : peer (peer_), rect (rect_)
  207740. {
  207741. }
  207742. void messageCallback()
  207743. {
  207744. if (ComponentPeer::isValidPeer (peer))
  207745. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207746. }
  207747. };
  207748. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207749. {
  207750. if (insideDrawRect)
  207751. {
  207752. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207753. }
  207754. else
  207755. {
  207756. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207757. (float) w, (float) h)];
  207758. }
  207759. }
  207760. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207761. {
  207762. [view displayIfNeeded];
  207763. }
  207764. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207765. {
  207766. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207767. }
  207768. Image* juce_createIconForFile (const File& file)
  207769. {
  207770. const ScopedAutoReleasePool pool;
  207771. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207772. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207773. [NSGraphicsContext saveGraphicsState];
  207774. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207775. [image drawAtPoint: NSMakePoint (0, 0)
  207776. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207777. operation: NSCompositeSourceOver fraction: 1.0f];
  207778. [[NSGraphicsContext currentContext] flushGraphics];
  207779. [NSGraphicsContext restoreGraphicsState];
  207780. return result;
  207781. }
  207782. const int KeyPress::spaceKey = ' ';
  207783. const int KeyPress::returnKey = 0x0d;
  207784. const int KeyPress::escapeKey = 0x1b;
  207785. const int KeyPress::backspaceKey = 0x7f;
  207786. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207787. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207788. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207789. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207790. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207791. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207792. const int KeyPress::endKey = NSEndFunctionKey;
  207793. const int KeyPress::homeKey = NSHomeFunctionKey;
  207794. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207795. const int KeyPress::insertKey = -1;
  207796. const int KeyPress::tabKey = 9;
  207797. const int KeyPress::F1Key = NSF1FunctionKey;
  207798. const int KeyPress::F2Key = NSF2FunctionKey;
  207799. const int KeyPress::F3Key = NSF3FunctionKey;
  207800. const int KeyPress::F4Key = NSF4FunctionKey;
  207801. const int KeyPress::F5Key = NSF5FunctionKey;
  207802. const int KeyPress::F6Key = NSF6FunctionKey;
  207803. const int KeyPress::F7Key = NSF7FunctionKey;
  207804. const int KeyPress::F8Key = NSF8FunctionKey;
  207805. const int KeyPress::F9Key = NSF9FunctionKey;
  207806. const int KeyPress::F10Key = NSF10FunctionKey;
  207807. const int KeyPress::F11Key = NSF1FunctionKey;
  207808. const int KeyPress::F12Key = NSF12FunctionKey;
  207809. const int KeyPress::F13Key = NSF13FunctionKey;
  207810. const int KeyPress::F14Key = NSF14FunctionKey;
  207811. const int KeyPress::F15Key = NSF15FunctionKey;
  207812. const int KeyPress::F16Key = NSF16FunctionKey;
  207813. const int KeyPress::numberPad0 = 0x30020;
  207814. const int KeyPress::numberPad1 = 0x30021;
  207815. const int KeyPress::numberPad2 = 0x30022;
  207816. const int KeyPress::numberPad3 = 0x30023;
  207817. const int KeyPress::numberPad4 = 0x30024;
  207818. const int KeyPress::numberPad5 = 0x30025;
  207819. const int KeyPress::numberPad6 = 0x30026;
  207820. const int KeyPress::numberPad7 = 0x30027;
  207821. const int KeyPress::numberPad8 = 0x30028;
  207822. const int KeyPress::numberPad9 = 0x30029;
  207823. const int KeyPress::numberPadAdd = 0x3002a;
  207824. const int KeyPress::numberPadSubtract = 0x3002b;
  207825. const int KeyPress::numberPadMultiply = 0x3002c;
  207826. const int KeyPress::numberPadDivide = 0x3002d;
  207827. const int KeyPress::numberPadSeparator = 0x3002e;
  207828. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207829. const int KeyPress::numberPadEquals = 0x30030;
  207830. const int KeyPress::numberPadDelete = 0x30031;
  207831. const int KeyPress::playKey = 0x30000;
  207832. const int KeyPress::stopKey = 0x30001;
  207833. const int KeyPress::fastForwardKey = 0x30002;
  207834. const int KeyPress::rewindKey = 0x30003;
  207835. #endif
  207836. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207837. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207838. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207839. // compiled on its own).
  207840. #if JUCE_INCLUDED_FILE
  207841. #if JUCE_MAC
  207842. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  207843. {
  207844. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207845. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207846. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207847. [im release];
  207848. return (void*) c;
  207849. }
  207850. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  207851. {
  207852. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  207853. jassert (im != 0);
  207854. if (im == 0)
  207855. return 0;
  207856. return juce_createMouseCursorFromImage (*im,
  207857. (int) (hx * im->getWidth()),
  207858. (int) (hy * im->getHeight()));
  207859. }
  207860. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207861. {
  207862. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207863. MemoryBlock mb;
  207864. if (f.getChildFile (filename).loadFileAsData (mb))
  207865. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  207866. return 0;
  207867. }
  207868. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  207869. {
  207870. const ScopedAutoReleasePool pool;
  207871. NSCursor* c = 0;
  207872. switch (type)
  207873. {
  207874. case MouseCursor::NormalCursor:
  207875. c = [NSCursor arrowCursor];
  207876. break;
  207877. case MouseCursor::NoCursor:
  207878. {
  207879. Image blank (Image::ARGB, 8, 8, true);
  207880. return juce_createMouseCursorFromImage (blank, 0, 0);
  207881. }
  207882. case MouseCursor::DraggingHandCursor:
  207883. c = [NSCursor openHandCursor];
  207884. break;
  207885. case MouseCursor::CopyingCursor:
  207886. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207887. case MouseCursor::WaitCursor:
  207888. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207889. break;
  207890. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207891. case MouseCursor::IBeamCursor:
  207892. c = [NSCursor IBeamCursor];
  207893. break;
  207894. case MouseCursor::PointingHandCursor:
  207895. c = [NSCursor pointingHandCursor];
  207896. break;
  207897. case MouseCursor::LeftRightResizeCursor:
  207898. c = [NSCursor resizeLeftRightCursor];
  207899. break;
  207900. case MouseCursor::LeftEdgeResizeCursor:
  207901. c = [NSCursor resizeLeftCursor];
  207902. break;
  207903. case MouseCursor::RightEdgeResizeCursor:
  207904. c = [NSCursor resizeRightCursor];
  207905. break;
  207906. case MouseCursor::UpDownResizeCursor:
  207907. case MouseCursor::TopEdgeResizeCursor:
  207908. case MouseCursor::BottomEdgeResizeCursor:
  207909. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207910. case MouseCursor::TopLeftCornerResizeCursor:
  207911. case MouseCursor::BottomRightCornerResizeCursor:
  207912. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207913. case MouseCursor::TopRightCornerResizeCursor:
  207914. case MouseCursor::BottomLeftCornerResizeCursor:
  207915. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207916. case MouseCursor::UpDownLeftRightResizeCursor:
  207917. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207918. case MouseCursor::CrosshairCursor:
  207919. c = [NSCursor crosshairCursor];
  207920. break;
  207921. }
  207922. [c retain];
  207923. return (void*) c;
  207924. }
  207925. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  207926. {
  207927. NSCursor* c = (NSCursor*) cursorHandle;
  207928. [c release];
  207929. }
  207930. void MouseCursor::showInAllWindows() const throw()
  207931. {
  207932. showInWindow (0);
  207933. }
  207934. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  207935. {
  207936. NSCursor* const c = (NSCursor*) getHandle();
  207937. [c set];
  207938. }
  207939. #else
  207940. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  207941. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  207942. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  207943. void MouseCursor::showInAllWindows() const throw() {}
  207944. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  207945. #endif
  207946. #endif
  207947. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207948. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207949. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207950. // compiled on its own).
  207951. #if JUCE_INCLUDED_FILE
  207952. class NSViewComponentInternal : public ComponentMovementWatcher
  207953. {
  207954. Component* const owner;
  207955. NSViewComponentPeer* currentPeer;
  207956. bool wasShowing;
  207957. public:
  207958. NSView* const view;
  207959. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207960. : ComponentMovementWatcher (owner_),
  207961. owner (owner_),
  207962. currentPeer (0),
  207963. wasShowing (false),
  207964. view (view_)
  207965. {
  207966. [view_ retain];
  207967. if (owner_->isShowing())
  207968. componentPeerChanged();
  207969. }
  207970. ~NSViewComponentInternal()
  207971. {
  207972. [view removeFromSuperview];
  207973. [view release];
  207974. }
  207975. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207976. {
  207977. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207978. // The ComponentMovementWatcher version of this method avoids calling
  207979. // us when the top-level comp is resized, but for an NSView we need to know this
  207980. // because with inverted co-ords, we need to update the position even if the
  207981. // top-left pos hasn't changed
  207982. if (comp.isOnDesktop() && wasResized)
  207983. componentMovedOrResized (wasMoved, wasResized);
  207984. }
  207985. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207986. {
  207987. Component* const topComp = owner->getTopLevelComponent();
  207988. if (topComp->getPeer() != 0)
  207989. {
  207990. int x = 0, y = 0;
  207991. owner->relativePositionToOtherComponent (topComp, x, y);
  207992. NSRect r;
  207993. r.origin.x = (float) x;
  207994. r.origin.y = (float) y;
  207995. r.size.width = (float) owner->getWidth();
  207996. r.size.height = (float) owner->getHeight();
  207997. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207998. [view setFrame: r];
  207999. }
  208000. }
  208001. void componentPeerChanged()
  208002. {
  208003. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  208004. if (currentPeer != peer)
  208005. {
  208006. [view removeFromSuperview];
  208007. currentPeer = peer;
  208008. if (peer != 0)
  208009. {
  208010. [peer->view addSubview: view];
  208011. componentMovedOrResized (false, false);
  208012. }
  208013. }
  208014. [view setHidden: ! owner->isShowing()];
  208015. }
  208016. void componentVisibilityChanged (Component&)
  208017. {
  208018. componentPeerChanged();
  208019. }
  208020. juce_UseDebuggingNewOperator
  208021. private:
  208022. NSViewComponentInternal (const NSViewComponentInternal&);
  208023. const NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  208024. };
  208025. NSViewComponent::NSViewComponent()
  208026. {
  208027. }
  208028. NSViewComponent::~NSViewComponent()
  208029. {
  208030. }
  208031. void NSViewComponent::setView (void* view)
  208032. {
  208033. if (view != getView())
  208034. {
  208035. if (view != 0)
  208036. info = new NSViewComponentInternal ((NSView*) view, this);
  208037. else
  208038. info = 0;
  208039. }
  208040. }
  208041. void* NSViewComponent::getView() const
  208042. {
  208043. return info == 0 ? 0 : info->view;
  208044. }
  208045. void NSViewComponent::paint (Graphics& g)
  208046. {
  208047. }
  208048. #endif
  208049. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  208050. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  208051. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208052. // compiled on its own).
  208053. #if JUCE_INCLUDED_FILE
  208054. AppleRemoteDevice::AppleRemoteDevice()
  208055. : device (0),
  208056. queue (0),
  208057. remoteId (0)
  208058. {
  208059. }
  208060. AppleRemoteDevice::~AppleRemoteDevice()
  208061. {
  208062. stop();
  208063. }
  208064. static io_object_t getAppleRemoteDevice()
  208065. {
  208066. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  208067. io_iterator_t iter = 0;
  208068. io_object_t iod = 0;
  208069. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  208070. && iter != 0)
  208071. {
  208072. iod = IOIteratorNext (iter);
  208073. }
  208074. IOObjectRelease (iter);
  208075. return iod;
  208076. }
  208077. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  208078. {
  208079. jassert (*device == 0);
  208080. io_name_t classname;
  208081. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  208082. {
  208083. IOCFPlugInInterface** cfPlugInInterface = 0;
  208084. SInt32 score = 0;
  208085. if (IOCreatePlugInInterfaceForService (iod,
  208086. kIOHIDDeviceUserClientTypeID,
  208087. kIOCFPlugInInterfaceID,
  208088. &cfPlugInInterface,
  208089. &score) == kIOReturnSuccess)
  208090. {
  208091. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  208092. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  208093. device);
  208094. (void) hr;
  208095. (*cfPlugInInterface)->Release (cfPlugInInterface);
  208096. }
  208097. }
  208098. return *device != 0;
  208099. }
  208100. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  208101. {
  208102. if (queue != 0)
  208103. return true;
  208104. stop();
  208105. bool result = false;
  208106. io_object_t iod = getAppleRemoteDevice();
  208107. if (iod != 0)
  208108. {
  208109. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  208110. result = true;
  208111. else
  208112. stop();
  208113. IOObjectRelease (iod);
  208114. }
  208115. return result;
  208116. }
  208117. void AppleRemoteDevice::stop()
  208118. {
  208119. if (queue != 0)
  208120. {
  208121. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  208122. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  208123. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  208124. queue = 0;
  208125. }
  208126. if (device != 0)
  208127. {
  208128. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  208129. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  208130. device = 0;
  208131. }
  208132. }
  208133. bool AppleRemoteDevice::isActive() const
  208134. {
  208135. return queue != 0;
  208136. }
  208137. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208138. {
  208139. if (result == kIOReturnSuccess)
  208140. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208141. }
  208142. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208143. {
  208144. Array <int> cookies;
  208145. CFArrayRef elements;
  208146. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208147. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208148. return false;
  208149. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208150. {
  208151. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208152. // get the cookie
  208153. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208154. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208155. continue;
  208156. long number;
  208157. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208158. continue;
  208159. cookies.add ((int) number);
  208160. }
  208161. CFRelease (elements);
  208162. if ((*(IOHIDDeviceInterface**) device)
  208163. ->open ((IOHIDDeviceInterface**) device,
  208164. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208165. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208166. {
  208167. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208168. if (queue != 0)
  208169. {
  208170. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208171. for (int i = 0; i < cookies.size(); ++i)
  208172. {
  208173. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208174. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208175. }
  208176. CFRunLoopSourceRef eventSource;
  208177. if ((*(IOHIDQueueInterface**) queue)
  208178. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208179. {
  208180. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208181. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208182. {
  208183. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208184. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208185. return true;
  208186. }
  208187. }
  208188. }
  208189. }
  208190. return false;
  208191. }
  208192. void AppleRemoteDevice::handleCallbackInternal()
  208193. {
  208194. int totalValues = 0;
  208195. AbsoluteTime nullTime = { 0, 0 };
  208196. char cookies [12];
  208197. int numCookies = 0;
  208198. while (numCookies < numElementsInArray (cookies))
  208199. {
  208200. IOHIDEventStruct e;
  208201. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208202. break;
  208203. if ((int) e.elementCookie == 19)
  208204. {
  208205. remoteId = e.value;
  208206. buttonPressed (switched, false);
  208207. }
  208208. else
  208209. {
  208210. totalValues += e.value;
  208211. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208212. }
  208213. }
  208214. cookies [numCookies++] = 0;
  208215. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208216. static const char buttonPatterns[] =
  208217. {
  208218. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208219. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208220. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208221. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208222. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208223. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208224. 0x1f, 0x12, 0x04, 0x02, 0,
  208225. 0x1f, 0x12, 0x03, 0x02, 0,
  208226. 0x1f, 0x12, 0x1f, 0x12, 0,
  208227. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208228. 19, 0
  208229. };
  208230. int buttonNum = (int) menuButton;
  208231. int i = 0;
  208232. while (i < numElementsInArray (buttonPatterns))
  208233. {
  208234. if (strcmp (cookies, buttonPatterns + i) == 0)
  208235. {
  208236. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208237. break;
  208238. }
  208239. i += (int) strlen (buttonPatterns + i) + 1;
  208240. ++buttonNum;
  208241. }
  208242. }
  208243. #endif
  208244. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208245. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208246. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208247. // compiled on its own).
  208248. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208249. #if JUCE_MAC
  208250. END_JUCE_NAMESPACE
  208251. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208252. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208253. {
  208254. CriticalSection* contextLock;
  208255. bool needsUpdate;
  208256. }
  208257. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208258. - (bool) makeActive;
  208259. - (void) makeInactive;
  208260. - (void) reshape;
  208261. @end
  208262. @implementation ThreadSafeNSOpenGLView
  208263. - (id) initWithFrame: (NSRect) frameRect
  208264. pixelFormat: (NSOpenGLPixelFormat*) format
  208265. {
  208266. contextLock = new CriticalSection();
  208267. self = [super initWithFrame: frameRect pixelFormat: format];
  208268. if (self != nil)
  208269. [[NSNotificationCenter defaultCenter] addObserver: self
  208270. selector: @selector (_surfaceNeedsUpdate:)
  208271. name: NSViewGlobalFrameDidChangeNotification
  208272. object: self];
  208273. return self;
  208274. }
  208275. - (void) dealloc
  208276. {
  208277. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208278. delete contextLock;
  208279. [super dealloc];
  208280. }
  208281. - (bool) makeActive
  208282. {
  208283. const ScopedLock sl (*contextLock);
  208284. if ([self openGLContext] == 0)
  208285. return false;
  208286. [[self openGLContext] makeCurrentContext];
  208287. if (needsUpdate)
  208288. {
  208289. [super update];
  208290. needsUpdate = false;
  208291. }
  208292. return true;
  208293. }
  208294. - (void) makeInactive
  208295. {
  208296. const ScopedLock sl (*contextLock);
  208297. [NSOpenGLContext clearCurrentContext];
  208298. }
  208299. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208300. {
  208301. const ScopedLock sl (*contextLock);
  208302. needsUpdate = true;
  208303. }
  208304. - (void) update
  208305. {
  208306. const ScopedLock sl (*contextLock);
  208307. needsUpdate = true;
  208308. }
  208309. - (void) reshape
  208310. {
  208311. const ScopedLock sl (*contextLock);
  208312. needsUpdate = true;
  208313. }
  208314. @end
  208315. BEGIN_JUCE_NAMESPACE
  208316. class WindowedGLContext : public OpenGLContext
  208317. {
  208318. public:
  208319. WindowedGLContext (Component* const component,
  208320. const OpenGLPixelFormat& pixelFormat_,
  208321. NSOpenGLContext* sharedContext)
  208322. : renderContext (0),
  208323. pixelFormat (pixelFormat_)
  208324. {
  208325. jassert (component != 0);
  208326. NSOpenGLPixelFormatAttribute attribs [64];
  208327. int n = 0;
  208328. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208329. attribs[n++] = NSOpenGLPFAAccelerated;
  208330. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208331. attribs[n++] = NSOpenGLPFAColorSize;
  208332. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208333. pixelFormat.greenBits,
  208334. pixelFormat.blueBits);
  208335. attribs[n++] = NSOpenGLPFAAlphaSize;
  208336. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208337. attribs[n++] = NSOpenGLPFADepthSize;
  208338. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208339. attribs[n++] = NSOpenGLPFAStencilSize;
  208340. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208341. attribs[n++] = NSOpenGLPFAAccumSize;
  208342. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208343. pixelFormat.accumulationBufferGreenBits,
  208344. pixelFormat.accumulationBufferBlueBits,
  208345. pixelFormat.accumulationBufferAlphaBits);
  208346. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208347. attribs[n++] = NSOpenGLPFASampleBuffers;
  208348. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208349. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208350. attribs[n++] = NSOpenGLPFANoRecovery;
  208351. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208352. NSOpenGLPixelFormat* format
  208353. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208354. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208355. pixelFormat: format];
  208356. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208357. shareContext: sharedContext] autorelease];
  208358. const GLint swapInterval = 1;
  208359. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208360. [view setOpenGLContext: renderContext];
  208361. [renderContext setView: view];
  208362. [format release];
  208363. viewHolder = new NSViewComponentInternal (view, component);
  208364. }
  208365. ~WindowedGLContext()
  208366. {
  208367. makeInactive();
  208368. [renderContext clearDrawable];
  208369. viewHolder = 0;
  208370. }
  208371. bool makeActive() const throw()
  208372. {
  208373. jassert (renderContext != 0);
  208374. [view makeActive];
  208375. return isActive();
  208376. }
  208377. bool makeInactive() const throw()
  208378. {
  208379. [view makeInactive];
  208380. return true;
  208381. }
  208382. bool isActive() const throw()
  208383. {
  208384. return [NSOpenGLContext currentContext] == renderContext;
  208385. }
  208386. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208387. void* getRawContext() const throw() { return renderContext; }
  208388. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208389. {
  208390. }
  208391. void swapBuffers()
  208392. {
  208393. [renderContext flushBuffer];
  208394. }
  208395. bool setSwapInterval (const int numFramesPerSwap)
  208396. {
  208397. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208398. forParameter: NSOpenGLCPSwapInterval];
  208399. return true;
  208400. }
  208401. int getSwapInterval() const
  208402. {
  208403. GLint numFrames = 0;
  208404. [renderContext getValues: &numFrames
  208405. forParameter: NSOpenGLCPSwapInterval];
  208406. return numFrames;
  208407. }
  208408. void repaint()
  208409. {
  208410. // we need to invalidate the juce view that holds this gl view, to make it
  208411. // cause a repaint callback
  208412. NSView* v = (NSView*) viewHolder->view;
  208413. NSRect r = [v frame];
  208414. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208415. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208416. // repaint message, thus never causing our paint() callback, and never repainting
  208417. // the comp. So invalidating just a little bit around the edge helps..
  208418. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208419. }
  208420. void* getNativeWindowHandle() const { return viewHolder->view; }
  208421. juce_UseDebuggingNewOperator
  208422. NSOpenGLContext* renderContext;
  208423. ThreadSafeNSOpenGLView* view;
  208424. private:
  208425. OpenGLPixelFormat pixelFormat;
  208426. ScopedPointer <NSViewComponentInternal> viewHolder;
  208427. WindowedGLContext (const WindowedGLContext&);
  208428. const WindowedGLContext& operator= (const WindowedGLContext&);
  208429. };
  208430. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208431. const OpenGLPixelFormat& pixelFormat,
  208432. const OpenGLContext* const contextToShareWith)
  208433. {
  208434. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  208435. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  208436. return (c->renderContext != 0) ? c.release() : 0;
  208437. }
  208438. void* OpenGLComponent::getNativeWindowHandle() const
  208439. {
  208440. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  208441. : 0;
  208442. }
  208443. void juce_glViewport (const int w, const int h)
  208444. {
  208445. glViewport (0, 0, w, h);
  208446. }
  208447. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208448. OwnedArray <OpenGLPixelFormat>& results)
  208449. {
  208450. /* GLint attribs [64];
  208451. int n = 0;
  208452. attribs[n++] = AGL_RGBA;
  208453. attribs[n++] = AGL_DOUBLEBUFFER;
  208454. attribs[n++] = AGL_ACCELERATED;
  208455. attribs[n++] = AGL_NO_RECOVERY;
  208456. attribs[n++] = AGL_NONE;
  208457. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208458. while (p != 0)
  208459. {
  208460. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208461. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208462. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208463. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208464. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208465. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208466. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208467. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208468. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208469. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208470. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208471. results.add (pf);
  208472. p = aglNextPixelFormat (p);
  208473. }*/
  208474. //jassertfalse //xxx can't see how you do this in cocoa!
  208475. }
  208476. #else
  208477. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208478. const OpenGLPixelFormat& pixelFormat,
  208479. const OpenGLContext* const contextToShareWith)
  208480. {
  208481. return 0;
  208482. }
  208483. void juce_glViewport (const int w, const int h)
  208484. {
  208485. //glViewport (0, 0, w, h);
  208486. }
  208487. #endif
  208488. #endif
  208489. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208490. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208491. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208492. // compiled on its own).
  208493. #if JUCE_INCLUDED_FILE
  208494. class JuceMainMenuHandler;
  208495. END_JUCE_NAMESPACE
  208496. using namespace JUCE_NAMESPACE;
  208497. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208498. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208499. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208500. #else
  208501. @interface JuceMenuCallback : NSObject
  208502. #endif
  208503. {
  208504. JuceMainMenuHandler* owner;
  208505. }
  208506. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208507. - (void) dealloc;
  208508. - (void) menuItemInvoked: (id) menu;
  208509. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208510. @end
  208511. BEGIN_JUCE_NAMESPACE
  208512. class JuceMainMenuHandler : private MenuBarModelListener,
  208513. private DeletedAtShutdown
  208514. {
  208515. public:
  208516. static JuceMainMenuHandler* instance;
  208517. JuceMainMenuHandler()
  208518. : currentModel (0),
  208519. lastUpdateTime (0)
  208520. {
  208521. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208522. }
  208523. ~JuceMainMenuHandler()
  208524. {
  208525. setMenu (0);
  208526. jassert (instance == this);
  208527. instance = 0;
  208528. [callback release];
  208529. }
  208530. void setMenu (MenuBarModel* const newMenuBarModel)
  208531. {
  208532. if (currentModel != newMenuBarModel)
  208533. {
  208534. if (currentModel != 0)
  208535. currentModel->removeListener (this);
  208536. currentModel = newMenuBarModel;
  208537. if (currentModel != 0)
  208538. currentModel->addListener (this);
  208539. menuBarItemsChanged (0);
  208540. }
  208541. }
  208542. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208543. const String& name, const int menuId, const int tag)
  208544. {
  208545. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208546. action: nil
  208547. keyEquivalent: @""];
  208548. [item setTag: tag];
  208549. NSMenu* sub = createMenu (child, name, menuId, tag);
  208550. [parent setSubmenu: sub forItem: item];
  208551. [sub setAutoenablesItems: false];
  208552. [sub release];
  208553. }
  208554. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208555. const String& name, const int menuId, const int tag)
  208556. {
  208557. [parentItem setTag: tag];
  208558. NSMenu* menu = [parentItem submenu];
  208559. [menu setTitle: juceStringToNS (name)];
  208560. while ([menu numberOfItems] > 0)
  208561. [menu removeItemAtIndex: 0];
  208562. PopupMenu::MenuItemIterator iter (menuToCopy);
  208563. while (iter.next())
  208564. addMenuItem (iter, menu, menuId, tag);
  208565. [menu setAutoenablesItems: false];
  208566. [menu update];
  208567. }
  208568. void menuBarItemsChanged (MenuBarModel*)
  208569. {
  208570. lastUpdateTime = Time::getMillisecondCounter();
  208571. StringArray menuNames;
  208572. if (currentModel != 0)
  208573. menuNames = currentModel->getMenuBarNames();
  208574. NSMenu* menuBar = [NSApp mainMenu];
  208575. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208576. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208577. int menuId = 1;
  208578. for (int i = 0; i < menuNames.size(); ++i)
  208579. {
  208580. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208581. if (i >= [menuBar numberOfItems] - 1)
  208582. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208583. else
  208584. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208585. }
  208586. }
  208587. static void flashMenuBar (NSMenu* menu)
  208588. {
  208589. [menu retain];
  208590. const unichar f35Key = NSF35FunctionKey;
  208591. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208592. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208593. action: nil
  208594. keyEquivalent: f35String];
  208595. [item setTarget: nil];
  208596. [menu insertItem: item atIndex: [menu numberOfItems]];
  208597. [item release];
  208598. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208599. location: NSZeroPoint
  208600. modifierFlags: NSCommandKeyMask
  208601. timestamp: 0
  208602. windowNumber: 0
  208603. context: [NSGraphicsContext currentContext]
  208604. characters: f35String
  208605. charactersIgnoringModifiers: f35String
  208606. isARepeat: NO
  208607. keyCode: 0];
  208608. [menu performKeyEquivalent: f35Event];
  208609. if ([menu indexOfItem: item] >= 0)
  208610. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208611. [menu release];
  208612. }
  208613. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208614. {
  208615. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208616. {
  208617. NSMenuItem* m = [menu itemAtIndex: i];
  208618. if ([m tag] == info.commandID)
  208619. return m;
  208620. if ([m submenu] != 0)
  208621. {
  208622. NSMenuItem* found = findMenuItem ([m submenu], info);
  208623. if (found != 0)
  208624. return found;
  208625. }
  208626. }
  208627. return 0;
  208628. }
  208629. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208630. {
  208631. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208632. if (item != 0)
  208633. flashMenuBar ([item menu]);
  208634. }
  208635. void updateMenus()
  208636. {
  208637. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208638. menuBarItemsChanged (0);
  208639. }
  208640. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208641. {
  208642. if (currentModel != 0)
  208643. {
  208644. if (commandManager != 0)
  208645. {
  208646. ApplicationCommandTarget::InvocationInfo info (commandId);
  208647. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208648. commandManager->invoke (info, true);
  208649. }
  208650. currentModel->menuItemSelected (commandId, topLevelIndex);
  208651. }
  208652. }
  208653. MenuBarModel* currentModel;
  208654. uint32 lastUpdateTime;
  208655. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208656. const int topLevelMenuId, const int topLevelIndex)
  208657. {
  208658. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf (T("<end>"), false, true));
  208659. if (text == 0)
  208660. text = @"";
  208661. if (iter.isSeparator)
  208662. {
  208663. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208664. }
  208665. else if (iter.isSectionHeader)
  208666. {
  208667. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208668. action: nil
  208669. keyEquivalent: @""];
  208670. [item setEnabled: false];
  208671. }
  208672. else if (iter.subMenu != 0)
  208673. {
  208674. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208675. action: nil
  208676. keyEquivalent: @""];
  208677. [item setTag: iter.itemId];
  208678. [item setEnabled: iter.isEnabled];
  208679. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208680. [sub setDelegate: nil];
  208681. [menuToAddTo setSubmenu: sub forItem: item];
  208682. [sub release];
  208683. }
  208684. else
  208685. {
  208686. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208687. action: @selector (menuItemInvoked:)
  208688. keyEquivalent: @""];
  208689. [item setTag: iter.itemId];
  208690. [item setEnabled: iter.isEnabled];
  208691. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208692. [item setTarget: (id) callback];
  208693. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208694. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208695. [item setRepresentedObject: info];
  208696. if (iter.commandManager != 0)
  208697. {
  208698. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208699. ->getKeyPressesAssignedToCommand (iter.itemId));
  208700. if (keyPresses.size() > 0)
  208701. {
  208702. const KeyPress& kp = keyPresses.getReference(0);
  208703. juce_wchar key = kp.getTextCharacter();
  208704. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208705. key = NSBackspaceCharacter;
  208706. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208707. key = NSDeleteCharacter;
  208708. else if (key == 0)
  208709. key = (juce_wchar) kp.getKeyCode();
  208710. unsigned int mods = 0;
  208711. if (kp.getModifiers().isShiftDown())
  208712. mods |= NSShiftKeyMask;
  208713. if (kp.getModifiers().isCtrlDown())
  208714. mods |= NSControlKeyMask;
  208715. if (kp.getModifiers().isAltDown())
  208716. mods |= NSAlternateKeyMask;
  208717. if (kp.getModifiers().isCommandDown())
  208718. mods |= NSCommandKeyMask;
  208719. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208720. [item setKeyEquivalentModifierMask: mods];
  208721. }
  208722. }
  208723. }
  208724. }
  208725. JuceMenuCallback* callback;
  208726. private:
  208727. NSMenu* createMenu (const PopupMenu menu,
  208728. const String& menuName,
  208729. const int topLevelMenuId,
  208730. const int topLevelIndex)
  208731. {
  208732. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208733. [m setAutoenablesItems: false];
  208734. [m setDelegate: callback];
  208735. PopupMenu::MenuItemIterator iter (menu);
  208736. while (iter.next())
  208737. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208738. [m update];
  208739. return m;
  208740. }
  208741. };
  208742. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208743. END_JUCE_NAMESPACE
  208744. @implementation JuceMenuCallback
  208745. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208746. {
  208747. [super init];
  208748. owner = owner_;
  208749. return self;
  208750. }
  208751. - (void) dealloc
  208752. {
  208753. [super dealloc];
  208754. }
  208755. - (void) menuItemInvoked: (id) menu
  208756. {
  208757. NSMenuItem* item = (NSMenuItem*) menu;
  208758. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208759. {
  208760. // 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
  208761. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208762. // into the focused component and let it trigger the menu item indirectly.
  208763. NSEvent* e = [NSApp currentEvent];
  208764. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208765. {
  208766. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->isValidComponent())
  208767. {
  208768. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208769. if (peer != 0)
  208770. {
  208771. if ([e type] == NSKeyDown)
  208772. peer->redirectKeyDown (e);
  208773. else
  208774. peer->redirectKeyUp (e);
  208775. return;
  208776. }
  208777. }
  208778. }
  208779. NSArray* info = (NSArray*) [item representedObject];
  208780. owner->invoke ((int) [item tag],
  208781. (ApplicationCommandManager*) (pointer_sized_int)
  208782. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208783. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208784. }
  208785. }
  208786. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208787. {
  208788. if (JuceMainMenuHandler::instance != 0)
  208789. JuceMainMenuHandler::instance->updateMenus();
  208790. }
  208791. @end
  208792. BEGIN_JUCE_NAMESPACE
  208793. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208794. const PopupMenu* extraItems)
  208795. {
  208796. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208797. {
  208798. PopupMenu::MenuItemIterator iter (*extraItems);
  208799. while (iter.next())
  208800. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208801. [menu addItem: [NSMenuItem separatorItem]];
  208802. }
  208803. NSMenuItem* item;
  208804. // Services...
  208805. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208806. action: nil keyEquivalent: @""];
  208807. [menu addItem: item];
  208808. [item release];
  208809. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208810. [menu setSubmenu: servicesMenu forItem: item];
  208811. [NSApp setServicesMenu: servicesMenu];
  208812. [servicesMenu release];
  208813. [menu addItem: [NSMenuItem separatorItem]];
  208814. // Hide + Show stuff...
  208815. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208816. action: @selector (hide:) keyEquivalent: @"h"];
  208817. [item setTarget: NSApp];
  208818. [menu addItem: item];
  208819. [item release];
  208820. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208821. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208822. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208823. [item setTarget: NSApp];
  208824. [menu addItem: item];
  208825. [item release];
  208826. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208827. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208828. [item setTarget: NSApp];
  208829. [menu addItem: item];
  208830. [item release];
  208831. [menu addItem: [NSMenuItem separatorItem]];
  208832. // Quit item....
  208833. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208834. action: @selector (terminate:) keyEquivalent: @"q"];
  208835. [item setTarget: NSApp];
  208836. [menu addItem: item];
  208837. [item release];
  208838. return menu;
  208839. }
  208840. // Since our app has no NIB, this initialises a standard app menu...
  208841. static void rebuildMainMenu (const PopupMenu* extraItems)
  208842. {
  208843. // this can't be used in a plugin!
  208844. jassert (JUCEApplication::getInstance() != 0);
  208845. if (JUCEApplication::getInstance() != 0)
  208846. {
  208847. const ScopedAutoReleasePool pool;
  208848. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208849. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208850. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208851. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208852. [mainMenu setSubmenu: appMenu forItem: item];
  208853. [NSApp setMainMenu: mainMenu];
  208854. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208855. [appMenu release];
  208856. [mainMenu release];
  208857. }
  208858. }
  208859. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208860. const PopupMenu* extraAppleMenuItems)
  208861. {
  208862. if (getMacMainMenu() != newMenuBarModel)
  208863. {
  208864. const ScopedAutoReleasePool pool;
  208865. if (newMenuBarModel == 0)
  208866. {
  208867. delete JuceMainMenuHandler::instance;
  208868. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208869. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208870. extraAppleMenuItems = 0;
  208871. }
  208872. else
  208873. {
  208874. if (JuceMainMenuHandler::instance == 0)
  208875. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208876. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208877. }
  208878. }
  208879. rebuildMainMenu (extraAppleMenuItems);
  208880. if (newMenuBarModel != 0)
  208881. newMenuBarModel->menuItemsChanged();
  208882. }
  208883. MenuBarModel* MenuBarModel::getMacMainMenu()
  208884. {
  208885. return JuceMainMenuHandler::instance != 0
  208886. ? JuceMainMenuHandler::instance->currentModel : 0;
  208887. }
  208888. void initialiseMainMenu()
  208889. {
  208890. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208891. rebuildMainMenu (0);
  208892. }
  208893. #endif
  208894. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208895. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208896. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208897. // compiled on its own).
  208898. #if JUCE_INCLUDED_FILE
  208899. #if JUCE_MAC
  208900. END_JUCE_NAMESPACE
  208901. using namespace JUCE_NAMESPACE;
  208902. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208903. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208904. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208905. #else
  208906. @interface JuceFileChooserDelegate : NSObject
  208907. #endif
  208908. {
  208909. StringArray* filters;
  208910. }
  208911. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208912. - (void) dealloc;
  208913. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208914. @end
  208915. @implementation JuceFileChooserDelegate
  208916. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  208917. {
  208918. [super init];
  208919. filters = filters_;
  208920. return self;
  208921. }
  208922. - (void) dealloc
  208923. {
  208924. delete filters;
  208925. [super dealloc];
  208926. }
  208927. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  208928. {
  208929. const File f (nsStringToJuce (filename));
  208930. for (int i = filters->size(); --i >= 0;)
  208931. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  208932. return true;
  208933. return f.isDirectory();
  208934. }
  208935. @end
  208936. BEGIN_JUCE_NAMESPACE
  208937. void FileChooser::showPlatformDialog (Array<File>& results,
  208938. const String& title,
  208939. const File& currentFileOrDirectory,
  208940. const String& filter,
  208941. bool selectsDirectory,
  208942. bool selectsFiles,
  208943. bool isSaveDialogue,
  208944. bool warnAboutOverwritingExistingFiles,
  208945. bool selectMultipleFiles,
  208946. FilePreviewComponent* extraInfoComponent)
  208947. {
  208948. const ScopedAutoReleasePool pool;
  208949. StringArray* filters = new StringArray();
  208950. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  208951. filters->trim();
  208952. filters->removeEmptyStrings();
  208953. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  208954. [delegate autorelease];
  208955. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  208956. : [NSOpenPanel openPanel];
  208957. [panel setTitle: juceStringToNS (title)];
  208958. if (! isSaveDialogue)
  208959. {
  208960. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208961. [openPanel setCanChooseDirectories: selectsDirectory];
  208962. [openPanel setCanChooseFiles: selectsFiles];
  208963. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  208964. }
  208965. [panel setDelegate: delegate];
  208966. if (isSaveDialogue || selectsDirectory)
  208967. [panel setCanCreateDirectories: YES];
  208968. String directory, filename;
  208969. if (currentFileOrDirectory.isDirectory())
  208970. {
  208971. directory = currentFileOrDirectory.getFullPathName();
  208972. }
  208973. else
  208974. {
  208975. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  208976. filename = currentFileOrDirectory.getFileName();
  208977. }
  208978. if ([panel runModalForDirectory: juceStringToNS (directory)
  208979. file: juceStringToNS (filename)]
  208980. == NSOKButton)
  208981. {
  208982. if (isSaveDialogue)
  208983. {
  208984. results.add (File (nsStringToJuce ([panel filename])));
  208985. }
  208986. else
  208987. {
  208988. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208989. NSArray* urls = [openPanel filenames];
  208990. for (unsigned int i = 0; i < [urls count]; ++i)
  208991. {
  208992. NSString* f = [urls objectAtIndex: i];
  208993. results.add (File (nsStringToJuce (f)));
  208994. }
  208995. }
  208996. }
  208997. [panel setDelegate: nil];
  208998. }
  208999. #else
  209000. void FileChooser::showPlatformDialog (Array<File>& results,
  209001. const String& title,
  209002. const File& currentFileOrDirectory,
  209003. const String& filter,
  209004. bool selectsDirectory,
  209005. bool selectsFiles,
  209006. bool isSaveDialogue,
  209007. bool warnAboutOverwritingExistingFiles,
  209008. bool selectMultipleFiles,
  209009. FilePreviewComponent* extraInfoComponent)
  209010. {
  209011. const ScopedAutoReleasePool pool;
  209012. jassertfalse //xxx to do
  209013. }
  209014. #endif
  209015. #endif
  209016. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  209017. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209018. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209019. // compiled on its own).
  209020. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  209021. #define theMovie ((QTMovie*) movie)
  209022. QuickTimeMovieComponent::QuickTimeMovieComponent()
  209023. : movie (0)
  209024. {
  209025. setOpaque (true);
  209026. setVisible (true);
  209027. QTMovieView* view = [[QTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  209028. setView (view);
  209029. }
  209030. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  209031. {
  209032. closeMovie();
  209033. setView (0);
  209034. }
  209035. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  209036. {
  209037. return true;
  209038. }
  209039. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  209040. {
  209041. // unfortunately, QTMovie objects can only be created on the main thread..
  209042. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209043. QTMovie* movie = 0;
  209044. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  209045. if (fin != 0)
  209046. {
  209047. movieFile = fin->getFile();
  209048. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  209049. error: nil];
  209050. }
  209051. else
  209052. {
  209053. MemoryBlock temp;
  209054. movieStream->readIntoMemoryBlock (temp);
  209055. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  209056. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  209057. {
  209058. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  209059. length: temp.getSize()]
  209060. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  209061. MIMEType: @""]
  209062. error: nil];
  209063. if (movie != 0)
  209064. break;
  209065. }
  209066. }
  209067. return movie;
  209068. }
  209069. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209070. const bool isControllerVisible_)
  209071. {
  209072. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209073. }
  209074. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209075. const bool controllerVisible_)
  209076. {
  209077. closeMovie();
  209078. if (getPeer() == 0)
  209079. {
  209080. // To open a movie, this component must be visible inside a functioning window, so that
  209081. // the QT control can be assigned to the window.
  209082. jassertfalse
  209083. return false;
  209084. }
  209085. movie = openMovieFromStream (movieStream, movieFile);
  209086. [theMovie retain];
  209087. QTMovieView* view = (QTMovieView*) getView();
  209088. [view setMovie: theMovie];
  209089. [view setControllerVisible: controllerVisible_];
  209090. setLooping (looping);
  209091. return movie != nil;
  209092. }
  209093. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209094. const bool isControllerVisible_)
  209095. {
  209096. // unfortunately, QTMovie objects can only be created on the main thread..
  209097. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209098. closeMovie();
  209099. if (getPeer() == 0)
  209100. {
  209101. // To open a movie, this component must be visible inside a functioning window, so that
  209102. // the QT control can be assigned to the window.
  209103. jassertfalse
  209104. return false;
  209105. }
  209106. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209107. NSError* err;
  209108. if ([QTMovie canInitWithURL: url])
  209109. movie = [QTMovie movieWithURL: url error: &err];
  209110. [theMovie retain];
  209111. QTMovieView* view = (QTMovieView*) getView();
  209112. [view setMovie: theMovie];
  209113. [view setControllerVisible: controllerVisible];
  209114. setLooping (looping);
  209115. return movie != nil;
  209116. }
  209117. void QuickTimeMovieComponent::closeMovie()
  209118. {
  209119. stop();
  209120. QTMovieView* view = (QTMovieView*) getView();
  209121. [view setMovie: nil];
  209122. [theMovie release];
  209123. movie = 0;
  209124. movieFile = File::nonexistent;
  209125. }
  209126. bool QuickTimeMovieComponent::isMovieOpen() const
  209127. {
  209128. return movie != nil;
  209129. }
  209130. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209131. {
  209132. return movieFile;
  209133. }
  209134. void QuickTimeMovieComponent::play()
  209135. {
  209136. [theMovie play];
  209137. }
  209138. void QuickTimeMovieComponent::stop()
  209139. {
  209140. [theMovie stop];
  209141. }
  209142. bool QuickTimeMovieComponent::isPlaying() const
  209143. {
  209144. return movie != 0 && [theMovie rate] != 0;
  209145. }
  209146. void QuickTimeMovieComponent::setPosition (const double seconds)
  209147. {
  209148. if (movie != 0)
  209149. {
  209150. QTTime t;
  209151. t.timeValue = (uint64) (100000.0 * seconds);
  209152. t.timeScale = 100000;
  209153. t.flags = 0;
  209154. [theMovie setCurrentTime: t];
  209155. }
  209156. }
  209157. double QuickTimeMovieComponent::getPosition() const
  209158. {
  209159. if (movie == 0)
  209160. return 0.0;
  209161. QTTime t = [theMovie currentTime];
  209162. return t.timeValue / (double) t.timeScale;
  209163. }
  209164. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209165. {
  209166. [theMovie setRate: newSpeed];
  209167. }
  209168. double QuickTimeMovieComponent::getMovieDuration() const
  209169. {
  209170. if (movie == 0)
  209171. return 0.0;
  209172. QTTime t = [theMovie duration];
  209173. return t.timeValue / (double) t.timeScale;
  209174. }
  209175. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209176. {
  209177. looping = shouldLoop;
  209178. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209179. forKey: QTMovieLoopsAttribute];
  209180. }
  209181. bool QuickTimeMovieComponent::isLooping() const
  209182. {
  209183. return looping;
  209184. }
  209185. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209186. {
  209187. [theMovie setVolume: newVolume];
  209188. }
  209189. float QuickTimeMovieComponent::getMovieVolume() const
  209190. {
  209191. return movie != 0 ? [theMovie volume] : 0.0f;
  209192. }
  209193. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209194. {
  209195. width = 0;
  209196. height = 0;
  209197. if (movie != 0)
  209198. {
  209199. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209200. width = (int) s.width;
  209201. height = (int) s.height;
  209202. }
  209203. }
  209204. void QuickTimeMovieComponent::paint (Graphics& g)
  209205. {
  209206. if (movie == 0)
  209207. g.fillAll (Colours::black);
  209208. }
  209209. bool QuickTimeMovieComponent::isControllerVisible() const
  209210. {
  209211. return controllerVisible;
  209212. }
  209213. void QuickTimeMovieComponent::goToStart()
  209214. {
  209215. setPosition (0.0);
  209216. }
  209217. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209218. const RectanglePlacement& placement)
  209219. {
  209220. int normalWidth, normalHeight;
  209221. getMovieNormalSize (normalWidth, normalHeight);
  209222. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209223. {
  209224. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209225. placement.applyTo (x, y, w, h,
  209226. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209227. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209228. if (w > 0 && h > 0)
  209229. {
  209230. setBounds (roundToInt (x), roundToInt (y),
  209231. roundToInt (w), roundToInt (h));
  209232. }
  209233. }
  209234. else
  209235. {
  209236. setBounds (spaceToFitWithin);
  209237. }
  209238. }
  209239. #if ! (JUCE_MAC && JUCE_64BIT)
  209240. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209241. {
  209242. if (movieStream == 0)
  209243. return false;
  209244. File file;
  209245. QTMovie* movie = openMovieFromStream (movieStream, file);
  209246. if (movie != nil)
  209247. result = [movie quickTimeMovie];
  209248. return movie != nil;
  209249. }
  209250. #endif
  209251. #endif
  209252. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209253. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209254. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209255. // compiled on its own).
  209256. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209257. END_JUCE_NAMESPACE
  209258. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209259. @interface OpenDiskDevice : NSObject
  209260. {
  209261. DRDevice* device;
  209262. NSMutableArray* tracks;
  209263. }
  209264. - (OpenDiskDevice*) initWithDevice: (DRDevice*) device;
  209265. - (void) dealloc;
  209266. - (bool) isDiskPresent;
  209267. - (int) getNumAvailableAudioBlocks;
  209268. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209269. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209270. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting;
  209271. @end
  209272. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209273. @interface AudioTrackProducer : NSObject
  209274. {
  209275. JUCE_NAMESPACE::AudioSource* source;
  209276. int readPosition, lengthInFrames;
  209277. }
  209278. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209279. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209280. - (void) dealloc;
  209281. - (void) setupTrackProperties: (DRTrack*) track;
  209282. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209283. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209284. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209285. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209286. toMedia:(NSDictionary*)mediaInfo;
  209287. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209288. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209289. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209290. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209291. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209292. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209293. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209294. ioFlags:(uint32_t*)flags;
  209295. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209296. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209297. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209298. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209299. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209300. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209301. ioFlags:(uint32_t*)flags;
  209302. @end
  209303. @implementation OpenDiskDevice
  209304. - (OpenDiskDevice*) initWithDevice: (DRDevice*) device_
  209305. {
  209306. [super init];
  209307. device = device_;
  209308. tracks = [[NSMutableArray alloc] init];
  209309. return self;
  209310. }
  209311. - (void) dealloc
  209312. {
  209313. [tracks release];
  209314. [super dealloc];
  209315. }
  209316. - (bool) isDiskPresent
  209317. {
  209318. return [device isValid]
  209319. && [[[device status] objectForKey: DRDeviceMediaStateKey]
  209320. isEqualTo: DRDeviceMediaStateMediaPresent];
  209321. }
  209322. - (int) getNumAvailableAudioBlocks
  209323. {
  209324. return [[[[device status] objectForKey: DRDeviceMediaInfoKey]
  209325. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209326. }
  209327. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209328. {
  209329. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209330. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209331. [p setupTrackProperties: t];
  209332. [tracks addObject: t];
  209333. [t release];
  209334. [p release];
  209335. }
  209336. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209337. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting
  209338. {
  209339. DRBurn* burn = [DRBurn burnForDevice: device];
  209340. if (! [device acquireExclusiveAccess])
  209341. {
  209342. *error = "Couldn't open or write to the CD device";
  209343. return;
  209344. }
  209345. [device acquireMediaReservation];
  209346. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209347. [d autorelease];
  209348. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209349. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209350. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount)
  209351. forKey: DRBurnCompletionActionKey];
  209352. [burn setProperties: d];
  209353. [burn writeLayout: tracks];
  209354. for (;;)
  209355. {
  209356. JUCE_NAMESPACE::Thread::sleep (300);
  209357. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209358. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209359. {
  209360. [burn abort];
  209361. *error = "User cancelled the write operation";
  209362. break;
  209363. }
  209364. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209365. {
  209366. *error = "Write operation failed";
  209367. break;
  209368. }
  209369. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209370. {
  209371. break;
  209372. }
  209373. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209374. objectForKey: DRErrorStatusErrorStringKey];
  209375. if ([err length] > 0)
  209376. {
  209377. *error = JUCE_NAMESPACE::String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [err UTF8String]);
  209378. break;
  209379. }
  209380. }
  209381. [device releaseMediaReservation];
  209382. [device releaseExclusiveAccess];
  209383. }
  209384. @end
  209385. @implementation AudioTrackProducer
  209386. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209387. {
  209388. lengthInFrames = lengthInFrames_;
  209389. readPosition = 0;
  209390. return self;
  209391. }
  209392. - (void) setupTrackProperties: (DRTrack*) track
  209393. {
  209394. NSMutableDictionary* p = [[track properties] mutableCopy];
  209395. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209396. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209397. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209398. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209399. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209400. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209401. [track setProperties: p];
  209402. [p release];
  209403. }
  209404. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209405. {
  209406. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209407. if (s != nil)
  209408. s->source = source_;
  209409. return s;
  209410. }
  209411. - (void) dealloc
  209412. {
  209413. if (source != 0)
  209414. {
  209415. source->releaseResources();
  209416. delete source;
  209417. }
  209418. [super dealloc];
  209419. }
  209420. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209421. {
  209422. }
  209423. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209424. {
  209425. return true;
  209426. }
  209427. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209428. {
  209429. return lengthInFrames;
  209430. }
  209431. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209432. toMedia: (NSDictionary*) mediaInfo
  209433. {
  209434. if (source != 0)
  209435. source->prepareToPlay (44100 / 75, 44100);
  209436. readPosition = 0;
  209437. return true;
  209438. }
  209439. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209440. {
  209441. if (source != 0)
  209442. source->prepareToPlay (44100 / 75, 44100);
  209443. return true;
  209444. }
  209445. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209446. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209447. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209448. {
  209449. if (source != 0)
  209450. {
  209451. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209452. if (numSamples > 0)
  209453. {
  209454. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209455. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209456. info.buffer = &tempBuffer;
  209457. info.startSample = 0;
  209458. info.numSamples = numSamples;
  209459. source->getNextAudioBlock (info);
  209460. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209461. buffer, numSamples, 4);
  209462. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209463. buffer + 2, numSamples, 4);
  209464. readPosition += numSamples;
  209465. }
  209466. return numSamples * 4;
  209467. }
  209468. return 0;
  209469. }
  209470. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209471. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209472. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209473. ioFlags: (uint32_t*) flags
  209474. {
  209475. zeromem (buffer, bufferLength);
  209476. return bufferLength;
  209477. }
  209478. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209479. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209480. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209481. {
  209482. return true;
  209483. }
  209484. @end
  209485. BEGIN_JUCE_NAMESPACE
  209486. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209487. : internal (0)
  209488. {
  209489. OpenDiskDevice* dev = [[OpenDiskDevice alloc] initWithDevice: [[DRDevice devices] objectAtIndex: deviceIndex]];
  209490. internal = (void*) dev;
  209491. }
  209492. AudioCDBurner::~AudioCDBurner()
  209493. {
  209494. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209495. if (dev != 0)
  209496. [dev release];
  209497. }
  209498. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209499. {
  209500. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209501. if (b->internal == 0)
  209502. b = 0;
  209503. return b.release();
  209504. }
  209505. static NSArray* findDiskBurnerDevices()
  209506. {
  209507. NSMutableArray* results = [NSMutableArray array];
  209508. NSArray* devs = [DRDevice devices];
  209509. if (devs != 0)
  209510. {
  209511. int num = [devs count];
  209512. int i;
  209513. for (i = 0; i < num; ++i)
  209514. {
  209515. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209516. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209517. if (name != nil)
  209518. [results addObject: name];
  209519. }
  209520. }
  209521. return results;
  209522. }
  209523. const StringArray AudioCDBurner::findAvailableDevices()
  209524. {
  209525. NSArray* names = findDiskBurnerDevices();
  209526. StringArray s;
  209527. for (unsigned int i = 0; i < [names count]; ++i)
  209528. s.add (String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [[names objectAtIndex: i] UTF8String]));
  209529. return s;
  209530. }
  209531. bool AudioCDBurner::isDiskPresent() const
  209532. {
  209533. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209534. return dev != 0 && [dev isDiskPresent];
  209535. }
  209536. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209537. {
  209538. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209539. return [dev getNumAvailableAudioBlocks];
  209540. }
  209541. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209542. {
  209543. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209544. if (dev != 0)
  209545. {
  209546. [dev addSourceTrack: source numSamples: numSamps];
  209547. return true;
  209548. }
  209549. return false;
  209550. }
  209551. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209552. const bool ejectDiscAfterwards,
  209553. const bool peformFakeBurnForTesting)
  209554. {
  209555. String error ("Couldn't open or write to the CD device");
  209556. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209557. if (dev != 0)
  209558. {
  209559. error = String::empty;
  209560. [dev burn: listener
  209561. errorString: &error
  209562. ejectAfterwards: ejectDiscAfterwards
  209563. isFake: peformFakeBurnForTesting];
  209564. }
  209565. return error;
  209566. }
  209567. void AudioCDReader::ejectDisk()
  209568. {
  209569. const ScopedAutoReleasePool p;
  209570. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209571. }
  209572. #endif
  209573. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209574. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209575. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209576. // compiled on its own).
  209577. #if JUCE_INCLUDED_FILE
  209578. struct CallbackMessagePayload
  209579. {
  209580. MessageCallbackFunction* function;
  209581. void* parameter;
  209582. void* volatile result;
  209583. bool volatile hasBeenExecuted;
  209584. };
  209585. class AppDelegateRedirector
  209586. {
  209587. public:
  209588. AppDelegateRedirector()
  209589. {
  209590. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209591. runLoop = CFRunLoopGetMain();
  209592. #else
  209593. runLoop = CFRunLoopGetCurrent();
  209594. #endif
  209595. CFRunLoopSourceContext sourceContext;
  209596. zerostruct (sourceContext);
  209597. sourceContext.info = this;
  209598. sourceContext.perform = runLoopSourceCallback;
  209599. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209600. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209601. }
  209602. virtual ~AppDelegateRedirector()
  209603. {
  209604. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209605. CFRunLoopSourceInvalidate (runLoopSource);
  209606. CFRelease (runLoopSource);
  209607. while (messages.size() > 0)
  209608. delete ((Message*) messages.remove(0));
  209609. }
  209610. virtual NSApplicationTerminateReply shouldTerminate()
  209611. {
  209612. if (JUCEApplication::getInstance() != 0)
  209613. {
  209614. JUCEApplication::getInstance()->systemRequestedQuit();
  209615. return NSTerminateCancel;
  209616. }
  209617. return NSTerminateNow;
  209618. }
  209619. virtual BOOL openFile (const NSString* filename)
  209620. {
  209621. if (JUCEApplication::getInstance() != 0)
  209622. {
  209623. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209624. return YES;
  209625. }
  209626. return NO;
  209627. }
  209628. virtual void openFiles (NSArray* filenames)
  209629. {
  209630. StringArray files;
  209631. for (unsigned int i = 0; i < [filenames count]; ++i)
  209632. {
  209633. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209634. if (filename.containsChar (T(' ')))
  209635. filename = filename.quoted('"');
  209636. files.add (filename);
  209637. }
  209638. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209639. {
  209640. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
  209641. }
  209642. }
  209643. virtual void focusChanged()
  209644. {
  209645. juce_HandleProcessFocusChange();
  209646. }
  209647. virtual void performCallback (CallbackMessagePayload* pl)
  209648. {
  209649. pl->result = (*pl->function) (pl->parameter);
  209650. pl->hasBeenExecuted = true;
  209651. }
  209652. virtual void deleteSelf()
  209653. {
  209654. delete this;
  209655. }
  209656. void postMessage (void* m)
  209657. {
  209658. messages.add (m);
  209659. CFRunLoopSourceSignal (runLoopSource);
  209660. CFRunLoopWakeUp (runLoop);
  209661. }
  209662. private:
  209663. CFRunLoopRef runLoop;
  209664. CFRunLoopSourceRef runLoopSource;
  209665. Array <void*, CriticalSection> messages;
  209666. void runLoopCallback()
  209667. {
  209668. int numDispatched = 0;
  209669. do
  209670. {
  209671. void* const nextMessage = messages.remove (0);
  209672. if (nextMessage == 0)
  209673. return;
  209674. const ScopedAutoReleasePool pool;
  209675. MessageManager::getInstance()->deliverMessage (nextMessage);
  209676. } while (++numDispatched <= 4);
  209677. CFRunLoopSourceSignal (runLoopSource);
  209678. CFRunLoopWakeUp (runLoop);
  209679. }
  209680. static void runLoopSourceCallback (void* info)
  209681. {
  209682. ((AppDelegateRedirector*) info)->runLoopCallback();
  209683. }
  209684. };
  209685. END_JUCE_NAMESPACE
  209686. using namespace JUCE_NAMESPACE;
  209687. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209688. @interface JuceAppDelegate : NSObject
  209689. {
  209690. @private
  209691. id oldDelegate;
  209692. @public
  209693. AppDelegateRedirector* redirector;
  209694. }
  209695. - (JuceAppDelegate*) init;
  209696. - (void) dealloc;
  209697. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209698. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209699. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209700. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209701. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209702. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209703. - (void) performCallback: (id) info;
  209704. - (void) dummyMethod;
  209705. @end
  209706. @implementation JuceAppDelegate
  209707. - (JuceAppDelegate*) init
  209708. {
  209709. [super init];
  209710. redirector = new AppDelegateRedirector();
  209711. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209712. if (JUCEApplication::getInstance() != 0)
  209713. {
  209714. oldDelegate = [NSApp delegate];
  209715. [NSApp setDelegate: self];
  209716. }
  209717. else
  209718. {
  209719. oldDelegate = 0;
  209720. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209721. name: NSApplicationDidResignActiveNotification object: NSApp];
  209722. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209723. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209724. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209725. name: NSApplicationWillUnhideNotification object: NSApp];
  209726. }
  209727. return self;
  209728. }
  209729. - (void) dealloc
  209730. {
  209731. if (oldDelegate != 0)
  209732. [NSApp setDelegate: oldDelegate];
  209733. redirector->deleteSelf();
  209734. [super dealloc];
  209735. }
  209736. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209737. {
  209738. return redirector->shouldTerminate();
  209739. }
  209740. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209741. {
  209742. return redirector->openFile (filename);
  209743. }
  209744. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209745. {
  209746. return redirector->openFiles (filenames);
  209747. }
  209748. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209749. {
  209750. redirector->focusChanged();
  209751. }
  209752. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209753. {
  209754. redirector->focusChanged();
  209755. }
  209756. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209757. {
  209758. redirector->focusChanged();
  209759. }
  209760. - (void) performCallback: (id) info
  209761. {
  209762. if ([info isKindOfClass: [NSData class]])
  209763. {
  209764. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  209765. if (pl != 0)
  209766. redirector->performCallback (pl);
  209767. }
  209768. else
  209769. {
  209770. jassertfalse // should never get here!
  209771. }
  209772. }
  209773. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209774. @end
  209775. BEGIN_JUCE_NAMESPACE
  209776. static JuceAppDelegate* juceAppDelegate = 0;
  209777. void MessageManager::runDispatchLoop()
  209778. {
  209779. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209780. {
  209781. const ScopedAutoReleasePool pool;
  209782. // must only be called by the message thread!
  209783. jassert (isThisTheMessageThread());
  209784. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209785. @try
  209786. {
  209787. [NSApp run];
  209788. }
  209789. @catch (NSException* e)
  209790. {
  209791. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209792. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209793. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209794. }
  209795. @finally
  209796. {
  209797. }
  209798. #else
  209799. [NSApp run];
  209800. #endif
  209801. }
  209802. }
  209803. void MessageManager::stopDispatchLoop()
  209804. {
  209805. quitMessagePosted = true;
  209806. [NSApp stop: nil];
  209807. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  209808. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  209809. }
  209810. static bool isEventBlockedByModalComps (NSEvent* e)
  209811. {
  209812. if (Component::getNumCurrentlyModalComponents() == 0)
  209813. return false;
  209814. NSWindow* const w = [e window];
  209815. if (w == 0 || [w worksWhenModal])
  209816. return false;
  209817. bool isKey = false, isInputAttempt = false;
  209818. switch ([e type])
  209819. {
  209820. case NSKeyDown:
  209821. case NSKeyUp:
  209822. isKey = isInputAttempt = true;
  209823. break;
  209824. case NSLeftMouseDown:
  209825. case NSRightMouseDown:
  209826. case NSOtherMouseDown:
  209827. isInputAttempt = true;
  209828. break;
  209829. case NSLeftMouseDragged:
  209830. case NSRightMouseDragged:
  209831. case NSLeftMouseUp:
  209832. case NSRightMouseUp:
  209833. case NSOtherMouseUp:
  209834. case NSOtherMouseDragged:
  209835. if (Component::getComponentUnderMouse() != 0)
  209836. return false;
  209837. break;
  209838. case NSMouseMoved:
  209839. case NSMouseEntered:
  209840. case NSMouseExited:
  209841. case NSCursorUpdate:
  209842. case NSScrollWheel:
  209843. case NSTabletPoint:
  209844. case NSTabletProximity:
  209845. break;
  209846. default:
  209847. return false;
  209848. }
  209849. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  209850. {
  209851. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  209852. NSView* const compView = (NSView*) peer->getNativeHandle();
  209853. if ([compView window] == w)
  209854. {
  209855. if (isKey)
  209856. {
  209857. if (compView == [w firstResponder])
  209858. return false;
  209859. }
  209860. else
  209861. {
  209862. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  209863. [compView bounds]))
  209864. return false;
  209865. }
  209866. }
  209867. }
  209868. if (isInputAttempt)
  209869. {
  209870. if (! [NSApp isActive])
  209871. [NSApp activateIgnoringOtherApps: YES];
  209872. Component* const modal = Component::getCurrentlyModalComponent (0);
  209873. if (modal != 0)
  209874. modal->inputAttemptWhenModal();
  209875. }
  209876. return true;
  209877. }
  209878. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  209879. {
  209880. const ScopedAutoReleasePool pool;
  209881. jassert (isThisTheMessageThread()); // must only be called by the message thread
  209882. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  209883. while (! quitMessagePosted)
  209884. {
  209885. const ScopedAutoReleasePool pool2;
  209886. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  209887. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  209888. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  209889. inMode: NSDefaultRunLoopMode
  209890. dequeue: YES];
  209891. if (e != 0 && ! isEventBlockedByModalComps (e))
  209892. [NSApp sendEvent: e];
  209893. if (Time::getMillisecondCounter() >= endTime)
  209894. break;
  209895. }
  209896. return ! quitMessagePosted;
  209897. }
  209898. void MessageManager::doPlatformSpecificInitialisation()
  209899. {
  209900. if (juceAppDelegate == 0)
  209901. juceAppDelegate = [[JuceAppDelegate alloc] init];
  209902. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  209903. // correctly (needed prior to 10.5)
  209904. if (! [NSThread isMultiThreaded])
  209905. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  209906. toTarget: juceAppDelegate
  209907. withObject: nil];
  209908. initialiseMainMenu();
  209909. }
  209910. void MessageManager::doPlatformSpecificShutdown()
  209911. {
  209912. if (juceAppDelegate != 0)
  209913. {
  209914. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  209915. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  209916. [juceAppDelegate release];
  209917. juceAppDelegate = 0;
  209918. }
  209919. }
  209920. bool juce_postMessageToSystemQueue (void* message)
  209921. {
  209922. juceAppDelegate->redirector->postMessage (message);
  209923. return true;
  209924. }
  209925. void MessageManager::broadcastMessage (const String& value) throw()
  209926. {
  209927. }
  209928. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  209929. void* data)
  209930. {
  209931. if (isThisTheMessageThread())
  209932. {
  209933. return (*callback) (data);
  209934. }
  209935. else
  209936. {
  209937. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  209938. // deadlock because the message manager is blocked from running, so can never
  209939. // call your function..
  209940. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  209941. const ScopedAutoReleasePool pool;
  209942. CallbackMessagePayload cmp;
  209943. cmp.function = callback;
  209944. cmp.parameter = data;
  209945. cmp.result = 0;
  209946. cmp.hasBeenExecuted = false;
  209947. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  209948. withObject: [NSData dataWithBytesNoCopy: &cmp
  209949. length: sizeof (cmp)
  209950. freeWhenDone: NO]
  209951. waitUntilDone: YES];
  209952. return cmp.result;
  209953. }
  209954. }
  209955. #endif
  209956. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  209957. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  209958. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209959. // compiled on its own).
  209960. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  209961. #if JUCE_MAC
  209962. END_JUCE_NAMESPACE
  209963. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  209964. @interface DownloadClickDetector : NSObject
  209965. {
  209966. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  209967. }
  209968. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  209969. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  209970. request: (NSURLRequest*) request
  209971. frame: (WebFrame*) frame
  209972. decisionListener: (id<WebPolicyDecisionListener>) listener;
  209973. @end
  209974. @implementation DownloadClickDetector
  209975. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  209976. {
  209977. [super init];
  209978. ownerComponent = ownerComponent_;
  209979. return self;
  209980. }
  209981. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  209982. request: (NSURLRequest*) request
  209983. frame: (WebFrame*) frame
  209984. decisionListener: (id <WebPolicyDecisionListener>) listener
  209985. {
  209986. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  209987. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  209988. [listener use];
  209989. else
  209990. [listener ignore];
  209991. }
  209992. @end
  209993. BEGIN_JUCE_NAMESPACE
  209994. class WebBrowserComponentInternal : public NSViewComponent
  209995. {
  209996. public:
  209997. WebBrowserComponentInternal (WebBrowserComponent* owner)
  209998. {
  209999. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  210000. frameName: @""
  210001. groupName: @""];
  210002. setView (webView);
  210003. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  210004. [webView setPolicyDelegate: clickListener];
  210005. }
  210006. ~WebBrowserComponentInternal()
  210007. {
  210008. [webView setPolicyDelegate: nil];
  210009. [clickListener release];
  210010. setView (0);
  210011. }
  210012. void goToURL (const String& url,
  210013. const StringArray* headers,
  210014. const MemoryBlock* postData)
  210015. {
  210016. NSMutableURLRequest* r
  210017. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  210018. cachePolicy: NSURLRequestUseProtocolCachePolicy
  210019. timeoutInterval: 30.0];
  210020. if (postData != 0 && postData->getSize() > 0)
  210021. {
  210022. [r setHTTPMethod: @"POST"];
  210023. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  210024. length: postData->getSize()]];
  210025. }
  210026. if (headers != 0)
  210027. {
  210028. for (int i = 0; i < headers->size(); ++i)
  210029. {
  210030. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  210031. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  210032. [r setValue: juceStringToNS (headerValue)
  210033. forHTTPHeaderField: juceStringToNS (headerName)];
  210034. }
  210035. }
  210036. stop();
  210037. [[webView mainFrame] loadRequest: r];
  210038. }
  210039. void goBack()
  210040. {
  210041. [webView goBack];
  210042. }
  210043. void goForward()
  210044. {
  210045. [webView goForward];
  210046. }
  210047. void stop()
  210048. {
  210049. [webView stopLoading: nil];
  210050. }
  210051. void refresh()
  210052. {
  210053. [webView reload: nil];
  210054. }
  210055. private:
  210056. WebView* webView;
  210057. DownloadClickDetector* clickListener;
  210058. };
  210059. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210060. : browser (0),
  210061. blankPageShown (false),
  210062. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210063. {
  210064. setOpaque (true);
  210065. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210066. }
  210067. WebBrowserComponent::~WebBrowserComponent()
  210068. {
  210069. deleteAndZero (browser);
  210070. }
  210071. void WebBrowserComponent::goToURL (const String& url,
  210072. const StringArray* headers,
  210073. const MemoryBlock* postData)
  210074. {
  210075. lastURL = url;
  210076. lastHeaders.clear();
  210077. if (headers != 0)
  210078. lastHeaders = *headers;
  210079. lastPostData.setSize (0);
  210080. if (postData != 0)
  210081. lastPostData = *postData;
  210082. blankPageShown = false;
  210083. browser->goToURL (url, headers, postData);
  210084. }
  210085. void WebBrowserComponent::stop()
  210086. {
  210087. browser->stop();
  210088. }
  210089. void WebBrowserComponent::goBack()
  210090. {
  210091. lastURL = String::empty;
  210092. blankPageShown = false;
  210093. browser->goBack();
  210094. }
  210095. void WebBrowserComponent::goForward()
  210096. {
  210097. lastURL = String::empty;
  210098. browser->goForward();
  210099. }
  210100. void WebBrowserComponent::refresh()
  210101. {
  210102. browser->refresh();
  210103. }
  210104. void WebBrowserComponent::paint (Graphics& g)
  210105. {
  210106. }
  210107. void WebBrowserComponent::checkWindowAssociation()
  210108. {
  210109. if (isShowing())
  210110. {
  210111. if (blankPageShown)
  210112. goBack();
  210113. }
  210114. else
  210115. {
  210116. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210117. {
  210118. // when the component becomes invisible, some stuff like flash
  210119. // carries on playing audio, so we need to force it onto a blank
  210120. // page to avoid this, (and send it back when it's made visible again).
  210121. blankPageShown = true;
  210122. browser->goToURL ("about:blank", 0, 0);
  210123. }
  210124. }
  210125. }
  210126. void WebBrowserComponent::reloadLastURL()
  210127. {
  210128. if (lastURL.isNotEmpty())
  210129. {
  210130. goToURL (lastURL, &lastHeaders, &lastPostData);
  210131. lastURL = String::empty;
  210132. }
  210133. }
  210134. void WebBrowserComponent::parentHierarchyChanged()
  210135. {
  210136. checkWindowAssociation();
  210137. }
  210138. void WebBrowserComponent::resized()
  210139. {
  210140. browser->setSize (getWidth(), getHeight());
  210141. }
  210142. void WebBrowserComponent::visibilityChanged()
  210143. {
  210144. checkWindowAssociation();
  210145. }
  210146. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210147. {
  210148. return true;
  210149. }
  210150. #else
  210151. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210152. {
  210153. }
  210154. WebBrowserComponent::~WebBrowserComponent()
  210155. {
  210156. }
  210157. void WebBrowserComponent::goToURL (const String& url,
  210158. const StringArray* headers,
  210159. const MemoryBlock* postData)
  210160. {
  210161. }
  210162. void WebBrowserComponent::stop()
  210163. {
  210164. }
  210165. void WebBrowserComponent::goBack()
  210166. {
  210167. }
  210168. void WebBrowserComponent::goForward()
  210169. {
  210170. }
  210171. void WebBrowserComponent::refresh()
  210172. {
  210173. }
  210174. void WebBrowserComponent::paint (Graphics& g)
  210175. {
  210176. }
  210177. void WebBrowserComponent::checkWindowAssociation()
  210178. {
  210179. }
  210180. void WebBrowserComponent::reloadLastURL()
  210181. {
  210182. }
  210183. void WebBrowserComponent::parentHierarchyChanged()
  210184. {
  210185. }
  210186. void WebBrowserComponent::resized()
  210187. {
  210188. }
  210189. void WebBrowserComponent::visibilityChanged()
  210190. {
  210191. }
  210192. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210193. {
  210194. return true;
  210195. }
  210196. #endif
  210197. #endif
  210198. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210199. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210200. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210201. // compiled on its own).
  210202. #if JUCE_INCLUDED_FILE
  210203. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210204. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210205. #endif
  210206. #undef log
  210207. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210208. #define log(a) Logger::writeToLog (a)
  210209. #else
  210210. #define log(a)
  210211. #endif
  210212. #undef OK
  210213. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210214. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210215. {
  210216. if (err == noErr)
  210217. return true;
  210218. Logger::writeToLog (T("CoreAudio error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  210219. jassertfalse
  210220. return false;
  210221. }
  210222. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210223. #else
  210224. #define OK(a) (a == noErr)
  210225. #endif
  210226. class CoreAudioInternal : public Timer
  210227. {
  210228. public:
  210229. CoreAudioInternal (AudioDeviceID id)
  210230. : inputLatency (0),
  210231. outputLatency (0),
  210232. callback (0),
  210233. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210234. audioProcID (0),
  210235. #endif
  210236. inputDevice (0),
  210237. isSlaveDevice (false),
  210238. deviceID (id),
  210239. started (false),
  210240. sampleRate (0),
  210241. bufferSize (512),
  210242. numInputChans (0),
  210243. numOutputChans (0),
  210244. callbacksAllowed (true),
  210245. numInputChannelInfos (0),
  210246. numOutputChannelInfos (0)
  210247. {
  210248. jassert (deviceID != 0);
  210249. updateDetailsFromDevice();
  210250. AudioObjectPropertyAddress pa;
  210251. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210252. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210253. pa.mElement = kAudioObjectPropertyElementWildcard;
  210254. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210255. }
  210256. ~CoreAudioInternal()
  210257. {
  210258. AudioObjectPropertyAddress pa;
  210259. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210260. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210261. pa.mElement = kAudioObjectPropertyElementWildcard;
  210262. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210263. stop (false);
  210264. delete inputDevice;
  210265. }
  210266. void allocateTempBuffers()
  210267. {
  210268. const int tempBufSize = bufferSize + 4;
  210269. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210270. tempInputBuffers.calloc (numInputChans + 2);
  210271. tempOutputBuffers.calloc (numOutputChans + 2);
  210272. int i, count = 0;
  210273. for (i = 0; i < numInputChans; ++i)
  210274. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210275. for (i = 0; i < numOutputChans; ++i)
  210276. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210277. }
  210278. // returns the number of actual available channels
  210279. void fillInChannelInfo (const bool input)
  210280. {
  210281. int chanNum = 0;
  210282. UInt32 size;
  210283. AudioObjectPropertyAddress pa;
  210284. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210285. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210286. pa.mElement = kAudioObjectPropertyElementMaster;
  210287. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210288. {
  210289. HeapBlock <AudioBufferList> bufList;
  210290. bufList.calloc (size, 1);
  210291. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210292. {
  210293. const int numStreams = bufList->mNumberBuffers;
  210294. for (int i = 0; i < numStreams; ++i)
  210295. {
  210296. const AudioBuffer& b = bufList->mBuffers[i];
  210297. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210298. {
  210299. String name;
  210300. {
  210301. uint8 channelName [256];
  210302. zerostruct (channelName);
  210303. UInt32 nameSize = sizeof (channelName);
  210304. UInt32 channelNum = chanNum + 1;
  210305. pa.mSelector = kAudioDevicePropertyChannelName;
  210306. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210307. name = String::fromUTF8 (channelName, nameSize);
  210308. }
  210309. if (input)
  210310. {
  210311. if (activeInputChans[chanNum])
  210312. {
  210313. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210314. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210315. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210316. ++numInputChannelInfos;
  210317. }
  210318. if (name.isEmpty())
  210319. name << "Input " << (chanNum + 1);
  210320. inChanNames.add (name);
  210321. }
  210322. else
  210323. {
  210324. if (activeOutputChans[chanNum])
  210325. {
  210326. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210327. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210328. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210329. ++numOutputChannelInfos;
  210330. }
  210331. if (name.isEmpty())
  210332. name << "Output " << (chanNum + 1);
  210333. outChanNames.add (name);
  210334. }
  210335. ++chanNum;
  210336. }
  210337. }
  210338. }
  210339. }
  210340. }
  210341. void updateDetailsFromDevice()
  210342. {
  210343. stopTimer();
  210344. if (deviceID == 0)
  210345. return;
  210346. const ScopedLock sl (callbackLock);
  210347. Float64 sr;
  210348. UInt32 size = sizeof (Float64);
  210349. AudioObjectPropertyAddress pa;
  210350. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210351. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210352. pa.mElement = kAudioObjectPropertyElementMaster;
  210353. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210354. sampleRate = sr;
  210355. UInt32 framesPerBuf;
  210356. size = sizeof (framesPerBuf);
  210357. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210358. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210359. {
  210360. bufferSize = framesPerBuf;
  210361. allocateTempBuffers();
  210362. }
  210363. bufferSizes.clear();
  210364. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210365. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210366. {
  210367. HeapBlock <AudioValueRange> ranges;
  210368. ranges.calloc (size, 1);
  210369. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210370. {
  210371. bufferSizes.add ((int) ranges[0].mMinimum);
  210372. for (int i = 32; i < 8192; i += 32)
  210373. {
  210374. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210375. {
  210376. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210377. {
  210378. bufferSizes.addIfNotAlreadyThere (i);
  210379. break;
  210380. }
  210381. }
  210382. }
  210383. if (bufferSize > 0)
  210384. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210385. }
  210386. }
  210387. if (bufferSizes.size() == 0 && bufferSize > 0)
  210388. bufferSizes.add (bufferSize);
  210389. sampleRates.clear();
  210390. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210391. String rates;
  210392. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210393. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210394. {
  210395. HeapBlock <AudioValueRange> ranges;
  210396. ranges.calloc (size, 1);
  210397. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210398. {
  210399. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210400. {
  210401. bool ok = false;
  210402. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210403. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210404. ok = true;
  210405. if (ok)
  210406. {
  210407. sampleRates.add (possibleRates[i]);
  210408. rates << possibleRates[i] << T(" ");
  210409. }
  210410. }
  210411. }
  210412. }
  210413. if (sampleRates.size() == 0 && sampleRate > 0)
  210414. {
  210415. sampleRates.add (sampleRate);
  210416. rates << sampleRate;
  210417. }
  210418. log (T("sr: ") + rates);
  210419. inputLatency = 0;
  210420. outputLatency = 0;
  210421. UInt32 lat;
  210422. size = sizeof (lat);
  210423. pa.mSelector = kAudioDevicePropertyLatency;
  210424. pa.mScope = kAudioDevicePropertyScopeInput;
  210425. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210426. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210427. inputLatency = (int) lat;
  210428. pa.mScope = kAudioDevicePropertyScopeOutput;
  210429. size = sizeof (lat);
  210430. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210431. outputLatency = (int) lat;
  210432. log (T("lat: ") + String (inputLatency) + T(" ") + String (outputLatency));
  210433. inChanNames.clear();
  210434. outChanNames.clear();
  210435. inputChannelInfo.calloc (numInputChans + 2);
  210436. numInputChannelInfos = 0;
  210437. outputChannelInfo.calloc (numOutputChans + 2);
  210438. numOutputChannelInfos = 0;
  210439. fillInChannelInfo (true);
  210440. fillInChannelInfo (false);
  210441. }
  210442. const StringArray getSources (bool input)
  210443. {
  210444. StringArray s;
  210445. HeapBlock <OSType> types;
  210446. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210447. for (int i = 0; i < num; ++i)
  210448. {
  210449. AudioValueTranslation avt;
  210450. char buffer[256];
  210451. avt.mInputData = (void*) &(types[i]);
  210452. avt.mInputDataSize = sizeof (UInt32);
  210453. avt.mOutputData = buffer;
  210454. avt.mOutputDataSize = 256;
  210455. UInt32 transSize = sizeof (avt);
  210456. AudioObjectPropertyAddress pa;
  210457. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210458. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210459. pa.mElement = kAudioObjectPropertyElementMaster;
  210460. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210461. {
  210462. DBG (buffer);
  210463. s.add (buffer);
  210464. }
  210465. }
  210466. return s;
  210467. }
  210468. int getCurrentSourceIndex (bool input) const
  210469. {
  210470. OSType currentSourceID = 0;
  210471. UInt32 size = sizeof (currentSourceID);
  210472. int result = -1;
  210473. AudioObjectPropertyAddress pa;
  210474. pa.mSelector = kAudioDevicePropertyDataSource;
  210475. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210476. pa.mElement = kAudioObjectPropertyElementMaster;
  210477. if (deviceID != 0)
  210478. {
  210479. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210480. {
  210481. HeapBlock <OSType> types;
  210482. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210483. for (int i = 0; i < num; ++i)
  210484. {
  210485. if (types[num] == currentSourceID)
  210486. {
  210487. result = i;
  210488. break;
  210489. }
  210490. }
  210491. }
  210492. }
  210493. return result;
  210494. }
  210495. void setCurrentSourceIndex (int index, bool input)
  210496. {
  210497. if (deviceID != 0)
  210498. {
  210499. HeapBlock <OSType> types;
  210500. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210501. if (((unsigned int) index) < (unsigned int) num)
  210502. {
  210503. AudioObjectPropertyAddress pa;
  210504. pa.mSelector = kAudioDevicePropertyDataSource;
  210505. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210506. pa.mElement = kAudioObjectPropertyElementMaster;
  210507. OSType typeId = types[index];
  210508. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210509. }
  210510. }
  210511. }
  210512. const String reopen (const BitArray& inputChannels,
  210513. const BitArray& outputChannels,
  210514. double newSampleRate,
  210515. int bufferSizeSamples)
  210516. {
  210517. String error;
  210518. log ("CoreAudio reopen");
  210519. callbacksAllowed = false;
  210520. stopTimer();
  210521. stop (false);
  210522. activeInputChans = inputChannels;
  210523. activeInputChans.setRange (inChanNames.size(),
  210524. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210525. false);
  210526. activeOutputChans = outputChannels;
  210527. activeOutputChans.setRange (outChanNames.size(),
  210528. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210529. false);
  210530. numInputChans = activeInputChans.countNumberOfSetBits();
  210531. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210532. // set sample rate
  210533. AudioObjectPropertyAddress pa;
  210534. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210535. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210536. pa.mElement = kAudioObjectPropertyElementMaster;
  210537. Float64 sr = newSampleRate;
  210538. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210539. {
  210540. error = "Couldn't change sample rate";
  210541. }
  210542. else
  210543. {
  210544. // change buffer size
  210545. UInt32 framesPerBuf = bufferSizeSamples;
  210546. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210547. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210548. {
  210549. error = "Couldn't change buffer size";
  210550. }
  210551. else
  210552. {
  210553. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210554. // correctly report their new settings until some random time in the future, so
  210555. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210556. // to make sure we're using the correct numbers..
  210557. updateDetailsFromDevice();
  210558. sampleRate = newSampleRate;
  210559. bufferSize = bufferSizeSamples;
  210560. if (sampleRates.size() == 0)
  210561. error = "Device has no available sample-rates";
  210562. else if (bufferSizes.size() == 0)
  210563. error = "Device has no available buffer-sizes";
  210564. else if (inputDevice != 0)
  210565. error = inputDevice->reopen (inputChannels,
  210566. outputChannels,
  210567. newSampleRate,
  210568. bufferSizeSamples);
  210569. }
  210570. }
  210571. callbacksAllowed = true;
  210572. return error;
  210573. }
  210574. bool start (AudioIODeviceCallback* cb)
  210575. {
  210576. if (! started)
  210577. {
  210578. callback = 0;
  210579. if (deviceID != 0)
  210580. {
  210581. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210582. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, (void*) this)))
  210583. #else
  210584. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, (void*) this, &audioProcID)))
  210585. #endif
  210586. {
  210587. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210588. {
  210589. started = true;
  210590. }
  210591. else
  210592. {
  210593. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210594. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210595. #else
  210596. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210597. audioProcID = 0;
  210598. #endif
  210599. }
  210600. }
  210601. }
  210602. }
  210603. if (started)
  210604. {
  210605. const ScopedLock sl (callbackLock);
  210606. callback = cb;
  210607. }
  210608. if (inputDevice != 0)
  210609. return started && inputDevice->start (cb);
  210610. else
  210611. return started;
  210612. }
  210613. void stop (bool leaveInterruptRunning)
  210614. {
  210615. callbackLock.enter();
  210616. callback = 0;
  210617. callbackLock.exit();
  210618. if (started
  210619. && (deviceID != 0)
  210620. && ! leaveInterruptRunning)
  210621. {
  210622. OK (AudioDeviceStop (deviceID, audioIOProc));
  210623. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210624. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210625. #else
  210626. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210627. audioProcID = 0;
  210628. #endif
  210629. started = false;
  210630. callbackLock.enter();
  210631. callbackLock.exit();
  210632. // wait until it's definately stopped calling back..
  210633. for (int i = 40; --i >= 0;)
  210634. {
  210635. Thread::sleep (50);
  210636. UInt32 running = 0;
  210637. UInt32 size = sizeof (running);
  210638. AudioObjectPropertyAddress pa;
  210639. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210640. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210641. pa.mElement = kAudioObjectPropertyElementMaster;
  210642. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210643. if (running == 0)
  210644. break;
  210645. }
  210646. callbackLock.enter();
  210647. callbackLock.exit();
  210648. }
  210649. if (inputDevice != 0)
  210650. inputDevice->stop (leaveInterruptRunning);
  210651. }
  210652. double getSampleRate() const
  210653. {
  210654. return sampleRate;
  210655. }
  210656. int getBufferSize() const
  210657. {
  210658. return bufferSize;
  210659. }
  210660. void audioCallback (const AudioBufferList* inInputData,
  210661. AudioBufferList* outOutputData)
  210662. {
  210663. int i;
  210664. const ScopedLock sl (callbackLock);
  210665. if (callback != 0)
  210666. {
  210667. if (inputDevice == 0)
  210668. {
  210669. for (i = numInputChans; --i >= 0;)
  210670. {
  210671. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210672. float* dest = tempInputBuffers [i];
  210673. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210674. + info.dataOffsetSamples;
  210675. const int stride = info.dataStrideSamples;
  210676. if (stride != 0) // if this is zero, info is invalid
  210677. {
  210678. for (int j = bufferSize; --j >= 0;)
  210679. {
  210680. *dest++ = *src;
  210681. src += stride;
  210682. }
  210683. }
  210684. }
  210685. }
  210686. if (! isSlaveDevice)
  210687. {
  210688. if (inputDevice == 0)
  210689. {
  210690. callback->audioDeviceIOCallback ((const float**) tempInputBuffers,
  210691. numInputChans,
  210692. tempOutputBuffers,
  210693. numOutputChans,
  210694. bufferSize);
  210695. }
  210696. else
  210697. {
  210698. jassert (inputDevice->bufferSize == bufferSize);
  210699. // Sometimes the two linked devices seem to get their callbacks in
  210700. // parallel, so we need to lock both devices to stop the input data being
  210701. // changed while inside our callback..
  210702. const ScopedLock sl2 (inputDevice->callbackLock);
  210703. callback->audioDeviceIOCallback ((const float**) inputDevice->tempInputBuffers,
  210704. inputDevice->numInputChans,
  210705. tempOutputBuffers,
  210706. numOutputChans,
  210707. bufferSize);
  210708. }
  210709. for (i = numOutputChans; --i >= 0;)
  210710. {
  210711. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210712. const float* src = tempOutputBuffers [i];
  210713. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210714. + info.dataOffsetSamples;
  210715. const int stride = info.dataStrideSamples;
  210716. if (stride != 0) // if this is zero, info is invalid
  210717. {
  210718. for (int j = bufferSize; --j >= 0;)
  210719. {
  210720. *dest = *src++;
  210721. dest += stride;
  210722. }
  210723. }
  210724. }
  210725. }
  210726. }
  210727. else
  210728. {
  210729. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210730. {
  210731. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210732. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210733. + info.dataOffsetSamples;
  210734. const int stride = info.dataStrideSamples;
  210735. if (stride != 0) // if this is zero, info is invalid
  210736. {
  210737. for (int j = bufferSize; --j >= 0;)
  210738. {
  210739. *dest = 0.0f;
  210740. dest += stride;
  210741. }
  210742. }
  210743. }
  210744. }
  210745. }
  210746. // called by callbacks
  210747. void deviceDetailsChanged()
  210748. {
  210749. if (callbacksAllowed)
  210750. startTimer (100);
  210751. }
  210752. void timerCallback()
  210753. {
  210754. stopTimer();
  210755. log ("CoreAudio device changed callback");
  210756. const double oldSampleRate = sampleRate;
  210757. const int oldBufferSize = bufferSize;
  210758. updateDetailsFromDevice();
  210759. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210760. {
  210761. callbacksAllowed = false;
  210762. stop (false);
  210763. updateDetailsFromDevice();
  210764. callbacksAllowed = true;
  210765. }
  210766. }
  210767. CoreAudioInternal* getRelatedDevice() const
  210768. {
  210769. UInt32 size = 0;
  210770. ScopedPointer <CoreAudioInternal> result;
  210771. AudioObjectPropertyAddress pa;
  210772. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210773. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210774. pa.mElement = kAudioObjectPropertyElementMaster;
  210775. if (deviceID != 0
  210776. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210777. && size > 0)
  210778. {
  210779. HeapBlock <AudioDeviceID> devs;
  210780. devs.calloc (size, 1);
  210781. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210782. {
  210783. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210784. {
  210785. if (devs[i] != deviceID && devs[i] != 0)
  210786. {
  210787. result = new CoreAudioInternal (devs[i]);
  210788. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210789. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210790. if (thisIsInput != otherIsInput
  210791. || (inChanNames.size() + outChanNames.size() == 0)
  210792. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210793. break;
  210794. result = 0;
  210795. }
  210796. }
  210797. }
  210798. }
  210799. return result.release();
  210800. }
  210801. juce_UseDebuggingNewOperator
  210802. int inputLatency, outputLatency;
  210803. BitArray activeInputChans, activeOutputChans;
  210804. StringArray inChanNames, outChanNames;
  210805. Array <double> sampleRates;
  210806. Array <int> bufferSizes;
  210807. AudioIODeviceCallback* callback;
  210808. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210809. AudioDeviceIOProcID audioProcID;
  210810. #endif
  210811. CoreAudioInternal* inputDevice;
  210812. bool isSlaveDevice;
  210813. private:
  210814. CriticalSection callbackLock;
  210815. AudioDeviceID deviceID;
  210816. bool started;
  210817. double sampleRate;
  210818. int bufferSize;
  210819. HeapBlock <float> audioBuffer;
  210820. int numInputChans, numOutputChans;
  210821. bool callbacksAllowed;
  210822. struct CallbackDetailsForChannel
  210823. {
  210824. int streamNum;
  210825. int dataOffsetSamples;
  210826. int dataStrideSamples;
  210827. };
  210828. int numInputChannelInfos, numOutputChannelInfos;
  210829. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  210830. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  210831. CoreAudioInternal (const CoreAudioInternal&);
  210832. const CoreAudioInternal& operator= (const CoreAudioInternal&);
  210833. static OSStatus audioIOProc (AudioDeviceID inDevice,
  210834. const AudioTimeStamp* inNow,
  210835. const AudioBufferList* inInputData,
  210836. const AudioTimeStamp* inInputTime,
  210837. AudioBufferList* outOutputData,
  210838. const AudioTimeStamp* inOutputTime,
  210839. void* device)
  210840. {
  210841. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  210842. return noErr;
  210843. }
  210844. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  210845. {
  210846. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  210847. switch (pa->mSelector)
  210848. {
  210849. case kAudioDevicePropertyBufferSize:
  210850. case kAudioDevicePropertyBufferFrameSize:
  210851. case kAudioDevicePropertyNominalSampleRate:
  210852. case kAudioDevicePropertyStreamFormat:
  210853. case kAudioDevicePropertyDeviceIsAlive:
  210854. intern->deviceDetailsChanged();
  210855. break;
  210856. case kAudioDevicePropertyBufferSizeRange:
  210857. case kAudioDevicePropertyVolumeScalar:
  210858. case kAudioDevicePropertyMute:
  210859. case kAudioDevicePropertyPlayThru:
  210860. case kAudioDevicePropertyDataSource:
  210861. case kAudioDevicePropertyDeviceIsRunning:
  210862. break;
  210863. }
  210864. return noErr;
  210865. }
  210866. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  210867. {
  210868. AudioObjectPropertyAddress pa;
  210869. pa.mSelector = kAudioDevicePropertyDataSources;
  210870. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210871. pa.mElement = kAudioObjectPropertyElementMaster;
  210872. UInt32 size = 0;
  210873. if (deviceID != 0
  210874. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210875. {
  210876. types.calloc (size, 1);
  210877. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  210878. return size / (int) sizeof (OSType);
  210879. }
  210880. return 0;
  210881. }
  210882. };
  210883. class CoreAudioIODevice : public AudioIODevice
  210884. {
  210885. public:
  210886. CoreAudioIODevice (const String& deviceName,
  210887. AudioDeviceID inputDeviceId,
  210888. const int inputIndex_,
  210889. AudioDeviceID outputDeviceId,
  210890. const int outputIndex_)
  210891. : AudioIODevice (deviceName, "CoreAudio"),
  210892. inputIndex (inputIndex_),
  210893. outputIndex (outputIndex_),
  210894. isOpen_ (false),
  210895. isStarted (false)
  210896. {
  210897. internal = 0;
  210898. CoreAudioInternal* device = 0;
  210899. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  210900. {
  210901. jassert (inputDeviceId != 0);
  210902. device = new CoreAudioInternal (inputDeviceId);
  210903. }
  210904. else
  210905. {
  210906. device = new CoreAudioInternal (outputDeviceId);
  210907. if (inputDeviceId != 0)
  210908. {
  210909. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  210910. device->inputDevice = secondDevice;
  210911. secondDevice->isSlaveDevice = true;
  210912. }
  210913. }
  210914. internal = device;
  210915. AudioObjectPropertyAddress pa;
  210916. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210917. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210918. pa.mElement = kAudioObjectPropertyElementWildcard;
  210919. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210920. }
  210921. ~CoreAudioIODevice()
  210922. {
  210923. AudioObjectPropertyAddress pa;
  210924. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210925. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210926. pa.mElement = kAudioObjectPropertyElementWildcard;
  210927. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210928. delete internal;
  210929. }
  210930. const StringArray getOutputChannelNames()
  210931. {
  210932. return internal->outChanNames;
  210933. }
  210934. const StringArray getInputChannelNames()
  210935. {
  210936. if (internal->inputDevice != 0)
  210937. return internal->inputDevice->inChanNames;
  210938. else
  210939. return internal->inChanNames;
  210940. }
  210941. int getNumSampleRates()
  210942. {
  210943. return internal->sampleRates.size();
  210944. }
  210945. double getSampleRate (int index)
  210946. {
  210947. return internal->sampleRates [index];
  210948. }
  210949. int getNumBufferSizesAvailable()
  210950. {
  210951. return internal->bufferSizes.size();
  210952. }
  210953. int getBufferSizeSamples (int index)
  210954. {
  210955. return internal->bufferSizes [index];
  210956. }
  210957. int getDefaultBufferSize()
  210958. {
  210959. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  210960. if (getBufferSizeSamples(i) >= 512)
  210961. return getBufferSizeSamples(i);
  210962. return 512;
  210963. }
  210964. const String open (const BitArray& inputChannels,
  210965. const BitArray& outputChannels,
  210966. double sampleRate,
  210967. int bufferSizeSamples)
  210968. {
  210969. isOpen_ = true;
  210970. if (bufferSizeSamples <= 0)
  210971. bufferSizeSamples = getDefaultBufferSize();
  210972. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  210973. isOpen_ = lastError.isEmpty();
  210974. return lastError;
  210975. }
  210976. void close()
  210977. {
  210978. isOpen_ = false;
  210979. internal->stop (false);
  210980. }
  210981. bool isOpen()
  210982. {
  210983. return isOpen_;
  210984. }
  210985. int getCurrentBufferSizeSamples()
  210986. {
  210987. return internal != 0 ? internal->getBufferSize() : 512;
  210988. }
  210989. double getCurrentSampleRate()
  210990. {
  210991. return internal != 0 ? internal->getSampleRate() : 0;
  210992. }
  210993. int getCurrentBitDepth()
  210994. {
  210995. return 32; // no way to find out, so just assume it's high..
  210996. }
  210997. const BitArray getActiveOutputChannels() const
  210998. {
  210999. return internal != 0 ? internal->activeOutputChans : BitArray();
  211000. }
  211001. const BitArray getActiveInputChannels() const
  211002. {
  211003. BitArray chans;
  211004. if (internal != 0)
  211005. {
  211006. chans = internal->activeInputChans;
  211007. if (internal->inputDevice != 0)
  211008. chans.orWith (internal->inputDevice->activeInputChans);
  211009. }
  211010. return chans;
  211011. }
  211012. int getOutputLatencyInSamples()
  211013. {
  211014. if (internal == 0)
  211015. return 0;
  211016. // this seems like a good guess at getting the latency right - comparing
  211017. // this with a round-trip measurement, it gets it to within a few millisecs
  211018. // for the built-in mac soundcard
  211019. return internal->outputLatency + internal->getBufferSize() * 2;
  211020. }
  211021. int getInputLatencyInSamples()
  211022. {
  211023. if (internal == 0)
  211024. return 0;
  211025. return internal->inputLatency + internal->getBufferSize() * 2;
  211026. }
  211027. void start (AudioIODeviceCallback* callback)
  211028. {
  211029. if (internal != 0 && ! isStarted)
  211030. {
  211031. if (callback != 0)
  211032. callback->audioDeviceAboutToStart (this);
  211033. isStarted = true;
  211034. internal->start (callback);
  211035. }
  211036. }
  211037. void stop()
  211038. {
  211039. if (isStarted && internal != 0)
  211040. {
  211041. AudioIODeviceCallback* const lastCallback = internal->callback;
  211042. isStarted = false;
  211043. internal->stop (true);
  211044. if (lastCallback != 0)
  211045. lastCallback->audioDeviceStopped();
  211046. }
  211047. }
  211048. bool isPlaying()
  211049. {
  211050. if (internal->callback == 0)
  211051. isStarted = false;
  211052. return isStarted;
  211053. }
  211054. const String getLastError()
  211055. {
  211056. return lastError;
  211057. }
  211058. int inputIndex, outputIndex;
  211059. juce_UseDebuggingNewOperator
  211060. private:
  211061. CoreAudioInternal* internal;
  211062. bool isOpen_, isStarted;
  211063. String lastError;
  211064. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211065. {
  211066. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211067. switch (pa->mSelector)
  211068. {
  211069. case kAudioHardwarePropertyDevices:
  211070. intern->deviceDetailsChanged();
  211071. break;
  211072. case kAudioHardwarePropertyDefaultOutputDevice:
  211073. case kAudioHardwarePropertyDefaultInputDevice:
  211074. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211075. break;
  211076. }
  211077. return noErr;
  211078. }
  211079. CoreAudioIODevice (const CoreAudioIODevice&);
  211080. const CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211081. };
  211082. class CoreAudioIODeviceType : public AudioIODeviceType
  211083. {
  211084. public:
  211085. CoreAudioIODeviceType()
  211086. : AudioIODeviceType (T("CoreAudio")),
  211087. hasScanned (false)
  211088. {
  211089. }
  211090. ~CoreAudioIODeviceType()
  211091. {
  211092. }
  211093. void scanForDevices()
  211094. {
  211095. hasScanned = true;
  211096. inputDeviceNames.clear();
  211097. outputDeviceNames.clear();
  211098. inputIds.clear();
  211099. outputIds.clear();
  211100. UInt32 size;
  211101. AudioObjectPropertyAddress pa;
  211102. pa.mSelector = kAudioHardwarePropertyDevices;
  211103. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211104. pa.mElement = kAudioObjectPropertyElementMaster;
  211105. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211106. {
  211107. HeapBlock <AudioDeviceID> devs;
  211108. devs.calloc (size, 1);
  211109. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211110. {
  211111. static bool alreadyLogged = false;
  211112. const int num = size / (int) sizeof (AudioDeviceID);
  211113. for (int i = 0; i < num; ++i)
  211114. {
  211115. char name [1024];
  211116. size = sizeof (name);
  211117. pa.mSelector = kAudioDevicePropertyDeviceName;
  211118. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211119. {
  211120. const String nameString (String::fromUTF8 ((const uint8*) name, (int) strlen (name)));
  211121. if (! alreadyLogged)
  211122. log (T("CoreAudio device: ") + nameString);
  211123. const int numIns = getNumChannels (devs[i], true);
  211124. const int numOuts = getNumChannels (devs[i], false);
  211125. if (numIns > 0)
  211126. {
  211127. inputDeviceNames.add (nameString);
  211128. inputIds.add (devs[i]);
  211129. }
  211130. if (numOuts > 0)
  211131. {
  211132. outputDeviceNames.add (nameString);
  211133. outputIds.add (devs[i]);
  211134. }
  211135. }
  211136. }
  211137. alreadyLogged = true;
  211138. }
  211139. }
  211140. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211141. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211142. }
  211143. const StringArray getDeviceNames (const bool wantInputNames) const
  211144. {
  211145. jassert (hasScanned); // need to call scanForDevices() before doing this
  211146. if (wantInputNames)
  211147. return inputDeviceNames;
  211148. else
  211149. return outputDeviceNames;
  211150. }
  211151. int getDefaultDeviceIndex (const bool forInput) const
  211152. {
  211153. jassert (hasScanned); // need to call scanForDevices() before doing this
  211154. AudioDeviceID deviceID;
  211155. UInt32 size = sizeof (deviceID);
  211156. // if they're asking for any input channels at all, use the default input, so we
  211157. // get the built-in mic rather than the built-in output with no inputs..
  211158. AudioObjectPropertyAddress pa;
  211159. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211160. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211161. pa.mElement = kAudioObjectPropertyElementMaster;
  211162. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211163. {
  211164. if (forInput)
  211165. {
  211166. for (int i = inputIds.size(); --i >= 0;)
  211167. if (inputIds[i] == deviceID)
  211168. return i;
  211169. }
  211170. else
  211171. {
  211172. for (int i = outputIds.size(); --i >= 0;)
  211173. if (outputIds[i] == deviceID)
  211174. return i;
  211175. }
  211176. }
  211177. return 0;
  211178. }
  211179. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  211180. {
  211181. jassert (hasScanned); // need to call scanForDevices() before doing this
  211182. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211183. if (d == 0)
  211184. return -1;
  211185. return asInput ? d->inputIndex
  211186. : d->outputIndex;
  211187. }
  211188. bool hasSeparateInputsAndOutputs() const { return true; }
  211189. AudioIODevice* createDevice (const String& outputDeviceName,
  211190. const String& inputDeviceName)
  211191. {
  211192. jassert (hasScanned); // need to call scanForDevices() before doing this
  211193. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211194. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211195. String deviceName (outputDeviceName);
  211196. if (deviceName.isEmpty())
  211197. deviceName = inputDeviceName;
  211198. if (index >= 0)
  211199. return new CoreAudioIODevice (deviceName,
  211200. inputIds [inputIndex],
  211201. inputIndex,
  211202. outputIds [outputIndex],
  211203. outputIndex);
  211204. return 0;
  211205. }
  211206. juce_UseDebuggingNewOperator
  211207. private:
  211208. StringArray inputDeviceNames, outputDeviceNames;
  211209. Array <AudioDeviceID> inputIds, outputIds;
  211210. bool hasScanned;
  211211. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211212. {
  211213. int total = 0;
  211214. UInt32 size;
  211215. AudioObjectPropertyAddress pa;
  211216. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211217. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211218. pa.mElement = kAudioObjectPropertyElementMaster;
  211219. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211220. {
  211221. HeapBlock <AudioBufferList> bufList;
  211222. bufList.calloc (size, 1);
  211223. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211224. {
  211225. const int numStreams = bufList->mNumberBuffers;
  211226. for (int i = 0; i < numStreams; ++i)
  211227. {
  211228. const AudioBuffer& b = bufList->mBuffers[i];
  211229. total += b.mNumberChannels;
  211230. }
  211231. }
  211232. }
  211233. return total;
  211234. }
  211235. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211236. const CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211237. };
  211238. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211239. {
  211240. return new CoreAudioIODeviceType();
  211241. }
  211242. #undef log
  211243. #endif
  211244. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211245. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211246. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211247. // compiled on its own).
  211248. #if JUCE_INCLUDED_FILE
  211249. #if JUCE_MAC
  211250. #undef log
  211251. #define log(a) Logger::writeToLog(a)
  211252. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211253. {
  211254. if (err == noErr)
  211255. return true;
  211256. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  211257. jassertfalse
  211258. return false;
  211259. }
  211260. #undef OK
  211261. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211262. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211263. {
  211264. String result;
  211265. CFStringRef str = 0;
  211266. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211267. if (str != 0)
  211268. {
  211269. result = PlatformUtilities::cfStringToJuceString (str);
  211270. CFRelease (str);
  211271. str = 0;
  211272. }
  211273. MIDIEntityRef entity = 0;
  211274. MIDIEndpointGetEntity (endpoint, &entity);
  211275. if (entity == 0)
  211276. return result; // probably virtual
  211277. if (result.isEmpty())
  211278. {
  211279. // endpoint name has zero length - try the entity
  211280. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211281. if (str != 0)
  211282. {
  211283. result += PlatformUtilities::cfStringToJuceString (str);
  211284. CFRelease (str);
  211285. str = 0;
  211286. }
  211287. }
  211288. // now consider the device's name
  211289. MIDIDeviceRef device = 0;
  211290. MIDIEntityGetDevice (entity, &device);
  211291. if (device == 0)
  211292. return result;
  211293. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211294. if (str != 0)
  211295. {
  211296. const String s (PlatformUtilities::cfStringToJuceString (str));
  211297. CFRelease (str);
  211298. // if an external device has only one entity, throw away
  211299. // the endpoint name and just use the device name
  211300. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211301. {
  211302. result = s;
  211303. }
  211304. else if (! result.startsWithIgnoreCase (s))
  211305. {
  211306. // prepend the device name to the entity name
  211307. result = (s + T(" ") + result).trimEnd();
  211308. }
  211309. }
  211310. return result;
  211311. }
  211312. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211313. {
  211314. String result;
  211315. // Does the endpoint have connections?
  211316. CFDataRef connections = 0;
  211317. int numConnections = 0;
  211318. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211319. if (connections != 0)
  211320. {
  211321. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211322. if (numConnections > 0)
  211323. {
  211324. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211325. for (int i = 0; i < numConnections; ++i, ++pid)
  211326. {
  211327. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211328. MIDIObjectRef connObject;
  211329. MIDIObjectType connObjectType;
  211330. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211331. if (err == noErr)
  211332. {
  211333. String s;
  211334. if (connObjectType == kMIDIObjectType_ExternalSource
  211335. || connObjectType == kMIDIObjectType_ExternalDestination)
  211336. {
  211337. // Connected to an external device's endpoint (10.3 and later).
  211338. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211339. }
  211340. else
  211341. {
  211342. // Connected to an external device (10.2) (or something else, catch-all)
  211343. CFStringRef str = 0;
  211344. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211345. if (str != 0)
  211346. {
  211347. s = PlatformUtilities::cfStringToJuceString (str);
  211348. CFRelease (str);
  211349. }
  211350. }
  211351. if (s.isNotEmpty())
  211352. {
  211353. if (result.isNotEmpty())
  211354. result += (", ");
  211355. result += s;
  211356. }
  211357. }
  211358. }
  211359. }
  211360. CFRelease (connections);
  211361. }
  211362. if (result.isNotEmpty())
  211363. return result;
  211364. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211365. return getEndpointName (endpoint, false);
  211366. }
  211367. const StringArray MidiOutput::getDevices()
  211368. {
  211369. StringArray s;
  211370. const ItemCount num = MIDIGetNumberOfDestinations();
  211371. for (ItemCount i = 0; i < num; ++i)
  211372. {
  211373. MIDIEndpointRef dest = MIDIGetDestination (i);
  211374. if (dest != 0)
  211375. {
  211376. String name (getConnectedEndpointName (dest));
  211377. if (name.isEmpty())
  211378. name = "<error>";
  211379. s.add (name);
  211380. }
  211381. else
  211382. {
  211383. s.add ("<error>");
  211384. }
  211385. }
  211386. return s;
  211387. }
  211388. int MidiOutput::getDefaultDeviceIndex()
  211389. {
  211390. return 0;
  211391. }
  211392. static MIDIClientRef globalMidiClient;
  211393. static bool hasGlobalClientBeenCreated = false;
  211394. static bool makeSureClientExists()
  211395. {
  211396. if (! hasGlobalClientBeenCreated)
  211397. {
  211398. String name (T("JUCE"));
  211399. if (JUCEApplication::getInstance() != 0)
  211400. name = JUCEApplication::getInstance()->getApplicationName();
  211401. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211402. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211403. CFRelease (appName);
  211404. }
  211405. return hasGlobalClientBeenCreated;
  211406. }
  211407. class MidiPortAndEndpoint
  211408. {
  211409. public:
  211410. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211411. : port (port_), endPoint (endPoint_)
  211412. {
  211413. }
  211414. ~MidiPortAndEndpoint()
  211415. {
  211416. if (port != 0)
  211417. MIDIPortDispose (port);
  211418. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211419. MIDIEndpointDispose (endPoint);
  211420. }
  211421. MIDIPortRef port;
  211422. MIDIEndpointRef endPoint;
  211423. };
  211424. MidiOutput* MidiOutput::openDevice (int index)
  211425. {
  211426. MidiOutput* mo = 0;
  211427. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211428. {
  211429. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211430. CFStringRef pname;
  211431. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211432. {
  211433. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  211434. if (makeSureClientExists())
  211435. {
  211436. MIDIPortRef port;
  211437. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211438. {
  211439. mo = new MidiOutput();
  211440. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  211441. }
  211442. }
  211443. CFRelease (pname);
  211444. }
  211445. }
  211446. return mo;
  211447. }
  211448. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211449. {
  211450. MidiOutput* mo = 0;
  211451. if (makeSureClientExists())
  211452. {
  211453. MIDIEndpointRef endPoint;
  211454. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211455. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211456. {
  211457. mo = new MidiOutput();
  211458. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  211459. }
  211460. CFRelease (name);
  211461. }
  211462. return mo;
  211463. }
  211464. MidiOutput::~MidiOutput()
  211465. {
  211466. delete (MidiPortAndEndpoint*) internal;
  211467. }
  211468. void MidiOutput::reset()
  211469. {
  211470. }
  211471. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211472. {
  211473. return false;
  211474. }
  211475. void MidiOutput::setVolume (float leftVol, float rightVol)
  211476. {
  211477. }
  211478. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211479. {
  211480. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211481. if (message.isSysEx())
  211482. {
  211483. const int maxPacketSize = 256;
  211484. int pos = 0, bytesLeft = message.getRawDataSize();
  211485. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211486. HeapBlock <MIDIPacketList> packets;
  211487. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211488. packets->numPackets = numPackets;
  211489. MIDIPacket* p = packets->packet;
  211490. for (int i = 0; i < numPackets; ++i)
  211491. {
  211492. p->timeStamp = 0;
  211493. p->length = jmin (maxPacketSize, bytesLeft);
  211494. memcpy (p->data, message.getRawData() + pos, p->length);
  211495. pos += p->length;
  211496. bytesLeft -= p->length;
  211497. p = MIDIPacketNext (p);
  211498. }
  211499. if (mpe->port != 0)
  211500. MIDISend (mpe->port, mpe->endPoint, packets);
  211501. else
  211502. MIDIReceived (mpe->endPoint, packets);
  211503. }
  211504. else
  211505. {
  211506. MIDIPacketList packets;
  211507. packets.numPackets = 1;
  211508. packets.packet[0].timeStamp = 0;
  211509. packets.packet[0].length = message.getRawDataSize();
  211510. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211511. if (mpe->port != 0)
  211512. MIDISend (mpe->port, mpe->endPoint, &packets);
  211513. else
  211514. MIDIReceived (mpe->endPoint, &packets);
  211515. }
  211516. }
  211517. const StringArray MidiInput::getDevices()
  211518. {
  211519. StringArray s;
  211520. const ItemCount num = MIDIGetNumberOfSources();
  211521. for (ItemCount i = 0; i < num; ++i)
  211522. {
  211523. MIDIEndpointRef source = MIDIGetSource (i);
  211524. if (source != 0)
  211525. {
  211526. String name (getConnectedEndpointName (source));
  211527. if (name.isEmpty())
  211528. name = "<error>";
  211529. s.add (name);
  211530. }
  211531. else
  211532. {
  211533. s.add ("<error>");
  211534. }
  211535. }
  211536. return s;
  211537. }
  211538. int MidiInput::getDefaultDeviceIndex()
  211539. {
  211540. return 0;
  211541. }
  211542. struct MidiPortAndCallback
  211543. {
  211544. MidiInput* input;
  211545. MidiPortAndEndpoint* portAndEndpoint;
  211546. MidiInputCallback* callback;
  211547. MemoryBlock pendingData;
  211548. int pendingBytes;
  211549. double pendingDataTime;
  211550. bool active;
  211551. };
  211552. static CriticalSection callbackLock;
  211553. static VoidArray activeCallbacks;
  211554. static void processSysex (MidiPortAndCallback* const mpc, const uint8*& d, int& size, const double time)
  211555. {
  211556. if (*d == 0xf0)
  211557. {
  211558. mpc->pendingBytes = 0;
  211559. mpc->pendingDataTime = time;
  211560. }
  211561. mpc->pendingData.ensureSize (mpc->pendingBytes + size, false);
  211562. uint8* totalMessage = (uint8*) mpc->pendingData.getData();
  211563. uint8* dest = totalMessage + mpc->pendingBytes;
  211564. while (size > 0)
  211565. {
  211566. if (mpc->pendingBytes > 0 && *d >= 0x80)
  211567. {
  211568. if (*d >= 0xfa || *d == 0xf8)
  211569. {
  211570. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (*d, time));
  211571. ++d;
  211572. --size;
  211573. }
  211574. else
  211575. {
  211576. if (*d == 0xf7)
  211577. {
  211578. *dest++ = *d++;
  211579. mpc->pendingBytes++;
  211580. --size;
  211581. }
  211582. break;
  211583. }
  211584. }
  211585. else
  211586. {
  211587. *dest++ = *d++;
  211588. mpc->pendingBytes++;
  211589. --size;
  211590. }
  211591. }
  211592. if (totalMessage [mpc->pendingBytes - 1] == 0xf7)
  211593. {
  211594. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (totalMessage,
  211595. mpc->pendingBytes,
  211596. mpc->pendingDataTime));
  211597. mpc->pendingBytes = 0;
  211598. }
  211599. else
  211600. {
  211601. mpc->callback->handlePartialSysexMessage (mpc->input,
  211602. totalMessage,
  211603. mpc->pendingBytes,
  211604. mpc->pendingDataTime);
  211605. }
  211606. }
  211607. static void midiInputProc (const MIDIPacketList* pktlist,
  211608. void* readProcRefCon,
  211609. void* srcConnRefCon)
  211610. {
  211611. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211612. const double originalTime = time;
  211613. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211614. const ScopedLock sl (callbackLock);
  211615. if (activeCallbacks.contains (mpc) && mpc->active)
  211616. {
  211617. const MIDIPacket* packet = &pktlist->packet[0];
  211618. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211619. {
  211620. const uint8* d = (const uint8*) (packet->data);
  211621. int size = packet->length;
  211622. while (size > 0)
  211623. {
  211624. time = originalTime;
  211625. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211626. {
  211627. processSysex (mpc, d, size, time);
  211628. }
  211629. else
  211630. {
  211631. int used = 0;
  211632. const MidiMessage m (d, size, used, 0, time);
  211633. if (used <= 0)
  211634. {
  211635. jassertfalse // malformed midi message
  211636. break;
  211637. }
  211638. else
  211639. {
  211640. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211641. }
  211642. size -= used;
  211643. d += used;
  211644. }
  211645. }
  211646. packet = MIDIPacketNext (packet);
  211647. }
  211648. }
  211649. }
  211650. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211651. {
  211652. MidiInput* mi = 0;
  211653. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211654. {
  211655. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211656. if (endPoint != 0)
  211657. {
  211658. CFStringRef pname;
  211659. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211660. {
  211661. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  211662. if (makeSureClientExists())
  211663. {
  211664. MIDIPortRef port;
  211665. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211666. mpc->active = false;
  211667. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211668. {
  211669. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211670. {
  211671. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211672. mpc->callback = callback;
  211673. mpc->pendingBytes = 0;
  211674. mpc->pendingData.ensureSize (128);
  211675. mi = new MidiInput (getDevices() [index]);
  211676. mpc->input = mi;
  211677. mi->internal = (void*) mpc;
  211678. const ScopedLock sl (callbackLock);
  211679. activeCallbacks.add (mpc.release());
  211680. }
  211681. else
  211682. {
  211683. OK (MIDIPortDispose (port));
  211684. }
  211685. }
  211686. }
  211687. }
  211688. CFRelease (pname);
  211689. }
  211690. }
  211691. return mi;
  211692. }
  211693. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211694. {
  211695. MidiInput* mi = 0;
  211696. if (makeSureClientExists())
  211697. {
  211698. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211699. mpc->active = false;
  211700. MIDIEndpointRef endPoint;
  211701. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211702. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211703. {
  211704. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211705. mpc->callback = callback;
  211706. mpc->pendingBytes = 0;
  211707. mpc->pendingData.ensureSize (128);
  211708. mi = new MidiInput (deviceName);
  211709. mpc->input = mi;
  211710. mi->internal = (void*) mpc;
  211711. const ScopedLock sl (callbackLock);
  211712. activeCallbacks.add (mpc.release());
  211713. }
  211714. CFRelease (name);
  211715. }
  211716. return mi;
  211717. }
  211718. MidiInput::MidiInput (const String& name_)
  211719. : name (name_)
  211720. {
  211721. }
  211722. MidiInput::~MidiInput()
  211723. {
  211724. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211725. mpc->active = false;
  211726. callbackLock.enter();
  211727. activeCallbacks.removeValue (mpc);
  211728. callbackLock.exit();
  211729. if (mpc->portAndEndpoint->port != 0)
  211730. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211731. delete mpc->portAndEndpoint;
  211732. delete mpc;
  211733. }
  211734. void MidiInput::start()
  211735. {
  211736. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211737. const ScopedLock sl (callbackLock);
  211738. mpc->active = true;
  211739. }
  211740. void MidiInput::stop()
  211741. {
  211742. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211743. const ScopedLock sl (callbackLock);
  211744. mpc->active = false;
  211745. }
  211746. #undef log
  211747. #else
  211748. MidiOutput::~MidiOutput()
  211749. {
  211750. }
  211751. void MidiOutput::reset()
  211752. {
  211753. }
  211754. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211755. {
  211756. return false;
  211757. }
  211758. void MidiOutput::setVolume (float leftVol, float rightVol)
  211759. {
  211760. }
  211761. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211762. {
  211763. }
  211764. const StringArray MidiOutput::getDevices()
  211765. {
  211766. return StringArray();
  211767. }
  211768. MidiOutput* MidiOutput::openDevice (int index)
  211769. {
  211770. return 0;
  211771. }
  211772. const StringArray MidiInput::getDevices()
  211773. {
  211774. return StringArray();
  211775. }
  211776. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211777. {
  211778. return 0;
  211779. }
  211780. #endif
  211781. #endif
  211782. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211783. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211784. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211785. // compiled on its own).
  211786. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME && JUCE_USE_CAMERA
  211787. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211788. class QTCameraDeviceInteral;
  211789. END_JUCE_NAMESPACE
  211790. @interface QTCaptureCallbackDelegate : NSObject
  211791. {
  211792. @public
  211793. CameraDevice* owner;
  211794. QTCameraDeviceInteral* internal;
  211795. Time* firstRecordedTime;
  211796. }
  211797. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  211798. - (void) dealloc;
  211799. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211800. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211801. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211802. fromConnection: (QTCaptureConnection*) connection;
  211803. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211804. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211805. fromConnection: (QTCaptureConnection*) connection;
  211806. @end
  211807. BEGIN_JUCE_NAMESPACE
  211808. class QTCameraDeviceInteral
  211809. {
  211810. public:
  211811. QTCameraDeviceInteral (CameraDevice* owner, int index)
  211812. {
  211813. const ScopedAutoReleasePool pool;
  211814. session = [[QTCaptureSession alloc] init];
  211815. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211816. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  211817. input = 0;
  211818. audioInput = 0;
  211819. audioDevice = 0;
  211820. fileOutput = 0;
  211821. imageOutput = 0;
  211822. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  211823. internalDev: this];
  211824. NSError* err = 0;
  211825. [device retain];
  211826. [device open: &err];
  211827. if (err == 0)
  211828. {
  211829. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211830. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211831. [session addInput: input error: &err];
  211832. if (err == 0)
  211833. {
  211834. resetFile();
  211835. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  211836. [imageOutput setDelegate: callbackDelegate];
  211837. if (err == 0)
  211838. {
  211839. [session startRunning];
  211840. return;
  211841. }
  211842. }
  211843. }
  211844. openingError = nsStringToJuce ([err description]);
  211845. DBG (openingError);
  211846. }
  211847. ~QTCameraDeviceInteral()
  211848. {
  211849. [session stopRunning];
  211850. [session removeOutput: imageOutput];
  211851. [session release];
  211852. [input release];
  211853. [device release];
  211854. [audioDevice release];
  211855. [audioInput release];
  211856. [fileOutput release];
  211857. [imageOutput release];
  211858. [callbackDelegate release];
  211859. }
  211860. void resetFile()
  211861. {
  211862. [fileOutput recordToOutputFileURL: nil];
  211863. [session removeOutput: fileOutput];
  211864. [fileOutput release];
  211865. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  211866. [session removeInput: audioInput];
  211867. [audioInput release];
  211868. audioInput = 0;
  211869. [audioDevice release];
  211870. audioDevice = 0;
  211871. [fileOutput setDelegate: callbackDelegate];
  211872. }
  211873. void addDefaultAudioInput()
  211874. {
  211875. NSError* err = nil;
  211876. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  211877. if ([audioDevice open: &err])
  211878. [audioDevice retain];
  211879. else
  211880. audioDevice = nil;
  211881. if (audioDevice != 0)
  211882. {
  211883. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  211884. [session addInput: audioInput error: &err];
  211885. }
  211886. }
  211887. void addListener (CameraImageListener* listenerToAdd)
  211888. {
  211889. const ScopedLock sl (listenerLock);
  211890. if (listeners.size() == 0)
  211891. [session addOutput: imageOutput error: nil];
  211892. listeners.addIfNotAlreadyThere (listenerToAdd);
  211893. }
  211894. void removeListener (CameraImageListener* listenerToRemove)
  211895. {
  211896. const ScopedLock sl (listenerLock);
  211897. listeners.removeValue (listenerToRemove);
  211898. if (listeners.size() == 0)
  211899. [session removeOutput: imageOutput];
  211900. }
  211901. void callListeners (CIImage* frame, int w, int h)
  211902. {
  211903. CoreGraphicsImage image (Image::ARGB, w, h, false);
  211904. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  211905. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  211906. CGContextFlush (image.context);
  211907. const ScopedLock sl (listenerLock);
  211908. for (int i = listeners.size(); --i >= 0;)
  211909. {
  211910. CameraImageListener* l = (CameraImageListener*) listeners[i];
  211911. if (l != 0)
  211912. l->imageReceived (image);
  211913. }
  211914. }
  211915. QTCaptureDevice* device;
  211916. QTCaptureDeviceInput* input;
  211917. QTCaptureDevice* audioDevice;
  211918. QTCaptureDeviceInput* audioInput;
  211919. QTCaptureSession* session;
  211920. QTCaptureMovieFileOutput* fileOutput;
  211921. QTCaptureDecompressedVideoOutput* imageOutput;
  211922. QTCaptureCallbackDelegate* callbackDelegate;
  211923. String openingError;
  211924. VoidArray listeners;
  211925. CriticalSection listenerLock;
  211926. };
  211927. END_JUCE_NAMESPACE
  211928. @implementation QTCaptureCallbackDelegate
  211929. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  211930. internalDev: (QTCameraDeviceInteral*) d
  211931. {
  211932. [super init];
  211933. owner = owner_;
  211934. internal = d;
  211935. firstRecordedTime = 0;
  211936. return self;
  211937. }
  211938. - (void) dealloc
  211939. {
  211940. delete firstRecordedTime;
  211941. [super dealloc];
  211942. }
  211943. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211944. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211945. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211946. fromConnection: (QTCaptureConnection*) connection
  211947. {
  211948. if (internal->listeners.size() > 0)
  211949. {
  211950. const ScopedAutoReleasePool pool;
  211951. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  211952. CVPixelBufferGetWidth (videoFrame),
  211953. CVPixelBufferGetHeight (videoFrame));
  211954. }
  211955. }
  211956. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211957. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211958. fromConnection: (QTCaptureConnection*) connection
  211959. {
  211960. if (firstRecordedTime == 0)
  211961. {
  211962. const Time now (Time::getCurrentTime());
  211963. firstRecordedTime = new Time (now - RelativeTime (0.1));
  211964. }
  211965. }
  211966. @end
  211967. BEGIN_JUCE_NAMESPACE
  211968. class QTCaptureViewerComp : public NSViewComponent
  211969. {
  211970. public:
  211971. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  211972. {
  211973. const ScopedAutoReleasePool pool;
  211974. captureView = [[QTCaptureView alloc] init];
  211975. [captureView setCaptureSession: internal->session];
  211976. setSize (640, 480); // xxx need to somehow get the movie size - how?
  211977. setView (captureView);
  211978. }
  211979. ~QTCaptureViewerComp()
  211980. {
  211981. setView (0);
  211982. [captureView setCaptureSession: nil];
  211983. [captureView release];
  211984. }
  211985. QTCaptureView* captureView;
  211986. };
  211987. CameraDevice::CameraDevice (const String& name_, int index)
  211988. : name (name_)
  211989. {
  211990. isRecording = false;
  211991. QTCameraDeviceInteral* d = new QTCameraDeviceInteral (this, index);
  211992. internal = d;
  211993. }
  211994. CameraDevice::~CameraDevice()
  211995. {
  211996. stopRecording();
  211997. delete (QTCameraDeviceInteral*) internal;
  211998. internal = 0;
  211999. }
  212000. Component* CameraDevice::createViewerComponent()
  212001. {
  212002. return new QTCaptureViewerComp (this, (QTCameraDeviceInteral*) internal);
  212003. }
  212004. const String CameraDevice::getFileExtension()
  212005. {
  212006. return ".mov";
  212007. }
  212008. void CameraDevice::startRecordingToFile (const File& file)
  212009. {
  212010. stopRecording();
  212011. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212012. deleteAndZero (d->callbackDelegate->firstRecordedTime);
  212013. file.deleteFile();
  212014. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  212015. // out wrong, so we'll put some audio in there too..,
  212016. d->addDefaultAudioInput();
  212017. [d->session addOutput: d->fileOutput error: nil];
  212018. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  212019. for (;;)
  212020. {
  212021. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  212022. if (connection == 0)
  212023. break;
  212024. QTCompressionOptions* options = 0;
  212025. NSString* mediaType = [connection mediaType];
  212026. if ([mediaType isEqualToString: QTMediaTypeVideo])
  212027. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsSD480SizeH264Video"];
  212028. else if ([mediaType isEqualToString: QTMediaTypeSound])
  212029. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  212030. [d->fileOutput setCompressionOptions: options forConnection: connection];
  212031. }
  212032. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212033. isRecording = true;
  212034. }
  212035. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212036. {
  212037. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212038. if (d->callbackDelegate->firstRecordedTime != 0)
  212039. return *d->callbackDelegate->firstRecordedTime;
  212040. return Time();
  212041. }
  212042. void CameraDevice::stopRecording()
  212043. {
  212044. if (isRecording)
  212045. {
  212046. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212047. d->resetFile();
  212048. isRecording = false;
  212049. }
  212050. }
  212051. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212052. {
  212053. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212054. if (listenerToAdd != 0)
  212055. d->addListener (listenerToAdd);
  212056. }
  212057. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212058. {
  212059. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212060. if (listenerToRemove != 0)
  212061. d->removeListener (listenerToRemove);
  212062. }
  212063. const StringArray CameraDevice::getAvailableDevices()
  212064. {
  212065. const ScopedAutoReleasePool pool;
  212066. StringArray results;
  212067. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212068. for (int i = 0; i < (int) [devs count]; ++i)
  212069. {
  212070. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212071. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212072. }
  212073. return results;
  212074. }
  212075. CameraDevice* CameraDevice::openDevice (int index,
  212076. int minWidth, int minHeight,
  212077. int maxWidth, int maxHeight)
  212078. {
  212079. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212080. if (((QTCameraDeviceInteral*) (d->internal))->openingError.isEmpty())
  212081. return d.release();
  212082. return 0;
  212083. }
  212084. #endif
  212085. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212086. #endif
  212087. #endif
  212088. END_JUCE_NAMESPACE
  212089. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212090. #endif
  212091. #endif